Skip to content
Snippets Groups Projects
Commit cd30b9c4 authored by Andrei-Cristian NEAGU's avatar Andrei-Cristian NEAGU
Browse files

changed the provided display driver (the original one didint run) and modified...

changed the provided display driver (the original one didint run) and modified typo in embedded-hal crate import
parent ce96a3c5
No related branches found
No related tags found
No related merge requests found
Pipeline #109610 passed
...@@ -399,36 +399,84 @@ spi.transfer(&mut rx_buf, &tx_buf).await; ...@@ -399,36 +399,84 @@ spi.transfer(&mut rx_buf, &tx_buf).await;
The **ST7735** features a **128x160** screen and an integrated **SD card reader**. For now, we will ignore the SD card reader and focus on the screen. The **ST7735** features a **128x160** screen and an integrated **SD card reader**. For now, we will ignore the SD card reader and focus on the screen.
Because writing an SPI driver for the ST7735 would be out of the scope of the lab, we will be using the one provided by the **mipidsi** crate. Because writing an SPI driver for the ST7735 would be out of the scope of the lab, we will be using the one provided by the **st7735-lcd** crate.
```rust ```rust
use embassy_embedded_hal::shared_bus::blocking::spi::SpiDevice; use embassy_executor::Spawner;
use embassy_sync::blocking_mutex::{Mutex, raw::NoopRawMutex}; use embassy_rp::{gpio::{Level, Output}, peripherals::{SPI0, SPI1}, spi::{Blocking, Config as ConfigSpi, Spi}};
use embassy_time::Delay; use embassy_time::Delay;
use display_interface_spi::SPIInterface; use embassy_sync::blocking_mutex::NoopMutex;
use mipidsi::models::ST7735s; use embassy_embedded_hal::shared_bus::blocking::spi::SpiDevice;
use mipidsi::options::{Orientation, Rotation}; use defmt::info;
// Add this code to Cargo.toml (modified version of st7735-lcd-rs crate)
let mut screen_config = embassy_rp::spi::Config::default(); // [dependencies]
screen_config.frequency = 32_000_000u32; // st7735-lcd = { version = "0.10.1", git = "https://github.com/mohgTheOmen/st7735-lcd-rs", branch = "master" }
screen_config.phase = embassy_rp::spi::Phase::CaptureOnSecondTransition; // static_cell = "1.2"
screen_config.polarity = embassy_rp::spi::Polarity::IdleHigh; //
// [dependencies.embedded-graphics]
let screen_rst = Output::new(p.PIN_X, Level::Low); // version = "0.7"
let screen_dc = Output::new(p.PIN_Y, Level::Low); // optional = true
let screen_cs = Output::new(p.PIN_Z, Level::High); //
// [features]
let spi = Spi::new_blocking(p.SPI0, clk, mosi, miso, screen_config); // default = ["graphics"]
let spi_bus: Mutex<NoopRawMutex, _> = Mutex::new(RefCell::new(spi)); // graphics = ["embedded-graphics"]
let display_spi = SpiDevice::new(&spi_bus, screen_cs);
use st7735_lcd::{Orientation, ST7735};
let di = SPIInterface::new(display_spi, screen_dc); use core::cell::RefCell;
let mut screen = mipidsi::Builder::new(ST7735s, di) use static_cell::StaticCell;
.reset_pin(screen_rst) use embedded_graphics::{mono_font::{ascii::FONT_6X10, MonoTextStyle}, pixelcolor::Rgb565, prelude::*, text::Text};
.orientation(Orientation::new().rotate(Rotation::Deg180)) use {defmt_rtt as _, panic_probe as _};
.init(&mut Delay)
.unwrap(); // static SPI_BUS: StaticCell<NoopMutex<RefCell<Spi<'static, SPI0, Blocking>>>> = StaticCell::new(); // for borrowing to a task
// #[embassy_executor::task]
// async fn dispay_task(
// spi_bus: &'static NoopMutex<RefCell<Spi<'static, SPI0, Blocking>>>
// // other parameters
// ) {
// let spi_dev = SpiDevice::new(spi_bus, cs);
//
// // code in the task
// }
#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_rp::init(Default::default());
let mut spiconfig1 = ConfigSpi::default();
spiconfig1.frequency = 32_000_000;
let miso1 = p.PIN_16;
let mosi1 = p.PIN_19;
let clk1 = p.PIN_18;
let mut spi1 = Spi::new_blocking(p.SPI0, clk1, mosi1, miso1, spiconfig1);
let spi_bus = NoopMutex::new(RefCell::new(spi1));
// let spi_bus = SPI_BUS.init(spi_bus); // for sending to task
let mut cs = Output::new(p.PIN_17, Level::High);
let mut dc = Output::new(p.PIN_20, Level::Low);
let mut reset = Output::new(p.PIN_21, Level::High);
let spi_dev = SpiDevice::new(&spi_bus, cs);
let mut display = ST7735::new(spi_dev, dc, core::prelude::v1::Some(reset), Default::default(), false, 128, 160);
let mut delay = Delay;
display.init(&mut delay).unwrap();
display.set_orientation(&Orientation::Portrait).unwrap();
display.clear(Rgb565::BLACK).unwrap();
let text_style = MonoTextStyle::new(&FONT_6X10, Rgb565::RED);
Text::new("Hello, World!", Point::new(20, 50), text_style)
.draw(&mut display)
.unwrap();
info!("Display initialized and text written.");
}
``` ```
Make sure to wire the pins on **J9** according to the pins chosen in the code and the picture below. Make sure to wire the pins on **J9** according to the pins chosen in the code and the picture below.
...@@ -437,7 +485,7 @@ Make sure to wire the pins on **J9** according to the pins chosen in the code an ...@@ -437,7 +485,7 @@ Make sure to wire the pins on **J9** according to the pins chosen in the code an
### Embedded Graphics ### Embedded Graphics
Because **mipidsi** only provides a very primitive way to draw on the screen, by setting individual pixels, we will be using the **embedded_graphics** framework. This library enables us to do more complex things, such as rendering image files, drawing shapes and displaying text. Because **st7735-lcd** only provides a very primitive way to draw on the screen, by setting individual pixels, we will be using the **embedded_graphics** framework. This library enables us to do more complex things, such as rendering image files, drawing shapes and displaying text.
```rust ```rust
use embedded_graphics::{ use embedded_graphics::{
...@@ -504,7 +552,7 @@ For this, we will need to initialize the sensor to use the same SPI bus as the s ...@@ -504,7 +552,7 @@ For this, we will need to initialize the sensor to use the same SPI bus as the s
```rust ```rust
// Import the Trait in order to be able to use imu_spi.transfer() // Import the Trait in order to be able to use imu_spi.transfer()
use embedded_hal_1::spi::SpiDevice as _; use embedded_hal::spi::SpiDevice as _;
let mut imu_spi = SpiDeviceWithConfig::new(&spi_bus, imu_cs, imu_config); let mut imu_spi = SpiDeviceWithConfig::new(&spi_bus, imu_cs, imu_config);
// Note: you no longer need to manually set the chip select pin when using imu_spi.transfer() // Note: you no longer need to manually set the chip select pin when using imu_spi.transfer()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment