LibDriver TCS34725
Loading...
Searching...
No Matches
driver_tcs34725_interrupt.c
Go to the documentation of this file.
1
37
39
40static tcs34725_handle_t gs_handle;
41
52uint8_t tcs34725_interrupt_init(tcs34725_interrupt_mode_t mode, uint16_t low_threshold, uint16_t high_threshold)
53{
54 uint8_t res;
55
56 /* link interface function */
64
65 /* tcs34725 init */
66 res = tcs34725_init(&gs_handle);
67 if (res != 0)
68 {
69 tcs34725_interface_debug_print("tcs34725: init failed.\n");
70
71 return 1;
72 }
73
74 /* enable rgbc interrupt */
76 if (res != 0)
77 {
78 tcs34725_interface_debug_print("tcs34725: set rgbc interrupt failed.\n");
79 (void)tcs34725_deinit(&gs_handle);
80
81 return 1;
82 }
83
84 /* set wait */
86 if (res != 0)
87 {
88 tcs34725_interface_debug_print("tcs34725: set wait failed.\n");
89 (void)tcs34725_deinit(&gs_handle);
90
91 return 1;
92 }
93
94 /* set rgbc */
96 if (res != 0)
97 {
98 tcs34725_interface_debug_print("tcs34725: set rgbc failed.\n");
99 (void)tcs34725_deinit(&gs_handle);
100
101 return 1;
102 }
103
104 /* set rgbc integration time */
106 if (res != 0)
107 {
108 tcs34725_interface_debug_print("tcs34725: set rgbc integration time failed.\n");
109 (void)tcs34725_deinit(&gs_handle);
110
111 return 1;
112 }
113
114 /* set wait time */
116 if (res != 0)
117 {
118 tcs34725_interface_debug_print("tcs34725: set wait time failed.\n");
119 (void)tcs34725_deinit(&gs_handle);
120
121 return 1;
122 }
123
124 /* set rgbc clear low interrupt threshold */
125 res = tcs34725_set_rgbc_clear_low_interrupt_threshold(&gs_handle, low_threshold);
126 if (res != 0)
127 {
128 tcs34725_interface_debug_print("tcs34725: set rgbc clear low interrupt threshold failed.\n");
129 (void)tcs34725_deinit(&gs_handle);
130
131 return 1;
132 }
133
134 /* set rgbc clear high interrupt threshold */
135 res = tcs34725_set_rgbc_clear_high_interrupt_threshold(&gs_handle, high_threshold);
136 if (res != 0)
137 {
138 tcs34725_interface_debug_print("tcs34725: set rgbc clear high interrupt threshold failed.\n");
139 (void)tcs34725_deinit(&gs_handle);
140
141 return 1;
142 }
143
144 /* set gain */
146 if (res != 0)
147 {
148 tcs34725_interface_debug_print("tcs34725: set gain failed.\n");
149 (void)tcs34725_deinit(&gs_handle);
150
151 return 1;
152 }
153
154 /* set interrupt mode */
155 res = tcs34725_set_interrupt_mode(&gs_handle, mode);
156 if (res != 0)
157 {
158 tcs34725_interface_debug_print("tcs34725: set interrupt mode failed.\n");
159 (void)tcs34725_deinit(&gs_handle);
160
161 return 1;
162 }
163
164 /* set power on */
166 if (res != 0)
167 {
168 tcs34725_interface_debug_print("tcs34725: set power on failed.\n");
169 (void)tcs34725_deinit(&gs_handle);
170
171 return 1;
172 }
173
174 return 0;
175}
176
188uint8_t tcs34725_interrupt_read(uint16_t *red, uint16_t *green, uint16_t *blue, uint16_t *clear)
189{
190 /* read data */
191 if (tcs34725_read_rgbc(&gs_handle, red, green, blue, clear) != 0)
192 {
193 return 1;
194 }
195 else
196 {
197 return 0;
198 }
199}
200
209{
210 /* tcs34725 deinit */
211 if (tcs34725_deinit(&gs_handle) != 0)
212 {
213 return 1;
214 }
215 else
216 {
217 return 0;
218 }
219}
driver tcs34725 interrupt header file
uint8_t tcs34725_set_rgbc_integration_time(tcs34725_handle_t *handle, tcs34725_integration_time_t t)
set the rgbc adc integration time
uint8_t tcs34725_deinit(tcs34725_handle_t *handle)
close the chip
uint8_t tcs34725_set_gain(tcs34725_handle_t *handle, tcs34725_gain_t gain)
set the adc gain
uint8_t tcs34725_set_rgbc(tcs34725_handle_t *handle, tcs34725_bool_t enable)
enable or disable the rgbc adc
uint8_t tcs34725_set_wait_time(tcs34725_handle_t *handle, tcs34725_wait_time_t t)
set the wait time
uint8_t tcs34725_set_power_on(tcs34725_handle_t *handle, tcs34725_bool_t enable)
enable or disable the power
struct tcs34725_handle_s tcs34725_handle_t
tcs34725 handle structure definition
uint8_t tcs34725_init(tcs34725_handle_t *handle)
initialize the chip
uint8_t tcs34725_read_rgbc(tcs34725_handle_t *handle, uint16_t *red, uint16_t *green, uint16_t *blue, uint16_t *clear)
read the rgbc data
uint8_t tcs34725_set_wait(tcs34725_handle_t *handle, tcs34725_bool_t enable)
enable or disable the wait time
@ TCS34725_BOOL_TRUE
uint8_t tcs34725_interrupt_read(uint16_t *red, uint16_t *green, uint16_t *blue, uint16_t *clear)
interrupt example read
#define TCS34725_INTERRUPT_DEFAULT_WAIT
tcs34725 interrupt example default definition
uint8_t tcs34725_interrupt_init(tcs34725_interrupt_mode_t mode, uint16_t low_threshold, uint16_t high_threshold)
interrupt example init
#define TCS34725_INTERRUPT_DEFAULT_POWER_ON
#define TCS34725_INTERRUPT_DEFAULT_RGBC
uint8_t tcs34725_interrupt_deinit(void)
interrupt example deinit
#define TCS34725_INTERRUPT_DEFAULT_GAIN
#define TCS34725_INTERRUPT_DEFAULT_WAIT_TIME
#define TCS34725_INTERRUPT_DEFAULT_INTEGRATION_TIME
void tcs34725_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t tcs34725_interface_iic_init(void)
interface iic bus init
uint8_t tcs34725_interface_iic_write(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus write
uint8_t tcs34725_interface_iic_deinit(void)
interface iic bus deinit
uint8_t tcs34725_interface_iic_read(uint8_t addr, uint8_t reg, uint8_t *buf, uint16_t len)
interface iic bus read
void tcs34725_interface_debug_print(const char *const fmt,...)
interface print format data
tcs34725_interrupt_mode_t
tcs34725 interrupt mode enumeration definition
uint8_t tcs34725_set_rgbc_clear_high_interrupt_threshold(tcs34725_handle_t *handle, uint16_t threshold)
set the rgbc clear high interrupt threshold
uint8_t tcs34725_set_rgbc_interrupt(tcs34725_handle_t *handle, tcs34725_bool_t enable)
enable or disable the rgbc interrupt
uint8_t tcs34725_set_rgbc_clear_low_interrupt_threshold(tcs34725_handle_t *handle, uint16_t threshold)
set the rgbc clear low interrupt threshold
uint8_t tcs34725_set_interrupt_mode(tcs34725_handle_t *handle, tcs34725_interrupt_mode_t mode)
set the interrupt mode