buzzer without pwm, and feedback with embassy Sync. Error when more then 4 tasks spawn

This commit is contained in:
Philipp_EndevourOS
2025-08-01 16:42:14 +02:00
parent fe6540ca3d
commit 5950279dc4
7 changed files with 214 additions and 123 deletions

View File

@@ -3,68 +3,82 @@
#![feature(type_alias_impl_trait)]
#![feature(impl_trait_in_assoc_type)]
use esp_alloc::EspHeap;
use embassy_executor::Spawner;
use embassy_net::Stack;
use embassy_sync::{
blocking_mutex::raw::{CriticalSectionRawMutex, NoopRawMutex}, mutex::Mutex, pubsub::{
blocking_mutex::raw::{NoopRawMutex, CriticalSectionRawMutex},
pubsub::{
PubSubChannel, Publisher,
WaitResult::{Lagged, Message},
}
},
signal::Signal,
};
use embassy_time::{Duration, Timer};
use esp_alloc::psram_allocator;
use esp_hal::{gpio::Output, i2c, peripherals, Async};
use esp_hal::uart::Uart;
use log::{debug, info};
use static_cell::make_static;
use crate::{store::TallyID, webserver::start_webserver};
include!(concat!(env!("OUT_DIR"), "/build_time.rs"));
mod init;
mod drivers;
mod feedback;
mod store;
mod webserver;
mod feedback;
include!(concat!(env!("OUT_DIR"), "/build_time.rs"));
static UTC_TIME: Signal<CriticalSectionRawMutex, u64> = Signal::new();
static FEEDBACK_STATE: Signal<CriticalSectionRawMutex, feedback::FeedbackState> = Signal::new();
type TallyChannel = PubSubChannel<NoopRawMutex, TallyID, 8, 2, 1>;
type TallyPublisher = Publisher<'static, NoopRawMutex, TallyID, 8, 2, 1>;
static UTC_TIME: Mutex<CriticalSectionRawMutex, u64> = Mutex::new(0);
#[esp_hal_embassy::main]
async fn main(mut spawner: Spawner) {
{
let mut utc_time = UTC_TIME.lock().await;
*utc_time = BUILD_UNIX_TIME;
info!("UTC Time initialized to: {}", *utc_time);
}
let (uart_device, stack, _i2c, sqw_pin, buzzer_gpio) = init::hardware::hardware_init(&mut spawner).await;
let (uart_device, stack, _i2c, sqw_pin, buzzer_gpio) =
init::hardware::hardware_init(&mut spawner).await;
wait_for_stack_up(stack).await;
info!("Starting up...");
let chan: &'static mut TallyChannel = make_static!(PubSubChannel::new());
start_webserver(&mut spawner, stack);
//start_webserver(&mut spawner, stack);
let publisher = chan.publisher().unwrap();
debug!("spawing NFC reader task");
spawner.must_spawn(drivers::nfc_reader::rfid_reader_task(uart_device, publisher));
//debug!("spawing rtc task");
//spawner.must_spawn(rtc_task(_i2c, sqw_pin));
debug!("spawing feedback task");
spawner.must_spawn(drivers::buzzer::feedback_task(buzzer_gpio));
/****************************** Spawning tasks ***********************************/
debug!("spawing NFC reader task...");
spawner.must_spawn(drivers::nfc_reader::rfid_reader_task(
uart_device,
publisher,
));
debug!("spawing rtc task");
spawner.must_spawn(drivers::rtc::rtc_task());
debug!("spawing feedback task..");
spawner.must_spawn(feedback::feedback_task(buzzer_gpio));
/******************************************************************************/
let mut sub = chan.subscriber().unwrap();
debug!("everythig spwawned");
FEEDBACK_STATE.signal(feedback::FeedbackState::Startup);
loop {
let wait_result = sub.next_message().await;
match wait_result {
Lagged(_) => debug!("Lagged"),
Message(msg) => debug!("Got message: {msg:?}"),
}
info!("runnung in main loop");
Timer::after(Duration::from_millis(1000)).await;
// let wait_result = sub.next_message().await;
// match wait_result {
// Lagged(_) => debug!("Lagged"),
// Message(msg) => debug!("Got message: {msg:?}"),
// }
}
}
@@ -79,4 +93,4 @@ async fn wait_for_stack_up(stack: Stack<'static>) {
}
Timer::after(Duration::from_millis(500)).await;
}
}
}