Merge #581
581: stm32: expose all functionality as inherent methods. r=Dirbaio a=Dirbaio This is the previous step to implementing both the embedded-hal 0.2 and embedded-hal 1.0 + embedded-hal-async traits. The equivalent in nrf was done in #552 - Removes need for `unwrap` in gpio. - Removes need for `use embedded_hal::whatever` in all cases. Co-authored-by: Dario Nieuwenhuis <dirbaio@dirbaio.net>
This commit is contained in:
commit
6b0cb0609b
@ -16,7 +16,6 @@ use embassy_stm32::{
|
||||
TxParams,
|
||||
},
|
||||
};
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use lorawan_device::async_device::{
|
||||
radio::{Bandwidth, PhyRxTx, RfConfig, RxQuality, SpreadingFactor, TxConfig},
|
||||
Timings,
|
||||
@ -329,22 +328,22 @@ impl<'a> RadioSwitch<'a> {
|
||||
}
|
||||
|
||||
pub(crate) fn set_rx(&mut self) {
|
||||
self.ctrl1.set_high().unwrap();
|
||||
self.ctrl2.set_low().unwrap();
|
||||
self.ctrl3.set_high().unwrap();
|
||||
self.ctrl1.set_high();
|
||||
self.ctrl2.set_low();
|
||||
self.ctrl3.set_high();
|
||||
}
|
||||
|
||||
pub(crate) fn set_tx_lp(&mut self) {
|
||||
self.ctrl1.set_high().unwrap();
|
||||
self.ctrl2.set_high().unwrap();
|
||||
self.ctrl3.set_high().unwrap();
|
||||
self.ctrl1.set_high();
|
||||
self.ctrl2.set_high();
|
||||
self.ctrl3.set_high();
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn set_tx_hp(&mut self) {
|
||||
self.ctrl2.set_high().unwrap();
|
||||
self.ctrl1.set_low().unwrap();
|
||||
self.ctrl3.set_high().unwrap();
|
||||
self.ctrl2.set_high();
|
||||
self.ctrl1.set_low();
|
||||
self.ctrl3.set_high();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,2 +0,0 @@
|
||||
[pep8]
|
||||
max_line_length = 255
|
@ -89,7 +89,8 @@ pac::dma_channels! {
|
||||
($channel_peri:ident, $dma_peri:ident, bdma, $channel_num:expr, $dmamux:tt) => {
|
||||
impl crate::dma::sealed::Channel for crate::peripherals::$channel_peri {
|
||||
|
||||
unsafe fn start_write<W: Word>(&mut self, request: Request, buf: &[W], reg_addr: *mut W) {
|
||||
unsafe fn start_write<W: Word>(&mut self, request: Request, buf: *const[W], reg_addr: *mut W) {
|
||||
let (ptr, len) = super::slice_ptr_parts(buf);
|
||||
low_level_api::start_transfer(
|
||||
pac::$dma_peri,
|
||||
$channel_num,
|
||||
@ -97,8 +98,8 @@ pac::dma_channels! {
|
||||
request,
|
||||
vals::Dir::FROMMEMORY,
|
||||
reg_addr as *const u32,
|
||||
buf.as_ptr() as *mut u32,
|
||||
buf.len(),
|
||||
ptr as *mut u32,
|
||||
len,
|
||||
true,
|
||||
vals::Size::from(W::bits()),
|
||||
#[cfg(dmamux)]
|
||||
@ -129,7 +130,8 @@ pac::dma_channels! {
|
||||
)
|
||||
}
|
||||
|
||||
unsafe fn start_read<W: Word>(&mut self, request: Request, reg_addr: *mut W, buf: &mut [W]) {
|
||||
unsafe fn start_read<W: Word>(&mut self, request: Request, reg_addr: *const W, buf: *mut [W]) {
|
||||
let (ptr, len) = super::slice_ptr_parts_mut(buf);
|
||||
low_level_api::start_transfer(
|
||||
pac::$dma_peri,
|
||||
$channel_num,
|
||||
@ -137,8 +139,8 @@ pac::dma_channels! {
|
||||
request,
|
||||
vals::Dir::FROMPERIPHERAL,
|
||||
reg_addr as *const u32,
|
||||
buf.as_ptr() as *mut u32,
|
||||
buf.len(),
|
||||
ptr as *mut u32,
|
||||
len,
|
||||
true,
|
||||
vals::Size::from(W::bits()),
|
||||
#[cfg(dmamux)]
|
||||
|
@ -84,15 +84,16 @@ pub(crate) unsafe fn init() {
|
||||
pac::dma_channels! {
|
||||
($channel_peri:ident, $dma_peri:ident, dma, $channel_num:expr, $dmamux:tt) => {
|
||||
impl crate::dma::sealed::Channel for crate::peripherals::$channel_peri {
|
||||
unsafe fn start_write<W: Word>(&mut self, request: Request, buf: &[W], reg_addr: *mut W) {
|
||||
unsafe fn start_write<W: Word>(&mut self, request: Request, buf: *const [W], reg_addr: *mut W) {
|
||||
let (ptr, len) = super::slice_ptr_parts(buf);
|
||||
low_level_api::start_transfer(
|
||||
pac::$dma_peri,
|
||||
$channel_num,
|
||||
request,
|
||||
vals::Dir::MEMORYTOPERIPHERAL,
|
||||
reg_addr as *const u32,
|
||||
buf.as_ptr() as *mut u32,
|
||||
buf.len(),
|
||||
ptr as *mut u32,
|
||||
len,
|
||||
true,
|
||||
vals::Size::from(W::bits()),
|
||||
#[cfg(dmamux)]
|
||||
@ -121,15 +122,16 @@ pac::dma_channels! {
|
||||
)
|
||||
}
|
||||
|
||||
unsafe fn start_read<W: Word>(&mut self, request: Request, reg_addr: *mut W, buf: &mut [W]) {
|
||||
unsafe fn start_read<W: Word>(&mut self, request: Request, reg_addr: *const W, buf: *mut [W]) {
|
||||
let (ptr, len) = super::slice_ptr_parts_mut(buf);
|
||||
low_level_api::start_transfer(
|
||||
pac::$dma_peri,
|
||||
$channel_num,
|
||||
request,
|
||||
vals::Dir::PERIPHERALTOMEMORY,
|
||||
reg_addr as *const u32,
|
||||
buf.as_ptr() as *mut u32,
|
||||
buf.len(),
|
||||
ptr as *mut u32,
|
||||
len,
|
||||
true,
|
||||
vals::Size::from(W::bits()),
|
||||
#[cfg(dmamux)]
|
||||
|
@ -10,6 +10,7 @@ pub use dmamux::*;
|
||||
|
||||
use core::future::Future;
|
||||
use core::marker::PhantomData;
|
||||
use core::mem;
|
||||
use core::pin::Pin;
|
||||
use core::task::Waker;
|
||||
use core::task::{Context, Poll};
|
||||
@ -36,12 +37,13 @@ pub(crate) mod sealed {
|
||||
/// Starts this channel for writing a stream of words.
|
||||
///
|
||||
/// Safety:
|
||||
/// - `buf` must point to a valid buffer for DMA reading.
|
||||
/// - `buf` must be alive for the entire duration of the DMA transfer.
|
||||
/// - `reg_addr` must be a valid peripheral register address to write to.
|
||||
unsafe fn start_write<W: super::Word>(
|
||||
&mut self,
|
||||
request: Request,
|
||||
buf: &[W],
|
||||
buf: *const [W],
|
||||
reg_addr: *mut W,
|
||||
);
|
||||
|
||||
@ -60,13 +62,14 @@ pub(crate) mod sealed {
|
||||
/// Starts this channel for reading a stream of words.
|
||||
///
|
||||
/// Safety:
|
||||
/// - `buf` must point to a valid buffer for DMA writing.
|
||||
/// - `buf` must be alive for the entire duration of the DMA transfer.
|
||||
/// - `reg_addr` must be a valid peripheral register address to write to.
|
||||
/// - `reg_addr` must be a valid peripheral register address to read from.
|
||||
unsafe fn start_read<W: super::Word>(
|
||||
&mut self,
|
||||
request: Request,
|
||||
reg_addr: *mut W,
|
||||
buf: &mut [W],
|
||||
reg_addr: *const W,
|
||||
buf: *mut [W],
|
||||
);
|
||||
|
||||
/// Requests the channel to stop.
|
||||
@ -132,10 +135,7 @@ mod transfers {
|
||||
|
||||
unsafe { channel.start_read::<W>(request, reg_addr, buf) };
|
||||
|
||||
Transfer {
|
||||
channel,
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
Transfer::new(channel)
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
@ -150,10 +150,7 @@ mod transfers {
|
||||
|
||||
unsafe { channel.start_write::<W>(request, buf, reg_addr) };
|
||||
|
||||
Transfer {
|
||||
channel,
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
Transfer::new(channel)
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
@ -168,15 +165,22 @@ mod transfers {
|
||||
|
||||
unsafe { channel.start_write_repeated::<W>(request, repeated, count, reg_addr) };
|
||||
|
||||
Transfer {
|
||||
Transfer::new(channel)
|
||||
}
|
||||
|
||||
pub(crate) struct Transfer<'a, C: Channel> {
|
||||
channel: C,
|
||||
_phantom: PhantomData<&'a mut C>,
|
||||
}
|
||||
|
||||
impl<'a, C: Channel> Transfer<'a, C> {
|
||||
pub(crate) fn new(channel: impl Unborrow<Target = C> + 'a) -> Self {
|
||||
unborrow!(channel);
|
||||
Self {
|
||||
channel,
|
||||
_phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
struct Transfer<'a, C: Channel> {
|
||||
channel: C,
|
||||
_phantom: PhantomData<&'a mut C>,
|
||||
}
|
||||
|
||||
impl<'a, C: Channel> Drop for Transfer<'a, C> {
|
||||
@ -221,3 +225,14 @@ pub(crate) unsafe fn init() {
|
||||
#[cfg(dmamux)]
|
||||
dmamux::init();
|
||||
}
|
||||
|
||||
// TODO: replace transmutes with core::ptr::metadata once it's stable
|
||||
#[allow(unused)]
|
||||
pub(crate) fn slice_ptr_parts<T>(slice: *const [T]) -> (usize, usize) {
|
||||
unsafe { mem::transmute(slice) }
|
||||
}
|
||||
|
||||
#[allow(unused)]
|
||||
pub(crate) fn slice_ptr_parts_mut<T>(slice: *mut [T]) -> (usize, usize) {
|
||||
unsafe { mem::transmute(slice) }
|
||||
}
|
||||
|
@ -3,7 +3,9 @@ use core::future::Future;
|
||||
use core::marker::PhantomData;
|
||||
use core::pin::Pin;
|
||||
use core::task::{Context, Poll};
|
||||
use embassy::traits::gpio::{WaitForAnyEdge, WaitForFallingEdge, WaitForRisingEdge};
|
||||
use embassy::traits::gpio::{
|
||||
WaitForAnyEdge, WaitForFallingEdge, WaitForHigh, WaitForLow, WaitForRisingEdge,
|
||||
};
|
||||
use embassy::util::Unborrow;
|
||||
use embassy::waitqueue::AtomicWaker;
|
||||
use embassy_hal_common::unsafe_impl_unborrow;
|
||||
@ -94,17 +96,75 @@ impl<'d, T: GpioPin> ExtiInput<'d, T> {
|
||||
pub fn new(pin: Input<'d, T>, _ch: impl Unborrow<Target = T::ExtiChannel> + 'd) -> Self {
|
||||
Self { pin }
|
||||
}
|
||||
|
||||
pub fn is_high(&self) -> bool {
|
||||
self.pin.is_high()
|
||||
}
|
||||
|
||||
pub fn is_low(&self) -> bool {
|
||||
self.pin.is_low()
|
||||
}
|
||||
|
||||
pub async fn wait_for_high<'a>(&'a mut self) {
|
||||
let fut = ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), true, false);
|
||||
if self.is_high() {
|
||||
return;
|
||||
}
|
||||
fut.await
|
||||
}
|
||||
|
||||
pub async fn wait_for_low<'a>(&'a mut self) {
|
||||
let fut = ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), false, true);
|
||||
if self.is_low() {
|
||||
return;
|
||||
}
|
||||
fut.await
|
||||
}
|
||||
|
||||
pub async fn wait_for_rising_edge<'a>(&'a mut self) {
|
||||
ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), true, false).await
|
||||
}
|
||||
|
||||
pub async fn wait_for_falling_edge<'a>(&'a mut self) {
|
||||
ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), false, true).await
|
||||
}
|
||||
|
||||
pub async fn wait_for_any_edge<'a>(&'a mut self) {
|
||||
ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), true, true).await
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: GpioPin> InputPin for ExtiInput<'d, T> {
|
||||
type Error = Infallible;
|
||||
|
||||
fn is_high(&self) -> Result<bool, Self::Error> {
|
||||
self.pin.is_high()
|
||||
Ok(self.is_high())
|
||||
}
|
||||
|
||||
fn is_low(&self) -> Result<bool, Self::Error> {
|
||||
self.pin.is_low()
|
||||
Ok(self.is_low())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: GpioPin> WaitForHigh for ExtiInput<'d, T> {
|
||||
type Future<'a>
|
||||
where
|
||||
Self: 'a,
|
||||
= impl Future<Output = ()> + 'a;
|
||||
|
||||
fn wait_for_high<'a>(&'a mut self) -> Self::Future<'a> {
|
||||
self.wait_for_high()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: GpioPin> WaitForLow for ExtiInput<'d, T> {
|
||||
type Future<'a>
|
||||
where
|
||||
Self: 'a,
|
||||
= impl Future<Output = ()> + 'a;
|
||||
|
||||
fn wait_for_low<'a>(&'a mut self) -> Self::Future<'a> {
|
||||
self.wait_for_low()
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,10 +172,10 @@ impl<'d, T: GpioPin> WaitForRisingEdge for ExtiInput<'d, T> {
|
||||
type Future<'a>
|
||||
where
|
||||
Self: 'a,
|
||||
= ExtiInputFuture<'a>;
|
||||
= impl Future<Output = ()> + 'a;
|
||||
|
||||
fn wait_for_rising_edge<'a>(&'a mut self) -> Self::Future<'a> {
|
||||
ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), true, false)
|
||||
self.wait_for_rising_edge()
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,10 +183,10 @@ impl<'d, T: GpioPin> WaitForFallingEdge for ExtiInput<'d, T> {
|
||||
type Future<'a>
|
||||
where
|
||||
Self: 'a,
|
||||
= ExtiInputFuture<'a>;
|
||||
= impl Future<Output = ()> + 'a;
|
||||
|
||||
fn wait_for_falling_edge<'a>(&'a mut self) -> Self::Future<'a> {
|
||||
ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), false, true)
|
||||
self.wait_for_falling_edge()
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,21 +194,21 @@ impl<'d, T: GpioPin> WaitForAnyEdge for ExtiInput<'d, T> {
|
||||
type Future<'a>
|
||||
where
|
||||
Self: 'a,
|
||||
= ExtiInputFuture<'a>;
|
||||
= impl Future<Output = ()> + 'a;
|
||||
|
||||
fn wait_for_any_edge<'a>(&'a mut self) -> Self::Future<'a> {
|
||||
ExtiInputFuture::new(self.pin.pin.pin(), self.pin.pin.port(), true, true)
|
||||
self.wait_for_any_edge()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ExtiInputFuture<'a> {
|
||||
struct ExtiInputFuture<'a> {
|
||||
pin: u8,
|
||||
phantom: PhantomData<&'a mut AnyPin>,
|
||||
}
|
||||
|
||||
impl<'a> ExtiInputFuture<'a> {
|
||||
fn new(pin: u8, port: u8, rising: bool, falling: bool) -> Self {
|
||||
cortex_m::interrupt::free(|_| unsafe {
|
||||
critical_section::with(|_| unsafe {
|
||||
let pin = pin as usize;
|
||||
exticr_regs()
|
||||
.exticr(pin / 4)
|
||||
@ -177,7 +237,7 @@ impl<'a> ExtiInputFuture<'a> {
|
||||
|
||||
impl<'a> Drop for ExtiInputFuture<'a> {
|
||||
fn drop(&mut self) {
|
||||
cortex_m::interrupt::free(|_| unsafe {
|
||||
critical_section::with(|_| unsafe {
|
||||
let pin = self.pin as _;
|
||||
cpu_regs().imr(0).modify(|w| w.set_line(pin, false));
|
||||
});
|
||||
|
@ -3,7 +3,7 @@ use core::convert::Infallible;
|
||||
use core::marker::PhantomData;
|
||||
use embassy::util::Unborrow;
|
||||
use embassy_hal_common::{unborrow, unsafe_impl_unborrow};
|
||||
use embedded_hal::digital::v2::{toggleable, InputPin, OutputPin, StatefulOutputPin};
|
||||
use embedded_hal::digital::v2::{InputPin, OutputPin, StatefulOutputPin, ToggleableOutputPin};
|
||||
|
||||
use crate::pac;
|
||||
use crate::pac::gpio::{self, vals};
|
||||
@ -80,7 +80,7 @@ impl<'d, T: Pin> Input<'d, T> {
|
||||
pub fn new(pin: impl Unborrow<Target = T> + 'd, pull: Pull) -> Self {
|
||||
unborrow!(pin);
|
||||
|
||||
cortex_m::interrupt::free(|_| unsafe {
|
||||
critical_section::with(|_| unsafe {
|
||||
let r = pin.block();
|
||||
let n = pin.pin() as usize;
|
||||
#[cfg(gpio_v1)]
|
||||
@ -113,11 +113,20 @@ impl<'d, T: Pin> Input<'d, T> {
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_high(&self) -> bool {
|
||||
!self.is_low()
|
||||
}
|
||||
|
||||
pub fn is_low(&self) -> bool {
|
||||
let state = unsafe { self.pin.block().idr().read().idr(self.pin.pin() as _) };
|
||||
state == vals::Idr::LOW
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> Drop for Input<'d, T> {
|
||||
fn drop(&mut self) {
|
||||
cortex_m::interrupt::free(|_| unsafe {
|
||||
critical_section::with(|_| unsafe {
|
||||
let r = self.pin.block();
|
||||
let n = self.pin.pin() as usize;
|
||||
#[cfg(gpio_v1)]
|
||||
@ -132,19 +141,6 @@ impl<'d, T: Pin> Drop for Input<'d, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> InputPin for Input<'d, T> {
|
||||
type Error = Infallible;
|
||||
|
||||
fn is_high(&self) -> Result<bool, Self::Error> {
|
||||
self.is_low().map(|v| !v)
|
||||
}
|
||||
|
||||
fn is_low(&self) -> Result<bool, Self::Error> {
|
||||
let state = unsafe { self.pin.block().idr().read().idr(self.pin.pin() as _) };
|
||||
Ok(state == vals::Idr::LOW)
|
||||
}
|
||||
}
|
||||
|
||||
/// Digital input or output level.
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
|
||||
@ -168,7 +164,7 @@ impl<'d, T: Pin> Output<'d, T> {
|
||||
Level::Low => pin.set_low(),
|
||||
}
|
||||
|
||||
cortex_m::interrupt::free(|_| unsafe {
|
||||
critical_section::with(|_| unsafe {
|
||||
let r = pin.block();
|
||||
let n = pin.pin() as usize;
|
||||
#[cfg(gpio_v1)]
|
||||
@ -191,11 +187,41 @@ impl<'d, T: Pin> Output<'d, T> {
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the output as high.
|
||||
pub fn set_high(&mut self) {
|
||||
self.pin.set_high();
|
||||
}
|
||||
|
||||
/// Set the output as low.
|
||||
pub fn set_low(&mut self) {
|
||||
self.pin.set_low();
|
||||
}
|
||||
|
||||
/// Is the output pin set as high?
|
||||
pub fn is_set_high(&self) -> bool {
|
||||
!self.is_set_low()
|
||||
}
|
||||
|
||||
/// Is the output pin set as low?
|
||||
pub fn is_set_low(&self) -> bool {
|
||||
let state = unsafe { self.pin.block().odr().read().odr(self.pin.pin() as _) };
|
||||
state == vals::Odr::LOW
|
||||
}
|
||||
|
||||
/// Toggle pin output
|
||||
pub fn toggle(&mut self) {
|
||||
if self.is_set_low() {
|
||||
self.set_high()
|
||||
} else {
|
||||
self.set_low()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> Drop for Output<'d, T> {
|
||||
fn drop(&mut self) {
|
||||
cortex_m::interrupt::free(|_| unsafe {
|
||||
critical_section::with(|_| unsafe {
|
||||
let r = self.pin.block();
|
||||
let n = self.pin.pin() as usize;
|
||||
#[cfg(gpio_v1)]
|
||||
@ -214,37 +240,6 @@ impl<'d, T: Pin> Drop for Output<'d, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> OutputPin for Output<'d, T> {
|
||||
type Error = Infallible;
|
||||
|
||||
/// Set the output as high.
|
||||
fn set_high(&mut self) -> Result<(), Self::Error> {
|
||||
self.pin.set_high();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set the output as low.
|
||||
fn set_low(&mut self) -> Result<(), Self::Error> {
|
||||
self.pin.set_low();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> StatefulOutputPin for Output<'d, T> {
|
||||
/// Is the output pin set as high?
|
||||
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
||||
self.is_set_low().map(|v| !v)
|
||||
}
|
||||
|
||||
/// Is the output pin set as low?
|
||||
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
||||
let state = unsafe { self.pin.block().odr().read().odr(self.pin.pin() as _) };
|
||||
Ok(state == vals::Odr::LOW)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> toggleable::Default for Output<'d, T> {}
|
||||
|
||||
/// GPIO output open-drain driver.
|
||||
pub struct OutputOpenDrain<'d, T: Pin> {
|
||||
pub(crate) pin: T,
|
||||
@ -265,7 +260,7 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> {
|
||||
Level::Low => pin.set_low(),
|
||||
}
|
||||
|
||||
cortex_m::interrupt::free(|_| unsafe {
|
||||
critical_section::with(|_| unsafe {
|
||||
let r = pin.block();
|
||||
let n = pin.pin() as usize;
|
||||
#[cfg(gpio_v1)]
|
||||
@ -294,11 +289,50 @@ impl<'d, T: Pin> OutputOpenDrain<'d, T> {
|
||||
phantom: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_high(&self) -> bool {
|
||||
!self.is_low()
|
||||
}
|
||||
|
||||
pub fn is_low(&self) -> bool {
|
||||
let state = unsafe { self.pin.block().idr().read().idr(self.pin.pin() as _) };
|
||||
state == vals::Idr::LOW
|
||||
}
|
||||
|
||||
/// Set the output as high.
|
||||
pub fn set_high(&mut self) {
|
||||
self.pin.set_high();
|
||||
}
|
||||
|
||||
/// Set the output as low.
|
||||
pub fn set_low(&mut self) {
|
||||
self.pin.set_low();
|
||||
}
|
||||
|
||||
/// Is the output pin set as high?
|
||||
pub fn is_set_high(&self) -> bool {
|
||||
!self.is_set_low()
|
||||
}
|
||||
|
||||
/// Is the output pin set as low?
|
||||
pub fn is_set_low(&self) -> bool {
|
||||
let state = unsafe { self.pin.block().odr().read().odr(self.pin.pin() as _) };
|
||||
state == vals::Odr::LOW
|
||||
}
|
||||
|
||||
/// Toggle pin output
|
||||
pub fn toggle(&mut self) {
|
||||
if self.is_set_low() {
|
||||
self.set_high()
|
||||
} else {
|
||||
self.set_low()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> Drop for OutputOpenDrain<'d, T> {
|
||||
fn drop(&mut self) {
|
||||
cortex_m::interrupt::free(|_| unsafe {
|
||||
critical_section::with(|_| unsafe {
|
||||
let r = self.pin.block();
|
||||
let n = self.pin.pin() as usize;
|
||||
#[cfg(gpio_v1)]
|
||||
@ -317,36 +351,6 @@ impl<'d, T: Pin> Drop for OutputOpenDrain<'d, T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> OutputPin for OutputOpenDrain<'d, T> {
|
||||
type Error = Infallible;
|
||||
|
||||
/// Set the output as high.
|
||||
fn set_high(&mut self) -> Result<(), Self::Error> {
|
||||
self.pin.set_high();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Set the output as low.
|
||||
fn set_low(&mut self) -> Result<(), Self::Error> {
|
||||
self.pin.set_low();
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> InputPin for OutputOpenDrain<'d, T> {
|
||||
type Error = Infallible;
|
||||
|
||||
fn is_high(&self) -> Result<bool, Self::Error> {
|
||||
self.is_low().map(|v| !v)
|
||||
}
|
||||
|
||||
fn is_low(&self) -> Result<bool, Self::Error> {
|
||||
// NOTE(safety) Atomic read
|
||||
let state = unsafe { self.pin.block().idr().read().idr(self.pin.pin() as usize) };
|
||||
Ok(state == vals::Idr::LOW)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) mod sealed {
|
||||
use super::*;
|
||||
|
||||
@ -612,3 +616,79 @@ pub(crate) unsafe fn init() {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
mod eh02 {
|
||||
use super::*;
|
||||
|
||||
impl<'d, T: Pin> InputPin for Input<'d, T> {
|
||||
type Error = Infallible;
|
||||
|
||||
fn is_high(&self) -> Result<bool, Self::Error> {
|
||||
Ok(self.is_high())
|
||||
}
|
||||
|
||||
fn is_low(&self) -> Result<bool, Self::Error> {
|
||||
Ok(self.is_low())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> OutputPin for Output<'d, T> {
|
||||
type Error = Infallible;
|
||||
|
||||
fn set_high(&mut self) -> Result<(), Self::Error> {
|
||||
Ok(self.set_high())
|
||||
}
|
||||
|
||||
fn set_low(&mut self) -> Result<(), Self::Error> {
|
||||
Ok(self.set_low())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> StatefulOutputPin for Output<'d, T> {
|
||||
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
||||
Ok(self.is_set_high())
|
||||
}
|
||||
|
||||
/// Is the output pin set as low?
|
||||
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
||||
Ok(self.is_set_low())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> ToggleableOutputPin for Output<'d, T> {
|
||||
type Error = Infallible;
|
||||
fn toggle(&mut self) -> Result<(), Self::Error> {
|
||||
Ok(self.toggle())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> OutputPin for OutputOpenDrain<'d, T> {
|
||||
type Error = Infallible;
|
||||
|
||||
fn set_high(&mut self) -> Result<(), Self::Error> {
|
||||
Ok(self.set_high())
|
||||
}
|
||||
|
||||
fn set_low(&mut self) -> Result<(), Self::Error> {
|
||||
Ok(self.set_low())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> StatefulOutputPin for OutputOpenDrain<'d, T> {
|
||||
fn is_set_high(&self) -> Result<bool, Self::Error> {
|
||||
Ok(self.is_set_high())
|
||||
}
|
||||
|
||||
/// Is the output pin set as low?
|
||||
fn is_set_low(&self) -> Result<bool, Self::Error> {
|
||||
Ok(self.is_set_low())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Pin> ToggleableOutputPin for OutputOpenDrain<'d, T> {
|
||||
type Error = Infallible;
|
||||
fn toggle(&mut self) -> Result<(), Self::Error> {
|
||||
Ok(self.toggle())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,6 @@ use crate::time::Hertz;
|
||||
use core::marker::PhantomData;
|
||||
use embassy::util::Unborrow;
|
||||
use embassy_hal_common::unborrow;
|
||||
use embedded_hal::blocking::i2c::Read;
|
||||
use embedded_hal::blocking::i2c::Write;
|
||||
use embedded_hal::blocking::i2c::WriteRead;
|
||||
|
||||
use crate::pac::i2c;
|
||||
|
||||
@ -179,12 +176,8 @@ impl<'d, T: Instance> I2c<'d, T> {
|
||||
let value = T::regs().dr().read().dr();
|
||||
Ok(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Instance> Read for I2c<'d, T> {
|
||||
type Error = Error;
|
||||
|
||||
fn read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Self::Error> {
|
||||
pub fn blocking_read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Error> {
|
||||
if let Some((last, buffer)) = buffer.split_last_mut() {
|
||||
// Send a START condition and set ACK bit
|
||||
unsafe {
|
||||
@ -248,12 +241,8 @@ impl<'d, T: Instance> Read for I2c<'d, T> {
|
||||
Err(Error::Overrun)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Instance> Write for I2c<'d, T> {
|
||||
type Error = Error;
|
||||
|
||||
fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Self::Error> {
|
||||
pub fn blocking_write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Error> {
|
||||
unsafe {
|
||||
self.write_bytes(addr, bytes)?;
|
||||
// Send a STOP condition
|
||||
@ -267,16 +256,41 @@ impl<'d, T: Instance> Write for I2c<'d, T> {
|
||||
// Fallthrough is success
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn blocking_write_read(
|
||||
&mut self,
|
||||
addr: u8,
|
||||
bytes: &[u8],
|
||||
buffer: &mut [u8],
|
||||
) -> Result<(), Error> {
|
||||
unsafe { self.write_bytes(addr, bytes)? };
|
||||
self.blocking_read(addr, buffer)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Instance> WriteRead for I2c<'d, T> {
|
||||
impl<'d, T: Instance> embedded_hal::blocking::i2c::Read for I2c<'d, T> {
|
||||
type Error = Error;
|
||||
|
||||
fn read(&mut self, addr: u8, buffer: &mut [u8]) -> Result<(), Self::Error> {
|
||||
self.blocking_read(addr, buffer)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Instance> embedded_hal::blocking::i2c::Write for I2c<'d, T> {
|
||||
type Error = Error;
|
||||
|
||||
fn write(&mut self, addr: u8, bytes: &[u8]) -> Result<(), Self::Error> {
|
||||
self.blocking_write(addr, bytes)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Instance> embedded_hal::blocking::i2c::WriteRead for I2c<'d, T> {
|
||||
type Error = Error;
|
||||
|
||||
fn write_read(&mut self, addr: u8, bytes: &[u8], buffer: &mut [u8]) -> Result<(), Self::Error> {
|
||||
unsafe { self.write_bytes(addr, bytes)? };
|
||||
self.read(addr, buffer)?;
|
||||
|
||||
Ok(())
|
||||
self.blocking_write_read(addr, bytes, buffer)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,9 +10,6 @@ use embassy::util::Unborrow;
|
||||
use embassy::waitqueue::AtomicWaker;
|
||||
use embassy_hal_common::drop::OnDrop;
|
||||
use embassy_hal_common::unborrow;
|
||||
use embedded_hal::blocking::i2c::Read;
|
||||
use embedded_hal::blocking::i2c::Write;
|
||||
use embedded_hal::blocking::i2c::WriteRead;
|
||||
use futures::future::poll_fn;
|
||||
|
||||
use crate::dma::NoDma;
|
||||
@ -300,7 +297,12 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
|
||||
}
|
||||
}
|
||||
|
||||
fn read(&mut self, address: u8, buffer: &mut [u8], restart: bool) -> Result<(), Error> {
|
||||
fn read_internal(
|
||||
&mut self,
|
||||
address: u8,
|
||||
buffer: &mut [u8],
|
||||
restart: bool,
|
||||
) -> Result<(), Error> {
|
||||
let completed_chunks = buffer.len() / 255;
|
||||
let total_chunks = if completed_chunks * 255 == buffer.len() {
|
||||
completed_chunks
|
||||
@ -339,7 +341,7 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn write(&mut self, address: u8, bytes: &[u8], send_stop: bool) -> Result<(), Error> {
|
||||
fn write_internal(&mut self, address: u8, bytes: &[u8], send_stop: bool) -> Result<(), Error> {
|
||||
let completed_chunks = bytes.len() / 255;
|
||||
let total_chunks = if completed_chunks * 255 == bytes.len() {
|
||||
completed_chunks
|
||||
@ -568,14 +570,17 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn write_dma(&mut self, address: u8, bytes: &[u8]) -> Result<(), Error>
|
||||
// =========================
|
||||
// Async public API
|
||||
|
||||
pub async fn write(&mut self, address: u8, bytes: &[u8]) -> Result<(), Error>
|
||||
where
|
||||
TXDMA: crate::i2c::TxDma<T>,
|
||||
{
|
||||
self.write_dma_internal(address, bytes, true, true).await
|
||||
}
|
||||
|
||||
pub async fn write_dma_vectored(&mut self, address: u8, bytes: &[&[u8]]) -> Result<(), Error>
|
||||
pub async fn write_vectored(&mut self, address: u8, bytes: &[&[u8]]) -> Result<(), Error>
|
||||
where
|
||||
TXDMA: crate::i2c::TxDma<T>,
|
||||
{
|
||||
@ -597,19 +602,52 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn read_dma(
|
||||
&mut self,
|
||||
address: u8,
|
||||
buffer: &mut [u8],
|
||||
restart: bool,
|
||||
) -> Result<(), Error>
|
||||
pub async fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Error>
|
||||
where
|
||||
RXDMA: crate::i2c::RxDma<T>,
|
||||
{
|
||||
self.read_dma_internal(address, buffer, restart).await
|
||||
self.read_dma_internal(address, buffer, false).await
|
||||
}
|
||||
|
||||
pub fn write_vectored(&mut self, address: u8, bytes: &[&[u8]]) -> Result<(), Error> {
|
||||
pub async fn write_read(
|
||||
&mut self,
|
||||
address: u8,
|
||||
bytes: &[u8],
|
||||
buffer: &mut [u8],
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
TXDMA: super::TxDma<T>,
|
||||
RXDMA: super::RxDma<T>,
|
||||
{
|
||||
self.write_dma_internal(address, bytes, true, true).await?;
|
||||
self.read_dma_internal(address, buffer, true).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// =========================
|
||||
// Blocking public API
|
||||
|
||||
pub fn blocking_read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Error> {
|
||||
self.read_internal(address, buffer, false)
|
||||
// Automatic Stop
|
||||
}
|
||||
|
||||
pub fn blocking_write(&mut self, address: u8, bytes: &[u8]) -> Result<(), Error> {
|
||||
self.write_internal(address, bytes, true)
|
||||
}
|
||||
|
||||
pub fn blocking_write_read(
|
||||
&mut self,
|
||||
address: u8,
|
||||
bytes: &[u8],
|
||||
buffer: &mut [u8],
|
||||
) -> Result<(), Error> {
|
||||
self.write_internal(address, bytes, false)?;
|
||||
self.read_internal(address, buffer, true)
|
||||
// Automatic Stop
|
||||
}
|
||||
|
||||
pub fn blocking_write_vectored(&mut self, address: u8, bytes: &[&[u8]]) -> Result<(), Error> {
|
||||
if bytes.is_empty() {
|
||||
return Err(Error::ZeroLengthTransfer);
|
||||
}
|
||||
@ -679,24 +717,23 @@ impl<'d, T: Instance, TXDMA, RXDMA> I2c<'d, T, TXDMA, RXDMA> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Instance> Read for I2c<'d, T> {
|
||||
impl<'d, T: Instance> embedded_hal::blocking::i2c::Read for I2c<'d, T> {
|
||||
type Error = Error;
|
||||
|
||||
fn read(&mut self, address: u8, buffer: &mut [u8]) -> Result<(), Self::Error> {
|
||||
self.read(address, buffer, false)
|
||||
// Automatic Stop
|
||||
self.blocking_read(address, buffer)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Instance> Write for I2c<'d, T> {
|
||||
impl<'d, T: Instance> embedded_hal::blocking::i2c::Write for I2c<'d, T> {
|
||||
type Error = Error;
|
||||
|
||||
fn write(&mut self, address: u8, bytes: &[u8]) -> Result<(), Self::Error> {
|
||||
self.write(address, bytes, true)
|
||||
self.blocking_write(address, bytes)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Instance> WriteRead for I2c<'d, T> {
|
||||
impl<'d, T: Instance> embedded_hal::blocking::i2c::WriteRead for I2c<'d, T> {
|
||||
type Error = Error;
|
||||
|
||||
fn write_read(
|
||||
@ -705,9 +742,7 @@ impl<'d, T: Instance> WriteRead for I2c<'d, T> {
|
||||
bytes: &[u8],
|
||||
buffer: &mut [u8],
|
||||
) -> Result<(), Self::Error> {
|
||||
self.write(address, bytes, false)?;
|
||||
self.read(address, buffer, true)
|
||||
// Automatic Stop
|
||||
self.blocking_write_read(address, bytes, buffer)
|
||||
}
|
||||
}
|
||||
|
||||
@ -715,7 +750,7 @@ impl<'d, T: Instance> WriteRead for I2c<'d, T> {
|
||||
///
|
||||
/// Peripheral options for generating the STOP condition
|
||||
#[derive(Copy, Clone, PartialEq)]
|
||||
pub enum Stop {
|
||||
enum Stop {
|
||||
/// Software end mode: Must write register to generate STOP condition
|
||||
Software,
|
||||
/// Automatic end mode: A STOP condition is automatically generated once the
|
||||
@ -860,32 +895,23 @@ impl<'d, T: Instance, TXDMA: super::TxDma<T>, RXDMA: super::RxDma<T>> I2cTrait<u
|
||||
|
||||
type WriteFuture<'a>
|
||||
where
|
||||
'd: 'a,
|
||||
T: 'a,
|
||||
TXDMA: 'a,
|
||||
RXDMA: 'a,
|
||||
Self: 'a,
|
||||
= impl Future<Output = Result<(), Self::Error>> + 'a;
|
||||
type ReadFuture<'a>
|
||||
where
|
||||
'd: 'a,
|
||||
T: 'a,
|
||||
TXDMA: 'a,
|
||||
RXDMA: 'a,
|
||||
Self: 'a,
|
||||
= impl Future<Output = Result<(), Self::Error>> + 'a;
|
||||
type WriteReadFuture<'a>
|
||||
where
|
||||
'd: 'a,
|
||||
T: 'a,
|
||||
TXDMA: 'a,
|
||||
RXDMA: 'a,
|
||||
Self: 'a,
|
||||
= impl Future<Output = Result<(), Self::Error>> + 'a;
|
||||
|
||||
fn read<'a>(&'a mut self, address: u8, buffer: &'a mut [u8]) -> Self::ReadFuture<'a> {
|
||||
self.read_dma(address, buffer, false)
|
||||
self.read(address, buffer)
|
||||
}
|
||||
|
||||
fn write<'a>(&'a mut self, address: u8, bytes: &'a [u8]) -> Self::WriteFuture<'a> {
|
||||
self.write_dma(address, bytes)
|
||||
self.write(address, bytes)
|
||||
}
|
||||
|
||||
fn write_read<'a>(
|
||||
@ -894,9 +920,6 @@ impl<'d, T: Instance, TXDMA: super::TxDma<T>, RXDMA: super::RxDma<T>> I2cTrait<u
|
||||
bytes: &'a [u8],
|
||||
buffer: &'a mut [u8],
|
||||
) -> Self::WriteReadFuture<'a> {
|
||||
async move {
|
||||
self.write_dma(address, bytes).await?;
|
||||
self.read_dma(address, buffer, true).await
|
||||
}
|
||||
self.write_read(address, bytes, buffer)
|
||||
}
|
||||
}
|
||||
|
@ -1254,7 +1254,7 @@ where
|
||||
fn configure(&mut self) {
|
||||
let (clk_pin, cmd_pin, d0_pin, d1_pin, d2_pin, d3_pin) = self;
|
||||
|
||||
cortex_m::interrupt::free(|_| unsafe {
|
||||
critical_section::with(|_| unsafe {
|
||||
// clk
|
||||
let block = clk_pin.block();
|
||||
let n = clk_pin.pin() as usize;
|
||||
@ -1298,7 +1298,7 @@ where
|
||||
|
||||
let (clk_pin, cmd_pin, d0_pin, d1_pin, d2_pin, d3_pin) = self;
|
||||
|
||||
cortex_m::interrupt::free(|_| unsafe {
|
||||
critical_section::with(|_| unsafe {
|
||||
// clk
|
||||
let n = clk_pin.pin().into();
|
||||
clk_pin
|
||||
@ -1400,7 +1400,7 @@ where
|
||||
fn configure(&mut self) {
|
||||
let (clk_pin, cmd_pin, d0_pin) = self;
|
||||
|
||||
cortex_m::interrupt::free(|_| unsafe {
|
||||
critical_section::with(|_| unsafe {
|
||||
// clk
|
||||
let block = clk_pin.block();
|
||||
let n = clk_pin.pin() as usize;
|
||||
@ -1426,7 +1426,7 @@ where
|
||||
|
||||
let (clk_pin, cmd_pin, d0_pin) = self;
|
||||
|
||||
cortex_m::interrupt::free(|_| unsafe {
|
||||
critical_section::with(|_| unsafe {
|
||||
// clk
|
||||
let n = clk_pin.pin().into();
|
||||
clk_pin
|
||||
|
@ -1,5 +1,13 @@
|
||||
#![macro_use]
|
||||
|
||||
use core::future::Future;
|
||||
use core::marker::PhantomData;
|
||||
use core::ptr;
|
||||
use embassy::util::Unborrow;
|
||||
use embassy_hal_common::unborrow;
|
||||
use embassy_traits::spi as traits;
|
||||
|
||||
use self::sealed::WordSize;
|
||||
use crate::dma;
|
||||
use crate::dma::NoDma;
|
||||
use crate::gpio::sealed::{AFType, Pin};
|
||||
@ -8,19 +16,14 @@ use crate::pac::spi::{regs, vals};
|
||||
use crate::peripherals;
|
||||
use crate::rcc::RccPeripheral;
|
||||
use crate::time::Hertz;
|
||||
use core::future::Future;
|
||||
use core::marker::PhantomData;
|
||||
use core::ptr;
|
||||
use embassy::util::Unborrow;
|
||||
use embassy_hal_common::unborrow;
|
||||
use embassy_traits::spi as traits;
|
||||
|
||||
pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
|
||||
|
||||
#[cfg_attr(spi_v1, path = "v1.rs")]
|
||||
#[cfg_attr(spi_f1, path = "v1.rs")]
|
||||
#[cfg_attr(spi_v2, path = "v2.rs")]
|
||||
#[cfg_attr(spi_v3, path = "v3.rs")]
|
||||
mod _version;
|
||||
pub use _version::*;
|
||||
|
||||
type Regs = &'static crate::pac::spi::Spi;
|
||||
|
||||
@ -40,54 +43,6 @@ pub enum BitOrder {
|
||||
MsbFirst,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialOrd, PartialEq)]
|
||||
enum WordSize {
|
||||
EightBit,
|
||||
SixteenBit,
|
||||
}
|
||||
|
||||
impl WordSize {
|
||||
#[cfg(any(spi_v1, spi_f1))]
|
||||
fn dff(&self) -> vals::Dff {
|
||||
match self {
|
||||
WordSize::EightBit => vals::Dff::EIGHTBIT,
|
||||
WordSize::SixteenBit => vals::Dff::SIXTEENBIT,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(spi_v2)]
|
||||
fn ds(&self) -> vals::Ds {
|
||||
match self {
|
||||
WordSize::EightBit => vals::Ds::EIGHTBIT,
|
||||
WordSize::SixteenBit => vals::Ds::SIXTEENBIT,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(spi_v2)]
|
||||
fn frxth(&self) -> vals::Frxth {
|
||||
match self {
|
||||
WordSize::EightBit => vals::Frxth::QUARTER,
|
||||
WordSize::SixteenBit => vals::Frxth::HALF,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(spi_v3)]
|
||||
fn dsize(&self) -> u8 {
|
||||
match self {
|
||||
WordSize::EightBit => 0b0111,
|
||||
WordSize::SixteenBit => 0b1111,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(spi_v3)]
|
||||
fn _frxth(&self) -> vals::Fthlv {
|
||||
match self {
|
||||
WordSize::EightBit => vals::Fthlv::ONEFRAME,
|
||||
WordSize::SixteenBit => vals::Fthlv::ONEFRAME,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[non_exhaustive]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Config {
|
||||
@ -379,6 +334,47 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
|
||||
self.current_word_size = word_size;
|
||||
}
|
||||
|
||||
pub async fn write(&mut self, data: &[u8]) -> Result<(), Error>
|
||||
where
|
||||
Tx: TxDmaChannel<T>,
|
||||
{
|
||||
self.write_dma_u8(data).await
|
||||
}
|
||||
|
||||
pub async fn read(&mut self, data: &mut [u8]) -> Result<(), Error>
|
||||
where
|
||||
Tx: TxDmaChannel<T>,
|
||||
Rx: RxDmaChannel<T>,
|
||||
{
|
||||
self.read_dma_u8(data).await
|
||||
}
|
||||
|
||||
pub async fn transfer(&mut self, read: &mut [u8], write: &[u8]) -> Result<(), Error>
|
||||
where
|
||||
Tx: TxDmaChannel<T>,
|
||||
Rx: RxDmaChannel<T>,
|
||||
{
|
||||
self.transfer_dma_u8(read, write).await
|
||||
}
|
||||
|
||||
pub fn blocking_write<W: Word>(&mut self, words: &[W]) -> Result<(), Error> {
|
||||
self.set_word_size(W::WORDSIZE);
|
||||
let regs = T::regs();
|
||||
for word in words.iter() {
|
||||
let _ = transfer_word(regs, *word)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn blocking_transfer_in_place<W: Word>(&mut self, words: &mut [W]) -> Result<(), Error> {
|
||||
self.set_word_size(W::WORDSIZE);
|
||||
let regs = T::regs();
|
||||
for word in words.iter_mut() {
|
||||
*word = transfer_word(regs, *word)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Instance, Tx, Rx> Drop for Spi<'d, T, Tx, Rx> {
|
||||
@ -537,17 +533,6 @@ fn finish_dma(regs: Regs) {
|
||||
}
|
||||
}
|
||||
|
||||
trait Word {
|
||||
const WORDSIZE: WordSize;
|
||||
}
|
||||
|
||||
impl Word for u8 {
|
||||
const WORDSIZE: WordSize = WordSize::EightBit;
|
||||
}
|
||||
impl Word for u16 {
|
||||
const WORDSIZE: WordSize = WordSize::SixteenBit;
|
||||
}
|
||||
|
||||
fn transfer_word<W: Word>(regs: Regs, tx_word: W) -> Result<W, Error> {
|
||||
spin_until_tx_ready(regs)?;
|
||||
|
||||
@ -572,14 +557,7 @@ macro_rules! impl_blocking {
|
||||
type Error = Error;
|
||||
|
||||
fn write(&mut self, words: &[$w]) -> Result<(), Self::Error> {
|
||||
self.set_word_size($w::WORDSIZE);
|
||||
let regs = T::regs();
|
||||
|
||||
for word in words.iter() {
|
||||
let _ = transfer_word(regs, *word)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
self.blocking_write(words)
|
||||
}
|
||||
}
|
||||
|
||||
@ -589,13 +567,7 @@ macro_rules! impl_blocking {
|
||||
type Error = Error;
|
||||
|
||||
fn transfer<'w>(&mut self, words: &'w mut [$w]) -> Result<&'w [$w], Self::Error> {
|
||||
self.set_word_size($w::WORDSIZE);
|
||||
let regs = T::regs();
|
||||
|
||||
for word in words.iter_mut() {
|
||||
*word = transfer_word(regs, *word)?;
|
||||
}
|
||||
|
||||
self.blocking_transfer_in_place(words)?;
|
||||
Ok(words)
|
||||
}
|
||||
}
|
||||
@ -616,7 +588,7 @@ impl<'d, T: Instance, Tx: TxDmaChannel<T>, Rx> traits::Write<u8> for Spi<'d, T,
|
||||
= impl Future<Output = Result<(), Self::Error>> + 'a;
|
||||
|
||||
fn write<'a>(&'a mut self, data: &'a [u8]) -> Self::WriteFuture<'a> {
|
||||
self.write_dma_u8(data)
|
||||
self.write(data)
|
||||
}
|
||||
}
|
||||
|
||||
@ -629,7 +601,7 @@ impl<'d, T: Instance, Tx: TxDmaChannel<T>, Rx: RxDmaChannel<T>> traits::Read<u8>
|
||||
= impl Future<Output = Result<(), Self::Error>> + 'a;
|
||||
|
||||
fn read<'a>(&'a mut self, data: &'a mut [u8]) -> Self::ReadFuture<'a> {
|
||||
self.read_dma_u8(data)
|
||||
self.read(data)
|
||||
}
|
||||
}
|
||||
|
||||
@ -646,7 +618,7 @@ impl<'d, T: Instance, Tx: TxDmaChannel<T>, Rx: RxDmaChannel<T>> traits::FullDupl
|
||||
read: &'a mut [u8],
|
||||
write: &'a [u8],
|
||||
) -> Self::WriteReadFuture<'a> {
|
||||
self.read_write_dma_u8(read, write)
|
||||
self.transfer(read, write)
|
||||
}
|
||||
}
|
||||
|
||||
@ -676,8 +648,72 @@ pub(crate) mod sealed {
|
||||
pub trait RxDmaChannel<T: Instance> {
|
||||
fn request(&self) -> dma::Request;
|
||||
}
|
||||
|
||||
pub trait Word: Copy + 'static {
|
||||
const WORDSIZE: WordSize;
|
||||
}
|
||||
|
||||
impl Word for u8 {
|
||||
const WORDSIZE: WordSize = WordSize::EightBit;
|
||||
}
|
||||
impl Word for u16 {
|
||||
const WORDSIZE: WordSize = WordSize::SixteenBit;
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialOrd, PartialEq)]
|
||||
pub enum WordSize {
|
||||
EightBit,
|
||||
SixteenBit,
|
||||
}
|
||||
|
||||
impl WordSize {
|
||||
#[cfg(any(spi_v1, spi_f1))]
|
||||
pub fn dff(&self) -> vals::Dff {
|
||||
match self {
|
||||
WordSize::EightBit => vals::Dff::EIGHTBIT,
|
||||
WordSize::SixteenBit => vals::Dff::SIXTEENBIT,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(spi_v2)]
|
||||
pub fn ds(&self) -> vals::Ds {
|
||||
match self {
|
||||
WordSize::EightBit => vals::Ds::EIGHTBIT,
|
||||
WordSize::SixteenBit => vals::Ds::SIXTEENBIT,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(spi_v2)]
|
||||
pub fn frxth(&self) -> vals::Frxth {
|
||||
match self {
|
||||
WordSize::EightBit => vals::Frxth::QUARTER,
|
||||
WordSize::SixteenBit => vals::Frxth::HALF,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(spi_v3)]
|
||||
pub fn dsize(&self) -> u8 {
|
||||
match self {
|
||||
WordSize::EightBit => 0b0111,
|
||||
WordSize::SixteenBit => 0b1111,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(spi_v3)]
|
||||
pub fn _frxth(&self) -> vals::Fthlv {
|
||||
match self {
|
||||
WordSize::EightBit => vals::Fthlv::ONEFRAME,
|
||||
WordSize::SixteenBit => vals::Fthlv::ONEFRAME,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Word: Copy + 'static + sealed::Word {}
|
||||
|
||||
impl Word for u8 {}
|
||||
impl Word for u16 {}
|
||||
|
||||
pub trait Instance: sealed::Instance + RccPeripheral {}
|
||||
pub trait SckPin<T: Instance>: sealed::SckPin<T> {}
|
||||
pub trait MosiPin<T: Instance>: sealed::MosiPin<T> {}
|
||||
|
@ -1,13 +1,12 @@
|
||||
#![macro_use]
|
||||
|
||||
pub use embedded_hal::blocking;
|
||||
pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
|
||||
use futures::future::join;
|
||||
|
||||
use super::*;
|
||||
use crate::dma::{slice_ptr_parts, slice_ptr_parts_mut, Transfer};
|
||||
|
||||
impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
pub(super) async fn write_dma_u8(&mut self, write: &[u8]) -> Result<(), Error>
|
||||
pub(super) async fn write_dma_u8(&mut self, write: *const [u8]) -> Result<(), Error>
|
||||
where
|
||||
Tx: TxDmaChannel<T>,
|
||||
{
|
||||
@ -18,9 +17,10 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
}
|
||||
self.set_word_size(WordSize::EightBit);
|
||||
|
||||
let request = self.txdma.request();
|
||||
let dst = T::regs().tx_ptr();
|
||||
let f = crate::dma::write(&mut self.txdma, request, write, dst);
|
||||
let tx_request = self.txdma.request();
|
||||
let tx_dst = T::regs().tx_ptr();
|
||||
unsafe { self.txdma.start_write(tx_request, write, tx_dst) }
|
||||
let tx_f = Transfer::new(&mut self.txdma);
|
||||
|
||||
unsafe {
|
||||
T::regs().cr2().modify(|reg| {
|
||||
@ -31,14 +31,14 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
});
|
||||
}
|
||||
|
||||
f.await;
|
||||
tx_f.await;
|
||||
|
||||
finish_dma(T::regs());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) async fn read_dma_u8(&mut self, read: &mut [u8]) -> Result<(), Error>
|
||||
pub(super) async fn read_dma_u8(&mut self, read: *mut [u8]) -> Result<(), Error>
|
||||
where
|
||||
Tx: TxDmaChannel<T>,
|
||||
Rx: RxDmaChannel<T>,
|
||||
@ -53,11 +53,12 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
}
|
||||
self.set_word_size(WordSize::EightBit);
|
||||
|
||||
let clock_byte_count = read.len();
|
||||
let (_, clock_byte_count) = slice_ptr_parts_mut(read);
|
||||
|
||||
let rx_request = self.rxdma.request();
|
||||
let rx_src = T::regs().rx_ptr();
|
||||
let rx_f = crate::dma::read(&mut self.rxdma, rx_request, rx_src, read);
|
||||
unsafe { self.rxdma.start_read(rx_request, rx_src, read) };
|
||||
let rx_f = Transfer::new(&mut self.rxdma);
|
||||
|
||||
let tx_request = self.txdma.request();
|
||||
let tx_dst = T::regs().tx_ptr();
|
||||
@ -86,16 +87,18 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) async fn read_write_dma_u8(
|
||||
pub(super) async fn transfer_dma_u8(
|
||||
&mut self,
|
||||
read: &mut [u8],
|
||||
write: &[u8],
|
||||
read: *mut [u8],
|
||||
write: *const [u8],
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
Tx: TxDmaChannel<T>,
|
||||
Rx: RxDmaChannel<T>,
|
||||
{
|
||||
assert!(read.len() >= write.len());
|
||||
let (_, rx_len) = slice_ptr_parts(read);
|
||||
let (_, tx_len) = slice_ptr_parts(write);
|
||||
assert_eq!(rx_len, tx_len);
|
||||
|
||||
unsafe {
|
||||
T::regs().cr1().modify(|w| {
|
||||
@ -109,16 +112,13 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
|
||||
let rx_request = self.rxdma.request();
|
||||
let rx_src = T::regs().rx_ptr();
|
||||
let rx_f = crate::dma::read(
|
||||
&mut self.rxdma,
|
||||
rx_request,
|
||||
rx_src,
|
||||
&mut read[0..write.len()],
|
||||
);
|
||||
unsafe { self.rxdma.start_read(rx_request, rx_src, read) };
|
||||
let rx_f = Transfer::new(&mut self.rxdma);
|
||||
|
||||
let tx_request = self.txdma.request();
|
||||
let tx_dst = T::regs().tx_ptr();
|
||||
let tx_f = crate::dma::write(&mut self.txdma, tx_request, write, tx_dst);
|
||||
unsafe { self.txdma.start_write(tx_request, write, tx_dst) }
|
||||
let tx_f = Transfer::new(&mut self.txdma);
|
||||
|
||||
unsafe {
|
||||
T::regs().cr2().modify(|reg| {
|
||||
|
@ -1,12 +1,12 @@
|
||||
#![macro_use]
|
||||
|
||||
pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
|
||||
use futures::future::join;
|
||||
|
||||
use super::*;
|
||||
use crate::dma::{slice_ptr_parts, slice_ptr_parts_mut, Transfer};
|
||||
|
||||
impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
pub(super) async fn write_dma_u8(&mut self, write: &[u8]) -> Result<(), Error>
|
||||
pub(super) async fn write_dma_u8(&mut self, write: *const [u8]) -> Result<(), Error>
|
||||
where
|
||||
Tx: TxDmaChannel<T>,
|
||||
{
|
||||
@ -22,9 +22,10 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
}
|
||||
self.set_word_size(WordSize::EightBit);
|
||||
|
||||
let request = self.txdma.request();
|
||||
let dst = T::regs().tx_ptr();
|
||||
let f = crate::dma::write(&mut self.txdma, request, write, dst);
|
||||
let tx_request = self.txdma.request();
|
||||
let tx_dst = T::regs().tx_ptr();
|
||||
unsafe { self.txdma.start_write(tx_request, write, tx_dst) }
|
||||
let tx_f = Transfer::new(&mut self.txdma);
|
||||
|
||||
unsafe {
|
||||
T::regs().cr2().modify(|reg| {
|
||||
@ -35,14 +36,14 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
});
|
||||
}
|
||||
|
||||
f.await;
|
||||
tx_f.await;
|
||||
|
||||
finish_dma(T::regs());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) async fn read_dma_u8(&mut self, read: &mut [u8]) -> Result<(), Error>
|
||||
pub(super) async fn read_dma_u8(&mut self, read: *mut [u8]) -> Result<(), Error>
|
||||
where
|
||||
Tx: TxDmaChannel<T>,
|
||||
Rx: RxDmaChannel<T>,
|
||||
@ -57,11 +58,12 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
}
|
||||
self.set_word_size(WordSize::EightBit);
|
||||
|
||||
let clock_byte_count = read.len();
|
||||
let (_, clock_byte_count) = slice_ptr_parts_mut(read);
|
||||
|
||||
let rx_request = self.rxdma.request();
|
||||
let rx_src = T::regs().rx_ptr();
|
||||
let rx_f = crate::dma::read(&mut self.rxdma, rx_request, rx_src, read);
|
||||
unsafe { self.rxdma.start_read(rx_request, rx_src, read) };
|
||||
let rx_f = Transfer::new(&mut self.rxdma);
|
||||
|
||||
let tx_request = self.txdma.request();
|
||||
let tx_dst = T::regs().tx_ptr();
|
||||
@ -90,16 +92,18 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) async fn read_write_dma_u8(
|
||||
pub(super) async fn transfer_dma_u8(
|
||||
&mut self,
|
||||
read: &mut [u8],
|
||||
write: &[u8],
|
||||
read: *mut [u8],
|
||||
write: *const [u8],
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
Tx: TxDmaChannel<T>,
|
||||
Rx: RxDmaChannel<T>,
|
||||
{
|
||||
assert!(read.len() >= write.len());
|
||||
let (_, rx_len) = slice_ptr_parts(read);
|
||||
let (_, tx_len) = slice_ptr_parts(write);
|
||||
assert_eq!(rx_len, tx_len);
|
||||
|
||||
unsafe {
|
||||
T::regs().cr1().modify(|w| {
|
||||
@ -118,16 +122,13 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
|
||||
let rx_request = self.rxdma.request();
|
||||
let rx_src = T::regs().rx_ptr();
|
||||
let rx_f = crate::dma::read(
|
||||
&mut self.rxdma,
|
||||
rx_request,
|
||||
rx_src,
|
||||
&mut read[0..write.len()],
|
||||
);
|
||||
unsafe { self.rxdma.start_read(rx_request, rx_src, read) };
|
||||
let rx_f = Transfer::new(&mut self.rxdma);
|
||||
|
||||
let tx_request = self.txdma.request();
|
||||
let tx_dst = T::regs().tx_ptr();
|
||||
let tx_f = crate::dma::write(&mut self.txdma, tx_request, write, tx_dst);
|
||||
unsafe { self.txdma.start_write(tx_request, write, tx_dst) }
|
||||
let tx_f = Transfer::new(&mut self.txdma);
|
||||
|
||||
unsafe {
|
||||
T::regs().cr2().modify(|reg| {
|
||||
|
@ -1,12 +1,12 @@
|
||||
#![macro_use]
|
||||
|
||||
pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3};
|
||||
use futures::future::join;
|
||||
|
||||
use super::*;
|
||||
use crate::dma::{slice_ptr_parts, slice_ptr_parts_mut, Transfer};
|
||||
|
||||
impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
pub(super) async fn write_dma_u8(&mut self, write: &[u8]) -> Result<(), Error>
|
||||
pub(super) async fn write_dma_u8(&mut self, write: *const [u8]) -> Result<(), Error>
|
||||
where
|
||||
Tx: TxDmaChannel<T>,
|
||||
{
|
||||
@ -22,9 +22,10 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
}
|
||||
}
|
||||
|
||||
let request = self.txdma.request();
|
||||
let dst = T::regs().tx_ptr();
|
||||
let f = crate::dma::write(&mut self.txdma, request, write, dst);
|
||||
let tx_request = self.txdma.request();
|
||||
let tx_dst = T::regs().tx_ptr();
|
||||
unsafe { self.txdma.start_write(tx_request, write, tx_dst) }
|
||||
let tx_f = Transfer::new(&mut self.txdma);
|
||||
|
||||
unsafe {
|
||||
T::regs().cfg1().modify(|reg| {
|
||||
@ -38,14 +39,14 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
});
|
||||
}
|
||||
|
||||
f.await;
|
||||
tx_f.await;
|
||||
|
||||
finish_dma(T::regs());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) async fn read_dma_u8(&mut self, read: &mut [u8]) -> Result<(), Error>
|
||||
pub(super) async fn read_dma_u8(&mut self, read: *mut [u8]) -> Result<(), Error>
|
||||
where
|
||||
Tx: TxDmaChannel<T>,
|
||||
Rx: RxDmaChannel<T>,
|
||||
@ -60,11 +61,12 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
});
|
||||
}
|
||||
|
||||
let clock_byte_count = read.len();
|
||||
let (_, clock_byte_count) = slice_ptr_parts_mut(read);
|
||||
|
||||
let rx_request = self.rxdma.request();
|
||||
let rx_src = T::regs().rx_ptr();
|
||||
let rx_f = crate::dma::read(&mut self.rxdma, rx_request, rx_src, read);
|
||||
unsafe { self.rxdma.start_read(rx_request, rx_src, read) };
|
||||
let rx_f = Transfer::new(&mut self.rxdma);
|
||||
|
||||
let tx_request = self.txdma.request();
|
||||
let tx_dst = T::regs().tx_ptr();
|
||||
@ -96,16 +98,18 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(super) async fn read_write_dma_u8(
|
||||
pub(super) async fn transfer_dma_u8(
|
||||
&mut self,
|
||||
read: &mut [u8],
|
||||
write: &[u8],
|
||||
read: *mut [u8],
|
||||
write: *const [u8],
|
||||
) -> Result<(), Error>
|
||||
where
|
||||
Tx: TxDmaChannel<T>,
|
||||
Rx: RxDmaChannel<T>,
|
||||
{
|
||||
assert!(read.len() >= write.len());
|
||||
let (_, rx_len) = slice_ptr_parts(read);
|
||||
let (_, tx_len) = slice_ptr_parts(write);
|
||||
assert_eq!(rx_len, tx_len);
|
||||
|
||||
self.set_word_size(WordSize::EightBit);
|
||||
unsafe {
|
||||
@ -124,16 +128,13 @@ impl<'d, T: Instance, Tx, Rx> Spi<'d, T, Tx, Rx> {
|
||||
|
||||
let rx_request = self.rxdma.request();
|
||||
let rx_src = T::regs().rx_ptr();
|
||||
let rx_f = crate::dma::read(
|
||||
&mut self.rxdma,
|
||||
rx_request,
|
||||
rx_src,
|
||||
&mut read[0..write.len()],
|
||||
);
|
||||
unsafe { self.rxdma.start_read(rx_request, rx_src, read) };
|
||||
let rx_f = Transfer::new(&mut self.rxdma);
|
||||
|
||||
let tx_request = self.txdma.request();
|
||||
let tx_dst = T::regs().tx_ptr();
|
||||
let tx_f = crate::dma::write(&mut self.txdma, tx_request, write, tx_dst);
|
||||
unsafe { self.txdma.start_write(tx_request, write, tx_dst) }
|
||||
let tx_f = Transfer::new(&mut self.txdma);
|
||||
|
||||
unsafe {
|
||||
T::regs().cfg1().modify(|reg| {
|
||||
|
@ -82,14 +82,10 @@ use crate::{
|
||||
pac,
|
||||
peripherals::SUBGHZSPI,
|
||||
rcc::sealed::RccPeripheral,
|
||||
spi::{BitOrder, Config as SpiConfig, MisoPin, MosiPin, SckPin, Spi},
|
||||
spi::{BitOrder, Config as SpiConfig, MisoPin, MosiPin, SckPin, Spi, MODE_0},
|
||||
time::Hertz,
|
||||
};
|
||||
use embassy::util::Unborrow;
|
||||
use embedded_hal::{
|
||||
blocking::spi::{Transfer, Write},
|
||||
spi::MODE_0,
|
||||
};
|
||||
|
||||
/// Passthrough for SPI errors (for now)
|
||||
pub type Error = crate::spi::Error;
|
||||
@ -255,8 +251,8 @@ impl<'d> SubGhz<'d, NoDma, NoDma> {
|
||||
self.poll_not_busy();
|
||||
{
|
||||
let _nss: Nss = Nss::new();
|
||||
self.spi.write(&[opcode as u8])?;
|
||||
self.spi.transfer(data)?;
|
||||
self.spi.blocking_write(&[opcode as u8])?;
|
||||
self.spi.blocking_transfer_in_place(data)?;
|
||||
}
|
||||
self.poll_not_busy();
|
||||
Ok(())
|
||||
@ -280,7 +276,7 @@ impl<'d> SubGhz<'d, NoDma, NoDma> {
|
||||
self.poll_not_busy();
|
||||
{
|
||||
let _nss: Nss = Nss::new();
|
||||
self.spi.write(data)?;
|
||||
self.spi.blocking_write(data)?;
|
||||
}
|
||||
self.poll_not_busy();
|
||||
Ok(())
|
||||
@ -290,8 +286,9 @@ impl<'d> SubGhz<'d, NoDma, NoDma> {
|
||||
self.poll_not_busy();
|
||||
{
|
||||
let _nss: Nss = Nss::new();
|
||||
self.spi.write(&[OpCode::WriteBuffer as u8, offset])?;
|
||||
self.spi.write(data)?;
|
||||
self.spi
|
||||
.blocking_write(&[OpCode::WriteBuffer as u8, offset])?;
|
||||
self.spi.blocking_write(data)?;
|
||||
}
|
||||
self.poll_not_busy();
|
||||
|
||||
@ -308,9 +305,10 @@ impl<'d> SubGhz<'d, NoDma, NoDma> {
|
||||
self.poll_not_busy();
|
||||
{
|
||||
let _nss: Nss = Nss::new();
|
||||
self.spi.write(&[OpCode::ReadBuffer as u8, offset])?;
|
||||
self.spi.transfer(&mut status_buf)?;
|
||||
self.spi.transfer(buf)?;
|
||||
self.spi
|
||||
.blocking_write(&[OpCode::ReadBuffer as u8, offset])?;
|
||||
self.spi.blocking_transfer_in_place(&mut status_buf)?;
|
||||
self.spi.blocking_transfer_in_place(buf)?;
|
||||
}
|
||||
self.poll_not_busy();
|
||||
|
||||
@ -342,8 +340,8 @@ impl<'d> SubGhz<'d, NoDma, NoDma> {
|
||||
{
|
||||
let _nss: Nss = Nss::new();
|
||||
self.spi
|
||||
.write(&[OpCode::WriteRegister as u8, addr[0], addr[1]])?;
|
||||
self.spi.write(data)?;
|
||||
.blocking_write(&[OpCode::WriteRegister as u8, addr[0], addr[1]])?;
|
||||
self.spi.blocking_write(data)?;
|
||||
}
|
||||
self.poll_not_busy();
|
||||
|
||||
|
@ -129,7 +129,7 @@ impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
|
||||
}
|
||||
}
|
||||
|
||||
async fn write_dma(&mut self, buffer: &[u8]) -> Result<(), Error>
|
||||
pub async fn write(&mut self, buffer: &[u8]) -> Result<(), Error>
|
||||
where
|
||||
TxDma: crate::usart::TxDma<T>,
|
||||
{
|
||||
@ -146,7 +146,7 @@ impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
async fn read_dma(&mut self, buffer: &mut [u8]) -> Result<(), Error>
|
||||
pub async fn read(&mut self, buffer: &mut [u8]) -> Result<(), Error>
|
||||
where
|
||||
RxDma: crate::usart::RxDma<T>,
|
||||
{
|
||||
@ -163,7 +163,7 @@ impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn read_blocking(&mut self, buffer: &mut [u8]) -> Result<(), Error> {
|
||||
pub fn blocking_read(&mut self, buffer: &mut [u8]) -> Result<(), Error> {
|
||||
unsafe {
|
||||
let r = self.inner.regs();
|
||||
for b in buffer {
|
||||
@ -190,6 +190,25 @@ impl<'d, T: Instance, TxDma, RxDma> Uart<'d, T, TxDma, RxDma> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn blocking_write(&mut self, buffer: &[u8]) -> Result<(), Error> {
|
||||
unsafe {
|
||||
let r = self.inner.regs();
|
||||
for &b in buffer {
|
||||
while !sr(r).read().txe() {}
|
||||
tdr(r).write_volatile(b);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn blocking_flush(&mut self) -> Result<(), Error> {
|
||||
unsafe {
|
||||
let r = self.inner.regs();
|
||||
while !sr(r).read().tc() {}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'d, T: Instance, TxDma, RxDma> embedded_hal::serial::Read<u8> for Uart<'d, T, TxDma, RxDma> {
|
||||
@ -224,21 +243,10 @@ impl<'d, T: Instance, TxDma, RxDma> embedded_hal::blocking::serial::Write<u8>
|
||||
{
|
||||
type Error = Error;
|
||||
fn bwrite_all(&mut self, buffer: &[u8]) -> Result<(), Self::Error> {
|
||||
unsafe {
|
||||
let r = self.inner.regs();
|
||||
for &b in buffer {
|
||||
while !sr(r).read().txe() {}
|
||||
tdr(r).write_volatile(b);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
self.blocking_write(buffer)
|
||||
}
|
||||
fn bflush(&mut self) -> Result<(), Self::Error> {
|
||||
unsafe {
|
||||
let r = self.inner.regs();
|
||||
while !sr(r).read().tc() {}
|
||||
}
|
||||
Ok(())
|
||||
self.blocking_flush()
|
||||
}
|
||||
}
|
||||
|
||||
@ -252,7 +260,7 @@ where
|
||||
= impl Future<Output = Result<(), embassy_traits::uart::Error>> + 'a;
|
||||
|
||||
fn write<'a>(&'a mut self, buf: &'a [u8]) -> Self::WriteFuture<'a> {
|
||||
self.write_dma(buf)
|
||||
self.write(buf)
|
||||
.map_err(|_| embassy_traits::uart::Error::Other)
|
||||
}
|
||||
}
|
||||
@ -267,7 +275,7 @@ where
|
||||
= impl Future<Output = Result<(), embassy_traits::uart::Error>> + 'a;
|
||||
|
||||
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Self::ReadFuture<'a> {
|
||||
self.read_dma(buf)
|
||||
self.read(buf)
|
||||
.map_err(|_| embassy_traits::uart::Error::Other)
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
|
||||
loop {
|
||||
info!("high");
|
||||
unwrap!(led.set_high());
|
||||
led.set_high();
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
|
||||
info!("low");
|
||||
unwrap!(led.set_low());
|
||||
led.set_low();
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
@ -20,11 +19,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
|
||||
loop {
|
||||
info!("high");
|
||||
unwrap!(led.set_high());
|
||||
led.set_high();
|
||||
Timer::after(Duration::from_millis(1000)).await;
|
||||
|
||||
info!("low");
|
||||
unwrap!(led.set_low());
|
||||
led.set_low();
|
||||
Timer::after(Duration::from_millis(1000)).await;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
mod example_common;
|
||||
use cortex_m_rt::entry;
|
||||
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
|
||||
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
||||
use example_common::*;
|
||||
|
||||
#[entry]
|
||||
@ -20,14 +19,14 @@ fn main() -> ! {
|
||||
let mut led2 = Output::new(p.PE15, Level::High, Speed::Low);
|
||||
|
||||
loop {
|
||||
if unwrap!(button.is_high()) {
|
||||
if button.is_high() {
|
||||
info!("high");
|
||||
unwrap!(led1.set_high());
|
||||
unwrap!(led2.set_low());
|
||||
led1.set_high();
|
||||
led2.set_low();
|
||||
} else {
|
||||
info!("low");
|
||||
unwrap!(led1.set_low());
|
||||
unwrap!(led2.set_high());
|
||||
led1.set_low();
|
||||
led2.set_high();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ use embassy::executor::Spawner;
|
||||
use embassy_stm32::exti::ExtiInput;
|
||||
use embassy_stm32::gpio::{Input, Pull};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
|
@ -9,7 +9,6 @@ use embassy::executor::Spawner;
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::usart::{Config, Uart};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::uart::Write as _;
|
||||
use example_common::*;
|
||||
use heapless::String;
|
||||
|
||||
|
@ -8,7 +8,6 @@ use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
|
||||
loop {
|
||||
info!("high");
|
||||
unwrap!(led.set_high());
|
||||
led.set_high();
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
|
||||
info!("low");
|
||||
unwrap!(led.set_low());
|
||||
led.set_low();
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
mod example_common;
|
||||
use cortex_m_rt::entry;
|
||||
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
|
||||
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
||||
use example_common::*;
|
||||
|
||||
#[entry]
|
||||
@ -21,14 +20,14 @@ fn main() -> ! {
|
||||
let mut led3 = Output::new(p.PB14, Level::High, Speed::Low);
|
||||
|
||||
loop {
|
||||
if unwrap!(button.is_high()) {
|
||||
if button.is_high() {
|
||||
info!("high");
|
||||
unwrap!(led1.set_high());
|
||||
unwrap!(led3.set_low());
|
||||
led1.set_high();
|
||||
led3.set_low();
|
||||
} else {
|
||||
info!("low");
|
||||
unwrap!(led1.set_low());
|
||||
unwrap!(led3.set_high());
|
||||
led1.set_low();
|
||||
led3.set_high();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ use embassy::executor::Spawner;
|
||||
use embassy_stm32::exti::ExtiInput;
|
||||
use embassy_stm32::gpio::{Input, Pull};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
|
@ -10,8 +10,6 @@ use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::spi::{Config, Spi};
|
||||
use embassy_stm32::time::Hertz;
|
||||
use embedded_hal::blocking::spi::Transfer;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::*;
|
||||
|
||||
#[entry]
|
||||
@ -35,9 +33,9 @@ fn main() -> ! {
|
||||
|
||||
loop {
|
||||
let mut buf = [0x0Au8; 4];
|
||||
unwrap!(cs.set_low());
|
||||
unwrap!(spi.transfer(&mut buf));
|
||||
unwrap!(cs.set_high());
|
||||
cs.set_low();
|
||||
unwrap!(spi.blocking_transfer_in_place(&mut buf));
|
||||
cs.set_high();
|
||||
info!("xfer {=[u8]:x}", buf);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ use embassy::executor::Spawner;
|
||||
use embassy_stm32::spi::{Config, Spi};
|
||||
use embassy_stm32::time::Hertz;
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::spi::FullDuplex;
|
||||
use example_common::*;
|
||||
use heapless::String;
|
||||
|
||||
@ -33,7 +32,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
let mut write: String<128> = String::new();
|
||||
let mut read = [0; 128];
|
||||
core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap();
|
||||
spi.read_write(&mut read[0..write.len()], write.as_bytes())
|
||||
spi.transfer(&mut read[0..write.len()], write.as_bytes())
|
||||
.await
|
||||
.ok();
|
||||
info!("read via spi+dma: {}", from_utf8(&read).unwrap());
|
||||
|
@ -7,7 +7,6 @@ mod example_common;
|
||||
use cortex_m_rt::entry;
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::usart::{Config, Uart};
|
||||
use embedded_hal::blocking::serial::Write;
|
||||
use example_common::*;
|
||||
|
||||
#[entry]
|
||||
@ -19,12 +18,12 @@ fn main() -> ! {
|
||||
let config = Config::default();
|
||||
let mut usart = Uart::new(p.USART3, p.PD9, p.PD8, NoDma, NoDma, config);
|
||||
|
||||
unwrap!(usart.bwrite_all(b"Hello Embassy World!\r\n"));
|
||||
unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
|
||||
info!("wrote Hello, starting echo");
|
||||
|
||||
let mut buf = [0u8; 1];
|
||||
loop {
|
||||
unwrap!(usart.read_blocking(&mut buf));
|
||||
unwrap!(usart.bwrite_all(&buf));
|
||||
unwrap!(usart.blocking_read(&mut buf));
|
||||
unwrap!(usart.blocking_write(&buf));
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ use embassy::executor::Spawner;
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::usart::{Config, Uart};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::uart::Write as _;
|
||||
use example_common::*;
|
||||
use heapless::String;
|
||||
|
||||
|
@ -8,7 +8,6 @@ use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
|
||||
loop {
|
||||
info!("high");
|
||||
unwrap!(led.set_high());
|
||||
led.set_high();
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
|
||||
info!("low");
|
||||
unwrap!(led.set_low());
|
||||
led.set_low();
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
mod example_common;
|
||||
use cortex_m_rt::entry;
|
||||
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
|
||||
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
||||
use example_common::*;
|
||||
|
||||
#[entry]
|
||||
@ -21,14 +20,14 @@ fn main() -> ! {
|
||||
let mut led3 = Output::new(p.PB14, Level::High, Speed::Low);
|
||||
|
||||
loop {
|
||||
if unwrap!(button.is_high()) {
|
||||
if button.is_high() {
|
||||
info!("high");
|
||||
unwrap!(led1.set_high());
|
||||
unwrap!(led3.set_low());
|
||||
led1.set_high();
|
||||
led3.set_low();
|
||||
} else {
|
||||
info!("low");
|
||||
unwrap!(led1.set_low());
|
||||
unwrap!(led3.set_high());
|
||||
led1.set_low();
|
||||
led3.set_high();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ use embassy::executor::Spawner;
|
||||
use embassy_stm32::exti::ExtiInput;
|
||||
use embassy_stm32::gpio::{Input, Pull};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
|
@ -9,7 +9,6 @@ use embassy::executor::Spawner;
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::usart::{Config, Uart};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::uart::Write as _Write;
|
||||
use example_common::*;
|
||||
|
||||
use heapless::String;
|
||||
|
@ -8,7 +8,6 @@ use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
|
||||
loop {
|
||||
info!("high");
|
||||
unwrap!(led.set_high());
|
||||
led.set_high();
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
|
||||
info!("low");
|
||||
unwrap!(led.set_low());
|
||||
led.set_low();
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
mod example_common;
|
||||
use cortex_m_rt::entry;
|
||||
use embassy_stm32::gpio::{Input, Pull};
|
||||
use embedded_hal::digital::v2::InputPin;
|
||||
use example_common::*;
|
||||
|
||||
#[entry]
|
||||
@ -18,7 +17,7 @@ fn main() -> ! {
|
||||
let button = Input::new(p.PC13, Pull::Up);
|
||||
|
||||
loop {
|
||||
if unwrap!(button.is_high()) {
|
||||
if button.is_high() {
|
||||
info!("high");
|
||||
} else {
|
||||
info!("low");
|
||||
|
@ -8,7 +8,6 @@ use embassy::executor::Spawner;
|
||||
use embassy_stm32::exti::ExtiInput;
|
||||
use embassy_stm32::gpio::{Input, Pull};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
|
@ -8,7 +8,6 @@ use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
|
||||
loop {
|
||||
info!("high");
|
||||
unwrap!(led.set_high());
|
||||
led.set_high();
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
|
||||
info!("low");
|
||||
unwrap!(led.set_low());
|
||||
led.set_low();
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
mod example_common;
|
||||
use cortex_m_rt::entry;
|
||||
use embassy_stm32::gpio::{Input, Pull};
|
||||
use embedded_hal::digital::v2::InputPin;
|
||||
use example_common::*;
|
||||
|
||||
#[entry]
|
||||
@ -18,7 +17,7 @@ fn main() -> ! {
|
||||
let button = Input::new(p.PC13, Pull::Down);
|
||||
|
||||
loop {
|
||||
if unwrap!(button.is_high()) {
|
||||
if button.is_high() {
|
||||
info!("high");
|
||||
} else {
|
||||
info!("low");
|
||||
|
@ -8,7 +8,6 @@ use embassy::executor::Spawner;
|
||||
use embassy_stm32::exti::ExtiInput;
|
||||
use embassy_stm32::gpio::{Input, Pull};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
|
@ -8,7 +8,6 @@ use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
|
||||
loop {
|
||||
info!("high");
|
||||
unwrap!(led.set_high());
|
||||
led.set_high();
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
|
||||
info!("low");
|
||||
unwrap!(led.set_low());
|
||||
led.set_low();
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ use embassy::executor::Spawner;
|
||||
use embassy_stm32::exti::ExtiInput;
|
||||
use embassy_stm32::gpio::{Input, Pull};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
|
@ -11,7 +11,6 @@ use embassy_stm32::interrupt;
|
||||
use embassy_stm32::rcc::{Mco, Mco1Source, McoClock};
|
||||
use embassy_stm32::time::U32Ext;
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
|
||||
use defmt_rtt as _; // global logger
|
||||
use panic_probe as _;
|
||||
@ -114,11 +113,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
defmt::info!("main loop running");
|
||||
loop {
|
||||
defmt::info!("high");
|
||||
defmt::unwrap!(led.set_high());
|
||||
led.set_high();
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
|
||||
defmt::info!("low");
|
||||
defmt::unwrap!(led.set_low());
|
||||
led.set_low();
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::rcc::{Mco, Mco1Source, McoClock};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
@ -22,11 +21,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
|
||||
loop {
|
||||
info!("high");
|
||||
unwrap!(led.set_high());
|
||||
led.set_high();
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
|
||||
info!("low");
|
||||
unwrap!(led.set_low());
|
||||
led.set_low();
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ use embassy::traits::rng::Random;
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::rng::Rng;
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
@ -23,11 +22,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
|
||||
loop {
|
||||
info!("high {}", unwrap!(rng.next_u8(16).await));
|
||||
unwrap!(led.set_high());
|
||||
led.set_high();
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
|
||||
info!("low {}", unwrap!(rng.next_u8(16).await));
|
||||
unwrap!(led.set_low());
|
||||
led.set_low();
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ use embassy::executor::Executor;
|
||||
use embassy::util::Forever;
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::spi;
|
||||
use embedded_hal::blocking::spi::Transfer;
|
||||
use example_common::*;
|
||||
|
||||
use core::str::from_utf8;
|
||||
@ -25,7 +24,7 @@ async fn main_task(mut spi: spi::Spi<'static, SPI3, NoDma, NoDma>) {
|
||||
let mut write: String<128> = String::new();
|
||||
core::write!(&mut write, "Hello DMA World {}!\r\n", n).unwrap();
|
||||
unsafe {
|
||||
let result = spi.transfer(write.as_bytes_mut());
|
||||
let result = spi.blocking_transfer_in_place(write.as_bytes_mut());
|
||||
if let Err(_) = result {
|
||||
defmt::panic!("crap");
|
||||
}
|
||||
|
@ -4,7 +4,6 @@
|
||||
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
use cortex_m::prelude::_embedded_hal_blocking_serial_Write;
|
||||
use embassy::executor::Executor;
|
||||
use embassy::util::Forever;
|
||||
use embassy_stm32::dma::NoDma;
|
||||
@ -20,13 +19,13 @@ async fn main_task() {
|
||||
let config = Config::default();
|
||||
let mut usart = Uart::new(p.UART7, p.PF6, p.PF7, NoDma, NoDma, config);
|
||||
|
||||
unwrap!(usart.bwrite_all(b"Hello Embassy World!\r\n"));
|
||||
unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
|
||||
info!("wrote Hello, starting echo");
|
||||
|
||||
let mut buf = [0u8; 1];
|
||||
loop {
|
||||
unwrap!(usart.read_blocking(&mut buf));
|
||||
unwrap!(usart.bwrite_all(&buf));
|
||||
unwrap!(usart.blocking_read(&mut buf));
|
||||
unwrap!(usart.blocking_write(&buf));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,7 +9,6 @@ use embassy::executor::Executor;
|
||||
use embassy::util::Forever;
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::usart::{Config, Uart};
|
||||
use embassy_traits::uart::Write as _Write;
|
||||
use example_common::*;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
|
@ -1,6 +1,6 @@
|
||||
[target.'cfg(all(target_arch = "arm", target_os = "none"))']
|
||||
# replace your chip as listed in `probe-run --list-chips`
|
||||
runner = "probe-run --chip STM32L072CZ"
|
||||
runner = "probe-run --chip STM32L072CZTx"
|
||||
|
||||
[build]
|
||||
target = "thumbv6m-none-eabi"
|
||||
|
@ -8,7 +8,7 @@ resolver = "2"
|
||||
[dependencies]
|
||||
embassy = { version = "0.1.0", path = "../../embassy", features = ["defmt"] }
|
||||
embassy-traits = { version = "0.1.0", path = "../../embassy-traits", features = ["defmt"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-tim3", "exti"] }
|
||||
embassy-stm32 = { version = "0.1.0", path = "../../embassy-stm32", features = ["defmt", "stm32l072cz", "time-driver-tim3", "exti", "memory-x"] }
|
||||
|
||||
embassy-lora = { version = "0.1.0", path = "../../embassy-lora", features = ["sx127x", "time", "defmt"] }
|
||||
|
||||
|
@ -1,34 +1,4 @@
|
||||
//! This build script copies the `memory.x` file from the crate root into
|
||||
//! a directory where the linker can always find it at build time.
|
||||
//! For many projects this is optional, as the linker always searches the
|
||||
//! project root directory -- wherever `Cargo.toml` is. However, if you
|
||||
//! are using a workspace or have a more complicated build setup, this
|
||||
//! build script becomes required. Additionally, by requesting that
|
||||
//! Cargo re-run the build script whenever `memory.x` is changed,
|
||||
//! updating `memory.x` ensures a rebuild of the application with the
|
||||
//! new memory settings.
|
||||
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn main() {
|
||||
// Put `memory.x` in our output directory and ensure it's
|
||||
// on the linker search path.
|
||||
let out = &PathBuf::from(env::var_os("OUT_DIR").unwrap());
|
||||
File::create(out.join("memory.x"))
|
||||
.unwrap()
|
||||
.write_all(include_bytes!("memory.x"))
|
||||
.unwrap();
|
||||
println!("cargo:rustc-link-search={}", out.display());
|
||||
|
||||
// By default, Cargo will re-run a build script whenever
|
||||
// any file in the project changes. By specifying `memory.x`
|
||||
// here, we ensure the build script is only re-run when
|
||||
// `memory.x` is changed.
|
||||
println!("cargo:rerun-if-changed=memory.x");
|
||||
|
||||
println!("cargo:rustc-link-arg-bins=--nmagic");
|
||||
println!("cargo:rustc-link-arg-bins=-Tlink.x");
|
||||
println!("cargo:rustc-link-arg-bins=-Tdefmt.x");
|
||||
|
@ -1,5 +0,0 @@
|
||||
MEMORY
|
||||
{
|
||||
FLASH : ORIGIN = 0x08000000, LENGTH = 192K
|
||||
RAM : ORIGIN = 0x20000000, LENGTH = 20K
|
||||
}
|
@ -9,7 +9,6 @@ use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
@ -20,11 +19,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
|
||||
loop {
|
||||
info!("high");
|
||||
unwrap!(led.set_high());
|
||||
led.set_high();
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
|
||||
info!("low");
|
||||
unwrap!(led.set_low());
|
||||
led.set_low();
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
}
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ mod example_common;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
@ -19,14 +18,14 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
let mut led2 = Output::new(p.PB5, Level::High, Speed::Low);
|
||||
|
||||
loop {
|
||||
if unwrap!(button.is_high()) {
|
||||
if button.is_high() {
|
||||
info!("high");
|
||||
unwrap!(led1.set_high());
|
||||
unwrap!(led2.set_low());
|
||||
led1.set_high();
|
||||
led2.set_low();
|
||||
} else {
|
||||
info!("low");
|
||||
unwrap!(led1.set_low());
|
||||
unwrap!(led2.set_high());
|
||||
led1.set_low();
|
||||
led2.set_high();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ use embassy::executor::Spawner;
|
||||
use embassy_stm32::exti::ExtiInput;
|
||||
use embassy_stm32::gpio::{Input, Pull};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
|
||||
use example_common::*;
|
||||
|
||||
fn config() -> embassy_stm32::Config {
|
||||
|
@ -7,14 +7,12 @@ mod example_common;
|
||||
|
||||
use embassy::executor::Spawner;
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::*;
|
||||
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::spi::{Config, Spi};
|
||||
use embassy_stm32::time::Hertz;
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::blocking::spi::Transfer;
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
@ -35,9 +33,9 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
|
||||
loop {
|
||||
let mut buf = [0x0Au8; 4];
|
||||
unwrap!(cs.set_low());
|
||||
unwrap!(spi.transfer(&mut buf));
|
||||
unwrap!(cs.set_high());
|
||||
cs.set_low();
|
||||
unwrap!(spi.blocking_transfer_in_place(&mut buf));
|
||||
cs.set_high();
|
||||
info!("xfer {=[u8]:x}", buf);
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ use example_common::*;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy_stm32::usart::{Config, Uart};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::uart::{Read, Write};
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
|
@ -9,7 +9,6 @@ use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
@ -20,11 +19,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
|
||||
loop {
|
||||
info!("high");
|
||||
unwrap!(led.set_high());
|
||||
led.set_high();
|
||||
Timer::after(Duration::from_millis(1000)).await;
|
||||
|
||||
info!("low");
|
||||
unwrap!(led.set_low());
|
||||
led.set_low();
|
||||
Timer::after(Duration::from_millis(1000)).await;
|
||||
}
|
||||
}
|
||||
|
@ -7,14 +7,12 @@ mod example_common;
|
||||
|
||||
use embassy::executor::Spawner;
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::*;
|
||||
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::spi::{Config, Spi};
|
||||
use embassy_stm32::time::Hertz;
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::blocking::spi::Transfer;
|
||||
|
||||
#[embassy::main]
|
||||
async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
@ -35,9 +33,9 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
|
||||
loop {
|
||||
let mut buf = [0x0Au8; 4];
|
||||
unwrap!(cs.set_low());
|
||||
unwrap!(spi.transfer(&mut buf));
|
||||
unwrap!(cs.set_high());
|
||||
cs.set_low();
|
||||
unwrap!(spi.blocking_transfer_in_place(&mut buf));
|
||||
cs.set_high();
|
||||
info!("xfer {=[u8]:x}", buf);
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
@ -18,9 +17,9 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
let mut led = Output::new(p.PB14, Level::High, Speed::Low);
|
||||
|
||||
loop {
|
||||
unwrap!(led.set_high());
|
||||
led.set_high();
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
unwrap!(led.set_low());
|
||||
led.set_low();
|
||||
Timer::after(Duration::from_millis(300)).await;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
use embassy_stm32::gpio::{Input, Pull};
|
||||
use embedded_hal::digital::v2::InputPin;
|
||||
use example_common::*;
|
||||
|
||||
#[cortex_m_rt::entry]
|
||||
@ -17,7 +16,7 @@ fn main() -> ! {
|
||||
let button = Input::new(p.PC13, Pull::Up);
|
||||
|
||||
loop {
|
||||
if unwrap!(button.is_high()) {
|
||||
if button.is_high() {
|
||||
info!("high");
|
||||
} else {
|
||||
info!("low");
|
||||
|
@ -8,7 +8,6 @@ use embassy::executor::Spawner;
|
||||
use embassy_stm32::exti::ExtiInput;
|
||||
use embassy_stm32::gpio::{Input, Pull};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
|
@ -11,7 +11,6 @@ use embassy_stm32::i2c::I2c;
|
||||
use embassy_stm32::interrupt;
|
||||
use embassy_stm32::time::Hertz;
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::blocking::i2c::WriteRead;
|
||||
use example_common::{info, unwrap};
|
||||
|
||||
const ADDRESS: u8 = 0x5F;
|
||||
@ -23,6 +22,6 @@ async fn main(_spawner: Spawner, p: Peripherals) -> ! {
|
||||
let mut i2c = I2c::new(p.I2C2, p.PB10, p.PB11, irq, NoDma, NoDma, Hertz(100_000));
|
||||
|
||||
let mut data = [0u8; 1];
|
||||
unwrap!(i2c.write_read(ADDRESS, &[WHOAMI], &mut data));
|
||||
unwrap!(i2c.blocking_write_read(ADDRESS, &[WHOAMI], &mut data));
|
||||
info!("Whoami: {}", data[0]);
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
mod example_common;
|
||||
|
||||
use embassy::executor::Spawner;
|
||||
use embassy::traits::i2c::I2c as I2cTrait;
|
||||
use embassy_stm32::i2c::I2c;
|
||||
use embassy_stm32::interrupt;
|
||||
use embassy_stm32::time::Hertz;
|
||||
|
@ -9,8 +9,6 @@ use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::spi::{Config, Spi};
|
||||
use embassy_stm32::time::Hertz;
|
||||
use embedded_hal::blocking::spi::Transfer;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::*;
|
||||
|
||||
#[cortex_m_rt::entry]
|
||||
@ -34,9 +32,9 @@ fn main() -> ! {
|
||||
|
||||
loop {
|
||||
let mut buf = [0x0Au8; 4];
|
||||
unwrap!(cs.set_low());
|
||||
unwrap!(spi.transfer(&mut buf));
|
||||
unwrap!(cs.set_high());
|
||||
cs.set_low();
|
||||
unwrap!(spi.blocking_transfer_in_place(&mut buf));
|
||||
cs.set_high();
|
||||
info!("xfer {=[u8]:x}", buf);
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ use embassy_stm32::spi::{Config, Spi};
|
||||
use embassy_stm32::time::Hertz;
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::{adapter::BlockingAsync, spi::FullDuplex};
|
||||
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
@ -41,17 +40,17 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
let ready = Input::new(p.PE1, Pull::Up);
|
||||
|
||||
cortex_m::asm::delay(100_000);
|
||||
unwrap!(reset.set_high());
|
||||
reset.set_high();
|
||||
cortex_m::asm::delay(100_000);
|
||||
|
||||
while unwrap!(ready.is_low()) {
|
||||
while ready.is_low() {
|
||||
info!("waiting for ready");
|
||||
}
|
||||
|
||||
let write = [0x0A; 10];
|
||||
let mut read = [0; 10];
|
||||
unwrap!(cs.set_low());
|
||||
cs.set_low();
|
||||
spi.read_write(&mut read, &write).await.ok();
|
||||
unwrap!(cs.set_high());
|
||||
cs.set_high();
|
||||
info!("xfer {=[u8]:x}", read);
|
||||
}
|
||||
|
@ -11,7 +11,6 @@ use embassy_stm32::spi::{Config, Spi};
|
||||
use embassy_stm32::time::Hertz;
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::spi::FullDuplex;
|
||||
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
@ -38,17 +37,17 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
let ready = Input::new(p.PE1, Pull::Up);
|
||||
|
||||
cortex_m::asm::delay(100_000);
|
||||
unwrap!(reset.set_high());
|
||||
reset.set_high();
|
||||
cortex_m::asm::delay(100_000);
|
||||
|
||||
while unwrap!(ready.is_low()) {
|
||||
while ready.is_low() {
|
||||
info!("waiting for ready");
|
||||
}
|
||||
|
||||
let write = [0x0A; 10];
|
||||
let mut read = [0; 10];
|
||||
unwrap!(cs.set_low());
|
||||
cs.set_low();
|
||||
spi.read_write(&mut read, &write).await.ok();
|
||||
unwrap!(cs.set_high());
|
||||
cs.set_high();
|
||||
info!("xfer {=[u8]:x}", read);
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ mod example_common;
|
||||
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::usart::{Config, Uart};
|
||||
use embedded_hal::blocking::serial::Write;
|
||||
use example_common::*;
|
||||
|
||||
#[cortex_m_rt::entry]
|
||||
@ -19,12 +18,12 @@ fn main() -> ! {
|
||||
let config = Config::default();
|
||||
let mut usart = Uart::new(p.UART4, p.PA1, p.PA0, NoDma, NoDma, config);
|
||||
|
||||
unwrap!(usart.bwrite_all(b"Hello Embassy World!\r\n"));
|
||||
unwrap!(usart.blocking_write(b"Hello Embassy World!\r\n"));
|
||||
info!("wrote Hello, starting echo");
|
||||
|
||||
let mut buf = [0u8; 1];
|
||||
loop {
|
||||
unwrap!(usart.read_blocking(&mut buf));
|
||||
unwrap!(usart.bwrite_all(&buf));
|
||||
unwrap!(usart.blocking_read(&mut buf));
|
||||
unwrap!(usart.blocking_write(&buf));
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ use embassy::executor::Spawner;
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::usart::{Config, Uart};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::uart::Write as _;
|
||||
use example_common::*;
|
||||
use heapless::String;
|
||||
|
||||
|
@ -8,7 +8,6 @@ use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
|
||||
loop {
|
||||
info!("high");
|
||||
unwrap!(led.set_high());
|
||||
led.set_high();
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
|
||||
info!("low");
|
||||
unwrap!(led.set_low());
|
||||
led.set_low();
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ use embassy::executor::Spawner;
|
||||
use embassy_stm32::exti::ExtiInput;
|
||||
use embassy_stm32::gpio::{Input, Pull};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
|
@ -8,7 +8,6 @@ use embassy::executor::Spawner;
|
||||
use embassy::time::{Duration, Timer};
|
||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
@ -19,11 +18,11 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
|
||||
loop {
|
||||
info!("high");
|
||||
unwrap!(led.set_high());
|
||||
led.set_high();
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
|
||||
info!("low");
|
||||
unwrap!(led.set_low());
|
||||
led.set_low();
|
||||
Timer::after(Duration::from_millis(500)).await;
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@
|
||||
#[path = "../example_common.rs"]
|
||||
mod example_common;
|
||||
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
|
||||
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
||||
use example_common::*;
|
||||
|
||||
use cortex_m_rt::entry;
|
||||
@ -21,12 +20,12 @@ fn main() -> ! {
|
||||
let mut led2 = Output::new(p.PB9, Level::High, Speed::Low);
|
||||
|
||||
loop {
|
||||
if button.is_high().unwrap() {
|
||||
led1.set_high().unwrap();
|
||||
led2.set_low().unwrap();
|
||||
if button.is_high() {
|
||||
led1.set_high();
|
||||
led2.set_low();
|
||||
} else {
|
||||
led1.set_low().unwrap();
|
||||
led2.set_high().unwrap();
|
||||
led1.set_low();
|
||||
led2.set_high();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ use embassy::executor::Spawner;
|
||||
use embassy_stm32::exti::ExtiInput;
|
||||
use embassy_stm32::gpio::{Input, Pull};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::gpio::{WaitForFallingEdge, WaitForRisingEdge};
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main]
|
||||
|
@ -10,14 +10,12 @@ mod example_common;
|
||||
|
||||
use embassy::channel::signal::Signal;
|
||||
use embassy::interrupt::{Interrupt, InterruptExt};
|
||||
use embassy::traits::gpio::WaitForRisingEdge;
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::exti::ExtiInput;
|
||||
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
|
||||
use embassy_stm32::interrupt;
|
||||
use embassy_stm32::subghz::*;
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::digital::v2::OutputPin;
|
||||
use example_common::unwrap;
|
||||
|
||||
const PING_DATA: &str = "PING";
|
||||
@ -89,9 +87,9 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) {
|
||||
|
||||
defmt::info!("Radio ready for use");
|
||||
|
||||
unwrap!(led1.set_low());
|
||||
led1.set_low();
|
||||
|
||||
unwrap!(led2.set_high());
|
||||
led2.set_high();
|
||||
|
||||
unwrap!(radio.set_standby(StandbyClk::Rc));
|
||||
unwrap!(radio.set_tcxo_mode(&TCXO_MODE));
|
||||
@ -110,11 +108,11 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) {
|
||||
|
||||
defmt::info!("Status: {:?}", unwrap!(radio.status()));
|
||||
|
||||
unwrap!(led2.set_low());
|
||||
led2.set_low();
|
||||
|
||||
loop {
|
||||
pin.wait_for_rising_edge().await;
|
||||
unwrap!(led3.set_high());
|
||||
led3.set_high();
|
||||
unwrap!(radio.set_irq_cfg(&CfgIrq::new().irq_enable_all(Irq::TxDone)));
|
||||
unwrap!(radio.write_buffer(TX_BUF_OFFSET, PING_DATA_BYTES));
|
||||
unwrap!(radio.set_tx(Timeout::DISABLED));
|
||||
@ -127,6 +125,6 @@ async fn main(_spawner: embassy::executor::Spawner, p: Peripherals) {
|
||||
defmt::info!("TX done");
|
||||
}
|
||||
unwrap!(radio.clear_irq_status(irq_status));
|
||||
unwrap!(led3.set_low());
|
||||
led3.set_low();
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ use defmt::assert;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy_stm32::gpio::{Input, Level, Output, Pull, Speed};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::digital::v2::{InputPin, OutputPin};
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main(config = "config()")]
|
||||
@ -35,12 +34,12 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
{
|
||||
let _a = Output::new(&mut a, Level::Low, Speed::Low);
|
||||
delay();
|
||||
assert!(b.is_low().unwrap());
|
||||
assert!(b.is_low());
|
||||
}
|
||||
{
|
||||
let _a = Output::new(&mut a, Level::High, Speed::Low);
|
||||
delay();
|
||||
assert!(b.is_high().unwrap());
|
||||
assert!(b.is_high());
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,38 +50,38 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
|
||||
let mut a = Output::new(&mut a, Level::Low, Speed::Low);
|
||||
delay();
|
||||
assert!(b.is_low().unwrap());
|
||||
a.set_high().unwrap();
|
||||
assert!(b.is_low());
|
||||
a.set_high();
|
||||
delay();
|
||||
assert!(b.is_high().unwrap());
|
||||
assert!(b.is_high());
|
||||
}
|
||||
|
||||
// Test input pulldown
|
||||
{
|
||||
let b = Input::new(&mut b, Pull::Down);
|
||||
delay();
|
||||
assert!(b.is_low().unwrap());
|
||||
assert!(b.is_low());
|
||||
|
||||
let mut a = Output::new(&mut a, Level::Low, Speed::Low);
|
||||
delay();
|
||||
assert!(b.is_low().unwrap());
|
||||
a.set_high().unwrap();
|
||||
assert!(b.is_low());
|
||||
a.set_high();
|
||||
delay();
|
||||
assert!(b.is_high().unwrap());
|
||||
assert!(b.is_high());
|
||||
}
|
||||
|
||||
// Test input pullup
|
||||
{
|
||||
let b = Input::new(&mut b, Pull::Up);
|
||||
delay();
|
||||
assert!(b.is_high().unwrap());
|
||||
assert!(b.is_high());
|
||||
|
||||
let mut a = Output::new(&mut a, Level::Low, Speed::Low);
|
||||
delay();
|
||||
assert!(b.is_low().unwrap());
|
||||
a.set_high().unwrap();
|
||||
assert!(b.is_low());
|
||||
a.set_high();
|
||||
delay();
|
||||
assert!(b.is_high().unwrap());
|
||||
assert!(b.is_high());
|
||||
}
|
||||
|
||||
info!("Test OK");
|
||||
|
@ -10,7 +10,6 @@ use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::spi::{self, Spi};
|
||||
use embassy_stm32::time::Hertz;
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::blocking::spi::Transfer;
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main(config = "config()")]
|
||||
@ -38,7 +37,7 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
// Arduino pins D11 and D12 (MOSI-MISO) are connected together with a 1K resistor.
|
||||
// so we should get the data we sent back.
|
||||
let mut buf = data;
|
||||
spi.transfer(&mut buf).unwrap();
|
||||
spi.blocking_transfer_in_place(&mut buf).unwrap();
|
||||
assert_eq!(buf, data);
|
||||
|
||||
info!("Test OK");
|
||||
|
@ -9,7 +9,6 @@ use embassy::executor::Spawner;
|
||||
use embassy_stm32::dma::NoDma;
|
||||
use embassy_stm32::usart::{Config, Uart};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embedded_hal::blocking::serial::Write;
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main(config = "config()")]
|
||||
@ -42,10 +41,10 @@ async fn main(_spawner: Spawner, p: Peripherals) {
|
||||
// This is because we aren't sending+receiving at the same time.
|
||||
|
||||
let data = [0xC0, 0xDE];
|
||||
usart.bwrite_all(&data).unwrap();
|
||||
usart.blocking_write(&data).unwrap();
|
||||
|
||||
let mut buf = [0; 2];
|
||||
usart.read_blocking(&mut buf).unwrap();
|
||||
usart.blocking_read(&mut buf).unwrap();
|
||||
assert_eq!(buf, data);
|
||||
|
||||
info!("Test OK");
|
||||
|
@ -8,7 +8,6 @@ use defmt::assert_eq;
|
||||
use embassy::executor::Spawner;
|
||||
use embassy_stm32::usart::{Config, Uart};
|
||||
use embassy_stm32::Peripherals;
|
||||
use embassy_traits::uart::{Read, Write};
|
||||
use example_common::*;
|
||||
|
||||
#[embassy::main(config = "config()")]
|
||||
|
12
tests/stm32/teleprobe.sh
Executable file
12
tests/stm32/teleprobe.sh
Executable file
@ -0,0 +1,12 @@
|
||||
echo Running target=$1 elf=$2
|
||||
STATUSCODE=$(
|
||||
curl \
|
||||
-sS \
|
||||
--output /dev/stderr \
|
||||
--write-out "%{http_code}" \
|
||||
-H "Authorization: Bearer $TELEPROBE_TOKEN" \
|
||||
https://teleprobe.embassy.dev/targets/$1/run --data-binary @$2
|
||||
)
|
||||
echo
|
||||
echo HTTP Status code: $STATUSCODE
|
||||
test "$STATUSCODE" -eq 200
|
Loading…
Reference in New Issue
Block a user