55// Generates Morse code audio signals for text from UART, playing back over I2S
66// Tested with nRF52840-DK and a UDA1334a DAC
77
8- use aligned:: { Aligned , A4 } ;
98use embedded_hal:: digital:: v2:: { InputPin , OutputPin } ;
109use heapless:: {
1110 consts:: * ,
3029 rtt_target:: { rprintln, rtt_init_print} ,
3130} ;
3231
32+ #[ repr( align( 4 ) ) ]
33+ struct Aligned < T : ?Sized > ( T ) ;
34+
3335#[ rtic:: app( device = crate :: hal:: pac, peripherals = true , monotonic = rtic:: cyccnt:: CYCCNT ) ]
3436const APP : ( ) = {
3537 struct Resources {
@@ -53,14 +55,14 @@ const APP: () = {
5355 #[ init( resources = [ queue] , spawn = [ tick] ) ]
5456 fn init ( mut ctx : init:: Context ) -> init:: LateResources {
5557 // The I2S buffer address must be 4 byte aligned.
56- static mut MUTE_BUF : Aligned < A4 , [ i16 ; 32 ] > = Aligned ( [ 0i16 ; 32 ] ) ;
57- static mut SIGNAL_BUF : Aligned < A4 , [ i16 ; 32 ] > = Aligned ( [ 0i16 ; 32 ] ) ;
58+ static mut MUTE_BUF : Aligned < [ i16 ; 32 ] > = Aligned ( [ 0i16 ; 32 ] ) ;
59+ static mut SIGNAL_BUF : Aligned < [ i16 ; 32 ] > = Aligned ( [ 0i16 ; 32 ] ) ;
5860
5961 // Fill signal buffer with triangle waveform, 2 channels interleaved
60- let len = SIGNAL_BUF . len ( ) / 2 ;
62+ let len = SIGNAL_BUF . 0 . len ( ) / 2 ;
6163 for x in 0 ..len {
62- SIGNAL_BUF [ 2 * x] = triangle_wave ( x as i32 , len, 2048 , 0 , 1 ) as i16 ;
63- SIGNAL_BUF [ 2 * x + 1 ] = triangle_wave ( x as i32 , len, 2048 , 0 , 1 ) as i16 ;
64+ SIGNAL_BUF . 0 [ 2 * x] = triangle_wave ( x as i32 , len, 2048 , 0 , 1 ) as i16 ;
65+ SIGNAL_BUF . 0 [ 2 * x + 1 ] = triangle_wave ( x as i32 , len, 2048 , 0 , 1 ) as i16 ;
6466 }
6567
6668 let _clocks = hal:: clocks:: Clocks :: new ( ctx. device . CLOCK ) . enable_ext_hfosc ( ) ;
@@ -126,9 +128,9 @@ const APP: () = {
126128 led : p0. p0_13 . into_push_pull_output ( Level :: High ) . degrade ( ) ,
127129 uarte,
128130 uarte_timer : Timer :: new ( ctx. device . TIMER0 ) ,
129- transfer : i2s. tx ( & * * MUTE_BUF ) . ok ( ) ,
130- signal_buf : & * * SIGNAL_BUF ,
131- mute_buf : & * * MUTE_BUF ,
131+ transfer : i2s. tx ( & MUTE_BUF . 0 ) . ok ( ) ,
132+ signal_buf : & SIGNAL_BUF . 0 ,
133+ mute_buf : & MUTE_BUF . 0 ,
132134 }
133135 }
134136
0 commit comments