66#[ global_allocator]
77static ALLOCATOR : esp_alloc:: EspHeap = esp_alloc:: EspHeap :: empty ( ) ;
88
9+ // use display_interface_spi::SPIInterfaceNoCS;
10+ use spi_dma_displayinterface:: spi_dma_displayinterface:: SPIInterfaceNoCS ;
11+
912use esp_backtrace as _;
10- use hal:: { psram, prelude:: * , peripherals:: Peripherals ,
13+ use hal:: { psram, prelude:: * ,
14+ peripherals:: Peripherals ,
15+ dma:: DmaPriority ,
16+ pdma:: Dma ,
1117 spi:: {
12- master:: Spi ,
18+ master:: { prelude :: * , Spi } ,
1319 SpiMode ,
1420 } ,
1521 clock:: { ClockControl , CpuClock } , Delay , Rng , IO } ;
16- use display_interface_spi :: SPIInterfaceNoCS ;
22+
1723use embedded_graphics:: {
1824 mono_font:: { ascii:: FONT_8X13 , MonoTextStyle } ,
1925 prelude:: { Point , RgbColor } ,
@@ -25,7 +31,8 @@ mod setup;
2531mod types;
2632mod app;
2733use app:: app_loop;
28- use setup:: * ;
34+
35+ use crate :: types:: ConfiguredPins ;
2936
3037pub fn init_psram_heap ( ) {
3138 unsafe {
@@ -41,29 +48,64 @@ fn main() -> ! {
4148 init_psram_heap ( ) ;
4249
4350 let system = peripherals. SYSTEM . split ( ) ;
44- let clocks = ClockControl :: configure ( system. clock_control , CpuClock :: Clock240MHz ) . freeze ( ) ;
51+
52+ // With DMA we have sufficient throughput, so we can clock down the CPU to 160MHz
53+ let clocks = ClockControl :: configure ( system. clock_control , CpuClock :: Clock160MHz ) . freeze ( ) ;
4554
4655 let mut delay = Delay :: new ( & clocks) ;
4756
4857 let io = IO :: new ( peripherals. GPIO , peripherals. IO_MUX ) ;
49- let ( unconfigured_pins, configured_pins, configured_system_pins) = setup_pins ( io. pins ) ;
5058
51- let spi = Spi :: new_no_cs_no_miso (
59+ let lcd_h_res = 240 ;
60+ let lcd_v_res = 320 ;
61+
62+ let lcd_sclk = io. pins . gpio19 ;
63+ let lcd_mosi = io. pins . gpio23 ;
64+ let lcd_miso = io. pins . gpio25 ;
65+ let lcd_cs = io. pins . gpio22 ;
66+ let lcd_dc = io. pins . gpio21 . into_push_pull_output ( ) ;
67+ let _lcd_backlight = io. pins . gpio5 . into_push_pull_output ( ) ;
68+ let lcd_reset = io. pins . gpio18 . into_push_pull_output ( ) ;
69+
70+ let dma = Dma :: new ( system. dma ) ;
71+ let dma_channel = dma. spi2channel ;
72+
73+ let mut descriptors = [ 0u32 ; 8 * 3 ] ;
74+ let mut rx_descriptors = [ 0u32 ; 8 * 3 ] ;
75+
76+ let configured_pins = ConfiguredPins {
77+ up_button : io. pins . gpio14 . into_pull_up_input ( ) ,
78+ down_button : io. pins . gpio12 . into_pull_up_input ( ) ,
79+ left_button : io. pins . gpio13 . into_pull_up_input ( ) ,
80+ right_button : io. pins . gpio15 . into_pull_up_input ( ) ,
81+ dynamite_button : io. pins . gpio26 . into_pull_up_input ( ) ,
82+ teleport_button : io. pins . gpio27 . into_pull_up_input ( ) ,
83+ } ;
84+
85+ let spi = Spi :: new (
5286 peripherals. SPI2 ,
53- unconfigured_pins. sclk ,
54- unconfigured_pins. mosi ,
87+ lcd_sclk,
88+ lcd_mosi,
89+ lcd_miso,
90+ lcd_cs,
5591 60u32 . MHz ( ) ,
5692 SpiMode :: Mode0 ,
5793 & clocks,
58- ) ;
94+ // );
95+ ) . with_dma ( dma_channel. configure (
96+ false ,
97+ & mut descriptors,
98+ & mut rx_descriptors,
99+ DmaPriority :: Priority0 ,
100+ ) ) ;
59101
60- let di = SPIInterfaceNoCS :: new ( spi, configured_system_pins . dc ) ;
102+ let di = SPIInterfaceNoCS :: new ( spi, lcd_dc ) ;
61103
62104 let mut display = match mipidsi:: Builder :: ili9341_rgb565 ( di)
63- . with_display_size ( 240 as u16 , 320 as u16 )
105+ . with_display_size ( lcd_h_res as u16 , lcd_v_res as u16 )
64106 . with_orientation ( mipidsi:: Orientation :: Landscape ( false ) )
65107 . with_color_order ( mipidsi:: ColorOrder :: Bgr )
66- . init ( & mut delay, Some ( configured_system_pins . reset ) ) {
108+ . init ( & mut delay, Some ( lcd_reset ) ) {
67109 Ok ( disp) => { disp } ,
68110 Err ( _) => { panic ! ( ) } ,
69111 } ;
@@ -80,6 +122,6 @@ fn main() -> ! {
80122 let mut seed_buffer = [ 1u8 ; 32 ] ;
81123 rng. read ( & mut seed_buffer) . unwrap ( ) ;
82124
83- app_loop ( configured_pins , & mut display, seed_buffer) ;
125+ app_loop ( & mut display, lcd_h_res , lcd_v_res , configured_pins , seed_buffer) ;
84126 loop { }
85127}
0 commit comments