Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions firmware/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions firmware/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ heapless = "0.9.1"
static_cell = "2.1"
portable-atomic = { version = "1.5", features = ["critical-section"] }

sha2 = { version = "0.10", default-features = false }
base64 = { version = "0.22.1", default-features = false }
hexa-tune-proto = { path = "../../hexaTuneProto/crates/hexa-tune-proto", default-features = false }
hexa-tune-proto-embedded = { path = "../../hexaTuneProto/crates/hexa-tune-proto-embedded", default-features = false, features = ["defmt"] }

[profile.release]
# Enable generation of debug symbols even on release builds
Expand Down
86 changes: 72 additions & 14 deletions firmware/src/at/at_task.rs
Original file line number Diff line number Diff line change
@@ -1,53 +1,52 @@
// SPDX-FileCopyrightText: 2025 hexaTune LLC
// SPDX-License-Identifier: MIT

use cortex_m::peripheral::SCB;
use defmt::{error, info};
use embassy_executor::Spawner;
use heapless::String;
use {defmt_rtt as _, panic_probe as _};

use hexa_tune_proto_embedded::command::HexaCommand;
use hexa_tune_proto_embedded::HexaError;

use crate::AT_CH;
use crate::USB_CH;
use crate::at::*;
use crate::channel::*;
use crate::error::FirmwareError;
use crate::hexa_config::*;

#[embassy_executor::task]
pub async fn at_task(dispatcher: &'static AtDispatcher, spawner: Spawner) {
pub async fn at_task(spawner: Spawner) {
info!("Starting AT task");
let mut last_operation_status: String<64> = String::new();
loop {
match AT_CH.receive().await {
Msg::AtRxLine(line) => {
if let Some(e) = dispatcher.dispatch(spawner, &line) {
let compiled = compile_at_error(get_empty_id(), e);
if let Err((id, e)) = dispatch_and_spawn(spawner, line.as_bytes()) {
let compiled = encode_error_response(id, &e);
error!("Dispatch error: {:?}", compiled.as_str());
USB_CH.send(Msg::UsbTxLine(compiled)).await;
}
}
Msg::AtCmdOutput(at_command) => {
let compiled = at_command.compile();
info!("Sending output: {}", compiled.as_str());
USB_CH.send(Msg::UsbTxLine(compiled)).await;
Msg::AtCmdResponse(line) => {
info!("Sending response: {}", line.as_str());
USB_CH.send(Msg::UsbTxLine(line)).await;
}
Msg::Done(msg_id) => {
let compiled = compile_at_done(msg_id);
let compiled = encode_done(msg_id);
info!("Sending done: {}", compiled.as_str());
USB_CH.send(Msg::UsbTxLine(compiled)).await;
}
Msg::Err(msg_id, e) => {
let compiled = compile_at_error(msg_id, e);
let compiled = encode_error_response(msg_id, &e);
error!("Sending error: {}", compiled.as_str());
USB_CH.send(Msg::UsbTxLine(compiled)).await;
}
Msg::SetDdsAvailable(status) => {
set_dds_available(status);
}
Msg::Completed(at_command) => {
let compiled = compile_at_completed(at_command);
info!("Sending done: {}", compiled.as_str());
USB_CH.send(Msg::UsbTxLine(compiled)).await;
}
Msg::SetOperationStatus(status) => {
last_operation_status = status;
}
Expand All @@ -60,3 +59,62 @@ pub async fn at_task(dispatcher: &'static AtDispatcher, spawner: Spawner) {
}
}
}

fn dispatch_and_spawn(spawner: Spawner, payload: &[u8]) -> Result<(), (u32, FirmwareError)> {
let cmd = dispatch_at_payload(payload).map_err(|e| (0u32, e))?;
let id = command_id(&cmd);

match cmd {
HexaCommand::VersionQuery => {
info!("Dispatching VERSION query");
spawner.spawn(version_task()).ok();
}
HexaCommand::SetRgb { id, r, g, b } => {
info!("Dispatching SETRGB command");
spawner.spawn(setrgb_task(id, r, g, b)).ok();
}
HexaCommand::Reset { .. } => {
info!("Dispatching RESET command");
SCB::sys_reset();
}
HexaCommand::FwUpdate { .. } => {
info!("Dispatching FWUPDATE command");
spawner.spawn(fwupdate_task()).ok();
}
HexaCommand::Freq { id, freq, time_ms } => {
if !is_dds_available() {
error!("DDS busy, cannot set FREQ");
return Err((id, FirmwareError::Hexa(HexaError::DdsBusy)));
}
info!("Dispatching FREQ command");
spawner.spawn(freq_task(id, freq, time_ms)).ok();
}
HexaCommand::Operation { id, sub } => {
if !is_dds_available() {
error!("DDS busy, cannot set OPERATION");
return Err((id, FirmwareError::Hexa(HexaError::DdsBusy)));
}
info!("Dispatching OPERATION command");
spawner.spawn(operation_task(id, sub)).ok();
}
HexaCommand::OperationQuery => {
info!("Dispatching OPERATION query");
spawner.spawn(operation_status_task()).ok();
}
_ => {
return Err((id, FirmwareError::Hexa(HexaError::UnknownCommand)));
}
}
Ok(())
}

fn command_id(cmd: &HexaCommand) -> u32 {
match cmd {
HexaCommand::SetRgb { id, .. }
| HexaCommand::Reset { id }
| HexaCommand::FwUpdate { id }
| HexaCommand::Freq { id, .. }
| HexaCommand::Operation { id, .. } => *id,
_ => 0,
}
}
162 changes: 0 additions & 162 deletions firmware/src/at/command.rs

This file was deleted.

Loading
Loading