PIO support for RPi Pico
This commit is contained in:
@ -26,6 +26,7 @@ time-driver = []
|
||||
rom-func-cache = []
|
||||
intrinsics = []
|
||||
rom-v2-intrinsics = []
|
||||
pio = ["dep:pio", "dep:pio-proc"]
|
||||
|
||||
# Enable nightly-only features
|
||||
nightly = ["embassy-executor/nightly", "embedded-hal-1", "embedded-hal-async", "embassy-embedded-hal/nightly", "dep:embassy-usb-driver", "dep:embedded-io"]
|
||||
@ -64,3 +65,10 @@ embedded-hal-02 = { package = "embedded-hal", version = "0.2.6", features = ["un
|
||||
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.9", optional = true}
|
||||
embedded-hal-async = { version = "=0.2.0-alpha.0", optional = true}
|
||||
embedded-hal-nb = { version = "=1.0.0-alpha.1", optional = true}
|
||||
|
||||
paste = "1.0"
|
||||
pio-proc = {version= "0.2", optional = true}
|
||||
pio = {version= "0.2", optional = true}
|
||||
|
||||
[patch.crates-io]
|
||||
pio = {git = "https://github.com/rp-rs/pio-rs.git"}
|
@ -48,6 +48,21 @@ pub enum Pull {
|
||||
Down,
|
||||
}
|
||||
|
||||
/// Drive strength of an output
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub enum Drive {
|
||||
_2mA,
|
||||
_4mA,
|
||||
_8mA,
|
||||
_12mA,
|
||||
}
|
||||
/// Slew rate of an output
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub enum SlewRate {
|
||||
Fast,
|
||||
Slow,
|
||||
}
|
||||
|
||||
/// A GPIO bank with up to 32 pins.
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub enum Bank {
|
||||
@ -459,7 +474,7 @@ impl<'d, T: Pin> Flex<'d, T> {
|
||||
#[inline]
|
||||
pub fn set_pull(&mut self, pull: Pull) {
|
||||
unsafe {
|
||||
self.pin.pad_ctrl().write(|w| {
|
||||
self.pin.pad_ctrl().modify(|w| {
|
||||
w.set_ie(true);
|
||||
match pull {
|
||||
Pull::Up => w.set_pue(true),
|
||||
@ -470,6 +485,31 @@ impl<'d, T: Pin> Flex<'d, T> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the pin's drive strength.
|
||||
#[inline]
|
||||
pub fn set_drive_strength(&mut self, strength: Drive) {
|
||||
unsafe {
|
||||
self.pin.pad_ctrl().modify(|w| {
|
||||
w.set_drive(match strength {
|
||||
Drive::_2mA => pac::pads::vals::Drive::_2MA,
|
||||
Drive::_4mA => pac::pads::vals::Drive::_4MA,
|
||||
Drive::_8mA => pac::pads::vals::Drive::_8MA,
|
||||
Drive::_12mA => pac::pads::vals::Drive::_12MA,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Set the pin's slew rate.
|
||||
#[inline]
|
||||
pub fn set_slew_rate(&mut self, slew_rate: SlewRate) {
|
||||
unsafe {
|
||||
self.pin.pad_ctrl().modify(|w| {
|
||||
w.set_slewfast(slew_rate == SlewRate::Fast);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Put the pin into input mode.
|
||||
///
|
||||
/// The pull setting is left unchanged.
|
||||
|
@ -12,6 +12,12 @@ pub mod dma;
|
||||
pub mod gpio;
|
||||
pub mod i2c;
|
||||
pub mod interrupt;
|
||||
|
||||
#[cfg(feature = "pio")]
|
||||
pub mod pio;
|
||||
#[cfg(feature = "pio")]
|
||||
pub mod pio_instr_util;
|
||||
|
||||
pub mod rom_data;
|
||||
pub mod rtc;
|
||||
pub mod spi;
|
||||
@ -102,6 +108,9 @@ embassy_hal_common::peripherals! {
|
||||
FLASH,
|
||||
|
||||
ADC,
|
||||
|
||||
PIO0,
|
||||
PIO1,
|
||||
}
|
||||
|
||||
#[link_section = ".boot2"]
|
||||
|
1250
embassy-rp/src/pio.rs
Normal file
1250
embassy-rp/src/pio.rs
Normal file
File diff suppressed because it is too large
Load Diff
90
embassy-rp/src/pio_instr_util.rs
Normal file
90
embassy-rp/src/pio_instr_util.rs
Normal file
@ -0,0 +1,90 @@
|
||||
use pio::{InSource, InstructionOperands, JmpCondition, OutDestination, SetDestination};
|
||||
|
||||
use crate::pio::PioStateMachine;
|
||||
|
||||
pub fn set_x<SM: PioStateMachine>(sm: &mut SM, value: u32) {
|
||||
const OUT: u16 = InstructionOperands::OUT {
|
||||
destination: OutDestination::X,
|
||||
bit_count: 32,
|
||||
}
|
||||
.encode();
|
||||
sm.push_tx(value);
|
||||
sm.exec_instr(OUT);
|
||||
}
|
||||
|
||||
pub fn get_x<SM: PioStateMachine>(sm: &mut SM) -> u32 {
|
||||
const IN: u16 = InstructionOperands::IN {
|
||||
source: InSource::X,
|
||||
bit_count: 32,
|
||||
}
|
||||
.encode();
|
||||
sm.exec_instr(IN);
|
||||
sm.pull_rx()
|
||||
}
|
||||
|
||||
pub fn set_y<SM: PioStateMachine>(sm: &mut SM, value: u32) {
|
||||
const OUT: u16 = InstructionOperands::OUT {
|
||||
destination: OutDestination::Y,
|
||||
bit_count: 32,
|
||||
}
|
||||
.encode();
|
||||
sm.push_tx(value);
|
||||
sm.exec_instr(OUT);
|
||||
}
|
||||
|
||||
pub fn get_y<SM: PioStateMachine>(sm: &mut SM) -> u32 {
|
||||
const IN: u16 = InstructionOperands::IN {
|
||||
source: InSource::Y,
|
||||
bit_count: 32,
|
||||
}
|
||||
.encode();
|
||||
sm.exec_instr(IN);
|
||||
|
||||
sm.pull_rx()
|
||||
}
|
||||
|
||||
pub fn set_pindir<SM: PioStateMachine>(sm: &mut SM, data: u8) {
|
||||
let set: u16 = InstructionOperands::SET {
|
||||
destination: SetDestination::PINDIRS,
|
||||
data,
|
||||
}
|
||||
.encode();
|
||||
sm.exec_instr(set);
|
||||
}
|
||||
|
||||
pub fn set_pin<SM: PioStateMachine>(sm: &mut SM, data: u8) {
|
||||
let set: u16 = InstructionOperands::SET {
|
||||
destination: SetDestination::PINS,
|
||||
data,
|
||||
}
|
||||
.encode();
|
||||
sm.exec_instr(set);
|
||||
}
|
||||
|
||||
pub fn set_out_pin<SM: PioStateMachine>(sm: &mut SM, data: u32) {
|
||||
const OUT: u16 = InstructionOperands::OUT {
|
||||
destination: OutDestination::PINS,
|
||||
bit_count: 32,
|
||||
}
|
||||
.encode();
|
||||
sm.push_tx(data);
|
||||
sm.exec_instr(OUT);
|
||||
}
|
||||
pub fn set_out_pindir<SM: PioStateMachine>(sm: &mut SM, data: u32) {
|
||||
const OUT: u16 = InstructionOperands::OUT {
|
||||
destination: OutDestination::PINDIRS,
|
||||
bit_count: 32,
|
||||
}
|
||||
.encode();
|
||||
sm.push_tx(data);
|
||||
sm.exec_instr(OUT);
|
||||
}
|
||||
|
||||
pub fn exec_jmp<SM: PioStateMachine>(sm: &mut SM, to_addr: u8) {
|
||||
let jmp: u16 = InstructionOperands::JMP {
|
||||
address: to_addr,
|
||||
condition: JmpCondition::Always,
|
||||
}
|
||||
.encode();
|
||||
sm.exec_instr(jmp);
|
||||
}
|
Reference in New Issue
Block a user