Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gpio inherent #325

Merged
merged 5 commits into from
Jul 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Added

- `PinState` and `get/set_state`.
- Inherent methods for infallible digital operations.
- Generic `into_alternate` and `into_alternate_open_drain`. Non-generic ones are deprecated
- Internal implementation of GPIO Pin API changed to use Const Generics
- `PinExt` trait. Make `ExtiPin` implementation generic
Expand Down
22 changes: 11 additions & 11 deletions examples/analog-stopwatch-with-spi-ssd1306.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ fn main() -> ! {
let mut ss = gpioe.pe4.into_push_pull_output();
let mut delay = hal::delay::Delay::new(cp.SYST, clocks);

ss.set_high().unwrap();
ss.set_high();
delay.delay_ms(100_u32);
ss.set_low().unwrap();
ss.set_low();

// Set up the display
let interface = SPIInterfaceNoCS::new(spi, dc);
Expand Down Expand Up @@ -164,21 +164,21 @@ fn main() -> ! {

match state {
StopwatchState::Ready => {
led3.set_high().unwrap();
led4.set_low().unwrap();
led3.set_high();
led4.set_low();
}
StopwatchState::Running => {
if state_led {
led4.set_low().unwrap();
led3.set_high().unwrap();
led4.set_low();
led3.set_high();
} else {
led4.set_low().unwrap();
led3.set_low().unwrap();
led4.set_low();
led3.set_low();
}
}
StopwatchState::Stopped => {
led3.set_low().unwrap();
led4.set_high().unwrap();
led3.set_low();
led4.set_high();
}
};

Expand Down Expand Up @@ -282,7 +282,7 @@ fn TIM2() {
StopwatchState::Stopped => {
let mut btn_ref = BUTTON.borrow(cs).borrow_mut();
if let Some(ref mut btn) = btn_ref.deref_mut() {
if btn.is_high().unwrap() {
if btn.is_high() {
cell_reset.replace(val_reset + 1);
}
}
Expand Down
1 change: 0 additions & 1 deletion examples/blinky-timer-irq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::hal::{
use core::cell::RefCell;
use cortex_m::{asm::wfi, interrupt::Mutex};
use cortex_m_rt::entry;
use embedded_hal::digital::v2::OutputPin;
use embedded_hal::timer::CountDown;

// NOTE You can uncomment 'hprintln' here and in the code below for a bit more
Expand Down
4 changes: 2 additions & 2 deletions examples/delay-blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ fn main() -> ! {

loop {
// On for 1s, off for 1s.
led.set_high().unwrap();
led.set_high();
delay.delay_ms(1000_u32);
led.set_low().unwrap();
led.set_low();
delay.delay_ms(1000_u32);
}
}
Expand Down
8 changes: 4 additions & 4 deletions examples/dwt-blinky.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ fn main() -> ! {
let mut sw = dwt.stopwatch(&mut lap_times);
loop {
// On for 1s, off for 1s.
led1.set_high().unwrap();
led2.set_low().unwrap();
led1.set_high();
led2.set_low();
delay.delay_ms(1000_u32);
sw.lap();
led1.set_low().unwrap();
led2.set_high().unwrap();
led1.set_low();
led2.set_high();
delay.delay_ms(900_u32);
// Also you can measure with almost clock precision
let cd: ClockDuration = dwt.measure(|| delay.delay_ms(100_u32));
Expand Down
2 changes: 1 addition & 1 deletion examples/f413disco_lcd_ferris.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ fn main() -> ! {
let mut _te = gpiob.pb14.into_floating_input();

// Enable backlight
gpioe.pe5.into_push_pull_output().set_high().ok();
gpioe.pe5.into_push_pull_output().set_high();

// Get delay provider
let mut delay = Delay::new(cp.SYST, clocks);
Expand Down
2 changes: 1 addition & 1 deletion examples/i2s-audio-out-dma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ fn main() -> ! {
// Keep DAC reset low for at least one millisecond
delay.delay_ms(1u8);
// Release the DAC from reset
dac_reset.set_high().unwrap();
dac_reset.set_high();
// Wait at least 550 ns before starting I2C communication
delay.delay_us(1u8);

Expand Down
2 changes: 1 addition & 1 deletion examples/i2s-audio-out.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fn main() -> ! {
// Keep DAC reset low for at least one millisecond
delay.delay_ms(1u8);
// Release the DAC from reset
dac_reset.set_high().unwrap();
dac_reset.set_high();
// Wait at least 550 ns before starting I2C communication
delay.delay_us(1u8);

Expand Down
4 changes: 2 additions & 2 deletions examples/qei.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ fn main() -> ! {
// Light up the LED when turning clockwise, turn it off
// when turning counter-clockwise.
match rotary_encoder.direction() {
RotaryDirection::Upcounting => led.set_low().unwrap(),
RotaryDirection::Downcounting => led.set_high().unwrap(),
RotaryDirection::Upcounting => led.set_low(),
RotaryDirection::Downcounting => led.set_high(),
}

current_count = new_count;
Expand Down
2 changes: 1 addition & 1 deletion examples/rtic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,6 @@ const APP: () = {
#[task(binds = EXTI0, resources = [button, led])]
fn button_click(ctx: button_click::Context) {
ctx.resources.button.clear_interrupt_pending_bit();
ctx.resources.led.toggle().unwrap();
ctx.resources.led.toggle();
}
};
16 changes: 8 additions & 8 deletions examples/serial-9bit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,24 +84,24 @@ fn main() -> ! {

// Update LEDs to display what was received
if ((received >> 5) & 1) == 1 {
led_bit5.set_high().unwrap();
led_bit5.set_high();
} else {
led_bit5.set_low().unwrap();
led_bit5.set_low();
}
if ((received >> 6) & 1) == 1 {
led_bit6.set_high().unwrap();
led_bit6.set_high();
} else {
led_bit6.set_low().unwrap();
led_bit6.set_low();
}
if ((received >> 7) & 1) == 1 {
led_bit7.set_high().unwrap();
led_bit7.set_high();
} else {
led_bit7.set_low().unwrap();
led_bit7.set_low();
}
if ((received >> 8) & 1) == 1 {
led_bit8.set_high().unwrap();
led_bit8.set_high();
} else {
led_bit8.set_low().unwrap();
led_bit8.set_low();
}

delay.delay_ms(10u32);
Expand Down
4 changes: 2 additions & 2 deletions examples/ssd1306-image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ fn main() -> ! {

// Set up state for the loop
let mut orientation = DisplayRotation::Rotate0;
let mut was_pressed = btn.is_low().unwrap();
let mut was_pressed = btn.is_low();

// This runs continuously, as fast as possible
loop {
// Check if the button has just been pressed.
// Remember, active low.
let is_pressed = btn.is_low().unwrap();
let is_pressed = btn.is_low();
if !was_pressed && is_pressed {
// Since the button was pressed, flip the screen upside down
orientation = get_next_rotation(orientation);
Expand Down
10 changes: 5 additions & 5 deletions examples/st7789-lcd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,14 @@ fn main() -> ! {
// https://github.com/STMicroelectronics/STM32CubeF4/blob/e084518f363e04344dc37822210a75e87377b200/Drivers/BSP/Components/st7789h2/st7789h2.c

// Reset LCD controller
lcd_reset.set_low().unwrap();
lcd_reset.set_low();
delay.delay_ms(5u16);
lcd_reset.set_high().unwrap();
lcd_reset.set_high();
delay.delay_ms(10u16);
lcd_reset.set_low().unwrap();
lcd_reset.set_low();
delay.delay_ms(20u16);
// Release from reset
lcd_reset.set_high().unwrap();
lcd_reset.set_high();
delay.delay_ms(10u16);

// Add LCD controller driver
Expand All @@ -140,7 +140,7 @@ fn main() -> ! {
lcd.write(0x29, &[]);

// Turn on backlight
backlight_control.set_high().unwrap();
backlight_control.set_high();

// Draw some circles
let test_colors = [
Expand Down
Loading