The sensor driver interface facilitates the physical sensor driver porting.
More...
The sensor driver interface facilitates the physical sensor driver porting.
Developers can easily enable/operate different physical sensors, such as accelerometer, gyroscope, and more using the interface APIs. An example to port the accelerometer driver is described below.
- Step 1. Configure GPIO pins for sensor hardware connection. For more information, please refer to [sdk_root]/project/mt2523_sdk/apps/sensor_subsys_accelerometer/inc/ept_gpio_drv.h and bsp_sensor_peripheral_init in [sdk_root]/driver/board/mt25x3_hdk/mems_init/mems_init.c.
- Step 2. Prepare the sensor_driver_object_t for this sensor driver.
- Step 3. Call sensor_driver_attach() to register this sensor driver in the initialization function (bma255_sensor_subsys_init(), please refer to [sdk_root]/driver/board/component/mems/src/bma255_sensor_adaptor.c).
- Step 4. Call the initialization function (bma255_sensor_subsys_init()) in bsp_sensor_peripheral_init().
- Sample code:
int32_t bma_acc_operate(void *self, uint32_t command, void *buff_out, int32_t size_out, int32_t *actual_out,
void *buff_in, int32_t size_in)
{
int err = 0;
int32_t value = 0;
switch (command) {
break;
break;
break;
break;
default:
break;
}
return err;
}
BMA2x2_RETURN_FUNCTION_TYPE bma255_sensor_subsys_init()
{
BMA2x2_RETURN_FUNCTION_TYPE err = ERROR;
err = bma255_init();
obj_acc.
self = (
void *)&obj_acc;
return err;
}
void bsp_sensor_peripheral_init()
{
bma255_sensor_subsys_init();
}
| #define SENSOR_BATCH 0x10 |
Command of setting the batch timeout to a physical sensor driver.
Command of setting the customization to a physical sensor driver.
| #define SENSOR_DEFAULT_DELAY (200) |
Default delay between two consecutive sensor events in ms.
| #define SENSOR_DELAY 0x01 |
Command of setting a delay to a physical sensor driver.
| #define SENSOR_ENABLE 0x02 |
Command of enabling/disabling a physical sensor driver.
| #define SENSOR_GET_DATA 0x04 |
Command of getting data from a physical sensor driver.
Registers the physical sensor driver.
- Parameters
-
| [in] | sensor_type | is the specified sensor type. |
| [in] | obj | is of type sensor_driver_object_t for the registration. |
- Returns
- >=0, if the operation completed successfully.