mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-25 08:12:30 +00:00
Fixed suggestions, added nRF51 to BLE
This commit is contained in:
parent
5b5d54c0c7
commit
bb73d6b3fe
@ -11,8 +11,8 @@ pub use pac::radio::mode::MODE_A as Mode;
|
||||
use pac::radio::pcnf0::PLEN_A as PreambleLength;
|
||||
|
||||
use crate::interrupt::typelevel::Interrupt;
|
||||
pub use crate::radio::Error;
|
||||
use crate::radio::*;
|
||||
pub use crate::radio::{Error, TxPower};
|
||||
use crate::util::slice_in_ram_or;
|
||||
|
||||
/// Radio driver.
|
||||
@ -103,15 +103,7 @@ impl<'d, T: Instance> Radio<'d, T> {
|
||||
}
|
||||
|
||||
fn state(&self) -> RadioState {
|
||||
match T::regs().state.read().state().variant() {
|
||||
Some(s) => s,
|
||||
None => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
fn trace_state(&self) {
|
||||
super::trace_state(T::regs())
|
||||
super::state(T::regs())
|
||||
}
|
||||
|
||||
/// Set the radio mode
|
||||
@ -318,9 +310,6 @@ impl<'d, T: Instance> Radio<'d, T> {
|
||||
// Initialize the transmission
|
||||
// trace!("txen");
|
||||
|
||||
#[cfg(not(any(feature = "nrf51", feature = "nrf52832")))]
|
||||
r.tasks_txen.write(|w| w.tasks_txen().set_bit());
|
||||
#[cfg(any(feature = "nrf51", feature = "nrf52832"))]
|
||||
r.tasks_txen.write(|w| unsafe { w.bits(1) });
|
||||
})
|
||||
.await;
|
||||
@ -338,9 +327,6 @@ impl<'d, T: Instance> Radio<'d, T> {
|
||||
self.trigger_and_wait_end(move || {
|
||||
// Initialize the transmission
|
||||
// trace!("rxen");
|
||||
#[cfg(not(any(feature = "nrf51", feature = "nrf52832")))]
|
||||
r.tasks_rxen.write(|w| w.tasks_rxen().set_bit());
|
||||
#[cfg(any(feature = "nrf51", feature = "nrf52832"))]
|
||||
r.tasks_rxen.write(|w| unsafe { w.bits(1) });
|
||||
})
|
||||
.await;
|
||||
@ -363,15 +349,9 @@ impl<'d, T: Instance> Radio<'d, T> {
|
||||
r.intenclr.write(|w| w.end().clear());
|
||||
r.events_end.reset();
|
||||
|
||||
#[cfg(not(any(feature = "nrf51", feature = "nrf52832")))]
|
||||
r.tasks_stop.write(|w| w.tasks_stop().set_bit());
|
||||
#[cfg(any(feature = "nrf51", feature = "nrf52832"))]
|
||||
r.tasks_stop.write(|w| unsafe { w.bits(1) });
|
||||
|
||||
// The docs don't explicitly mention any event to acknowledge the stop task
|
||||
#[cfg(not(any(feature = "nrf51", feature = "nrf52832")))]
|
||||
while r.events_end.read().events_end().bit_is_clear() {}
|
||||
#[cfg(any(feature = "nrf51", feature = "nrf52832"))]
|
||||
while r.events_end.read().bits() == 0 {}
|
||||
|
||||
trace!("radio drop: stopped");
|
||||
@ -393,11 +373,7 @@ impl<'d, T: Instance> Radio<'d, T> {
|
||||
// On poll check if interrupt happen
|
||||
poll_fn(|cx| {
|
||||
s.event_waker.register(cx.waker());
|
||||
#[cfg(not(any(feature = "nrf51", feature = "nrf52832")))]
|
||||
let end_event = r.events_end.read().events_end().bit_is_set();
|
||||
#[cfg(any(feature = "nrf51", feature = "nrf52832"))]
|
||||
let end_event = r.events_end.read().bits() == 1;
|
||||
if end_event {
|
||||
if r.events_end.read().bits() == 1 {
|
||||
// trace!("radio:end");
|
||||
return core::task::Poll::Ready(());
|
||||
}
|
||||
@ -421,15 +397,9 @@ impl<'d, T: Instance> Radio<'d, T> {
|
||||
if self.state() != RadioState::DISABLED {
|
||||
trace!("radio:disable");
|
||||
// Trigger the disable task
|
||||
#[cfg(not(any(feature = "nrf51", feature = "nrf52832")))]
|
||||
r.tasks_disable.write(|w| w.tasks_disable().set_bit());
|
||||
#[cfg(any(feature = "nrf51", feature = "nrf52832"))]
|
||||
r.tasks_disable.write(|w| unsafe { w.bits(1) });
|
||||
|
||||
// Wait until the radio is disabled
|
||||
#[cfg(not(any(feature = "nrf51", feature = "nrf52832")))]
|
||||
while r.events_disabled.read().events_disabled().bit_is_clear() {}
|
||||
#[cfg(any(feature = "nrf51", feature = "nrf52832"))]
|
||||
while r.events_disabled.read().bits() == 0 {}
|
||||
|
||||
compiler_fence(Ordering::SeqCst);
|
||||
|
@ -162,19 +162,19 @@ impl<'d, T: Instance> Radio<'d, T> {
|
||||
self.needs_enable = true;
|
||||
|
||||
let tx_power: TxPower = match power {
|
||||
#[cfg(not(feature = "_nrf5340-net"))]
|
||||
#[cfg(not(any(feature = "nrf52811", feature = "_nrf5340-net")))]
|
||||
8 => TxPower::POS8D_BM,
|
||||
#[cfg(not(feature = "_nrf5340-net"))]
|
||||
#[cfg(not(any(feature = "nrf52811", feature = "_nrf5340-net")))]
|
||||
7 => TxPower::POS7D_BM,
|
||||
#[cfg(not(feature = "_nrf5340-net"))]
|
||||
#[cfg(not(any(feature = "nrf52811", feature = "_nrf5340-net")))]
|
||||
6 => TxPower::POS6D_BM,
|
||||
#[cfg(not(feature = "_nrf5340-net"))]
|
||||
#[cfg(not(any(feature = "nrf52811", feature = "_nrf5340-net")))]
|
||||
5 => TxPower::POS5D_BM,
|
||||
#[cfg(not(feature = "_nrf5340-net"))]
|
||||
4 => TxPower::POS4D_BM,
|
||||
#[cfg(not(feature = "_nrf5340-net"))]
|
||||
3 => TxPower::POS3D_BM,
|
||||
#[cfg(not(feature = "_nrf5340-net"))]
|
||||
#[cfg(not(any(feature = "nrf52811", feature = "_nrf5340-net")))]
|
||||
2 => TxPower::POS2D_BM,
|
||||
0 => TxPower::_0D_BM,
|
||||
#[cfg(feature = "_nrf5340-net")]
|
||||
|
@ -6,9 +6,9 @@
|
||||
#![macro_use]
|
||||
|
||||
/// Bluetooth Low Energy Radio driver.
|
||||
#[cfg(not(feature = "nrf51"))]
|
||||
pub mod ble;
|
||||
#[cfg(any(
|
||||
feature = "nrf52811",
|
||||
feature = "nrf52820",
|
||||
feature = "nrf52833",
|
||||
feature = "nrf52840",
|
||||
@ -20,8 +20,7 @@ pub mod ieee802154;
|
||||
use core::marker::PhantomData;
|
||||
|
||||
use pac::radio::state::STATE_A as RadioState;
|
||||
#[cfg(not(feature = "nrf51"))]
|
||||
use pac::radio::txpower::TXPOWER_A as TxPower;
|
||||
pub use pac::radio::txpower::TXPOWER_A as TxPower;
|
||||
|
||||
use crate::{interrupt, pac, Peripheral};
|
||||
|
||||
@ -109,18 +108,3 @@ pub(crate) fn state(radio: &pac::radio::RegisterBlock) -> RadioState {
|
||||
None => unreachable!(),
|
||||
}
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub(crate) fn trace_state(radio: &pac::radio::RegisterBlock) {
|
||||
match state(radio) {
|
||||
RadioState::DISABLED => trace!("radio:state:DISABLED"),
|
||||
RadioState::RX_RU => trace!("radio:state:RX_RU"),
|
||||
RadioState::RX_IDLE => trace!("radio:state:RX_IDLE"),
|
||||
RadioState::RX => trace!("radio:state:RX"),
|
||||
RadioState::RX_DISABLE => trace!("radio:state:RX_DISABLE"),
|
||||
RadioState::TX_RU => trace!("radio:state:TX_RU"),
|
||||
RadioState::TX_IDLE => trace!("radio:state:TX_IDLE"),
|
||||
RadioState::TX => trace!("radio:state:TX"),
|
||||
RadioState::TX_DISABLE => trace!("radio:state:TX_DISABLE"),
|
||||
}
|
||||
}
|
||||
|
@ -34,7 +34,6 @@ pub(crate) fn slice_in_ram<T>(slice: *const [T]) -> bool {
|
||||
}
|
||||
|
||||
/// Return an error if slice is not in RAM. Skips check if slice is zero-length.
|
||||
#[cfg(not(feature = "nrf51"))]
|
||||
pub(crate) fn slice_in_ram_or<T, E>(slice: *const [T], err: E) -> Result<(), E> {
|
||||
let (_, len) = slice_ptr_parts(slice);
|
||||
if len == 0 || slice_in_ram(slice) {
|
||||
|
Loading…
Reference in New Issue
Block a user