mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
commit
28232ff999
10 changed files with 247 additions and 108 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
|
@ -360,6 +360,7 @@ dependencies = [
|
||||||
"bao1x-emu",
|
"bao1x-emu",
|
||||||
"bao1x-hal",
|
"bao1x-hal",
|
||||||
"bao1x-hal-service",
|
"bao1x-hal-service",
|
||||||
|
"base45",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"chrono",
|
"chrono",
|
||||||
"log",
|
"log",
|
||||||
|
|
@ -612,6 +613,12 @@ version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "23ce669cd6c8588f79e15cf450314f9638f967fc5770ff1c7c1deb0925ea7cfa"
|
checksum = "23ce669cd6c8588f79e15cf450314f9638f967fc5770ff1c7c1deb0925ea7cfa"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base45"
|
||||||
|
version = "3.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b3103f6d6af63726e86b026ac66769fc578ea38aba33f409e5855a4def97a564"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "base64"
|
name = "base64"
|
||||||
version = "0.5.2"
|
version = "0.5.2"
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ use xous_ipc::Buffer;
|
||||||
|
|
||||||
use super::FrameBuffer;
|
use super::FrameBuffer;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
use crate::service::api::QrRender;
|
||||||
use crate::wordwrap::*;
|
use crate::wordwrap::*;
|
||||||
|
|
||||||
pub fn draw_clip_object<T: FrameBuffer>(display: &mut T, msg: &mut xous::envelope::Envelope) {
|
pub fn draw_clip_object<T: FrameBuffer>(display: &mut T, msg: &mut xous::envelope::Envelope) {
|
||||||
|
|
@ -400,3 +401,68 @@ pub fn draw_text_view<T: FrameBuffer>(display: &mut T, msg: &mut xous::envelope:
|
||||||
// pack our data back into the buffer to return
|
// pack our data back into the buffer to return
|
||||||
buffer.replace(tv).unwrap();
|
buffer.replace(tv).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn render_qr<T: FrameBuffer>(
|
||||||
|
display: &mut T,
|
||||||
|
screen_clip: Option<Rectangle>,
|
||||||
|
msg: &mut xous::envelope::Envelope,
|
||||||
|
) {
|
||||||
|
if msg.body.has_memory() {
|
||||||
|
let screensize = Rectangle::new(
|
||||||
|
Point::new(0, 0),
|
||||||
|
Point::new(crate::platform::WIDTH as _, crate::platform::HEIGHT as _),
|
||||||
|
);
|
||||||
|
let buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||||
|
let qr_render = buffer.to_original::<QrRender, _>().unwrap();
|
||||||
|
log::debug!(
|
||||||
|
"qr_render width {}: {:?}",
|
||||||
|
qr_render.width,
|
||||||
|
&qr_render.modules[..32.min(qr_render.modules.len())]
|
||||||
|
);
|
||||||
|
const QUIET_MODULES: isize = 1;
|
||||||
|
let window_width = screen_clip.unwrap_or(screensize).width() as isize;
|
||||||
|
let total_width = qr_render.width as isize + QUIET_MODULES * 2;
|
||||||
|
let module_width = (window_width / total_width).max(1) as isize;
|
||||||
|
let left_edge = if module_width * total_width < window_width {
|
||||||
|
(window_width - (module_width * total_width)) as isize / 2
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
const USE_TOP_LEFT: bool = false;
|
||||||
|
let tl = if USE_TOP_LEFT { qr_render.top_left } else { Point::new(0, 0) };
|
||||||
|
|
||||||
|
// draw a white background over the rendering area
|
||||||
|
let r = Rectangle::new_with_style(
|
||||||
|
Point::from((left_edge, tl.y)),
|
||||||
|
screen_clip.unwrap_or(screensize).br,
|
||||||
|
DrawStyle::new(PixelColor::Light, PixelColor::Light, 1),
|
||||||
|
);
|
||||||
|
op::rectangle(display, r, screen_clip.into(), false);
|
||||||
|
|
||||||
|
// now raster in the modules
|
||||||
|
let mut line_top_left =
|
||||||
|
Point::new(left_edge + module_width * QUIET_MODULES, tl.y + module_width * QUIET_MODULES);
|
||||||
|
let dark = DrawStyle::new(PixelColor::Dark, PixelColor::Dark, 1);
|
||||||
|
for line in qr_render.modules.chunks(qr_render.width) {
|
||||||
|
for (i, &module) in line.iter().enumerate() {
|
||||||
|
if module {
|
||||||
|
// dark color: render a square
|
||||||
|
let m = Rectangle::new_coords_with_style(
|
||||||
|
line_top_left.x + i as isize * module_width,
|
||||||
|
line_top_left.y,
|
||||||
|
line_top_left.x + (i + 1) as isize * module_width,
|
||||||
|
line_top_left.y + module_width,
|
||||||
|
dark,
|
||||||
|
);
|
||||||
|
op::rectangle(display, m, screen_clip.into(), false);
|
||||||
|
} else {
|
||||||
|
// light color: don't render, background is already light
|
||||||
|
}
|
||||||
|
}
|
||||||
|
line_top_left += Point::new(0, module_width);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
panic!("Incorrect message type for RenderQr")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,7 @@ pub enum GfxOpcode {
|
||||||
UnclippedObjectList,
|
UnclippedObjectList,
|
||||||
/// V2 API for getting filtered keyboard events
|
/// V2 API for getting filtered keyboard events
|
||||||
FilteredKeyboardListener,
|
FilteredKeyboardListener,
|
||||||
|
RenderQr,
|
||||||
|
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(feature = "board-baosec")]
|
||||||
AcquireQr,
|
AcquireQr,
|
||||||
|
|
@ -137,6 +138,13 @@ pub struct QrAcquisition {
|
||||||
pub meta: Option<String>,
|
pub meta: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(rkyv::Archive, rkyv::Serialize, rkyv::Deserialize)]
|
||||||
|
pub struct QrRender {
|
||||||
|
pub width: usize,
|
||||||
|
pub top_left: crate::minigfx::Point,
|
||||||
|
pub modules: Vec<bool>,
|
||||||
|
}
|
||||||
|
|
||||||
// this structure is used to register a keyboard listener.
|
// this structure is used to register a keyboard listener.
|
||||||
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Clone)]
|
#[derive(Debug, rkyv::Archive, rkyv::Serialize, rkyv::Deserialize, Clone)]
|
||||||
pub struct KeyboardRegistration {
|
pub struct KeyboardRegistration {
|
||||||
|
|
|
||||||
|
|
@ -729,6 +729,20 @@ impl Gfx {
|
||||||
buf.lend(self.conn, GfxOpcode::UnclippedObjectList.to_u32().unwrap()).map(|_| ())
|
buf.lend(self.conn, GfxOpcode::UnclippedObjectList.to_u32().unwrap()).map(|_| ())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// On small screens, `top_left` is ignored and the code takes the whole screen, always
|
||||||
|
pub fn render_qr(
|
||||||
|
&self,
|
||||||
|
qr_stream: &Vec<bool>,
|
||||||
|
qr_width: usize,
|
||||||
|
top_left: Point,
|
||||||
|
) -> Result<(), xous::Error> {
|
||||||
|
let qr_render = QrRender { width: qr_width, top_left, modules: qr_stream.to_owned() };
|
||||||
|
let mut buf = Buffer::into_buf(qr_render).unwrap();
|
||||||
|
buf.lend_mut(self.conn, GfxOpcode::RenderQr.to_u32().unwrap())?;
|
||||||
|
// do nothing with the response - function just blocks until the QR code is done rendering
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(feature = "board-baosec")]
|
||||||
pub fn acquire_qr(&self) -> Result<QrAcquisition, xous::Error> {
|
pub fn acquire_qr(&self) -> Result<QrAcquisition, xous::Error> {
|
||||||
let acquisition = QrAcquisition { content: None, meta: None };
|
let acquisition = QrAcquisition { content: None, meta: None };
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ use locales::t;
|
||||||
use qrcode::{Color, QrCode};
|
use qrcode::{Color, QrCode};
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::minigfx::op::{HEIGHT, WIDTH};
|
use crate::minigfx::op::HEIGHT;
|
||||||
use crate::minigfx::*;
|
use crate::minigfx::*;
|
||||||
use crate::service::api::*;
|
use crate::service::api::*;
|
||||||
use crate::service::gfx::Gfx;
|
use crate::service::gfx::Gfx;
|
||||||
|
|
@ -52,14 +52,14 @@ impl Notification {
|
||||||
Err(_e) => QrCode::new(t!("notification.qrcode.error", locales::LANG)).unwrap(),
|
Err(_e) => QrCode::new(t!("notification.qrcode.error", locales::LANG)).unwrap(),
|
||||||
};
|
};
|
||||||
self.qrwidth = qrcode.width();
|
self.qrwidth = qrcode.width();
|
||||||
log::info!("qrcode {}x{} : {} bytes ", self.qrwidth, self.qrwidth, setting.len());
|
self.qrcode = qrcode.into_colors().into_iter().map(|c| c != Color::Light).collect();
|
||||||
self.qrcode = Vec::new();
|
log::info!(
|
||||||
for color in qrcode.to_colors().iter() {
|
"qrcode {}x{} : {} bytes, {} modules",
|
||||||
match color {
|
self.qrwidth,
|
||||||
Color::Dark => self.qrcode.push(true),
|
self.qrwidth,
|
||||||
Color::Light => self.qrcode.push(false),
|
setting.len(),
|
||||||
}
|
self.qrcode.len()
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
self.qrcode = Vec::new();
|
self.qrcode = Vec::new();
|
||||||
|
|
@ -99,54 +99,10 @@ impl Notification {
|
||||||
self.gfx.draw_textview(&mut tv).expect("couldn't post tv");
|
self.gfx.draw_textview(&mut tv).expect("couldn't post tv");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_qrcode(&self, at_height: isize, modal: &Modal) {
|
fn draw_qrcode(&self, at_height: isize, _modal: &Modal) {
|
||||||
// calculate pixel size of each module in the qrcode
|
|
||||||
let qrcode_modules: isize = self.qrwidth.try_into().unwrap();
|
|
||||||
let modules: isize = qrcode_modules + 2 * QUIET_MODULES;
|
|
||||||
let canvas_width = modal.canvas_width - 2 * modal.margin;
|
|
||||||
let mod_size_px: isize = canvas_width / modules;
|
|
||||||
let qrcode_width_px = qrcode_modules * mod_size_px;
|
|
||||||
let quiet_px: isize = (canvas_width - qrcode_width_px) / 2;
|
|
||||||
|
|
||||||
// Iterate thru qrcode and stamp each square module like a typewriter
|
|
||||||
let black = DrawStyle::new(PixelColor::Dark, PixelColor::Dark, 1);
|
|
||||||
let top = at_height + quiet_px;
|
|
||||||
|
|
||||||
// draw a white background over the whole screen
|
|
||||||
self.gfx
|
self.gfx
|
||||||
.draw_rectangle(Rectangle::new_with_style(
|
.render_qr(&self.qrcode, self.qrwidth, Point { x: 0, y: at_height })
|
||||||
Point::new(0, at_height),
|
.expect("couldn't render QR");
|
||||||
Point::new(WIDTH, HEIGHT),
|
|
||||||
DrawStyle::new(PixelColor::Light, PixelColor::Light, 1),
|
|
||||||
))
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let left = modal.margin + quiet_px;
|
|
||||||
let right = left + qrcode_modules * mod_size_px;
|
|
||||||
let mut module =
|
|
||||||
Rectangle::new_with_style(Point::new(0, 0), Point::new(mod_size_px - 1, mod_size_px - 1), black);
|
|
||||||
let step = Point::new(mod_size_px, 0);
|
|
||||||
let cr_lf = Point::new(-qrcode_modules * mod_size_px, mod_size_px);
|
|
||||||
let mut j: isize;
|
|
||||||
let mut obj_list = ObjectList::new();
|
|
||||||
module.translate(Point::new(right, top));
|
|
||||||
for (i, stamp) in self.qrcode.iter().enumerate() {
|
|
||||||
j = i.try_into().unwrap();
|
|
||||||
if j % qrcode_modules == 0 {
|
|
||||||
module.translate(cr_lf);
|
|
||||||
}
|
|
||||||
if *stamp {
|
|
||||||
if obj_list.push(ClipObjectType::Rect(module.clone())).is_err() {
|
|
||||||
// the capacity of the list has exceeded the capacity of the buffer, send it and make a
|
|
||||||
// new one
|
|
||||||
self.gfx.draw_object_list(obj_list).expect("couldn't draw qrcode module");
|
|
||||||
obj_list = ObjectList::new();
|
|
||||||
obj_list.push(ClipObjectType::Rect(module.clone())).unwrap();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
module.translate(step);
|
|
||||||
}
|
|
||||||
self.gfx.draw_object_list(obj_list).expect("couldn't draw qrcode module");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,9 @@ aes = { path = "../aes", default-features = false, optional = true, features = [
|
||||||
# time testing
|
# time testing
|
||||||
chrono = "0.4.33"
|
chrono = "0.4.33"
|
||||||
|
|
||||||
|
# QR code encoding
|
||||||
|
base45 = "3.1.0"
|
||||||
|
|
||||||
# hid bringup
|
# hid bringup
|
||||||
xous-usb-hid = { git = "https://github.com/betrusted-io/xous-usb-hid.git", branch = "main", optional = true }
|
xous-usb-hid = { git = "https://github.com/betrusted-io/xous-usb-hid.git", branch = "main", optional = true }
|
||||||
|
|
||||||
|
|
@ -50,6 +53,7 @@ board-baosec = [
|
||||||
"usb-bao1x/board-baosec",
|
"usb-bao1x/board-baosec",
|
||||||
"pddb/board-baosec",
|
"pddb/board-baosec",
|
||||||
"xous-swapper",
|
"xous-swapper",
|
||||||
|
"ux-api/board-baosec",
|
||||||
]
|
]
|
||||||
hosted-baosec = [
|
hosted-baosec = [
|
||||||
"modals/hosted-baosec",
|
"modals/hosted-baosec",
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,7 @@ pub(crate) enum BenchOp {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
||||||
|
#[allow(dead_code)]
|
||||||
pub(crate) enum BenchResult {
|
pub(crate) enum BenchResult {
|
||||||
AesHwDone,
|
AesHwDone,
|
||||||
AesSwDone,
|
AesSwDone,
|
||||||
|
|
|
||||||
|
|
@ -128,6 +128,51 @@ impl<'a> ShellCmdApi<'a> for Test {
|
||||||
"keepon" => {
|
"keepon" => {
|
||||||
todo!("Fix this to use DCDC2 for keepon (as per baosec v2)");
|
todo!("Fix this to use DCDC2 for keepon (as per baosec v2)");
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "board-baosec")]
|
||||||
|
"qrshow" => {
|
||||||
|
// note that 40 bytes gives 320 bits which fits nicely into a version 3 code,
|
||||||
|
// which allows 4 pixels per module rendering.
|
||||||
|
// if we have to move to 3 pixels per module, the next code up that optimally
|
||||||
|
// uses the full screen is version 6. This would give 102 bytes of transfer
|
||||||
|
// in a single scan.
|
||||||
|
//
|
||||||
|
// The equation for capacity is:
|
||||||
|
// `binary_bytes = floor((alphanumeric_capacity / 3) × 2)`
|
||||||
|
//
|
||||||
|
// where `alphameric_capacity` is the capacity of the QR code version
|
||||||
|
// per spec lookup table.
|
||||||
|
let modals = modals::Modals::new(&_env.xns).unwrap();
|
||||||
|
let mut test_data = [0u8; 40];
|
||||||
|
for (i, d) in test_data.iter_mut().enumerate() {
|
||||||
|
*d = i as u8;
|
||||||
|
}
|
||||||
|
let encoded = base45::encode(&test_data);
|
||||||
|
modals.show_notification("", Some(&encoded)).ok();
|
||||||
|
}
|
||||||
|
#[cfg(feature = "board-baosec")]
|
||||||
|
"qrget" => {
|
||||||
|
let gfx = ux_api::service::gfx::Gfx::new(&_env.xns).unwrap();
|
||||||
|
match gfx.acquire_qr() {
|
||||||
|
Ok(qr_data) => {
|
||||||
|
if let Some(meta) = qr_data.meta {
|
||||||
|
log::info!("QR code metadata: {}", meta);
|
||||||
|
}
|
||||||
|
if let Some(coded) = qr_data.content {
|
||||||
|
match base45::decode(&coded) {
|
||||||
|
Ok(data) => {
|
||||||
|
log::info!("Recovered: {:x?}", data);
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
log::info!("Base45 decode err: {:?}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
log::info!("QR error: {:?}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
write!(ret, "{}", helpstring).unwrap();
|
write!(ret, "{}", helpstring).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ use bao1x_api::*;
|
||||||
use bao1x_emu::{
|
use bao1x_emu::{
|
||||||
camera::Gc2145,
|
camera::Gc2145,
|
||||||
display::{MainThreadToken, Mono, Oled128x128, claim_main_thread},
|
display::{MainThreadToken, Mono, Oled128x128, claim_main_thread},
|
||||||
i2c::I2c,
|
|
||||||
udma::UdmaGlobal,
|
udma::UdmaGlobal,
|
||||||
};
|
};
|
||||||
// breadcrumb to future self:
|
// breadcrumb to future self:
|
||||||
|
|
@ -173,6 +172,7 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
// ---- basic hardware setup
|
// ---- basic hardware setup
|
||||||
let iox = IoxHal::new();
|
let iox = IoxHal::new();
|
||||||
let udma_global = UdmaGlobal::new();
|
let udma_global = UdmaGlobal::new();
|
||||||
|
#[cfg(not(feature = "hosted-baosec"))]
|
||||||
let mut i2c = I2c::new();
|
let mut i2c = I2c::new();
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
#[cfg(not(feature = "hosted-baosec"))]
|
#[cfg(not(feature = "hosted-baosec"))]
|
||||||
|
|
@ -206,17 +206,30 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
#[cfg(not(feature = "hosted-baosec"))]
|
#[cfg(not(feature = "hosted-baosec"))]
|
||||||
kbd.register_listener(SERVER_NAME_GFX, GfxOpcode::KeyPress.to_u32().unwrap() as usize);
|
kbd.register_listener(SERVER_NAME_GFX, GfxOpcode::KeyPress.to_u32().unwrap() as usize);
|
||||||
|
|
||||||
|
#[cfg(not(feature = "hosted-baosec"))]
|
||||||
|
let mut timer = {
|
||||||
|
let timer_range = xous::map_memory(
|
||||||
|
xous::MemoryAddress::new(utra::pwm::HW_PWM_BASE),
|
||||||
|
None,
|
||||||
|
4096,
|
||||||
|
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||||
|
)
|
||||||
|
.expect("couldn't map PWM range");
|
||||||
|
utralib::CSR::new(timer_range.as_ptr() as usize as *mut u32)
|
||||||
|
};
|
||||||
|
|
||||||
|
udma_global.udma_clock_config(PeriphId::Cam, true);
|
||||||
// ---- camera initialization
|
// ---- camera initialization
|
||||||
#[cfg(not(feature = "hosted-baosec"))]
|
#[cfg(not(feature = "hosted-baosec"))]
|
||||||
{
|
let (mut cam, cam_pdwn) = {
|
||||||
// wait for other inits to finish so we can do this roughly atomically
|
// wait for other inits to finish so we can do this roughly atomically
|
||||||
tt.sleep_ms(1000).ok();
|
tt.sleep_ms(1000).ok();
|
||||||
|
|
||||||
// setup camera power
|
// setup camera power
|
||||||
match bao1x_hal::axp2101::Axp2101::new(&mut i2c) {
|
match bao1x_hal::axp2101::Axp2101::new(&mut i2c) {
|
||||||
Ok(mut pmic) => {
|
Ok(mut pmic) => {
|
||||||
pmic.set_ldo(&mut i2c, Some(2.85), bao1x_hal::axp2101::WhichLdo::Bldo2).unwrap();
|
|
||||||
pmic.set_dcdc(&mut i2c, Some((1.8, false)), bao1x_hal::axp2101::WhichDcDc::Dcdc5).unwrap();
|
pmic.set_dcdc(&mut i2c, Some((1.8, false)), bao1x_hal::axp2101::WhichDcDc::Dcdc5).unwrap();
|
||||||
|
pmic.set_ldo(&mut i2c, Some(2.85), bao1x_hal::axp2101::WhichLdo::Bldo2).unwrap();
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
log::error!("Couldn't setup regulators for camera, camera will be non-functional: {:?}", e);
|
log::error!("Couldn't setup regulators for camera, camera will be non-functional: {:?}", e);
|
||||||
|
|
@ -245,22 +258,12 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
Some(IoxEnable::Disable),
|
Some(IoxEnable::Disable),
|
||||||
Some(IoxDriveStrength::Drive8mA),
|
Some(IoxDriveStrength::Drive8mA),
|
||||||
);
|
);
|
||||||
let timer_range = xous::map_memory(
|
|
||||||
xous::MemoryAddress::new(utra::pwm::HW_PWM_BASE),
|
|
||||||
None,
|
|
||||||
4096,
|
|
||||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
|
||||||
)
|
|
||||||
.expect("couldn't map PWM range");
|
|
||||||
let mut timer = utralib::CSR::new(timer_range.as_ptr() as usize as *mut u32);
|
|
||||||
timer.wo(utra::pwm::REG_CH_EN, 1);
|
timer.wo(utra::pwm::REG_CH_EN, 1);
|
||||||
timer.rmwf(utra::pwm::REG_TIM0_CFG_R_TIMER0_SAW, 1);
|
timer.rmwf(utra::pwm::REG_TIM0_CFG_R_TIMER0_SAW, 1);
|
||||||
timer.rmwf(utra::pwm::REG_TIM0_CH0_TH_R_TIMER0_CH0_TH, 0);
|
timer.rmwf(utra::pwm::REG_TIM0_CH0_TH_R_TIMER0_CH0_TH, 0);
|
||||||
timer.rmwf(utra::pwm::REG_TIM0_CH0_TH_R_TIMER0_CH0_MODE, 3);
|
timer.rmwf(utra::pwm::REG_TIM0_CH0_TH_R_TIMER0_CH0_MODE, 3);
|
||||||
let pwm = timer_range.as_mut_ptr() as *mut u32;
|
unsafe { timer.base().add(2).write_volatile(0) }; // for some reason the register extraction didn't get this register...
|
||||||
unsafe { pwm.add(2).write_volatile(0) }; // for some reason the register extraction didn't get this register...
|
timer.rmwf(utra::pwm::REG_TIM0_CMD_R_TIMER0_START, 0);
|
||||||
timer.rmwf(utra::pwm::REG_TIM0_CMD_R_TIMER0_START, 1);
|
|
||||||
log::info!("PWM running on PA0");
|
|
||||||
/* // register debug
|
/* // register debug
|
||||||
for i in 0..12 {
|
for i in 0..12 {
|
||||||
println!("0x{:2x}: 0x{:08x}", i, unsafe { pwm.add(i).read_volatile() })
|
println!("0x{:2x}: 0x{:08x}", i, unsafe { pwm.add(i).read_volatile() })
|
||||||
|
|
@ -269,26 +272,44 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// setup camera pins
|
// setup camera pins
|
||||||
let (cam_pdwn_bnk, cam_pdwn_pin) = bao1x_hal::board::setup_camera_pins(&iox);
|
let cam_pdwn = bao1x_hal::board::setup_camera_pins(&iox);
|
||||||
// disable camera powerdown
|
// this is safe because we turned on the clocks before calling it
|
||||||
iox.set_gpio_pin_value(cam_pdwn_bnk, cam_pdwn_pin, IoxValue::Low);
|
let mut cam = unsafe { Gc2145::new().expect("couldn't allocate camera") };
|
||||||
}
|
|
||||||
udma_global.udma_clock_config(PeriphId::Cam, true);
|
timer.rmwf(utra::pwm::REG_TIM0_CMD_R_TIMER0_START, 1);
|
||||||
// this is safe because we turned on the clocks before calling it
|
tt.sleep_ms(2).ok(); // wait for camera to clock-up
|
||||||
|
iox.set_gpio_pin_value(cam_pdwn.0, cam_pdwn.1, IoxValue::Low);
|
||||||
|
|
||||||
|
// power up the camera
|
||||||
|
// starts MCLK
|
||||||
|
timer.rmwf(utra::pwm::REG_TIM0_CMD_R_TIMER0_START, 1);
|
||||||
|
tt.sleep_ms(2).ok(); // wait for camera to clock-up
|
||||||
|
// bring camera out of powerdown
|
||||||
|
iox.set_gpio_pin_value(cam_pdwn.0, cam_pdwn.1, IoxValue::Low);
|
||||||
|
tt.sleep_ms(3).ok(); // wait for camera to power-up
|
||||||
|
let (pid, mid) = cam.read_id(&mut i2c);
|
||||||
|
log::info!("Camera pid {:x}, mid {:x}", pid, mid);
|
||||||
|
cam.init(&mut i2c, bao1x_api::camera::Resolution::Res320x240);
|
||||||
|
tt.sleep_ms(1).ok();
|
||||||
|
|
||||||
|
let (cols, _rows) = cam.resolution();
|
||||||
|
let border = (cols - IMAGE_WIDTH) / 2;
|
||||||
|
cam.set_slicing((border, 0), (cols - border, IMAGE_HEIGHT));
|
||||||
|
tt.sleep_ms(2).ok();
|
||||||
|
|
||||||
|
// power down the camera, now that all the internal registers have been set up
|
||||||
|
// assert PWWDN
|
||||||
|
iox.set_gpio_pin_value(cam_pdwn.0, cam_pdwn.1, IoxValue::High);
|
||||||
|
// stop MCLK
|
||||||
|
tt.sleep_ms(2).ok();
|
||||||
|
timer.rmwf(utra::pwm::REG_TIM0_CMD_R_TIMER0_START, 0);
|
||||||
|
|
||||||
|
(cam, cam_pdwn)
|
||||||
|
};
|
||||||
|
#[cfg(feature = "hosted-baosec")]
|
||||||
|
// unused dummy object
|
||||||
let mut cam = unsafe { Gc2145::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, bao1x_api::camera::Resolution::Res320x240);
|
|
||||||
tt.sleep_ms(1).ok();
|
|
||||||
|
|
||||||
let (cols, _rows) = cam.resolution();
|
|
||||||
let border = (cols - IMAGE_WIDTH) / 2;
|
|
||||||
cam.set_slicing((border, 0), (cols - border, IMAGE_HEIGHT));
|
|
||||||
log::info!("320x240 resolution setup with 256x240 slicing");
|
|
||||||
|
|
||||||
#[cfg(not(feature = "hosted-baosec"))]
|
#[cfg(not(feature = "hosted-baosec"))]
|
||||||
let cid = xous::connect(sid).unwrap(); // self-connection always succeeds
|
let cid = xous::connect(sid).unwrap(); // self-connection always succeeds
|
||||||
|
|
||||||
|
|
@ -324,17 +345,15 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
#[cfg(feature = "autotest")]
|
#[cfg(feature = "autotest")]
|
||||||
{
|
{
|
||||||
log::info!("initiating auto test");
|
log::info!("initiating auto test");
|
||||||
cam.capture_async();
|
let acquisition = QrAcquisition { content: None, meta: None };
|
||||||
// cam_irq serves as a preemption timer source, every time it fires a different
|
let mut buf = Buffer::into_buf(acquisition).unwrap();
|
||||||
// task can run after cam_irq is handled.
|
buf.lend_mut(cid, GfxOpcode::AcquireQr.to_u32().unwrap()).ok();
|
||||||
hal.set_preemption(false);
|
|
||||||
}
|
}
|
||||||
#[cfg(feature = "no-gam")]
|
#[cfg(feature = "no-gam")]
|
||||||
let modals = modals::Modals::new(&xns).unwrap();
|
let modals = modals::Modals::new(&xns).unwrap();
|
||||||
let mut modal_queue = VecDeque::<Sender>::new();
|
let mut modal_queue = VecDeque::<Sender>::new();
|
||||||
let mut frames = 0;
|
let mut frames = 0;
|
||||||
let mut frame = [0u8; IMAGE_WIDTH * IMAGE_HEIGHT];
|
let mut frame = [0u8; IMAGE_WIDTH * IMAGE_HEIGHT];
|
||||||
let mut decode_success;
|
|
||||||
let mut msg_opt = None;
|
let mut msg_opt = None;
|
||||||
#[cfg(feature = "gfx-testing")]
|
#[cfg(feature = "gfx-testing")]
|
||||||
testing::tests();
|
testing::tests();
|
||||||
|
|
@ -356,6 +375,23 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
// this will defer response until later
|
// this will defer response until later
|
||||||
qr_request = msg_opt.take();
|
qr_request = msg_opt.take();
|
||||||
|
|
||||||
|
// power up the camera
|
||||||
|
// starts MCLK
|
||||||
|
timer.rmwf(utra::pwm::REG_TIM0_CMD_R_TIMER0_START, 1);
|
||||||
|
tt.sleep_ms(2).ok(); // wait for camera to clock-up
|
||||||
|
// bring camera out of powerdown
|
||||||
|
iox.set_gpio_pin_value(cam_pdwn.0, cam_pdwn.1, IoxValue::Low);
|
||||||
|
tt.sleep_ms(3).ok(); // wait for camera to power-up
|
||||||
|
let (pid, mid) = cam.read_id(&mut i2c);
|
||||||
|
log::info!("Camera pid {:x}, mid {:x}", pid, mid);
|
||||||
|
cam.init(&mut i2c, bao1x_api::camera::Resolution::Res320x240);
|
||||||
|
tt.sleep_ms(1).ok();
|
||||||
|
|
||||||
|
let (cols, _rows) = cam.resolution();
|
||||||
|
let border = (cols - IMAGE_WIDTH) / 2;
|
||||||
|
cam.set_slicing((border, 0), (cols - border, IMAGE_HEIGHT));
|
||||||
|
log::info!("320x240 resolution setup with 256x240 slicing");
|
||||||
|
|
||||||
// decode dummy data - what this does is load the swapped out QR decoding logic, thus
|
// decode dummy data - what this does is load the swapped out QR decoding logic, thus
|
||||||
// improving the latency of the decoder on the "first hit". The sole purpose of this
|
// improving the latency of the decoder on the "first hit". The sole purpose of this
|
||||||
// is to improve the user experience during scanning.
|
// is to improve the user experience during scanning.
|
||||||
|
|
@ -427,6 +463,16 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
GfxOpcode::CamIrq => {
|
GfxOpcode::CamIrq => {
|
||||||
if qr_request.is_some() {
|
if qr_request.is_some() {
|
||||||
cam.capture_async();
|
cam.capture_async();
|
||||||
|
} else {
|
||||||
|
#[cfg(not(feature = "hosted-baosec"))]
|
||||||
|
{
|
||||||
|
// power down the camera, now that the request is done
|
||||||
|
// assert PWWDN
|
||||||
|
iox.set_gpio_pin_value(cam_pdwn.0, cam_pdwn.1, IoxValue::High);
|
||||||
|
// stop MCLK
|
||||||
|
tt.sleep_ms(2).ok();
|
||||||
|
timer.rmwf(utra::pwm::REG_TIM0_CMD_R_TIMER0_START, 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy the camera data to our FB
|
// copy the camera data to our FB
|
||||||
|
|
@ -450,7 +496,6 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
frames += 1;
|
frames += 1;
|
||||||
|
|
||||||
let mut candidates = Vec::<Point>::new();
|
let mut candidates = Vec::<Point>::new();
|
||||||
decode_success = false;
|
|
||||||
log::debug!("------------- SEARCH {} -----------", frames);
|
log::debug!("------------- SEARCH {} -----------", frames);
|
||||||
let _finder_width =
|
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;
|
||||||
|
|
@ -459,24 +504,18 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
if candidates.len() == 3 {
|
if candidates.len() == 3 {
|
||||||
gfx::msg(
|
gfx::msg(
|
||||||
&mut display,
|
&mut display,
|
||||||
"Searching...",
|
"Decoding...",
|
||||||
Point::new(0, 0),
|
Point::new(0, 0),
|
||||||
Mono::White.into(),
|
Mono::White.into(),
|
||||||
Mono::Black.into(),
|
Mono::Black.into(),
|
||||||
);
|
);
|
||||||
|
display.draw();
|
||||||
let mut img =
|
let mut img =
|
||||||
rqrr::PreparedImage::prepare_from_greyscale(IMAGE_WIDTH, IMAGE_HEIGHT, |x, y| {
|
rqrr::PreparedImage::prepare_from_greyscale(IMAGE_WIDTH, IMAGE_HEIGHT, |x, y| {
|
||||||
frame[y * IMAGE_WIDTH + x]
|
frame[y * IMAGE_WIDTH + x]
|
||||||
});
|
});
|
||||||
let grids = img.detect_grids();
|
let grids = img.detect_grids();
|
||||||
if grids.len() == 1 {
|
if grids.len() == 1 {
|
||||||
gfx::msg(
|
|
||||||
&mut display,
|
|
||||||
"Decoding...",
|
|
||||||
Point::new(0, 0),
|
|
||||||
Mono::White.into(),
|
|
||||||
Mono::Black.into(),
|
|
||||||
);
|
|
||||||
match grids[0].decode() {
|
match grids[0].decode() {
|
||||||
Ok((meta, content)) => {
|
Ok((meta, content)) => {
|
||||||
gfx::msg(
|
gfx::msg(
|
||||||
|
|
@ -505,7 +544,6 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
} else {
|
} else {
|
||||||
log::info!("meta: {:?}", meta);
|
log::info!("meta: {:?}", meta);
|
||||||
log::info!("************ {} ***********", content);
|
log::info!("************ {} ***********", content);
|
||||||
decode_success = true;
|
|
||||||
gfx::msg(
|
gfx::msg(
|
||||||
&mut display,
|
&mut display,
|
||||||
&format!("{:?}", meta),
|
&format!("{:?}", meta),
|
||||||
|
|
@ -545,9 +583,6 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
}
|
}
|
||||||
|
|
||||||
display.draw();
|
display.draw();
|
||||||
if decode_success {
|
|
||||||
tt.sleep_ms(1500).ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
// clear the front buffer
|
// clear the front buffer
|
||||||
display.clear();
|
display.clear();
|
||||||
|
|
@ -702,6 +737,9 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
}
|
}
|
||||||
// no failure if it's not
|
// no failure if it's not
|
||||||
}
|
}
|
||||||
|
GfxOpcode::RenderQr => {
|
||||||
|
minigfx::handlers::render_qr(&mut display, screen_clip.into(), msg);
|
||||||
|
}
|
||||||
GfxOpcode::Quit => break,
|
GfxOpcode::Quit => break,
|
||||||
_ => {
|
_ => {
|
||||||
// This is perfectly normal because not all opcodes are handled by all platforms.
|
// This is perfectly normal because not all opcodes are handled by all platforms.
|
||||||
|
|
|
||||||
|
|
@ -520,7 +520,7 @@ fn wrapped_main() -> ! {
|
||||||
renderer_modal.modify(
|
renderer_modal.modify(
|
||||||
Some(ActionType::Notification(notification)),
|
Some(ActionType::Notification(notification)),
|
||||||
Some(text),
|
Some(text),
|
||||||
false,
|
text.len() == 0,
|
||||||
None,
|
None,
|
||||||
true,
|
true,
|
||||||
Some(DEFAULT_STYLE),
|
Some(DEFAULT_STYLE),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue