Fix some bugs, add read_pin
This commit is contained in:
parent
dde679292a
commit
15f850623c
@ -141,17 +141,13 @@ fn main() -> ! {
|
||||
);
|
||||
|
||||
sx1509.init().unwrap();
|
||||
sx1509.set_pin_dir(15, sx1509::PinDirection::Output, true);
|
||||
|
||||
let mut is_high = true;
|
||||
sx1509.set_pin_dir(15, sx1509::PinDirection::InputPullUp, true);
|
||||
|
||||
let delay = Delay::new();
|
||||
|
||||
loop {
|
||||
delay.delay_millis(500);
|
||||
is_high = !is_high;
|
||||
sx1509.write_pin(15, is_high);
|
||||
log::info!("Pin: {}", is_high)
|
||||
log::info!("Pin: {:?}", sx1509.read_pin(15));
|
||||
}
|
||||
|
||||
// let mut at_commands = ATCommands::new(sim_rst, sim_pwr_key, uart);
|
||||
|
||||
@ -100,14 +100,14 @@ impl<'d> Sx1509<'d> {
|
||||
is_input = true;
|
||||
}
|
||||
|
||||
let mut temp_reg_data = self.read_16(Register::RegDirB);
|
||||
if !is_input {
|
||||
temp_reg_data |= 1 << pin;
|
||||
let mut temp_reg_dir = self.read_16(Register::RegDirB);
|
||||
if is_input {
|
||||
temp_reg_dir |= 1 << pin;
|
||||
} else {
|
||||
temp_reg_data &= !(1 << pin);
|
||||
temp_reg_dir &= !(1 << pin);
|
||||
}
|
||||
|
||||
self.write_16(Register::RegDirB, temp_reg_data);
|
||||
self.write_16(Register::RegDirB, temp_reg_dir);
|
||||
|
||||
if dir == PinDirection::InputPullUp {
|
||||
self.write_pin(pin, true);
|
||||
@ -146,6 +146,16 @@ impl<'d> Sx1509<'d> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read_pin(&mut self, pin: u8) -> Option<bool> {
|
||||
let temp_reg_dir = self.read_16(Register::RegDirB);
|
||||
if (temp_reg_dir & (1 << pin)) > 0 {
|
||||
let temp_reg_data = self.read_16(Register::RegDataB);
|
||||
Some((temp_reg_data & (1 << pin)) > 0)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
pub fn led_driver_init(&mut self, pin: u8) {
|
||||
todo!()
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user