-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
808 lines (754 loc) · 23 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
#![no_std]
#![no_main]
#![feature(type_alias_impl_trait)]
use core::cell::RefCell;
use core::ptr::addr_of_mut;
use core::sync::atomic::AtomicBool;
use core::sync::atomic::Ordering;
use critical_section::Mutex;
use embassy_futures::join::join;
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
use embassy_sync::signal::Signal;
use embassy_time::Duration;
use embassy_time::Timer;
use embedded_graphics::framebuffer::buffer_size;
use embedded_graphics::framebuffer::Framebuffer;
use embedded_graphics::geometry::Point;
use embedded_graphics::image::Image;
use embedded_graphics::pixelcolor::raw::BigEndian;
use embedded_graphics::pixelcolor::raw::RawU16;
use embedded_graphics::Drawable;
use embedded_graphics_core::pixelcolor::Rgb565;
use esp_backtrace as _;
use esp_hal::cpu_control::CpuControl;
use esp_hal::cpu_control::Stack;
use esp_hal::dma::DmaRxBuf;
use esp_hal::dma::DmaTxBuf;
use esp_hal::spi::master::HalfDuplexReadWrite;
use esp_hal::dma::{Dma, DmaPriority};
use esp_hal::dma_buffers;
use esp_hal::dma_descriptors;
use esp_hal::gpio::Level;
use esp_hal::interrupt;
use esp_hal::interrupt::Priority;
use esp_hal::otg_fs;
use esp_hal::otg_fs::asynch::{Config, Driver};
use esp_hal::otg_fs::Usb;
use esp_hal::peripherals::Interrupt;
use esp_hal::system::SystemControl;
use esp_hal::timer::systimer::SystemTimer;
use esp_hal::timer::systimer::Target;
use esp_hal::Blocking;
use esp_hal::{
clock::ClockControl,
delay::Delay,
gpio::Io,
gpio::{any_pin::AnyPin, Input, Output, Pull},
peripherals::Peripherals,
prelude::*,
spi::{
master::{prelude::*, Address, Command, Spi},
HalfDuplexMode, SpiDataMode, SpiMode,
},
};
use esp_hal_embassy::{self, Executor};
use static_cell::make_static;
use embassy_usb::class::hid::{HidReaderWriter, ReportId, RequestHandler, State};
use embassy_usb::control::OutResponse;
use embassy_usb::{Builder, Handler};
use usbd_hid::descriptor::KeyboardReport;
use usbd_hid::descriptor::SerializedDescriptor;
// MUST be the first module so other modules see the macros
pub mod fmt;
type QSpiDisplay<'a> = esp_hal::spi::master::dma::SpiDmaBus<
'a,
esp_hal::peripherals::SPI2,
esp_hal::dma::DmaChannel0,
HalfDuplexMode,
Blocking,
>;
const MAX_DMA_TRANSFER: usize = 32736;
const WIDTH: usize = 356;
const HEIGHT: usize = 400;
static TE: Mutex<RefCell<Option<Input<'static, esp_hal::gpio::Gpio17>>>> =
Mutex::new(RefCell::new(None));
static TE_READY: AtomicBool = AtomicBool::new(false);
static mut APP_CORE_STACK: Stack<16384> = Stack::new();
static mut FRAME_BUFFER: Framebuffer<
Rgb565,
RawU16,
BigEndian,
WIDTH,
HEIGHT,
{ buffer_size::<Rgb565>(WIDTH, HEIGHT) },
> = Framebuffer::new();
#[entry]
fn main() -> ! {
let peripherals = Peripherals::take();
esp_println::logger::init_logger_from_env();
// V1.0 of the mKey has the USB DM and DP swapped.. oops. There is an EFUSE to swap the pins, yay! However,
// it is bugged, and doesn't swap the pullups too. We can work around this by correcting the pullups early in the program,
// as they are only used for signally to the host that we are a full speed device.
// If flash is fully erased without programming again, the USB-SERIAL-JTAG will cease to work, firmware
// will have to be flashed via UART0, at which point you can switch back.
#[cfg(feature = "usb-pin-exchange")]
{
let usj = unsafe { &*esp_hal::peripherals::USB_DEVICE::PTR };
usj.conf0().modify(|_, w| {
w.pad_pull_override()
.set_bit()
.dm_pullup()
.clear_bit()
.dp_pullup()
.set_bit()
});
}
let system = SystemControl::new(peripherals.SYSTEM);
let clocks = ClockControl::max(system.clock_control).freeze();
let sys = SystemTimer::new(peripherals.SYSTIMER).split::<Target>();
esp_hal_embassy::init(&clocks, sys.alarm0);
let mut cpu_control = CpuControl::new(peripherals.CPU_CTRL);
let delay = Delay::new(&clocks);
let mut io = Io::new(peripherals.GPIO, peripherals.IO_MUX);
io.set_interrupt_handler(te);
interrupt::enable(Interrupt::GPIO, Priority::Priority2).unwrap();
let sclk = io.pins.gpio4;
let sio0 = io.pins.gpio6;
let sio1 = io.pins.gpio5;
let sio2 = io.pins.gpio15;
let sio3 = io.pins.gpio7;
let cs = io.pins.gpio16;
let mut reset = Output::new(io.pins.gpio3, Level::Low);
let mut te_pin: Input<_> = Input::new(io.pins.gpio17, Pull::Down);
te_pin.listen(esp_hal::gpio::Event::RisingEdge);
critical_section::with(|cs| TE.borrow_ref_mut(cs).replace(te_pin));
let dma = Dma::new(peripherals.DMA);
let (tx_buffer, tx_descriptors, _, _) =
dma_buffers!(MAX_DMA_TRANSFER, 0);
// Half-Duplex because the display will only send a response once the master has finished
let mut spi = Spi::new_half_duplex(peripherals.SPI2, 80u32.MHz(), SpiMode::Mode3, &clocks)
.with_pins(
Some(sclk),
Some(sio0),
Some(sio1),
Some(sio2),
Some(sio3),
Some(cs),
)
.with_dma(dma.channel0.configure(false, DmaPriority::Priority0))
.with_buffers(
DmaTxBuf::new(tx_descriptors, tx_buffer).unwrap(),
DmaRxBuf::empty(),
);
reset.set_low();
delay.delay_millis(300u32);
reset.set_high();
delay.delay_millis(300u32);
// initialization commands
for (cmd, data) in WEA2012_INIT_CMDS {
lcd_write_cmd(&mut spi, *cmd, data);
}
log::info!("Finished initializing display!");
let pixels = unsafe { &mut *addr_of_mut!(FRAME_BUFFER) };
/*
Matrix
*/
let columns: &mut [Input<'static, AnyPin<'static>>] = make_static!([
Input::new(AnyPin::new(io.pins.gpio2), Pull::Up), // 0
Input::new(AnyPin::new(io.pins.gpio43), Pull::Up), // 1
Input::new(AnyPin::new(io.pins.gpio44), Pull::Up), // 2
Input::new(AnyPin::new(io.pins.gpio38), Pull::Up), // 3
Input::new(AnyPin::new(io.pins.gpio37), Pull::Up), // 4
Input::new(AnyPin::new(io.pins.gpio36), Pull::Up), // 5
Input::new(AnyPin::new(io.pins.gpio48), Pull::Up), // 6
Input::new(AnyPin::new(io.pins.gpio47), Pull::Up), // 7
Input::new(AnyPin::new(io.pins.gpio21), Pull::Up), // 8
Input::new(AnyPin::new(io.pins.gpio14), Pull::Up), // 9
Input::new(AnyPin::new(io.pins.gpio13), Pull::Up), // 10
Input::new(AnyPin::new(io.pins.gpio12), Pull::Up), // 11
Input::new(AnyPin::new(io.pins.gpio11), Pull::Up), // 12
Input::new(AnyPin::new(io.pins.gpio10), Pull::Up), // 13
]);
let rows: &mut [Output<'static, AnyPin<'static>>] = make_static!([
Output::new(AnyPin::new(io.pins.gpio1), Level::Low), // 0
Output::new(AnyPin::new(io.pins.gpio35), Level::Low), // 1
Output::new(AnyPin::new(io.pins.gpio45), Level::Low), // 2
Output::new(AnyPin::new(io.pins.gpio9), Level::Low), // 3
Output::new(AnyPin::new(io.pins.gpio46), Level::Low), // 4
]);
let _guard = cpu_control
.start_app_core(unsafe { &mut *addr_of_mut!(APP_CORE_STACK) }, move || {
let device = Usb::new(peripherals.USB0, io.pins.gpio20, io.pins.gpio19);
let signal = &*make_static!(Signal::new());
let executor = make_static!(Executor::new());
executor.run(|spawner| {
spawner.must_spawn(matrix(columns, rows, signal));
// spawner.must_spawn(usb(device, signal));
});
})
.unwrap();
let image =
tinygif::Gif::<Rgb565>::from_slice(include_bytes!("../Ferris-240x240.gif")).unwrap();
let mut start = SystemTimer::now();
let mut frames = 0;
loop {
for frame in image.frames() {
let frame = Image::with_center(
&frame,
Point::new(WIDTH as i32 / 2, (HEIGHT as i32 / 2) - 40),
);
frame.draw(pixels).unwrap();
// TE_READY won't get set until we mark that we're ready to flush a buffer
critical_section::with(|cs| {
TE_READY.store(false, Ordering::SeqCst);
// TE.borrow_ref_mut(cs).as_mut().unwrap().clear_interrupt();
});
// wait for next sync
while !TE_READY.load(Ordering::SeqCst) {}
let pixels = unsafe {
core::slice::from_raw_parts(
pixels.data().as_ptr() as *const u8,
pixels.data().len(),
)
};
let now = SystemTimer::now();
lcd_fill(&mut spi, pixels);
log::trace!(
"Time to fill display: {}ms",
(SystemTimer::now() - now) / (SystemTimer::ticks_per_second() / 1024)
);
frames += 1;
let now = SystemTimer::now();
if now.wrapping_sub(start) > SystemTimer::ticks_per_second() {
start = now;
log::info!("FPS: {}", frames);
frames = 0;
}
}
}
}
#[embassy_executor::task]
async fn usb(usb: otg_fs::Usb<'static>, signal: &'static Signal<NoopRawMutex, u8>) {
// Create the driver, from the HAL.
let mut ep_out_buffer = [0u8; 1024];
let driver = Driver::new(usb, &mut ep_out_buffer, Config::default());
// Create embassy-usb DeviceBuilder using the driver and config.
// It needs some buffers for building the descriptors.
let mut config_descriptor = [0; 256];
let mut bos_descriptor = [0; 256];
// You can also add a Microsoft OS descriptor.
let mut msos_descriptor = [0; 256];
let mut control_buf = [0; 64];
let mut request_handler = MyRequestHandler {};
let mut device_handler = MyDeviceHandler::new();
let mut state = State::new();
// Create embassy-usb Config
let mut config = embassy_usb::Config::new(0x16c0, 0x27dd);
config.max_power = 100;
config.max_packet_size_0 = 64;
config.manufacturer = Some("Scott Mabin");
config.product = Some("mKey");
config.serial_number = Some("000001");
let mut builder = Builder::new(
driver,
config,
&mut config_descriptor,
&mut bos_descriptor,
&mut msos_descriptor,
&mut control_buf,
);
builder.handler(&mut device_handler);
// Create classes on the builder.
let config = embassy_usb::class::hid::Config {
report_descriptor: KeyboardReport::desc(),
request_handler: None,
poll_ms: 60,
max_packet_size: 64,
};
let hid = HidReaderWriter::<_, 1, 8>::new(&mut builder, &mut state, config);
let mut usb = builder.build();
let (reader, mut writer) = hid.split();
let in_fut = async {
loop {
let code = signal.wait().await;
// Create a report with the A key pressed. (no shift modifier)
let report = KeyboardReport {
keycodes: [code, 0, 0, 0, 0, 0],
leds: 0,
modifier: 0,
reserved: 0,
};
// // Send the report.
// match writer.write_serialize(&report).await {
// Ok(()) => {}
// Err(e) => warn!("Failed to send report: {:?}", e),
// };
// Timer::after_micros(500).await; // simulate a release
// let report = KeyboardReport {
// keycodes: [0, 0, 0, 0, 0, 0],
// leds: 0,
// modifier: 0,
// reserved: 0,
// };
// match writer.write_serialize(&report).await {
// Ok(()) => {}
// Err(e) => warn!("Failed to send report: {:?}", e),
// };
}
};
let out_fut = async {
reader.run(false, &mut request_handler).await;
};
// Run everything concurrently.
// If we had made everything `'static` above instead, we could do this using separate tasks instead.
join(usb.run(), join(in_fut, out_fut)).await;
}
#[embassy_executor::task]
async fn matrix(
columns: &'static mut [Input<'static, AnyPin<'static>>],
rows: &'static mut [Output<'static, AnyPin<'static>>],
signal: &'static Signal<NoopRawMutex, u8>,
) -> ! {
info!("Matrix scanning starting...");
let mut last = (usize::MAX, usize::MAX);
loop {
for (y, row) in rows.iter_mut().enumerate() {
row.set_low();
Timer::after(Duration::from_micros(1)).await;
for (x, col) in columns.iter_mut().enumerate() {
if col.is_low() {
let current = (x, y);
if current != last {
last = current;
log::info!("({x}, {y}) is pressed!");
signal.signal(4); // always send "a" for now
}
}
}
row.set_high();
}
}
}
struct MyRequestHandler {}
impl RequestHandler for MyRequestHandler {
fn get_report(&mut self, id: ReportId, _buf: &mut [u8]) -> Option<usize> {
info!("Get report for {:?}", id);
None
}
fn set_report(&mut self, id: ReportId, data: &[u8]) -> OutResponse {
info!("Set report for {:?}: {:?}", id, data);
OutResponse::Accepted
}
fn set_idle_ms(&mut self, id: Option<ReportId>, dur: u32) {
info!("Set idle rate for {:?} to {:?}", id, dur);
}
fn get_idle_ms(&mut self, id: Option<ReportId>) -> Option<u32> {
info!("Get idle rate for {:?}", id);
None
}
}
struct MyDeviceHandler {
configured: AtomicBool,
}
impl MyDeviceHandler {
fn new() -> Self {
MyDeviceHandler {
configured: AtomicBool::new(false),
}
}
}
impl Handler for MyDeviceHandler {
fn enabled(&mut self, enabled: bool) {
self.configured.store(false, Ordering::Relaxed);
if enabled {
info!("Device enabled");
} else {
info!("Device disabled");
}
}
fn reset(&mut self) {
self.configured.store(false, Ordering::Relaxed);
info!("Bus reset, the Vbus current limit is 100mA");
}
fn addressed(&mut self, addr: u8) {
self.configured.store(false, Ordering::Relaxed);
info!("USB address set to: {}", addr);
}
fn configured(&mut self, configured: bool) {
self.configured.store(configured, Ordering::Relaxed);
if configured {
info!(
"Device configured, it may now draw up to the configured current limit from Vbus."
)
} else {
info!("Device is no longer configured, the Vbus current limit is 100mA.");
}
}
}
#[ram]
#[handler]
fn te() {
unsafe {
static mut LAST: u64 = 0;
let now = SystemTimer::now();
log::trace!(
"TE fired! Interval: {}ms",
(now - LAST) / (SystemTimer::ticks_per_second() / 1024)
);
LAST = now;
}
critical_section::with(|cs| TE.borrow_ref_mut(cs).as_mut().unwrap().clear_interrupt());
TE_READY.store(true, Ordering::SeqCst);
}
fn lcd_fill<'a>(spi: &mut QSpiDisplay<'a>, pixels: &'static [u8]) {
set_draw_area(spi, 0, 0, WIDTH as u16 - 1, HEIGHT as u16 - 1);
for (i, pixels) in pixels.chunks(MAX_DMA_TRANSFER / 2).enumerate() {
// fifo size
spi.write(
SpiDataMode::Quad,
Command::Command8(0x32, SpiDataMode::Single),
Address::Address24(if i > 0 { 0x002C00 } else { 0x003C00 }, SpiDataMode::Single),
0,
&pixels,
)
.unwrap();
}
}
fn lcd_write_cmd<'a>(spi: &mut QSpiDisplay<'a>, cmd: u32, data: &[u8]) {
static mut BUF: [u8; 4] = [0u8; 4];
let buf = unsafe { &mut *addr_of_mut!(BUF) };
if data.len() > 0 {
buf[..data.len()].copy_from_slice(&data);
}
log::trace!("Sending: {} => {:?}", cmd, &buf[..data.len()]);
spi.write(
SpiDataMode::Single,
Command::Command8(0x02, SpiDataMode::Single),
Address::Address24(cmd << 8, SpiDataMode::Single),
0,
&&buf[..data.len()],
)
.unwrap();
}
fn set_draw_area<'a>(spi: &mut QSpiDisplay<'a>, x1: u16, y1: u16, x2: u16, y2: u16) {
let cmds = [
(
0x2a,
&[(x1 >> 8) as u8, x1 as u8, (x2 >> 8) as u8, x2 as u8][..],
),
(
0x2b,
&[(y1 >> 8) as u8, y1 as u8, (y2 >> 8) as u8, y2 as u8][..],
),
];
for (cmd, data) in cmds {
lcd_write_cmd(spi, cmd, data);
}
}
// CMD, data
const WEA2012_INIT_CMDS: &[(u32, &[u8])] = &[
(0xFF, &[0x20, 0x10, 0x43]),
(0x04, &[0x70]),
(0xFF, &[0x20, 0x10, 0x10]),
(0x0C, &[0x11]),
(0x10, &[0x02]),
(0x11, &[0x11]),
(0x15, &[0x42]),
(0x16, &[0x11]),
(0x1A, &[0x02]),
(0x1B, &[0x11]),
(0x61, &[0x80]),
(0x62, &[0x80]),
(0x54, &[0x44]),
(0x58, &[0x88]),
(0x5C, &[0xcc]),
(0x20, &[0x80]),
(0x21, &[0x81]),
(0x22, &[0x31]),
(0x23, &[0x20]),
(0x24, &[0x11]),
(0x25, &[0x11]),
(0x26, &[0x12]),
(0x27, &[0x12]),
(0x30, &[0x80]),
(0x31, &[0x81]),
(0x32, &[0x31]),
(0x33, &[0x20]),
(0x34, &[0x11]),
(0x35, &[0x11]),
(0x36, &[0x12]),
(0x37, &[0x12]),
(0x41, &[0x11]),
(0x42, &[0x22]),
(0x43, &[0x33]),
(0x49, &[0x11]),
(0x4A, &[0x22]),
(0x4B, &[0x33]),
(0xFF, &[0x20, 0x10, 0x15]),
(0x00, &[0x00]),
(0x01, &[0x00]),
(0x02, &[0x00]),
(0x03, &[0x00]),
(0x04, &[0x10]),
(0x05, &[0x0C]),
(0x06, &[0x23]),
(0x07, &[0x22]),
(0x08, &[0x21]),
(0x09, &[0x20]),
(0x0A, &[0x33]),
(0x0B, &[0x32]),
(0x0C, &[0x34]),
(0x0D, &[0x35]),
(0x0E, &[0x01]),
(0x0F, &[0x01]),
(0x20, &[0x00]),
(0x21, &[0x00]),
(0x22, &[0x00]),
(0x23, &[0x00]),
(0x24, &[0x0C]),
(0x25, &[0x10]),
(0x26, &[0x20]),
(0x27, &[0x21]),
(0x28, &[0x22]),
(0x29, &[0x23]),
(0x2A, &[0x33]),
(0x2B, &[0x32]),
(0x2C, &[0x34]),
(0x2D, &[0x35]),
(0x2E, &[0x01]),
(0x2F, &[0x01]),
(0xFF, &[0x20, 0x10, 0x16]),
(0x00, &[0x00]),
(0x01, &[0x00]),
(0x02, &[0x00]),
(0x03, &[0x00]),
(0x04, &[0x08]),
(0x05, &[0x04]),
(0x06, &[0x19]),
(0x07, &[0x18]),
(0x08, &[0x17]),
(0x09, &[0x16]),
(0x0A, &[0x33]),
(0x0B, &[0x32]),
(0x0C, &[0x34]),
(0x0D, &[0x35]),
(0x0E, &[0x01]),
(0x0F, &[0x01]),
(0x20, &[0x00]),
(0x21, &[0x00]),
(0x22, &[0x00]),
(0x23, &[0x00]),
(0x24, &[0x04]),
(0x25, &[0x08]),
(0x26, &[0x16]),
(0x27, &[0x17]),
(0x28, &[0x18]),
(0x29, &[0x19]),
(0x2A, &[0x33]),
(0x2B, &[0x32]),
(0x2C, &[0x34]),
(0x2D, &[0x35]),
(0x2E, &[0x01]),
(0x2F, &[0x01]),
(0xFF, &[0x20, 0x10, 0x12]),
(0x00, &[0x99]),
(0x2A, &[0x28]),
(0x2B, &[0x0f]),
(0x2C, &[0x16]),
(0x2D, &[0x28]),
(0x2E, &[0x0f]),
(0xFF, &[0x20, 0x10, 0xA0]),
(0x08, &[0xdc]),
(0xFF, &[0x20, 0x10, 0x45]),
(0x03, &[0x64]),
(0xFF, &[0x20, 0x10, 0x40]),
(0x86, &[0x00]),
(0xFF, &[0x20, 0x10, 0x00]),
(0x2A, &[0x00, 0x00, 0x01, 0x63]),
(0xFF, &[0x20, 0x10, 0x42]),
(0x05, &[0x2c]),
(0xFF, &[0x20, 0x10, 0x11]),
(0x50, &[0x01]),
(0xFF, &[0x20, 0x10, 0x12]),
(0x0D, &[0x66]),
(0xFF, &[0x20, 0x10, 0x17]),
(0x39, &[0x3c]),
(0xFF, &[0x20, 0x10, 0x31]),
(0x00, &[0x00]),
(0x01, &[0x00]),
(0x02, &[0x00]),
(0x03, &[0x09]),
(0x04, &[0x00]),
(0x05, &[0x1c]),
(0x06, &[0x00]),
(0x07, &[0x36]),
(0x08, &[0x00]),
(0x09, &[0x3d]),
(0x0a, &[0x00]),
(0x0b, &[0x54]),
(0x0c, &[0x00]),
(0x0d, &[0x62]),
(0x0e, &[0x00]),
(0x0f, &[0x72]),
(0x10, &[0x00]),
(0x11, &[0x79]),
(0x12, &[0x00]),
(0x13, &[0xa6]),
(0x14, &[0x00]),
(0x15, &[0xd0]),
(0x16, &[0x01]),
(0x17, &[0x0e]),
(0x18, &[0x01]),
(0x19, &[0x3d]),
(0x1a, &[0x01]),
(0x1b, &[0x7b]),
(0x1c, &[0x01]),
(0x1d, &[0xcf]),
(0x1e, &[0x02]),
(0x1f, &[0x0E]),
(0x20, &[0x02]),
(0x21, &[0x53]),
(0x22, &[0x02]),
(0x23, &[0x80]),
(0x24, &[0x02]),
(0x25, &[0xC2]),
(0x26, &[0x02]),
(0x27, &[0xFA]),
(0x28, &[0x03]),
(0x29, &[0x3E]),
(0x2a, &[0x03]),
(0x2b, &[0x52]),
(0x2c, &[0x03]),
(0x2d, &[0x70]),
(0x2e, &[0x03]),
(0x2f, &[0x8E]),
(0x30, &[0x03]),
(0x31, &[0xA2]),
(0x32, &[0x03]),
(0x33, &[0xBA]),
(0x34, &[0x03]),
(0x35, &[0xCF]),
(0x36, &[0x03]),
(0x37, &[0xe8]),
(0x38, &[0x03]),
(0x39, &[0xf0]),
(0xFF, &[0x20, 0x10, 0x32]),
(0x00, &[0x00]),
(0x01, &[0x00]),
(0x02, &[0x00]),
(0x03, &[0x09]),
(0x04, &[0x00]),
(0x05, &[0x1c]),
(0x06, &[0x00]),
(0x07, &[0x36]),
(0x08, &[0x00]),
(0x09, &[0x3d]),
(0x0a, &[0x00]),
(0x0b, &[0x54]),
(0x0c, &[0x00]),
(0x0d, &[0x62]),
(0x0e, &[0x00]),
(0x0f, &[0x72]),
(0x10, &[0x00]),
(0x11, &[0x79]),
(0x12, &[0x00]),
(0x13, &[0xa6]),
(0x14, &[0x00]),
(0x15, &[0xd0]),
(0x16, &[0x01]),
(0x17, &[0x0e]),
(0x18, &[0x01]),
(0x19, &[0x3d]),
(0x1a, &[0x01]),
(0x1b, &[0x7b]),
(0x1c, &[0x01]),
(0x1d, &[0xcf]),
(0x1e, &[0x02]),
(0x1f, &[0x0E]),
(0x20, &[0x02]),
(0x21, &[0x53]),
(0x22, &[0x02]),
(0x23, &[0x80]),
(0x24, &[0x02]),
(0x25, &[0xC2]),
(0x26, &[0x02]),
(0x27, &[0xFA]),
(0x28, &[0x03]),
(0x29, &[0x3E]),
(0x2a, &[0x03]),
(0x2b, &[0x52]),
(0x2c, &[0x03]),
(0x2d, &[0x70]),
(0x2e, &[0x03]),
(0x2f, &[0x8E]),
(0x30, &[0x03]),
(0x31, &[0xA2]),
(0x32, &[0x03]),
(0x33, &[0xBA]),
(0x34, &[0x03]),
(0x35, &[0xCF]),
(0x36, &[0x03]),
(0x37, &[0xe8]),
(0x38, &[0x03]),
(0x39, &[0xf0]),
(0xFF, &[0x20, 0x10, 0x11]),
(0x60, &[0x01]),
(0x65, &[0x03]),
(0x66, &[0x38]),
(0x67, &[0x04]),
(0x68, &[0x34]),
(0x69, &[0x03]),
(0x61, &[0x03]),
(0x62, &[0x38]),
(0x63, &[0x04]),
(0x64, &[0x34]),
(0x0A, &[0x11]),
(0x0B, &[0x14]),
(0x0c, &[0x14]),
(0x55, &[0x06]),
(0xFF, &[0x20, 0x10, 0x42]),
(0x05, &[0x3D]),
(0x06, &[0x03]),
(0xFF, &[0x20, 0x10, 0x12]),
(0x1f, &[0xdc]),
(0xFF, &[0x20, 0x10, 0x17]),
(0x11, &[0xAA]),
(0x16, &[0x12]),
(0x0B, &[0xC3]),
(0x10, &[0x0E]),
(0x14, &[0xAA]),
(0x18, &[0xA0]),
(0x1A, &[0x80]),
(0x1F, &[0x80]),
(0xFF, &[0x20, 0x10, 0x11]),
(0x30, &[0xEE]),
(0xFF, &[0x20, 0x10, 0x12]),
(0x15, &[0x0F]),
(0x10, &[0x0F]),
(0xFF, &[0x20, 0x10, 0x40]),
(0x83, &[0xC4]),
(0xFF, &[0x20, 0x10, 0x2d]),
(0x01, &[0x3e]),
(0xFF, &[0x20, 0x10, 0x12]),
(0x2B, &[0x1e]),
(0x2C, &[0x26]),
(0x2E, &[0x1e]),
(0xFF, &[0x20, 0x10, 0x18]),
(0x01, &[0x01]),
(0x00, &[0x1E]),
(0xFF, &[0x20, 0x10, 0x43]),
(0x03, &[0x04]),
// touch For I2C
(0xFF, &[0x20, 0x10, 0x50]),
(0x05, &[0x00]),
(0x00, &[0xA6]),
(0x01, &[0xA6]),
(0x08, &[0x55]),
(0xFF, &[0x20, 0x10, 0x12]),
(0x21, &[0xB4]), // set vcom
(0xFF, &[0x20, 0x10, 0x00]),
// ADD FOR QSPI/TP TEST
(0x3A, &[0x05]), // Set 65K colour mode
(0x11, &[0x00]),
(0x29, &[0x00]),
];