525 Commits

Author SHA1 Message Date
bors[bot]
b4d4aaed41
Try #394: 2022-09-06 20:14:40 +00:00
Dario Nieuwenhuis
6e285a4320 Update bors config. 2022-09-06 22:14:29 +02:00
Dario Nieuwenhuis
f1c4356543 Fix clippy lints. 2022-09-06 22:10:47 +02:00
Dario Nieuwenhuis
d93c9354da Actually deny clippy warnings. 2022-09-06 22:10:47 +02:00
Dario Nieuwenhuis
815fda507a Move embedded-hal to a subdir, add workspace, simplify CI. 2022-09-06 21:47:02 +02:00
Dario Nieuwenhuis
1dd5ccc4d3 Split nb and can traits to separate crates. 2022-09-05 02:03:58 +02:00
bors[bot]
1f87498690
Merge #403
403: Make the async SpiDevice trait unsafe to implement r=Dirbaio a=GrantM11235

This is necessary due to the raw pointer workaround.

Co-authored-by: Grant Miller <GrantM11235@gmail.com>
2022-09-04 21:43:16 +00:00
Grant Miller
597493d7e0 Make the async SpiDevice trait unsafe to implement 2022-08-29 15:36:36 -05:00
bors[bot]
d8ddd73355
Merge #400
400: e-h-bus: Add MSRV notice and prepare 0.1.0-alpha.0 release r=Dirbaio a=eldruin

🎉 

Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
embedded-hal-bus-v0.1.0-alpha.0
2022-08-17 16:43:56 +00:00
Diego Barrios Romero
b86fe26d1e Add e-h-bus to CI 2022-08-17 18:36:10 +02:00
Diego Barrios Romero
b92b0db993 Prepare e-h-bus 0.1.0-alpha.0 release 2022-08-17 18:27:01 +02:00
Diego Barrios Romero
b60c4ca254 Add MSRV notice 2022-08-17 18:26:26 +02:00
bors[bot]
da1a4d5dbb
Merge #398
398: Extract SPI exclusive device into shared crate r=Dirbaio a=eldruin

Some concerns have been raised regarding the error handling in `spi::blocking::ExclusiveDevice`.
I am not sure what the problem was, though.
I think `@GrantM11235` was the one to raise the concerns so maybe he can elaborate and then I can improve this description.
Since that struct is just a helpful wrapper for a very specific situation, I propose we move it out of `embedded-hal` itself. For example into an `embedded-hal-shared` crate (or some other name, feel free to bikeshed).

We should note that we (probably) have the same problem in `embedded-hal-async` where there is also an `ExclusiveDevice` for SPI, so if we create such a crate, we should agree on what to put in there:
1. Only blocking `ExclusiveDevice`
2. blocking + async `ExclusiveDevice`
3. any of the above + `RefCell`-based sharing
4. any of the above + some mutex / critical section

We should also note that the great `shared-bus` crate also solves some of these problems so we might also put (some?) of this there.

cc: `@Rahix`

Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2022-08-17 14:19:00 +00:00
Diego Barrios Romero
01ebca6681 Rename crate embedded-hal-bus 2022-08-16 21:47:40 +02:00
bors[bot]
a1806f7ed4
Merge #399
399: SpiDevice: add guidelines for behaviour of CS pin upon bus failures r=eldruin a=newAM

Currently the `SpiDevice` trait does not define the sequence of actions that occur after a bus error.

I discussed this with `@Dirbaio` in the matrix chat and the conclusion we reached was that this should be added to the documentation as a guideline to match what already exists for `ExclusiveDevice`.  The rationale for a guideline instead of a requirement is that SPI error recovery is implementation specific.

Co-authored-by: Alex Martens <alex@thinglab.org>
2022-08-15 06:17:19 +00:00
Alex Martens
cf6fdd45b9 SpiDevice: add guidelines for behaviour of CS pin upon bus failures 2022-08-14 15:13:02 -07:00
Diego Barrios Romero
0631aba39a Extract SPI exclusive device into shared crate 2022-08-10 07:37:30 +02:00
bors[bot]
d5cdf3388e
Merge #393
393: Remove IoPin r=eldruin a=Dirbaio

As discussed in #340 it's unclear if the current IoPin trait is the best way to go (tldr: due to the fact it changes type it's hard to own it in driver structs).

I propose temporarily removing it, to unblock the 1.0 release. When discussion settles on a final design, we can add it back.

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2022-08-09 13:21:15 +00:00
bors[bot]
8cf26d5f1e
Merge #396
396: spi: clarify traits are for master mode. r=eldruin a=Dirbaio

All dirvers out there assume the traitsare for master mode. However, there are some HALs
out there that impl the traits for SPI in slave mode, which will break when used with drivers.
(stm32f1xx-hal, stm32f4xx-hal, stm32l4xx-hal, probably more).

If we add SPI slave traits in the future, they should be a separate set of traits because the
API would look quite different:

- you'd want the API to give extra extra info about the transaction lengths: if you start a transfer with 256-byte buffer but the master only sends 10 bytes (sets CS low, sends 10 bytes, sets CS high),
you'd want `transfer` to return, saying "I got only 10 bytes", instead of hanging waiting for the other 246 bytes.
- The bus/device split doesn't make sense in slave mode.

Also IMO the `spi, spi_slave` naming is fine even if inconsistent, since the vast majority
of uses are master mode. I wouldn't name the `spi` module `spi_master`.

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2022-08-04 09:17:49 +00:00
Dario Nieuwenhuis
edc2a3f8d0 spi: clarify traits are for master mode.
All dirvers out there assume the traitsare for master mode. However, there are some HALs
out there that impl the traits for SPI in slave mode, which will break when used with drivers.
(stm32f1xx-hal, stm32f4xx-hal, stm32l4xx-hal, probably more).

If we add SPI slave traits in the future, they should be a separate set of traits because the
API would look quite different:

- you'd want the API to give extra extra info about the transaction lengths: if you start a transfer with 256-byte buffer but the master only sends 10 bytes (sets CS low, sends 10 bytes, sets CS high),
you'd want `transfer` to return, saying "I got only 10 bytes", instead of hanging waiting for the other 246 bytes.
- The bus/device split doesn't make sense in slave mode.

Also IMO the `spi, spi_slave` naming is fine even if inconsistent, since the vast majority
of uses are master mode. I wouldn't name the `spi` module `spi_master`.
2022-08-01 10:36:38 +02:00
bors[bot]
707b8c4b46
Merge #391
391: Change missing_docs from deny to warn. r=eldruin a=Dirbaio

It is annoying to get hard errors while developing, it prevents testing things out
without documenting them because it fails the build.

This changes it to warn, which has the same effect in CI (because it already has `RUSTFLAGS: '--deny warnings'`),
but still allows buildilng.

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2022-07-26 18:10:58 +00:00
Dario Nieuwenhuis
54c0759cbd Remove IoPin. 2022-07-26 15:09:15 +02:00
Dario Nieuwenhuis
df73bb3e99 Change missing_docs from deny to warn.
It is annoying to get hard errors while developing, it prevents testing things out
without documenting them because it fails the build.

This changes it to warn, which has the same effect in CI (because it already has `RUSTFLAGS: '--deny warnings'`),
but still allows buildilng.
2022-07-26 14:04:21 +02:00
bors[bot]
d04a2ed6fb
Merge #390
390: fix inverted logic in docs r=eldruin a=spookyvision



Co-authored-by: Anatol Ulrich <45840+spookyvision@users.noreply.github.com>
2022-07-26 07:44:34 +00:00
Anatol Ulrich
ce7b1b6898
Update CHANGELOG.md 2022-07-25 22:35:31 +02:00
Anatol Ulrich
190dfdc8c3
fix inverted logic in docs 2022-07-25 22:32:36 +02:00
bors[bot]
43cc9b9e2e
Merge #389
389: Remove old documentation about the `timer::CountDown` trait r=eldruin a=GrantM11235



Co-authored-by: Grant Miller <GrantM11235@gmail.com>
2022-07-01 19:13:17 +00:00
Grant Miller
a61616e037 Remove old documentation about the timer::CountDown trait 2022-07-01 13:27:59 -05:00
bors[bot]
eb0bf2be6b
Merge #388
388: Minor doc fix r=eldruin a=jannic



Co-authored-by: Jan Niehusmann <jan@gondor.com>
2022-06-22 19:34:22 +00:00
Jan Niehusmann
bc45726154 Minor doc fix 2022-06-21 21:21:52 +00:00
bors[bot]
ebf1c12dce
Merge #386
386: Prepare embedded-hal-async 0.1.0-alpha.1 release r=ryankurte a=eldruin



Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
embedded-hal-async-v0.1.0-alpha.1
2022-05-25 05:33:29 +00:00
Diego Barrios Romero
4b5b7d0f91 Prepare embedded-hal-async 0.1.0-alpha.1 release 2022-05-24 22:06:02 +02:00
Diego Barrios Romero
72669fe266 Update changelog 2022-05-24 22:02:18 +02:00
Diego Barrios Romero
ce92d133f5 Add more content to README 2022-05-24 22:01:47 +02:00
Diego Barrios Romero
96227943bc Update copyright year 2022-05-24 22:01:07 +02:00
Diego Barrios Romero
a7d9782901 Add badges to readme 2022-05-24 21:56:41 +02:00
bors[bot]
748f6f0438
Merge #384
384: Make `can::Id` usable as key in `BTreeMap` and `HashMap` r=eldruin a=usbalbin

Implement `Ord` and `Hash` for `can::Id` to make it usable as key in `BTreeMap` and `HashMap`

Co-authored-by: Albin Hedman <albin.hedman@dectron.se>
Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2022-05-13 20:03:47 +00:00
Diego Barrios Romero
0c066ad8bd
Update src/can/id.rs 2022-05-13 22:02:25 +02:00
Diego Barrios Romero
b657a93a65
Update CHANGELOG.md 2022-05-13 22:02:17 +02:00
Albin Hedman
da3b64ea31 Add documentation and update changelog 2022-05-11 08:01:19 +02:00
Albin Hedman
b14a937a9c Remove old tests 2022-05-11 07:33:34 +02:00
Albin Hedman
6a164ee34e Updated tests 2022-05-10 13:31:24 +02:00
Albin Hedman
bcdca453b2 Manually implement Ord according to CAN bus arbitration rules 2022-05-10 13:05:13 +02:00
Albin Hedman
fd280d5c85 Make can::Id usable as key in BTreeMap and HashMap by implementing Ord and Hash 2022-05-10 08:49:47 +02:00
bors[bot]
aa7408180f
Merge #383
383: async: remove useless `+ 'a` in TAITs. r=ryankurte a=Dirbaio

These aren't needed, they're already implied by the type having `'a` as a generic param.

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2022-05-04 05:08:42 +00:00
Dario Nieuwenhuis
c231a1dff5 async: remove useless + 'a in TAITs. 2022-05-04 03:50:06 +02:00
bors[bot]
3b8a4f8743
Merge #382
382: async/spi: make helpers default methods instead of an extension trait. r=ryankurte a=Dirbaio

It turns out you *can* have default methods on a GAT-based async trait. All
you have to do is move the TAITs out of the trait so Rust infers them
instead of the impl specifying them.

Impls can't override the methods, but they already couldn't before with
the extension trait.

This makes async SpiDevice more consistent with blocking, and makes the helpers
more discoverable.

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2022-05-03 23:22:44 +00:00
Dario Nieuwenhuis
14103be039 async/spi: make helpers default methods instead of an extension trait.
It turns out you *can* have default methods on a GAT-based async trait. All
you have to do is move the TAITs out of the trait so Rust infers them
instead of the impl specifying them.

Impls can't override the methods, but they already couldn't before with
the extension trait.

This makes async SpiDevice more consistent with blocking, and makes the helpers
more discoverable.
2022-05-03 23:54:02 +02:00
bors[bot]
58587e8de0
Merge #380
380: async/spi: replace the "give back the Bus" hack with a raw pointer. r=ryankurte a=Dirbaio

The async SPI trait contains a "hack" to workaround limitations in Rust's borrow checker: #347 

It turns out the hack doesn't allow many shared bus implementations, for example when using an async Mutex: The `transaction` method gets `&'a mut self`, and the closure wants `&'a mut Self::Bus`. This only works if the Bus is a direct field in `self`. In the mutex case, the Bus has to come from inside the `MutexGuard`, so it'll live for less than `'a`.

See https://gist.github.com/kalkyl/ad3075182d610e7b413b8bbe1228ab90 which fails with the following error:

```
error[E0597]: `bus` does not live long enough
  --> src/shared_[spi.rs:78](http://spi.rs:78/):34
   |
63 |     fn transaction<'a, R, F, Fut>(&'a mut self, f: F) -> Self::TransactionFuture<'a, R, F, Fut>
   |                    -- lifetime `'a` defined here
...
78 |             let (bus, f_res) = f(&mut bus).await;
   |                                --^^^^^^^^-
   |                                | |
   |                                | borrowed value does not live long enough
   |                                argument requires that `bus` is borrowed for `'a`
...
89 |         }
   |         - `bus` dropped here while still borrowed
```

This is an alternative hack. If lifetimes don't work, simply don't use lifetimes at all! 

- Downside: it needs `unsafe{}` in all callers of transaction (but these should be rare, many users will use the `SpiDeviceExt` helpers.
- Upside: it's now possible to write sound shared bus impls.
- Upside: it no longer requires the "give back the bus" hack, it's now possible again to use `?` inside the closure for error handling.

cc `@kalkyl`

Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
2022-04-27 00:15:30 +00:00
Dario Nieuwenhuis
8cf16a78d3 async/spi: replace the "give back the Bus" hack with a raw pointer. 2022-04-26 20:06:04 +02:00