LibDriver PMW3901MB
Loading...
Searching...
No Matches
driver_pmw3901mb_basic.c
Go to the documentation of this file.
1
36
38
39static pmw3901mb_handle_t gs_handle;
40
49{
50 uint8_t res;
51
52 /* link interface function */
63
64 /* init pmw3901mb */
65 res = pmw3901mb_init(&gs_handle);
66 if (res != 0)
67 {
68 pmw3901mb_interface_debug_print("pmw3901mb: init failed.\n");
69
70 return 1;
71 }
72
73 /* chip power up */
74 res = pmw3901mb_power_up(&gs_handle);
75 if (res != 0)
76 {
77 pmw3901mb_interface_debug_print("pmw3901mb: power up failed.\n");
78 (void)pmw3901mb_deinit(&gs_handle);
79
80 return 1;
81 }
82
83 /* set optimum performance */
84 res = pmw3901mb_set_optimum_performance(&gs_handle);
85 if (res != 0)
86 {
87 pmw3901mb_interface_debug_print("pmw3901mb: set optimum performance failed.\n");
88 (void)pmw3901mb_deinit(&gs_handle);
89
90 return 1;
91 }
92
93 return 0;
94}
95
107uint8_t pmw3901mb_basic_read(float height_m, pmw3901mb_motion_t *motion, float *delta_x, float *delta_y)
108{
109 uint8_t res;
110
111 if (pmw3901mb_burst_read(&gs_handle, motion) != 0)
112 {
113 return 1;
114 }
115 else
116 {
117 if (motion->is_valid == 1)
118 {
119 /* convert the delta x */
120 res = pmw3901mb_delta_raw_to_delta_cm(&gs_handle, motion->delta_x, height_m, (float *)delta_x);
121 if (res != 0)
122 {
123 return 1;
124 }
125
126 /* convert the delta y */
127 res = pmw3901mb_delta_raw_to_delta_cm(&gs_handle, motion->delta_y, height_m, (float *)delta_y);
128 if (res != 0)
129 {
130 return 1;
131 }
132 }
133 else
134 {
135 *delta_x = 0;
136 *delta_y = 0;
137 }
138
139 return 0;
140 }
141}
142
151{
152 if (pmw3901mb_deinit(&gs_handle) != 0)
153 {
154 return 1;
155 }
156 else
157 {
158 return 0;
159 }
160}
driver pmw3901mb basic 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_optimum_performance(pmw3901mb_handle_t *handle)
set the optimum performance
uint8_t pmw3901mb_power_up(pmw3901mb_handle_t *handle)
power up the chip
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
uint8_t pmw3901mb_basic_init(void)
basic example init
uint8_t pmw3901mb_basic_deinit(void)
basic example deinit
uint8_t pmw3901mb_basic_read(float height_m, pmw3901mb_motion_t *motion, float *delta_x, float *delta_y)
basic example read
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