|
@@ -196,7 +196,7 @@ static bool camera_suite_view_camera_input(InputEvent* event, void* context) {
|
|
|
UNUSED(model);
|
|
UNUSED(model);
|
|
|
|
|
|
|
|
// Stop camera stream.
|
|
// Stop camera stream.
|
|
|
- furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[]){'s'}, 1);
|
|
|
|
|
|
|
+ furi_hal_serial_tx(instance->serial_handle, (uint8_t[]){'s'}, 1);
|
|
|
furi_delay_ms(50);
|
|
furi_delay_ms(50);
|
|
|
|
|
|
|
|
// Go back to the main menu.
|
|
// Go back to the main menu.
|
|
@@ -217,13 +217,13 @@ static bool camera_suite_view_camera_input(InputEvent* event, void* context) {
|
|
|
|
|
|
|
|
if(model->is_inverted) {
|
|
if(model->is_inverted) {
|
|
|
// Camera: Set invert to false on the ESP32-CAM.
|
|
// Camera: Set invert to false on the ESP32-CAM.
|
|
|
- furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[]){'i'}, 1);
|
|
|
|
|
|
|
+ furi_hal_serial_tx(instance->serial_handle, (uint8_t[]){'i'}, 1);
|
|
|
furi_delay_ms(50);
|
|
furi_delay_ms(50);
|
|
|
|
|
|
|
|
model->is_inverted = false;
|
|
model->is_inverted = false;
|
|
|
} else {
|
|
} else {
|
|
|
// Camera: Set invert to true on the ESP32-CAM.
|
|
// Camera: Set invert to true on the ESP32-CAM.
|
|
|
- furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[]){'I'}, 1);
|
|
|
|
|
|
|
+ furi_hal_serial_tx(instance->serial_handle, (uint8_t[]){'I'}, 1);
|
|
|
furi_delay_ms(50);
|
|
furi_delay_ms(50);
|
|
|
|
|
|
|
|
model->is_inverted = true;
|
|
model->is_inverted = true;
|
|
@@ -246,13 +246,13 @@ static bool camera_suite_view_camera_input(InputEvent* event, void* context) {
|
|
|
|
|
|
|
|
if(model->is_dithering_enabled) {
|
|
if(model->is_dithering_enabled) {
|
|
|
// Camera: Disable dithering.
|
|
// Camera: Disable dithering.
|
|
|
- furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[]){'d'}, 1);
|
|
|
|
|
|
|
+ furi_hal_serial_tx(instance->serial_handle, (uint8_t[]){'d'}, 1);
|
|
|
furi_delay_ms(50);
|
|
furi_delay_ms(50);
|
|
|
|
|
|
|
|
model->is_dithering_enabled = false;
|
|
model->is_dithering_enabled = false;
|
|
|
} else {
|
|
} else {
|
|
|
// Camera: Enable dithering.
|
|
// Camera: Enable dithering.
|
|
|
- furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[]){'D'}, 1);
|
|
|
|
|
|
|
+ furi_hal_serial_tx(instance->serial_handle, (uint8_t[]){'D'}, 1);
|
|
|
furi_delay_ms(50);
|
|
furi_delay_ms(50);
|
|
|
|
|
|
|
|
model->is_dithering_enabled = true;
|
|
model->is_dithering_enabled = true;
|
|
@@ -276,7 +276,7 @@ static bool camera_suite_view_camera_input(InputEvent* event, void* context) {
|
|
|
camera_suite_led_set_rgb(instance->context, 0, 0, 255);
|
|
camera_suite_led_set_rgb(instance->context, 0, 0, 255);
|
|
|
|
|
|
|
|
// Camera: Increase contrast.
|
|
// Camera: Increase contrast.
|
|
|
- furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[]){'C'}, 1);
|
|
|
|
|
|
|
+ furi_hal_serial_tx(instance->serial_handle, (uint8_t[]){'C'}, 1);
|
|
|
furi_delay_ms(50);
|
|
furi_delay_ms(50);
|
|
|
|
|
|
|
|
instance->callback(CameraSuiteCustomEventSceneCameraUp, instance->context);
|
|
instance->callback(CameraSuiteCustomEventSceneCameraUp, instance->context);
|
|
@@ -297,7 +297,7 @@ static bool camera_suite_view_camera_input(InputEvent* event, void* context) {
|
|
|
camera_suite_led_set_rgb(instance->context, 0, 0, 255);
|
|
camera_suite_led_set_rgb(instance->context, 0, 0, 255);
|
|
|
|
|
|
|
|
// Camera: Reduce contrast.
|
|
// Camera: Reduce contrast.
|
|
|
- furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[]){'c'}, 1);
|
|
|
|
|
|
|
+ furi_hal_serial_tx(instance->serial_handle, (uint8_t[]){'c'}, 1);
|
|
|
furi_delay_ms(50);
|
|
furi_delay_ms(50);
|
|
|
|
|
|
|
|
instance->callback(CameraSuiteCustomEventSceneCameraDown, instance->context);
|
|
instance->callback(CameraSuiteCustomEventSceneCameraDown, instance->context);
|
|
@@ -316,7 +316,7 @@ static bool camera_suite_view_camera_input(InputEvent* event, void* context) {
|
|
|
camera_suite_led_set_rgb(instance->context, 0, 0, 255);
|
|
camera_suite_led_set_rgb(instance->context, 0, 0, 255);
|
|
|
|
|
|
|
|
// @todo - Save picture directly to ESP32-CAM.
|
|
// @todo - Save picture directly to ESP32-CAM.
|
|
|
- // furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[]){'P'}, 1);
|
|
|
|
|
|
|
+ // furi_hal_serial_tx(instance->serial_handle, (uint8_t[]){'P'}, 1);
|
|
|
|
|
|
|
|
// Save currently displayed image to the Flipper Zero SD card.
|
|
// Save currently displayed image to the Flipper Zero SD card.
|
|
|
save_image_to_flipper_sd_card(model);
|
|
save_image_to_flipper_sd_card(model);
|
|
@@ -349,22 +349,22 @@ static void camera_suite_view_camera_enter(void* context) {
|
|
|
CameraSuite* instance_context = instance->context;
|
|
CameraSuite* instance_context = instance->context;
|
|
|
|
|
|
|
|
// Start camera stream.
|
|
// Start camera stream.
|
|
|
- furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[]){'S'}, 1);
|
|
|
|
|
|
|
+ furi_hal_serial_tx(instance->serial_handle, (uint8_t[]){'S'}, 1);
|
|
|
furi_delay_ms(50);
|
|
furi_delay_ms(50);
|
|
|
|
|
|
|
|
// Get/set dither type.
|
|
// Get/set dither type.
|
|
|
uint8_t dither_type = instance_context->dither;
|
|
uint8_t dither_type = instance_context->dither;
|
|
|
- furi_hal_uart_tx(FuriHalUartIdUSART1, &dither_type, 1);
|
|
|
|
|
|
|
+ furi_hal_serial_tx(instance->serial_handle, &dither_type, 1);
|
|
|
furi_delay_ms(50);
|
|
furi_delay_ms(50);
|
|
|
|
|
|
|
|
// Make sure the camera is not inverted.
|
|
// Make sure the camera is not inverted.
|
|
|
- furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t[]){'i'}, 1);
|
|
|
|
|
|
|
+ furi_hal_serial_tx(instance->serial_handle, (uint8_t[]){'i'}, 1);
|
|
|
furi_delay_ms(50);
|
|
furi_delay_ms(50);
|
|
|
|
|
|
|
|
// Toggle flash on or off based on the current state. If the user has this
|
|
// Toggle flash on or off based on the current state. If the user has this
|
|
|
// on the flash will stay on the entire time the user is in the camera view.
|
|
// on the flash will stay on the entire time the user is in the camera view.
|
|
|
uint8_t flash_state = instance_context->flash ? 'F' : 'f';
|
|
uint8_t flash_state = instance_context->flash ? 'F' : 'f';
|
|
|
- furi_hal_uart_tx(FuriHalUartIdUSART1, &flash_state, 1);
|
|
|
|
|
|
|
+ furi_hal_serial_tx(instance->serial_handle, &flash_state, 1);
|
|
|
furi_delay_ms(50);
|
|
furi_delay_ms(50);
|
|
|
|
|
|
|
|
with_view_model(
|
|
with_view_model(
|
|
@@ -374,9 +374,9 @@ static void camera_suite_view_camera_enter(void* context) {
|
|
|
true);
|
|
true);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-static void camera_on_irq_cb(UartIrqEvent uartIrqEvent, uint8_t data, void* context) {
|
|
|
|
|
- furi_assert(uartIrqEvent);
|
|
|
|
|
- furi_assert(data);
|
|
|
|
|
|
|
+static void
|
|
|
|
|
+ camera_on_irq_cb(FuriHalSerialHandle* handle, FuriHalSerialRxEvent event, void* context) {
|
|
|
|
|
+ furi_assert(handle);
|
|
|
furi_assert(context);
|
|
furi_assert(context);
|
|
|
|
|
|
|
|
// Cast `context` to `CameraSuiteViewCamera*` and store it in `instance`.
|
|
// Cast `context` to `CameraSuiteViewCamera*` and store it in `instance`.
|
|
@@ -384,7 +384,8 @@ static void camera_on_irq_cb(UartIrqEvent uartIrqEvent, uint8_t data, void* cont
|
|
|
|
|
|
|
|
// If `uartIrqEvent` is `UartIrqEventRXNE`, send the data to the
|
|
// If `uartIrqEvent` is `UartIrqEventRXNE`, send the data to the
|
|
|
// `rx_stream` and set the `WorkerEventRx` flag.
|
|
// `rx_stream` and set the `WorkerEventRx` flag.
|
|
|
- if(uartIrqEvent == UartIrqEventRXNE) {
|
|
|
|
|
|
|
+ if(event == FuriHalSerialRxEventData) {
|
|
|
|
|
+ uint8_t data = furi_hal_serial_async_rx(handle);
|
|
|
furi_stream_buffer_send(instance->rx_stream, &data, 1, 0);
|
|
furi_stream_buffer_send(instance->rx_stream, &data, 1, 0);
|
|
|
furi_thread_flags_set(furi_thread_get_id(instance->worker_thread), WorkerEventRx);
|
|
furi_thread_flags_set(furi_thread_get_id(instance->worker_thread), WorkerEventRx);
|
|
|
}
|
|
}
|
|
@@ -512,14 +513,13 @@ CameraSuiteViewCamera* camera_suite_view_camera_alloc() {
|
|
|
instance->worker_thread = thread;
|
|
instance->worker_thread = thread;
|
|
|
furi_thread_start(instance->worker_thread);
|
|
furi_thread_start(instance->worker_thread);
|
|
|
|
|
|
|
|
- // Enable uart listener
|
|
|
|
|
- furi_hal_console_disable();
|
|
|
|
|
-
|
|
|
|
|
// 115200 is the default baud rate for the ESP32-CAM.
|
|
// 115200 is the default baud rate for the ESP32-CAM.
|
|
|
- furi_hal_uart_set_br(FuriHalUartIdUSART1, 230400);
|
|
|
|
|
|
|
+ instance->serial_handle = furi_hal_serial_control_acquire(UART_CH);
|
|
|
|
|
+ furi_check(instance->serial_handle);
|
|
|
|
|
+ furi_hal_serial_init(instance->serial_handle, 230400);
|
|
|
|
|
|
|
|
// Enable UART1 and set the IRQ callback.
|
|
// Enable UART1 and set the IRQ callback.
|
|
|
- furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, camera_on_irq_cb, instance);
|
|
|
|
|
|
|
+ furi_hal_serial_async_rx_start(instance->serial_handle, camera_on_irq_cb, instance, false);
|
|
|
|
|
|
|
|
return instance;
|
|
return instance;
|
|
|
}
|
|
}
|
|
@@ -527,17 +527,17 @@ CameraSuiteViewCamera* camera_suite_view_camera_alloc() {
|
|
|
void camera_suite_view_camera_free(CameraSuiteViewCamera* instance) {
|
|
void camera_suite_view_camera_free(CameraSuiteViewCamera* instance) {
|
|
|
furi_assert(instance);
|
|
furi_assert(instance);
|
|
|
|
|
|
|
|
- // Remove the IRQ callback.
|
|
|
|
|
- furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, NULL, NULL);
|
|
|
|
|
-
|
|
|
|
|
// Free the worker thread.
|
|
// Free the worker thread.
|
|
|
|
|
+ furi_thread_flags_set(furi_thread_get_id(instance->worker_thread), WorkerEventStop);
|
|
|
|
|
+ furi_thread_join(instance->worker_thread);
|
|
|
furi_thread_free(instance->worker_thread);
|
|
furi_thread_free(instance->worker_thread);
|
|
|
|
|
|
|
|
// Free the allocated stream buffer.
|
|
// Free the allocated stream buffer.
|
|
|
furi_stream_buffer_free(instance->rx_stream);
|
|
furi_stream_buffer_free(instance->rx_stream);
|
|
|
|
|
|
|
|
// Re-enable the console.
|
|
// Re-enable the console.
|
|
|
- // furi_hal_console_enable();
|
|
|
|
|
|
|
+ furi_hal_serial_deinit(instance->serial_handle);
|
|
|
|
|
+ furi_hal_serial_control_release(instance->serial_handle);
|
|
|
|
|
|
|
|
with_view_model(
|
|
with_view_model(
|
|
|
instance->view, UartDumpModel * model, { UNUSED(model); }, true);
|
|
instance->view, UartDumpModel * model, { UNUSED(model); }, true);
|