11// Licensed under the Apache-2.0 license
22
3+ use crate :: uart:: UartController ;
4+ use core:: ops:: { Index , IndexMut } ;
5+ use embedded_io:: Write ;
6+
37pub struct DummyDelay ;
48
59impl embedded_hal:: delay:: DelayNs for DummyDelay {
@@ -38,27 +42,25 @@ impl<const N: usize> DmaBuffer<N> {
3842 }
3943
4044 #[ must_use]
41- pub fn len ( & self ) -> usize {
45+ pub const fn len ( & self ) -> usize {
4246 N
4347 }
4448
4549 #[ must_use]
46- pub fn is_empty ( & self ) -> bool {
50+ pub const fn is_empty ( & self ) -> bool {
4751 N == 0
4852 }
4953
5054 #[ must_use]
51- pub fn as_slice ( & self ) -> & [ u8 ] {
52- & self . buf
55+ pub fn as_slice ( & self , start : usize , end : usize ) -> & [ u8 ] {
56+ & self . buf [ start..end ]
5357 }
5458
5559 pub fn as_mut_slice ( & mut self , start : usize , end : usize ) -> & mut [ u8 ] {
5660 & mut self . buf [ start..end]
5761 }
5862}
5963
60- use core:: ops:: { Index , IndexMut } ;
61-
6264impl < const N : usize > Index < usize > for DmaBuffer < N > {
6365 type Output = u8 ;
6466 fn index ( & self , idx : usize ) -> & Self :: Output {
@@ -71,3 +73,37 @@ impl<const N: usize> IndexMut<usize> for DmaBuffer<N> {
7173 & mut self . buf [ idx]
7274 }
7375}
76+
77+ pub trait Logger {
78+ fn debug ( & mut self , msg : & str ) ;
79+ fn error ( & mut self , msg : & str ) ;
80+ }
81+
82+ // No-op implementation for production builds
83+ pub struct NoOpLogger ;
84+ impl Logger for NoOpLogger {
85+ fn debug ( & mut self , _msg : & str ) { }
86+ fn error ( & mut self , _msg : & str ) { }
87+ }
88+
89+ // UART logger adapter (separate concern)
90+ pub struct UartLogger < ' a > {
91+ uart : & ' a mut UartController < ' a > ,
92+ }
93+
94+ impl < ' a > UartLogger < ' a > {
95+ pub fn new ( uart : & ' a mut UartController < ' a > ) -> Self {
96+ UartLogger { uart }
97+ }
98+ }
99+
100+ impl < ' a > Logger for UartLogger < ' a > {
101+ fn debug ( & mut self , msg : & str ) {
102+ writeln ! ( self . uart, "{msg}" ) . ok ( ) ;
103+ write ! ( self . uart, "\r " ) . ok ( ) ;
104+ }
105+ fn error ( & mut self , msg : & str ) {
106+ writeln ! ( self . uart, "ERROR: {msg}" ) . ok ( ) ;
107+ write ! ( self . uart, "\r " ) . ok ( ) ;
108+ }
109+ }
0 commit comments