This commit is contained in:
Astro 2020-09-18 00:55:53 +02:00
parent 7361619a53
commit a4dde1b8ca
8 changed files with 7 additions and 60 deletions

View File

@ -100,24 +100,6 @@ impl<SPI: Transfer<u8, Error = E>, NSS: OutputPin, E: fmt::Debug> Adc<SPI, NSS>
Ok(()) Ok(())
} }
pub fn disable_channel(
&mut self, index: u8
) -> Result<(), SPI::Error> {
self.update_reg(&regs::Channel { index }, |data| {
data.set_enabled(false);
})?;
Ok(())
}
pub fn disable_all_channels(&mut self) -> Result<(), SPI::Error> {
for index in 0..4 {
self.update_reg(&regs::Channel { index }, |data| {
data.set_enabled(false);
})?;
}
Ok(())
}
pub fn get_calibration(&mut self, index: u8) -> Result<ChannelCalibration, SPI::Error> { pub fn get_calibration(&mut self, index: u8) -> Result<ChannelCalibration, SPI::Error> {
let offset = self.read_reg(&regs::Offset { index })?.offset(); let offset = self.read_reg(&regs::Offset { index })?.offset();
let gain = self.read_reg(&regs::Gain { index })?.gain(); let gain = self.read_reg(&regs::Gain { index })?.gain();

View File

@ -19,8 +19,6 @@ pub const SPI_MODE: spi::Mode = spi::Mode {
/// 2 MHz /// 2 MHz
pub const SPI_CLOCK: MegaHertz = MegaHertz(2); pub const SPI_CLOCK: MegaHertz = MegaHertz(2);
pub const MAX_VALUE: u32 = 0xFF_FFFF;
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
#[repr(u8)] #[repr(u8)]

View File

@ -45,8 +45,8 @@ impl Channels {
.expect("adc_calibration1"); .expect("adc_calibration1");
adc.start_continuous_conversion().unwrap(); adc.start_continuous_conversion().unwrap();
let mut channel0 = Channel::new(pins.channel0, adc_calibration0); let channel0 = Channel::new(pins.channel0, adc_calibration0);
let mut channel1 = Channel::new(pins.channel1, adc_calibration1); let channel1 = Channel::new(pins.channel1, adc_calibration1);
let pins_adc = pins.pins_adc; let pins_adc = pins.pins_adc;
let pwm = pins.pwm; let pwm = pins.pwm;
let mut channels = Channels { channel0, channel1, adc, pins_adc, pwm }; let mut channels = Channels { channel0, channel1, adc, pins_adc, pwm };
@ -164,7 +164,6 @@ impl Channels {
let mut prev = self.read_dac_feedback(channel); let mut prev = self.read_dac_feedback(channel);
loop { loop {
let current = self.read_dac_feedback(channel); let current = self.read_dac_feedback(channel);
use num_traits::float::Float;
if (current - prev).abs() < tolerance { if (current - prev).abs() < tolerance {
return current; return current;
} }

View File

@ -122,17 +122,6 @@ pub enum PwmPin {
MaxV, MaxV,
} }
impl PwmPin {
pub fn name(&self) -> &'static str {
match self {
PwmPin::ISet => "i_set",
PwmPin::MaxIPos => "max_i_pos",
PwmPin::MaxINeg => "max_i_neg",
PwmPin::MaxV => "max_v",
}
}
}
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]
pub enum Command { pub enum Command {
Quit, Quit,
@ -178,19 +167,6 @@ fn whitespace(input: &[u8]) -> IResult<&[u8], ()> {
fold_many1(char(' '), (), |(), _| ())(input) fold_many1(char(' '), (), |(), _| ())(input)
} }
fn unsigned(input: &[u8]) -> IResult<&[u8], Result<u32, Error>> {
take_while1(is_digit)(input)
.map(|(input, digits)| {
let result =
from_utf8(digits)
.map_err(|e| e.into())
.and_then(|digits| u32::from_str_radix(digits, 10)
.map_err(|e| e.into())
);
(input, result)
})
}
fn float(input: &[u8]) -> IResult<&[u8], Result<f64, Error>> { fn float(input: &[u8]) -> IResult<&[u8], Result<f64, Error>> {
let (input, sign) = opt(is_a("-"))(input)?; let (input, sign) = opt(is_a("-"))(input)?;
let negative = sign.is_some(); let negative = sign.is_some();

View File

@ -5,7 +5,7 @@ static USB_LOGGER: usb::Logger = usb::Logger;
#[cfg(not(feature = "semihosting"))] #[cfg(not(feature = "semihosting"))]
pub fn init_log() { pub fn init_log() {
log::set_logger(&USB_LOGGER); let _ = log::set_logger(&USB_LOGGER);
} }
#[cfg(feature = "semihosting")] #[cfg(feature = "semihosting")]

View File

@ -10,15 +10,11 @@ use panic_semihosting as _;
use log::{info, warn}; use log::{info, warn};
use core::ops::DerefMut;
use core::fmt::Write; use core::fmt::Write;
use cortex_m::asm::wfi; use cortex_m::asm::wfi;
use cortex_m_rt::entry; use cortex_m_rt::entry;
use stm32f4xx_hal::{ use stm32f4xx_hal::{
hal::{ hal::watchdog::{WatchdogEnable, Watchdog},
self,
watchdog::{WatchdogEnable, Watchdog},
},
rcc::RccExt, rcc::RccExt,
watchdog::IndependentWatchdog, watchdog::IndependentWatchdog,
time::{U32Ext, MegaHertz}, time::{U32Ext, MegaHertz},
@ -353,8 +349,6 @@ fn main() -> ! {
max.into_format_args(ampere, Abbreviation), max.into_format_args(ampere, Abbreviation),
); );
} }
_ =>
unreachable!(),
} }
} }
Command::Pid { channel, parameter, value } => { Command::Pid { channel, parameter, value } => {

View File

@ -6,13 +6,11 @@ use stm32f4xx_hal::{
gpioa::*, gpioa::*,
gpiob::*, gpiob::*,
gpioc::*, gpioc::*,
gpiod::*,
gpioe::*, gpioe::*,
gpiof::*, gpiof::*,
gpiog::*, gpiog::*,
GpioExt, GpioExt,
Output, PushPull, Output, PushPull,
Speed::VeryHigh,
}, },
otg_fs::USB, otg_fs::USB,
rcc::Clocks, rcc::Clocks,

View File

@ -6,10 +6,10 @@ use stm32f4xx_hal::{
}; };
use usb_device::{ use usb_device::{
class_prelude::{UsbBusAllocator}, class_prelude::{UsbBusAllocator},
prelude::{UsbError, UsbDevice, UsbDeviceBuilder, UsbVidPid}, prelude::{UsbDevice, UsbDeviceBuilder, UsbVidPid},
}; };
use usbd_serial::SerialPort; use usbd_serial::SerialPort;
use log::{Record, Level, Log, Metadata}; use log::{Record, Log, Metadata};
static mut EP_MEMORY: [u32; 1024] = [0; 1024]; static mut EP_MEMORY: [u32; 1024] = [0; 1024];
@ -30,7 +30,7 @@ impl State {
let serial = SerialPort::new(bus); let serial = SerialPort::new(bus);
let dev = UsbDeviceBuilder::new(bus, UsbVidPid(0x16c0, 0x27dd)) let dev = UsbDeviceBuilder::new(bus, UsbVidPid(0x16c0, 0x27dd))
.manufacturer("M-Labs") .manufacturer("M-Labs")
.product("thermostat") .product("tecpak")
.device_release(0x20) .device_release(0x20)
.self_powered(true) .self_powered(true)
.device_class(usbd_serial::USB_CLASS_CDC) .device_class(usbd_serial::USB_CLASS_CDC)