From 81c4865f48062f7b66e372d3db3c08e5482ad515 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Fri, 21 Jul 2023 23:37:21 +0200 Subject: [PATCH 1/2] Random cleanup --- .vscode/example/tasks.json | 6 +- applications/debug/unit_tests/nfc/nfc_test.c | 150 ------------------- applications/main/application.fam | 1 - applications/system/updater/application.fam | 2 - applications/system/updater/updater.c | 4 +- applications/system/updater/updater_i.h | 2 +- 6 files changed, 6 insertions(+), 159 deletions(-) diff --git a/.vscode/example/tasks.json b/.vscode/example/tasks.json index 0acfc7e2d..1d2b55a2c 100644 --- a/.vscode/example/tasks.json +++ b/.vscode/example/tasks.json @@ -172,13 +172,13 @@ "label": "[Debug] Build and upload all FAPs to Flipper over USB", "group": "build", "type": "shell", - "command": "./fbt faps_copy" + "command": "./fbt fap_deploy" }, { "label": "[Release] Build and upload all FAPs to Flipper over USB", "group": "build", "type": "shell", - "command": "./fbt COMPACT=1 DEBUG=0 faps_copy" + "command": "./fbt COMPACT=1 DEBUG=0 fap_deploy" }, { // Press Ctrl+] to quit @@ -187,7 +187,7 @@ "command": "./fbt cli", "group": "none", "isBackground": true, - "options": { + "options": { "env": { "FBT_NO_SYNC": "0" } diff --git a/applications/debug/unit_tests/nfc/nfc_test.c b/applications/debug/unit_tests/nfc/nfc_test.c index 4aec0b060..bc2f7887b 100644 --- a/applications/debug/unit_tests/nfc/nfc_test.c +++ b/applications/debug/unit_tests/nfc/nfc_test.c @@ -1,12 +1,10 @@ #include #include -#include #include #include #include #include #include -#include #include #include @@ -224,153 +222,6 @@ MU_TEST(nfc_digital_signal_test) { "NFC long digital signal test failed\r\n"); } -static bool nfc_test_pulse_reader_toggle( - uint32_t usec_low, - uint32_t usec_high, - uint32_t period_count, - uint32_t tolerance) { - furi_assert(nfc_test); - - bool success = false; - uint32_t pulses = 0; - const GpioPin* gpio_in = &gpio_ext_pa6; - const GpioPin* gpio_out = &gpio_ext_pa7; - PulseReader* reader = NULL; - - do { - reader = pulse_reader_alloc(gpio_in, 512); - - if(!reader) { - FURI_LOG_E(TAG, "failed to allocate pulse reader"); - break; - } - - /* use TIM1 to create a specific number of pulses with defined duty cycle - but first set the IO to high, so the low/high pulse can get detected */ - furi_hal_gpio_init(gpio_out, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh); - furi_hal_gpio_write(gpio_out, true); - - LL_TIM_DeInit(TIM1); - - LL_TIM_SetCounterMode(TIM1, LL_TIM_COUNTERMODE_UP); - LL_TIM_SetRepetitionCounter(TIM1, 0); - LL_TIM_SetClockDivision(TIM1, LL_TIM_CLOCKDIVISION_DIV1); - LL_TIM_SetClockSource(TIM1, LL_TIM_CLOCKSOURCE_INTERNAL); - LL_TIM_DisableARRPreload(TIM1); - - LL_TIM_OC_DisablePreload(TIM1, LL_TIM_CHANNEL_CH1); - LL_TIM_OC_SetMode(TIM1, LL_TIM_CHANNEL_CH1, LL_TIM_OCMODE_PWM2); - LL_TIM_OC_SetPolarity(TIM1, LL_TIM_CHANNEL_CH1N, LL_TIM_OCPOLARITY_HIGH); - LL_TIM_OC_DisableFast(TIM1, LL_TIM_CHANNEL_CH1); - LL_TIM_CC_EnableChannel(TIM1, LL_TIM_CHANNEL_CH1N); - - LL_TIM_EnableAllOutputs(TIM1); - - /* now calculate the TIM1 period and compare values */ - uint32_t freq_div = 64 * (usec_low + usec_high); - uint32_t prescaler = freq_div / 0x10000LU; - uint32_t period = freq_div / (prescaler + 1); - uint32_t compare = 64 * usec_low / (prescaler + 1); - - LL_TIM_SetPrescaler(TIM1, prescaler); - LL_TIM_SetAutoReload(TIM1, period - 1); - LL_TIM_SetCounter(TIM1, period - 1); - LL_TIM_OC_SetCompareCH1(TIM1, compare); - - /* timer is ready to launch, now start the pulse reader */ - pulse_reader_set_timebase(reader, PulseReaderUnitMicrosecond); - pulse_reader_start(reader); - - /* and quickly enable and switch over the GPIO to the generated signal */ - LL_TIM_EnableCounter(TIM1); - furi_hal_gpio_init_ex( - gpio_out, GpioModeAltFunctionPushPull, GpioPullNo, GpioSpeedVeryHigh, GpioAltFn1TIM1); - - /* now it's time to parse the pulses received by the reader */ - uint32_t timer_pulses = period_count; - uint32_t prev_cnt = 0; - - while(timer_pulses > 0) { - /* whenever the counter gets reset, we went through a full period */ - uint32_t cur_cnt = LL_TIM_GetCounter(TIM1); - if(cur_cnt < prev_cnt) { - timer_pulses--; - } - prev_cnt = cur_cnt; - } - /* quickly halt the counter to keep a static signal */ - LL_TIM_DisableCounter(TIM1); - - do { - /* as all edges were sampled asynchronously, the timeout can be zero */ - uint32_t length = pulse_reader_receive(reader, 0); - - /* in the last pulse, we expect a "no edge" return value. if seen that, test succeeded. */ - if(pulses > period_count * 2) { - if(length != PULSE_READER_NO_EDGE) { - FURI_LOG_E( - TAG, - "last pulse expected to be PULSE_READER_NO_EDGE, but was %lu.", - length); - break; - } - success = true; - break; - } - - /* else we shall never see "no edge" or "lost edge" */ - if(length == PULSE_READER_NO_EDGE) { - FURI_LOG_E(TAG, "%lu. pulse not expected to be PULSE_READER_NO_EDGE", pulses); - break; - } - if(length == PULSE_READER_LOST_EDGE) { - FURI_LOG_E(TAG, "%lu. pulse not expected to be PULSE_READER_LOST_EDGE", pulses); - break; - } - - if(pulses > 0) { - /* throw away the first pulse, which is the 1->0 from the first start and will be irrelevant for our test */ - bool phase = ((pulses - 1) % 2) == 1; - uint32_t expected = phase ? usec_high : usec_low; - uint32_t deviation = abs((int32_t)length - (int32_t)expected); - - if(deviation > tolerance) { - FURI_LOG_E( - TAG, - "%lu. pulse expected %lu, but pulse was %lu.", - pulses, - expected, - length); - break; - } - } - pulses++; - } while(true); - } while(false); - - if(reader != NULL) { - pulse_reader_stop(reader); - pulse_reader_free(reader); - } - - LL_TIM_DeInit(TIM1); - furi_hal_gpio_init_simple(gpio_in, GpioModeAnalog); - furi_hal_gpio_init_simple(gpio_out, GpioModeAnalog); - - return success; -} - -MU_TEST(nfc_pulse_reader_test) { - mu_assert(nfc_test_pulse_reader_toggle(1500, 2500, 50, 10), "1 ms signal failed\r\n"); - mu_assert(nfc_test_pulse_reader_toggle(10000, 10000, 10, 10), "10 ms signal failed\r\n"); - mu_assert(nfc_test_pulse_reader_toggle(100000, 100000, 5, 50), "100 ms signal failed\r\n"); - mu_assert(nfc_test_pulse_reader_toggle(100, 900, 50, 10), "1 ms asymmetric signal failed\r\n"); - mu_assert( - nfc_test_pulse_reader_toggle(3333, 6666, 10, 10), "10 ms asymmetric signal failed\r\n"); - mu_assert( - nfc_test_pulse_reader_toggle(25000, 75000, 5, 10), "100 ms asymmetric signal failed\r\n"); -} - MU_TEST(mf_classic_dict_test) { MfClassicDict* instance = NULL; uint64_t key = 0; @@ -705,7 +556,6 @@ MU_TEST(mf_classic_4k_7b_file_test) { MU_TEST_SUITE(nfc) { nfc_test_alloc(); - MU_RUN_TEST(nfc_pulse_reader_test); MU_RUN_TEST(nfca_file_test); MU_RUN_TEST(mf_mini_file_test); MU_RUN_TEST(mf_classic_1k_4b_file_test); diff --git a/applications/main/application.fam b/applications/main/application.fam index 0af6617d7..6f1be721b 100644 --- a/applications/main/application.fam +++ b/applications/main/application.fam @@ -13,7 +13,6 @@ App( "u2f", "xtreme_app", "archive", - "nightstand", "main_apps_on_start", ], ) diff --git a/applications/system/updater/application.fam b/applications/system/updater/application.fam index f53ee9b07..cdf98530b 100644 --- a/applications/system/updater/application.fam +++ b/applications/system/updater/application.fam @@ -6,7 +6,6 @@ App( requires=[ "gui", "storage", - "archive", ], conflicts=["desktop"], entry_point="updater_srv", @@ -23,7 +22,6 @@ App( "gui", "storage", "bt", - "archive", ], conflicts=["updater"], provides=["updater_start"], diff --git a/applications/system/updater/updater.c b/applications/system/updater/updater.c index 9d3a7bab8..248435b61 100644 --- a/applications/system/updater/updater.c +++ b/applications/system/updater/updater.c @@ -32,7 +32,7 @@ static void updater_main_model_set_state(main_view, message, progress, failed); } -Updater* updater_alloc(char* arg) { +Updater* updater_alloc(const char* arg) { Updater* updater = malloc(sizeof(Updater)); if(arg && strlen(arg)) { updater->startup_arg = furi_string_alloc_set(arg); @@ -118,7 +118,7 @@ void updater_free(Updater* updater) { free(updater); } -int32_t updater_srv(char* p) { +int32_t updater_srv(const char* p) { Updater* updater = updater_alloc(p); view_dispatcher_run(updater->view_dispatcher); updater_free(updater); diff --git a/applications/system/updater/updater_i.h b/applications/system/updater/updater_i.h index 4940eb60e..4e3c704d2 100644 --- a/applications/system/updater/updater_i.h +++ b/applications/system/updater/updater_i.h @@ -52,7 +52,7 @@ typedef struct { int32_t idle_ticks; } Updater; -Updater* updater_alloc(char* arg); +Updater* updater_alloc(const char* arg); void updater_free(Updater* updater); From dd42b70c349d1593ab91557ccb8975da1c0ad140 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Fri, 21 Jul 2023 23:45:52 +0200 Subject: [PATCH 2/2] Add unmerged subghz code (?) --- applications/main/subghz/application.fam | 2 ++ firmware/targets/f7/furi_hal/furi_hal_spi.c | 28 ++++++++++----------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/applications/main/subghz/application.fam b/applications/main/subghz/application.fam index 35d7ef6d1..edc86b38d 100644 --- a/applications/main/subghz/application.fam +++ b/applications/main/subghz/application.fam @@ -3,6 +3,7 @@ App( name="SubGHz", apptype=FlipperAppType.APP, targets=["f7"], + cdefines=["APP_SUBGHZ"], entry_point="subghz_app", requires=[ "gui", @@ -25,6 +26,7 @@ App( targets=["f7"], apptype=FlipperAppType.STARTUP, entry_point="subghz_on_system_start", + requires=["subghz"], order=40, ) diff --git a/firmware/targets/f7/furi_hal/furi_hal_spi.c b/firmware/targets/f7/furi_hal/furi_hal_spi.c index 42b854799..17769832b 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_spi.c +++ b/firmware/targets/f7/furi_hal/furi_hal_spi.c @@ -12,10 +12,10 @@ #define TAG "FuriHalSpi" #define SPI_DMA DMA2 -#define SPI_DMA_RX_CHANNEL LL_DMA_CHANNEL_3 -#define SPI_DMA_TX_CHANNEL LL_DMA_CHANNEL_4 -#define SPI_DMA_RX_IRQ FuriHalInterruptIdDma2Ch3 -#define SPI_DMA_TX_IRQ FuriHalInterruptIdDma2Ch4 +#define SPI_DMA_RX_CHANNEL LL_DMA_CHANNEL_6 +#define SPI_DMA_TX_CHANNEL LL_DMA_CHANNEL_7 +#define SPI_DMA_RX_IRQ FuriHalInterruptIdDma2Ch6 +#define SPI_DMA_TX_IRQ FuriHalInterruptIdDma2Ch7 #define SPI_DMA_RX_DEF SPI_DMA, SPI_DMA_RX_CHANNEL #define SPI_DMA_TX_DEF SPI_DMA, SPI_DMA_TX_CHANNEL @@ -170,18 +170,18 @@ bool furi_hal_spi_bus_trx( } static void spi_dma_isr() { -#if SPI_DMA_RX_CHANNEL == LL_DMA_CHANNEL_3 - if(LL_DMA_IsActiveFlag_TC3(SPI_DMA) && LL_DMA_IsEnabledIT_TC(SPI_DMA_RX_DEF)) { - LL_DMA_ClearFlag_TC3(SPI_DMA); +#if SPI_DMA_RX_CHANNEL == LL_DMA_CHANNEL_6 + if(LL_DMA_IsActiveFlag_TC6(SPI_DMA) && LL_DMA_IsEnabledIT_TC(SPI_DMA_RX_DEF)) { + LL_DMA_ClearFlag_TC6(SPI_DMA); furi_check(furi_semaphore_release(spi_dma_completed) == FuriStatusOk); } #else #error Update this code. Would you kindly? #endif -#if SPI_DMA_TX_CHANNEL == LL_DMA_CHANNEL_4 - if(LL_DMA_IsActiveFlag_TC4(SPI_DMA) && LL_DMA_IsEnabledIT_TC(SPI_DMA_TX_DEF)) { - LL_DMA_ClearFlag_TC4(SPI_DMA); +#if SPI_DMA_TX_CHANNEL == LL_DMA_CHANNEL_7 + if(LL_DMA_IsActiveFlag_TC7(SPI_DMA) && LL_DMA_IsEnabledIT_TC(SPI_DMA_TX_DEF)) { + LL_DMA_ClearFlag_TC7(SPI_DMA); furi_check(furi_semaphore_release(spi_dma_completed) == FuriStatusOk); } #else @@ -241,8 +241,8 @@ bool furi_hal_spi_bus_trx_dma( dma_config.Priority = LL_DMA_PRIORITY_MEDIUM; LL_DMA_Init(SPI_DMA_TX_DEF, &dma_config); -#if SPI_DMA_TX_CHANNEL == LL_DMA_CHANNEL_4 - LL_DMA_ClearFlag_TC4(SPI_DMA); +#if SPI_DMA_TX_CHANNEL == LL_DMA_CHANNEL_7 + LL_DMA_ClearFlag_TC7(SPI_DMA); #else #error Update this code. Would you kindly? #endif @@ -315,8 +315,8 @@ bool furi_hal_spi_bus_trx_dma( dma_config.Priority = LL_DMA_PRIORITY_MEDIUM; LL_DMA_Init(SPI_DMA_RX_DEF, &dma_config); -#if SPI_DMA_RX_CHANNEL == LL_DMA_CHANNEL_3 - LL_DMA_ClearFlag_TC3(SPI_DMA); +#if SPI_DMA_RX_CHANNEL == LL_DMA_CHANNEL_6 + LL_DMA_ClearFlag_TC6(SPI_DMA); #else #error Update this code. Would you kindly? #endif