Add .clang-format and .editorconfig

This commit is contained in:
Jasper Blanckenburg 2022-05-29 00:47:46 +02:00 committed by jazzpi
parent b28ff29f45
commit ec9fa4bb0f
16 changed files with 697 additions and 536 deletions

137
.clang-format Normal file
View File

@ -0,0 +1,137 @@
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Right
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AllowShortLambdasOnASingleLine: All
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeColon
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 80
CommentPragmas: "^ IWYU pragma:"
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: true
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^[<"]stm'
Priority: 2
SortPriority: 0
- Regex: "^<std"
Priority: 4
SortPriority: 0
- Regex: ".*"
Priority: 1
SortPriority: 0
IncludeIsMainRegex: "(Test)?$"
IncludeIsMainSourceRegex: ""
IndentCaseLabels: false
IndentGotoLabels: true
IndentPPDirectives: None
IndentWidth: 2
IndentWrappedFunctionNames: false
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
MacroBlockBegin: ""
MacroBlockEnd: ""
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakAssignment: 2
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpaceBeforeSquareBrackets: false
Standard: Latest
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 8
UseCRLF: false
UseTab: Never
---

8
.editorconfig Normal file
View File

@ -0,0 +1,8 @@
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
[*.{h,c}]
indent_style = space
indent_size = 2

View File

@ -42,7 +42,7 @@ typedef struct {
* The event is deep-copied to the queue, so it can be deallocated after the * The event is deep-copied to the queue, so it can be deallocated after the
* call is complete. * call is complete.
*/ */
void event_push(Event *ev); void event_push(Event* ev);
/** /**
* @brief Pop an event from the start of the queue. * @brief Pop an event from the start of the queue.
* *

View File

@ -25,7 +25,7 @@ extern RPiI2CState rpi_i2c_state;
extern size_t rpi_num_polls; extern size_t rpi_num_polls;
void rpi_init(I2C_HandleTypeDef *handle); void rpi_init(I2C_HandleTypeDef* handle);
void rpi_update_tx_buffer(); void rpi_update_tx_buffer();
void rpi_update_tx_buffer_mission_select(); void rpi_update_tx_buffer_mission_select();

View File

@ -2,10 +2,11 @@
#define __FT_USER_INPUTS_H #define __FT_USER_INPUTS_H
#include "events.h" #include "events.h"
#include "stm32g4xx_hal.h" #include "stm32g4xx_hal.h"
void handle_button_press(const ButtonPressEvent *ev); void handle_button_press(const ButtonPressEvent* ev);
void handle_button_press_mission_select(const ButtonPressEvent *ev); void handle_button_press_mission_select(const ButtonPressEvent* ev);
#endif // __FT_USER_INPUTS_H #endif // __FT_USER_INPUTS_H

View File

@ -2,13 +2,14 @@
#define __VEHICLE_H #define __VEHICLE_H
#include "state.h" #include "state.h"
#include "stm32g4xx_hal.h" #include "stm32g4xx_hal.h"
#include "stm32g4xx_hal_fdcan.h" #include "stm32g4xx_hal_fdcan.h"
#define CAN_ID_MISSION_SELECT 0x400 #define CAN_ID_MISSION_SELECT 0x400
#define CAN_ID_AS_MISSION_FB 0x410 #define CAN_ID_AS_MISSION_FB 0x410
void vehicle_init(FDCAN_HandleTypeDef *handle); void vehicle_init(FDCAN_HandleTypeDef* handle);
void vehicle_send_mission_select(Mission mission); void vehicle_send_mission_select(Mission mission);

View File

@ -1,11 +1,13 @@
#include "events.h" #include "events.h"
#include "main.h" #include "main.h"
#include "user_inputs.h" #include "user_inputs.h"
#include <stdint.h> #include <stdint.h>
static volatile EventQueue event_queue = {.read_idx = 0, .write_idx = 0}; static volatile EventQueue event_queue = {.read_idx = 0, .write_idx = 0};
void event_push(Event *ev) { void event_push(Event* ev) {
if (event_num_free() == 0) { if (event_num_free() == 0) {
// TODO: How do we handle this? // TODO: How do we handle this?
return; return;

View File

@ -1,5 +1,7 @@
#include "leds.h" #include "leds.h"
#include "main.h" #include "main.h"
#include "stm32g4xx_hal.h" #include "stm32g4xx_hal.h"
#include "stm32g4xx_hal_gpio.h" #include "stm32g4xx_hal_gpio.h"

View File

@ -114,7 +114,7 @@ int main(void) {
/* Infinite loop */ /* Infinite loop */
/* USER CODE BEGIN WHILE */ /* USER CODE BEGIN WHILE */
uint32_t rpi_active_since = 0; uint32_t last_can = 0;
while (1) { while (1) {
/* USER CODE END WHILE */ /* USER CODE END WHILE */
@ -126,6 +126,10 @@ int main(void) {
HAL_GPIO_WritePin(DISP_RESET_GPIO_Port, DISP_RESET_Pin, GPIO_PIN_SET); HAL_GPIO_WritePin(DISP_RESET_GPIO_Port, DISP_RESET_Pin, GPIO_PIN_SET);
} }
handle_events(); handle_events();
if (now - last_can > 100) {
// vehicle_send_mission_select(MISSION_ACCELERATION);
last_can = now;
}
} }
/* USER CODE END 3 */ /* USER CODE END 3 */
} }
@ -391,7 +395,7 @@ void Error_Handler(void) {
* @param line: assert_param error line source number * @param line: assert_param error line source number
* @retval None * @retval None
*/ */
void assert_failed(uint8_t *file, uint32_t line) { void assert_failed(uint8_t* file, uint32_t line) {
/* USER CODE BEGIN 6 */ /* USER CODE BEGIN 6 */
/* User can add his own implementation to report the file name and line /* User can add his own implementation to report the file name and line
number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file, number, ex: printf("Wrong parameters value: file %s on line %d\r\n", file,

View File

@ -1,9 +1,12 @@
#include "rpi.h" #include "rpi.h"
#include "main.h" #include "main.h"
#include "state.h" #include "state.h"
#include "stm32g4xx_hal_def.h" #include "stm32g4xx_hal_def.h"
#include "stm32g4xx_hal_gpio.h" #include "stm32g4xx_hal_gpio.h"
#include "stm32g4xx_hal_i2c.h" #include "stm32g4xx_hal_i2c.h"
#include <stdint.h> #include <stdint.h>
uint8_t i2c_rx_buf[I2C_RX_BUF_SIZE]; uint8_t i2c_rx_buf[I2C_RX_BUF_SIZE];
@ -12,10 +15,10 @@ uint8_t i2c_tx_len;
RPiI2CState rpi_i2c_state; RPiI2CState rpi_i2c_state;
size_t rpi_num_polls; size_t rpi_num_polls;
static I2C_HandleTypeDef *bus; static I2C_HandleTypeDef* bus;
static uint8_t current_command; static uint8_t current_command;
void rpi_init(I2C_HandleTypeDef *handle) { void rpi_init(I2C_HandleTypeDef* handle) {
bus = handle; bus = handle;
rpi_i2c_state = RPI_I2C_IDLE; rpi_i2c_state = RPI_I2C_IDLE;
rpi_num_polls = 0; rpi_num_polls = 0;
@ -51,7 +54,7 @@ void rpi_update_tx_buffer_ami() {
i2c_tx_buf[1] = stw_state.view_state.ami.current_mission; i2c_tx_buf[1] = stw_state.view_state.ami.current_mission;
} }
void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *handle) { void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef* handle) {
switch (rpi_i2c_state) { switch (rpi_i2c_state) {
case RPI_I2C_SENDING_DATA_SIZE: case RPI_I2C_SENDING_DATA_SIZE:
if (HAL_I2C_Slave_Seq_Transmit_IT(bus, i2c_tx_buf, i2c_tx_len, if (HAL_I2C_Slave_Seq_Transmit_IT(bus, i2c_tx_buf, i2c_tx_len,
@ -70,7 +73,7 @@ void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *handle) {
} }
} }
void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *handle) { void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef* handle) {
if (rpi_i2c_state != RPI_I2C_WAITING_FOR_COMMAND) { if (rpi_i2c_state != RPI_I2C_WAITING_FOR_COMMAND) {
// TODO: How do we handle this? // TODO: How do we handle this?
return; return;
@ -81,7 +84,7 @@ void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *handle) {
rpi_i2c_state = RPI_I2C_WAITING_FOR_MASTER_RECEIVE; rpi_i2c_state = RPI_I2C_WAITING_FOR_MASTER_RECEIVE;
} }
void HAL_I2C_AddrCallback(I2C_HandleTypeDef *handle, uint8_t TransferDirection, void HAL_I2C_AddrCallback(I2C_HandleTypeDef* handle, uint8_t TransferDirection,
uint16_t AddrMatchCode) { uint16_t AddrMatchCode) {
if (handle != bus) { if (handle != bus) {
HAL_GPIO_WritePin(LED_SER_GPIO_Port, LED_SER_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(LED_SER_GPIO_Port, LED_SER_Pin, GPIO_PIN_RESET);
@ -116,7 +119,7 @@ void HAL_I2C_AddrCallback(I2C_HandleTypeDef *handle, uint8_t TransferDirection,
} }
} }
void HAL_I2C_ListenCpltCallback(I2C_HandleTypeDef *handle) { void HAL_I2C_ListenCpltCallback(I2C_HandleTypeDef* handle) {
if (handle != bus) { if (handle != bus) {
return; return;
} }

View File

@ -3,9 +3,10 @@
#include "events.h" #include "events.h"
#include "main.h" #include "main.h"
#include "state.h" #include "state.h"
#include "stm32g4xx_hal_gpio.h"
#include "vehicle.h" #include "vehicle.h"
#include "stm32g4xx_hal_gpio.h"
void HAL_GPIO_EXTI_Callback(uint16_t pin) { void HAL_GPIO_EXTI_Callback(uint16_t pin) {
Event ev; Event ev;
@ -35,7 +36,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t pin) {
event_push(&ev); event_push(&ev);
} }
void handle_button_press(const ButtonPressEvent *ev) { void handle_button_press(const ButtonPressEvent* ev) {
switch (stw_state.view) { switch (stw_state.view) {
case VIEW_MISSION_SELECT: case VIEW_MISSION_SELECT:
handle_button_press_mission_select(ev); handle_button_press_mission_select(ev);
@ -47,10 +48,10 @@ void handle_button_press(const ButtonPressEvent *ev) {
} }
} }
void handle_button_press_mission_select(const ButtonPressEvent *ev) { void handle_button_press_mission_select(const ButtonPressEvent* ev) {
switch (*ev) { switch (*ev) {
case BTN_PRESS_PREV: { case BTN_PRESS_PREV: {
Mission *selection = &stw_state.view_state.mission_select.selection; Mission* selection = &stw_state.view_state.mission_select.selection;
if (*selection == MISSION_ACCELERATION || *selection == MISSION_NONE) { if (*selection == MISSION_ACCELERATION || *selection == MISSION_NONE) {
*selection = MISSION_MANUAL; *selection = MISSION_MANUAL;
} else { } else {
@ -64,7 +65,7 @@ void handle_button_press_mission_select(const ButtonPressEvent *ev) {
vehicle_send_mission_select(stw_state.view_state.mission_select.selection); vehicle_send_mission_select(stw_state.view_state.mission_select.selection);
break; break;
case BTN_PRESS_NEXT: { case BTN_PRESS_NEXT: {
Mission *selection = &stw_state.view_state.mission_select.selection; Mission* selection = &stw_state.view_state.mission_select.selection;
if (*selection == MISSION_MANUAL) { if (*selection == MISSION_MANUAL) {
*selection = MISSION_ACCELERATION; *selection = MISSION_ACCELERATION;
} else { } else {

View File

@ -1,14 +1,16 @@
#include "vehicle.h" #include "vehicle.h"
#include "main.h" #include "main.h"
#include "state.h" #include "state.h"
#include "stm32g4xx_hal_def.h" #include "stm32g4xx_hal_def.h"
#include "stm32g4xx_hal_fdcan.h" #include "stm32g4xx_hal_fdcan.h"
FDCAN_HandleTypeDef *can; FDCAN_HandleTypeDef* can;
void handle_as_mission_fb(FDCAN_RxHeaderTypeDef *header, uint8_t *data); void handle_as_mission_fb(FDCAN_RxHeaderTypeDef* header, uint8_t* data);
void vehicle_init(FDCAN_HandleTypeDef *handle) { void vehicle_init(FDCAN_HandleTypeDef* handle) {
can = handle; can = handle;
// RX Filter // RX Filter
@ -67,7 +69,7 @@ void vehicle_send_mission_select(Mission mission) {
/* BEGIN CAN MESSAGE HANDLERS { */ /* BEGIN CAN MESSAGE HANDLERS { */
void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *handle, void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef* handle,
uint32_t interrupt_flags) { uint32_t interrupt_flags) {
if (!(interrupt_flags & FDCAN_IT_RX_FIFO0_NEW_MESSAGE)) { if (!(interrupt_flags & FDCAN_IT_RX_FIFO0_NEW_MESSAGE)) {
return; return;
@ -91,7 +93,7 @@ void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *handle,
} }
} }
void handle_as_mission_fb(FDCAN_RxHeaderTypeDef *header, uint8_t *data) { void handle_as_mission_fb(FDCAN_RxHeaderTypeDef* header, uint8_t* data) {
Mission mission_fb = data[0]; Mission mission_fb = data[0];
if (mission_fb == MISSION_NONE) { if (mission_fb == MISSION_NONE) {
return; return;