鲜花销售管理系统seo类目链接优化
文章目录
- 说在前面
- 模块详情
- 准备工作
- 开始
- 编译
- 烧录
- 结果
说在前面
- esp32版本:s3
- 运行环境:esp-idf(std)
- 开发环境:wsl2
- LCD模块:ST7789V2 240*280 LCD
- github地址:这里
模块详情
-
某宙的esp32s3开发板
-
某雪的1.69inch LCD模块,包含杜邦线
准备工作
-
开发环境(
std
)搭建,见上篇 -
lcd引脚
-
esp32引脚
-
引脚连接
除了几个固定的,其它可以自行选择,这里我的连接如下LCD esp32(括号里为上图的序号) esp32 gpio VCC 3.3V(18) / GND GND(17) / DIN SPI_MOSI(20) GPIO17 CLK SPI_CK(19) GPIO18 CS SPI_CS(23) GPIO14 DC GPIO15(22) GPIO15 RST GPIO16(21) GPIO16 BL GPIO13(24) GPIO13
开始
- 如果从空工程开始的话,可以使用
code-generate
cargo generate esp-rs/esp-idf-template cargo
- 添加依赖
[features] default = ["std", "embassy", "esp-idf-svc/native"]pio = ["esp-idf-svc/pio"] std = ["alloc", "esp-idf-svc/binstart", "esp-idf-svc/std"] alloc = ["esp-idf-svc/alloc"] nightly = ["esp-idf-svc/nightly"] experimental = ["esp-idf-svc/experimental"] embassy = ["esp-idf-svc/embassy-sync", "esp-idf-svc/critical-section", "esp-idf-svc/embassy-time-driver"][dependencies] anyhow = {version = "1", features = ["backtrace"]} log = { version = "0.4", default-features = false } esp-idf-svc = { version = "0.47.1", default-features = false } embedded-graphics = "0.8.1" display-interface-spi = "0.4" mipidsi = "0.7.1"[build-dependencies] embuild = "0.31.3"[package.metadata.esp-idf-sys] esp_idf_tools_install_dir = "global"
- 代码(逻辑基本和树莓派一致)
use display_interface_spi::SPIInterfaceNoCS; use embedded_graphics::{mono_font::{MonoTextStyle, ascii::FONT_10X20}, pixelcolor::Rgb565, text::Text, prelude::*, Drawable}; use esp_idf_svc::hal::{spi, gpio, prelude::*}; use anyhow::Result;fn main() -> Result<()> {// It is necessary to call this function once. Otherwise some patches to the runtime// implemented by esp-idf-sys might not link properly. See https://github.com/esp-rs/esp-idf-template/issues/71esp_idf_svc::sys::link_patches();// Bind the log crate to the ESP Logging facilitiesesp_idf_svc::log::EspLogger::initialize_default();let peripherals = Peripherals::take().unwrap();let pins = peripherals.pins;test_lcd(peripherals.spi2,pins.gpio13.into(),pins.gpio15.into(),pins.gpio16.into(),pins.gpio18.into(),pins.gpio17.into(),pins.gpio14.into(),)?;Ok(()) }fn test_lcd(spi: spi::SPI2,backlight: gpio::AnyOutputPin,dc: gpio::AnyOutputPin,rst: gpio::AnyOutputPin,sclk: gpio::AnyOutputPin,sdo: gpio::AnyOutputPin,cs: gpio::AnyOutputPin, ) -> Result<()> {let driver = spi::SpiDeviceDriver::new_single(spi,sclk,sdo,Option::<gpio::AnyIOPin>::None,Some(cs),&spi::SpiDriverConfig::new().dma(spi::Dma::Disabled),&spi::SpiConfig::new().baudrate(20_000_000.into()).data_mode(esp_idf_svc::hal::spi::config::MODE_0),)?;let dc = gpio::PinDriver::output(dc)?;let rst = gpio::PinDriver::output(rst)?;let mut backlight = gpio::PinDriver::output(backlight)?;let di = SPIInterfaceNoCS::new(driver, dc);let mut delay = esp_idf_svc::hal::delay::Ets;let mut display = mipidsi::Builder::st7789(di).with_display_size(240, 280).with_orientation(mipidsi::Orientation::Landscape(true)).init(&mut delay, Some(rst)).unwrap();// Textlet text = "Hello World ^_^;";let text_x = 120;let text_y = 280 / 2;let text_style = MonoTextStyle::new(&FONT_10X20, Rgb565::WHITE);// Alternating colorlet colors = [Rgb565::RED, Rgb565::GREEN, Rgb565::BLUE];// Clear the display initiallydisplay.clear(colors[0]).unwrap();// Turn on backlightlet _ = backlight.set_high();// Draw textText::new(text, Point::new(text_x, text_y), text_style).draw(&mut display).unwrap();println!("Draw Hello from Rust!");Ok(()) }
编译
- 编译如果不通过,可以参考环境搭建
cargo build --target xtensa-esp32s3-espidf
烧录
- wsl访问usb设备见环境搭建
espflash flash target/xtensa-esp32s3-espidf/debug/rs-esp32s3-st7789-demo