Skip to content

Commit

Permalink
enhance(gpio): rename output drive variant
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed Oct 28, 2023
1 parent 3087b93 commit 67ed418
Show file tree
Hide file tree
Showing 18 changed files with 32 additions and 32 deletions.
2 changes: 1 addition & 1 deletion examples/adc_pin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/adc_temp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion examples/blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion examples/embassy-blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion examples/embassy-gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion examples/empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion examples/flashisp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion examples/gpio_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions examples/hardfault.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion examples/i2c-mpu6050.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion examples/serial.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions examples/spi-ssd1306.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion examples/systick_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion examples/uart-echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion examples/yd-ch582m.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 5 additions & 5 deletions src/gpio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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)));
},
}
Expand Down
12 changes: 6 additions & 6 deletions src/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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();
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 67ed418

Please sign in to comment.