refactor: move firmware workspace under firmware

This commit is contained in:
Onur Özkan committed 2026-08-10 16:58:55 +03:00
1 parent 153b0bf262
commit f03fc119a4
222 files changed
+56 -13

No files matched your search

+101
View File
@@ -0,0 +1,101 @@
//! Finite STM32F722 execution profiles.
//!
//! This module is the sole owner of STM32F722 register routes and execution
//! lifecycle. Its public-in-crate profile names describe useful electrical
//! meaning; the RTIC bindings, PAC names, DMA streams and synchronization are
//! intentionally contained here and in the macro template.
mod board;
mod clock;
mod data_channel;
mod firmware;
mod interrupts;
mod motor_inhibit;
mod peripherals;
mod routes;
mod sensors;
use crate::{BoardError, F722BoardRoutes};
use kaptan_board::BoardConfig;
/// Completion classification crossing the RTIC interrupt template.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum F722ImuTransferCompletion {
Complete,
TransferFault,
NotPending,
}
impl From<kaptan_spi::SpiCompletion> for F722ImuTransferCompletion {
fn from(value: kaptan_spi::SpiCompletion) -> Self {
match value {
kaptan_spi::SpiCompletion::Complete => Self::Complete,
kaptan_spi::SpiCompletion::TransferFault => Self::TransferFault,
kaptan_spi::SpiCompletion::NotPending => Self::NotPending,
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum VerticalRoute {
None,
Mtf01,
LidarLiteV3,
}
pub(crate) use board::{
F722InitResources, F722LidarState, F722MavlinkState, F722Mtf01, F722Mtf01Uart,
F722ServiceTimer, on_uart4_interrupt, process_imu, record_mavlink_completion,
validate_board_routes,
};
pub(crate) use interrupts::{
acknowledge_exti3, acknowledge_exti4, acknowledge_imu_rx_dma1, acknowledge_imu_rx_dma2,
acknowledge_imu_spi1_error, acknowledge_imu_spi3_error, acknowledge_imu_tx_dma1,
acknowledge_imu_tx_dma2, acknowledge_mavlink_dma1, acknowledge_mavlink_dma2,
acknowledge_mavlink_rx_usart1, acknowledge_mavlink_rx_usart2,
};
pub(crate) use sensors::F722Imu;
/// Materializes a board declaration after RTIC has exclusively taken the PAC
/// peripherals. The route/config check happens before any pin or peripheral
/// is initialized, so a malformed board declaration cannot drive hardware.
pub fn initialize(
core: cortex_m::Peripherals,
device: stm32f7::stm32f722::Peripherals,
config: BoardConfig,
routes: F722BoardRoutes,
) -> Result<F722InitResources, BoardError> {
// This is deliberately the first hardware access, before configuration
// validation, clocks, sensor routes, interrupts, or UART setup. It keeps
// the former four motor pins low even for malformed configuration.
motor_inhibit::inhibit_motor_pins(&device.RCC, &device.GPIOB);
crate::validate_board_config(config, routes)?;
board::initialize(core, device, config, routes)
}
unsafe extern "Rust" {
static KAPTAN_F722_BOARD_CONFIG: BoardConfig;
fn kaptan_f722_board_routes() -> Result<F722BoardRoutes, BoardError>;
}
fn registered_config() -> BoardConfig {
// SAFETY: `flight_firmware!` emits this immutable symbol exactly once in
// the selected board binary. The platform reads it only during RTIC init,
// before any interrupt or worker can observe configuration state.
unsafe { KAPTAN_F722_BOARD_CONFIG }
}
fn registered_routes() -> Result<F722BoardRoutes, BoardError> {
// SAFETY: `flight_firmware!` emits this function exactly once in the board
// binary. It only constructs a safe descriptor; it cannot touch PAC state
// because the board builder contains no peripherals.
unsafe { kaptan_f722_board_routes() }
}
// This is one source-level task graph. Its compile-time bindings are the
// platform-owned finite interrupt superset, independent of the board crate.
#[cfg(target_os = "none")]
firmware::f722_flight_application!(
crate::f722::registered_routes,
crate::f722::registered_config
);