Skip to content

Commit 1730eb0

Browse files
committed
docs: Restructure main README and extract CONTRIBUTING.md.
1 parent a96fd64 commit 1730eb0

3 files changed

Lines changed: 284 additions & 493 deletions

File tree

CONTRIBUTING.md

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
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/
12+
├── <driver_name>/
13+
| ├── <driver_name>
14+
| | ├── __init__.py
15+
| | ├── device.py
16+
| | ├── exceptions.py
17+
| | └── const.py
18+
| ├── examples/
19+
| │ └── *.py
20+
| ├── manifest.py
21+
| └── README.md
22+
```
23+
24+
### Requirements
25+
26+
* The directory name must match the driver name (e.g. `mcp23009e`, `wsen-hids`)
27+
* The main class must be exposed in `__init__.py`
28+
* Drivers must be self-contained (no cross-driver dependencies)
29+
30+
## Coding conventions
31+
32+
- **Constants**: use `from micropython import const` wrapper in `const.py` files.
33+
- **Naming**: `snake_case` for all methods and variables. Enforced by ruff (N802, N803, N806).
34+
- **Class inheritance**: `class Foo(object):` is the existing convention.
35+
- **Time**: use `from time import sleep_ms` (not `utime`, not `sleep()` with float seconds).
36+
- **Exceptions**: use `except Exception:` instead of bare `except:`.
37+
- **No debug `print()`** in production driver code.
38+
39+
40+
## Driver API conventions
41+
42+
- **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`.
43+
- **Attributes**: `self.i2c` for the I2C bus, `self.address` for the device address (not `self.bus`, `self.addr`).
44+
- **I2C helpers**: use private snake_case methods `_read_reg()`, `_write_reg()` for register access.
45+
- **Device identification**: `device_id()` — returns the device/WHO_AM_I register value. All I2C drivers with an ID register must implement this method.
46+
- **Reset methods**: `reset()` for hardware reset (pin toggle), `soft_reset()` for software reset (register write), `reboot()` for memory reboot (reload trimming).
47+
- **Power methods**: `power_on()` / `power_off()`. All drivers must implement both.
48+
- **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()`).
49+
- **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.
50+
- **Mode methods**: `set_continuous(odr)` to start continuous measurements, `trigger_one_shot()` for a single conversion, `read_one_shot()` for trigger + wait + return data.
51+
52+
## Linting
53+
54+
The project uses `ruff` for linting.
55+
56+
```bash
57+
ruff check .
58+
```
59+
60+
To automatically fix issues:
61+
62+
```bash
63+
ruff check . --fix
64+
```
65+
66+
## Commit messages
67+
68+
Use the following format:
69+
70+
```
71+
<scope>: <Description starting with a capital letter ending with a period.>
72+
```
73+
74+
### Types
75+
76+
* `feat`: new feature or driver
77+
* `fix`: bug fix
78+
* `docs`: documentation changes
79+
* `refactor`: code improvement
80+
* `test`: test-related changes
81+
82+
### Examples
83+
84+
```
85+
hts221: Fix missing self parameter in getAv method.
86+
feat: add ism330dl driver
87+
fix: correct pressure conversion in wsen-pads
88+
docs: update README driver table
89+
```
90+
91+
## Workflow
92+
93+
1. Fork the repository
94+
2. Create a branch for your feature (`git checkout -b feat/my-new-feature`)
95+
3. Write your code and add tests in `tests/scenarios/<driver>.yaml`
96+
4. Run `ruff check` and `python -m pytest tests/ -v -k mock` locally
97+
5. Commit your changes following the commit message format
98+
6. Push to the branch and create a Pull Request
99+
100+
## Continuous Integration
101+
102+
All pull requests must pass these checks:
103+
104+
| Check | Workflow | Description |
105+
|-------|----------|-------------|
106+
| Commit messages | `check-commits.yml` | Validates commit message format |
107+
| Linting | `python-linter.yml` | Runs `ruff check` |
108+
| Mock tests | `tests.yml` | Runs mock driver tests |
109+
110+
111+
## Notes
112+
113+
* Keep implementations simple and readable
114+
* Follow existing drivers as reference
115+
* Ensure documentation (`README.md`) and examples are included for each driver

0 commit comments

Comments
 (0)