diff options
| author | James Munns <[email protected]> | 2025-11-25 18:08:13 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-11-25 18:08:13 +0100 |
| commit | 05bf2d0438fe8c41d0fe26b85106ff73a6e273e9 (patch) | |
| tree | 8a2969ac89735154f8090d629d9c37814a25190a /examples/src/bin/adc_polling.rs | |
| parent | 7ee5cb570f0c0daeb2e6a9d5120fd96ee885025f (diff) | |
Wire up Lpuart pins (#43)
Allow the HAL lpuart driver to correctly configure pins as requested on init.
Diffstat (limited to 'examples/src/bin/adc_polling.rs')
| -rw-r--r-- | examples/src/bin/adc_polling.rs | 31 |
1 files changed, 4 insertions, 27 deletions
diff --git a/examples/src/bin/adc_polling.rs b/examples/src/bin/adc_polling.rs index 02ac321b5..ddf3f586b 100644 --- a/examples/src/bin/adc_polling.rs +++ b/examples/src/bin/adc_polling.rs | |||
| @@ -1,19 +1,15 @@ | |||
| 1 | #![no_std] | 1 | #![no_std] |
| 2 | #![no_main] | 2 | #![no_main] |
| 3 | 3 | ||
| 4 | use core::fmt::Write; | ||
| 5 | |||
| 6 | use embassy_executor::Spawner; | 4 | use embassy_executor::Spawner; |
| 7 | use embassy_mcxa_examples::{init_adc_pins, init_uart2_pins}; | 5 | use embassy_mcxa_examples::init_adc_pins; |
| 8 | use hal::adc::{ConvResult, LpadcConfig, TriggerPriorityPolicy}; | 6 | use hal::adc::{ConvResult, LpadcConfig, TriggerPriorityPolicy}; |
| 9 | use hal::clocks::periph_helpers::{AdcClockSel, Div4}; | 7 | use hal::clocks::periph_helpers::{AdcClockSel, Div4}; |
| 10 | use hal::clocks::PoweredClock; | 8 | use hal::clocks::PoweredClock; |
| 11 | use hal::lpuart::{Config, Lpuart}; | ||
| 12 | use hal::pac::adc1::cfg::{Pwrsel, Refsel}; | 9 | use hal::pac::adc1::cfg::{Pwrsel, Refsel}; |
| 13 | use hal::pac::adc1::cmdl1::{Adch, Mode}; | 10 | use hal::pac::adc1::cmdl1::{Adch, Mode}; |
| 14 | use hal::pac::adc1::ctrl::CalAvgs; | 11 | use hal::pac::adc1::ctrl::CalAvgs; |
| 15 | use hal::pac::adc1::tctrl::Tcmd; | 12 | use hal::pac::adc1::tctrl::Tcmd; |
| 16 | use heapless::String; | ||
| 17 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; | 13 | use {defmt_rtt as _, embassy_mcxa as hal, panic_probe as _}; |
| 18 | 14 | ||
| 19 | const G_LPADC_RESULT_SHIFT: u32 = 0; | 15 | const G_LPADC_RESULT_SHIFT: u32 = 0; |
| @@ -22,28 +18,11 @@ const G_LPADC_RESULT_SHIFT: u32 = 0; | |||
| 22 | async fn main(_spawner: Spawner) { | 18 | async fn main(_spawner: Spawner) { |
| 23 | let p = hal::init(hal::config::Config::default()); | 19 | let p = hal::init(hal::config::Config::default()); |
| 24 | 20 | ||
| 25 | // Create UART configuration | ||
| 26 | let config = Config { | ||
| 27 | baudrate_bps: 115_200, | ||
| 28 | enable_tx: true, | ||
| 29 | enable_rx: true, | ||
| 30 | ..Default::default() | ||
| 31 | }; | ||
| 32 | |||
| 33 | // Create UART instance using LPUART2 with P2_2 as TX and P2_3 as RX | ||
| 34 | unsafe { | 21 | unsafe { |
| 35 | init_uart2_pins(); | ||
| 36 | init_adc_pins(); | 22 | init_adc_pins(); |
| 37 | } | 23 | } |
| 38 | let mut uart = Lpuart::new_blocking( | ||
| 39 | p.LPUART2, // Peripheral | ||
| 40 | p.P2_2, // TX pin | ||
| 41 | p.P2_3, // RX pin | ||
| 42 | config, | ||
| 43 | ) | ||
| 44 | .unwrap(); | ||
| 45 | 24 | ||
| 46 | uart.write_str_blocking("\r\n=== ADC polling Example ===\r\n"); | 25 | defmt::info!("=== ADC polling Example ==="); |
| 47 | 26 | ||
| 48 | let adc_config = LpadcConfig { | 27 | let adc_config = LpadcConfig { |
| 49 | enable_in_doze_mode: true, | 28 | enable_in_doze_mode: true, |
| @@ -75,7 +54,7 @@ async fn main(_spawner: Spawner) { | |||
| 75 | conv_trigger_config.enable_hardware_trigger = false; | 54 | conv_trigger_config.enable_hardware_trigger = false; |
| 76 | adc.set_conv_trigger_config(0, &conv_trigger_config); | 55 | adc.set_conv_trigger_config(0, &conv_trigger_config); |
| 77 | 56 | ||
| 78 | uart.write_str_blocking("\r\n=== ADC configuration done... ===\r\n"); | 57 | defmt::info!("=== ADC configuration done... ==="); |
| 79 | 58 | ||
| 80 | loop { | 59 | loop { |
| 81 | adc.do_software_trigger(1); | 60 | adc.do_software_trigger(1); |
| @@ -84,8 +63,6 @@ async fn main(_spawner: Spawner) { | |||
| 84 | result = hal::adc::get_conv_result(); | 63 | result = hal::adc::get_conv_result(); |
| 85 | } | 64 | } |
| 86 | let value = result.unwrap().conv_value >> G_LPADC_RESULT_SHIFT; | 65 | let value = result.unwrap().conv_value >> G_LPADC_RESULT_SHIFT; |
| 87 | let mut buf: String<16> = String::new(); // adjust size as needed | 66 | defmt::info!("value: {=u16}", value); |
| 88 | write!(buf, "\r\nvalue: {}\r\n", value).unwrap(); | ||
| 89 | uart.write_str_blocking(&buf); | ||
| 90 | } | 67 | } |
| 91 | } | 68 | } |
