PIO support for RPi Pico

This commit is contained in:
Simon Berg
2022-07-27 22:45:46 +02:00
parent e94ca0efd6
commit 35db6e639b
8 changed files with 1576 additions and 2 deletions

View File

@ -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.