Connected usb task to display for testing
This commit is contained in:
parent
a7b8f1ca67
commit
ace48440f3
|
@ -1,9 +1,9 @@
|
||||||
use core::fmt::Write;
|
|
||||||
|
|
||||||
use embassy_stm32::i2c;
|
use embassy_stm32::i2c;
|
||||||
use embassy_stm32::peripherals;
|
use embassy_stm32::peripherals;
|
||||||
use embassy_stm32::time::Hertz;
|
use embassy_stm32::time::Hertz;
|
||||||
use embassy_time::{Duration, Timer};
|
use embassy_time::{Duration, Timer};
|
||||||
|
use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
|
||||||
|
use embassy_util::channel::mpmc::Receiver;
|
||||||
|
|
||||||
use embedded_graphics::{
|
use embedded_graphics::{
|
||||||
mono_font::{
|
mono_font::{
|
||||||
|
@ -16,10 +16,20 @@ use embedded_graphics::{
|
||||||
text::Text,
|
text::Text,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use core::fmt::Write;
|
||||||
|
use heapless::String;
|
||||||
|
|
||||||
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
|
use ssd1306::{prelude::*, I2CDisplayInterface, Ssd1306};
|
||||||
|
|
||||||
|
use crate::AzElPair;
|
||||||
|
|
||||||
#[embassy_executor::task]
|
#[embassy_executor::task]
|
||||||
pub async fn display_task(i2c1: peripherals::I2C1, sda: peripherals::PB6, scl: peripherals::PB7) {
|
pub async fn display_task(
|
||||||
|
i2c1: peripherals::I2C1,
|
||||||
|
sda: peripherals::PB6,
|
||||||
|
scl: peripherals::PB7,
|
||||||
|
cmd_receiver: Receiver<'static, ThreadModeRawMutex, AzElPair, 1>,
|
||||||
|
) {
|
||||||
let i2c = i2c::I2c::new(i2c1, sda, scl, Hertz::hz(100_000), i2c::Config::default());
|
let i2c = i2c::I2c::new(i2c1, sda, scl, Hertz::hz(100_000), i2c::Config::default());
|
||||||
|
|
||||||
let interface = I2CDisplayInterface::new(i2c);
|
let interface = I2CDisplayInterface::new(i2c);
|
||||||
|
@ -37,6 +47,8 @@ pub async fn display_task(i2c1: peripherals::I2C1, sda: peripherals::PB6, scl: p
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
let pair = cmd_receiver.recv().await;
|
||||||
|
|
||||||
display.clear();
|
display.clear();
|
||||||
|
|
||||||
Text::new("AFG rotor ctrl v0.1.0", Point::new(0, 6), text_small)
|
Text::new("AFG rotor ctrl v0.1.0", Point::new(0, 6), text_small)
|
||||||
|
@ -56,24 +68,18 @@ pub async fn display_task(i2c1: peripherals::I2C1, sda: peripherals::PB6, scl: p
|
||||||
.draw(&mut display)
|
.draw(&mut display)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
Text::new("AZ: 23", Point::new(1, 30), text_large_inv)
|
let mut tmp: String<16> = String::new();
|
||||||
|
write!(tmp, "AZ: {}", pair.az).unwrap();
|
||||||
|
Text::new(&tmp, Point::new(1, 30), text_large_inv)
|
||||||
.draw(&mut display)
|
.draw(&mut display)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
Text::new("EL: 42", Point::new(64, 30), text_large_inv)
|
tmp.clear();
|
||||||
|
write!(tmp, "EL: {}", pair.el).unwrap();
|
||||||
|
Text::new(&tmp, Point::new(64, 30), text_large_inv)
|
||||||
.draw(&mut display)
|
.draw(&mut display)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
/*
|
|
||||||
let now = Instant::now().as_millis();
|
|
||||||
|
|
||||||
|
|
||||||
let mut buf = ArrayString::<20>::new();
|
|
||||||
write!(&mut buf, "{}", now).expect("Can't write");
|
|
||||||
Text::new(&buf, Point::new(0, 20), text_large)
|
|
||||||
.draw(&mut display)
|
|
||||||
.unwrap();
|
|
||||||
*/
|
|
||||||
display.flush().unwrap();
|
display.flush().unwrap();
|
||||||
|
|
||||||
Timer::after(Duration::from_millis(500)).await;
|
Timer::after(Duration::from_millis(500)).await;
|
||||||
|
|
22
src/main.rs
22
src/main.rs
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
|
|
||||||
use defmt::panic;
|
use defmt::{panic, Format};
|
||||||
use defmt_rtt as _;
|
use defmt_rtt as _;
|
||||||
use panic_probe as _;
|
use panic_probe as _;
|
||||||
|
|
||||||
|
@ -13,6 +13,9 @@ use embassy_stm32::gpio::{Level, Output, Speed};
|
||||||
use embassy_stm32::time::Hertz;
|
use embassy_stm32::time::Hertz;
|
||||||
use embassy_stm32::Config;
|
use embassy_stm32::Config;
|
||||||
use embassy_time::{Duration, Timer};
|
use embassy_time::{Duration, Timer};
|
||||||
|
use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
|
||||||
|
use embassy_util::channel::mpmc::Channel;
|
||||||
|
use embassy_util::Forever;
|
||||||
|
|
||||||
mod display;
|
mod display;
|
||||||
use display::display_task;
|
use display::display_task;
|
||||||
|
@ -20,8 +23,17 @@ use display::display_task;
|
||||||
mod usb;
|
mod usb;
|
||||||
use usb::usb_task;
|
use usb::usb_task;
|
||||||
|
|
||||||
|
#[derive(PartialEq, Format)]
|
||||||
|
pub struct AzElPair {
|
||||||
|
az: u16,
|
||||||
|
el: u16,
|
||||||
|
}
|
||||||
|
|
||||||
#[embassy_executor::main]
|
#[embassy_executor::main]
|
||||||
async fn main(spawner: Spawner) {
|
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();
|
let mut config = Config::default();
|
||||||
config.rcc.hse = Some(Hertz(8_000_000));
|
config.rcc.hse = Some(Hertz(8_000_000));
|
||||||
config.rcc.sys_ck = Some(Hertz(48_000_000));
|
config.rcc.sys_ck = Some(Hertz(48_000_000));
|
||||||
|
@ -39,6 +51,10 @@ async fn main(spawner: Spawner) {
|
||||||
Timer::after(Duration::from_millis(10)).await;
|
Timer::after(Duration::from_millis(10)).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
spawner.spawn(usb_task(p.USB, p.PA12, p.PA11)).unwrap();
|
spawner
|
||||||
spawner.spawn(display_task(p.I2C1, p.PB6, p.PB7)).unwrap();
|
.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();
|
||||||
}
|
}
|
||||||
|
|
26
src/usb.rs
26
src/usb.rs
|
@ -1,22 +1,27 @@
|
||||||
use defmt::Format;
|
use defmt::Format;
|
||||||
|
|
||||||
use embassy_executor::Spawner;
|
use embassy_stm32::interrupt;
|
||||||
use embassy_stm32::gpio::{Level, Output, Speed};
|
|
||||||
use embassy_stm32::peripherals;
|
use embassy_stm32::peripherals;
|
||||||
use embassy_stm32::time::Hertz;
|
|
||||||
use embassy_stm32::usb::Driver;
|
use embassy_stm32::usb::Driver;
|
||||||
use embassy_stm32::{interrupt, Config};
|
|
||||||
use embassy_time::{Duration, Timer};
|
|
||||||
use embassy_usb::Builder;
|
use embassy_usb::Builder;
|
||||||
use embassy_usb_serial::{CdcAcmClass, State};
|
use embassy_usb_serial::{CdcAcmClass, State};
|
||||||
|
use embassy_util::blocking_mutex::raw::ThreadModeRawMutex;
|
||||||
|
use embassy_util::channel::mpmc::Sender;
|
||||||
|
|
||||||
use futures::future::join;
|
use futures::future::join;
|
||||||
|
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
|
|
||||||
use heapless::String;
|
use heapless::String;
|
||||||
|
|
||||||
|
use crate::AzElPair;
|
||||||
|
|
||||||
#[embassy_executor::task]
|
#[embassy_executor::task]
|
||||||
pub async fn usb_task(usb: peripherals::USB, dp_pin: peripherals::PA12, dm_pin: peripherals::PA11) {
|
pub async fn usb_task(
|
||||||
|
usb: peripherals::USB,
|
||||||
|
dp_pin: peripherals::PA12,
|
||||||
|
dm_pin: peripherals::PA11,
|
||||||
|
cmd_sender: Sender<'static, ThreadModeRawMutex, AzElPair, 1>,
|
||||||
|
) {
|
||||||
let irq = interrupt::take!(USB_LP_CAN1_RX0);
|
let irq = interrupt::take!(USB_LP_CAN1_RX0);
|
||||||
let driver = Driver::new(usb, irq, dp_pin, dm_pin);
|
let driver = Driver::new(usb, irq, dp_pin, dm_pin);
|
||||||
|
|
||||||
|
@ -98,7 +103,8 @@ pub async fn usb_task(usb: peripherals::USB, dp_pin: peripherals::PA12, dm_pin:
|
||||||
Gs232Cmd::GetAlEz => {
|
Gs232Cmd::GetAlEz => {
|
||||||
write!(&mut resp, "AZ={} EL={}\r", az_actual, el_actual).unwrap();
|
write!(&mut resp, "AZ={} EL={}\r", az_actual, el_actual).unwrap();
|
||||||
}
|
}
|
||||||
Gs232Cmd::MoveTo(_az, _el) => {
|
Gs232Cmd::MoveTo(pair) => {
|
||||||
|
cmd_sender.send(pair).await;
|
||||||
resp.push_str("\r").unwrap();
|
resp.push_str("\r").unwrap();
|
||||||
}
|
}
|
||||||
Gs232Cmd::Stop => {
|
Gs232Cmd::Stop => {
|
||||||
|
@ -133,7 +139,7 @@ enum Gs232Cmd {
|
||||||
GetAl,
|
GetAl,
|
||||||
GetEz,
|
GetEz,
|
||||||
GetAlEz,
|
GetAlEz,
|
||||||
MoveTo(u16, u16),
|
MoveTo(AzElPair),
|
||||||
Stop,
|
Stop,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,7 +167,7 @@ fn parse_command(data: &str) -> Gs232Cmd {
|
||||||
if data.len() == 8 {
|
if data.len() == 8 {
|
||||||
if let Ok(az) = data[1..4].parse::<u16>() {
|
if let Ok(az) = data[1..4].parse::<u16>() {
|
||||||
if let Ok(el) = data[5..].parse::<u16>() {
|
if let Ok(el) = data[5..].parse::<u16>() {
|
||||||
Gs232Cmd::MoveTo(az, el)
|
Gs232Cmd::MoveTo(AzElPair { az: az, el: el })
|
||||||
} else {
|
} else {
|
||||||
Gs232Cmd::Unkown
|
Gs232Cmd::Unkown
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue