You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

125 lines
4.3 KiB

  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_24LC64)
  48. # define EXTERNAL_EEPROM_BYTE_COUNT 8192
  49. # define EXTERNAL_EEPROM_PAGE_SIZE 32
  50. # define EXTERNAL_EEPROM_ADDRESS_SIZE 2
  51. # define EXTERNAL_EEPROM_WRITE_TIME 5
  52. #elif defined(EEPROM_I2C_24LC32A)
  53. # define EXTERNAL_EEPROM_BYTE_COUNT 4096
  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_MB85RC256V)
  58. # define EXTERNAL_EEPROM_BYTE_COUNT 32768
  59. # define EXTERNAL_EEPROM_PAGE_SIZE 128
  60. # define EXTERNAL_EEPROM_ADDRESS_SIZE 2
  61. # define EXTERNAL_EEPROM_WRITE_TIME 0
  62. #endif
  63. /*
  64. The base I2C address of the EEPROM.
  65. This needs to be shifted up by 1, to match i2c_master requirements.
  66. */
  67. #ifndef EXTERNAL_EEPROM_I2C_BASE_ADDRESS
  68. # define EXTERNAL_EEPROM_I2C_BASE_ADDRESS 0b10100000
  69. #endif
  70. /*
  71. The calculated I2C address based on the input memory location.
  72. For EEPROM chips that embed part of the memory location in the I2C address
  73. such as AT24M02 you can use something similar to the following (ensuring the
  74. result is shifted by left by 1):
  75. #define EXTERNAL_EEPROM_I2C_ADDRESS(loc) \
  76. (EXTERNAL_EEPROM_I2C_BASE_ADDRESS | ((((loc) >> 16) & 0x07) << 1))
  77. */
  78. #ifndef EXTERNAL_EEPROM_I2C_ADDRESS
  79. # define EXTERNAL_EEPROM_I2C_ADDRESS(loc) (EXTERNAL_EEPROM_I2C_BASE_ADDRESS)
  80. #endif
  81. /*
  82. The total size of the EEPROM, in bytes. The EEPROM datasheet will usually
  83. specify this value in kbits, and will require conversion to bytes.
  84. */
  85. #ifndef EXTERNAL_EEPROM_BYTE_COUNT
  86. # define EXTERNAL_EEPROM_BYTE_COUNT 8192
  87. #endif
  88. /*
  89. The page size in bytes of the EEPROM, as specified in the datasheet.
  90. */
  91. #ifndef EXTERNAL_EEPROM_PAGE_SIZE
  92. # define EXTERNAL_EEPROM_PAGE_SIZE 32
  93. #endif
  94. /*
  95. The address size in bytes of the EEPROM. For EEPROMs with <=256 bytes, this
  96. will likely be 1. For EEPROMs >256 and <=65536, this will be 2. For EEPROMs
  97. >65536, this will likely need to be 2 with the modified variant of
  98. EXTERNAL_EEPROM_I2C_ADDRESS above.
  99. As expected, consult the datasheet for specifics of your EEPROM.
  100. */
  101. #ifndef EXTERNAL_EEPROM_ADDRESS_SIZE
  102. # define EXTERNAL_EEPROM_ADDRESS_SIZE 2
  103. #endif
  104. /*
  105. The write cycle time of the EEPROM in milliseconds, as specified in the
  106. datasheet.
  107. */
  108. #ifndef EXTERNAL_EEPROM_WRITE_TIME
  109. # define EXTERNAL_EEPROM_WRITE_TIME 5
  110. #endif