Skip to content

Commit

Permalink
WIP: Open short detection
Browse files Browse the repository at this point in the history
```
let open1 = matrix.device.check_open(&mut delay, 0x03, true).unwrap();
let open2 = matrix.device.check_open(&mut delay, 0x07, true).unwrap();
let open3 = matrix.device.check_open(&mut delay, 0x08, true).unwrap();
let open4 = matrix.device.check_open(&mut delay, 0x0C, true).unwrap();

let short1 = matrix.device.check_open(&mut delay, 0x03, false).unwrap();
let short2 = matrix.device.check_open(&mut delay, 0x07, false).unwrap();
let short2 = matrix.device.check_open(&mut delay, 0x07, false).unwrap();
let short3 = matrix.device.check_open(&mut delay, 0x08, false).unwrap();
let short4 = matrix.device.check_open(&mut delay, 0x0C, false).unwrap();
```

Signed-off-by: Daniel Schaefer <git@danielschaefer.me>
  • Loading branch information
JohnAZoidberg committed Sep 19, 2023
1 parent eb53a00 commit 767b9c4
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,39 @@ where
],
)
}

//pub fn check_open(&mut self, register: u8) -> Result<u8, I2cError> {
pub fn check_open<DEL: DelayMs<u8>>(&mut self, delay: &mut DEL, register: u8, open: bool) -> Result<u8, I2cError> {
// Set low current before testing
self.write_register(Page::Config, addresses::CURRENT_REGISTER, 0x01)?;
if open {
self.write_register(Page::Config, addresses::PULL_UP_REGISTER, 0x00)?;
}
delay.delay_ms(10);

// Trigger detection
// OSDE 01 => open detection
// OSDE 10 => short detection
let osde = if open {
0b010
} else {
0b100
};
let reg = self.read_register(Page::Config, addresses::CONFIG_REGISTER)?;
let reg = reg & (!0b110); // Clear OSDE
self.write_register(Page::Config, addresses::CONFIG_REGISTER, reg)?;
delay.delay_ms(100);
self.write_register(Page::Config, addresses::CONFIG_REGISTER, reg | osde)?;
delay.delay_ms(100);

// Read status
let status = self.read_register(Page::Config, register)?;

// Reset high current again
//self.write_register(Page::Config, addresses::CURRENT_REGISTER, 0xFF)?;
delay.delay_ms(10);
Ok(status)
}
}

/// See the [data sheet](https://lumissil.com/assets/pdf/core/IS31FL3741A_DS.pdf)
Expand Down

0 comments on commit 767b9c4

Please sign in to comment.