rp/gpio: implement Input

This commit is contained in:
Dario Nieuwenhuis
2021-03-29 21:33:46 +02:00
parent 5f6f1c38d9
commit 403b308279
6 changed files with 124 additions and 75 deletions

View File

@ -0,0 +1,32 @@
#![no_std]
#![no_main]
#![feature(asm)]
#![feature(min_type_alias_impl_trait)]
#![feature(impl_trait_in_bindings)]
#![feature(type_alias_impl_trait)]
#![allow(incomplete_features)]
#[path = "../example_common.rs"]
mod example_common;
use defmt::*;
use embassy::executor::Spawner;
use embassy_rp::{gpio, Peripherals};
use embedded_hal::digital::v2::OutputPin;
#[embassy::main]
async fn main(_spawner: Spawner) {
let p = unwrap!(Peripherals::take());
let mut led = gpio::Output::new(p.PIN_25, gpio::Level::Low);
loop {
info!("led on!");
led.set_high().unwrap();
cortex_m::asm::delay(1_000_000);
info!("led off!");
led.set_low().unwrap();
cortex_m::asm::delay(1_000_000);
}
}

View File

@ -0,0 +1,28 @@
#![no_std]
#![no_main]
#![feature(asm)]
#![feature(min_type_alias_impl_trait)]
#![feature(impl_trait_in_bindings)]
#![feature(type_alias_impl_trait)]
#![allow(incomplete_features)]
#[path = "../example_common.rs"]
mod example_common;
use defmt::*;
use embassy::executor::Spawner;
use embassy_rp::gpio::{Input, Pull};
use embassy_rp::Peripherals;
use embedded_hal::digital::v2::InputPin;
#[embassy::main]
async fn main(_spawner: Spawner) {
let p = unwrap!(Peripherals::take());
let button = Input::new(p.PIN_28, Pull::Up);
loop {
info!("high? {=bool}", button.is_high().unwrap());
cortex_m::asm::delay(1_000_000);
}
}

View File

@ -0,0 +1,28 @@
#![no_std]
#![no_main]
#![feature(asm)]
#![feature(min_type_alias_impl_trait)]
#![feature(impl_trait_in_bindings)]
#![feature(type_alias_impl_trait)]
#![allow(incomplete_features)]
#[path = "../example_common.rs"]
mod example_common;
use defmt::*;
use embassy::executor::Spawner;
use embassy_rp::{uart, Peripherals};
#[embassy::main]
async fn main(_spanwer: Spawner) {
let p = unwrap!(Peripherals::take());
let config = uart::Config::default();
let mut uart = uart::Uart::new(p.UART0, p.PIN_0, p.PIN_1, p.PIN_2, p.PIN_3, config);
uart.send("Hello World!\r\n".as_bytes());
loop {
uart.send("hello there!\r\n".as_bytes());
cortex_m::asm::delay(1_000_000);
}
}