From 67ed4184eec6d5da2e838c9c349a7f94201e0e61 Mon Sep 17 00:00:00 2001 From: Andelf Date: Sat, 28 Oct 2023 16:56:47 +0800 Subject: [PATCH] enhance(gpio): rename output drive variant --- examples/adc_pin.rs | 2 +- examples/adc_temp.rs | 2 +- examples/blinky.rs | 2 +- examples/embassy-blinky.rs | 2 +- examples/embassy-gpio.rs | 2 +- examples/empty.rs | 2 +- examples/flashisp.rs | 2 +- examples/gpio_int.rs | 2 +- examples/hardfault.rs | 4 ++-- examples/i2c-mpu6050.rs | 2 +- examples/serial.rs | 2 +- examples/spi-ssd1306.rs | 8 ++++---- examples/systick_int.rs | 2 +- examples/uart-echo.rs | 2 +- examples/yd-ch582m.rs | 2 +- src/gpio.rs | 10 +++++----- src/spi.rs | 12 ++++++------ src/uart.rs | 4 ++-- 18 files changed, 32 insertions(+), 32 deletions(-) diff --git a/examples/adc_pin.rs b/examples/adc_pin.rs index 951272c..57daff1 100644 --- a/examples/adc_pin.rs +++ b/examples/adc_pin.rs @@ -28,7 +28,7 @@ fn main() -> ! { let mut delay = SysTick::new(p.SYSTICK); // LED PA8 - let mut blue_led = Output::new(p.PA8, Level::Low, OutputDrive::Standard); + let mut blue_led = Output::new(p.PA8, Level::Low, OutputDrive::_5mA); let mut serial = UartTx::new(p.UART1, p.PA9, Default::default()).unwrap(); diff --git a/examples/adc_temp.rs b/examples/adc_temp.rs index a37fcbe..8dd74a1 100644 --- a/examples/adc_temp.rs +++ b/examples/adc_temp.rs @@ -28,7 +28,7 @@ fn main() -> ! { let mut delay = SysTick::new(p.SYSTICK); // LED PA8 - let mut blue_led = Output::new(p.PA8, Level::Low, OutputDrive::Standard); + let mut blue_led = Output::new(p.PA8, Level::Low, OutputDrive::_5mA); let mut serial = UartTx::new(p.UART1, p.PA9, Default::default()).unwrap(); diff --git a/examples/blinky.rs b/examples/blinky.rs index 6131919..31472de 100644 --- a/examples/blinky.rs +++ b/examples/blinky.rs @@ -32,7 +32,7 @@ fn main() -> ! { let mut delay = SysTick::new(p.SYSTICK); - let mut pa8 = Output::new(p.PA8, Level::Low, OutputDrive::Standard); + let mut pa8 = Output::new(p.PA8, Level::Low, OutputDrive::_5mA); let mut download_button = Input::new(p.PB22, Pull::Up); let mut reset_button = Input::new(p.PB23, Pull::Up); diff --git a/examples/embassy-blinky.rs b/examples/embassy-blinky.rs index f09c6d6..406d3e0 100644 --- a/examples/embassy-blinky.rs +++ b/examples/embassy-blinky.rs @@ -41,7 +41,7 @@ fn panic(info: &core::panic::PanicInfo) -> ! { #[embassy_executor::task] async fn blink(pin: AnyPin) { - let mut led = Output::new(pin, Level::Low, OutputDrive::Standard); + let mut led = Output::new(pin, Level::Low, OutputDrive::_5mA); loop { led.set_high(); diff --git a/examples/embassy-gpio.rs b/examples/embassy-gpio.rs index f0e9b94..e000331 100644 --- a/examples/embassy-gpio.rs +++ b/examples/embassy-gpio.rs @@ -25,7 +25,7 @@ fn panic(info: &core::panic::PanicInfo) -> ! { #[embassy_executor::task] async fn blink(pin: AnyPin) { - let mut led = Output::new(pin, Level::Low, OutputDrive::Standard); + let mut led = Output::new(pin, Level::Low, OutputDrive::_5mA); loop { led.set_high(); diff --git a/examples/empty.rs b/examples/empty.rs index d732b06..155625a 100644 --- a/examples/empty.rs +++ b/examples/empty.rs @@ -35,7 +35,7 @@ fn main() -> ! { let mut delay = SysTick::new(p.SYSTICK); - let mut led = Output::new(p.PA8, Level::Low, OutputDrive::Standard); + let mut led = Output::new(p.PA8, Level::Low, OutputDrive::_5mA); let download_button = Input::new(p.PB22, Pull::Up); let reset_button = Input::new(p.PB23, Pull::Up); diff --git a/examples/flashisp.rs b/examples/flashisp.rs index fdcc06a..4745496 100644 --- a/examples/flashisp.rs +++ b/examples/flashisp.rs @@ -38,7 +38,7 @@ fn main() -> ! { let mut delay = SysTick::new(p.SYSTICK); // GPIO - let mut led = Output::new(p.PA8, Level::Low, OutputDrive::Standard); + let mut led = Output::new(p.PA8, Level::Low, OutputDrive::_5mA); let download_button = Input::new(p.PB22, Pull::Up); let reset_button = Input::new(p.PB23, Pull::Up); diff --git a/examples/gpio_int.rs b/examples/gpio_int.rs index 8cf2c8e..759eb5a 100644 --- a/examples/gpio_int.rs +++ b/examples/gpio_int.rs @@ -47,7 +47,7 @@ fn main() -> ! { let mut delay = SysTick::new(p.SYSTICK); // LED PA8 - let mut blue_led = Output::new(p.PA8, Level::Low, OutputDrive::Standard); + let mut blue_led = Output::new(p.PA8, Level::Low, OutputDrive::_5mA); let mut serial = UartTx::new(p.UART1, p.PA9, Default::default()).unwrap(); unsafe { diff --git a/examples/hardfault.rs b/examples/hardfault.rs index 53637c6..da3e63c 100644 --- a/examples/hardfault.rs +++ b/examples/hardfault.rs @@ -42,7 +42,7 @@ fn RTC() { #[ch32v_rt::interrupt] fn HardFault() { let pa8 = unsafe { hal::peripherals::PA8::steal() }; - let mut led = Output::new(pa8, Level::Low, OutputDrive::HighDrive); + let mut led = Output::new(pa8, Level::Low, OutputDrive::_20mA); println!("in hardfault"); let mcause = riscv::register::mcause::read(); @@ -76,7 +76,7 @@ fn main() -> ! { let mut delay = SysTick::new(p.SYSTICK); - let mut pa8 = Output::new(p.PA8, Level::Low, OutputDrive::Standard); + let mut pa8 = Output::new(p.PA8, Level::Low, OutputDrive::_5mA); let mut download_button = Input::new(p.PB22, Pull::Up); let mut reset_button = Input::new(p.PB23, Pull::Up); diff --git a/examples/i2c-mpu6050.rs b/examples/i2c-mpu6050.rs index 423231b..130d976 100644 --- a/examples/i2c-mpu6050.rs +++ b/examples/i2c-mpu6050.rs @@ -325,7 +325,7 @@ fn main() -> ! { let mut delay = SysTick::new(p.SYSTICK); // GPIO - let mut led = Output::new(p.PA8, Level::Low, OutputDrive::Standard); + let mut led = Output::new(p.PA8, Level::Low, OutputDrive::_5mA); let download_button = Input::new(p.PB22, Pull::Up); let reset_button = Input::new(p.PB23, Pull::Up); diff --git a/examples/serial.rs b/examples/serial.rs index fa27e83..78b6964 100644 --- a/examples/serial.rs +++ b/examples/serial.rs @@ -29,7 +29,7 @@ fn main() -> ! { let mut delay = SysTick::new(p.SYSTICK); // LED PA8 - let mut blue_led = Output::new(p.PA8, Level::Low, OutputDrive::Standard); + let mut blue_led = Output::new(p.PA8, Level::Low, OutputDrive::_5mA); let mut serial = UartTx::new(p.UART1, p.PA9, Default::default()).unwrap(); //let mut serial = UartTx::new(p.UART3, p.PA5, Default::default()).unwrap(); diff --git a/examples/spi-ssd1306.rs b/examples/spi-ssd1306.rs index be86da3..27e14cb 100644 --- a/examples/spi-ssd1306.rs +++ b/examples/spi-ssd1306.rs @@ -65,7 +65,7 @@ fn main() -> ! { let mut delay = SysTick::new(p.SYSTICK); // GPIO - let mut led = Output::new(p.PA8, Level::Low, OutputDrive::Standard); + let mut led = Output::new(p.PA8, Level::Low, OutputDrive::_5mA); let download_button = Input::new(p.PB22, Pull::Up); let reset_button = Input::new(p.PB23, Pull::Up); @@ -89,11 +89,11 @@ fn main() -> ! { // pin wiring - let dc = Output::new(p.PA10, Level::High, OutputDrive::Standard); + let dc = Output::new(p.PA10, Level::High, OutputDrive::_5mA); // active low - let mut res = Output::new(p.PA4, Level::High, OutputDrive::Standard); + let mut res = Output::new(p.PA4, Level::High, OutputDrive::_5mA); // SPI MODE_0, clk idle low, data valid on rising edge - let cs = Output::new(p.PA5, Level::Low, OutputDrive::Standard); + let cs = Output::new(p.PA5, Level::Low, OutputDrive::_5mA); res.set_low(); delay_ms(100); diff --git a/examples/systick_int.rs b/examples/systick_int.rs index 2e8e857..034c0f4 100644 --- a/examples/systick_int.rs +++ b/examples/systick_int.rs @@ -35,7 +35,7 @@ fn main() -> ! { let p = hal::init(config); // GPIO - let mut led = Output::new(p.PA8, Level::Low, OutputDrive::Standard); + let mut led = Output::new(p.PA8, Level::Low, OutputDrive::_5mA); //let download_button = Input::new(p.PB22, Pull::Up); let reset_button = Input::new(p.PB23, Pull::Up); diff --git a/examples/uart-echo.rs b/examples/uart-echo.rs index 7cda4bc..c463494 100644 --- a/examples/uart-echo.rs +++ b/examples/uart-echo.rs @@ -58,7 +58,7 @@ fn main() -> ! { let p = hal::init(config); // GPIO - let mut led = Output::new(p.PB4, Level::Low, OutputDrive::Standard); + let mut led = Output::new(p.PB4, Level::Low, OutputDrive::_5mA); // let boot_btn = Input::new(p.PB22, Pull::Up); // let rst_btn = Input::new(p.PB23, Pull::Up); diff --git a/examples/yd-ch582m.rs b/examples/yd-ch582m.rs index 4504b3c..256bada 100644 --- a/examples/yd-ch582m.rs +++ b/examples/yd-ch582m.rs @@ -50,7 +50,7 @@ fn main() -> ! { let mut delay = SysTick::new(p.SYSTICK); // GPIO - let mut led = Output::new(p.PB4, Level::Low, OutputDrive::Standard); + let mut led = Output::new(p.PB4, Level::Low, OutputDrive::_5mA); let boot_btn = Input::new(p.PB22, Pull::Up); let rst_btn = Input::new(p.PB23, Pull::Up); diff --git a/src/gpio.rs b/src/gpio.rs index 7777d4e..d236708 100644 --- a/src/gpio.rs +++ b/src/gpio.rs @@ -174,9 +174,9 @@ pub enum Pull { pub enum OutputDrive { // The drive current is 5mA #[default] - Standard = 0, + _5mA = 0, // The drive current is 20mA - HighDrive = 1, + _20mA = 1, } /// GPIO input driver. @@ -520,7 +520,7 @@ pub(crate) mod sealed { let rb = self.block(); let pin = self._pin(); unsafe { - if drive == OutputDrive::HighDrive { + if drive == OutputDrive::_20mA { rb.pd_drv.modify(|r, w| w.bits(r.bits() | (1 << pin))); } else { rb.pd_drv.modify(|r, w| w.bits(r.bits() & !(1 << pin))); @@ -557,10 +557,10 @@ pub(crate) mod sealed { let rb = self.block(); let pin = self._pin(); match drive { - OutputDrive::Standard => unsafe { + OutputDrive::_5mA => unsafe { rb.pd_drv.modify(|r, w| w.bits(r.bits() & !(1 << pin))); }, - OutputDrive::HighDrive => unsafe { + OutputDrive::_20mA => unsafe { rb.pd_drv.modify(|r, w| w.bits(r.bits() | (1 << pin))); }, } diff --git a/src/spi.rs b/src/spi.rs index 9a43460..8193584 100644 --- a/src/spi.rs +++ b/src/spi.rs @@ -72,8 +72,8 @@ impl<'d, T: Instance> Spi<'d, T> { } else { sck.set_high(); } - sck.set_as_output(OutputDrive::Standard); - mosi.set_as_output(OutputDrive::Standard); + sck.set_as_output(OutputDrive::_5mA); + mosi.set_as_output(OutputDrive::_5mA); miso.set_as_input(Pull::None); if REMAP { @@ -102,7 +102,7 @@ impl<'d, T: Instance> Spi<'d, T> { } else { sck.set_high(); } - sck.set_as_output(OutputDrive::Standard); + sck.set_as_output(OutputDrive::_5mA); miso.set_as_input(Pull::None); if REMAP { @@ -126,8 +126,8 @@ impl<'d, T: Instance> Spi<'d, T> { } else { sck.set_high(); } - sck.set_as_output(OutputDrive::Standard); - mosi.set_as_output(OutputDrive::Standard); + sck.set_as_output(OutputDrive::_5mA); + mosi.set_as_output(OutputDrive::_5mA); if REMAP { T::set_remap(); @@ -142,7 +142,7 @@ impl<'d, T: Instance> Spi<'d, T> { ) -> Self { into_ref!(mosi); - mosi.set_as_output(OutputDrive::Standard); + mosi.set_as_output(OutputDrive::_5mA); if REMAP { T::set_remap(); diff --git a/src/uart.rs b/src/uart.rs index ba657ee..186ceee 100644 --- a/src/uart.rs +++ b/src/uart.rs @@ -114,7 +114,7 @@ impl<'d, T: BasicInstance> UartTx<'d, T> { into_ref!(_peri, tx); // set up pin - tx.set_as_output(OutputDrive::Standard); + tx.set_as_output(OutputDrive::_5mA); if REMAP { T::set_remap(); } @@ -270,7 +270,7 @@ impl<'d, T: BasicInstance> Uart<'d, T> { into_ref!(peri, tx, rx); let _ = peri; - tx.set_as_output(OutputDrive::Standard); + tx.set_as_output(OutputDrive::_5mA); rx.set_as_input(Pull::Up); if REMAP {