Skip to content

Commit c1bc991

Browse files
docs: document mixed-bus scanning and new i2c helper APIs
1 parent c6fa396 commit c1bc991

3 files changed

Lines changed: 80 additions & 2 deletions

File tree

docs/api-reference.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,69 @@ int count = crumbs_controller_scan_for_crumbs(
850850
devices, 10, 10000);
851851
```
852852

853+
### Candidate-Address Scanner
854+
855+
```c
856+
int crumbs_controller_scan_for_crumbs_candidates(
857+
const crumbs_context_t *ctx,
858+
const uint8_t *candidates,
859+
size_t candidate_count,
860+
int strict,
861+
crumbs_i2c_write_fn write_fn,
862+
crumbs_i2c_read_fn read_fn,
863+
void *io_ctx,
864+
uint8_t *found,
865+
uint8_t *types,
866+
size_t max_found,
867+
uint32_t timeout_us);
868+
```
869+
870+
Use this helper on mixed buses. It probes only the explicit addresses in `candidates` (deduplicated), avoiding full-range scans.
871+
872+
---
873+
874+
## Raw I2C Device Helpers
875+
876+
```c
877+
typedef int (*crumbs_i2c_write_read_fn)(
878+
void *user_ctx, uint8_t addr,
879+
const uint8_t *tx, size_t tx_len,
880+
uint8_t *rx, size_t rx_len,
881+
uint32_t timeout_us,
882+
int require_repeated_start);
883+
```
884+
885+
`crumbs_i2c_write_read_fn` performs a combined write-then-read transaction. Return value is bytes read (`>=0`) or negative on error.
886+
887+
Helper APIs bound to `crumbs_device_t`:
888+
889+
```c
890+
int crumbs_i2c_dev_write(...);
891+
int crumbs_i2c_dev_read(...);
892+
int crumbs_i2c_dev_write_then_read(...);
893+
int crumbs_i2c_dev_read_reg_ex(...);
894+
int crumbs_i2c_dev_write_reg_ex(...);
895+
int crumbs_i2c_dev_read_reg_u8(...);
896+
int crumbs_i2c_dev_write_reg_u8(...);
897+
int crumbs_i2c_dev_read_reg_u16be(...);
898+
int crumbs_i2c_dev_write_reg_u16be(...);
899+
```
900+
901+
Standard helper error codes:
902+
903+
- `CRUMBS_I2C_DEV_E_INVALID` (`-1`)
904+
- `CRUMBS_I2C_DEV_E_WRITE` (`-2`)
905+
- `CRUMBS_I2C_DEV_E_READ` (`-3`)
906+
- `CRUMBS_I2C_DEV_E_SHORT_READ` (`-4`)
907+
- `CRUMBS_I2C_DEV_E_NO_REPEATED_START` (`-5`)
908+
- `CRUMBS_I2C_DEV_E_SIZE` (`-6`)
909+
910+
`crumbs_i2c_dev_write_then_read` fallback behavior:
911+
912+
- if `write_read_fn` is provided, it is used,
913+
- if it is NULL and `require_repeated_start == 0`, fallback is `dev->write_fn` + `dev->read_fn`,
914+
- if it is NULL and `require_repeated_start != 0`, returns `CRUMBS_I2C_DEV_E_NO_REPEATED_START`.
915+
853916
---
854917
855918
## Return Values and Error Codes

docs/architecture.md

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

99
**Key Principle**: CRUMBS is the transport layer. Module families define the application layer.
1010

11-
**Key Constraint**: A single I²C bus uses one module family. The controller is compiled with that family's headers and only understands those type_ids and opcodes.
11+
**Key Constraint**: A single CRUMBS controller instance uses one module-family vocabulary (type_ids/opcodes). A physical I²C bus may also host non-CRUMBS peripherals, but CRUMBS discovery should then use constrained candidate-address scans rather than broad range probing.
1212

1313
### Design Goals
1414

@@ -101,7 +101,7 @@ The same headers are used by peripheral firmware to implement handlers.
101101
- Self-documenting: Headers define the complete vocabulary
102102
- Version control: Headers can be versioned with the family
103103
104-
**Trade-off:** Controllers cannot communicate with modules from different families (different vocabulary). One bus = one family.
104+
**Trade-off:** A controller cannot speak multiple CRUMBS vocabularies at once. This is a vocabulary constraint, not a hard prohibition on non-CRUMBS devices sharing the same physical bus.
105105
106106
### Physical Deployment
107107
@@ -160,6 +160,8 @@ for (int i = 0; i < count; i++) {
160160
- **Strict mode** (`strict=1`): Read-only probes, safer for sensitive devices
161161
- **Non-strict mode** (`strict=0`): May send probe write to stimulate response
162162

163+
On mixed buses (CRUMBS + non-CRUMBS), avoid broad address-range scans and prefer explicit candidate address lists.
164+
163165
**Runtime device map example:**
164166

165167
```

docs/platform-setup.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,17 @@ void setup() {
578578
void loop() {}
579579
```
580580

581+
If your physical bus also includes non-CRUMBS peripherals, avoid broad range scans and use an explicit candidate list:
582+
583+
```c
584+
uint8_t candidates[] = {0x10, 0x12, 0x20};
585+
uint8_t found[8], types[8];
586+
int count = crumbs_controller_scan_for_crumbs_candidates(
587+
&ctx, candidates, sizeof(candidates), 1,
588+
crumbs_arduino_wire_write, crumbs_arduino_read, NULL,
589+
found, types, 8, 10000);
590+
```
591+
581592
### I²C Bus Scanner (Linux)
582593
583594
```bash
@@ -598,6 +609,8 @@ sudo ./build/crumbs_simple_linux_controller scan
598609
sudo ./build/crumbs_simple_linux_controller scan strict
599610
```
600611

612+
For mixed buses, prefer candidate-address scanning in application code instead of broad `0x08..0x77` sweeps.
613+
601614
---
602615

603616
## Next Steps

0 commit comments

Comments
 (0)