|
| 1 | +# CONTRIBUTING.md |
| 2 | + |
| 3 | +This document explains some concepts used for this repository and answers some |
| 4 | +questions for contributors. |
| 5 | + |
| 6 | +## Abstracting a new peripheral |
| 7 | + |
| 8 | +- Useful documentations are |
| 9 | + - STM datasheets - a list of these can be found in the |
| 10 | + [`stm32f3`][device-support] README. |
| 11 | + - Documentation of [`stm32f3`](https://docs.rs/stm32f3/latest/stm32f3/) |
| 12 | + itself. |
| 13 | + - The HTML table overview of |
| 14 | + [all documented registers](https://stm32-rs.github.io/stm32-rs/). |
| 15 | +- While designing, take inspiration of existing abstraction. For example from |
| 16 | + the existing `stm32` abstractions ([`stm32f1xx`], [`stm32f4xx`], |
| 17 | + [`stm32f7xx`], ...) or the [`nrf-hal`] |
| 18 | +- Incomplete abstraction of peripherals are OK! |
| 19 | + - Reading through the documentation can be daunting. |
| 20 | + - Rather concentrate on a few features you want to support. |
| 21 | + - Think about extensibility. |
| 22 | + - If you know your implementation is incomplete, leave it in a state, |
| 23 | + where it is easy to at least add the most common features afterwards |
| 24 | + without having to introduce [Breaking Changes](#breaking-changes). |
| 25 | + For example use [`#[non_exhaustive]`][non-exhaustive] where it does make |
| 26 | + sense. |
| 27 | + |
| 28 | +[device-support]: https://github.com/stm32-rs/stm32-rs-nightlies/tree/master/stm32f3#supported-devices |
| 29 | +[non-exhaustive]: https://rust-lang.github.io/rfcs/2008-non-exhaustive.html |
| 30 | +[`stm32f1xx`]: https://github.com/stm32-rs/stm32f1xx-hal |
| 31 | +[`stm32f4xx`]: https://github.com/stm32-rs/stm32f4xx-hal |
| 32 | +[`stm32f7xx`]: https://github.com/stm32-rs/stm32f7xx-hal |
| 33 | +[`nrf-hal`]: https://github.com/nrf-rs/nrf-hal |
| 34 | + |
| 35 | +## Breaking Changes |
| 36 | + |
| 37 | +- Breaking changes are defined [here][breaking] |
| 38 | +- Do **not fear** to introduce a breaking change! |
| 39 | + - This crate is a long way of being stable API wise (v1.0.0) and the best |
| 40 | + practices in the embedded ecosystem are still evolving. |
| 41 | + Also, introducing new useful compiler features like [`const-generics`] means |
| 42 | + that there is no other way, then introducing them with a breaking change. |
| 43 | + (_[`min_const_generics`] are already usable_) |
| 44 | + |
| 45 | +[breaking]: https://doc.rust-lang.org/cargo/reference/semver.html |
| 46 | +[`const-generics`]: https://rust-lang.github.io/rfcs/2000-const-generics.html |
| 47 | +[`min_const_generics`]: https://blog.rust-lang.org/2021/02/26/const-generics-mvp-beta.html |
| 48 | + |
| 49 | +## Test your changes |
| 50 | + |
| 51 | +If possible, test if your changes still work with the testsuite (see |
| 52 | +[here](testsuite/README.md)). |
| 53 | + |
| 54 | +This for now requires a stm32f3-discovery board, which you might not have. |
| 55 | +[Adjustments](testsuite/README.md#using-a-different-board) can be made to be |
| 56 | +able to run it on your board. |
| 57 | + |
| 58 | +If you are not sure and / or want to test your changes on the full testsuite |
| 59 | +either way, ask a contributor who should have a board available to test your |
| 60 | +changes on. (In the future, there might also be a job running, which automatically |
| 61 | +tests your changes on a physical board. 🚀) |
| 62 | + |
| 63 | +## CHANGELOG entry |
| 64 | + |
| 65 | +For any **user** visible change, please a note, what changed in the [CHANGELOG](CHANGELOG.md) |
| 66 | + |
| 67 | +For easier traceability, a link to the corresponding PR implementing that |
| 68 | +change is appended, e.g. |
| 69 | + |
| 70 | +```markdown |
| 71 | +### CHANGED |
| 72 | + |
| 73 | +- Output pins have gained the `random()` method, which randomly chooses |
| 74 | + the output state. ([#123]) <!-- LINK to the PR --> |
| 75 | + |
| 76 | +<!-- ... almost at the end of the file --> |
| 77 | +<!-- This is needed to make the link actually work! --> |
| 78 | +[#123]: https://github.com/stm32-rs/stm32f3xx-hal/pull/123 |
| 79 | +``` |
| 80 | + |
| 81 | +## MSVR Job is failing |
| 82 | + |
| 83 | +If the MSRV ("minimal supported rust version") CI job fails, feel free to update |
| 84 | +it. Places are: |
| 85 | + |
| 86 | +- in the [ci.yml](.github/workflows/ci.yml) |
| 87 | +- in the [README](README.md) |
| 88 | + |
| 89 | +## API Design |
| 90 | + |
| 91 | +Some design patterns to take into consideration, while introducing crafting |
| 92 | +APIs. |
| 93 | + |
| 94 | +_This part is written without much research and out of the position |
| 95 | +of the current experience of the author / maintainer, so take it with a grain of |
| 96 | +salt 🧂_ |
| 97 | + |
| 98 | +### Embedded Rust designing patterns |
| 99 | + |
| 100 | +There are some designing patterns written down in "[The Embedded Rust Book]". |
| 101 | +This crate does not follow them for 100%, but the aim is to do so! |
| 102 | + |
| 103 | +[The Embedded Rust Book]: https://docs.rust-embedded.org/book/design-patterns/hal/checklist.html |
| 104 | + |
| 105 | +### Principle of least surprise |
| 106 | + |
| 107 | +If adding a new feature does mean designing a new API try to follow the |
| 108 | +["Principle of least surprise"][POLS]. The type system should guide the user |
| 109 | +towards the right usage of the API and if that is not possible, try to document |
| 110 | +common pitfalls and surprising behavior. |
| 111 | + |
| 112 | +[POLS]: https://en.wikipedia.org/wiki/Principle_of_least_astonishment |
| 113 | + |
| 114 | +### Misc |
| 115 | + |
| 116 | +- Add `#[derive(Debug)]` and `#[cfg_attr(feature = "defmt", |
| 117 | + derive(defmt::Format))]` to new `struct`s and `enum`s where possible. And add |
| 118 | + `#[derive(Copy, Clone)]` for `enum`s and small `struct`s, which is not bound |
| 119 | + to a resource (like a peripheral) where leveraging the move semantics does not |
| 120 | + make sense. |
| 121 | + |
| 122 | +### Parametrization before nameability |
| 123 | + |
| 124 | +E.g. don't introduce a bool for every Enum variant `fn is_enum_variant_1()`, `fn |
| 125 | +is_enum_variant_2()`, `...`, rather use `fn is_enum_variant(enum: Enum)` if |
| 126 | +possible. |
0 commit comments