mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2024-12-24 05:01:31 +11:00
f8984a9eac
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 `&`. |
||
---|---|---|
.. | ||
pico_blinky.rs | ||
pico_countdown_blinky.rs | ||
pico_gpio_in_out.rs | ||
pico_hd44780_display.rs | ||
pico_i2c_oled_display_ssd1306.rs | ||
pico_i2c_pio.rs | ||
pico_pio_pwm.rs | ||
pico_pwm_blink.rs | ||
pico_pwm_servo.rs | ||
pico_rtic.rs | ||
pico_spi_sd_card.rs | ||
pico_uart_irq_buffer.rs | ||
pico_uart_irq_echo.rs | ||
pico_usb_serial.rs | ||
pico_usb_serial_interrupt.rs | ||
pico_usb_twitchy_mouse.rs | ||
pico_ws2812_led.rs | ||
pwm.pio |