|
| 1 | +Eeprom format |
| 2 | +=== |
| 3 | + |
| 4 | +This document is a work in progress. More details will be added as they become available. |
| 5 | + |
| 6 | +If you want your eeprom-equipped hexpansion to do something automatically, you need to write some data to the eeprom. The data consists of a header which contains hexpansion metadata and a littlefs file system which contains your application and data. The minimal application consists of a file called `app.py` that contains your code. |
| 7 | + |
| 8 | +We will look for eeproms on the following i2c addresses: |
| 9 | +- 0x50 |
| 10 | +- 0x57 |
| 11 | + |
| 12 | +The header is 32 bytes long and contains the following values: |
| 13 | + |
| 14 | +- Magic (offset 0, length 4): |
| 15 | + - ASCII `THEX` |
| 16 | + - This must match exactly |
| 17 | +- Manifest version (offset 4, length 4): |
| 18 | + - ASCII `2024` |
| 19 | + - This must match exactly |
| 20 | +- Filesystem info (offset 8, length 8): |
| 21 | + - 2 bytes offset (bytes from beginning of eeprom) |
| 22 | + - This is the number of bytes from the start of the eeprom to the start of the littlefs filesystem. It must be a multiple of the eeprom page size, and greater or equal to 32. |
| 23 | + - 2 bytes page size (eeprom page size in bytes) |
| 24 | + - As specified in the eeprom datasheet |
| 25 | + - 4 bytes total size (total filesystem size in bytes) |
| 26 | +- VID/PID (offset 16, length 4) |
| 27 | + - 2 bytes VID |
| 28 | + - This is a Vendor ID. To obtain a Vendor ID, contact the Unnecessary Hexpansion Bureaucracy Implementers Forum (UHB-IF) at (location to be disclosed). If you don't want to do that, use vendor id f055. |
| 29 | + - 2 bytes PID |
| 30 | + - This is a Product ID. If you have a Vendor ID, you can choose your own Product ID. If you are using the free-for-all Vendor ID, you will have to coordinate number assignments with other users on a wiki page (to be disclosed). Each hexpansion design with an eeprom needs a unique VID/PID combination. |
| 31 | +- Unique ID (offset 20, length 2) |
| 32 | + - 0x0000 if unused, otherwise unique ID |
| 33 | + - This may be used to identify individual hexpansion instances of the same kind. Leave at zero if not using, otherwise ensure each hexpansion instance has a unique value. |
| 34 | +- Friendly name (offset 22, length 9, padded with 0x00) |
| 35 | + - This is an ASCII string containing a name to be displayed in menus and prompts so that users can identify the hexpansion. It can contain up to ten characters, and unused characters should be set to 0x00. |
| 36 | +- Checksum (offset 31, length 1) |
| 37 | + - This is a checksum calculated by the following algorithm: |
| 38 | + 1. Start with a variable S with the value 0x55 |
| 39 | + 2. for each byte B of the header **except the first byte**, S = B xor S. The first byte (index 0) is ignored. Only bytes with index 1-30 are used. |
| 40 | + 3. when all 30 bytes have been processed, store the result in the checksum position |
| 41 | + |
| 42 | + An example implementation of the checksum algorithm in Python: |
| 43 | + ```Python |
| 44 | + def calc_checksum(header): #header assumed to be of type bytes |
| 45 | + value=0x55 |
| 46 | + for b in header[1:]: |
| 47 | + value= value ^ b |
| 48 | + return value |
| 49 | + |
| 50 | + header_w_checksum = header+bytes([calc_checksum(header)]) #to generate a checksum |
| 51 | + |
| 52 | + calc_checksum(header_w_checksum) # should return 0 if checksum is correct |
| 53 | + |
| 54 | + |
| 55 | + ``` |
| 56 | + |
| 57 | +The header format uses little-endian byte ordering for the individual values, e.g. 0x0123 = 0x01 as least significant byte and 0x23 as most significant byte, resulting in a value of 8961 |
| 58 | + |
| 59 | +The Littlefs filesystem should start on a page boundary of the eeprom. If your eeprom has a page size larger than 32 bytes, this means there will be gap between the header and the filesystem. If your eeprom has a page size smaller than 32 bytes, this means the header will use more than one page. |
| 60 | + |
| 61 | +The filesystem should contain a file named `app.py` which contains micropython code conformant to the app framework API (to be disclosed). It may contain other Python files or data. |
| 62 | + |
| 63 | +# Example |
| 64 | + |
| 65 | +`b'THEX2024\x40\x00\\x40\x00\x00\x00\x01\x00\x55\xf0\x01\x00\x02\x00EXAMPLE\x00\x00\x8b'` |
| 66 | + |
| 67 | +- Magic "THEX" |
| 68 | +- Version "2024" |
| 69 | +- Filesystem offset 64 bytes (0x4000) |
| 70 | +- Filesystem page size 64 bytes (0x4000) |
| 71 | +- Filesystem total size 64k (0x00000100) |
| 72 | +- VID 0xf055 |
| 73 | +- PID 0x0001 |
| 74 | +- Unique ID in use, value 0x0002 |
| 75 | +- Friendly name is "EXAMPLE" (padded with zeroes) |
| 76 | +- Checksum is 0x8b |
| 77 | + |
| 78 | +(header length: 32 bytes) |
| 79 | + |
| 80 | +followed by 32 bytes that are not used |
| 81 | + |
| 82 | +followed by the littlefs filesystem |
0 commit comments