MBot Software Library  v1.0
An API documentation to mbot_firmware repository
bhy_uc_driver.h
Go to the documentation of this file.
1 
52 #ifndef BHY_UC_DRIVER_H_
53 #define BHY_UC_DRIVER_H_
54 
55 #include "bhy_support.h"
56 #include "bhy_uc_driver_types.h"
57 
58 /****************************************************************************/
59 /* Driver Functions */
60 /****************************************************************************/
61 
62 
63 /* initializes the driver, the API and loads the ram patch into the sensor */
64 BHY_RETURN_FUNCTION_TYPE bhy_driver_init
65  (const uint8_t *bhy_fw_data);
66 
67 /* this function configures meta event */
68 BHY_RETURN_FUNCTION_TYPE bhy_meta_event_set_config( bhy_meta_event_type_t meta_event_id,
69  bhy_meta_event_fifo_type_t fifo_sel,
70  uint8_t enable_state, uint8_t int_enable_state);
71 
72 /* this function gets configuration from specific meta event */
73 BHY_RETURN_FUNCTION_TYPE bhy_meta_event_get_config( bhy_meta_event_type_t meta_event_id,
74  bhy_meta_event_fifo_type_t fifo_sel,
75  uint8_t* p_enable_state, uint8_t* p_int_enable_state);
76 
77 /*****************************************************************************
78  * Function : bhy_mapping_matrix_set
79  * Description : Set mapping matrix to a corresponding physical sensor.
80  * Input : index: physical sensor index.
81  * PHYSICAL_SENSOR_INDEX_ACC = 0,
82  * PHYSICAL_SENSOR_INDEX_MAG = 1,
83  * PHYSICAL_SENSOR_INDEX_GYRO = 2,
84  * p_mapping_matrix: pointer to a "int8_t mapping_matrix[9]".
85  * Output : None
86  * Return :
87 *****************************************************************************/
88 BHY_RETURN_FUNCTION_TYPE bhy_mapping_matrix_set(bhy_physical_sensor_index_type_t index , int8_t *p_mapping_matrix);
89 
90 /*****************************************************************************
91  * Function : bhy_mapping_matrix_get
92  * Description : Get mapping matrix from a corresponding physical sensor.
93  * Input : index: physical sensor index.
94  * PHYSICAL_SENSOR_INDEX_ACC = 0,
95  * PHYSICAL_SENSOR_INDEX_MAG = 1,
96  * PHYSICAL_SENSOR_INDEX_GYRO = 2,
97  * Output : p_mapping_matrix: pointer to a "int8_t mapping_matrix[9]".
98  * Return :
99 *****************************************************************************/
100 BHY_RETURN_FUNCTION_TYPE bhy_mapping_matrix_get(bhy_physical_sensor_index_type_t index , int8_t *p_mapping_matrix);
101 
102 /* This function uses the soft pass-through feature to perform single multi-*/
103 /* byte transfers in order to write the data. parameters: */
104 /* addr i2c address of the slave device */
105 /* reg register address to write to */
106 /* data pointer to the data buffer with data to write to the */
107 /* slave */
108 /* length number of bytes to write to the slave */
109 /* increment_reg if true, the function will automatically increment the */
110 /* register between successive 4-bytes transfers */
111 BHY_RETURN_FUNCTION_TYPE bhy_soft_passthru_write(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t length, uint8_t increment_reg);
112 
113 /* This function uses the soft pass-through feature to perform single multi-*/
114 /* byte transfers in order to read the data. parameters: */
115 /* addr i2c address of the slave device */
116 /* reg register address to read from */
117 /* data pointer to the data buffer where to place the data read */
118 /* from the slave */
119 /* length number of bytes to fread from the slave */
120 /* increment_reg if true, the function will automatically increment the */
121 /* register between successive 4-bytes transfers */
122 BHY_RETURN_FUNCTION_TYPE bhy_soft_passthru_read(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t length, uint8_t increment_reg);
123 
124 /*****************************************************************************
125  * Function : bhy_gp_register_write
126  * Description : Write data to specific GP register.
127  * Input : bhy_gp_register_type_t: GP register address.
128  * : p_data: pointer to receive buffer.
129  * Output :
130  * Return :
131 *****************************************************************************/
132 BHY_RETURN_FUNCTION_TYPE bhy_gp_register_write(bhy_gp_register_type_t gp_reg, uint8_t data);
133 
134 /*****************************************************************************
135  * Function : bhy_gp_register_read
136  * Description : Read data from specific GP register.
137  * Input : bhy_gp_register_type_t: GP register address.
138  * Output : p_data: pointer to receive buffer.
139  * Return :
140 *****************************************************************************/
141 BHY_RETURN_FUNCTION_TYPE bhy_gp_register_read(bhy_gp_register_type_t gp_reg, uint8_t *p_data);
142 
143 /* this functions enables the selected virtual sensor */
144 BHY_RETURN_FUNCTION_TYPE bhy_enable_virtual_sensor
145  (bhy_virtual_sensor_t sensor_id, uint8_t wakeup_status, uint16_t sample_rate,
146  uint16_t max_report_latency_ms, uint8_t flush_sensor, uint16_t change_sensitivity,
147  uint16_t dynamic_range);
148 
149 /* this functions disables the selected virtual sensor */
150 BHY_RETURN_FUNCTION_TYPE bhy_disable_virtual_sensor
151  (bhy_virtual_sensor_t sensor_id, uint8_t wakeup_status);
152 
153 /* retrieves the fifo data. it needs a buffer of at least 51 bytes to work */
154 /* it outputs the data into the variable buffer. the number of bytes read */
155 /* into bytes_read and the bytes remaining in the fifo into bytes_left. */
156 /* Setting BST_APPLICATION_BOARD to 1 will limit the size to 51 bytes all */
157 /* the time. Arguments : */
158 /* buffer Pointer to the buffer to use for the fifo readout. */
159 /* buffer_size Size of the buffer to work with. Needs to be 51 bytes+ */
160 /* bytes_read Pointer to output the number of bytes actually read from*/
161 /* the fifo. */
162 /* bytes_left Pointer to output the number of bytes still in the fifo.*/
163 /* This function automatically keeps track of the current */
164 /* fifo readout progress.
165 */
166 BHY_RETURN_FUNCTION_TYPE bhy_read_fifo(uint8_t * buffer, uint16_t buffer_size,
167  uint16_t * bytes_read, uint16_t * bytes_left);
168 
169 /* This function parses the next fifo packet and return it into a generic */
170 /* data structure while telling you what the data type is so you can */
171 /* retrieve it. Here are the parameters: */
172 /* fifo_buffer pointer to the fifo byte that is the start of a */
173 /* packet. This pointer will be automatically */
174 /* incremented so you can call this function in a loop */
175 /* fifo_buffer_length pointer to the amount of data left in the */
176 /* fifo_buffer. This data will be automatically */
177 /* decremented so you can call this function in a loop */
178 /* fifo_data_output buffer in which to place the data */
179 /* fifo_data_type data type output */
180 BHY_RETURN_FUNCTION_TYPE bhy_parse_next_fifo_packet
181  (uint8_t **fifo_buffer, uint16_t *fifo_buffer_length,
182  bhy_data_generic_t * fifo_data_output, bhy_data_type_t * fifo_data_type);
183 
184 /* This function will detect the timestamp packet accordingly and update */
185 /* either the MSW or the LSW of the system timestamp. Arguments : */
186 /* timestamp_packet The timestamp packet processed by the parse_next_ */
187 /* fifo_packet, properly typecasted */
188 /* system_timestamp Pointer to a 32bit variable holding the system */
189 /* timestamp in 1/32000th seconds. it will wrap around */
190 /* every 36 hours. */
191 BHY_RETURN_FUNCTION_TYPE bhy_update_system_timestamp(bhy_data_scalar_u16_t *timestamp_packet,
192  uint32_t * system_timestamp);
193 
194 /* This function writes arbitrary data to an arbitrary parameter page. To be*/
195 /* used carefully since it can override system configurations. Refer to the */
196 /* datasheet for free to use parameter pages. Here are the arguments: */
197 /* page Page number. Valid range 1 to 15. */
198 /* parameter Parameter number. Valid range 0 to 127. */
199 /* data Pointer to the data source to write to. */
200 /* length Number of bytes to write. Valid range 1 to 8. */
201 BHY_RETURN_FUNCTION_TYPE bhy_write_parameter_page(uint8_t page, uint8_t parameter,
202  uint8_t *data, uint8_t length);
203 
204 /* This function reads arbitrary data to an arbitrary parameter page. To be*/
205 /* used carefully since it can override system configurations. Refer to the */
206 /* datasheet for free to use parameter pages. Here are the arguments: */
207 /* page Page number. Valid range 1 to 15. */
208 /* parameter Parameter number. Valid range 0 to 127. */
209 /* data Pointer to the data source to write to. */
210 /* length Number of bytes to read. Valid range 1 to 16. */
211 BHY_RETURN_FUNCTION_TYPE bhy_read_parameter_page(uint8_t page, uint8_t parameter,
212  uint8_t *data, uint8_t length);
213 
214 /* This function write a new SIC matrix to the BHy. Arguments are: */
215 /* sic_matrix pointer to array of 9 floats with SIC matrix */
216 BHY_RETURN_FUNCTION_TYPE bhy_set_sic_matrix(float * sic_matrix);
217 
218 /* This function reads out the current SIC matrix from BHy. Arguments are: */
219 /* sic_matrix pointer to array of 9 floats with SIC matrix */
220 BHY_RETURN_FUNCTION_TYPE bhy_get_sic_matrix(float * sic_matrix);
221 
222 /* This function outputs the debug data to function pointer. You need to */
223 /* provide a function that takes as argument a zero-terminated string and */
224 /* prints it */
225 void bhy_print_debug_packet(bhy_data_debug_t *packet, void (*debug_print_ptr)(const uint8_t *));
226 
227 BHY_RETURN_FUNCTION_TYPE bhy_sync_cus_evt_size(void);
228 
229 int8_t bhy_get_cus_evt_size(bhy_virtual_sensor_t sensor_id);
230 
231 
232 #if BHY_CALLBACK_MODE
233 /* These functions will install the callback and return an error code if */
234 /* there is already a callback installed */
235 BHY_RETURN_FUNCTION_TYPE bhy_install_sensor_callback (bhy_virtual_sensor_t sensor_id, uint8_t wakeup_status, void (*sensor_callback)(bhy_data_generic_t *, bhy_virtual_sensor_t));
236 BHY_RETURN_FUNCTION_TYPE bhy_install_timestamp_callback(uint8_t wakeup_status, void (*timestamp_callback)(bhy_data_scalar_u16_t *));
237 BHY_RETURN_FUNCTION_TYPE bhy_install_meta_event_callback(bhy_meta_event_type_t meta_event_id, void (*meta_event_callback)(bhy_data_meta_event_t *, bhy_meta_event_type_t));
238 
239 
240 /* These functions will uninstall the callback and return an error code if */
241 /* there was no callback installed */
242 BHY_RETURN_FUNCTION_TYPE bhy_uninstall_sensor_callback (bhy_virtual_sensor_t sensor_id, uint8_t wakeup_status);
243 BHY_RETURN_FUNCTION_TYPE bhy_uninstall_timestamp_callback (uint8_t wakeup_status );
244 BHY_RETURN_FUNCTION_TYPE bhy_uninstall_meta_event_callback (bhy_meta_event_type_t meta_event_id);
245 
246 #endif
247 
248 #endif /* BHY_UC_DRIVER_H_ */
249 
driver on MCU for bhy
BHY_RETURN_FUNCTION_TYPE bhy_read_parameter_page(uint8_t page, uint8_t parameter, uint8_t *data, uint8_t length)
This function reads arbitrary data from an arbitrary parameter page.
Definition: bhy_uc_driver.c:925
BHY_RETURN_FUNCTION_TYPE bhy_driver_init(const uint8_t *bhy_fw_data)
This function initializes the driver, the API and loads the ram patch into the sensor.
Definition: bhy_uc_driver.c:150
BHY_RETURN_FUNCTION_TYPE bhy_sync_cus_evt_size(void)
This function get all the custom sensor data length according reading information from hub.
Definition: bhy_uc_driver.c:1328
BHY_RETURN_FUNCTION_TYPE bhy_mapping_matrix_set(bhy_physical_sensor_index_type_t index, int8_t *p_mapping_matrix)
This function set mapping matrix to a corresponding physical sensor.
Definition: bhy_uc_driver.c:994
BHY_RETURN_FUNCTION_TYPE bhy_parse_next_fifo_packet(uint8_t **fifo_buffer, uint16_t *fifo_buffer_length, bhy_data_generic_t *fifo_data_output, bhy_data_type_t *fifo_data_type)
this functions parse the packet in fifo and get the actual fifo data of sensors
Definition: bhy_uc_driver.c:425
BHY_RETURN_FUNCTION_TYPE bhy_enable_virtual_sensor(bhy_virtual_sensor_t sensor_id, uint8_t wakeup_status, uint16_t sample_rate, uint16_t max_report_latency_ms, uint8_t flush_sensor, uint16_t change_sensitivity, uint16_t dynamic_range)
this functions enables the selected virtual sensor
Definition: bhy_uc_driver.c:234
BHY_RETURN_FUNCTION_TYPE bhy_get_sic_matrix(float *sic_matrix)
This function reads out the current SIC matrix from BHy.
Definition: bhy_uc_driver.c:1292
BHY_RETURN_FUNCTION_TYPE bhy_meta_event_set_config(bhy_meta_event_type_t meta_event_id, bhy_meta_event_fifo_type_t fifo_sel, uint8_t enable_state, uint8_t int_enable_state)
this function configures meta event
Definition: bhy_uc_driver.c:187
BHY_RETURN_FUNCTION_TYPE bhy_mapping_matrix_get(bhy_physical_sensor_index_type_t index, int8_t *p_mapping_matrix)
This function get mapping matrix from a corresponding physical sensor.
Definition: bhy_uc_driver.c:1073
BHY_RETURN_FUNCTION_TYPE bhy_soft_passthru_write(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t length, uint8_t increment_reg)
Soft pass-through parameter write function.
Definition: bhy_uc_driver.c:1146
BHY_RETURN_FUNCTION_TYPE bhy_meta_event_get_config(bhy_meta_event_type_t meta_event_id, bhy_meta_event_fifo_type_t fifo_sel, uint8_t *p_enable_state, uint8_t *p_int_enable_state)
this function gets configuration from specific meta event
Definition: bhy_uc_driver.c:209
BHY_RETURN_FUNCTION_TYPE bhy_set_sic_matrix(float *sic_matrix)
This function write a new SIC matrix to the BHy.
Definition: bhy_uc_driver.c:1370
BHY_RETURN_FUNCTION_TYPE bhy_gp_register_read(bhy_gp_register_type_t gp_reg, uint8_t *p_data)
Write data to specific GP register.
Definition: bhy_uc_driver.c:1276
BHY_RETURN_FUNCTION_TYPE bhy_read_fifo(uint8_t *buffer, uint16_t buffer_size, uint16_t *bytes_read, uint16_t *bytes_left)
this functions retrieves the fifo data,it needs a buffer of at least (BHY_I2C_REG_BUFFER_LENGTH + 1) ...
Definition: bhy_uc_driver.c:354
int8_t bhy_get_cus_evt_size(bhy_virtual_sensor_t sensor_id)
This function get the specific custom sensor data length according reading information from hub.
Definition: bhy_uc_driver.c:1353
BHY_RETURN_FUNCTION_TYPE bhy_gp_register_write(bhy_gp_register_type_t gp_reg, uint8_t data)
Write data to specific GP register.
Definition: bhy_uc_driver.c:1251
BHY_RETURN_FUNCTION_TYPE bhy_soft_passthru_read(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t length, uint8_t increment_reg)
Soft pass-through parameter read function.
Definition: bhy_uc_driver.c:1190
BHY_RETURN_FUNCTION_TYPE bhy_update_system_timestamp(bhy_data_scalar_u16_t *timestamp_packet, uint32_t *system_timestamp)
This function will detect the timestamp packet accordingly and update either the MSW or the LSW of th...
Definition: bhy_uc_driver.c:815
BHY_RETURN_FUNCTION_TYPE bhy_write_parameter_page(uint8_t page, uint8_t parameter, uint8_t *data, uint8_t length)
This function writes arbitrary data to an arbitrary parameter page.
Definition: bhy_uc_driver.c:854
void bhy_print_debug_packet(bhy_data_debug_t *packet, void(*debug_print_ptr)(const uint8_t *))
This function outputs the debug data to function pointer You need to provide a function that takes as...
Definition: bhy_uc_driver.c:1408
BHY_RETURN_FUNCTION_TYPE bhy_disable_virtual_sensor(bhy_virtual_sensor_t sensor_id, uint8_t wakeup_status)
this functions disables the selected virtual sensor
Definition: bhy_uc_driver.c:303
header file of bhy_uc_driver.c
Definition: bhy_uc_driver_types.h:277
Definition: bhy_uc_driver_types.h:262
Definition: bhy_uc_driver_types.h:232
Definition: bhy_uc_driver_types.h:301