Compare commits
2 Commits
9a912392be
...
5244077144
Author | SHA1 | Date |
---|---|---|
Astro | 5244077144 | |
Astro | 4e6aa5fe0c |
|
@ -241,9 +241,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.19"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "04f5f085b5d71e2188cb8271e5da0161ad52c3f227a661a3c135fdf28e258b12"
|
||||
checksum = "175c513d55719db99da20232b06cda8bab6b83ec2d04e3283edf0213c37c1a29"
|
||||
dependencies = [
|
||||
"unicode-xid",
|
||||
]
|
||||
|
@ -314,6 +314,7 @@ checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3"
|
|||
[[package]]
|
||||
name = "stm32-eth"
|
||||
version = "0.2.0"
|
||||
source = "git+https://github.com/stm32-rs/stm32-eth.git#4d6b29bf1ecdd1f68e5bc304a3d4f170049896c8"
|
||||
dependencies = [
|
||||
"aligned",
|
||||
"cortex-m",
|
||||
|
@ -353,9 +354,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "1.0.39"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "891d8d6567fe7c7f8835a3a98af4208f3846fba258c1bc3c31d6e506239f11f9"
|
||||
checksum = "963f7d3cc59b59b9325165add223142bbf1df27655d07789f109896d353d8350"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
@ -1 +1 @@
|
|||
"1y1ry0b5wv4jcnh5sijrpd71nqgwgvd5vq4crmb4rmxk21g2vbca"
|
||||
"02cxj3iwj6b26r81fmxcmrbj2chd8xp7f9n5qq7l833lxh5rim4p"
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
use stm32f4xx_hal::{
|
||||
gpio::{
|
||||
gpiod::{PD9, PD10, PD11},
|
||||
Output, PushPull,
|
||||
},
|
||||
hal::digital::v2::OutputPin,
|
||||
};
|
||||
|
||||
pub struct Leds {
|
||||
/// Red LED L1
|
||||
pub r1: Led<PD9<Output<PushPull>>>,
|
||||
/// Green LED L3
|
||||
pub g3: Led<PD10<Output<PushPull>>>,
|
||||
/// Green LED L4
|
||||
pub g4: Led<PD11<Output<PushPull>>>,
|
||||
}
|
||||
|
||||
impl Leds {
|
||||
pub fn new<M1, M2, M3>(r1: PD9<M1>, g3: PD10<M2>, g4: PD11<M3>) -> Self {
|
||||
Leds {
|
||||
r1: Led::new(r1.into_push_pull_output()),
|
||||
g3: Led::new(g3.into_push_pull_output()),
|
||||
g4: Led::new(g4.into_push_pull_output()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Led<P> {
|
||||
pin: P,
|
||||
}
|
||||
|
||||
impl<P: OutputPin> Led<P> {
|
||||
pub fn new(pin: P) -> Self {
|
||||
Led { pin }
|
||||
}
|
||||
|
||||
pub fn on(&mut self) {
|
||||
let _ = self.pin.set_high();
|
||||
}
|
||||
|
||||
pub fn off(&mut self) {
|
||||
let _ = self.pin.set_low();
|
||||
}
|
||||
}
|
16
src/main.rs
16
src/main.rs
|
@ -30,6 +30,7 @@ use smoltcp::{
|
|||
|
||||
mod init_log;
|
||||
use init_log::init_log;
|
||||
mod leds;
|
||||
mod pins;
|
||||
use pins::Pins;
|
||||
mod ad7172;
|
||||
|
@ -89,12 +90,17 @@ fn main() -> ! {
|
|||
|
||||
timer::setup(cp.SYST, clocks);
|
||||
|
||||
let (pins, eth_pins) = Pins::setup(
|
||||
let (pins, mut leds, eth_pins) = Pins::setup(
|
||||
clocks, dp.TIM1, dp.TIM3,
|
||||
dp.GPIOA, dp.GPIOB, dp.GPIOC, dp.GPIOE, dp.GPIOF, dp.GPIOG,
|
||||
dp.GPIOA, dp.GPIOB, dp.GPIOC, dp.GPIOD, dp.GPIOE, dp.GPIOF, dp.GPIOG,
|
||||
dp.SPI2, dp.SPI4, dp.SPI5,
|
||||
dp.ADC1,
|
||||
);
|
||||
|
||||
leds.r1.on();
|
||||
leds.g3.off();
|
||||
leds.g4.off();
|
||||
|
||||
let mut channels = Channels::new(pins);
|
||||
channels.calibrate_dac_value(0);
|
||||
channels.calibrate_dac_value(1);
|
||||
|
@ -110,6 +116,8 @@ fn main() -> ! {
|
|||
|
||||
net::run(clocks, dp.ETHERNET_MAC, dp.ETHERNET_DMA, eth_pins, hwaddr, |iface| {
|
||||
Server::<Session>::run(iface, |server| {
|
||||
leds.r1.off();
|
||||
|
||||
loop {
|
||||
let instant = Instant::from_millis(i64::from(timer::now()));
|
||||
let updated_channel = channels.poll_adc(instant);
|
||||
|
@ -259,11 +267,13 @@ fn main() -> ! {
|
|||
}
|
||||
Command::PwmPid { channel } => {
|
||||
channels.channel_state(channel).pid_engaged = true;
|
||||
leds.g3.on();
|
||||
let _ = writeln!(socket, "channel {}: PID enabled to control PWM", channel
|
||||
);
|
||||
}
|
||||
Command::Pwm { channel, pin: PwmPin::ISet, duty } => {
|
||||
channels.channel_state(channel).pid_engaged = false;
|
||||
leds.g3.off();
|
||||
let voltage = Volts(duty);
|
||||
channels.set_dac(channel, voltage);
|
||||
let _ = writeln!(
|
||||
|
@ -376,6 +386,7 @@ fn main() -> ! {
|
|||
// Update watchdog
|
||||
wd.feed();
|
||||
|
||||
leds.g4.off();
|
||||
cortex_m::interrupt::free(|cs| {
|
||||
if !net::is_pending(cs) {
|
||||
// Wait for interrupts
|
||||
|
@ -383,6 +394,7 @@ fn main() -> ! {
|
|||
wfi();
|
||||
}
|
||||
});
|
||||
leds.g4.on();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
17
src/pins.rs
17
src/pins.rs
|
@ -6,6 +6,7 @@ use stm32f4xx_hal::{
|
|||
gpioa::*,
|
||||
gpiob::*,
|
||||
gpioc::*,
|
||||
gpiod::*,
|
||||
gpioe::*,
|
||||
gpiof::*,
|
||||
gpiog::*,
|
||||
|
@ -16,11 +17,14 @@ use stm32f4xx_hal::{
|
|||
rcc::Clocks,
|
||||
pwm::{self, PwmChannels},
|
||||
spi::{Spi, NoMiso},
|
||||
stm32::{ADC1, GPIOA, GPIOB, GPIOC, GPIOE, GPIOF, GPIOG, SPI2, SPI4, SPI5, TIM1, TIM3},
|
||||
stm32::{ADC1, GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, SPI2, SPI4, SPI5, TIM1, TIM3},
|
||||
time::U32Ext,
|
||||
};
|
||||
use stm32_eth::EthPins;
|
||||
use crate::channel::{Channel0, Channel1};
|
||||
use crate::{
|
||||
channel::{Channel0, Channel1},
|
||||
leds::Leds,
|
||||
};
|
||||
|
||||
|
||||
pub type EthernetPins = EthPins<
|
||||
|
@ -96,13 +100,14 @@ impl Pins {
|
|||
pub fn setup(
|
||||
clocks: Clocks,
|
||||
tim1: TIM1, tim3: TIM3,
|
||||
gpioa: GPIOA, gpiob: GPIOB, gpioc: GPIOC, gpioe: GPIOE, gpiof: GPIOF, gpiog: GPIOG,
|
||||
gpioa: GPIOA, gpiob: GPIOB, gpioc: GPIOC, gpiod: GPIOD, gpioe: GPIOE, gpiof: GPIOF, gpiog: GPIOG,
|
||||
spi2: SPI2, spi4: SPI4, spi5: SPI5,
|
||||
adc1: ADC1,
|
||||
) -> (Self, EthernetPins) {
|
||||
) -> (Self, Leds, EthernetPins) {
|
||||
let gpioa = gpioa.split();
|
||||
let gpiob = gpiob.split();
|
||||
let gpioc = gpioc.split();
|
||||
let gpiod = gpiod.split();
|
||||
let gpioe = gpioe.split();
|
||||
let gpiof = gpiof.split();
|
||||
let gpiog = gpiog.split();
|
||||
|
@ -167,6 +172,8 @@ impl Pins {
|
|||
channel1,
|
||||
};
|
||||
|
||||
let leds = Leds::new(gpiod.pd9, gpiod.pd10.into_push_pull_output(), gpiod.pd11.into_push_pull_output());
|
||||
|
||||
let eth_pins = EthPins {
|
||||
ref_clk: gpioa.pa1,
|
||||
md_io: gpioa.pa2,
|
||||
|
@ -179,7 +186,7 @@ impl Pins {
|
|||
rx_d1: gpioc.pc5,
|
||||
};
|
||||
|
||||
(pins, eth_pins)
|
||||
(pins, leds, eth_pins)
|
||||
}
|
||||
|
||||
/// Configure the GPIO pins for SPI operation, and initialize SPI
|
||||
|
|
Loading…
Reference in New Issue