diff options
author | Nick Brassel <nick@tzarc.org> | 2019-11-06 08:04:50 +1100 |
---|---|---|
committer | Nick Brassel <nick@tzarc.org> | 2020-01-24 12:45:58 +1100 |
commit | d13ada11622977bcc0b530212b4405229805016d (patch) | |
tree | 3f8874ac3c9b5950b1fed6ac4d0081a268d9f487 /drivers/eeprom/eeprom_i2c.h | |
parent | 6ff093efbee21d3f64f5b4bfdbc66d4648490523 (diff) | |
download | qmk_firmware-d13ada11622977bcc0b530212b4405229805016d.tar.gz qmk_firmware-d13ada11622977bcc0b530212b4405229805016d.zip |
Add customisable EEPROM driver selection (#7274)
- uprintf -> dprintf
- Fix atsam "vendor" eeprom.
- Bump Kinetis K20x to 64 bytes, too.
- Rollback Kinetis to 32 bytes as partitioning can only be done once. Add warning about changing the value.
- Change RAM-backed "fake" EEPROM implementations to match eeconfig's current usage.
- Add 24LC128 by request.
Diffstat (limited to 'drivers/eeprom/eeprom_i2c.h')
-rw-r--r-- | drivers/eeprom/eeprom_i2c.h | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/drivers/eeprom/eeprom_i2c.h b/drivers/eeprom/eeprom_i2c.h new file mode 100644 index 000000000..51bce825b --- /dev/null +++ b/drivers/eeprom/eeprom_i2c.h | |||
@@ -0,0 +1,115 @@ | |||
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_MB85RC256V) | ||
53 | # define EXTERNAL_EEPROM_BYTE_COUNT 32768 | ||
54 | # define EXTERNAL_EEPROM_PAGE_SIZE 128 | ||
55 | # define EXTERNAL_EEPROM_ADDRESS_SIZE 2 | ||
56 | # define EXTERNAL_EEPROM_WRITE_TIME 0 | ||
57 | #endif | ||
58 | |||
59 | /* | ||
60 | The base I2C address of the EEPROM. | ||
61 | This needs to be shifted up by 1, to match i2c_master requirements. | ||
62 | */ | ||
63 | #ifndef EXTERNAL_EEPROM_I2C_BASE_ADDRESS | ||
64 | # define EXTERNAL_EEPROM_I2C_BASE_ADDRESS 0b10100000 | ||
65 | #endif | ||
66 | |||
67 | /* | ||
68 | The calculated I2C address based on the input memory location. | ||
69 | |||
70 | For EEPROM chips that embed part of the memory location in the I2C address | ||
71 | such as AT24M02 you can use something similar to the following (ensuring the | ||
72 | result is shifted by left by 1): | ||
73 | |||
74 | #define EXTERNAL_EEPROM_I2C_ADDRESS(loc) \ | ||
75 | (EXTERNAL_EEPROM_I2C_BASE_ADDRESS | ((((loc) >> 16) & 0x07) << 1)) | ||
76 | |||
77 | */ | ||
78 | #ifndef EXTERNAL_EEPROM_I2C_ADDRESS | ||
79 | # define EXTERNAL_EEPROM_I2C_ADDRESS(loc) (EXTERNAL_EEPROM_I2C_BASE_ADDRESS) | ||
80 | #endif | ||
81 | |||
82 | /* | ||
83 | The total size of the EEPROM, in bytes. The EEPROM datasheet will usually | ||
84 | specify this value in kbits, and will require conversion to bytes. | ||
85 | */ | ||
86 | #ifndef EXTERNAL_EEPROM_BYTE_COUNT | ||
87 | # define EXTERNAL_EEPROM_BYTE_COUNT 8192 | ||
88 | #endif | ||
89 | |||
90 | /* | ||
91 | The page size in bytes of the EEPROM, as specified in the datasheet. | ||
92 | */ | ||
93 | #ifndef EXTERNAL_EEPROM_PAGE_SIZE | ||
94 | # define EXTERNAL_EEPROM_PAGE_SIZE 32 | ||
95 | #endif | ||
96 | |||
97 | /* | ||
98 | The address size in bytes of the EEPROM. For EEPROMs with <=256 bytes, this | ||
99 | will likely be 1. For EEPROMs >256 and <=65536, this will be 2. For EEPROMs | ||
100 | >65536, this will likely need to be 2 with the modified variant of | ||
101 | EXTERNAL_EEPROM_I2C_ADDRESS above. | ||
102 | |||
103 | As expected, consult the datasheet for specifics of your EEPROM. | ||
104 | */ | ||
105 | #ifndef EXTERNAL_EEPROM_ADDRESS_SIZE | ||
106 | # define EXTERNAL_EEPROM_ADDRESS_SIZE 2 | ||
107 | #endif | ||
108 | |||
109 | /* | ||
110 | The write cycle time of the EEPROM in milliseconds, as specified in the | ||
111 | datasheet. | ||
112 | */ | ||
113 | #ifndef EXTERNAL_EEPROM_WRITE_TIME | ||
114 | # define EXTERNAL_EEPROM_WRITE_TIME 5 | ||
115 | #endif | ||