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]
|
## [unreleased]
|
||||||
|
|
||||||
|
### Changed
|
||||||
|
|
||||||
|
- Minor optimizations and tweaks for GPIO module
|
||||||
|
|
||||||
## [0.2.0]
|
## [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 crate::time::Hertz;
|
||||||
use cortex_m::interrupt::{self, Mutex};
|
use cortex_m::interrupt::{self, Mutex};
|
||||||
use once_cell::unsync::OnceCell;
|
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
|
//! 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).
|
//! [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 {
|
fn get_perid(&self) -> u32 {
|
||||||
let portreg = self.port_reg();
|
let portreg = self.port_reg();
|
||||||
portreg.perid.read().bits()
|
portreg.perid.read().bits()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
/// Read the logic level of an output pin
|
/// Read the logic level of an output pin
|
||||||
fn read_pin(&self) -> bool {
|
fn read_pin(&self) -> bool {
|
||||||
let portreg = self.port_reg();
|
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
|
/// Read a pin but use the masked version but check whether the datamask for the pin is
|
||||||
/// cleared as well
|
/// cleared as well
|
||||||
|
#[inline]
|
||||||
fn read_pin_masked(&self) -> Result<bool, PinError> {
|
fn read_pin_masked(&self) -> Result<bool, PinError> {
|
||||||
if !self.datamask() {
|
if !self.datamask() {
|
||||||
Err(PinError::IsMasked)
|
Err(PinError::IsMasked)
|
||||||
} else {
|
} else {
|
||||||
let portreg = self.port_reg();
|
Ok(((self.port_reg().datain().read().bits() >> self.id().num) & 0x01) == 1)
|
||||||
Ok(((portreg.datain().read().bits() >> self.id().num) & 0x01) == 1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write the logic level of an output pin
|
/// Write the logic level of an output pin
|
||||||
#[inline]
|
#[inline]
|
||||||
fn write_pin(&mut self, bit: bool) {
|
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
|
// Safety: SETOUT is a "mask" register, and we only write the bit for
|
||||||
// this pin ID
|
// this pin ID
|
||||||
unsafe {
|
unsafe {
|
||||||
if bit {
|
if bit {
|
||||||
portreg.setout().write(|w| w.bits(mask));
|
self.port_reg().setout().write(|w| w.bits(self.mask_32()));
|
||||||
} else {
|
} 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() {
|
if !self.datamask() {
|
||||||
Err(PinError::IsMasked)
|
Err(PinError::IsMasked)
|
||||||
} else {
|
} else {
|
||||||
let portreg = self.port_reg();
|
|
||||||
let mask = self.mask_32();
|
|
||||||
// Safety: SETOUT is a "mask" register, and we only write the bit for
|
// Safety: SETOUT is a "mask" register, and we only write the bit for
|
||||||
// this pin ID
|
// this pin ID
|
||||||
unsafe {
|
unsafe {
|
||||||
if bit {
|
if bit {
|
||||||
portreg.setout().write(|w| w.bits(mask));
|
self.port_reg().setout().write(|w| w.bits(self.mask_32()));
|
||||||
} else {
|
} else {
|
||||||
portreg.clrout().write(|w| w.bits(mask));
|
self.port_reg().clrout().write(|w| w.bits(self.mask_32()));
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -270,18 +268,15 @@ pub(super) unsafe trait RegisterInterface {
|
|||||||
/// Toggle the logic level of an output pin
|
/// Toggle the logic level of an output pin
|
||||||
#[inline]
|
#[inline]
|
||||||
fn toggle(&mut self) {
|
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
|
// Safety: TOGOUT is a "mask" register, and we only write the bit for
|
||||||
// this pin ID
|
// 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
|
/// Only useful for input pins
|
||||||
#[inline]
|
#[inline]
|
||||||
fn filter_type(&self, filter: FilterType, clksel: FilterClkSel) {
|
fn filter_type(&self, filter: FilterType, clksel: FilterClkSel) {
|
||||||
let iocfg = self.iocfg_port();
|
self.iocfg_port().port[self.id().num as usize].modify(|_, w| {
|
||||||
iocfg.port[self.id().num as usize].modify(|_, w| {
|
|
||||||
// Safety: Only write to register for this Pin ID
|
// Safety: Only write to register for this Pin ID
|
||||||
unsafe {
|
unsafe {
|
||||||
w.flttype().bits(filter as u8);
|
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::{convert::Infallible, ptr};
|
||||||
use core::{marker::PhantomData, ops::Deref};
|
use core::{marker::PhantomData, ops::Deref};
|
||||||
use libm::floorf;
|
use libm::floorf;
|
||||||
|
Reference in New Issue
Block a user