Remove anyfmt

This commit is contained in:
Dario Nieuwenhuis 2020-11-27 18:42:59 +01:00
parent 49d5121094
commit 78135a81d9
24 changed files with 79 additions and 231 deletions

View File

@ -3,7 +3,7 @@
members = [
"embassy",
"embassy-nrf",
"anyfmt",
"embassy-macros",
"examples",
]
@ -11,11 +11,6 @@ exclude = [
"third_party"
]
[patch.crates-io]
panic-probe = { git = "https://github.com/knurling-rs/probe-run", branch="main" }
defmt-rtt = { git = "https://github.com/knurling-rs/defmt", branch="main" }
defmt = { git = "https://github.com/knurling-rs/defmt", branch="main" }
[profile.dev]
codegen-units = 1
debug = 2

View File

@ -52,14 +52,6 @@ cargo install --git https://github.com/knurling-rs/probe-run --branch main --fea
cargo run --bin rtc_async
```
## Using on your project
`embassy` requires git version of a few dependencies.
When using `embassy` in your own project, make sure you copy over the `[patch.crates-io]` section from root `Cargo.toml`.
This will no longer needed after the first crates.io release.
## Minimum supported Rust version (MSRV)
`rustc 1.48.0-nightly (1fd5b9d51 2020-09-20)`

View File

@ -1,10 +0,0 @@
[package]
name = "anyfmt"
version = "0.1.0"
authors = ["Dario Nieuwenhuis <dirbaio@dirbaio.net>"]
edition = "2018"
[dependencies]
defmt = { version = "0.1.0", optional = true }
log = { version = "0.4.11", optional = true }

View File

@ -1,149 +0,0 @@
#![no_std]
pub mod export {
#[cfg(feature = "defmt")]
pub use defmt;
#[cfg(feature = "log")]
pub use log;
}
#[cfg(feature = "log")]
#[macro_export]
macro_rules! log {
(trace, $($arg:expr),*) => { $crate::export::log::trace!($($arg),*); };
(debug, $($arg:expr),*) => { $crate::export::log::debug!($($arg),*); };
(info, $($arg:expr),*) => { $crate::export::log::info!($($arg),*); };
(warn, $($arg:expr),*) => { $crate::export::log::warn!($($arg),*); };
(error, $($arg:expr),*) => { $crate::export::log::error!($($arg),*); };
}
#[cfg(feature = "defmt")]
#[macro_export]
macro_rules! log {
(trace, $($arg:expr),*) => { $crate::export::defmt::trace!($($arg),*); };
(debug, $($arg:expr),*) => { $crate::export::defmt::debug!($($arg),*); };
(info, $($arg:expr),*) => { $crate::export::defmt::info!($($arg),*); };
(warn, $($arg:expr),*) => { $crate::export::defmt::warn!($($arg),*); };
(error, $($arg:expr),*) => { $crate::export::defmt::error!($($arg),*); };
}
#[cfg(not(any(feature = "log", feature = "defmt")))]
#[macro_export]
macro_rules! log {
($level:ident, $($arg:expr),*) => {{}};
}
#[macro_export]
macro_rules! trace {
($($arg:expr),*) => (log!(trace, $($arg),*));
}
#[macro_export]
macro_rules! debug {
($($arg:expr),*) => ($crate::log!(debug, $($arg),*));
}
#[macro_export]
macro_rules! info {
($($arg:expr),*) => ($crate::log!(info, $($arg),*));
}
#[macro_export]
macro_rules! warn {
($($arg:expr),*) => ($crate::log!(warn, $($arg),*));
}
#[macro_export]
macro_rules! error {
($($arg:expr),*) => ($crate::log!(error, $($arg),*));
}
#[macro_export]
macro_rules! expect {
($arg:expr, $msg:expr) => {
match $crate::Try::into_result($arg) {
::core::result::Result::Ok(t) => t,
::core::result::Result::Err(e) => {
$crate::panic!("{:?}: {:?}", $crate::intern!($msg), e);
}
}
};
}
#[cfg(feature = "defmt")]
#[macro_export]
macro_rules! intern {
($arg:expr) => {
$crate::export::defmt::intern!($arg)
};
}
#[cfg(not(feature = "defmt"))]
#[macro_export]
macro_rules! intern {
($arg:expr) => {
$arg
};
}
#[macro_export]
macro_rules! unwrap {
($arg:expr) => {
expect!($arg, "Unwrap failed")
};
}
#[macro_export]
macro_rules! panic {
() => {
$crate::panic!("panic")
};
($($arg:expr),*) => {{
$crate::log!(error, $($arg),*);
::core::panic!()
}};
}
#[macro_export]
macro_rules! assert {
($cond:expr) => {
$crate::assert!($cond, "assertion failed");
};
($cond:expr, $($arg:expr),*) => {
{
if !$cond {
$crate::panic!($($arg),*);
}
}
};
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct NoneError;
pub trait Try {
type Ok;
type Error;
fn into_result(self) -> Result<Self::Ok, Self::Error>;
}
impl<T> Try for Option<T> {
type Ok = T;
type Error = NoneError;
#[inline]
fn into_result(self) -> Result<T, NoneError> {
self.ok_or(NoneError)
}
}
impl<T, E> Try for Result<T, E> {
type Ok = T;
type Error = E;
#[inline]
fn into_result(self) -> Self {
self
}
}

View File

@ -21,13 +21,10 @@ defmt-error = [ ]
[dependencies]
embassy = { version = "0.1.0", path = "../embassy" }
anyfmt = { version = "0.1.0", path = "../anyfmt" }
defmt = { version = "0.1.0", optional = true }
cortex-m-rt = "0.6.12"
cortex-m = { version = "0.6.3" }
defmt = { version = "0.1.2" }
cortex-m-rt = "0.6.13"
cortex-m = { version = "0.6.4" }
embedded-hal = { version = "0.2.4" }
bare-metal = { version = "0.2.0", features = ["const-fn"] }
nrf52810-pac = { version = "0.9.0", optional = true }
nrf52811-pac = { version = "0.9.1", optional = true }
@ -35,8 +32,8 @@ nrf52832-pac = { version = "0.9.0", optional = true }
nrf52833-pac = { version = "0.9.0", optional = true }
nrf52840-pac = { version = "0.9.0", optional = true }
nrf52810-hal = { version = "0.11.0", optional = true }
#nrf52811-hal = { version = "0.11.0", optional = true } # doesn't exist yet
nrf52832-hal = { version = "0.11.0", optional = true }
nrf52833-hal = { version = "0.11.0", optional = true }
nrf52840-hal = { version = "0.11.0", optional = true }
nrf52810-hal = { version = "0.12.0", optional = true }
#nrf52811-hal = { version = "0.12.0", optional = true } # doesn't exist yet
nrf52832-hal = { version = "0.12.0", optional = true }
nrf52833-hal = { version = "0.12.0", optional = true }
nrf52840-hal = { version = "0.12.0", optional = true }

View File

@ -1,8 +1,8 @@
use anyfmt::{panic, *};
use core::cell::Cell;
use core::future::Future;
use core::ptr;
use core::task::{Context, Poll};
use defmt::{panic, *};
use embassy::util::Signal;
use crate::hal::gpio::{Input, Level, Output, Pin, Port};
@ -51,8 +51,7 @@ pub enum OutputChannelPolarity {
Toggle,
}
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Copy, Clone, Eq, PartialEq, defmt::Format)]
pub enum NewChannelError {
NoFreeChannels,
}

View File

@ -10,10 +10,9 @@ use crate::pac::{NVIC, NVIC_PRIO_BITS};
// Re-exports
pub use crate::pac::Interrupt;
pub use crate::pac::Interrupt::*; // needed for cortex-m-rt #[interrupt]
pub use bare_metal::{CriticalSection, Mutex};
pub use cortex_m::interrupt::{CriticalSection, Mutex};
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, defmt::Format)]
#[repr(u8)]
pub enum Priority {
Level0 = 0,

View File

@ -1,4 +1,5 @@
use core::future::Future;
use defmt::{assert, assert_eq, panic, *};
use crate::hal::gpio::{Output, Pin as GpioPin, Port as GpioPort, PushPull};
use crate::pac::{Interrupt, QSPI};
@ -32,12 +33,18 @@ pub struct Pins {
pub io3: Option<GpioPin<Output<PushPull>>>,
}
pub struct DeepPowerDownConfig {
pub enter_time: u16,
pub exit_time: u16,
}
pub struct Config {
pub pins: Pins,
pub xip_offset: u32,
pub read_opcode: ReadOpcode,
pub write_opcode: WriteOpcode,
pub write_page_size: WritePageSize,
pub deep_power_down: Option<DeepPowerDownConfig>,
}
pub struct Qspi {
@ -96,15 +103,27 @@ impl Qspi {
}
});
qspi.ifconfig0.write(|w| {
let w = w.addrmode().variant(AddressMode::_24BIT);
let w = w.dpmenable().disable();
let w = w.ppsize().variant(config.write_page_size);
let w = w.readoc().variant(config.read_opcode);
let w = w.writeoc().variant(config.write_opcode);
qspi.ifconfig0.write(|mut w| {
w = w.addrmode().variant(AddressMode::_24BIT);
if config.deep_power_down.is_some() {
w = w.dpmenable().enable();
} else {
w = w.dpmenable().disable();
}
w = w.ppsize().variant(config.write_page_size);
w = w.readoc().variant(config.read_opcode);
w = w.writeoc().variant(config.write_opcode);
w
});
if let Some(dpd) = &config.deep_power_down {
qspi.dpmdur.write(|mut w| unsafe {
w = w.enter().bits(dpd.enter_time);
w = w.exit().bits(dpd.exit_time);
w
})
}
qspi.ifconfig1.write(|w| {
let w = unsafe { w.sckdelay().bits(80) };
let w = w.dpmen().exit();
@ -125,13 +144,28 @@ impl Qspi {
qspi.events_ready.reset();
// Enable READY interrupt
SIGNAL.reset();
qspi.intenset.write(|w| w.ready().set());
interrupt::set_priority(Interrupt::QSPI, interrupt::Priority::Level7);
interrupt::unpend(Interrupt::QSPI);
interrupt::enable(Interrupt::QSPI);
Self { inner: qspi }
}
pub fn sleep(&mut self) {
info!("flash: sleeping");
info!("flash: state = {:?}", self.inner.status.read().bits());
self.inner.ifconfig1.modify(|r, w| w.dpmen().enter());
info!("flash: state = {:?}", self.inner.status.read().bits());
cortex_m::asm::delay(1000000);
info!("flash: state = {:?}", self.inner.status.read().bits());
self.inner
.tasks_deactivate
.write(|w| w.tasks_deactivate().set_bit());
}
pub fn custom_instruction<'a>(
&'a mut self,
opcode: u8,
@ -318,6 +352,7 @@ unsafe fn QSPI() {
let p = crate::pac::Peripherals::steal().QSPI;
if p.events_ready.read().events_ready().bit_is_set() {
p.events_ready.reset();
info!("qspi ready");
SIGNAL.signal(());
}
}

View File

@ -28,7 +28,7 @@ pub use uarte0::{baudrate::BAUDRATE_A as Baudrate, config::PARITY_A as Parity};
use embassy::io::{AsyncBufRead, AsyncWrite, Result};
use embassy::util::WakerStore;
use anyfmt::{assert, panic, *};
use defmt::{assert, panic, todo, *};
//use crate::trace;

View File

@ -13,12 +13,11 @@ defmt-warn = []
defmt-error = []
[dependencies]
anyfmt = { version = "0.1.0", path = "../anyfmt" }
defmt = { version = "0.1.0", optional = true }
defmt = { version = "0.1.0" }
cortex-m = "0.6.3"
cortex-m = "0.6.4"
futures = { version = "0.3.5", default-features = false }
pin-project = { version = "0.4.23", default-features = false }
pin-project = { version = "1.0.2", default-features = false }
futures-intrusive = { version = "0.3.1", default-features = false }
embassy-macros = { version = "0.1.0", path = "../embassy-macros"}

View File

@ -63,8 +63,7 @@ pub struct Task<F: Future + 'static> {
future: UninitCell<F>, // Valid if STATE_RUNNING
}
#[derive(Copy, Clone, Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Copy, Clone, Debug, defmt::Format)]
pub enum SpawnError {
Busy,
}

View File

@ -1,7 +1,6 @@
use core::future::Future;
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Copy, Clone, Debug, Eq, PartialEq, defmt::Format)]
pub enum Error {
Failed,
AddressMisaligned,

View File

@ -2,8 +2,7 @@
///
/// This list is intended to grow over time and it is not recommended to
/// exhaustively match against it.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, defmt::Format)]
pub enum Error {
/// An entity was not found, often a file.
NotFound,

View File

@ -1,4 +1,4 @@
use anyfmt::*;
use defmt::*;
pub trait Rand {
fn rand(&self, buf: &mut [u8]);
@ -11,5 +11,5 @@ pub unsafe fn set_rand(rand: &'static dyn Rand) {
}
pub fn rand(buf: &mut [u8]) {
unsafe { expect!(RAND, "No rand set").rand(buf) }
unsafe { unwrap!(RAND, "No rand set").rand(buf) }
}

View File

@ -3,8 +3,7 @@ use core::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Sub, SubAssign};
use super::TICKS_PER_SECOND;
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Default, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, defmt::Format)]
pub struct Duration {
pub(crate) ticks: u64,
}

View File

@ -5,8 +5,7 @@ use core::ops::{Add, AddAssign, Sub, SubAssign};
use super::TICKS_PER_SECOND;
use super::{now, Duration};
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, defmt::Format)]
pub struct Instant {
ticks: u64,
}

View File

@ -8,7 +8,7 @@ pub use instant::Instant;
pub use timer::Timer;
pub use traits::*;
use anyfmt::*;
use defmt::*;
// TODO allow customizing, probably via Cargo features `tick-hz-32768` or something.
pub const TICKS_PER_SECOND: u64 = 32768;
@ -20,5 +20,5 @@ pub unsafe fn set_clock(clock: &'static dyn Clock) {
}
pub(crate) fn now() -> u64 {
unsafe { expect!(CLOCK, "No clock set").now() }
unsafe { unwrap!(CLOCK, "No clock set").now() }
}

View File

@ -1,5 +1,5 @@
use anyfmt::panic;
use core::mem;
use defmt::panic;
pub struct DropBomb {
_private: (),

View File

@ -1,8 +1,8 @@
use anyfmt::panic;
use core::cell::UnsafeCell;
use core::future::Future;
use core::mem;
use core::mem::MaybeUninit;
use defmt::panic;
use crate::util::*;

View File

@ -1,8 +1,8 @@
use anyfmt::panic;
use core::cell::UnsafeCell;
use core::future::Future;
use core::mem;
use core::task::{Context, Poll, Waker};
use defmt::panic;
pub struct Signal<T> {
state: UnsafeCell<State<T>>,

View File

@ -17,17 +17,16 @@ defmt-error = []
[dependencies]
embassy = { version = "0.1.0", path = "../embassy", features = ["defmt"] }
embassy-nrf = { version = "0.1.0", path = "../embassy-nrf", features = ["defmt", "defmt-trace", "52840"] }
anyfmt = { version = "0.1.0", path = "../anyfmt", features = ["defmt"] }
embassy = { version = "0.1.0", path = "../embassy", features = ["defmt-trace"] }
embassy-nrf = { version = "0.1.0", path = "../embassy-nrf", features = ["defmt-trace", "52840"] }
defmt = "0.1.0"
defmt = "0.1.2"
defmt-rtt = "0.1.0"
cortex-m = { version = "0.6.3" }
cortex-m-rt = "0.6.12"
embedded-hal = { version = "0.2.4" }
panic-probe = "0.1.0"
nrf52840-hal = { version = "0.11.0" }
futures = { version = "0.3.7", default-features = false, features = ["async-await"] }
nrf52840-hal = { version = "0.12.0" }
futures = { version = "0.3.8", default-features = false, features = ["async-await"] }
cortex-m-rtic = { git = "https://github.com/rtic-rs/cortex-m-rtic", branch = "master"}

View File

@ -6,8 +6,8 @@
mod example_common;
use example_common::*;
use anyfmt::panic;
use cortex_m_rt::entry;
use defmt::{assert_eq, panic, *};
use nrf52840_hal::gpio;
use embassy::executor::{task, Executor};
@ -65,6 +65,7 @@ async fn run() {
write_opcode: qspi::WriteOpcode::PP4IO,
xip_offset: 0,
write_page_size: qspi::WritePageSize::_256BYTES,
deep_power_down: None,
};
let mut q = qspi::Qspi::new(p.QSPI, config);

View File

@ -4,7 +4,7 @@ use defmt_rtt as _; // global logger
use nrf52840_hal as _;
use panic_probe as _;
pub use anyfmt::*;
pub use defmt::*;
use core::sync::atomic::{AtomicUsize, Ordering};

View File

@ -7,15 +7,11 @@ set -euxo pipefail
# embassy
(cd embassy; cargo build --target thumbv7em-none-eabihf)
(cd embassy; cargo build --target thumbv7em-none-eabihf --features defmt,anyfmt/defmt)
(cd embassy; cargo build --target thumbv7em-none-eabihf --features anyfmt/log)
# embassy-nrf
(cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52810)
(cd embassy-nrf; cargo build --target thumbv7em-none-eabi --features 52810)
#(cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52811) # nrf52811-hal doesn't exist yet
(cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52832)
(cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52833)
(cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52840)
(cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52840,anyfmt/log)
(cd embassy-nrf; cargo build --target thumbv7em-none-eabihf --features 52840,defmt,embassy/defmt,anyfmt/defmt)