Commit Graph

235 Commits

Author SHA1 Message Date
David Sawatzke
ce8a7b9729 Document implicit assumption about the blocking behaviour of the calls 2020-07-27 18:52:33 +02:00
David Sawatzke
c4a8eb7b84 Document implicit assumption in spi non-blocking trait 2020-07-27 18:52:33 +02:00
bors[bot]
d81cf7cdb3 Merge #238
238:  Pwm: allow get_duty to return the old value for some time r=therealprof a=eldruin

This is #140 applied to the `Pwm` trait as well, since the same concerns apply. Follows up on #236.

Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2020-07-22 07:52:17 +00:00
Diego Barrios Romero
0b0547874d Pwm: allow get_duty to return the old value for some time
PWM is often implemented in a buffered way to allow glitch-free
operation; as a result, implementing a strict "you get what you last
set" is not feasible for some implementations.
2020-07-22 09:33:52 +02:00
bors[bot]
5b898bba17 Merge #236
236: PwmPin: allow get_duty to return the old value for some time r=therealprof a=eldruin

This is #140 rebased to master.
However, I suppose the same thing applies to the `Pwm::try_get_duty()` method. Shouldn't the same note be added to that method as well?

Closes #140

Co-authored-by: chrysn <chrysn@fsfe.org>
2020-07-22 07:24:49 +00:00
chrysn
d26ccb9c88 PwmPin: allow get_duty to return the old value for some time
PWM is often implemented in a buffered way to allow glitch-free
operation; as a result, implementing a strict "you get what you last
set" is not feasible for some implementations.
2020-07-21 19:04:35 +02:00
bors[bot]
83f5beac72 Merge #230
230: Make I2C compatible with multiple address sizes r=ryankurte a=eldruin

This adds I2C 7-bit and 10-bit address mode compatibility as roughly described [here](https://github.com/rust-embedded/embedded-hal/issues/147#issuecomment-511703503).
Discussion issue: #147 

I have also added the `SevenBitAddress` as the default address mode to the traits so this is not even a breaking change.

Usage broken down per use case:
* **Device driver which only supports 7-bit addressing mode:**
       The driver looks exactly the same as now since the default address mode is 7-bit.

```rust
 impl<I2C, E> MyDriver<I2C>
 where I2C: i2c::Write<Error = E> {
   pub fn do_cool_stuff(&mut self) // ...
 }
 ```

* **Device driver which only supports 10-bit addressing mode:**
       The only difference to a 7-bit-address-only driver is one additional parameter in the I2C trait bound.
```rust
 impl<I2C, E> MyDriver<I2C>
 where I2C: i2c::Write<TenBitAddress, Error = E> {
   pub fn do_cool_stuff(&mut self) // ...
 }
 ```
 
* **Driver for device supporting both addressing modes:**
       Complexity can be abstracted away into additional internal traits which can handle the addressing stuff. Driver code stays clean.
       **This is nothing new**. We already do this on drivers for devices compatible with both I2C and SPI. No need for duplicated code.
       Here a real example: [usage](3af5637f1d/src/device_impl.rs (L43)), [traits](https://github.com/eldruin/bmi160-rs/blob/master/src/interface.rs)
  
 ```rust
 impl<DI, E> MyDriver<DI>
 where DI: WriteData<Error = E> {
   pub fn do_cool_stuff(&mut self) {} // ...
 }
 
 pub trait WriteData {
 // ...
 }
 
// it is also possible to just leave the `SevenBitAddress` type out here,
// since it is the default.
 impl<I2C, E> WriteData for I2cInterface<I2C, SevenBitAddress>
 where
     I2C: i2c::Write<SevenBitAddress, Error = E>,
 {
   // ...
 }
 
 impl<I2C, E> WriteData for I2cInterface<I2C, TenBitAddress>
 where
     I2C: i2c::Write<TenBitAddress, Error = E>,
 {
   // ...
 }
 ```
 
* **Bus controller impl supporting only 7-bit addressing mode:**
       Code stays almost the same, just adding one addressing mode parameter. Additionally, _if desired_:
    * 10-bit addressing can be software-emulated:
         Emulate by extending and copying payload in separate `TenBitAddress` implementation. Total flexibility to do whatever is necessary in this case since the code is independent.
    * 10-bit addressing cannot be software-emulated:
         Implementation does not offer implementation for `TenBitAddress` variant. The user gets a compilation error and everything is clear.
 
* **Bus controller impl supporting both addressing modes:**
       No problem. Two separate implementations guarantee as much flexibility as necessary. At the same time, sharing generic code is possible.
  
 Additional benefits: 
* No runtime performance cost 
* No runtime switching, duplicated code or panics for unsupported modes. 
* Consistent with what we do for code paths that can be determined statically by the compiler.
* To my taste elegant, simple and very descriptive.

See [here](https://github.com/rust-embedded/embedded-hal/issues/147#issuecomment-647157906) for a comparison to other alternatives.

I have also sealed the trait.

## Proof
* A HAL implementation of both modes: [bitbang-hal](https://github.com/eldruin/bitbang-hal/tree/i2c-multi-address-mode). [code changes](https://github.com/eldruin/bitbang-hal/compare/embedded-hal-1.0.0-alpha.1...eldruin:i2c-multi-address-mode)
* Drivers supporting only 7-bit addresses need **no changes**.
For demonstration purposes, explicitly including the `SevenBitAddress` would look like this: [OPT300x](https://github.com/eldruin/opt300x-rs/tree/i2c-multi-address-mode). [code changes](https://github.com/eldruin/opt300x-rs/compare/i2c-multi-address-mode).
This would be similar to the case of a 10-bit-only device driver.

Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2020-07-16 23:17:42 +00:00
Diego Barrios Romero
d8187c3d62 Support 7-bit and 10-bit I2C address modes 2020-07-16 08:49:34 +02:00
bors[bot]
d983a3d916 Merge #222
222: Improve watchdog API design using move semantics r=therealprof a=luojia65

This pull request improved watchdog API design. When starting watchdog, we may convert it into another type. We may implement different functions for this type. Or downstream developers can implement `Watchdog` for only an enabled type, to prevent feed to disabled watchdogs or forget to enable before feeding. If we are able to stop this watchdog, it can be converted into the former type.

If current design still need a same type after the watchdog is enabled, they may use `Target = Self`. In this way we create a fallback for earlier designs. 

A simple proof of concept: [here](https://github.com/gd32v-rust/gd32vf103-hal/blob/new-watchdog-design/src/wdog.rs#L155-L169) (L120-L153 for its `Enable` implementation, and there is `Disable` implementation)

Related issue: https://github.com/rust-embedded/embedded-hal/issues/98
Earlier discussion: https://github.com/rust-embedded/embedded-hal/pull/76#issuecomment-417413406

Co-authored-by: luojia65 <me@luojia.cc>
Co-authored-by: Luo Jia <account@luojia.cc>
2020-07-15 13:06:31 +00:00
Luo Jia
599d44fdc7 Merge branch 'master' into new-watchdog-design 2020-07-15 20:54:35 +08:00
luojia65
8a7500b262 Improve watchdog API design using move semantics
Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>

Co-authored-by: Daniel Egger <@therealprof:matrix.org>
2020-07-15 20:48:21 +08:00
bors[bot]
b46d300816 Merge #234
234: Use nb 1.0 r=eldruin a=eldruin

🎉 

Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2020-07-13 08:19:13 +00:00
Diego Barrios Romero
e09d57b8d0 Use nb 1.0 2020-07-13 07:27:52 +02:00
bors[bot]
c2f15c6e8f Merge #231
231: Rename I2C iterator write method for consistency r=therealprof a=eldruin



Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2020-07-05 11:18:24 +00:00
Diego Barrios Romero
a61cc4f4dd Rename I2C iterator write method for consistency 2020-07-05 09:46:02 +02:00
bors[bot]
f88ddc5ae4 Merge #228
228: Standardize address wording r=therealprof a=eldruin

For consistency.
Credit goes to @BroderickCarlin for noticing in #147.

Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2020-06-21 16:31:24 +00:00
Diego Barrios Romero
69606d40cc Standardize address wording 2020-06-21 18:15:29 +02:00
bors[bot]
70bed3a7d5 Merge #227
227: Add missing traits to prelude r=therealprof a=eldruin

Fixes #225 

Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2020-06-21 11:17:06 +00:00
Diego Barrios Romero
e78c0a02a8 Add missing traits to prelude 2020-06-21 12:48:14 +02:00
luojia65
a31192fd27 Another probable watchdog API design (issue #98) 2020-06-16 17:51:13 +08:00
bors[bot]
036cfa48e4 Merge #219
219: v1.0.0 alpha release r=therealprof a=ryankurte

🎉🎊🥳


See #177 for progress on blocking issues

Co-authored-by: ryan kurte <ryankurte@gmail.com>
Co-authored-by: Daniel Egger <daniel@eggers-club.de>
v1.0.0-alpha.1
2020-06-16 01:12:01 +00:00
bors[bot]
f72c91dd1d Merge #221
221: Enable doctests and fix them r=therealprof a=eldruin

I discovered that due to a typo some doctests were not being run.
A couple small fixes were also necessary for them to compile.

Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2020-06-16 00:52:14 +00:00
Daniel Egger
347abaf8e4 Update CHANGELOG to fix organisation and added tags
Signed-off-by: Daniel Egger <daniel@eggers-club.de>
2020-06-16 02:50:10 +02:00
Diego Barrios Romero
ed7de7aa9e Enable doctests and fix them 2020-06-10 08:16:45 +02:00
ryan kurte
42e98dc041 Update cargo.toml, changelog for v1.0.0 release 2020-06-10 14:22:41 +12:00
bors[bot]
e626c848a7 Merge #216
216: Switch from Travis to GitHub actions r=ryankurte a=therealprof

Signed-off-by: Daniel Egger <daniel@eggers-club.de>

Co-authored-by: Daniel Egger <daniel@eggers-club.de>
2020-06-02 21:32:20 +00:00
Daniel Egger
33e16f1ed9 Don't run rustfmt and clippy multiple times per PR
Signed-off-by: Daniel Egger <daniel@eggers-club.de>
2020-06-02 23:18:26 +02:00
Daniel Egger
63b5e3886d Add adjusted bors configuration
Signed-off-by: Daniel Egger <daniel@eggers-club.de>
2020-06-02 23:18:26 +02:00
Daniel Egger
1e512886c2 Switch from Travis to GitHub actions
Signed-off-by: Daniel Egger <daniel@eggers-club.de>
2020-06-02 23:18:26 +02:00
bors[bot]
1d6e6ae70e Merge #217
217: Restrict ADC ID type to Copy types r=ryankurte a=therealprof

This fixes a deny-by-default clippy lint:

```
error: a `const` item should never be interior mutable
  --> src/adc.rs:47:5
   |
47 |     const CHANNEL: Self::ID;
   |     ^^^^^^^^^^^^^^^--------^
   |                    |
   |                    consider requiring `<Self as adc::Channel<ADC>>::ID` to be `Copy`
   |
   = note: `#[deny(clippy::declare_interior_mutable_const)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#declare_interior_mutable_const
```

Signed-off-by: Daniel Egger <daniel@eggers-club.de>

Co-authored-by: Daniel Egger <daniel@eggers-club.de>
2020-06-02 21:06:08 +00:00
Daniel Egger
4a5f512ea7 Restrict ADC ID type to Copy types
This fixes a deny-by-default clippy lint:

```
error: a `const` item should never be interior mutable
  --> src/adc.rs:47:5
   |
47 |     const CHANNEL: Self::ID;
   |     ^^^^^^^^^^^^^^^--------^
   |                    |
   |                    consider requiring `<Self as adc::Channel<ADC>>::ID` to be `Copy`
   |
   = note: `#[deny(clippy::declare_interior_mutable_const)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#declare_interior_mutable_const
```

Signed-off-by: Daniel Egger <daniel@eggers-club.de>
2020-06-02 22:21:05 +02:00
bors[bot]
181d44bb13 Merge #202
202: Add triagebot configuration r=ryankurte a=LeSeulArtichaut

This enables [assignment](https://github.com/rust-lang/triagebot/wiki/Assignment) through triagebot on this repository, in preparation for the migration from highfive to triagebot for PR assignment.

cc rust-lang/highfive#258 rust-lang/triagebot#433

Co-authored-by: LeSeulArtichaut <leseulartichaut@gmail.com>
2020-04-13 22:23:56 +00:00
LeSeulArtichaut
58160be492 Add triagebot configuration 2020-04-13 14:29:01 +02:00
bors[bot]
cad3b0c190 Merge #198
198: Add MSRV configuration to CI r=therealprof a=eldruin

The compatibility with the MSRV should be checked by the CI. At the moment that is Rust 1.35.0 due to [this issue](https://github.com/rust-lang/rust/issues/54973).
The MSRV and its update process should probably also be documented in the README.

Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2020-04-13 10:38:25 +00:00
Diego Barrios Romero
c61e421d9f Add note about MSRV on README 2020-04-08 09:11:18 +02:00
bors[bot]
3f22b003b1 Merge #197
197: Updated readme with new process r=therealprof a=ryankurte

Updated process from [hal-meeting](https://hackmd.io/ck-xRXtMTmKYXdK5bEh82A?view)

Co-authored-by: ryan <ryan@kurte.nz>
Co-authored-by: Ryan <ryankurte@users.noreply.github.com>
2020-04-07 22:48:42 +00:00
Ryan
d6a9166dae Update README.md
Co-Authored-By: Daniel Egger <daniel@eggers-club.de>
2020-04-08 09:47:40 +12:00
Diego Barrios Romero
34b0a7a523 Add MSRV configuration to CI 2020-04-06 21:51:23 +02:00
ryan
74e70253d4 Updated readme with new process 2020-04-05 10:34:27 +12:00
bors[bot]
e82ddb8f8a Merge #196
196: Document moved traits in changelog r=ryankurte a=eldruin

This was missing in #195.

Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2020-04-04 22:16:11 +00:00
Diego Barrios Romero
2463c6fce3 Document moved traits in changelog 2020-04-04 14:05:18 +02:00
bors[bot]
adf7f9b788 Merge #195
195: Separate Capture, Pwm and Qei traits into modules r=ryankurte a=eldruin

The `lib.rs` file is already _very_ long. I propose separating these traits which are just at the end of the file into their own modules.
I have kept the modules private and reexported the traits and types to maintain the same interface.
However, for consistency with the other traits maybe it would be worth it to expose these new modules as well and not reexport the traits in `lib.rs`.
What do you think?

Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2020-04-02 21:46:16 +00:00
Diego Barrios Romero
60c9263a83 Expose capture, pwm and qei modules only for consistency 2020-03-19 20:00:10 +01:00
Diego Barrios Romero
39f215e2bc Separate Capture, Pwm and Qei traits into modules 2020-03-16 07:21:48 +01:00
bors[bot]
88412b9666 Merge #192
192: [towards 1.0]: Fallible proven traits r=thejpster a=eldruin

Here some work towards 1.0 following https://github.com/rust-embedded/embedded-hal/issues/177#issuecomment-597682592.

Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2020-03-16 00:05:41 +00:00
Diego Barrios Romero
ee56d1e736 Make ADC Channel::channel() a constant and update MSRV to 1.35 2020-03-14 11:23:50 +01:00
Diego Barrios Romero
5bc0f0c85d Update changelog 2020-03-12 08:57:07 +01:00
Diego Barrios Romero
90c3c3e922 Remove unproven feature 2020-03-12 08:54:22 +01:00
Diego Barrios Romero
4a4ff0c923 use core instead of std 2020-03-12 08:47:30 +01:00
Diego Barrios Romero
750f0be0c4 Rename methods try_* for consistency 2020-03-12 08:44:19 +01:00