eeprom_i2c.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. #pragma once
  17. /*
  18. Default device configurations:
  19. For the Sparkfun Qwiic I2C EEPROM module: https://www.sparkfun.com/products/14764
  20. #define EEPROM_I2C_CAT24C512 // (part number 24512A)
  21. #define EEPROM_I2C_RM24C512C // (part number 24512C)
  22. For the Sparkfun I2C EEPROM chip: https://www.sparkfun.com/products/525
  23. #define EEPROM_I2C_24LC256
  24. For the Adafruit I2C FRAM chip: https://www.adafruit.com/product/1895
  25. #define EEPROM_I2C_MB85RC256V
  26. */
  27. #if defined(EEPROM_I2C_CAT24C512)
  28. # define EXTERNAL_EEPROM_BYTE_COUNT 65536
  29. # define EXTERNAL_EEPROM_PAGE_SIZE 128
  30. # define EXTERNAL_EEPROM_ADDRESS_SIZE 2
  31. # define EXTERNAL_EEPROM_WRITE_TIME 5
  32. #elif defined(EEPROM_I2C_RM24C512C)
  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 3
  37. #elif defined(EEPROM_I2C_24LC256)
  38. # define EXTERNAL_EEPROM_BYTE_COUNT 32768
  39. # define EXTERNAL_EEPROM_PAGE_SIZE 64
  40. # define EXTERNAL_EEPROM_ADDRESS_SIZE 2
  41. # define EXTERNAL_EEPROM_WRITE_TIME 5
  42. #elif defined(EEPROM_I2C_24LC128)
  43. # define EXTERNAL_EEPROM_BYTE_COUNT 16384
  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_MB85RC256V)
  48. # define EXTERNAL_EEPROM_BYTE_COUNT 32768
  49. # define EXTERNAL_EEPROM_PAGE_SIZE 128
  50. # define EXTERNAL_EEPROM_ADDRESS_SIZE 2
  51. # define EXTERNAL_EEPROM_WRITE_TIME 0
  52. #endif
  53. /*
  54. The base I2C address of the EEPROM.
  55. This needs to be shifted up by 1, to match i2c_master requirements.
  56. */
  57. #ifndef EXTERNAL_EEPROM_I2C_BASE_ADDRESS
  58. # define EXTERNAL_EEPROM_I2C_BASE_ADDRESS 0b10100000
  59. #endif
  60. /*
  61. The calculated I2C address based on the input memory location.
  62. For EEPROM chips that embed part of the memory location in the I2C address
  63. such as AT24M02 you can use something similar to the following (ensuring the
  64. result is shifted by left by 1):
  65. #define EXTERNAL_EEPROM_I2C_ADDRESS(loc) \
  66. (EXTERNAL_EEPROM_I2C_BASE_ADDRESS | ((((loc) >> 16) & 0x07) << 1))
  67. */
  68. #ifndef EXTERNAL_EEPROM_I2C_ADDRESS
  69. # define EXTERNAL_EEPROM_I2C_ADDRESS(loc) (EXTERNAL_EEPROM_I2C_BASE_ADDRESS)
  70. #endif
  71. /*
  72. The total size of the EEPROM, in bytes. The EEPROM datasheet will usually
  73. specify this value in kbits, and will require conversion to bytes.
  74. */
  75. #ifndef EXTERNAL_EEPROM_BYTE_COUNT
  76. # define EXTERNAL_EEPROM_BYTE_COUNT 8192
  77. #endif
  78. /*
  79. The page size in bytes of the EEPROM, as specified in the datasheet.
  80. */
  81. #ifndef EXTERNAL_EEPROM_PAGE_SIZE
  82. # define EXTERNAL_EEPROM_PAGE_SIZE 32
  83. #endif
  84. /*
  85. The address size in bytes of the EEPROM. For EEPROMs with <=256 bytes, this
  86. will likely be 1. For EEPROMs >256 and <=65536, this will be 2. For EEPROMs
  87. >65536, this will likely need to be 2 with the modified variant of
  88. EXTERNAL_EEPROM_I2C_ADDRESS above.
  89. As expected, consult the datasheet for specifics of your EEPROM.
  90. */
  91. #ifndef EXTERNAL_EEPROM_ADDRESS_SIZE
  92. # define EXTERNAL_EEPROM_ADDRESS_SIZE 2
  93. #endif
  94. /*
  95. The write cycle time of the EEPROM in milliseconds, as specified in the
  96. datasheet.
  97. */
  98. #ifndef EXTERNAL_EEPROM_WRITE_TIME
  99. # define EXTERNAL_EEPROM_WRITE_TIME 5
  100. #endif