/**************************************************************************** Copyright(c) 2019 by Aerospace C.Power (Chongqing) Microelectronics. ALL RIGHTS RESERVED. This Information is proprietary to Aerospace C.Power (Chongqing) Microelectronics and MAY NOT be copied by any method or incorporated into another program without the express written consent of Aerospace C.Power. This Information or any portion thereof remains the property of Aerospace C.Power. The Information contained herein is believed to be accurate and Aerospace C.Power assumes no responsibility or liability for its use in any way and conveys no license or title under any patent or copyright and makes no representation or warranty that this Information is free from patent or copyright infringement. ****************************************************************************/ #ifndef IOT_I2C_SLAVE_API_H #define IOT_I2C_SLAVE_API_H #ifdef __cplusplus extern "C" { #endif #define IOT_I2C_DIRC_RD 1 #define IOT_I2C_DIRC_WR 0 /* enum { IOT_I2C_S_PORT_0 = 0, IOT_I2C_S_PORT_1, IOT_I2C_S_PORT_NUM, } IOT_I2C_S_PORT;*/ #define IOT_I2C_S_PORT_0 0 #define IOT_I2C_S_PORT_1 1 #define IOT_I2C_S_PORT_NUM 2 typedef void (*iot_i2c_slave_cb)(bool_t); typedef struct _iot_i2c_slave_gpio_sel { uint8_t scl; uint8_t sda; } iot_i2c_slave_gpio_sel_t; typedef struct _iot_i2c_slave_cfg { /** i2c port number */ uint8_t port; /** i2c slave dev addr */ uint32_t addr; /** gpio number select */ iot_i2c_slave_gpio_sel_t gpio; /** write done callback */ iot_i2c_slave_cb callback; } iot_i2c_slave_cfg_t; /** * @brief i2c slave initialize * * @param cfg the pointer of i2c slave configure structure * * @return 0: slave device init successful * @return other: slave device init failed */ uint8_t iot_i2c_slave_init(iot_i2c_slave_cfg_t *cfg); /** * @brief i2c slave get recv data num * * @param port the i2c slave port * * @return 0: slave device init successful * @return other: slave device init failed */ uint8_t iot_i2c_s_get_data_num(uint8_t port); /** * @brief i2c slave get status * * @param port the i2c slave port * * @return status */ uint32_t iot_i2c_s_get_st(uint8_t port); /** * @brief i2c slave clear status * * @param port the i2c slave port * * @return None */ void iot_i2c_s_clear_st(uint8_t port, uint8_t status); /** * @brief i2c slave read one byte from fifo * * @param port the i2c slave port * * @return read byte */ uint8_t iot_i2c_s_fifo_read_byte(uint8_t port); /** * @brief i2c slave write date * * @param port the i2c slave port * @param buf the buffer will be send * @param len the length of the buffer * * @return 0 for succ otherwise false */ uint8_t iot_i2c_s_write_data(uint8_t port, uint8_t *buf, uint32_t len); #ifdef __cplusplus } #endif #endif /* IOT_I2C_SLAVE_API_H */