Skip to content

Commit fc4c6bd

Browse files
committed
Configurable SPI & UART Channels
1 parent 71dc8ff commit fc4c6bd

File tree

36 files changed

+458
-103
lines changed

36 files changed

+458
-103
lines changed

ReadMe.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ This software is for experimental purposes only and is not meant for any illegal
3131

3232
## Latest Updates - [PATREON: Latest Release RM0727-0355-0.87.1-1670f3c](https://www.patreon.com/RogueMaster?filters[tag]=Latest%20Release)
3333

34-
- Last Synced/Checked Unleashed, changes in [changelog](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/blob/420/CHANGELOG.md) and in [commits](https://github.com/DarkFlippers/unleashed-firmware/commits/dev): `2023-07-28 01:00 EST`
35-
- Last Synced/Checked OFW, changes in [commits](https://github.com/flipperdevices/flipperzero-firmware/commits/dev): `2023-07-28 01:00 EST`
34+
- Last Synced/Checked Unleashed, changes in [changelog](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/blob/420/CHANGELOG.md) and in [commits](https://github.com/DarkFlippers/unleashed-firmware/commits/dev): `2023-07-28 02:20 EST`
35+
- Last Synced/Checked OFW, changes in [commits](https://github.com/flipperdevices/flipperzero-firmware/commits/dev): `2023-07-28 02:20 EST`
3636
- [Fixed Memory leak/Pointer issue with CFW Settings app (By ESurge)](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/pull/724)
37+
- [Configurable SPI & UART Channels (By Sil333033)]
3738

3839
<a name="release">
3940

applications/drivers/subghz/cc1101_ext/cc1101_ext.c

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#define TAG "SubGhz_Device_CC1101_Ext"
1919

2020
#define SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO &gpio_ext_pb2
21-
#define SUBGHZ_DEVICE_CC1101_EXT_DANGEROUS_RANGE false
21+
#define SUBGHZ_DEVICE_CC1101_EXT_EXTENDED_RANGE false
2222

2323
/* DMA Channels definition */
2424
#define SUBGHZ_DEVICE_CC1101_EXT_DMA DMA2
@@ -193,11 +193,25 @@ bool subghz_device_cc1101_ext_alloc() {
193193
subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateInit;
194194
subghz_device_cc1101_ext->regulation = SubGhzDeviceCC1101ExtRegulationTxRx;
195195
subghz_device_cc1101_ext->async_mirror_pin = NULL;
196-
subghz_device_cc1101_ext->spi_bus_handle = &furi_hal_spi_bus_handle_external;
196+
197197
subghz_device_cc1101_ext->g0_pin = SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO;
198198

199199
subghz_device_cc1101_ext->async_rx.capture_delta_duration = 0;
200200

201+
subghz_device_cc1101_ext->spi_bus_handle =
202+
(CFW_SETTINGS()->spi_cc1101_handle == SpiDefault ?
203+
&furi_hal_spi_bus_handle_external :
204+
&furi_hal_spi_bus_handle_external_extra);
205+
206+
// this is needed if multiple SPI devices are connected to the same bus but with different CS pins
207+
if(CFW_SETTINGS()->spi_cc1101_handle == SpiDefault) {
208+
furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull);
209+
furi_hal_gpio_write(&gpio_ext_pc3, true);
210+
} else if(CFW_SETTINGS()->spi_cc1101_handle == SpiExtra) {
211+
furi_hal_gpio_init_simple(&gpio_ext_pa4, GpioModeOutputPushPull);
212+
furi_hal_gpio_write(&gpio_ext_pa4, true);
213+
}
214+
201215
furi_hal_spi_bus_handle_init(subghz_device_cc1101_ext->spi_bus_handle);
202216
return subghz_device_cc1101_ext_check_init();
203217
}
@@ -207,6 +221,13 @@ void subghz_device_cc1101_ext_free() {
207221
furi_hal_spi_bus_handle_deinit(subghz_device_cc1101_ext->spi_bus_handle);
208222
free(subghz_device_cc1101_ext);
209223
subghz_device_cc1101_ext = NULL;
224+
225+
// resetting the CS pins to floating
226+
if(CFW_SETTINGS()->spi_nrf24_handle == SpiDefault) {
227+
furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog);
228+
} else if(CFW_SETTINGS()->spi_nrf24_handle == SpiExtra) {
229+
furi_hal_gpio_init_simple(&gpio_ext_pa4, GpioModeAnalog);
230+
}
210231
}
211232

212233
void subghz_device_cc1101_ext_set_async_mirror_pin(const GpioPin* pin) {
@@ -432,16 +453,16 @@ bool subghz_device_cc1101_ext_is_frequency_valid(uint32_t value) {
432453
}
433454

434455
bool subghz_device_cc1101_ext_is_tx_allowed(uint32_t value) {
435-
if(!(SUBGHZ_DEVICE_CC1101_EXT_DANGEROUS_RANGE) &&
456+
if(!(SUBGHZ_DEVICE_CC1101_EXT_EXTENDED_RANGE) &&
436457
!(value >= 299999755 && value <= 350000335) && // was increased from 348 to 350
437458
!(value >= 386999938 && value <= 467750000) && // was increased from 464 to 467.75
438459
!(value >= 778999847 && value <= 928000000)) {
439460
FURI_LOG_I(TAG, "Frequency blocked - outside default range");
440461
return false;
441462
} else if(
442-
(SUBGHZ_DEVICE_CC1101_EXT_DANGEROUS_RANGE) &&
463+
(SUBGHZ_DEVICE_CC1101_EXT_EXTENDED_RANGE) &&
443464
!subghz_device_cc1101_ext_is_frequency_valid(value)) {
444-
FURI_LOG_I(TAG, "Frequency blocked - outside dangerous range");
465+
FURI_LOG_I(TAG, "Frequency blocked - outside extended range");
445466
return false;
446467
}
447468

@@ -529,7 +550,7 @@ void subghz_device_cc1101_ext_start_async_rx(
529550
furi_hal_bus_enable(FuriHalBusTIM17);
530551

531552
// Configure TIM
532-
//Set the timer resolution to 2 µs
553+
//Set the timer resolution to 2 �s
533554
LL_TIM_SetPrescaler(TIM17, (64 << 1) - 1);
534555
LL_TIM_SetCounterMode(TIM17, LL_TIM_COUNTERMODE_UP);
535556
LL_TIM_SetAutoReload(TIM17, 0xFFFF);
@@ -710,7 +731,7 @@ bool subghz_device_cc1101_ext_start_async_tx(SubGhzDeviceCC1101ExtCallback callb
710731
furi_hal_bus_enable(FuriHalBusTIM17);
711732

712733
// Configure TIM
713-
// Set the timer resolution to 2 µs
734+
// Set the timer resolution to 2 �s
714735
LL_TIM_SetPrescaler(TIM17, (64 << 1) - 1);
715736
LL_TIM_SetCounterMode(TIM17, LL_TIM_COUNTERMODE_UP);
716737
LL_TIM_SetAutoReload(TIM17, 0xFFFF);

applications/drivers/subghz/cc1101_ext/cc1101_ext.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <stddef.h>
1111
#include <toolbox/level_duration.h>
1212
#include <furi_hal_gpio.h>
13+
#include <cfw.h>
1314

1415
#ifdef __cplusplus
1516
extern "C" {

applications/external/camera_suite/views/camera_suite_view_camera.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ static bool camera_suite_view_camera_input(InputEvent* event, void* context) {
202202
break;
203203
}
204204
// Send `data` to the ESP32-CAM
205-
furi_hal_uart_tx(FuriHalUartIdUSART1, data, 1);
205+
furi_hal_uart_tx(UART_CH, data, 1);
206206
}
207207
return true;
208208
}
@@ -224,7 +224,7 @@ static void camera_suite_view_camera_enter(void* context) {
224224
uint8_t data[1];
225225
data[0] = 'S'; // Uppercase `S` to start the camera
226226
// Send `data` to the ESP32-CAM
227-
furi_hal_uart_tx(FuriHalUartIdUSART1, data, 1);
227+
furi_hal_uart_tx(UART_CH, data, 1);
228228

229229
with_view_model(
230230
instance->view,
@@ -352,9 +352,13 @@ CameraSuiteViewCamera* camera_suite_view_camera_alloc() {
352352
furi_thread_start(instance->worker_thread);
353353

354354
// Enable uart listener
355-
furi_hal_console_disable();
356-
furi_hal_uart_set_br(FuriHalUartIdUSART1, 230400);
357-
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, camera_on_irq_cb, instance);
355+
if(UART_CH == FuriHalUartIdUSART1) {
356+
furi_hal_console_disable();
357+
} else if(UART_CH == FuriHalUartIdLPUART1) {
358+
furi_hal_uart_init(UART_CH, 230400);
359+
}
360+
furi_hal_uart_set_br(UART_CH, 230400);
361+
furi_hal_uart_set_irq_cb(UART_CH, camera_on_irq_cb, instance);
358362

359363
return instance;
360364
}
@@ -366,6 +370,14 @@ void camera_suite_view_camera_free(CameraSuiteViewCamera* instance) {
366370
instance->view, UartDumpModel * model, { UNUSED(model); }, true);
367371
view_free(instance->view);
368372
free(instance);
373+
374+
furi_hal_uart_set_irq_cb(UART_CH, NULL, NULL);
375+
376+
if(UART_CH == FuriHalUartIdLPUART1) {
377+
furi_hal_uart_deinit(UART_CH);
378+
} else {
379+
furi_hal_console_enable();
380+
}
369381
}
370382

371383
View* camera_suite_view_camera_get_view(CameraSuiteViewCamera* instance) {

applications/external/camera_suite/views/camera_suite_view_camera.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
#include <storage/filesystem_api_defines.h>
1515
#include <storage/storage.h>
1616

17+
#include <cfw.h>
18+
19+
#define UART_CH \
20+
(CFW_SETTINGS()->uart_esp_channel == UARTDefault ? FuriHalUartIdUSART1 : FuriHalUartIdLPUART1)
21+
1722
#pragma once
1823

1924
#define FRAME_WIDTH 128

applications/external/esp_flasher/esp_flasher_uart.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#include "esp_flasher_app_i.h"
22
#include "esp_flasher_uart.h"
3+
#include <cfw.h>
34

4-
#define UART_CH (FuriHalUartIdUSART1)
5+
#define UART_CH \
6+
(CFW_SETTINGS()->uart_esp_channel == UARTDefault ? FuriHalUartIdUSART1 : FuriHalUartIdLPUART1)
57
#define BAUDRATE (115200)
68

79
struct EspFlasherUart {

applications/external/evil_portal/evil_portal_app_i.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@
1212
#include <gui/scene_manager.h>
1313
#include <gui/view_dispatcher.h>
1414

15+
#include <dialogs/dialogs.h>
16+
#include <cfw.h>
17+
1518
#define NUM_MENU_ITEMS (5)
1619

1720
#define EVIL_PORTAL_TEXT_BOX_STORE_SIZE (4096)
18-
#define UART_CH (FuriHalUartIdUSART1)
21+
#define UART_CH \
22+
(CFW_SETTINGS()->uart_esp_channel == UARTDefault ? FuriHalUartIdUSART1 : FuriHalUartIdLPUART1)
1923

2024
#define SET_HTML_CMD "sethtml"
2125
#define SET_AP_CMD "setap"

applications/external/evil_portal/evil_portal_uart.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,16 @@ Evil_PortalUart* evil_portal_uart_init(Evil_PortalApp* app) {
121121

122122
furi_thread_start(uart->rx_thread);
123123

124-
furi_hal_console_disable();
124+
if(UART_CH == FuriHalUartIdUSART1) {
125+
furi_hal_console_disable();
126+
} else if(UART_CH == FuriHalUartIdLPUART1) {
127+
furi_hal_uart_init(UART_CH, app->BAUDRATE);
128+
}
129+
125130
if(app->BAUDRATE == 0) {
126131
app->BAUDRATE = 115200;
127132
}
133+
128134
furi_hal_uart_set_br(UART_CH, app->BAUDRATE);
129135
furi_hal_uart_set_irq_cb(UART_CH, evil_portal_uart_on_irq_cb, uart);
130136

@@ -139,7 +145,12 @@ void evil_portal_uart_free(Evil_PortalUart* uart) {
139145
furi_thread_free(uart->rx_thread);
140146

141147
furi_hal_uart_set_irq_cb(UART_CH, NULL, NULL);
142-
furi_hal_console_enable();
148+
149+
if(UART_CH == FuriHalUartIdLPUART1) {
150+
furi_hal_uart_deinit(UART_CH);
151+
} else {
152+
furi_hal_console_enable();
153+
}
143154

144155
free(uart);
145156
}

applications/external/gps_nmea_uart/gps_uart.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,24 @@ static void gps_uart_on_irq_cb(UartIrqEvent ev, uint8_t data, void* context) {
2020
}
2121

2222
static void gps_uart_serial_init(GpsUart* gps_uart) {
23-
furi_hal_console_disable();
24-
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, gps_uart_on_irq_cb, gps_uart);
25-
furi_hal_uart_set_br(FuriHalUartIdUSART1, gps_uart->baudrate);
23+
if(UART_CH == FuriHalUartIdUSART1) {
24+
furi_hal_console_disable();
25+
} else if(UART_CH == FuriHalUartIdLPUART1) {
26+
furi_hal_uart_init(UART_CH, gps_uart->baudrate);
27+
}
28+
29+
furi_hal_uart_set_irq_cb(UART_CH, gps_uart_on_irq_cb, gps_uart);
30+
furi_hal_uart_set_br(UART_CH, gps_uart->baudrate);
2631
}
2732

2833
static void gps_uart_serial_deinit(GpsUart* gps_uart) {
2934
UNUSED(gps_uart);
30-
furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, NULL, NULL);
31-
furi_hal_console_enable();
35+
furi_hal_uart_set_irq_cb(UART_CH, NULL, NULL);
36+
if(UART_CH == FuriHalUartIdLPUART1) {
37+
furi_hal_uart_deinit(UART_CH);
38+
} else {
39+
furi_hal_console_enable();
40+
}
3241
}
3342

3443
static void gps_uart_parse_nmea(GpsUart* gps_uart, char* line) {

applications/external/gps_nmea_uart/gps_uart.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
#include <furi_hal.h>
44
#include <notification/notification_messages.h>
5+
#include <cfw.h>
6+
7+
#define UART_CH \
8+
(CFW_SETTINGS()->uart_nmea_channel == UARTDefault ? FuriHalUartIdUSART1 : FuriHalUartIdLPUART1)
59

610
#define RX_BUF_SIZE 1024
711

0 commit comments

Comments
 (0)