improve sensor framework (#6784)
* [stm32l475-pandora] rename sensor_port.c as drv_sensors.c * [sensor][cmd] add enter critical section protection * [sensor] add sensor reset command
This commit is contained in:
parent
7450ef6c4d
commit
f4b285dc9c
|
@ -27,8 +27,8 @@ if GetDepend(['BSP_USING_FS']):
|
|||
src += Glob('ports/fal/fal_spi_flash_sfud_port.c')
|
||||
path += [cwd + '/ports/fal']
|
||||
|
||||
if GetDepend(['BSP_USING_ICM20608']) or GetDepend(['BSP_USING_AHT10']):
|
||||
src += Glob('ports/sensor_port.c')
|
||||
if GetDepend(['RT_USING_SENSOR']):
|
||||
src += Glob('ports/drv_sensors.c')
|
||||
|
||||
if GetDepend(['BSP_USING_AUDIO']):
|
||||
src += Glob('ports/audio/drv_es8388.c')
|
||||
|
|
|
@ -228,8 +228,8 @@ __exit:
|
|||
static rt_err_t _sensor_close(rt_device_t dev)
|
||||
{
|
||||
rt_sensor_t sensor = (rt_sensor_t)dev;
|
||||
int i;
|
||||
rt_err_t (*local_ctrl)(rt_sensor_t sensor, int cmd, void *arg) = _local_control;
|
||||
int i;
|
||||
|
||||
RT_ASSERT(dev != RT_NULL);
|
||||
|
||||
|
@ -517,10 +517,5 @@ int rt_hw_sensor_register(rt_sensor_t sensor,
|
|||
LOG_I("sensor[%s] init success", device_name);
|
||||
rt_free(device_name);
|
||||
|
||||
/* set sensor accuracy and power as the hightest, and polling data as default */
|
||||
rt_device_control(device, RT_SENSOR_CTRL_SET_ACCURACY_MODE, RT_SENSOR_MODE_ACCURACY_HIGHEST);
|
||||
rt_device_control(device, RT_SENSOR_CTRL_SET_POWER_MODE, RT_SENSOR_MODE_POWER_HIGHEST);
|
||||
rt_device_control(device, RT_SENSOR_CTRL_SET_FETCH_MODE, RT_SENSOR_MODE_FETCH_POLLING);
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
|
|
@ -542,6 +542,7 @@ static void sensor_cmd_warning_unknown(void)
|
|||
rt_kprintf(" power [mode] set or get power mode\n");
|
||||
rt_kprintf(" accuracy [mode] set or get accuracy mode\n");
|
||||
rt_kprintf(" fetch [mode] set or get fetch data mode\n");
|
||||
rt_kprintf(" reset reset sensor chip\n");
|
||||
}
|
||||
|
||||
static void sensor_cmd_warning_probe(void)
|
||||
|
@ -649,6 +650,19 @@ static void sensor(int argc, char **argv)
|
|||
2, sensor_dev->info.scale.range_min, 2, sensor_dev->info.scale.range_max, 5, sensor_get_unit_name(&sensor_dev->info));
|
||||
}
|
||||
}
|
||||
else if (!rt_strcmp(argv[1], "reset"))
|
||||
{
|
||||
if (dev == RT_NULL)
|
||||
{
|
||||
sensor_cmd_warning_probe();
|
||||
return;
|
||||
}
|
||||
|
||||
if (rt_device_control(dev, RT_SENSOR_CTRL_SOFT_RESET, RT_NULL) != RT_EOK)
|
||||
{
|
||||
LOG_E("This sensor doesn't support this command!");
|
||||
}
|
||||
}
|
||||
else if (!rt_strcmp(argv[1], "probe"))
|
||||
{
|
||||
rt_uint8_t reg = 0xFF;
|
||||
|
|
Loading…
Reference in New Issue