[WIP] Add syntax check for rust and C\C++ code (#108)

* proof of concept

* fix syntax for rust and add auto fix syntax

* fix syntax for C

* fix bug with files owner

* add information to wiki

* try to add ci

* format code from master

* even more format fixes

* change docker to docker-compose

* Exclude ./target_*/build directories from format check

* Run rustfmt only on project files

* add ulimit setup for long clang list

* merge

* fix rustfmt, exclude target Inc directory

* sync with master

* abspath

Co-authored-by: aanper <mail@s3f.ru>
Co-authored-by: Vadim Kaushan <admin@disasm.info>
This commit is contained in:
Nikita Beletskii
2020-09-30 02:18:30 +03:00
committed by GitHub
parent 7ded31c19d
commit 110a9efc3c
73 changed files with 4354 additions and 4667 deletions

View File

@@ -2,10 +2,10 @@
#include <stdio.h>
extern "C" {
#include "startup.h"
#include "furi.h"
#include "log.h"
#include "tty_uart.h"
#include "startup.h"
#include "furi.h"
#include "log.h"
#include "tty_uart.h"
}
extern "C" void app() {
@@ -15,16 +15,16 @@ extern "C" void app() {
fuprintf(log, "\n=== Welcome to Flipper Zero! ===\n\n");
// FURI startup
FuriApp* handlers[sizeof(FLIPPER_STARTUP)/sizeof(FLIPPER_STARTUP[0])];
FuriApp* handlers[sizeof(FLIPPER_STARTUP) / sizeof(FLIPPER_STARTUP[0])];
for(size_t i = 0; i < sizeof(FLIPPER_STARTUP)/sizeof(FLIPPER_STARTUP[0]); i++) {
for(size_t i = 0; i < sizeof(FLIPPER_STARTUP) / sizeof(FLIPPER_STARTUP[0]); i++) {
handlers[i] = furiac_start(FLIPPER_STARTUP[i].app, FLIPPER_STARTUP[i].name, NULL);
}
bool is_alive = false;
do {
is_alive = false;
for(size_t i = 0; i < sizeof(FLIPPER_STARTUP)/sizeof(FLIPPER_STARTUP[0]); i++) {
for(size_t i = 0; i < sizeof(FLIPPER_STARTUP) / sizeof(FLIPPER_STARTUP[0]); i++) {
if(handlers[i]->handler != NULL) {
is_alive = true;
}

View File

@@ -4,11 +4,11 @@
extern "C" {
#endif
#include "main.h"
#include "flipper_hal.h"
#include "cmsis_os.h"
#include "furi.h"
#include "log.h"
#include "main.h"
#include "flipper_hal.h"
#include "cmsis_os.h"
#include "furi.h"
#include "log.h"
#ifdef __cplusplus
}

View File

@@ -29,16 +29,16 @@ static FuriRecord* find_record(const char* name) {
// TODO: change open-create to only open
bool furi_create(const char* name, void* value, size_t size) {
#ifdef FURI_DEBUG
printf("[FURI] creating %s record\n", name);
#endif
#ifdef FURI_DEBUG
printf("[FURI] creating %s record\n", name);
#endif
FuriRecord* record = find_record(name);
if(record != NULL) {
#ifdef FURI_DEBUG
printf("[FURI] record already exist\n");
#endif
#ifdef FURI_DEBUG
printf("[FURI] record already exist\n");
#endif
record->value = value;
record->size = size;
@@ -49,17 +49,16 @@ bool furi_create(const char* name, void* value, size_t size) {
// record not exist, create new
if(current_buffer_idx >= MAX_RECORD_COUNT) {
// max record count exceed
#ifdef FURI_DEBUG
printf("[FURI] create: max record count exceed\n");
#endif
// max record count exceed
#ifdef FURI_DEBUG
printf("[FURI] create: max record count exceed\n");
#endif
return NULL;
}
records[current_buffer_idx].mute_counter = 0;
records[current_buffer_idx].mutex = xSemaphoreCreateMutexStatic(
&records[current_buffer_idx].mutex_buffer
);
records[current_buffer_idx].mutex =
xSemaphoreCreateMutexStatic(&records[current_buffer_idx].mutex_buffer);
records[current_buffer_idx].value = value;
records[current_buffer_idx].size = size;
records[current_buffer_idx].name = name;
@@ -74,26 +73,24 @@ bool furi_create(const char* name, void* value, size_t size) {
return true;
}
FuriRecordSubscriber* furi_open(
const char* name,
bool solo,
bool no_mute,
FlipperRecordCallback value_callback,
FlipperRecordStateCallback state_callback,
void* ctx
) {
#ifdef FURI_DEBUG
printf("[FURI] opening %s record\n", name);
#endif
FuriRecordSubscriber* furi_open(const char* name,
bool solo,
bool no_mute,
FlipperRecordCallback value_callback,
FlipperRecordStateCallback state_callback,
void* ctx) {
#ifdef FURI_DEBUG
printf("[FURI] opening %s record\n", name);
#endif
// get furi record by name
FuriRecord* record = find_record(name);
if(record == NULL) {
// cannot find record
#ifdef FURI_DEBUG
printf("[FURI] cannot find record %s\n", name);
#endif
// cannot find record
#ifdef FURI_DEBUG
printf("[FURI] cannot find record %s\n", name);
#endif
// create record if not exist
if(!furi_create(name, NULL, 0)) {
@@ -118,11 +115,11 @@ FuriRecordSubscriber* furi_open(
}
if(subscriber == NULL) {
// cannot add subscriber (full)
#ifdef FURI_DEBUG
printf("[FURI] open: cannot add subscriber (full)\n");
#endif
// cannot add subscriber (full)
#ifdef FURI_DEBUG
printf("[FURI] open: cannot add subscriber (full)\n");
#endif
return NULL;
}
@@ -147,19 +144,18 @@ FuriRecordSubscriber* furi_open(
current_task->records[current_task->records_count] = record;
current_task->records_count++;
} else {
#ifdef FURI_DEBUG
printf("[FURI] open: no current task\n");
#endif
#ifdef FURI_DEBUG
printf("[FURI] open: no current task\n");
#endif
}
return subscriber;
}
void furi_close(FuriRecordSubscriber* handler) {
#ifdef FURI_DEBUG
printf("[FURI] closing %s record\n", handler->record->name);
#endif
#ifdef FURI_DEBUG
printf("[FURI] closing %s record\n", handler->record->name);
#endif
// deallocate subscriber
handler->allocated = false;
@@ -181,10 +177,7 @@ static void furi_notify(FuriRecordSubscriber* handler, const void* value, size_t
if(handler->record->subscribers[i].allocated) {
if(handler->record->subscribers[i].cb != NULL) {
handler->record->subscribers[i].cb(
value,
size,
handler->record->subscribers[i].ctx
);
value, size, handler->record->subscribers[i].ctx);
}
}
}
@@ -193,7 +186,7 @@ static void furi_notify(FuriRecordSubscriber* handler, const void* value, size_t
void* furi_take(FuriRecordSubscriber* handler) {
if(handler == NULL || handler->record == NULL) return NULL;
if (xSemaphoreTake(handler->record->mutex, portMAX_DELAY) == pdTRUE) {
if(xSemaphoreTake(handler->record->mutex, portMAX_DELAY) == pdTRUE) {
return handler->record->value;
} else {
return NULL;
@@ -214,9 +207,9 @@ void furi_commit(FuriRecordSubscriber* handler) {
}
bool furi_read(FuriRecordSubscriber* handler, void* value, size_t size) {
#ifdef FURI_DEBUG
printf("[FURI] read from %s\n", handler->record->name);
#endif
#ifdef FURI_DEBUG
printf("[FURI] read from %s\n", handler->record->name);
#endif
if(handler == NULL || handler->record == NULL || value == NULL) return false;
@@ -234,41 +227,40 @@ bool furi_read(FuriRecordSubscriber* handler, void* value, size_t size) {
}
bool furi_write(FuriRecordSubscriber* handler, const void* value, size_t size) {
#ifdef FURI_DEBUG
printf("[FURI] write to %s\n", handler->record->name);
#endif
#ifdef FURI_DEBUG
printf("[FURI] write to %s\n", handler->record->name);
#endif
if(handler == NULL || handler->record == NULL || value == NULL) {
#ifdef FURI_DEBUG
printf("[FURI] write: null param %x %x\n", (uint32_t)(size_t)handler, (uint32_t)(size_t)value);
#endif
#ifdef FURI_DEBUG
printf("[FURI] write: null param %x %x\n",
(uint32_t)(size_t)handler,
(uint32_t)(size_t)value);
#endif
return false;
}
// check if closed
if(!handler->allocated) {
#ifdef FURI_DEBUG
printf("[FURI] write: handler closed\n");
#endif
#ifdef FURI_DEBUG
printf("[FURI] write: handler closed\n");
#endif
return false;
}
if(handler->record->value != NULL && size > handler->record->size) {
#ifdef FURI_DEBUG
printf("[FURI] write: wrong size %d\n", (uint32_t)size);
#endif
#ifdef FURI_DEBUG
printf("[FURI] write: wrong size %d\n", (uint32_t)size);
#endif
return false;
}
// check mute
if(
handler->record->mute_counter != handler->mute_counter
&& !handler->no_mute
) {
#ifdef FURI_DEBUG
printf("[FURI] write: muted\n");
#endif
if(handler->record->mute_counter != handler->mute_counter && !handler->no_mute) {
#ifdef FURI_DEBUG
printf("[FURI] write: muted\n");
#endif
return false;
}

View File

@@ -8,10 +8,10 @@
#define MAX_RECORD_SUBSCRIBERS 8
/// application is just a function
typedef void(*FlipperApplication)(void*);
typedef void (*FlipperApplication)(void*);
/// pointer to value callback function
typedef void(*FlipperRecordCallback)(const void*, size_t, void*);
typedef void (*FlipperRecordCallback)(const void*, size_t, void*);
typedef enum {
FlipperRecordStateMute, ///< record open and mute this handler
@@ -20,7 +20,7 @@ typedef enum {
} FlipperRecordState;
/// pointer to state callback function
typedef void(*FlipperRecordStateCallback)(FlipperRecordState, void*);
typedef void (*FlipperRecordStateCallback)(FlipperRecordState, void*);
struct _FuriRecord;
@@ -90,7 +90,6 @@ bool furiac_kill(FuriApp* app);
// find task pointer by handle
FuriApp* find_task(TaskHandle_t handler);
/*!
Creates named FURI record.
\param[in] name you can open this record anywhere
@@ -110,14 +109,12 @@ When appication has exited or record has closed, all handlers is unmuted.
It may be useful for concurrently acces to resources like framebuffer or beeper.
\param[in] no_mute if true, another applications cannot mute this handler.
*/
FuriRecordSubscriber* furi_open(
const char* name,
bool solo,
bool no_mute,
FlipperRecordCallback value_callback,
FlipperRecordStateCallback state_callback,
void* ctx
);
FuriRecordSubscriber* furi_open(const char* name,
bool solo,
bool no_mute,
FlipperRecordCallback value_callback,
FlipperRecordStateCallback state_callback,
void* ctx);
/*!

View File

@@ -29,30 +29,29 @@ FuriApp* find_task(TaskHandle_t handler) {
}
FuriApp* furiac_start(FlipperApplication app, const char* name, void* param) {
#ifdef FURI_DEBUG
printf("[FURIAC] start %s\n", name);
#endif
#ifdef FURI_DEBUG
printf("[FURIAC] start %s\n", name);
#endif
// TODO check first free item (.handler == NULL) and use it
if(current_buffer_idx >= MAX_TASK_COUNT) {
// max task count exceed
#ifdef FURI_DEBUG
printf("[FURIAC] max task count exceed\n");
#endif
// max task count exceed
#ifdef FURI_DEBUG
printf("[FURIAC] max task count exceed\n");
#endif
return NULL;
}
// create task on static stack memory
task_buffer[current_buffer_idx].handler = xTaskCreateStatic(
(TaskFunction_t)app,
(const char * const)name,
DEFAULT_STACK_SIZE / 4, // freertos specify stack size in words
(void * const) param,
tskIDLE_PRIORITY + 3, // normal priority
stack_buffer[current_buffer_idx],
&task_info_buffer[current_buffer_idx]
);
task_buffer[current_buffer_idx].handler =
xTaskCreateStatic((TaskFunction_t)app,
(const char* const)name,
DEFAULT_STACK_SIZE / 4, // freertos specify stack size in words
(void* const)param,
tskIDLE_PRIORITY + 3, // normal priority
stack_buffer[current_buffer_idx],
&task_info_buffer[current_buffer_idx]);
// save task
task_buffer[current_buffer_idx].application = app;
@@ -67,9 +66,9 @@ FuriApp* furiac_start(FlipperApplication app, const char* name, void* param) {
}
bool furiac_kill(FuriApp* app) {
#ifdef FURI_DEBUG
printf("[FURIAC] kill %s\n", app->name);
#endif
#ifdef FURI_DEBUG
printf("[FURIAC] kill %s\n", app->name);
#endif
// check handler
if(app == NULL || app->handler == NULL) return false;
@@ -90,16 +89,16 @@ void furiac_exit(void* param) {
// run prev
if(current_task != NULL) {
#ifdef FURI_DEBUG
printf("[FURIAC] exit %s\n", current_task->name);
#endif
#ifdef FURI_DEBUG
printf("[FURIAC] exit %s\n", current_task->name);
#endif
if(current_task->prev != NULL) {
furiac_start(current_task->prev, current_task->prev_name, param);
} else {
#ifdef FURI_DEBUG
printf("[FURIAC] no prev\n");
#endif
#ifdef FURI_DEBUG
printf("[FURIAC] no prev\n");
#endif
}
// cleanup registry
@@ -108,7 +107,7 @@ void furiac_exit(void* param) {
}
// kill itself
vTaskDelete(NULL);
vTaskDelete(NULL);
}
void furiac_switch(FlipperApplication app, char* name, void* param) {
@@ -116,14 +115,14 @@ void furiac_switch(FlipperApplication app, char* name, void* param) {
FuriApp* current_task = find_task(xTaskGetCurrentTaskHandle());
if(current_task == NULL) {
#ifdef FURI_DEBUG
printf("[FURIAC] no current task found\n");
#endif
#ifdef FURI_DEBUG
printf("[FURIAC] no current task found\n");
#endif
}
#ifdef FURI_DEBUG
printf("[FURIAC] switch %s to %s\n", current_task->name, name);
#endif
#ifdef FURI_DEBUG
printf("[FURIAC] switch %s to %s\n", current_task->name, name);
#endif
// run next
FuriApp* next = furiac_start(app, name, param);

View File

@@ -9,7 +9,7 @@
#define PRINT_STR_SIZE 64
void fuprintf(FuriRecordSubscriber* f, const char * format, ...) {
void fuprintf(FuriRecordSubscriber* f, const char* format, ...) {
char buffer[PRINT_STR_SIZE];
va_list args;

View File

@@ -3,4 +3,4 @@
#include "furi.h"
FuriRecordSubscriber* get_default_log();
void fuprintf(FuriRecordSubscriber* f, const char * format, ...);
void fuprintf(FuriRecordSubscriber* f, const char* format, ...);

View File

@@ -6,19 +6,19 @@
extern UART_HandleTypeDef DEBUG_UART;
void handle_uart_write(const void* data, size_t size, void* ctx) {
HAL_UART_Transmit(&DEBUG_UART, (uint8_t*)data, (uint16_t)size, HAL_MAX_DELAY);
HAL_UART_Transmit(&DEBUG_UART, (uint8_t*)data, (uint16_t)size, HAL_MAX_DELAY);
}
static ssize_t stdout_write(void *_cookie, const char *buf, size_t n) {
FuriRecordSubscriber *log = pvTaskGetThreadLocalStoragePointer(NULL, 0);
if (log == NULL) {
static ssize_t stdout_write(void* _cookie, const char* buf, size_t n) {
FuriRecordSubscriber* log = pvTaskGetThreadLocalStoragePointer(NULL, 0);
if(log == NULL) {
log = furi_open("tty", false, false, NULL, NULL, NULL);
if (log == NULL) {
if(log == NULL) {
return -1;
}
vTaskSetThreadLocalStoragePointer(NULL, 0, log);
}
if (buf == 0) {
if(buf == 0) {
/*
* This means that we should flush internal buffers. Since we
* don't we just return. (Remember, "handle" == -1 means that all
@@ -33,22 +33,24 @@ static ssize_t stdout_write(void *_cookie, const char *buf, size_t n) {
}
bool register_tty_uart() {
if(!furi_create("tty", NULL, 0)) {
return false;
}
if(!furi_create("tty", NULL, 0)) {
return false;
}
if(furi_open("tty", false, false, handle_uart_write, NULL, NULL) == NULL) {
return false;
}
if(furi_open("tty", false, false, handle_uart_write, NULL, NULL) == NULL) {
return false;
}
FILE* fp = fopencookie(NULL, "w", (cookie_io_functions_t) {
.read = NULL,
.write = stdout_write,
.seek = NULL,
.close = NULL,
});
FILE* fp = fopencookie(NULL,
"w",
(cookie_io_functions_t){
.read = NULL,
.write = stdout_write,
.seek = NULL,
.close = NULL,
});
setvbuf(fp, NULL, _IONBF, 0);
stdout = fp;
return true;
return true;
}