diff --git a/boards/rp-pico/examples/pico_i2c_pio.rs b/boards/rp-pico/examples/pico_i2c_pio.rs index 6d350ee..b6cb1d0 100644 --- a/boards/rp-pico/examples/pico_i2c_pio.rs +++ b/boards/rp-pico/examples/pico_i2c_pio.rs @@ -88,18 +88,20 @@ fn main() -> ! { &mut pac.RESETS, ); - let mut uart = hal::uart::UartPeripheral::<_, _>::new(pac.UART0, &mut pac.RESETS) + let uart_pins = ( + // UART TX (characters sent from RP2040) on pin 1 (GPIO0) + pins.gpio0.into_mode::(), + // UART RX (characters reveived by RP2040) on pin 2 (GPIO1) + pins.gpio1.into_mode::(), + ); + + let mut uart = hal::uart::UartPeripheral::new(pac.UART0, uart_pins, &mut pac.RESETS) .enable( hal::uart::common_configs::_115200_8_N_1, clocks.peripheral_clock.into(), ) .unwrap(); - // UART TX (characters sent from RP2040) on pin 1 (GPIO0) - let _tx_pin = pins.gpio0.into_mode::(); - // UART RX (characters reveived by RP2040) on pin 2 (GPIO1) - let _rx_pin = pins.gpio1.into_mode::(); - let (mut pio, sm0, _, _, _) = pac.PIO0.split(&mut pac.RESETS); let mut i2c_pio = i2c_pio::I2C::new( diff --git a/rp2040-hal/examples/adc.rs b/rp2040-hal/examples/adc.rs index 950ab7c..c848d93 100644 --- a/rp2040-hal/examples/adc.rs +++ b/rp2040-hal/examples/adc.rs @@ -84,18 +84,20 @@ fn main() -> ! { &mut pac.RESETS, ); + // UART TX (characters sent from pico) on pin 1 (GPIO0) and RX (on pin 2 (GPIO1) + let uart_pins = ( + pins.gpio0.into_mode::(), + pins.gpio1.into_mode::(), + ); + // Create a UART driver - let mut uart = hal::uart::UartPeripheral::<_, _>::new(pac.UART0, &mut pac.RESETS) + let mut uart = hal::uart::UartPeripheral::new(pac.UART0, uart_pins, &mut pac.RESETS) .enable( hal::uart::common_configs::_9600_8_N_1, clocks.peripheral_clock.into(), ) .unwrap(); - // UART TX (characters sent from pico) on pin 1 (GPIO0) and RX (on pin 2 (GPIO1) - let _tx_pin = pins.gpio0.into_mode::(); - let _rx_pin = pins.gpio1.into_mode::(); - // Write to the UART uart.write_full_blocking(b"ADC example\r\n"); diff --git a/rp2040-hal/examples/rom_funcs.rs b/rp2040-hal/examples/rom_funcs.rs index 4a89dd6..e4a349a 100644 --- a/rp2040-hal/examples/rom_funcs.rs +++ b/rp2040-hal/examples/rom_funcs.rs @@ -80,18 +80,19 @@ fn main() -> ! { &mut pac.RESETS, ); - let mut uart = hal::uart::UartPeripheral::<_, _>::new(pac.UART0, &mut pac.RESETS) + let uart_pins = ( + // UART TX (characters sent from RP2040) on pin 1 (GPIO0) + pins.gpio0.into_mode::(), + // UART RX (characters reveived by RP2040) on pin 2 (GPIO1) + pins.gpio1.into_mode::(), + ); + let mut uart = hal::uart::UartPeripheral::new(pac.UART0, uart_pins, &mut pac.RESETS) .enable( hal::uart::common_configs::_9600_8_N_1, clocks.peripheral_clock.into(), ) .unwrap(); - // UART TX (characters sent from RP2040) on pin 1 (GPIO0) - let _tx_pin = pins.gpio0.into_mode::(); - // UART RX (characters reveived by RP2040) on pin 2 (GPIO1) - let _rx_pin = pins.gpio1.into_mode::(); - writeln!(uart, "ROM Copyright: {}", hal::rom_data::copyright_string()).unwrap(); writeln!( uart, diff --git a/rp2040-hal/examples/uart.rs b/rp2040-hal/examples/uart.rs index 0705599..c4e122e 100644 --- a/rp2040-hal/examples/uart.rs +++ b/rp2040-hal/examples/uart.rs @@ -82,18 +82,19 @@ fn main() -> ! { &mut pac.RESETS, ); - let mut uart = hal::uart::UartPeripheral::<_, _>::new(pac.UART0, &mut pac.RESETS) + let uart_pins = ( + // UART TX (characters sent from RP2040) on pin 1 (GPIO0) + pins.gpio0.into_mode::(), + // UART RX (characters reveived by RP2040) on pin 2 (GPIO1) + pins.gpio1.into_mode::(), + ); + let mut uart = hal::uart::UartPeripheral::new(pac.UART0, uart_pins, &mut pac.RESETS) .enable( hal::uart::common_configs::_9600_8_N_1, clocks.peripheral_clock.into(), ) .unwrap(); - // UART TX (characters sent from RP2040) on pin 1 (GPIO0) - let _tx_pin = pins.gpio0.into_mode::(); - // UART RX (characters reveived by RP2040) on pin 2 (GPIO1) - let _rx_pin = pins.gpio1.into_mode::(); - uart.write_full_blocking(b"UART example\r\n"); let mut value = 0u32; diff --git a/rp2040-hal/src/uart/peripheral.rs b/rp2040-hal/src/uart/peripheral.rs index cb6e83e..65bd199 100644 --- a/rp2040-hal/src/uart/peripheral.rs +++ b/rp2040-hal/src/uart/peripheral.rs @@ -173,6 +173,8 @@ impl> UartPeripheral { /// Join the reader and writer halves together back into the original Uart peripheral. /// /// A reader/writer pair can be obtained by calling [`split`]. + /// + /// [`split`]: #method.split pub fn join(reader: Reader, writer: Writer) -> Self { let _ = writer; Self { diff --git a/rp2040-hal/src/uart/reader.rs b/rp2040-hal/src/uart/reader.rs index b6e126d..bb0f478 100644 --- a/rp2040-hal/src/uart/reader.rs +++ b/rp2040-hal/src/uart/reader.rs @@ -118,6 +118,9 @@ pub(crate) fn read_full_blocking( } /// Half of an [`UartPeripheral`] that is only capable of reading. Obtained by calling [`UartPeripheral::split()`] +/// +/// [`UartPeripheral`]: struct.UartPeripheral.html +/// [`UartPeripheral::split()`]: struct.UartPeripheral.html#method.split pub struct Reader> { pub(super) device: D, pub(super) pins: P, diff --git a/rp2040-hal/src/uart/writer.rs b/rp2040-hal/src/uart/writer.rs index 7b81808..3944ed0 100644 --- a/rp2040-hal/src/uart/writer.rs +++ b/rp2040-hal/src/uart/writer.rs @@ -58,6 +58,9 @@ pub(crate) fn write_full_blocking(rb: &RegisterBlock, data: &[u8]) { } /// Half of an [`UartPeripheral`] that is only capable of writing. Obtained by calling [`UartPeripheral::split()`] +/// +/// [`UartPeripheral`]: struct.UartPeripheral.html +/// [`UartPeripheral::split()`]: struct.UartPeripheral.html#method.split pub struct Writer> { pub(super) device: &'static RegisterBlock, pub(super) device_marker: PhantomData,