2022-08-18 23:46:01 +02:00
|
|
|
#![no_std]
|
|
|
|
#![no_main]
|
|
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
|
2022-08-24 20:08:51 +02:00
|
|
|
use defmt::Format;
|
2022-08-18 23:46:01 +02:00
|
|
|
use defmt_rtt as _;
|
|
|
|
use panic_probe as _;
|
|
|
|
|
|
|
|
use embassy_executor::Spawner;
|
|
|
|
use embassy_stm32::gpio::{Level, Output, Speed};
|
|
|
|
use embassy_stm32::time::Hertz;
|
2022-08-20 18:27:10 +02:00
|
|
|
use embassy_stm32::Config;
|
|
|
|
use embassy_time::{Duration, Timer};
|
2022-08-21 00:51:24 +02:00
|
|
|
use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
|
|
|
|
use embassy_util::channel::mpmc::Channel;
|
2022-08-18 23:46:01 +02:00
|
|
|
|
2022-08-20 18:27:10 +02:00
|
|
|
mod display;
|
|
|
|
use display::display_task;
|
2022-08-18 23:46:01 +02:00
|
|
|
|
2022-08-20 18:27:10 +02:00
|
|
|
mod usb;
|
2022-08-21 18:11:58 +02:00
|
|
|
use usb::{usb_task, Gs232Cmd};
|
2022-08-18 23:46:01 +02:00
|
|
|
|
2022-08-21 18:11:58 +02:00
|
|
|
mod movement;
|
|
|
|
use movement::movement_task;
|
|
|
|
|
|
|
|
#[derive(PartialEq, Format, Copy, Clone)]
|
2022-08-21 00:51:24 +02:00
|
|
|
pub struct AzElPair {
|
|
|
|
az: u16,
|
|
|
|
el: u16,
|
|
|
|
}
|
|
|
|
|
2022-08-21 18:11:58 +02:00
|
|
|
#[derive(PartialEq, Format, Copy, Clone)]
|
|
|
|
pub struct RotorState {
|
|
|
|
actual_pos: AzElPair,
|
|
|
|
setpoint_pos: AzElPair,
|
|
|
|
stopped: bool,
|
|
|
|
}
|
|
|
|
|
2022-08-18 23:46:01 +02:00
|
|
|
#[embassy_executor::main]
|
2022-08-20 18:27:10 +02:00
|
|
|
async fn main(spawner: Spawner) {
|
2022-08-21 18:11:58 +02:00
|
|
|
static CMD_CHAN: Channel<ThreadModeRawMutex, Gs232Cmd, 1> = Channel::new();
|
2022-08-21 00:51:24 +02:00
|
|
|
static POS_CHAN: Channel<ThreadModeRawMutex, AzElPair, 1> = Channel::new();
|
2022-08-21 18:11:58 +02:00
|
|
|
static STATE_CHAN: Channel<ThreadModeRawMutex, RotorState, 1> = Channel::new();
|
2022-08-21 00:51:24 +02:00
|
|
|
|
2022-08-18 23:46:01 +02:00
|
|
|
let mut config = Config::default();
|
|
|
|
config.rcc.hse = Some(Hertz(8_000_000));
|
|
|
|
config.rcc.sys_ck = Some(Hertz(48_000_000));
|
|
|
|
config.rcc.pclk1 = Some(Hertz(24_000_000));
|
|
|
|
let mut p = embassy_stm32::init(config);
|
|
|
|
|
|
|
|
defmt::info!("Startup");
|
|
|
|
|
|
|
|
{
|
|
|
|
// BluePill board has a pull-up resistor on the D+ line.
|
|
|
|
// Pull the D+ pin down to send a RESET condition to the USB bus.
|
|
|
|
// This forced reset is needed only for development, without it host
|
|
|
|
// will not reset your device when you upload new firmware.
|
|
|
|
let _dp = Output::new(&mut p.PA12, Level::Low, Speed::Low);
|
|
|
|
Timer::after(Duration::from_millis(10)).await;
|
|
|
|
}
|
|
|
|
|
2022-08-21 00:51:24 +02:00
|
|
|
spawner
|
2022-08-21 22:19:34 +02:00
|
|
|
.spawn(usb_task(
|
|
|
|
p.USB,
|
|
|
|
p.PA12,
|
|
|
|
p.PA11,
|
|
|
|
CMD_CHAN.sender(),
|
|
|
|
POS_CHAN.receiver(),
|
|
|
|
))
|
2022-08-21 00:51:24 +02:00
|
|
|
.unwrap();
|
2022-08-21 18:11:58 +02:00
|
|
|
|
|
|
|
spawner
|
|
|
|
.spawn(movement_task(
|
2022-08-24 20:08:51 +02:00
|
|
|
p.ADC1,
|
|
|
|
p.PA0,
|
|
|
|
p.PA1,
|
|
|
|
p.PA2,
|
2022-08-21 22:19:34 +02:00
|
|
|
p.PA3,
|
|
|
|
p.PA4,
|
|
|
|
p.PA5,
|
2022-08-21 18:11:58 +02:00
|
|
|
CMD_CHAN.receiver(),
|
|
|
|
POS_CHAN.sender(),
|
|
|
|
STATE_CHAN.sender(),
|
|
|
|
))
|
|
|
|
.unwrap();
|
2022-08-21 00:51:24 +02:00
|
|
|
spawner
|
2022-08-21 18:11:58 +02:00
|
|
|
.spawn(display_task(p.I2C1, p.PB6, p.PB7, STATE_CHAN.receiver()))
|
2022-08-21 00:51:24 +02:00
|
|
|
.unwrap();
|
2022-08-18 23:46:01 +02:00
|
|
|
}
|