1 #ifndef PCA9544_H 2 #define PCA9544_H 3 4 #ifdef __cplusplus 5 extern "C" { 6 #endif 7 8 /* ===== System include ===== */ 9 #include "aos/hal/i2c.h" 10 11 /* ===== Default Configuration Based on BSP ===== */ 12 #ifdef HAAS_I2C 13 #define I2C_PORT 1 14 #define I2C_ADDR_W_8BIT 8 15 #define I2C_BR_100K 100000 16 #endif 17 18 /* ===== MACRO Definition ===== */ 19 #define PCA9544_CHAN_CLEAN 0 20 #define PCA9544_CONFIG_REG_LEN 1U 21 #define PCA9544_IRQ_MASK 0xF0 22 #define PCA9544_BASE_ADDR 0x70 23 24 /* ===== Dev Type Definition ===== */ 25 /* pca9544 channel list */ 26 typedef enum { 27 PCA9544_CH_NULL = 0, 28 PCA9544_CHO = 4, 29 PCA9544_CH1 = 5, 30 PCA9544_CH2 = 6, 31 PCA9544_CH3 = 7, 32 } PCA9544_CH_E; 33 34 /* pca9544 parameters configuration */ 35 typedef struct { 36 /* pca9544 i2c address */ 37 uint8_t dev_addr; 38 /* pca9544 interrupt status */ 39 uint8_t irq_status; 40 /* the current pca9544 channel */ 41 PCA9544_CH_E pca9544_ch; 42 /* the sub dev addr for the selected pca9544 channel */ 43 uint8_t subdev_addr; 44 // uint8_t control_reg; 45 /* the sub dev register address */ 46 uint8_t reg_addr; 47 } PCA9544_DEV_CFG_T; 48 49 /* ===== API Lists ===== */ 50 /********************************************************** 51 * @fun pca9544_init 52 * @breif pca9544 initialization 53 * @param i2c:the pointer for i2c configuration 54 * @param dev_cfg: the pointer for dev configuration 55 * @rtn 56 *********************************************************/ 57 int pca9544_init(i2c_dev_t *i2c, PCA9544_DEV_CFG_T *dev_cfg); 58 59 /********************************************************** 60 * @fun pca9544_deinit 61 * @breif pca9544 deinitialization 62 * @param none 63 * @rtn none 64 *********************************************************/ 65 void pca9544_deinit(); 66 67 /********************************************************** 68 * @fun pca9544_set_chan 69 * @breif pca9544 channel set 70 * @param chan: the object channel 71 * @rtn ret 72 *********************************************************/ 73 int pca9544_set_chan(PCA9544_CH_E chan); 74 75 /********************************************************** 76 * @fun pca9544_clean_chan 77 * @breif pca9544 channel clean 78 * @param none 79 * @rtn ret 80 *********************************************************/ 81 int pca9544_clean_chan(); 82 83 /********************************************************** 84 * @fun pca9544_read_chan 85 * @breif pca9544 channel reading 86 * @param none 87 * @rtn chan: the current selected channel of pca9544 88 *********************************************************/ 89 PCA9544_CH_E pca9544_read_chan(); 90 91 /********************************************************** 92 * @fun pca9544_write_reg 93 * @breif pca9544 register writing operation 94 * @param dev_addr: i2c device address 95 * @param regval: register value 96 * @rtn ret 97 *********************************************************/ 98 int pca9544_write_reg(uint16_t dev_addr, uint8_t regval); 99 100 /********************************************************** 101 * @fun pca9544_read_reg 102 * @breif pca9544 register reading operation 103 * @param dev_addr: i2c device address 104 * @param regval: register value 105 * @rtn ret 106 *********************************************************/ 107 int pca9544_read_reg(uint16_t dev_addr, uint8_t *data); 108 109 int pca954x_irq_handler(uint16_t dev_addr, uint8_t *data); 110 int pca9544_get_irq_state(uint16_t dev_addr, uint8_t *regval); 111 112 /********************************************************** 113 * @fun pca9544_raw_data_write 114 * @breif write raw data to the selected channel 115 * @param sub_addr: the sub dev addr for 116 * the selected pca9544 channel 117 * @param reg_addr: the sub dev register addr for 118 * the selected pca9544 channel 119 * @param size: register size 120 * @param data: the pointer for the writing data 121 * @param len: the data length 122 * @rtn ret 123 *********************************************************/ 124 int pca9544_raw_data_write(uint16_t subdev_addr, uint16_t reg_addr, uint16_t size, uint8_t *data, uint16_t len); 125 126 /********************************************************** 127 * @fun pca9544_raw_data_read 128 * @breif read raw data to the selected channel 129 * @param sub_addr: the sub dev addr for 130 * the selected pca9544 channel 131 * @param reg_addr: the sub dev register addr for 132 * the selected pca9544 channel 133 * @param size: register size 134 * @param data: the pointer for the reading data 135 * @param len: the data length 136 * @rtn ret 137 *********************************************************/ 138 int pca9544_raw_data_read(uint16_t subdev_addr, uint16_t reg_addr, uint16_t size, uint8_t *data, uint16_t len); 139 140 #ifdef __cplusplus 141 } 142 #endif /* __cplusplus */ 143 144 #endif /* PCA9544_H */ 145