@@ -161,35 +161,56 @@ static void TLV320_I2S_Poll(void)
161161 }
162162}
163163
164+ static uint8_t s_i2s_bitslip_check = 1U ;
165+ static uint8_t s_i2s_bitslip_false_checks_in_a_row = 0U ;
166+ static uint8_t s_i2s_bitslip_sync_displayed_count = UINT8_MAX ;
167+
164168static void TLV320_I2S_CheckBitslip (void )
165169{
166- static uint8_t enabled = 1U ;
167- static uint8_t false_checks_in_a_row = 0U ;
168170
169- if (enabled == 0U )
171+ if (s_i2s_bitslip_check == 0U )
170172 {
171173 return ;
172174 }
173175
174176 if (i2s_needs_reset ())
175177 {
176- false_checks_in_a_row = 0U ;
178+ s_i2s_bitslip_false_checks_in_a_row = 0U ;
177179 printf (" bitslipped, resetting\n " );
178180 i2s_hw_enable (DISABLE );
179181 i2s_hw_deinit ();
180182 Delay_Ms (10 );
181183 i2s_hw_init ();
182184 i2s_hw_enable (ENABLE );
183185 s_tlv320_i2s_report_initialized = 0U ;
184- enabled = 1U ;
186+ s_i2s_bitslip_check = 1U ;
185187 return ;
186188 }
187189
188- ++false_checks_in_a_row;
189- if (false_checks_in_a_row >= 20U )
190+ ++s_i2s_bitslip_false_checks_in_a_row;
191+ if (s_i2s_bitslip_false_checks_in_a_row >= 20U )
192+ {
193+ s_i2s_bitslip_check = 0U ;
194+ }
195+ }
196+
197+ static void Draw_I2S_Sync_Status (void )
198+ {
199+ char sync_text[24 ];
200+
201+ if (s_i2s_bitslip_sync_displayed_count == s_i2s_bitslip_false_checks_in_a_row)
190202 {
191- enabled = 0U ;
203+ return ;
192204 }
205+
206+ s_i2s_bitslip_sync_displayed_count = s_i2s_bitslip_false_checks_in_a_row;
207+ snprintf (sync_text, sizeof (sync_text),
208+ " Synced: %u/20" ,
209+ (unsigned int )s_i2s_bitslip_false_checks_in_a_row);
210+
211+ ST7789_Fill (0U , 0U , ST7789_WIDTH - 1U , 49U , BLACK );
212+ ST7789_WriteString (0U , 5U , " Initializing..." , Font_11x18, WHITE , BLACK );
213+ ST7789_WriteString (0U , 27U , sync_text, Font_11x18, WHITE , BLACK );
193214}
194215
195216static uint64_t ticks_from_ms (uint32_t ms)
@@ -256,8 +277,6 @@ int main(void)
256277 printf (" FM audio out: enabled (fixed-point FM demod to DAC)\r\n " );
257278
258279 blinky_init ();
259- UI_FFT_Init ();
260- UI_Init ();
261280
262281 // watchdog_init();
263282
@@ -267,6 +286,16 @@ int main(void)
267286 PeriodicTrigger SysTickReportUSB{1000U , SysTick_Report_USB_EverySecond};
268287 PeriodicTrigger FFTDraw{1000U / 60U , UI_FFT_Draw};
269288
289+ while (s_i2s_bitslip_check)
290+ {
291+ Draw_I2S_Sync_Status ();
292+ I2SBitslipCheck ();
293+ tud_task ();
294+ }
295+
296+ UI_FFT_Init ();
297+ UI_Init ();
298+
270299 while (1 )
271300 {
272301 I2SBitslipCheck ();
0 commit comments