Skip to content

Commit 2afc12e

Browse files
committed
Use official devkit
1 parent 73bcdd1 commit 2afc12e

File tree

1 file changed

+187
-104
lines changed

1 file changed

+187
-104
lines changed

examples/src/bin/lcd_dpi.rs

Lines changed: 187 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
//! Drives the 16-bit parallel RGB display on Makerfabs ESP32-S3-Parallel-TFT-with-Touch-4.3inch
1+
//! Drives the 16-bit parallel RGB display on ESP32-S3-LCD-EV-Board v1.5
22
//!
33
//! This example fills the screen with every color.
44
//!
55
//! The following wiring is assumed:
6-
//! - LCD_VYSNC => GPIO41
7-
//! - LCD_HSYNC => GPIO39
8-
//! - LCD_DE => GPIO40
9-
//! - LCD_PCLK => GPIO42
10-
//! - LCD_DATA0 => GPIO8
11-
//! - LCD_DATA1 => GPIO3
12-
//! - LCD_DATA2 => GPIO46
13-
//! - LCD_DATA3 => GPIO9
14-
//! - LCD_DATA4 => GPIO1
15-
//! - LCD_DATA5 => GPIO5
16-
//! - LCD_DATA6 => GPIO6
17-
//! - LCD_DATA7 => GPIO7
18-
//! - LCD_DATA8 => GPIO15
19-
//! - LCD_DATA9 => GPIO16
20-
//! - LCD_DATA10 => GPIO4
21-
//! - LCD_DATA11 => GPIO45
22-
//! - LCD_DATA12 => GPIO48
23-
//! - LCD_DATA13 => GPIO47
24-
//! - LCD_DATA14 => GPIO21
25-
//! - LCD_DATA15 => GPIO14
6+
//! - LCD_VYSNC => GPIO3
7+
//! - LCD_HSYNC => GPIO46
8+
//! - LCD_DE => GPIO17
9+
//! - LCD_PCLK => GPIO9
10+
//! - LCD_DATA0 => GPIO10
11+
//! - LCD_DATA1 => GPIO11
12+
//! - LCD_DATA2 => GPIO12
13+
//! - LCD_DATA3 => GPIO13
14+
//! - LCD_DATA4 => GPIO14
15+
//! - LCD_DATA5 => GPIO21
16+
//! - LCD_DATA6 => GPIO8
17+
//! - LCD_DATA7 => GPIO18
18+
//! - LCD_DATA8 => GPIO45
19+
//! - LCD_DATA9 => GPIO38
20+
//! - LCD_DATA10 => GPIO39
21+
//! - LCD_DATA11 => GPIO40
22+
//! - LCD_DATA12 => GPIO41
23+
//! - LCD_DATA13 => GPIO42
24+
//! - LCD_DATA14 => GPIO2
25+
//! - LCD_DATA15 => GPIO1
2626
2727
//% CHIPS: esp32s3
2828

@@ -32,17 +32,25 @@
3232
use core::iter::{empty, once};
3333

3434
use esp_backtrace as _;
35-
use esp_hal::{dma::{Dma, DmaPriority}, dma_loop_buffer, gpio::{Io, Level}, i2c, lcd_cam::{
36-
lcd::{
37-
dpi::{Config, Dpi, Format, FrameTiming},
38-
ClockMode,
39-
Phase,
40-
Polarity,
35+
use esp_hal::{
36+
delay::Delay,
37+
dma::{Dma, DmaPriority},
38+
dma_loop_buffer,
39+
gpio::{Io, Level, Output},
40+
i2c,
41+
i2c::I2c,
42+
lcd_cam::{
43+
lcd::{
44+
dpi::{Config, Dpi, Format, FrameTiming},
45+
ClockMode,
46+
Phase,
47+
Polarity,
48+
},
49+
LcdCam,
4150
},
42-
LcdCam,
43-
}, prelude::*, Blocking};
44-
use esp_hal::delay::Delay;
45-
use esp_hal::i2c::I2c;
51+
prelude::*,
52+
Blocking,
53+
};
4654
use esp_println::println;
4755

4856
#[entry]
@@ -53,7 +61,7 @@ fn main() -> ! {
5361

5462
let io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
5563

56-
let i2c = I2c::new(peripherals.I2C0, io.pins.gpio47, io.pins.gpio48, 100.kHz());
64+
let i2c = I2c::new(peripherals.I2C0, io.pins.gpio47, io.pins.gpio48, 400.kHz());
5765
let dma = Dma::new(peripherals.DMA);
5866
let channel = dma.channel2.configure(true, DmaPriority::Priority0);
5967
let lcd_cam = LcdCam::new(peripherals.LCD_CAM);
@@ -64,36 +72,47 @@ fn main() -> ! {
6472

6573
let delay = Delay::new();
6674

67-
println!("Ughh....");
75+
println!("Initialising");
6876

6977
let mut write_byte = |b: u8, is_cmd: bool| {
70-
// const fn compose(cs: bool, scl: bool, sda: bool) -> u8 {
71-
// let mut base = 0b1111_0001;
72-
// if cs {
73-
// base |= 0b0000_0010;
74-
// }
75-
// if scl {
76-
// base |= 0b0000_0100;
77-
// }
78-
// if sda {
79-
// base |= 0b0000_1000;
80-
// }
81-
// base
82-
// }
83-
84-
expander.write_output_reg(0b1111_0101).unwrap();
78+
const SCS_BIT: u8 = 0b0000_0010;
79+
const SCL_BIT: u8 = 0b0000_0100;
80+
const SDA_BIT: u8 = 0b0000_1000;
81+
82+
let mut output = 0b1111_0001 & !SCS_BIT;
83+
expander.write_output_reg(output).unwrap();
84+
8585
for bit in once(!is_cmd).chain((0..8).map(|i| (b >> i) & 0b1 != 0).rev()) {
86-
let sda = if bit { 0b0000_1000 } else { 0b0000_0000 };
87-
// Set SDA
88-
expander.write_output_reg(0b1111_0101 | sda).unwrap();
86+
let prev = output;
87+
if bit {
88+
output |= SDA_BIT;
89+
} else {
90+
output &= !SDA_BIT;
91+
}
92+
if prev != output {
93+
expander.write_output_reg(output).unwrap();
94+
}
8995

90-
// Toggle SCL
91-
expander.write_output_reg(0b1111_0001 | sda).unwrap();
92-
expander.write_output_reg(0b1111_0101 | sda).unwrap();
96+
output &= !SCL_BIT;
97+
expander.write_output_reg(output).unwrap();
98+
99+
output |= SCL_BIT;
100+
expander.write_output_reg(output).unwrap();
93101
}
94-
expander.write_output_reg(0b1111_0111).unwrap();
102+
103+
output &= !SCL_BIT;
104+
expander.write_output_reg(output).unwrap();
105+
106+
output &= !SDA_BIT;
107+
expander.write_output_reg(output).unwrap();
108+
109+
output |= SCS_BIT;
110+
expander.write_output_reg(output).unwrap();
95111
};
96112

113+
let mut vsync_pin = io.pins.gpio3;
114+
115+
let vsync_must_be_high_during_setup = Output::new(&mut vsync_pin, Level::High);
97116
for &init in INIT_CMDS.iter() {
98117
match init {
99118
InitCmd::Cmd(cmd, args) => {
@@ -107,48 +126,44 @@ fn main() -> ! {
107126
}
108127
}
109128
}
129+
drop(vsync_must_be_high_during_setup);
110130

111131
let mut dma_buf = dma_loop_buffer!(2 * 16);
112132

113133
let config = Config {
114134
clock_mode: ClockMode {
115135
polarity: Polarity::IdleLow,
116-
phase: Phase::ShiftHigh,
136+
phase: Phase::ShiftLow,
117137
},
118138
format: Format {
119139
enable_2byte_mode: true,
120140
..Default::default()
121141
},
122-
// https://www.makerfabs.com/desfile/files/QT4300H40R10-V03-Spec.pdf
123142
timing: FrameTiming {
124143
horizontal_active_width: 480,
125-
horizontal_total_width: 608,
126-
horizontal_blank_front_porch: 40,
144+
horizontal_total_width: 520,
145+
horizontal_blank_front_porch: 10,
127146

128147
vertical_active_height: 480,
129-
vertical_total_height: 525,
130-
vertical_blank_front_porch: 13,
148+
vertical_total_height: 510,
149+
vertical_blank_front_porch: 10,
131150

132-
hsync_width: 48, // 1..255
133-
vsync_width: 3, // 3..255
151+
hsync_width: 10,
152+
vsync_width: 10,
134153

135154
hsync_position: 0,
136155
},
137-
vsync_idle_level: Level::Low,
138-
hsync_idle_level: Level::Low,
139-
de_idle_level: Level::High,
156+
vsync_idle_level: Level::High,
157+
hsync_idle_level: Level::High,
158+
de_idle_level: Level::Low,
140159
disable_black_region: false,
141160
..Default::default()
142161
};
143162

144-
let mut dpi = Dpi::new(lcd_cam.lcd, channel.tx, 30.MHz(), config)
145-
.with_ctrl_pins(
146-
io.pins.gpio3,
147-
io.pins.gpio46,
148-
io.pins.gpio17,
149-
io.pins.gpio9,
150-
)
163+
let mut dpi = Dpi::new(lcd_cam.lcd, channel.tx, 16.MHz(), config)
164+
.with_ctrl_pins(vsync_pin, io.pins.gpio46, io.pins.gpio17, io.pins.gpio9)
151165
.with_data_pins(
166+
// Blue
152167
io.pins.gpio10,
153168
io.pins.gpio11,
154169
io.pins.gpio12,
@@ -228,7 +243,7 @@ impl Tca9554 {
228243
#[derive(Copy, Clone)]
229244
enum InitCmd {
230245
Cmd(u8, &'static [u8]),
231-
Delay(u8)
246+
Delay(u8),
232247
}
233248

234249
const INIT_CMDS: &[InitCmd] = &[
@@ -255,42 +270,110 @@ const INIT_CMDS: &[InitCmd] = &[
255270
InitCmd::Cmd(0x9a, &[0x72]),
256271
InitCmd::Cmd(0x9b, &[0x5a]),
257272
InitCmd::Cmd(0x82, &[0x2c, 0x2c]),
258-
InitCmd::Cmd(0x6d, &[0x00, 0x1f, 0x19, 0x1a, 0x10, 0x0e, 0x0c, 0x0a, 0x02, 0x07, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x08, 0x01, 0x09, 0x0b, 0x0d, 0x0f, 0x1a, 0x19, 0x1f, 0x00]),
259-
InitCmd::Cmd(0x64, &[0x38, 0x05, 0x01, 0xdb, 0x03, 0x03, 0x38, 0x04, 0x01, 0xdc, 0x03, 0x03, 0x7a, 0x7a, 0x7a, 0x7a]),
260-
InitCmd::Cmd(0x65, &[0x38, 0x03, 0x01, 0xdd, 0x03, 0x03, 0x38, 0x02, 0x01, 0xde, 0x03, 0x03, 0x7a, 0x7a, 0x7a, 0x7a]),
261-
InitCmd::Cmd(0x66, &[0x38, 0x01, 0x01, 0xdf, 0x03, 0x03, 0x38, 0x00, 0x01, 0xe0, 0x03, 0x03, 0x7a, 0x7a, 0x7a, 0x7a]),
262-
InitCmd::Cmd(0x67, &[0x30, 0x01, 0x01, 0xe1, 0x03, 0x03, 0x30, 0x02, 0x01, 0xe2, 0x03, 0x03, 0x7a, 0x7a, 0x7a, 0x7a]),
263-
InitCmd::Cmd(0x68, &[0x00, 0x08, 0x15, 0x08, 0x15, 0x7a, 0x7a, 0x08, 0x15, 0x08, 0x15, 0x7a, 0x7a]),
273+
InitCmd::Cmd(0xB1, &[0x10]),
274+
InitCmd::Cmd(
275+
0x6d,
276+
&[
277+
0x00, 0x1f, 0x19, 0x1a, 0x10, 0x0e, 0x0c, 0x0a, 0x02, 0x07, 0x1e, 0x1e, 0x1e, 0x1e,
278+
0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x1e, 0x08, 0x01, 0x09, 0x0b, 0x0d, 0x0f,
279+
0x1a, 0x19, 0x1f, 0x00,
280+
],
281+
),
282+
InitCmd::Cmd(
283+
0x64,
284+
&[
285+
0x38, 0x05, 0x01, 0xdb, 0x03, 0x03, 0x38, 0x04, 0x01, 0xdc, 0x03, 0x03, 0x7a, 0x7a,
286+
0x7a, 0x7a,
287+
],
288+
),
289+
InitCmd::Cmd(
290+
0x65,
291+
&[
292+
0x38, 0x03, 0x01, 0xdd, 0x03, 0x03, 0x38, 0x02, 0x01, 0xde, 0x03, 0x03, 0x7a, 0x7a,
293+
0x7a, 0x7a,
294+
],
295+
),
296+
InitCmd::Cmd(
297+
0x66,
298+
&[
299+
0x38, 0x01, 0x01, 0xdf, 0x03, 0x03, 0x38, 0x00, 0x01, 0xe0, 0x03, 0x03, 0x7a, 0x7a,
300+
0x7a, 0x7a,
301+
],
302+
),
303+
InitCmd::Cmd(
304+
0x67,
305+
&[
306+
0x30, 0x01, 0x01, 0xe1, 0x03, 0x03, 0x30, 0x02, 0x01, 0xe2, 0x03, 0x03, 0x7a, 0x7a,
307+
0x7a, 0x7a,
308+
],
309+
),
310+
InitCmd::Cmd(
311+
0x68,
312+
&[
313+
0x00, 0x08, 0x15, 0x08, 0x15, 0x7a, 0x7a, 0x08, 0x15, 0x08, 0x15, 0x7a, 0x7a,
314+
],
315+
),
264316
InitCmd::Cmd(0x60, &[0x38, 0x08, 0x7a, 0x7a, 0x38, 0x09, 0x7a, 0x7a]),
265317
InitCmd::Cmd(0x63, &[0x31, 0xe4, 0x7a, 0x7a, 0x31, 0xe5, 0x7a, 0x7a]),
266318
InitCmd::Cmd(0x69, &[0x04, 0x22, 0x14, 0x22, 0x14, 0x22, 0x08]),
267319
InitCmd::Cmd(0x6b, &[0x07]),
268320
InitCmd::Cmd(0x7a, &[0x08, 0x13]),
269321
InitCmd::Cmd(0x7b, &[0x08, 0x13]),
270-
InitCmd::Cmd(0xd1, &[0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00,
271-
0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee,
272-
0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03,
273-
0xff]),
274-
InitCmd::Cmd(0xd2, &[0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00,
275-
0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee,
276-
0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03,
277-
0xff]),
278-
InitCmd::Cmd(0xd3, &[0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00,
279-
0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee,
280-
0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03,
281-
0xff]),
282-
InitCmd::Cmd(0xd4, &[0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00,
283-
0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee,
284-
0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03,
285-
0xff]),
286-
InitCmd::Cmd(0xd5, &[0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00,
287-
0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee,
288-
0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03,
289-
0xff]),
290-
InitCmd::Cmd(0xd6, &[0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35, 0x00, 0x47, 0x00,
291-
0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7, 0x02, 0x36, 0x02, 0xa6, 0x02, 0xee,
292-
0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5, 0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03,
293-
0xff]),
322+
InitCmd::Cmd(
323+
0xd1,
324+
&[
325+
0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35,
326+
0x00, 0x47, 0x00, 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7,
327+
0x02, 0x36, 0x02, 0xa6, 0x02, 0xee, 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5,
328+
0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03, 0xff,
329+
],
330+
),
331+
InitCmd::Cmd(
332+
0xd2,
333+
&[
334+
0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35,
335+
0x00, 0x47, 0x00, 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7,
336+
0x02, 0x36, 0x02, 0xa6, 0x02, 0xee, 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5,
337+
0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03, 0xff,
338+
],
339+
),
340+
InitCmd::Cmd(
341+
0xd3,
342+
&[
343+
0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35,
344+
0x00, 0x47, 0x00, 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7,
345+
0x02, 0x36, 0x02, 0xa6, 0x02, 0xee, 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5,
346+
0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03, 0xff,
347+
],
348+
),
349+
InitCmd::Cmd(
350+
0xd4,
351+
&[
352+
0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35,
353+
0x00, 0x47, 0x00, 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7,
354+
0x02, 0x36, 0x02, 0xa6, 0x02, 0xee, 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5,
355+
0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03, 0xff,
356+
],
357+
),
358+
InitCmd::Cmd(
359+
0xd5,
360+
&[
361+
0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35,
362+
0x00, 0x47, 0x00, 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7,
363+
0x02, 0x36, 0x02, 0xa6, 0x02, 0xee, 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5,
364+
0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03, 0xff,
365+
],
366+
),
367+
InitCmd::Cmd(
368+
0xd6,
369+
&[
370+
0x00, 0x00, 0x00, 0x04, 0x00, 0x12, 0x00, 0x18, 0x00, 0x21, 0x00, 0x2a, 0x00, 0x35,
371+
0x00, 0x47, 0x00, 0x56, 0x00, 0x90, 0x00, 0xe5, 0x01, 0x68, 0x01, 0xd5, 0x01, 0xd7,
372+
0x02, 0x36, 0x02, 0xa6, 0x02, 0xee, 0x03, 0x48, 0x03, 0xa0, 0x03, 0xba, 0x03, 0xc5,
373+
0x03, 0xd0, 0x03, 0xe0, 0x03, 0xea, 0x03, 0xfa, 0x03, 0xff,
374+
],
375+
),
376+
InitCmd::Cmd(0x3A, &[0x66]),
294377
InitCmd::Cmd(0x11, &[]),
295378
InitCmd::Delay(120),
296379
InitCmd::Cmd(0x29, &[]),

0 commit comments

Comments
 (0)