mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
fix power consumption on camera
mclk wasn't stopping correctly, causing lots of leakage power.
This commit is contained in:
parent
a3a566b240
commit
0ada90fec5
1 changed files with 50 additions and 12 deletions
|
|
@ -35,10 +35,11 @@ use bao1x_emu::{
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(feature = "board-baosec")]
|
||||||
use bao1x_hal::{
|
use bao1x_hal::{
|
||||||
gc2145::Gc2145,
|
gc2145::Gc2145,
|
||||||
|
i2c::I2c,
|
||||||
sh1107::{MainThreadToken, Mono, Oled128x128, claim_main_thread},
|
sh1107::{MainThreadToken, Mono, Oled128x128, claim_main_thread},
|
||||||
};
|
};
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(feature = "board-baosec")]
|
||||||
use bao1x_hal_service::{I2c, UdmaGlobal};
|
use bao1x_hal_service::UdmaGlobal;
|
||||||
#[cfg(feature = "b64-export")]
|
#[cfg(feature = "b64-export")]
|
||||||
use base64::{Engine as _, engine::general_purpose};
|
use base64::{Engine as _, engine::general_purpose};
|
||||||
#[cfg(feature = "board-baosec")]
|
#[cfg(feature = "board-baosec")]
|
||||||
|
|
@ -236,18 +237,12 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// setup camera clock
|
// ensure that muxed pins are tri-state for low power (maybe move this too loader?)
|
||||||
iox.setup_pin(IoxPort::PF, 9, Some(IoxDir::Input), Some(IoxFunction::Gpio), None, None, None, None);
|
iox.setup_pin(IoxPort::PF, 9, Some(IoxDir::Input), Some(IoxFunction::Gpio), None, None, None, None);
|
||||||
iox.setup_pin(
|
iox.setup_pin(IoxPort::PA, 1, Some(IoxDir::Input), Some(IoxFunction::Gpio), None, None, None, None);
|
||||||
IoxPort::PA,
|
iox.setup_pin(IoxPort::PA, 2, Some(IoxDir::Input), Some(IoxFunction::Gpio), None, None, None, None);
|
||||||
0,
|
|
||||||
Some(IoxDir::Output),
|
// setup camera clock
|
||||||
Some(IoxFunction::Gpio),
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
Some(IoxEnable::Disable),
|
|
||||||
Some(IoxDriveStrength::Drive8mA),
|
|
||||||
);
|
|
||||||
iox.setup_pin(
|
iox.setup_pin(
|
||||||
IoxPort::PA,
|
IoxPort::PA,
|
||||||
0,
|
0,
|
||||||
|
|
@ -303,6 +298,8 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
// stop MCLK
|
// stop MCLK
|
||||||
tt.sleep_ms(2).ok();
|
tt.sleep_ms(2).ok();
|
||||||
timer.rmwf(utra::pwm::REG_TIM0_CMD_R_TIMER0_START, 0);
|
timer.rmwf(utra::pwm::REG_TIM0_CMD_R_TIMER0_START, 0);
|
||||||
|
timer.wo(utra::pwm::REG_CH_EN, 0);
|
||||||
|
iox.setup_pin(IoxPort::PA, 0, Some(IoxDir::Input), Some(IoxFunction::Gpio), None, None, None, None);
|
||||||
|
|
||||||
(cam, cam_pdwn)
|
(cam, cam_pdwn)
|
||||||
};
|
};
|
||||||
|
|
@ -377,6 +374,17 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
|
|
||||||
// power up the camera
|
// power up the camera
|
||||||
// starts MCLK
|
// starts MCLK
|
||||||
|
iox.setup_pin(
|
||||||
|
IoxPort::PA,
|
||||||
|
0,
|
||||||
|
Some(IoxDir::Output),
|
||||||
|
Some(IoxFunction::AF3),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
Some(IoxEnable::Disable),
|
||||||
|
Some(IoxDriveStrength::Drive8mA),
|
||||||
|
);
|
||||||
|
timer.wo(utra::pwm::REG_CH_EN, 1);
|
||||||
timer.rmwf(utra::pwm::REG_TIM0_CMD_R_TIMER0_START, 1);
|
timer.rmwf(utra::pwm::REG_TIM0_CMD_R_TIMER0_START, 1);
|
||||||
tt.sleep_ms(2).ok(); // wait for camera to clock-up
|
tt.sleep_ms(2).ok(); // wait for camera to clock-up
|
||||||
// bring camera out of powerdown
|
// bring camera out of powerdown
|
||||||
|
|
@ -472,6 +480,17 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
// stop MCLK
|
// stop MCLK
|
||||||
tt.sleep_ms(2).ok();
|
tt.sleep_ms(2).ok();
|
||||||
timer.rmwf(utra::pwm::REG_TIM0_CMD_R_TIMER0_START, 0);
|
timer.rmwf(utra::pwm::REG_TIM0_CMD_R_TIMER0_START, 0);
|
||||||
|
timer.wo(utra::pwm::REG_CH_EN, 0);
|
||||||
|
iox.setup_pin(
|
||||||
|
IoxPort::PA,
|
||||||
|
0,
|
||||||
|
Some(IoxDir::Input),
|
||||||
|
Some(IoxFunction::Gpio),
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -740,6 +759,25 @@ pub fn wrapped_main(main_thread_token: MainThreadToken) -> ! {
|
||||||
GfxOpcode::RenderQr => {
|
GfxOpcode::RenderQr => {
|
||||||
minigfx::handlers::render_qr(&mut display, screen_clip.into(), msg);
|
minigfx::handlers::render_qr(&mut display, screen_clip.into(), msg);
|
||||||
}
|
}
|
||||||
|
GfxOpcode::PowerDown => {
|
||||||
|
display.stash();
|
||||||
|
display.powerdown();
|
||||||
|
if let Some(scalar) = msg.body.scalar_message_mut() {
|
||||||
|
// ack the message if it's a blocking scalar
|
||||||
|
scalar.arg1 = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
GfxOpcode::PowerUp => {
|
||||||
|
// safety: this is safe because we call init() a prescribed delay after power-up
|
||||||
|
unsafe { display.powerup() };
|
||||||
|
tt.sleep_ms(5).ok();
|
||||||
|
display.init();
|
||||||
|
display.pop();
|
||||||
|
if let Some(scalar) = msg.body.scalar_message_mut() {
|
||||||
|
// ack the message if it's a blocking scalar
|
||||||
|
scalar.arg1 = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
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.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue