mirror of
https://github.com/esp-rs/esp-hal.git
synced 2025-10-02 14:44:42 +00:00
Consistent println output, take 2 (#4162)
This commit is contained in:
parent
6ee143eef9
commit
7edd62d15b
@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
- `critical-section` now wraps the entirety of the `print!` macros (#4162)
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
|
||||||
|
@ -38,11 +38,19 @@ log_format!("serial");
|
|||||||
#[cfg(not(feature = "no-op"))]
|
#[cfg(not(feature = "no-op"))]
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! println {
|
macro_rules! println {
|
||||||
|
() => {{
|
||||||
|
$crate::Printer::write_bytes(&[b'\n']);
|
||||||
|
}};
|
||||||
($($arg:tt)*) => {{
|
($($arg:tt)*) => {{
|
||||||
{
|
fn _do_print(args: core::fmt::Arguments<'_>) -> Result<(), core::fmt::Error> {
|
||||||
use core::fmt::Write;
|
$crate::with(|_| {
|
||||||
writeln!($crate::Printer, $($arg)*).ok();
|
use ::core::fmt::Write;
|
||||||
|
($crate::Printer).write_fmt(args)?;
|
||||||
|
$crate::Printer::write_bytes(&[b'\n']);
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
_do_print(::core::format_args!($($arg)*)).ok();
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,10 +59,13 @@ macro_rules! println {
|
|||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! print {
|
macro_rules! print {
|
||||||
($($arg:tt)*) => {{
|
($($arg:tt)*) => {{
|
||||||
{
|
fn _do_print(args: core::fmt::Arguments<'_>) -> Result<(), core::fmt::Error> {
|
||||||
use core::fmt::Write;
|
$crate::with(|_| {
|
||||||
write!($crate::Printer, $($arg)*).ok();
|
use ::core::fmt::Write;
|
||||||
|
($crate::Printer).write_fmt(args)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
_do_print(::core::format_args!($($arg)*)).ok();
|
||||||
}};
|
}};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -486,7 +497,8 @@ mod noop {
|
|||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
|
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
struct LockToken<'a>(PhantomData<&'a ()>);
|
#[doc(hidden)]
|
||||||
|
pub struct LockToken<'a>(PhantomData<&'a ()>);
|
||||||
|
|
||||||
impl LockToken<'_> {
|
impl LockToken<'_> {
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
@ -499,8 +511,9 @@ impl LockToken<'_> {
|
|||||||
static LOCK: esp_sync::RawMutex = esp_sync::RawMutex::new();
|
static LOCK: esp_sync::RawMutex = esp_sync::RawMutex::new();
|
||||||
|
|
||||||
/// Runs the callback in a critical section, if enabled.
|
/// Runs the callback in a critical section, if enabled.
|
||||||
|
#[doc(hidden)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn with<R>(f: impl FnOnce(LockToken) -> R) -> R {
|
pub fn with<R>(f: impl FnOnce(LockToken) -> R) -> R {
|
||||||
#[cfg(feature = "critical-section")]
|
#[cfg(feature = "critical-section")]
|
||||||
return LOCK.lock(|| f(unsafe { LockToken::conjure() }));
|
return LOCK.lock(|| f(unsafe { LockToken::conjure() }));
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user