GPIO optimization and tweaks
- Some functions marked inline - Doc updated
This commit is contained in:
parent
6c9d9f7dfa
commit
04830087da
@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [unreleased]
|
||||
|
||||
### Changed
|
||||
|
||||
- Minor optimizations and tweaks for GPIO module
|
||||
|
||||
## [0.2.0]
|
||||
|
||||
|
@ -1,3 +1,6 @@
|
||||
//! # API for clock related functionality
|
||||
//!
|
||||
//! This also includes functionality to enable the peripheral clocks
|
||||
use crate::time::Hertz;
|
||||
use cortex_m::interrupt::{self, Mutex};
|
||||
use once_cell::unsync::OnceCell;
|
||||
|
@ -1,4 +1,4 @@
|
||||
//! # GPIO module
|
||||
//! # API for the GPIO peripheral
|
||||
//!
|
||||
//! The implementation of this GPIO module is heavily based on the
|
||||
//! [ATSAMD HAL implementation](https://docs.rs/atsamd-hal/0.13.0/atsamd_hal/gpio/v2/index.html).
|
||||
|
@ -200,11 +200,13 @@ pub(super) unsafe trait RegisterInterface {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn get_perid(&self) -> u32 {
|
||||
let portreg = self.port_reg();
|
||||
portreg.perid.read().bits()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
/// Read the logic level of an output pin
|
||||
fn read_pin(&self) -> bool {
|
||||
let portreg = self.port_reg();
|
||||
@ -220,27 +222,25 @@ pub(super) unsafe trait RegisterInterface {
|
||||
|
||||
/// Read a pin but use the masked version but check whether the datamask for the pin is
|
||||
/// cleared as well
|
||||
#[inline]
|
||||
fn read_pin_masked(&self) -> Result<bool, PinError> {
|
||||
if !self.datamask() {
|
||||
Err(PinError::IsMasked)
|
||||
} else {
|
||||
let portreg = self.port_reg();
|
||||
Ok(((portreg.datain().read().bits() >> self.id().num) & 0x01) == 1)
|
||||
Ok(((self.port_reg().datain().read().bits() >> self.id().num) & 0x01) == 1)
|
||||
}
|
||||
}
|
||||
|
||||
/// Write the logic level of an output pin
|
||||
#[inline]
|
||||
fn write_pin(&mut self, bit: bool) {
|
||||
let portreg = self.port_reg();
|
||||
let mask = self.mask_32();
|
||||
// Safety: SETOUT is a "mask" register, and we only write the bit for
|
||||
// this pin ID
|
||||
unsafe {
|
||||
if bit {
|
||||
portreg.setout().write(|w| w.bits(mask));
|
||||
self.port_reg().setout().write(|w| w.bits(self.mask_32()));
|
||||
} else {
|
||||
portreg.clrout().write(|w| w.bits(mask));
|
||||
self.port_reg().clrout().write(|w| w.bits(self.mask_32()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -252,15 +252,13 @@ pub(super) unsafe trait RegisterInterface {
|
||||
if !self.datamask() {
|
||||
Err(PinError::IsMasked)
|
||||
} else {
|
||||
let portreg = self.port_reg();
|
||||
let mask = self.mask_32();
|
||||
// Safety: SETOUT is a "mask" register, and we only write the bit for
|
||||
// this pin ID
|
||||
unsafe {
|
||||
if bit {
|
||||
portreg.setout().write(|w| w.bits(mask));
|
||||
self.port_reg().setout().write(|w| w.bits(self.mask_32()));
|
||||
} else {
|
||||
portreg.clrout().write(|w| w.bits(mask));
|
||||
self.port_reg().clrout().write(|w| w.bits(self.mask_32()));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@ -270,18 +268,15 @@ pub(super) unsafe trait RegisterInterface {
|
||||
/// Toggle the logic level of an output pin
|
||||
#[inline]
|
||||
fn toggle(&mut self) {
|
||||
let portreg = self.port_reg();
|
||||
let mask = self.mask_32();
|
||||
// Safety: TOGOUT is a "mask" register, and we only write the bit for
|
||||
// this pin ID
|
||||
unsafe { portreg.togout().write(|w| w.bits(mask)) };
|
||||
unsafe { self.port_reg().togout().write(|w| w.bits(self.mask_32())) };
|
||||
}
|
||||
|
||||
/// Only useful for input pins
|
||||
#[inline]
|
||||
fn filter_type(&self, filter: FilterType, clksel: FilterClkSel) {
|
||||
let iocfg = self.iocfg_port();
|
||||
iocfg.port[self.id().num as usize].modify(|_, w| {
|
||||
self.iocfg_port().port[self.id().num as usize].modify(|_, w| {
|
||||
// Safety: Only write to register for this Pin ID
|
||||
unsafe {
|
||||
w.flttype().bits(filter as u8);
|
||||
|
@ -1,4 +1,7 @@
|
||||
//! API for the UART peripheral
|
||||
//! # API for the UART peripheral
|
||||
//!
|
||||
//! ## Examples
|
||||
//! - [UART example](https://github.com/robamu-org/va108xx-hal-rs/blob/main/examples/uart.rs)
|
||||
use core::{convert::Infallible, ptr};
|
||||
use core::{marker::PhantomData, ops::Deref};
|
||||
use libm::floorf;
|
||||
|
Reference in New Issue
Block a user