Commit graph

11 commits

Author SHA1 Message Date
Jan Niehusmann f8984a9eac Implement conversion from Clock to Hertz using reference
Implementing `impl From<SystemClock> for Hertz` is a footgun, as
SystemClock is not Copy, so the automatic conversion consumes the
owned clock.

This is visible in the example i2c.rs:

```
    let mut i2c = hal::I2C::i2c1(
        pac.I2C1,
        sda_pin,
        scl_pin, // Try `not_an_scl_pin` here
        400.kHz(),
        &mut pac.RESETS,
        clocks.peripheral_clock,
    );
```

If the user wants to use both `i2c0` and `i2c1` at the same time,
copying from this example won't work:

```
error[E0382]: use of moved value: `clocks.peripheral_clock`
   --> rp2040-hal/examples/i2c.rs:106:9
    |
97  |         clocks.peripheral_clock,
    |         ----------------------- value moved here
...
106 |         clocks.peripheral_clock,
    |         ^^^^^^^^^^^^^^^^^^^^^^^ value used here after move
    |
    = note: move occurs because `clocks.peripheral_clock` has type
`PeripheralClock`, which does not implement the `Copy` trait
```

As getting the frequency from a clock doesn't really need ownership,
changing it to `impl From<&SystemClock> for Hertz` is both more
logical and provides better usability.

This is, however, a breaking change: Code relying on this trait
implementation needs to be changed by adding a `&`.
2022-07-22 20:17:26 +00:00
mqy 623457a498 fixed typos 2022-04-30 12:51:45 +10:00
Victor Koenders 86444448a4
Migrated examples to the new uart system 2021-12-25 09:46:40 +01:00
Jonathan 'theJPster' Pallant b94a5ab885
Merge pull request #232 from jannic/refactor-uart-init
Refactor uart init
2021-12-05 18:02:44 +00:00
Jan Niehusmann 26fa532fa3 Refactor Uart initialization 2021-12-03 21:24:50 +00:00
9names 55a8b4acf9 Re-export mod structs 2021-12-04 00:04:45 +11:00
Jonathan Pallant (42 Technology) 8e66ddcfb1 Switch to new rp2040-boot2 crate. 2021-10-18 10:53:17 +01:00
Jonathan Pallant (42 Technology) d251627e47 Make trait comments more consistent. 2021-09-27 19:01:46 +01:00
Jonathan Pallant (42 Technology) 07c183a636 Remove hard coded clock speed from ADC example. 2021-09-27 17:29:50 +01:00
Jonathan Pallant (42 Technology) ed27dc9949 Update ADC example. 2021-09-27 14:42:19 +01:00
9names 9d2e18dc70
Add ADC example and doc-example (#93) 2021-09-02 22:40:13 +10:00