61 lines
1.7 KiB
Rust
61 lines
1.7 KiB
Rust
#![no_std]
|
|
#![no_main]
|
|
#![feature(type_alias_impl_trait)]
|
|
|
|
use core::fmt::Write;
|
|
|
|
use defmt::{panic, Format};
|
|
use defmt_rtt as _;
|
|
use panic_probe as _;
|
|
|
|
use embassy_executor::Spawner;
|
|
use embassy_stm32::gpio::{Level, Output, Speed};
|
|
use embassy_stm32::time::Hertz;
|
|
use embassy_stm32::Config;
|
|
use embassy_time::{Duration, Timer};
|
|
use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
|
|
use embassy_util::channel::mpmc::Channel;
|
|
use embassy_util::Forever;
|
|
|
|
mod display;
|
|
use display::display_task;
|
|
|
|
mod usb;
|
|
use usb::usb_task;
|
|
|
|
#[derive(PartialEq, Format)]
|
|
pub struct AzElPair {
|
|
az: u16,
|
|
el: u16,
|
|
}
|
|
|
|
#[embassy_executor::main]
|
|
async fn main(spawner: Spawner) {
|
|
static CMD_CHAN: Channel<ThreadModeRawMutex, AzElPair, 1> = Channel::new();
|
|
static POS_CHAN: Channel<ThreadModeRawMutex, AzElPair, 1> = Channel::new();
|
|
|
|
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;
|
|
}
|
|
|
|
spawner
|
|
.spawn(usb_task(p.USB, p.PA12, p.PA11, CMD_CHAN.sender()))
|
|
.unwrap();
|
|
spawner
|
|
.spawn(display_task(p.I2C1, p.PB6, p.PB7, CMD_CHAN.receiver()))
|
|
.unwrap();
|
|
}
|