Add blink task & code verified working

This commit is contained in:
Sebastian H. Gabrielli 2024-12-21 10:30:14 +01:00
parent c1d06806aa
commit 9604e0af66

View File

@ -8,12 +8,13 @@ use embassy_embedded_hal::shared_bus::blocking::spi::SpiDevice;
use embassy_executor::Spawner;
use embassy_nrf::{
bind_interrupts,
gpio::{Level, Output, OutputDrive},
gpio::{AnyPin, Level, Output, OutputDrive, Pin},
peripherals,
spim::{self, Spim},
};
use embassy_sync::blocking_mutex::Mutex;
use embassy_time::Timer;
use embassy_time::{Delay, Duration, Timer};
use embedded_hal::digital::OutputPin;
use ili9341::Ili9341;
use {defmt_rtt as _, panic_probe as _};
@ -33,15 +34,33 @@ bind_interrupts!(struct Irqs {
UARTE3_SPIM3_SPIS3_TWIM3_TWIS3 => embassy_nrf::spim::InterruptHandler<peripherals::SERIAL3>;
});
#[embassy_executor::task]
async fn blink(pin: AnyPin, blink_delay: Duration) -> ! {
let mut led = Output::new(pin, Level::Low, OutputDrive::Standard);
loop {
led.set_high();
Timer::after(blink_delay).await;
led.set_low();
Timer::after(blink_delay).await;
}
}
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
async fn main(spawner: Spawner) {
// Initialize the nRF
let p = embassy_nrf::init(Default::default());
// Get the pins
let mosi = p.P0_31;
let miso = p.P0_30;
let sck = p.P0_20;
let cs_pin = p.P0_13;
// Spawn the blink task
spawner
.spawn(blink(p.P0_02.degrade(), Duration::from_millis(250)))
.expect("Failed to start blink task");
// Get the pins for SPI
let mosi = p.P0_13;
let miso = p.P0_12;
let sck = p.P0_30;
let cs_pin = p.P0_31;
// Create an SPI config
let mut spim_config = spim::Config::default();
@ -51,23 +70,23 @@ async fn main(_spawner: Spawner) {
// Create a new SPI interface on the nrf //
///////////////////////////////////////////
// Setup the chip select as an output pin
let chip_select = Output::new(cs_pin, Level::Low, OutputDrive::Standard);
// Grab the SPI Master mode peripheral form the nRF60
let spim = embassy_nrf::spim::Spim::new(p.SERIAL3, Irqs, sck, miso, mosi, spim_config);
// Use the SPI peripheral to create a shared bus
let spi_bus: Mutex<embassy_sync::blocking_mutex::raw::NoopRawMutex, _> =
Mutex::new(RefCell::new(spim));
// Setup the chip select as an output pin
let chip_select = Output::new(cs_pin, Level::Low, OutputDrive::Standard);
// Use the shared bus to create a SPI Device to use for the display
let spi_display = SpiDevice::new(&spi_bus, chip_select);
// Create a new SPI display interface
let direction_control = Output::new(p.P0_07, Level::High, OutputDrive::Standard);
let direction_control = Output::new(p.P0_20, Level::High, OutputDrive::Standard);
let iface = SPIInterface::new(spi_display, direction_control);
// Create a new display
let display_reset = Output::new(p.P0_12, Level::High, OutputDrive::Standard);
let display_reset = Output::new(p.P0_11, Level::High, OutputDrive::Standard);
let display_orientation = ili9341::Orientation::Landscape;
let display_size = ili9341::DisplaySize240x320;
let mut display = Ili9341::new(
@ -129,7 +148,7 @@ async fn main(_spawner: Spawner) {
// )
// .draw(&mut display).unwrap();
let mut led = Output::new(p.P0_02, Level::Low, OutputDrive::Standard);
let mut led = Output::new(p.P0_03, Level::Low, OutputDrive::Standard);
loop {
info!("Going high!");