diff --git a/APP_Framework/Applications/sensor_app/humidity_hs300x.c b/APP_Framework/Applications/sensor_app/humidity_hs300x.c index be3ab441..451d2c3c 100644 --- a/APP_Framework/Applications/sensor_app/humidity_hs300x.c +++ b/APP_Framework/Applications/sensor_app/humidity_hs300x.c @@ -27,9 +27,14 @@ */ void HumiHs300x(void) { + int i = 0; + int32 humidity; struct SensorQuantity *humi = SensorQuantityFind(SENSOR_QUANTITY_HS300X_HUMIDITY, SENSOR_QUANTITY_HUMI); SensorQuantityOpen(humi); - int32 humidity = SensorQuantityRead(humi); - printf("Humidity : %d.%d %%RH\n", humidity/10, humidity%10); + for (i = 0; i < 100; i ++) { + humidity = SensorQuantityRead(humi); + printf("Humidity : %d.%d %%RH\n", humidity/10, humidity%10); + PrivTaskDelay(5000); + } SensorQuantityClose(humi); } \ No newline at end of file diff --git a/APP_Framework/Applications/sensor_app/temperature_hs300x.c b/APP_Framework/Applications/sensor_app/temperature_hs300x.c index 0730fdfb..c945040e 100644 --- a/APP_Framework/Applications/sensor_app/temperature_hs300x.c +++ b/APP_Framework/Applications/sensor_app/temperature_hs300x.c @@ -27,12 +27,20 @@ */ void TempHs300x(void) { + int i = 0; + int32 temperature; struct SensorQuantity *temp = SensorQuantityFind(SENSOR_QUANTITY_HS300X_TEMPERATURE, SENSOR_QUANTITY_TEMP); SensorQuantityOpen(temp); - int32 temperature = SensorQuantityRead(temp); - if (temperature > 0) - printf("Temperature : %d.%d ℃\n", temperature/10, temperature%10); - else - printf("Temperature : %d.%d ℃\n", temperature/10, -temperature%10); + for (i = 0; i < 100; i ++) { + temperature = SensorQuantityRead(temp); + if (temperature > 0) + printf("Temperature : %d.%d ℃\n", temperature/10, temperature%10); + else + printf("Temperature : %d.%d ℃\n", temperature/10, -temperature%10); + + PrivTaskDelay(5000); + } + SensorQuantityClose(temp); -} \ No newline at end of file +} +SHELL_EXPORT_CMD(SHELL_CMD_PERMISSION(0)|SHELL_CMD_TYPE(SHELL_TYPE_CMD_FUNC)|SHELL_CMD_PARAM_NUM(0)|SHELL_CMD_DISABLE_RETURN, TempHs300x, TempHs300x, TempHs300x function); diff --git a/APP_Framework/Framework/connection/4g/ec200t/ec200t.c b/APP_Framework/Framework/connection/4g/ec200t/ec200t.c index bfd2f89b..5ba720ed 100644 --- a/APP_Framework/Framework/connection/4g/ec200t/ec200t.c +++ b/APP_Framework/Framework/connection/4g/ec200t/ec200t.c @@ -40,6 +40,10 @@ static void Ec200tPowerSet(void) { int pin_fd; pin_fd = PrivOpen(ADAPTER_EC200T_PIN_DRIVER, O_RDWR); + if (pin_fd < 0) { + printf("open %s error\n", ADAPTER_EC200T_PIN_DRIVER); + return; + } struct PinParam pin_param; pin_param.cmd = GPIO_CONFIG_MODE; diff --git a/APP_Framework/Framework/sensor/co2/zg09/zg09.c b/APP_Framework/Framework/sensor/co2/zg09/zg09.c index c5ab95e0..d4d626d7 100644 --- a/APP_Framework/Framework/sensor/co2/zg09/zg09.c +++ b/APP_Framework/Framework/sensor/co2/zg09/zg09.c @@ -43,6 +43,10 @@ static int SensorDeviceOpen(struct SensorDevice *sdev) int result = 0; sdev->fd = PrivOpen(SENSOR_DEVICE_ZG09_DEV, O_RDWR); + if (sdev->fd < 0) { + printf("open %s error\n", SENSOR_DEVICE_ZG09_DEV); + return -1; + } struct SerialDataCfg cfg; cfg.serial_baud_rate = BAUD_RATE_9600; diff --git a/APP_Framework/Framework/sensor/humidity/Kconfig b/APP_Framework/Framework/sensor/humidity/Kconfig index 91011a9c..624edf34 100644 --- a/APP_Framework/Framework/sensor/humidity/Kconfig +++ b/APP_Framework/Framework/sensor/humidity/Kconfig @@ -16,6 +16,10 @@ config SENSOR_HS300X config SENSOR_DEVICE_HS300X_DEV string "HS300x device name" default "/dev/i2c1_dev0" + + config SENSOR_DEVICE_HS300X_I2C_ADDR + hex "HS300x device i2c address" + default 0x44 endif if ADD_NUTTX_FETURES diff --git a/APP_Framework/Framework/sensor/humidity/hs300x_humi/hs300x_humi.c b/APP_Framework/Framework/sensor/humidity/hs300x_humi/hs300x_humi.c index 7779db35..880ccaf1 100644 --- a/APP_Framework/Framework/sensor/humidity/hs300x_humi/hs300x_humi.c +++ b/APP_Framework/Framework/sensor/humidity/hs300x_humi/hs300x_humi.c @@ -32,28 +32,43 @@ static struct SensorProductInfo info = /** * @description: Open HS300x sensor device * @param sdev - sensor device pointer - * @return 1 + * @return success : 0 error : -1 */ static int SensorDeviceOpen(struct SensorDevice *sdev) { + int result; + uint16_t i2c_dev_addr = SENSOR_DEVICE_HS300X_I2C_ADDR; + sdev->fd = PrivOpen(SENSOR_DEVICE_HS300X_DEV, O_RDWR); - return 0; + if (sdev->fd < 0) { + printf("open %s error\n", SENSOR_DEVICE_HS300X_DEV); + return -1; + } + + struct PrivIoctlCfg ioctl_cfg; + ioctl_cfg.ioctl_driver_type = I2C_TYPE; + ioctl_cfg.args = &i2c_dev_addr; + result = PrivIoctl(sdev->fd, OPE_INT, &ioctl_cfg); + + return result; } /** * @description: Read sensor device * @param sdev - sensor device pointer * @param len - the length of the read data - * @return success: 1 , failure: -1 + * @return success: 0 , failure: -1 */ static int SensorDeviceRead(struct SensorDevice *sdev, size_t len) { + //send i2c device start signal and address, need to implemente in OS i2c driver if (PrivWrite(sdev->fd, NULL, 0) != 1) return -1; PrivTaskDelay(50); + //Read i2c device data from i2c device address if (PrivRead(sdev->fd, sdev->buffer, len) != 1) return -1; diff --git a/APP_Framework/Framework/sensor/pm/ps5308/ps5308.c b/APP_Framework/Framework/sensor/pm/ps5308/ps5308.c index 126eb082..f287d97d 100644 --- a/APP_Framework/Framework/sensor/pm/ps5308/ps5308.c +++ b/APP_Framework/Framework/sensor/pm/ps5308/ps5308.c @@ -58,6 +58,10 @@ static int SensorDeviceOpen(struct SensorDevice *sdev) PrivMutexCreate(&buff_lock, 0); sdev->fd = open(SENSOR_DEVICE_PS5308_DEV, O_RDWR); + if (sdev->fd < 0) { + printf("open %s error\n", SENSOR_DEVICE_PS5308_DEV); + return -1; + } struct SerialDataCfg cfg; cfg.serial_baud_rate = BAUD_RATE_9600; diff --git a/APP_Framework/Framework/sensor/temperature/Kconfig b/APP_Framework/Framework/sensor/temperature/Kconfig index 2815c03e..0817643e 100644 --- a/APP_Framework/Framework/sensor/temperature/Kconfig +++ b/APP_Framework/Framework/sensor/temperature/Kconfig @@ -16,6 +16,10 @@ config SENSOR_HS300X config SENSOR_DEVICE_HS300X_DEV string "HS300x device name" default "/dev/i2c1_dev0" + + config SENSOR_DEVICE_HS300X_I2C_ADDR + hex "HS300x device i2c address" + default 0x44 endif if ADD_NUTTX_FETURES diff --git a/APP_Framework/Framework/sensor/temperature/hs300x_temp/hs300x_temp.c b/APP_Framework/Framework/sensor/temperature/hs300x_temp/hs300x_temp.c index f2b2d1e3..7ffb4347 100644 --- a/APP_Framework/Framework/sensor/temperature/hs300x_temp/hs300x_temp.c +++ b/APP_Framework/Framework/sensor/temperature/hs300x_temp/hs300x_temp.c @@ -32,28 +32,42 @@ static struct SensorProductInfo info = /** * @description: Open HS300x sensor device * @param sdev - sensor device pointer - * @return 1 + * @return success : 0 error : -1 */ static int SensorDeviceOpen(struct SensorDevice *sdev) { + int result; + uint16_t i2c_dev_addr = SENSOR_DEVICE_HS300X_I2C_ADDR; + sdev->fd = PrivOpen(SENSOR_DEVICE_HS300X_DEV, O_RDWR); + if (sdev->fd < 0) { + printf("open %s error\n", SENSOR_DEVICE_HS300X_DEV); + return -1; + } - return 0; + struct PrivIoctlCfg ioctl_cfg; + ioctl_cfg.ioctl_driver_type = I2C_TYPE; + ioctl_cfg.args = &i2c_dev_addr; + result = PrivIoctl(sdev->fd, OPE_INT, &ioctl_cfg); + + return result; } /** * @description: Read sensor device * @param sdev - sensor device pointer * @param len - the length of the read data - * @return success: 1 , failure: -1 + * @return success: 0 , failure: -1 */ static int SensorDeviceRead(struct SensorDevice *sdev, size_t len) { + //send i2c device start signal and address, need to implemente in OS i2c driver if (PrivWrite(sdev->fd, NULL, 0) != 1) return -1; PrivTaskDelay(50); + //Read i2c device data from i2c device address if (PrivRead(sdev->fd, sdev->buffer, len) != 1) return -1; @@ -101,6 +115,7 @@ static int32_t ReadTemperature(struct SensorQuantity *quant) if (quant->sdev->done->read != NULL) { if (quant->sdev->status == SENSOR_DEVICE_PASSIVE) { quant->sdev->done->read(quant->sdev, 4); + PrivTaskDelay(50); quant->sdev->done->read(quant->sdev, 4); /* It takes two reads to get the data right */ result = ((quant->sdev->buffer[2] << 8 | quant->sdev->buffer[3]) >> 2) * 165.0 /( (1 << 14) - 1) - 40.0; diff --git a/APP_Framework/Framework/sensor/voice/d124/d124.c b/APP_Framework/Framework/sensor/voice/d124/d124.c index 6c9b93f4..5691bafb 100644 --- a/APP_Framework/Framework/sensor/voice/d124/d124.c +++ b/APP_Framework/Framework/sensor/voice/d124/d124.c @@ -59,6 +59,10 @@ static int SensorDeviceOpen(struct SensorDevice *sdev) PrivMutexCreate(&buff_lock, 0); sdev->fd = PrivOpen(SENSOR_DEVICE_D124_DEV, O_RDWR); + if (sdev->fd < 0) { + printf("open %s error\n", SENSOR_DEVICE_D124_DEV); + return -1; + } struct SerialDataCfg cfg; cfg.serial_baud_rate = BAUD_RATE_9600; diff --git a/APP_Framework/Framework/transform_layer/xiuos/transform.c b/APP_Framework/Framework/transform_layer/xiuos/transform.c index e7eb652c..e80102a6 100644 --- a/APP_Framework/Framework/transform_layer/xiuos/transform.c +++ b/APP_Framework/Framework/transform_layer/xiuos/transform.c @@ -151,6 +151,9 @@ int PrivIoctl(int fd, int cmd, void *args) case PIN_TYPE: ret = PrivPinIoctl(fd, cmd, ioctl_cfg->args); break; + case I2C_TYPE: + ret = ioctl(fd, cmd, ioctl_cfg->args); + break; default: break; } diff --git a/Ubiquitous/XiUOS/board/aiit-arm32-board/third_party_driver/i2c/connect_i2c.c b/Ubiquitous/XiUOS/board/aiit-arm32-board/third_party_driver/i2c/connect_i2c.c index 289789bb..53bf1388 100644 --- a/Ubiquitous/XiUOS/board/aiit-arm32-board/third_party_driver/i2c/connect_i2c.c +++ b/Ubiquitous/XiUOS/board/aiit-arm32-board/third_party_driver/i2c/connect_i2c.c @@ -604,6 +604,41 @@ out: return ret; } +static uint32 I2cInit(struct I2cDriver *i2c_drv, struct BusConfigureInfo *configure_info) +{ + NULL_PARAM_CHECK(i2c_drv); + + struct I2cHardwareDevice *i2c_dev = (struct I2cHardwareDevice *)i2c_drv->driver.owner_bus->owner_haldev; + + if (configure_info->private_data) { + i2c_dev->i2c_dev_addr = *((uint16 *)configure_info->private_data); + return EOK; + } + + KPrintf("I2cInit need set i2c dev addr\n"); + return ERROR; +} + +static uint32 I2cDrvConfigure(void *drv, struct BusConfigureInfo *configure_info) +{ + NULL_PARAM_CHECK(drv); + NULL_PARAM_CHECK(configure_info); + + x_err_t ret = EOK; + struct I2cDriver *i2c_drv = (struct I2cDriver *)drv; + + switch (configure_info->configure_cmd) + { + case OPE_INT: + ret = I2cInit(i2c_drv, configure_info); + break; + default: + break; + } + + return ret; +} + /*manage the i2c device operations*/ static const struct I2cDevDone i2c_dev_done = { @@ -681,6 +716,8 @@ int Stm32HwI2cInit(void) #ifdef BSP_USING_I2C1 I2cGpioInit(&i2c_bus_param); + i2c_driver.configure = I2cDrvConfigure; + ret = BoardI2cBusInit(&i2c_bus, &i2c_driver); if (EOK != ret) { KPrintf("board_i2c_Init error ret %u\n", ret); diff --git a/Ubiquitous/XiUOS/board/aiit-riscv64-board/third_party_driver/i2c/connect_i2c.c b/Ubiquitous/XiUOS/board/aiit-riscv64-board/third_party_driver/i2c/connect_i2c.c index 81ade217..8979e75c 100644 --- a/Ubiquitous/XiUOS/board/aiit-riscv64-board/third_party_driver/i2c/connect_i2c.c +++ b/Ubiquitous/XiUOS/board/aiit-riscv64-board/third_party_driver/i2c/connect_i2c.c @@ -512,6 +512,41 @@ out: return ret; } +static uint32 I2cInit(struct I2cDriver *i2c_drv, struct BusConfigureInfo *configure_info) +{ + NULL_PARAM_CHECK(i2c_drv); + + struct I2cHardwareDevice *i2c_dev = (struct I2cHardwareDevice *)i2c_drv->driver.owner_bus->owner_haldev; + + if (configure_info->private_data) { + i2c_dev->i2c_dev_addr = *((uint16 *)configure_info->private_data); + return EOK; + } + + KPrintf("I2cInit need set i2c dev addr\n"); + return ERROR; +} + +static uint32 I2cDrvConfigure(void *drv, struct BusConfigureInfo *configure_info) +{ + NULL_PARAM_CHECK(drv); + NULL_PARAM_CHECK(configure_info); + + x_err_t ret = EOK; + struct I2cDriver *i2c_drv = (struct I2cDriver *)drv; + + switch (configure_info->configure_cmd) + { + case OPE_INT: + ret = I2cInit(i2c_drv, configure_info); + break; + default: + break; + } + + return ret; +} + /*manage the i2c device operations*/ static const struct I2cDevDone i2c_dev_done = { @@ -589,6 +624,8 @@ int HwI2cInit(void) #ifdef BSP_USING_I2C1 I2cGpioInit(&i2c_bus_param); + i2c_driver.configure = I2cDrvConfigure; + ret = BoardI2cBusInit(&i2c_bus, &i2c_driver); if (EOK != ret) { KPrintf("board_i2c_Init error ret %u\n", ret); diff --git a/Ubiquitous/XiUOS/board/kd233/third_party_driver/i2c/connect_i2c.c b/Ubiquitous/XiUOS/board/kd233/third_party_driver/i2c/connect_i2c.c index edede3cd..acbcf05c 100644 --- a/Ubiquitous/XiUOS/board/kd233/third_party_driver/i2c/connect_i2c.c +++ b/Ubiquitous/XiUOS/board/kd233/third_party_driver/i2c/connect_i2c.c @@ -500,6 +500,41 @@ out: return ret; } +static uint32 I2cInit(struct I2cDriver *i2c_drv, struct BusConfigureInfo *configure_info) +{ + NULL_PARAM_CHECK(i2c_drv); + + struct I2cHardwareDevice *i2c_dev = (struct I2cHardwareDevice *)i2c_drv->driver.owner_bus->owner_haldev; + + if (configure_info->private_data) { + i2c_dev->i2c_dev_addr = *((uint16 *)configure_info->private_data); + return EOK; + } + + KPrintf("I2cInit need set i2c dev addr\n"); + return ERROR; +} + +static uint32 I2cDrvConfigure(void *drv, struct BusConfigureInfo *configure_info) +{ + NULL_PARAM_CHECK(drv); + NULL_PARAM_CHECK(configure_info); + + x_err_t ret = EOK; + struct I2cDriver *i2c_drv = (struct I2cDriver *)drv; + + switch (configure_info->configure_cmd) + { + case OPE_INT: + ret = I2cInit(i2c_drv, configure_info); + break; + default: + break; + } + + return ret; +} + /*manage the i2c device operations*/ static const struct I2cDevDone i2c_dev_done = { @@ -577,6 +612,8 @@ int HwI2cInit(void) #ifdef BSP_USING_I2C1 I2cGpioInit(&i2c_bus_param); + i2c_driver.configure = I2cDrvConfigure; + ret = BoardI2cBusInit(&i2c_bus, &i2c_driver); if (EOK != ret) { KPrintf("board_i2c_Init error ret %u\n", ret); diff --git a/Ubiquitous/XiUOS/board/stm32f407-st-discovery/third_party_driver/i2c/connect_i2c.c b/Ubiquitous/XiUOS/board/stm32f407-st-discovery/third_party_driver/i2c/connect_i2c.c index 1bb39194..7ef31b5d 100644 --- a/Ubiquitous/XiUOS/board/stm32f407-st-discovery/third_party_driver/i2c/connect_i2c.c +++ b/Ubiquitous/XiUOS/board/stm32f407-st-discovery/third_party_driver/i2c/connect_i2c.c @@ -600,6 +600,41 @@ out: return ret; } +static uint32 I2cInit(struct I2cDriver *i2c_drv, struct BusConfigureInfo *configure_info) +{ + NULL_PARAM_CHECK(i2c_drv); + + struct I2cHardwareDevice *i2c_dev = (struct I2cHardwareDevice *)i2c_drv->driver.owner_bus->owner_haldev; + + if (configure_info->private_data) { + i2c_dev->i2c_dev_addr = *((uint16 *)configure_info->private_data); + return EOK; + } + + KPrintf("I2cInit need set i2c dev addr\n"); + return ERROR; +} + +static uint32 I2cDrvConfigure(void *drv, struct BusConfigureInfo *configure_info) +{ + NULL_PARAM_CHECK(drv); + NULL_PARAM_CHECK(configure_info); + + x_err_t ret = EOK; + struct I2cDriver *i2c_drv = (struct I2cDriver *)drv; + + switch (configure_info->configure_cmd) + { + case OPE_INT: + ret = I2cInit(i2c_drv, configure_info); + break; + default: + break; + } + + return ret; +} + /*manage the i2c device operations*/ static const struct I2cDevDone i2c_dev_done = { @@ -677,6 +712,8 @@ int Stm32HwI2cInit(void) #ifdef BSP_USING_I2C1 I2cGpioInit(&i2c_bus_param); + i2c_driver.configure = I2cDrvConfigure; + ret = BoardI2cBusInit(&i2c_bus, &i2c_driver); if (EOK != ret) { KPrintf("board_i2c_Init error ret %u\n", ret); diff --git a/Ubiquitous/XiUOS/resources/i2c/bus_i2c.c b/Ubiquitous/XiUOS/resources/i2c/bus_i2c.c index a68b0afc..deeb4ad7 100644 --- a/Ubiquitous/XiUOS/resources/i2c/bus_i2c.c +++ b/Ubiquitous/XiUOS/resources/i2c/bus_i2c.c @@ -64,6 +64,8 @@ int I2cDriverInit(struct I2cDriver *i2c_driver, const char *driver_name) i2c_driver->driver.private_data = i2c_driver->private_data; + i2c_driver->driver.configure = i2c_driver->configure; + ret = I2cDriverRegister(&i2c_driver->driver); if (EOK != ret) { KPrintf("I2cDriverInit DriverRegister error %u\n", ret); diff --git a/Ubiquitous/XiUOS/resources/i2c/dev_i2c.c b/Ubiquitous/XiUOS/resources/i2c/dev_i2c.c index ca0e9af6..b6d83c51 100644 --- a/Ubiquitous/XiUOS/resources/i2c/dev_i2c.c +++ b/Ubiquitous/XiUOS/resources/i2c/dev_i2c.c @@ -37,7 +37,7 @@ static uint32 I2cDeviceWrite(void *dev, struct BusBlockWriteParam *write_param) struct I2cHardwareDevice *i2c_dev = (struct I2cHardwareDevice *)dev; struct I2cDataStandard i2c_msg; - i2c_msg.addr = I2C_SLAVE_ADDR; + i2c_msg.addr = i2c_dev->i2c_dev_addr; i2c_msg.flags = I2C_WR; i2c_msg.buf = NONE; i2c_msg.len = 0; @@ -55,7 +55,7 @@ static uint32 I2cDeviceRead(void *dev, struct BusBlockReadParam *read_param) struct I2cHardwareDevice *i2c_dev = (struct I2cHardwareDevice *)dev; struct I2cDataStandard i2c_msg; - i2c_msg.addr = I2C_SLAVE_ADDR; + i2c_msg.addr = i2c_dev->i2c_dev_addr; i2c_msg.flags = I2C_RD; i2c_msg.buf = read_param->buffer; i2c_msg.len = read_param->size; diff --git a/Ubiquitous/XiUOS/resources/include/bus_i2c.h b/Ubiquitous/XiUOS/resources/include/bus_i2c.h index 4bf20449..8905b418 100644 --- a/Ubiquitous/XiUOS/resources/include/bus_i2c.h +++ b/Ubiquitous/XiUOS/resources/include/bus_i2c.h @@ -55,6 +55,8 @@ struct I2cDriver { struct Driver driver; + uint32 (*configure) (void *drv, struct BusConfigureInfo *configure_info); + void *private_data; }; diff --git a/Ubiquitous/XiUOS/resources/include/dev_i2c.h b/Ubiquitous/XiUOS/resources/include/dev_i2c.h index ad437bc4..9a3a2278 100644 --- a/Ubiquitous/XiUOS/resources/include/dev_i2c.h +++ b/Ubiquitous/XiUOS/resources/include/dev_i2c.h @@ -27,7 +27,6 @@ extern "C" { #endif -#define I2C_SLAVE_ADDR 0x44 #define I2C_WR 0x0000 #define I2C_RD (1u << 0) #define I2C_ADDR_10BIT (1u << 2) @@ -61,7 +60,7 @@ struct I2cHardwareDevice struct HardwareDev haldev; const struct I2cDevDone *i2c_dev_done; - void *private_data; + uint16 i2c_dev_addr; }; /*Register the I2C device*/