Skip to content
Open
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
929 changes: 897 additions & 32 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ members = [
"apps/client-tui",
"apps/dashboard/backend",
"apps/db-logger",
"apps/flasher",
"apps/flasher", "apps/motherboard",
"apps/sensor-server",
"apps/spiview",
"lib/rust/amber-connect",
Expand Down
20 changes: 20 additions & 0 deletions apps/motherboard/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "motherboard"
version = "0.1.0"
edition = "2024"

[dependencies]
anyhow = "1.0.102"
crossterm = "0.29.0"
futures = "0.3.32"
prost = "0.14.3"
proto = { version = "0.1.0", path = "../../lib/rust/proto" }
ratatui = "0.30.0"
serde = "1.0.228"
serial = { version = "0.1.0", path = "../../lib/rust/serial" }
tokio = { version = "1.50.0", features = ["rt", "time"] }
tokio-serial = "5.4.5"
tokio-util = "0.7.18"

[lints]
workspace = true
99 changes: 99 additions & 0 deletions apps/motherboard/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
use crossterm::{
event::{self, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers},
execute,
terminal::{EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode},
};
use futures::FutureExt;
use proto::sensor::{Command, Status};
use ratatui::{
Terminal,
prelude::CrosstermBackend,
widgets::{Block, Borders, Paragraph},
};
use tokio::{
select,
sync::mpsc::{self, Receiver},
task::JoinSet,
};
use tokio_serial::UsbPortInfo;
use tokio_util::sync::CancellationToken;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
let (status_tx, status_rx) = mpsc::channel::<Status>(100);
let (_command_tx, command_rx) = mpsc::channel::<Command>(100); // Unused

let stop = CancellationToken::new();

let mut services = JoinSet::<anyhow::Result<()>>::new();
services.spawn(serial::run(command_rx, status_tx, is_base_station, stop.clone()).map(Ok));
services.spawn(printer(status_rx, stop.clone()));
services.spawn(input_handler(stop.clone()));

while services.join_next().await.is_some() {
stop.cancel();
}

services.join_all().await;

Ok(())
}

async fn input_handler(stop: CancellationToken) -> anyhow::Result<()> {
stop.run_until_cancelled(async {
loop {
let event = tokio::task::spawn_blocking(event::read).await??;
if let Event::Key(KeyEvent {
code,
modifiers,
kind: KeyEventKind::Press,
..
}) = event
{
match code {
KeyCode::Char('q') => break,
KeyCode::Char('c') if modifiers.contains(KeyModifiers::CONTROL) => break,
_ => {}
}
}
}

Ok(())
})
.await
.unwrap_or(Ok(()))
}

async fn printer(mut status_rx: Receiver<Status>, stop: CancellationToken) -> anyhow::Result<()> {
enable_raw_mode()?;
let mut stdout = std::io::stdout();
execute!(stdout, EnterAlternateScreen)?;
let backend = CrosstermBackend::new(stdout);
let mut terminal = Terminal::new(backend)?;

loop {
select! {
status = status_rx.recv() => {
let text = format!("{status:#?}");
terminal.draw(|f| {
let area = f.area();
let para = Paragraph::new(text).block(Block::default().borders(Borders::NONE));
f.render_widget(para, area);
})?;
}

() = stop.cancelled() => {
break;
}
}
}

disable_raw_mode()?;
execute!(terminal.backend_mut(), LeaveAlternateScreen)?;

Ok(())
}

fn is_base_station(info: &UsbPortInfo) -> bool {
info.manufacturer.as_deref() == Some("Amber") && info.product.as_deref() == Some("Base Station")
}
12 changes: 6 additions & 6 deletions boards/cc1101_test/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ void setup() {
cs_tx.setHigh();
cs_rx.setHigh();

cc1101::Driver transmitter(SPI, miso, cs_tx);
cc1101::Driver receiver(SPI, miso, cs_rx);
amber::cc1101::Driver transmitter(SPI, miso, cs_tx);
amber::cc1101::Driver receiver(SPI, miso, cs_rx);

transmitter.reset();
transmitter.configure(cc1101::Driver::Frequency::MHZ_915);
transmitter.begin(cc1101::Driver::Direction::TX);
transmitter.configure(amber::cc1101::Driver::Frequency::MHZ_915);
transmitter.begin(amber::cc1101::Driver::Direction::TX);

receiver.reset();
receiver.configure(cc1101::Driver::Frequency::MHZ_915);
receiver.begin(cc1101::Driver::Direction::TX);
receiver.configure(amber::cc1101::Driver::Frequency::MHZ_915);
receiver.begin(amber::cc1101::Driver::Direction::TX);
}

void loop() {
Expand Down
17 changes: 17 additions & 0 deletions boards/motherboard/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch

# PlatformIO doesn't have the U0 driver yet. Instead of tracking ~200k lines of code,
# each developer should `Generate Code` in CubeMX to get the drivers and middlewares
Drivers/
Middlewares/

# STMCubeMX dotfiles
.project
.cproject
.mxproject
.osx.project
.settings/
125 changes: 125 additions & 0 deletions boards/motherboard/Inc/FreeRTOSConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/* USER CODE BEGIN Header */
/*
* FreeRTOS Kernel V10.3.1
* Portion Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights
* Reserved. Portion Copyright (C) 2019 StMicroelectronics, Inc. All Rights
* Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* http://www.FreeRTOS.org
* http://aws.amazon.com/freertos
*
* 1 tab == 4 spaces!
*/
/* USER CODE END Header */

#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H

/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* These parameters and more are described within the 'configuration' section of
* the FreeRTOS API documentation available on the FreeRTOS.org web site.
*
* See http://www.freertos.org/a00110.html
*----------------------------------------------------------*/

/* USER CODE BEGIN Includes */
/* Section where include file can be added */
/* USER CODE END Includes */

/* Ensure definitions are only used by the compiler, and not by the assembler.
*/
#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
#include <stdint.h>
extern uint32_t SystemCoreClock;
#endif
#define configENABLE_FPU 0
#define configENABLE_MPU 0

#define configUSE_PREEMPTION 1
#define configSUPPORT_STATIC_ALLOCATION 1
#define configSUPPORT_DYNAMIC_ALLOCATION 0
#define configUSE_IDLE_HOOK 0
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ (SystemCoreClock)
#define configTICK_RATE_HZ ((TickType_t)1000)
#define configMAX_PRIORITIES (7)
#define configMINIMAL_STACK_SIZE ((uint16_t)128)
#define configMAX_TASK_NAME_LEN (16)
#define configUSE_16_BIT_TICKS 0
#define configUSE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 8
#define configUSE_PORT_OPTIMISED_TASK_SELECTION 0
/* USER CODE BEGIN MESSAGE_BUFFER_LENGTH_TYPE */
/* Defaults to size_t for backward compatibility, but can be changed
if lengths will always be less than the number of bytes in a size_t. */
#define configMESSAGE_BUFFER_LENGTH_TYPE size_t
/* USER CODE END MESSAGE_BUFFER_LENGTH_TYPE */

/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES (2)

/* The following flag must be enabled only when using newlib */
#define configUSE_NEWLIB_REENTRANT 1

/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 1
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xTaskGetSchedulerState 1

/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
/* USER CODE BEGIN 1 */
#define configASSERT(x) \
if ((x) == 0) { \
taskDISABLE_INTERRUPTS(); \
for (;;); \
}
/* USER CODE END 1 */

/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler

/* IMPORTANT: This define is commented when used with STM32Cube firmware, when
the timebase source is SysTick, to prevent overwriting SysTick_Handler
defined within STM32Cube HAL */

#define xPortSysTickHandler SysTick_Handler

/* USER CODE BEGIN Defines */
/* Section where parameter definitions can be added (for instance, to override
* default ones in FreeRTOS.h) */
/* USER CODE END Defines */

#endif /* FREERTOS_CONFIG_H */
51 changes: 51 additions & 0 deletions boards/motherboard/Inc/adc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* @file adc.h
* @brief This file contains all the function prototypes for
* the adc.c file
******************************************************************************
* @attention
*
* Copyright (c) 2026 STMicroelectronics.
* All rights reserved.
*
* This software is licensed under terms that can be found in the LICENSE file
* in the root directory of this software component.
* If no LICENSE file comes with this software, it is provided AS-IS.
*
******************************************************************************
*/
/* USER CODE END Header */
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __ADC_H__
#define __ADC_H__

#ifdef __cplusplus
extern "C" {
#endif

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

extern ADC_HandleTypeDef hadc1;

/* USER CODE BEGIN Private defines */

/* USER CODE END Private defines */

void MX_ADC1_Init(void);

/* USER CODE BEGIN Prototypes */

/* USER CODE END Prototypes */

#ifdef __cplusplus
}
#endif

#endif /* __ADC_H__ */
Loading