Skip to content

Commit d731420

Browse files
committed
docs: Document driver API conventions in README.
1 parent 79c36e0 commit d731420

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,12 +459,19 @@ lib/<component>/
459459

460460
### Coding conventions
461461

462-
- **Constants**: use `from micropython import const` in `const.py` files.
462+
- **Constants**: use `from micropython import const` wrapper in `const.py` files.
463463
- **Naming**: `snake_case` for new methods. Legacy `camelCase` is acceptable for I2C helpers to stay consistent with existing drivers.
464464
- **Class inheritance**: `class Foo(object):` is the existing convention.
465-
- **Time**: use `from time import sleep_ms` (not `utime`).
465+
- **Time**: use `from time import sleep_ms` (not `utime`, not `sleep()` with float seconds).
466+
- **Exceptions**: use `except Exception:` instead of bare `except:`.
466467
- **No debug `print()`** in production driver code.
467468

469+
### Driver API conventions
470+
471+
- **Constructor signature**: `def __init__(self, i2c, ..., address=DEFAULT_ADDR)` — first parameter is always `i2c` (not `bus`), address uses keyword argument with a default from `const.py`.
472+
- **Attributes**: `self.i2c` for the I2C bus, `self.address` for the device address (not `self.bus`, `self.addr`).
473+
- **I2C helpers**: use private snake_case methods `_read_reg()`, `_write_reg()` for register access. Legacy names (`setReg`, `getReg`, `i2cReadBytes`, etc.) are acceptable in existing drivers but new drivers must use the standard naming.
474+
468475
### Linting
469476

470477
The project uses [ruff](https://docs.astral.sh/ruff/) (config in `pyproject.toml`).

0 commit comments

Comments
 (0)