641 Commits

Author SHA1 Message Date
bors[bot]
7e24e0c136 Merge #463
463: embedded-hal: digital: add #[inline] hints for PinState functions r=Dirbaio a=luojia65

Add inline hints for:

- `<PinState as Not>::not`
- `<PinState as From<bool>>::from`
- `<bool as From<PinState>>::from`

Those hints would allow further optimizations if PinState structure functions is used on embedded-hal projects.

Co-authored-by: Luo Jia / Zhouqi Jiang <luojia@hust.edu.cn>
2023-05-31 12:30:36 +00:00
Luo Jia / Zhouqi Jiang
d500bfa661 embedded-hal: digital: add #[inline] hints for PinState functions
Add inline hints for:

- <PinState as Not>::not
- <PinState as From<bool>>::from
- <bool as From<PinState>>::from

Those hints would allow further optimizations if PinState structure functions is used on embedded-hal projects.

Signed-off-by: Zhouqi Jiang <luojia@hust.edu.cn>
2023-05-31 20:17:50 +08:00
bors[bot]
30a8190703 Merge #461
461: spi: remove write-only and read-only traits. r=Dirbaio a=Dirbaio

When introducing the Bus/Device split in #351, I kept the ability to represent "read-only" and "write-only" buses, with separate `SpiBusRead`, `SpiBusWrite` buses. This didn't have much discussion, as it was the logical consequence of keeping the separation in the already existing traits (`Read`, `Write`, `Transfer`, ...).

Later, in #443, when switching from the closure-based API to the operation-slice-based API, this required adding `SpiDeviceRead`, `SpiDeviceWrite` as well, because you can no longer put a bound on the underlying bus with the new API.

This means we now have *seven* traits, which we can reduce to *two* if we drop the distinction. So, is the distinction worth it?

I've always been on the fence about it, now I'm sort of leaning towards no.

First, using write-only or read-only SPI is rare. 
- write-only SPI: for SPI displays you don't want to read from, or to abuse it to bitbang stuff like ws2812b,
- read-only SPI: some ADCs that can't be configured at all, you just clock out bits. Or even weirder abuses, like to build a logic analyzer

Second, for it to be useful HALs have to track "read-onlyness / write-onlyness" in the type signature, so a read-only SPI really only implements `SpiBusRead` and not `SpiBus`. HALs already have enough generics. For example, Embassy HALs don't implement the distinction (you can create MOSI-only or MISO-only SPIs, but they all impl the full `SpiBus`, because I didn't want to make the types carry pin information).

Third, it makes the API easier to use. Simpler, users only have to import one trait, docs have all the methods in one place. Much less boilerplate to impl the traits (look at how shorter `embedded-hal-bus` gets!).

So I think we should remove them.

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2023-05-19 11:25:29 +00:00
Dario Nieuwenhuis
1567f258bf spi: remove write-only and read-only traits. 2023-05-10 22:43:52 +02:00
bors[bot]
804e1de2df Merge #456
456: spi: clarify flushing/blocking behavior. r=eldruin a=Dirbaio



Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2023-05-09 16:12:04 +00:00
bors[bot]
800eefdf28 Merge #457
457: embedded-can: make `StandardId::as_raw` and `ExtendedId::as_raw` const r=ryankurte a=dimpolo



Co-authored-by: dimpolo <33688001+dimpolo@users.noreply.github.com>
2023-05-04 22:23:45 +00:00
bors[bot]
1439504832 Merge #458
458: bus: Add a doc example for i2c::RefCellDevice r=Dirbaio a=tomgilligan

`embedded-hal-bus` is turning out to be very useful for something I'm working on.  It wasn't too hard to work out how to use it but it feels like an example would still be helpful here.  Not sure:

- is this the best place to put such an example?
- how much of the example should be hidden with `#`?

Co-authored-by: Thomas Gilligan <thomas.gilligan@icloud.com>
2023-05-03 16:43:00 +00:00
Thomas Gilligan
6a0c442fc9 Actually commit doc test fix 🥲 2023-05-04 01:49:06 +10:00
Thomas Gilligan
baefcf241b Put i2c bus example on struct, fix doc test 2023-05-03 20:52:23 +10:00
Thomas Gilligan
d187dc0fcb Add a doc example for i2c::RefCellDevice 2023-05-03 19:31:29 +10:00
dimpolo
215d7b4fa0 embedded-can: make StandardId::as_raw and ExtendedId::as_raw const 2023-05-02 22:20:10 +02:00
Dario Nieuwenhuis
28df44c1f7 spi: clarify flushing/blocking behavior.
Fixes #455.
2023-05-02 20:08:00 +02:00
bors[bot]
3a7c3cad28 Merge #449
449: Release e-h v1.0.0-alpha.10, e-h-async v0.2.0-alpha.1, e-h-bus v0.1.0… r=eldruin a=Dirbaio

…-alpha.2, e-h-nb v1.0.0-alpha.2.

lots of crates, whew 😅 

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
embedded-hal-nb-v1.0.0-alpha.2 embedded-hal-bus-v0.1.0-alpha.2 embedded-hal-async-v0.2.0-alpha.1 v1.0.0-alpha.10
2023-04-05 06:53:27 +00:00
Dario Nieuwenhuis
76c66f3799 Release e-h v1.0.0-alpha.10, e-h-async v0.2.0-alpha.1, e-h-bus v0.1.0-alpha.2, e-h-nb v1.0.0-alpha.2. 2023-04-04 22:09:17 +02:00
bors[bot]
0c98b79766 Merge #444
444: bus/spi: add RefCell, CriticalSection and Mutex shared bus implementations. r=eldruin a=Dirbaio

Requires #443 

This adds a few bus sharing implementations, with varying tradeoffs:
- `RefCellDevice`: single thread only
- `CriticalSectionDevice`: thread-safe, coarse locking, nostd.
- `MutexDevice`: thread-safe, fine-grained locking, std only.

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2023-04-01 09:05:22 +00:00
Dario Nieuwenhuis
756b05519e spi: Add changelog for transaction changes. 2023-04-01 10:52:48 +02:00
Dario Nieuwenhuis
76541e0766 bus/spi: add RefCell, CriticalSection and Mutex shared bus implementations. 2023-04-01 10:50:42 +02:00
bors[bot]
a8ea55f888 Merge #443
443: spi: make SpiDevice transaction take an operation slice instead of a closure. r=eldruin a=Dirbaio

As discussed in [today's WG meeting](https://matrix.to/#/!BHcierreUuwCMxVqOf:matrix.org/$l3MzRbzKQ0LGOops0ioYfM2kEr6-eT7ODboDj9iiCfY?via=matrix.org&via=psion.agg.io&via=tchncs.de).

- Fixes https://github.com/rust-embedded/linux-embedded-hal/issues/87
- Gets rid of the cursed borrow issues in async.
- Makes the trait more consistent with I2C.


Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2023-04-01 07:01:16 +00:00
Dario Nieuwenhuis
b6764ecd57 spi: SpiDevice transactiontake an operation slice instead of a closure. 2023-03-28 14:41:54 +02:00
bors[bot]
8aaa48b6d3 Merge #448
448: Misc doc fixes. r=eldruin a=Dirbaio

- Switch from GAT to AFIT has already happened.
- We're no longer planning to integrate EHA into EH
- Fix all broken links.

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2023-03-28 12:28:57 +00:00
Dario Nieuwenhuis
0584ebe8fb Misc doc fixes. 2023-03-28 13:57:56 +02:00
bors[bot]
a0f24262f7 Merge #445
445: bus/i2c: add RefCell, CriticalSection and Mutex shared bus implementations. r=eldruin a=Dirbaio

Requires #440 

Same as #443 but for I2C.


This adds a few bus sharing implementations, with varying tradeoffs:
- `RefCellDevice`: single thread only
- `CriticalSectionDevice`: thread-safe, coarse locking, nostd.
- `MutexDevice`: thread-safe, fine-grained locking, std only.

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2023-03-28 11:45:54 +00:00
Dario Nieuwenhuis
16ac2e68df bus: update docs, document features. 2023-03-28 13:31:11 +02:00
Dario Nieuwenhuis
37a8e614f0 bus/i2c: add RefCell, CriticalSection and Mutex shared bus implementations. 2023-03-28 13:13:42 +02:00
bors[bot]
1d74e8927d Merge #440
440: I2c: simplify, expand docs, document shared bus usage. r=eldruin a=Dirbaio

~Depends on #441 -- check that one out first.~

This does some simplifications to the trait that I think we should do:

- Implement all methods in terms of `transaction`. This way HALs have to implement just that.
- Removed byte-wise-iteration methods: `write_iter` and `write_iter_read`. The reason is that they're quite inefficient, especially with DMA implementations. We've already removed these on other traits, so I think we should do as well here.
- Removed `transaction_iter`. I don't think it's much useful in practice, because the way iterators work all the yielded `Operation`s must have the same lifetime. This means that, even if the user can generate the `Operation`s on the fly, they can't allocate buffers for these on the fly, all buffers must be pre-allocated. So it's not useful for, say, streaming a large transfer by reusing some small buffer repeatedly. See #367 
- Removed useless lifetimes
- Standardized buffer names on `read` and `write`, I think they're clearer.

It also specifies how i2c bus sharing is supposed to work. This is an alternative to #392 . After the discussions there, I don't think we should split I2C into Bus and Device anymore. For SPI it makes sense, because drivers want to enforce that there's a CS pin (`SpiDevice`) or not (`SpiBus`). This is not the case with I2C, the API is exactly the same in the shared and non-shared case. Drivers shouldn't care which case it is.

So all we have to do to "support" bus sharing is docs, This PR does:

- Document that it's allowed for implementations to be either shared or not.
- Document some guidelines for drivers and HALs on how to best use the traits, expand the examples.


Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2023-03-28 06:59:51 +00:00
bors[bot]
3250073f96 Merge #446
446: Update changelog after #442 r=Dirbaio a=eldruin

This was forgotten in #442 

Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2023-03-15 11:16:22 +00:00
Dario Nieuwenhuis
7b42f2430f i2c: changelog. 2023-03-15 12:08:28 +01:00
Dario Nieuwenhuis
147aee2ffc I2c: expand docs, document shared bus usage. 2023-03-15 12:07:17 +01:00
Dario Nieuwenhuis
8b984d299a i2c: implement all operations in terms of transaction. 2023-03-15 12:07:17 +01:00
Dario Nieuwenhuis
f644e8225f i2c: rename args to write/read. 2023-03-15 12:07:17 +01:00
Dario Nieuwenhuis
6236f2baf1 i2c: remove useless lifetimes. 2023-03-15 12:07:17 +01:00
Dario Nieuwenhuis
f43ab6e0ef i2c: remove iter methods. 2023-03-15 12:07:17 +01:00
Diego Barrios Romero
336eb5aaa6 Update changelog after #442 2023-03-15 09:18:58 +01:00
bors[bot]
15337167d5 Merge #442
442: async/serial: add Write. r=eldruin a=Dirbaio

Extracted out of #349 

This is just `Write`, mirroring the blocking version. so it should hopefully be uncontroversial.

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2023-03-14 20:12:20 +00:00
bors[bot]
49a42e8802 Merge #430
430: Add PWM SetDuty trait. r=therealprof a=Dirbaio

This adds back a version of the 0.2 trait `PwmPin`. 

cc #358

WG meeting [chatlog](https://matrix.to/#/!BHcierreUuwCMxVqOf:matrix.org/$_4DVnptWkGRjvW7-5Y6qCQZvj8oi9t4tbt8v4hXxJak?via=matrix.org&via=psion.agg.io&via=tchncs.de)

Differences to 0.2:

- `enable()` and `disable()` are gone. I think they were underspecified (for example, is the pin high or low when disabled?), and not very useful in practice. Disabling can be achieved already by setting duty to 0% or 100%. If the HAL cares about power consumption, it can transparently disable the timer and set the pin to fixed high/low when duty is 0% or 100%.
- Duty is no longer an unconstrained associated type. `u16` has been chosen because it gives enough dynamic range without being too big. `u8` might give too little dynamic range for some applications, `u32` might be annoyingly big for smaller archs like AVR/MSP430.
- Range is `0..u16::MAX` instead of `0..get_max_duty()`. This makes the HAL instead of the user responsible for the scaling, which makes using the trait easier. Also, if the HAL wants to optimize for performance, it can set the hardware period to be a power of 2, so scaling is just a bit shift.
- Name is `SetDuty` instead of `PwmPin`, because we might have a `SetFrequency` or similar in the future.
- I haven't included `get_duty()`, because I think in practice most drivers don't need it, and implementing it in HALs is annoying. They either have to read it back from hardware and unscaling it (losing precision), or storing the unscaled value in `self` (wasting RAM). We could add a `GetDuty` or `StatefulSetDuty` in the future if it turns out this is wanted, but I hope it won't be.

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
Co-authored-by: Grant Miller <GrantM11235@gmail.com>
2023-03-14 19:43:21 +00:00
Dario Nieuwenhuis
002786df37 asyn/serial: add Write. 2023-03-08 00:33:14 +01:00
Dario Nieuwenhuis
78a6f06322 Add changelog. 2023-03-07 20:55:54 +01:00
Dario Nieuwenhuis
d5f9747a06 pwm: Rename "duty" to "duty cycle". 2023-03-07 20:55:09 +01:00
Grant Miller
3f53ffc9dd Add #[inline] to provided methods 2023-03-07 20:55:09 +01:00
Grant Miller
ff0b1ced64 Add get_max_duty() and convenience methods 2023-03-07 20:55:09 +01:00
Dario Nieuwenhuis
e8199411d5 Add PWM SetDuty trait. 2023-03-07 20:55:09 +01:00
bors[bot]
b036e16030 Merge #432
432: delay: make infallible. r=therealprof a=Dirbaio

1.0 alphas have been out for a while, some HALs out there implement it. I haven't seen one with an actual fallible delay.

I know the decision was made to make Delay fallible for consistency, but I think we should make one exception for just this one trait. 

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2023-03-07 19:46:55 +00:00
Dario Nieuwenhuis
d3f8fe6b2f delay: make infallible. 2023-02-28 21:41:14 +01:00
bors[bot]
e8d94e9895 Merge #439
439: Use github action dtolnay/rust-toolchain@master instead of actions-rs r=Dirbaio a=jannic

actions-rs/toolchain@v1 uses deprecated features and has not been updated for years

Co-authored-by: Jan Niehusmann <jan@gondor.com>
2023-02-28 20:40:32 +00:00
Jan Niehusmann
9e4d4794e9 Update github workflows to actions/checkout@v3 2023-02-28 20:25:06 +00:00
Jan Niehusmann
ed9e0c13f1 Use github action dtolnay/rust-toolchain@master instead of actions-rs/toolchain@v1
actions-rs/toolchain@v1 uses deprecated features and has not been updated for years
2023-02-28 20:25:06 +00:00
bors[bot]
ef20420015 Merge #431
431: gpio: add ErrorKind. r=Dirbaio a=Dirbaio

This adds an `ErrorKind` to the GPIO `Error` associated type, just like all the other drivers. It has just a single `Other` variant for now. 

The reason to have it is future-proofness: Even if we don't have ideas for ErrorKind variants for now, we might have them in the future.

- If we have `ErrorKind`, we can add more variants in the future backwards-compatibly after the 1.0 launch, thanks to `ErrorKind` being marked `#[non_exhaustive]`.
- If we *don't* have `ErrorKind`, adding it in the future would be a breaking change, because HALs would have to add support for it.

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2023-02-28 20:23:09 +00:00
bors[bot]
010dc85fa9 Merge #438
438: Bump MSRV to 1.59, switch to Edition 2021. Fix CI. r=therealprof a=Dirbaio

Bump MSRV to 1.59, switch to Edition 2021.

Fixes CI, It broke due to yanking `cortex-m-rt 0.71` due to the stack align bug.

~~I don't think the MSRV should matter for `dev-dependencies`? They're only required for running tests, bumping it doesn't affect crates using `embedded-hal` as a regular dep.~~ of course *out* CI requires it, duh.

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2023-02-28 20:19:58 +00:00
Dario Nieuwenhuis
d36ddc2009 Bump MSRV to 1.59, switch to Edition 2021. 2023-02-28 21:09:10 +01:00
Dario Nieuwenhuis
02aade1224 Fix CI. 2023-02-28 20:56:18 +01:00