@@ -196,7 +196,7 @@ static bool camera_suite_view_camera_input(InputEvent* event, void* context) {
196196 UNUSED (model );
197197
198198 // Stop camera stream.
199- furi_hal_uart_tx ( FuriHalUartIdUSART1 , (uint8_t []){'s' }, 1 );
199+ furi_hal_serial_tx ( instance -> serial_handle , (uint8_t []){'s' }, 1 );
200200 furi_delay_ms (50 );
201201
202202 // Go back to the main menu.
@@ -217,13 +217,13 @@ static bool camera_suite_view_camera_input(InputEvent* event, void* context) {
217217
218218 if (model -> is_inverted ) {
219219 // Camera: Set invert to false on the ESP32-CAM.
220- furi_hal_uart_tx ( FuriHalUartIdUSART1 , (uint8_t []){'i' }, 1 );
220+ furi_hal_serial_tx ( instance -> serial_handle , (uint8_t []){'i' }, 1 );
221221 furi_delay_ms (50 );
222222
223223 model -> is_inverted = false;
224224 } else {
225225 // Camera: Set invert to true on the ESP32-CAM.
226- furi_hal_uart_tx ( FuriHalUartIdUSART1 , (uint8_t []){'I' }, 1 );
226+ furi_hal_serial_tx ( instance -> serial_handle , (uint8_t []){'I' }, 1 );
227227 furi_delay_ms (50 );
228228
229229 model -> is_inverted = true;
@@ -246,13 +246,13 @@ static bool camera_suite_view_camera_input(InputEvent* event, void* context) {
246246
247247 if (model -> is_dithering_enabled ) {
248248 // Camera: Disable dithering.
249- furi_hal_uart_tx ( FuriHalUartIdUSART1 , (uint8_t []){'d' }, 1 );
249+ furi_hal_serial_tx ( instance -> serial_handle , (uint8_t []){'d' }, 1 );
250250 furi_delay_ms (50 );
251251
252252 model -> is_dithering_enabled = false;
253253 } else {
254254 // Camera: Enable dithering.
255- furi_hal_uart_tx ( FuriHalUartIdUSART1 , (uint8_t []){'D' }, 1 );
255+ furi_hal_serial_tx ( instance -> serial_handle , (uint8_t []){'D' }, 1 );
256256 furi_delay_ms (50 );
257257
258258 model -> is_dithering_enabled = true;
@@ -276,7 +276,7 @@ static bool camera_suite_view_camera_input(InputEvent* event, void* context) {
276276 camera_suite_led_set_rgb (instance -> context , 0 , 0 , 255 );
277277
278278 // Camera: Increase contrast.
279- furi_hal_uart_tx ( FuriHalUartIdUSART1 , (uint8_t []){'C' }, 1 );
279+ furi_hal_serial_tx ( instance -> serial_handle , (uint8_t []){'C' }, 1 );
280280 furi_delay_ms (50 );
281281
282282 instance -> callback (CameraSuiteCustomEventSceneCameraUp , instance -> context );
@@ -297,7 +297,7 @@ static bool camera_suite_view_camera_input(InputEvent* event, void* context) {
297297 camera_suite_led_set_rgb (instance -> context , 0 , 0 , 255 );
298298
299299 // Camera: Reduce contrast.
300- furi_hal_uart_tx ( FuriHalUartIdUSART1 , (uint8_t []){'c' }, 1 );
300+ furi_hal_serial_tx ( instance -> serial_handle , (uint8_t []){'c' }, 1 );
301301 furi_delay_ms (50 );
302302
303303 instance -> callback (CameraSuiteCustomEventSceneCameraDown , instance -> context );
@@ -316,7 +316,7 @@ static bool camera_suite_view_camera_input(InputEvent* event, void* context) {
316316 camera_suite_led_set_rgb (instance -> context , 0 , 0 , 255 );
317317
318318 // @todo - Save picture directly to ESP32-CAM.
319- // furi_hal_uart_tx(FuriHalUartIdUSART1 , (uint8_t[]){'P'}, 1);
319+ // furi_hal_serial_tx(instance->serial_handle , (uint8_t[]){'P'}, 1);
320320
321321 // Save currently displayed image to the Flipper Zero SD card.
322322 save_image_to_flipper_sd_card (model );
@@ -349,22 +349,22 @@ static void camera_suite_view_camera_enter(void* context) {
349349 CameraSuite * instance_context = instance -> context ;
350350
351351 // Start camera stream.
352- furi_hal_uart_tx ( FuriHalUartIdUSART1 , (uint8_t []){'S' }, 1 );
352+ furi_hal_serial_tx ( instance -> serial_handle , (uint8_t []){'S' }, 1 );
353353 furi_delay_ms (50 );
354354
355355 // Get/set dither type.
356356 uint8_t dither_type = instance_context -> dither ;
357- furi_hal_uart_tx ( FuriHalUartIdUSART1 , & dither_type , 1 );
357+ furi_hal_serial_tx ( instance -> serial_handle , & dither_type , 1 );
358358 furi_delay_ms (50 );
359359
360360 // Make sure the camera is not inverted.
361- furi_hal_uart_tx ( FuriHalUartIdUSART1 , (uint8_t []){'i' }, 1 );
361+ furi_hal_serial_tx ( instance -> serial_handle , (uint8_t []){'i' }, 1 );
362362 furi_delay_ms (50 );
363363
364364 // Toggle flash on or off based on the current state. If the user has this
365365 // on the flash will stay on the entire time the user is in the camera view.
366366 uint8_t flash_state = instance_context -> flash ? 'F' : 'f' ;
367- furi_hal_uart_tx ( FuriHalUartIdUSART1 , & flash_state , 1 );
367+ furi_hal_serial_tx ( instance -> serial_handle , & flash_state , 1 );
368368 furi_delay_ms (50 );
369369
370370 with_view_model (
@@ -374,17 +374,18 @@ static void camera_suite_view_camera_enter(void* context) {
374374 true);
375375}
376376
377- static void camera_on_irq_cb ( UartIrqEvent uartIrqEvent , uint8_t data , void * context ) {
378- furi_assert ( uartIrqEvent );
379- furi_assert (data );
377+ static void
378+ camera_on_irq_cb ( FuriHalSerialHandle * handle , FuriHalSerialRxEvent event , void * context ) {
379+ furi_assert (handle );
380380 furi_assert (context );
381381
382382 // Cast `context` to `CameraSuiteViewCamera*` and store it in `instance`.
383383 CameraSuiteViewCamera * instance = context ;
384384
385385 // If `uartIrqEvent` is `UartIrqEventRXNE`, send the data to the
386386 // `rx_stream` and set the `WorkerEventRx` flag.
387- if (uartIrqEvent == UartIrqEventRXNE ) {
387+ if (event == FuriHalSerialRxEventData ) {
388+ uint8_t data = furi_hal_serial_async_rx (handle );
388389 furi_stream_buffer_send (instance -> rx_stream , & data , 1 , 0 );
389390 furi_thread_flags_set (furi_thread_get_id (instance -> worker_thread ), WorkerEventRx );
390391 }
@@ -512,32 +513,31 @@ CameraSuiteViewCamera* camera_suite_view_camera_alloc() {
512513 instance -> worker_thread = thread ;
513514 furi_thread_start (instance -> worker_thread );
514515
515- // Enable uart listener
516- furi_hal_console_disable ();
517-
518516 // 115200 is the default baud rate for the ESP32-CAM.
519- furi_hal_uart_set_br (FuriHalUartIdUSART1 , 230400 );
517+ instance -> serial_handle = furi_hal_serial_control_acquire (UART_CH );
518+ furi_check (instance -> serial_handle );
519+ furi_hal_serial_init (instance -> serial_handle , 230400 );
520520
521521 // Enable UART1 and set the IRQ callback.
522- furi_hal_uart_set_irq_cb ( FuriHalUartIdUSART1 , camera_on_irq_cb , instance );
522+ furi_hal_serial_async_rx_start ( instance -> serial_handle , camera_on_irq_cb , instance , false );
523523
524524 return instance ;
525525}
526526
527527void camera_suite_view_camera_free (CameraSuiteViewCamera * instance ) {
528528 furi_assert (instance );
529529
530- // Remove the IRQ callback.
531- furi_hal_uart_set_irq_cb (FuriHalUartIdUSART1 , NULL , NULL );
532-
533530 // Free the worker thread.
531+ furi_thread_flags_set (furi_thread_get_id (instance -> worker_thread ), WorkerEventStop );
532+ furi_thread_join (instance -> worker_thread );
534533 furi_thread_free (instance -> worker_thread );
535534
536535 // Free the allocated stream buffer.
537536 furi_stream_buffer_free (instance -> rx_stream );
538537
539538 // Re-enable the console.
540- // furi_hal_console_enable();
539+ furi_hal_serial_deinit (instance -> serial_handle );
540+ furi_hal_serial_control_release (instance -> serial_handle );
541541
542542 with_view_model (
543543 instance -> view , UartDumpModel * model , { UNUSED (model ); }, true);
0 commit comments