Skip to content

Commit

Permalink
prefix public low-level i2c interfaces with raw_*
Browse files Browse the repository at this point in the history
  • Loading branch information
agrif committed May 22, 2024
1 parent ff98cf9 commit e1a8e26
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ where
/// **This is a low-level control function.** For normal I2C devices,
/// please use the embedded-hal traits [Read], [Write], or
/// [WriteRead].
pub fn i2c_start(&mut self) -> Result<(), crate::i2c::Error<E>> {
pub fn raw_i2c_start(&mut self) -> Result<(), crate::i2c::Error<E>> {
self.set_scl_high()?;
self.set_sda_high()?;
self.wait_for_clk();
Expand All @@ -113,7 +113,7 @@ where
/// **This is a low-level control function.** For normal I2C devices,
/// please use the embedded-hal traits [Read], [Write], or
/// [WriteRead].
pub fn i2c_stop(&mut self) -> Result<(), crate::i2c::Error<E>> {
pub fn raw_i2c_stop(&mut self) -> Result<(), crate::i2c::Error<E>> {
self.set_scl_high()?;
self.wait_for_clk();

Expand Down Expand Up @@ -197,7 +197,7 @@ where
/// please use the embedded-hal traits [Read], [Write], or
/// [WriteRead].
#[inline]
pub fn read_from_slave(&mut self, input: &mut [u8]) -> Result<(), crate::i2c::Error<E>> {
pub fn raw_read_from_slave(&mut self, input: &mut [u8]) -> Result<(), crate::i2c::Error<E>> {
for i in 0..input.len() {
let should_send_ack = i != (input.len() - 1);
input[i] = self.i2c_read_byte(should_send_ack)?;
Expand All @@ -211,7 +211,7 @@ where
/// please use the embedded-hal traits [Read], [Write], or
/// [WriteRead].
#[inline]
pub fn write_to_slave(&mut self, output: &[u8]) -> Result<(), crate::i2c::Error<E>> {
pub fn raw_write_to_slave(&mut self, output: &[u8]) -> Result<(), crate::i2c::Error<E>> {
for byte in output {
self.i2c_write_byte(*byte)?;
self.check_ack()?;
Expand Down Expand Up @@ -264,16 +264,16 @@ where

fn write(&mut self, addr: u8, output: &[u8]) -> Result<(), Self::Error> {
// ST
self.i2c_start()?;
self.raw_i2c_start()?;

// SAD + W
self.i2c_write_byte((addr << 1) | 0x0)?;
self.check_ack()?;

self.write_to_slave(output)?;
self.raw_write_to_slave(output)?;

// SP
self.i2c_stop()
self.raw_i2c_stop()
}
}

Expand All @@ -291,16 +291,16 @@ where
}

// ST
self.i2c_start()?;
self.raw_i2c_start()?;

// SAD + R
self.i2c_write_byte((addr << 1) | 0x1)?;
self.check_ack()?;

self.read_from_slave(input)?;
self.raw_read_from_slave(input)?;

// SP
self.i2c_stop()
self.raw_i2c_stop()
}
}

Expand All @@ -318,24 +318,24 @@ where
}

// ST
self.i2c_start()?;
self.raw_i2c_start()?;

// SAD + W
self.i2c_write_byte((addr << 1) | 0x0)?;
self.check_ack()?;

self.write_to_slave(output)?;
self.raw_write_to_slave(output)?;

// SR
self.i2c_start()?;
self.raw_i2c_start()?;

// SAD + R
self.i2c_write_byte((addr << 1) | 0x1)?;
self.check_ack()?;

self.read_from_slave(input)?;
self.raw_read_from_slave(input)?;

// SP
self.i2c_stop()
self.raw_i2c_stop()
}
}

0 comments on commit e1a8e26

Please sign in to comment.