diff --git a/components/drivers/sensors/sensor.c b/components/drivers/sensors/sensor.c index 80c9a60ae0..98a0e8aa74 100644 --- a/components/drivers/sensors/sensor.c +++ b/components/drivers/sensors/sensor.c @@ -51,12 +51,12 @@ void rt_sensor_cb(rt_sensor_t sen) { sen->parent.rx_indicate(&sen->parent, sen->data_len / sizeof(struct rt_sensor_data)); } - else if (sen->config.mode == RT_SEN_MODE_INT) + else if (sen->config.mode == RT_SENSOR_MODE_INT) { /* The interrupt mode only produces one data at a time */ sen->parent.rx_indicate(&sen->parent, 1); } - else if (sen->config.mode == RT_SEN_MODE_FIFO) + else if (sen->config.mode == RT_SENSOR_MODE_FIFO) { sen->parent.rx_indicate(&sen->parent, sen->info.fifo_max); } @@ -164,27 +164,27 @@ static rt_err_t rt_sensor_open(rt_device_t dev, rt_uint16_t oflag) if (oflag & RT_DEVICE_FLAG_RDONLY && dev->flag & RT_DEVICE_FLAG_RDONLY) { /* If polling mode is supported, configure it to polling mode */ - if (sensor->ops->control(sensor, RT_SEN_CTRL_SET_MODE, (void *)RT_SEN_MODE_POLLING) == RT_EOK) + if (sensor->ops->control(sensor, RT_SENSOR_CTRL_SET_MODE, (void *)RT_SENSOR_MODE_POLLING) == RT_EOK) { - sensor->config.mode = RT_SEN_MODE_POLLING; + sensor->config.mode = RT_SENSOR_MODE_POLLING; } } else if (oflag & RT_DEVICE_FLAG_INT_RX && dev->flag & RT_DEVICE_FLAG_INT_RX) { /* If interrupt mode is supported, configure it to interrupt mode */ - if (sensor->ops->control(sensor, RT_SEN_CTRL_SET_MODE, (void *)RT_SEN_MODE_INT) == RT_EOK) + if (sensor->ops->control(sensor, RT_SENSOR_CTRL_SET_MODE, (void *)RT_SENSOR_MODE_INT) == RT_EOK) { - sensor->config.mode = RT_SEN_MODE_INT; + sensor->config.mode = RT_SENSOR_MODE_INT; /* Initialization sensor interrupt */ rt_sensor_irq_init(sensor); } } - else if (oflag & RT_SEN_FLAG_FIFO && dev->flag & RT_SEN_FLAG_FIFO) + else if (oflag & RT_SENSOR_FLAG_FIFO && dev->flag & RT_SENSOR_FLAG_FIFO) { /* If fifo mode is supported, configure it to fifo mode */ - if (sensor->ops->control(sensor, RT_SEN_CTRL_SET_MODE, (void *)RT_SEN_MODE_FIFO) == RT_EOK) + if (sensor->ops->control(sensor, RT_SENSOR_CTRL_SET_MODE, (void *)RT_SENSOR_MODE_FIFO) == RT_EOK) { - sensor->config.mode = RT_SEN_MODE_FIFO; + sensor->config.mode = RT_SENSOR_MODE_FIFO; /* Initialization sensor interrupt */ rt_sensor_irq_init(sensor); } @@ -195,9 +195,9 @@ static rt_err_t rt_sensor_open(rt_device_t dev, rt_uint16_t oflag) } /* Configure power mode to normal mode */ - if (sensor->ops->control(sensor, RT_SEN_CTRL_SET_POWER, (void *)RT_SEN_POWER_NORMAL) == RT_EOK) + if (sensor->ops->control(sensor, RT_SENSOR_CTRL_SET_POWER, (void *)RT_SENSOR_POWER_NORMAL) == RT_EOK) { - sensor->config.power = RT_SEN_POWER_NORMAL; + sensor->config.power = RT_SENSOR_POWER_NORMAL; } if (sensor->module) @@ -220,9 +220,9 @@ static rt_err_t rt_sensor_close(rt_device_t dev) } /* Configure power mode to power down mode */ - if (sensor->ops->control(sensor, RT_SEN_CTRL_SET_POWER, (void *)RT_SEN_POWER_DOWN) == RT_EOK) + if (sensor->ops->control(sensor, RT_SENSOR_CTRL_SET_POWER, (void *)RT_SENSOR_POWER_DOWN) == RT_EOK) { - sensor->config.power = RT_SEN_POWER_DOWN; + sensor->config.power = RT_SENSOR_POWER_DOWN; } /* Sensor disable interrupt */ @@ -293,71 +293,71 @@ static rt_err_t rt_sensor_control(rt_device_t dev, int cmd, void *args) switch (cmd) { - case RT_SEN_CTRL_GET_ID: + case RT_SENSOR_CTRL_GET_ID: if (args) { - sensor->ops->control(sensor, RT_SEN_CTRL_GET_ID, args); + sensor->ops->control(sensor, RT_SENSOR_CTRL_GET_ID, args); } break; - case RT_SEN_CTRL_GET_INFO: + case RT_SENSOR_CTRL_GET_INFO: if (args) { rt_memcpy(args, &sensor->info, sizeof(struct rt_sensor_info)); } break; - case RT_SEN_CTRL_SET_RANGE: + case RT_SENSOR_CTRL_SET_RANGE: /* Configuration measurement range */ - result = sensor->ops->control(sensor, RT_SEN_CTRL_SET_RANGE, args); + result = sensor->ops->control(sensor, RT_SENSOR_CTRL_SET_RANGE, args); if (result == RT_EOK) { sensor->config.range = (rt_int32_t)args; LOG_D("set range %d", sensor->config.range); } break; - case RT_SEN_CTRL_SET_ODR: + case RT_SENSOR_CTRL_SET_ODR: /* Configuration data output rate */ - result = sensor->ops->control(sensor, RT_SEN_CTRL_SET_ODR, args); + result = sensor->ops->control(sensor, RT_SENSOR_CTRL_SET_ODR, args); if (result == RT_EOK) { sensor->config.odr = (rt_uint32_t)args & 0xFFFF; LOG_D("set odr %d", sensor->config.odr); } break; - case RT_SEN_CTRL_SET_MODE: + case RT_SENSOR_CTRL_SET_MODE: /* Configuration sensor work mode */ - result = sensor->ops->control(sensor, RT_SEN_CTRL_SET_MODE, args); + result = sensor->ops->control(sensor, RT_SENSOR_CTRL_SET_MODE, args); if (result == RT_EOK) { sensor->config.mode = (rt_uint32_t)args & 0xFF; LOG_D("set work mode code:", sensor->config.mode); - if (sensor->config.mode == RT_SEN_MODE_POLLING) + if (sensor->config.mode == RT_SENSOR_MODE_POLLING) { rt_sensor_irq_disable(sensor); } - else if (sensor->config.mode == RT_SEN_MODE_INT || sensor->config.mode == RT_SEN_MODE_FIFO) + else if (sensor->config.mode == RT_SENSOR_MODE_INT || sensor->config.mode == RT_SENSOR_MODE_FIFO) { rt_sensor_irq_enable(sensor); } } break; - case RT_SEN_CTRL_SET_POWER: + case RT_SENSOR_CTRL_SET_POWER: /* Configuration sensor power mode */ - result = sensor->ops->control(sensor, RT_SEN_CTRL_SET_POWER, args); + result = sensor->ops->control(sensor, RT_SENSOR_CTRL_SET_POWER, args); if (result == RT_EOK) { sensor->config.power = (rt_uint32_t)args & 0xFF; LOG_D("set power mode code:", sensor->config.power); } break; - case RT_SEN_CTRL_SELF_TEST: + case RT_SENSOR_CTRL_SELF_TEST: /* Device self-test */ - result = sensor->ops->control(sensor, RT_SEN_CTRL_SELF_TEST, args); + result = sensor->ops->control(sensor, RT_SENSOR_CTRL_SELF_TEST, args); break; default: return -RT_ERROR; diff --git a/components/drivers/sensors/sensor.h b/components/drivers/sensors/sensor.h index 75011a6db2..f6afdb6dbb 100644 --- a/components/drivers/sensors/sensor.h +++ b/components/drivers/sensors/sensor.h @@ -19,86 +19,86 @@ extern "C" { #endif #ifdef RT_USING_RTC -#define rt_sen_get_timestamp() time() /* API for the sensor to get the timestamp */ +#define rt_sensor_get_ts() time() /* API for the sensor to get the timestamp */ #else -#define rt_sen_get_timestamp() rt_tick_get() /* API for the sensor to get the timestamp */ +#define rt_sensor_get_ts() rt_tick_get() /* API for the sensor to get the timestamp */ #endif #define RT_PIN_NONE 0xFFFF /* RT PIN NONE */ -#define RT_SEN_FLAG_FIFO 0x200 /* Flag to use when the sensor is open by fifo mode */ +#define RT_SENSOR_FLAG_FIFO 0x200 /* Flag to use when the sensor is open by fifo mode */ -#define RT_SEN_MODULE_MAX (3) /* The maximum number of members of a sensor module */ +#define RT_SENSOR_MODULE_MAX (3) /* The maximum number of members of a sensor module */ /* Sensor types */ -#define RT_SEN_CLASS_NONE (0) -#define RT_SEN_CLASS_ACCE (1) /* Accelerometer */ -#define RT_SEN_CLASS_GYRO (2) /* Gyroscope */ -#define RT_SEN_CLASS_MAG (3) /* Magnetometer */ -#define RT_SEN_CLASS_TEMP (4) /* Temperature */ -#define RT_SEN_CLASS_HUMI (5) /* Relative Humidity */ -#define RT_SEN_CLASS_BARO (6) /* Barometer */ -#define RT_SEN_CLASS_LIGHT (7) /* Ambient light */ -#define RT_SEN_CLASS_PROXIMITY (8) /* Proximity */ -#define RT_SEN_CLASS_HR (9) /* Heart Rate */ -#define RT_SEN_CLASS_TVOC (10) /* TVOC Level */ -#define RT_SEN_CLASS_NOISE (11) /* Noise Loudness */ -#define RT_SEN_CLASS_STEP (12) /* Step sensor */ +#define RT_SENSOR_CLASS_NONE (0) +#define RT_SENSOR_CLASS_ACCE (1) /* Accelerometer */ +#define RT_SENSOR_CLASS_GYRO (2) /* Gyroscope */ +#define RT_SENSOR_CLASS_MAG (3) /* Magnetometer */ +#define RT_SENSOR_CLASS_TEMP (4) /* Temperature */ +#define RT_SENSOR_CLASS_HUMI (5) /* Relative Humidity */ +#define RT_SENSOR_CLASS_BARO (6) /* Barometer */ +#define RT_SENSOR_CLASS_LIGHT (7) /* Ambient light */ +#define RT_SENSOR_CLASS_PROXIMITY (8) /* Proximity */ +#define RT_SENSOR_CLASS_HR (9) /* Heart Rate */ +#define RT_SENSOR_CLASS_TVOC (10) /* TVOC Level */ +#define RT_SENSOR_CLASS_NOISE (11) /* Noise Loudness */ +#define RT_SENSOR_CLASS_STEP (12) /* Step sensor */ /* Sensor vendor types */ -#define RT_SEN_VENDOR_UNKNOWN (0) -#define RT_SEN_VENDOR_STM (1) /* STMicroelectronics */ -#define RT_SEN_VENDOR_BOSCH (2) /* Bosch */ -#define RT_SEN_VENDOR_INVENSENSE (3) /* Invensense */ -#define RT_SEN_VENDOR_SEMTECH (4) /* Semtech */ -#define RT_SEN_VENDOR_GOERTEK (5) /* Goertek */ +#define RT_SENSOR_VENDOR_UNKNOWN (0) +#define RT_SENSOR_VENDOR_STM (1) /* STMicroelectronics */ +#define RT_SENSOR_VENDOR_BOSCH (2) /* Bosch */ +#define RT_SENSOR_VENDOR_INVENSENSE (3) /* Invensense */ +#define RT_SENSOR_VENDOR_SEMTECH (4) /* Semtech */ +#define RT_SENSOR_VENDOR_GOERTEK (5) /* Goertek */ /* Sensor unit types */ -#define RT_SEN_UNIT_NONE (0) -#define RT_SEN_UNIT_MG (1) /* Accelerometer unit: mG */ -#define RT_SEN_UNIT_MDPS (2) /* Gyroscope unit: mdps */ -#define RT_SEN_UNIT_MGAUSS (3) /* Magnetometer unit: mGauss */ -#define RT_SEN_UNIT_LUX (4) /* Ambient light unit: lux */ -#define RT_SEN_UNIT_CM (5) /* Distance unit: cm */ -#define RT_SEN_UNIT_PA (6) /* Barometer unit: pa */ -#define RT_SEN_UNIT_PERMILLAGE (7) /* Relative Humidity unit: permillage */ -#define RT_SEN_UNIT_DCELSIUS (8) /* Temperature unit: dCelsius */ -#define RT_SEN_UNIT_HZ (9) /* Frequency unit: HZ */ -#define RT_SEN_UNIT_ONE (10) /* Dimensionless quantity unit: 1 */ +#define RT_SENSOR_UNIT_NONE (0) +#define RT_SENSOR_UNIT_MG (1) /* Accelerometer unit: mG */ +#define RT_SENSOR_UNIT_MDPS (2) /* Gyroscope unit: mdps */ +#define RT_SENSOR_UNIT_MGAUSS (3) /* Magnetometer unit: mGauss */ +#define RT_SENSOR_UNIT_LUX (4) /* Ambient light unit: lux */ +#define RT_SENSOR_UNIT_CM (5) /* Distance unit: cm */ +#define RT_SENSOR_UNIT_PA (6) /* Barometer unit: pa */ +#define RT_SENSOR_UNIT_PERMILLAGE (7) /* Relative Humidity unit: permillage */ +#define RT_SENSOR_UNIT_DCELSIUS (8) /* Temperature unit: dCelsius */ +#define RT_SENSOR_UNIT_HZ (9) /* Frequency unit: HZ */ +#define RT_SENSOR_UNIT_ONE (10) /* Dimensionless quantity unit: 1 */ /* Sensor communication interface types */ -#define RT_SEN_INTF_I2C (1 << 0) -#define RT_SEN_INTF_SPI (1 << 1) -#define RT_SEN_INTF_UART (1 << 2) -#define RT_SEN_INTF_ONEWIRE (1 << 3) +#define RT_SENSOR_INTF_I2C (1 << 0) +#define RT_SENSOR_INTF_SPI (1 << 1) +#define RT_SENSOR_INTF_UART (1 << 2) +#define RT_SENSOR_INTF_ONEWIRE (1 << 3) /* Sensor power mode types */ -#define RT_SEN_POWER_NONE (0) -#define RT_SEN_POWER_DOWN (1) /* power down mode */ -#define RT_SEN_POWER_NORMAL (2) /* normal-power mode */ -#define RT_SEN_POWER_LOW (3) /* low-power mode */ -#define RT_SEN_POWER_HIGH (4) /* high-power mode */ +#define RT_SENSOR_POWER_NONE (0) +#define RT_SENSOR_POWER_DOWN (1) /* power down mode */ +#define RT_SENSOR_POWER_NORMAL (2) /* normal-power mode */ +#define RT_SENSOR_POWER_LOW (3) /* low-power mode */ +#define RT_SENSOR_POWER_HIGH (4) /* high-power mode */ /* Sensor work mode types */ -#define RT_SEN_MODE_NONE (0) -#define RT_SEN_MODE_POLLING (1) /* One shot only read a data */ -#define RT_SEN_MODE_INT (2) /* TODO: One shot interrupt only read a data */ -#define RT_SEN_MODE_FIFO (3) /* TODO: One shot interrupt read all fifo data */ +#define RT_SENSOR_MODE_NONE (0) +#define RT_SENSOR_MODE_POLLING (1) /* One shot only read a data */ +#define RT_SENSOR_MODE_INT (2) /* TODO: One shot interrupt only read a data */ +#define RT_SENSOR_MODE_FIFO (3) /* TODO: One shot interrupt read all fifo data */ /* Sensor control cmd types */ -#define RT_SEN_CTRL_GET_ID (0) /* Get device id */ -#define RT_SEN_CTRL_GET_INFO (1) /* Get sensor info */ -#define RT_SEN_CTRL_SET_RANGE (2) /* Set the measure range of sensor. unit is info of sensor */ -#define RT_SEN_CTRL_SET_ODR (3) /* Set output date rate. unit is HZ */ -#define RT_SEN_CTRL_SET_MODE (4) /* Set sensor's work mode. ex. RT_SEN_MODE_POLLING,RT_SEN_MODE_INT */ -#define RT_SEN_CTRL_SET_POWER (5) /* Set power mode. args type of sensor power mode. ex. RT_SEN_POWER_DOWN,RT_SEN_POWER_NORMAL */ -#define RT_SEN_CTRL_SELF_TEST (6) /* Take a self test */ +#define RT_SENSOR_CTRL_GET_ID (0) /* Get device id */ +#define RT_SENSOR_CTRL_GET_INFO (1) /* Get sensor info */ +#define RT_SENSOR_CTRL_SET_RANGE (2) /* Set the measure range of sensor. unit is info of sensor */ +#define RT_SENSOR_CTRL_SET_ODR (3) /* Set output date rate. unit is HZ */ +#define RT_SENSOR_CTRL_SET_MODE (4) /* Set sensor's work mode. ex. RT_SENSOR_MODE_POLLING,RT_SENSOR_MODE_INT */ +#define RT_SENSOR_CTRL_SET_POWER (5) /* Set power mode. args type of sensor power mode. ex. RT_SENSOR_POWER_DOWN,RT_SENSOR_POWER_NORMAL */ +#define RT_SENSOR_CTRL_SELF_TEST (6) /* Take a self test */ struct rt_sensor_info { @@ -148,10 +148,10 @@ typedef struct rt_sensor_device *rt_sensor_t; struct rt_sensor_module { - rt_mutex_t lock; /* The module lock */ + rt_mutex_t lock; /* The module lock */ - rt_sensor_t sen[RT_SEN_MODULE_MAX]; /* The module contains a list of sensors */ - rt_uint8_t sen_num; /* Number of sensors contained in the module */ + rt_sensor_t sen[RT_SENSOR_MODULE_MAX]; /* The module contains a list of sensors */ + rt_uint8_t sen_num; /* Number of sensors contained in the module */ }; /* 3-axis Data Type */ diff --git a/components/drivers/sensors/sensor_test.c b/components/drivers/sensors/sensor_test.c index 0221167e83..4b7fea2d03 100644 --- a/components/drivers/sensors/sensor_test.c +++ b/components/drivers/sensors/sensor_test.c @@ -25,25 +25,25 @@ static void sensor_show_data(rt_size_t num, rt_sensor_t sensor, struct rt_sensor { switch (sensor->info.type) { - case RT_SEN_CLASS_ACCE: + case RT_SENSOR_CLASS_ACCE: LOG_I("num:%3d, x:%5d, y:%5d, z:%5d, timestamp:%5d", num, sensor_data->data.acce.x, sensor_data->data.acce.y, sensor_data->data.acce.z, sensor_data->timestamp); break; - case RT_SEN_CLASS_GYRO: + case RT_SENSOR_CLASS_GYRO: LOG_I("num:%3d, x:%8d, y:%8d, z:%8d, timestamp:%5d", num, sensor_data->data.gyro.x, sensor_data->data.gyro.y, sensor_data->data.gyro.z, sensor_data->timestamp); break; - case RT_SEN_CLASS_MAG: + case RT_SENSOR_CLASS_MAG: LOG_I("num:%3d, x:%5d, y:%5d, z:%5d, timestamp:%5d", num, sensor_data->data.mag.x, sensor_data->data.mag.y, sensor_data->data.mag.z, sensor_data->timestamp); break; - case RT_SEN_CLASS_HUMI: + case RT_SENSOR_CLASS_HUMI: LOG_I("num:%3d, humi:%3d.%d%%, timestamp:%5d", num, sensor_data->data.humi / 10, sensor_data->data.humi % 10, sensor_data->timestamp); break; - case RT_SEN_CLASS_TEMP: + case RT_SENSOR_CLASS_TEMP: LOG_I("num:%3d, temp:%3d.%dC, timestamp:%5d", num, sensor_data->data.temp / 10, sensor_data->data.temp % 10, sensor_data->timestamp); break; - case RT_SEN_CLASS_BARO: + case RT_SENSOR_CLASS_BARO: LOG_I("num:%3d, press:%5d, timestamp:%5d", num, sensor_data->data.baro, sensor_data->timestamp); break; - case RT_SEN_CLASS_STEP: + case RT_SENSOR_CLASS_STEP: LOG_I("num:%3d, step:%5d, timestamp:%5d", num, sensor_data->data.step, sensor_data->timestamp); break; default: @@ -65,7 +65,7 @@ static void sensor_fifo_rx_entry(void *parameter) struct rt_sensor_info info; rt_size_t res, i; - rt_device_control(dev, RT_SEN_CTRL_GET_INFO, &info); + rt_device_control(dev, RT_SENSOR_CTRL_GET_INFO, &info); data = rt_malloc(sizeof(struct rt_sensor_data) * info.fifo_max); if (data == RT_NULL) @@ -119,12 +119,12 @@ static void sensor_fifo(int argc, char **argv) rt_device_set_rx_indicate(dev, rx_callback); - if (rt_device_open(dev, RT_SEN_FLAG_FIFO) != RT_EOK) + if (rt_device_open(dev, RT_SENSOR_FLAG_FIFO) != RT_EOK) { LOG_E("open device failed!"); return; } - rt_device_control(dev, RT_SEN_CTRL_SET_ODR, (void *)20); + rt_device_control(dev, RT_SENSOR_CTRL_SET_ODR, (void *)20); } #ifdef FINSH_USING_MSH MSH_CMD_EXPORT(sensor_fifo, Sensor fifo mode test function); @@ -188,7 +188,7 @@ static void sensor_int(int argc, char **argv) LOG_E("open device failed!"); return; } - rt_device_control(dev, RT_SEN_CTRL_SET_ODR, (void *)20); + rt_device_control(dev, RT_SENSOR_CTRL_SET_ODR, (void *)20); } #ifdef FINSH_USING_MSH MSH_CMD_EXPORT(sensor_int, Sensor interrupt mode test function); @@ -218,7 +218,7 @@ static void sensor_polling(int argc, char **argv) LOG_E("open device failed!"); return; } - rt_device_control(dev, RT_SEN_CTRL_SET_ODR, (void *)100); + rt_device_control(dev, RT_SENSOR_CTRL_SET_ODR, (void *)100); for (i = 0; i < num; i++) { @@ -263,7 +263,7 @@ static void sensor(int argc, char **argv) else if (!strcmp(argv[1], "info")) { struct rt_sensor_info info; - rt_device_control(dev, RT_SEN_CTRL_GET_INFO, &info); + rt_device_control(dev, RT_SENSOR_CTRL_GET_INFO, &info); rt_kprintf("vendor :%d\n", info.vendor); rt_kprintf("model :%s\n", info.model); rt_kprintf("unit :%d\n", info.unit); @@ -321,7 +321,7 @@ static void sensor(int argc, char **argv) LOG_E("open device failed!"); return; } - rt_device_control(dev, RT_SEN_CTRL_GET_ID, ®); + rt_device_control(dev, RT_SENSOR_CTRL_GET_ID, ®); LOG_I("device id: 0x%x!", reg); } @@ -332,19 +332,19 @@ static void sensor(int argc, char **argv) } else if (!strcmp(argv[1], "sr")) { - rt_device_control(dev, RT_SEN_CTRL_SET_RANGE, (void *)atoi(argv[2])); + rt_device_control(dev, RT_SENSOR_CTRL_SET_RANGE, (void *)atoi(argv[2])); } else if (!strcmp(argv[1], "sm")) { - rt_device_control(dev, RT_SEN_CTRL_SET_MODE, (void *)atoi(argv[2])); + rt_device_control(dev, RT_SENSOR_CTRL_SET_MODE, (void *)atoi(argv[2])); } else if (!strcmp(argv[1], "sp")) { - rt_device_control(dev, RT_SEN_CTRL_SET_POWER, (void *)atoi(argv[2])); + rt_device_control(dev, RT_SENSOR_CTRL_SET_POWER, (void *)atoi(argv[2])); } else if (!strcmp(argv[1], "sodr")) { - rt_device_control(dev, RT_SEN_CTRL_SET_ODR, (void *)atoi(argv[2])); + rt_device_control(dev, RT_SENSOR_CTRL_SET_ODR, (void *)atoi(argv[2])); } else {