mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-04-18 17:35:05 +00:00
code style aligned
added .clang-format and updated projects Furi and NanoBake with it
This commit is contained in:
parent
c4a576e4af
commit
6282011634
67
.clang-format
Normal file
67
.clang-format
Normal file
@ -0,0 +1,67 @@
|
||||
# Generated from CLion C/C++ Code Style settings
|
||||
# See https://clang.llvm.org/docs/ClangFormatStyleOptions.html
|
||||
BasedOnStyle: LLVM
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: BlockIndent
|
||||
AlignConsecutiveAssignments: None
|
||||
AlignOperands: Align
|
||||
AllowAllArgumentsOnNextLine: false
|
||||
AllowAllConstructorInitializersOnNextLine: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: Always
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: All
|
||||
AllowShortIfStatementsOnASingleLine: Always
|
||||
AllowShortLambdasOnASingleLine: All
|
||||
AllowShortLoopsOnASingleLine: true
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakTemplateDeclarations: Yes
|
||||
BreakBeforeBraces: Custom
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterUnion: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: false
|
||||
SplitEmptyRecord: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeTernaryOperators: true
|
||||
BreakConstructorInitializers: BeforeColon
|
||||
BreakInheritanceList: BeforeColon
|
||||
ColumnLimit: 0
|
||||
CompactNamespaces: false
|
||||
ContinuationIndentWidth: 4
|
||||
IndentCaseLabels: true
|
||||
IndentPPDirectives: None
|
||||
IndentWidth: 4
|
||||
KeepEmptyLinesAtTheStartOfBlocks: true
|
||||
MaxEmptyLinesToKeep: 2
|
||||
NamespaceIndentation: All
|
||||
ObjCSpaceAfterProperty: false
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
PointerAlignment: Left
|
||||
ReflowComments: false
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterLogicalNot: false
|
||||
SpaceAfterTemplateKeyword: false
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCpp11BracedList: true
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: false
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
TabWidth: 4
|
||||
UseTab: Never
|
||||
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <furi_config.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -17,25 +17,25 @@ typedef enum {
|
||||
FuriFlagWaitAll = 0x00000001U, ///< Wait for all flags.
|
||||
FuriFlagNoClear = 0x00000002U, ///< Do not clear flags which have been specified to wait for.
|
||||
|
||||
FuriFlagError = 0x80000000U, ///< Error indicator.
|
||||
FuriFlagErrorUnknown = 0xFFFFFFFFU, ///< FuriStatusError (-1).
|
||||
FuriFlagErrorTimeout = 0xFFFFFFFEU, ///< FuriStatusErrorTimeout (-2).
|
||||
FuriFlagErrorResource = 0xFFFFFFFDU, ///< FuriStatusErrorResource (-3).
|
||||
FuriFlagError = 0x80000000U, ///< Error indicator.
|
||||
FuriFlagErrorUnknown = 0xFFFFFFFFU, ///< FuriStatusError (-1).
|
||||
FuriFlagErrorTimeout = 0xFFFFFFFEU, ///< FuriStatusErrorTimeout (-2).
|
||||
FuriFlagErrorResource = 0xFFFFFFFDU, ///< FuriStatusErrorResource (-3).
|
||||
FuriFlagErrorParameter = 0xFFFFFFFCU, ///< FuriStatusErrorParameter (-4).
|
||||
FuriFlagErrorISR = 0xFFFFFFFAU, ///< FuriStatusErrorISR (-6).
|
||||
FuriFlagErrorISR = 0xFFFFFFFAU, ///< FuriStatusErrorISR (-6).
|
||||
} FuriFlag;
|
||||
|
||||
typedef enum {
|
||||
FuriStatusOk = 0, ///< Operation completed successfully.
|
||||
FuriStatusError =
|
||||
-1, ///< Unspecified RTOS error: run-time error but no other error message fits.
|
||||
FuriStatusErrorTimeout = -2, ///< Operation not completed within the timeout period.
|
||||
FuriStatusErrorResource = -3, ///< Resource not available.
|
||||
-1, ///< Unspecified RTOS error: run-time error but no other error message fits.
|
||||
FuriStatusErrorTimeout = -2, ///< Operation not completed within the timeout period.
|
||||
FuriStatusErrorResource = -3, ///< Resource not available.
|
||||
FuriStatusErrorParameter = -4, ///< Parameter error.
|
||||
FuriStatusErrorNoMemory =
|
||||
-5, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation.
|
||||
FuriStatusErrorISR =
|
||||
-6, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines.
|
||||
-6, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines.
|
||||
FuriStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
|
||||
} FuriStatus;
|
||||
|
||||
|
||||
@ -6,8 +6,10 @@
|
||||
#include <freertos/task.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
PLACE_IN_SECTION("MB_MEM2") const char* __furi_check_message = NULL;
|
||||
PLACE_IN_SECTION("MB_MEM2") uint32_t __furi_check_registers[13] = {0};
|
||||
PLACE_IN_SECTION("MB_MEM2")
|
||||
const char* __furi_check_message = NULL;
|
||||
PLACE_IN_SECTION("MB_MEM2")
|
||||
uint32_t __furi_check_registers[13] = {0};
|
||||
|
||||
/** Load r12 value to __furi_check_message and store registers to __furi_check_registers */
|
||||
/*#define GET_MESSAGE_AND_STORE_REGISTERS() \
|
||||
@ -62,7 +64,7 @@ static void __furi_put_uint32_as_hex(uint32_t data) {
|
||||
|
||||
static void __furi_print_register_info() {
|
||||
// Print registers
|
||||
for(uint8_t i = 0; i < 12; i++) {
|
||||
for (uint8_t i = 0; i < 12; i++) {
|
||||
furi_hal_console_puts("\r\n\tr");
|
||||
__furi_put_uint32_as_text(i);
|
||||
furi_hal_console_puts(" : ");
|
||||
@ -79,22 +81,26 @@ static void __furi_print_stack_info() {
|
||||
}
|
||||
|
||||
static void __furi_print_bt_stack_info() {
|
||||
// const FuriHalBtHardfaultInfo* fault_info = furi_hal_bt_get_hardfault_info();
|
||||
// if(fault_info == NULL) {
|
||||
// furi_hal_console_puts("\r\n\tcore2: not faulted");
|
||||
// } else {
|
||||
// furi_hal_console_puts("\r\n\tcore2: hardfaulted.\r\n\tPC: ");
|
||||
// __furi_put_uint32_as_hex(fault_info->source_pc);
|
||||
// furi_hal_console_puts("\r\n\tLR: ");
|
||||
// __furi_put_uint32_as_hex(fault_info->source_lr);
|
||||
// furi_hal_console_puts("\r\n\tSP: ");
|
||||
// __furi_put_uint32_as_hex(fault_info->source_sp);
|
||||
// }
|
||||
/*
|
||||
const FuriHalBtHardfaultInfo* fault_info = furi_hal_bt_get_hardfault_info();
|
||||
if(fault_info == NULL) {
|
||||
furi_hal_console_puts("\r\n\tcore2: not faulted");
|
||||
} else {
|
||||
furi_hal_console_puts("\r\n\tcore2: hardfaulted.\r\n\tPC: ");
|
||||
__furi_put_uint32_as_hex(fault_info->source_pc);
|
||||
furi_hal_console_puts("\r\n\tLR: ");
|
||||
__furi_put_uint32_as_hex(fault_info->source_lr);
|
||||
furi_hal_console_puts("\r\n\tSP: ");
|
||||
__furi_put_uint32_as_hex(fault_info->source_sp);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
static void __furi_print_heap_info() {
|
||||
// furi_hal_console_puts("\r\n\t heap total: ");
|
||||
// __furi_put_uint32_as_text(xPortGetTotalHeapSize());
|
||||
/*
|
||||
furi_hal_console_puts("\r\n\t heap total: ");
|
||||
__furi_put_uint32_as_text(xPortGetTotalHeapSize());
|
||||
*/
|
||||
furi_hal_console_puts("\r\n\t heap free: ");
|
||||
__furi_put_uint32_as_text(xPortGetFreeHeapSize());
|
||||
furi_hal_console_puts("\r\n\t heap watermark: ");
|
||||
@ -102,13 +108,13 @@ static void __furi_print_heap_info() {
|
||||
}
|
||||
|
||||
static void __furi_print_name(bool isr) {
|
||||
if(isr) {
|
||||
if (isr) {
|
||||
furi_hal_console_puts("[ISR ");
|
||||
__furi_put_uint32_as_text(__get_IPSR());
|
||||
furi_hal_console_puts("] ");
|
||||
} else {
|
||||
const char* name = pcTaskGetName(NULL);
|
||||
if(name == NULL) {
|
||||
if (name == NULL) {
|
||||
furi_hal_console_puts("[main] ");
|
||||
} else {
|
||||
furi_hal_console_puts("[");
|
||||
@ -120,15 +126,15 @@ static void __furi_print_name(bool isr) {
|
||||
|
||||
FURI_NORETURN void __furi_crash_implementation() {
|
||||
__disable_irq();
|
||||
// GET_MESSAGE_AND_STORE_REGISTERS();
|
||||
// GET_MESSAGE_AND_STORE_REGISTERS();
|
||||
|
||||
bool isr = FURI_IS_IRQ_MODE();
|
||||
|
||||
if(__furi_check_message == NULL) {
|
||||
if (__furi_check_message == NULL) {
|
||||
__furi_check_message = "Fatal Error";
|
||||
} else if(__furi_check_message == (void*)__FURI_ASSERT_MESSAGE_FLAG) {
|
||||
} else if (__furi_check_message == (void*)__FURI_ASSERT_MESSAGE_FLAG) {
|
||||
__furi_check_message = "furi_assert failed";
|
||||
} else if(__furi_check_message == (void*)__FURI_CHECK_MESSAGE_FLAG) {
|
||||
} else if (__furi_check_message == (void*)__FURI_CHECK_MESSAGE_FLAG) {
|
||||
__furi_check_message = "furi_check failed";
|
||||
}
|
||||
|
||||
@ -137,7 +143,7 @@ FURI_NORETURN void __furi_crash_implementation() {
|
||||
furi_hal_console_puts(__furi_check_message);
|
||||
|
||||
__furi_print_register_info();
|
||||
if(!isr) {
|
||||
if (!isr) {
|
||||
__furi_print_stack_info();
|
||||
}
|
||||
__furi_print_heap_info();
|
||||
@ -147,17 +153,17 @@ FURI_NORETURN void __furi_crash_implementation() {
|
||||
// https://developer.arm.com/documentation/ddi0403/d/Debug-Architecture/ARMv7-M-Debug/Debug-register-support-in-the-SCS/Debug-Halting-Control-and-Status-Register--DHCSR?lang=en
|
||||
// bool debug = CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk;
|
||||
#ifdef FURI_NDEBUG
|
||||
if(debug) {
|
||||
if (debug) {
|
||||
#endif
|
||||
furi_hal_console_puts("\r\nSystem halted. Connect debugger for more info\r\n");
|
||||
furi_hal_console_puts("\033[0m\r\n");
|
||||
// furi_hal_debug_enable();
|
||||
// furi_hal_debug_enable();
|
||||
|
||||
esp_system_abort("crash");
|
||||
esp_system_abort("crash");
|
||||
#ifdef FURI_NDEBUG
|
||||
} else {
|
||||
uint32_t ptr = (uint32_t)__furi_check_message;
|
||||
if(ptr < FLASH_BASE || ptr > (FLASH_BASE + FLASH_SIZE)) {
|
||||
if (ptr < FLASH_BASE || ptr > (FLASH_BASE + FLASH_SIZE)) {
|
||||
ptr = (uint32_t) "Check serial logs";
|
||||
}
|
||||
furi_hal_rtc_set_fault_data(ptr);
|
||||
@ -170,11 +176,11 @@ FURI_NORETURN void __furi_crash_implementation() {
|
||||
}
|
||||
FURI_NORETURN void __furi_halt_implementation() {
|
||||
__disable_irq();
|
||||
// GET_MESSAGE_AND_STORE_REGISTERS();
|
||||
// GET_MESSAGE_AND_STORE_REGISTERS();
|
||||
|
||||
bool isr = FURI_IS_IRQ_MODE();
|
||||
|
||||
if(__furi_check_message == NULL) {
|
||||
if (__furi_check_message == NULL) {
|
||||
__furi_check_message = "System halt requested.";
|
||||
}
|
||||
|
||||
@ -186,8 +192,8 @@ FURI_NORETURN void __furi_halt_implementation() {
|
||||
|
||||
// Check if debug enabled by DAP
|
||||
// https://developer.arm.com/documentation/ddi0403/d/Debug-Architecture/ARMv7-M-Debug/Debug-register-support-in-the-SCS/Debug-Halting-Control-and-Status-Register--DHCSR?lang=en
|
||||
// bool debug = CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk;
|
||||
// RESTORE_REGISTERS_AND_HALT_MCU(true);
|
||||
// bool debug = CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk;
|
||||
// RESTORE_REGISTERS_AND_HALT_MCU(true);
|
||||
|
||||
__builtin_unreachable();
|
||||
}
|
||||
|
||||
@ -13,8 +13,8 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <m-core.h>
|
||||
#include <esp_log.h>
|
||||
#include <m-core.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -35,11 +35,11 @@ FURI_NORETURN void __furi_crash_implementation();
|
||||
FURI_NORETURN void __furi_halt_implementation();
|
||||
|
||||
/** Crash system with message. */
|
||||
#define __furi_crash(message) \
|
||||
do { \
|
||||
#define __furi_crash(message) \
|
||||
do { \
|
||||
ESP_LOGE("crash", "%s\n\tat %s:%d", ((message) ? ((const char*)message) : ""), __FILE__, __LINE__); \
|
||||
__furi_crash_implementation(); \
|
||||
} while(0)
|
||||
__furi_crash_implementation(); \
|
||||
} while (0)
|
||||
|
||||
/** Crash system
|
||||
*
|
||||
@ -48,11 +48,11 @@ FURI_NORETURN void __furi_halt_implementation();
|
||||
#define furi_crash(...) M_APPLY(__furi_crash, M_IF_EMPTY(__VA_ARGS__)((NULL), (__VA_ARGS__)))
|
||||
|
||||
/** Halt system with message. */
|
||||
#define __furi_halt(message) \
|
||||
do { \
|
||||
ESP_LOGE("halt", "%s\n\tat %s:%d", ((message) ? ((const char*)message) : ""), __FILE__, __LINE__); \
|
||||
__furi_halt_implementation(); \
|
||||
} while(0)
|
||||
#define __furi_halt(message) \
|
||||
do { \
|
||||
ESP_LOGE("halt", "%s\n\tat %s:%d", ((message) ? ((const char*)message) : ""), __FILE__, __LINE__); \
|
||||
__furi_halt_implementation(); \
|
||||
} while (0)
|
||||
|
||||
/** Halt system
|
||||
*
|
||||
@ -61,13 +61,13 @@ FURI_NORETURN void __furi_halt_implementation();
|
||||
#define furi_halt(...) M_APPLY(__furi_halt, M_IF_EMPTY(__VA_ARGS__)((NULL), (__VA_ARGS__)))
|
||||
|
||||
/** Check condition and crash if check failed */
|
||||
#define __furi_check(__e, __m) \
|
||||
do { \
|
||||
if(!(__e)) { \
|
||||
#define __furi_check(__e, __m) \
|
||||
do { \
|
||||
if (!(__e)) { \
|
||||
ESP_LOGE("check", "%s", #__e); \
|
||||
__furi_crash(__m); \
|
||||
} \
|
||||
} while(0)
|
||||
__furi_crash(__m); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/** Check condition and crash if failed
|
||||
*
|
||||
@ -79,19 +79,19 @@ FURI_NORETURN void __furi_halt_implementation();
|
||||
|
||||
/** Only in debug build: Assert condition and crash if assert failed */
|
||||
#ifdef FURI_DEBUG
|
||||
#define __furi_assert(__e, __m) \
|
||||
do { \
|
||||
if(!(__e)) { \
|
||||
#define __furi_assert(__e, __m) \
|
||||
do { \
|
||||
if (!(__e)) { \
|
||||
ESP_LOGE("assert", "%s", #__e); \
|
||||
__furi_crash(__m); \
|
||||
} \
|
||||
} while(0)
|
||||
__furi_crash(__m); \
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
#define __furi_assert(__e, __m) \
|
||||
do { \
|
||||
((void)(__e)); \
|
||||
((void)(__m)); \
|
||||
} while(0)
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
/** Assert condition and crash if failed
|
||||
|
||||
@ -51,7 +51,7 @@ extern "C" {
|
||||
typeof(x) SWAP = x; \
|
||||
x = y; \
|
||||
y = SWAP; \
|
||||
} while(0)
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#ifndef PLACE_IN_SECTION
|
||||
@ -84,9 +84,9 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef REVERSE_BYTES_U32
|
||||
#define REVERSE_BYTES_U32(x) \
|
||||
((((x)&0x000000FF) << 24) | (((x)&0x0000FF00) << 8) | (((x)&0x00FF0000) >> 8) | \
|
||||
(((x)&0xFF000000) >> 24))
|
||||
#define REVERSE_BYTES_U32(x) \
|
||||
((((x) & 0x000000FF) << 24) | (((x) & 0x0000FF00) << 8) | (((x) & 0x00FF0000) >> 8) | \
|
||||
(((x) & 0xFF000000) >> 24))
|
||||
#endif
|
||||
|
||||
#ifndef FURI_BIT
|
||||
|
||||
@ -12,9 +12,9 @@ __FuriCriticalInfo __furi_critical_enter(void) {
|
||||
info.from_isr = FURI_IS_ISR();
|
||||
info.kernel_running = (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING);
|
||||
|
||||
if(info.from_isr) {
|
||||
if (info.from_isr) {
|
||||
info.isrm = taskENTER_CRITICAL_FROM_ISR();
|
||||
} else if(info.kernel_running) {
|
||||
} else if (info.kernel_running) {
|
||||
taskENTER_CRITICAL(&prv_critical_mutex);
|
||||
} else {
|
||||
__disable_irq();
|
||||
@ -24,9 +24,9 @@ __FuriCriticalInfo __furi_critical_enter(void) {
|
||||
}
|
||||
|
||||
void __furi_critical_exit(__FuriCriticalInfo info) {
|
||||
if(info.from_isr) {
|
||||
if (info.from_isr) {
|
||||
taskEXIT_CRITICAL_FROM_ISR(info.isrm);
|
||||
} else if(info.kernel_running) {
|
||||
} else if (info.kernel_running) {
|
||||
taskEXIT_CRITICAL(&prv_critical_mutex);
|
||||
} else {
|
||||
__enable_irq();
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include "event_flag.h"
|
||||
#include "common_defines.h"
|
||||
#include "check.h"
|
||||
#include "common_defines.h"
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/event_groups.h>
|
||||
@ -30,9 +30,9 @@ uint32_t furi_event_flag_set(FuriEventFlag* instance, uint32_t flags) {
|
||||
uint32_t rflags;
|
||||
BaseType_t yield;
|
||||
|
||||
if(FURI_IS_IRQ_MODE()) {
|
||||
if (FURI_IS_IRQ_MODE()) {
|
||||
yield = pdFALSE;
|
||||
if(xEventGroupSetBitsFromISR(hEventGroup, (EventBits_t)flags, &yield) == pdFAIL) {
|
||||
if (xEventGroupSetBitsFromISR(hEventGroup, (EventBits_t)flags, &yield) == pdFAIL) {
|
||||
rflags = (uint32_t)FuriFlagErrorResource;
|
||||
} else {
|
||||
rflags = flags;
|
||||
@ -53,10 +53,10 @@ uint32_t furi_event_flag_clear(FuriEventFlag* instance, uint32_t flags) {
|
||||
EventGroupHandle_t hEventGroup = (EventGroupHandle_t)instance;
|
||||
uint32_t rflags;
|
||||
|
||||
if(FURI_IS_IRQ_MODE()) {
|
||||
if (FURI_IS_IRQ_MODE()) {
|
||||
rflags = xEventGroupGetBitsFromISR(hEventGroup);
|
||||
|
||||
if(xEventGroupClearBitsFromISR(hEventGroup, (EventBits_t)flags) == pdFAIL) {
|
||||
if (xEventGroupClearBitsFromISR(hEventGroup, (EventBits_t)flags) == pdFAIL) {
|
||||
rflags = (uint32_t)FuriStatusErrorResource;
|
||||
} else {
|
||||
/* xEventGroupClearBitsFromISR only registers clear operation in the timer command queue. */
|
||||
@ -78,7 +78,7 @@ uint32_t furi_event_flag_get(FuriEventFlag* instance) {
|
||||
EventGroupHandle_t hEventGroup = (EventGroupHandle_t)instance;
|
||||
uint32_t rflags;
|
||||
|
||||
if(FURI_IS_IRQ_MODE()) {
|
||||
if (FURI_IS_IRQ_MODE()) {
|
||||
rflags = xEventGroupGetBitsFromISR(hEventGroup);
|
||||
} else {
|
||||
rflags = xEventGroupGetBits(hEventGroup);
|
||||
@ -92,7 +92,8 @@ uint32_t furi_event_flag_wait(
|
||||
FuriEventFlag* instance,
|
||||
uint32_t flags,
|
||||
uint32_t options,
|
||||
uint32_t timeout) {
|
||||
uint32_t timeout
|
||||
) {
|
||||
furi_assert(!FURI_IS_IRQ_MODE());
|
||||
furi_assert(instance);
|
||||
furi_assert((flags & FURI_EVENT_FLAG_INVALID_BITS) == 0U);
|
||||
@ -102,32 +103,33 @@ uint32_t furi_event_flag_wait(
|
||||
BaseType_t exit_clr;
|
||||
uint32_t rflags;
|
||||
|
||||
if(options & FuriFlagWaitAll) {
|
||||
if (options & FuriFlagWaitAll) {
|
||||
wait_all = pdTRUE;
|
||||
} else {
|
||||
wait_all = pdFAIL;
|
||||
}
|
||||
|
||||
if(options & FuriFlagNoClear) {
|
||||
if (options & FuriFlagNoClear) {
|
||||
exit_clr = pdFAIL;
|
||||
} else {
|
||||
exit_clr = pdTRUE;
|
||||
}
|
||||
|
||||
rflags = xEventGroupWaitBits(
|
||||
hEventGroup, (EventBits_t)flags, exit_clr, wait_all, (TickType_t)timeout);
|
||||
hEventGroup, (EventBits_t)flags, exit_clr, wait_all, (TickType_t)timeout
|
||||
);
|
||||
|
||||
if(options & FuriFlagWaitAll) {
|
||||
if((flags & rflags) != flags) {
|
||||
if(timeout > 0U) {
|
||||
if (options & FuriFlagWaitAll) {
|
||||
if ((flags & rflags) != flags) {
|
||||
if (timeout > 0U) {
|
||||
rflags = (uint32_t)FuriStatusErrorTimeout;
|
||||
} else {
|
||||
rflags = (uint32_t)FuriStatusErrorResource;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if((flags & rflags) == 0U) {
|
||||
if(timeout > 0U) {
|
||||
if ((flags & rflags) == 0U) {
|
||||
if (timeout > 0U) {
|
||||
rflags = (uint32_t)FuriStatusErrorTimeout;
|
||||
} else {
|
||||
rflags = (uint32_t)FuriStatusErrorResource;
|
||||
|
||||
@ -63,7 +63,8 @@ uint32_t furi_event_flag_wait(
|
||||
FuriEventFlag* instance,
|
||||
uint32_t flags,
|
||||
uint32_t options,
|
||||
uint32_t timeout);
|
||||
uint32_t timeout
|
||||
);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
@ -2,18 +2,12 @@
|
||||
#include "common_defines.h"
|
||||
#include "furi_string.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <esp_log.h>
|
||||
#include <memory.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#define TAG "FuriHalConsole"
|
||||
|
||||
#ifdef HEAP_PRINT_DEBUG
|
||||
#define CONSOLE_BAUDRATE 1843200
|
||||
#else
|
||||
#define CONSOLE_BAUDRATE 230400
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
bool alive;
|
||||
FuriHalConsoleTxCallback tx_callback;
|
||||
@ -27,21 +21,14 @@ FuriHalConsole furi_hal_console = {
|
||||
};
|
||||
|
||||
void furi_hal_console_init() {
|
||||
// furi_hal_uart_init(FuriHalUartIdUSART1, CONSOLE_BAUDRATE);
|
||||
furi_hal_console.alive = true;
|
||||
}
|
||||
|
||||
void furi_hal_console_enable() {
|
||||
// furi_hal_uart_set_irq_cb(FuriHalUartIdUSART1, NULL, NULL);
|
||||
// while(!LL_USART_IsActiveFlag_TC(USART1))
|
||||
// ;
|
||||
// furi_hal_uart_set_br(FuriHalUartIdUSART1, CONSOLE_BAUDRATE);
|
||||
furi_hal_console.alive = true;
|
||||
}
|
||||
|
||||
void furi_hal_console_disable() {
|
||||
// while(!LL_USART_IsActiveFlag_TC(USART1))
|
||||
// ;
|
||||
furi_hal_console.alive = false;
|
||||
}
|
||||
|
||||
@ -53,12 +40,10 @@ void furi_hal_console_set_tx_callback(FuriHalConsoleTxCallback callback, void* c
|
||||
}
|
||||
|
||||
void furi_hal_console_tx(const uint8_t* buffer, size_t buffer_size) {
|
||||
if(!furi_hal_console.alive) return;
|
||||
if (!furi_hal_console.alive) return;
|
||||
|
||||
FURI_CRITICAL_ENTER();
|
||||
// Transmit data
|
||||
|
||||
if(furi_hal_console.tx_callback) {
|
||||
if (furi_hal_console.tx_callback) {
|
||||
furi_hal_console.tx_callback(buffer, buffer_size, furi_hal_console.tx_callback_context);
|
||||
}
|
||||
|
||||
@ -67,15 +52,11 @@ void furi_hal_console_tx(const uint8_t* buffer, size_t buffer_size) {
|
||||
safe_buffer[buffer_size] = 0;
|
||||
|
||||
ESP_LOGI(TAG, "%s", safe_buffer);
|
||||
// furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)buffer, buffer_size);
|
||||
//// Wait for TC flag to be raised for last char
|
||||
// while(!LL_USART_IsActiveFlag_TC(USART1))
|
||||
// ;
|
||||
FURI_CRITICAL_EXIT();
|
||||
}
|
||||
|
||||
void furi_hal_console_tx_with_new_line(const uint8_t* buffer, size_t buffer_size) {
|
||||
if(!furi_hal_console.alive) return;
|
||||
if (!furi_hal_console.alive) return;
|
||||
|
||||
FURI_CRITICAL_ENTER();
|
||||
|
||||
@ -84,13 +65,6 @@ void furi_hal_console_tx_with_new_line(const uint8_t* buffer, size_t buffer_size
|
||||
safe_buffer[buffer_size] = 0;
|
||||
ESP_LOGI(TAG, "%s", safe_buffer);
|
||||
|
||||
// Transmit data
|
||||
// furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)buffer, buffer_size);
|
||||
// Transmit new line symbols
|
||||
// furi_hal_uart_tx(FuriHalUartIdUSART1, (uint8_t*)"\r\n", 2);
|
||||
// Wait for TC flag to be raised for last char
|
||||
// while(!LL_USART_IsActiveFlag_TC(USART1))
|
||||
// ;
|
||||
FURI_CRITICAL_EXIT();
|
||||
}
|
||||
|
||||
|
||||
@ -189,7 +189,7 @@ void furi_string_replace_at(FuriString* v, size_t pos, size_t len, const char st
|
||||
}
|
||||
|
||||
size_t
|
||||
furi_string_replace(FuriString* string, FuriString* needle, FuriString* replace, size_t start) {
|
||||
furi_string_replace(FuriString* string, FuriString* needle, FuriString* replace, size_t start) {
|
||||
return string_replace(string->string, needle->string, replace->string, start);
|
||||
}
|
||||
|
||||
@ -266,32 +266,32 @@ void furi_string_utf8_push(FuriString* str, FuriStringUnicodeValue u) {
|
||||
}
|
||||
|
||||
static m_str1ng_utf8_state_e furi_state_to_state(FuriStringUTF8State state) {
|
||||
switch(state) {
|
||||
case FuriStringUTF8StateStarting:
|
||||
return M_STR1NG_UTF8_STARTING;
|
||||
case FuriStringUTF8StateDecoding1:
|
||||
return M_STR1NG_UTF8_DECODING_1;
|
||||
case FuriStringUTF8StateDecoding2:
|
||||
return M_STR1NG_UTF8_DECODING_2;
|
||||
case FuriStringUTF8StateDecoding3:
|
||||
return M_STR1NG_UTF8_DECODING_3;
|
||||
default:
|
||||
return M_STR1NG_UTF8_ERROR;
|
||||
switch (state) {
|
||||
case FuriStringUTF8StateStarting:
|
||||
return M_STR1NG_UTF8_STARTING;
|
||||
case FuriStringUTF8StateDecoding1:
|
||||
return M_STR1NG_UTF8_DECODING_1;
|
||||
case FuriStringUTF8StateDecoding2:
|
||||
return M_STR1NG_UTF8_DECODING_2;
|
||||
case FuriStringUTF8StateDecoding3:
|
||||
return M_STR1NG_UTF8_DECODING_3;
|
||||
default:
|
||||
return M_STR1NG_UTF8_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
static FuriStringUTF8State state_to_furi_state(m_str1ng_utf8_state_e state) {
|
||||
switch(state) {
|
||||
case M_STR1NG_UTF8_STARTING:
|
||||
return FuriStringUTF8StateStarting;
|
||||
case M_STR1NG_UTF8_DECODING_1:
|
||||
return FuriStringUTF8StateDecoding1;
|
||||
case M_STR1NG_UTF8_DECODING_2:
|
||||
return FuriStringUTF8StateDecoding2;
|
||||
case M_STR1NG_UTF8_DECODING_3:
|
||||
return FuriStringUTF8StateDecoding3;
|
||||
default:
|
||||
return FuriStringUTF8StateError;
|
||||
switch (state) {
|
||||
case M_STR1NG_UTF8_STARTING:
|
||||
return FuriStringUTF8StateStarting;
|
||||
case M_STR1NG_UTF8_DECODING_1:
|
||||
return FuriStringUTF8StateDecoding1;
|
||||
case M_STR1NG_UTF8_DECODING_2:
|
||||
return FuriStringUTF8StateDecoding2;
|
||||
case M_STR1NG_UTF8_DECODING_3:
|
||||
return FuriStringUTF8StateDecoding3;
|
||||
default:
|
||||
return FuriStringUTF8StateError;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -4,11 +4,11 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdarg.h>
|
||||
#include <m-core.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -402,7 +402,7 @@ void furi_string_replace_at(FuriString* string, size_t pos, size_t len, const ch
|
||||
* @return size_t
|
||||
*/
|
||||
size_t
|
||||
furi_string_replace(FuriString* string, FuriString* needle, FuriString* replace, size_t start);
|
||||
furi_string_replace(FuriString* string, FuriString* needle, FuriString* replace, size_t start);
|
||||
|
||||
/**
|
||||
* @brief Replace a C string 'needle' to C string 'replace' in a string from 'start' position.
|
||||
@ -418,7 +418,8 @@ size_t furi_string_replace_str(
|
||||
FuriString* string,
|
||||
const char needle[],
|
||||
const char replace[],
|
||||
size_t start);
|
||||
size_t start
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Replace all occurrences of 'needle' string into 'replace' string.
|
||||
@ -429,7 +430,8 @@ size_t furi_string_replace_str(
|
||||
void furi_string_replace_all(
|
||||
FuriString* string,
|
||||
const FuriString* needle,
|
||||
const FuriString* replace);
|
||||
const FuriString* replace
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Replace all occurrences of 'needle' C string into 'replace' C string.
|
||||
@ -569,25 +571,25 @@ void furi_string_utf8_decode(char c, FuriStringUTF8State* state, FuriStringUnico
|
||||
* @brief Select for 1 argument
|
||||
*/
|
||||
#define FURI_STRING_SELECT1(func1, func2, a) \
|
||||
_Generic((a), char* : func2, const char* : func2, FuriString* : func1, const FuriString* : func1)(a)
|
||||
_Generic((a), char*: func2, const char*: func2, FuriString*: func1, const FuriString*: func1)(a)
|
||||
|
||||
/**
|
||||
* @brief Select for 2 arguments
|
||||
*/
|
||||
#define FURI_STRING_SELECT2(func1, func2, a, b) \
|
||||
_Generic((b), char* : func2, const char* : func2, FuriString* : func1, const FuriString* : func1)(a, b)
|
||||
_Generic((b), char*: func2, const char*: func2, FuriString*: func1, const FuriString*: func1)(a, b)
|
||||
|
||||
/**
|
||||
* @brief Select for 3 arguments
|
||||
*/
|
||||
#define FURI_STRING_SELECT3(func1, func2, a, b, c) \
|
||||
_Generic((b), char* : func2, const char* : func2, FuriString* : func1, const FuriString* : func1)(a, b, c)
|
||||
_Generic((b), char*: func2, const char*: func2, FuriString*: func1, const FuriString*: func1)(a, b, c)
|
||||
|
||||
/**
|
||||
* @brief Select for 4 arguments
|
||||
*/
|
||||
#define FURI_STRING_SELECT4(func1, func2, a, b, c, d) \
|
||||
_Generic((b), char* : func2, const char* : func2, FuriString* : func1, const FuriString* : func1)(a, b, c, d)
|
||||
_Generic((b), char*: func2, const char*: func2, FuriString*: func1, const FuriString*: func1)(a, b, c, d)
|
||||
|
||||
/**
|
||||
* @brief Allocate new FuriString and set it content to string (or C string).
|
||||
@ -633,12 +635,13 @@ void furi_string_utf8_decode(char c, FuriStringUTF8State* state, FuriStringUnico
|
||||
* @brief Search for a string (or C string) in a string
|
||||
* (string, [c]string[, start=0])
|
||||
*/
|
||||
#define furi_string_search(...) \
|
||||
M_APPLY( \
|
||||
FURI_STRING_SELECT3, \
|
||||
furi_string_search, \
|
||||
furi_string_search_str, \
|
||||
M_DEFAULT_ARGS(3, (0), __VA_ARGS__))
|
||||
#define furi_string_search(...) \
|
||||
M_APPLY( \
|
||||
FURI_STRING_SELECT3, \
|
||||
furi_string_search, \
|
||||
furi_string_search_str, \
|
||||
M_DEFAULT_ARGS(3, (0), __VA_ARGS__) \
|
||||
)
|
||||
/**
|
||||
* @brief Search for a C string in a string
|
||||
* (string, cstring[, start=0])
|
||||
@ -687,12 +690,13 @@ void furi_string_utf8_decode(char c, FuriStringUTF8State* state, FuriStringUnico
|
||||
* @brief Replace a string to another string (or C string to another C string) in a string.
|
||||
* (string, [c]string, [c]string[, start=0])
|
||||
*/
|
||||
#define furi_string_replace(...) \
|
||||
M_APPLY( \
|
||||
FURI_STRING_SELECT4, \
|
||||
furi_string_replace, \
|
||||
furi_string_replace_str, \
|
||||
M_DEFAULT_ARGS(4, (0), __VA_ARGS__))
|
||||
#define furi_string_replace(...) \
|
||||
M_APPLY( \
|
||||
FURI_STRING_SELECT4, \
|
||||
furi_string_replace, \
|
||||
furi_string_replace_str, \
|
||||
M_DEFAULT_ARGS(4, (0), __VA_ARGS__) \
|
||||
)
|
||||
|
||||
/**
|
||||
* @brief Replace a C string to another C string in a string.
|
||||
|
||||
@ -11,16 +11,16 @@ bool furi_kernel_is_irq_or_masked() {
|
||||
bool irq = false;
|
||||
BaseType_t state;
|
||||
|
||||
if(FURI_IS_IRQ_MODE()) {
|
||||
if (FURI_IS_IRQ_MODE()) {
|
||||
/* Called from interrupt context */
|
||||
irq = true;
|
||||
} else {
|
||||
/* Get FreeRTOS scheduler state */
|
||||
state = xTaskGetSchedulerState();
|
||||
|
||||
if(state != taskSCHEDULER_NOT_STARTED) {
|
||||
if (state != taskSCHEDULER_NOT_STARTED) {
|
||||
/* Scheduler was started */
|
||||
if(FURI_IS_IRQ_MASKED()) {
|
||||
if (FURI_IS_IRQ_MASKED()) {
|
||||
/* Interrupts are masked */
|
||||
irq = true;
|
||||
}
|
||||
@ -40,20 +40,20 @@ int32_t furi_kernel_lock() {
|
||||
|
||||
int32_t lock;
|
||||
|
||||
switch(xTaskGetSchedulerState()) {
|
||||
case taskSCHEDULER_SUSPENDED:
|
||||
lock = 1;
|
||||
break;
|
||||
switch (xTaskGetSchedulerState()) {
|
||||
case taskSCHEDULER_SUSPENDED:
|
||||
lock = 1;
|
||||
break;
|
||||
|
||||
case taskSCHEDULER_RUNNING:
|
||||
vTaskSuspendAll();
|
||||
lock = 0;
|
||||
break;
|
||||
case taskSCHEDULER_RUNNING:
|
||||
vTaskSuspendAll();
|
||||
lock = 0;
|
||||
break;
|
||||
|
||||
case taskSCHEDULER_NOT_STARTED:
|
||||
default:
|
||||
lock = (int32_t)FuriStatusError;
|
||||
break;
|
||||
case taskSCHEDULER_NOT_STARTED:
|
||||
default:
|
||||
lock = (int32_t)FuriStatusError;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Return previous lock state */
|
||||
@ -65,25 +65,25 @@ int32_t furi_kernel_unlock() {
|
||||
|
||||
int32_t lock;
|
||||
|
||||
switch(xTaskGetSchedulerState()) {
|
||||
case taskSCHEDULER_SUSPENDED:
|
||||
lock = 1;
|
||||
switch (xTaskGetSchedulerState()) {
|
||||
case taskSCHEDULER_SUSPENDED:
|
||||
lock = 1;
|
||||
|
||||
if(xTaskResumeAll() != pdTRUE) {
|
||||
if(xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED) {
|
||||
lock = (int32_t)FuriStatusError;
|
||||
if (xTaskResumeAll() != pdTRUE) {
|
||||
if (xTaskGetSchedulerState() == taskSCHEDULER_SUSPENDED) {
|
||||
lock = (int32_t)FuriStatusError;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case taskSCHEDULER_RUNNING:
|
||||
lock = 0;
|
||||
break;
|
||||
case taskSCHEDULER_RUNNING:
|
||||
lock = 0;
|
||||
break;
|
||||
|
||||
case taskSCHEDULER_NOT_STARTED:
|
||||
default:
|
||||
lock = (int32_t)FuriStatusError;
|
||||
break;
|
||||
case taskSCHEDULER_NOT_STARTED:
|
||||
default:
|
||||
lock = (int32_t)FuriStatusError;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Return previous lock state */
|
||||
@ -93,28 +93,28 @@ int32_t furi_kernel_unlock() {
|
||||
int32_t furi_kernel_restore_lock(int32_t lock) {
|
||||
furi_assert(!furi_kernel_is_irq_or_masked());
|
||||
|
||||
switch(xTaskGetSchedulerState()) {
|
||||
case taskSCHEDULER_SUSPENDED:
|
||||
case taskSCHEDULER_RUNNING:
|
||||
if(lock == 1) {
|
||||
vTaskSuspendAll();
|
||||
} else {
|
||||
if(lock != 0) {
|
||||
lock = (int32_t)FuriStatusError;
|
||||
switch (xTaskGetSchedulerState()) {
|
||||
case taskSCHEDULER_SUSPENDED:
|
||||
case taskSCHEDULER_RUNNING:
|
||||
if (lock == 1) {
|
||||
vTaskSuspendAll();
|
||||
} else {
|
||||
if(xTaskResumeAll() != pdTRUE) {
|
||||
if(xTaskGetSchedulerState() != taskSCHEDULER_RUNNING) {
|
||||
lock = (int32_t)FuriStatusError;
|
||||
if (lock != 0) {
|
||||
lock = (int32_t)FuriStatusError;
|
||||
} else {
|
||||
if (xTaskResumeAll() != pdTRUE) {
|
||||
if (xTaskGetSchedulerState() != taskSCHEDULER_RUNNING) {
|
||||
lock = (int32_t)FuriStatusError;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case taskSCHEDULER_NOT_STARTED:
|
||||
default:
|
||||
lock = (int32_t)FuriStatusError;
|
||||
break;
|
||||
case taskSCHEDULER_NOT_STARTED:
|
||||
default:
|
||||
lock = (int32_t)FuriStatusError;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Return new lock state */
|
||||
@ -128,7 +128,7 @@ uint32_t furi_kernel_get_tick_frequency() {
|
||||
|
||||
void furi_delay_tick(uint32_t ticks) {
|
||||
furi_assert(!furi_kernel_is_irq_or_masked());
|
||||
if(ticks == 0U) {
|
||||
if (ticks == 0U) {
|
||||
taskYIELD();
|
||||
} else {
|
||||
vTaskDelay(ticks);
|
||||
@ -148,8 +148,8 @@ FuriStatus furi_delay_until_tick(uint32_t tick) {
|
||||
delay = (TickType_t)tick - tcnt;
|
||||
|
||||
/* Check if target tick has not expired */
|
||||
if((delay != 0U) && (0 == (delay >> (8 * sizeof(TickType_t) - 1)))) {
|
||||
if(xTaskDelayUntil(&tcnt, delay) == pdFALSE) {
|
||||
if ((delay != 0U) && (0 == (delay >> (8 * sizeof(TickType_t) - 1)))) {
|
||||
if (xTaskDelayUntil(&tcnt, delay) == pdFALSE) {
|
||||
/* Did not delay */
|
||||
stat = FuriStatusError;
|
||||
}
|
||||
@ -165,7 +165,7 @@ FuriStatus furi_delay_until_tick(uint32_t tick) {
|
||||
uint32_t furi_get_tick() {
|
||||
TickType_t ticks;
|
||||
|
||||
if(furi_kernel_is_irq_or_masked() != 0U) {
|
||||
if (furi_kernel_is_irq_or_masked() != 0U) {
|
||||
ticks = xTaskGetTickCountFromISR();
|
||||
} else {
|
||||
ticks = xTaskGetTickCount();
|
||||
@ -183,8 +183,8 @@ uint32_t furi_ms_to_ticks(uint32_t milliseconds) {
|
||||
}
|
||||
|
||||
void furi_delay_ms(uint32_t milliseconds) {
|
||||
if(!FURI_IS_ISR() && xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) {
|
||||
if(milliseconds > 0 && milliseconds < portMAX_DELAY - 1) {
|
||||
if (!FURI_IS_ISR() && xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) {
|
||||
if (milliseconds > 0 && milliseconds < portMAX_DELAY - 1) {
|
||||
milliseconds += 1;
|
||||
}
|
||||
#if configTICK_RATE_HZ_RAW == 1000
|
||||
@ -192,7 +192,7 @@ void furi_delay_ms(uint32_t milliseconds) {
|
||||
#else
|
||||
furi_delay_tick(furi_ms_to_ticks(milliseconds));
|
||||
#endif
|
||||
} else if(milliseconds > 0) {
|
||||
} else if (milliseconds > 0) {
|
||||
furi_delay_us(milliseconds * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include "kernel.h"
|
||||
#include "message_queue.h"
|
||||
#include "check.h"
|
||||
#include "kernel.h"
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
#include <freertos/queue.h>
|
||||
@ -22,31 +22,31 @@ void furi_message_queue_free(FuriMessageQueue* instance) {
|
||||
}
|
||||
|
||||
FuriStatus
|
||||
furi_message_queue_put(FuriMessageQueue* instance, const void* msg_ptr, uint32_t timeout) {
|
||||
furi_message_queue_put(FuriMessageQueue* instance, const void* msg_ptr, uint32_t timeout) {
|
||||
QueueHandle_t hQueue = (QueueHandle_t)instance;
|
||||
FuriStatus stat;
|
||||
BaseType_t yield;
|
||||
|
||||
stat = FuriStatusOk;
|
||||
|
||||
if(furi_kernel_is_irq_or_masked() != 0U) {
|
||||
if((hQueue == NULL) || (msg_ptr == NULL) || (timeout != 0U)) {
|
||||
if (furi_kernel_is_irq_or_masked() != 0U) {
|
||||
if ((hQueue == NULL) || (msg_ptr == NULL) || (timeout != 0U)) {
|
||||
stat = FuriStatusErrorParameter;
|
||||
} else {
|
||||
yield = pdFALSE;
|
||||
|
||||
if(xQueueSendToBackFromISR(hQueue, msg_ptr, &yield) != pdTRUE) {
|
||||
if (xQueueSendToBackFromISR(hQueue, msg_ptr, &yield) != pdTRUE) {
|
||||
stat = FuriStatusErrorResource;
|
||||
} else {
|
||||
portYIELD_FROM_ISR(yield);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if((hQueue == NULL) || (msg_ptr == NULL)) {
|
||||
if ((hQueue == NULL) || (msg_ptr == NULL)) {
|
||||
stat = FuriStatusErrorParameter;
|
||||
} else {
|
||||
if(xQueueSendToBack(hQueue, msg_ptr, (TickType_t)timeout) != pdPASS) {
|
||||
if(timeout != 0U) {
|
||||
if (xQueueSendToBack(hQueue, msg_ptr, (TickType_t)timeout) != pdPASS) {
|
||||
if (timeout != 0U) {
|
||||
stat = FuriStatusErrorTimeout;
|
||||
} else {
|
||||
stat = FuriStatusErrorResource;
|
||||
@ -66,24 +66,24 @@ FuriStatus furi_message_queue_get(FuriMessageQueue* instance, void* msg_ptr, uin
|
||||
|
||||
stat = FuriStatusOk;
|
||||
|
||||
if(furi_kernel_is_irq_or_masked() != 0U) {
|
||||
if((hQueue == NULL) || (msg_ptr == NULL) || (timeout != 0U)) {
|
||||
if (furi_kernel_is_irq_or_masked() != 0U) {
|
||||
if ((hQueue == NULL) || (msg_ptr == NULL) || (timeout != 0U)) {
|
||||
stat = FuriStatusErrorParameter;
|
||||
} else {
|
||||
yield = pdFALSE;
|
||||
|
||||
if(xQueueReceiveFromISR(hQueue, msg_ptr, &yield) != pdPASS) {
|
||||
if (xQueueReceiveFromISR(hQueue, msg_ptr, &yield) != pdPASS) {
|
||||
stat = FuriStatusErrorResource;
|
||||
} else {
|
||||
portYIELD_FROM_ISR(yield);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if((hQueue == NULL) || (msg_ptr == NULL)) {
|
||||
if ((hQueue == NULL) || (msg_ptr == NULL)) {
|
||||
stat = FuriStatusErrorParameter;
|
||||
} else {
|
||||
if(xQueueReceive(hQueue, msg_ptr, (TickType_t)timeout) != pdPASS) {
|
||||
if(timeout != 0U) {
|
||||
if (xQueueReceive(hQueue, msg_ptr, (TickType_t)timeout) != pdPASS) {
|
||||
if (timeout != 0U) {
|
||||
stat = FuriStatusErrorTimeout;
|
||||
} else {
|
||||
stat = FuriStatusErrorResource;
|
||||
@ -100,7 +100,7 @@ uint32_t furi_message_queue_get_capacity(FuriMessageQueue* instance) {
|
||||
StaticQueue_t* mq = (StaticQueue_t*)instance;
|
||||
uint32_t capacity;
|
||||
|
||||
if(mq == NULL) {
|
||||
if (mq == NULL) {
|
||||
capacity = 0U;
|
||||
} else {
|
||||
/* capacity = pxQueue->uxLength */
|
||||
@ -115,7 +115,7 @@ uint32_t furi_message_queue_get_message_size(FuriMessageQueue* instance) {
|
||||
StaticQueue_t* mq = (StaticQueue_t*)instance;
|
||||
uint32_t size;
|
||||
|
||||
if(mq == NULL) {
|
||||
if (mq == NULL) {
|
||||
size = 0U;
|
||||
} else {
|
||||
/* size = pxQueue->uxItemSize */
|
||||
@ -130,9 +130,9 @@ uint32_t furi_message_queue_get_count(FuriMessageQueue* instance) {
|
||||
QueueHandle_t hQueue = (QueueHandle_t)instance;
|
||||
UBaseType_t count;
|
||||
|
||||
if(hQueue == NULL) {
|
||||
if (hQueue == NULL) {
|
||||
count = 0U;
|
||||
} else if(furi_kernel_is_irq_or_masked() != 0U) {
|
||||
} else if (furi_kernel_is_irq_or_masked() != 0U) {
|
||||
count = uxQueueMessagesWaitingFromISR(hQueue);
|
||||
} else {
|
||||
count = uxQueueMessagesWaiting(hQueue);
|
||||
@ -147,9 +147,9 @@ uint32_t furi_message_queue_get_space(FuriMessageQueue* instance) {
|
||||
uint32_t space;
|
||||
uint32_t isrm;
|
||||
|
||||
if(mq == NULL) {
|
||||
if (mq == NULL) {
|
||||
space = 0U;
|
||||
} else if(furi_kernel_is_irq_or_masked() != 0U) {
|
||||
} else if (furi_kernel_is_irq_or_masked() != 0U) {
|
||||
isrm = taskENTER_CRITICAL_FROM_ISR();
|
||||
|
||||
/* space = pxQueue->uxLength - pxQueue->uxMessagesWaiting; */
|
||||
@ -168,9 +168,9 @@ FuriStatus furi_message_queue_reset(FuriMessageQueue* instance) {
|
||||
QueueHandle_t hQueue = (QueueHandle_t)instance;
|
||||
FuriStatus stat;
|
||||
|
||||
if(furi_kernel_is_irq_or_masked() != 0U) {
|
||||
if (furi_kernel_is_irq_or_masked() != 0U) {
|
||||
stat = FuriStatusErrorISR;
|
||||
} else if(hQueue == NULL) {
|
||||
} else if (hQueue == NULL) {
|
||||
stat = FuriStatusErrorParameter;
|
||||
} else {
|
||||
stat = FuriStatusOk;
|
||||
|
||||
@ -37,7 +37,7 @@ void furi_message_queue_free(FuriMessageQueue* instance);
|
||||
* @return The furi status.
|
||||
*/
|
||||
FuriStatus
|
||||
furi_message_queue_put(FuriMessageQueue* instance, const void* msg_ptr, uint32_t timeout);
|
||||
furi_message_queue_put(FuriMessageQueue* instance, const void* msg_ptr, uint32_t timeout);
|
||||
|
||||
/** Get message from queue
|
||||
*
|
||||
|
||||
@ -10,9 +10,9 @@ FuriMutex* furi_mutex_alloc(FuriMutexType type) {
|
||||
|
||||
SemaphoreHandle_t hMutex = NULL;
|
||||
|
||||
if(type == FuriMutexTypeNormal) {
|
||||
if (type == FuriMutexTypeNormal) {
|
||||
hMutex = xSemaphoreCreateMutex();
|
||||
} else if(type == FuriMutexTypeRecursive) {
|
||||
} else if (type == FuriMutexTypeRecursive) {
|
||||
hMutex = xSemaphoreCreateRecursiveMutex();
|
||||
} else {
|
||||
furi_crash("Programming error");
|
||||
@ -20,7 +20,7 @@ FuriMutex* furi_mutex_alloc(FuriMutexType type) {
|
||||
|
||||
furi_check(hMutex != NULL);
|
||||
|
||||
if(type == FuriMutexTypeRecursive) {
|
||||
if (type == FuriMutexTypeRecursive) {
|
||||
/* Set LSB as 'recursive mutex flag' */
|
||||
hMutex = (SemaphoreHandle_t)((uint32_t)hMutex | 1U);
|
||||
}
|
||||
@ -48,22 +48,22 @@ FuriStatus furi_mutex_acquire(FuriMutex* instance, uint32_t timeout) {
|
||||
|
||||
stat = FuriStatusOk;
|
||||
|
||||
if(FURI_IS_IRQ_MODE()) {
|
||||
if (FURI_IS_IRQ_MODE()) {
|
||||
stat = FuriStatusErrorISR;
|
||||
} else if(hMutex == NULL) {
|
||||
} else if (hMutex == NULL) {
|
||||
stat = FuriStatusErrorParameter;
|
||||
} else {
|
||||
if(rmtx != 0U) {
|
||||
if(xSemaphoreTakeRecursive(hMutex, timeout) != pdPASS) {
|
||||
if(timeout != 0U) {
|
||||
if (rmtx != 0U) {
|
||||
if (xSemaphoreTakeRecursive(hMutex, timeout) != pdPASS) {
|
||||
if (timeout != 0U) {
|
||||
stat = FuriStatusErrorTimeout;
|
||||
} else {
|
||||
stat = FuriStatusErrorResource;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(xSemaphoreTake(hMutex, timeout) != pdPASS) {
|
||||
if(timeout != 0U) {
|
||||
if (xSemaphoreTake(hMutex, timeout) != pdPASS) {
|
||||
if (timeout != 0U) {
|
||||
stat = FuriStatusErrorTimeout;
|
||||
} else {
|
||||
stat = FuriStatusErrorResource;
|
||||
@ -88,17 +88,17 @@ FuriStatus furi_mutex_release(FuriMutex* instance) {
|
||||
|
||||
stat = FuriStatusOk;
|
||||
|
||||
if(FURI_IS_IRQ_MODE()) {
|
||||
if (FURI_IS_IRQ_MODE()) {
|
||||
stat = FuriStatusErrorISR;
|
||||
} else if(hMutex == NULL) {
|
||||
} else if (hMutex == NULL) {
|
||||
stat = FuriStatusErrorParameter;
|
||||
} else {
|
||||
if(rmtx != 0U) {
|
||||
if(xSemaphoreGiveRecursive(hMutex) != pdPASS) {
|
||||
if (rmtx != 0U) {
|
||||
if (xSemaphoreGiveRecursive(hMutex) != pdPASS) {
|
||||
stat = FuriStatusErrorResource;
|
||||
}
|
||||
} else {
|
||||
if(xSemaphoreGive(hMutex) != pdPASS) {
|
||||
if (xSemaphoreGive(hMutex) != pdPASS) {
|
||||
stat = FuriStatusErrorResource;
|
||||
}
|
||||
}
|
||||
@ -114,7 +114,7 @@ FuriThreadId furi_mutex_get_owner(FuriMutex* instance) {
|
||||
|
||||
hMutex = (SemaphoreHandle_t)((uint32_t)instance & ~1U);
|
||||
|
||||
if((FURI_IS_IRQ_MODE()) || (hMutex == NULL)) {
|
||||
if ((FURI_IS_IRQ_MODE()) || (hMutex == NULL)) {
|
||||
owner = 0;
|
||||
} else {
|
||||
owner = (FuriThreadId)xSemaphoreGetMutexHolder(hMutex);
|
||||
|
||||
@ -40,7 +40,7 @@ void furi_pubsub_free(FuriPubSub* pubsub) {
|
||||
}
|
||||
|
||||
FuriPubSubSubscription*
|
||||
furi_pubsub_subscribe(FuriPubSub* pubsub, FuriPubSubCallback callback, void* callback_context) {
|
||||
furi_pubsub_subscribe(FuriPubSub* pubsub, FuriPubSubCallback callback, void* callback_context) {
|
||||
furi_check(furi_mutex_acquire(pubsub->mutex, FuriWaitForever) == FuriStatusOk);
|
||||
// put uninitialized item to the list
|
||||
FuriPubSubSubscription* item = FuriPubSubSubscriptionList_push_raw(pubsub->items);
|
||||
@ -63,12 +63,12 @@ void furi_pubsub_unsubscribe(FuriPubSub* pubsub, FuriPubSubSubscription* pubsub_
|
||||
|
||||
// iterate over items
|
||||
FuriPubSubSubscriptionList_it_t it;
|
||||
for(FuriPubSubSubscriptionList_it(it, pubsub->items); !FuriPubSubSubscriptionList_end_p(it);
|
||||
FuriPubSubSubscriptionList_next(it)) {
|
||||
for (FuriPubSubSubscriptionList_it(it, pubsub->items); !FuriPubSubSubscriptionList_end_p(it);
|
||||
FuriPubSubSubscriptionList_next(it)) {
|
||||
const FuriPubSubSubscription* item = FuriPubSubSubscriptionList_cref(it);
|
||||
|
||||
// if the iterator is equal to our element
|
||||
if(item == pubsub_subscription) {
|
||||
if (item == pubsub_subscription) {
|
||||
FuriPubSubSubscriptionList_remove(pubsub->items, it);
|
||||
result = true;
|
||||
break;
|
||||
@ -84,8 +84,8 @@ void furi_pubsub_publish(FuriPubSub* pubsub, void* message) {
|
||||
|
||||
// iterate over subscribers
|
||||
FuriPubSubSubscriptionList_it_t it;
|
||||
for(FuriPubSubSubscriptionList_it(it, pubsub->items); !FuriPubSubSubscriptionList_end_p(it);
|
||||
FuriPubSubSubscriptionList_next(it)) {
|
||||
for (FuriPubSubSubscriptionList_it(it, pubsub->items); !FuriPubSubSubscriptionList_end_p(it);
|
||||
FuriPubSubSubscriptionList_next(it)) {
|
||||
const FuriPubSubSubscription* item = FuriPubSubSubscriptionList_cref(it);
|
||||
item->callback(message, item->callback_context);
|
||||
}
|
||||
|
||||
@ -42,7 +42,7 @@ void furi_pubsub_free(FuriPubSub* pubsub);
|
||||
* @return pointer to FuriPubSubSubscription instance
|
||||
*/
|
||||
FuriPubSubSubscription*
|
||||
furi_pubsub_subscribe(FuriPubSub* pubsub, FuriPubSubCallback callback, void* callback_context);
|
||||
furi_pubsub_subscribe(FuriPubSub* pubsub, FuriPubSubCallback callback, void* callback_context);
|
||||
|
||||
/** Unsubscribe from FuriPubSub
|
||||
*
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
#include "record.h"
|
||||
#include "check.h"
|
||||
#include "mutex.h"
|
||||
#include "event_flag.h"
|
||||
#include "mutex.h"
|
||||
|
||||
#include <m-dict.h>
|
||||
#include "m_cstr_dup.h"
|
||||
#include <m-dict.h>
|
||||
|
||||
#define FURI_RECORD_FLAG_READY (0x1)
|
||||
|
||||
@ -46,7 +46,7 @@ void furi_record_init() {
|
||||
static FuriRecordData* furi_record_data_get_or_create(const char* name) {
|
||||
furi_assert(furi_record);
|
||||
FuriRecordData* record_data = furi_record_get(name);
|
||||
if(!record_data) {
|
||||
if (!record_data) {
|
||||
FuriRecordData new_record;
|
||||
new_record.flags = furi_event_flag_alloc();
|
||||
new_record.data = NULL;
|
||||
@ -101,7 +101,7 @@ bool furi_record_destroy(const char* name) {
|
||||
|
||||
FuriRecordData* record_data = furi_record_get(name);
|
||||
furi_assert(record_data);
|
||||
if(record_data->holders_count == 0) {
|
||||
if (record_data->holders_count == 0) {
|
||||
furi_record_erase(name, record_data);
|
||||
ret = true;
|
||||
}
|
||||
@ -127,7 +127,9 @@ void* furi_record_open(const char* name) {
|
||||
record_data->flags,
|
||||
FURI_RECORD_FLAG_READY,
|
||||
FuriFlagWaitAny | FuriFlagNoClear,
|
||||
FuriWaitForever) == FURI_RECORD_FLAG_READY);
|
||||
FuriWaitForever
|
||||
) == FURI_RECORD_FLAG_READY
|
||||
);
|
||||
|
||||
return record_data->data;
|
||||
}
|
||||
|
||||
@ -5,8 +5,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include "core_defines.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -18,11 +18,11 @@ extern "C" {
|
||||
* @param variable_name the name of the variable that is used in the `code`
|
||||
* @param code the code to execute: consider putting it between {}
|
||||
*/
|
||||
#define FURI_RECORD_TRANSACTION(record_name, variable_name, code) \
|
||||
{ \
|
||||
NbGui* (variable_name) = (NbGui*)furi_record_open(record_name); \
|
||||
code \
|
||||
furi_record_close(record_name); \
|
||||
#define FURI_RECORD_TRANSACTION(record_name, variable_name, code) \
|
||||
{ \
|
||||
NbGui*(variable_name) = (NbGui*)furi_record_open(record_name); \
|
||||
code; \
|
||||
furi_record_close(record_name); \
|
||||
}
|
||||
|
||||
/** Initialize record storage For internal use only.
|
||||
|
||||
@ -10,10 +10,10 @@ FuriSemaphore* furi_semaphore_alloc(uint32_t max_count, uint32_t initial_count)
|
||||
furi_assert((max_count > 0U) && (initial_count <= max_count));
|
||||
|
||||
SemaphoreHandle_t hSemaphore = NULL;
|
||||
if(max_count == 1U) {
|
||||
if (max_count == 1U) {
|
||||
hSemaphore = xSemaphoreCreateBinary();
|
||||
if((hSemaphore != NULL) && (initial_count != 0U)) {
|
||||
if(xSemaphoreGive(hSemaphore) != pdPASS) {
|
||||
if ((hSemaphore != NULL) && (initial_count != 0U)) {
|
||||
if (xSemaphoreGive(hSemaphore) != pdPASS) {
|
||||
vSemaphoreDelete(hSemaphore);
|
||||
hSemaphore = NULL;
|
||||
}
|
||||
@ -46,21 +46,21 @@ FuriStatus furi_semaphore_acquire(FuriSemaphore* instance, uint32_t timeout) {
|
||||
|
||||
stat = FuriStatusOk;
|
||||
|
||||
if(FURI_IS_IRQ_MODE()) {
|
||||
if(timeout != 0U) {
|
||||
if (FURI_IS_IRQ_MODE()) {
|
||||
if (timeout != 0U) {
|
||||
stat = FuriStatusErrorParameter;
|
||||
} else {
|
||||
yield = pdFALSE;
|
||||
|
||||
if(xSemaphoreTakeFromISR(hSemaphore, &yield) != pdPASS) {
|
||||
if (xSemaphoreTakeFromISR(hSemaphore, &yield) != pdPASS) {
|
||||
stat = FuriStatusErrorResource;
|
||||
} else {
|
||||
portYIELD_FROM_ISR(yield);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(xSemaphoreTake(hSemaphore, (TickType_t)timeout) != pdPASS) {
|
||||
if(timeout != 0U) {
|
||||
if (xSemaphoreTake(hSemaphore, (TickType_t)timeout) != pdPASS) {
|
||||
if (timeout != 0U) {
|
||||
stat = FuriStatusErrorTimeout;
|
||||
} else {
|
||||
stat = FuriStatusErrorResource;
|
||||
@ -81,16 +81,16 @@ FuriStatus furi_semaphore_release(FuriSemaphore* instance) {
|
||||
|
||||
stat = FuriStatusOk;
|
||||
|
||||
if(FURI_IS_IRQ_MODE()) {
|
||||
if (FURI_IS_IRQ_MODE()) {
|
||||
yield = pdFALSE;
|
||||
|
||||
if(xSemaphoreGiveFromISR(hSemaphore, &yield) != pdTRUE) {
|
||||
if (xSemaphoreGiveFromISR(hSemaphore, &yield) != pdTRUE) {
|
||||
stat = FuriStatusErrorResource;
|
||||
} else {
|
||||
portYIELD_FROM_ISR(yield);
|
||||
}
|
||||
} else {
|
||||
if(xSemaphoreGive(hSemaphore) != pdPASS) {
|
||||
if (xSemaphoreGive(hSemaphore) != pdPASS) {
|
||||
stat = FuriStatusErrorResource;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include "stream_buffer.h"
|
||||
#include "base.h"
|
||||
#include "check.h"
|
||||
#include "stream_buffer.h"
|
||||
#include "common_defines.h"
|
||||
|
||||
#include <freertos/FreeRTOS.h>
|
||||
@ -29,10 +29,11 @@ size_t furi_stream_buffer_send(
|
||||
FuriStreamBuffer* stream_buffer,
|
||||
const void* data,
|
||||
size_t length,
|
||||
uint32_t timeout) {
|
||||
uint32_t timeout
|
||||
) {
|
||||
size_t ret;
|
||||
|
||||
if(FURI_IS_IRQ_MODE()) {
|
||||
if (FURI_IS_IRQ_MODE()) {
|
||||
BaseType_t yield;
|
||||
ret = xStreamBufferSendFromISR(stream_buffer, data, length, &yield);
|
||||
portYIELD_FROM_ISR(yield);
|
||||
@ -47,10 +48,11 @@ size_t furi_stream_buffer_receive(
|
||||
FuriStreamBuffer* stream_buffer,
|
||||
void* data,
|
||||
size_t length,
|
||||
uint32_t timeout) {
|
||||
uint32_t timeout
|
||||
) {
|
||||
size_t ret;
|
||||
|
||||
if(FURI_IS_IRQ_MODE()) {
|
||||
if (FURI_IS_IRQ_MODE()) {
|
||||
BaseType_t yield;
|
||||
ret = xStreamBufferReceiveFromISR(stream_buffer, data, length, &yield);
|
||||
portYIELD_FROM_ISR(yield);
|
||||
@ -78,7 +80,7 @@ bool furi_stream_buffer_is_empty(FuriStreamBuffer* stream_buffer) {
|
||||
};
|
||||
|
||||
FuriStatus furi_stream_buffer_reset(FuriStreamBuffer* stream_buffer) {
|
||||
if(xStreamBufferReset(stream_buffer) == pdPASS) {
|
||||
if (xStreamBufferReset(stream_buffer) == pdPASS) {
|
||||
return FuriStatusOk;
|
||||
} else {
|
||||
return FuriStatusError;
|
||||
|
||||
@ -12,8 +12,10 @@
|
||||
* interrupt that will read from the buffer (the reader).
|
||||
*/
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "base.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -72,7 +74,8 @@ size_t furi_stream_buffer_send(
|
||||
FuriStreamBuffer* stream_buffer,
|
||||
const void* data,
|
||||
size_t length,
|
||||
uint32_t timeout);
|
||||
uint32_t timeout
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Receives bytes from a stream buffer.
|
||||
@ -93,7 +96,8 @@ size_t furi_stream_buffer_receive(
|
||||
FuriStreamBuffer* stream_buffer,
|
||||
void* data,
|
||||
size_t length,
|
||||
uint32_t timeout);
|
||||
uint32_t timeout
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief Queries a stream buffer to see how much data it contains, which is equal to
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#include "thread.h"
|
||||
#include "kernel.h"
|
||||
#include "check.h"
|
||||
#include "common_defines.h"
|
||||
#include "furi_string.h"
|
||||
#include "kernel.h"
|
||||
|
||||
#include <esp_log.h>
|
||||
|
||||
@ -15,6 +15,13 @@
|
||||
|
||||
#define THREAD_NOTIFY_INDEX 1 // Index 0 is used for stream buffers
|
||||
|
||||
// Limits
|
||||
#define MAX_BITS_TASK_NOTIFY 31U
|
||||
#define MAX_BITS_EVENT_GROUPS 24U
|
||||
|
||||
#define THREAD_FLAGS_INVALID_BITS (~((1UL << MAX_BITS_TASK_NOTIFY) - 1U))
|
||||
#define EVENT_FLAGS_INVALID_BITS (~((1UL << MAX_BITS_EVENT_GROUPS) - 1U))
|
||||
|
||||
typedef struct FuriThreadStdout FuriThreadStdout;
|
||||
|
||||
struct FuriThreadStdout {
|
||||
@ -57,7 +64,7 @@ static int32_t __furi_thread_stdout_flush(FuriThread* thread);
|
||||
__attribute__((__noreturn__)) void furi_thread_catch() { //-V1082
|
||||
// If you're here it means you're probably doing something wrong
|
||||
// with critical sections or with scheduler state
|
||||
asm volatile("nop"); // extra magic
|
||||
asm volatile("nop"); // extra magic
|
||||
furi_crash("You are doing it wrong"); //-V779
|
||||
__builtin_unreachable();
|
||||
}
|
||||
@ -65,7 +72,7 @@ __attribute__((__noreturn__)) void furi_thread_catch() { //-V1082
|
||||
static void furi_thread_set_state(FuriThread* thread, FuriThreadState state) {
|
||||
furi_assert(thread);
|
||||
thread->state = state;
|
||||
if(thread->state_callback) {
|
||||
if (thread->state_callback) {
|
||||
thread->state_callback(state, thread->state_context);
|
||||
}
|
||||
}
|
||||
@ -81,32 +88,37 @@ static void furi_thread_body(void* context) {
|
||||
furi_assert(thread->state == FuriThreadStateStarting);
|
||||
furi_thread_set_state(thread, FuriThreadStateRunning);
|
||||
|
||||
// TaskHandle_t task_handle = xTaskGetCurrentTaskHandle();
|
||||
// if(thread->heap_trace_enabled == true) {
|
||||
// memmgr_heap_enable_thread_trace((FuriThreadId)task_handle);
|
||||
// }
|
||||
/*
|
||||
TaskHandle_t task_handle = xTaskGetCurrentTaskHandle();
|
||||
if(thread->heap_trace_enabled == true) {
|
||||
memmgr_heap_enable_thread_trace((FuriThreadId)task_handle);
|
||||
}
|
||||
*/
|
||||
|
||||
thread->ret = thread->callback(thread->context);
|
||||
|
||||
// if(thread->heap_trace_enabled == true) {
|
||||
// furi_delay_ms(33);
|
||||
// thread->heap_size = memmgr_heap_get_thread_memory((FuriThreadId)task_handle);
|
||||
// furi_log_print_format(
|
||||
// thread->heap_size ? FuriLogLevelError : FuriLogLevelInfo,
|
||||
// TAG,
|
||||
// "%s allocation balance: %zu",
|
||||
// thread->name ? thread->name : "Thread",
|
||||
// thread->heap_size);
|
||||
// memmgr_heap_disable_thread_trace((FuriThreadId)task_handle);
|
||||
// }
|
||||
/*
|
||||
if(thread->heap_trace_enabled == true) {
|
||||
furi_delay_ms(33);
|
||||
thread->heap_size = memmgr_heap_get_thread_memory((FuriThreadId)task_handle);
|
||||
furi_log_print_format(
|
||||
thread->heap_size ? FuriLogLevelError : FuriLogLevelInfo,
|
||||
TAG,
|
||||
"%s allocation balance: %zu",
|
||||
thread->name ? thread->name : "Thread",
|
||||
thread->heap_size);
|
||||
memmgr_heap_disable_thread_trace((FuriThreadId)task_handle);
|
||||
}
|
||||
*/
|
||||
|
||||
furi_assert(thread->state == FuriThreadStateRunning);
|
||||
|
||||
if(thread->is_service) {
|
||||
if (thread->is_service) {
|
||||
ESP_LOGI(
|
||||
TAG,
|
||||
"%s service thread TCB memory will not be reclaimed",
|
||||
thread->name ? thread->name : "<unnamed service>");
|
||||
thread->name ? thread->name : "<unnamed service>"
|
||||
);
|
||||
}
|
||||
|
||||
// flush stdout
|
||||
@ -126,11 +138,11 @@ FuriThread* furi_thread_alloc() {
|
||||
thread->is_service = false;
|
||||
|
||||
FuriThread* parent = NULL;
|
||||
if(xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
|
||||
if (xTaskGetSchedulerState() != taskSCHEDULER_NOT_STARTED) {
|
||||
// TLS is not available, if we called not from thread context
|
||||
parent = pvTaskGetThreadLocalStoragePointer(NULL, 0);
|
||||
|
||||
if(parent && parent->appid) {
|
||||
if (parent && parent->appid) {
|
||||
furi_thread_set_appid(thread, parent->appid);
|
||||
} else {
|
||||
furi_thread_set_appid(thread, "unknown");
|
||||
@ -145,7 +157,8 @@ FuriThread* furi_thread_alloc() {
|
||||
thread->heap_trace_enabled = true;
|
||||
} else if(mode == FuriHalRtcHeapTrackModeTree && furi_thread_get_current_id()) {
|
||||
if(parent) thread->heap_trace_enabled = parent->heap_trace_enabled;
|
||||
} else */{
|
||||
} else */
|
||||
{
|
||||
thread->heap_trace_enabled = false;
|
||||
}
|
||||
|
||||
@ -156,7 +169,8 @@ FuriThread* furi_thread_alloc_ex(
|
||||
const char* name,
|
||||
uint32_t stack_size,
|
||||
FuriThreadCallback callback,
|
||||
void* context) {
|
||||
void* context
|
||||
) {
|
||||
FuriThread* thread = furi_thread_alloc();
|
||||
furi_thread_set_name(thread, name);
|
||||
furi_thread_set_stack_size(thread, stack_size);
|
||||
@ -172,8 +186,8 @@ void furi_thread_free(FuriThread* thread) {
|
||||
furi_assert(thread->state == FuriThreadStateStopped);
|
||||
furi_assert(thread->task_handle == NULL);
|
||||
|
||||
if(thread->name) free(thread->name);
|
||||
if(thread->appid) free(thread->appid);
|
||||
if (thread->name) free(thread->name);
|
||||
if (thread->appid) free(thread->appid);
|
||||
furi_string_free(thread->output.buffer);
|
||||
|
||||
free(thread);
|
||||
@ -182,14 +196,14 @@ void furi_thread_free(FuriThread* thread) {
|
||||
void furi_thread_set_name(FuriThread* thread, const char* name) {
|
||||
furi_assert(thread);
|
||||
furi_assert(thread->state == FuriThreadStateStopped);
|
||||
if(thread->name) free(thread->name);
|
||||
if (thread->name) free(thread->name);
|
||||
thread->name = name ? strdup(name) : NULL;
|
||||
}
|
||||
|
||||
void furi_thread_set_appid(FuriThread* thread, const char* appid) {
|
||||
furi_assert(thread);
|
||||
furi_assert(thread->state == FuriThreadStateStopped);
|
||||
if(thread->appid) free(thread->appid);
|
||||
if (thread->appid) free(thread->appid);
|
||||
thread->appid = appid ? strdup(appid) : NULL;
|
||||
}
|
||||
|
||||
@ -267,7 +281,7 @@ void furi_thread_start(FuriThread* thread) {
|
||||
|
||||
uint32_t stack = thread->stack_size / sizeof(StackType_t);
|
||||
UBaseType_t priority = thread->priority ? thread->priority : FuriThreadPriorityNormal;
|
||||
if(thread->is_service) {
|
||||
if (thread->is_service) {
|
||||
thread->task_handle = xTaskCreateStatic(
|
||||
furi_thread_body,
|
||||
thread->name,
|
||||
@ -275,10 +289,12 @@ void furi_thread_start(FuriThread* thread) {
|
||||
thread,
|
||||
priority,
|
||||
malloc(sizeof(StackType_t) * stack),
|
||||
malloc(sizeof(StaticTask_t)));
|
||||
malloc(sizeof(StaticTask_t))
|
||||
);
|
||||
} else {
|
||||
BaseType_t ret = xTaskCreate(
|
||||
furi_thread_body, thread->name, stack, thread, priority, &thread->task_handle);
|
||||
furi_thread_body, thread->name, stack, thread, priority, &thread->task_handle
|
||||
);
|
||||
furi_check(ret == pdPASS);
|
||||
}
|
||||
|
||||
@ -287,7 +303,7 @@ void furi_thread_start(FuriThread* thread) {
|
||||
|
||||
void furi_thread_cleanup_tcb_event(TaskHandle_t task) {
|
||||
FuriThread* thread = pvTaskGetThreadLocalStoragePointer(task, 0);
|
||||
if(thread) {
|
||||
if (thread) {
|
||||
// clear thread local storage
|
||||
vTaskSetThreadLocalStoragePointer(task, 0, NULL);
|
||||
furi_assert(thread->task_handle == task);
|
||||
@ -304,7 +320,7 @@ bool furi_thread_join(FuriThread* thread) {
|
||||
//
|
||||
// If your thread exited, but your app stuck here: some other thread uses
|
||||
// all cpu time, which delays kernel from releasing task handle
|
||||
while(thread->task_handle) {
|
||||
while (thread->task_handle) {
|
||||
furi_delay_ms(10);
|
||||
}
|
||||
|
||||
@ -354,29 +370,23 @@ void furi_thread_yield() {
|
||||
taskYIELD();
|
||||
}
|
||||
|
||||
/* Limits */
|
||||
#define MAX_BITS_TASK_NOTIFY 31U
|
||||
#define MAX_BITS_EVENT_GROUPS 24U
|
||||
|
||||
#define THREAD_FLAGS_INVALID_BITS (~((1UL << MAX_BITS_TASK_NOTIFY) - 1U))
|
||||
#define EVENT_FLAGS_INVALID_BITS (~((1UL << MAX_BITS_EVENT_GROUPS) - 1U))
|
||||
|
||||
uint32_t furi_thread_flags_set(FuriThreadId thread_id, uint32_t flags) {
|
||||
TaskHandle_t hTask = (TaskHandle_t)thread_id;
|
||||
uint32_t rflags;
|
||||
BaseType_t yield;
|
||||
|
||||
if((hTask == NULL) || ((flags & THREAD_FLAGS_INVALID_BITS) != 0U)) {
|
||||
if ((hTask == NULL) || ((flags & THREAD_FLAGS_INVALID_BITS) != 0U)) {
|
||||
rflags = (uint32_t)FuriStatusErrorParameter;
|
||||
} else {
|
||||
rflags = (uint32_t)FuriStatusError;
|
||||
|
||||
if(FURI_IS_IRQ_MODE()) {
|
||||
if (FURI_IS_IRQ_MODE()) {
|
||||
yield = pdFALSE;
|
||||
|
||||
(void)xTaskNotifyIndexedFromISR(hTask, THREAD_NOTIFY_INDEX, flags, eSetBits, &yield);
|
||||
(void)xTaskNotifyAndQueryIndexedFromISR(
|
||||
hTask, THREAD_NOTIFY_INDEX, 0, eNoAction, &rflags, NULL);
|
||||
hTask, THREAD_NOTIFY_INDEX, 0, eNoAction, &rflags, NULL
|
||||
);
|
||||
|
||||
portYIELD_FROM_ISR(yield);
|
||||
} else {
|
||||
@ -392,20 +402,20 @@ uint32_t furi_thread_flags_clear(uint32_t flags) {
|
||||
TaskHandle_t hTask;
|
||||
uint32_t rflags, cflags;
|
||||
|
||||
if(FURI_IS_IRQ_MODE()) {
|
||||
if (FURI_IS_IRQ_MODE()) {
|
||||
rflags = (uint32_t)FuriStatusErrorISR;
|
||||
} else if((flags & THREAD_FLAGS_INVALID_BITS) != 0U) {
|
||||
} else if ((flags & THREAD_FLAGS_INVALID_BITS) != 0U) {
|
||||
rflags = (uint32_t)FuriStatusErrorParameter;
|
||||
} else {
|
||||
hTask = xTaskGetCurrentTaskHandle();
|
||||
|
||||
if(xTaskNotifyAndQueryIndexed(hTask, THREAD_NOTIFY_INDEX, 0, eNoAction, &cflags) ==
|
||||
pdPASS) {
|
||||
if (xTaskNotifyAndQueryIndexed(hTask, THREAD_NOTIFY_INDEX, 0, eNoAction, &cflags) ==
|
||||
pdPASS) {
|
||||
rflags = cflags;
|
||||
cflags &= ~flags;
|
||||
|
||||
if(xTaskNotifyIndexed(hTask, THREAD_NOTIFY_INDEX, cflags, eSetValueWithOverwrite) !=
|
||||
pdPASS) {
|
||||
if (xTaskNotifyIndexed(hTask, THREAD_NOTIFY_INDEX, cflags, eSetValueWithOverwrite) !=
|
||||
pdPASS) {
|
||||
rflags = (uint32_t)FuriStatusError;
|
||||
}
|
||||
} else {
|
||||
@ -421,13 +431,13 @@ uint32_t furi_thread_flags_get(void) {
|
||||
TaskHandle_t hTask;
|
||||
uint32_t rflags;
|
||||
|
||||
if(FURI_IS_IRQ_MODE()) {
|
||||
if (FURI_IS_IRQ_MODE()) {
|
||||
rflags = (uint32_t)FuriStatusErrorISR;
|
||||
} else {
|
||||
hTask = xTaskGetCurrentTaskHandle();
|
||||
|
||||
if(xTaskNotifyAndQueryIndexed(hTask, THREAD_NOTIFY_INDEX, 0, eNoAction, &rflags) !=
|
||||
pdPASS) {
|
||||
if (xTaskNotifyAndQueryIndexed(hTask, THREAD_NOTIFY_INDEX, 0, eNoAction, &rflags) !=
|
||||
pdPASS) {
|
||||
rflags = (uint32_t)FuriStatusError;
|
||||
}
|
||||
}
|
||||
@ -441,12 +451,12 @@ uint32_t furi_thread_flags_wait(uint32_t flags, uint32_t options, uint32_t timeo
|
||||
TickType_t t0, td, tout;
|
||||
BaseType_t rval;
|
||||
|
||||
if(FURI_IS_IRQ_MODE()) {
|
||||
if (FURI_IS_IRQ_MODE()) {
|
||||
rflags = (uint32_t)FuriStatusErrorISR;
|
||||
} else if((flags & THREAD_FLAGS_INVALID_BITS) != 0U) {
|
||||
} else if ((flags & THREAD_FLAGS_INVALID_BITS) != 0U) {
|
||||
rflags = (uint32_t)FuriStatusErrorParameter;
|
||||
} else {
|
||||
if((options & FuriFlagNoClear) == FuriFlagNoClear) {
|
||||
if ((options & FuriFlagNoClear) == FuriFlagNoClear) {
|
||||
clear = 0U;
|
||||
} else {
|
||||
clear = flags;
|
||||
@ -459,24 +469,24 @@ uint32_t furi_thread_flags_wait(uint32_t flags, uint32_t options, uint32_t timeo
|
||||
do {
|
||||
rval = xTaskNotifyWaitIndexed(THREAD_NOTIFY_INDEX, 0, clear, &nval, tout);
|
||||
|
||||
if(rval == pdPASS) {
|
||||
if (rval == pdPASS) {
|
||||
rflags &= flags;
|
||||
rflags |= nval;
|
||||
|
||||
if((options & FuriFlagWaitAll) == FuriFlagWaitAll) {
|
||||
if((flags & rflags) == flags) {
|
||||
if ((options & FuriFlagWaitAll) == FuriFlagWaitAll) {
|
||||
if ((flags & rflags) == flags) {
|
||||
break;
|
||||
} else {
|
||||
if(timeout == 0U) {
|
||||
if (timeout == 0U) {
|
||||
rflags = (uint32_t)FuriStatusErrorResource;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if((flags & rflags) != 0) {
|
||||
if ((flags & rflags) != 0) {
|
||||
break;
|
||||
} else {
|
||||
if(timeout == 0U) {
|
||||
if (timeout == 0U) {
|
||||
rflags = (uint32_t)FuriStatusErrorResource;
|
||||
break;
|
||||
}
|
||||
@ -486,19 +496,19 @@ uint32_t furi_thread_flags_wait(uint32_t flags, uint32_t options, uint32_t timeo
|
||||
/* Update timeout */
|
||||
td = xTaskGetTickCount() - t0;
|
||||
|
||||
if(td > tout) {
|
||||
if (td > tout) {
|
||||
tout = 0;
|
||||
} else {
|
||||
tout -= td;
|
||||
}
|
||||
} else {
|
||||
if(timeout == 0) {
|
||||
if (timeout == 0) {
|
||||
rflags = (uint32_t)FuriStatusErrorResource;
|
||||
} else {
|
||||
rflags = (uint32_t)FuriStatusErrorTimeout;
|
||||
}
|
||||
}
|
||||
} while(rval != pdFAIL);
|
||||
} while (rval != pdFAIL);
|
||||
}
|
||||
|
||||
/* Return flags before clearing */
|
||||
@ -509,7 +519,7 @@ uint32_t furi_thread_enumerate(FuriThreadId* thread_array, uint32_t array_items)
|
||||
uint32_t i, count;
|
||||
TaskStatus_t* task;
|
||||
|
||||
if(FURI_IS_IRQ_MODE() || (thread_array == NULL) || (array_items == 0U)) {
|
||||
if (FURI_IS_IRQ_MODE() || (thread_array == NULL) || (array_items == 0U)) {
|
||||
count = 0U;
|
||||
} else {
|
||||
vTaskSuspendAll();
|
||||
@ -517,10 +527,10 @@ uint32_t furi_thread_enumerate(FuriThreadId* thread_array, uint32_t array_items)
|
||||
count = uxTaskGetNumberOfTasks();
|
||||
task = pvPortMalloc(count * sizeof(TaskStatus_t));
|
||||
|
||||
if(task != NULL) {
|
||||
if (task != NULL) {
|
||||
count = uxTaskGetSystemState(task, count, NULL);
|
||||
|
||||
for(i = 0U; (i < count) && (i < array_items); i++) {
|
||||
for (i = 0U; (i < count) && (i < array_items); i++) {
|
||||
thread_array[i] = (FuriThreadId)task[i].xHandle;
|
||||
}
|
||||
count = i;
|
||||
@ -537,7 +547,7 @@ const char* furi_thread_get_name(FuriThreadId thread_id) {
|
||||
TaskHandle_t hTask = (TaskHandle_t)thread_id;
|
||||
const char* name;
|
||||
|
||||
if(FURI_IS_IRQ_MODE() || (hTask == NULL)) {
|
||||
if (FURI_IS_IRQ_MODE() || (hTask == NULL)) {
|
||||
name = NULL;
|
||||
} else {
|
||||
name = pcTaskGetName(hTask);
|
||||
@ -550,9 +560,9 @@ const char* furi_thread_get_appid(FuriThreadId thread_id) {
|
||||
TaskHandle_t hTask = (TaskHandle_t)thread_id;
|
||||
const char* appid = "system";
|
||||
|
||||
if(!FURI_IS_IRQ_MODE() && (hTask != NULL)) {
|
||||
if (!FURI_IS_IRQ_MODE() && (hTask != NULL)) {
|
||||
FuriThread* thread = (FuriThread*)pvTaskGetThreadLocalStoragePointer(hTask, 0);
|
||||
if(thread) {
|
||||
if (thread) {
|
||||
appid = thread->appid;
|
||||
}
|
||||
}
|
||||
@ -564,7 +574,7 @@ uint32_t furi_thread_get_stack_space(FuriThreadId thread_id) {
|
||||
TaskHandle_t hTask = (TaskHandle_t)thread_id;
|
||||
uint32_t sz;
|
||||
|
||||
if(FURI_IS_IRQ_MODE() || (hTask == NULL)) {
|
||||
if (FURI_IS_IRQ_MODE() || (hTask == NULL)) {
|
||||
sz = 0U;
|
||||
} else {
|
||||
sz = (uint32_t)(uxTaskGetStackHighWaterMark(hTask) * sizeof(StackType_t));
|
||||
@ -574,7 +584,7 @@ uint32_t furi_thread_get_stack_space(FuriThreadId thread_id) {
|
||||
}
|
||||
|
||||
static size_t __furi_thread_stdout_write(FuriThread* thread, const char* data, size_t size) {
|
||||
if(thread->output.write_callback != NULL) {
|
||||
if (thread->output.write_callback != NULL) {
|
||||
thread->output.write_callback(data, size);
|
||||
} else {
|
||||
furi_hal_console_tx((const uint8_t*)data, size);
|
||||
@ -585,7 +595,7 @@ static size_t __furi_thread_stdout_write(FuriThread* thread, const char* data, s
|
||||
static int32_t __furi_thread_stdout_flush(FuriThread* thread) {
|
||||
FuriString* buffer = thread->output.buffer;
|
||||
size_t size = furi_string_size(buffer);
|
||||
if(size > 0) {
|
||||
if (size > 0) {
|
||||
__furi_thread_stdout_write(thread, furi_string_get_cstr(buffer), size);
|
||||
furi_string_reset(buffer);
|
||||
}
|
||||
@ -608,18 +618,18 @@ FuriThreadStdoutWriteCallback furi_thread_get_stdout_callback() {
|
||||
size_t furi_thread_stdout_write(const char* data, size_t size) {
|
||||
FuriThread* thread = furi_thread_get_current();
|
||||
furi_assert(thread);
|
||||
if(size == 0 || data == NULL) {
|
||||
if (size == 0 || data == NULL) {
|
||||
return __furi_thread_stdout_flush(thread);
|
||||
} else {
|
||||
if(data[size - 1] == '\n') {
|
||||
if (data[size - 1] == '\n') {
|
||||
// if the last character is a newline, we can flush buffer and write data as is, wo buffers
|
||||
__furi_thread_stdout_flush(thread);
|
||||
__furi_thread_stdout_write(thread, data, size);
|
||||
} else {
|
||||
// string_cat doesn't work here because we need to write the exact size data
|
||||
for(size_t i = 0; i < size; i++) {
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
furi_string_push_back(thread->output.buffer, data[i]);
|
||||
if(data[i] == '\n') {
|
||||
if (data[i] == '\n') {
|
||||
__furi_thread_stdout_flush(thread);
|
||||
}
|
||||
}
|
||||
@ -642,7 +652,7 @@ void furi_thread_suspend(FuriThreadId thread_id) {
|
||||
|
||||
void furi_thread_resume(FuriThreadId thread_id) {
|
||||
TaskHandle_t hTask = (TaskHandle_t)thread_id;
|
||||
if(FURI_IS_IRQ_MODE()) {
|
||||
if (FURI_IS_IRQ_MODE()) {
|
||||
xTaskResumeFromISR(hTask);
|
||||
} else {
|
||||
vTaskResume(hTask);
|
||||
|
||||
@ -8,8 +8,8 @@
|
||||
#include "base.h"
|
||||
#include "common_defines.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -24,12 +24,12 @@ typedef enum {
|
||||
|
||||
/** FuriThreadPriority */
|
||||
typedef enum {
|
||||
FuriThreadPriorityNone = 0, /**< Uninitialized, choose system default */
|
||||
FuriThreadPriorityIdle = 1, /**< Idle priority */
|
||||
FuriThreadPriorityLowest = 14, /**< Lowest */
|
||||
FuriThreadPriorityLow = 15, /**< Low */
|
||||
FuriThreadPriorityNormal = 16, /**< Normal */
|
||||
FuriThreadPriorityHigh = 17, /**< High */
|
||||
FuriThreadPriorityNone = 0, /**< Uninitialized, choose system default */
|
||||
FuriThreadPriorityIdle = 1, /**< Idle priority */
|
||||
FuriThreadPriorityLowest = 14, /**< Lowest */
|
||||
FuriThreadPriorityLow = 15, /**< Low */
|
||||
FuriThreadPriorityNormal = 16, /**< Normal */
|
||||
FuriThreadPriorityHigh = 17, /**< High */
|
||||
FuriThreadPriorityHighest = 18, /**< Highest */
|
||||
FuriThreadPriorityIsr =
|
||||
(FURI_CONFIG_THREAD_MAX_PRIORITIES - 1), /**< Deferred ISR (highest possible) */
|
||||
@ -76,7 +76,8 @@ FuriThread* furi_thread_alloc_ex(
|
||||
const char* name,
|
||||
uint32_t stack_size,
|
||||
FuriThreadCallback callback,
|
||||
void* context);
|
||||
void* context
|
||||
);
|
||||
|
||||
/** Release FuriThread
|
||||
*
|
||||
|
||||
@ -19,7 +19,7 @@ static void TimerCallback(TimerHandle_t hTimer) {
|
||||
/* Remove dynamic allocation flag */
|
||||
callb = (TimerCallback_t*)((uint32_t)callb & ~1U);
|
||||
|
||||
if(callb != NULL) {
|
||||
if (callb != NULL) {
|
||||
callb->func(callb->context);
|
||||
}
|
||||
}
|
||||
@ -40,7 +40,7 @@ FuriTimer* furi_timer_alloc(FuriTimerCallback func, FuriTimerType type, void* co
|
||||
callb->func = func;
|
||||
callb->context = context;
|
||||
|
||||
if(type == FuriTimerTypeOnce) {
|
||||
if (type == FuriTimerTypeOnce) {
|
||||
reload = pdFALSE;
|
||||
} else {
|
||||
reload = pdTRUE;
|
||||
@ -68,9 +68,9 @@ void furi_timer_free(FuriTimer* instance) {
|
||||
|
||||
furi_check(xTimerDelete(hTimer, portMAX_DELAY) == pdPASS);
|
||||
|
||||
while(furi_timer_is_running(instance)) furi_delay_tick(2);
|
||||
while (furi_timer_is_running(instance)) furi_delay_tick(2);
|
||||
|
||||
if((uint32_t)callb & 1U) {
|
||||
if ((uint32_t)callb & 1U) {
|
||||
/* Callback memory was allocated from dynamic pool, clear flag */
|
||||
callb = (TimerCallback_t*)((uint32_t)callb & ~1U);
|
||||
|
||||
@ -87,7 +87,7 @@ FuriStatus furi_timer_start(FuriTimer* instance, uint32_t ticks) {
|
||||
TimerHandle_t hTimer = (TimerHandle_t)instance;
|
||||
FuriStatus stat;
|
||||
|
||||
if(xTimerChangePeriod(hTimer, ticks, portMAX_DELAY) == pdPASS) {
|
||||
if (xTimerChangePeriod(hTimer, ticks, portMAX_DELAY) == pdPASS) {
|
||||
stat = FuriStatusOk;
|
||||
} else {
|
||||
stat = FuriStatusErrorResource;
|
||||
@ -105,8 +105,8 @@ FuriStatus furi_timer_restart(FuriTimer* instance, uint32_t ticks) {
|
||||
TimerHandle_t hTimer = (TimerHandle_t)instance;
|
||||
FuriStatus stat;
|
||||
|
||||
if(xTimerChangePeriod(hTimer, ticks, portMAX_DELAY) == pdPASS &&
|
||||
xTimerReset(hTimer, portMAX_DELAY) == pdPASS) {
|
||||
if (xTimerChangePeriod(hTimer, ticks, portMAX_DELAY) == pdPASS &&
|
||||
xTimerReset(hTimer, portMAX_DELAY) == pdPASS) {
|
||||
stat = FuriStatusOk;
|
||||
} else {
|
||||
stat = FuriStatusErrorResource;
|
||||
@ -148,7 +148,7 @@ uint32_t furi_timer_get_expire_time(FuriTimer* instance) {
|
||||
|
||||
void furi_timer_pending_callback(FuriTimerPendigCallback callback, void* context, uint32_t arg) {
|
||||
BaseType_t ret = pdFAIL;
|
||||
if(furi_kernel_is_irq_or_masked()) {
|
||||
if (furi_kernel_is_irq_or_masked()) {
|
||||
ret = xTimerPendFunctionCallFromISR(callback, context, arg, NULL);
|
||||
} else {
|
||||
ret = xTimerPendFunctionCall(callback, context, arg, FuriWaitForever);
|
||||
@ -162,9 +162,9 @@ void furi_timer_set_thread_priority(FuriTimerThreadPriority priority) {
|
||||
TaskHandle_t task_handle = xTimerGetTimerDaemonTaskHandle();
|
||||
furi_check(task_handle); // Don't call this method before timer task start
|
||||
|
||||
if(priority == FuriTimerThreadPriorityNormal) {
|
||||
if (priority == FuriTimerThreadPriorityNormal) {
|
||||
vTaskPrioritySet(task_handle, configTIMER_TASK_PRIORITY);
|
||||
} else if(priority == FuriTimerThreadPriorityElevated) {
|
||||
} else if (priority == FuriTimerThreadPriorityElevated) {
|
||||
vTaskPrioritySet(task_handle, configMAX_PRIORITIES - 1);
|
||||
} else {
|
||||
furi_crash();
|
||||
|
||||
@ -9,7 +9,7 @@ extern "C" {
|
||||
typedef void (*FuriTimerCallback)(void* context);
|
||||
|
||||
typedef enum {
|
||||
FuriTimerTypeOnce = 0, ///< One-shot timer.
|
||||
FuriTimerTypeOnce = 0, ///< One-shot timer.
|
||||
FuriTimerTypePeriodic = 1 ///< Repeating timer.
|
||||
} FuriTimerType;
|
||||
|
||||
@ -91,7 +91,7 @@ typedef void (*FuriTimerPendigCallback)(void* context, uint32_t arg);
|
||||
void furi_timer_pending_callback(FuriTimerPendigCallback callback, void* context, uint32_t arg);
|
||||
|
||||
typedef enum {
|
||||
FuriTimerThreadPriorityNormal, /**< Lower then other threads */
|
||||
FuriTimerThreadPriorityNormal, /**< Lower then other threads */
|
||||
FuriTimerThreadPriorityElevated, /**< Same as other threads */
|
||||
} FuriTimerThreadPriority;
|
||||
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
idf_component_register(
|
||||
SRC_DIRS "src"
|
||||
"src/applications"
|
||||
"src/applications/system/system_info"
|
||||
"src/applications/services/desktop"
|
||||
"src/applications/services/loader"
|
||||
"src/applications/services/gui"
|
||||
"src/applications"
|
||||
"src/applications/system/system_info"
|
||||
"src/applications/services/desktop"
|
||||
"src/applications/services/loader"
|
||||
"src/applications/services/gui"
|
||||
INCLUDE_DIRS "src"
|
||||
REQUIRES esp_lvgl_port esp_lcd esp_lcd_touch driver mlib cmsis_core furi
|
||||
)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include "desktop.h"
|
||||
#include "nb_hardware.h"
|
||||
#include "core_defines.h"
|
||||
#include "nb_hardware.h"
|
||||
|
||||
static int32_t prv_desktop_main(void* param) {
|
||||
UNUSED(param);
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#include "gui_i.h"
|
||||
#include "core_defines.h"
|
||||
#include "record.h"
|
||||
#include "check.h"
|
||||
#include "core_defines.h"
|
||||
#include "gui_i.h"
|
||||
#include "record.h"
|
||||
|
||||
#define TAG "gui"
|
||||
|
||||
@ -13,9 +13,9 @@ ViewPort* gui_view_port_find_enabled(ViewPortArray_t array) {
|
||||
// Iterating backward
|
||||
ViewPortArray_it_t it;
|
||||
ViewPortArray_it_last(it, array);
|
||||
while(!ViewPortArray_end_p(it)) {
|
||||
while (!ViewPortArray_end_p(it)) {
|
||||
ViewPort* view_port = *ViewPortArray_ref(it);
|
||||
if(view_port_is_enabled(view_port)) {
|
||||
if (view_port_is_enabled(view_port)) {
|
||||
return view_port;
|
||||
}
|
||||
ViewPortArray_previous(it);
|
||||
@ -31,9 +31,9 @@ size_t gui_active_view_port_count(NbGui* gui, GuiLayer layer) {
|
||||
gui_lock(gui);
|
||||
ViewPortArray_it_t it;
|
||||
ViewPortArray_it_last(it, gui->layers[layer]);
|
||||
while(!ViewPortArray_end_p(it)) {
|
||||
while (!ViewPortArray_end_p(it)) {
|
||||
ViewPort* view_port = *ViewPortArray_ref(it);
|
||||
if(view_port_is_enabled(view_port)) {
|
||||
if (view_port_is_enabled(view_port)) {
|
||||
ret++;
|
||||
}
|
||||
ViewPortArray_previous(it);
|
||||
@ -67,9 +67,9 @@ void gui_add_view_port(NbGui* gui, ViewPort* view_port, GuiLayer layer) {
|
||||
gui_lock(gui);
|
||||
// Verify that view port is not yet added
|
||||
ViewPortArray_it_t it;
|
||||
for(size_t i = 0; i < GuiLayerMAX; i++) {
|
||||
for (size_t i = 0; i < GuiLayerMAX; i++) {
|
||||
ViewPortArray_it(it, gui->layers[i]);
|
||||
while(!ViewPortArray_end_p(it)) {
|
||||
while (!ViewPortArray_end_p(it)) {
|
||||
furi_assert(*ViewPortArray_ref(it) != view_port);
|
||||
ViewPortArray_next(it);
|
||||
}
|
||||
@ -90,19 +90,21 @@ void gui_remove_view_port(NbGui* gui, ViewPort* view_port) {
|
||||
gui_lock(gui);
|
||||
view_port_gui_set(view_port, NULL);
|
||||
ViewPortArray_it_t it;
|
||||
for(size_t i = 0; i < GuiLayerMAX; i++) {
|
||||
for (size_t i = 0; i < GuiLayerMAX; i++) {
|
||||
ViewPortArray_it(it, gui->layers[i]);
|
||||
while(!ViewPortArray_end_p(it)) {
|
||||
if(*ViewPortArray_ref(it) == view_port) {
|
||||
while (!ViewPortArray_end_p(it)) {
|
||||
if (*ViewPortArray_ref(it) == view_port) {
|
||||
ViewPortArray_remove(gui->layers[i], it);
|
||||
} else {
|
||||
ViewPortArray_next(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
// if(gui->ongoing_input_view_port == view_port) {
|
||||
// gui->ongoing_input_view_port = NULL;
|
||||
// }
|
||||
/*
|
||||
if(gui->ongoing_input_view_port == view_port) {
|
||||
gui->ongoing_input_view_port = NULL;
|
||||
}
|
||||
*/
|
||||
gui_unlock(gui);
|
||||
|
||||
// Request redraw
|
||||
@ -117,10 +119,10 @@ void gui_view_port_send_to_front(NbGui* gui, ViewPort* view_port) {
|
||||
// Remove
|
||||
GuiLayer layer = GuiLayerMAX;
|
||||
ViewPortArray_it_t it;
|
||||
for(size_t i = 0; i < GuiLayerMAX; i++) {
|
||||
for (size_t i = 0; i < GuiLayerMAX; i++) {
|
||||
ViewPortArray_it(it, gui->layers[i]);
|
||||
while(!ViewPortArray_end_p(it)) {
|
||||
if(*ViewPortArray_ref(it) == view_port) {
|
||||
while (!ViewPortArray_end_p(it)) {
|
||||
if (*ViewPortArray_ref(it) == view_port) {
|
||||
ViewPortArray_remove(gui->layers[i], it);
|
||||
furi_assert(layer == GuiLayerMAX);
|
||||
layer = i;
|
||||
@ -146,10 +148,10 @@ void gui_view_port_send_to_back(NbGui* gui, ViewPort* view_port) {
|
||||
// Remove
|
||||
GuiLayer layer = GuiLayerMAX;
|
||||
ViewPortArray_it_t it;
|
||||
for(size_t i = 0; i < GuiLayerMAX; i++) {
|
||||
for (size_t i = 0; i < GuiLayerMAX; i++) {
|
||||
ViewPortArray_it(it, gui->layers[i]);
|
||||
while(!ViewPortArray_end_p(it)) {
|
||||
if(*ViewPortArray_ref(it) == view_port) {
|
||||
while (!ViewPortArray_end_p(it)) {
|
||||
if (*ViewPortArray_ref(it) == view_port) {
|
||||
ViewPortArray_remove(gui->layers[i], it);
|
||||
furi_assert(layer == GuiLayerMAX);
|
||||
layer = i;
|
||||
@ -185,18 +187,18 @@ NbGui* gui_alloc() {
|
||||
gui->lvgl_parent = lv_scr_act();
|
||||
gui->lockdown = false;
|
||||
furi_check(gui->mutex);
|
||||
for(size_t i = 0; i < GuiLayerMAX; i++) {
|
||||
for (size_t i = 0; i < GuiLayerMAX; i++) {
|
||||
ViewPortArray_init(gui->layers[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
/*
|
||||
// Input
|
||||
gui->input_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
|
||||
gui->input_events = furi_record_open(RECORD_INPUT_EVENTS);
|
||||
|
||||
furi_check(gui->input_events);
|
||||
furi_pubsub_subscribe(gui->input_events, gui_input_events_callback, gui);
|
||||
*/
|
||||
*/
|
||||
return gui;
|
||||
}
|
||||
|
||||
@ -213,13 +215,13 @@ __attribute((__noreturn__)) int32_t prv_gui_main(void* parameter) {
|
||||
FuriWaitForever
|
||||
);
|
||||
// Process and dispatch input
|
||||
if (flags & GUI_THREAD_FLAG_INPUT) {
|
||||
// // Process till queue become empty
|
||||
// InputEvent input_event;
|
||||
// while(furi_message_queue_get(gui->input_queue, &input_event, 0) == FuriStatusOk) {
|
||||
// gui_input(gui, &input_event);
|
||||
// }
|
||||
}
|
||||
/*if (flags & GUI_THREAD_FLAG_INPUT) {
|
||||
// Process till queue become empty
|
||||
InputEvent input_event;
|
||||
while(furi_message_queue_get(gui->input_queue, &input_event, 0) == FuriStatusOk) {
|
||||
gui_input(gui, &input_event);
|
||||
}
|
||||
}*/
|
||||
// Process and dispatch draw call
|
||||
if (flags & GUI_THREAD_FLAG_DRAW) {
|
||||
// Clear flags that arrived on input step
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "view_port.h"
|
||||
#include "lvgl.h"
|
||||
#include "nb_app.h"
|
||||
#include "view_port.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -24,7 +24,7 @@ typedef enum {
|
||||
|
||||
GuiLayerWindow, /**< Window layer, status bar is shown */
|
||||
|
||||
GuiLayerStatusBarLeft, /**< Status bar left-side layer, auto-layout */
|
||||
GuiLayerStatusBarLeft, /**< Status bar left-side layer, auto-layout */
|
||||
GuiLayerStatusBarRight, /**< Status bar right-side layer, auto-layout */
|
||||
|
||||
GuiLayerFullscreen, /**< Fullscreen layer, no status bar */
|
||||
@ -37,7 +37,8 @@ typedef void (*GuiCanvasCommitCallback)(
|
||||
uint8_t* data,
|
||||
size_t size,
|
||||
CanvasOrientation orientation,
|
||||
void* context);
|
||||
void* context
|
||||
);
|
||||
|
||||
#define RECORD_GUI "gui"
|
||||
|
||||
|
||||
@ -1,169 +1,175 @@
|
||||
#include "gui_i.h"
|
||||
#include "check.h"
|
||||
#include "gui_i.h"
|
||||
|
||||
static void gui_redraw_status_bar(NbGui* gui, bool need_attention) {
|
||||
// ViewPortArray_it_t it;
|
||||
// uint8_t left_used = 0;
|
||||
// uint8_t right_used = 0;
|
||||
// uint8_t width;
|
||||
//
|
||||
// canvas_frame_set(
|
||||
// gui->lvgl_parent, GUI_STATUS_BAR_X, GUI_STATUS_BAR_Y, GUI_DISPLAY_WIDTH, GUI_STATUS_BAR_HEIGHT);
|
||||
//
|
||||
// /* for support black theme - paint white area and
|
||||
// * draw icon with transparent white color
|
||||
// */
|
||||
// canvas_set_color(gui->canvas, ColorWhite);
|
||||
// canvas_draw_box(gui->canvas, 1, 1, 9, 7);
|
||||
// canvas_draw_box(gui->canvas, 7, 3, 58, 6);
|
||||
// canvas_draw_box(gui->canvas, 61, 1, 32, 7);
|
||||
// canvas_draw_box(gui->canvas, 89, 3, 38, 6);
|
||||
// canvas_set_color(gui->canvas, ColorBlack);
|
||||
// canvas_set_bitmap_mode(gui->canvas, 1);
|
||||
// canvas_draw_icon(gui->canvas, 0, 0, &I_Background_128x11);
|
||||
// canvas_set_bitmap_mode(gui->canvas, 0);
|
||||
//
|
||||
// // Right side
|
||||
// uint8_t x = GUI_DISPLAY_WIDTH - 1;
|
||||
// ViewPortArray_it(it, gui->layers[GuiLayerStatusBarRight]);
|
||||
// while(!ViewPortArray_end_p(it) && right_used < GUI_STATUS_BAR_WIDTH) {
|
||||
// ViewPort* view_port = *ViewPortArray_ref(it);
|
||||
// if(view_port_is_enabled(view_port)) {
|
||||
// width = view_port_get_width(view_port);
|
||||
// if(!width) width = 8;
|
||||
// // Recalculate next position
|
||||
// right_used += (width + 2);
|
||||
// x -= (width + 2);
|
||||
// // Prepare work area background
|
||||
// canvas_frame_set(
|
||||
// gui->canvas,
|
||||
// x - 1,
|
||||
// GUI_STATUS_BAR_Y + 1,
|
||||
// width + 2,
|
||||
// GUI_STATUS_BAR_WORKAREA_HEIGHT + 2);
|
||||
// canvas_set_color(gui->canvas, ColorWhite);
|
||||
// canvas_draw_box(
|
||||
// gui->canvas, 0, 0, canvas_width(gui->canvas), canvas_height(gui->canvas));
|
||||
// canvas_set_color(gui->canvas, ColorBlack);
|
||||
// // ViewPort draw
|
||||
// canvas_frame_set(
|
||||
// gui->canvas, x, GUI_STATUS_BAR_Y + 2, width, GUI_STATUS_BAR_WORKAREA_HEIGHT);
|
||||
// view_port_draw(view_port, gui->canvas);
|
||||
// }
|
||||
// ViewPortArray_next(it);
|
||||
// }
|
||||
// // Draw frame around icons on the right
|
||||
// if(right_used) {
|
||||
// canvas_frame_set(
|
||||
// gui->canvas,
|
||||
// GUI_DISPLAY_WIDTH - 3 - right_used,
|
||||
// GUI_STATUS_BAR_Y,
|
||||
// right_used + 3,
|
||||
// GUI_STATUS_BAR_HEIGHT);
|
||||
// canvas_set_color(gui->canvas, ColorBlack);
|
||||
// canvas_draw_rframe(
|
||||
// gui->canvas, 0, 0, canvas_width(gui->canvas), canvas_height(gui->canvas), 1);
|
||||
// canvas_draw_line(
|
||||
// gui->canvas,
|
||||
// canvas_width(gui->canvas) - 2,
|
||||
// 1,
|
||||
// canvas_width(gui->canvas) - 2,
|
||||
// canvas_height(gui->canvas) - 2);
|
||||
// canvas_draw_line(
|
||||
// gui->canvas,
|
||||
// 1,
|
||||
// canvas_height(gui->canvas) - 2,
|
||||
// canvas_width(gui->canvas) - 2,
|
||||
// canvas_height(gui->canvas) - 2);
|
||||
// }
|
||||
//
|
||||
// // Left side
|
||||
// x = 2;
|
||||
// ViewPortArray_it(it, gui->layers[GuiLayerStatusBarLeft]);
|
||||
// while(!ViewPortArray_end_p(it) && (right_used + left_used) < GUI_STATUS_BAR_WIDTH) {
|
||||
// ViewPort* view_port = *ViewPortArray_ref(it);
|
||||
// if(view_port_is_enabled(view_port)) {
|
||||
// width = view_port_get_width(view_port);
|
||||
// if(!width) width = 8;
|
||||
// // Prepare work area background
|
||||
// canvas_frame_set(
|
||||
// gui->canvas,
|
||||
// x - 1,
|
||||
// GUI_STATUS_BAR_Y + 1,
|
||||
// width + 2,
|
||||
// GUI_STATUS_BAR_WORKAREA_HEIGHT + 2);
|
||||
// canvas_set_color(gui->canvas, ColorWhite);
|
||||
// canvas_draw_box(
|
||||
// gui->canvas, 0, 0, canvas_width(gui->canvas), canvas_height(gui->canvas));
|
||||
// canvas_set_color(gui->canvas, ColorBlack);
|
||||
// // ViewPort draw
|
||||
// canvas_frame_set(
|
||||
// gui->canvas, x, GUI_STATUS_BAR_Y + 2, width, GUI_STATUS_BAR_WORKAREA_HEIGHT);
|
||||
// view_port_draw(view_port, gui->canvas);
|
||||
// // Recalculate next position
|
||||
// left_used += (width + 2);
|
||||
// x += (width + 2);
|
||||
// }
|
||||
// ViewPortArray_next(it);
|
||||
// }
|
||||
// // Extra notification
|
||||
// if(need_attention) {
|
||||
// width = icon_get_width(&I_Hidden_window_9x8);
|
||||
// // Prepare work area background
|
||||
// canvas_frame_set(
|
||||
// gui->canvas,
|
||||
// x - 1,
|
||||
// GUI_STATUS_BAR_Y + 1,
|
||||
// width + 2,
|
||||
// GUI_STATUS_BAR_WORKAREA_HEIGHT + 2);
|
||||
// canvas_set_color(gui->canvas, ColorWhite);
|
||||
// canvas_draw_box(gui->canvas, 0, 0, canvas_width(gui->canvas), canvas_height(gui->canvas));
|
||||
// canvas_set_color(gui->canvas, ColorBlack);
|
||||
// // Draw Icon
|
||||
// canvas_frame_set(
|
||||
// gui->canvas, x, GUI_STATUS_BAR_Y + 2, width, GUI_STATUS_BAR_WORKAREA_HEIGHT);
|
||||
// canvas_draw_icon(gui->canvas, 0, 0, &I_Hidden_window_9x8);
|
||||
// // Recalculate next position
|
||||
// left_used += (width + 2);
|
||||
// x += (width + 2);
|
||||
// }
|
||||
// // Draw frame around icons on the left
|
||||
// if(left_used) {
|
||||
// canvas_frame_set(gui->canvas, 0, 0, left_used + 3, GUI_STATUS_BAR_HEIGHT);
|
||||
// canvas_draw_rframe(
|
||||
// gui->canvas, 0, 0, canvas_width(gui->canvas), canvas_height(gui->canvas), 1);
|
||||
// canvas_draw_line(
|
||||
// gui->canvas,
|
||||
// canvas_width(gui->canvas) - 2,
|
||||
// 1,
|
||||
// canvas_width(gui->canvas) - 2,
|
||||
// canvas_height(gui->canvas) - 2);
|
||||
// canvas_draw_line(
|
||||
// gui->canvas,
|
||||
// 1,
|
||||
// canvas_height(gui->canvas) - 2,
|
||||
// canvas_width(gui->canvas) - 2,
|
||||
// canvas_height(gui->canvas) - 2);
|
||||
// }
|
||||
/*
|
||||
ViewPortArray_it_t it;
|
||||
uint8_t left_used = 0;
|
||||
uint8_t right_used = 0;
|
||||
uint8_t width;
|
||||
|
||||
canvas_frame_set(
|
||||
gui->lvgl_parent, GUI_STATUS_BAR_X, GUI_STATUS_BAR_Y, GUI_DISPLAY_WIDTH, GUI_STATUS_BAR_HEIGHT);
|
||||
|
||||
// for support black theme - paint white area and
|
||||
// draw icon with transparent white color
|
||||
|
||||
canvas_set_color(gui->canvas, ColorWhite);
|
||||
canvas_draw_box(gui->canvas, 1, 1, 9, 7);
|
||||
canvas_draw_box(gui->canvas, 7, 3, 58, 6);
|
||||
canvas_draw_box(gui->canvas, 61, 1, 32, 7);
|
||||
canvas_draw_box(gui->canvas, 89, 3, 38, 6);
|
||||
canvas_set_color(gui->canvas, ColorBlack);
|
||||
canvas_set_bitmap_mode(gui->canvas, 1);
|
||||
canvas_draw_icon(gui->canvas, 0, 0, &I_Background_128x11);
|
||||
canvas_set_bitmap_mode(gui->canvas, 0);
|
||||
|
||||
// Right side
|
||||
uint8_t x = GUI_DISPLAY_WIDTH - 1;
|
||||
ViewPortArray_it(it, gui->layers[GuiLayerStatusBarRight]);
|
||||
while(!ViewPortArray_end_p(it) && right_used < GUI_STATUS_BAR_WIDTH) {
|
||||
ViewPort* view_port = *ViewPortArray_ref(it);
|
||||
if(view_port_is_enabled(view_port)) {
|
||||
width = view_port_get_width(view_port);
|
||||
if(!width) width = 8;
|
||||
// Recalculate next position
|
||||
right_used += (width + 2);
|
||||
x -= (width + 2);
|
||||
// Prepare work area background
|
||||
canvas_frame_set(
|
||||
gui->canvas,
|
||||
x - 1,
|
||||
GUI_STATUS_BAR_Y + 1,
|
||||
width + 2,
|
||||
GUI_STATUS_BAR_WORKAREA_HEIGHT + 2);
|
||||
canvas_set_color(gui->canvas, ColorWhite);
|
||||
canvas_draw_box(
|
||||
gui->canvas, 0, 0, canvas_width(gui->canvas), canvas_height(gui->canvas));
|
||||
canvas_set_color(gui->canvas, ColorBlack);
|
||||
// ViewPort draw
|
||||
canvas_frame_set(
|
||||
gui->canvas, x, GUI_STATUS_BAR_Y + 2, width, GUI_STATUS_BAR_WORKAREA_HEIGHT);
|
||||
view_port_draw(view_port, gui->canvas);
|
||||
}
|
||||
ViewPortArray_next(it);
|
||||
}
|
||||
// Draw frame around icons on the right
|
||||
if(right_used) {
|
||||
canvas_frame_set(
|
||||
gui->canvas,
|
||||
GUI_DISPLAY_WIDTH - 3 - right_used,
|
||||
GUI_STATUS_BAR_Y,
|
||||
right_used + 3,
|
||||
GUI_STATUS_BAR_HEIGHT);
|
||||
canvas_set_color(gui->canvas, ColorBlack);
|
||||
canvas_draw_rframe(
|
||||
gui->canvas, 0, 0, canvas_width(gui->canvas), canvas_height(gui->canvas), 1);
|
||||
canvas_draw_line(
|
||||
gui->canvas,
|
||||
canvas_width(gui->canvas) - 2,
|
||||
1,
|
||||
canvas_width(gui->canvas) - 2,
|
||||
canvas_height(gui->canvas) - 2);
|
||||
canvas_draw_line(
|
||||
gui->canvas,
|
||||
1,
|
||||
canvas_height(gui->canvas) - 2,
|
||||
canvas_width(gui->canvas) - 2,
|
||||
canvas_height(gui->canvas) - 2);
|
||||
}
|
||||
|
||||
// Left side
|
||||
x = 2;
|
||||
ViewPortArray_it(it, gui->layers[GuiLayerStatusBarLeft]);
|
||||
while(!ViewPortArray_end_p(it) && (right_used + left_used) < GUI_STATUS_BAR_WIDTH) {
|
||||
ViewPort* view_port = *ViewPortArray_ref(it);
|
||||
if(view_port_is_enabled(view_port)) {
|
||||
width = view_port_get_width(view_port);
|
||||
if(!width) width = 8;
|
||||
// Prepare work area background
|
||||
canvas_frame_set(
|
||||
gui->canvas,
|
||||
x - 1,
|
||||
GUI_STATUS_BAR_Y + 1,
|
||||
width + 2,
|
||||
GUI_STATUS_BAR_WORKAREA_HEIGHT + 2);
|
||||
canvas_set_color(gui->canvas, ColorWhite);
|
||||
canvas_draw_box(
|
||||
gui->canvas, 0, 0, canvas_width(gui->canvas), canvas_height(gui->canvas));
|
||||
canvas_set_color(gui->canvas, ColorBlack);
|
||||
// ViewPort draw
|
||||
canvas_frame_set(
|
||||
gui->canvas, x, GUI_STATUS_BAR_Y + 2, width, GUI_STATUS_BAR_WORKAREA_HEIGHT);
|
||||
view_port_draw(view_port, gui->canvas);
|
||||
// Recalculate next position
|
||||
left_used += (width + 2);
|
||||
x += (width + 2);
|
||||
}
|
||||
ViewPortArray_next(it);
|
||||
}
|
||||
// Extra notification
|
||||
if(need_attention) {
|
||||
width = icon_get_width(&I_Hidden_window_9x8);
|
||||
// Prepare work area background
|
||||
canvas_frame_set(
|
||||
gui->canvas,
|
||||
x - 1,
|
||||
GUI_STATUS_BAR_Y + 1,
|
||||
width + 2,
|
||||
GUI_STATUS_BAR_WORKAREA_HEIGHT + 2);
|
||||
canvas_set_color(gui->canvas, ColorWhite);
|
||||
canvas_draw_box(gui->canvas, 0, 0, canvas_width(gui->canvas), canvas_height(gui->canvas));
|
||||
canvas_set_color(gui->canvas, ColorBlack);
|
||||
// Draw Icon
|
||||
canvas_frame_set(
|
||||
gui->canvas, x, GUI_STATUS_BAR_Y + 2, width, GUI_STATUS_BAR_WORKAREA_HEIGHT);
|
||||
canvas_draw_icon(gui->canvas, 0, 0, &I_Hidden_window_9x8);
|
||||
// Recalculate next position
|
||||
left_used += (width + 2);
|
||||
x += (width + 2);
|
||||
}
|
||||
// Draw frame around icons on the left
|
||||
if(left_used) {
|
||||
canvas_frame_set(gui->canvas, 0, 0, left_used + 3, GUI_STATUS_BAR_HEIGHT);
|
||||
canvas_draw_rframe(
|
||||
gui->canvas, 0, 0, canvas_width(gui->canvas), canvas_height(gui->canvas), 1);
|
||||
canvas_draw_line(
|
||||
gui->canvas,
|
||||
canvas_width(gui->canvas) - 2,
|
||||
1,
|
||||
canvas_width(gui->canvas) - 2,
|
||||
canvas_height(gui->canvas) - 2);
|
||||
canvas_draw_line(
|
||||
gui->canvas,
|
||||
1,
|
||||
canvas_height(gui->canvas) - 2,
|
||||
canvas_width(gui->canvas) - 2,
|
||||
canvas_height(gui->canvas) - 2);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
static bool gui_redraw_window(NbGui* gui) {
|
||||
// canvas_frame_set(gui->lvgl_parent, GUI_WINDOW_X, GUI_WINDOW_Y, GUI_WINDOW_WIDTH, GUI_WINDOW_HEIGHT);
|
||||
// ViewPort* view_port = gui_view_port_find_enabled(gui->layers[GuiLayerWindow]);
|
||||
// if(view_port) {
|
||||
// view_port_draw(view_port, gui->lvgl_parent);
|
||||
// return true;
|
||||
// }
|
||||
/*
|
||||
canvas_frame_set(gui->lvgl_parent, GUI_WINDOW_X, GUI_WINDOW_Y, GUI_WINDOW_WIDTH, GUI_WINDOW_HEIGHT);
|
||||
ViewPort* view_port = gui_view_port_find_enabled(gui->layers[GuiLayerWindow]);
|
||||
if(view_port) {
|
||||
view_port_draw(view_port, gui->lvgl_parent);
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool gui_redraw_desktop(NbGui* gui) {
|
||||
// canvas_frame_set(gui->lvgl_parent, 0, 0, GUI_DISPLAY_WIDTH, GUI_DISPLAY_HEIGHT);
|
||||
// ViewPort* view_port = gui_view_port_find_enabled(gui->layers[GuiLayerDesktop]);
|
||||
// if(view_port) {
|
||||
// view_port_draw(view_port, gui->lvgl_parent);
|
||||
// return true;
|
||||
// }
|
||||
/*
|
||||
canvas_frame_set(gui->lvgl_parent, 0, 0, GUI_DISPLAY_WIDTH, GUI_DISPLAY_HEIGHT);
|
||||
ViewPort* view_port = gui_view_port_find_enabled(gui->layers[GuiLayerDesktop]);
|
||||
if(view_port) {
|
||||
view_port_draw(view_port, gui->lvgl_parent);
|
||||
return true;
|
||||
}
|
||||
*/
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -184,7 +190,7 @@ void gui_redraw(NbGui* gui) {
|
||||
|
||||
lv_obj_clean(gui->lvgl_parent);
|
||||
|
||||
if(gui->lockdown) {
|
||||
if (gui->lockdown) {
|
||||
ESP_LOGI("gui", "gui_redraw with lockdown");
|
||||
gui_redraw_desktop(gui);
|
||||
bool need_attention =
|
||||
|
||||
@ -2,15 +2,15 @@
|
||||
|
||||
#include "gui.h"
|
||||
|
||||
#include <m-array.h>
|
||||
#include <m-algo.h>
|
||||
#include <m-array.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "message_queue.h"
|
||||
#include "mutex.h"
|
||||
#include "pubsub.h"
|
||||
#include "view_port.h"
|
||||
#include "view_port_i.h"
|
||||
#include "message_queue.h"
|
||||
#include "pubsub.h"
|
||||
#include "mutex.h"
|
||||
|
||||
#define GUI_DISPLAY_WIDTH 128
|
||||
#define GUI_DISPLAY_HEIGHT 64
|
||||
@ -55,12 +55,12 @@ struct NbGui {
|
||||
lv_obj_t* lvgl_parent;
|
||||
|
||||
// Input
|
||||
/*
|
||||
/*
|
||||
FuriMessageQueue* input_queue;
|
||||
FuriPubSub* input_events;
|
||||
uint8_t ongoing_input;
|
||||
ViewPort* ongoing_input_view_port;
|
||||
*/
|
||||
*/
|
||||
};
|
||||
|
||||
/** Find enabled ViewPort in ViewPortArray
|
||||
|
||||
@ -1,8 +1,7 @@
|
||||
#include "view_port_i.h"
|
||||
|
||||
#include "check.h"
|
||||
#include "gui.h"
|
||||
#include "gui_i.h"
|
||||
#include "check.h"
|
||||
#include "view_port_i.h"
|
||||
|
||||
#define TAG "viewport"
|
||||
|
||||
@ -10,7 +9,8 @@ _Static_assert(ViewPortOrientationMAX == 4, "Incorrect ViewPortOrientation count
|
||||
_Static_assert(
|
||||
(ViewPortOrientationHorizontal == 0 && ViewPortOrientationHorizontalFlip == 1 &&
|
||||
ViewPortOrientationVertical == 2 && ViewPortOrientationVerticalFlip == 3),
|
||||
"Incorrect ViewPortOrientation order");
|
||||
"Incorrect ViewPortOrientation order"
|
||||
);
|
||||
|
||||
ViewPort* view_port_alloc() {
|
||||
ViewPort* view_port = malloc(sizeof(ViewPort));
|
||||
@ -32,9 +32,9 @@ void view_port_free(ViewPort* view_port) {
|
||||
void view_port_enabled_set(ViewPort* view_port, bool enabled) {
|
||||
furi_assert(view_port);
|
||||
furi_check(furi_mutex_acquire(view_port->mutex, FuriWaitForever) == FuriStatusOk);
|
||||
if(view_port->is_enabled != enabled) {
|
||||
if (view_port->is_enabled != enabled) {
|
||||
view_port->is_enabled = enabled;
|
||||
if(view_port->gui) gui_update(view_port->gui);
|
||||
if (view_port->gui) gui_update(view_port->gui);
|
||||
}
|
||||
furi_check(furi_mutex_release(view_port->mutex) == FuriStatusOk);
|
||||
}
|
||||
@ -60,11 +60,11 @@ void view_port_update(ViewPort* view_port) {
|
||||
|
||||
// We are not going to lockup system, but will notify you instead
|
||||
// Make sure that you don't call viewport methods inside another mutex, especially one that is used in draw call
|
||||
if(furi_mutex_acquire(view_port->mutex, 2) != FuriStatusOk) {
|
||||
if (furi_mutex_acquire(view_port->mutex, 2) != FuriStatusOk) {
|
||||
ESP_LOGW(TAG, "ViewPort lockup: see %s:%d", __FILE__, __LINE__ - 3);
|
||||
}
|
||||
|
||||
if(view_port->gui && view_port->is_enabled) gui_update(view_port->gui);
|
||||
if (view_port->gui && view_port->is_enabled) gui_update(view_port->gui);
|
||||
furi_mutex_release(view_port->mutex);
|
||||
}
|
||||
|
||||
@ -81,7 +81,7 @@ void view_port_draw(ViewPort* view_port, lv_obj_t* parent) {
|
||||
|
||||
// We are not going to lockup system, but will notify you instead
|
||||
// Make sure that you don't call viewport methods inside another mutex, especially one that is used in draw call
|
||||
if(furi_mutex_acquire(view_port->mutex, 2) != FuriStatusOk) {
|
||||
if (furi_mutex_acquire(view_port->mutex, 2) != FuriStatusOk) {
|
||||
ESP_LOGW(TAG, "ViewPort lockup: see %s:%d", __FILE__, __LINE__ - 3);
|
||||
}
|
||||
|
||||
|
||||
@ -64,4 +64,3 @@ void view_port_update(ViewPort* view_port);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "gui_i.h"
|
||||
#include "view_port.h"
|
||||
#include "mutex.h"
|
||||
#include "view_port.h"
|
||||
|
||||
struct ViewPort {
|
||||
NbGui* gui;
|
||||
@ -12,8 +12,10 @@ struct ViewPort {
|
||||
ViewPortDrawCallback draw_callback;
|
||||
void* draw_callback_context;
|
||||
|
||||
// ViewPortInputCallback input_callback;
|
||||
// void* input_callback_context;
|
||||
/*
|
||||
ViewPortInputCallback input_callback;
|
||||
void* input_callback_context;
|
||||
*/
|
||||
};
|
||||
|
||||
/** Set GUI reference.
|
||||
@ -35,10 +37,10 @@ void view_port_gui_set(ViewPort* view_port, NbGui* gui);
|
||||
void view_port_draw(ViewPort* view_port, lv_obj_t* parent);
|
||||
|
||||
/** Process input. Calls input callback.
|
||||
// *
|
||||
// * To be used by GUI, called on input dispatch.
|
||||
// *
|
||||
// * @param view_port ViewPort instance
|
||||
// * @param event pointer to input event
|
||||
// */
|
||||
*
|
||||
* To be used by GUI, called on input dispatch.
|
||||
*
|
||||
* @param view_port ViewPort instance
|
||||
* @param event pointer to input event
|
||||
*/
|
||||
//void view_port_input(ViewPort* view_port, InputEvent* event);
|
||||
|
||||
@ -3,10 +3,12 @@
|
||||
/** ViewPort Input callback
|
||||
* @warning called from GUI thread
|
||||
*/
|
||||
//typedef void (*ViewPortInputCallback)(InputEvent* event, void* context);
|
||||
/*
|
||||
typedef void (*ViewPortInputCallback)(InputEvent* event, void* context);
|
||||
|
||||
//void view_port_input_callback_set(
|
||||
// ViewPort* view_port,
|
||||
// ViewPortInputCallback callback,
|
||||
// void* context);
|
||||
//
|
||||
void view_port_input_callback_set(
|
||||
ViewPort* view_port,
|
||||
ViewPortInputCallback callback,
|
||||
void* context);
|
||||
|
||||
*/
|
||||
@ -1,6 +1,6 @@
|
||||
#include "system_info.h"
|
||||
#include "nanobake.h"
|
||||
#include "core_defines.h"
|
||||
#include "nanobake.h"
|
||||
#include "thread.h"
|
||||
|
||||
static int32_t system_info_entry_point(void* param) {
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
#include "nanobake.h"
|
||||
#include "nb_hardware_i.h"
|
||||
#include "nb_lvgl_i.h"
|
||||
#include "nb_app_i.h"
|
||||
#include "applications/nb_applications.h"
|
||||
#include "esp_log.h"
|
||||
#include "m-list.h"
|
||||
#include "nb_app_i.h"
|
||||
#include "nb_hardware_i.h"
|
||||
#include "nb_lvgl_i.h"
|
||||
// Furi
|
||||
#include "thread.h"
|
||||
#include "kernel.h"
|
||||
#include "record.h"
|
||||
#include "thread.h"
|
||||
|
||||
M_LIST_DEF(thread_ids, FuriThreadId);
|
||||
|
||||
@ -36,10 +36,7 @@ size_t nanobake_get_app_thread_count() {
|
||||
}
|
||||
|
||||
static void prv_start_app(const NbApp _Nonnull* app) {
|
||||
ESP_LOGI(TAG, "Starting %s app \"%s\"",
|
||||
nb_app_type_to_string(app->type),
|
||||
app->name
|
||||
);
|
||||
ESP_LOGI(TAG, "Starting %s app \"%s\"", nb_app_type_to_string(app->type), app->name);
|
||||
|
||||
FuriThread* thread = furi_thread_alloc_ex(
|
||||
app->name,
|
||||
@ -64,7 +61,7 @@ __attribute__((unused)) extern void nanobake_start(NbConfig _Nonnull* config) {
|
||||
prv_furi_init();
|
||||
|
||||
NbHardware hardware = nb_hardware_create(config);
|
||||
/*NbLvgl lvgl =*/ nb_lvgl_init(&hardware);
|
||||
/*NbLvgl lvgl =*/nb_lvgl_init(&hardware);
|
||||
|
||||
thread_ids_init(prv_thread_ids);
|
||||
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "nb_hardware.h"
|
||||
#include "nb_app.h"
|
||||
#include "nb_config.h"
|
||||
#include "nb_hardware.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
#include "nb_app_i.h"
|
||||
#include "check.h"
|
||||
#include "nb_app_i.h"
|
||||
|
||||
const char* prv_type_service = "service";
|
||||
const char* prv_type_system = "system";
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdio.h>
|
||||
#include "esp_err.h"
|
||||
#include "lvgl.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -25,7 +25,7 @@ typedef enum {
|
||||
NB_TASK_STACK_SIZE_DEFAULT = 2048
|
||||
} NbStackSize;
|
||||
|
||||
typedef int32_t (*NbAppEntryPoint) (void _Nonnull* parameter);
|
||||
typedef int32_t (*NbAppEntryPoint)(void _Nonnull* parameter);
|
||||
|
||||
typedef struct {
|
||||
const char id[NB_APP_ID_LENGTH];
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include "nb_app.h"
|
||||
#include "nb_display.h"
|
||||
#include "nb_touch.h"
|
||||
#include "nb_app.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@ -18,7 +18,7 @@ typedef struct {
|
||||
bool swap_xy;
|
||||
} NbDisplay;
|
||||
|
||||
typedef bool(*CreateDisplay)(NbDisplay* display);
|
||||
typedef bool (*CreateDisplay)(NbDisplay* display);
|
||||
|
||||
typedef struct {
|
||||
char name[32];
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#include "nb_hardware_i.h"
|
||||
#include "check.h"
|
||||
#include "esp_check.h"
|
||||
#include "esp_err.h"
|
||||
#include "check.h"
|
||||
#include "nb_hardware_i.h"
|
||||
|
||||
#define TAG "hardware"
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "nb_hardware.h"
|
||||
#include "nb_config.h"
|
||||
#include "nb_hardware.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include "nb_lvgl_i.h"
|
||||
#include "esp_lvgl_port.h"
|
||||
#include "check.h"
|
||||
#include "esp_lvgl_port.h"
|
||||
#include "nb_lvgl_i.h"
|
||||
|
||||
#define TAG "lvgl"
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "nb_lvgl.h"
|
||||
#include "nb_hardware.h"
|
||||
#include "nb_lvgl.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "esp_lcd_touch.h"
|
||||
#include "esp_lcd_panel_io.h"
|
||||
#include "esp_lcd_touch.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user