mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-15 08:30:02 +00:00
add support for more board options
- oem-baosec-lite board support - more flash memory types - transparent polarity switching on reset line The reset line in particular is having its polarity switched because the I/Os pull-up by default, and we'd like the reset line for peripherals to be asserted on reset (this prevents glitching on e.g. displays while the CPU boots).
This commit is contained in:
parent
42a55cc238
commit
4523fea62c
4 changed files with 72 additions and 27 deletions
|
|
@ -71,6 +71,9 @@ board-baosec = [
|
|||
"ux-api/board-baosec",
|
||||
"ux-api/std",
|
||||
] # USB form factor token
|
||||
# "lite" variant of baosec. Shares the same basic flags but some things remapped when this is added.
|
||||
oem-baosec-lite = []
|
||||
|
||||
loader-baosec = [
|
||||
"utralib/bao1x",
|
||||
"camera-gc2145",
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ pub fn setup_memory_pins(iox: &dyn IoSetup) -> SpimChannel {
|
|||
None,
|
||||
Some(IoxFunction::AF1),
|
||||
None,
|
||||
None,
|
||||
Some(IoxEnable::Enable),
|
||||
Some(IoxEnable::Disable),
|
||||
Some(IoxDriveStrength::Drive8mA),
|
||||
);
|
||||
|
|
@ -169,7 +169,7 @@ pub fn setup_memory_pins(iox: &dyn IoSetup) -> SpimChannel {
|
|||
Some(IoxDir::Output),
|
||||
Some(IoxFunction::AF1),
|
||||
None,
|
||||
None,
|
||||
Some(IoxEnable::Enable),
|
||||
Some(IoxEnable::Disable),
|
||||
Some(IoxDriveStrength::Drive8mA),
|
||||
);
|
||||
|
|
@ -220,9 +220,13 @@ pub fn get_i2c_channel() -> I2cChannel { I2C_CHANNEL }
|
|||
|
||||
/// returns the power-down port and pin number
|
||||
pub fn setup_camera_pins<T: IoSetup + IoGpio>(iox: &T) -> (IoxPort, u8) {
|
||||
#[cfg(not(feature = "oem-baosec-lite"))]
|
||||
let pwdn = (IoxPort::PC, 14);
|
||||
#[cfg(feature = "oem-baosec-lite")]
|
||||
let pwdn = (IoxPort::PA, 5);
|
||||
iox.setup_pin(
|
||||
IoxPort::PC,
|
||||
14,
|
||||
pwdn.0,
|
||||
pwdn.1,
|
||||
Some(IoxDir::Output),
|
||||
Some(IoxFunction::Gpio),
|
||||
None,
|
||||
|
|
@ -231,7 +235,7 @@ pub fn setup_camera_pins<T: IoSetup + IoGpio>(iox: &T) -> (IoxPort, u8) {
|
|||
Some(IoxDriveStrength::Drive2mA),
|
||||
);
|
||||
// power-down pin - default to powered down
|
||||
iox.set_gpio_pin_value(IoxPort::PC, 14, IoxValue::High);
|
||||
iox.set_gpio_pin_value(pwdn.0, pwdn.1, IoxValue::High);
|
||||
// camera interface proper
|
||||
for pin in 2..11 {
|
||||
iox.setup_pin(
|
||||
|
|
@ -245,11 +249,13 @@ pub fn setup_camera_pins<T: IoSetup + IoGpio>(iox: &T) -> (IoxPort, u8) {
|
|||
Some(IoxDriveStrength::Drive2mA),
|
||||
);
|
||||
}
|
||||
(IoxPort::PC, 14)
|
||||
pwdn
|
||||
}
|
||||
|
||||
pub fn setup_periph_reset_pin<T: IoSetup + IoGpio>(iox: &T) -> (IoxPort, u8) {
|
||||
#[cfg(not(feature = "oem-baosec-lite"))]
|
||||
let (port, pin) = (IoxPort::PC, 6);
|
||||
#[cfg(not(feature = "oem-baosec-lite"))]
|
||||
iox.setup_pin(
|
||||
port,
|
||||
pin,
|
||||
|
|
@ -260,9 +266,44 @@ pub fn setup_periph_reset_pin<T: IoSetup + IoGpio>(iox: &T) -> (IoxPort, u8) {
|
|||
None,
|
||||
Some(IoxDriveStrength::Drive2mA),
|
||||
);
|
||||
#[cfg(feature = "oem-baosec-lite")]
|
||||
let (port, pin) = (IoxPort::PA, 6);
|
||||
#[cfg(feature = "oem-baosec-lite")]
|
||||
iox.setup_pin(
|
||||
port,
|
||||
pin,
|
||||
Some(IoxDir::Output),
|
||||
Some(IoxFunction::Gpio),
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
Some(IoxDriveStrength::Drive2mA),
|
||||
);
|
||||
(port, pin)
|
||||
}
|
||||
|
||||
/// ASSUME: setup_periph_reset_pin has already been invoked
|
||||
pub fn assert_periph_reset(iox: &dyn IoGpio, assert: bool) {
|
||||
#[cfg(not(feature = "oem-baosec-lite"))]
|
||||
{
|
||||
let (port, pin) = (IoxPort::PC, 6);
|
||||
if assert {
|
||||
iox.set_gpio_pin_value(port, pin, IoxValue::Low);
|
||||
} else {
|
||||
iox.set_gpio_pin_value(port, pin, IoxValue::High);
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "oem-baosec-lite")]
|
||||
{
|
||||
let (port, pin) = (IoxPort::PA, 6);
|
||||
if assert {
|
||||
iox.set_gpio_pin_value(port, pin, IoxValue::High);
|
||||
} else {
|
||||
iox.set_gpio_pin_value(port, pin, IoxValue::Low);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// returns the USB SE0 port and pin number
|
||||
pub fn setup_usb_pins<T: IoSetup + IoGpio>(iox: &T) -> (IoxPort, u8) {
|
||||
const SE0_PIN: u8 = 5;
|
||||
|
|
@ -450,6 +491,7 @@ pub fn kpc_sr1_to_key(raw_event: u32) -> KeyPress {
|
|||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "oem-baosec-lite"))]
|
||||
pub fn setup_pmic_irq<T: IoIrq>(iox: &T, server: &str, opcode: usize) {
|
||||
iox.set_irq_pin(IoxPort::PB, 15, IoxValue::Low, server, opcode);
|
||||
}
|
||||
|
|
@ -500,6 +542,12 @@ pub fn setup_trng_input_pin<T: IoSetup + IoGpio>(iox: &T) -> (IoxPort, u8) {
|
|||
(port, pin)
|
||||
}
|
||||
|
||||
#[cfg(feature = "oem-baosec-lite")]
|
||||
pub fn get_power_off_pin() -> (IoxPort, u8) {
|
||||
let (port, pin) = (IoxPort::PF, 0);
|
||||
(port, pin)
|
||||
}
|
||||
|
||||
pub fn setup_dcdc2_pin<T: IoSetup + IoGpio>(iox: &T) -> (IoxPort, u8) {
|
||||
let (port, pin) = (IoxPort::PF, 0);
|
||||
iox.setup_pin(
|
||||
|
|
|
|||
|
|
@ -180,10 +180,6 @@ pub struct Oled128x128<'a> {
|
|||
powerdown: bool,
|
||||
power_port: IoxPort,
|
||||
power_pin: u8,
|
||||
/// Note: this pin is also tied to the reset on the camera. We're assuming that there is no
|
||||
/// possible state where we'd want the camera running without the display also on.
|
||||
reset_port: IoxPort,
|
||||
reset_pin: u8,
|
||||
}
|
||||
|
||||
impl<'a> Oled128x128<'a> {
|
||||
|
|
@ -246,7 +242,7 @@ impl<'a> Oled128x128<'a> {
|
|||
};
|
||||
spim.set_endianness(crate::udma::SpimEndian::MsbFirst);
|
||||
let (power_port, power_pin) = crate::board::setup_oled_power_pin(iox);
|
||||
let (reset_port, reset_pin) = crate::board::setup_periph_reset_pin(iox);
|
||||
crate::board::setup_periph_reset_pin(iox);
|
||||
Self {
|
||||
spim,
|
||||
// safety: this is safe because these ranges are in fact allocated, and all values can be
|
||||
|
|
@ -267,8 +263,6 @@ impl<'a> Oled128x128<'a> {
|
|||
iox,
|
||||
power_port,
|
||||
power_pin,
|
||||
reset_port,
|
||||
reset_pin,
|
||||
powerdown: false,
|
||||
}
|
||||
}
|
||||
|
|
@ -379,7 +373,7 @@ impl<'a> Oled128x128<'a> {
|
|||
let ifram_vaddr = spim.ifram.virt_range.as_mut_ptr();
|
||||
let (_channel, cd_port, cd_pin, _cs_pin) = crate::board::get_display_pins();
|
||||
let (power_port, power_pin) = crate::board::setup_oled_power_pin(iox);
|
||||
let (reset_port, reset_pin) = crate::board::setup_periph_reset_pin(iox);
|
||||
crate::board::setup_periph_reset_pin(iox);
|
||||
Self {
|
||||
spim,
|
||||
// safety: this is safe because these ranges are in fact allocated, and all values can be
|
||||
|
|
@ -401,8 +395,6 @@ impl<'a> Oled128x128<'a> {
|
|||
powerdown,
|
||||
power_pin,
|
||||
power_port,
|
||||
reset_port,
|
||||
reset_pin,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -496,7 +488,7 @@ impl<'a> Oled128x128<'a> {
|
|||
pub fn powerdown(&mut self) {
|
||||
self.powerdown = true;
|
||||
// assert reset
|
||||
self.iox.set_gpio_pin_value(self.reset_port, self.reset_pin, IoxValue::Low);
|
||||
crate::board::assert_periph_reset(self.iox, true);
|
||||
self.iox.set_gpio_pin_value(self.cd_port, self.cd_pin, IoxValue::Low);
|
||||
// cut power
|
||||
self.iox.set_gpio_pin_value(self.power_port, self.power_pin, IoxValue::Low);
|
||||
|
|
@ -509,7 +501,7 @@ impl<'a> Oled128x128<'a> {
|
|||
// restore power
|
||||
self.iox.set_gpio_pin_value(self.power_port, self.power_pin, IoxValue::High);
|
||||
// de-assert reset
|
||||
self.iox.set_gpio_pin_value(self.reset_port, self.reset_pin, IoxValue::High);
|
||||
crate::board::assert_periph_reset(self.iox, false);
|
||||
self.powerdown = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,10 +87,11 @@ pub enum SpimWaitType {
|
|||
pub enum CommandSet {
|
||||
Macronix = 0xc2,
|
||||
Xtx = 0x0b,
|
||||
Zetta = 0xba,
|
||||
}
|
||||
// be sure to update this when updating the command set above! this is used to iterate
|
||||
// through all valid types by other routines.
|
||||
pub const ALL_COMMAND_SETS: [CommandSet; 2] = [CommandSet::Macronix, CommandSet::Xtx];
|
||||
pub const ALL_COMMAND_SETS: [CommandSet; 3] = [CommandSet::Macronix, CommandSet::Xtx, CommandSet::Zetta];
|
||||
impl TryFrom<u8> for CommandSet {
|
||||
type Error = xous::Error;
|
||||
|
||||
|
|
@ -98,6 +99,7 @@ impl TryFrom<u8> for CommandSet {
|
|||
match value {
|
||||
0xc2 => Ok(CommandSet::Macronix),
|
||||
0x0b => Ok(CommandSet::Xtx),
|
||||
0xba => Ok(CommandSet::Zetta),
|
||||
_ => Err(xous::Error::BadAddress),
|
||||
}
|
||||
}
|
||||
|
|
@ -207,7 +209,7 @@ pub struct Spim {
|
|||
// length of a pending txrx, if any
|
||||
pending_txrx: Option<usize>,
|
||||
// type of command set to use - inferred from ID read
|
||||
command_set: Option<CommandSet>,
|
||||
pub command_set: Option<CommandSet>,
|
||||
}
|
||||
|
||||
// length of the command buffer
|
||||
|
|
@ -1042,7 +1044,7 @@ impl Spim {
|
|||
SpimMode::Standard => self.mem_send_cmd(0x9F),
|
||||
SpimMode::Quad => match self.command_set {
|
||||
Some(CommandSet::Macronix) | None => self.mem_send_cmd(0xAF),
|
||||
Some(CommandSet::Xtx) => self.mem_send_cmd(0x9F),
|
||||
Some(CommandSet::Xtx) | Some(CommandSet::Zetta) => self.mem_send_cmd(0x9F),
|
||||
},
|
||||
}
|
||||
|
||||
|
|
@ -1106,7 +1108,7 @@ impl Spim {
|
|||
if activate {
|
||||
match self.command_set {
|
||||
Some(CommandSet::Macronix) | None => self.mem_send_cmd(0x35),
|
||||
Some(CommandSet::Xtx) => {
|
||||
Some(CommandSet::Xtx) | Some(CommandSet::Zetta) => {
|
||||
crate::println!("activating Xtx QPI");
|
||||
self.mem_send_cmd(0x38)
|
||||
}
|
||||
|
|
@ -1115,7 +1117,7 @@ impl Spim {
|
|||
self.mode = SpimMode::Quad; // pre-assumes quad mode
|
||||
match self.command_set {
|
||||
Some(CommandSet::Macronix) | None => self.mem_send_cmd(0xF5),
|
||||
Some(CommandSet::Xtx) => self.mem_send_cmd(0xFF),
|
||||
Some(CommandSet::Xtx) | Some(CommandSet::Zetta) => self.mem_send_cmd(0xFF),
|
||||
}
|
||||
}
|
||||
self.mem_cs(false);
|
||||
|
|
@ -1128,7 +1130,7 @@ impl Spim {
|
|||
// cleanup any parameter settings
|
||||
match self.command_set {
|
||||
Some(CommandSet::Macronix) | None => (),
|
||||
Some(CommandSet::Xtx) => {
|
||||
Some(CommandSet::Xtx) | Some(CommandSet::Zetta) => {
|
||||
crate::println!("Xtx setting 6 dummy cycles");
|
||||
// set 6 dummy cycles; 8 is default
|
||||
self.mem_param_set(false, 0xc0, &[0b0010_0000]);
|
||||
|
|
@ -1358,7 +1360,7 @@ impl Spim {
|
|||
}
|
||||
self.mem_read_id_flash();
|
||||
let addresses: &[u8] = match self.command_set {
|
||||
Some(CommandSet::Xtx) => &[0x05, 0x35, 0x15],
|
||||
Some(CommandSet::Xtx) | Some(CommandSet::Zetta) => &[0x05, 0x35, 0x15],
|
||||
Some(CommandSet::Macronix) | None => &[0x05],
|
||||
};
|
||||
let mut ret = 0u32;
|
||||
|
|
@ -1396,7 +1398,7 @@ impl Spim {
|
|||
let sr = self.flash_read_status_register();
|
||||
let qe_set = match self.command_set {
|
||||
Some(CommandSet::Macronix) => 0b0100_0000 & sr != 0,
|
||||
Some(CommandSet::Xtx) => 0b10_0000_0000 & sr != 0,
|
||||
Some(CommandSet::Xtx) | Some(CommandSet::Zetta) => 0b10_0000_0000 & sr != 0,
|
||||
None => {
|
||||
crate::println!("Can't set QE on unknown flash type");
|
||||
return;
|
||||
|
|
@ -1411,7 +1413,7 @@ impl Spim {
|
|||
CommandSet::Macronix => {
|
||||
self.mem_write_status_register(0b0100_0000 | (sr & 0xFF) as u8, ((sr & 0xFF00) >> 8) as u8);
|
||||
}
|
||||
CommandSet::Xtx => {
|
||||
CommandSet::Xtx | CommandSet::Zetta => {
|
||||
self.mem_param_set(true, 0x31, &[((sr & 0xFF00 >> 8) as u8) | 0b0000_0010]);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue