aboutsummaryrefslogtreecommitdiff
path: root/examples/lpc55s69/src
diff options
context:
space:
mode:
authorDion Dokter <[email protected]>2025-11-20 13:22:38 +0100
committerDion Dokter <[email protected]>2025-11-20 13:22:38 +0100
commit4f2c36e447455e8d33607d586859d3d075cabf1d (patch)
tree003cd822d688acd7c074dd229663b4648d100f71 /examples/lpc55s69/src
parent663732d85abbae400f2dbab2c411802a5b60e9b1 (diff)
parent661874d11de7d93ed52e08e020a9d4c7ee11122d (diff)
Merge branch 'main' into u0-lcd
Diffstat (limited to 'examples/lpc55s69/src')
-rw-r--r--examples/lpc55s69/src/bin/blinky_embassy_time.rs26
-rw-r--r--examples/lpc55s69/src/bin/blinky_nop.rs33
-rw-r--r--examples/lpc55s69/src/bin/button_executor.rs25
-rw-r--r--examples/lpc55s69/src/bin/pwm.rs18
-rw-r--r--examples/lpc55s69/src/bin/usart_async.rs70
-rw-r--r--examples/lpc55s69/src/bin/usart_blocking.rs40
6 files changed, 212 insertions, 0 deletions
diff --git a/examples/lpc55s69/src/bin/blinky_embassy_time.rs b/examples/lpc55s69/src/bin/blinky_embassy_time.rs
new file mode 100644
index 000000000..adc3d8bd3
--- /dev/null
+++ b/examples/lpc55s69/src/bin/blinky_embassy_time.rs
@@ -0,0 +1,26 @@
1#![no_std]
2#![no_main]
3
4use defmt::*;
5use embassy_executor::Spawner;
6use embassy_nxp::gpio::{Level, Output};
7use embassy_time::Timer;
8use {defmt_rtt as _, panic_halt as _};
9
10#[embassy_executor::main]
11async fn main(_spawner: Spawner) {
12 let p = embassy_nxp::init(Default::default());
13 info!("Initialization complete");
14 let mut led = Output::new(p.PIO1_6, Level::Low);
15
16 info!("Entering main loop");
17 loop {
18 info!("led off!");
19 led.set_high();
20 Timer::after_millis(500).await;
21
22 info!("led on!");
23 led.set_low();
24 Timer::after_millis(500).await;
25 }
26}
diff --git a/examples/lpc55s69/src/bin/blinky_nop.rs b/examples/lpc55s69/src/bin/blinky_nop.rs
new file mode 100644
index 000000000..58e2d9808
--- /dev/null
+++ b/examples/lpc55s69/src/bin/blinky_nop.rs
@@ -0,0 +1,33 @@
1//! This example has been made with the LPCXpresso55S69 board in mind, which has a built-in LED on PIO1_6.
2
3#![no_std]
4#![no_main]
5
6use cortex_m::asm::nop;
7use defmt::*;
8use embassy_executor::Spawner;
9use embassy_nxp::gpio::{Level, Output};
10use {defmt_rtt as _, panic_halt as _};
11
12#[embassy_executor::main]
13async fn main(_spawner: Spawner) {
14 let p = embassy_nxp::init(Default::default());
15
16 let mut led = Output::new(p.PIO1_6, Level::Low);
17
18 loop {
19 info!("led off!");
20 led.set_high();
21
22 for _ in 0..200_000 {
23 nop();
24 }
25
26 info!("led on!");
27 led.set_low();
28
29 for _ in 0..200_000 {
30 nop();
31 }
32 }
33}
diff --git a/examples/lpc55s69/src/bin/button_executor.rs b/examples/lpc55s69/src/bin/button_executor.rs
new file mode 100644
index 000000000..836b1c9eb
--- /dev/null
+++ b/examples/lpc55s69/src/bin/button_executor.rs
@@ -0,0 +1,25 @@
1//! This example has been made with the LPCXpresso55S69 board in mind, which has a built-in LED on
2//! PIO1_6 and a button (labeled "user") on PIO1_9.
3
4#![no_std]
5#![no_main]
6
7use defmt::*;
8use embassy_executor::Spawner;
9use embassy_nxp::gpio::{Input, Level, Output, Pull};
10use {defmt_rtt as _, panic_halt as _};
11
12#[embassy_executor::main]
13async fn main(_spawner: Spawner) -> ! {
14 let p = embassy_nxp::init(Default::default());
15
16 let mut led = Output::new(p.PIO1_6, Level::Low);
17 let mut button = Input::new(p.PIO1_9, Pull::Up);
18
19 info!("Entered main loop");
20 loop {
21 button.wait_for_rising_edge().await;
22 info!("Button pressed");
23 led.toggle();
24 }
25}
diff --git a/examples/lpc55s69/src/bin/pwm.rs b/examples/lpc55s69/src/bin/pwm.rs
new file mode 100644
index 000000000..8a9894b94
--- /dev/null
+++ b/examples/lpc55s69/src/bin/pwm.rs
@@ -0,0 +1,18 @@
1#![no_std]
2#![no_main]
3
4use defmt::*;
5use embassy_executor::Spawner;
6use embassy_nxp::pwm::{Config, Pwm};
7use embassy_time::Timer;
8use {defmt_rtt as _, panic_halt as _};
9
10#[embassy_executor::main]
11async fn main(_spawner: Spawner) {
12 let p = embassy_nxp::init(Default::default());
13 let pwm = Pwm::new_output(p.SCT0_OUT1, p.PIO0_18, Config::new(1_000_000_000, 2_000_000_000));
14 loop {
15 info!("Counter: {}", pwm.counter());
16 Timer::after_millis(50).await;
17 }
18}
diff --git a/examples/lpc55s69/src/bin/usart_async.rs b/examples/lpc55s69/src/bin/usart_async.rs
new file mode 100644
index 000000000..a9815b920
--- /dev/null
+++ b/examples/lpc55s69/src/bin/usart_async.rs
@@ -0,0 +1,70 @@
1#![no_std]
2#![no_main]
3
4use core::str::from_utf8_mut;
5
6use defmt::*;
7use embassy_executor::Spawner;
8use embassy_nxp::bind_interrupts;
9use embassy_nxp::gpio::{Level, Output};
10use embassy_nxp::peripherals::USART2;
11use embassy_nxp::usart::{Config, InterruptHandler, Usart};
12use embassy_time::Timer;
13use {defmt_rtt as _, panic_halt as _};
14
15bind_interrupts!(struct Irqs {
16 FLEXCOMM2 => InterruptHandler<USART2>;
17 }
18);
19
20#[embassy_executor::task]
21async fn blinky_task(mut led: Output<'static>) {
22 loop {
23 info!("[TASK] led off!");
24 led.set_high();
25 Timer::after_millis(500).await;
26
27 info!("[TASK] led on!");
28 led.set_low();
29 Timer::after_millis(500).await;
30 }
31}
32
33#[embassy_executor::main]
34async fn main(spawner: Spawner) {
35 let p = embassy_nxp::init(Default::default());
36 let mut usart = Usart::new(
37 p.USART2,
38 p.PIO0_27,
39 p.PIO1_24,
40 Irqs,
41 p.DMA0_CH11,
42 p.DMA0_CH10,
43 Config::default(),
44 );
45 let led = Output::new(p.PIO1_6, Level::Low);
46 spawner.spawn(blinky_task(led).unwrap());
47 info!("[MAIN] Entering main loop");
48 loop {
49 let tx_buf = b"Hello, Ferris!";
50 let mut rx_buf = [0u8; 14];
51 info!("[MAIN] Write a message");
52 usart.write(tx_buf).await.unwrap();
53 Timer::after_millis(500).await;
54
55 info!("[MAIN] Read a message");
56 match usart.read(&mut rx_buf).await {
57 Ok(_) => match from_utf8_mut(&mut rx_buf) {
58 Ok(str) => {
59 info!("[MAIN] The message is: {}", str);
60 }
61 Err(_) => {
62 error!("[MAIN] Error in converting to UTF8");
63 }
64 },
65 Err(e) => warn!("[MAIN] Error: {}", e),
66 }
67
68 Timer::after_millis(500).await;
69 }
70}
diff --git a/examples/lpc55s69/src/bin/usart_blocking.rs b/examples/lpc55s69/src/bin/usart_blocking.rs
new file mode 100644
index 000000000..a38ec0c5b
--- /dev/null
+++ b/examples/lpc55s69/src/bin/usart_blocking.rs
@@ -0,0 +1,40 @@
1#![no_std]
2#![no_main]
3
4use core::str::from_utf8_mut;
5
6use defmt::*;
7use embassy_executor::Spawner;
8use embassy_nxp::usart::{Config, Usart};
9use embassy_time::Timer;
10use {defmt_rtt as _, panic_halt as _};
11
12#[embassy_executor::main]
13async fn main(_spawner: Spawner) {
14 let p = embassy_nxp::init(Default::default());
15 let mut usart = Usart::new_blocking(p.USART2, p.PIO0_27, p.PIO1_24, Config::default());
16 let tx_buf = b"Hello, Ferris!";
17 let mut rx_buf = [0u8; 14];
18
19 loop {
20 info!("Write a message");
21 usart.blocking_write(tx_buf).unwrap();
22 usart.blocking_flush().unwrap();
23
24 Timer::after_millis(500).await;
25
26 info!("Read a message");
27 usart.blocking_read(&mut rx_buf).unwrap();
28
29 match from_utf8_mut(&mut rx_buf) {
30 Ok(str) => {
31 info!("The message is: {}", str);
32 }
33 Err(_) => {
34 error!("Error in converting to UTF8");
35 }
36 }
37
38 Timer::after_millis(500).await;
39 }
40}