X-Git-Url: https://codewiz.org/gitweb?a=blobdiff_plain;f=bertos%2Fdrv%2Feeprom.h;h=accbba6f83eb88365f4b5446b2e8ab1b7e512b8e;hb=e957b9c1c7935ab27d2b7f96fded1914f303ddec;hp=922fc9d815e2e752dc1ce9441b625bd2164d0506;hpb=9a76f040340e6fd0c42989871173fd0a03ec1f2f;p=bertos.git diff --git a/bertos/drv/eeprom.h b/bertos/drv/eeprom.h index 922fc9d8..accbba6f 100644 --- a/bertos/drv/eeprom.h +++ b/bertos/drv/eeprom.h @@ -36,18 +36,33 @@ * \author Bernie Innocenti * * $WIZ$ module_name = "eeprom" - * $WIZ$ module_depends = "kfile", "i2c" + * $WIZ$ module_configuration = "bertos/cfg/cfg_eeprom.h" + * $WIZ$ module_depends = "kfile", "kfile_block", "kblock", "i2c" */ #ifndef DRV_EEPROM_H #define DRV_EEPROM_H +#include "cfg/cfg_eeprom.h" + #include #include #include #include +#include +#include + +#include + +#if COMPILER_C99 + #define eeprom_init(...) PP_CAT(eeprom_init ## _, COUNT_PARMS(__VA_ARGS__)) (__VA_ARGS__) + #define eeprom_verify(...) PP_CAT(eeprom_verify ## _, COUNT_PARMS(__VA_ARGS__)) (__VA_ARGS__) +#else + #define eeprom_init(args...) PP_CAT(eeprom_init ## _, COUNT_PARMS(args)) (args) + #define eeprom_verify(args...) PP_CAT(eeprom_verify ## _, COUNT_PARMS(args)) (args) +#endif /** @@ -57,6 +72,9 @@ typedef enum EepromType { EEPROM_24XX08, EEPROM_24XX16, + EEPROM_24XX32, + EEPROM_24XX64, + EEPROM_24XX128, EEPROM_24XX256, EEPROM_24XX512, EEPROM_24XX1024, @@ -76,12 +94,23 @@ typedef uint8_t e2dev_addr_t; */ typedef struct Eeprom { - KBlock b; + KBlock blk; I2c *i2c; EepromType type; ///< EEPROM type e2dev_addr_t addr; ///< Device address. + bool verify; +#if !CONFIG_EEPROM_DISABLE_OLD_API + union { + KFile fd; + KFileBlock fdblk; + } DEPRECATED; +#endif /* !CONFIG_EEPROM_DISABLE_OLD_API */ } Eeprom; +#if !CONFIG_EEPROM_DISABLE_OLD_API + STATIC_ASSERT(offsetof(Eeprom, fd) == offsetof(Eeprom, fdblk.fd)); +#endif /* !CONFIG_EEPROM_DISABLE_OLD_API */ + /** * ID for eeproms. */ @@ -90,10 +119,10 @@ typedef struct Eeprom /** * Convert + ASSERT from generic KFile to Eeprom. */ -INLINE Eeprom * EEPROM_CAST(KBlock *b) +INLINE Eeprom * EEPROM_CAST_KBLOCK(KBlock *blk) { - ASSERT(b->priv.type == KBT_EEPROM); - return (Eeprom *)b; + ASSERT(blk->priv.type == KBT_EEPROM); + return (Eeprom *)blk; } /// Type for EEPROM addresses @@ -131,12 +160,21 @@ typedef struct EepromInfo e2_size_t e2_size; ///< eeprom size } EepromInfo; -#if 0 -bool eeprom_erase(Eeprom *fd, e2addr_t addr, e2_size_t count); -bool eeprom_verify(Eeprom *fd, const void *buf, size_t count); -void eeprom_init(Eeprom *fd, EepromType, e2dev_addr_t, bool verify); -#endif +bool eeprom_erase(Eeprom *eep, e2addr_t addr, e2_size_t count); +bool eeprom_verify_4(Eeprom *eep, e2addr_t addr, const void *buf, size_t count); +void eeprom_init_5(Eeprom *eep, I2c *i2c, EepromType type, e2dev_addr_t addr, bool verify); -void eeprom_init(Eeprom *b, I2c *i2c, EepromType type, e2dev_addr_t addr); +#if !CONFIG_EEPROM_DISABLE_OLD_API + +DEPRECATED INLINE bool eeprom_verify_3(Eeprom *eep, const void *buf, size_t count) +{ + return eeprom_verify_4(eep, (e2addr_t)eep->fdblk.fd.seek_pos, buf, count); +} +DEPRECATED INLINE void eeprom_init_4(Eeprom *eep, EepromType type, e2dev_addr_t addr, bool verify) +{ + eeprom_init_5(eep, &local_i2c_old_api, type, addr, verify); + kfileblock_init(&eep->fdblk, &eep->blk); +} +#endif /* !CONFIG_EEPROM_DISABLE_OLD_API */ #endif /* DRV_EEPROM_H */