From 02a827da38c2cb5b7103b77b95a0401f37851ec5 Mon Sep 17 00:00:00 2001 From: hedger Date: Mon, 19 Feb 2024 09:34:51 +0000 Subject: [PATCH 1/6] libs: added callback-connector to SDK --- lib/SConscript | 2 ++ lib/callback-connector/callback-connector.h | 15 +++++++++++---- targets/f18/api_symbols.csv | 1 + targets/f7/api_symbols.csv | 1 + 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/lib/SConscript b/lib/SConscript index 812573932..0767dc0b2 100644 --- a/lib/SConscript +++ b/lib/SConscript @@ -48,4 +48,6 @@ libs = env.BuildModules( ], ) +env.Append(SDK_HEADERS=[File("#/lib/callback-connector/callback-connector.h")]) + Return("libs") diff --git a/lib/callback-connector/callback-connector.h b/lib/callback-connector/callback-connector.h index 10fec3e2d..dd99c5b26 100644 --- a/lib/callback-connector/callback-connector.h +++ b/lib/callback-connector/callback-connector.h @@ -1,10 +1,13 @@ #ifndef CALLBACKCONNECTOR_H #define CALLBACKCONNECTOR_H + +#ifdef __cplusplus #include namespace cbc { namespace Details { -template class FuncMemberWrapper { +template +class FuncMemberWrapper { public: FuncMemberWrapper() = delete; using member_fun_t = Ret (T::*)(Args...); @@ -43,7 +46,8 @@ template typename FuncMemberWrapper::const_member_fun_t FuncMemberWrapper::const_member{}; -template struct FunctorWrapper { +template +struct FunctorWrapper { public: static std::function functor; static auto instatiate(Functor fn) { @@ -75,7 +79,8 @@ auto const_instantiate(T* t, Ret (T::*ptr)(Args...) const) { return FuncMemberWrapper::instantiate(t, ptr); } -template auto const_instantiate(T* t, Func ptr) { +template +auto const_instantiate(T* t, Func ptr) { return const_instantiate(t, ptr); } @@ -91,9 +96,11 @@ auto obtain_connector(T* t, Ret (T::*ptr)(Args...) const) { return Details::FuncMemberWrapper::instantiate(t, ptr); } -template auto obtain_connector(Functor functor) { +template +auto obtain_connector(Functor functor) { return Details::deducer(std::move(functor), &Functor::operator()); } } //end of cbc scope +#endif // __cplusplus #endif // CALLBACKCONNECTOR_H diff --git a/targets/f18/api_symbols.csv b/targets/f18/api_symbols.csv index bdfa8c7a4..f2190e43f 100644 --- a/targets/f18/api_symbols.csv +++ b/targets/f18/api_symbols.csv @@ -40,6 +40,7 @@ Header,+,applications/services/storage/storage.h,, Header,+,lib/bit_lib/bit_lib.h,, Header,+,lib/ble_profile/extra_profiles/hid_profile.h,, Header,+,lib/ble_profile/extra_services/hid_service.h,, +Header,+,lib/callback-connector/callback-connector.h,, Header,+,lib/datetime/datetime.h,, Header,+,lib/digital_signal/digital_sequence.h,, Header,+,lib/digital_signal/digital_signal.h,, diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv index d856dc694..fed083cad 100644 --- a/targets/f7/api_symbols.csv +++ b/targets/f7/api_symbols.csv @@ -41,6 +41,7 @@ Header,+,applications/services/storage/storage.h,, Header,+,lib/bit_lib/bit_lib.h,, Header,+,lib/ble_profile/extra_profiles/hid_profile.h,, Header,+,lib/ble_profile/extra_services/hid_service.h,, +Header,+,lib/callback-connector/callback-connector.h,, Header,+,lib/datetime/datetime.h,, Header,+,lib/digital_signal/digital_sequence.h,, Header,+,lib/digital_signal/digital_signal.h,, From 71e763d9b3efa735ce7523a3f78badb0248d4202 Mon Sep 17 00:00:00 2001 From: hedger Date: Tue, 20 Feb 2024 02:06:08 +0000 Subject: [PATCH 2/6] fbt: bumped c&cpp standard versions --- applications/drivers/subghz/cc1101_ext/cc1101_ext.c | 6 ++++-- .../example_plugins_advanced/app_api_table.cpp | 4 ++-- applications/main/nfc/api/nfc_app_api_table.cpp | 4 ++-- .../services/loader/firmware_api/firmware_api.cpp | 8 ++++---- .../system/js_app/plugin_api/app_api_table.cpp | 4 ++-- site_scons/cc.scons | 4 ++-- targets/f7/furi_hal/furi_hal_ibutton.c | 3 ++- targets/f7/furi_hal/furi_hal_infrared.c | 10 +++++++--- targets/f7/furi_hal/furi_hal_nfc_irq.c | 3 ++- targets/f7/furi_hal/furi_hal_rfid.c | 3 ++- targets/f7/furi_hal/furi_hal_spi.c | 3 ++- targets/f7/furi_hal/furi_hal_subghz.c | 6 ++++-- targets/f7/src/update.c | 2 +- 13 files changed, 36 insertions(+), 24 deletions(-) diff --git a/applications/drivers/subghz/cc1101_ext/cc1101_ext.c b/applications/drivers/subghz/cc1101_ext/cc1101_ext.c index f8ce82bf3..1242b8857 100644 --- a/applications/drivers/subghz/cc1101_ext/cc1101_ext.c +++ b/applications/drivers/subghz/cc1101_ext/cc1101_ext.c @@ -495,7 +495,8 @@ static bool subghz_device_cc1101_ext_stop_debug() { return ret; } -static void subghz_device_cc1101_ext_capture_ISR() { +static void subghz_device_cc1101_ext_capture_ISR(void* context) { + UNUSED(context); if(!furi_hal_gpio_read(subghz_device_cc1101_ext->g0_pin)) { if(subghz_device_cc1101_ext->async_rx.capture_callback) { if(subghz_device_cc1101_ext->async_mirror_pin != NULL) @@ -674,7 +675,8 @@ static void subghz_device_cc1101_ext_async_tx_refill(uint32_t* buffer, size_t sa } } -static void subghz_device_cc1101_ext_async_tx_dma_isr() { +static void subghz_device_cc1101_ext_async_tx_dma_isr(void* context) { + UNUSED(context); furi_assert(subghz_device_cc1101_ext->state == SubGhzDeviceCC1101ExtStateAsyncTx); #if SUBGHZ_DEVICE_CC1101_EXT_DMA_CH3_CHANNEL == LL_DMA_CHANNEL_3 diff --git a/applications/examples/example_plugins_advanced/app_api_table.cpp b/applications/examples/example_plugins_advanced/app_api_table.cpp index aacfb8c18..db15c84d1 100644 --- a/applications/examples/example_plugins_advanced/app_api_table.cpp +++ b/applications/examples/example_plugins_advanced/app_api_table.cpp @@ -18,8 +18,8 @@ constexpr HashtableApiInterface applicaton_hashtable_api_interface{ .resolver_callback = &elf_resolve_from_hashtable, }, /* pointers to application's API table boundaries */ - .table_cbegin = app_api_table.cbegin(), - .table_cend = app_api_table.cend(), + app_api_table.cbegin(), + app_api_table.cend(), }; /* Casting to generic resolver to use in Composite API resolver */ diff --git a/applications/main/nfc/api/nfc_app_api_table.cpp b/applications/main/nfc/api/nfc_app_api_table.cpp index ca190665b..6a769c9eb 100644 --- a/applications/main/nfc/api/nfc_app_api_table.cpp +++ b/applications/main/nfc/api/nfc_app_api_table.cpp @@ -18,8 +18,8 @@ constexpr HashtableApiInterface nfc_application_hashtable_api_interface{ .resolver_callback = &elf_resolve_from_hashtable, }, /* pointers to application's API table boundaries */ - .table_cbegin = nfc_app_api_table.cbegin(), - .table_cend = nfc_app_api_table.cend(), + nfc_app_api_table.cbegin(), + nfc_app_api_table.cend(), }; /* Casting to generic resolver to use in Composite API resolver */ diff --git a/applications/services/loader/firmware_api/firmware_api.cpp b/applications/services/loader/firmware_api/firmware_api.cpp index 47554f628..833f99abe 100644 --- a/applications/services/loader/firmware_api/firmware_api.cpp +++ b/applications/services/loader/firmware_api/firmware_api.cpp @@ -17,8 +17,8 @@ constexpr HashtableApiInterface mock_elf_api_interface{ .api_version_minor = 0, .resolver_callback = &elf_resolve_from_hashtable, }, - .table_cbegin = nullptr, - .table_cend = nullptr, + nullptr, + nullptr, }; const ElfApiInterface* const firmware_api_interface = &mock_elf_api_interface; @@ -29,8 +29,8 @@ constexpr HashtableApiInterface elf_api_interface{ .api_version_minor = (elf_api_version & 0xFFFF), .resolver_callback = &elf_resolve_from_hashtable, }, - .table_cbegin = elf_api_table.cbegin(), - .table_cend = elf_api_table.cend(), + elf_api_table.cbegin(), + elf_api_table.cend(), }; const ElfApiInterface* const firmware_api_interface = &elf_api_interface; #endif diff --git a/applications/system/js_app/plugin_api/app_api_table.cpp b/applications/system/js_app/plugin_api/app_api_table.cpp index aacfb8c18..db15c84d1 100644 --- a/applications/system/js_app/plugin_api/app_api_table.cpp +++ b/applications/system/js_app/plugin_api/app_api_table.cpp @@ -18,8 +18,8 @@ constexpr HashtableApiInterface applicaton_hashtable_api_interface{ .resolver_callback = &elf_resolve_from_hashtable, }, /* pointers to application's API table boundaries */ - .table_cbegin = app_api_table.cbegin(), - .table_cend = app_api_table.cend(), + app_api_table.cbegin(), + app_api_table.cend(), }; /* Casting to generic resolver to use in Composite API resolver */ diff --git a/site_scons/cc.scons b/site_scons/cc.scons index 029f9d415..507cd2d12 100644 --- a/site_scons/cc.scons +++ b/site_scons/cc.scons @@ -3,10 +3,10 @@ Import("ENV") ENV.AppendUnique( CFLAGS=[ - "-std=gnu17", + "-std=gnu2x", ], CXXFLAGS=[ - "-std=c++17", + "-std=c++20", "-fno-rtti", "-fno-use-cxa-atexit", "-fno-exceptions", diff --git a/targets/f7/furi_hal/furi_hal_ibutton.c b/targets/f7/furi_hal/furi_hal_ibutton.c index f8f7e4966..bf1127a85 100644 --- a/targets/f7/furi_hal/furi_hal_ibutton.c +++ b/targets/f7/furi_hal/furi_hal_ibutton.c @@ -25,7 +25,8 @@ typedef struct { FuriHalIbutton* furi_hal_ibutton = NULL; -static void furi_hal_ibutton_emulate_isr() { +static void furi_hal_ibutton_emulate_isr(void* context) { + UNUSED(context); if(LL_TIM_IsActiveFlag_UPDATE(FURI_HAL_IBUTTON_TIMER)) { LL_TIM_ClearFlag_UPDATE(FURI_HAL_IBUTTON_TIMER); furi_hal_ibutton->callback(furi_hal_ibutton->context); diff --git a/targets/f7/furi_hal/furi_hal_infrared.c b/targets/f7/furi_hal/furi_hal_infrared.c index cc4156872..af3c8fc6b 100644 --- a/targets/f7/furi_hal/furi_hal_infrared.c +++ b/targets/f7/furi_hal/furi_hal_infrared.c @@ -94,7 +94,9 @@ static uint8_t furi_hal_infrared_get_current_dma_tx_buffer(void); static void furi_hal_infrared_tx_dma_polarity_isr(); static void furi_hal_infrared_tx_dma_isr(); -static void furi_hal_infrared_tim_rx_isr() { +static void furi_hal_infrared_tim_rx_isr(void* context) { + UNUSED(context); + static uint32_t previous_captured_ch2 = 0; /* Timeout */ @@ -259,7 +261,8 @@ static uint8_t furi_hal_infrared_get_current_dma_tx_buffer(void) { return buf_num; } -static void furi_hal_infrared_tx_dma_polarity_isr() { +static void furi_hal_infrared_tx_dma_polarity_isr(void* context) { + UNUSED(context); #if INFRARED_DMA_CH1_CHANNEL == LL_DMA_CHANNEL_1 if(LL_DMA_IsActiveFlag_TE1(INFRARED_DMA)) { LL_DMA_ClearFlag_TE1(INFRARED_DMA); @@ -281,7 +284,8 @@ static void furi_hal_infrared_tx_dma_polarity_isr() { #endif } -static void furi_hal_infrared_tx_dma_isr() { +static void furi_hal_infrared_tx_dma_isr(void* context) { + UNUSED(context); #if INFRARED_DMA_CH2_CHANNEL == LL_DMA_CHANNEL_2 if(LL_DMA_IsActiveFlag_TE2(INFRARED_DMA)) { LL_DMA_ClearFlag_TE2(INFRARED_DMA); diff --git a/targets/f7/furi_hal/furi_hal_nfc_irq.c b/targets/f7/furi_hal/furi_hal_nfc_irq.c index 170d8dee6..edacc52bf 100644 --- a/targets/f7/furi_hal/furi_hal_nfc_irq.c +++ b/targets/f7/furi_hal/furi_hal_nfc_irq.c @@ -3,7 +3,8 @@ #include #include -static void furi_hal_nfc_int_callback() { +static void furi_hal_nfc_int_callback(void* context) { + UNUSED(context); furi_hal_nfc_event_set(FuriHalNfcEventInternalTypeIrq); } diff --git a/targets/f7/furi_hal/furi_hal_rfid.c b/targets/f7/furi_hal/furi_hal_rfid.c index 67f11d6ff..c40932922 100644 --- a/targets/f7/furi_hal/furi_hal_rfid.c +++ b/targets/f7/furi_hal/furi_hal_rfid.c @@ -315,7 +315,8 @@ void furi_hal_rfid_tim_read_capture_stop() { furi_hal_bus_disable(RFID_CAPTURE_TIM_BUS); } -static void furi_hal_rfid_dma_isr() { +static void furi_hal_rfid_dma_isr(void* context) { + UNUSED(context); #if RFID_DMA_CH1_CHANNEL == LL_DMA_CHANNEL_1 if(LL_DMA_IsActiveFlag_HT1(RFID_DMA)) { LL_DMA_ClearFlag_HT1(RFID_DMA); diff --git a/targets/f7/furi_hal/furi_hal_spi.c b/targets/f7/furi_hal/furi_hal_spi.c index 98ca71af3..d295ad196 100644 --- a/targets/f7/furi_hal/furi_hal_spi.c +++ b/targets/f7/furi_hal/furi_hal_spi.c @@ -169,7 +169,8 @@ bool furi_hal_spi_bus_trx( return ret; } -static void spi_dma_isr() { +static void spi_dma_isr(void* context) { + UNUSED(context); #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); diff --git a/targets/f7/furi_hal/furi_hal_subghz.c b/targets/f7/furi_hal/furi_hal_subghz.c index e73a325aa..392345b0c 100644 --- a/targets/f7/furi_hal/furi_hal_subghz.c +++ b/targets/f7/furi_hal/furi_hal_subghz.c @@ -413,7 +413,8 @@ volatile uint32_t furi_hal_subghz_capture_delta_duration = 0; volatile FuriHalSubGhzCaptureCallback furi_hal_subghz_capture_callback = NULL; volatile void* furi_hal_subghz_capture_callback_context = NULL; -static void furi_hal_subghz_capture_ISR() { +static void furi_hal_subghz_capture_ISR(void* context) { + UNUSED(context); // Channel 1 if(LL_TIM_IsActiveFlag_CC1(TIM2)) { LL_TIM_ClearFlag_CC1(TIM2); @@ -647,7 +648,8 @@ static void furi_hal_subghz_async_tx_refill(uint32_t* buffer, size_t samples) { } } -static void furi_hal_subghz_async_tx_dma_isr() { +static void furi_hal_subghz_async_tx_dma_isr(void* context) { + UNUSED(context); furi_assert(furi_hal_subghz.state == SubGhzStateAsyncTx); #if SUBGHZ_DMA_CH1_CHANNEL == LL_DMA_CHANNEL_1 diff --git a/targets/f7/src/update.c b/targets/f7/src/update.c index e9228a6e9..42ac90e7b 100644 --- a/targets/f7/src/update.c +++ b/targets/f7/src/update.c @@ -18,7 +18,7 @@ static FATFS* pfs = NULL; #define CHECK_FRESULT(result) \ { \ if((result) != FR_OK) { \ - return false; \ + return 0; \ } \ } From ee11aca46421b630ce6d360b4fcdc9f58d6eff51 Mon Sep 17 00:00:00 2001 From: hedger Date: Tue, 20 Feb 2024 02:13:38 +0000 Subject: [PATCH 3/6] accessor: unvolatiled stuff according to c++20 --- applications/debug/accessor/helpers/wiegand.cpp | 12 ++++++------ applications/debug/accessor/helpers/wiegand.h | 14 ++++++-------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/applications/debug/accessor/helpers/wiegand.cpp b/applications/debug/accessor/helpers/wiegand.cpp index 10b284eaa..32b2a1753 100644 --- a/applications/debug/accessor/helpers/wiegand.cpp +++ b/applications/debug/accessor/helpers/wiegand.cpp @@ -2,12 +2,12 @@ #include #include -volatile unsigned long WIEGAND::_cardTempHigh = 0; -volatile unsigned long WIEGAND::_cardTemp = 0; -volatile unsigned long WIEGAND::_lastWiegand = 0; +unsigned long WIEGAND::_cardTempHigh = 0; +unsigned long WIEGAND::_cardTemp = 0; +unsigned long WIEGAND::_lastWiegand = 0; unsigned long WIEGAND::_code = 0; unsigned long WIEGAND::_codeHigh = 0; -volatile int WIEGAND::_bitCount = 0; +int WIEGAND::_bitCount = 0; int WIEGAND::_wiegandType = 0; constexpr uint32_t clocks_in_ms = 64 * 1000; @@ -99,8 +99,8 @@ void WIEGAND::ReadD1() { } unsigned long WIEGAND::GetCardId( - volatile unsigned long* codehigh, - volatile unsigned long* codelow, + unsigned long* codehigh, + unsigned long* codelow, char bitlength) { if(bitlength == 26) // EM tag return (*codelow & 0x1FFFFFE) >> 1; diff --git a/applications/debug/accessor/helpers/wiegand.h b/applications/debug/accessor/helpers/wiegand.h index 8127f4286..be80f94cd 100644 --- a/applications/debug/accessor/helpers/wiegand.h +++ b/applications/debug/accessor/helpers/wiegand.h @@ -15,15 +15,13 @@ public: private: static bool DoWiegandConversion(); - static unsigned long GetCardId( - volatile unsigned long* codehigh, - volatile unsigned long* codelow, - char bitlength); + static unsigned long + GetCardId(unsigned long* codehigh, unsigned long* codelow, char bitlength); - static volatile unsigned long _cardTempHigh; - static volatile unsigned long _cardTemp; - static volatile unsigned long _lastWiegand; - static volatile int _bitCount; + static unsigned long _cardTempHigh; + static unsigned long _cardTemp; + static unsigned long _lastWiegand; + static int _bitCount; static int _wiegandType; static unsigned long _code; static unsigned long _codeHigh; From e143833ee1019cbcbeb3e6ea6ccf31b1891d2968 Mon Sep 17 00:00:00 2001 From: hedger Date: Tue, 20 Feb 2024 02:19:44 +0000 Subject: [PATCH 4/6] battery_test_app: signature fixes --- applications/debug/battery_test_app/battery_test_app.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/applications/debug/battery_test_app/battery_test_app.c b/applications/debug/battery_test_app/battery_test_app.c index eabf3c04b..82c814ef4 100644 --- a/applications/debug/battery_test_app/battery_test_app.c +++ b/applications/debug/battery_test_app/battery_test_app.c @@ -12,7 +12,8 @@ void battery_test_dialog_callback(DialogExResult result, void* context) { } } -uint32_t battery_test_exit_confirm_view() { +uint32_t battery_test_exit_confirm_view(void* context) { + UNUSED(context); return BatteryTestAppViewExitDialog; } From d73191819702cd10be9a4687cad6ff3b660e9ef9 Mon Sep 17 00:00:00 2001 From: hedger Date: Tue, 20 Feb 2024 02:21:49 +0000 Subject: [PATCH 5/6] linter fixes --- applications/debug/accessor/helpers/wiegand.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/applications/debug/accessor/helpers/wiegand.cpp b/applications/debug/accessor/helpers/wiegand.cpp index 32b2a1753..f20b09120 100644 --- a/applications/debug/accessor/helpers/wiegand.cpp +++ b/applications/debug/accessor/helpers/wiegand.cpp @@ -98,10 +98,7 @@ void WIEGAND::ReadD1() { _lastWiegand = DWT->CYCCNT; // Keep track of last wiegand bit received } -unsigned long WIEGAND::GetCardId( - unsigned long* codehigh, - unsigned long* codelow, - char bitlength) { +unsigned long WIEGAND::GetCardId(unsigned long* codehigh, unsigned long* codelow, char bitlength) { if(bitlength == 26) // EM tag return (*codelow & 0x1FFFFFE) >> 1; From bc98c788feb7fc924e2ed58903fac1b5a00ff295 Mon Sep 17 00:00:00 2001 From: hedger Date: Tue, 20 Feb 2024 22:32:39 +0000 Subject: [PATCH 6/6] fbt: moved FBT_NOEVN check to env setup script for *nix --- fbt | 5 +---- scripts/toolchain/fbtenv.sh | 11 +++++++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/fbt b/fbt index e6133d07b..efb031eb2 100755 --- a/fbt +++ b/fbt @@ -12,15 +12,12 @@ SCONS_DEFAULT_FLAGS="--warn=target-not-built"; SCONS_EP="python3 -m SCons"; # public variables -FBT_NOENV="${FBT_NOENV:-""}"; FBT_NO_SYNC="${FBT_NO_SYNC:-""}"; FBT_TOOLCHAIN_PATH="${FBT_TOOLCHAIN_PATH:-$SCRIPT_PATH}"; FBT_VERBOSE="${FBT_VERBOSE:-""}"; FBT_GIT_SUBMODULE_SHALLOW="${FBT_GIT_SUBMODULE_SHALLOW:-""}"; -if [ -z "$FBT_NOENV" ]; then - FBT_VERBOSE="$FBT_VERBOSE" . "$SCRIPT_PATH/scripts/toolchain/fbtenv.sh"; -fi +FBT_VERBOSE="$FBT_VERBOSE" . "$SCRIPT_PATH/scripts/toolchain/fbtenv.sh"; if [ -z "$FBT_VERBOSE" ]; then SCONS_DEFAULT_FLAGS="$SCONS_DEFAULT_FLAGS -Q"; diff --git a/scripts/toolchain/fbtenv.sh b/scripts/toolchain/fbtenv.sh index e1a9905d6..c7007acdc 100755 --- a/scripts/toolchain/fbtenv.sh +++ b/scripts/toolchain/fbtenv.sh @@ -76,6 +76,14 @@ fbtenv_restore_env() unset FBT_TOOLCHAIN_PATH; } +fbtenv_check_if_noenv_set() +{ + if [ -n "${FBT_NOENV:-""}" ]; then + return 1; + fi + return 0; +} + fbtenv_check_sourced() { if [ -n "${FBT_SKIP_CHECK_SOURCED:-""}" ]; then @@ -298,6 +306,9 @@ fbtenv_print_config() fbtenv_main() { + if ! fbtenv_check_if_noenv_set; then + return 0; + fi fbtenv_check_sourced || return 1; fbtenv_get_kernel_type || return 1; if [ "$1" = "--restore" ]; then