GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing feastorg.github.io — Protocol ProtocolCRUMBS protocol 1.1. The frame below has been the wire format since library
0.7; SET_REPLY (opcode CRUMBS is a message layer over plain I²C. The I²C address selects the device; everything inside the transaction is one CRUMBS frame. FrameThe frame.
Frame length is A receiver rejects a frame when the buffer is shorter than 4 bytes, CRC-8
These are the parameters of CRC-8/SMBUS. The CRC covers Multi-byte valuesThe payload is opaque to the protocol. The library’s helpers
( TransactionsTwo I²C transaction shapes carry every CRUMBS exchange. SET — one write. The controller writes a frame; the peripheral validates it
and dispatches on GET — a write, then a read. A GET as the generated getters send it: two I2C transactions, one after the
other, each read left to right and not to scale. The wait is
The peripheral stores
SET_REPLY (
|
| Measured SCL | SETs applied | Bad GET_STATE replies |
|---|---|---|
| 98 kHz | 96/100, 96/100; every loss a write that NACKed and was retried | not measured |
| 79 kHz | 200/200 | 33/300, 29/300 |
| 66 kHz | 200/200 | 92/300, 10/300 |
| 49.7 kHz | 200/200 | 0/300, 0/300 |
Both failures fit the peripheral missing the first SCL edge after its stretch
and ending up one bit behind. A bad reply is correct up to some byte, then
0xFF, and fails the CRC. A SET whose write NACKs is not delivered by a
controller retry, though the controller sees the retry succeed: the
peripheral’s ACK masks the controller’s STOP, the retry arrives in the same
receive buffer as the failed frame, and the decoder rejects the result. It is
stretch timing, not signal margin: at 49.7 kHz, masking interrupts on the
peripheral for 10–30 µs per loop brought both failures back (8–28 of 300
replies bad, up to 5 write NACKs). Whether the edge is lost in the Pi’s
controller or in the AVR’s TWI is not established, and other peripheral
firmware was not swept. The Pi 4 setting is in
platform-setup.md.
0xFD): the SET acknowledgement
Since protocol 1.1 (library 0.16.0) a peripheral keeps a record of the command
frames it receives, and the library answers the reserved query 0xFD with it.
A controller stages 0xFD with SET_REPLY like any GET and reads:
| Byte | Content |
|---|---|
counter |
Command frames counted since the peripheral started, modulo 256. |
opcode |
The last counted frame’s opcode. |
status |
0x00 none yet, 0x01 applied, 0x02 refused, 0x03 rejected. |
reason |
0x00 when applied. Refused: a byte the firmware chose (its meaning is the family’s). Rejected: 0x01 nothing took the opcode, 0x02 the type check failed. |
Status 0x00 occurs only before the first command frame, and then all four
bytes are 0x00. A reply with any other status, or with status 0x00 and a
non-zero byte, is not an acknowledgement, and a controller treats it as one
from a peripheral without GET_ACK.
“Applied” is the library’s view: the frame reached on_message or a handler
and neither called crumbs_refuse(). A peripheral that dispatches only
through on_message therefore reports every frame it receives as applied,
including opcodes it ignores, unless it calls crumbs_refuse() for them
(crumbs_has_handler() tells it which opcodes it registered handlers for); and
a handler that only queues work reports the command applied when it returns.
The reply’s type_id is the peripheral’s declared type, or 0x00 if it has
declared none.
A command frame is every frame that decodes, CRC included, other than SET_REPLY. Each one advances the counter and becomes the last command:
on_message or a handler for its opcode received it and
did not refuse it;crumbs_refuse(ctx, reason): the
command arrived and was deliberately not acted on;0x01), or when it failed
the type check (0x02).A frame that does not decode — a CRC error, a wrong length, or a retried write merged into a failed one (above) — is not counted: to the acknowledgement it never arrived. SET_REPLY is not counted, so reading the acknowledgement does not move it.
A controller reads the acknowledgement before a SET (the baseline) and after it. The counter is compared for change only, so it may wrap; a peripheral that restarts starts again from all zeros:
| After the SET | Means |
|---|---|
all four bytes equal to the baseline, status not 0x00 |
not advanced: the frame did not arrive intact; send it again |
status 0x00 |
unknown: the peripheral has counted nothing since it started, which is both a lost first frame and a frame applied before a restart; do not re-send |
| counter equal to the baseline, record different | unknown: the counter came round, or the peripheral restarted and counted back to it; do not re-send |
| counter changed, same opcode | the status says applied, refused or rejected |
| counter changed, another opcode | mismatch: another frame was dispatched in between; do not re-send |
So the first SET to a peripheral that has counted nothing since it started is never re-sent. A restart that brings the record back to exactly the baseline still reads as not advanced; the counter cannot rule that out.
flowchart TD
S(["ACK record read<br/>after the SET,<br/>vs. the baseline"]) --> Astatus is<br/>none (0x00)?
A -- yes --> U["unknown:<br/>do not re-send"]
A -- no --> Bcounter same<br/>as baseline?
B -- yes --> Call four bytes<br/>same as baseline?
C -- yes --> N["not advanced:<br/>send again"]
C -- no --> U
B -- no --> Dopcode is<br/>the SET's?
D -- no --> M["mismatch:<br/>do not re-send"]
D -- yes --> SS["SET counted:<br/>the status says<br/>applied, refused<br/>or rejected"]
The table above, for two valid records, in the order crumbs_ack_classify()
and the Python binding’s classify() test it. Unknown is
CRUMBS_RX_ACK_UNKNOWN (Python raises AckUnknown), mismatch is
CRUMBS_RX_ACK_MISMATCH (AckMismatch).
A failed read of the acknowledgement is read again, never answered by sending
the SET again, so a frame is not applied twice because a read failed.
crumbs_controller_send_confirmed() and the Python binding’s
Controller.send_confirmed() do exactly this, with a bounded number of sends,
after checking the peripheral’s version reply (below).
Compatibility. A peripheral built with a library older than 0.16.0 does not
answer 0xFD: it returns whatever its reply handlers or on_request build
for an unknown opcode, or nothing. What a controller then reads depends on
that fallback:
| The older peripheral’s fallback | crumbs_controller_read_ack() returns |
|---|---|
another opcode’s reply (a version reply from on_request) |
CRUMBS_RX_REPLY_MISMATCH (-7) |
an echo of 0xFD with a short payload or one that is not a valid record (the basic_peripheral example’s on_request) |
-7 |
| no reply | -1: the read does not decode |
| an echo whose first four bytes happen to form a valid record | success, with a counter that never moves |
So only its version reply tells a
controller reliably which it is: a CRUMBS_VERSION below 1600
(CRUMBS_ACK_MIN_VERSION) has no acknowledgement, and its SETs can only be
sent unconfirmed. crumbs_controller_send_confirmed() reads the version reply
first and sends nothing to such a peripheral (-7), so the echo in the last
row is not re-sent to its bound; a controller that reads the acknowledgement
itself checks the version the same way. Nothing else on the wire changed, so
old controllers and new peripherals work together unchanged.
A peripheral may declare its own type_id (crumbs_set_type_id()). Once
declared, an incoming frame is dropped — before SET_REPLY handling and before
any callback — when its type_id is neither 0x00 nor the declared value. A
peripheral that has not declared a type accepts every frame. The check runs
after CRC validation, so a corrupt frame is reported as a CRC error whatever
its type.
On the controller side, crumbs_controller_read_expect() applies the mirror
check to a reply: opcode must match, and type_id must match unless the
expected type is 0x00.
CRUMBS uses 7-bit addressing. I²C reserves 0x00–0x07 and 0x78–0x7F,
leaving 0x08–0x77. Within it,
avoid addresses another standard on the same bus may drive.
Why each band is one to avoid, worst first:
| Avoid | Why |
|---|---|
0x0C |
SMBus Alert Response Address: a host reads it expecting every alerting device to answer |
0x08–0x0B |
SMBus Host, Smart Battery Charger, Selector and Battery (SMBus 3.3.1, Table 17) |
0x48–0x4B |
SMBus prototype addresses, “not intended for production parts and should never be assigned to any device” (SMBus §6.2.2.3); LM75-class temperature sensors occupy 0x48–0x4F |
0x50–0x57 |
24Cxx EEPROMs and DIMM SPD, the most contested block on a real bus |
0x61 |
SMBus Device Default Address (ARP); the Atlas Scientific EZO-DO also ships here |
0x10–0x17 is reserved by neither the I²C specification nor SMBus, and is
where the library’s examples default. Every address is a default: the
integrator owns the map, and the controller-side scanners exist so a conflict
is found on the bench rather than in the field.
type_id
0x00 is the wildcard and must not be assigned to a device. 0x01–0xFF
identify a device class, not an individual — two devices of the same type are
told apart by address. Each type owns an independent opcode space.
opcode
0xFE (SET_REPLY) and 0xFD (GET_ACK, the SET acknowledgement, since
protocol 1.1) are reserved. Every other opcode is free per type. By
convention 0x00 is version information,
SET commands sit low and GET queries from 0x80 up, so a reply’s opcode says
what it is.
0x00 is an ordinary opcode to the library; only the convention gives it
meaning.
0x00: version information
A peripheral should answer opcode 0x00 with five bytes: the
CRUMBS_VERSION of the library it was built with, little-endian, then its
module version as major, minor and patch.
crumbs_build_version_reply(reply, type_id, major, minor, patch) produces
exactly this frame. A controller that reads it can tell the device’s type,
its firmware version and which CRUMBS release it runs; a peripheral that
implements it answers a bare read with it, since the requested opcode starts
at 0x00. For compatibility, treat the module version as semantic: a major
mismatch is incompatible, and a peripheral’s minor must be at least the
controller’s. crumbs_controller_scan_for_crumbs_with_types() reports the
type_id of whatever frame each device returns.
CRUMBS_VERSION is major × 10000 + minor × 100 + patch (0.17.0 → 1700).
For the module version, bump major for an incompatible opcode or payload
change, minor for additions, patch for fixes.
The controller-side scanners take one of two probes:
crumbs_controller_scan_for_crumbs*, both modes): read the
address and accept it if the bytes decode as a CRUMBS frame. The CRC is the
discriminator, so a foreign device whose first bytes happen to be
CRC-consistent is reported as present; the tests keep a deliberate example.
In non-strict mode an address whose read did not decode is written an
all-zero frame (00 00 00 00) and read once more. A CRUMBS peripheral
dispatches that frame as an opcode-0x00 SET with no payload, so a family
that binds SET opcode 0x00 will see it; a 24Cxx EEPROM takes it as a page
write.crumbs_arduino_scan, crumbs_linux_scan): I²C-level only.
Strict mode reads one byte, which consumes a byte from whatever device
answers; non-strict mode is an address-only ACK check. Neither decodes a
frame.See api-reference.md for the signatures and return values.