|
| 1 | +# CLAUDE.md — Project Guidelines |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +MicroPython driver library for the [STeaMi](https://www.steami.cc/) board. Each driver lives under `lib/<component>/` and follows a standard structure. |
| 6 | + |
| 7 | +## Driver Structure |
| 8 | + |
| 9 | +Each completed driver must contain: |
| 10 | + |
| 11 | +``` |
| 12 | +lib/<component>/ |
| 13 | +├── README.md |
| 14 | +├── manifest.py # metadata() + package("<module_name>") |
| 15 | +├── <module_name>/ |
| 16 | +│ ├── __init__.py # exports main class |
| 17 | +│ ├── const.py # register constants using micropython.const() |
| 18 | +│ └── device.py # main driver class |
| 19 | +└── examples/ # English, plural — NOT "exemple" or "example" |
| 20 | + └── *.py |
| 21 | +``` |
| 22 | + |
| 23 | +## Coding Conventions |
| 24 | + |
| 25 | +- **Naming**: `snake_case` for all methods and variables. Enforced by ruff (N802, N803, N806). |
| 26 | +- **Constants**: use `from micropython import const` wrapper in `const.py` files. |
| 27 | +- **Imports**: `from <module>.const import *` is the project convention (F403/F405 ignored by ruff). |
| 28 | +- **Class inheritance**: `class Foo(object):` is the existing convention (Python 2 style, kept for consistency). |
| 29 | +- **Time**: use `from time import sleep_ms` (not `utime`, which is deprecated since MicroPython 1.19+). |
| 30 | +- **Exceptions**: use `except Exception:` instead of bare `except:` when possible. |
| 31 | +- **No debug prints** in production driver code. Enforced by ruff (T20, examples and tests excluded). |
| 32 | + |
| 33 | +## Driver API Conventions |
| 34 | + |
| 35 | +Each driver class must follow these conventions for consistency across the library: |
| 36 | + |
| 37 | +- **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`. |
| 38 | +- **Attributes**: `self.i2c` for the I2C bus, `self.address` for the device address (not `self.bus`, `self.addr`). |
| 39 | +- **I2C helpers**: use private snake_case methods `_read_reg()`, `_write_reg()` for register access. |
| 40 | +- **Time functions**: `from time import sleep_ms` — use `sleep_ms()` with integer milliseconds (not `sleep()` with float seconds, not `from utime import`). |
| 41 | +- **Constants**: always wrap register values with `micropython.const()` in `const.py` files. |
| 42 | +- **Class style**: `class DriverName(object):` (Python 2 compatible style, kept for MicroPython consistency). |
| 43 | +- **Exception handling**: `except Exception:` — never use bare `except:`. |
| 44 | + |
| 45 | +## Linting |
| 46 | + |
| 47 | +- Linter: **ruff** (config in `pyproject.toml`) |
| 48 | +- Line length: 99 |
| 49 | +- Target: Python 3.7 |
| 50 | +- Run: `ruff check` (CI runs this on PRs) |
| 51 | +- Key ignored rules: E722 (bare except), F401/F403/F405 (wildcard imports), E501 (line length) |
| 52 | +- Naming rules: N802 (function name), N803 (argument name), N806 (variable name) |
| 53 | +- No-print rule: T20 (examples and tests excluded) |
| 54 | + |
| 55 | +## Commit Messages |
| 56 | + |
| 57 | +Format enforced by CI: `<scope>: <Description starting with capital letter ending with .>` |
| 58 | + |
| 59 | +- Pattern: `^[^!]+: [A-Za-z]+.+ .+\.$` |
| 60 | +- Max length: 78 characters |
| 61 | +- Examples: `hts221: Fix missing self parameter in get_av method.`, `docs: Fix typos in README files.` |
| 62 | + |
| 63 | +## CI Checks |
| 64 | + |
| 65 | +- `.github/workflows/python-linter.yml` — runs `ruff check` on push/PR to main |
| 66 | +- `.github/workflows/check-commits.yml` — validates commit message format on PRs |
| 67 | + |
| 68 | +## Related Repositories |
| 69 | + |
| 70 | +- [steamicc/micropython-steami-tutorials](https://github.com/steamicc/micropython-steami-tutorials) — high-level display library (`steami_screen.py`, `steami_gc9a01.py`) that wraps the low-level drivers from this repo. |
0 commit comments