From e0cdc356ccd7f9e20c2b5355cc52b7eb7610147b Mon Sep 17 00:00:00 2001 From: i509VCB Date: Thu, 13 Mar 2025 22:10:45 -0500 Subject: Embassy for MSPM0 This adds an embassy hal for the Texas Instruments MSPM0 microcontroller series. So far the GPIO and time drivers have been implemented. I have tested these drivers on the following parts: - C1104 - L1306 - L2228 - G3507 - G3519 The PAC is generated at https://github.com/mspm0-rs --- examples/mspm0l1306/src/bin/blinky.rs | 27 +++++++++++++++++++++++++++ examples/mspm0l1306/src/bin/button.rs | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 examples/mspm0l1306/src/bin/blinky.rs create mode 100644 examples/mspm0l1306/src/bin/button.rs (limited to 'examples/mspm0l1306/src') diff --git a/examples/mspm0l1306/src/bin/blinky.rs b/examples/mspm0l1306/src/bin/blinky.rs new file mode 100644 index 000000000..11eee2d80 --- /dev/null +++ b/examples/mspm0l1306/src/bin/blinky.rs @@ -0,0 +1,27 @@ +#![no_std] +#![no_main] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_mspm0::{ + gpio::{Level, Output}, + Config, +}; +use embassy_time::Timer; +use {defmt_rtt as _, panic_halt as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { + info!("Hello world!"); + let p = embassy_mspm0::init(Config::default()); + + let mut led1 = Output::new(p.PA0, Level::Low); + led1.set_inversion(true); + + loop { + Timer::after_millis(400).await; + + info!("Toggle"); + led1.toggle(); + } +} diff --git a/examples/mspm0l1306/src/bin/button.rs b/examples/mspm0l1306/src/bin/button.rs new file mode 100644 index 000000000..2813518c2 --- /dev/null +++ b/examples/mspm0l1306/src/bin/button.rs @@ -0,0 +1,35 @@ +#![no_std] +#![no_main] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_mspm0::{ + gpio::{Input, Level, Output, Pull}, + Config, +}; +use {defmt_rtt as _, panic_halt as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { + info!("Hello world!"); + + let p = embassy_mspm0::init(Config::default()); + + let led1 = p.PA0; + let s2 = p.PA14; + + let mut led1 = Output::new(led1, Level::Low); + + let mut s2 = Input::new(s2, Pull::Up); + + // led1 is active low + led1.set_high(); + + loop { + s2.wait_for_falling_edge().await; + + info!("Switch 2 was pressed"); + + led1.toggle(); + } +} -- cgit From 0c8dadf0ca2dfa7fac3767d0c33276bd694c5824 Mon Sep 17 00:00:00 2001 From: i509VCB Date: Thu, 13 Mar 2025 22:30:45 -0500 Subject: rustfmt 2: electric boogaloo --- examples/mspm0l1306/src/bin/blinky.rs | 6 ++---- examples/mspm0l1306/src/bin/button.rs | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) (limited to 'examples/mspm0l1306/src') diff --git a/examples/mspm0l1306/src/bin/blinky.rs b/examples/mspm0l1306/src/bin/blinky.rs index 11eee2d80..055a5cd81 100644 --- a/examples/mspm0l1306/src/bin/blinky.rs +++ b/examples/mspm0l1306/src/bin/blinky.rs @@ -3,10 +3,8 @@ use defmt::*; use embassy_executor::Spawner; -use embassy_mspm0::{ - gpio::{Level, Output}, - Config, -}; +use embassy_mspm0::gpio::{Level, Output}; +use embassy_mspm0::Config; use embassy_time::Timer; use {defmt_rtt as _, panic_halt as _}; diff --git a/examples/mspm0l1306/src/bin/button.rs b/examples/mspm0l1306/src/bin/button.rs index 2813518c2..d8c85947f 100644 --- a/examples/mspm0l1306/src/bin/button.rs +++ b/examples/mspm0l1306/src/bin/button.rs @@ -3,10 +3,8 @@ use defmt::*; use embassy_executor::Spawner; -use embassy_mspm0::{ - gpio::{Input, Level, Output, Pull}, - Config, -}; +use embassy_mspm0::gpio::{Input, Level, Output, Pull}; +use embassy_mspm0::Config; use {defmt_rtt as _, panic_halt as _}; #[embassy_executor::main] -- cgit From 91cde689cc0c771ffeb3864eb41e88104d476b47 Mon Sep 17 00:00:00 2001 From: i509VCB Date: Sat, 22 Mar 2025 17:52:13 -0500 Subject: mspm0: blocking uart driver --- examples/mspm0l1306/src/bin/uart.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 examples/mspm0l1306/src/bin/uart.rs (limited to 'examples/mspm0l1306/src') diff --git a/examples/mspm0l1306/src/bin/uart.rs b/examples/mspm0l1306/src/bin/uart.rs new file mode 100644 index 000000000..95c56fdd3 --- /dev/null +++ b/examples/mspm0l1306/src/bin/uart.rs @@ -0,0 +1,35 @@ +//! Example of using blocking uart +//! +//! This uses the virtual COM port provided on the LP-MSPM0L1306 board. + +#![no_std] +#![no_main] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_mspm0::uart::{Config, Uart}; +use {defmt_rtt as _, panic_halt as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { + info!("Hello world!"); + + let p = embassy_mspm0::init(Default::default()); + + let instance = p.UART0; + let tx = p.PA8; + let rx = p.PA9; + + let config = Config::default(); + let mut uart = unwrap!(Uart::new_blocking(instance, rx, tx, config)); + + unwrap!(uart.blocking_write(b"Hello Embassy World!\r\n")); + info!("wrote Hello, starting echo"); + + let mut buf = [0u8; 1]; + + loop { + unwrap!(uart.blocking_read(&mut buf)); + unwrap!(uart.blocking_write(&buf)); + } +} -- cgit From f9753f3d314ca00fb36103fa39b0911d3e3047ba Mon Sep 17 00:00:00 2001 From: Siarhei B Date: Mon, 21 Jul 2025 14:22:32 +0200 Subject: mspm0: Add I2C Controller examples for mspm0l1306, mspm0g3507 MCUs - mspm0l1306 examples: add I2C blocking & async examples - mspm0l1306 examples: add -O2 optimization due to Flash limitations - mspm0g3507 examples: add I2C blocking & async examples --- examples/mspm0l1306/src/bin/i2c.rs | 37 +++++++++++++++++++++++++++ examples/mspm0l1306/src/bin/i2c_async.rs | 43 ++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 examples/mspm0l1306/src/bin/i2c.rs create mode 100644 examples/mspm0l1306/src/bin/i2c_async.rs (limited to 'examples/mspm0l1306/src') diff --git a/examples/mspm0l1306/src/bin/i2c.rs b/examples/mspm0l1306/src/bin/i2c.rs new file mode 100644 index 000000000..02c0ee740 --- /dev/null +++ b/examples/mspm0l1306/src/bin/i2c.rs @@ -0,0 +1,37 @@ +//! Example of using blocking I2C +//! +//! This uses the virtual COM port provided on the LP-MSPM0L1306 board. + +#![no_std] +#![no_main] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_mspm0::i2c::{BusSpeed, ClockSel, Config, I2c}; +use {defmt_rtt as _, panic_halt as _}; + +const ADDRESS: u8 = 0x6a; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { + let p = embassy_mspm0::init(Default::default()); + + let instance = p.I2C0; + let scl = p.PA1; + let sda = p.PA0; + + let mut config = Config::default(); + config.clock_source = ClockSel::BusClk; + config.bus_speed = BusSpeed::FastMode; + let mut i2c = unwrap!(I2c::new_blocking(instance, scl, sda, config)); + + let mut to_read = [0u8; 1]; + let to_write: u8 = 0x0F; + + match i2c.blocking_write_read(ADDRESS, &[to_write], &mut to_read) { + Ok(()) => info!("Register {}: {}", to_write, to_read[0]), + Err(e) => error!("I2c Error: {:?}", e), + } + + loop {} +} diff --git a/examples/mspm0l1306/src/bin/i2c_async.rs b/examples/mspm0l1306/src/bin/i2c_async.rs new file mode 100644 index 000000000..34e2c64e7 --- /dev/null +++ b/examples/mspm0l1306/src/bin/i2c_async.rs @@ -0,0 +1,43 @@ +//! Example of using async I2C +//! +//! This uses the virtual COM port provided on the LP-MSPM0L1306 board. + +#![no_std] +#![no_main] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_mspm0::bind_interrupts; +use embassy_mspm0::i2c::{BusSpeed, ClockSel, Config, I2c, InterruptHandler}; +use embassy_mspm0::peripherals::I2C0; +use {defmt_rtt as _, panic_halt as _}; + +const ADDRESS: u8 = 0x6a; + +bind_interrupts!(struct Irqs { + I2C0 => InterruptHandler; +}); + +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { + let p = embassy_mspm0::init(Default::default()); + + let instance = p.I2C0; + let scl = p.PA1; + let sda = p.PA0; + + let mut config = Config::default(); + config.clock_source = ClockSel::BusClk; + config.bus_speed = BusSpeed::FastMode; + let mut i2c = unwrap!(I2c::new_async(instance, scl, sda, Irqs, config)); + + let mut to_read = [0u8; 1]; + let to_write: u8 = 0x0F; + + match i2c.async_write_read(ADDRESS, &[to_write], &mut to_read).await { + Ok(()) => info!("Register {}: {}", to_write, to_read[0]), + Err(e) => error!("I2c Error: {:?}", e), + } + + loop {} +} -- cgit From 917a509c1a899d7054f1a9cf2a21369dc143f46b Mon Sep 17 00:00:00 2001 From: Siarhei B Date: Wed, 23 Jul 2025 17:00:10 +0200 Subject: mspm0-I2C: automate source clock definition - i2c-config: automatically defines clock source based on input I2C rate - i2c: proper config functions naming - i2c-examples: adapt to changed API - i2c: save initialization pf cctr register --- examples/mspm0l1306/src/bin/i2c.rs | 7 ++----- examples/mspm0l1306/src/bin/i2c_async.rs | 7 ++----- 2 files changed, 4 insertions(+), 10 deletions(-) (limited to 'examples/mspm0l1306/src') diff --git a/examples/mspm0l1306/src/bin/i2c.rs b/examples/mspm0l1306/src/bin/i2c.rs index 02c0ee740..cf65206b2 100644 --- a/examples/mspm0l1306/src/bin/i2c.rs +++ b/examples/mspm0l1306/src/bin/i2c.rs @@ -7,7 +7,7 @@ use defmt::*; use embassy_executor::Spawner; -use embassy_mspm0::i2c::{BusSpeed, ClockSel, Config, I2c}; +use embassy_mspm0::i2c::{Config, I2c}; use {defmt_rtt as _, panic_halt as _}; const ADDRESS: u8 = 0x6a; @@ -20,10 +20,7 @@ async fn main(_spawner: Spawner) -> ! { let scl = p.PA1; let sda = p.PA0; - let mut config = Config::default(); - config.clock_source = ClockSel::BusClk; - config.bus_speed = BusSpeed::FastMode; - let mut i2c = unwrap!(I2c::new_blocking(instance, scl, sda, config)); + let mut i2c = unwrap!(I2c::new_blocking(instance, scl, sda, Config::default())); let mut to_read = [0u8; 1]; let to_write: u8 = 0x0F; diff --git a/examples/mspm0l1306/src/bin/i2c_async.rs b/examples/mspm0l1306/src/bin/i2c_async.rs index 34e2c64e7..a54beebe5 100644 --- a/examples/mspm0l1306/src/bin/i2c_async.rs +++ b/examples/mspm0l1306/src/bin/i2c_async.rs @@ -8,7 +8,7 @@ use defmt::*; use embassy_executor::Spawner; use embassy_mspm0::bind_interrupts; -use embassy_mspm0::i2c::{BusSpeed, ClockSel, Config, I2c, InterruptHandler}; +use embassy_mspm0::i2c::{Config, I2c, InterruptHandler}; use embassy_mspm0::peripherals::I2C0; use {defmt_rtt as _, panic_halt as _}; @@ -26,10 +26,7 @@ async fn main(_spawner: Spawner) -> ! { let scl = p.PA1; let sda = p.PA0; - let mut config = Config::default(); - config.clock_source = ClockSel::BusClk; - config.bus_speed = BusSpeed::FastMode; - let mut i2c = unwrap!(I2c::new_async(instance, scl, sda, Irqs, config)); + let mut i2c = unwrap!(I2c::new_async(instance, scl, sda, Irqs, Config::default())); let mut to_read = [0u8; 1]; let to_write: u8 = 0x0F; -- cgit From d6a87b411432d9c6eedd48aa30b72cda069bd86c Mon Sep 17 00:00:00 2001 From: Siarhei B Date: Tue, 29 Jul 2025 15:26:34 +0200 Subject: mspm0-I2C: mention blocking API's restrictions - blocking API for transfering max 8 bytes - async API has no such limitations --- examples/mspm0l1306/src/bin/i2c.rs | 3 ++- examples/mspm0l1306/src/bin/i2c_async.rs | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'examples/mspm0l1306/src') diff --git a/examples/mspm0l1306/src/bin/i2c.rs b/examples/mspm0l1306/src/bin/i2c.rs index cf65206b2..51327dff5 100644 --- a/examples/mspm0l1306/src/bin/i2c.rs +++ b/examples/mspm0l1306/src/bin/i2c.rs @@ -1,4 +1,5 @@ -//! Example of using blocking I2C +//! This example uses FIFO with polling, and the maximum FIFO size is 8. +//! Refer to async example to handle larger packets. //! //! This uses the virtual COM port provided on the LP-MSPM0L1306 board. diff --git a/examples/mspm0l1306/src/bin/i2c_async.rs b/examples/mspm0l1306/src/bin/i2c_async.rs index a54beebe5..74826bcc4 100644 --- a/examples/mspm0l1306/src/bin/i2c_async.rs +++ b/examples/mspm0l1306/src/bin/i2c_async.rs @@ -1,4 +1,4 @@ -//! Example of using async I2C +//! The example uses FIFO and interrupts, wrapped in async API. //! //! This uses the virtual COM port provided on the LP-MSPM0L1306 board. @@ -28,10 +28,10 @@ async fn main(_spawner: Spawner) -> ! { let mut i2c = unwrap!(I2c::new_async(instance, scl, sda, Irqs, Config::default())); - let mut to_read = [0u8; 1]; - let to_write: u8 = 0x0F; + let mut to_read = [1u8; 17]; + let to_write = [0u8; 17]; - match i2c.async_write_read(ADDRESS, &[to_write], &mut to_read).await { + match i2c.async_write_read(ADDRESS, &to_write, &mut to_read).await { Ok(()) => info!("Register {}: {}", to_write, to_read[0]), Err(e) => error!("I2c Error: {:?}", e), } -- cgit From e78959ed67f8c89f2adc78f5e4580c62d3c66081 Mon Sep 17 00:00:00 2001 From: Siarhei B Date: Mon, 4 Aug 2025 13:10:39 +0200 Subject: mspm0-I2C: replace examples for mspm0l1306 & mspm0g3507 with AD5171 --- examples/mspm0l1306/src/bin/i2c.rs | 28 +++++++++++++++++++--------- examples/mspm0l1306/src/bin/i2c_async.rs | 26 ++++++++++++++++++-------- 2 files changed, 37 insertions(+), 17 deletions(-) (limited to 'examples/mspm0l1306/src') diff --git a/examples/mspm0l1306/src/bin/i2c.rs b/examples/mspm0l1306/src/bin/i2c.rs index 51327dff5..e8801c485 100644 --- a/examples/mspm0l1306/src/bin/i2c.rs +++ b/examples/mspm0l1306/src/bin/i2c.rs @@ -1,7 +1,7 @@ //! This example uses FIFO with polling, and the maximum FIFO size is 8. //! Refer to async example to handle larger packets. //! -//! This uses the virtual COM port provided on the LP-MSPM0L1306 board. +//! This example controls AD5171 digital potentiometer via I2C with the LP-MSPM0L1306 board. #![no_std] #![no_main] @@ -9,9 +9,10 @@ use defmt::*; use embassy_executor::Spawner; use embassy_mspm0::i2c::{Config, I2c}; +use embassy_time::Timer; use {defmt_rtt as _, panic_halt as _}; -const ADDRESS: u8 = 0x6a; +const ADDRESS: u8 = 0x2c; #[embassy_executor::main] async fn main(_spawner: Spawner) -> ! { @@ -23,13 +24,22 @@ async fn main(_spawner: Spawner) -> ! { let mut i2c = unwrap!(I2c::new_blocking(instance, scl, sda, Config::default())); - let mut to_read = [0u8; 1]; - let to_write: u8 = 0x0F; + let mut pot_value: u8 = 0; - match i2c.blocking_write_read(ADDRESS, &[to_write], &mut to_read) { - Ok(()) => info!("Register {}: {}", to_write, to_read[0]), - Err(e) => error!("I2c Error: {:?}", e), - } + loop { + let to_write = [0u8, pot_value]; + + match i2c.blocking_write(ADDRESS, &to_write) { + Ok(()) => info!("New potentioemter value: {}", pot_value), + Err(e) => error!("I2c Error: {:?}", e), + } - loop {} + pot_value += 1; + // if reached 64th position (max) + // start over from lowest value + if pot_value == 64 { + pot_value = 0; + } + Timer::after_millis(500).await; + } } diff --git a/examples/mspm0l1306/src/bin/i2c_async.rs b/examples/mspm0l1306/src/bin/i2c_async.rs index 74826bcc4..c4a6938ff 100644 --- a/examples/mspm0l1306/src/bin/i2c_async.rs +++ b/examples/mspm0l1306/src/bin/i2c_async.rs @@ -1,6 +1,6 @@ //! The example uses FIFO and interrupts, wrapped in async API. //! -//! This uses the virtual COM port provided on the LP-MSPM0L1306 board. +//! This example controls AD5171 digital potentiometer via I2C with the LP-MSPM0L1306 board. #![no_std] #![no_main] @@ -10,6 +10,7 @@ use embassy_executor::Spawner; use embassy_mspm0::bind_interrupts; use embassy_mspm0::i2c::{Config, I2c, InterruptHandler}; use embassy_mspm0::peripherals::I2C0; +use embassy_time::Timer; use {defmt_rtt as _, panic_halt as _}; const ADDRESS: u8 = 0x6a; @@ -28,13 +29,22 @@ async fn main(_spawner: Spawner) -> ! { let mut i2c = unwrap!(I2c::new_async(instance, scl, sda, Irqs, Config::default())); - let mut to_read = [1u8; 17]; - let to_write = [0u8; 17]; + let mut pot_value: u8 = 0; - match i2c.async_write_read(ADDRESS, &to_write, &mut to_read).await { - Ok(()) => info!("Register {}: {}", to_write, to_read[0]), - Err(e) => error!("I2c Error: {:?}", e), - } + loop { + let to_write = [0u8, pot_value]; + + match i2c.async_write(ADDRESS, &to_write).await { + Ok(()) => info!("New potentioemter value: {}", pot_value), + Err(e) => error!("I2c Error: {:?}", e), + } - loop {} + pot_value += 1; + // if reached 64th position (max) + // start over from lowest value + if pot_value == 64 { + pot_value = 0; + } + Timer::after_millis(500).await; + } } -- cgit From 93ba2c9c95721f1fe16269f09c219b161b2969cb Mon Sep 17 00:00:00 2001 From: Siarhei B Date: Thu, 21 Aug 2025 09:32:05 +0200 Subject: mspm0-watchdog: add watchdog examples for all chips --- examples/mspm0l1306/src/bin/wwdt.rs | 54 +++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 examples/mspm0l1306/src/bin/wwdt.rs (limited to 'examples/mspm0l1306/src') diff --git a/examples/mspm0l1306/src/bin/wwdt.rs b/examples/mspm0l1306/src/bin/wwdt.rs new file mode 100644 index 000000000..f2bbe5701 --- /dev/null +++ b/examples/mspm0l1306/src/bin/wwdt.rs @@ -0,0 +1,54 @@ +//! Example of using window watchdog timer in the MSPM0L1306 chip. +//! +//! It tests the use case when watchdog timer is expired and when watchdog is pet too early. + +#![no_std] +#![no_main] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_mspm0::gpio::{Level, Output}; +use embassy_mspm0::watchdog::{ClosedWindowPercentage, Config, Timeout, Watchdog}; +use embassy_time::Timer; +use {defmt_rtt as _, panic_halt as _}; + +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { + info!("Hello world!"); + + let p = embassy_mspm0::init(Default::default()); + let mut conf = Config::default(); + conf.timeout = Timeout::Sec1; + + // watchdog also resets the system if the pet comes too early, + // less than 250 msec == 25% from 1 sec + conf.closed_window = ClosedWindowPercentage::TwentyFive; + let mut wdt = Watchdog::new(p.WWDT0, conf); + info!("Started the watchdog timer"); + + let mut led1 = Output::new(p.PA0, Level::High); + led1.set_inversion(true); + Timer::after_millis(900).await; + + for _ in 1..=5 { + info!("pet watchdog"); + led1.toggle(); + wdt.pet(); + Timer::after_millis(500).await; + } + + // watchdog timeout test + info!("Stopped the pet command, device will reset in less than 1 second"); + loop { + led1.toggle(); + Timer::after_millis(500).await; + } + + // watchdog "too early" test + // info!("Device will reset when the pet comes too early"); + // loop { + // led1.toggle(); + // wdt.pet(); + // Timer::after_millis(200).await; + // } +} -- cgit From 2eb643bac66844dccddc11065c3debbaef468595 Mon Sep 17 00:00:00 2001 From: Siarhei B Date: Tue, 26 Aug 2025 08:19:12 +0200 Subject: mspm0-watchdog: rename mod watchdog to wwdt --- examples/mspm0l1306/src/bin/wwdt.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'examples/mspm0l1306/src') diff --git a/examples/mspm0l1306/src/bin/wwdt.rs b/examples/mspm0l1306/src/bin/wwdt.rs index f2bbe5701..b8fb1a1cd 100644 --- a/examples/mspm0l1306/src/bin/wwdt.rs +++ b/examples/mspm0l1306/src/bin/wwdt.rs @@ -8,7 +8,7 @@ use defmt::*; use embassy_executor::Spawner; use embassy_mspm0::gpio::{Level, Output}; -use embassy_mspm0::watchdog::{ClosedWindowPercentage, Config, Timeout, Watchdog}; +use embassy_mspm0::wwdt::{ClosedWindowPercentage, Config, Timeout, Watchdog}; use embassy_time::Timer; use {defmt_rtt as _, panic_halt as _}; -- cgit From bbcaab13bc074d8223b43d8e05682b708c192d78 Mon Sep 17 00:00:00 2001 From: crispaudio Date: Mon, 8 Sep 2025 09:10:16 +0200 Subject: mspm0-adc: add adc with examples --- examples/mspm0l1306/src/bin/adc.rs | 48 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 examples/mspm0l1306/src/bin/adc.rs (limited to 'examples/mspm0l1306/src') diff --git a/examples/mspm0l1306/src/bin/adc.rs b/examples/mspm0l1306/src/bin/adc.rs new file mode 100644 index 000000000..9ede31fed --- /dev/null +++ b/examples/mspm0l1306/src/bin/adc.rs @@ -0,0 +1,48 @@ +#![no_std] +#![no_main] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_mspm0::adc::{self, Adc, AdcChannel, AdcConfig, Resolution, Vrsel}; +use embassy_mspm0::{bind_interrupts, peripherals, Config}; +use embassy_time::Timer; +use {defmt_rtt as _, panic_halt as _}; + +bind_interrupts!(struct Irqs { + ADC0 => adc::InterruptHandler; +}); + +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { + info!("Hello world!"); + let p = embassy_mspm0::init(Config::default()); + + let adc_config = AdcConfig { + resolution: Resolution::BIT12, + vr_select: Vrsel::VddaVssa, + sample_time: 50, + }; + + // Configure adc with sequence 0 to 1 + let mut adc = Adc::new_async(p.ADC0, adc_config, Irqs); + let pin1 = p.PA22.degrade_adc(); + let pin2 = p.PA20.degrade_adc(); + let sequence = [(&pin1, Vrsel::VddaVssa), (&pin2, Vrsel::VddaVssa)]; + let mut readings = [0u16; 2]; + let mut pin3 = p.PA27; + + loop { + let r = adc.read_channel(&mut pin3).await; + info!("Raw adc PA27: {}", r); + // With a voltage range of 0-3.3V and a resolution of 12 bits, the raw value can be + // approximated to voltage (~0.0008 per step). + let mut x = r as u32; + x = x * 8; + info!("Adc voltage PA27: {},{:#04}", x / 10_000, x % 10_000); + // Read a sequence of channels + adc.read_sequence(sequence.into_iter(), &mut readings).await; + info!("Raw adc sequence: {}", readings); + + Timer::after_millis(400).await; + } +} -- cgit From 7b9fe7e6398a8bce236da904b251b4cb424150fb Mon Sep 17 00:00:00 2001 From: crispaudio Date: Tue, 9 Sep 2025 22:21:10 +0200 Subject: mspm0-adc: remove dynamic vrsel and cleanup --- examples/mspm0l1306/src/bin/adc.rs | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'examples/mspm0l1306/src') diff --git a/examples/mspm0l1306/src/bin/adc.rs b/examples/mspm0l1306/src/bin/adc.rs index 9ede31fed..a0c2c0cff 100644 --- a/examples/mspm0l1306/src/bin/adc.rs +++ b/examples/mspm0l1306/src/bin/adc.rs @@ -3,7 +3,7 @@ use defmt::*; use embassy_executor::Spawner; -use embassy_mspm0::adc::{self, Adc, AdcChannel, AdcConfig, Resolution, Vrsel}; +use embassy_mspm0::adc::{self, Adc, AdcChannel, Vrsel}; use embassy_mspm0::{bind_interrupts, peripherals, Config}; use embassy_time::Timer; use {defmt_rtt as _, panic_halt as _}; @@ -17,14 +17,8 @@ async fn main(_spawner: Spawner) -> ! { info!("Hello world!"); let p = embassy_mspm0::init(Config::default()); - let adc_config = AdcConfig { - resolution: Resolution::BIT12, - vr_select: Vrsel::VddaVssa, - sample_time: 50, - }; - // Configure adc with sequence 0 to 1 - let mut adc = Adc::new_async(p.ADC0, adc_config, Irqs); + let mut adc = Adc::new_async(p.ADC0, Default::default(), Irqs); let pin1 = p.PA22.degrade_adc(); let pin2 = p.PA20.degrade_adc(); let sequence = [(&pin1, Vrsel::VddaVssa), (&pin2, Vrsel::VddaVssa)]; -- cgit From 31b5a3f0a4fafd425aef34b9d6fb93ead851b4c6 Mon Sep 17 00:00:00 2001 From: crispaudio Date: Sun, 14 Sep 2025 01:34:49 +0200 Subject: mspm0-adc: implement From for AnyAdcChannel --- examples/mspm0l1306/src/bin/adc.rs | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'examples/mspm0l1306/src') diff --git a/examples/mspm0l1306/src/bin/adc.rs b/examples/mspm0l1306/src/bin/adc.rs index a0c2c0cff..2806b98cc 100644 --- a/examples/mspm0l1306/src/bin/adc.rs +++ b/examples/mspm0l1306/src/bin/adc.rs @@ -3,7 +3,7 @@ use defmt::*; use embassy_executor::Spawner; -use embassy_mspm0::adc::{self, Adc, AdcChannel, Vrsel}; +use embassy_mspm0::adc::{self, Adc, Vrsel}; use embassy_mspm0::{bind_interrupts, peripherals, Config}; use embassy_time::Timer; use {defmt_rtt as _, panic_halt as _}; @@ -19,14 +19,11 @@ async fn main(_spawner: Spawner) -> ! { // Configure adc with sequence 0 to 1 let mut adc = Adc::new_async(p.ADC0, Default::default(), Irqs); - let pin1 = p.PA22.degrade_adc(); - let pin2 = p.PA20.degrade_adc(); - let sequence = [(&pin1, Vrsel::VddaVssa), (&pin2, Vrsel::VddaVssa)]; + let sequence = [(&p.PA22.into(), Vrsel::VddaVssa), (&p.PA20.into(), Vrsel::VddaVssa)]; let mut readings = [0u16; 2]; - let mut pin3 = p.PA27; loop { - let r = adc.read_channel(&mut pin3).await; + let r = adc.read_channel(&p.PA27).await; info!("Raw adc PA27: {}", r); // With a voltage range of 0-3.3V and a resolution of 12 bits, the raw value can be // approximated to voltage (~0.0008 per step). -- cgit From 8730a013c395cf0bf4c2fa8eeb7f138288103039 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 6 Oct 2025 22:56:31 +0200 Subject: Rustfmt for edition 2024. --- examples/mspm0l1306/src/bin/adc.rs | 2 +- examples/mspm0l1306/src/bin/blinky.rs | 2 +- examples/mspm0l1306/src/bin/button.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'examples/mspm0l1306/src') diff --git a/examples/mspm0l1306/src/bin/adc.rs b/examples/mspm0l1306/src/bin/adc.rs index 2806b98cc..235396b8a 100644 --- a/examples/mspm0l1306/src/bin/adc.rs +++ b/examples/mspm0l1306/src/bin/adc.rs @@ -4,7 +4,7 @@ use defmt::*; use embassy_executor::Spawner; use embassy_mspm0::adc::{self, Adc, Vrsel}; -use embassy_mspm0::{bind_interrupts, peripherals, Config}; +use embassy_mspm0::{Config, bind_interrupts, peripherals}; use embassy_time::Timer; use {defmt_rtt as _, panic_halt as _}; diff --git a/examples/mspm0l1306/src/bin/blinky.rs b/examples/mspm0l1306/src/bin/blinky.rs index 055a5cd81..47eaf1535 100644 --- a/examples/mspm0l1306/src/bin/blinky.rs +++ b/examples/mspm0l1306/src/bin/blinky.rs @@ -3,8 +3,8 @@ use defmt::*; use embassy_executor::Spawner; -use embassy_mspm0::gpio::{Level, Output}; use embassy_mspm0::Config; +use embassy_mspm0::gpio::{Level, Output}; use embassy_time::Timer; use {defmt_rtt as _, panic_halt as _}; diff --git a/examples/mspm0l1306/src/bin/button.rs b/examples/mspm0l1306/src/bin/button.rs index d8c85947f..33e682272 100644 --- a/examples/mspm0l1306/src/bin/button.rs +++ b/examples/mspm0l1306/src/bin/button.rs @@ -3,8 +3,8 @@ use defmt::*; use embassy_executor::Spawner; -use embassy_mspm0::gpio::{Input, Level, Output, Pull}; use embassy_mspm0::Config; +use embassy_mspm0::gpio::{Input, Level, Output, Pull}; use {defmt_rtt as _, panic_halt as _}; #[embassy_executor::main] -- cgit From 7797cc0effa069b78be29ff19b81068b17f98ac2 Mon Sep 17 00:00:00 2001 From: Iooon Date: Wed, 1 Oct 2025 11:00:44 +0200 Subject: mspm0-i2c-target: add mspm0l1306 example and set target address explicitly in examples --- examples/mspm0l1306/src/bin/i2c_target.rs | 61 +++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 examples/mspm0l1306/src/bin/i2c_target.rs (limited to 'examples/mspm0l1306/src') diff --git a/examples/mspm0l1306/src/bin/i2c_target.rs b/examples/mspm0l1306/src/bin/i2c_target.rs new file mode 100644 index 000000000..38d309e6b --- /dev/null +++ b/examples/mspm0l1306/src/bin/i2c_target.rs @@ -0,0 +1,61 @@ +//! Example of using async I2C target +//! +//! This uses the virtual COM port provided on the LP-MSPM0L1306 board. + +#![no_std] +#![no_main] + +use defmt::*; +use embassy_executor::Spawner; +use embassy_mspm0::i2c_target::{Command, I2cTarget, ReadStatus}; +use embassy_mspm0::peripherals::I2C0; +use embassy_mspm0::{bind_interrupts, i2c}; +use {defmt_rtt as _, panic_halt as _}; + +bind_interrupts!(struct Irqs { + I2C0 => i2c::InterruptHandler; +}); + +#[embassy_executor::main] +async fn main(_spawner: Spawner) -> ! { + let p = embassy_mspm0::init(Default::default()); + + let instance = p.I2C0; + let scl = p.PA1; + let sda = p.PA0; + + let mut config = i2c::Config::default(); + config.target_addr = 0x48; + config.general_call = true; + let mut i2c = I2cTarget::new(instance, scl, sda, Irqs, config).unwrap(); + + let mut read = [0u8; 8]; + let data = [8u8; 2]; + let data_wr = [9u8; 2]; + + loop { + match i2c.listen(&mut read).await { + Ok(Command::GeneralCall(_)) => info!("General call received"), + Ok(Command::Read) => { + info!("Read command received"); + match i2c.respond_to_read(&data).await.unwrap() { + ReadStatus::Done => info!("Finished reading"), + ReadStatus::NeedMoreBytes => { + info!("Read needs more bytes - will reset"); + i2c.reset().unwrap(); + } + ReadStatus::LeftoverBytes(_) => { + info!("Leftover bytes received"); + i2c.flush_tx_fifo(); + } + } + } + Ok(Command::Write(_)) => info!("Write command received"), + Ok(Command::WriteRead(_)) => { + info!("Write-Read command received"); + i2c.respond_and_fill(&data_wr, 0xFE).await.unwrap(); + } + Err(e) => info!("Got error {}", e), + } + } +} -- cgit From 4217a264dba3a77da38897537f90e1fdfe5b9ddb Mon Sep 17 00:00:00 2001 From: crispaudio Date: Mon, 6 Oct 2025 10:06:28 +0200 Subject: mspm0-i2c-target: update examples with split config --- examples/mspm0l1306/src/bin/i2c_target.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'examples/mspm0l1306/src') diff --git a/examples/mspm0l1306/src/bin/i2c_target.rs b/examples/mspm0l1306/src/bin/i2c_target.rs index 38d309e6b..4d147d08b 100644 --- a/examples/mspm0l1306/src/bin/i2c_target.rs +++ b/examples/mspm0l1306/src/bin/i2c_target.rs @@ -7,7 +7,8 @@ use defmt::*; use embassy_executor::Spawner; -use embassy_mspm0::i2c_target::{Command, I2cTarget, ReadStatus}; +use embassy_mspm0::i2c::Config; +use embassy_mspm0::i2c_target::{Command, Config as TargetConfig, I2cTarget, ReadStatus}; use embassy_mspm0::peripherals::I2C0; use embassy_mspm0::{bind_interrupts, i2c}; use {defmt_rtt as _, panic_halt as _}; @@ -24,10 +25,11 @@ async fn main(_spawner: Spawner) -> ! { let scl = p.PA1; let sda = p.PA0; - let mut config = i2c::Config::default(); - config.target_addr = 0x48; - config.general_call = true; - let mut i2c = I2cTarget::new(instance, scl, sda, Irqs, config).unwrap(); + let config = Config::default(); + let mut target_config = TargetConfig::default(); + target_config.target_addr = 0x48; + target_config.general_call = true; + let mut i2c = I2cTarget::new(instance, scl, sda, Irqs, config, target_config).unwrap(); let mut read = [0u8; 8]; let data = [8u8; 2]; -- cgit