eeprom_i2c.h (4383B)
1 /* Copyright 2019 Nick Brassel (tzarc) 2 * 3 * This program is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 2 of the License, or 6 * (at your option) any later version. 7 * 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * 13 * You should have received a copy of the GNU General Public License 14 * along with this program. If not, see <http://www.gnu.org/licenses/>. 15 */ 16 17 #pragma once 18 19 /* 20 Default device configurations: 21 22 For the Sparkfun Qwiic I2C EEPROM module: https://www.sparkfun.com/products/14764 23 #define EEPROM_I2C_CAT24C512 // (part number 24512A) 24 #define EEPROM_I2C_RM24C512C // (part number 24512C) 25 26 For the Sparkfun I2C EEPROM chip: https://www.sparkfun.com/products/525 27 #define EEPROM_I2C_24LC256 28 29 For the Adafruit I2C FRAM chip: https://www.adafruit.com/product/1895 30 #define EEPROM_I2C_MB85RC256V 31 */ 32 #if defined(EEPROM_I2C_CAT24C512) 33 # define EXTERNAL_EEPROM_BYTE_COUNT 65536 34 # define EXTERNAL_EEPROM_PAGE_SIZE 128 35 # define EXTERNAL_EEPROM_ADDRESS_SIZE 2 36 # define EXTERNAL_EEPROM_WRITE_TIME 5 37 #elif defined(EEPROM_I2C_RM24C512C) 38 # define EXTERNAL_EEPROM_BYTE_COUNT 65536 39 # define EXTERNAL_EEPROM_PAGE_SIZE 128 40 # define EXTERNAL_EEPROM_ADDRESS_SIZE 2 41 # define EXTERNAL_EEPROM_WRITE_TIME 3 42 #elif defined(EEPROM_I2C_24LC256) 43 # define EXTERNAL_EEPROM_BYTE_COUNT 32768 44 # define EXTERNAL_EEPROM_PAGE_SIZE 64 45 # define EXTERNAL_EEPROM_ADDRESS_SIZE 2 46 # define EXTERNAL_EEPROM_WRITE_TIME 5 47 #elif defined(EEPROM_I2C_24LC128) 48 # define EXTERNAL_EEPROM_BYTE_COUNT 16384 49 # define EXTERNAL_EEPROM_PAGE_SIZE 64 50 # define EXTERNAL_EEPROM_ADDRESS_SIZE 2 51 # define EXTERNAL_EEPROM_WRITE_TIME 5 52 #elif defined(EEPROM_I2C_24LC64) 53 # define EXTERNAL_EEPROM_BYTE_COUNT 8192 54 # define EXTERNAL_EEPROM_PAGE_SIZE 32 55 # define EXTERNAL_EEPROM_ADDRESS_SIZE 2 56 # define EXTERNAL_EEPROM_WRITE_TIME 5 57 #elif defined(EEPROM_I2C_24LC32A) 58 # define EXTERNAL_EEPROM_BYTE_COUNT 4096 59 # define EXTERNAL_EEPROM_PAGE_SIZE 32 60 # define EXTERNAL_EEPROM_ADDRESS_SIZE 2 61 # define EXTERNAL_EEPROM_WRITE_TIME 5 62 #elif defined(EEPROM_I2C_MB85RC256V) 63 # define EXTERNAL_EEPROM_BYTE_COUNT 32768 64 # define EXTERNAL_EEPROM_PAGE_SIZE 128 65 # define EXTERNAL_EEPROM_ADDRESS_SIZE 2 66 # define EXTERNAL_EEPROM_WRITE_TIME 0 67 #endif 68 69 /* 70 The base I2C address of the EEPROM. 71 This needs to be shifted up by 1, to match i2c_master requirements. 72 */ 73 #ifndef EXTERNAL_EEPROM_I2C_BASE_ADDRESS 74 # define EXTERNAL_EEPROM_I2C_BASE_ADDRESS 0b10100000 75 #endif 76 77 /* 78 The calculated I2C address based on the input memory location. 79 80 For EEPROM chips that embed part of the memory location in the I2C address 81 such as AT24M02 you can use something similar to the following (ensuring the 82 result is shifted by left by 1): 83 84 #define EXTERNAL_EEPROM_I2C_ADDRESS(loc) \ 85 (EXTERNAL_EEPROM_I2C_BASE_ADDRESS | ((((loc) >> 16) & 0x07) << 1)) 86 87 */ 88 #ifndef EXTERNAL_EEPROM_I2C_ADDRESS 89 # define EXTERNAL_EEPROM_I2C_ADDRESS(loc) (EXTERNAL_EEPROM_I2C_BASE_ADDRESS) 90 #endif 91 92 /* 93 The total size of the EEPROM, in bytes. The EEPROM datasheet will usually 94 specify this value in kbits, and will require conversion to bytes. 95 */ 96 #ifndef EXTERNAL_EEPROM_BYTE_COUNT 97 # define EXTERNAL_EEPROM_BYTE_COUNT 8192 98 #endif 99 100 /* 101 The page size in bytes of the EEPROM, as specified in the datasheet. 102 */ 103 #ifndef EXTERNAL_EEPROM_PAGE_SIZE 104 # define EXTERNAL_EEPROM_PAGE_SIZE 32 105 #endif 106 107 /* 108 The address size in bytes of the EEPROM. For EEPROMs with <=256 bytes, this 109 will likely be 1. For EEPROMs >256 and <=65536, this will be 2. For EEPROMs 110 >65536, this will likely need to be 2 with the modified variant of 111 EXTERNAL_EEPROM_I2C_ADDRESS above. 112 113 As expected, consult the datasheet for specifics of your EEPROM. 114 */ 115 #ifndef EXTERNAL_EEPROM_ADDRESS_SIZE 116 # define EXTERNAL_EEPROM_ADDRESS_SIZE 2 117 #endif 118 119 /* 120 The write cycle time of the EEPROM in milliseconds, as specified in the 121 datasheet. 122 */ 123 #ifndef EXTERNAL_EEPROM_WRITE_TIME 124 # define EXTERNAL_EEPROM_WRITE_TIME 5 125 #endif