Skip to content

Commit

Permalink
Add a type alias for the I2C register block, Add pins used on a disco…
Browse files Browse the repository at this point in the history
… board
  • Loading branch information
psycowithespn committed Nov 25, 2018
1 parent 118ec4a commit 9f31167
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub trait Pins<I2c> {}

impl Pins<I2C1> for (PB6<Alternate<AF4>>, PB7<Alternate<AF4>>) {}
impl Pins<I2C1> for (PB8<Alternate<AF4>>, PB9<Alternate<AF4>>) {}
impl Pins<I2C1> for (PB6<Alternate<AF4>>, PB9<Alternate<AF4>>) {}

impl Pins<I2C2> for (PB10<Alternate<AF4>>, PB11<Alternate<AF4>>) {}

Expand All @@ -30,8 +31,10 @@ pub enum Error {
NACK,
}

type I2cRegisterBlock = i2c3::RegisterBlock;

trait I2cInit {
fn i2c(&self) -> &i2c3::RegisterBlock;
fn i2c(&self) -> &I2cRegisterBlock;

fn enable_peripheral(&self, rcc: &rcc::RegisterBlock);

Expand Down Expand Up @@ -113,7 +116,7 @@ trait I2cInit {
}

trait I2cCommon {
fn i2c(&self) -> &i2c3::RegisterBlock;
fn i2c(&self) -> &I2cRegisterBlock;

fn send_byte(&self, byte: u8) -> Result<(), Error> {
// Wait until we're ready for sending
Expand Down Expand Up @@ -146,16 +149,16 @@ trait I2cCommon {

impl<I2C, PINS> I2cCommon for I2c<I2C, PINS>
where
I2C: Deref<Target = i2c3::RegisterBlock>,
I2C: Deref<Target = I2cRegisterBlock>,
{
fn i2c(&self) -> &i2c3::RegisterBlock {
fn i2c(&self) -> &I2cRegisterBlock {
&self.i2c
}
}

impl<I2C, PINS> WriteRead for I2c<I2C, PINS>
where
I2C: Deref<Target = i2c3::RegisterBlock>,
I2C: Deref<Target = I2cRegisterBlock>,
{
type Error = Error;

Expand All @@ -169,7 +172,7 @@ where

impl<I2C, PINS> Write for I2c<I2C, PINS>
where
I2C: Deref<Target = i2c3::RegisterBlock>,
I2C: Deref<Target = I2cRegisterBlock>,
{
type Error = Error;

Expand Down Expand Up @@ -215,7 +218,7 @@ where

impl<I2C, PINS> Read for I2c<I2C, PINS>
where
I2C: Deref<Target = i2c3::RegisterBlock>,
I2C: Deref<Target = I2cRegisterBlock>,
{
type Error = Error;

Expand Down Expand Up @@ -281,7 +284,7 @@ impl<PINS> I2c<I2C1, PINS> {
}

impl<PINS> I2cInit for I2c<I2C1, PINS> {
fn i2c(&self) -> &i2c3::RegisterBlock {
fn i2c(&self) -> &I2cRegisterBlock {
&self.i2c
}

Expand Down Expand Up @@ -316,7 +319,7 @@ impl<PINS> I2c<I2C2, PINS> {
}

impl<PINS> I2cInit for I2c<I2C2, PINS> {
fn i2c(&self) -> &i2c3::RegisterBlock {
fn i2c(&self) -> &I2cRegisterBlock {
&self.i2c
}

Expand Down

0 comments on commit 9f31167

Please sign in to comment.