Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Feature/spi display #117

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions esp32s2-hal/.cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,25 @@ runner = "espflash --monitor"

[build]
rustflags = [
"-C", "link-arg=-nostartfiles",
"-C", "link-arg=-Wl,-Tlinkall.x",
# Enable the atomic codegen option for Xtensa
"-C",
"target-feature=+s32c1i",

# Tell the `core` library that we have atomics, even though it's not
# specified in the target definition
"--cfg",
'target_has_atomic="8"',
"--cfg",
'target_has_atomic="16"',
"--cfg",
'target_has_atomic="32"',
"--cfg",
'target_has_atomic="ptr"',

"-C",
"link-arg=-nostartfiles",
"-C",
"link-arg=-Wl,-Tlinkall.x",
]
target = "xtensa-esp32s2-none-elf"

Expand Down
64 changes: 33 additions & 31 deletions esp32s2-hal/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,53 +1,55 @@
[package]
name = "esp32s2-hal"
name = "esp32s2-hal"
version = "0.1.0"
authors = [
"Jesse Braham <[email protected]>",
"Björn Quentin <[email protected]>",
]
edition = "2021"
edition = "2021"
description = "HAL for ESP32-S2 microcontrollers"
repository = "https://github.com/esp-rs/esp-hal"
license = "MIT OR Apache-2.0"
repository = "https://github.com/esp-rs/esp-hal"
license = "MIT OR Apache-2.0"

keywords = [
"embedded",
"embedded-hal",
"esp",
"esp32s2",
"no-std",
]
categories = [
"embedded",
"hardware-support",
"no-std",
]
keywords = ["embedded", "embedded-hal", "esp", "esp32s2", "no-std"]
categories = ["embedded", "hardware-support", "no-std"]

[dependencies]
bare-metal = "1.0"
embedded-hal = { version = "0.2", features = ["unproven"] }
bare-metal = "1.0"
embedded-hal = { version = "0.2", features = ["unproven"] }
embedded-hal-1 = { package = "embedded-hal", version = "=1.0.0-alpha.8" }
xtensa-lx = { version = "0.7", features = ["esp32s2"] }
xtensa-lx-rt = { version = "0.13", features = ["esp32s2"], optional = true }
xtensa-lx = { version = "0.7", features = ["esp32s2"] }
xtensa-lx-rt = { version = "0.13", features = ["esp32s2"], optional = true }

# ESP32-S2 SPI Example
st7789 = "0.6"
display-interface = "0.4"
display-interface-spi = "0.4"
esp-backtrace = { git = "https://github.com/esp-rs/esp-backtrace", features = [
"esp32s2",
"panic-handler",
"print-uart",
] }
xtensa-atomic-emulation-trap = "0.1.0"
embedded-graphics = "0.7"

[dependencies.esp-hal-common]
path = "../esp-hal-common"
path = "../esp-hal-common"
features = ["esp32s2"]

[dev-dependencies]
embedded-graphics = "0.7"
panic-halt = "0.2"
ssd1306 = "0.7"
smart-leds = "0.3"
esp-println = { version = "0.2.0", features = ["esp32s2"] }
panic-halt = "0.2"
ssd1306 = "0.7"
smart-leds = "0.3"
esp-println = { version = "0.2.0", features = ["esp32s2"] }

[features]
default = ["rt"]
eh1 = ["esp-hal-common/eh1"]
rt = ["xtensa-lx-rt/esp32s2"]
smartled = ["esp-hal-common/smartled"]
ufmt = ["esp-hal-common/ufmt"]
default = ["rt"]
eh1 = ["esp-hal-common/eh1"]
rt = ["xtensa-lx-rt/esp32s2"]
smartled = ["esp-hal-common/smartled"]
ufmt = ["esp-hal-common/ufmt"]

[[example]]
name = "hello_rgb"
name = "hello_rgb"
required-features = ["smartled"]
99 changes: 99 additions & 0 deletions esp32s2-hal/examples/spi_display.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
#![no_std]
#![no_main]

use display_interface_spi::SPIInterfaceNoCS;
use embedded_graphics::{
draw_target::DrawTarget,
prelude::RgbColor,
mono_font::{
ascii::{FONT_8X13, FONT_9X18_BOLD},
MonoTextStyle,
},
prelude::Point,
text::Text,
Drawable,
};
use esp_println::println;
use esp32s2_hal::{
clock::ClockControl,
pac::Peripherals,
prelude::*,
spi,
timer::TimerGroup,
RtcCntl,
IO,
Delay
};
use panic_halt as _;
use xtensa_lx_rt::entry;

#[entry]
fn main() -> ! {
let peripherals = Peripherals::take().unwrap();
let mut system = peripherals.SYSTEM.split();
let mut clocks = ClockControl::boot_defaults(system.clock_control).freeze();

// Disable the RTC and TIMG watchdog timers
let mut rtc_cntl = RtcCntl::new(peripherals.RTC_CNTL);
let timer_group0 = TimerGroup::new(peripherals.TIMG0, &clocks);
let mut wdt0 = timer_group0.wdt;
let timer_group1 = TimerGroup::new(peripherals.TIMG1, &clocks);
let mut wdt1 = timer_group1.wdt;

rtc_cntl.set_wdt_global_enable(false);
wdt0.disable();
wdt1.disable();

println!("About to initialize the SPI LED driver ST7789VW");
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
let backlight = io.pins.gpio9;
let mut backlight = backlight.into_push_pull_output();
backlight.set_high().unwrap();

let mosi = io.pins.gpio7;
let cs = io.pins.gpio5;
let rst = io.pins.gpio8;
let dc = io.pins.gpio4;
let sck = io.pins.gpio6;
let miso = io.pins.gpio12;

let spi = spi::Spi::new(
peripherals.SPI3,
sck,
mosi,
Some(miso),
Some(cs),
80u32.kHz(),
spi::SpiMode::Mode0,
&mut system.peripheral_clock_control,
&mut clocks,
);

let di = SPIInterfaceNoCS::new(spi, dc.into_push_pull_output());
let reset = rst.into_push_pull_output();
let mut display = st7789::ST7789::new(di, reset, 240, 240);
let mut delay = Delay::new(&clocks);

display.init(&mut delay).unwrap();
display.set_orientation(st7789::Orientation::Landscape).unwrap();
display.clear(RgbColor::WHITE).unwrap();
println!("Initialized");

Text::new(
"Hello from",
Point::new(80, 110),
MonoTextStyle::new(&FONT_8X13, RgbColor::BLACK),
)
.draw(&mut display)
.unwrap();

Text::new(
"ESP-RS",
Point::new(90, 140),
MonoTextStyle::new(&FONT_9X18_BOLD, RgbColor::RED),
)
.draw(&mut display)
.unwrap();

loop {}
}