rp-hal-boards/boards/rp-pico/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
..
pico_blinky.rs Merge pull request #324 from 9names/bsp_use_hal_entry_macro 2022-05-31 23:41:45 +10:00
pico_countdown_blinky.rs Merge pull request #324 from 9names/bsp_use_hal_entry_macro 2022-05-31 23:41:45 +10:00
pico_gpio_in_out.rs Merge pull request #324 from 9names/bsp_use_hal_entry_macro 2022-05-31 23:41:45 +10:00
pico_hd44780_display.rs Port HD44780 display example from rp2040-hal to rp-pico (#347) 2022-05-31 23:08:02 +10:00
pico_i2c_oled_display_ssd1306.rs Implement conversion from Clock to Hertz using reference 2022-07-22 20:17:26 +00:00
pico_i2c_pio.rs Implement conversion from Clock to Hertz using reference 2022-07-22 20:17:26 +00:00
pico_pio_pwm.rs Add pio pwm example (#365) 2022-06-26 22:11:41 +10:00
pico_pwm_blink.rs Merge pull request #324 from 9names/bsp_use_hal_entry_macro 2022-05-31 23:41:45 +10:00
pico_pwm_servo.rs Add Pico PWM micro servo example (#346) 2022-05-26 22:25:49 +10:00
pico_rtic.rs Abstract alarms 2022-04-30 11:54:54 +10:00
pico_spi_sd_card.rs Merge pull request #324 from 9names/bsp_use_hal_entry_macro 2022-05-31 23:41:45 +10:00
pico_uart_irq_buffer.rs Implement conversion from Clock to Hertz using reference 2022-07-22 20:17:26 +00:00
pico_uart_irq_echo.rs Implement conversion from Clock to Hertz using reference 2022-07-22 20:17:26 +00:00
pico_usb_serial.rs Merge pull request #324 from 9names/bsp_use_hal_entry_macro 2022-05-31 23:41:45 +10:00
pico_usb_serial_interrupt.rs Merge pull request #324 from 9names/bsp_use_hal_entry_macro 2022-05-31 23:41:45 +10:00
pico_usb_twitchy_mouse.rs Merge pull request #324 from 9names/bsp_use_hal_entry_macro 2022-05-31 23:41:45 +10:00
pico_ws2812_led.rs Merge pull request #324 from 9names/bsp_use_hal_entry_macro 2022-05-31 23:41:45 +10:00
pwm.pio Add pio pwm example (#365) 2022-06-26 22:11:41 +10:00