#![doc = include_str!("../README.md")]
#![no_std]
#![deny(missing_docs)]
#[cfg(feature = "async")]
mod asynch;
mod register;
pub use register::*;
#[cfg(not(feature = "async"))]
mod sync;
const I2C_ADDR: u8 = 0x2A;
pub struct Ldc3114<I2C> {
i2c: I2C,
sency0: u8,
sency1: u8,
sency2: u8,
sency3: u8,
lcdiv: u8,
}
#[derive(Debug)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum Error<I2cError> {
I2c(I2cError),
WriteToReadOnly,
InvalidParameter,
}
#[derive(Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Status {
pub output_status: bool,
pub chip_ready: bool,
pub ready_to_write: bool,
pub maximum_output_code: bool,
pub fsm_watchdog_error: bool,
pub lc_sensor_watchdog_error: bool,
pub button_timeout: bool,
pub register_integrity_bad: bool,
}
#[derive(Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct OutputLogicStates {
pub new_data_available: bool,
pub out0: bool,
pub out1: bool,
pub out2: bool,
pub out3: bool,
}
#[derive(Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub enum ChannelMode {
Disabled,
NormalMode,
NormalAndLowPowerMode,
}
#[derive(Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum ScanRate {
Continuous = 0x04,
Highest = 0x08,
High = 0x00,
Medium = 0x01,
Low = 0x02,
Lowest = 0x03,
}
#[derive(Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum LowPowerScanRate {
Highest = 0x00,
High = 0x01,
Medium = 0x02,
Low = 0x03,
}
#[derive(Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum InterruptPolarity {
ActiveLow = 0,
ActiveHigh = 1,
}
#[derive(Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum OutputPolarity {
ActiveLow = 0,
ActiveHigh = 1,
}
#[derive(Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum DataPolarity {
Inverted,
Normal,
}
#[derive(Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[allow(missing_docs)]
#[repr(u8)]
pub enum CounterScale {
Zero = 0,
One = 1,
Two = 2,
Three = 3,
}
#[derive(Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum RpRange {
Rp50OhmTo4kOhm = 0x00,
Rp800OhmTo10kOhm = 0x80,
}
#[derive(Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[repr(u8)]
pub enum FrequencyRange {
Freq1MHzTo3_3MHz = 0x00,
Freq3_3MHzTo10MHz = 0x20,
Freq10MHzTo30MHz = 0x40,
}
#[derive(Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct SensorConfig {
pub rp_range: RpRange,
pub frequency_range: FrequencyRange,
pub cycle_count: u8,
}
impl SensorConfig {
pub const fn const_default() -> Self {
Self {
rp_range: RpRange::Rp50OhmTo4kOhm,
frequency_range: FrequencyRange::Freq1MHzTo3_3MHz,
cycle_count: 4,
}
}
}
#[derive(Clone, Copy)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
#[allow(missing_docs)]
#[repr(u8)]
pub enum FastTrackingFactor {
Zero = 0,
One = 1,
Two = 2,
Three = 3,
}
#[derive(Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct ChannelConfig {
pub mode: ChannelMode,
pub gain: u8,
pub output_polarity: OutputPolarity,
pub data_polarity: DataPolarity,
pub counter_scale: CounterScale,
pub sensor_config: SensorConfig,
pub fast_tracking_factor: FastTrackingFactor,
pub enable_anticommon_algorithm: bool,
pub enable_antideform_algorithm: bool,
pub enable_max_win_button_algorithm: bool,
pub baseline_tracking_pause: bool,
}
impl ChannelConfig {
pub const fn const_default<T: ChannelRegisters>(_ch: T) -> Self {
Self {
mode: T::DEFAULT_MODE,
gain: 0x28,
output_polarity: OutputPolarity::ActiveLow,
data_polarity: DataPolarity::Normal,
counter_scale: CounterScale::One,
sensor_config: SensorConfig::const_default(),
fast_tracking_factor: FastTrackingFactor::One,
enable_anticommon_algorithm: false,
enable_antideform_algorithm: false,
baseline_tracking_pause: false,
enable_max_win_button_algorithm: false,
}
}
}
#[derive(Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct DeviceConfig {
pub ch0: ChannelConfig,
pub ch1: ChannelConfig,
pub ch2: ChannelConfig,
pub ch3: ChannelConfig,
pub scan_rate: ScanRate,
pub low_power_scan_rate: LowPowerScanRate,
pub enable_max_out_check: bool,
pub enable_button_timeout: bool,
pub interrupt_polarity: InterruptPolarity,
pub enable_button_press_detection_algorithm: bool,
pub enable_reset_of_button_baseline_tracking: bool,
pub baseline_tracking_increment_np: u8,
pub baseline_tracking_increment_lp: u8,
pub lc_divider: u8,
pub hysteresis: u8,
pub antitwist: u8,
}
impl DeviceConfig {
pub const fn const_default() -> Self {
Self {
ch0: ChannelConfig::const_default(Channel0),
ch1: ChannelConfig::const_default(Channel1),
ch2: ChannelConfig::const_default(Channel2),
ch3: ChannelConfig::const_default(Channel3),
scan_rate: ScanRate::Medium,
low_power_scan_rate: LowPowerScanRate::Highest,
enable_max_out_check: true,
enable_button_timeout: true,
interrupt_polarity: InterruptPolarity::ActiveLow,
enable_button_press_detection_algorithm: true,
enable_reset_of_button_baseline_tracking: true,
baseline_tracking_increment_np: 0x03,
baseline_tracking_increment_lp: 0x05,
lc_divider: 0x03,
hysteresis: 0x08,
antitwist: 0x00,
}
}
}