LibDriver PMW3901MB
Loading...
Searching...
No Matches
driver_pmw3901mb_frame_test.c
Go to the documentation of this file.
1
36
38
39static pmw3901mb_handle_t gs_handle;
40static uint8_t gs_frame[35][35];
41
50uint8_t pmw3901mb_frame_test(uint32_t times)
51{
52 uint8_t res;
53 uint8_t i, j;
55
56 /* link interface function */
67
68 /* get information */
69 res = pmw3901mb_info(&info);
70 if (res != 0)
71 {
72 pmw3901mb_interface_debug_print("pmw3901mb: get info failed.\n");
73
74 return 1;
75 }
76 else
77 {
78 /* print chip info */
79 pmw3901mb_interface_debug_print("pmw3901mb: chip is %s.\n", info.chip_name);
80 pmw3901mb_interface_debug_print("pmw3901mb: manufacturer is %s.\n", info.manufacturer_name);
81 pmw3901mb_interface_debug_print("pmw3901mb: interface is %s.\n", info.interface);
82 pmw3901mb_interface_debug_print("pmw3901mb: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
83 pmw3901mb_interface_debug_print("pmw3901mb: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
84 pmw3901mb_interface_debug_print("pmw3901mb: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
85 pmw3901mb_interface_debug_print("pmw3901mb: max current is %0.2fmA.\n", info.max_current_ma);
86 pmw3901mb_interface_debug_print("pmw3901mb: max temperature is %0.1fC.\n", info.temperature_max);
87 pmw3901mb_interface_debug_print("pmw3901mb: min temperature is %0.1fC.\n", info.temperature_min);
88 }
89
90 /* start the frame capture test */
91 pmw3901mb_interface_debug_print("pmw3901mb: start frame capture test.\n");
92
93 /* init pmw3901mb */
94 res = pmw3901mb_init(&gs_handle);
95 if (res != 0)
96 {
97 pmw3901mb_interface_debug_print("pmw3901mb: init failed.\n");
98
99 return 1;
100 }
101
102 /* chip power up */
103 res = pmw3901mb_power_up(&gs_handle);
104 if (res != 0)
105 {
106 pmw3901mb_interface_debug_print("pmw3901mb: power up failed.\n");
107 (void)pmw3901mb_deinit(&gs_handle);
108
109 return 1;
110 }
111
112 /* start frame capture */
113 res = pmw3901mb_start_frame_capture(&gs_handle);
114 if (res != 0)
115 {
116 pmw3901mb_interface_debug_print("pmw3901mb: start frame capture failed.\n");
117 (void)pmw3901mb_deinit(&gs_handle);
118
119 return 1;
120 }
121
122 /* wait */
123 while (times != 0)
124 {
125 /* get frame */
126 res = pmw3901mb_get_frame(&gs_handle, gs_frame);
127 if (res != 0)
128 {
129 pmw3901mb_interface_debug_print("pmw3901mb: get frame failed.\n");
130 (void)pmw3901mb_deinit(&gs_handle);
131
132 return 1;
133 }
134
135 /* print frame */
136 for (i = 0; i < 35; i++)
137 {
138 for (j = 0; j < 35; j++)
139 {
140 pmw3901mb_interface_debug_print("0x%02X ", gs_frame[i][j]);
141 }
143 }
144
145 /* if the last */
146 if (times != 1)
147 {
149 }
150
151 /* delay 1000 ms */
153
154 /* times-- */
155 times--;
156 }
157
158 /* stop frame capture */
159 res = pmw3901mb_stop_frame_capture(&gs_handle);
160 if (res != 0)
161 {
162 pmw3901mb_interface_debug_print("pmw3901mb: stop frame capture failed.\n");
163 (void)pmw3901mb_deinit(&gs_handle);
164
165 return 1;
166 }
167
168 /* finish the frame capture test */
169 pmw3901mb_interface_debug_print("pmw3901mb: finish frame capture test.\n");
170 (void)pmw3901mb_deinit(&gs_handle);
171
172 return 0;
173}
driver pmw3901mb frame test header file
uint8_t pmw3901mb_init(pmw3901mb_handle_t *handle)
initialize the chip
uint8_t pmw3901mb_stop_frame_capture(pmw3901mb_handle_t *handle)
stop frame capture
struct pmw3901mb_handle_s pmw3901mb_handle_t
pmw3901mb handle structure definition
struct pmw3901mb_info_s pmw3901mb_info_t
pmw3901mb information structure definition
uint8_t pmw3901mb_get_frame(pmw3901mb_handle_t *handle, uint8_t frame[35][35])
get the frame
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
uint8_t pmw3901mb_deinit(pmw3901mb_handle_t *handle)
close the chip
uint8_t pmw3901mb_start_frame_capture(pmw3901mb_handle_t *handle)
start frame capture
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_frame_test(uint32_t times)
frame capture test