diff --git a/actors/src/button.rs b/actors/src/button.rs index 0ac191068..fc3049456 100644 --- a/actors/src/button.rs +++ b/actors/src/button.rs @@ -2,6 +2,7 @@ use core::future::Future; use core::pin::Pin; use drogue_device_kernel::{ actor::{Actor, Address}, + channel::consts, util::ImmediateFuture, }; use embassy_traits::gpio::WaitForAnyEdge; @@ -43,6 +44,7 @@ impl<'a, P: WaitForAnyEdge + InputPin + 'a, A: Actor + FromButtonEvent> + 'a> Actor for Button<'a, P, A> { + type QueueLength<'m> where 'a: 'm = consts::U0; type Configuration = Address<'a, A>; #[rustfmt::skip] type Message<'m> where 'a: 'm = (); diff --git a/kernel/src/actor.rs b/kernel/src/actor.rs index 78a74034e..ab1825fb6 100644 --- a/kernel/src/actor.rs +++ b/kernel/src/actor.rs @@ -1,4 +1,4 @@ -use crate::channel::{consts, Channel, ChannelSend}; +use crate::channel::{consts, ArrayLength, Channel, ChannelSend}; use crate::signal::{SignalFuture, SignalSlot}; use core::cell::UnsafeCell; use core::future::Future; @@ -7,7 +7,11 @@ use core::task::{Context, Poll}; use embassy::util::DropBomb; /// Trait that each actor must implement. -pub trait Actor { +pub trait Actor: Sized { + /// Queue size; + #[rustfmt::skip] + type QueueLength<'a>: ArrayLength> + ArrayLength + 'a where Self: 'a = consts::U1; + /// The configuration that this actor will expect when mounted. type Configuration; @@ -100,13 +104,13 @@ impl<'a, A: Actor> Clone for Address<'a, A> { pub struct ActorState<'a, A: Actor> { pub actor: UnsafeCell, - pub channel: Channel<'a, ActorMessage<'a, A>, consts::U4>, + pub channel: Channel<'a, ActorMessage<'a, A>, A::QueueLength<'a>>, signals: UnsafeCell<[SignalSlot; 4]>, } impl<'a, A: Actor> ActorState<'a, A> { pub fn new(actor: A) -> Self { - let channel: Channel<'a, ActorMessage, consts::U4> = Channel::new(); + let channel: Channel<'a, ActorMessage, A::QueueLength<'a>> = Channel::new(); Self { actor: UnsafeCell::new(actor), channel, @@ -176,7 +180,7 @@ enum SendState { } pub struct SendFuture<'a, 'm, A: Actor + 'a> { - channel: ChannelSend<'a, ActorMessage<'a, A>, consts::U4>, + channel: ChannelSend<'a, ActorMessage<'a, A>, A::QueueLength<'a>>, signal: SignalFuture<'a, 'm>, state: SendState, bomb: Option, @@ -184,7 +188,7 @@ pub struct SendFuture<'a, 'm, A: Actor + 'a> { impl<'a, 'm, A: Actor> SendFuture<'a, 'm, A> { pub fn new( - channel: ChannelSend<'a, ActorMessage<'a, A>, consts::U4>, + channel: ChannelSend<'a, ActorMessage<'a, A>, A::QueueLength<'a>>, signal: SignalFuture<'a, 'm>, ) -> Self { Self { diff --git a/kernel/src/lib.rs b/kernel/src/lib.rs index 0795052b9..12bdab034 100644 --- a/kernel/src/lib.rs +++ b/kernel/src/lib.rs @@ -4,6 +4,7 @@ #![feature(min_type_alias_impl_trait)] #![feature(impl_trait_in_bindings)] #![feature(generic_associated_types)] +#![feature(associated_type_defaults)] #![feature(type_alias_impl_trait)] pub(crate) mod fmt;