1 /* 2 * Copyright (C) 2015-2017 Alibaba Group Holding Limited 3 */ 4 5 #ifndef SENSOR_DRV_API_H 6 #define SENSOR_DRV_API_H 7 8 9 #include "aos/kernel.h" 10 #include "ulog/ulog.h" 11 #include "sensor/sensor.h" 12 #include "aos/hal/spi.h" 13 #include "aos/hal/i2c.h" 14 15 typedef struct _sensor_io_dev_t{ 16 dev_io_port_e io_port; 17 union{ 18 i2c_dev_t dev_i2c; 19 spi_dev_t dev_spi; 20 }; 21 }sensor_io_dev_t; 22 23 typedef struct _sensor_io_func_st 24 { 25 int (*read)(uint16_t reg, uint8_t *data, uint16_t size); 26 int (*write)(uint16_t reg, uint8_t *data, uint16_t size); 27 } sensor_io_func_st; 28 29 30 int32_t sensor_i2c_init(i2c_dev_t *i2c); 31 int32_t sensor_i2c_read(i2c_dev_t *i2c, uint16_t reg, uint8_t *data, 32 uint16_t size, uint32_t timeout); 33 int32_t sensor_i2c_write(i2c_dev_t *i2c, uint16_t reg, uint8_t *data, 34 uint16_t size, uint32_t timeout); 35 int32_t sensor_drv_i2c_master_send(i2c_dev_t *i2c, uint8_t *data, uint16_t size, uint32_t timeout); 36 int32_t sensor_drv_i2c_master_recv(i2c_dev_t *i2c, uint8_t *data, uint16_t size, uint32_t timeout); 37 int32_t sensor_spi_read(spi_dev_t *spi, uint8_t *tx, uint8_t *rx, 38 uint16_t size, uint32_t timeout); 39 int32_t sensor_spi_write(spi_dev_t *spi, uint8_t *data, uint16_t size, 40 uint32_t timeout); 41 42 int32_t sensor_io_read(sensor_io_dev_t* dev, uint8_t* reg, uint8_t* data, uint16_t size,uint32_t timeout); 43 int32_t sensor_io_write(sensor_io_dev_t* dev, uint8_t* reg, uint8_t *data, uint16_t size, uint32_t timeout); 44 #endif /* SENSOR_DRV_API_H */ 45