aboutsummaryrefslogtreecommitdiffstats
path: root/fw/eeprom.c
diff options
context:
space:
mode:
authorSam Anthony <sam@samanthony.xyz>2025-10-25 12:54:14 -0400
committerSam Anthony <sam@samanthony.xyz>2025-10-25 12:54:14 -0400
commitc73bbe16321a5de0649fd9d29b3dd159a25b63db (patch)
tree66f8d7898cf00a7fa25b1cc8f60d63d1def1681f /fw/eeprom.c
parent866eca8392991c03386dae1f4c0a3821e4fcfbbb (diff)
downloadcan-gauge-interface-c73bbe16321a5de0649fd9d29b3dd159a25b63db.zip
handle ID Control Frames
Diffstat (limited to 'fw/eeprom.c')
-rw-r--r--fw/eeprom.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/fw/eeprom.c b/fw/eeprom.c
index 71a53b1..11d0493 100644
--- a/fw/eeprom.c
+++ b/fw/eeprom.c
@@ -178,17 +178,12 @@ eepromWriteCanId(U16 addr, const CanId *id) {
// Copy ID to buffer
memset(buf, 0u, sizeof(buf));
- switch (id->type) {
- case CAN_ID_STD:
- buf[0u] = id->sid.lo;
- buf[1u] = id->sid.hi & 0x7;
- break;
- case CAN_ID_EXT:
+ if (id->isExt) { // extended
memmove(buf, id->eid, sizeof(buf));
buf[3u] = (buf[3u] & 0x1F) | 0x80; // set EID flag
- break;
- default:
- return FAIL; // unreachable
+ } else { // standard
+ buf[0u] = id->sid.lo;
+ buf[1u] = id->sid.hi & 0x7;
}
return eepromWrite(addr, buf, sizeof(buf));
@@ -209,10 +204,10 @@ eepromReadCanId(U16 addr, CanId *id) {
// Unpack
if (id->eid[3u] & 0x80) { // bit 31 is standard/extended flag
- id->type = CAN_ID_EXT; // extended
+ id->isExt = true; // extended
id->eid[3u] &= 0x1F;
} else {
- id->type = CAN_ID_STD; // standard
+ id->isExt = false; // standard
id->sid.lo = id->eid[0u];
id->sid.hi = id->eid[1u] & 0x7;
}