Port io_expander code from Kasli #214
|
@ -32,7 +32,6 @@ use crate::moninj;
|
||||||
use crate::mgmt;
|
use crate::mgmt;
|
||||||
use crate::analyzer;
|
use crate::analyzer;
|
||||||
use crate::rtio_mgt::{self, resolve_channel_name};
|
use crate::rtio_mgt::{self, resolve_channel_name};
|
||||||
use crate::io_expander;
|
|
||||||
#[cfg(has_drtio)]
|
#[cfg(has_drtio)]
|
||||||
use crate::pl;
|
use crate::pl;
|
||||||
|
|
||||||
|
@ -381,7 +380,7 @@ async fn handle_connection(stream: &mut TcpStream, control: Rc<RefCell<kernel::C
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main(timer: GlobalTimer, cfg: Config, mut io_expander0: io_expander::IoExpander, mut io_expander1: io_expander::IoExpander) {
|
pub fn main(timer: GlobalTimer, cfg: Config) {
|
||||||
let net_addresses = net_settings::get_addresses(&cfg);
|
let net_addresses = net_settings::get_addresses(&cfg);
|
||||||
info!("network addresses: {}", net_addresses);
|
info!("network addresses: {}", net_addresses);
|
||||||
|
|
||||||
|
@ -495,11 +494,6 @@ pub fn main(timer: GlobalTimer, cfg: Config, mut io_expander0: io_expander::IoEx
|
||||||
let _ = stream.flush().await;
|
let _ = stream.flush().await;
|
||||||
let _ = stream.abort().await;
|
let _ = stream.abort().await;
|
||||||
});
|
});
|
||||||
#[cfg(feature = "target_kasli_soc")]
|
|
||||||
{
|
|
||||||
io_expander0.service().expect("I2C I/O expander #0 service failed");
|
|
||||||
io_expander1.service().expect("I2C I/O expander #1 service failed");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ use crate::i2c;
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
// Only the bare minimum registers. Bits/IO connections equivalent between IC types.
|
// Only the bare minimum registers. Bits/IO connections equivalent between IC types.
|
||||||
#[cfg(feature = "target_kasli_soc")]
|
|
||||||
struct Registers {
|
struct Registers {
|
||||||
// PCA9539 equivalent register names in comments
|
// PCA9539 equivalent register names in comments
|
||||||
iodira: u8, // Configuration Port 0
|
iodira: u8, // Configuration Port 0
|
||||||
|
@ -11,33 +10,19 @@ struct Registers {
|
||||||
gpiob: u8, // Output Port 1
|
gpiob: u8, // Output Port 1
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "target_kasli_soc")]
|
|
||||||
pub struct IoExpander {
|
pub struct IoExpander {
|
||||||
busno: i32,
|
busno: i32,
|
||||||
port: u8,
|
port: u8,
|
||||||
address: i32,
|
address: i32,
|
||||||
virtual_led_mapping: &'static [(u8, u8, u8)],
|
|
||||||
iodir: [u8; 2],
|
iodir: [u8; 2],
|
||||||
out_current: [u8; 2],
|
out_current: [u8; 2],
|
||||||
out_target: [u8; 2],
|
out_target: [u8; 2],
|
||||||
registers: Registers,
|
registers: Registers,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(feature = "target_kasli_soc"))]
|
|
||||||
pub struct IoExpander;
|
|
||||||
|
|
||||||
#[cfg(not(feature = "target_kasli_soc"))]
|
|
||||||
impl IoExpander {
|
impl IoExpander {
|
||||||
pub fn new(index: u8) -> Result<Self, &'static str> {
|
pub fn new(index: u8) -> Result<Self, &'static str> {
|
||||||
Ok(IoExpander {})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "target_kasli_soc")]
|
|
||||||
impl IoExpander {
|
|
||||||
pub fn new(index: u8) -> Result<Self, &'static str> {
|
|
||||||
const VIRTUAL_LED_MAPPING0: [(u8, u8, u8); 2] = [(0, 0, 6), (1, 1, 6)];
|
|
||||||
const VIRTUAL_LED_MAPPING1: [(u8, u8, u8); 2] = [(2, 0, 6), (3, 1, 6)];
|
|
||||||
|
|
||||||
// Both expanders on SHARED I2C bus
|
// Both expanders on SHARED I2C bus
|
||||||
let mut io_expander = match index {
|
let mut io_expander = match index {
|
||||||
|
@ -45,7 +30,6 @@ impl IoExpander {
|
||||||
busno: 0,
|
busno: 0,
|
||||||
port: 11,
|
port: 11,
|
||||||
address: 0x40,
|
address: 0x40,
|
||||||
virtual_led_mapping: &VIRTUAL_LED_MAPPING0,
|
|
||||||
iodir: [0xff; 2],
|
iodir: [0xff; 2],
|
||||||
out_current: [0; 2],
|
out_current: [0; 2],
|
||||||
out_target: [0; 2],
|
out_target: [0; 2],
|
||||||
|
@ -60,7 +44,6 @@ impl IoExpander {
|
||||||
busno: 0,
|
busno: 0,
|
||||||
port: 11,
|
port: 11,
|
||||||
address: 0x42,
|
address: 0x42,
|
||||||
virtual_led_mapping: &VIRTUAL_LED_MAPPING1,
|
|
||||||
iodir: [0xff; 2],
|
iodir: [0xff; 2],
|
||||||
out_current: [0; 2],
|
out_current: [0; 2],
|
||||||
out_target: [0; 2],
|
out_target: [0; 2],
|
||||||
|
@ -125,10 +108,6 @@ impl IoExpander {
|
||||||
|
|
||||||
pub fn init(&mut self) -> Result<(), &'static str> {
|
pub fn init(&mut self) -> Result<(), &'static str> {
|
||||||
self.select()?;
|
self.select()?;
|
||||||
|
|
||||||
for (_led, port, bit) in self.virtual_led_mapping.iter() {
|
|
||||||
self.iodir[*port as usize] &= !(1 << *bit);
|
|
||||||
}
|
|
||||||
self.update_iodir()?;
|
self.update_iodir()?;
|
||||||
|
|
||||||
self.out_current[0] = 0x00;
|
self.out_current[0] = 0x00;
|
||||||
|
@ -153,10 +132,6 @@ impl IoExpander {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn service(&mut self) -> Result<(), &'static str> {
|
pub fn service(&mut self) -> Result<(), &'static str> {
|
||||||
for (_led, port, bit) in self.virtual_led_mapping.iter() {
|
|
||||||
self.set(*port, *bit, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.out_target != self.out_current {
|
if self.out_target != self.out_current {
|
||||||
self.select()?;
|
self.select()?;
|
||||||
if self.out_target[0] != self.out_current[0] {
|
if self.out_target[0] != self.out_current[0] {
|
||||||
|
|
|
@ -46,6 +46,7 @@ mod mgmt;
|
||||||
mod analyzer;
|
mod analyzer;
|
||||||
mod irq;
|
mod irq;
|
||||||
mod i2c;
|
mod i2c;
|
||||||
|
#[cfg(feature = "target_kasli_soc")]
|
||||||
mod io_expander;
|
mod io_expander;
|
||||||
|
|
||||||
static mut SEEN_ASYNC_ERRORS: u8 = 0;
|
static mut SEEN_ASYNC_ERRORS: u8 = 0;
|
||||||
|
@ -115,9 +116,9 @@ pub fn main_core0() {
|
||||||
|
|
||||||
i2c::init();
|
i2c::init();
|
||||||
|
|
||||||
let (mut io_expander0, mut io_expander1) = (io_expander::IoExpander::new(0).unwrap(), io_expander::IoExpander::new(1).unwrap());
|
|
||||||
#[cfg(feature = "target_kasli_soc")]
|
#[cfg(feature = "target_kasli_soc")]
|
||||||
{
|
{
|
||||||
|
let (mut io_expander0, mut io_expander1) = (io_expander::IoExpander::new(0).unwrap(), io_expander::IoExpander::new(1).unwrap());
|
||||||
io_expander0.init().expect("I2C I/O expander #0 initialization failed");
|
io_expander0.init().expect("I2C I/O expander #0 initialization failed");
|
||||||
io_expander1.init().expect("I2C I/O expander #1 initialization failed");
|
io_expander1.init().expect("I2C I/O expander #1 initialization failed");
|
||||||
|
|
||||||
|
@ -146,5 +147,5 @@ pub fn main_core0() {
|
||||||
|
|
||||||
task::spawn(report_async_rtio_errors());
|
task::spawn(report_async_rtio_errors());
|
||||||
|
|
||||||
comms::main(timer, cfg, io_expander0, io_expander1);
|
comms::main(timer, cfg);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue