Initial commit
This commit is contained in:
commit
ff3e80aacc
4 changed files with 95 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
/target
|
||||
/Cargo.lock
|
10
Cargo.toml
Normal file
10
Cargo.toml
Normal file
|
@ -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"
|
48
src/lib.rs
Normal file
48
src/lib.rs
Normal file
|
@ -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: I2C,
|
||||
address: u8,
|
||||
}
|
||||
|
||||
impl<I2C, E> QwiicTwist<I2C>
|
||||
where
|
||||
I2C: Read<Error = E> + Write<Error = E> + WriteRead<Error = E>,
|
||||
{
|
||||
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<u8, E> {
|
||||
let mut temp = [0];
|
||||
self.i2c
|
||||
.write_read(self.address, &[0x78], &mut temp)
|
||||
.and(Ok(temp[0]))
|
||||
}
|
||||
}
|
35
src/registers.rs
Normal file
35
src/registers.rs
Normal file
|
@ -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;
|
Loading…
Add table
Reference in a new issue