From 7a7ce13365e9e339dd5dd712d2c03d908e0dce8b Mon Sep 17 00:00:00 2001 From: "Sebastian H. Gabrielli" Date: Fri, 20 Dec 2024 17:47:22 +0100 Subject: [PATCH] It compiles! --- Cargo.toml | 3 ++- src/main.rs | 50 ++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 97112fb..c792b98 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ embassy-sync = { version = "0.6" } embassy-time = { version = "0.3", features = ["defmt", "defmt-timestamp-uptime"] } #embassy-net-nrf91 = { version = "0.1.0", features = ["defmt"] } embassy-net = { version = "0.5.0", features = ["defmt", "tcp", "proto-ipv4", "medium-ip"] } +embassy-embedded-hal = "0.2" cortex-m = { version = "0.7.6", features = ["critical-section-single-core", "inline-asm"] } embassy-nrf = { version = "0.2", features = ["defmt", "nrf9160-s", "time-driver-rtc1", "gpiote", "unstable-pac", "time"] } @@ -35,4 +36,4 @@ ili9341 = "0.6.0" display-interface-spi = "0.5.0" [profile.release] -debug = 2 \ No newline at end of file +debug = 2 diff --git a/src/main.rs b/src/main.rs index 4f8a3cf..47f63b1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,18 +1,30 @@ #![no_std] #![no_main] +use core::cell::RefCell; +use defmt::info; use display_interface_spi::SPIInterface; +use embassy_embedded_hal::shared_bus::blocking::spi::SpiDevice; use embassy_executor::Spawner; -use embassy_nrf::{bind_interrupts, gpio::{Level, Output, OutputDrive}, peripherals, spim}; +use embassy_nrf::{ + bind_interrupts, + gpio::{Level, Output, OutputDrive}, + peripherals, + spim::{self, Spim}, +}; +use embassy_sync::blocking_mutex::Mutex; use embassy_time::Timer; use ili9341::Ili9341; use {defmt_rtt as _, panic_probe as _}; -use defmt::info; use embedded_graphics::{ - mono_font::{ascii::FONT_6X10, MonoTextStyle}, pixelcolor::{BinaryColor, Rgb565}, prelude::*, primitives::{ + mono_font::{ascii::FONT_6X10, MonoTextStyle}, + pixelcolor::{BinaryColor, Rgb565}, + prelude::*, + primitives::{ Circle, PrimitiveStyle, PrimitiveStyleBuilder, Rectangle, StrokeAlignment, Triangle, - }, text::{Alignment, Text} + }, + text::{Alignment, Text}, }; // Setup interrupts @@ -35,19 +47,37 @@ async fn main(_spawner: Spawner) { let mut spim_config = spim::Config::default(); spim_config.frequency = spim::Frequency::M8; - // Create a new SPI interface on the nrf - let spi = embassy_nrf::spim::Spim::new(p.SERIAL3, Irqs, sck, miso, mosi, spim_config); + /////////////////////////////////////////// + // 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 = + Mutex::new(RefCell::new(spim)); + + // 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 chip_select = Output::new(p.P0_08, Level::Low, OutputDrive::Standard); - let iface = SPIInterface::new(spi, direction_control); + 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_orientation = ili9341::Orientation::Landscape; let display_size = ili9341::DisplaySize240x320; - let mut display = Ili9341::new(iface, display_reset, &mut embassy_time::Delay, display_orientation, display_size).unwrap(); + let mut display = Ili9341::new( + iface, + display_reset, + &mut embassy_time::Delay, + display_orientation, + display_size, + ) + .unwrap(); display.clear(Rgb565::RED).unwrap(); @@ -109,4 +139,4 @@ async fn main(_spawner: Spawner) { led.set_low(); Timer::after_millis(300).await; } -} \ No newline at end of file +}