LibDriver PMW3901MB
Loading...
Searching...
No Matches
driver_pmw3901mb_interrupt_test.c
Go to the documentation of this file.
1
36
38
39static pmw3901mb_handle_t gs_handle;
40static volatile uint8_t gs_flag;
41
51{
52 uint8_t res;
53 float delta_x;
54 float delta_y;
55 pmw3901mb_motion_t motion;
56
57 /* burst read */
58 res = pmw3901mb_burst_read(&gs_handle, &motion);
59 if (res != 0)
60 {
61 pmw3901mb_interface_debug_print("pmw3901mb: burst read failed.\n");
62 (void)pmw3901mb_set_motion(&gs_handle, 0x00);
63
64 return 1;
65 }
66
67 /* check the result */
68 if (motion.is_valid == 1)
69 {
70 /* convert the delta x */
71 res = pmw3901mb_delta_raw_to_delta_cm(&gs_handle, motion.delta_x, height_m, (float *)&delta_x);
72 if (res != 0)
73 {
74 pmw3901mb_interface_debug_print("pmw3901mb: delta raw to delta cm failed.\n");
75 (void)pmw3901mb_set_motion(&gs_handle, 0x00);
76
77 return 1;
78 }
79
80 /* convert the delta y */
81 res = pmw3901mb_delta_raw_to_delta_cm(&gs_handle, motion.delta_y, height_m, (float *)&delta_y);
82 if (res != 0)
83 {
84 pmw3901mb_interface_debug_print("pmw3901mb: delta raw to delta cm failed.\n");
85 (void)pmw3901mb_set_motion(&gs_handle, 0x00);
86
87 return 1;
88 }
89
90 /* print the result */
91 pmw3901mb_interface_debug_print("pmw3901mb: find interrupt.\n");
92 pmw3901mb_interface_debug_print("pmw3901mb: delta_x: %0.3fcm delta_y: %0.3fcm.\n", delta_x, delta_y);
93 pmw3901mb_interface_debug_print("pmw3901mb: raw_average is 0x%02X.\n", motion.raw_average);
94 pmw3901mb_interface_debug_print("pmw3901mb: raw_max is 0x%02X.\n", motion.raw_max);
95 pmw3901mb_interface_debug_print("pmw3901mb: raw_min is 0x%02X.\n", motion.raw_min);
96 pmw3901mb_interface_debug_print("pmw3901mb: observation is 0x%02X.\n", motion.observation);
97 pmw3901mb_interface_debug_print("pmw3901mb: shutter is 0x%04X.\n", motion.shutter);
98 pmw3901mb_interface_debug_print("pmw3901mb: surface quality is 0x%04X.\n", motion.surface_quality);
99
100 /* set flag */
101 gs_flag = 1;
102 }
103
104 /* clear the interrupt flag */
105 res = pmw3901mb_set_motion(&gs_handle, 0x00);
106 if (res != 0)
107 {
108 pmw3901mb_interface_debug_print("pmw3901mb: set motion failed.\n");
109
110 return 1;
111 }
112
113 return 0;
114}
115
124uint8_t pmw3901mb_interrupt_test(uint32_t times)
125{
126 uint8_t res;
127 pmw3901mb_info_t info;
128
129 /* link interface function */
140
141 /* get information */
142 res = pmw3901mb_info(&info);
143 if (res != 0)
144 {
145 pmw3901mb_interface_debug_print("pmw3901mb: get info failed.\n");
146
147 return 1;
148 }
149 else
150 {
151 /* print chip info */
152 pmw3901mb_interface_debug_print("pmw3901mb: chip is %s.\n", info.chip_name);
153 pmw3901mb_interface_debug_print("pmw3901mb: manufacturer is %s.\n", info.manufacturer_name);
154 pmw3901mb_interface_debug_print("pmw3901mb: interface is %s.\n", info.interface);
155 pmw3901mb_interface_debug_print("pmw3901mb: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
156 pmw3901mb_interface_debug_print("pmw3901mb: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
157 pmw3901mb_interface_debug_print("pmw3901mb: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
158 pmw3901mb_interface_debug_print("pmw3901mb: max current is %0.2fmA.\n", info.max_current_ma);
159 pmw3901mb_interface_debug_print("pmw3901mb: max temperature is %0.1fC.\n", info.temperature_max);
160 pmw3901mb_interface_debug_print("pmw3901mb: min temperature is %0.1fC.\n", info.temperature_min);
161 }
162
163 /* start the interrupt test */
164 pmw3901mb_interface_debug_print("pmw3901mb: start the interrupt test.\n");
165
166 /* init pmw3901mb */
167 res = pmw3901mb_init(&gs_handle);
168 if (res != 0)
169 {
170 pmw3901mb_interface_debug_print("pmw3901mb: init failed.\n");
171
172 return 1;
173 }
174
175 /* chip power up */
176 res = pmw3901mb_power_up(&gs_handle);
177 if (res != 0)
178 {
179 pmw3901mb_interface_debug_print("pmw3901mb: power up failed.\n");
180 (void)pmw3901mb_deinit(&gs_handle);
181
182 return 1;
183 }
184
185 /* set optimum performance */
186 res = pmw3901mb_set_optimum_performance(&gs_handle);
187 if (res != 0)
188 {
189 pmw3901mb_interface_debug_print("pmw3901mb: set optimum performance failed.\n");
190 (void)pmw3901mb_deinit(&gs_handle);
191
192 return 1;
193 }
194
195 /* wait */
196 while (times != 0)
197 {
198 gs_flag = 0x00;
199 while (gs_flag == 0x00)
200 {
202 }
203 times--;
204 }
205
206 /* finish the interrupt test */
207 pmw3901mb_interface_debug_print("pmw3901mb: finish the interrupt test.\n");
208 (void)pmw3901mb_deinit(&gs_handle);
209
210 return 0;
211}
driver pmw3901mb interrupt test header file
uint8_t pmw3901mb_init(pmw3901mb_handle_t *handle)
initialize the chip
struct pmw3901mb_handle_s pmw3901mb_handle_t
pmw3901mb handle structure definition
uint8_t pmw3901mb_set_motion(pmw3901mb_handle_t *handle, uint8_t motion)
set the motion
struct pmw3901mb_info_s pmw3901mb_info_t
pmw3901mb information structure definition
uint8_t pmw3901mb_set_optimum_performance(pmw3901mb_handle_t *handle)
set the optimum performance
uint8_t pmw3901mb_power_up(pmw3901mb_handle_t *handle)
power up the chip
uint8_t pmw3901mb_info(pmw3901mb_info_t *info)
get chip's information
struct pmw3901mb_motion_s pmw3901mb_motion_t
pmw3901mb motion structure definition
uint8_t pmw3901mb_delta_raw_to_delta_cm(pmw3901mb_handle_t *handle, int16_t raw, float height_m, float *cm)
convert the delta raw to the delta cm
uint8_t pmw3901mb_deinit(pmw3901mb_handle_t *handle)
close the chip
uint8_t pmw3901mb_burst_read(pmw3901mb_handle_t *handle, pmw3901mb_motion_t *motion)
burst read data
void pmw3901mb_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t pmw3901mb_interface_spi_write(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus write
uint8_t pmw3901mb_interface_spi_deinit(void)
interface spi bus deinit
uint8_t pmw3901mb_interface_reset_gpio_write(uint8_t data)
interface reset gpio write
uint8_t pmw3901mb_interface_spi_read(uint8_t reg, uint8_t *buf, uint16_t len)
interface spi bus read
uint8_t pmw3901mb_interface_spi_init(void)
interface spi bus init
uint8_t pmw3901mb_interface_reset_gpio_deinit(void)
interface reset gpio deinit
void pmw3901mb_interface_delay_ms(uint32_t ms)
interface delay ms
uint8_t pmw3901mb_interface_reset_gpio_init(void)
interface reset gpio init
uint8_t pmw3901mb_interrupt_test_irq_handler(float height_m)
interrupt test irq
uint8_t pmw3901mb_interrupt_test(uint32_t times)
interrupt test