Crates.io | soft-i2c |
lib.rs | soft-i2c |
version | 0.1.1 |
source | src |
created_at | 2024-09-02 13:21:44.939535 |
updated_at | 2024-09-02 13:33:59.005332 |
description | Soft i2c for any open drain pin |
homepage | |
repository | https://github.com/Merisy-Thing/rust_hal_with_c_sdk_framework/tree/main/soft-i2c |
max_upload_size | |
id | 1360491 |
size | 14,063 |
Soft I2C for any open drain pin
use soft_i2c::{OpenDrainPin, SoftI2C, FREQ_I2C_SCL_100K};
struct SDA<'a>(&'a mut FastPin<PB, FastPin14, OutputFastPin>);
impl<'a> OpenDrainPin for SDA<'a> {
fn set(&mut self, level: bool) {
if level {
self.0.output_high();
} else {
self.0.output_low();
}
}
fn get(&mut self) -> bool {
self.0.is_input_high()
}
}
...
let mut sda_pin = FastPin::<PB, FastPin14, OutputFastPin>::new().into_output(FastPinModeOutput::OutOD);
let mut sda = SDA(&mut sda_pin);
let mut scl = FastPin::<PB, FastPin13, OutputFastPin>::new().into_output(FastPinModeOutput::OutOD);
let mut i2c_delay = Delay::new();
let soft_i2c = SoftI2C::<_, _, _, FREQ_I2C_SCL_100K>::new(&mut scl, &mut sda, &mut i2c_delay);