Skip to content

Commit

Permalink
Add defmt type hints
Browse files Browse the repository at this point in the history
  • Loading branch information
kesyog committed Oct 2, 2023
1 parent 9aee029 commit ce82f72
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 33 deletions.
4 changes: 2 additions & 2 deletions src/bin/blinky_p0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ fn config() -> Config {

#[embassy_executor::main]
async fn main(spawner: Spawner) -> ! {
defmt::println!("Start {}!", core::env!("CARGO_BIN_NAME"));
defmt::println!("Start {=str}!", core::env!("CARGO_BIN_NAME"));
unsafe {
HEAP.init(cortex_m_rt::heap_start() as usize, HEAP_SIZE);
let reset_reason: u32 = (*pac::POWER::ptr()).resetreas.read().bits();
defmt::info!("Reset reason: {:X}", reset_reason);
defmt::info!("Reset reason: {=u32:X}", reset_reason);
}

let p = embassy_nrf::init(config());
Expand Down
4 changes: 2 additions & 2 deletions src/bin/blinky_p1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ fn config() -> Config {

#[embassy_executor::main]
async fn main(spawner: Spawner) -> ! {
defmt::println!("Start {}!", core::env!("CARGO_BIN_NAME"));
defmt::println!("Start {=str}!", core::env!("CARGO_BIN_NAME"));
unsafe {
HEAP.init(cortex_m_rt::heap_start() as usize, HEAP_SIZE);
let reset_reason: u32 = (*pac::POWER::ptr()).resetreas.read().bits();
defmt::info!("Reset reason: {:X}", reset_reason);
defmt::info!("Reset reason: {=u32:X}", reset_reason);
}

let p = embassy_nrf::init(config());
Expand Down
9 changes: 4 additions & 5 deletions src/bin/calibration_p0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,11 @@ fn config() -> Config {

#[embassy_executor::main]
async fn main(spawner: Spawner) -> ! {
defmt::println!("Start {}!", core::env!("CARGO_BIN_NAME"));
defmt::println!("Start {=str}!", core::env!("CARGO_BIN_NAME"));
unsafe {
HEAP.init(cortex_m_rt::heap_start() as usize, HEAP_SIZE);
let reset_reason: u32 = (*pac::POWER::ptr()).resetreas.read().bits();
defmt::info!("Reset reason: {:X}", reset_reason);
defmt::info!("Reset reason: {=u32:X}", reset_reason);
}
weight::init(weight::Config {
sampling_interval_hz: 80,
Expand Down Expand Up @@ -127,7 +127,7 @@ async fn main(spawner: Spawner) -> ! {
weight::Command::StartSampling(weight::SampleType::FilteredRaw(Some(Box::new(
move |_, value| {
if let Some(average) = average.add_sample(value) {
defmt::info!("Averaged: {}", average);
defmt::info!("Averaged: {=i32}", average);
}
},
))))
Expand All @@ -137,8 +137,7 @@ async fn main(spawner: Spawner) -> ! {
weight::Command::StartSampling(weight::SampleType::Calibrated(Some(Box::new(
move |_, value| {
if let Some(average) = average.add_sample(value) {
// defmt::info!("Averaged: {}", average);
defmt::info!("Averaged: {}", average / 0.454);
defmt::info!("Averaged: {=f32}", average / 0.454);
}
},
))))
Expand Down
9 changes: 4 additions & 5 deletions src/bin/calibration_p1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ fn config() -> Config {

#[embassy_executor::main]
async fn main(spawner: Spawner) -> ! {
defmt::println!("Start {}!", core::env!("CARGO_BIN_NAME"));
defmt::println!("Start {=str}!", core::env!("CARGO_BIN_NAME"));
unsafe {
HEAP.init(cortex_m_rt::heap_start() as usize, HEAP_SIZE);
let reset_reason: u32 = (*pac::POWER::ptr()).resetreas.read().bits();
defmt::info!("Reset reason: {:X}", reset_reason);
defmt::info!("Reset reason: {=u32:X}", reset_reason);
}
weight::init(weight::Config {
sampling_interval_hz: 80,
Expand Down Expand Up @@ -140,7 +140,7 @@ async fn main(spawner: Spawner) -> ! {
weight::Command::StartSampling(weight::SampleType::FilteredRaw(Some(Box::new(
move |_, value| {
if let Some(average) = average.add_sample(value) {
defmt::info!("Averaged: {}", average);
defmt::info!("Averaged: {=i32}", average);
}
},
))))
Expand All @@ -150,8 +150,7 @@ async fn main(spawner: Spawner) -> ! {
weight::Command::StartSampling(weight::SampleType::Calibrated(Some(Box::new(
move |_, value| {
if let Some(average) = average.add_sample(value) {
// defmt::info!("Averaged: {}", average);
defmt::info!("Averaged: {}", average / 0.454);
defmt::info!("Averaged: {=f32}", average / 0.454);
}
},
))))
Expand Down
6 changes: 3 additions & 3 deletions src/bin/dongle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ fn config() -> Config {

#[embassy_executor::main]
async fn main(spawner: Spawner) -> ! {
defmt::println!("Start {}!", core::env!("CARGO_BIN_NAME"));
defmt::println!("Start {=str}!", core::env!("CARGO_BIN_NAME"));
unsafe {
HEAP.init(cortex_m_rt::heap_start() as usize, HEAP_SIZE);
let reset_reason: u32 = (*pac::POWER::ptr()).resetreas.read().bits();
defmt::info!("Reset reason: {:X}", reset_reason);
defmt::info!("Reset reason: {=u32:X}", reset_reason);
// Reset certain GPIO settings that are retained through system OFF and interfere with the
// HAL
util::disable_all_gpio_sense();
Expand Down Expand Up @@ -158,7 +158,7 @@ async fn main(spawner: Spawner) -> ! {
)))
.await;
let battery_voltage = battery_voltage::one_time_sample(p.SAADC, Irqs).await;
defmt::info!("Battery voltage: {} mV", battery_voltage);
defmt::info!("Battery voltage: {=u32} mV", battery_voltage);
ch.sender().send(weight::Command::StopSampling).await;

#[cfg(feature = "console")]
Expand Down
6 changes: 3 additions & 3 deletions src/bin/proto0_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ fn config() -> Config {

#[embassy_executor::main]
async fn main(spawner: Spawner) -> ! {
defmt::println!("Start {}!", core::env!("CARGO_BIN_NAME"));
defmt::println!("Start {=str}!", core::env!("CARGO_BIN_NAME"));
unsafe {
HEAP.init(cortex_m_rt::heap_start() as usize, HEAP_SIZE);
let reset_reason: u32 = (*pac::POWER::ptr()).resetreas.read().bits();
defmt::info!("Reset reason: {:X}", reset_reason);
defmt::info!("Reset reason: {=u32:X}", reset_reason);
// Reset certain GPIO settings that are retained through system OFF and interfere with the
// HAL
util::disable_all_gpio_sense();
Expand Down Expand Up @@ -139,7 +139,7 @@ async fn main(spawner: Spawner) -> ! {
)))
.await;
let battery_voltage = battery_voltage::one_time_sample(p.SAADC, Irqs).await;
defmt::info!("Battery voltage: {} mV", battery_voltage);
defmt::info!("Battery voltage: {=u32} mV", battery_voltage);
ch.sender().send(weight::Command::StopSampling).await;

ch.sender().send(weight::Command::Tare).await;
Expand Down
6 changes: 3 additions & 3 deletions src/bin/proto1_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ fn config() -> Config {

#[embassy_executor::main]
async fn main(spawner: Spawner) -> ! {
defmt::println!("Start {}!", core::env!("CARGO_BIN_NAME"));
defmt::println!("Start {=str}!", core::env!("CARGO_BIN_NAME"));
unsafe {
HEAP.init(cortex_m_rt::heap_start() as usize, HEAP_SIZE);
let reset_reason: u32 = (*pac::POWER::ptr()).resetreas.read().bits();
defmt::info!("Reset reason: {:X}", reset_reason);
defmt::info!("Reset reason: {=u32:X}", reset_reason);
// Reset certain GPIO settings that are retained through system OFF and interfere with the
// HAL
util::disable_all_gpio_sense();
Expand Down Expand Up @@ -154,7 +154,7 @@ async fn main(spawner: Spawner) -> ! {
)))
.await;
let battery_voltage = battery_voltage::one_time_sample(p.SAADC, Irqs).await;
defmt::info!("Battery voltage: {} mV", battery_voltage);
defmt::info!("Battery voltage: {=u32} mV", battery_voltage);
ch.sender().send(weight::Command::StopSampling).await;

// This will run the offset calibration that we scheduled above
Expand Down
2 changes: 1 addition & 1 deletion src/ble/gatt_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ pub(crate) async fn run(conn: &Connection, measure_ch: &MeasureChannel) {
on_control_message(value, conn, measure_ch);
}
ProgressorServiceEvent::DataCccdWrite { notifications } => {
defmt::info!("DataCccdWrite: {}", notifications);
defmt::debug!("DataCccdWrite: {}", notifications);
}
},
})
Expand Down
2 changes: 1 addition & 1 deletion src/ble/gatt_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl GattValue for ControlOpcode {

fn from_gatt(data: &[u8]) -> Self {
if data.len() < Self::MIN_SIZE || data.len() > Self::MAX_SIZE {
defmt::error!("Control payload size out of range: {}", data.len());
defmt::error!("Control payload size out of range: {=usize}", data.len());
return Self::Invalid;
}
let opcode = data[0];
Expand Down
4 changes: 2 additions & 2 deletions src/ble/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub async fn task(sd: &'static Softdevice, measure_ch: MeasureChannel, wakeup_bu

const ADVERTISED_NAME_STR: Result<&str, core::str::Utf8Error> =
core::str::from_utf8(super::ADVERTISED_NAME);
defmt::info!("Advertising as {}", ADVERTISED_NAME_STR.unwrap());
defmt::info!("Advertising as {=str}", ADVERTISED_NAME_STR.unwrap());
let conn: Connection = match advertising::start(sd).await {
Ok(conn) => conn,
Err(AdvertiseError::Timeout) => {
Expand All @@ -56,7 +56,7 @@ pub async fn task(sd: &'static Softdevice, measure_ch: MeasureChannel, wakeup_bu
system_off(measure_ch, wakeup_button).await
}
Err(AdvertiseError::Raw(err)) => {
defmt::error!("Advertising error: {}", err as u32);
defmt::error!("Advertising error: {=u32}", err as u32);
system_off(measure_ch, wakeup_button).await
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/weight/ads1230.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ impl<'d> Ads1230<'d> {
n_skips += 1;
defmt::info!("Skipping -1 reading");
} else {
defmt::trace!("Raw = {}", raw_reading);
defmt::trace!("Raw = 0x{=u32:X}", raw_reading);
return Some(Sample { timestamp, value });
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/weight/calibrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl<T> Calibrator<T> {

fn calibrate(&self, raw_value: RawReading) -> f32 {
let value = (raw_value - self.b) as f32 * self.m;
defmt::trace!("Calibrated = {}", value);
defmt::trace!("Calibrated = {=f32}", value);
value
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/weight/hx711.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ impl<'d> Hx711<'d> {
// HX711 sometimes spontaneously returns -1 (0xFFFFFF)
if value == -1 && n_skips < 3 {
n_skips += 1;
defmt::info!("Skipping -1 reading");
defmt::warn!("Skipping -1 reading");
} else {
defmt::trace!("Raw = {}", value);
defmt::trace!("Raw = {=u32:X}", value);
return Some(Sample { timestamp, value });
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/weight/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async fn handle_command(cmd: Command, context: &mut MeasurementContext, adc: &Sh
if let Some(factory_calibration::Constants { m, b }) =
context.factory_cal.get_cal_constants()
{
defmt::info!("New calibration: m = {} b = {}", m, b);
defmt::info!("New calibration: m = {=f32} b = {=i32}", m, b);
super::write_calibration(&mut context.nvm, m, b).await;
context.calibrator.lock().await.set_calibration(m, b);
} else {
Expand Down Expand Up @@ -183,7 +183,7 @@ pub async fn task_function(rx: MeasureCommandReceiver, adc: Adc, sd: &'static So
let nvm = Nvm::new(sd);
let cal_m = nvm.read_cal_m();
let cal_b = nvm.read_cal_b();
defmt::info!("Loaded calibration: m={} b={}", cal_m, cal_b);
defmt::info!("Loaded calibration: m={=f32} b={=i32}", cal_m, cal_b);
let calibrator: &SharedCalibrator =
make_static!(Mutex::new(Calibrator::new(median, cal_m, cal_b)));

Expand Down

0 comments on commit ce82f72

Please sign in to comment.