init commit
This commit is contained in:
205
src/bin/main.rs
Normal file
205
src/bin/main.rs
Normal file
@ -0,0 +1,205 @@
|
||||
#![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."
|
||||
)]
|
||||
#![allow(unreachable_code)]
|
||||
|
||||
use defmt::info;
|
||||
use embedded_graphics::Drawable;
|
||||
use embedded_graphics::framebuffer::{Framebuffer, buffer_size};
|
||||
use embedded_graphics::image::{Image, ImageRaw};
|
||||
use embedded_graphics::pixelcolor::Rgb565;
|
||||
use embedded_graphics::pixelcolor::raw::{BigEndian, LittleEndian};
|
||||
use embedded_graphics::prelude::{Angle, DrawTarget, Point, Primitive, RgbColor, WebColors};
|
||||
use embedded_graphics::primitives::{
|
||||
Circle, PrimitiveStyle, PrimitiveStyleBuilder, Sector, StyledDrawable, Triangle,
|
||||
};
|
||||
use embedded_graphics::text::renderer::TextRenderer;
|
||||
use embedded_hal_bus::spi::ExclusiveDevice;
|
||||
use esp_hal::clock::CpuClock;
|
||||
use esp_hal::delay::Delay;
|
||||
use esp_hal::gpio::{Level, Output, OutputConfig};
|
||||
use esp_hal::main;
|
||||
use esp_hal::riscv::asm::delay;
|
||||
use esp_hal::rtc_cntl::Rtc;
|
||||
use esp_hal::time::{Duration, Instant, Rate};
|
||||
use esp_hal::timer::Timer;
|
||||
use esp_hal::timer::timg::TimerGroup;
|
||||
use mipidsi::interface::{Interface, SpiInterface};
|
||||
use mipidsi::models::ST7789;
|
||||
use {esp_backtrace as _, esp_println as _};
|
||||
|
||||
extern crate alloc;
|
||||
|
||||
// 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!();
|
||||
|
||||
#[main]
|
||||
fn main() -> ! {
|
||||
// generator version: 1.0.1
|
||||
|
||||
esp_alloc::heap_allocator!(size: 32 * 1024);
|
||||
let config = esp_hal::Config::default().with_cpu_clock(CpuClock::max());
|
||||
let peripherals = esp_hal::init(config);
|
||||
let mut timer = Delay::new();
|
||||
|
||||
let spi = esp_hal::spi::master::Spi::new(
|
||||
peripherals.SPI2,
|
||||
esp_hal::spi::master::Config::default()
|
||||
.with_mode(esp_hal::spi::Mode::_0)
|
||||
.with_frequency(Rate::from_mhz(80)),
|
||||
)
|
||||
.unwrap()
|
||||
.with_sck(peripherals.GPIO4)
|
||||
.with_mosi(peripherals.GPIO6);
|
||||
|
||||
let mut cs_output = Output::new(peripherals.GPIO1, Level::High, OutputConfig::default());
|
||||
cs_output.set_high();
|
||||
let spi_device = ExclusiveDevice::new_no_delay(spi, cs_output).unwrap();
|
||||
let _ = Output::new(peripherals.GPIO0, Level::High, OutputConfig::default());
|
||||
|
||||
let mut buffer = [0_u8; 512];
|
||||
|
||||
// Define the display interface with no chip select
|
||||
let di = SpiInterface::new(
|
||||
spi_device,
|
||||
Output::new(peripherals.GPIO2, Level::Low, OutputConfig::default()),
|
||||
&mut buffer,
|
||||
);
|
||||
|
||||
let mut display = mipidsi::Builder::new(ST7789, di)
|
||||
.reset_pin(Output::new(
|
||||
peripherals.GPIO3,
|
||||
Level::Low,
|
||||
OutputConfig::default(),
|
||||
))
|
||||
.invert_colors(mipidsi::options::ColorInversion::Inverted)
|
||||
.init(&mut timer)
|
||||
.unwrap();
|
||||
|
||||
display
|
||||
.set_tearing_effect(mipidsi::options::TearingEffect::Vertical)
|
||||
.unwrap();
|
||||
|
||||
// Create styles used by the drawing operations.
|
||||
let sector_style = PrimitiveStyleBuilder::new()
|
||||
.stroke_color(Rgb565::BLACK)
|
||||
.stroke_width(2)
|
||||
.fill_color(Rgb565::YELLOW)
|
||||
.build();
|
||||
let eye_style = PrimitiveStyleBuilder::new()
|
||||
.stroke_color(Rgb565::BLACK)
|
||||
.stroke_width(1)
|
||||
.fill_color(Rgb565::BLACK)
|
||||
.build();
|
||||
|
||||
//let output_settings = ::new().scale(4).build();
|
||||
//let mut window = Window::new("Pacman", &output_settings);
|
||||
|
||||
// The current progress of the animation
|
||||
const STEPS: i32 = 10;
|
||||
let mut progress: i32 = 0;
|
||||
let delay = Delay::new();
|
||||
|
||||
loop {
|
||||
let mut fb = Framebuffer::<
|
||||
Rgb565,
|
||||
_,
|
||||
LittleEndian,
|
||||
320,
|
||||
240,
|
||||
{ buffer_size::<Rgb565>(320, 240) },
|
||||
>::new();
|
||||
fb.clear(Rgb565::WHITE).unwrap();
|
||||
|
||||
let p = (progress - STEPS).abs();
|
||||
|
||||
// Draw a Sector as the main Pacman feature.
|
||||
let _ = Sector::new(
|
||||
Point::new(2, 2),
|
||||
61,
|
||||
Angle::from_degrees((p * 30 / STEPS) as f32),
|
||||
Angle::from_degrees((360 - 2 * p * 30 / STEPS) as f32),
|
||||
)
|
||||
.draw_styled(§or_style, &mut fb);
|
||||
|
||||
// Draw a Circle as the eye.
|
||||
let _ = Circle::new(Point::new(36, 16), 5).draw_styled(&eye_style, &mut fb);
|
||||
|
||||
delay.delay_millis(50);
|
||||
|
||||
progress = (progress + 1) % (2 * STEPS + 1);
|
||||
|
||||
let img_raw = ImageRaw::<Rgb565, LittleEndian>::new(fb.data(), 320);
|
||||
let image = Image::new(&img_raw, Point::zero());
|
||||
image.draw(&mut display).unwrap();
|
||||
}
|
||||
|
||||
// display
|
||||
// .set_pixels(0, 0, 50, 50, core::iter::repeat(Rgb565::BLUE))
|
||||
// .unwrap();
|
||||
// //display.set_pixel(10, 10, Rgb565::WHITE).unwrap();
|
||||
|
||||
// let i2c = I2c::new(peripherals.I2C0, Config::default())
|
||||
// .unwrap()
|
||||
// .with_sda(peripherals.GPIO8)
|
||||
// .with_scl(peripherals.GPIO9);
|
||||
//
|
||||
// esp_alloc::heap_allocator!(#[esp_hal::ram(reclaimed)] size: 66320);
|
||||
//
|
||||
// let rc = RefCell::new(i2c);
|
||||
//
|
||||
// let mut device = Ens160::new(embedded_hal_bus::i2c::RefCellDevice::new(&rc), 0x53);
|
||||
// timer.delay_millis(500);
|
||||
// device.reset().unwrap();
|
||||
// info!("Reset device");
|
||||
// timer.delay_millis(500);
|
||||
// device.operational().unwrap();
|
||||
// info!("Device operational");
|
||||
//
|
||||
// // Configure the AHT20 temperature and humidity sensor.
|
||||
// let mut aht20_uninit = aht20_driver::AHT20::new(
|
||||
// embedded_hal_bus::i2c::RefCellDevice::new(&rc),
|
||||
// aht20_driver::SENSOR_ADDRESS,
|
||||
// );
|
||||
// let mut aht20 = aht20_uninit.init(&mut timer).unwrap();
|
||||
//
|
||||
// // Take the temperature and humidity measurement.
|
||||
//
|
||||
// loop {
|
||||
// //timer.delay_millis(5000);
|
||||
// if let Ok(status) = device.status() {
|
||||
// if status.data_is_ready() {
|
||||
// let aht20_measurement = aht20.measure(&mut timer).unwrap();
|
||||
// //println!("temperature (aht20): {}C", aht20_measurement.temperature);
|
||||
// //println!("humidity (aht20): {}%", aht20_measurement.humidity);
|
||||
//
|
||||
// let tvoc = device.tvoc().unwrap();
|
||||
// let eco2 = device.eco2().unwrap();
|
||||
// //info!("eco2: {}, tvoc: {}", *eco2, tvoc);
|
||||
// print!(
|
||||
// "{}, {}, {}, {}\n",
|
||||
// *eco2, tvoc, aht20_measurement.temperature, aht20_measurement.humidity
|
||||
// );
|
||||
// // from eCO2
|
||||
// // directly
|
||||
// //let air_quality_index = device.air_quality_index().unwrap();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
loop {
|
||||
info!("Hello world!");
|
||||
let delay_start = Instant::now();
|
||||
while delay_start.elapsed() < Duration::from_millis(500) {}
|
||||
}
|
||||
|
||||
// for inspiration have a look at the examples at https://github.com/esp-rs/esp-hal/tree/esp-hal-v1.0.0/examples/src/bin
|
||||
}
|
||||
|
||||
fn draw_interface<T: DrawTarget>(target: &mut T) {}
|
||||
1
src/lib.rs
Normal file
1
src/lib.rs
Normal file
@ -0,0 +1 @@
|
||||
#![no_std]
|
||||
Reference in New Issue
Block a user