#![no_std]
#![no_main]
use core::panic::PanicInfo;
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}
#[no_mangle]
pub extern "C" fn main() -> ! {
example_fir_filter();
example_stack_arrays();
example_fixed_point_math();
loop {
}
}
fn example_fir_filter() {
use scirs2_core::fixed_point::{Fixed32, signal::FirFilter};
let coeffs = [
Fixed32::<16>::from_float(0.054),
Fixed32::<16>::from_float(0.244),
Fixed32::<16>::from_float(0.402),
Fixed32::<16>::from_float(0.244),
Fixed32::<16>::from_float(0.054),
];
let mut filter = FirFilter::new(&coeffs);
let samples = [
Fixed32::<16>::from_float(0.5),
Fixed32::<16>::from_float(0.8),
Fixed32::<16>::from_float(1.0),
Fixed32::<16>::from_float(0.8),
Fixed32::<16>::from_float(0.5),
];
for sample in &samples {
let filtered = filter.process(*sample);
let _ = filtered.to_float(); }
}
fn example_stack_arrays() {
use scirs2_core::embedded::{StackArray, stack_add, stack_mean};
let mut sensor_data = StackArray::<f32, 16>::new();
let mut baseline = StackArray::<f32, 16>::new();
for i in 0..16 {
sensor_data[i] = i as f32 * 0.1;
baseline[i] = 0.5;
}
let calibrated = stack_add(&sensor_data, &baseline);
let average = stack_mean(&calibrated);
let threshold = 5.0;
let _ = average > threshold;
}
fn example_fixed_point_math() {
use scirs2_core::fixed_point::{Fixed32, math};
let pitch = Fixed32::<16>::from_float(0.1); let roll = Fixed32::<16>::from_float(0.2);
let sin_pitch = math::sin(pitch);
let cos_pitch = math::cos(pitch);
let sin_roll = math::sin(roll);
let cos_roll = math::cos(roll);
let r11 = cos_pitch * cos_roll;
let r12 = sin_pitch;
let _ = r11.to_float();
let _ = r12.to_float();
}
fn example_circular_buffer() {
use scirs2_core::embedded::FixedSizeBuffer;
let mut buffer = FixedSizeBuffer::<i16, 32>::new();
for _ in 0..100 {
let adc_value: i16 = 2048;
if buffer.is_full() {
let _ = buffer.pop(); }
let _ = buffer.push(adc_value);
if buffer.is_full() {
process_buffer(&buffer);
buffer.clear();
}
}
}
fn process_buffer<const N: usize>(_buffer: &scirs2_core::embedded::FixedSizeBuffer<i16, N>) {
}
fn estimate_memory_usage() {
use scirs2_core::embedded::memory_estimation::{MemoryRequirement, estimate_stack_usage};
let fir_stack = estimate_stack_usage::<f32>(64); assert!(fir_stack == 256);
let req = MemoryRequirement::signal_processing();
assert!(req.stack_bytes >= 4096);
assert!(req.heap_bytes == 0); }
#[cfg(target_arch = "arm")]
mod platform {
#[cfg(target_feature = "thumb-mode")]
pub const MAX_FILTER_SIZE: usize = 32;
#[cfg(target_feature = "fp")]
pub const MAX_FILTER_SIZE: usize = 128;
#[cfg(all(target_feature = "fp", target_feature = "d32"))]
pub const MAX_FILTER_SIZE: usize = 256;
}
#[cfg(not(target_arch = "arm"))]
mod platform {
pub const MAX_FILTER_SIZE: usize = 64;
}