Skip to content

Commit 3bf801c

Browse files
docs: mostly cosmetic revisions to all markdown
1 parent 32f7a85 commit 3bf801c

20 files changed

Lines changed: 497 additions & 279 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ We follow a concise in-source documentation style. See [docs/doxygen-style-guide
174174
* @param msg Message to encode
175175
* @param buffer Output buffer (min 31 bytes)
176176
* @param buffer_len Size of output buffer
177-
* @return Encoded frame length (4-31 bytes), or 0 on error
177+
* @return Encoded frame length (431 bytes), or 0 on error
178178
*/
179179
size_t crumbs_encode_message(const crumbs_message_t *msg,
180180
uint8_t *buffer,

README.md

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,46 +18,56 @@ CRUMBS (Communications Router and Unified Message Broker System) is a small, por
1818
1919
## Features
2020

21-
- **Variable-Length Message Format**: 4-31 byte frames with opaque byte payloads (0-27 bytes)
21+
- **Variable-Length Message Format**: 431 byte frames with opaque byte payloads (027 bytes)
2222
- **Controller/Peripheral Architecture**: One controller, multiple addressable devices
2323
- **Per-Command Handler Dispatch**: Register handlers for specific command types
2424
- **Message Builder/Reader Helpers**: Type-safe payload construction via `crumbs_message_helpers.h`
2525
- **Event-Driven Communication**: Callback-based message handling
2626
- **CRC-8 Protection**: Integrity check on every message
2727
- **CRUMBS-aware Discovery**: Core scanner helper to find devices that speak CRUMBS
2828

29-
## Quick Start (Arduino - C API)
29+
## Quick Start
3030

3131
```c
3232
#include <crumbs_arduino.h>
3333
#include <crumbs_message_helpers.h>
3434

35-
crumbs_context_t controller_ctx;
36-
crumbs_arduino_init_controller(&controller_ctx);
35+
crumbs_context_t ctx;
36+
crumbs_arduino_init_controller(&ctx);
3737

3838
crumbs_message_t m;
39-
crumbs_msg_init(&m, 0x01, 0x01); // type_id=1, opcode=1
39+
crumbs_msg_init(&m, 0x01, 0x01); // type_id=1, opcode=1
40+
crumbs_msg_add_float(&m, 25.5f); // Payload: float
41+
crumbs_msg_add_u8(&m, 0x01); // Payload: byte
4042

41-
// Type-safe payload building
42-
crumbs_msg_add_float(&m, 25.5f); // e.g. change a temperature value
43-
crumbs_msg_add_u8(&m, 0x01); // e.g. configure the channel index
44-
45-
crumbs_controller_send(&controller_ctx, 0x08, &m, crumbs_arduino_wire_write, NULL);
43+
crumbs_controller_send(&ctx, 0x08, &m, crumbs_arduino_wire_write, NULL);
4644
```
4745
46+
Upload [hello examples](examples/core_usage/arduino/hello_peripheral/) to two Arduinos, wire I²C + GND, Serial Monitor (115200): `s`/`r`. See [examples/](examples/).
47+
4848
## Installation
4949
50-
1. Download or clone this repository
51-
2. Place the CRUMBS folder in your Arduino `libraries` directory
52-
3. Include in your sketch: `#include <crumbs_arduino.h>` (Arduino) or `#include "crumbs.h"` (C projects)
50+
**PlatformIO (Recommended):**
51+
52+
```ini
53+
[env]
54+
lib_deps = cameronbrooks11/CRUMBS@^0.10.3
55+
```
5356

54-
No external dependencies required - CRC implementations are included under `src/crc`.
57+
**Arduino IDE:** Tools → Manage Libraries → "CRUMBS" → Install, or copy to `~/Arduino/libraries/`
58+
59+
**Linux/Native:** CMake build (see [CONTRIBUTING.md](CONTRIBUTING.md))
60+
61+
No external dependencies.
5562

5663
## Hardware Requirements
5764

5865
- Arduino or compatible microcontroller
59-
- I²C bus with 4.7k-Ohm pull-up resistors on SDA/SCL lines
60-
- Unique addresses (0x08-0x77) for each peripheral device
66+
- I²C bus with 4.7kΩ pull-up resistors on SDA/SCL
67+
- Unique addresses (0x08–0x77) for each peripheral
68+
- **Level shifter if mixing 5V/3.3V devices**
69+
70+
**Wiring:** SDA↔SDA, SCL↔SCL, GND↔GND (+ 4.7kΩ pull-ups to VCC)
6171

6272
## Documentation
6373

@@ -89,6 +99,18 @@ Examples are organized into three progressive tiers:
8999

90100
See [examples/README.md](examples/README.md) for complete platform coverage and [docs/examples.md](docs/examples.md) for detailed documentation.
91101

102+
## Troubleshooting
103+
104+
**No communication:** Check 4.7kΩ pull-ups, common ground, addresses. Level shifter for 5V↔3.3V.
105+
106+
**CRC errors:** Shorten wires (<30cm), `Wire.setClock(50000)`, add 0.1µF caps.
107+
108+
**Handlers:** `build_flags = -DCRUMBS_MAX_HANDLERS=16` in platformio.ini.
109+
110+
Details: [platform-setup.md](docs/platform-setup.md)
111+
112+
---
113+
92114
## License
93115

94116
GPL-3.0 - see [LICENSE](LICENSE) file for details.

TODO.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

docs/api-reference.md

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@ typedef struct {
2121
uint8_t address; // Device address (not serialized, for context only)
2222
uint8_t type_id; // Device/module type identifier
2323
uint8_t opcode; // Command/query opcode
24-
uint8_t data_len; // Payload length (0-27)
24+
uint8_t data_len; // Payload length (027)
2525
uint8_t data[27]; // Payload buffer
2626
uint8_t crc8; // CRC-8 checksum over serialized frame
2727
} crumbs_message_t;
2828
```
2929

30-
**Serialized frame format** (4-31 bytes):
30+
**Serialized frame format** (431 bytes):
3131

32-
```
33-
[type_id:1][opcode:1][data_len:1][data:0-27][crc8:1]
32+
```text
33+
[type_id:1][opcode:1][data_len:1][data:027][crc8:1]
3434
```
3535

3636
CRC is computed over: `type_id + opcode + data_len + data[0..data_len-1]`
@@ -61,7 +61,7 @@ typedef struct crumbs_context_t {
6161
```c
6262
#define CRUMBS_MAX_PAYLOAD 27 // Maximum payload bytes
6363
#define CRUMBS_MESSAGE_MAX_SIZE 31 // Maximum serialized frame size
64-
#define CRUMBS_VERSION 0x0A03 // Library version (0x0A03 = v0.10.3)
64+
#define CRUMBS_VERSION 1003 // Library version (1003 = v0.10.3, formula: major*10000 + minor*100 + patch)
6565
```
6666
6767
### Callback Signatures
@@ -182,8 +182,14 @@ Send a message from controller to a peripheral device.
182182
- `0` — Success
183183
- `-1` — Invalid arguments (NULL ctx/msg/write_fn)
184184
- `-2` — Context not in controller role
185-
- `-3` — Encode failed
186-
- `>0` — I2C write error (from write_fn)
185+
- `-3` — Encode failed (data_len > 27 or buffer issue)
186+
- `>0` — I2C write error (platform-specific, from write_fn)
187+
188+
**Common issues:**
189+
190+
- Return `-3`: Check `msg->data_len` ≤ 27
191+
- Return `>0`: I²C bus error - check wiring, pull-ups, address
192+
- No response from peripheral: Add 10ms delay before reading
187193
188194
**Example:**
189195
@@ -192,6 +198,10 @@ crumbs_message_t msg;
192198
crumbs_msg_init(&msg, 0x01, 0x10); // type=LED, opcode=query
193199
int rc = crumbs_controller_send(&ctx, 0x08, &msg,
194200
crumbs_arduino_wire_write, NULL);
201+
if (rc != 0) {
202+
Serial.print("Send failed: ");
203+
Serial.println(rc); // Debug error code
204+
}
195205
```
196206

197207
### Peripheral Operations
@@ -204,13 +214,9 @@ int crumbs_peripheral_handle_receive(crumbs_context_t *ctx,
204214
205215
Process incoming data on a peripheral device. Decodes the message, validates CRC, and invokes callbacks/handlers.
206216
207-
**Returns:**
208-
209-
- `0` — Success (callbacks invoked)
210-
- `-1` — Invalid arguments, not peripheral role, or decode failed
211-
- `-2` — CRC mismatch
217+
**Returns:** `0`=success, `-1`=invalid/decode fail, `-2`=CRC error (check wiring, use `crumbs_get_crc_error_count()`)
212218
213-
Typically called from Wire `onReceive()` callback on Arduino.
219+
Called from Wire `onReceive()` on Arduino.
214220
215221
---
216222
@@ -320,7 +326,7 @@ void my_handler(crumbs_context_t *ctx,
320326
- `ctx` — The CRUMBS context
321327
- `opcode` — The command that triggered this handler
322328
- `data` — Payload bytes (may be NULL if data_len == 0)
323-
- `data_len` — Payload length (0-27)
329+
- `data_len` — Payload length (027)
324330
- `user_data` — Opaque pointer registered with this handler
325331

326332
### Handler Dispatch Flow
@@ -547,7 +553,7 @@ Wire-based read function for scanner and diagnostics.
547553

548554
**Returns:**
549555

550-
- Number of bytes read (0-31)
556+
- Number of bytes read (031)
551557
- Negative values on error
552558

553559
### Bus Scanner
@@ -677,7 +683,7 @@ Platform-independent bus scanner for CRUMBS-compatible devices.
677683

678684
**Parameters:**
679685

680-
- `start_addr`/`end_addr` — Inclusive probe range (0x08-0x77 typical)
686+
- `start_addr`/`end_addr` — Inclusive probe range (0x080x77 typical)
681687
- `strict` — Non-zero: request data-phase read (strong detection). Zero: ACK probe only.
682688
- `write_fn`/`read_fn` — Platform primitives
683689
- `found` — Output array for discovered addresses

docs/architecture.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ CRUMBS is a lightweight I²C messaging protocol enabling controllers (e.g., sing
1414

1515
CRUMBS was created to solve practical problems in distributed embedded systems:
1616

17-
- **Compact wire format**: 4-31 bytes per message (variable length)
17+
- **Compact wire format**: 431 bytes per message (variable length)
1818
- **Robust communication**: CRC-8 integrity checking for noisy I²C buses
1919
- **Portable C core**: Easy to integrate on resource-constrained microcontrollers
2020
- **Platform abstraction**: Thin HALs for Arduino (Wire) and Linux (linux-wire)
@@ -108,7 +108,7 @@ The same headers are used by peripheral firmware to implement handlers.
108108
**Bus topology:**
109109
110110
- Modules connect to shared I²C bus (SDA/SCL)
111-
- Each peripheral at unique 7-bit address (0x08-0x77)
111+
- Each peripheral at unique 7-bit address (0x080x77)
112112
- Controller initiates all communication (I²C master)
113113
- Pull-up resistors required (typically 4.7kΩ)
114114
@@ -124,7 +124,7 @@ Controllers use CRUMBS-aware scanning to discover devices on the bus:
124124
125125
**How Discovery Works:**
126126
127-
1. **Bus scan**: Controller probes each address (0x08-0x77)
127+
1. **Bus scan**: Controller probes each address (0x080x77)
128128
2. **Read attempt**: Tries to read a CRUMBS frame from each address
129129
3. **Validation**: Decodes message and validates CRC
130130
4. **Type extraction**: Valid response contains type_id in frame
@@ -258,7 +258,7 @@ Controller can:
258258

259259
- Wire format encoding/decoding
260260
- CRC-8 computation and validation
261-
- Frame boundaries (4-31 bytes)
261+
- Frame boundaries (431 bytes)
262262
- Role management (controller/peripheral)
263263

264264
**Platform Layer (HALs):**
@@ -276,10 +276,10 @@ Controller can:
276276

277277
### Wire Format
278278

279-
**Serialized frame** (4-31 bytes):
279+
**Serialized frame** (431 bytes):
280280

281281
```
282-
[type_id:1][opcode:1][data_len:1][data:0-27][crc8:1]
282+
[type_id:1][opcode:1][data_len:1][data:027][crc8:1]
283283
```
284284

285285
**Key properties:**
@@ -460,8 +460,8 @@ The LHWIT family is intentionally simple (4 module types, basic commands) to rem
460460
**Buffer sizing:**
461461

462462
- `crumbs_message_t`: 31 bytes (fixed maximum)
463-
- `crumbs_context_t`: ~100-200 bytes depending on handler configuration
464-
- Handler table: configurable (0-255 entries)
463+
- `crumbs_context_t`: ~100200 bytes depending on handler configuration
464+
- Handler table: configurable (0255 entries)
465465

466466
### CRC Implementation
467467

docs/character-usage-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ float range = 0.0 to 1.0; // or: 0.0-1.0
5656
- Decorative Unicode symbols
5757
- Non-standard punctuation
5858
59-
### Examples
59+
### Examples (Documentation)
6060
6161
```markdown
6262
<!-- ✅ GOOD -->

docs/index.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
# CRUMBS Documentation
22

3-
Arduino I²C communication library for controller/peripheral messaging with variable-length payloads and CRC validation.
3+
I²C messaging library for controller/peripheral communication with CRC validation.
4+
5+
## 🚀 Start Here
6+
7+
1. [Platform Setup](platform-setup.md) → PlatformIO
8+
2. Test I²C: [scanner](https://playground.arduino.cc/Main/I2cScanner/)
9+
3. Upload [hello examples](../examples/core_usage/arduino/)
10+
4. Read [Protocol](protocol.md) and [examples](examples.md)
11+
12+
Issues? [Troubleshooting](../README.md#troubleshooting)
13+
14+
---
415

516
## Quick Start
617

@@ -48,14 +59,15 @@ void setup() {
4859

4960
## Features
5061

51-
- **Variable-length payload** (0–27 bytes per message)
52-
- **Controller/peripheral architecture** (one controller, multiple devices)
53-
- **Per-command handler dispatch** (register handlers for specific opcodes)
54-
- **Message builder/reader helpers** (type-safe payload construction)
55-
- **Event-driven callbacks** (message and request handling)
56-
- **CRC-8 data integrity** (automatic validation)
57-
- **CRUMBS-aware discovery** (find devices that speak the protocol)
58-
- **Platform support** (Arduino, PlatformIO, Linux)
62+
- **Variable-length payload** (0–27 bytes, 4–31 total frame)
63+
- **Controller/peripheral** (one controller, up to 112 devices)
64+
- **Handler dispatch** (per-opcode callbacks, O(n) lookup)
65+
- **Message helpers** (type-safe: u8, u16, u32, i32, float)
66+
- **Event callbacks** (on_message, on_request)
67+
- **CRC-8 integrity** (auto validation, error stats)
68+
- **Discovery** (scan for compatible devices)
69+
- **Platforms** (Arduino, PlatformIO, Linux)
70+
- **Zero allocation** (deterministic, RTOS-safe)
5971

6072
---
6173

@@ -120,13 +132,13 @@ typedef struct {
120132
uint8_t address; // Device I²C address (not serialized)
121133
uint8_t type_id; // Device/module type identifier
122134
uint8_t opcode; // Command/query opcode
123-
uint8_t data_len; // Payload length (0-27)
135+
uint8_t data_len; // Payload length (027)
124136
uint8_t data[27]; // Payload buffer
125137
uint8_t crc8; // CRC-8 checksum
126138
} crumbs_message_t;
127139
```
128140

129-
**Wire format:** `[type_id:1][opcode:1][data_len:1][data:0-27][crc8:1]` (4-31 bytes)
141+
**Wire format:** `[type_id:1][opcode:1][data_len:1][data:027][crc8:1]` (431 bytes)
130142

131143
### Core Functions
132144

0 commit comments

Comments
 (0)