|
| 1 | +# Contributing |
| 2 | + |
| 3 | +This repository provides MicroPython drivers for the STeaMi board. |
| 4 | +The goal is to maintain a consistent, reliable, and maintainable codebase across all drivers. |
| 5 | + |
| 6 | +## Driver structure |
| 7 | + |
| 8 | +Each driver must follow this layout: |
| 9 | + |
| 10 | +``` |
| 11 | +lib/<component>/ |
| 12 | +├── README.md |
| 13 | +├── manifest.py |
| 14 | +├── <module_name>/ |
| 15 | +│ ├── __init__.py |
| 16 | +│ ├── const.py |
| 17 | +│ └── device.py |
| 18 | +└── examples/ |
| 19 | + └── *.py |
| 20 | +``` |
| 21 | + |
| 22 | +### Requirements |
| 23 | + |
| 24 | +* The directory name must match the driver name (e.g. `mcp23009e`, `wsen-hids`) |
| 25 | +* The main class must be exposed in `__init__.py` |
| 26 | +* Drivers must be self-contained (no cross-driver dependencies) |
| 27 | + |
| 28 | +## Coding conventions |
| 29 | + |
| 30 | +- **Constants**: use `from micropython import const` wrapper in `const.py` files. |
| 31 | +- **Naming**: `snake_case` for all methods and variables. Enforced by ruff (N802, N803, N806). |
| 32 | +- **Class inheritance**: `class Foo(object):` is the existing convention. |
| 33 | +- **Time**: use `from time import sleep_ms` (not `utime`, not `sleep()` with float seconds). |
| 34 | +- **Exceptions**: use `except Exception:` instead of bare `except:`. |
| 35 | +- **No debug `print()`** in production driver code. |
| 36 | + |
| 37 | +## Driver API conventions |
| 38 | + |
| 39 | +- **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`. |
| 40 | +- **Attributes**: `self.i2c` for the I2C bus, `self.address` for the device address (not `self.bus`, `self.addr`). |
| 41 | +- **I2C helpers**: use private snake_case methods `_read_reg()`, `_write_reg()` for register access. |
| 42 | +- **Device identification**: `device_id()` — returns the device/WHO_AM_I register value. All I2C drivers with an ID register must implement this method. |
| 43 | +- **Reset methods**: `reset()` for hardware reset (pin toggle), `soft_reset()` for software reset (register write), `reboot()` for memory reboot (reload trimming). |
| 44 | +- **Power methods**: `power_on()` / `power_off()`. All drivers must implement both. |
| 45 | +- **Status methods**: `_status()` returns the raw status register as an int (private), `data_ready()` returns True when all channels have new data, `<measurement>_ready()` for per-channel readiness (e.g. `temperature_ready()`, `pressure_ready()`). |
| 46 | +- **Measurement methods**: bare noun without unit suffix only for `temperature()` (°C) and `humidity()` (%RH). All others include the unit: `pressure_hpa()`, `distance_mm()`, `voltage_mv()`, `acceleration_g()`, etc. `read()` for combined reading returning a tuple, `<measurement>_raw()` for raw register values. |
| 47 | +- **Mode methods**: `set_continuous(odr)` to start continuous measurements, `trigger_one_shot()` for a single conversion, `read_one_shot()` for trigger + wait + return data. |
| 48 | + |
| 49 | +## Linting |
| 50 | + |
| 51 | +The project uses `ruff` for linting. |
| 52 | + |
| 53 | +```bash |
| 54 | +ruff check . |
| 55 | +``` |
| 56 | + |
| 57 | +To automatically fix issues: |
| 58 | + |
| 59 | +```bash |
| 60 | +ruff check . --fix |
| 61 | +``` |
| 62 | + |
| 63 | +## Commit messages |
| 64 | + |
| 65 | +Use the following format: |
| 66 | + |
| 67 | +``` |
| 68 | +<scope>: <Description starting with a capital letter ending with a period.> |
| 69 | +``` |
| 70 | + |
| 71 | +The scope is the driver name or domain (`hts221`, `ism330dl`, `docs`, `tests`, `ci`...). There is no predefined list of types — the scope is free-form. |
| 72 | + |
| 73 | +### Examples |
| 74 | + |
| 75 | +``` |
| 76 | +hts221: Fix missing self parameter in get_av method. |
| 77 | +ism330dl: Add driver support for temperature reading. |
| 78 | +wsen-pads: Correct pressure conversion formula. |
| 79 | +docs: Update README driver table. |
| 80 | +tests: Add mock scenarios for mcp23009e driver. |
| 81 | +``` |
| 82 | + |
| 83 | +## Workflow |
| 84 | + |
| 85 | +1. Create a branch from main (`git checkout -b my-new-feature`) |
| 86 | +2. Write your code and add tests in `tests/scenarios/<driver>.yaml` |
| 87 | +3. Run `ruff check` and `python -m pytest tests/ -v -k mock locally` |
| 88 | +4. Commit your changes following the commit message format |
| 89 | +5. Push your branch to the repository |
| 90 | +6. Open a Pull Request |
| 91 | + |
| 92 | +## Continuous Integration |
| 93 | + |
| 94 | +All pull requests must pass these checks: |
| 95 | + |
| 96 | +| Check | Workflow | Description | |
| 97 | +|-------|----------|-------------| |
| 98 | +| Commit messages | `check-commits.yml` | Validates commit message format | |
| 99 | +| Linting | `python-linter.yml` | Runs `ruff check` | |
| 100 | +| Mock tests | `tests.yml` | Runs mock driver tests | |
| 101 | + |
| 102 | +## Notes |
| 103 | + |
| 104 | +* Keep implementations simple and readable |
| 105 | +* Follow existing drivers as reference |
| 106 | +* Ensure documentation (`README.md`) and examples are included for each driver |
0 commit comments