Update register names

This commit is contained in:
2025-07-30 12:04:46 +02:00
parent f0e9fbc52c
commit d04f457c9f
2 changed files with 53 additions and 49 deletions

View File

@@ -127,25 +127,25 @@ impl AD5940 {
Ok(())
}
pub async fn afecon(&mut self, ctr: ConfigurationRegister, state: bool) {
pub async fn afecon(&mut self, ctr: AFECON, state: bool) {
let reg = self.read_reg_32(Register::AFECON).await.unwrap();
let mut reg = ConfigurationRegister::from_bits_truncate(reg);
let mut reg = AFECON::from_bits_truncate(reg);
let flags = [
ConfigurationRegister::DACBUFEN,
ConfigurationRegister::DACREFEN,
ConfigurationRegister::SINC2EN,
ConfigurationRegister::DFTEN,
ConfigurationRegister::WAVEGENEN,
ConfigurationRegister::TEMPCONVEN,
ConfigurationRegister::TEMPSENSEN,
ConfigurationRegister::TIAEN,
ConfigurationRegister::INAMPEN,
ConfigurationRegister::EXBUFEN,
ConfigurationRegister::ADCCONVEN,
ConfigurationRegister::ADCEN,
ConfigurationRegister::DACEN,
ConfigurationRegister::HSREFDIS,
AFECON::DACBUFEN,
AFECON::DACREFEN,
AFECON::SINC2EN,
AFECON::DFTEN,
AFECON::WAVEGENEN,
AFECON::TEMPCONVEN,
AFECON::TEMPSENSEN,
AFECON::TIAEN,
AFECON::INAMPEN,
AFECON::EXBUFEN,
AFECON::ADCCONVEN,
AFECON::ADCEN,
AFECON::DACEN,
AFECON::HSREFDIS,
];
for &flag in flags.iter() {
@@ -161,32 +161,32 @@ impl AD5940 {
self.write_reg_32(Register::AFECON, reg.bits()).await.unwrap();
}
pub async fn swcon(&mut self, ctr: SwitchMatrixConfigurationRegister) {
pub async fn swcon(&mut self, ctr: SWCON) {
let reg = self.read_reg_32(Register::SWCON).await.unwrap();
let mut reg = SwitchMatrixConfigurationRegister::from_bits_truncate(reg);
let mut reg = SWCON::from_bits_truncate(reg);
// NMUXCON
if (ctr & SwitchMatrixConfigurationRegister::NMUXCON_MSK) == SwitchMatrixConfigurationRegister::NMUXCON_N2 {
reg &= !SwitchMatrixConfigurationRegister::NMUXCON_MSK;
reg |= SwitchMatrixConfigurationRegister::NMUXCON_N2;
} else if (ctr & SwitchMatrixConfigurationRegister::NMUXCON_MSK) == SwitchMatrixConfigurationRegister::NMUXCON_N5 {
reg &= !SwitchMatrixConfigurationRegister::NMUXCON_MSK;
reg |= SwitchMatrixConfigurationRegister::NMUXCON_N5;
if (ctr & SWCON::NMUXCON_MSK) == SWCON::NMUXCON_N2 {
reg &= !SWCON::NMUXCON_MSK;
reg |= SWCON::NMUXCON_N2;
} else if (ctr & SWCON::NMUXCON_MSK) == SWCON::NMUXCON_N5 {
reg &= !SWCON::NMUXCON_MSK;
reg |= SWCON::NMUXCON_N5;
};
// PMUXCON
if (ctr & SwitchMatrixConfigurationRegister::PMUXCON_MSK) == SwitchMatrixConfigurationRegister::PMUXCON_P2 {
reg &= !SwitchMatrixConfigurationRegister::PMUXCON_MSK;
reg |= SwitchMatrixConfigurationRegister::PMUXCON_P2;
} else if (ctr & SwitchMatrixConfigurationRegister::PMUXCON_MSK) == SwitchMatrixConfigurationRegister::PMUXCON_P11 {
reg &= !SwitchMatrixConfigurationRegister::PMUXCON_MSK;
reg |= SwitchMatrixConfigurationRegister::PMUXCON_P11;
if (ctr & SWCON::PMUXCON_MSK) == SWCON::PMUXCON_P2 {
reg &= !SWCON::PMUXCON_MSK;
reg |= SWCON::PMUXCON_P2;
} else if (ctr & SWCON::PMUXCON_MSK) == SWCON::PMUXCON_P11 {
reg &= !SWCON::PMUXCON_MSK;
reg |= SWCON::PMUXCON_P11;
}
// DMUXCON
if ctr.contains(SwitchMatrixConfigurationRegister::DMUXCON_D5) {
reg &= !SwitchMatrixConfigurationRegister::DMUXCON_MSK;
reg |= SwitchMatrixConfigurationRegister::DMUXCON_D5;
if ctr.contains(SWCON::DMUXCON_D5) {
reg &= !SWCON::DMUXCON_MSK;
reg |= SWCON::DMUXCON_D5;
}
self.write_reg_32(Register::SWCON, reg.bits()).await.unwrap();
@@ -208,14 +208,14 @@ impl AD5940 {
pub async fn init_temperature(&mut self) -> Result<(), Error> {
// AFECON:
self.afecon(ConfigurationRegister::TEMPSENSEN | ConfigurationRegister::ADCEN, true).await;
self.afecon(AFECON::TEMPSENSEN | AFECON::ADCEN, true).await;
// ADCCON
let config_adccon = ADCConfigurationRegister::GNPGA_1_5.bits() | ADCConfigurationRegister::MUXSELN_TEMP.bits() | ADCConfigurationRegister::MUXSELP_TEMP.bits();
let config_adccon = ADCCON::GNPGA_1_5.bits() | ADCCON::MUXSELN_TEMP.bits() | ADCCON::MUXSELP_TEMP.bits();
self.write_reg_32(Register::ADCCON, config_adccon).await?;
// AFECON - start conversion
self.afecon(ConfigurationRegister::TEMPCONVEN | ConfigurationRegister::ADCCONVEN, true).await;
self.afecon(AFECON::TEMPCONVEN | AFECON::ADCCONVEN, true).await;
Ok(())
}
@@ -241,22 +241,22 @@ impl AD5940 {
self.write_reg_32(Register::WGAMPLITUDE, wg_amplitude).await?;
// WGCON, enable waveform generator and set to sinusoidal, NO DACCAL
let config_wgcon = WaveformGeneratorConfigurationRegister::TYPESEL_SIN.bits();
let config_wgcon = WGCON::TYPESEL_SIN.bits();
self.write_reg_32(Register::WGCON, config_wgcon).await?;
// SWCON - set up switch matrix
self.swcon(
SwitchMatrixConfigurationRegister::NMUXCON_N2
| SwitchMatrixConfigurationRegister::PMUXCON_P11
| SwitchMatrixConfigurationRegister::DMUXCON_D5).await;
SWCON::NMUXCON_N2
| SWCON::PMUXCON_P11
| SWCON::DMUXCON_D5).await;
// AFECON:
self.afecon(
ConfigurationRegister::DACREFEN
| ConfigurationRegister::EXBUFEN
| ConfigurationRegister::INAMPEN
| ConfigurationRegister::DACEN
| ConfigurationRegister::WAVEGENEN,
AFECON::DACREFEN
| AFECON::EXBUFEN
| AFECON::INAMPEN
| AFECON::DACEN
| AFECON::WAVEGENEN,
true,
)
.await;