-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisplay.rs
More file actions
120 lines (103 loc) · 3.75 KB
/
Copy pathdisplay.rs
File metadata and controls
120 lines (103 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#![no_std]
#![no_main]
#![deny(
clippy::mem_forget,
reason = "mem::forget is generally not safe to do with esp_hal types, especially those \
holding buffers for the duration of a data transfer."
)]
use embedded_hal_bus::spi::ExclusiveDevice;
use esp_hal::clock::CpuClock;
use esp_hal::delay::Delay;
use esp_hal::gpio::Level::{High, Low};
use esp_hal::gpio::{Input, InputConfig, Output, OutputConfig, Pull};
use esp_hal::main;
use esp_hal::spi::master::{Config as SpiConfig, Spi};
use esp_hal::time::{Duration, Instant, Rate};
use log::info;
use embedded_graphics::{
mono_font::{ascii::FONT_6X10, MonoTextStyle},
pixelcolor::Rgb565,
prelude::*,
text::Text,
};
use mipidsi::interface::SpiInterface;
use mipidsi::options::{ColorInversion, ColorOrder, Orientation, Rotation};
use mipidsi::{models::ST7789, Builder};
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
loop {}
}
// This creates a default app-descriptor required by the esp-idf bootloader.
// For more information see: <https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/app_image_format.html#application-description>
esp_bootloader_esp_idf::esp_app_desc!();
extern crate alloc;
#[main]
fn main() -> ! {
esp_println::logger::init_logger_from_env();
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
let peripherals = esp_hal::init(config);
esp_alloc::heap_allocator!(size: 72 * 1024);
let mut delay = Delay::new();
// have to turn on the board and wait 500ms before using the keyboard
let mut board_power = Output::new(peripherals.GPIO10, High, OutputConfig::default());
board_power.set_high();
delay.delay_millis(1000);
// ==== display setup ====
// https://github.com/Xinyuan-LilyGO/T-Deck/blob/master/examples/HelloWorld/HelloWorld.ino
let mut tft_cs = Output::new(peripherals.GPIO12, High, OutputConfig::default());
tft_cs.set_high();
let tft_dc = Output::new(peripherals.GPIO11, Low, OutputConfig::default());
let mut tft_enable = Output::new(peripherals.GPIO42, High, OutputConfig::default());
tft_enable.set_high();
let spi = Spi::new(
peripherals.SPI2,
SpiConfig::default().with_frequency(Rate::from_mhz(40)),
)
.unwrap()
.with_sck(peripherals.GPIO40)
.with_miso(Input::new(
peripherals.GPIO38,
InputConfig::default().with_pull(Pull::Up),
))
.with_mosi(peripherals.GPIO41);
let mut buffer = [0u8; 512];
info!("setting up the display");
let spi_delay = Delay::new();
let spi_device = ExclusiveDevice::new(spi, tft_cs, spi_delay).unwrap();
let di = SpiInterface::new(spi_device, tft_dc, &mut buffer);
info!("building");
let mut display = Builder::new(ST7789, di)
.display_size(240, 320)
.invert_colors(ColorInversion::Inverted)
.color_order(ColorOrder::Rgb)
.orientation(Orientation::new().rotate(Rotation::Deg90))
.init(&mut delay)
.unwrap();
info!("initialized display");
// wait for everything to boot up
// delay.delay_millis(500);
let colors = [
Rgb565::BLACK,
Rgb565::WHITE,
Rgb565::RED,
Rgb565::GREEN,
Rgb565::BLUE,
];
let style = MonoTextStyle::new(&FONT_6X10, Rgb565::WHITE);
for _ in 1..10 {
for color in colors.iter() {
display.clear(*color).unwrap();
Text::new("Hello Rust!", Point::new(20, 30), style)
.draw(&mut display)
.unwrap();
info!("color {:?}", *color);
delay.delay_millis(1000);
}
}
info!("Display initialized");
loop {
info!("sleeping");
let delay_start = Instant::now();
while delay_start.elapsed() < Duration::from_millis(500) {}
}
}