|
|
@@ -3,6 +3,10 @@ use embassy_rp::i2c::{Async, Error, I2c, Instance, Mode};
|
|
|
|
|
|
const I2C_ADDRESS: u16 = 0x0068;
|
|
|
|
|
|
+const CMD_BEGIN_TRANSACTION: [u8; 2] = [0x0E, 0x20];
|
|
|
+const CMD_GET_TEMP_HIGH: [u8; 1] = [0x11];
|
|
|
+const CMD_GET_TEMP_LOW: [u8; 1] = [0x12];
|
|
|
+
|
|
|
#[derive(Clone, Copy, Eq, PartialEq)]
|
|
|
pub enum Temperature {
|
|
|
Unknown,
|
|
|
@@ -40,17 +44,14 @@ impl<'a, T: Instance, M: Mode> TemperatureSensor<'a, T, M> {
|
|
|
|
|
|
impl<'a, T: Instance> TemperatureSensor<'a, T, Async> {
|
|
|
pub async fn update_async(&mut self) -> Result<(), Error> {
|
|
|
- let begin_transaction = [0x0Eu8, 0x20u8];
|
|
|
- let get_temp_high = [0x11u8];
|
|
|
- let get_temp_low = [0x12u8];
|
|
|
let mut buffer: [u8; 1] = [0];
|
|
|
- self.i2c.write_async(I2C_ADDRESS, begin_transaction).await?;
|
|
|
- self.i2c.write_async(I2C_ADDRESS, get_temp_high).await?;
|
|
|
+ self.i2c.write_async(I2C_ADDRESS, CMD_BEGIN_TRANSACTION).await?;
|
|
|
+ self.i2c.write_async(I2C_ADDRESS, CMD_GET_TEMP_HIGH).await?;
|
|
|
self.i2c
|
|
|
.read_async(I2C_ADDRESS, buffer.as_mut_slice())
|
|
|
.await?;
|
|
|
let temp_high = buffer[0];
|
|
|
- self.i2c.write_async(I2C_ADDRESS, get_temp_low).await?;
|
|
|
+ self.i2c.write_async(I2C_ADDRESS, CMD_GET_TEMP_LOW).await?;
|
|
|
self.i2c
|
|
|
.read_async(I2C_ADDRESS, buffer.as_mut_slice())
|
|
|
.await?;
|