forked from M-Labs/thermostat
adc: read u32 for unipolar coding
This commit is contained in:
parent
2e72a03b93
commit
723901b341
|
@ -129,7 +129,7 @@ impl<SPI: Transfer<u8, Error = E>, NSS: OutputPin, E: fmt::Debug> Adc<SPI, NSS>
|
|||
}
|
||||
|
||||
/// Get data
|
||||
pub fn read_data(&mut self) -> Result<i32, AdcError<SPI::Error>> {
|
||||
pub fn read_data(&mut self) -> Result<u32, AdcError<SPI::Error>> {
|
||||
self.read_reg(®s::Data)
|
||||
.map(|data| data.data())
|
||||
}
|
||||
|
|
|
@ -160,16 +160,10 @@ impl if_mode::Data {
|
|||
|
||||
def_reg!(Data, data, 0x04, 3);
|
||||
impl data::Data {
|
||||
pub fn data(&self) -> i32 {
|
||||
let raw =
|
||||
(u32::from(self.0[0]) << 16) |
|
||||
(u32::from(self.0[1]) << 8) |
|
||||
u32::from(self.0[2]);
|
||||
if raw & 0x80_0000 != 0 {
|
||||
((raw & 0x7F_FFFF) | 0x8000_0000) as i32
|
||||
} else {
|
||||
raw as i32
|
||||
}
|
||||
pub fn data(&self) -> u32 {
|
||||
(u32::from(self.0[0]) << 16) |
|
||||
(u32::from(self.0[1]) << 8) |
|
||||
u32::from(self.0[2])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ use crate::{ad5680, ad7172, pid, steinhart_hart as sh};
|
|||
|
||||
|
||||
pub struct ChannelState {
|
||||
pub adc_data: Option<i32>,
|
||||
pub adc_data: Option<u32>,
|
||||
pub adc_time: Instant,
|
||||
pub dac_value: u32,
|
||||
pub pid_enabled: bool,
|
||||
|
@ -26,7 +26,7 @@ impl Default for ChannelState {
|
|||
|
||||
impl ChannelState {
|
||||
/// Update PID state on ADC input, calculate new DAC output
|
||||
pub fn update_adc(&mut self, now: Instant, adc_data: i32) {
|
||||
pub fn update_adc(&mut self, now: Instant, adc_data: u32) {
|
||||
self.adc_data = Some(adc_data);
|
||||
self.adc_time = now;
|
||||
|
||||
|
|
Loading…
Reference in New Issue