From 2523b0afee6750e798d2b530bd40d35ec774c7c5 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 1 May 2025 04:07:24 +0800 Subject: [PATCH 01/12] gc2145 talking and up exposure and noise levels need to be fixed, and need to find a way to rotate/flip the screen? i think. --- libs/cramium-hal/src/gc2145/constants.rs | 37 + libs/cramium-hal/src/gc2145/gc2145.rs | 326 ++++ libs/cramium-hal/src/gc2145/mod.rs | 4 + libs/cramium-hal/src/gc2145/tables.rs | 1974 ++++++++++++++++++++++ 4 files changed, 2341 insertions(+) create mode 100644 libs/cramium-hal/src/gc2145/constants.rs create mode 100644 libs/cramium-hal/src/gc2145/gc2145.rs create mode 100644 libs/cramium-hal/src/gc2145/mod.rs create mode 100644 libs/cramium-hal/src/gc2145/tables.rs diff --git a/libs/cramium-hal/src/gc2145/constants.rs b/libs/cramium-hal/src/gc2145/constants.rs new file mode 100644 index 000000000..50aff9455 --- /dev/null +++ b/libs/cramium-hal/src/gc2145/constants.rs @@ -0,0 +1,37 @@ +#![allow(dead_code)] +/* + The constant tables below are derived from https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/video/gc2145.c + with the following license: + + * Copyright (c) 2024 Felipe Neves + * + * SPDX-License-Identifier: Apache-2.0 +*/ + +pub(crate) const GC2145_REG_AMODE1: u8 = 0x17; +pub(crate) const GC2145_AMODE1_WINDOW_MASK: u8 = 0xFC; +pub(crate) const GC2145_REG_AMODE1_DEF: u8 = 0x14; +pub(crate) const GC2145_REG_OUTPUT_FMT: u8 = 0x84; +pub(crate) const GC2145_REG_OUTPUT_FMT_MASK: u8 = 0x1F; +pub(crate) const GC2145_REG_OUTPUT_FMT_RGB565: u8 = 0x06; +pub(crate) const GC2145_REG_OUTPUT_FMT_YCBYCR: u8 = 0x02; +pub(crate) const GC2145_REG_SYNC_MODE: u8 = 0x86; +pub(crate) const GC2145_REG_SYNC_MODE_DEF: u8 = 0x23; +pub(crate) const GC2145_REG_SYNC_MODE_COL_SWITCH: u8 = 0x10; +pub(crate) const GC2145_REG_SYNC_MODE_ROW_SWITCH: u8 = 0x20; +pub(crate) const GC2145_REG_RESET: u8 = 0xFE; +pub(crate) const GC2145_REG_SW_RESET: u8 = 0x80; +pub(crate) const GC2145_SET_P0_REGS: u8 = 0x00; +pub(crate) const GC2145_REG_CROP_ENABLE: u8 = 0x90; +pub(crate) const GC2145_CROP_SET_ENABLE: u8 = 0x01; +pub(crate) const GC2145_REG_BLANK_WINDOW_BASE: u8 = 0x09; +pub(crate) const GC2145_REG_WINDOW_BASE: u8 = 0x91; +pub(crate) const GC2145_REG_SUBSAMPLE: u8 = 0x99; +pub(crate) const GC2145_REG_SUBSAMPLE_MODE: u8 = 0x9A; +pub(crate) const GC2145_SUBSAMPLE_MODE_SMOOTH: u8 = 0x0E; +pub(crate) const GC2145_PIDH: u8 = 0xF0; +pub(crate) const GC2145_PIDL: u8 = 0xF1; +pub(crate) const GC2145_I2C_ID: u8 = 0xFB; + +pub(crate) const UXGA_HSIZE: u16 = 1600; +pub(crate) const UXGA_VSIZE: u16 = 1200; diff --git a/libs/cramium-hal/src/gc2145/gc2145.rs b/libs/cramium-hal/src/gc2145/gc2145.rs new file mode 100644 index 000000000..1817677c4 --- /dev/null +++ b/libs/cramium-hal/src/gc2145/gc2145.rs @@ -0,0 +1,326 @@ +use cramium_api::camera::*; +use cramium_api::*; +use utralib::CSR; +use utralib::utra; +use utralib::utra::udma_camera::REG_CAM_CFG_GLOB; + +use super::constants::*; +use super::tables::*; +use crate::ifram::IframRange; +use crate::udma::Udma; +use crate::udma::*; + +pub const GC2145_DEV: u8 = 0x3C; + +pub const CFG_FRAMEDROP_EN: utralib::Field = utralib::Field::new(1, 0, REG_CAM_CFG_GLOB); +pub const CFG_FRAMEDROP_VAL: utralib::Field = utralib::Field::new(6, 1, REG_CAM_CFG_GLOB); +pub const CFG_FRAMESLICE_EN: utralib::Field = utralib::Field::new(1, 7, REG_CAM_CFG_GLOB); +pub const CFG_FORMAT: utralib::Field = utralib::Field::new(3, 8, REG_CAM_CFG_GLOB); +pub const CFG_SHIFT: utralib::Field = utralib::Field::new(4, 11, REG_CAM_CFG_GLOB); +pub const CFG_GLOB_EN: utralib::Field = utralib::Field::new(1, 31, REG_CAM_CFG_GLOB); + +pub struct Gc2145 { + csr: CSR, + ifram: Option, + resolution: Resolution, + slicing: Option<(usize, usize)>, +} + +impl Udma for Gc2145 { + fn csr_mut(&mut self) -> &mut CSR { &mut self.csr } + + fn csr(&self) -> &CSR { &self.csr } +} + +impl Gc2145 { + #[cfg(feature = "std")] + /// Safety: clocks must be turned on before this is called + pub unsafe fn new() -> Result { + let ifram_virt = xous::syscall::map_memory( + xous::MemoryAddress::new(crate::board::CAM_IFRAM_ADDR), + None, + crate::board::CAM_IFRAM_LEN_PAGES * 4096, + xous::MemoryFlags::R | xous::MemoryFlags::W, + )?; + let ifram = IframRange::from_raw_parts( + crate::board::CAM_IFRAM_ADDR, + ifram_virt.as_ptr() as usize, + ifram_virt.len(), + ); + Ok(Gc2145::new_with_ifram(ifram)) + } + + pub unsafe fn new_with_ifram(ifram: IframRange) -> Self { + #[cfg(target_os = "xous")] + let csr_range = xous::syscall::map_memory( + xous::MemoryAddress::new(utra::udma_camera::HW_UDMA_CAMERA_BASE), + None, + 4096, + xous::MemoryFlags::R | xous::MemoryFlags::W, + ) + .expect("couldn't map cam port"); + #[cfg(target_os = "xous")] + let csr = CSR::new(csr_range.as_mut_ptr() as *mut u32); + #[cfg(not(target_os = "xous"))] + let csr = CSR::new(utra::udma_camera::HW_UDMA_CAMERA_BASE as *mut u32); + + Self { + csr, + ifram: Some(ifram), + // bogus value + resolution: Resolution::Res160x120, + slicing: None, + } + } + + pub fn release_ifram(&mut self) { + if let Some(ifram) = self.ifram.take() { + xous::syscall::unmap_memory(ifram.virt_range).unwrap(); + } + } + + pub fn claim_ifram(&mut self) -> Result<(), xous::Error> { + if self.ifram.is_none() { + let ifram = xous::syscall::map_memory( + xous::MemoryAddress::new(crate::board::CAM_IFRAM_ADDR), + None, + crate::board::CAM_IFRAM_LEN_PAGES * 4096, + xous::MemoryFlags::R | xous::MemoryFlags::W, + )?; + let cam_ifram = unsafe { + crate::ifram::IframRange::from_raw_parts( + crate::board::CAM_IFRAM_ADDR, + ifram.as_ptr() as usize, + ifram.len(), + ) + }; + self.ifram = Some(cam_ifram); + } + Ok(()) + } + + pub fn has_ifram(&self) -> bool { self.ifram.is_some() } + + pub fn poke(&self, i2c: &mut dyn I2cApi, adr: u8, dat: u8) { + i2c.i2c_write(GC2145_DEV, adr, &[dat]).expect("write failed"); + } + + // chip does not support sequential reads + pub fn peek(&self, i2c: &mut dyn I2cApi, adr: u8, dat: &mut [u8]) { + for (i, d) in dat.iter_mut().enumerate() { + let mut one_byte = [0u8]; + i2c.i2c_read(GC2145_DEV, adr + i as u8, &mut one_byte, false).expect("read failed"); + *d = one_byte[0]; + } + } + + fn gc2145_set_window(&self, i2c: &mut dyn I2cApi, mut reg: u8, x: u16, y: u16, w: u16, h: u16) { + self.poke(i2c, GC2145_REG_RESET, GC2145_SET_P0_REGS); + + /* Y/row offset */ + self.poke(i2c, reg, (y >> 8) as u8); + reg += 1; + self.poke(i2c, reg, (y & 0xff) as u8); + reg += 1; + + /* X/col offset */ + self.poke(i2c, reg, (x >> 8) as u8); + reg += 1; + self.poke(i2c, reg, (x & 0xff) as u8); + reg += 1; + + /* Window height */ + self.poke(i2c, reg, (h >> 8) as u8); + reg += 1; + self.poke(i2c, reg, (h & 0xff) as u8); + reg += 1; + + /* Window width */ + self.poke(i2c, reg, (w >> 8) as u8); + reg += 1; + self.poke(i2c, reg, (w & 0xff) as u8); + } + + fn set_resolution(&self, i2c: &mut dyn I2cApi, w: u16, h: u16) { + // TODO: figure out what this parameter even means in the context of an...unconstrained variable + // resolution? Maybe? It's not even clear to me that was the original intent from the C driver. + + // 160x120 base scaling + // let c_ratio = 4u16; + // let r_ratio = 4u16; + // 320x240 base scaling + let c_ratio = 3u16; + let r_ratio = 3u16; + // 640x480 base scaling + // let c_ratio = 2u16; + // let r_ratio = 2u16; + + /* Calculates the window boundaries to obtain the desired resolution */ + let win_w = w * c_ratio; + let win_h = h * r_ratio; + let x = ((win_w / c_ratio) - w) / 2; + let y = ((win_h / r_ratio) - h) / 2; + let win_x = (UXGA_HSIZE - win_w) / 2; + let win_y = (UXGA_VSIZE - win_h) / 2; + + /* Set readout window first. */ + self.gc2145_set_window(i2c, GC2145_REG_BLANK_WINDOW_BASE, win_x, win_y, win_w + 16, win_h + 8); + + /* Set cropping window next. */ + self.gc2145_set_window(i2c, GC2145_REG_WINDOW_BASE, x, y, w, h); + + /* Enable crop */ + self.poke(i2c, GC2145_REG_CROP_ENABLE, GC2145_CROP_SET_ENABLE); + // self.poke(i2c, GC2145_REG_CROP_ENABLE, 0); + + /* Set Sub-sampling ratio and mode */ + self.poke(i2c, GC2145_REG_SUBSAMPLE, ((r_ratio << 4) | c_ratio) as u8); + + self.poke(i2c, GC2145_REG_SUBSAMPLE_MODE, GC2145_SUBSAMPLE_MODE_SMOOTH); + + self.delay(30); + + // divide the clock down + self.poke(i2c, 0xFA, 0x32); + // self.poke(i2c, 0xFA, 0x63); + } + + #[inline(never)] + pub fn init(&mut self, i2c: &mut dyn I2cApi, resolution: Resolution) { + // initiate a reset + self.poke(i2c, GC2145_REG_RESET, GC2145_REG_SW_RESET); + self.delay(300); // wait for reset + + // do the init pokes + for &[adr, dat] in GC2145_INIT.iter() { + self.poke(i2c, adr, dat); + } + // setup AEC + for &[adr, dat] in GC2145_AEC.iter() { + self.poke(i2c, adr, dat); + } + + // set up YUV mode + self.poke(i2c, GC2145_REG_RESET, GC2145_SET_P0_REGS); + self.delay(30); + let mut buf = [0u8; 1]; + self.peek(i2c, GC2145_REG_OUTPUT_FMT, &mut buf); + self.delay(30); + self.poke( + i2c, + GC2145_REG_OUTPUT_FMT, + (buf[0] & !GC2145_REG_OUTPUT_FMT_MASK) | GC2145_REG_OUTPUT_FMT_YCBYCR, + ); + self.delay(30); + + let (w, h) = resolution.into(); + crate::println!("resolution set to {}x{}", w, h); + self.set_resolution(i2c, w as u16, h as u16); + self.resolution = resolution; + + crate::println!("udma setup"); + // set sync polarity + let vsync_pol = 0; + let hsync_pol = match resolution { + Resolution::Res320x240 => 0, + _ => 0, + }; + self.csr.wo( + utra::udma_camera::REG_CAM_VSYNC_POLARITY, + self.csr.ms(utra::udma_camera::REG_CAM_VSYNC_POLARITY_R_CAM_VSYNC_POLARITY, vsync_pol) + | self.csr.ms(utra::udma_camera::REG_CAM_VSYNC_POLARITY_R_CAM_HSYNC_POLARITY, hsync_pol), + ); + + // multiply by 1 + self.csr.wo(utra::udma_camera::REG_CAM_CFG_FILTER, 0x01_01_01); + + let (x, _y) = resolution.into(); + self.csr.wo(utra::udma_camera::REG_CAM_CFG_SIZE, (x as u32 - 1) << 16); + + let global = self.csr.ms(CFG_FRAMEDROP_EN, 0) + | self.csr.ms(CFG_FORMAT, Format::BypassLe as u32) + | self.csr.ms(CFG_FRAMESLICE_EN, 0) + | self.csr.ms(CFG_SHIFT, 0); + self.csr.wo(utra::udma_camera::REG_CAM_CFG_GLOB, global); + } + + /// TODO: figure out how to length-bound this to...the frame slice size? line size? idk... + pub fn rx_buf(&self) -> &[T] { &self.ifram.as_ref().unwrap().as_slice() } + + /// TODO: figure out how to length-bound this to...the frame slice size? line size? idk... + pub unsafe fn rx_buf_phys(&self) -> &[T] { &self.ifram.as_ref().unwrap().as_phys_slice() } + + /// TODO: Rework this to use the frame sync + automatic re-initiation on capture_await() for frames + /// TODO: Also make an interrupt driven version of this. + pub fn capture_async(&mut self) { + // we want the sliced resolution so resolve resolution through the method call wrapper + let (cols, rows) = self.resolution(); + let total_len = rows * cols; + self.csr.rmwf(CFG_GLOB_EN, 1); + unsafe { self.udma_enqueue(Bank::Rx, &self.rx_buf_phys::()[..total_len], CFG_EN | CFG_SIZE_16) } + } + + pub fn capture_await(&mut self, _use_yield: bool) { + while self.udma_busy(Bank::Rx) { + #[cfg(feature = "std")] + if _use_yield { + xous::yield_slice(); + } + } + } + + pub fn resolution(&self) -> (usize, usize) { + if let Some((x, y)) = self.slicing { (x, y) } else { self.resolution.into() } + } + + pub fn set_slicing(&mut self, ll: (usize, usize), ur: (usize, usize)) { + let (llx, lly) = ll; + let (urxx, uryy) = ur; + let urx = urxx.saturating_sub(1); + let ury = uryy.saturating_sub(1); + self.csr.wo(utra::udma_camera::REG_CAM_CFG_LL, llx as u32 & 0xFFFF | ((lly as u32 & 0xFFFF) << 16)); + self.csr.wo(utra::udma_camera::REG_CAM_CFG_UR, urx as u32 & 0xFFFF | ((ury as u32 & 0xFFFF) << 16)); + self.csr.rmwf(CFG_FRAMESLICE_EN, 1); + self.slicing = Some((urxx - llx, uryy - lly)); + // self.csr.wo(utra::udma_camera::REG_CAM_CFG_SIZE, (urx - llx) as u32 - 1); + } + + pub fn disable_slicing(&mut self) { + self.csr.rmwf(CFG_FRAMESLICE_EN, 0); + self.slicing = None; + } + + /// Returns (product ID, manufacturer ID) + /// Should be 0x2155, 0x0078 + pub fn read_id(&self, i2c: &mut dyn I2cApi) -> (u16, u16) { + let mut pid = [0u8; 2]; + let mut did = [0u8; 1]; + self.peek(i2c, GC2145_PIDH, &mut pid); // should return 0x2155 + self.peek(i2c, GC2145_I2C_ID, &mut did); + (u16::from_be_bytes(pid), did[0] as u16) + } + + pub fn delay(&self, quantum: usize) { + #[cfg(feature = "std")] + { + let tt = xous_api_ticktimer::Ticktimer::new().unwrap(); + tt.sleep_ms(quantum).ok(); + } + #[cfg(not(feature = "std"))] + { + use utralib::{CSR, utra}; + // abuse the d11ctime timer to create some time-out like thing + let mut d11c = CSR::new(utra::d11ctime::HW_D11CTIME_BASE as *mut u32); + d11c.wfo(utra::d11ctime::CONTROL_COUNT, 333_333); // 1.0ms per interval + let mut polarity = d11c.rf(utra::d11ctime::HEARTBEAT_BEAT); + for _ in 0..quantum { + while polarity == d11c.rf(utra::d11ctime::HEARTBEAT_BEAT) {} + polarity = d11c.rf(utra::d11ctime::HEARTBEAT_BEAT); + } + // we have to split this because we don't know where we caught the previous interval + if quantum == 1 { + while polarity == d11c.rf(utra::d11ctime::HEARTBEAT_BEAT) {} + } + } + } +} diff --git a/libs/cramium-hal/src/gc2145/mod.rs b/libs/cramium-hal/src/gc2145/mod.rs new file mode 100644 index 000000000..ae1af9719 --- /dev/null +++ b/libs/cramium-hal/src/gc2145/mod.rs @@ -0,0 +1,4 @@ +mod constants; +pub mod gc2145; +mod tables; +pub use gc2145::*; diff --git a/libs/cramium-hal/src/gc2145/tables.rs b/libs/cramium-hal/src/gc2145/tables.rs new file mode 100644 index 000000000..a98bc5fb8 --- /dev/null +++ b/libs/cramium-hal/src/gc2145/tables.rs @@ -0,0 +1,1974 @@ +/* + The constant tables below are derived from https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/video/gc2145.c + with the following license: + + * Copyright (c) 2024 Felipe Neves + * + * SPDX-License-Identifier: Apache-2.0 +*/ +use crate::gc2145::constants::*; + +pub(crate) const GC2145_INIT: [[u8; 2]; 607] = [ + [0xfe, 0xf0], + [0xfe, 0xf0], + [0xfe, 0xf0], + [0xfc, 0x06], + [0xf6, 0x00], + [0xf7, 0x1d], + [0xf8, 0x85], + [0xfa, 0x00], + [0xf9, 0xfe], + [0xf2, 0x00], + /* ISP settings */ + [0xfe, 0x00], + [0x03, 0x04], + [0x04, 0xe2], + [0x09, 0x00], + [0x0a, 0x00], + [0x0b, 0x00], + [0x0c, 0x00], + [0x0d, 0x04], /* Window height */ + [0x0e, 0xc0], + [0x0f, 0x06], /* Window width */ + [0x10, 0x52], + [0x99, 0x11], /* Subsample */ + [0x9a, 0x0E], /* Subsample mode */ + [0x12, 0x2e], + [0x17, 0x14], /* Analog Mode 1 (vflip/mirror[1:0]) */ + [0x18, 0x22], /* Analog Mode 2 */ + [0x19, 0x0e], + [0x1a, 0x01], + [0x1b, 0x4b], + [0x1c, 0x07], + [0x1d, 0x10], + [0x1e, 0x88], + [0x1f, 0x78], + [0x20, 0x03], + [0x21, 0x40], + [0x22, 0xa0], + [0x24, 0x16], + [0x25, 0x01], + [0x26, 0x10], + [0x2d, 0x60], + [0x30, 0x01], + [0x31, 0x90], + [0x33, 0x06], + [0x34, 0x01], + [0x80, 0x7f], + [0x81, 0x26], + [0x82, 0xfa], + [0x83, 0x00], + [GC2145_REG_OUTPUT_FMT, 0x06], + [GC2145_REG_SYNC_MODE, 0x23], + [0x88, 0x03], + [0x89, 0x03], + [0x85, 0x08], + [0x8a, 0x00], + [0x8b, 0x00], + [0xb0, 0x55], + [0xc3, 0x00], + [0xc4, 0x80], + [0xc5, 0x90], + [0xc6, 0x3b], + [0xc7, 0x46], + [0xec, 0x06], + [0xed, 0x04], + [0xee, 0x60], + [0xef, 0x90], + [0xb6, 0x01], + [0x90, 0x01], + [0x91, 0x00], + [0x92, 0x00], + [0x93, 0x00], + [0x94, 0x00], + [0x95, 0x02], + [0x96, 0x58], + [0x97, 0x03], + [0x98, 0x20], + [0x99, 0x22], + [0x9a, 0x0E], + [0x9b, 0x00], + [0x9c, 0x00], + [0x9d, 0x00], + [0x9e, 0x00], + [0x9f, 0x00], + [0xa0, 0x00], + [0xa1, 0x00], + [0xa2, 0x00], + /* BLK Settings */ + [0xfe, 0x00], + [0x40, 0x42], + [0x41, 0x00], + [0x43, 0x5b], + [0x5e, 0x00], + [0x5f, 0x00], + [0x60, 0x00], + [0x61, 0x00], + [0x62, 0x00], + [0x63, 0x00], + [0x64, 0x00], + [0x65, 0x00], + [0x66, 0x20], + [0x67, 0x20], + [0x68, 0x20], + [0x69, 0x20], + [0x76, 0x00], + [0x6a, 0x08], + [0x6b, 0x08], + [0x6c, 0x08], + [0x6d, 0x08], + [0x6e, 0x08], + [0x6f, 0x08], + [0x70, 0x08], + [0x71, 0x08], + [0x76, 0x00], + [0x72, 0xf0], + [0x7e, 0x3c], + [0x7f, 0x00], + [0xfe, 0x02], + [0x48, 0x15], + [0x49, 0x00], + [0x4b, 0x0b], + [0xfe, 0x00], + /* AEC Settings */ + [0xfe, 0x01], + [0x01, 0x04], + [0x02, 0xc0], + [0x03, 0x04], + [0x04, 0x90], + [0x05, 0x30], + [0x06, 0x90], + [0x07, 0x30], + [0x08, 0x80], + [0x09, 0x00], + [0x0a, 0x82], + [0x0b, 0x11], + [0x0c, 0x10], + [0x11, 0x10], + [0x13, 0x68], + [GC2145_REG_OUTPUT_FMT, 0x00], + [0x1c, 0x11], + [0x1e, 0x61], + [0x1f, 0x35], + [0x20, 0x40], + [0x22, 0x40], + [0x23, 0x20], + [0xfe, 0x02], + [0x0f, 0x04], + [0xfe, 0x01], + [0x12, 0x30], + [0x15, 0xb0], + [0x10, 0x31], + [0x3e, 0x28], + [0x3f, 0xb0], + [0x40, 0x90], + [0x41, 0x0f], + [0xfe, 0x02], + [0x90, 0x6c], + [0x91, 0x03], + [0x92, 0xcb], + [0x94, 0x33], + [0x95, 0x84], + [0x97, 0x65], + [0xa2, 0x11], + [0xfe, 0x00], + [0xfe, 0x02], + [0x80, 0xc1], + [0x81, 0x08], + [0x82, 0x05], + [0x83, 0x08], + [GC2145_REG_OUTPUT_FMT, 0x0a], + [GC2145_REG_SYNC_MODE, 0xf0], + [0x87, 0x50], + [0x88, 0x15], + [0x89, 0xb0], + [0x8a, 0x30], + [0x8b, 0x10], + [0xfe, 0x01], + [0x21, 0x04], + [0xfe, 0x02], + [0xa3, 0x50], + [0xa4, 0x20], + [0xa5, 0x40], + [0xa6, 0x80], + [0xab, 0x40], + [0xae, 0x0c], + [0xb3, 0x46], + [0xb4, 0x64], + [0xb6, 0x38], + [0xb7, 0x01], + [0xb9, 0x2b], + [0x3c, 0x04], + [0x3d, 0x15], + [0x4b, 0x06], + [0x4c, 0x20], + [0xfe, 0x00], + /* Gamma Control */ + [0xfe, 0x02], + [0x10, 0x09], + [0x11, 0x0d], + [0x12, 0x13], + [0x13, 0x19], + [0x14, 0x27], + [0x15, 0x37], + [0x16, 0x45], + [GC2145_REG_OUTPUT_FMT, 0x53], + [0x18, 0x69], + [0x19, 0x7d], + [0x1a, 0x8f], + [0x1b, 0x9d], + [0x1c, 0xa9], + [0x1d, 0xbd], + [0x1e, 0xcd], + [0x1f, 0xd9], + [0x20, 0xe3], + [0x21, 0xea], + [0x22, 0xef], + [0x23, 0xf5], + [0x24, 0xf9], + [0x25, 0xff], + [0xfe, 0x00], + [0xc6, 0x20], + [0xc7, 0x2b], + [0xfe, 0x02], + [0x26, 0x0f], + [0x27, 0x14], + [0x28, 0x19], + [0x29, 0x1e], + [0x2a, 0x27], + [0x2b, 0x33], + [0x2c, 0x3b], + [0x2d, 0x45], + [0x2e, 0x59], + [0x2f, 0x69], + [0x30, 0x7c], + [0x31, 0x89], + [0x32, 0x98], + [0x33, 0xae], + [0x34, 0xc0], + [0x35, 0xcf], + [0x36, 0xda], + [0x37, 0xe2], + [0x38, 0xe9], + [0x39, 0xf3], + [0x3a, 0xf9], + [0x3b, 0xff], + [0xfe, 0x02], + [0xd1, 0x32], + [0xd2, 0x32], + [0xd3, 0x40], + [0xd6, 0xf0], + [0xd7, 0x10], + [0xd8, 0xda], + [0xdd, 0x14], + [0xde, 0x86], + [0xed, 0x80], + [0xee, 0x00], + [0xef, 0x3f], + [0xd8, 0xd8], + [0xfe, 0x01], + [0x9f, 0x40], + [0xfe, 0x01], + [0xc2, 0x14], + [0xc3, 0x0d], + [0xc4, 0x0c], + [0xc8, 0x15], + [0xc9, 0x0d], + [0xca, 0x0a], + [0xbc, 0x24], + [0xbd, 0x10], + [0xbe, 0x0b], + [0xb6, 0x25], + [0xb7, 0x16], + [0xb8, 0x15], + [0xc5, 0x00], + [0xc6, 0x00], + [0xc7, 0x00], + [0xcb, 0x00], + [0xcc, 0x00], + [0xcd, 0x00], + [0xbf, 0x07], + [0xc0, 0x00], + [0xc1, 0x00], + [0xb9, 0x00], + [0xba, 0x00], + [0xbb, 0x00], + [0xaa, 0x01], + [0xab, 0x01], + [0xac, 0x00], + [0xad, 0x05], + [0xae, 0x06], + [0xaf, 0x0e], + [0xb0, 0x0b], + [0xb1, 0x07], + [0xb2, 0x06], + [0xb3, 0x17], + [0xb4, 0x0e], + [0xb5, 0x0e], + [0xd0, 0x09], + [0xd1, 0x00], + [0xd2, 0x00], + [0xd6, 0x08], + [0xd7, 0x00], + [0xd8, 0x00], + [0xd9, 0x00], + [0xda, 0x00], + [0xdb, 0x00], + [0xd3, 0x0a], + [0xd4, 0x00], + [0xd5, 0x00], + [0xa4, 0x00], + [0xa5, 0x00], + [0xa6, 0x77], + [0xa7, 0x77], + [0xa8, 0x77], + [0xa9, 0x77], + [0xa1, 0x80], + [0xa2, 0x80], + [0xfe, 0x01], + [0xdf, 0x0d], + [0xdc, 0x25], + [0xdd, 0x30], + [0xe0, 0x77], + [0xe1, 0x80], + [0xe2, 0x77], + [0xe3, 0x90], + [0xe6, 0x90], + [0xe7, 0xa0], + [0xe8, 0x90], + [0xe9, 0xa0], + [0xfe, 0x00], + [0xfe, 0x01], + [0x4f, 0x00], + [0x4f, 0x00], + [0x4b, 0x01], + [0x4f, 0x00], + [0x4c, 0x01], + [0x4d, 0x71], + [0x4e, 0x01], + [0x4c, 0x01], + [0x4d, 0x91], + [0x4e, 0x01], + [0x4c, 0x01], + [0x4d, 0x70], + [0x4e, 0x01], + [0x4c, 0x01], + [0x4d, 0x90], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0xb0], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0x8f], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0x6f], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0xaf], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0xd0], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0xf0], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0xcf], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0xef], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0x6e], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x8e], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xae], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xce], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x4d], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x6d], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x8d], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xad], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xcd], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x4c], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x6c], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x8c], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xac], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xcc], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xcb], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x4b], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x6b], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x8b], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xab], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x8a], + [0x4e, 0x04], + [0x4c, 0x01], + [0x4d, 0xaa], + [0x4e, 0x04], + [0x4c, 0x01], + [0x4d, 0xca], + [0x4e, 0x04], + [0x4c, 0x01], + [0x4d, 0xca], + [0x4e, 0x04], + [0x4c, 0x01], + [0x4d, 0xc9], + [0x4e, 0x04], + [0x4c, 0x01], + [0x4d, 0x8a], + [0x4e, 0x04], + [0x4c, 0x01], + [0x4d, 0x89], + [0x4e, 0x04], + [0x4c, 0x01], + [0x4d, 0xa9], + [0x4e, 0x04], + [0x4c, 0x02], + [0x4d, 0x0b], + [0x4e, 0x05], + [0x4c, 0x02], + [0x4d, 0x0a], + [0x4e, 0x05], + [0x4c, 0x01], + [0x4d, 0xeb], + [0x4e, 0x05], + [0x4c, 0x01], + [0x4d, 0xea], + [0x4e, 0x05], + [0x4c, 0x02], + [0x4d, 0x09], + [0x4e, 0x05], + [0x4c, 0x02], + [0x4d, 0x29], + [0x4e, 0x05], + [0x4c, 0x02], + [0x4d, 0x2a], + [0x4e, 0x05], + [0x4c, 0x02], + [0x4d, 0x4a], + [0x4e, 0x05], + [0x4c, 0x02], + [0x4d, 0x8a], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0x49], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0x69], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0x89], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0xa9], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0x48], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0x68], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0x69], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0xca], + [0x4e, 0x07], + [0x4c, 0x02], + [0x4d, 0xc9], + [0x4e, 0x07], + [0x4c, 0x02], + [0x4d, 0xe9], + [0x4e, 0x07], + [0x4c, 0x03], + [0x4d, 0x09], + [0x4e, 0x07], + [0x4c, 0x02], + [0x4d, 0xc8], + [0x4e, 0x07], + [0x4c, 0x02], + [0x4d, 0xe8], + [0x4e, 0x07], + [0x4c, 0x02], + [0x4d, 0xa7], + [0x4e, 0x07], + [0x4c, 0x02], + [0x4d, 0xc7], + [0x4e, 0x07], + [0x4c, 0x02], + [0x4d, 0xe7], + [0x4e, 0x07], + [0x4c, 0x03], + [0x4d, 0x07], + [0x4e, 0x07], + [0x4f, 0x01], + [0x50, 0x80], + [0x51, 0xa8], + [0x52, 0x47], + [0x53, 0x38], + [0x54, 0xc7], + [0x56, 0x0e], + [0x58, 0x08], + [0x5b, 0x00], + [0x5c, 0x74], + [0x5d, 0x8b], + [0x61, 0xdb], + [0x62, 0xb8], + [0x63, 0x86], + [0x64, 0xc0], + [0x65, 0x04], + [0x67, 0xa8], + [0x68, 0xb0], + [0x69, 0x00], + [0x6a, 0xa8], + [0x6b, 0xb0], + [0x6c, 0xaf], + [0x6d, 0x8b], + [0x6e, 0x50], + [0x6f, 0x18], + [0x73, 0xf0], + [0x70, 0x0d], + [0x71, 0x60], + [0x72, 0x80], + [0x74, 0x01], + [0x75, 0x01], + [0x7f, 0x0c], + [0x76, 0x70], + [0x77, 0x58], + [0x78, 0xa0], + [0x79, 0x5e], + [0x7a, 0x54], + [0x7b, 0x58], + [0xfe, 0x00], + [0xfe, 0x02], + [0xc0, 0x01], + [0xc1, 0x44], + [0xc2, 0xfd], + [0xc3, 0x04], + [0xc4, 0xF0], + [0xc5, 0x48], + [0xc6, 0xfd], + [0xc7, 0x46], + [0xc8, 0xfd], + [0xc9, 0x02], + [0xca, 0xe0], + [0xcb, 0x45], + [0xcc, 0xec], + [0xcd, 0x48], + [0xce, 0xf0], + [0xcf, 0xf0], + [0xe3, 0x0c], + [0xe4, 0x4b], + [0xe5, 0xe0], + [0xfe, 0x01], + [0x9f, 0x40], + [0xfe, 0x00], + /* Output Control */ + [0xfe, 0x00], + [0xf2, 0x0f], + [0xfe, 0x02], + [0x40, 0xbf], + [0x46, 0xcf], + [0xfe, 0x00], + [0xfe, 0x00], + [0x05, 0x01], + [0x06, 0x1C], + [0x07, 0x00], + [0x08, 0x32], + [0x11, 0x00], + [0x12, 0x1D], + [0x13, 0x00], + [0x14, 0x00], + [0xfe, 0x01], + [0x3c, 0x00], + [0x3d, 0x04], + [0xfe, 0x00], + [0x00, 0x00], +]; + +pub(crate) const GC2145_INIT_2: [[u8; 2]; 633] = [ + [0xfe, 0xf0], + [0xfe, 0xf0], + [0xfe, 0xf0], + [0xfc, 0x06], + [0xf6, 0x00], + [0xf7, 0x1d], + [0xf8, 0x84], + [0xfa, 0x00], + [0xf9, 0x8e], + [0xf2, 0x00], + [0xfe, 0x00], + [0x03, 0x04], + [0x04, 0xe2], + [0x09, 0x00], + [0x0a, 0x00], + [0x0b, 0x00], + [0x0c, 0x00], + [0x0d, 0x04], + [0x0e, 0xc0], + [0x0f, 0x06], + [0x10, 0x52], + [0x12, 0x2e], + [0x17, 0x14], + [0x18, 0x22], + [0x19, 0x0e], + [0x1a, 0x01], + [0x1b, 0x4b], + [0x1c, 0x07], + [0x1d, 0x10], + [0x1e, 0x88], + [0x1f, 0x78], + [0x20, 0x03], + [0x21, 0x40], + [0x22, 0xa0], + [0x24, 0x16], + [0x25, 0x01], + [0x26, 0x10], + [0x2d, 0x60], + [0x30, 0x01], + [0x31, 0x90], + [0x33, 0x06], + [0x34, 0x01], + [0xfe, 0x00], + [0x80, 0x7f], + [0x81, 0x26], + [0x82, 0xfa], + [0x83, 0x00], + [0x84, 0x02], + [0x86, 0x02], + [0x88, 0x03], + [0x89, 0x03], + [0x85, 0x08], + [0x8a, 0x00], + [0x8b, 0x00], + [0xb0, 0x55], + [0xc3, 0x00], + [0xc4, 0x80], + [0xc5, 0x90], + [0xc6, 0x3b], + [0xc7, 0x46], + [0xec, 0x06], + [0xed, 0x04], + [0xee, 0x60], + [0xef, 0x90], + [0xb6, 0x01], + [0x90, 0x01], + [0x91, 0x00], + [0x92, 0x00], + [0x93, 0x00], + [0x94, 0x00], + [0x95, 0x04], + [0x96, 0xb0], + [0x97, 0x06], + [0x98, 0x40], + [0xfe, 0x00], + [0x40, 0x42], + [0x41, 0x00], + [0x43, 0x5b], + [0x5e, 0x00], + [0x5f, 0x00], + [0x60, 0x00], + [0x61, 0x00], + [0x62, 0x00], + [0x63, 0x00], + [0x64, 0x00], + [0x65, 0x00], + [0x66, 0x20], + [0x67, 0x20], + [0x68, 0x20], + [0x69, 0x20], + [0x76, 0x00], + [0x6a, 0x08], + [0x6b, 0x08], + [0x6c, 0x08], + [0x6d, 0x08], + [0x6e, 0x08], + [0x6f, 0x08], + [0x70, 0x08], + [0x71, 0x08], + [0x76, 0x00], + [0x72, 0xf0], + [0x7e, 0x3c], + [0x7f, 0x00], + [0xfe, 0x02], + [0x48, 0x15], + [0x49, 0x00], + [0x4b, 0x0b], + [0xfe, 0x00], + [0xfe, 0x01], + [0x01, 0x04], + [0x02, 0xc0], + [0x03, 0x04], + [0x04, 0x90], + [0x05, 0x30], + [0x06, 0x90], + [0x07, 0x30], + [0x08, 0x80], + [0x09, 0x00], + [0x0a, 0x82], + [0x0b, 0x11], + [0x0c, 0x10], + [0x11, 0x10], + [0x13, 0x7b], + [0x17, 0x00], + [0x1c, 0x11], + [0x1e, 0x61], + [0x1f, 0x35], + [0x20, 0x40], + [0x22, 0x40], + [0x23, 0x20], + [0xfe, 0x02], + [0x0f, 0x04], + [0xfe, 0x01], + [0x12, 0x35], + [0x15, 0xb0], + [0x10, 0x31], + [0x3e, 0x28], + [0x3f, 0xb0], + [0x40, 0x90], + [0x41, 0x0f], + [0xfe, 0x02], + [0x90, 0x6c], + [0x91, 0x03], + [0x92, 0xcb], + [0x94, 0x33], + [0x95, 0x84], + [0x97, 0x65], + [0xa2, 0x11], + [0xfe, 0x00], + [0xfe, 0x02], + [0x80, 0xc1], + [0x81, 0x08], + [0x82, 0x05], + [0x83, 0x08], + [0x84, 0x0a], + [0x86, 0xf0], + [0x87, 0x50], + [0x88, 0x15], + [0x89, 0xb0], + [0x8a, 0x30], + [0x8b, 0x10], + [0xfe, 0x01], + [0x21, 0x04], + [0xfe, 0x02], + [0xa3, 0x50], + [0xa4, 0x20], + [0xa5, 0x40], + [0xa6, 0x80], + [0xab, 0x40], + [0xae, 0x0c], + [0xb3, 0x46], + [0xb4, 0x64], + [0xb6, 0x38], + [0xb7, 0x01], + [0xb9, 0x2b], + [0x3c, 0x04], + [0x3d, 0x15], + [0x4b, 0x06], + [0x4c, 0x20], + [0xfe, 0x00], + [0xfe, 0x02], + [0x10, 0x09], + [0x11, 0x0d], + [0x12, 0x13], + [0x13, 0x19], + [0x14, 0x27], + [0x15, 0x37], + [0x16, 0x45], + [0x17, 0x53], + [0x18, 0x69], + [0x19, 0x7d], + [0x1a, 0x8f], + [0x1b, 0x9d], + [0x1c, 0xa9], + [0x1d, 0xbd], + [0x1e, 0xcd], + [0x1f, 0xd9], + [0x20, 0xe3], + [0x21, 0xea], + [0x22, 0xef], + [0x23, 0xf5], + [0x24, 0xf9], + [0x25, 0xff], + [0xfe, 0x00], + [0xc6, 0x20], + [0xc7, 0x2b], + [0xfe, 0x02], + [0x26, 0x0f], + [0x27, 0x14], + [0x28, 0x19], + [0x29, 0x1e], + [0x2a, 0x27], + [0x2b, 0x33], + [0x2c, 0x3b], + [0x2d, 0x45], + [0x2e, 0x59], + [0x2f, 0x69], + [0x30, 0x7c], + [0x31, 0x89], + [0x32, 0x98], + [0x33, 0xae], + [0x34, 0xc0], + [0x35, 0xcf], + [0x36, 0xda], + [0x37, 0xe2], + [0x38, 0xe9], + [0x39, 0xf3], + [0x3a, 0xf9], + [0x3b, 0xff], + [0xfe, 0x02], + [0xd1, 0x32], + [0xd2, 0x32], + [0xd3, 0x40], + [0xd6, 0xf0], + [0xd7, 0x10], + [0xd8, 0xda], + [0xdd, 0x14], + [0xde, 0x86], + [0xed, 0x80], + [0xee, 0x00], + [0xef, 0x3f], + [0xd8, 0xd8], + [0xfe, 0x01], + [0x9f, 0x40], + [0xfe, 0x01], + [0xc2, 0x14], + [0xc3, 0x0d], + [0xc4, 0x0c], + [0xc8, 0x15], + [0xc9, 0x0d], + [0xca, 0x0a], + [0xbc, 0x24], + [0xbd, 0x10], + [0xbe, 0x0b], + [0xb6, 0x25], + [0xb7, 0x16], + [0xb8, 0x15], + [0xc5, 0x00], + [0xc6, 0x00], + [0xc7, 0x00], + [0xcb, 0x00], + [0xcc, 0x00], + [0xcd, 0x00], + [0xbf, 0x07], + [0xc0, 0x00], + [0xc1, 0x00], + [0xb9, 0x00], + [0xba, 0x00], + [0xbb, 0x00], + [0xaa, 0x01], + [0xab, 0x01], + [0xac, 0x00], + [0xad, 0x05], + [0xae, 0x06], + [0xaf, 0x0e], + [0xb0, 0x0b], + [0xb1, 0x07], + [0xb2, 0x06], + [0xb3, 0x17], + [0xb4, 0x0e], + [0xb5, 0x0e], + [0xd0, 0x09], + [0xd1, 0x00], + [0xd2, 0x00], + [0xd6, 0x08], + [0xd7, 0x00], + [0xd8, 0x00], + [0xd9, 0x00], + [0xda, 0x00], + [0xdb, 0x00], + [0xd3, 0x0a], + [0xd4, 0x00], + [0xd5, 0x00], + [0xa4, 0x00], + [0xa5, 0x00], + [0xa6, 0x77], + [0xa7, 0x77], + [0xa8, 0x77], + [0xa9, 0x77], + [0xa1, 0x80], + [0xa2, 0x80], + [0xfe, 0x01], + [0xdf, 0x0d], + [0xdc, 0x25], + [0xdd, 0x30], + [0xe0, 0x77], + [0xe1, 0x80], + [0xe2, 0x77], + [0xe3, 0x90], + [0xe6, 0x90], + [0xe7, 0xa0], + [0xe8, 0x90], + [0xe9, 0xa0], + [0xfe, 0x00], + [0xfe, 0x01], + [0x4f, 0x00], + [0x4f, 0x00], + [0x4b, 0x01], + [0x4f, 0x00], + [0x4c, 0x01], + [0x4d, 0x71], + [0x4e, 0x01], + [0x4c, 0x01], + [0x4d, 0x91], + [0x4e, 0x01], + [0x4c, 0x01], + [0x4d, 0x70], + [0x4e, 0x01], + [0x4c, 0x01], + [0x4d, 0x90], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0xb0], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0x8f], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0x6f], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0xaf], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0xd0], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0xf0], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0xcf], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0xef], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0x6e], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x8e], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xae], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xce], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x4d], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x6d], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x8d], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xad], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xcd], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x4c], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x6c], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x8c], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xac], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xcc], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xcb], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x4b], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x6b], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x8b], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xab], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x8a], + [0x4e, 0x04], + [0x4c, 0x01], + [0x4d, 0xaa], + [0x4e, 0x04], + [0x4c, 0x01], + [0x4d, 0xca], + [0x4e, 0x04], + [0x4c, 0x01], + [0x4d, 0xca], + [0x4e, 0x04], + [0x4c, 0x01], + [0x4d, 0xc9], + [0x4e, 0x04], + [0x4c, 0x01], + [0x4d, 0x8a], + [0x4e, 0x04], + [0x4c, 0x01], + [0x4d, 0x89], + [0x4e, 0x04], + [0x4c, 0x01], + [0x4d, 0xa9], + [0x4e, 0x04], + [0x4c, 0x02], + [0x4d, 0x0b], + [0x4e, 0x05], + [0x4c, 0x02], + [0x4d, 0x0a], + [0x4e, 0x05], + [0x4c, 0x01], + [0x4d, 0xeb], + [0x4e, 0x05], + [0x4c, 0x01], + [0x4d, 0xea], + [0x4e, 0x05], + [0x4c, 0x02], + [0x4d, 0x09], + [0x4e, 0x05], + [0x4c, 0x02], + [0x4d, 0x29], + [0x4e, 0x05], + [0x4c, 0x02], + [0x4d, 0x2a], + [0x4e, 0x05], + [0x4c, 0x02], + [0x4d, 0x4a], + [0x4e, 0x05], + [0x4c, 0x02], + [0x4d, 0x8a], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0x49], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0x69], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0x89], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0xa9], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0x48], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0x68], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0x69], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0xca], + [0x4e, 0x07], + [0x4c, 0x02], + [0x4d, 0xc9], + [0x4e, 0x07], + [0x4c, 0x02], + [0x4d, 0xe9], + [0x4e, 0x07], + [0x4c, 0x03], + [0x4d, 0x09], + [0x4e, 0x07], + [0x4c, 0x02], + [0x4d, 0xc8], + [0x4e, 0x07], + [0x4c, 0x02], + [0x4d, 0xe8], + [0x4e, 0x07], + [0x4c, 0x02], + [0x4d, 0xa7], + [0x4e, 0x07], + [0x4c, 0x02], + [0x4d, 0xc7], + [0x4e, 0x07], + [0x4c, 0x02], + [0x4d, 0xe7], + [0x4e, 0x07], + [0x4c, 0x03], + [0x4d, 0x07], + [0x4e, 0x07], + [0x4f, 0x01], + [0x50, 0x80], + [0x51, 0xa8], + [0x52, 0x47], + [0x53, 0x38], + [0x54, 0xc7], + [0x56, 0x0e], + [0x58, 0x08], + [0x5b, 0x00], + [0x5c, 0x74], + [0x5d, 0x8b], + [0x61, 0xdb], + [0x62, 0xb8], + [0x63, 0x86], + [0x64, 0xc0], + [0x65, 0x04], + [0x67, 0xa8], + [0x68, 0xb0], + [0x69, 0x00], + [0x6a, 0xa8], + [0x6b, 0xb0], + [0x6c, 0xaf], + [0x6d, 0x8b], + [0x6e, 0x50], + [0x6f, 0x18], + [0x73, 0xf0], + [0x70, 0x0d], + [0x71, 0x60], + [0x72, 0x80], + [0x74, 0x01], + [0x75, 0x01], + [0x7f, 0x0c], + [0x76, 0x70], + [0x77, 0x58], + [0x78, 0xa0], + [0x79, 0x5e], + [0x7a, 0x54], + [0x7b, 0x58], + [0xfe, 0x00], + [0xfe, 0x02], + [0xc0, 0x01], + [0xc1, 0x44], + [0xc2, 0xfd], + [0xc3, 0x04], + [0xc4, 0xf0], + [0xc5, 0x48], + [0xc6, 0xfd], + [0xc7, 0x46], + [0xc8, 0xfd], + [0xc9, 0x02], + [0xca, 0xe0], + [0xcb, 0x45], + [0xcc, 0xec], + [0xcd, 0x48], + [0xce, 0xf0], + [0xcf, 0xf0], + [0xe3, 0x0c], + [0xe4, 0x4b], + [0xe5, 0xe0], + [0xfe, 0x01], + [0x9f, 0x40], + [0xfe, 0x00], + [0xfe, 0x02], + [0x40, 0xbf], + [0x46, 0xcf], + [0xfe, 0x00], + [0xfe, 0x00], + [0x05, 0x01], + [0x06, 0x56], + [0x07, 0x00], + [0x08, 0x10], + [0xfe, 0x01], + [0x25, 0x00], + [0x26, 0xfa], + [0x27, 0x04], + [0x28, 0xe2], + [0x29, 0x04], + [0x2a, 0xe2], + [0x2b, 0x04], + [0x2c, 0xe2], + [0x2d, 0x04], + [0x2e, 0xe2], + [0xfe, 0x00], + [0xfe, 0x00], + [0xf2, 0x00], + [0xfe, 0x03], + [0x01, 0x87], + [0x02, 0x22], + [0x03, 0x10], + [0x06, 0x88], + [0x10, 0x95], + [0x11, 0x1e], + [0x15, 0x10], + [0x22, 0x04], + [0x23, 0x10], + [0x24, 0x10], + [0x25, 0x10], + [0x26, 0x05], + [0x21, 0x10], + [0x29, 0x03], + [0x2a, 0x0a], + [0x2b, 0x06], + [0xfe, 0x00], + [0xfe, 0x00], + [0x84, 0x02], + [0x86, 0x02], + [0x86, 0x02], + [0xfe, 0x03], + [0x13, 0x0c], + [0x12, 0x80], + [0x05, 0x00], + [0x04, 0x01], + [0x17, 0xf0], + [0x11, 0x1e], + [0xfe, 0x00], + [0x8c, 0x00], + [0x8d, 0x00], + [0x17, 0x14], + [0x17, 0x14], +]; + +pub(crate) const GC2145_INIT_3: [[u8; 2]; 673] = [ + [0xfe, 0xf0], + [0xfe, 0xf0], + [0xfe, 0xf0], + [0xfc, 0x06], + [0xf6, 0x00], + [0xf7, 0x1d], + [0xf8, 0x86], + [0xfa, 0x00], + [0xf9, 0x8e], + [0xf2, 0x00], + [0xfe, 0x00], + [0x03, 0x04], + [0x04, 0xe2], + [0x09, 0x00], + [0x0a, 0x00], + [0x0b, 0x00], + [0x0c, 0x00], + [0x0d, 0x04], + [0x0e, 0xc0], + [0x0f, 0x06], + [0x10, 0x52], + [0x12, 0x2e], + [0x17, 0x14], + [0x18, 0x22], + [0x19, 0x0e], + [0x1a, 0x01], + [0x1b, 0x4b], + [0x1c, 0x07], + [0x1d, 0x10], + [0x1e, 0x88], + [0x1f, 0x78], + [0x20, 0x03], + [0x21, 0x40], + [0x22, 0xa0], + [0x24, 0x16], + [0x25, 0x01], + [0x26, 0x10], + [0x2d, 0x60], + [0x30, 0x01], + [0x31, 0x90], + [0x33, 0x06], + [0x34, 0x01], + [0xfe, 0x00], + [0x80, 0x7f], + [0x81, 0x26], + [0x82, 0xfa], + [0x83, 0x00], + [0x84, 0x02], + [0x86, 0x02], + [0x88, 0x03], + [0x89, 0x03], + [0x85, 0x08], + [0x8a, 0x00], + [0x8b, 0x00], + [0xb0, 0x55], + [0xc3, 0x00], + [0xc4, 0x80], + [0xc5, 0x90], + [0xc6, 0x3b], + [0xc7, 0x46], + [0xec, 0x06], + [0xed, 0x04], + [0xee, 0x60], + [0xef, 0x90], + [0xb6, 0x01], + [0x90, 0x01], + [0x91, 0x00], + [0x92, 0x00], + [0x93, 0x00], + [0x94, 0x00], + [0x95, 0x04], + [0x96, 0xb0], + [0x97, 0x06], + [0x98, 0x40], + [0xfe, 0x00], + [0x40, 0x42], + [0x41, 0x00], + [0x43, 0x5b], + [0x5e, 0x00], + [0x5f, 0x00], + [0x60, 0x00], + [0x61, 0x00], + [0x62, 0x00], + [0x63, 0x00], + [0x64, 0x00], + [0x65, 0x00], + [0x66, 0x20], + [0x67, 0x20], + [0x68, 0x20], + [0x69, 0x20], + [0x76, 0x00], + [0x6a, 0x08], + [0x6b, 0x08], + [0x6c, 0x08], + [0x6d, 0x08], + [0x6e, 0x08], + [0x6f, 0x08], + [0x70, 0x08], + [0x71, 0x08], + [0x76, 0x00], + [0x72, 0xf0], + [0x7e, 0x3c], + [0x7f, 0x00], + [0xfe, 0x02], + [0x48, 0x15], + [0x49, 0x00], + [0x4b, 0x0b], + [0xfe, 0x00], + [0xfe, 0x01], + [0x01, 0x04], + [0x02, 0xc0], + [0x03, 0x04], + [0x04, 0x90], + [0x05, 0x30], + [0x06, 0x90], + [0x07, 0x30], + [0x08, 0x80], + [0x09, 0x00], + [0x0a, 0x82], + [0x0b, 0x11], + [0x0c, 0x10], + [0x11, 0x10], + [0x13, 0x7b], + [0x17, 0x00], + [0x1c, 0x11], + [0x1e, 0x61], + [0x1f, 0x35], + [0x20, 0x40], + [0x22, 0x40], + [0x23, 0x20], + [0xfe, 0x02], + [0x0f, 0x04], + [0xfe, 0x01], + [0x12, 0x35], + [0x15, 0xb0], + [0x10, 0x31], + [0x3e, 0x28], + [0x3f, 0xb0], + [0x40, 0x90], + [0x41, 0x0f], + [0xfe, 0x02], + [0x90, 0x6c], + [0x91, 0x03], + [0x92, 0xcb], + [0x94, 0x33], + [0x95, 0x84], + [0x97, 0x65], + [0xa2, 0x11], + [0xfe, 0x00], + [0xfe, 0x02], + [0x80, 0xc1], + [0x81, 0x08], + [0x82, 0x05], + [0x83, 0x08], + [0x84, 0x0a], + [0x86, 0xf0], + [0x87, 0x50], + [0x88, 0x15], + [0x89, 0xb0], + [0x8a, 0x30], + [0x8b, 0x10], + [0xfe, 0x01], + [0x21, 0x04], + [0xfe, 0x02], + [0xa3, 0x50], + [0xa4, 0x20], + [0xa5, 0x40], + [0xa6, 0x80], + [0xab, 0x40], + [0xae, 0x0c], + [0xb3, 0x46], + [0xb4, 0x64], + [0xb6, 0x38], + [0xb7, 0x01], + [0xb9, 0x2b], + [0x3c, 0x04], + [0x3d, 0x15], + [0x4b, 0x06], + [0x4c, 0x20], + [0xfe, 0x00], + [0xfe, 0x02], + [0x10, 0x09], + [0x11, 0x0d], + [0x12, 0x13], + [0x13, 0x19], + [0x14, 0x27], + [0x15, 0x37], + [0x16, 0x45], + [0x17, 0x53], + [0x18, 0x69], + [0x19, 0x7d], + [0x1a, 0x8f], + [0x1b, 0x9d], + [0x1c, 0xa9], + [0x1d, 0xbd], + [0x1e, 0xcd], + [0x1f, 0xd9], + [0x20, 0xe3], + [0x21, 0xea], + [0x22, 0xef], + [0x23, 0xf5], + [0x24, 0xf9], + [0x25, 0xff], + [0xfe, 0x00], + [0xc6, 0x20], + [0xc7, 0x2b], + [0xfe, 0x02], + [0x26, 0x0f], + [0x27, 0x14], + [0x28, 0x19], + [0x29, 0x1e], + [0x2a, 0x27], + [0x2b, 0x33], + [0x2c, 0x3b], + [0x2d, 0x45], + [0x2e, 0x59], + [0x2f, 0x69], + [0x30, 0x7c], + [0x31, 0x89], + [0x32, 0x98], + [0x33, 0xae], + [0x34, 0xc0], + [0x35, 0xcf], + [0x36, 0xda], + [0x37, 0xe2], + [0x38, 0xe9], + [0x39, 0xf3], + [0x3a, 0xf9], + [0x3b, 0xff], + [0xfe, 0x02], + [0xd1, 0x32], + [0xd2, 0x32], + [0xd3, 0x40], + [0xd6, 0xf0], + [0xd7, 0x10], + [0xd8, 0xda], + [0xdd, 0x14], + [0xde, 0x86], + [0xed, 0x80], + [0xee, 0x00], + [0xef, 0x3f], + [0xd8, 0xd8], + [0xfe, 0x01], + [0x9f, 0x40], + [0xfe, 0x01], + [0xc2, 0x14], + [0xc3, 0x0d], + [0xc4, 0x0c], + [0xc8, 0x15], + [0xc9, 0x0d], + [0xca, 0x0a], + [0xbc, 0x24], + [0xbd, 0x10], + [0xbe, 0x0b], + [0xb6, 0x25], + [0xb7, 0x16], + [0xb8, 0x15], + [0xc5, 0x00], + [0xc6, 0x00], + [0xc7, 0x00], + [0xcb, 0x00], + [0xcc, 0x00], + [0xcd, 0x00], + [0xbf, 0x07], + [0xc0, 0x00], + [0xc1, 0x00], + [0xb9, 0x00], + [0xba, 0x00], + [0xbb, 0x00], + [0xaa, 0x01], + [0xab, 0x01], + [0xac, 0x00], + [0xad, 0x05], + [0xae, 0x06], + [0xaf, 0x0e], + [0xb0, 0x0b], + [0xb1, 0x07], + [0xb2, 0x06], + [0xb3, 0x17], + [0xb4, 0x0e], + [0xb5, 0x0e], + [0xd0, 0x09], + [0xd1, 0x00], + [0xd2, 0x00], + [0xd6, 0x08], + [0xd7, 0x00], + [0xd8, 0x00], + [0xd9, 0x00], + [0xda, 0x00], + [0xdb, 0x00], + [0xd3, 0x0a], + [0xd4, 0x00], + [0xd5, 0x00], + [0xa4, 0x00], + [0xa5, 0x00], + [0xa6, 0x77], + [0xa7, 0x77], + [0xa8, 0x77], + [0xa9, 0x77], + [0xa1, 0x80], + [0xa2, 0x80], + [0xfe, 0x01], + [0xdf, 0x0d], + [0xdc, 0x25], + [0xdd, 0x30], + [0xe0, 0x77], + [0xe1, 0x80], + [0xe2, 0x77], + [0xe3, 0x90], + [0xe6, 0x90], + [0xe7, 0xa0], + [0xe8, 0x90], + [0xe9, 0xa0], + [0xfe, 0x00], + [0xfe, 0x01], + [0x4f, 0x00], + [0x4f, 0x00], + [0x4b, 0x01], + [0x4f, 0x00], + [0x4c, 0x01], + [0x4d, 0x71], + [0x4e, 0x01], + [0x4c, 0x01], + [0x4d, 0x91], + [0x4e, 0x01], + [0x4c, 0x01], + [0x4d, 0x70], + [0x4e, 0x01], + [0x4c, 0x01], + [0x4d, 0x90], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0xb0], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0x8f], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0x6f], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0xaf], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0xd0], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0xf0], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0xcf], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0xef], + [0x4e, 0x02], + [0x4c, 0x01], + [0x4d, 0x6e], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x8e], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xae], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xce], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x4d], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x6d], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x8d], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xad], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xcd], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x4c], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x6c], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x8c], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xac], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xcc], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xcb], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x4b], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x6b], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x8b], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0xab], + [0x4e, 0x03], + [0x4c, 0x01], + [0x4d, 0x8a], + [0x4e, 0x04], + [0x4c, 0x01], + [0x4d, 0xaa], + [0x4e, 0x04], + [0x4c, 0x01], + [0x4d, 0xca], + [0x4e, 0x04], + [0x4c, 0x01], + [0x4d, 0xca], + [0x4e, 0x04], + [0x4c, 0x01], + [0x4d, 0xc9], + [0x4e, 0x04], + [0x4c, 0x01], + [0x4d, 0x8a], + [0x4e, 0x04], + [0x4c, 0x01], + [0x4d, 0x89], + [0x4e, 0x04], + [0x4c, 0x01], + [0x4d, 0xa9], + [0x4e, 0x04], + [0x4c, 0x02], + [0x4d, 0x0b], + [0x4e, 0x05], + [0x4c, 0x02], + [0x4d, 0x0a], + [0x4e, 0x05], + [0x4c, 0x01], + [0x4d, 0xeb], + [0x4e, 0x05], + [0x4c, 0x01], + [0x4d, 0xea], + [0x4e, 0x05], + [0x4c, 0x02], + [0x4d, 0x09], + [0x4e, 0x05], + [0x4c, 0x02], + [0x4d, 0x29], + [0x4e, 0x05], + [0x4c, 0x02], + [0x4d, 0x2a], + [0x4e, 0x05], + [0x4c, 0x02], + [0x4d, 0x4a], + [0x4e, 0x05], + [0x4c, 0x02], + [0x4d, 0x8a], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0x49], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0x69], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0x89], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0xa9], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0x48], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0x68], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0x69], + [0x4e, 0x06], + [0x4c, 0x02], + [0x4d, 0xca], + [0x4e, 0x07], + [0x4c, 0x02], + [0x4d, 0xc9], + [0x4e, 0x07], + [0x4c, 0x02], + [0x4d, 0xe9], + [0x4e, 0x07], + [0x4c, 0x03], + [0x4d, 0x09], + [0x4e, 0x07], + [0x4c, 0x02], + [0x4d, 0xc8], + [0x4e, 0x07], + [0x4c, 0x02], + [0x4d, 0xe8], + [0x4e, 0x07], + [0x4c, 0x02], + [0x4d, 0xa7], + [0x4e, 0x07], + [0x4c, 0x02], + [0x4d, 0xc7], + [0x4e, 0x07], + [0x4c, 0x02], + [0x4d, 0xe7], + [0x4e, 0x07], + [0x4c, 0x03], + [0x4d, 0x07], + [0x4e, 0x07], + [0x4f, 0x01], + [0x50, 0x80], + [0x51, 0xa8], + [0x52, 0x47], + [0x53, 0x38], + [0x54, 0xc7], + [0x56, 0x0e], + [0x58, 0x08], + [0x5b, 0x00], + [0x5c, 0x74], + [0x5d, 0x8b], + [0x61, 0xdb], + [0x62, 0xb8], + [0x63, 0x86], + [0x64, 0xc0], + [0x65, 0x04], + [0x67, 0xa8], + [0x68, 0xb0], + [0x69, 0x00], + [0x6a, 0xa8], + [0x6b, 0xb0], + [0x6c, 0xaf], + [0x6d, 0x8b], + [0x6e, 0x50], + [0x6f, 0x18], + [0x73, 0xf0], + [0x70, 0x0d], + [0x71, 0x60], + [0x72, 0x80], + [0x74, 0x01], + [0x75, 0x01], + [0x7f, 0x0c], + [0x76, 0x70], + [0x77, 0x58], + [0x78, 0xa0], + [0x79, 0x5e], + [0x7a, 0x54], + [0x7b, 0x58], + [0xfe, 0x00], + [0xfe, 0x02], + [0xc0, 0x01], + [0xc1, 0x44], + [0xc2, 0xfd], + [0xc3, 0x04], + [0xc4, 0xf0], + [0xc5, 0x48], + [0xc6, 0xfd], + [0xc7, 0x46], + [0xc8, 0xfd], + [0xc9, 0x02], + [0xca, 0xe0], + [0xcb, 0x45], + [0xcc, 0xec], + [0xcd, 0x48], + [0xce, 0xf0], + [0xcf, 0xf0], + [0xe3, 0x0c], + [0xe4, 0x4b], + [0xe5, 0xe0], + [0xfe, 0x01], + [0x9f, 0x40], + [0xfe, 0x00], + [0xfe, 0x02], + [0x40, 0xbf], + [0x46, 0xcf], + [0xfe, 0x00], + [0xfe, 0x00], + [0x05, 0x01], + [0x06, 0x30], + [0x07, 0x00], + [0x08, 0x0c], + [0xfe, 0x01], + [0x25, 0x01], + [0x26, 0x75], + [0x27, 0x04], + [0x28, 0x5f], + [0x29, 0x04], + [0x2a, 0x5f], + [0x2b, 0x04], + [0x2c, 0x5f], + [0x2d, 0x04], + [0x2e, 0x5f], + [0xfe, 0x00], + [0xfe, 0x00], + [0xf2, 0x00], + [0xfe, 0x03], + [0x02, 0x22], + [0x03, 0x10], + [0x06, 0x88], + [0x01, 0x87], + [0x10, 0x95], + [0x11, 0x1e], + [0x15, 0x10], + [0x22, 0x04], + [0x23, 0x10], + [0x24, 0x10], + [0x25, 0x10], + [0x26, 0x05], + [0x21, 0x10], + [0x29, 0x03], + [0x2a, 0x0a], + [0x2b, 0x06], + [0xfe, 0x00], + [0xfe, 0x00], + [0xfd, 0x01], + [0xfa, 0x00], + [0xfe, 0x00], + [0x90, 0x01], + [0x91, 0x00], + [0x92, 0x00], + [0x93, 0x00], + [0x94, 0x00], + [0x95, 0x01], + [0x96, 0xe0], + [0x97, 0x02], + [0x98, 0x80], + [0x99, 0x55], + [0x9a, 0x06], + [0x9b, 0x01], + [0x9c, 0x23], + [0x9d, 0x00], + [0x9e, 0x00], + [0x9f, 0x01], + [0xa0, 0x23], + [0xa1, 0x00], + [0xa2, 0x00], + [0xfe, 0x00], + [0xec, 0x06], + [0xed, 0x04], + [0xee, 0x60], + [0xef, 0x90], + [0xfe, 0x01], + [0x74, 0x01], + [0xfe, 0x01], + [0x01, 0x04], + [0x02, 0xc0], + [0x03, 0x04], + [0x04, 0x90], + [0x05, 0x30], + [0x06, 0x90], + [0x07, 0x30], + [0x08, 0x80], + [0x0a, 0x82], + [0xfe, 0x01], + [0x21, 0x04], + [0xfe, 0x00], + [0x84, 0x06], + [0xfe, 0x03], + [0x13, 0x05], + [0x12, 0x00], + [0x05, 0x01], + [0x04, 0x90], + [0x17, 0xf0], + [0x11, 0x22], + [0xfe, 0x00], + [0x8c, 0x00], + [0x8d, 0x00], + [0x17, 0x14], + [0x17, 0x14], +]; + +pub(crate) const GC2145_AEC: [[u8; 2]; 35] = [ + [0xfe, 0x00], + [0x03, 0x04], // default exposure msb + [0x04, 0xe2], // default exposure lsb + [0xfe, 0x01], + [0x01, 0x04], + [0x02, 0xc0], + [0x03, 0x04], + [0x04, 0x90], + [0x05, 0x30], + [0x06, 0x90], + [0x07, 0x30], + [0x08, 0x80], + [0x09, 0x00], + [0x0a, 0x82], + [0x0b, 0x11], + [0x0c, 0x10], + [0x11, 0x10], + [0x13, 0x7b], + [0x17, 0x00], + [0x1c, 0x11], + [0x1e, 0x61], + [0x1f, 0x35], + [0x20, 0x40], + [0x22, 0x40], + [0x23, 0x20], + [0xfe, 0x02], + [0x0f, 0x04], + [0xfe, 0x01], + [0x12, 0x35], + [0x15, 0xb0], + [0x10, 0x31], + [0x3e, 0x28], + [0x3f, 0xb0], + [0x40, 0x90], + [0x41, 0x0f], +]; From 19e9bcb1041c9a603d05e1ddb26f1ba5b466f3a0 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 1 May 2025 04:08:06 +0800 Subject: [PATCH 02/12] add emulation stub for gc2145 --- services/cramium-emu/src/camera.rs | 81 ++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/services/cramium-emu/src/camera.rs b/services/cramium-emu/src/camera.rs index 0bb67b616..4b05227ef 100644 --- a/services/cramium-emu/src/camera.rs +++ b/services/cramium-emu/src/camera.rs @@ -1,3 +1,4 @@ +#![allow(dead_code)] use cramium_api::camera; use cramium_api::*; @@ -83,3 +84,83 @@ impl Ov2640 { std::thread::sleep(std::time::Duration::from_millis(quantum as u64)); } } + +#[repr(C)] +pub struct Gc2145 { + frame: [u16; EMU_COLS * EMU_ROWS], +} + +impl Gc2145 { + /// Safety: clocks must be turned on before this is called + pub unsafe fn new() -> Result { Ok(Self { frame: [0u16; EMU_COLS * EMU_ROWS] }) } + + pub fn release_ifram(&mut self) {} + + pub fn claim_ifram(&mut self) -> Result<(), xous::Error> { Ok(()) } + + pub fn has_ifram(&self) -> bool { false } + + pub fn poke(&self, _i2c: &mut dyn I2cApi, _adr: u8, _dat: u8) {} + + // chip does not support sequential reads + pub fn peek(&self, _i2c: &mut dyn I2cApi, _adr: u8, _dat: &mut [u8]) {} + + pub fn init(&mut self, _i2c: &mut dyn I2cApi, _resolution: camera::Resolution) {} + + /// Safety: definitely not safe, but only used in emulation mode so I'm not going to worry about it too + /// much. + pub fn rx_buf(&self) -> &[T] { + unsafe { + core::slice::from_raw_parts( + self.frame.as_ptr() as *const T, + self.frame.len() / core::mem::size_of::(), + ) + } + } + + /// Safety: definitely not safe, but only used in emulation mode so I'm not going to worry about it too + /// much. + pub unsafe fn rx_buf_phys(&self) -> &[T] { + unsafe { + core::slice::from_raw_parts( + self.frame.as_ptr() as *const T, + self.frame.len() / core::mem::size_of::(), + ) + } + } + + pub fn capture_async(&mut self) {} + + pub fn capture_await(&mut self, _use_yield: bool) {} + + /// For emulation, we fix the resolution at 320x240 + pub fn resolution(&self) -> (usize, usize) { (EMU_COLS, EMU_ROWS) } + + pub fn set_slicing(&mut self, _ll: (usize, usize), _ur: (usize, usize)) {} + + pub fn disable_slicing(&mut self) {} + + // Commented out to avoid leaking the ColorMode type + // pub fn color_mode(&mut self, _i2c: &mut dyn I2cApi, _mode: ColorMode) {} + + // Commented out to avoid leaking the Contrast & Brightness types + /* + pub fn contrast_brightness( + &mut self, + _i2c: &mut dyn I2cApi, + _contrast: Contrast, + _brightness: Brightness, + ) { + } + */ + + // Commented out to avoid leaking the Effect types + // pub fn effect(&mut self, _i2c: &mut dyn I2cApi, _effect: Effect) {} + + /// Returns (product ID, manufacturer ID) - hard coded to match GC2145 values + pub fn read_id(&self, _i2c: &mut dyn I2cApi) -> (u16, u16) { (0x2155, 0x0078) } + + pub fn delay(&self, quantum: usize) { + std::thread::sleep(std::time::Duration::from_millis(quantum as u64)); + } +} From d7aafc6c50e682d63cff5e277dfa5a739666ce9f Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 1 May 2025 04:08:37 +0800 Subject: [PATCH 03/12] put yuv mode into the ov2640 driver directly --- libs/cramium-hal/src/ov2640/ov2640.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libs/cramium-hal/src/ov2640/ov2640.rs b/libs/cramium-hal/src/ov2640/ov2640.rs index f58d599a4..728d19e74 100644 --- a/libs/cramium-hal/src/ov2640/ov2640.rs +++ b/libs/cramium-hal/src/ov2640/ov2640.rs @@ -155,6 +155,10 @@ impl Ov2640 { } self.resolution = resolution; + // Setup YUV output mode + self.poke(&mut i2c, 0xFF, 0x00); + self.poke(&mut i2c, 0xDA, 0x01); // YUV LE + // set sync polarity let vsync_pol = 0; let hsync_pol = match resolution { From 0ca3caf917e4da5e0e0637ab83a917cbf8d55ce4 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 1 May 2025 04:09:00 +0800 Subject: [PATCH 04/12] add gc2145 module --- libs/cramium-hal/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libs/cramium-hal/src/lib.rs b/libs/cramium-hal/src/lib.rs index 2e537cd06..af4395209 100644 --- a/libs/cramium-hal/src/lib.rs +++ b/libs/cramium-hal/src/lib.rs @@ -5,6 +5,8 @@ pub mod debug; #[cfg(feature = "axp2101")] pub mod axp2101; pub mod board; +#[cfg(feature = "camera-gc2145")] +pub mod gc2145; pub mod ifram; pub mod iox; #[cfg(feature = "camera-ov2640")] From 6d1a362735e144bc13d00283d5dd80996b7a3e15 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 1 May 2025 04:09:17 +0800 Subject: [PATCH 05/12] add gc2145 to cargo file --- libs/cramium-hal/Cargo.toml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/libs/cramium-hal/Cargo.toml b/libs/cramium-hal/Cargo.toml index e52077aad..7c1f48eb2 100644 --- a/libs/cramium-hal/Cargo.toml +++ b/libs/cramium-hal/Cargo.toml @@ -29,21 +29,27 @@ xous = { version = "0.9.64", features = ["v2p"] } [features] camera-ov2640 = [] +camera-gc2145 = [] display-sh1107 = [] axp2101 = [] cramium-soc = ["utralib/cramium-soc"] board-baosec = [ - "camera-ov2640", + "camera-gc2145", "display-sh1107", "axp2101", "utralib/cramium-soc", "ux-api/board-baosec", ] # USB form factor token -loader-baosec = ["camera-ov2640", "display-sh1107", "axp2101", "ux-api/loader-baosec"] -test-baosec = ["ux-api/loader-baosec", "camera-ov2640"] +loader-baosec = [ + "camera-gc2145", + "display-sh1107", + "axp2101", + "ux-api/loader-baosec", +] +test-baosec = ["ux-api/loader-baosec", "camera-gc2145"] hosted-baosec = [] # emulated hardware on x86 platform board-baosor = [ - "camera-ov2640", + "camera-gc2145", "axp2101", "utralib/cramium-soc", ] # Precursor form factor From 6fdf868b4449cd6aabce89ba3c76a2649d677701 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 1 May 2025 04:09:36 +0800 Subject: [PATCH 06/12] make camera pins generic --- libs/cramium-hal/src/board/baosec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/cramium-hal/src/board/baosec.rs b/libs/cramium-hal/src/board/baosec.rs index 24f38c293..db564338c 100644 --- a/libs/cramium-hal/src/board/baosec.rs +++ b/libs/cramium-hal/src/board/baosec.rs @@ -192,7 +192,7 @@ pub fn setup_i2c_pins(iox: &dyn IoSetup) -> I2cChannel { } /// returns the power-down port and pin number -pub fn setup_ov2640_pins(iox: &T) -> (IoxPort, u8) { +pub fn setup_camera_pins(iox: &T) -> (IoxPort, u8) { // power-down pin - default to powered down iox.set_gpio_pin_value(IoxPort::PC, 14, IoxValue::High); iox.setup_pin( From 535153e0cb892f1317745c0d4a55f87625cb4da1 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 1 May 2025 04:09:52 +0800 Subject: [PATCH 07/12] switch cameras and move YUV setting into driver --- services/bao-video/src/main.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/services/bao-video/src/main.rs b/services/bao-video/src/main.rs index 25688f561..32ac03582 100644 --- a/services/bao-video/src/main.rs +++ b/services/bao-video/src/main.rs @@ -23,7 +23,7 @@ use cram_hal_service::{I2c, UdmaGlobal}; use cramium_api::*; #[cfg(feature = "hosted-baosec")] use cramium_emu::{ - camera::Ov2640, + camera::Gc2145, display::{MainThreadToken, Mono, Oled128x128, claim_main_thread}, i2c::I2c, udma::UdmaGlobal, @@ -32,7 +32,7 @@ use cramium_emu::{ // - For GC0308 drivers, look in code/esp32-camera for sample code/constants #[cfg(feature = "board-baosec")] use cramium_hal::{ - ov2640::Ov2640, + gc2145::Gc2145, sh1107::{MainThreadToken, Mono, Oled128x128, claim_main_thread}, }; #[cfg(feature = "board-baosec")] @@ -235,21 +235,19 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! { #[cfg(not(feature = "hosted-baosec"))] { // setup camera pins - let (cam_pdwn_bnk, cam_pdwn_pin) = cramium_hal::board::setup_ov2640_pins(&iox); + let (cam_pdwn_bnk, cam_pdwn_pin) = cramium_hal::board::setup_camera_pins(&iox); // disable camera powerdown iox.set_gpio_pin_value(cam_pdwn_bnk, cam_pdwn_pin, IoxValue::Low); } udma_global.udma_clock_config(PeriphId::Cam, true); // this is safe because we turned on the clocks before calling it - let mut cam = unsafe { Ov2640::new().expect("couldn't allocate camera") }; + let mut cam = unsafe { Gc2145::new().expect("couldn't allocate camera") }; tt.sleep_ms(100).ok(); let (pid, mid) = cam.read_id(&mut i2c); log::info!("Camera pid {:x}, mid {:x}", pid, mid); cam.init(&mut i2c, cramium_api::camera::Resolution::Res320x240); - cam.poke(&mut i2c, 0xFF, 0x00); - cam.poke(&mut i2c, 0xDA, 0x01); // YUV LE tt.sleep_ms(1).ok(); let (cols, _rows) = cam.resolution(); From 7ee15b874d6542adead80e749d96db0e139031f8 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 1 May 2025 16:40:46 +0800 Subject: [PATCH 08/12] cleanup on the gc2145 driver --- libs/cramium-hal/src/gc2145/gc2145.rs | 12 +++++++----- libs/cramium-hal/src/gc2145/tables.rs | 1 + 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/libs/cramium-hal/src/gc2145/gc2145.rs b/libs/cramium-hal/src/gc2145/gc2145.rs index 1817677c4..83c697e02 100644 --- a/libs/cramium-hal/src/gc2145/gc2145.rs +++ b/libs/cramium-hal/src/gc2145/gc2145.rs @@ -180,9 +180,11 @@ impl Gc2145 { self.delay(30); - // divide the clock down - self.poke(i2c, 0xFA, 0x32); - // self.poke(i2c, 0xFA, 0x63); + // divide the clock down, so that the system can keep up. + // self.poke(i2c, 0xFA, 0x32); // this offers a higher frame rate, but a greater bus congestion - + // maybe available on NTO + // self.poke(i2c, 0xFA, 0x63); // this is necessary for MPW due to SPI backpressure bug + self.poke(i2c, 0xFA, 0x52); // this is necessary for MPW due to SPI backpressure bug } #[inline(never)] @@ -191,11 +193,11 @@ impl Gc2145 { self.poke(i2c, GC2145_REG_RESET, GC2145_REG_SW_RESET); self.delay(300); // wait for reset - // do the init pokes + // do the init pokes, these settings are from the zephyr-OS reference code for &[adr, dat] in GC2145_INIT.iter() { self.poke(i2c, adr, dat); } - // setup AEC + // setup AEC, these settings are yanked out of the Linux kernel for &[adr, dat] in GC2145_AEC.iter() { self.poke(i2c, adr, dat); } diff --git a/libs/cramium-hal/src/gc2145/tables.rs b/libs/cramium-hal/src/gc2145/tables.rs index a98bc5fb8..66703d340 100644 --- a/libs/cramium-hal/src/gc2145/tables.rs +++ b/libs/cramium-hal/src/gc2145/tables.rs @@ -1,3 +1,4 @@ +#![allow(dead_code)] /* The constant tables below are derived from https://github.com/zephyrproject-rtos/zephyr/blob/main/drivers/video/gc2145.c with the following license: From 2699146d62f3db684a389f9ad35af42f6427eecf Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 1 May 2025 16:41:03 +0800 Subject: [PATCH 09/12] integrate gc2145 into userspace couple of notes: - bw threshold is now dynamic, based on the average of the previous frame - performance is a bit slower than ideal, because of the SPI back pressure bug preventing us from reading out the video at full speed. This should be better on NTO. - rotation introduced so that the preview image should align up with what we'll have in the final camera v. display orientation in the baosec product - tested against the TOTP test suite (edent.codeberg.page/TOTP_Test_Suite/) and it can quickly capture all of the basic valid tests. --- services/bao-video/src/main.rs | 38 ++++++++++++++++++------------- services/bao-video/src/modules.rs | 7 +++--- 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/services/bao-video/src/main.rs b/services/bao-video/src/main.rs index 32ac03582..2c385f84c 100644 --- a/services/bao-video/src/main.rs +++ b/services/bao-video/src/main.rs @@ -64,7 +64,6 @@ use xous_ipc::Buffer; pub const IMAGE_WIDTH: usize = 256; pub const IMAGE_HEIGHT: usize = 240; -pub const BW_THRESH: u8 = 128; // Next steps for performance improvement: // @@ -77,25 +76,29 @@ pub const BW_THRESH: u8 = 128; /// This converts a frame of `[u8]` grayscale pixels that may be larger than the native /// frame buffer resolution into a black and white bitmap. -pub fn blit_to_display(display: &mut Oled128x128, frame: &[u8], display_cleared: bool) { +pub fn blit_to_display(display: &mut Oled128x128, frame: &[u8], display_cleared: bool, bw_thresh: &mut u8) { + let mut sum: u32 = 0; + let mut count: u32 = 0; for (y, row) in frame.chunks(IMAGE_WIDTH).enumerate() { if y & 1 == 0 { // skip every other line for (x, &pixval) in row.iter().enumerate() { if x & 1 == 0 { // skip every other pixel - if x < display.dimensions().x as usize * 2 - && y < display.dimensions().y as usize * 2 - (gfx::CHAR_HEIGHT as usize + 1) * 2 + if y < display.dimensions().x as usize * 2 + && x < display.dimensions().y as usize * 2 - (gfx::CHAR_HEIGHT as usize + 1) * 2 { let luminance = pixval & 0xff; - if luminance > BW_THRESH { - display.put_pixel(Point::new(x as isize / 2, y as isize / 2), Mono::White.into()); + sum += luminance as u32; + count += 1; + if luminance > *bw_thresh { + display.put_pixel(Point::new(y as isize / 2, x as isize / 2), Mono::White.into()); } else { // optimization to avoid some computation if we're blitting to an already-black // buffer if !display_cleared { display.put_pixel( - Point::new(x as isize / 2, y as isize / 2), + Point::new(y as isize / 2, x as isize / 2), Mono::Black.into(), ); } @@ -107,6 +110,7 @@ pub fn blit_to_display(display: &mut Oled128x128, frame: &[u8], display_cleared: } } } + *bw_thresh = (sum / count) as u8; } #[repr(align(32))] @@ -310,6 +314,7 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! { let mut msg_opt = None; #[cfg(feature = "gfx-testing")] testing::tests(); + let mut bw_thresh: u8 = 128; loop { if !is_panic.load(Ordering::Relaxed) { xous::reply_and_receive_next(sid, &mut msg_opt).unwrap(); @@ -337,9 +342,9 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! { for (y_src, line) in fb.chunks(IMAGE_WIDTH / 2).enumerate() { for (x_src, &u32src) in line.iter().enumerate() { frame[(IMAGE_HEIGHT - y_src - 1) * IMAGE_WIDTH + 2 * x_src] = - (u32src & 0xff) as u8; + ((u32src >> 8) & 0xff) as u8; frame[(IMAGE_HEIGHT - y_src - 1) * IMAGE_WIDTH + 2 * x_src + 1] = - ((u32src >> 16) & 0xff) as u8; + ((u32src >> 24) & 0xff) as u8; } } frames += 1; @@ -348,7 +353,7 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! { decode_success = false; log::info!("------------- SEARCH {} -----------", frames); let finder_width = - qr::find_finders(&mut candidates, &frame, BW_THRESH, IMAGE_WIDTH) as isize; + qr::find_finders(&mut candidates, &frame, bw_thresh, IMAGE_WIDTH) as isize; if candidates.len() == 3 { let candidates_orig = candidates.clone(); let mut x_candidates: [Point; 3] = [Point::new(0, 0); 3]; @@ -363,7 +368,7 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! { as usize, ) { let dims = Point::new(IMAGE_WIDTH as isize, IMAGE_HEIGHT as isize); - let mut il = qr::ImageRoi::new(&mut frame, dims, BW_THRESH); + let mut il = qr::ImageRoi::new(&mut frame, dims, bw_thresh); let (src, dst) = qr_corners.mapping(&mut il, qr::HOMOGRAPHY_MARGIN); let mut src_f: [(f32, f32); 4] = [(0.0, 0.0); 4]; let mut dst_f: [(f32, f32); 4] = [(0.0, 0.0); 4]; @@ -448,7 +453,7 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! { *dst = src; } } - blit_to_display(&mut display, &frame, true); + blit_to_display(&mut display, &frame, true, &mut bw_thresh); // we now have a QR code in "canonical" orientation, with a // known width in pixels @@ -459,7 +464,7 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! { // Confirm that the finders coordinates are valid let mut checked_candidates = Vec::::new(); let x_finder_width = - qr::find_finders(&mut checked_candidates, &aligned, BW_THRESH, qr_width as _) + qr::find_finders(&mut checked_candidates, &aligned, bw_thresh, qr_width as _) as isize; log::info!("x_finder width: {}", x_finder_width); @@ -492,13 +497,14 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! { let qr = qr::ImageRoi::new( &mut aligned, Point::new(qr_width as _, qr_width as _), - BW_THRESH, + bw_thresh, ); let grid = modules::stream_to_grid( &qr, qr_width, modules, qr::HOMOGRAPHY_MARGIN.abs() as usize, + bw_thresh, ); println!("grid len {}", grid.len()); @@ -558,7 +564,7 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! { ); } } else { - blit_to_display(&mut display, &frame, true); + blit_to_display(&mut display, &frame, true, &mut bw_thresh); for c in candidates_orig.iter() { log::debug!("****** candidate: {}, {} ******", c.x, c.y); // remap image to screen coordinates (it's 2:1) @@ -577,7 +583,7 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! { } } else { // blit raw camera fb to display - blit_to_display(&mut display, &frame, true); + blit_to_display(&mut display, &frame, true, &mut bw_thresh); gfx::msg( &mut display, "Scan QR code...", diff --git a/services/bao-video/src/modules.rs b/services/bao-video/src/modules.rs index 580e583c5..bbfea3c2b 100644 --- a/services/bao-video/src/modules.rs +++ b/services/bao-video/src/modules.rs @@ -107,6 +107,7 @@ pub fn stream_to_grid( qr_size_pixels: usize, qr_size_modules: usize, margin: usize, + bw_thresh: u8, ) -> Vec { let pix_per_module = ((qr_size_pixels - margin * 2) << FIXED_POINT_SHIFT) / qr_size_modules; let mut x_frac = FracIter::new( @@ -128,9 +129,7 @@ pub fn stream_to_grid( while let Some(x) = x_frac.next() { if true { // seems to work better with the simple threshold? - if image.data[(y + margin - FUDGE_Y) * image.width + (x + margin + FUDGE_X)] - < crate::BW_THRESH - { + if image.data[(y + margin - FUDGE_Y) * image.width + (x + margin + FUDGE_X)] < bw_thresh { grid.push(true); } else { grid.push(false); @@ -139,7 +138,7 @@ pub fn stream_to_grid( if image .neighbor_luma(Point::new(x as isize + margin as isize, y as isize + margin as isize)) .unwrap() - < crate::BW_THRESH + < bw_thresh { grid.push(true); } else { From 3f2c4e396a6a00f279c3f0ed4ded2a64ed3b88fe Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 1 May 2025 16:43:53 +0800 Subject: [PATCH 10/12] cleanup the camera/QR testing loop in bootloader This loop was useful in bringing up the GC2145 camera, so we should keep this code around. had to be refactored/shuffled around a bit to compensate for e.g. bitrot. --- loader/src/platform/cramium.rs | 4 +- loader/src/platform/cramium/cramium.rs | 676 +++++++++++++------------ loader/src/platform/cramium/qr.rs | 4 +- 3 files changed, 358 insertions(+), 326 deletions(-) diff --git a/loader/src/platform/cramium.rs b/loader/src/platform/cramium.rs index ed3e43ba1..71fe0ccd3 100644 --- a/loader/src/platform/cramium.rs +++ b/loader/src/platform/cramium.rs @@ -16,9 +16,9 @@ mod verifier; #[cfg(any(feature = "board-baosec", feature = "board-baosor"))] mod gfx; -#[cfg(feature = "qr")] +#[cfg(any(feature = "qr", feature = "cam-test"))] mod homography; -#[cfg(feature = "qr")] +#[cfg(any(feature = "qr", feature = "cam-test"))] mod qr; #[cfg(feature = "usb")] mod usb; diff --git a/loader/src/platform/cramium/cramium.rs b/loader/src/platform/cramium/cramium.rs index be9eb3daa..14537261d 100644 --- a/loader/src/platform/cramium/cramium.rs +++ b/loader/src/platform/cramium/cramium.rs @@ -14,6 +14,10 @@ use utralib::generated::*; #[cfg(feature = "qr")] use crate::platform::cramium::{homography, qr}; +#[global_allocator] +#[cfg(not(feature = "usb"))] +static ALLOCATOR: linked_list_allocator::LockedHeap = linked_list_allocator::LockedHeap::empty(); + // Notes about the reset vector location // This can be set using fuses in the IFR (also called 'info') region // The offset is an 8-bit value, which is shifted into a final location @@ -336,8 +340,8 @@ pub fn early_init() -> u32 { // disable CCM, force PWM on for DCDC2 - required for rail stability pmic.set_pwm_mode(&mut i2c, cramium_hal::axp2101::WhichDcDc::Dcdc2, true).unwrap(); - pmic.set_ldo(&mut i2c, Some(2.5), cramium_hal::axp2101::WhichLdo::Aldo2).unwrap(); - pmic.set_dcdc(&mut i2c, Some((1.2, false)), cramium_hal::axp2101::WhichDcDc::Dcdc4).unwrap(); + pmic.set_ldo(&mut i2c, Some(2.7), cramium_hal::axp2101::WhichLdo::Aldo2).unwrap(); + pmic.set_dcdc(&mut i2c, Some((1.8, false)), cramium_hal::axp2101::WhichDcDc::Dcdc4).unwrap(); pmic.set_dcdc(&mut i2c, Some((1.8, false)), cramium_hal::axp2101::WhichDcDc::Dcdc5).unwrap(); // apply proposed baosec settings @@ -405,6 +409,7 @@ pub fn early_init() -> u32 { // show the boot logo use ux_api::minigfx::FrameBuffer; + let mut udma_global = GlobalConfig::new(utra::udma_ctrl::HW_UDMA_CTRL_BASE as *mut u32); let mut sh1107 = cramium_hal::sh1107::Oled128x128::new( cramium_hal::sh1107::MainThreadToken::new(), perclk, @@ -439,6 +444,350 @@ pub fn early_init() -> u32 { delay(250); } } + //------------- test camera ------------ + #[cfg(feature = "cam-test")] + { + use cramium_api::iox::IoxValue; + use cramium_hal::sh1107::Mono; + use cramium_hal::udma::Udma; + use ux_api::minigfx::Point; + + use crate::platform::cramium::gfx; + use crate::platform::cramium::qr; + + let iox = Iox::new(utra::iox::HW_IOX_BASE as *mut u32); + let udma_global = GlobalConfig::new(utra::udma_ctrl::HW_UDMA_CTRL_BASE as *mut u32); + + // setup camera pins + let (cam_pdwn_bnk, cam_pdwn_pin) = cramium_hal::board::setup_camera_pins(&iox); + // disable camera powerdown + iox.set_gpio_pin(cam_pdwn_bnk, cam_pdwn_pin, IoxValue::Low); + udma_global.clock_on(PeriphId::Cam); + let cam_ifram = unsafe { + cramium_hal::ifram::IframRange::from_raw_parts( + cramium_hal::board::CAM_IFRAM_ADDR, + cramium_hal::board::CAM_IFRAM_ADDR, + cramium_hal::board::CAM_IFRAM_LEN_PAGES * 4096, + ) + }; + // this is safe because we turned on the clocks before calling it + let mut cam = unsafe { cramium_hal::gc2145::Gc2145::new_with_ifram(cam_ifram) }; + + cam.delay(100); + let (pid, mid) = cam.read_id(&mut i2c); + crate::println!("Camera pid {:x}, did {:x}", pid, mid); + crate::println!("enter init"); + cam.init(&mut i2c, cramium_api::camera::Resolution::Res320x240); + cam.delay(1); + + const QR_WIDTH: usize = 256; + const QR_HEIGHT: usize = 240; + + let (cols, _rows) = cam.resolution(); + let border = (cols - QR_WIDTH) / 2; + cam.set_slicing((border, 0), (cols - border, QR_HEIGHT)); + crate::println!("320x240 resolution setup with 256x240 slicing"); + + let mut csr_tt = CSR::new(utra::ticktimer::HW_TICKTIMER_BASE as *mut u32); + csr_tt.wfo(utra::ticktimer::CLOCKS_PER_TICK_CLOCKS_PER_TICK, 200_000); + csr_tt.wfo(utra::ticktimer::CONTROL_RESET, 1); + + let iox_loop = iox.clone(); + let mut frames = 0; + let mut frame = [0u8; QR_WIDTH * QR_HEIGHT]; + while iox_loop.get_gpio_pin(IoxPort::PB, 9) == IoxValue::High {} + udma_uart.setup_async_read(); + let mut c = 0u8; + let mut bw_thresh: u8 = 131; + loop { + // toggling this off can improve performance by wasting less time "waiting" for the next + // frame... however, you will get "frame rolling" if the capture isn't + // initiated at exactly the right time. things could be improved by making + // this interrupt-driven. maybe the same effect could also be achieved with + // frame dropping? not sure. to be researched. + while iox_loop.get_gpio_pin(IoxPort::PB, 9) == IoxValue::High {} + + cam.capture_async(); + + // blit fb to sh1107 + let mut sum: u32 = 0; + let mut count: u32 = 0; + for (y, row) in frame.chunks(QR_WIDTH).enumerate() { + if y & 1 == 0 { + for (x, &pixval) in row.iter().enumerate() { + // note: image rotation is done here by swapping x/y coords in the lower equations + if x & 1 == 0 { + if y < sh1107.dimensions().x as usize * 2 + && x < sh1107.dimensions().y as usize * 2 + - (gfx::CHAR_HEIGHT as usize + 1) * 2 + { + let luminance = pixval & 0xff; + count += 1; + sum += luminance as u32; + if luminance > bw_thresh { + // flip on y to adjust for sensor orientation. Lower left is (0, 0) + // on the display. + sh1107.put_pixel( + Point::new( + y as isize / 2, + (sh1107.dimensions().y - 1) - (x as isize / 2), + ), + Mono::White.into(), + ); + } + } else { + break; + } + } + } + } + } + bw_thresh = (sum / count) as u8; + + let mut candidates: [Option; 64] = [None; 64]; + crate::println!("\n\r------------- SEARCH -----------"); + let finder_width = qr::find_finders(&mut candidates, &frame, bw_thresh, QR_WIDTH) as isize; + const CROSSHAIR_LEN: isize = 3; + let mut candidates_found = 0; + let mut candidate3 = [Point::new(0, 0); 3]; + for candidate in candidates.iter() { + if let Some(c) = candidate { + if candidates_found < candidate3.len() { + candidate3[candidates_found] = *c; + } + candidates_found += 1; + crate::println!("****** candidate: {}, {} ******", c.x, c.y); + // remap image to screen coordinates (it's 2:1) + let mut c_screen = *c / 2; + // flip coordinates to match the camera data + c_screen = Point::new(c_screen.x, sh1107.dimensions().y - 1 - c_screen.y); + draw_crosshair(&mut sh1107, c_screen); + } + } + use crate::platform::cramium::qr::*; + if candidates_found == 3 { + let maybe_qr_corners = QrCorners::from_finders( + &candidate3, + Point::new(QR_WIDTH as isize, QR_HEIGHT as isize), + // add a search margin on the finder width + (finder_width + + (crate::platform::cramium::qr::FINDER_SEARCH_MARGIN * finder_width) + / (1 + 1 + 3 + 1 + 1)) as usize, + ); + // just doing this to avoid nesting another if level out in the test code; make this + // better! + if maybe_qr_corners.is_none() { + continue; + } + let mut qr_corners = maybe_qr_corners.unwrap(); + + let dims = Point::new(QR_WIDTH as isize, QR_HEIGHT as isize); + let mut il = ImageRoi::new(&mut frame, dims, bw_thresh); + let (src, dst) = + qr_corners.mapping(&mut il, crate::platform::cramium::qr::HOMOGRAPHY_MARGIN); + for s in src.iter() { + if let Some(p) = s { + crate::println!("src {:?}", p); + draw_crosshair(&mut sh1107, *p / 2); + } + } + for d in dst.iter() { + if let Some(p) = d { + crate::println!("dst {:?}", p); + draw_crosshair(&mut sh1107, *p / 2); + } + } + + let mut src_f: [(f32, f32); 4] = [(0.0, 0.0); 4]; + let mut dst_f: [(f32, f32); 4] = [(0.0, 0.0); 4]; + let mut all_found = true; + for (s, s_f32) in src.iter().zip(src_f.iter_mut()) { + if let Some(p) = s { + *s_f32 = p.to_f32(); + } else { + all_found = false; + } + } + for (d, d_f32) in dst.iter().zip(dst_f.iter_mut()) { + if let Some(p) = d { + *d_f32 = p.to_f32(); + } else { + all_found = false; + } + } + + if all_found { + use crate::platform::cramium::homography::*; + if let Some(h) = find_homography(src_f, dst_f) { + if let Some(h_inv) = h.try_inverse() { + // crate::println!("{:?}", h_inv); + let h_inv_fp = matrix3_to_fixp(h_inv); + // crate::println!("{:?}", h_inv_fp); + + // apply homography to generate a new buffer for processing + let mut aligned = [0u8; QR_WIDTH * QR_HEIGHT]; + // iterate through pixels and apply homography + for y in 0..dims.y { + for x in 0..dims.x { + let (x_src, y_src) = + apply_fixp_homography(&h_inv_fp, (x as i32, y as i32)); + if (x_src as i32 >= 0) + && ((x_src as i32) < dims.x as i32) + && (y_src as i32 >= 0) + && ((y_src as i32) < dims.y as i32) + { + // println!("{},{} -> {},{}", x_src as i32, y_src as i32, x, y); + aligned[QR_WIDTH * y as usize + x as usize] = + frame[QR_WIDTH * y_src as usize + x_src as usize]; + } else { + aligned[QR_WIDTH * y as usize + x as usize] = 255; + } + } + } + + // blit aligned to sh1107 + for (y, row) in aligned.chunks(QR_WIDTH).enumerate() { + if y & 1 == 0 { + for (x, &pixval) in row.iter().enumerate() { + if x & 1 == 0 { + if x < sh1107.dimensions().x as usize * 2 + && y < sh1107.dimensions().y as usize * 2 + - (gfx::CHAR_HEIGHT as usize + 1) * 2 + { + let luminance = pixval & 0xff; + if luminance > bw_thresh { + // flip on y to adjust for sensor orientation. Lower + // left + // is (0, 0) + // on the display. + sh1107.put_pixel( + Point::new( + x as isize / 2, + (sh1107.dimensions().y - 1) + - (y as isize / 2), + ), + Mono::White.into(), + ); + } else { + sh1107.put_pixel( + Point::new( + x as isize / 2, + (sh1107.dimensions().y - 1) + - (y as isize / 2), + ), + Mono::Black.into(), + ); + } + } else { + break; + } + } + } + } + } + + gfx::msg( + &mut sh1107, + "Aligning...", + Point::new(0, 0), + Mono::White.into(), + Mono::Black.into(), + ); + + if udma_uart.read_async(&mut c) != 0 { + if c == ' ' as u32 as u8 { + crate::println!("Dumping..."); + + crate::println!("frame {}", frames); + udma_uart.write( + "------------------ divider ------------------\n\r".as_bytes(), + ); + let hex_to_ascii = [ + '0' as u32 as u8, + '1' as u32 as u8, + '2' as u32 as u8, + '3' as u32 as u8, + '4' as u32 as u8, + '5' as u32 as u8, + '6' as u32 as u8, + '7' as u32 as u8, + '8' as u32 as u8, + '9' as u32 as u8, + 'A' as u32 as u8, + 'B' as u32 as u8, + 'C' as u32 as u8, + 'D' as u32 as u8, + 'E' as u32 as u8, + 'F' as u32 as u8, + ]; + for line in frame.chunks(32) { + let mut output = [0u8; 3 * 32 + 3]; + for (i, &b) in line.iter().enumerate() { + output[i * 3 + 0] = hex_to_ascii[(b >> 4) as usize]; + output[i * 3 + 1] = hex_to_ascii[(b & 0xF) as usize]; + output[i * 3 + 2] = ',' as u32 as u8; + } + output[3 * 32] = '\\' as u32 as u8; + output[3 * 32 + 1] = '\n' as u32 as u8; + output[3 * 32 + 2] = '\r' as u32 as u8; + udma_uart.write(&output); + } + // continue with boot + break; + } + } + } + } + } + } else { + gfx::msg( + &mut sh1107, + "Searching...", + Point::new(0, 0), + Mono::White.into(), + Mono::Black.into(), + ); + } + + // crate::println!("frame {}", frames); + sh1107.draw(); + + // clear the front buffer + sh1107.clear(); + + // inspect camera values + if false { + crate::println!("RX_SADDR {:x}", cam.csr().r(utra::udma_camera::REG_RX_SADDR)); + crate::println!("RX_SIZE {:x}", cam.csr().r(utra::udma_camera::REG_RX_SIZE)); + crate::println!("RX_CFG {:x}", cam.csr().r(utra::udma_camera::REG_RX_CFG)); + crate::println!("CAM_GLOB {:x}", cam.csr().r(utra::udma_camera::REG_CAM_CFG_GLOB)); + crate::println!("CAM_LL {:x}", cam.csr().r(utra::udma_camera::REG_CAM_CFG_LL)); + crate::println!("CAM_UR {:x}", cam.csr().r(utra::udma_camera::REG_CAM_CFG_UR)); + crate::println!("CAM_CFG_SIZE {:x}", cam.csr().r(utra::udma_camera::REG_CAM_CFG_SIZE)); + crate::println!( + "CAM_CFG_FILTER {:x}", + cam.csr().r(utra::udma_camera::REG_CAM_CFG_FILTER) + ); + crate::println!("CAM_SYNC {:x}", cam.csr().r(utra::udma_camera::REG_CAM_VSYNC_POLARITY)); + } + + // wait for the transfer to finish + cam.capture_await(false); + let fb: &[u32] = cam.rx_buf(); + + // fb is non-cacheable, slow memory. If we stride through it in u16 chunks, we end + // up fetching each location *twice*, because the native width of the bus is a u32 + // Stride through the slice as a u32, allowing us to make the most out of each slow + // read from IFRAM, and unpack the values into fast SRAM. + for (&u32src, u8dest) in fb.iter().zip(frame.chunks_mut(2)) { + // note that GC2145 puts Y in top bytes of u16s, OV2640 puts them in the lower bytses of + // u16's. + u8dest[0] = ((u32src >> 8) & 0xff) as u8; + u8dest[1] = ((u32src >> 24) & 0xff) as u8; + } + frames += 1; + } + } } // Board bring-up: send characters to confirm the UART is configured & ready to go for the logging crate! @@ -496,327 +845,10 @@ pub fn early_init() -> u32 { crate::platform::cramium::usb::test_usb(); } } + } - //------------- test OV2640 ------------ - // setup camera pins - let (cam_pdwn_bnk, cam_pdwn_pin) = cramium_hal::board::setup_ov2640_pins(&iox); - // disable camera powerdown - iox.set_gpio_pin(cam_pdwn_bnk, cam_pdwn_pin, cramium_hal::iox::IoxValue::Low); - udma_global.clock_on(PeriphId::Cam); - let cam_ifram = unsafe { - cramium_hal::ifram::IframRange::from_raw_parts( - cramium_hal::board::CAM_IFRAM_ADDR, - cramium_hal::board::CAM_IFRAM_ADDR, - cramium_hal::board::CAM_IFRAM_LEN_PAGES * 4096, - ) - }; - // this is safe because we turned on the clocks before calling it - let mut cam = unsafe { cramium_hal::ov2640::Ov2640::new_with_ifram(cam_ifram) }; - - cam.delay(100); - let (pid, mid) = cam.read_id(&mut i2c); - crate::println!("Camera pid {:x}, mid {:x}", pid, mid); - cam.init(&mut i2c, cramium_hal::ov2640::Resolution::Res320x240); - cam.poke(&mut i2c, 0xFF, 0x00); - cam.poke(&mut i2c, 0xDA, 0x01); // YUV LE - cam.delay(1); - - // muck with ZMOW: only works in 160x120 mode - // cam.poke(&mut i2c, 0x5A, 0x28); - // cam.delay(1); - // cam.poke(&mut i2c, 0x5B, 0x1E); - // cam.delay(1); - let (cols, _rows) = cam.resolution(); - const QR_WIDTH: usize = 256; - const QR_HEIGHT: usize = 240; - let border = (cols - QR_WIDTH) / 2; - cam.set_slicing((border, 0), (cols - border, QR_HEIGHT)); - crate::println!("320x240 resolution setup with 256x240 slicing"); - - let mut csr_tt = CSR::new(utra::ticktimer::HW_TICKTIMER_BASE as *mut u32); - csr_tt.wfo(utra::ticktimer::CLOCKS_PER_TICK_CLOCKS_PER_TICK, 200_000); - csr_tt.wfo(utra::ticktimer::CONTROL_RESET, 1); - - let mut frames = 0; - let mut frame = [0u8; QR_WIDTH * QR_HEIGHT]; - while iox_loop.get_gpio_pin(IoxPort::PB, 9) == IoxValue::High {} - udma_uart.setup_async_read(); - let mut c = 0u8; - const BW_THRESH: u8 = 128; - #[cfg(feature = "qr")] - loop { - // toggling this off can improve performance by wasting less time "waiting" for the next frame... - // however, you will get "frame rolling" if the capture isn't initiated at exactly the right time. - // things could be improved by making this interrupt-driven. - // maybe the same effect could also be achieved with frame dropping? not sure. to be researched. - while iox_loop.get_gpio_pin(IoxPort::PB, 9) == IoxValue::High {} - - cam.capture_async(); - - // blit fb to sh1107 - for (y, row) in frame.chunks(QR_WIDTH).enumerate() { - if y & 1 == 0 { - for (x, &pixval) in row.iter().enumerate() { - if x & 1 == 0 { - if x < sh1107.dimensions().x as usize * 2 - && y < sh1107.dimensions().y as usize * 2 - - (gfx::CHAR_HEIGHT as usize + 1) * 2 - { - let luminance = pixval & 0xff; - if luminance > BW_THRESH { - // flip on y to adjust for sensor orientation. Lower left is (0, 0) - // on the display. - sh1107.put_pixel( - Point::new( - x as isize / 2, - (sh1107.dimensions().y - 1) - (y as isize / 2), - ), - Mono::White.into(), - ); - } - } else { - break; - } - } - } - } - } - - let mut candidates: [Option; 64] = [None; 64]; - crate::println!("\n\r------------- SEARCH -----------"); - let finder_width = qr::find_finders(&mut candidates, &frame, BW_THRESH, QR_WIDTH) as isize; - const CROSSHAIR_LEN: isize = 3; - let mut candidates_found = 0; - let mut candidate3 = [Point::new(0, 0); 3]; - for candidate in candidates.iter() { - if let Some(c) = candidate { - if candidates_found < candidate3.len() { - candidate3[candidates_found] = *c; - } - candidates_found += 1; - crate::println!("****** candidate: {}, {} ******", c.x, c.y); - // remap image to screen coordinates (it's 2:1) - let mut c_screen = *c / 2; - // flip coordinates to match the camera data - c_screen = Point::new(c_screen.x, sh1107.dimensions().y - 1 - c_screen.y); - draw_crosshair(&mut sh1107, c_screen); - } - } - use crate::platform::cramium::qr::*; - if candidates_found == 3 { - let maybe_qr_corners = QrCorners::from_finders( - &candidate3, - Point::new(QR_WIDTH as isize, QR_HEIGHT as isize), - // add a search margin on the finder width - (finder_width - + (crate::platform::cramium::qr::FINDER_SEARCH_MARGIN * finder_width) - / (1 + 1 + 3 + 1 + 1)) as usize, - ); - // just doing this to avoid nesting another if level out in the test code; make this better! - if maybe_qr_corners.is_none() { - continue; - } - let mut qr_corners = maybe_qr_corners.unwrap(); - - let dims = Point::new(QR_WIDTH as isize, QR_HEIGHT as isize); - let mut il = ImageRoi::new(&mut frame, dims, BW_THRESH); - let (src, dst) = qr_corners.mapping(&mut il, crate::platform::cramium::qr::HOMOGRAPHY_MARGIN); - for s in src.iter() { - if let Some(p) = s { - crate::println!("src {:?}", p); - draw_crosshair(&mut sh1107, *p / 2); - } - } - for d in dst.iter() { - if let Some(p) = d { - crate::println!("dst {:?}", p); - draw_crosshair(&mut sh1107, *p / 2); - } - } - - let mut src_f: [(f32, f32); 4] = [(0.0, 0.0); 4]; - let mut dst_f: [(f32, f32); 4] = [(0.0, 0.0); 4]; - let mut all_found = true; - for (s, s_f32) in src.iter().zip(src_f.iter_mut()) { - if let Some(p) = s { - *s_f32 = p.to_f32(); - } else { - all_found = false; - } - } - for (d, d_f32) in dst.iter().zip(dst_f.iter_mut()) { - if let Some(p) = d { - *d_f32 = p.to_f32(); - } else { - all_found = false; - } - } - - if all_found { - use crate::platform::cramium::homography::*; - if let Some(h) = find_homography(src_f, dst_f) { - if let Some(h_inv) = h.try_inverse() { - // crate::println!("{:?}", h_inv); - let h_inv_fp = matrix3_to_fixp(h_inv); - // crate::println!("{:?}", h_inv_fp); - - // apply homography to generate a new buffer for processing - let mut aligned = [0u8; QR_WIDTH * QR_HEIGHT]; - // iterate through pixels and apply homography - for y in 0..dims.y { - for x in 0..dims.x { - let (x_src, y_src) = - apply_fixp_homography(&h_inv_fp, (x as i32, y as i32)); - if (x_src as i32 >= 0) - && ((x_src as i32) < dims.x as i32) - && (y_src as i32 >= 0) - && ((y_src as i32) < dims.y as i32) - { - // println!("{},{} -> {},{}", x_src as i32, y_src as i32, x, y); - aligned[QR_WIDTH * y as usize + x as usize] = - frame[QR_WIDTH * y_src as usize + x_src as usize]; - } else { - aligned[QR_WIDTH * y as usize + x as usize] = 255; - } - } - } - - // blit aligned to sh1107 - for (y, row) in aligned.chunks(QR_WIDTH).enumerate() { - if y & 1 == 0 { - for (x, &pixval) in row.iter().enumerate() { - if x & 1 == 0 { - if x < sh1107.dimensions().x as usize * 2 - && y < sh1107.dimensions().y as usize * 2 - - (gfx::CHAR_HEIGHT as usize + 1) * 2 - { - let luminance = pixval & 0xff; - if luminance > BW_THRESH { - // flip on y to adjust for sensor orientation. Lower left - // is (0, 0) - // on the display. - sh1107.put_pixel( - Point::new( - x as isize / 2, - (sh1107.dimensions().y - 1) - (y as isize / 2), - ), - Mono::White.into(), - ); - } else { - sh1107.put_pixel( - Point::new( - x as isize / 2, - (sh1107.dimensions().y - 1) - (y as isize / 2), - ), - Mono::Black.into(), - ); - } - } else { - break; - } - } - } - } - } - - gfx::msg( - &mut sh1107, - "Aligning...", - Point::new(0, 0), - Mono::White.into(), - Mono::Black.into(), - ); - - if udma_uart.read_async(&mut c) != 0 { - if c == ' ' as u32 as u8 { - crate::println!("Dumping..."); - - crate::println!("frame {}", frames); - udma_uart.write( - "------------------ divider ------------------\n\r".as_bytes(), - ); - let hex_to_ascii = [ - '0' as u32 as u8, - '1' as u32 as u8, - '2' as u32 as u8, - '3' as u32 as u8, - '4' as u32 as u8, - '5' as u32 as u8, - '6' as u32 as u8, - '7' as u32 as u8, - '8' as u32 as u8, - '9' as u32 as u8, - 'A' as u32 as u8, - 'B' as u32 as u8, - 'C' as u32 as u8, - 'D' as u32 as u8, - 'E' as u32 as u8, - 'F' as u32 as u8, - ]; - for line in frame.chunks(32) { - let mut output = [0u8; 3 * 32 + 3]; - for (i, &b) in line.iter().enumerate() { - output[i * 3 + 0] = hex_to_ascii[(b >> 4) as usize]; - output[i * 3 + 1] = hex_to_ascii[(b & 0xF) as usize]; - output[i * 3 + 2] = ',' as u32 as u8; - } - output[3 * 32] = '\\' as u32 as u8; - output[3 * 32 + 1] = '\n' as u32 as u8; - output[3 * 32 + 2] = '\r' as u32 as u8; - udma_uart.write(&output); - } - // continue with boot - break; - } - } - } - } - } - } else { - gfx::msg( - &mut sh1107, - "Searching...", - Point::new(0, 0), - Mono::White.into(), - Mono::Black.into(), - ); - } - - // crate::println!("frame {}", frames); - sh1107.buffer_swap(); - sh1107.draw(); - - // clear the front buffer - sh1107.clear(); - - // inspect camera values - if false { - crate::println!("RX_SADDR {:x}", cam.csr().r(utra::udma_camera::REG_RX_SADDR)); - crate::println!("RX_SIZE {:x}", cam.csr().r(utra::udma_camera::REG_RX_SIZE)); - crate::println!("RX_CFG {:x}", cam.csr().r(utra::udma_camera::REG_RX_CFG)); - crate::println!("CAM_GLOB {:x}", cam.csr().r(utra::udma_camera::REG_CAM_CFG_GLOB)); - crate::println!("CAM_LL {:x}", cam.csr().r(utra::udma_camera::REG_CAM_CFG_LL)); - crate::println!("CAM_UR {:x}", cam.csr().r(utra::udma_camera::REG_CAM_CFG_UR)); - crate::println!("CAM_CFG_SIZE {:x}", cam.csr().r(utra::udma_camera::REG_CAM_CFG_SIZE)); - crate::println!("CAM_CFG_FILTER {:x}", cam.csr().r(utra::udma_camera::REG_CAM_CFG_FILTER)); - crate::println!("CAM_SYNC {:x}", cam.csr().r(utra::udma_camera::REG_CAM_VSYNC_POLARITY)); - } - - // wait for the transfer to finish - cam.capture_await(false); - let fb: &[u32] = cam.rx_buf(); - - // fb is non-cacheable, slow memory. If we stride through it in u16 chunks, we end - // up fetching each location *twice*, because the native width of the bus is a u32 - // Stride through the slice as a u32, allowing us to make the most out of each slow - // read from IFRAM, and unpack the values into fast SRAM. - for (&u32src, u8dest) in fb.iter().zip(frame.chunks_mut(2)) { - u8dest[0] = (u32src & 0xff) as u8; - u8dest[1] = ((u32src >> 16) & 0xff) as u8; - } - frames += 1; - } - + #[cfg(feature = "board-bringup")] + { // ---------------- test TRNG ------------------- // configure the SCE clocks to enable the TRNG let mut sce = CSR::new(HW_SCE_GLBSFR_BASE as *mut u32); diff --git a/loader/src/platform/cramium/qr.rs b/loader/src/platform/cramium/qr.rs index 41dbe034a..ca60fa8be 100644 --- a/loader/src/platform/cramium/qr.rs +++ b/loader/src/platform/cramium/qr.rs @@ -3,7 +3,7 @@ use core::cell::RefCell; use core::convert::TryFrom; use core::ops::{BitXor, Not}; -use cramium_hal::minigfx::{ColorNative, FrameBuffer, Point}; +use ux_api::minigfx::{ColorNative, FrameBuffer, Point}; use super::gfx; @@ -30,7 +30,7 @@ pub const HOMOGRAPHY_MARGIN: isize = -4; pub const CROSSHAIR_LEN: isize = 3; pub fn draw_crosshair(image: &mut dyn FrameBuffer, p: Point) { - use cramium_hal::minigfx::Line; + use ux_api::minigfx::Line; gfx::line( image, Line::new(p + Point::new(0, CROSSHAIR_LEN), p - Point::new(0, CROSSHAIR_LEN)), From 51b103d674d284abc3b3a915a46e11d9dbd9f3e2 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 1 May 2025 16:44:43 +0800 Subject: [PATCH 11/12] add cam-test target to the loader --- loader/Cargo.toml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/loader/Cargo.toml b/loader/Cargo.toml index b7480e483..77400fb77 100644 --- a/loader/Cargo.toml +++ b/loader/Cargo.toml @@ -114,7 +114,7 @@ swap = ["aes-gcm-siv"] # cramium target flags board-bringup = [] -sh1107-bringup = [] # used to discover FB parameters +sh1107-bringup = [] # used to discover FB parameters sram-margin = [] boot-delay = [] simulation-only = [] @@ -128,11 +128,12 @@ dump-trng = [] fast-fclk = [] clock-tests = [] reset-debug = [] +cam-test = ["nalgebra", "libm", "cramium-hal/debug-print-usb"] usb = [] qr = ["nalgebra", "libm"] updates = [] cramium-mpw = ["cramium-hal/mpw"] -userspace-swap-debug = [] # sets up app UART mapping. +userspace-swap-debug = [] # sets up app UART mapping. # general flags debug-print = [] From 2c534b6d4d7df69b0f42e54b9994a44e58fdc0e7 Mon Sep 17 00:00:00 2001 From: bunnie Date: Thu, 1 May 2025 16:44:51 +0800 Subject: [PATCH 12/12] add cam-test option to xtask loader as a comment --- xtask/src/main.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/xtask/src/main.rs b/xtask/src/main.rs index 539aa6eb2..8e7a9e144 100644 --- a/xtask/src/main.rs +++ b/xtask/src/main.rs @@ -634,6 +634,7 @@ fn main() -> Result<(), Box> { builder.add_loader_feature("sram-margin"); builder.add_loader_feature("usb"); builder.add_loader_feature("updates"); + // builder.add_loader_feature("cam-test"); match task.as_deref() { Some("baosec") => builder.target_cramium_soc(), _ => panic!("should be unreachable"),