1
1
#![ no_std]
2
2
#![ no_main]
3
3
4
- use esp_bsp:: prelude:: * ;
5
- use esp_display_interface_spi_dma:: display_interface_spi_dma;
6
-
4
+ // use esp_bsp::prelude::*;
5
+ // use esp_display_interface_spi_dma::display_interface_spi_dma;
6
+ use embedded_hal_bus :: spi :: ExclusiveDevice ;
7
7
use embedded_graphics:: {
8
8
mono_font:: { ascii:: FONT_8X13 , MonoTextStyle } ,
9
9
pixelcolor:: Rgb565 ,
@@ -15,18 +15,17 @@ use embedded_graphics::{
15
15
} ;
16
16
#[ allow( unused_imports) ]
17
17
use esp_backtrace as _;
18
- use esp_hal:: gpio:: OutputOpenDrain ;
19
- use esp_hal:: gpio:: Pull ;
18
+ // use esp_hal::gpio::OutputOpenDrain;
20
19
use esp_hal:: rng:: Rng ;
21
20
use esp_hal:: {
22
21
delay:: Delay ,
23
- dma:: DmaPriority ,
24
- gpio:: { Level , Output } ,
22
+ gpio:: { Level , Output , OutputConfig , DriveMode } ,
25
23
spi:: master:: Spi ,
26
- main
24
+ main,
25
+ time:: Rate ,
27
26
} ;
28
-
29
- use embedded_graphics_framebuf:: FrameBuf ;
27
+ use mipidsi :: interface :: SpiInterface ;
28
+ // use embedded_graphics_framebuf::FrameBuf;
30
29
use embedded_hal:: delay:: DelayNs ;
31
30
use log:: info;
32
31
@@ -37,8 +36,10 @@ const HEIGHT: usize = 48;
37
36
const RESET_AFTER_GENERATIONS : usize = 500 ;
38
37
39
38
use core:: fmt:: Write ;
40
-
39
+ // use esp_hal::dma::Owner::Dma;
40
+ use esp_hal:: spi:: Mode ;
41
41
use heapless:: String ;
42
+ use mipidsi:: { models:: ILI9486Rgb565 , Builder } ;
42
43
43
44
fn write_generation < D : DrawTarget < Color = Rgb565 > > (
44
45
display : & mut D ,
@@ -160,15 +161,70 @@ fn main() -> ! {
160
161
let peripherals = esp_hal:: init ( esp_hal:: Config :: default ( ) ) ;
161
162
esp_println:: logger:: init_logger_from_env ( ) ;
162
163
163
- let spi = lcd_spi ! ( peripherals) ;
164
- let di = lcd_display_interface ! ( peripherals, spi) ;
164
+ // let spi = lcd_spi!(peripherals);
165
+ let spi = Spi :: new (
166
+ peripherals. SPI2 ,
167
+ esp_hal:: spi:: master:: Config :: default ( )
168
+ . with_frequency ( Rate :: from_mhz ( 40 ) )
169
+ . with_mode ( Mode :: _0) ,
170
+ )
171
+ . unwrap ( )
172
+ . with_sck ( peripherals. GPIO7 )
173
+ . with_mosi ( peripherals. GPIO6 )
174
+ // .with_cs((peripherals.GPIO5))
175
+ ;
176
+ // .with_dma((peripherals.DMA_CH0));
177
+ // let mut spi = Spi::new(
178
+ // peripherals.SPI2,
179
+ // esp_hal::spi::master::Config::default()
180
+ // .with_frequency(100.kHz())
181
+ // .with_mode(Mode::_0),
182
+ // )
183
+ // .unwrap()
184
+ // .with_sck(sclk)
185
+ // .with_miso(miso)
186
+ // .with_mosi(mosi)
187
+ // .with_cs(cs)
188
+ // .with_dma(peripherals.DMA_CH0);
189
+
190
+ // let di = lcd_display_interface!(peripherals, spi);
191
+ // let lcd_dc = Output::new($dc_pin, Level::Low);
192
+ let mut buffer = [ 0_u8 ; 512 ] ;
193
+
194
+ let lcd_dc = Output :: new ( peripherals. GPIO4 , Level :: Low , OutputConfig :: default ( ) ) ;
195
+ // Define the display interface with no chip select
196
+ let cs_output = Output :: new ( peripherals. GPIO5 , Level :: High , OutputConfig :: default ( ) ) ;
197
+ let spi_device = ExclusiveDevice :: new_no_delay ( spi, cs_output) . unwrap ( ) ;
198
+ let di = SpiInterface :: new ( spi_device, lcd_dc, & mut buffer) ;
199
+
200
+ // let di = display_interface_spi_dma::new_no_cs(crate::LCD_MEMORY_SIZE, spi, lcd_dc);
201
+ // let di = SpiInterface::new(spi_device, dc, &mut buffer);
202
+ // }
165
203
let mut delay = Delay :: new ( ) ;
166
204
delay. delay_ns ( 500_000u32 ) ;
167
205
168
- let mut display = lcd_display ! ( peripherals, di) . init ( & mut delay) . unwrap ( ) ;
206
+ // let mut display = lcd_display!(peripherals, di).init(&mut delay).unwrap();
207
+ // let mut display = mipidsi::Builder::new(mipidsi::models::ILI9342CRgb565, di)
208
+ // .display_size((320 as u16), (240 as u16))
209
+ // .orientation((mipidsi::options::Orientation::new()
210
+ // .flip_vertical()
211
+ // .flip_horizontal()
212
+ // ))
213
+ // .color_order(mipidsi::options::ColorOrder::Bgr)
214
+ // .reset_pin(OutputOpenDrain::new(peripherals.GPIO48, Level::High, Pull::Up)
215
+ // );
216
+
217
+ let reset = Output :: new ( peripherals. GPIO48 , Level :: High , OutputConfig :: default ( ) . with_drive_mode ( DriveMode :: OpenDrain ) ) ;
218
+
219
+ let mut display = Builder :: new ( ILI9486Rgb565 , di)
220
+ . reset_pin ( reset)
221
+ . init ( & mut delay)
222
+ . unwrap ( ) ;
169
223
170
224
// Use the `lcd_backlight_init` macro to turn on the backlight
171
- lcd_backlight_init ! ( peripherals) ;
225
+ let mut backlight = Output :: new ( peripherals. GPIO47 , Level :: High , OutputConfig :: default ( ) ) ;
226
+ backlight. set_high ( ) ;
227
+ // lcd_backlight_init!(peripherals);
172
228
173
229
info ! ( "Hello Conway!" ) ;
174
230
@@ -181,15 +237,17 @@ fn main() -> ! {
181
237
}
182
238
let mut generation_count = 0 ;
183
239
184
- let mut data = [ Rgb565 :: BLACK ; 320 * 240 ] ;
185
- let mut fbuf = FrameBuf :: new ( & mut data, 320 , 240 ) ;
240
+ // let mut data = [Rgb565::BLACK; 320 * 240];
241
+ // let mut fbuf = FrameBuf::new(&mut data, 320, 240);
242
+ display. clear ( Rgb565 :: BLACK ) . unwrap ( ) ;
186
243
187
244
loop {
188
245
// Update the game state
189
246
update_game_of_life ( & mut grid) ;
190
247
191
248
// Draw the updated grid on the display
192
- draw_grid ( & mut fbuf, & grid) . unwrap ( ) ;
249
+ // draw_grid(&mut fbuf, &grid).unwrap();
250
+ draw_grid ( & mut display, & grid) . unwrap ( ) ;
193
251
194
252
generation_count += 1 ;
195
253
@@ -198,10 +256,18 @@ fn main() -> ! {
198
256
generation_count = 0 ; // Reset the generation counter
199
257
}
200
258
201
- write_generation ( & mut fbuf, generation_count) . unwrap ( ) ;
259
+ // write_generation(&mut fbuf, generation_count).unwrap();
260
+ write_generation ( & mut display, generation_count) . unwrap ( ) ;
261
+
262
+ // let pixel_iterator = fbuf.into_iter().map(|p| p.1);
263
+ // // let _ = display.set_pixels(0, 0, 319, 240, pixel_iterator);
264
+ // use mipidsi::interface::InterfacePixelFormat;
265
+
266
+ // let pixel_iterator = fbuf.into_iter().map(|p| p.1);
267
+
268
+ // // Send the pixels to the display
269
+ // Rgb565::send_pixels(&mut display, pixel_iterator).unwrap();
202
270
203
- let pixel_iterator = fbuf. into_iter ( ) . map ( |p| p. 1 ) ;
204
- let _ = display. set_pixels ( 0 , 0 , 319 , 240 , pixel_iterator) ;
205
271
206
272
// Add a delay to control the simulation speed
207
273
delay. delay_ms ( 100u32 ) ;
0 commit comments