rp-hal-boards/rp2040-hal/examples
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
..
adc.rs Implement conversion from Clock to Hertz using reference 2022-07-22 20:17:26 +00:00
blinky.rs fixed typos 2022-04-30 12:51:45 +10:00
dht11.rs fixed typos 2022-04-30 12:51:45 +10:00
gpio_in_out.rs fixed typos 2022-04-30 12:51:45 +10:00
gpio_irq_example.rs fixed typos 2022-04-30 12:51:45 +10:00
i2c.rs Implement conversion from Clock to Hertz using reference 2022-07-22 20:17:26 +00:00
lcd_display.rs fixed typos 2022-04-30 12:51:45 +10:00
multicore_fifo_blink.rs Make Multicore take SioFifo rather than the whole Sio & make the spawn closure the last argument 2022-05-08 18:24:49 +10:00
multicore_polyblink.rs Add multicore_polyblink example 2022-05-08 18:29:27 +10:00
pio_blink.rs Move uses of sio::Sio to Sio 2021-12-04 16:20:27 +11:00
pio_proc_blink.rs Prep for 0.4.0 release (#312) 2022-03-11 22:37:34 +11:00
pio_side_set.rs Prep for 0.4.0 release (#312) 2022-03-11 22:37:34 +11:00
pio_synchronized.rs Allow to start multiple state machines in sync (#301) 2022-03-18 20:55:31 +11:00
pwm_blink.rs fixed typos 2022-04-30 12:51:45 +10:00
rom_funcs.rs Implement conversion from Clock to Hertz using reference 2022-07-22 20:17:26 +00:00
spi.rs fixed typos 2022-04-30 12:51:45 +10:00
uart.rs fixed typos 2022-04-30 12:51:45 +10:00
watchdog.rs fixed typos 2022-04-30 12:51:45 +10:00