#![no_std]
#![no_main]
use esp32c3_hal::{
clock::ClockControl,
peripherals::Peripherals,
gpio::*,
prelude::*,
spi,
timer::TimerGroup,
Rtc,
IO,
Delay,
};
/* Display and graphics */
use mipidsi::{ Orientation, ColorOrder };
use display_interface_spi::SPIInterfaceNoCS;
use embedded_graphics::pixelcolor::*;
use embedded_graphics::prelude::*;
use embedded_graphics::draw_target::DrawTarget;
use esp_println::println;
use esp_backtrace as _;
use fixed::types::I10F22;
use num_complex::Complex;
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
let mut system = peripherals.SYSTEM.split();
let mut clocks = ClockControl::boot_defaults(system.clock_control).freeze();
// Disable the RTC and TIMG watchdog timers
let mut rtc = Rtc::new(peripherals.RTC_CNTL);
let timer_group0 = TimerGroup::new(
peripherals.TIMG0,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt0 = timer_group0.wdt;
let timer_group1 = TimerGroup::new(
peripherals.TIMG1,
&clocks,
&mut system.peripheral_clock_control,
);
let mut wdt1 = timer_group1.wdt;
rtc.rwdt.disable();
wdt0.disable();
wdt1.disable();
println!("About to initialize the SPI LED driver ILI9341");
let io = IO::new(peripherals.GPIO, peripherals.IO_MUX);
/* Set corresponding pins */
let mosi = io.pins.gpio7;
let cs = io.pins.gpio2;
let rst = io.pins.gpio10;
let dc = io.pins.gpio3;
let sck = io.pins.gpio6;
let miso = io.pins.gpio8;
let backlight = io.pins.gpio4;
/* Then set backlight (set_low() - display lights up when signal is in 0, set_high() - opposite case(for example.)) */
let mut backlight = backlight.into_push_pull_output();
backlight.set_low().unwrap();
/* Configure SPI */
let spi = spi::Spi::new(
peripherals.SPI2,
sck,
mosi,
miso,
cs,
100u32.MHz(),
spi::SpiMode::Mode0,
&mut system.peripheral_clock_control,
&mut clocks,
);
let di = SPIInterfaceNoCS::new(spi, dc.into_push_pull_output());
let reset = rst.into_push_pull_output();
let mut delay = Delay::new(&clocks);
let mut display = mipidsi::Builder::ili9341_rgb565(di)
.with_display_size(240 as u16, 320 as u16)
.with_framebuffer_size(240 as u16, 320 as u16)
.with_orientation(Orientation::LandscapeInverted(true))
.with_color_order(ColorOrder::Bgr)
.init(&mut delay, Some(reset))
.unwrap();
println!("Initialized");
let centre_r = I10F22::from_num(-0.5);
let centre_i = I10F22::from_num(0.0);
let size = 4.0;
let scale_x = I10F22::from_num(size / 320.0);
let scale_y = I10F22::from_num((size * 0.75) / 240.0);
for y in 0..240 {
println!("y={}", y);
for x in 0..320 {
let c = Complex::new((I10F22::from_num(x - 160) * scale_x) + centre_r,
(I10F22::from_num(y - 120) * scale_y) + centre_i);
//println!("({}, {}): c={}", x, y, c);
let mut z = Complex::new(I10F22::ZERO, I10F22::ZERO);
let mut count: u16 = 0;
loop {
//println!(" {}: {}", count, z);
if count > 255 || z.norm_sqr() > I10F22::from_num(4) {
break;
}
z = (z * z) + c;
count += 1;
}
display.set_pixel(x, y, Rgb565::new(count as u8,
(count * 3) as u8,
(count * 5) as u8));
}
}
loop {}
}