X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fdrv%2Fi2c.h;h=9327ff8d5d75c37fd5ef01e86797a9d9739cb256;hb=37efb5bdc0504ab6df2e8db0635c9c6f7477e23e;hp=907a32147413dbb31d9b33e76b8bc1e5852c8747;hpb=4b5d9de0c1791d0d4b7dcd78cf7ef01c6f5e3481;p=bertos.git diff --git a/bertos/drv/i2c.h b/bertos/drv/i2c.h index 907a3214..9327ff8d 100644 --- a/bertos/drv/i2c.h +++ b/bertos/drv/i2c.h @@ -30,22 +30,86 @@ * * --> * - * \brief I2C generic driver functions (interface). + * \brief I2C generic driver functions. * * \version $Id$ * \author Francesco Sacchi + * + * $WIZ$ module_name = "i2c" + * "configuration" : "bertos/cfg/cfg_i2c.h" */ + #ifndef DRV_I2C_H #define DRV_I2C_H +#include "cfg/cfg_i2c.h" #include -bool i2c_init(void); -bool i2c_start_w(uint8_t id); -bool i2c_start_r(uint8_t id); -void i2c_stop(void); -bool i2c_put(uint8_t _data); -int i2c_get(bool ack); +#define I2C_READBIT BV(0) + +/** + * I2C Backends. + * Sometimes your cpu does not have a builtin + * i2c driver or you don't want, for some reason, to + * use that. + * With this you can choose, at compile time, which backend to use. + * + * $WIZ$ i2c_backend = "I2C_BACKEND_BUILTIN", "I2C_BACKEND_BITBANG" + */ +#define I2C_BACKEND_BUILTIN 0 ///< Uses cpu builtin i2c driver +#define I2C_BACKEND_BITBANG 1 ///< Uses emulated bitbang driver + + +/** + * I2c builtin prototypes. + * Do NOT use these function directly, instead, + * you can call the ones named without "_builtin_" + * and specify in cfg_i2c.h ( \see CONFIG_I2C_BACKEND) + * that you want the builtin backend. + * \{ + */ +void i2c_builtin_init(void); +bool i2c_builtin_start_w(uint8_t id); +bool i2c_builtin_start_r(uint8_t id); +void i2c_builtin_stop(void); +bool i2c_builtin_put(uint8_t _data); +int i2c_builtin_get(bool ack); +/*\}*/ + +/** + * I2c bitbang prototypes. + * Same thing here: do NOT use these function directly, instead, + * you can call the ones named without "_bitbang_" + * and specify in cfg_i2c.h ( \see CONFIG_I2C_BACKEND) + * that you want the bitbang backend. + * \{ + */ +void i2c_bitbang_init(void); +bool i2c_bitbang_start_w(uint8_t id); +bool i2c_bitbang_start_r(uint8_t id); +void i2c_bitbang_stop(void); +bool i2c_bitbang_put(uint8_t _data); +int i2c_bitbang_get(bool ack); +/*\}*/ + +#if CONFIG_I2C_BACKEND == I2C_BACKEND_BUILTIN + #define i2c_init i2c_builtin_init + #define i2c_start_w i2c_builtin_start_w + #define i2c_start_r i2c_builtin_start_r + #define i2c_stop i2c_builtin_stop + #define i2c_put i2c_builtin_put + #define i2c_get i2c_builtin_get +#elif CONFIG_I2C_BACKEND == I2C_BACKEND_BITBANG + #define i2c_init i2c_bitbang_init + #define i2c_start_w i2c_bitbang_start_w + #define i2c_start_r i2c_bitbang_start_r + #define i2c_stop i2c_bitbang_stop + #define i2c_put i2c_bitbang_put + #define i2c_get i2c_bitbang_get +#else + #error Unsupported i2c backend. +#endif + bool i2c_send(const void *_buf, size_t count); bool i2c_recv(void *_buf, size_t count);