Add support for multiple AT24xx EEPROM devices

This commit is contained in:
Gregory Nutt
2015-11-17 07:40:17 -06:00
parent 876cb13356
commit 724901ceb9
4 changed files with 52 additions and 6 deletions
+2
View File
@@ -11096,4 +11096,6 @@
* Move rivers/wireless/cc3000/security.c to crypto/aes.c; move * Move rivers/wireless/cc3000/security.c to crypto/aes.c; move
include/nuttx/wireless/cc3000/security.h to include/nuttx/crypto/aes.h include/nuttx/wireless/cc3000/security.h to include/nuttx/crypto/aes.h
(2015-11-16). (2015-11-16).
* drivers/mtd/at24xx.c: Add support for multiple AT24xx EEPROM parts,
each with unique I2C addresses, but otherwise idential (2015-11-17).
+10
View File
@@ -278,6 +278,15 @@ config MTD_AT24XX
if MTD_AT24XX if MTD_AT24XX
config AT24XX_MULTI
bool "Multiple AT24XX devices"
default n
---help---
Build in additional support for multiple AT24XX devices, each with
dynamically allocated device structures wiath a separate I2C
addresses (but otherwise identical -- support for multiple, different
AT24xx, devices not yet supported).
config AT24XX_SIZE config AT24XX_SIZE
int "AT24xx size (Kbit)" int "AT24xx size (Kbit)"
default 64 default 64
@@ -291,6 +300,7 @@ config AT24XX_ADDR
hex "AT24XX I2C address" hex "AT24XX I2C address"
default 0x50 default 0x50
range 0x50 0x57 range 0x50 0x57
depends on !AT24XX_MULTI
---help--- ---help---
The I2C address of the FLASH part. This is should be 0b01010aaa The I2C address of the FLASH part. This is should be 0b01010aaa
(where aaa is determined by board/pin configuration). (where aaa is determined by board/pin configuration).
+34 -6
View File
@@ -74,11 +74,12 @@
# warning "Assuming AT24 size 64" # warning "Assuming AT24 size 64"
# define CONFIG_AT24XX_SIZE 64 # define CONFIG_AT24XX_SIZE 64
#endif #endif
#ifndef CONFIG_AT24XX_ADDR #if !defined(CONFIG_AT24XX_ADDR) && !defined(CONFIG_AT24XX_MULTI)
# warning "Assuming AT24 address of 0x50" # warning "Assuming AT24 I2C address of 0x50"
# define CONFIG_AT24XX_ADDR 0x50 # define CONFIG_AT24XX_ADDR 0x50
#endif #endif
#ifndef CONFIG_AT24XX_FREQUENCY #ifndef CONFIG_AT24XX_FREQUENCY
# warning "Assuming AT24 I2C frequency of 100KHz"
# define CONFIG_AT24XX_FREQUENCY 100000 # define CONFIG_AT24XX_FREQUENCY 100000
#endif #endif
@@ -134,7 +135,7 @@
*/ */
#ifndef CONFIG_AT24XX_MTD_BLOCKSIZE #ifndef CONFIG_AT24XX_MTD_BLOCKSIZE
# warning "Assuming driver block size is the same as the FLASH page size" # warning "Assuming MTD driver block size is the same as the FLASH page size"
# define CONFIG_AT24XX_MTD_BLOCKSIZE AT24XX_PAGESIZE # define CONFIG_AT24XX_MTD_BLOCKSIZE AT24XX_PAGESIZE
#endif #endif
@@ -179,11 +180,13 @@ static int at24c_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg);
* Private Data * Private Data
************************************************************************************/ ************************************************************************************/
/* At present, only a signal AT24 part is supported. In this case, a statically #ifndef CONFIG_AT24XX_MULTI
* allocated state structure may be used. /* If only a signal AT24 part is supported then a statically allocated state
* structure may be used.
*/ */
static struct at24c_dev_s g_at24c; static struct at24c_dev_s g_at24c;
#endif
/************************************************************************************ /************************************************************************************
* Private Functions * Private Functions
@@ -543,11 +546,16 @@ static int at24c_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
* *
************************************************************************************/ ************************************************************************************/
#ifdef CONFIG_AT24XX_MULTI
FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev, uint8_t address)
#else
FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev) FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev)
#endif
{ {
FAR struct at24c_dev_s *priv; FAR struct at24c_dev_s *priv;
fvdbg("dev: %p\n", dev); #ifdef CONFIG_AT24XX_MULTI
fvdbg("dev: %p address: %02x\n", dev, address);
/* Allocate a state structure (we allocate the structure instead of using /* Allocate a state structure (we allocate the structure instead of using
* a fixed, static allocation so that we can handle multiple FLASH devices. * a fixed, static allocation so that we can handle multiple FLASH devices.
@@ -556,12 +564,32 @@ FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev)
* to be extended to handle multiple FLASH parts on the same I2C bus. * to be extended to handle multiple FLASH parts on the same I2C bus.
*/ */
priv = (FAR struct at24c_dev_s *)kmm_zalloc(sizeof(struct at24c_dev_s));
if (priv == NULL)
{
fdbg("ERROR: Failed to allocate device structure\n");
return NULL;
}
#else
fvdbg("dev: %p\n", dev);
/* If only a signal AT24 part is supported then a statically allocated state
* structure is used.
*/
priv = &g_at24c; priv = &g_at24c;
#endif
if (!priv->initd) if (!priv->initd)
{ {
/* Initialize the allocated structure */ /* Initialize the allocated structure */
#ifdef CONFIG_AT24XX_MULTI
priv->addr = address;
#else
priv->addr = CONFIG_AT24XX_ADDR; priv->addr = CONFIG_AT24XX_ADDR;
#endif
priv->pagesize = AT24XX_PAGESIZE; priv->pagesize = AT24XX_PAGESIZE;
priv->npages = AT24XX_NPAGES; priv->npages = AT24XX_NPAGES;
+6
View File
@@ -382,7 +382,13 @@ FAR struct mtd_dev_s *at45db_initialize(FAR struct spi_dev_s *dev);
****************************************************************************/ ****************************************************************************/
struct i2c_dev_s; /* Forward reference */ struct i2c_dev_s; /* Forward reference */
#ifdef CONFIG_AT24XX_MULTI
FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev,
uint8_t address);
#else
FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev); FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_dev_s *dev);
#endif
/**************************************************************************** /****************************************************************************
* Name: at25_initialize * Name: at25_initialize