LibDriver TCS34725
Loading...
Searching...
No Matches
driver_tcs34725_interrupt_test.c
Go to the documentation of this file.
1
37
39
40static tcs34725_handle_t gs_handle;
41
53uint8_t tcs34725_interrupt_test(tcs34725_interrupt_mode_t mode, uint16_t clear_low_threshold, uint16_t clear_high_threshold, uint32_t times)
54{
55 uint8_t res;
56 tcs34725_info_t info;
57
58 /* link interface function */
66
67 /* get chip information */
68 res = tcs34725_info(&info);
69 if (res != 0)
70 {
71 tcs34725_interface_debug_print("tcs34725: get info failed.\n");
72
73 return 1;
74 }
75 else
76 {
77 /* print chip information */
78 tcs34725_interface_debug_print("tcs34725: chip is %s.\n", info.chip_name);
79 tcs34725_interface_debug_print("tcs34725: manufacturer is %s.\n", info.manufacturer_name);
80 tcs34725_interface_debug_print("tcs34725: interface is %s.\n", info.interface);
81 tcs34725_interface_debug_print("tcs34725: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
82 tcs34725_interface_debug_print("tcs34725: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
83 tcs34725_interface_debug_print("tcs34725: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
84 tcs34725_interface_debug_print("tcs34725: max current is %0.2fmA.\n", info.max_current_ma);
85 tcs34725_interface_debug_print("tcs34725: max temperature is %0.1fC.\n", info.temperature_max);
86 tcs34725_interface_debug_print("tcs34725: min temperature is %0.1fC.\n", info.temperature_min);
87 }
88
89 /* tcs34725 init */
90 res = tcs34725_init(&gs_handle);
91 if (res != 0)
92 {
93 tcs34725_interface_debug_print("tcs34725: init failed.\n");
94
95 return 1;
96 }
97
98 /* start interrupt test */
99 tcs34725_interface_debug_print("tcs34725: start interrupt test.\n");
100
101 /* enable rgbc interrupt */
103 if (res != 0)
104 {
105 tcs34725_interface_debug_print("tcs34725: set rgbc interrupt failed.\n");
106 (void)tcs34725_deinit(&gs_handle);
107
108 return 1;
109 }
110
111 /* enable wait */
112 res = tcs34725_set_wait(&gs_handle, TCS34725_BOOL_TRUE);
113 if (res != 0)
114 {
115 tcs34725_interface_debug_print("tcs34725: set wait failed.\n");
116 (void)tcs34725_deinit(&gs_handle);
117
118 return 1;
119 }
120
121 /* enable rgbc */
122 res = tcs34725_set_rgbc(&gs_handle, TCS34725_BOOL_TRUE);
123 if (res != 0)
124 {
125 tcs34725_interface_debug_print("tcs34725: set rgbc failed.\n");
126 (void)tcs34725_deinit(&gs_handle);
127
128 return 1;
129 }
130
131 /* set rgbc integration time 50 ms */
133 if (res != 0)
134 {
135 tcs34725_interface_debug_print("tcs34725: set rgbc integration time failed.\n");
136 (void)tcs34725_deinit(&gs_handle);
137
138 return 1;
139 }
140
141 /* set wait time 2.4 ms */
143 if (res != 0)
144 {
145 tcs34725_interface_debug_print("tcs34725: set wait time failed.\n");
146 (void)tcs34725_deinit(&gs_handle);
147
148 return 1;
149 }
150
151 /* set clear low interrupt threshold */
152 res = tcs34725_set_rgbc_clear_low_interrupt_threshold(&gs_handle, clear_low_threshold);
153 if (res != 0)
154 {
155 tcs34725_interface_debug_print("tcs34725: set rgbc clear low interrupt threshold failed.\n");
156 (void)tcs34725_deinit(&gs_handle);
157
158 return 1;
159 }
160
161 /* set clear high interrupt threshold */
162 res = tcs34725_set_rgbc_clear_high_interrupt_threshold(&gs_handle, clear_high_threshold);
163 if (res != 0)
164 {
165 tcs34725_interface_debug_print("tcs34725: set rgbc clear high interrupt threshold failed.\n");
166 (void)tcs34725_deinit(&gs_handle);
167
168 return 1;
169 }
170
171 /* set gain 16x */
172 res = tcs34725_set_gain(&gs_handle, TCS34725_GAIN_16X);
173 if (res != 0)
174 {
175 tcs34725_interface_debug_print("tcs34725: set gain failed.\n");
176 (void)tcs34725_deinit(&gs_handle);
177
178 return 1;
179 }
180
181 /* set interrupt mode */
182 res = tcs34725_set_interrupt_mode(&gs_handle, mode);
183 if (res != 0)
184 {
185 tcs34725_interface_debug_print("tcs34725: set interrupt mode failed.\n");
186 (void)tcs34725_deinit(&gs_handle);
187
188 return 1;
189 }
190
191 /* enable power on */
192 res = tcs34725_set_power_on(&gs_handle, TCS34725_BOOL_TRUE);
193 if (res != 0)
194 {
195 tcs34725_interface_debug_print("tcs34725: set power on failed.\n");
196 (void)tcs34725_deinit(&gs_handle);
197
198 return 1;
199 }
200
201 /* delay 1000 ms */
203 while (times != 0)
204 {
205 uint16_t red, green, blue, clear;
206
207 /* read rgbc data */
208 if (tcs34725_read_rgbc(&gs_handle, (uint16_t *)&red, (uint16_t *)&green, (uint16_t *)&blue, (uint16_t *)&clear) != 0)
209 {
210 tcs34725_interface_debug_print("tcs34725: read rgbc failed.\n");
211 (void)tcs34725_deinit(&gs_handle);
212
213 return 1;
214 }
215 tcs34725_interface_debug_print("tcs34725: clear is %d and check high interrupt %s.\n", clear, clear>clear_high_threshold?"high threshold":"none");
216 tcs34725_interface_debug_print("tcs34725: clear is %d and check low interrupt %s.\n", clear, clear<clear_low_threshold?"low threshold":"none");
217 times--;
219 }
220
221 /* finish interrupt test */
222 tcs34725_interface_debug_print("tcs34725: finish interrupt test.\n");
223 (void)tcs34725_deinit(&gs_handle);
224
225 return 0;
226}
driver tcs34725 interrupt test 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
struct tcs34725_info_s tcs34725_info_t
tcs34725 information structure definition
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
uint8_t tcs34725_info(tcs34725_info_t *info)
get chip information
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
@ TCS34725_WAIT_TIME_2P4MS
@ TCS34725_GAIN_16X
@ TCS34725_INTEGRATION_TIME_50MS
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
uint8_t tcs34725_interrupt_test(tcs34725_interrupt_mode_t mode, uint16_t clear_low_threshold, uint16_t clear_high_threshold, uint32_t times)
interrupt test
char manufacturer_name[32]