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_interrupt.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_interrupt.rs')
| -rw-r--r-- | examples/src/bin/adc_interrupt.rs | 26 |
1 files changed, 3 insertions, 23 deletions
diff --git a/examples/src/bin/adc_interrupt.rs b/examples/src/bin/adc_interrupt.rs index 0d3a75a28..83d8046b3 100644 --- a/examples/src/bin/adc_interrupt.rs +++ b/examples/src/bin/adc_interrupt.rs | |||
| @@ -6,7 +6,6 @@ use embassy_mcxa_examples::init_adc_pins; | |||
| 6 | use hal::adc::{LpadcConfig, TriggerPriorityPolicy}; | 6 | use hal::adc::{LpadcConfig, TriggerPriorityPolicy}; |
| 7 | use hal::clocks::periph_helpers::{AdcClockSel, Div4}; | 7 | use hal::clocks::periph_helpers::{AdcClockSel, Div4}; |
| 8 | use hal::clocks::PoweredClock; | 8 | use hal::clocks::PoweredClock; |
| 9 | use hal::lpuart::{Config, Lpuart}; | ||
| 10 | use hal::pac::adc1::cfg::{Pwrsel, Refsel}; | 9 | use hal::pac::adc1::cfg::{Pwrsel, Refsel}; |
| 11 | use hal::pac::adc1::cmdl1::{Adch, Mode}; | 10 | use hal::pac::adc1::cmdl1::{Adch, Mode}; |
| 12 | use hal::pac::adc1::ctrl::CalAvgs; | 11 | use hal::pac::adc1::ctrl::CalAvgs; |
| @@ -26,26 +25,7 @@ static KEEP_ADC: unsafe extern "C" fn() = ADC1; | |||
| 26 | async fn main(_spawner: Spawner) { | 25 | async fn main(_spawner: Spawner) { |
| 27 | let p = hal::init(hal::config::Config::default()); | 26 | let p = hal::init(hal::config::Config::default()); |
| 28 | 27 | ||
| 29 | // Create UART configuration | 28 | defmt::info!("ADC interrupt Example"); |
| 30 | let config = Config { | ||
| 31 | baudrate_bps: 115_200, | ||
| 32 | enable_tx: true, | ||
| 33 | enable_rx: true, | ||
| 34 | ..Default::default() | ||
| 35 | }; | ||
| 36 | |||
| 37 | // Create UART instance using LPUART2 with P2_2 as TX and P2_3 as RX | ||
| 38 | unsafe { | ||
| 39 | embassy_mcxa_examples::init_uart2_pins(); | ||
| 40 | } | ||
| 41 | let mut uart = Lpuart::new_blocking( | ||
| 42 | p.LPUART2, // Peripheral | ||
| 43 | p.P2_2, // TX pin | ||
| 44 | p.P2_3, // RX pin | ||
| 45 | config, | ||
| 46 | ) | ||
| 47 | .unwrap(); | ||
| 48 | uart.write_str_blocking("\r\n=== ADC interrupt Example ===\r\n"); | ||
| 49 | 29 | ||
| 50 | unsafe { | 30 | unsafe { |
| 51 | init_adc_pins(); | 31 | init_adc_pins(); |
| @@ -81,7 +61,7 @@ async fn main(_spawner: Spawner) { | |||
| 81 | conv_trigger_config.enable_hardware_trigger = false; | 61 | conv_trigger_config.enable_hardware_trigger = false; |
| 82 | adc.set_conv_trigger_config(0, &conv_trigger_config); | 62 | adc.set_conv_trigger_config(0, &conv_trigger_config); |
| 83 | 63 | ||
| 84 | uart.write_str_blocking("\r\n=== ADC configuration done... ===\r\n"); | 64 | defmt::info!("ADC configuration done..."); |
| 85 | 65 | ||
| 86 | adc.enable_interrupt(0x1); | 66 | adc.enable_interrupt(0x1); |
| 87 | 67 | ||
| @@ -98,7 +78,7 @@ async fn main(_spawner: Spawner) { | |||
| 98 | while !adc.is_interrupt_triggered() { | 78 | while !adc.is_interrupt_triggered() { |
| 99 | // Wait until the interrupt is triggered | 79 | // Wait until the interrupt is triggered |
| 100 | } | 80 | } |
| 101 | uart.write_str_blocking("\r\n*** ADC interrupt TRIGGERED! ***\r\n"); | 81 | defmt::info!("*** ADC interrupt TRIGGERED! ***"); |
| 102 | //TBD need to print the value | 82 | //TBD need to print the value |
| 103 | } | 83 | } |
| 104 | } | 84 | } |
