Skip to content

Commit c02313a

Browse files
committed
Add function to fill the whole matrix at once
Signed-off-by: Daniel Schaefer <[email protected]>
1 parent c84a200 commit c02313a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,23 @@ impl<I2C, I2cError> IS31FL3741<I2C>
2626
where
2727
I2C: Write<Error = I2cError>,
2828
{
29+
/// Fill all pixels of the display at once. The brightness should range from 0 to 255.
30+
pub fn fill_matrix(&mut self, brightnesses: &[u8]) -> Result<(), I2cError> {
31+
32+
// Extend by one, to add address to the beginning
33+
let mut buf = [0x00; 0xB5];
34+
buf[0] = 0x00; // set the initial address
35+
36+
buf[1..=0xB4].copy_from_slice(&brightnesses[..=0xB3]);
37+
self.bank(Page::Pwm1)?;
38+
self.write(&buf)?;
39+
40+
buf[1..=0xAB].copy_from_slice(&brightnesses[0xB4..=0xB4+0xAA]);
41+
self.bank(Page::Pwm2)?;
42+
self.write(&buf[..=0xAA])?;
43+
Ok(())
44+
}
45+
2946
/// Fill the display with a single brightness. The brightness should range from 0 to 255.
3047
pub fn fill(&mut self, brightness: u8) -> Result<(), I2cError> {
3148
self.bank(Page::Pwm1)?;

0 commit comments

Comments
 (0)