123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- #ifndef HAL_I2C_LLD_H
- #define HAL_I2C_LLD_H
- #if HAL_USE_I2C || defined(__DOXYGEN__)
- #if !defined(SW_I2C_USE_OSAL_DELAY) || defined(__DOXYGEN__)
- #define SW_I2C_USE_OSAL_DELAY TRUE
- #endif
- #if !defined(SW_I2C_USE_I2C1) || defined(__DOXYGEN__)
- #define SW_I2C_USE_I2C1 FALSE
- #endif
- #if !defined(SW_I2C_USE_I2C2) || defined(__DOXYGEN__)
- #define SW_I2C_USE_I2C2 FALSE
- #endif
- #if !defined(SW_I2C_USE_I2C3) || defined(__DOXYGEN__)
- #define SW_I2C_USE_I2C3 FALSE
- #endif
- #if !defined(SW_I2C_USE_I2C4) || defined(__DOXYGEN__)
- #define SW_I2C_USE_I2C4 FALSE
- #endif
- typedef uint16_t i2caddr_t;
- typedef uint8_t i2cflags_t;
- typedef void (*i2c_delay_t)(void);
- typedef struct {
-
- bool addr10;
-
- ioline_t scl;
-
- ioline_t sda;
- #if SW_I2C_USE_OSAL_DELAY || defined(__DOXYGEN__)
-
- systime_t ticks;
- #else
-
- i2c_delay_t delay;
- #endif
- } I2CConfig;
- typedef struct I2CDriver I2CDriver;
- struct I2CDriver {
-
- i2cstate_t state;
-
- const I2CConfig *config;
-
- i2cflags_t errors;
- #if I2C_USE_MUTUAL_EXCLUSION || defined(__DOXYGEN__)
- mutex_t mutex;
- #endif
- #if defined(I2C_DRIVER_EXT_FIELDS)
- I2C_DRIVER_EXT_FIELDS
- #endif
-
-
- systime_t start;
-
- systime_t end;
- };
- #define i2c_lld_get_errors(i2cp) ((i2cp)->errors)
- #if !defined(__DOXYGEN__)
- #if SW_I2C_USE_I2C1
- extern I2CDriver I2CD1;
- #endif
- #if SW_I2C_USE_I2C2
- extern I2CDriver I2CD2;
- #endif
- #if SW_I2C_USE_I2C3
- extern I2CDriver I2CD3;
- #endif
- #if SW_I2C_USE_I2C4
- extern I2CDriver I2CD4;
- #endif
- #endif
- #ifdef __cplusplus
- extern "C" {
- #endif
- void i2c_lld_init(void);
- void i2c_lld_start(I2CDriver *i2cp);
- void i2c_lld_stop(I2CDriver *i2cp);
- void i2c_lld_soft_stop(I2CDriver *i2cp);
- msg_t i2c_lld_master_transmit_timeout(I2CDriver *i2cp, i2caddr_t addr,
- const uint8_t *txbuf, size_t txbytes,
- uint8_t *rxbuf, size_t rxbytes,
- systime_t timeout);
- msg_t i2c_lld_master_receive_timeout(I2CDriver *i2cp, i2caddr_t addr,
- uint8_t *rxbuf, size_t rxbytes,
- systime_t timeout);
- #ifdef __cplusplus
- }
- #endif
- #endif
- #endif
|