mirror of
https://github.com/kittywitch/esp32-c3-meepy.git
synced 2026-02-08 23:49:18 -08:00
feat: god damn
This commit is contained in:
parent
2c32b306c1
commit
f3310667d9
4 changed files with 30 additions and 4 deletions
1
.envrc
Normal file
1
.envrc
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
use flake
|
||||||
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1 +1,2 @@
|
||||||
target/
|
target/
|
||||||
|
.direnv
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
outputs = { nixpkgs, flake-utils, esp-rs-nix, ... }@inputs: let
|
outputs = { nixpkgs, flake-utils, esp-rs-nix, ... }@inputs: let
|
||||||
mkPkgs = system: (import nixpkgs) {
|
mkPkgs = system: (import nixpkgs) {
|
||||||
inherit system;
|
inherit system;
|
||||||
|
rust.rustcTarget = "riscv32imc-unknown-none-elf";
|
||||||
};
|
};
|
||||||
eachSystemOutputs = flake-utils.lib.eachDefaultSystem (system: let
|
eachSystemOutputs = flake-utils.lib.eachDefaultSystem (system: let
|
||||||
pkgs = mkPkgs system;
|
pkgs = mkPkgs system;
|
||||||
|
|
@ -20,9 +21,9 @@
|
||||||
esp-rs
|
esp-rs
|
||||||
pkgs.rustup
|
pkgs.rustup
|
||||||
pkgs.espflash
|
pkgs.espflash
|
||||||
#pkgs.rust-analyzer
|
|
||||||
pkgs.pkg-config
|
pkgs.pkg-config
|
||||||
pkgs.stdenv.cc
|
pkgs.stdenv.cc
|
||||||
|
#pkgs.rust-analyzer
|
||||||
#pkgs.bacon
|
#pkgs.bacon
|
||||||
#pkgs.systemdMinimal
|
#pkgs.systemdMinimal
|
||||||
#pkgs.lunarvim
|
#pkgs.lunarvim
|
||||||
|
|
|
||||||
29
src/main.rs
29
src/main.rs
|
|
@ -55,10 +55,33 @@ type TFTSpiDevice<'spi> = ExclusiveDevice<Spi<'spi, Blocking>, Output<'spi>, NoD
|
||||||
type TFTSpiInterface<'spi> =
|
type TFTSpiInterface<'spi> =
|
||||||
SPIInterface<ExclusiveDevice<Spi<'spi, Blocking>, Output<'spi>, NoDelay>, Output<'spi>>;
|
SPIInterface<ExclusiveDevice<Spi<'spi, Blocking>, Output<'spi>, NoDelay>, Output<'spi>>;
|
||||||
|
|
||||||
|
type Ili<'spi> = Ili9341<TFTSpiInterface<'spi>, Output<'spi>>;
|
||||||
|
|
||||||
pub struct TFT<'spi> {
|
pub struct TFT<'spi> {
|
||||||
display: Ili9341<TFTSpiInterface<'spi>, Output<'spi>>,
|
display: Ili<'spi>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl <'spi>TFT<'spi> {
|
||||||
|
fn draw_target(&mut self) -> DrawFlipper<'_,'spi> {
|
||||||
|
DrawFlipper { display: &mut self.display }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
struct DrawFlipper<'a,'spi> { display: &'a mut Ili<'spi>, }
|
||||||
|
impl<'a, 'spi> DrawTarget for DrawFlipper<'a, 'spi> {
|
||||||
|
type Error = <Ili<'spi> as DrawTarget>::Error;
|
||||||
|
type Color = <Ili<'spi> as DrawTarget>::Color;
|
||||||
|
fn draw_iter<I>(&mut self, pixels: I) -> Result<(), Self::Error>
|
||||||
|
where I: IntoIterator<Item = Pixel<Self::Color>> {
|
||||||
|
let width = self.bounding_box().size.width as i32;
|
||||||
|
self.display.draw_iter(pixels.into_iter().map(|mut p| { p.0.x = width - p.0.x; p }))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
impl<'a> Dimensions for DrawFlipper<'a,'_> {
|
||||||
|
fn bounding_box(&self) -> Rectangle {
|
||||||
|
self.display.bounding_box()
|
||||||
|
}
|
||||||
|
}
|
||||||
impl<'spi> TFT<'spi> {
|
impl<'spi> TFT<'spi> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
spi2: SPI2<'spi>,
|
spi2: SPI2<'spi>,
|
||||||
|
|
@ -105,14 +128,14 @@ impl<'spi> TFT<'spi> {
|
||||||
pub fn part_clear(&mut self, x: i32, y: i32, w: u32, h: u32) {
|
pub fn part_clear(&mut self, x: i32, y: i32, w: u32, h: u32) {
|
||||||
Rectangle::new(Point::new(x, y), Size::new(w, h))
|
Rectangle::new(Point::new(x, y), Size::new(w, h))
|
||||||
.into_styled(PrimitiveStyle::with_fill(Rgb565::WHITE))
|
.into_styled(PrimitiveStyle::with_fill(Rgb565::WHITE))
|
||||||
.draw(&mut self.display)
|
.draw(&mut self.draw_target())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn println(&mut self, text: &str, x: i32, y: i32) {
|
pub fn println(&mut self, text: &str, x: i32, y: i32) {
|
||||||
let style = MonoTextStyle::new(&FONT_8X13, Rgb565::RED);
|
let style = MonoTextStyle::new(&FONT_8X13, Rgb565::RED);
|
||||||
Text::with_alignment(text, Point::new(x, y), style, Alignment::Center)
|
Text::with_alignment(text, Point::new(x, y), style, Alignment::Center)
|
||||||
.draw(&mut self.display)
|
.draw(&mut self.draw_target())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue