|
| 1 | +#![deny(warnings)] |
| 2 | +#![no_main] |
| 3 | +#![no_std] |
| 4 | + |
| 5 | +// Required |
| 6 | +extern crate panic_semihosting; |
| 7 | + |
| 8 | +use cortex_m_rt::entry; |
| 9 | +use embedded_graphics::{ |
| 10 | + egcircle, egrectangle, egtext, |
| 11 | + fonts::Font6x8, |
| 12 | + pixelcolor::{Rgb565, RgbColor}, |
| 13 | + prelude::*, |
| 14 | + primitive_style, text_style, |
| 15 | +}; |
| 16 | + |
| 17 | +use stm32f7xx_hal::{ |
| 18 | + device, |
| 19 | + gpio::Speed, |
| 20 | + ltdc::{Layer, PixelFormat}, |
| 21 | + prelude::*, |
| 22 | + rcc::{HSEClock, HSEClockMode, Rcc}, |
| 23 | +}; |
| 24 | + |
| 25 | +mod screen; |
| 26 | + |
| 27 | +// DIMENSIONS |
| 28 | +const WIDTH: u16 = 480; |
| 29 | +const HEIGHT: u16 = 272; |
| 30 | + |
| 31 | +// Graphics framebuffer |
| 32 | +const FB_GRAPHICS_SIZE: usize = (WIDTH as usize) * (HEIGHT as usize); |
| 33 | +static mut FB_LAYER1: [u16; FB_GRAPHICS_SIZE] = [0; FB_GRAPHICS_SIZE]; |
| 34 | + |
| 35 | +#[entry] |
| 36 | +fn main() -> ! { |
| 37 | + let perif = device::Peripherals::take().unwrap(); |
| 38 | + let _cp = cortex_m::Peripherals::take().unwrap(); |
| 39 | + |
| 40 | + let rcc_hal: Rcc = perif.RCC.constrain(); |
| 41 | + |
| 42 | + // Set up pins |
| 43 | + let _gpioa = perif.GPIOA.split(); |
| 44 | + let _gpiob = perif.GPIOB.split(); |
| 45 | + let gpioe = perif.GPIOE.split(); |
| 46 | + let gpiog = perif.GPIOG.split(); |
| 47 | + let gpioh = perif.GPIOH.split(); |
| 48 | + let gpioi = perif.GPIOI.split(); |
| 49 | + let gpioj = perif.GPIOJ.split(); |
| 50 | + let gpiok = perif.GPIOK.split(); |
| 51 | + |
| 52 | + gpioe.pe4.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_B0 |
| 53 | + |
| 54 | + gpiog.pg12.into_alternate_af9().set_speed(Speed::VeryHigh); // LTCD_B4 |
| 55 | + |
| 56 | + gpioi.pi9.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_VSYNC |
| 57 | + gpioi.pi10.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_HSYNC |
| 58 | + gpioi.pi13.into_alternate_af14().set_speed(Speed::VeryHigh); |
| 59 | + gpioi.pi14.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_CLK |
| 60 | + gpioi.pi15.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_R0 |
| 61 | + |
| 62 | + gpioj.pj0.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_R1 |
| 63 | + gpioj.pj1.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_R2 |
| 64 | + gpioj.pj2.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_R3 |
| 65 | + gpioj.pj3.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_R4 |
| 66 | + gpioj.pj4.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_R5 |
| 67 | + gpioj.pj5.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_R6 |
| 68 | + gpioj.pj6.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_R7 |
| 69 | + gpioj.pj7.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_G0 |
| 70 | + gpioj.pj8.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_G1 |
| 71 | + gpioj.pj9.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_G2 |
| 72 | + gpioj.pj10.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_G3 |
| 73 | + gpioj.pj11.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_G4 |
| 74 | + gpioj.pj13.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_B1 |
| 75 | + gpioj.pj14.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_B2 |
| 76 | + gpioj.pj15.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_B3 |
| 77 | + |
| 78 | + gpiok.pk0.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_G5 |
| 79 | + gpiok.pk1.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_G6 |
| 80 | + gpiok.pk2.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_G7 |
| 81 | + gpiok.pk4.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_B5 |
| 82 | + gpiok.pk5.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_B6 |
| 83 | + gpiok.pk6.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_D7 |
| 84 | + gpiok.pk7.into_alternate_af14().set_speed(Speed::VeryHigh); // LTCD_E |
| 85 | + |
| 86 | + // HSE osc out in High Z |
| 87 | + gpioh.ph1.into_floating_input(); |
| 88 | + let _clocks = rcc_hal |
| 89 | + .cfgr |
| 90 | + .hse(HSEClock::new(25.mhz(), HSEClockMode::Bypass)) |
| 91 | + .sysclk(216.mhz()) |
| 92 | + .hclk(216.mhz()) |
| 93 | + .freeze(); |
| 94 | + |
| 95 | + // LCD enable: set it low first to avoid LCD bleed while setting up timings |
| 96 | + let mut disp_on = gpioi.pi12.into_push_pull_output(); |
| 97 | + disp_on.set_low().ok(); |
| 98 | + |
| 99 | + // LCD backlight enable |
| 100 | + let mut backlight = gpiok.pk3.into_push_pull_output(); |
| 101 | + backlight.set_high().ok(); |
| 102 | + |
| 103 | + let mut display = screen::Stm32F7DiscoDisplay::new(perif.LTDC, perif.DMA2D); |
| 104 | + display |
| 105 | + .controller |
| 106 | + .config_layer(Layer::L1, unsafe { &mut FB_LAYER1 }, PixelFormat::RGB565); |
| 107 | + |
| 108 | + display.controller.enable_layer(Layer::L1); |
| 109 | + display.controller.reload(); |
| 110 | + |
| 111 | + let display = &mut display; |
| 112 | + |
| 113 | + // LCD enable: activate LCD ! |
| 114 | + disp_on.set_high().ok(); |
| 115 | + |
| 116 | + let r = egrectangle!( |
| 117 | + top_left = (0, 0), |
| 118 | + bottom_right = (479, 271), |
| 119 | + style = primitive_style!(fill_color = Rgb565::new(0, 0b11110, 0b11011)) |
| 120 | + ); |
| 121 | + r.draw(display).ok(); |
| 122 | + |
| 123 | + let c1 = egcircle!( |
| 124 | + center = (20, 20), |
| 125 | + radius = 8, |
| 126 | + style = primitive_style!(fill_color = Rgb565::new(0, 63, 0)) |
| 127 | + ); |
| 128 | + |
| 129 | + let c2 = egcircle!( |
| 130 | + center = (25, 20), |
| 131 | + radius = 8, |
| 132 | + style = primitive_style!(fill_color = Rgb565::new(31, 0, 0)) |
| 133 | + ); |
| 134 | + |
| 135 | + let t = egtext!( |
| 136 | + text = "Hello Rust!", |
| 137 | + top_left = (100, 100), |
| 138 | + style = text_style!(font = Font6x8, text_color = RgbColor::WHITE) |
| 139 | + ); |
| 140 | + |
| 141 | + c1.draw(display).ok(); |
| 142 | + c2.draw(display).ok(); |
| 143 | + t.draw(display).ok(); |
| 144 | + |
| 145 | + for i in 0..300 { |
| 146 | + let c1 = egcircle!( |
| 147 | + center = (20 + i, 20), |
| 148 | + radius = 8, |
| 149 | + style = primitive_style!(fill_color = RgbColor::GREEN) |
| 150 | + ); |
| 151 | + c1.draw(display).ok(); |
| 152 | + } |
| 153 | + |
| 154 | + loop {} |
| 155 | +} |
0 commit comments