[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

@@ -9,9 +9,7 @@ void coreglitch_demo_0(void* p) {
fuprintf(log, "coreglitch demo!\n");
// open record
FuriRecordSubscriber* fb_record = furi_open(
"u8g2_fb", false, false, NULL, NULL, NULL
);
FuriRecordSubscriber* fb_record = furi_open("u8g2_fb", false, false, NULL, NULL, NULL);
if(fb_record == NULL) {
fuprintf(log, "[widget] cannot create fb record\n");
@@ -33,18 +31,17 @@ void coreglitch_demo_0(void* p) {
1.0,
1.5,
0.75,
0.8
0.8,
};
uint8_t cnt = 0;
while(1) {
for(size_t note_idx = 0; note_idx < 400; note_idx++) {
float scale = scales[((cnt + note_idx)/16) % 4];
float scale = scales[((cnt + note_idx) / 16) % 4];
float freq = notes[(note_idx + cnt / 2) % 8] * scale;
float width = 0.001 + 0.05 * (note_idx % (cnt/7 + 5));
float width = 0.001 + 0.05 * (note_idx % (cnt / 7 + 5));
if(note_idx % 8 == 0) {
freq = 0;
@@ -56,7 +53,6 @@ void coreglitch_demo_0(void* p) {
cnt++;
u8g2_t* fb = furi_take(fb_record);
if(fb != NULL) {
u8g2_SetDrawColor(fb, 0);

View File

@@ -7,104 +7,107 @@ extern SPI_HandleTypeDef hspi1;
// TODO rewrite u8g2 to pass thread-local context in this handlers
static uint8_t u8g2_gpio_and_delay_stm32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr) {
static uint8_t
u8g2_gpio_and_delay_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr) {
switch(msg) {
//Initialize SPI peripheral
case U8X8_MSG_GPIO_AND_DELAY_INIT:
/* HAL initialization contains all what we need so we can skip this part. */
//Initialize SPI peripheral
case U8X8_MSG_GPIO_AND_DELAY_INIT:
/* HAL initialization contains all what we need so we can skip this part. */
break;
//Function which implements a delay, arg_int contains the amount of ms
case U8X8_MSG_DELAY_MILLI:
osDelay(arg_int);
//Function which implements a delay, arg_int contains the amount of ms
case U8X8_MSG_DELAY_MILLI:
osDelay(arg_int);
break;
//Function which delays 10us
case U8X8_MSG_DELAY_10MICRO:
delay_us(10);
//Function which delays 10us
case U8X8_MSG_DELAY_10MICRO:
delay_us(10);
break;
//Function which delays 100ns
case U8X8_MSG_DELAY_100NANO:
asm("nop");
//Function which delays 100ns
case U8X8_MSG_DELAY_100NANO:
asm("nop");
break;
// Function to define the logic level of the RESET line
case U8X8_MSG_GPIO_RESET:
#ifdef DEBUG
fuprintf(log, "[u8g2] rst %d\n", arg_int);
#endif
// Function to define the logic level of the RESET line
case U8X8_MSG_GPIO_RESET:
#ifdef DEBUG
fuprintf(log, "[u8g2] rst %d\n", arg_int);
#endif
// TODO change it to FuriRecord pin
HAL_GPIO_WritePin(DISPLAY_RST_GPIO_Port, DISPLAY_RST_Pin, arg_int ? GPIO_PIN_SET : GPIO_PIN_RESET);
// TODO change it to FuriRecord pin
HAL_GPIO_WritePin(
DISPLAY_RST_GPIO_Port, DISPLAY_RST_Pin, arg_int ? GPIO_PIN_SET : GPIO_PIN_RESET);
break;
default:
#ifdef DEBUG
fufuprintf(log, "[u8g2] unknown io %d\n", msg);
#endif
default:
#ifdef DEBUG
fufuprintf(log, "[u8g2] unknown io %d\n", msg);
#endif
return 0; //A message was received which is not implemented, return 0 to indicate an error
return 0; //A message was received which is not implemented, return 0 to indicate an error
}
return 1; // command processed successfully.
}
static uint8_t u8x8_hw_spi_stm32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr){
switch (msg) {
case U8X8_MSG_BYTE_SEND:
#ifdef DEBUG
fuprintf(log, "[u8g2] send %d bytes %02X\n", arg_int, ((uint8_t*)arg_ptr)[0]);
#endif
static uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_ptr) {
switch(msg) {
case U8X8_MSG_BYTE_SEND:
#ifdef DEBUG
fuprintf(log, "[u8g2] send %d bytes %02X\n", arg_int, ((uint8_t*)arg_ptr)[0]);
#endif
// TODO change it to FuriRecord SPI
HAL_SPI_Transmit(&hspi1, (uint8_t *)arg_ptr, arg_int, 10000);
// TODO change it to FuriRecord SPI
HAL_SPI_Transmit(&hspi1, (uint8_t*)arg_ptr, arg_int, 10000);
break;
case U8X8_MSG_BYTE_SET_DC:
#ifdef DEBUG
fuprintf(log, "[u8g2] dc %d\n", arg_int);
#endif
case U8X8_MSG_BYTE_SET_DC:
#ifdef DEBUG
fuprintf(log, "[u8g2] dc %d\n", arg_int);
#endif
// TODO change it to FuriRecord pin
HAL_GPIO_WritePin(DISPLAY_DI_GPIO_Port, DISPLAY_DI_Pin, arg_int ? GPIO_PIN_SET : GPIO_PIN_RESET);
// TODO change it to FuriRecord pin
HAL_GPIO_WritePin(
DISPLAY_DI_GPIO_Port, DISPLAY_DI_Pin, arg_int ? GPIO_PIN_SET : GPIO_PIN_RESET);
break;
case U8X8_MSG_BYTE_INIT:
#ifdef DEBUG
fuprintf(log, "[u8g2] init\n");
#endif
case U8X8_MSG_BYTE_INIT:
#ifdef DEBUG
fuprintf(log, "[u8g2] init\n");
#endif
// TODO change it to FuriRecord pin
HAL_GPIO_WritePin(DISPLAY_CS_GPIO_Port, DISPLAY_CS_Pin, GPIO_PIN_RESET);
// TODO change it to FuriRecord pin
HAL_GPIO_WritePin(DISPLAY_CS_GPIO_Port, DISPLAY_CS_Pin, GPIO_PIN_RESET);
break;
case U8X8_MSG_BYTE_START_TRANSFER:
#ifdef DEBUG
fuprintf(log, "[u8g2] start\n");
#endif
case U8X8_MSG_BYTE_START_TRANSFER:
#ifdef DEBUG
fuprintf(log, "[u8g2] start\n");
#endif
// TODO change it to FuriRecord pin
HAL_GPIO_WritePin(DISPLAY_CS_GPIO_Port, DISPLAY_CS_Pin, GPIO_PIN_RESET);
asm("nop");
// TODO change it to FuriRecord pin
HAL_GPIO_WritePin(DISPLAY_CS_GPIO_Port, DISPLAY_CS_Pin, GPIO_PIN_RESET);
asm("nop");
break;
case U8X8_MSG_BYTE_END_TRANSFER:
#ifdef DEBUG
fuprintf(log, "[u8g2] end\n");
#endif
case U8X8_MSG_BYTE_END_TRANSFER:
#ifdef DEBUG
fuprintf(log, "[u8g2] end\n");
#endif
asm("nop");
// TODO change it to FuriRecord pin
HAL_GPIO_WritePin(DISPLAY_CS_GPIO_Port, DISPLAY_CS_Pin, GPIO_PIN_SET);
asm("nop");
// TODO change it to FuriRecord pin
HAL_GPIO_WritePin(DISPLAY_CS_GPIO_Port, DISPLAY_CS_Pin, GPIO_PIN_SET);
break;
default:
#ifdef DEBUG
fuprintf(log, "[u8g2] unknown xfer %d\n", msg);
#endif
default:
#ifdef DEBUG
fuprintf(log, "[u8g2] unknown xfer %d\n", msg);
#endif
return 0;
return 0;
}
return 1;
@@ -131,8 +134,10 @@ void display_u8g2(void* p) {
HAL_GPIO_WritePin(DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin, GPIO_PIN_SET);
u8g2_t _u8g2;
u8g2_Setup_st7565_erc12864_alt_f(&_u8g2, U8G2_R0, u8x8_hw_spi_stm32, u8g2_gpio_and_delay_stm32);
u8g2_InitDisplay(&_u8g2); // send init sequence to the display, display is in sleep mode after this
u8g2_Setup_st7565_erc12864_alt_f(
&_u8g2, U8G2_R0, u8x8_hw_spi_stm32, u8g2_gpio_and_delay_stm32);
u8g2_InitDisplay(
&_u8g2); // send init sequence to the display, display is in sleep mode after this
u8g2_SetContrast(&_u8g2, 36);
if(!furi_create("u8g2_fb", (void*)&_u8g2, sizeof(_u8g2))) {
@@ -153,9 +158,8 @@ void display_u8g2(void* p) {
DisplayCtx ctx = {.update = update, .log = log};
// subscribe to record. ctx will be passed to handle_fb_change
FuriRecordSubscriber* fb_record = furi_open(
"u8g2_fb", false, false, handle_fb_change, NULL, &ctx
);
FuriRecordSubscriber* fb_record =
furi_open("u8g2_fb", false, false, handle_fb_change, NULL, &ctx);
if(fb_record == NULL) {
fuprintf(log, "[display] cannot open fb record\n");

View File

@@ -3,7 +3,7 @@
void application_blink(void* p) {
// create pin
GpioPin led = {.pin = GPIO_PIN_8, .port = GPIOA};
// configure pin
pinMode(led, GpioModeOpenDrain);

View File

@@ -25,7 +25,7 @@ static void handle_fb_change(const void* fb, size_t fb_size, void* raw_ctx) {
static void print_fb(char* fb, FuriRecordSubscriber* log) {
if(fb == NULL) return;
/* draw framebuffer like this:
+==========+
| |
@@ -78,57 +78,53 @@ void application_ipc_display(void* p) {
IpcCtx ctx = {.events = events, .log = log};
// subscribe to record. ctx will be passed to handle_fb_change
FuriRecordSubscriber* fb_record = furi_open(
"test_fb", false, false, handle_fb_change, NULL, &ctx
);
FuriRecordSubscriber* fb_record =
furi_open("test_fb", false, false, handle_fb_change, NULL, &ctx);
if(fb_record == NULL) {
fuprintf(log, "[display] cannot open fb record\n");
furiac_exit(NULL);
}
#ifdef HW_DISPLAY
#ifdef HW_DISPLAY
// on Flipper target -- open screen
// draw border
#else
#else
// on Local target -- print "blank screen"
{
void* fb = furi_take(fb_record);
print_fb((char*)fb, log);
furi_give(fb_record);
}
#endif
#endif
while(1) {
// wait for event
if(xSemaphoreTake(events, portMAX_DELAY) == pdTRUE) {
fuprintf(log, "[display] get fb update\n\n");
#ifdef HW_DISPLAY
// on Flipper target draw the screen
#else
#ifdef HW_DISPLAY
// on Flipper target draw the screen
#else
// on local target just print
{
void* fb = furi_take(fb_record);
print_fb((char*)fb, log);
furi_give(fb_record);
}
#endif
#endif
}
}
}
// Widget application
void application_ipc_widget(void* p) {
FuriRecordSubscriber* log = get_default_log();
// open record
FuriRecordSubscriber* fb_record = furi_open(
"test_fb", false, false, NULL, NULL, NULL
);
FuriRecordSubscriber* fb_record = furi_open("test_fb", false, false, NULL, NULL, NULL);
if(fb_record == NULL) {
fuprintf(log, "[widget] cannot create fb record\n");

View File

@@ -6,11 +6,9 @@ void u8g2_example(void* p) {
// TODO try open record and retry on timeout (needs FURI behaviour change)
delay(1000);
// open record
FuriRecordSubscriber* fb_record = furi_open(
"u8g2_fb", false, false, NULL, NULL, NULL
);
FuriRecordSubscriber* fb_record = furi_open("u8g2_fb", false, false, NULL, NULL, NULL);
if(fb_record == NULL) {
fuprintf(log, "[widget] cannot create fb record\n");

View File

@@ -23,25 +23,25 @@ void u8g2_example(void* p);
void coreglitch_demo_0(void* p);
const FlipperStartupApp FLIPPER_STARTUP[] = {
#ifndef TEST
#ifndef TEST
{.app = display_u8g2, .name = "display_u8g2"},
{.app = u8g2_example, .name = "u8g2_example"},
#endif
#endif
// {.app = coreglitch_demo_0, .name = "coreglitch_demo_0"},
#ifdef TEST
// {.app = coreglitch_demo_0, .name = "coreglitch_demo_0"},
#ifdef TEST
{.app = flipper_test_app, .name = "test app"},
#endif
#endif
#ifdef EXAMPLE_BLINK
#ifdef EXAMPLE_BLINK
{.app = application_blink, .name = "blink"},
#endif
#ifdef EXAMPLE_UART_WRITE
#endif
#ifdef EXAMPLE_UART_WRITE
{.app = application_uart_write, .name = "uart write"},
#endif
#ifdef EXAMPLE_IPC
#endif
#ifdef EXAMPLE_IPC
{.app = application_ipc_display, .name = "ipc display"},
{.app = application_ipc_widget, .name = "ipc widget"},
#endif
};
#endif
};

View File

@@ -29,10 +29,9 @@ bool test_furi_pipe_record(FuriRecordSubscriber* log) {
return false;
}
// 2. Open/subscribe to it
FuriRecordSubscriber* pipe_record = furi_open(
"test/pipe", false, false, pipe_record_cb, NULL, NULL
);
// 2. Open/subscribe to it
FuriRecordSubscriber* pipe_record =
furi_open("test/pipe", false, false, pipe_record_cb, NULL, NULL);
if(pipe_record == NULL) {
fuprintf(log, "cannot open record\n");
return false;
@@ -97,9 +96,8 @@ bool test_furi_holding_data(FuriRecordSubscriber* log) {
}
// 2. Open/Subscribe on it
FuriRecordSubscriber* holding_record = furi_open(
"test/holding", false, false, holding_record_cb, NULL, NULL
);
FuriRecordSubscriber* holding_record =
furi_open("test/holding", false, false, holding_record_cb, NULL, NULL);
if(holding_record == NULL) {
fuprintf(log, "cannot open record\n");
return false;
@@ -163,9 +161,8 @@ typedef struct {
void furi_concurent_app(void* p) {
FuriRecordSubscriber* log = (FuriRecordSubscriber*)p;
FuriRecordSubscriber* holding_record = furi_open(
"test/concurrent", false, false, NULL, NULL, NULL
);
FuriRecordSubscriber* holding_record =
furi_open("test/concurrent", false, false, NULL, NULL, NULL);
if(holding_record == NULL) {
fuprintf(log, "cannot open record\n");
furiac_exit(NULL);
@@ -202,18 +199,15 @@ bool test_furi_concurrent_access(FuriRecordSubscriber* log) {
}
// 2. Open it
FuriRecordSubscriber* holding_record = furi_open(
"test/concurrent", false, false, NULL, NULL, NULL
);
FuriRecordSubscriber* holding_record =
furi_open("test/concurrent", false, false, NULL, NULL, NULL);
if(holding_record == NULL) {
fuprintf(log, "cannot open record\n");
return false;
}
// 3. Create second app for interact with it
FuriApp* second_app = furiac_start(
furi_concurent_app, "furi concurent app", (void*)log
);
FuriApp* second_app = furiac_start(furi_concurent_app, "furi concurent app", (void*)log);
// 4. multiply ConcurrentValue::a
for(size_t i = 0; i < 4; i++) {
@@ -259,7 +253,6 @@ TEST: non-existent data
TODO: implement this test
*/
bool test_furi_nonexistent_data(FuriRecordSubscriber* log) {
return true;
}
@@ -326,9 +319,8 @@ void furi_mute_parent_app(void* p) {
}
// 2. Open watch handler: solo=false, no_mute=false, subscribe to data
FuriRecordSubscriber* watch_handler = furi_open(
"test/mute", false, false, mute_record_cb, NULL, NULL
);
FuriRecordSubscriber* watch_handler =
furi_open("test/mute", false, false, mute_record_cb, NULL, NULL);
if(watch_handler == NULL) {
fuprintf(log, "cannot open watch handler\n");
furiac_exit(NULL);
@@ -342,16 +334,13 @@ void furi_mute_parent_app(void* p) {
bool test_furi_mute_algorithm(FuriRecordSubscriber* log) {
// 1. Create "parent" application:
FuriApp* parent_app = furiac_start(
furi_mute_parent_app, "parent app", (void*)log
);
FuriApp* parent_app = furiac_start(furi_mute_parent_app, "parent app", (void*)log);
delay(2); // wait creating record
// 2. Open handler A: solo=false, no_mute=false, NULL subscriber. Subscribe to state.
FuriRecordSubscriber* handler_a = furi_open(
"test/mute", false, false, NULL, mute_record_state_cb, NULL
);
FuriRecordSubscriber* handler_a =
furi_open("test/mute", false, false, NULL, mute_record_state_cb, NULL);
if(handler_a == NULL) {
fuprintf(log, "cannot open handler A\n");
return false;
@@ -371,9 +360,7 @@ bool test_furi_mute_algorithm(FuriRecordSubscriber* log) {
}
// 3. Open handler B: solo=true, no_mute=true, NULL subscriber.
FuriRecordSubscriber* handler_b = furi_open(
"test/mute", true, true, NULL, NULL, NULL
);
FuriRecordSubscriber* handler_b = furi_open("test/mute", true, true, NULL, NULL, NULL);
if(handler_b == NULL) {
fuprintf(log, "cannot open handler B\n");
return false;
@@ -400,7 +387,6 @@ bool test_furi_mute_algorithm(FuriRecordSubscriber* log) {
test_counter = 3;
// Try to write data to B and check that subscriber get data.
if(!furi_write(handler_b, &test_counter, sizeof(uint8_t))) {
fuprintf(log, "write to B failed\n");
@@ -412,11 +398,8 @@ bool test_furi_mute_algorithm(FuriRecordSubscriber* log) {
return false;
}
// 4. Open hadler C: solo=true, no_mute=false, NULL subscriber.
FuriRecordSubscriber* handler_c = furi_open(
"test/mute", true, false, NULL, NULL, NULL
);
FuriRecordSubscriber* handler_c = furi_open("test/mute", true, false, NULL, NULL, NULL);
if(handler_c == NULL) {
fuprintf(log, "cannot open handler C\n");
return false;
@@ -427,9 +410,7 @@ bool test_furi_mute_algorithm(FuriRecordSubscriber* log) {
// TODO: Try to write data to C and check that subscriber get data.
// 5. Open handler D: solo=false, no_mute=false, NULL subscriber.
FuriRecordSubscriber* handler_d = furi_open(
"test/mute", false, false, NULL, NULL, NULL
);
FuriRecordSubscriber* handler_d = furi_open("test/mute", false, false, NULL, NULL, NULL);
if(handler_d == NULL) {
fuprintf(log, "cannot open handler D\n");
return false;

View File

@@ -78,7 +78,7 @@ typedef struct {
void task_a(void*);
void task_b(void*);
void task_a(void *p) {
void task_a(void* p) {
// simply starts, add 'A' letter to sequence and switch
// if sequence counter = 0, call task B, exit otherwise
@@ -118,7 +118,7 @@ bool test_furi_ac_switch_exit(FuriRecordSubscriber* log) {
furiac_start(task_a, "task A", (void*)&seq);
// TODO how to check that all child task ends?
delay(10); // wait while task do its work
seq.sequence[seq.count] = '\0';

View File

@@ -15,7 +15,7 @@ bool test_furi_mute_algorithm(FuriRecordSubscriber* log);
void flipper_test_app(void* p) {
FuriRecordSubscriber* log = get_default_log();
if(test_furi_ac_create_kill(log)) {
fuprintf(log, "[TEST] test_furi_ac_create_kill PASSED\n");
} else {
@@ -66,6 +66,5 @@ void flipper_test_app(void* p) {
rust_uart_write();
furiac_exit(NULL);
}