Skip to content

Commit ae63e83

Browse files
committed
add init_spi_rs
1 parent 0ca7630 commit ae63e83

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/main.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,14 @@ fn main() {
7878

7979
log::info!("Hello, world!");
8080

81-
ui::init_ui().unwrap();
81+
// ui::init_ui().unwrap();
82+
let _spi_driver = ui::init_ui_rs(
83+
peripherals.spi3,
84+
peripherals.pins.gpio21.into(),
85+
peripherals.pins.gpio47.into(),
86+
None,
87+
)
88+
.unwrap();
8289
log::info!("UI initialized");
8390
ui::hello_lcd().unwrap();
8491

@@ -111,4 +118,6 @@ fn main() {
111118
None,
112119
Some(&samples),
113120
);
121+
122+
unsafe { esp_idf_svc::sys::esp_restart() }
114123
}

src/ui.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use embedded_graphics::{
88
Drawable,
99
};
1010
use embedded_text::TextBox;
11+
use esp_idf_svc::hal::gpio::AnyIOPin;
1112
use esp_idf_svc::sys::EspError;
1213
use u8g2_fonts::U8g2TextStyle;
1314

@@ -17,6 +18,20 @@ pub type ColorFormat = Rgb565;
1718

1819
static mut ESP_LCD_PANEL_HANDLE: esp_idf_svc::sys::esp_lcd_panel_handle_t = std::ptr::null_mut();
1920

21+
fn init_spi_rs(
22+
spi: esp_idf_svc::hal::spi::SPI3,
23+
sclk: AnyIOPin,
24+
sdo: AnyIOPin,
25+
sdi: Option<AnyIOPin>,
26+
) -> esp_idf_svc::hal::spi::SpiDriver<'static> {
27+
let config = esp_idf_svc::hal::spi::SpiDriverConfig::new().dma(
28+
esp_idf_svc::hal::spi::Dma::Auto(DISPLAY_WIDTH * DISPLAY_HEIGHT),
29+
);
30+
31+
let driver = esp_idf_svc::hal::spi::SpiDriver::new(spi, sclk, sdo, sdi, &config).unwrap();
32+
driver
33+
}
34+
2035
fn init_spi() -> Result<(), EspError> {
2136
use esp_idf_svc::sys::*;
2237
const GPIO_NUM_NC: i32 = -1;
@@ -119,6 +134,17 @@ pub fn init_ui() -> Result<(), EspError> {
119134
Ok(())
120135
}
121136

137+
pub fn init_ui_rs(
138+
spi: esp_idf_svc::hal::spi::SPI3,
139+
sclk: AnyIOPin,
140+
sdo: AnyIOPin,
141+
sdi: Option<AnyIOPin>,
142+
) -> Result<esp_idf_svc::hal::spi::SpiDriver<'static>, EspError> {
143+
let driver = init_spi_rs(spi, sclk, sdo, sdi);
144+
init_lcd()?;
145+
Ok(driver)
146+
}
147+
122148
pub fn hello_lcd() -> Result<(), EspError> {
123149
let mut display = Box::new(Framebuffer::<
124150
ColorFormat,

0 commit comments

Comments
 (0)