Compare commits
6 commits
72bf0d8793
...
dd07cf5661
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dd07cf5661 | ||
|
|
4cf8f67bf9 | ||
|
|
77394816df | ||
|
|
2d0a54eccc | ||
|
|
bf672e3df1 | ||
|
|
78db26addc |
15 changed files with 701 additions and 1102 deletions
1253
Cargo.lock
generated
1253
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -5,26 +5,22 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.83"
|
anyhow = "1.0.83"
|
||||||
axum = { version = "0.8.8", features = ["macros"] }
|
axum = { version = "0.7.5", features = ["macros"] }
|
||||||
fern = { version = "0.7.1", features = ["colored"] }
|
fern = { version = "0.6.2", features = ["colored"] }
|
||||||
humantime = "2.1.0"
|
humantime = "2.1.0"
|
||||||
log = "0.4.21"
|
log = "0.4.21"
|
||||||
nom = "8.0.0"
|
nom = "7.1.3"
|
||||||
serde_json = "1.0.118"
|
serde_json = "1.0.118"
|
||||||
serialport = "4.5.1"
|
serialport = "4.5.1"
|
||||||
tokio = {version = "1.37.0", features = ["full"]}
|
tokio = {version = "1.37.0", features = ["full"]}
|
||||||
tower-http = { version = "0.6.8", features = ["fs", "trace"] }
|
tokio-macros = { version = "0.2.0-alpha.6" }
|
||||||
dfu-libusb = "0.5.5"
|
tower-http = { version = "0.5.2", features = ["fs", "trace"] }
|
||||||
rusb = "0.9"
|
|
||||||
clap = { version = "4.5.19", features = ["derive"] }
|
|
||||||
indicatif = "0.18.3"
|
|
||||||
tokio-serial = {version = "5.4.4", features = ["codec", "rt"] }
|
|
||||||
tokio-util = { version = "0.7.13", features = ["codec", "rt"] }
|
|
||||||
bytes = "1.9.0"
|
|
||||||
futures = "0.3.31"
|
|
||||||
nom-language = "0.1.0"
|
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
tracing-subscriber = "0.3.18"
|
tracing-subscriber = "0.3.18"
|
||||||
radomctl-protocol = { path = "../protocol" }
|
radomctl-protocol = { path = "../protocol" }
|
||||||
postcard = {version = "1.0.10", features = ["use-std"]}
|
postcard = {version = "1.0.10", features = ["use-std"]}
|
||||||
|
dfu-libusb = "0.3.0"
|
||||||
|
libusb1-sys = "0.6"
|
||||||
|
rusb = "0.9"
|
||||||
|
clap = { version = "4.5.19", features = ["derive"] }
|
||||||
|
indicatif = "0.17.8"
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,9 @@ use std::{
|
||||||
use anyhow::{anyhow, Context};
|
use anyhow::{anyhow, Context};
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use dfu_libusb::{Dfu, DfuLibusb};
|
use dfu_libusb::{Dfu, DfuLibusb};
|
||||||
use postcard::to_stdvec_cobs;
|
use postcard::{from_bytes_cobs, to_stdvec_cobs};
|
||||||
use radomctl_protocol::*;
|
use radomctl_protocol::*;
|
||||||
|
use radomctld::logger::setup_logger;
|
||||||
|
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
struct Cli {
|
struct Cli {
|
||||||
|
|
|
||||||
|
|
@ -1,16 +0,0 @@
|
||||||
use std::time::Duration;
|
|
||||||
|
|
||||||
use postcard::{from_bytes_cobs, to_stdvec_cobs};
|
|
||||||
use radomctl_protocol::*;
|
|
||||||
use radomctld::logger::setup_logger;
|
|
||||||
|
|
||||||
pub fn main() -> () {
|
|
||||||
let mut port = serialport::new("/dev/ttyACM0", 115_200)
|
|
||||||
.timeout(Duration::from_millis(10))
|
|
||||||
.open()
|
|
||||||
.expect("Failed to open port");
|
|
||||||
|
|
||||||
let host_msg = HostMessage::TriggerDFUBootloader;
|
|
||||||
let msg_bytes = to_stdvec_cobs(&host_msg).unwrap();
|
|
||||||
port.write_all(&msg_bytes).unwrap();
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use fern::colors::{Color, ColoredLevelConfig};
|
use fern::colors::{Color, ColoredLevelConfig};
|
||||||
|
use log::{debug, error, info, warn};
|
||||||
|
use std::io;
|
||||||
|
|
||||||
pub fn setup_logger() -> Result<()> {
|
pub fn setup_logger() -> Result<()> {
|
||||||
let colors = ColoredLevelConfig::new()
|
let colors = ColoredLevelConfig::new()
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,8 @@
|
||||||
use anyhow::anyhow;
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use axum::{extract::State, routing::get, Json, Router};
|
use fern::colors::{Color, ColoredLevelConfig};
|
||||||
use clap::Parser;
|
use log::{debug, error, info, warn, Level};
|
||||||
use log::{debug, error, info};
|
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
|
use std::{borrow::Borrow, io};
|
||||||
use tokio::{
|
use tokio::{
|
||||||
self,
|
self,
|
||||||
io::{AsyncBufReadExt, AsyncWriteExt, BufStream},
|
io::{AsyncBufReadExt, AsyncWriteExt, BufStream},
|
||||||
|
|
@ -11,23 +10,28 @@ use tokio::{
|
||||||
sync::{mpsc, watch},
|
sync::{mpsc, watch},
|
||||||
task::JoinSet,
|
task::JoinSet,
|
||||||
};
|
};
|
||||||
use tokio_serial;
|
|
||||||
|
|
||||||
use radomctld::{
|
use axum::{
|
||||||
logger::setup_logger,
|
extract::State,
|
||||||
rotctlprotocol::{parse_command, Command},
|
http::StatusCode,
|
||||||
rotor::control_rotor,
|
routing::{get, post},
|
||||||
|
Json, Router,
|
||||||
};
|
};
|
||||||
use tower_http::{
|
use tower_http::{
|
||||||
services::{ServeDir, ServeFile},
|
services::{ServeDir, ServeFile},
|
||||||
trace::TraceLayer,
|
trace::TraceLayer,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use radomctld::{
|
||||||
|
logger::setup_logger,
|
||||||
|
rotctlprotocol::{parse_command, Command},
|
||||||
|
rotor::control_rotor,
|
||||||
|
};
|
||||||
|
|
||||||
async fn process_socket(
|
async fn process_socket(
|
||||||
socket: TcpStream,
|
socket: TcpStream,
|
||||||
cmd_tx: mpsc::Sender<Command>,
|
cmd_tx: mpsc::Sender<Command>,
|
||||||
pos_rx: watch::Receiver<(f32, f32)>,
|
mut pos_rx: watch::Receiver<(f32, f32)>,
|
||||||
) {
|
) {
|
||||||
let mut stream = BufStream::new(socket);
|
let mut stream = BufStream::new(socket);
|
||||||
|
|
||||||
|
|
@ -82,61 +86,16 @@ struct AxumAppState {
|
||||||
pos_rx: watch::Receiver<(f32, f32)>,
|
pos_rx: watch::Receiver<(f32, f32)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Parser)]
|
|
||||||
struct Cli {
|
|
||||||
/// The usb serial number of the radom-controller
|
|
||||||
#[arg(short, long)]
|
|
||||||
serialnumber: String,
|
|
||||||
|
|
||||||
/// Listen address for the webserver
|
|
||||||
#[arg(short, long, default_value = "0.0.0.0:8000")]
|
|
||||||
web_listen_address: String,
|
|
||||||
|
|
||||||
/// Listen address for rotctl
|
|
||||||
#[arg(short, long, default_value = "0.0.0.0:1337")]
|
|
||||||
rotctl_listen_address: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<()> {
|
async fn main() -> Result<()> {
|
||||||
setup_logger()?;
|
setup_logger()?;
|
||||||
|
|
||||||
let args = Cli::parse();
|
|
||||||
|
|
||||||
let ports = tokio_serial::available_ports().unwrap_or(Vec::<serialport::SerialPortInfo>::new());
|
|
||||||
|
|
||||||
let mut radom_port: Option<String> = None;
|
|
||||||
for port in ports {
|
|
||||||
match port.port_type {
|
|
||||||
serialport::SerialPortType::UsbPort(usb_port_info) => {
|
|
||||||
match usb_port_info.serial_number {
|
|
||||||
Some(serial) => {
|
|
||||||
debug!("Found a serial port with: {}", serial);
|
|
||||||
if serial == args.serialnumber {
|
|
||||||
radom_port = Some(port.port_name.to_owned());
|
|
||||||
info!("Found radom-controller as {}", port.port_name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => continue,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => continue,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let radom_port = match radom_port {
|
|
||||||
Some(port) => port,
|
|
||||||
_ => {
|
|
||||||
return Err(anyhow!("No matching port found."));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let (cmd_tx, cmd_rx) = mpsc::channel::<Command>(16);
|
let (cmd_tx, cmd_rx) = mpsc::channel::<Command>(16);
|
||||||
let (pos_tx, pos_rx) = watch::channel::<(f32, f32)>((0.0, 0.0));
|
let (pos_tx, pos_rx) = watch::channel::<(f32, f32)>((0.0, 0.0));
|
||||||
|
|
||||||
let mut tasks = JoinSet::new();
|
let mut tasks = JoinSet::new();
|
||||||
|
|
||||||
tasks.spawn(async move { control_rotor(cmd_rx, pos_tx, radom_port).await });
|
tasks.spawn(async move { control_rotor(cmd_rx, pos_tx).await });
|
||||||
|
|
||||||
let state = AxumAppState {
|
let state = AxumAppState {
|
||||||
pos_rx: pos_rx.clone(),
|
pos_rx: pos_rx.clone(),
|
||||||
|
|
@ -149,14 +108,14 @@ async fn main() -> Result<()> {
|
||||||
.with_state(state)
|
.with_state(state)
|
||||||
.layer(TraceLayer::new_for_http());
|
.layer(TraceLayer::new_for_http());
|
||||||
|
|
||||||
let listener = tokio::net::TcpListener::bind(args.web_listen_address).await?;
|
let listener = tokio::net::TcpListener::bind("0.0.0.0:8000").await?;
|
||||||
axum::serve(listener, app).await?;
|
axum::serve(listener, app).await?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
});
|
});
|
||||||
|
|
||||||
tasks.spawn(async move {
|
tasks.spawn(async move {
|
||||||
let listener = TcpListener::bind(args.rotctl_listen_address).await?;
|
let listener = TcpListener::bind("127.0.0.1:1337").await?;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let (socket, _) = listener.accept().await?;
|
let (socket, _) = listener.accept().await?;
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,13 @@ use nom::{
|
||||||
character::complete::{
|
character::complete::{
|
||||||
alphanumeric1, i8, multispace0, multispace1, newline, none_of, not_line_ending, space1,
|
alphanumeric1, i8, multispace0, multispace1, newline, none_of, not_line_ending, space1,
|
||||||
},
|
},
|
||||||
combinator::{all_consuming, map, opt, recognize},
|
combinator::{all_consuming, map, opt, recognize, rest},
|
||||||
error::context,
|
error::{context, convert_error, VerboseError},
|
||||||
multi::many1,
|
multi::{many0, many1},
|
||||||
number::complete::float,
|
number::complete::float,
|
||||||
sequence::{preceded, separated_pair, terminated},
|
sequence::{preceded, separated_pair, terminated},
|
||||||
Err as NomErr, IResult, Parser,
|
Err as NomErr, IResult, Parser,
|
||||||
};
|
};
|
||||||
use nom_language::error::{convert_error, VerboseError};
|
|
||||||
|
|
||||||
#[derive(PartialEq, Debug)]
|
#[derive(PartialEq, Debug)]
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
|
|
|
||||||
|
|
@ -1,91 +1,52 @@
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use bytes::{BufMut, BytesMut};
|
use log::{debug, error, info, warn};
|
||||||
use futures::{stream::StreamExt, SinkExt};
|
|
||||||
use postcard::{from_bytes_cobs, to_stdvec_cobs};
|
|
||||||
use radomctl_protocol::{HostMessage, PositionTarget, RadomMessage};
|
|
||||||
use std::{io, time::Duration};
|
|
||||||
use tokio::{
|
use tokio::{
|
||||||
self,
|
self,
|
||||||
io::AsyncBufReadExt,
|
io::{AsyncBufReadExt, AsyncWriteExt, BufStream},
|
||||||
sync::{mpsc, watch},
|
net::{TcpListener, TcpStream},
|
||||||
|
sync::{self, mpsc, watch},
|
||||||
time,
|
time,
|
||||||
};
|
};
|
||||||
use tokio_serial::SerialPortBuilderExt;
|
|
||||||
use tokio_util::codec::{Decoder, Encoder};
|
|
||||||
|
|
||||||
use crate::rotctlprotocol::Command;
|
use crate::rotctlprotocol::{parse_command, Command};
|
||||||
|
|
||||||
struct ProtocolCodec;
|
|
||||||
|
|
||||||
impl Decoder for ProtocolCodec {
|
|
||||||
type Item = RadomMessage;
|
|
||||||
type Error = io::Error;
|
|
||||||
|
|
||||||
fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
|
|
||||||
let frame_end = src.as_ref().iter().position(|b| *b == 0);
|
|
||||||
if let Some(n) = frame_end {
|
|
||||||
let mut frame = src.split_to(n + 1);
|
|
||||||
let host_msg = from_bytes_cobs::<RadomMessage>(&mut frame).unwrap();
|
|
||||||
return Ok(Some(host_msg));
|
|
||||||
}
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Encoder<HostMessage> for ProtocolCodec {
|
|
||||||
type Error = io::Error;
|
|
||||||
|
|
||||||
fn encode(&mut self, item: HostMessage, dst: &mut BytesMut) -> Result<(), Self::Error> {
|
|
||||||
let msg_bytes = to_stdvec_cobs(&item).unwrap();
|
|
||||||
dst.put(msg_bytes.as_slice());
|
|
||||||
dst.put_u8(0);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn control_rotor(
|
pub async fn control_rotor(
|
||||||
mut rx_cmd: mpsc::Receiver<Command>,
|
mut rx_cmd: mpsc::Receiver<Command>,
|
||||||
pos_tx: watch::Sender<(f32, f32)>,
|
pos_tx: watch::Sender<(f32, f32)>,
|
||||||
radom_port: String,
|
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let port = tokio_serial::new(radom_port, 115_200)
|
let mut actual_az = 0.0;
|
||||||
.timeout(Duration::from_millis(10))
|
let mut actual_el = 0.0;
|
||||||
.open_native_async()
|
|
||||||
.expect("Failed to open port");
|
|
||||||
|
|
||||||
let (mut port_writer, mut port_reader) = ProtocolCodec.framed(port).split();
|
let mut target_az = 0.0;
|
||||||
|
let mut target_el = 0.0;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
Some(command) = rx_cmd.recv() => {
|
Some(command) = rx_cmd.recv() => {
|
||||||
match command {
|
match command {
|
||||||
Command::SetPos(az, el) => {
|
Command::SetPos(az, el) => {
|
||||||
//info!("Received set pos {} {}", az, el);
|
info!("Received set pos {} {}", az, el);
|
||||||
port_writer.send(HostMessage::SetTarget(PositionTarget { az, el })).await?;
|
target_az = az;
|
||||||
|
target_el = el;
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_ = time::sleep(time::Duration::from_millis(100)) => {
|
_ = time::sleep(time::Duration::from_millis(100)) => {
|
||||||
//info!("Requesting status");
|
if target_az < actual_az {
|
||||||
port_writer.send(HostMessage::RequestStatus).await?;
|
actual_az -= 1.0;
|
||||||
},
|
} else if target_az > actual_az {
|
||||||
|
actual_az += 1.0;
|
||||||
msg = port_reader.next() => {
|
|
||||||
match msg {
|
|
||||||
Some(Ok(msg)) => {
|
|
||||||
match msg {
|
|
||||||
RadomMessage::Status(status) => {
|
|
||||||
//info!("Received status {:?}", status);
|
|
||||||
pos_tx.send((status.position.az, status.position.el)).unwrap();
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
if target_el < actual_el {
|
||||||
|
actual_el -= 1.0;
|
||||||
|
} else if target_el > actual_el {
|
||||||
|
actual_el += 1.0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pos_tx.send((actual_az, actual_el)).unwrap();
|
||||||
|
},
|
||||||
else => return Ok(())
|
else => return Ok(())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,44 +19,3 @@ rrb = "run --release --bin"
|
||||||
|
|
||||||
[env]
|
[env]
|
||||||
DEFMT_LOG = "debug"
|
DEFMT_LOG = "debug"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# cargo build/run
|
|
||||||
[profile.dev]
|
|
||||||
codegen-units = 1
|
|
||||||
debug = 2
|
|
||||||
debug-assertions = true # <-
|
|
||||||
incremental = false
|
|
||||||
opt-level = 'z' # <-
|
|
||||||
overflow-checks = true # <-
|
|
||||||
|
|
||||||
# cargo test
|
|
||||||
[profile.test]
|
|
||||||
codegen-units = 1
|
|
||||||
debug = 2
|
|
||||||
debug-assertions = true # <-
|
|
||||||
incremental = false
|
|
||||||
opt-level = 3 # <-
|
|
||||||
overflow-checks = true # <-
|
|
||||||
|
|
||||||
# cargo build/run --release
|
|
||||||
[profile.release]
|
|
||||||
codegen-units = 1
|
|
||||||
debug = 2
|
|
||||||
debug-assertions = false # <-
|
|
||||||
incremental = false
|
|
||||||
lto = 'fat'
|
|
||||||
opt-level = 3 # <-
|
|
||||||
overflow-checks = false # <-
|
|
||||||
|
|
||||||
# cargo test --release
|
|
||||||
[profile.bench]
|
|
||||||
codegen-units = 1
|
|
||||||
debug = 2
|
|
||||||
debug-assertions = false # <-
|
|
||||||
incremental = false
|
|
||||||
lto = 'fat'
|
|
||||||
opt-level = 3 # <-
|
|
||||||
overflow-checks = false # <-
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,25 +5,25 @@ version = "0.1.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
|
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
|
||||||
defmt = { version = "1.0", features = ["encoding-rzcobs"] }
|
defmt = { version = "0.3", features = ["encoding-rzcobs"] }
|
||||||
defmt-brtt = { version = "0.1", default-features = false, features = ["rtt"] }
|
defmt-brtt = { version = "0.1", default-features = false, features = ["rtt"] }
|
||||||
panic-probe = { version = "1.0", features = ["print-defmt"] }
|
panic-probe = { version = "0.3", features = ["print-defmt"] }
|
||||||
rtic = { version = "2.0.1", features = [ "thumbv7-backend" ] }
|
rtic = { version = "2.0.1", features = [ "thumbv7-backend" ] }
|
||||||
defmt-rtt = "1.1"
|
defmt-rtt = "0.4"
|
||||||
stm32f4xx-hal = { version = "0.23.0", features = ["stm32f401", "usb_fs"] }
|
stm32f4xx-hal = { version = "0.21.0", features = ["stm32f401", "usb_fs"] }
|
||||||
embedded-hal = {version = "1.0.0"}
|
embedded-hal = {version = "1.0.0"}
|
||||||
nb = "1.0.0"
|
nb = "1.0.0"
|
||||||
num-traits = { version = "0.2", default-features = false, features = ["libm"] }
|
num-traits = { version = "0.2", default-features = false, features = ["libm"] }
|
||||||
num = {version = "0.4", default-features = false}
|
num = {version = "0.4", default-features = false}
|
||||||
ufmt = "0.2.0"
|
ufmt = "0.2.0"
|
||||||
qmc5883l = {version = "0.0.1", git="https://github.com/patrickelectric/qmc5883l", rev="62b8a64b54e0f843ddf0c5942f8ed218b5f3e492"}
|
qmc5883l = "0.0.1"
|
||||||
rtic-monotonics = {version = "2.0.2", features = ["cortex-m-systick"]}
|
rtic-monotonics = {version = "2.0.2", features = ["cortex-m-systick"]}
|
||||||
xca9548a = "1.0.0"
|
xca9548a = "0.2.1"
|
||||||
as5048a = { git = "https://github.com/LongHairedHacker/as5048a", rev="b15d716bf47ce4975a6cefebf82006c9b09e8fea"}
|
as5048a = { git = "https://github.com/LongHairedHacker/as5048a", rev="b15d716bf47ce4975a6cefebf82006c9b09e8fea"}
|
||||||
usb-device = "0.3.2"
|
usb-device = "0.3.2"
|
||||||
usbd-serial = "0.2.2"
|
usbd-serial = "0.2.2"
|
||||||
postcard = {version = "1.0.10", features = ["use-defmt"]}
|
postcard = {version = "1.0.10", features = ["use-defmt"]}
|
||||||
heapless = {version = "0.9.2", features = ["defmt"]}
|
heapless = {version = "0.8.0", features = ["defmt-03"]}
|
||||||
radomctl-protocol = { path = "../protocol" }
|
radomctl-protocol = { path = "../protocol" }
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -38,3 +38,50 @@ defmt-debug = []
|
||||||
defmt-info = []
|
defmt-info = []
|
||||||
defmt-warn = []
|
defmt-warn = []
|
||||||
defmt-error = []
|
defmt-error = []
|
||||||
|
|
||||||
|
# cargo build/run
|
||||||
|
[profile.dev]
|
||||||
|
codegen-units = 1
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = true # <-
|
||||||
|
incremental = false
|
||||||
|
opt-level = 'z' # <-
|
||||||
|
overflow-checks = true # <-
|
||||||
|
|
||||||
|
# cargo test
|
||||||
|
[profile.test]
|
||||||
|
codegen-units = 1
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = true # <-
|
||||||
|
incremental = false
|
||||||
|
opt-level = 3 # <-
|
||||||
|
overflow-checks = true # <-
|
||||||
|
|
||||||
|
# cargo build/run --release
|
||||||
|
[profile.release]
|
||||||
|
codegen-units = 1
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = false # <-
|
||||||
|
incremental = false
|
||||||
|
lto = 'fat'
|
||||||
|
opt-level = 3 # <-
|
||||||
|
overflow-checks = false # <-
|
||||||
|
|
||||||
|
# cargo test --release
|
||||||
|
[profile.bench]
|
||||||
|
codegen-units = 1
|
||||||
|
debug = 2
|
||||||
|
debug-assertions = false # <-
|
||||||
|
incremental = false
|
||||||
|
lto = 'fat'
|
||||||
|
opt-level = 3 # <-
|
||||||
|
overflow-checks = false # <-
|
||||||
|
|
||||||
|
|
||||||
|
# uncomment this to switch from the crates.io version of defmt to its git version
|
||||||
|
# check app-template's README for instructions
|
||||||
|
# [patch.crates-io]
|
||||||
|
# defmt = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version supported by probe-rs (see changelog)" }
|
||||||
|
# defmt-rtt = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version supported by probe-rs (see changelog)" }
|
||||||
|
# defmt-test = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version supported by probe-rs (see changelog)" }
|
||||||
|
# panic-probe = { git = "https://github.com/knurling-rs/defmt", rev = "use defmt version supported by probe-rs (see changelog)" }
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
use core::mem::MaybeUninit;
|
|
||||||
use core::ptr::addr_of_mut;
|
use core::ptr::addr_of_mut;
|
||||||
|
|
||||||
use stm32f4xx_hal::pac;
|
use stm32f4xx_hal::pac;
|
||||||
|
|
||||||
fn jump_to_bootloader() {
|
fn jump_to_bootloader() {
|
||||||
|
|
@ -9,7 +9,7 @@ fn jump_to_bootloader() {
|
||||||
let address: u32 = 0x1FFF0000;
|
let address: u32 = 0x1FFF0000;
|
||||||
|
|
||||||
let device = pac::Peripherals::steal();
|
let device = pac::Peripherals::steal();
|
||||||
device.SYSCFG.memrmp().modify(|_, w| w.bits(0x01));
|
device.SYSCFG.memrm.modify(|_, w| w.bits(0x01));
|
||||||
|
|
||||||
let mut p = cortex_m::Peripherals::steal();
|
let mut p = cortex_m::Peripherals::steal();
|
||||||
p.SCB.invalidate_icache();
|
p.SCB.invalidate_icache();
|
||||||
|
|
@ -47,10 +47,9 @@ fn clear_bootloader_flag() {
|
||||||
pub fn init() {
|
pub fn init() {
|
||||||
let requested = get_bootloader_flag() == BOOTLOADER_REQUESTED;
|
let requested = get_bootloader_flag() == BOOTLOADER_REQUESTED;
|
||||||
if requested {
|
if requested {
|
||||||
|
clear_bootloader_flag();
|
||||||
jump_to_bootloader();
|
jump_to_bootloader();
|
||||||
}
|
}
|
||||||
|
|
||||||
clear_bootloader_flag();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn reboot_to_bootloader() -> ! {
|
pub fn reboot_to_bootloader() -> ! {
|
||||||
|
|
|
||||||
|
|
@ -23,29 +23,32 @@ mod app {
|
||||||
|
|
||||||
use as5048a::AS5048A;
|
use as5048a::AS5048A;
|
||||||
|
|
||||||
use crate::bootloader;
|
|
||||||
use core::fmt::Write;
|
use core::fmt::Write;
|
||||||
use heapless::{String, Vec};
|
use heapless::{String, Vec};
|
||||||
use num_traits::{Float, FloatConst};
|
use num_traits::{Float, FloatConst};
|
||||||
use postcard::{from_bytes_cobs, to_vec_cobs};
|
use postcard::{from_bytes_cobs, to_vec_cobs};
|
||||||
use qmc5883l::{self, QMC5883L};
|
|
||||||
use radomctl_protocol::*;
|
|
||||||
use radomctl_protocol::{HostMessage, *};
|
|
||||||
use rtic_monotonics::systick::prelude::*;
|
|
||||||
use stm32f4xx_hal::{
|
use stm32f4xx_hal::{
|
||||||
gpio::{gpioa, gpiob, gpioc, Output, PushPull},
|
gpio::{gpioa, gpiob, gpioc, Output, PushPull},
|
||||||
i2c,
|
i2c,
|
||||||
otg_fs::{UsbBus, UsbBusType, USB},
|
otg_fs::{UsbBus, UsbBusType, USB},
|
||||||
pac::{I2C1, SPI1},
|
pac::{I2C1, SPI1},
|
||||||
prelude::*,
|
prelude::*,
|
||||||
rcc::Config,
|
|
||||||
signature, spi,
|
signature, spi,
|
||||||
};
|
};
|
||||||
use usb_device::prelude::*;
|
use usb_device::prelude::*;
|
||||||
use usb_device::{class_prelude::UsbBusAllocator, device};
|
use usb_device::{class_prelude::UsbBusAllocator, device};
|
||||||
use usbd_serial::SerialPort;
|
use usbd_serial::SerialPort;
|
||||||
|
|
||||||
use xca9548a::{SlaveAddr, Xca9548a};
|
use xca9548a::{SlaveAddr, Xca9548a};
|
||||||
|
|
||||||
|
use qmc5883l::{self, QMC5883L};
|
||||||
|
|
||||||
|
use radomctl_protocol::*;
|
||||||
|
|
||||||
|
use rtic_monotonics::systick::prelude::*;
|
||||||
|
|
||||||
|
use crate::bootloader;
|
||||||
|
|
||||||
systick_monotonic!(Mono, 1000);
|
systick_monotonic!(Mono, 1000);
|
||||||
|
|
||||||
const USB_BUFFER_SIZE: usize = 64;
|
const USB_BUFFER_SIZE: usize = 64;
|
||||||
|
|
@ -54,11 +57,6 @@ mod app {
|
||||||
#[shared]
|
#[shared]
|
||||||
struct Shared {
|
struct Shared {
|
||||||
az_angle: i32,
|
az_angle: i32,
|
||||||
az_compass: i32,
|
|
||||||
az_target: i32,
|
|
||||||
|
|
||||||
el_angle: i32,
|
|
||||||
el_target: i32,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Local resources go here
|
// Local resources go here
|
||||||
|
|
@ -73,7 +71,7 @@ mod app {
|
||||||
spi_cs3: gpiob::PB15<Output<PushPull>>,
|
spi_cs3: gpiob::PB15<Output<PushPull>>,
|
||||||
spi1: spi::Spi<SPI1>,
|
spi1: spi::Spi<SPI1>,
|
||||||
|
|
||||||
az_enable: gpiob::PB8<Output<PushPull>>,
|
az_enable: gpioa::PA10<Output<PushPull>>,
|
||||||
az_dir: gpioa::PA15<Output<PushPull>>,
|
az_dir: gpioa::PA15<Output<PushPull>>,
|
||||||
az_step: gpiob::PB3<Output<PushPull>>,
|
az_step: gpiob::PB3<Output<PushPull>>,
|
||||||
|
|
||||||
|
|
@ -91,19 +89,26 @@ mod app {
|
||||||
bootloader::init();
|
bootloader::init();
|
||||||
|
|
||||||
defmt::info!("init");
|
defmt::info!("init");
|
||||||
let mut rcc = cx
|
|
||||||
.device
|
|
||||||
.RCC
|
|
||||||
.freeze(Config::hse(25.MHz()).sysclk(84.MHz()).require_pll48clk());
|
|
||||||
|
|
||||||
Mono::start(cx.core.SYST, rcc.clocks.sysclk().to_Hz());
|
let rcc = cx.device.RCC.constrain();
|
||||||
|
|
||||||
|
// Freeze the configuration of all the clocks in the system and store the frozen frequencies in
|
||||||
|
// `clocks`
|
||||||
|
let clocks = rcc
|
||||||
|
.cfgr
|
||||||
|
.use_hse(25.MHz())
|
||||||
|
.sysclk(84.MHz())
|
||||||
|
.require_pll48clk()
|
||||||
|
.freeze();
|
||||||
|
|
||||||
|
Mono::start(cx.core.SYST, clocks.sysclk().to_Hz());
|
||||||
|
|
||||||
defmt::info!("Clock Setup done");
|
defmt::info!("Clock Setup done");
|
||||||
|
|
||||||
// Acquire the GPIO peripherials
|
// Acquire the GPIO peripherials
|
||||||
let gpioa = cx.device.GPIOA.split(&mut rcc);
|
let gpioa = cx.device.GPIOA.split();
|
||||||
let gpiob = cx.device.GPIOB.split(&mut rcc);
|
let gpiob = cx.device.GPIOB.split();
|
||||||
let gpioc = cx.device.GPIOC.split(&mut rcc);
|
let gpioc = cx.device.GPIOC.split();
|
||||||
|
|
||||||
let board_led = gpioc.pc13.into_push_pull_output();
|
let board_led = gpioc.pc13.into_push_pull_output();
|
||||||
|
|
||||||
|
|
@ -119,7 +124,7 @@ mod app {
|
||||||
cx.device.OTG_FS_PWRCLK,
|
cx.device.OTG_FS_PWRCLK,
|
||||||
),
|
),
|
||||||
(gpioa.pa11, gpioa.pa12),
|
(gpioa.pa11, gpioa.pa12),
|
||||||
&rcc.clocks,
|
&clocks,
|
||||||
);
|
);
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
|
|
@ -128,11 +133,22 @@ mod app {
|
||||||
|
|
||||||
let usb_serial = usbd_serial::SerialPort::new(unsafe { USB_BUS.as_ref().unwrap() });
|
let usb_serial = usbd_serial::SerialPort::new(unsafe { USB_BUS.as_ref().unwrap() });
|
||||||
|
|
||||||
let uid = signature::Uid::get();
|
let serial = unsafe {
|
||||||
|
let u_id0 = 0x1FFF_7A10 as *const u32;
|
||||||
|
let u_id2 = 0x1FFF_7A18 as *const u32;
|
||||||
|
|
||||||
|
defmt::debug!("UID0: {:x}", u_id0.read());
|
||||||
|
defmt::debug!("UID2: {:x}", u_id2.read());
|
||||||
|
|
||||||
|
// See https://community.st.com/t5/stm32-mcus-products/usb-bootloader-serial-number/td-p/432148
|
||||||
|
(u_id0.read() as u64 + u_id2.read() as u64) << 16
|
||||||
|
| (u_id2.read() as u64 & 0xFF00) >> 8
|
||||||
|
| (u_id2.read() as u64 & 0x00FF) << 8
|
||||||
|
};
|
||||||
|
|
||||||
static mut SERIAL: String<16> = String::new();
|
static mut SERIAL: String<16> = String::new();
|
||||||
unsafe {
|
unsafe {
|
||||||
write!(SERIAL, "{}{:x}{:x}", uid.lot_num(), uid.x(), uid.y()).unwrap();
|
write!(SERIAL, "{:X}", serial).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let usb_dev = unsafe {
|
let usb_dev = unsafe {
|
||||||
|
|
@ -145,6 +161,7 @@ mod app {
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.build()
|
.build()
|
||||||
};
|
};
|
||||||
|
|
||||||
defmt::info!("USB Setup done");
|
defmt::info!("USB Setup done");
|
||||||
|
|
||||||
// Todo: Check if internal pullups work here
|
// Todo: Check if internal pullups work here
|
||||||
|
|
@ -156,7 +173,7 @@ mod app {
|
||||||
i2c::Mode::Standard {
|
i2c::Mode::Standard {
|
||||||
frequency: 400.kHz(),
|
frequency: 400.kHz(),
|
||||||
},
|
},
|
||||||
&mut rcc,
|
&clocks,
|
||||||
);
|
);
|
||||||
|
|
||||||
defmt::info!("I2C Setup done");
|
defmt::info!("I2C Setup done");
|
||||||
|
|
@ -180,42 +197,32 @@ mod app {
|
||||||
let pico = gpioa.pa7.into_push_pull_output();
|
let pico = gpioa.pa7.into_push_pull_output();
|
||||||
let spi1 = spi::Spi::new(
|
let spi1 = spi::Spi::new(
|
||||||
cx.device.SPI1,
|
cx.device.SPI1,
|
||||||
(Some(sck), Some(poci), Some(pico)),
|
(sck, poci, pico),
|
||||||
spi::Mode {
|
spi::Mode {
|
||||||
polarity: spi::Polarity::IdleLow,
|
polarity: spi::Polarity::IdleLow,
|
||||||
phase: spi::Phase::CaptureOnSecondTransition,
|
phase: spi::Phase::CaptureOnFirstTransition,
|
||||||
},
|
},
|
||||||
8.MHz(),
|
8.MHz(),
|
||||||
&mut rcc,
|
&clocks,
|
||||||
);
|
);
|
||||||
|
|
||||||
defmt::info!("SPI Setup done");
|
defmt::info!("SPI Setup done");
|
||||||
|
|
||||||
let mut az_enable = gpiob.pb8.into_push_pull_output();
|
let az_enable = gpioa.pa10.into_push_pull_output();
|
||||||
az_enable.set_high();
|
|
||||||
let az_dir = gpioa.pa15.into_push_pull_output();
|
let az_dir = gpioa.pa15.into_push_pull_output();
|
||||||
let az_step = gpiob.pb3.into_push_pull_output();
|
let az_step = gpiob.pb3.into_push_pull_output();
|
||||||
|
|
||||||
let mut el_enable = gpiob.pb4.into_push_pull_output();
|
let el_enable = gpiob.pb4.into_push_pull_output();
|
||||||
el_enable.set_high();
|
|
||||||
let el_dir = gpioa.pa8.into_push_pull_output();
|
let el_dir = gpioa.pa8.into_push_pull_output();
|
||||||
let el_step = gpioa.pa9.into_push_pull_output();
|
let el_step = gpioa.pa9.into_push_pull_output();
|
||||||
|
|
||||||
defmt::info!("Motor Setup done");
|
defmt::info!("Motor Setup done");
|
||||||
|
|
||||||
poll_i2c::spawn().ok();
|
//poll_i2c::spawn().ok();
|
||||||
poll_spi::spawn().ok();
|
//poll_spi::spawn().ok();
|
||||||
move_az::spawn().ok();
|
|
||||||
move_el::spawn().ok();
|
|
||||||
|
|
||||||
(
|
(
|
||||||
Shared {
|
Shared { az_angle: 0 },
|
||||||
az_angle: 0,
|
|
||||||
az_target: 0,
|
|
||||||
el_angle: 0,
|
|
||||||
el_target: 0,
|
|
||||||
az_compass: 0,
|
|
||||||
},
|
|
||||||
Local {
|
Local {
|
||||||
i2cmux,
|
i2cmux,
|
||||||
board_led,
|
board_led,
|
||||||
|
|
@ -240,8 +247,8 @@ mod app {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(local = [i2cmux, board_led], shared = [az_compass])]
|
#[task(local = [i2cmux, board_led])]
|
||||||
async fn poll_i2c(mut cx: poll_i2c::Context) {
|
async fn poll_i2c(cx: poll_i2c::Context) {
|
||||||
let i2cmux = cx.local.i2cmux;
|
let i2cmux = cx.local.i2cmux;
|
||||||
let board_led = cx.local.board_led;
|
let board_led = cx.local.board_led;
|
||||||
|
|
||||||
|
|
@ -273,11 +280,6 @@ mod app {
|
||||||
heading -= 2.0 * f32::PI();
|
heading -= 2.0 * f32::PI();
|
||||||
}
|
}
|
||||||
let heading_degrees = heading * 180.0 / f32::PI();
|
let heading_degrees = heading * 180.0 / f32::PI();
|
||||||
|
|
||||||
cx.shared.az_compass.lock(|az_compass| {
|
|
||||||
*az_compass = heading_degrees as i32 * 10;
|
|
||||||
});
|
|
||||||
|
|
||||||
defmt::info!("Heading1 {}", heading_degrees);
|
defmt::info!("Heading1 {}", heading_degrees);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -319,18 +321,16 @@ mod app {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(local = [spi1, encoder_az, encoder_el, spi_cs2, spi_cs3], shared = [az_angle, el_angle])]
|
#[task(local = [spi1, encoder_az, encoder_el, spi_cs2, spi_cs3], shared = [az_angle])]
|
||||||
async fn poll_spi(mut cx: poll_spi::Context) {
|
async fn poll_spi(mut cx: poll_spi::Context) {
|
||||||
let spi1 = cx.local.spi1;
|
let spi1 = cx.local.spi1;
|
||||||
let encoder_az = cx.local.encoder_az;
|
let encoder_az = cx.local.encoder_az;
|
||||||
let encoder_el = cx.local.encoder_el;
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
/*
|
|
||||||
let (diag, gain) = encoder_az.diag_gain(spi1).unwrap();
|
let (diag, gain) = encoder_az.diag_gain(spi1).unwrap();
|
||||||
defmt::info!("diag: {:08b} gain: {}", diag, gain);
|
defmt::info!("diag: {:08b} gain: {}", diag, gain);
|
||||||
defmt::info!("magnitude: {:?}", encoder_az.magnitude(spi1).unwrap());
|
defmt::info!("magnitude: {:?}", encoder_az.magnitude(spi1).unwrap());
|
||||||
*/
|
|
||||||
let raw_angle = encoder_az.angle(spi1).unwrap();
|
let raw_angle = encoder_az.angle(spi1).unwrap();
|
||||||
let angle_deg = raw_angle as i32 * 3600 / 16384;
|
let angle_deg = raw_angle as i32 * 3600 / 16384;
|
||||||
|
|
||||||
|
|
@ -338,113 +338,45 @@ mod app {
|
||||||
*az_angle = angle_deg;
|
*az_angle = angle_deg;
|
||||||
});
|
});
|
||||||
|
|
||||||
defmt::info!("az angle: {:?}", angle_deg);
|
defmt::info!("angle: {:?}", angle_deg);
|
||||||
|
|
||||||
let raw_angle = encoder_el.angle(spi1).unwrap();
|
Mono::delay(50.millis()).await;
|
||||||
let angle_deg = raw_angle as i32 * 3600 / 16384;
|
|
||||||
|
|
||||||
cx.shared.el_angle.lock(|el_angle| {
|
|
||||||
*el_angle = angle_deg;
|
|
||||||
});
|
|
||||||
|
|
||||||
defmt::info!("el angle: {:?}", angle_deg);
|
|
||||||
|
|
||||||
Mono::delay(1.millis()).await;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(local = [az_enable, az_dir, az_step], shared = [az_angle, az_target])]
|
#[task(local = [az_enable, az_dir, az_step], shared = [az_angle])]
|
||||||
async fn move_az(mut cx: move_az::Context) {
|
async fn move_az(mut cx: move_az::Context) {
|
||||||
let az_enable = cx.local.az_enable;
|
let az_enable = cx.local.az_enable;
|
||||||
let az_dir = cx.local.az_dir;
|
let az_dir = cx.local.az_dir;
|
||||||
let az_step = cx.local.az_step;
|
let az_step = cx.local.az_step;
|
||||||
|
|
||||||
|
let az_target = 42i32;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let az_target = cx.shared.az_target.lock(|az_target| *az_target);
|
|
||||||
let az_angle = cx.shared.az_angle.lock(|az_angle| *az_angle);
|
let az_angle = cx.shared.az_angle.lock(|az_angle| *az_angle);
|
||||||
let diff = az_angle - az_target;
|
let diff = az_angle - az_target;
|
||||||
|
if diff.abs() > 2 {
|
||||||
|
az_enable.set_high();
|
||||||
|
|
||||||
defmt::info!(
|
if diff > 0 {
|
||||||
"angle diff/target/actual: {:?}/{:?}/{:?}",
|
|
||||||
diff,
|
|
||||||
az_target,
|
|
||||||
az_angle
|
|
||||||
);
|
|
||||||
|
|
||||||
let delay = if diff.abs() < 10 {
|
|
||||||
10.millis()
|
|
||||||
} else if diff < 100 {
|
|
||||||
5.millis()
|
|
||||||
} else {
|
|
||||||
1.millis()
|
|
||||||
};
|
|
||||||
|
|
||||||
if diff.abs() > 50 {
|
|
||||||
az_enable.set_low();
|
|
||||||
if diff < 0 {
|
|
||||||
az_dir.set_high();
|
az_dir.set_high();
|
||||||
} else {
|
} else {
|
||||||
az_dir.set_low();
|
az_dir.set_low();
|
||||||
}
|
}
|
||||||
|
|
||||||
az_step.set_low();
|
|
||||||
Mono::delay(delay / 2).await;
|
|
||||||
az_step.set_high();
|
az_step.set_high();
|
||||||
Mono::delay(delay / 2).await;
|
Mono::delay(250.micros()).await;
|
||||||
|
az_step.set_low();
|
||||||
|
Mono::delay(250.micros()).await;
|
||||||
} else {
|
} else {
|
||||||
az_enable.set_high();
|
az_enable.set_low();
|
||||||
Mono::delay(delay).await;
|
Mono::delay(500.micros()).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[task(local = [el_enable, el_dir, el_step], shared = [el_angle, el_target])]
|
#[task(binds=OTG_FS, local=[usb_dev, usb_serial, usb_buffer])]
|
||||||
async fn move_el(mut cx: move_el::Context) {
|
fn usb_fs(cx: usb_fs::Context) {
|
||||||
let el_enable = cx.local.el_enable;
|
|
||||||
let el_dir = cx.local.el_dir;
|
|
||||||
let el_step = cx.local.el_step;
|
|
||||||
|
|
||||||
loop {
|
|
||||||
let el_target = cx.shared.el_target.lock(|el_target| *el_target);
|
|
||||||
let el_angle = cx.shared.el_angle.lock(|el_angle| *el_angle);
|
|
||||||
let diff = el_angle - el_target;
|
|
||||||
|
|
||||||
defmt::info!(
|
|
||||||
"angle diff/target/actual: {:?}/{:?}/{:?}",
|
|
||||||
diff,
|
|
||||||
el_target,
|
|
||||||
el_angle
|
|
||||||
);
|
|
||||||
|
|
||||||
let delay = if diff.abs() < 10 {
|
|
||||||
10.millis()
|
|
||||||
} else if diff < 100 {
|
|
||||||
5.millis()
|
|
||||||
} else {
|
|
||||||
1.millis()
|
|
||||||
};
|
|
||||||
|
|
||||||
if diff.abs() > 50 {
|
|
||||||
el_enable.set_low();
|
|
||||||
if diff < 0 {
|
|
||||||
el_dir.set_high();
|
|
||||||
} else {
|
|
||||||
el_dir.set_low();
|
|
||||||
}
|
|
||||||
|
|
||||||
el_step.set_low();
|
|
||||||
Mono::delay(delay / 2).await;
|
|
||||||
el_step.set_high();
|
|
||||||
Mono::delay(delay / 2).await;
|
|
||||||
} else {
|
|
||||||
el_enable.set_high();
|
|
||||||
Mono::delay(delay).await;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[task(binds=OTG_FS, local=[usb_dev, usb_serial, usb_buffer], shared=[az_target, el_target, az_angle, el_angle])]
|
|
||||||
fn usb_fs(mut cx: usb_fs::Context) {
|
|
||||||
let usb_dev = cx.local.usb_dev;
|
let usb_dev = cx.local.usb_dev;
|
||||||
let serial = cx.local.usb_serial;
|
let serial = cx.local.usb_serial;
|
||||||
let buffer = cx.local.usb_buffer;
|
let buffer = cx.local.usb_buffer;
|
||||||
|
|
@ -477,8 +409,8 @@ mod app {
|
||||||
HostMessage::RequestStatus => {
|
HostMessage::RequestStatus => {
|
||||||
let status = StatusMessage {
|
let status = StatusMessage {
|
||||||
position: Position {
|
position: Position {
|
||||||
az: cx.shared.az_angle.lock(|az| (*az / 10) as f32),
|
az: 42.0,
|
||||||
el: cx.shared.el_angle.lock(|el| (*el / 10) as f32),
|
el: 23.0,
|
||||||
az_endcoder: 0.0,
|
az_endcoder: 0.0,
|
||||||
el_encoder: 0.0,
|
el_encoder: 0.0,
|
||||||
az_magnetic: 0.0,
|
az_magnetic: 0.0,
|
||||||
|
|
@ -491,10 +423,6 @@ mod app {
|
||||||
to_vec_cobs::<RadomMessage, USB_BUFFER_SIZE>(&device_msg).unwrap();
|
to_vec_cobs::<RadomMessage, USB_BUFFER_SIZE>(&device_msg).unwrap();
|
||||||
serial.write(bytes.as_slice()).unwrap();
|
serial.write(bytes.as_slice()).unwrap();
|
||||||
}
|
}
|
||||||
HostMessage::SetTarget(pos) => {
|
|
||||||
cx.shared.az_target.lock(|az| *az = (pos.az * 10.0) as i32);
|
|
||||||
cx.shared.el_target.lock(|el| *el = (pos.el * 10.0) as i32);
|
|
||||||
}
|
|
||||||
HostMessage::TriggerDFUBootloader => {
|
HostMessage::TriggerDFUBootloader => {
|
||||||
bootloader::reboot_to_bootloader();
|
bootloader::reboot_to_bootloader();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
memory.x
2
memory.x
|
|
@ -1,7 +1,7 @@
|
||||||
MEMORY
|
MEMORY
|
||||||
{
|
{
|
||||||
FLASH : ORIGIN = 0x08000000, LENGTH = 256K
|
FLASH : ORIGIN = 0x08000000, LENGTH = 256K
|
||||||
UNINIT : ORIGIN = 0x20000000, LENGTH = 0x10
|
UNINIT: ORIGIN = 0x20000000, LENGTH = 0x10
|
||||||
RAM : ORIGIN = 0x20000010, LENGTH = 64K - LENGTH(UNINIT)
|
RAM : ORIGIN = 0x20000010, LENGTH = 64K - LENGTH(UNINIT)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,4 +7,4 @@ edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
serde = {version = "1.0.193", default-features = false, features = ["derive"]}
|
serde = {version = "1.0.193", default-features = false, features = ["derive"]}
|
||||||
heapless = {version = "0.9.2", features = ["serde"]}
|
heapless = {version = "0.8.0", features = ["serde"]}
|
||||||
|
|
@ -11,7 +11,6 @@ pub enum RadomMessage {
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
||||||
pub enum HostMessage {
|
pub enum HostMessage {
|
||||||
RequestStatus,
|
RequestStatus,
|
||||||
SetTarget(PositionTarget),
|
|
||||||
TriggerDFUBootloader,
|
TriggerDFUBootloader,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -36,9 +35,3 @@ pub enum Alarm {
|
||||||
AZEncoderFault,
|
AZEncoderFault,
|
||||||
ELEncoderFault,
|
ELEncoderFault,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug, PartialEq)]
|
|
||||||
pub struct PositionTarget {
|
|
||||||
pub az: f32,
|
|
||||||
pub el: f32,
|
|
||||||
}
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue