commit ff3e80aacc0ed31dc6dd8c273437cd48dbcb7100 Author: Alex Page Date: Thu Jul 28 16:38:38 2022 -0400 Initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4fffb2f --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/target +/Cargo.lock diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..e32a617 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "qwiic-twist" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +embedded-hal = "0.2.7" +embedded-time = "0.12.1" diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..ae1f2d9 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,48 @@ +#![no_std] + +mod registers; + +use embedded_hal::blocking::i2c::{Read, Write, WriteRead}; +use embedded_hal::prelude::*; +use embedded_time::rate::Extensions; + +/// 7-bit unshifted default I2C Address +const QWIIC_TWIST_ADDR: u8 = 0x3F; + +pub struct QwiicTwist { + i2c: I2C, + address: u8, +} + +impl QwiicTwist +where + I2C: Read + Write + WriteRead, +{ + pub fn new(i2c: I2C, address: u8) -> Self { + Self { i2c, address } + } + + fn read_register(address: u8) -> u8 { + todo!() + } + fn read_register_16(address: u8) -> u16 { + todo!() + } + + fn write_register(address: u8, value: u8) { + todo!() + } + fn write_register_16(address: u8, value: u16) { + todo!() + } + fn write_register_24(address: u8, value: u32) { + todo!() + } + + pub fn read_temperature(&mut self) -> Result { + let mut temp = [0]; + self.i2c + .write_read(self.address, &[0x78], &mut temp) + .and(Ok(temp[0])) + } +} diff --git a/src/registers.rs b/src/registers.rs new file mode 100644 index 0000000..5aad5f6 --- /dev/null +++ b/src/registers.rs @@ -0,0 +1,35 @@ +/// Map to the various registers on the Twist + +const TWIST_ID: u8 = 0x00; + +/// - 2 - button clicked +/// - 1 - button pressed +/// - 0 - encoder moved +const TWIST_STATUS: u8 = 0x01; +const TWIST_VERSION: u8 = 0x02; + +/// - 1 - button interrupt +/// - 0 - encoder interrupt +const TWIST_ENABLE_INTS: u8 = 0x04; + +const TWIST_COUNT: u8 = 0x05; +const TWIST_DIFFERENCE: u8 = 0x07; +/// Milliseconds since the last movement of the knob +const TWIST_LAST_ENCODER_EVENT: u8 = 0x09; +/// Milliseconds since the last press/release +const TWIST_LAST_BUTTON_EVENT: u8 = 0x0B; + +const TWIST_RED: u8 = 0x0D; +const TWIST_GREEN: u8 = 0x0E; +const TWIST_BLUE: u8 = 0x0F; + +/// Amount to change the red LED for each encoder tick +const TWIST_CONNECT_RED: u8 = 0x10; +/// Amount to change the green LED for each encoder tick +const TWIST_CONNECT_GREEN: u8 = 0x12; +/// Amount to change the blue LED for each encoder tick +const TWIST_CONNECT_BLUE: u8 = 0x14; + +const TWIST_TURN_INT_TIMEOUT: u8 = 0x16; +const TWIST_CHANGE_ADDRESS: u8 = 0x18; +const TWIST_LIMIT: u8 = 0x19;