3
3
4
4
extern crate alloc;
5
5
use alloc:: boxed:: Box ;
6
- use embedded_hal_bus :: spi :: NoDelay ; // no longer used in our type alias
6
+
7
7
use core:: fmt:: Write ;
8
8
use embedded_hal:: delay:: DelayNs ;
9
9
use embedded_graphics:: {
@@ -26,20 +26,21 @@ use esp_hal::{
26
26
use embedded_hal_bus:: spi:: ExclusiveDevice ;
27
27
use esp_println:: { logger:: init_logger_from_env, println} ;
28
28
use log:: info;
29
- use mipidsi:: interface:: SpiInterface ;
30
- use mipidsi:: { models:: ILI9486Rgb565 , Builder } ;
29
+ use mipidsi:: { interface:: SpiInterface , options:: ColorInversion } ;
30
+
31
+ use mipidsi:: { models:: ST7789 , Builder } ;
31
32
// Bevy ECS (no_std) imports:
32
33
use bevy_ecs:: prelude:: * ;
33
34
34
35
// --- Type Alias for the Concrete Display ---
35
- // Now we specify that the SPI interface uses Delay (not NoDelay) .
36
+ // Now we specify that the SPI interface uses Delay.
36
37
type MyDisplay = mipidsi:: Display <
37
38
SpiInterface <
38
39
' static ,
39
40
ExclusiveDevice < Spi < ' static , Blocking > , Output < ' static > , Delay > ,
40
41
Output < ' static >
41
42
> ,
42
- ILI9486Rgb565 ,
43
+ ST7789 ,
43
44
Output < ' static >
44
45
> ;
45
46
@@ -102,6 +103,7 @@ fn draw_grid<D: DrawTarget<Color = Rgb565>>(
102
103
grid : & [ [ bool ; WIDTH ] ; HEIGHT ] ,
103
104
) -> Result < ( ) , D :: Error > {
104
105
let border_color = Rgb565 :: new ( 230 , 230 , 230 ) ;
106
+
105
107
for ( y, row) in grid. iter ( ) . enumerate ( ) {
106
108
for ( x, & cell) in row. iter ( ) . enumerate ( ) {
107
109
if cell {
@@ -216,23 +218,27 @@ fn main() -> ! {
216
218
let mut display_delay = Delay :: new ( ) ;
217
219
display_delay. delay_ns ( 500_000u32 ) ;
218
220
219
- // Reset pin: GPIO21.
221
+ // Reset pin: GPIO21. Per BSP, reset is active low.
220
222
let reset = Output :: new (
221
223
peripherals. GPIO21 ,
222
- Level :: High ,
223
- OutputConfig :: default ( ) . with_drive_mode ( DriveMode :: OpenDrain ) ,
224
+ Level :: Low , // match BSP: lcd_reset_pin! creates with Level::Low.
225
+ OutputConfig :: default ( ) ,
224
226
) ;
225
227
// Initialize the display using mipidsi's builder.
226
- let display: MyDisplay = Builder :: new ( ILI9486Rgb565 , di)
228
+ let mut display: MyDisplay = Builder :: new ( ST7789 , di)
227
229
. reset_pin ( reset)
230
+ . display_size ( 172 , 320 )
231
+ . invert_colors ( ColorInversion :: Inverted )
228
232
. init ( & mut display_delay)
229
233
. unwrap ( ) ;
230
234
231
- // Backlight on GPIO22.
232
- let mut backlight = Output :: new ( peripherals. GPIO22 , Level :: High , OutputConfig :: default ( ) ) ;
235
+ display. clear ( Rgb565 :: BLUE ) . unwrap ( ) ;
236
+
237
+ // Backlight on GPIO22: create pin with initial low then set high.
238
+ let mut backlight = Output :: new ( peripherals. GPIO22 , Level :: Low , OutputConfig :: default ( ) ) ;
233
239
backlight. set_high ( ) ;
234
240
235
- info ! ( "Hello Conway with Bevy ECS! " ) ;
241
+ info ! ( "Display initialized " ) ;
236
242
237
243
// --- Initialize Game Resources ---
238
244
let mut game = GameOfLifeResource :: default ( ) ;
0 commit comments