Commit Graph

278 Commits

Author SHA1 Message Date
Diego Barrios Romero
fdda379562 Add html root url 2020-11-11 14:13:09 +01:00
bors[bot]
b0d99b5cb4 Merge #260
260: Transactional I2C address modes r=ryankurte a=eldruin

The transactional I2C traits did not support multiple address modes.
Thanks to @ryankurte for noticing this at https://github.com/rust-embedded/linux-embedded-hal/pull/44

Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2020-11-09 22:13:19 +00:00
Diego Barrios Romero
ba03c1ac0b Add example of I2C trait default implementations 2020-11-09 10:51:17 +01:00
Diego Barrios Romero
5b97a328b3 Fix support for addressing modes in I2C transactional traits 2020-11-09 10:50:16 +01:00
bors[bot]
a5789bfcdd Merge #259
259: Update manifest/changelog for v1.0.0-alpha.3 release r=eldruin a=ryankurte

How do we feel about another alpha release now we've landed transactional SPI and I2C?

- Updated version in `Cargo.toml`
- Updated `CHANGELOG.md`

Note: create `v1.0.0-alpha.3` tag following merge

Co-authored-by: ryan <ryan@kurte.nz>
v1.0.0-alpha.3
2020-11-04 13:56:24 +00:00
ryan
5814ce1068 Update manifest/changelog for v1.0.0-alpha.3 release 2020-11-04 15:32:26 +13:00
bors[bot]
95de0e0002 Merge #223
223: Add transactional I2C interface r=therealprof a=eldruin

An example where a transactional I2C interface would be an improvement is when facing the problem of sending an array of data where the first item is the destination address.
At the moment this requires copying the data into a bigger array and assigning the first item to the address. With a transactional I2C two `write` operations could be chained into one transaction so that it is possible to send the address and data without an extra copy.
This is specially problematic if the data length is unknown e.g. because it comes from the user.

You can see the problem [here in the eeprom24x driver](f75770c6fc/src/eeprom24x.rs (L220)). In this case I am lucky enough to have the page upper limit so that the copy workaround is possible.

With this PR a bunch of code and macros could be replaced by doing something similar to this:
```rust
let user_data = [0x12, 0x34, ...]; // defined somewhere else. length may be unknown.
let target_address = 0xAB;
let mut ops = [
  Operation::Write(&[target_address]),
  Operation::Write(&user_data),
];
i2cdev.try_exec(DEV_ADDR, &ops)
```

I added a PoC [here in linux-embedded-hal](7512dbcc09/src/lib.rs (L211)) including [an example](https://github.com/eldruin/linux-embedded-hal/blob/transactional-i2c/examples/transactional-i2c.rs) of a driver where a classical combined write/read is performed through the transactional interface.

Note: A default implementation of the `Transactional` trait like in #191 is not possible because STOPs would always be sent after each operation. What is possible is to do is the other way around. This includes an implementation of the `Write`, `Read` and `WriteRead` traits for `Transactional` implementers.

This is based on previous work from #178 by @ryankurte and it is similar to #191 

TODO:
- [x] Add changelog entry

Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2020-10-30 21:49:00 +00:00
bors[bot]
da78c820f4 Merge #258
258: Clarify usage of alpha releases r=therealprof a=eldruin



Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2020-10-30 21:39:43 +00:00
Diego Barrios Romero
713231739c Clarify usage of alpha releases 2020-10-30 09:39:04 +01:00
Diego Barrios Romero
88e413323b Add transactional I2C to changelog and remove misplaced entry in alpha.2 2020-10-30 08:59:51 +01:00
Diego Barrios Romero
cfa13de2e9 Add iterator version of transactional interface 2020-10-30 08:49:06 +01:00
Diego Barrios Romero
6b562e0a23 Add Transactional I2C trait to prelude 2020-10-30 08:49:06 +01:00
Diego Barrios Romero
1bc7d95c05 Update src/blocking/i2c.rs
Co-authored-by: Daniel Egger <daniel@eggers-club.de>
2020-10-30 08:49:06 +01:00
Diego Barrios Romero
3d5a165161 Add default implementation of i2c traits for transactional implementers 2020-10-30 08:49:06 +01:00
Diego Barrios Romero
7766a5b9c3 Use Operation slice type for consistency 2020-10-30 08:49:06 +01:00
Diego Barrios Romero
749ebffd67 Add transactional I2C trait 2020-10-30 08:49:06 +01:00
bors[bot]
bbb79cdda2 Merge #257
257: Added SPI transactional interface to changelog r=therealprof a=ryankurte

Missing from #191

cc. @therealprof 

Co-authored-by: ryan <ryan@kurte.nz>
2020-10-28 19:36:12 +00:00
ryan
8a9856caa7 Added SPI transactions to changelog 2020-10-29 08:30:51 +13:00
bors[bot]
7884660a8f Merge #191
191: Added transactional SPI interface r=therealprof a=ryankurte

This PR adds a transactional interface for SPI devices (#94), compatible with linux spidev.

Split from #178 as I believe this is complete and useful, but that there is more experimentation required before (if?) the I2C component is landed, check there for previous reviews / discussion.

**Demonstrated in:**
- Linux embedded hal: https://github.com/rust-embedded/linux-embedded-hal/pull/35
- STM32F4xx-hal: https://github.com/stm32-rs/stm32f4xx-hal/pull/167
- embedded-spi driver abstraction (previously provided a polyfill for equivalent transactional functionality) https://github.com/ryankurte/rust-embedded-spi/pull/4/files#diff-74eea42f4e5e15399ac9184c8f2727a9R344
- sx128x radio driver: https://github.com/ryankurte/rust-radio-sx128x/pull/5


**Notes:**
- `Operation::Transfer` uses one buffer to allow polyfill using the existing `Transfer` trait (with the convenient side effect of reducing memory requirements)
- `W` has a static bound as it _should_ only ever be a type with static lifetime (u8, u16 etc., not a reference), and to differentiate this from `'a` which is the lifetime of the data in the object and only bound to the function
- `exec(.., &mut [Operation])` is chosen over `exec<O: AsMut<[Operation]>(..)` as the latter imposes limits on generic types using this trait (which i ran into, see [E0038](https://doc.rust-lang.org/error-index.html#E0038))

cc. @rust-embedded/hal folks, @eldruin, @RandomInsano, @rahix, @austinglaser for opinions / review

Co-authored-by: Ryan Kurte <ryankurte@gmail.com>
Co-authored-by: ryan <ryan@kurte.nz>
2020-10-28 07:51:00 +00:00
ryan
c66420be3c apply cargo fmt 2020-10-27 11:58:55 +13:00
bors[bot]
646bfeaf16 Merge #255
255: Release version 1.0.0-alpha.2 r=therealprof a=ryankurte

i forgot about bors and `cargo-release`'d this so, package is already live on crates.io :-/

(maybe it would be worth looking into releasing with tags via CI? but perhaps this is also more annoying)

related to #177 

Co-authored-by: ryan <ryan@kurte.nz>
v1.0.0-alpha.2
2020-10-15 21:20:14 +00:00
ryan
cbb53a175f Update changelog 2020-10-16 10:14:32 +13:00
ryan
502d52ddf5 (cargo-release) version 1.0.0-alpha.2 2020-10-16 09:59:52 +13:00
bors[bot]
314d25bd0b Merge #254
254: Remove futures examples r=therealprof a=eldruin

The `futures`-based examples are stuck on `futures` `0.1`, require nightly to run the tests and do not represent how asynchronous processing will be done in embedded any more.
In the `0.2.x` version these examples are still present. See [here](https://docs.rs/embedded-hal/0.2.4/embedded_hal/).
See [async/await on embedded Rust](https://ferrous-systems.com/blog/async-on-embedded/).
See #251 

Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2020-10-08 08:11:21 +00:00
Diego Barrios Romero
23557a5445 Run tests also on CI 2020-10-08 09:24:07 +02:00
Diego Barrios Romero
2f292c5c8b Remove futures examples 2020-10-07 08:39:04 +02:00
bors[bot]
8d31893982 Merge #251
251: Update reference implementation implementation to stm32f1xx-hal and update examples r=therealprof a=eldruin

I think the `stm32f1xx-hal` is a good candidate for a reference implementation.
I have also updated the examples accordingly and modernized them a bit.

An additional possibility would be to remove the `futures` examples as well, since async handling will be different.

Closes #156 

Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2020-10-06 20:02:02 +00:00
Diego Barrios Romero
0fd1720ea9 Mark stm32f1xx-hal as the reference implementation 2020-10-02 10:16:59 +02:00
Diego Barrios Romero
ba2f638638 Rewrite examples for stm32f1 2020-10-02 10:16:35 +02:00
Diego Barrios Romero
0477d1f79e Remove await example 2020-10-02 10:15:27 +02:00
bors[bot]
96e6c7cda3 Merge #250
250: Make use of nb explicit r=therealprof a=eldruin



Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2020-10-02 08:05:21 +00:00
Diego Barrios Romero
0e23a0fa2e Make use of nb explicit 2020-10-02 10:02:18 +02:00
bors[bot]
140255ed15 Merge #170
170: Remove unsupported examples for hal r=eldruin a=no111u3

Remove stm32f3 hal implementation as dependency and it's examples from runned doc tests.
Following the #156 

Co-authored-by: Boris Vinogradov <no111u3@gmail.com>
2020-09-17 09:38:23 +00:00
bors[bot]
ea5b5ce5b1 Merge #120
120: Document implicit assumption in non-blocking spi trait r=therealprof a=david-sawatzke

It should only be able to read the data returned by the last write call. Otherwise the overflow handling isn't really possible when doing only write calls (at least on stm32f0). @therealprof and me came to this conclusion after chatting on irc that this is the intended usage of this api.

Co-authored-by: David Sawatzke <david-sawatzke@users.noreply.github.com>
Co-authored-by: David Sawatzke <d-git@sawatzke.dev>
Co-authored-by: david-sawatzke <david-sawatzke@users.noreply.github.com>
2020-09-16 12:43:05 +00:00
david-sawatzke
5bae50b7a0 Fix missed remaining send in FullDuplex documentation
Co-authored-by: Vadim Kaushan <admin@disasm.info>
2020-09-16 13:43:38 +02:00
bors[bot]
6f172879c7 Merge #239
239: Add try_set_state method for OutputPin r=therealprof a=eldruin

This is an implementation of #200 to gather some opinions and so we can either accept it or close the issue.
This was earlier discussed at #44.

I added a conversion from `bool` following the usual convention as well as an `ops::Not` implementation as suggested in #200, which seemed appropriate.

I also added a default implementation for the `try_set_state` method. This bears the question whether a default implementation for `try_set_high()` / `try_set_low()` by using `try_set_state()` would be useful, so that potential implementors can choose to implement less methods.

It should be noted that adding a default implementation for all 3 methods has the somewhat amusing property of generating an endless loop if none is overwritten.

Closes #200 

Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2020-09-14 08:01:54 +00:00
bors[bot]
61671568b2 Merge #242
242: Make ADC Channel trait use a stateful method to get the IDs r=therealprof a=eldruin

Closes #110 

Co-authored-by: Diego Barrios Romero <eldruin@gmail.com>
2020-08-31 08:23:51 +00:00
Diego Barrios Romero
73b54adf05 Make ADC Channel trait use a stateful method to get the IDs 2020-08-04 23:08:20 +02:00
David Sawatzke
b8df447267 Update documentation for FullDuplex to try_ methods 2020-07-27 18:55:05 +02:00
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
Diego Barrios Romero
f90d9d182a Add try_set_state method for OutputPin 2020-07-22 09:54:10 +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