From: Nathael Pajani Date: Mon, 11 Mar 2013 16:26:05 +0000 (+0100) Subject: Moving EEPROM_TYPE to an enum in i2c.h and rewrite of get_eeprom_type() X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=d7baac308082670a6fc1684d26c5c19b9f2620b2;p=soft%2Flpc122x%2Fcore Moving EEPROM_TYPE to an enum in i2c.h and rewrite of get_eeprom_type() --- diff --git a/drivers/eeprom.c b/drivers/eeprom.c index e55ebc8..c3fccc8 100644 --- a/drivers/eeprom.c +++ b/drivers/eeprom.c @@ -45,10 +45,6 @@ #define EEPROM_ID_BIG_I2C_SIZE 16*1024 #define EEPROM_ID_BIG_PAGE_SIZE 64 -#define EEPROM_TYPE_SMALL EEPROM_ID_SMALL_ADDR -#define EEPROM_TYPE_BIG EEPROM_ID_BIG_ADDR -#define EEPROM_TYPE_NONE 0xFF /* Impossible eeprom address */ - /* Detect the eeprom size */ int eeprom_detect(void) @@ -78,16 +74,15 @@ int eeprom_detect(void) int get_eeprom_type(void) { - static int eeprom_type = 0; /* Will in fact store the eeprom address */ + static int eeprom_type = -1; - if (eeprom_type == EEPROM_TYPE_NONE) - return -1; /* No need to check again */ + if (eeprom_type >= 0) { + return eeprom_type; /* No need to check again */ + } + eeprom_type = eeprom_detect(); if (eeprom_type <= 0) { - eeprom_type = eeprom_detect(); - if (eeprom_type <= 0) { - return -EBADFD; - } + return -1; } return eeprom_type; } diff --git a/include/drivers/i2c.h b/include/drivers/i2c.h index 8b8965e..a498303 100644 --- a/include/drivers/i2c.h +++ b/include/drivers/i2c.h @@ -71,6 +71,12 @@ enum i2c_state_machine_states { I2C_DATA_NACK = 0x58, }; +enum i2c_eeprom_type { + EEPROM_TYPE_NONE = 0, + EEPROM_TYPE_SMALL, + EEPROM_TYPE_BIG, +}; + /***************************************************************************** */ /* I2C Init */