mirror of
https://github.com/italicsjenga/rp-hal-boards.git
synced 2024-12-24 13:11:30 +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 `&`. |
||
---|---|---|
.. | ||
clocks | ||
float | ||
gpio | ||
i2c | ||
pwm | ||
rtc | ||
uart | ||
adc.rs | ||
atomic_register_access.rs | ||
critical_section_impl.rs | ||
dma.rs | ||
i2c.rs | ||
intrinsics.rs | ||
lib.rs | ||
multicore.rs | ||
pio.rs | ||
pll.rs | ||
prelude.rs | ||
resets.rs | ||
rom_data.rs | ||
rosc.rs | ||
sio.rs | ||
spi.rs | ||
ssi.rs | ||
time.rs | ||
timer.rs | ||
typelevel.rs | ||
usb.rs | ||
watchdog.rs | ||
xosc.rs |