Skip to content

Commit

Permalink
fix: all demo use new spi api
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed May 2, 2024
1 parent 4ea8a4c commit 7fc7049
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 244 deletions.
7 changes: 3 additions & 4 deletions examples/ch32v003/src/bin/spi-lcd-st7735-cube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
use core::fmt::Write;

use ch32_hal as hal;
use embedded_graphics::pixelcolor::raw::ToBytes;
Expand Down Expand Up @@ -62,15 +61,15 @@ pub enum Instruction {
}

pub struct ST7735<const WIDTH: u16, const HEIGHT: u16, const OFFSETX: u16, const OFFSETY: u16> {
spi: Spi<'static, peripherals::SPI1, NoDma, NoDma>,
spi: Spi<'static, peripherals::SPI1, hal::mode::Blocking>,
dc: Output<'static>,
// _marker: core::marker::PhantomData<(OFFSETX, OFFSETY)>,
}

impl<const WIDTH: u16, const HEIGHT: u16, const OFFSETX: u16, const OFFSETY: u16>
ST7735<WIDTH, HEIGHT, OFFSETX, OFFSETY>
{
pub fn new(spi: Spi<'static, peripherals::SPI1, NoDma, NoDma>, dc: Output<'static>) -> Self {
pub fn new(spi: Spi<'static, peripherals::SPI1, hal::mode::Blocking>, dc: Output<'static>) -> Self {
Self {
spi,
dc,
Expand Down Expand Up @@ -265,7 +264,7 @@ fn main() -> ! {
spi_config.frequency = Hertz::mhz(1);

// Remap 0
let spi = Spi::new_txonly::<0>(p.SPI1, sck, sda, NoDma, NoDma, spi_config);
let spi = Spi::new_blocking_txonly::<0>(p.SPI1, sck, sda, spi_config);

rst.set_low();
// Timer::after_millis(120).await;
Expand Down
6 changes: 3 additions & 3 deletions examples/ch32v203/src/bin/spi-lcd-st7735.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,15 @@ pub enum Instruction {
}

pub struct ST7735<const WIDTH: u16, const HEIGHT: u16, const OFFSETX: u16, const OFFSETY: u16> {
spi: Spi<'static, peripherals::SPI1, NoDma, NoDma>,
spi: Spi<'static, peripherals::SPI1, hal::mode::Blocking>,
dc: Output<'static>,
// _marker: core::marker::PhantomData<(OFFSETX, OFFSETY)>,
}

impl<const WIDTH: u16, const HEIGHT: u16, const OFFSETX: u16, const OFFSETY: u16>
ST7735<WIDTH, HEIGHT, OFFSETX, OFFSETY>
{
pub fn new(spi: Spi<'static, peripherals::SPI1, NoDma, NoDma>, dc: Output<'static>) -> Self {
pub fn new(spi: Spi<'static, peripherals::SPI1, hal::mode::Blocking>, dc: Output<'static>) -> Self {
Self {
spi,
dc,
Expand Down Expand Up @@ -281,7 +281,7 @@ async fn main(spawner: Spawner) -> ! {
let mut spi_config = hal::spi::Config::default();
spi_config.frequency = Hertz::mhz(24);

let spi = Spi::new_txonly(p.SPI1, sck, sda, NoDma, NoDma, spi_config);
let spi = Spi::new_blocking_txonly(p.SPI1, sck, sda, spi_config);

rst.set_low();
Timer::after_millis(120).await;
Expand Down
6 changes: 3 additions & 3 deletions examples/ch32v305/src/bin/spi-lcd-st7735-cube.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ pub enum Instruction {
}

pub struct ST7735<const WIDTH: u16, const HEIGHT: u16, const OFFSETX: u16, const OFFSETY: u16> {
spi: Spi<'static, peripherals::SPI2, NoDma, NoDma>,
spi: Spi<'static, peripherals::SPI2, hal::mode::Blocking>,
dc: Output<'static>,
// _marker: core::marker::PhantomData<(OFFSETX, OFFSETY)>,
}

impl<const WIDTH: u16, const HEIGHT: u16, const OFFSETX: u16, const OFFSETY: u16>
ST7735<WIDTH, HEIGHT, OFFSETX, OFFSETY>
{
pub fn new(spi: Spi<'static, peripherals::SPI2, NoDma, NoDma>, dc: Output<'static>) -> Self {
pub fn new(spi: Spi<'static, peripherals::SPI2, hal::mode::Blocking>, dc: Output<'static>) -> Self {
Self {
spi,
dc,
Expand Down Expand Up @@ -309,7 +309,7 @@ async fn main(_spawner: Spawner) -> ! {
let mut spi_config = hal::spi::Config::default();
spi_config.frequency = Hertz::mhz(24);

let spi = Spi::new_txonly(p.SPI2, sck, mosi, NoDma, NoDma, spi_config);
let spi = Spi::new_blocking_txonly(p.SPI2, sck, mosi, spi_config);

rst.set_low();
Timer::after_millis(120).await;
Expand Down
3 changes: 1 addition & 2 deletions examples/ch32v307/src/bin/spi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![no_main]
#![feature(type_alias_impl_trait)]

use ch32_hal::dma::NoDma;
use ch32_hal::spi;
use embassy_executor::Spawner;
use embassy_time::{Duration, Timer};
Expand Down Expand Up @@ -35,7 +34,7 @@ async fn main(spawner: Spawner) -> ! {

let mut spi_config = spi::Config::default();
spi_config.frequency = Hertz::khz(375);
let mut spi = spi::Spi::new(p.SPI1, sck, mosi, miso, NoDma, NoDma, spi_config);
let mut spi = spi::Spi::new_blocking(p.SPI1, sck, mosi, miso, spi_config);

loop {
Timer::after_millis(2000).await;
Expand Down
7 changes: 3 additions & 4 deletions examples/ch32x035/src/bin/spi-lcd-st7735.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use embedded_graphics::prelude::*;
use embedded_graphics::primitives::{Line, PrimitiveStyle};
use embedded_graphics::text::{Alignment, Text};
use embedded_hal::delay::DelayNs;
use hal::dma::NoDma;
use hal::gpio::{AnyPin, Input, Level, Output, Pin};
use hal::prelude::*;
use hal::spi::Spi;
Expand Down Expand Up @@ -81,15 +80,15 @@ pub enum Instruction {
}

pub struct ST7735<const WIDTH: u16, const HEIGHT: u16, const OFFSETX: u16, const OFFSETY: u16> {
spi: Spi<'static, peripherals::SPI1, NoDma, NoDma>,
spi: Spi<'static, peripherals::SPI1, hal::mode::Blocking>,
dc: Output<'static>,
// _marker: core::marker::PhantomData<(OFFSETX, OFFSETY)>,
}

impl<const WIDTH: u16, const HEIGHT: u16, const OFFSETX: u16, const OFFSETY: u16>
ST7735<WIDTH, HEIGHT, OFFSETX, OFFSETY>
{
pub fn new(spi: Spi<'static, peripherals::SPI1, NoDma, NoDma>, dc: Output<'static>) -> Self {
pub fn new(spi: Spi<'static, peripherals::SPI1, hal::mode::Blocking>, dc: Output<'static>) -> Self {
Self {
spi,
dc,
Expand Down Expand Up @@ -287,7 +286,7 @@ async fn main(spawner: Spawner) -> ! {
let mut spi_config = hal::spi::Config::default();
spi_config.frequency = Hertz::mhz(24);

let spi = Spi::new_txonly(p.SPI1, sck, sda, NoDma, NoDma, spi_config);
let spi = Spi::new_blocking_txonly(p.SPI1, sck, sda, spi_config);

rst.set_low();
Timer::after_millis(120).await;
Expand Down
2 changes: 0 additions & 2 deletions examples/ch32x035/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![no_std]

pub use ch32_hal as hal;

pub mod st7735;
226 changes: 0 additions & 226 deletions examples/ch32x035/src/st7735.rs

This file was deleted.

0 comments on commit 7fc7049

Please sign in to comment.