Merge branch 'master' into multicore
This commit is contained in:
@ -29,6 +29,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"]
|
||||
@ -67,3 +68,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,13 +474,40 @@ 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),
|
||||
Pull::Down => w.set_pde(true),
|
||||
Pull::None => {}
|
||||
}
|
||||
let (pu, pd) = match pull {
|
||||
Pull::Up => (true, false),
|
||||
Pull::Down => (false, true),
|
||||
Pull::None => (false, false),
|
||||
};
|
||||
w.set_pue(pu);
|
||||
w.set_pde(pd);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// 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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,14 @@ 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;
|
||||
#[cfg(feature = "pio")]
|
||||
pub mod relocate;
|
||||
|
||||
pub mod rom_data;
|
||||
pub mod rtc;
|
||||
pub mod spi;
|
||||
@ -108,6 +116,9 @@ embassy_hal_common::peripherals! {
|
||||
ADC,
|
||||
|
||||
CORE1,
|
||||
|
||||
PIO0,
|
||||
PIO1,
|
||||
}
|
||||
|
||||
#[link_section = ".boot2"]
|
||||
|
1259
embassy-rp/src/pio.rs
Normal file
1259
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);
|
||||
}
|
77
embassy-rp/src/relocate.rs
Normal file
77
embassy-rp/src/relocate.rs
Normal file
@ -0,0 +1,77 @@
|
||||
use core::iter::Iterator;
|
||||
|
||||
use pio::{Program, SideSet, Wrap};
|
||||
|
||||
pub struct CodeIterator<'a, I>
|
||||
where
|
||||
I: Iterator<Item = &'a u16>,
|
||||
{
|
||||
iter: I,
|
||||
offset: u8,
|
||||
}
|
||||
|
||||
impl<'a, I: Iterator<Item = &'a u16>> CodeIterator<'a, I> {
|
||||
pub fn new(iter: I, offset: u8) -> CodeIterator<'a, I> {
|
||||
CodeIterator { iter, offset }
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, I> Iterator for CodeIterator<'a, I>
|
||||
where
|
||||
I: Iterator<Item = &'a u16>,
|
||||
{
|
||||
type Item = u16;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.iter.next().and_then(|&instr| {
|
||||
Some(if instr & 0b1110_0000_0000_0000 == 0 {
|
||||
// this is a JMP instruction -> add offset to address
|
||||
let address = (instr & 0b1_1111) as u8;
|
||||
let address = address + self.offset;
|
||||
assert!(
|
||||
address < pio::RP2040_MAX_PROGRAM_SIZE as u8,
|
||||
"Invalid JMP out of the program after offset addition"
|
||||
);
|
||||
instr & (!0b11111) | address as u16
|
||||
} else {
|
||||
instr
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub struct RelocatedProgram<'a, const PROGRAM_SIZE: usize> {
|
||||
program: &'a Program<PROGRAM_SIZE>,
|
||||
origin: u8,
|
||||
}
|
||||
|
||||
impl<'a, const PROGRAM_SIZE: usize> RelocatedProgram<'a, PROGRAM_SIZE> {
|
||||
pub fn new(program: &Program<PROGRAM_SIZE>) -> RelocatedProgram<PROGRAM_SIZE> {
|
||||
let origin = program.origin.unwrap_or(0);
|
||||
RelocatedProgram { program, origin }
|
||||
}
|
||||
|
||||
pub fn new_with_origin(program: &Program<PROGRAM_SIZE>, origin: u8) -> RelocatedProgram<PROGRAM_SIZE> {
|
||||
RelocatedProgram { program, origin }
|
||||
}
|
||||
|
||||
pub fn code(&'a self) -> CodeIterator<'a, core::slice::Iter<'a, u16>> {
|
||||
CodeIterator::new(self.program.code.iter(), self.origin)
|
||||
}
|
||||
|
||||
pub fn wrap(&self) -> Wrap {
|
||||
let wrap = self.program.wrap;
|
||||
let origin = self.origin;
|
||||
Wrap {
|
||||
source: wrap.source + origin,
|
||||
target: wrap.target + origin,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn side_set(&self) -> SideSet {
|
||||
self.program.side_set
|
||||
}
|
||||
|
||||
pub fn origin(&self) -> u8 {
|
||||
self.origin
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user