-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructure folders, add pmic abstraction
- Loading branch information
Showing
10 changed files
with
131 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//! led | ||
pub struct Led<PIN> { | ||
pin: PIN, | ||
} | ||
|
||
impl<PIN> Led<PIN> { | ||
pub fn new(pin: PIN) -> Self { | ||
Self { pin } | ||
} | ||
} | ||
|
||
impl<PIN: embedded_hal_v0::digital::v2::OutputPin> Led<PIN> { | ||
pub fn on(&mut self) { | ||
let _ = self.pin.set_low(); | ||
} | ||
|
||
pub fn off(&mut self) { | ||
let _ = self.pin.set_high(); | ||
} | ||
} | ||
|
||
impl<PIN: embedded_hal_v0::digital::v2::ToggleableOutputPin> Led<PIN> { | ||
pub fn toggle(&mut self) { | ||
let _ = self.pin.toggle(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
pub mod led; | ||
pub mod pmic; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
//! Pmic WIP | ||
const PMIC_ADDR: u8 = 0x08; | ||
|
||
#[derive(Clone, Copy, Debug)] | ||
pub enum Reg { | ||
DeviceId = 0x00, | ||
} | ||
|
||
impl Reg { | ||
pub const fn as_u8(&self) -> u8 { | ||
*self as u8 | ||
} | ||
} | ||
|
||
#[derive(Clone, Copy, Debug)] | ||
pub enum Error { | ||
I2cError, | ||
} | ||
|
||
pub struct Pmic<I2C> { | ||
i2c: I2C, | ||
} | ||
|
||
impl<I2C> Pmic<I2C> { | ||
pub fn new(i2c: I2C) -> Self { | ||
Self { i2c } | ||
} | ||
} | ||
|
||
impl<I2C: embedded_hal_v0::blocking::i2c::WriteRead> Pmic<I2C> { | ||
pub fn device_id(&mut self) -> Result<u8, Error> { | ||
let mut data = [0u8]; | ||
self.i2c | ||
.write_read(PMIC_ADDR, &[Reg::DeviceId.as_u8()], &mut data) | ||
.map_err(|_| Error::I2cError)?; | ||
Ok(data[0]) | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters