Add .clang-format and .editorconfig
This commit is contained in:
parent
b28ff29f45
commit
ec9fa4bb0f
137
.clang-format
Normal file
137
.clang-format
Normal 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
8
.editorconfig
Normal file
@ -0,0 +1,8 @@
|
||||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
charset = utf-8
|
||||
|
||||
[*.{h,c}]
|
||||
indent_style = space
|
||||
indent_size = 2
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,3 +1,3 @@
|
||||
build/
|
||||
.cache/
|
||||
.vscode/
|
||||
.vscode/
|
||||
|
@ -42,7 +42,7 @@ typedef struct {
|
||||
* The event is deep-copied to the queue, so it can be deallocated after the
|
||||
* call is complete.
|
||||
*/
|
||||
void event_push(Event *ev);
|
||||
void event_push(Event* ev);
|
||||
/**
|
||||
* @brief Pop an event from the start of the queue.
|
||||
*
|
||||
@ -57,4 +57,4 @@ uint16_t event_num_free();
|
||||
|
||||
void handle_events();
|
||||
|
||||
#endif // __EVENTS_H
|
||||
#endif // __EVENTS_H
|
||||
|
@ -3,4 +3,4 @@
|
||||
|
||||
void leds_init();
|
||||
|
||||
#endif // __LEDS_H
|
||||
#endif // __LEDS_H
|
||||
|
212
Core/Inc/main.h
212
Core/Inc/main.h
@ -1,106 +1,106 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.h
|
||||
* @brief : Header for main.c file.
|
||||
* This file contains the common defines of the application.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __MAIN_H
|
||||
#define __MAIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32g4xx_hal.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
|
||||
/* USER CODE END ET */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EC */
|
||||
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EM */
|
||||
|
||||
/* USER CODE END EM */
|
||||
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
void Error_Handler(void);
|
||||
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
#define TOP_PWM_Pin GPIO_PIN_0
|
||||
#define TOP_PWM_GPIO_Port GPIOA
|
||||
#define LOGO_PWM_Pin GPIO_PIN_1
|
||||
#define LOGO_PWM_GPIO_Port GPIOA
|
||||
#define LED_ICLK_Pin GPIO_PIN_2
|
||||
#define LED_ICLK_GPIO_Port GPIOA
|
||||
#define LED_OCLK_Pin GPIO_PIN_3
|
||||
#define LED_OCLK_GPIO_Port GPIOA
|
||||
#define LED_NCLR_Pin GPIO_PIN_4
|
||||
#define LED_NCLR_GPIO_Port GPIOA
|
||||
#define LED_SER_Pin GPIO_PIN_5
|
||||
#define LED_SER_GPIO_Port GPIOA
|
||||
#define LED_NOE_Pin GPIO_PIN_6
|
||||
#define LED_NOE_GPIO_Port GPIOA
|
||||
#define V_POT_Pin GPIO_PIN_11
|
||||
#define V_POT_GPIO_Port GPIOB
|
||||
#define BTN0_Pin GPIO_PIN_12
|
||||
#define BTN0_GPIO_Port GPIOB
|
||||
#define BTN0_EXTI_IRQn EXTI15_10_IRQn
|
||||
#define BTN1_Pin GPIO_PIN_13
|
||||
#define BTN1_GPIO_Port GPIOB
|
||||
#define BTN1_EXTI_IRQn EXTI15_10_IRQn
|
||||
#define BTN2_Pin GPIO_PIN_14
|
||||
#define BTN2_GPIO_Port GPIOB
|
||||
#define BTN2_EXTI_IRQn EXTI15_10_IRQn
|
||||
#define BTN3_Pin GPIO_PIN_15
|
||||
#define BTN3_GPIO_Port GPIOB
|
||||
#define BTN3_EXTI_IRQn EXTI15_10_IRQn
|
||||
#define DISP_RESET_Pin GPIO_PIN_15
|
||||
#define DISP_RESET_GPIO_Port GPIOA
|
||||
#define ENC0A_Pin GPIO_PIN_4
|
||||
#define ENC0A_GPIO_Port GPIOB
|
||||
#define ENC0B_Pin GPIO_PIN_5
|
||||
#define ENC0B_GPIO_Port GPIOB
|
||||
#define ENC1A_Pin GPIO_PIN_6
|
||||
#define ENC1A_GPIO_Port GPIOB
|
||||
#define ENC1B_Pin GPIO_PIN_7
|
||||
#define ENC1B_GPIO_Port GPIOB
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __MAIN_H */
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.h
|
||||
* @brief : Header for main.c file.
|
||||
* This file contains the common defines of the application.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __MAIN_H
|
||||
#define __MAIN_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "stm32g4xx_hal.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Exported types ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN ET */
|
||||
|
||||
/* USER CODE END ET */
|
||||
|
||||
/* Exported constants --------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EC */
|
||||
|
||||
/* USER CODE END EC */
|
||||
|
||||
/* Exported macro ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN EM */
|
||||
|
||||
/* USER CODE END EM */
|
||||
|
||||
/* Exported functions prototypes ---------------------------------------------*/
|
||||
void Error_Handler(void);
|
||||
|
||||
/* USER CODE BEGIN EFP */
|
||||
|
||||
/* USER CODE END EFP */
|
||||
|
||||
/* Private defines -----------------------------------------------------------*/
|
||||
#define TOP_PWM_Pin GPIO_PIN_0
|
||||
#define TOP_PWM_GPIO_Port GPIOA
|
||||
#define LOGO_PWM_Pin GPIO_PIN_1
|
||||
#define LOGO_PWM_GPIO_Port GPIOA
|
||||
#define LED_ICLK_Pin GPIO_PIN_2
|
||||
#define LED_ICLK_GPIO_Port GPIOA
|
||||
#define LED_OCLK_Pin GPIO_PIN_3
|
||||
#define LED_OCLK_GPIO_Port GPIOA
|
||||
#define LED_NCLR_Pin GPIO_PIN_4
|
||||
#define LED_NCLR_GPIO_Port GPIOA
|
||||
#define LED_SER_Pin GPIO_PIN_5
|
||||
#define LED_SER_GPIO_Port GPIOA
|
||||
#define LED_NOE_Pin GPIO_PIN_6
|
||||
#define LED_NOE_GPIO_Port GPIOA
|
||||
#define V_POT_Pin GPIO_PIN_11
|
||||
#define V_POT_GPIO_Port GPIOB
|
||||
#define BTN0_Pin GPIO_PIN_12
|
||||
#define BTN0_GPIO_Port GPIOB
|
||||
#define BTN0_EXTI_IRQn EXTI15_10_IRQn
|
||||
#define BTN1_Pin GPIO_PIN_13
|
||||
#define BTN1_GPIO_Port GPIOB
|
||||
#define BTN1_EXTI_IRQn EXTI15_10_IRQn
|
||||
#define BTN2_Pin GPIO_PIN_14
|
||||
#define BTN2_GPIO_Port GPIOB
|
||||
#define BTN2_EXTI_IRQn EXTI15_10_IRQn
|
||||
#define BTN3_Pin GPIO_PIN_15
|
||||
#define BTN3_GPIO_Port GPIOB
|
||||
#define BTN3_EXTI_IRQn EXTI15_10_IRQn
|
||||
#define DISP_RESET_Pin GPIO_PIN_15
|
||||
#define DISP_RESET_GPIO_Port GPIOA
|
||||
#define ENC0A_Pin GPIO_PIN_4
|
||||
#define ENC0A_GPIO_Port GPIOB
|
||||
#define ENC0B_Pin GPIO_PIN_5
|
||||
#define ENC0B_GPIO_Port GPIOB
|
||||
#define ENC1A_Pin GPIO_PIN_6
|
||||
#define ENC1A_GPIO_Port GPIOB
|
||||
#define ENC1B_Pin GPIO_PIN_7
|
||||
#define ENC1B_GPIO_Port GPIOB
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __MAIN_H */
|
||||
|
@ -25,7 +25,7 @@ extern RPiI2CState rpi_i2c_state;
|
||||
|
||||
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_mission_select();
|
||||
|
@ -2,10 +2,11 @@
|
||||
#define __FT_USER_INPUTS_H
|
||||
|
||||
#include "events.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
|
||||
|
@ -2,14 +2,15 @@
|
||||
#define __VEHICLE_H
|
||||
|
||||
#include "state.h"
|
||||
|
||||
#include "stm32g4xx_hal.h"
|
||||
#include "stm32g4xx_hal_fdcan.h"
|
||||
|
||||
#define CAN_ID_MISSION_SELECT 0x400
|
||||
#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);
|
||||
|
||||
#endif // __VEHICLE_H
|
||||
#endif // __VEHICLE_H
|
||||
|
@ -1,11 +1,13 @@
|
||||
#include "events.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "user_inputs.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
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) {
|
||||
// TODO: How do we handle this?
|
||||
return;
|
||||
@ -61,4 +63,4 @@ void handle_events() {
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
#include "leds.h"
|
||||
|
||||
#include "main.h"
|
||||
|
||||
#include "stm32g4xx_hal.h"
|
||||
#include "stm32g4xx_hal_gpio.h"
|
||||
|
||||
@ -24,4 +26,4 @@ void leds_init() {
|
||||
HAL_GPIO_WritePin(LED_OCLK_GPIO_Port, LED_OCLK_Pin, GPIO_PIN_SET);
|
||||
HAL_Delay(10);
|
||||
HAL_GPIO_WritePin(LED_OCLK_GPIO_Port, LED_OCLK_Pin, GPIO_PIN_RESET);
|
||||
}
|
||||
}
|
||||
|
798
Core/Src/main.c
798
Core/Src/main.c
@ -1,401 +1,405 @@
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.c
|
||||
* @brief : Main program body
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "events.h"
|
||||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file : main.c
|
||||
* @brief : Main program body
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2022 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include "events.h"
|
||||
#include "leds.h"
|
||||
#include "rpi.h"
|
||||
#include "state.h"
|
||||
#include "rpi.h"
|
||||
#include "state.h"
|
||||
#include "vehicle.h"
|
||||
|
||||
#include "stm32g4xx_hal.h"
|
||||
#include "stm32g4xx_hal_gpio.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PTD */
|
||||
|
||||
/* USER CODE END PTD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
ADC_HandleTypeDef hadc1;
|
||||
|
||||
FDCAN_HandleTypeDef hfdcan1;
|
||||
|
||||
I2C_HandleTypeDef hi2c2;
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void SystemClock_Config(void);
|
||||
static void MX_GPIO_Init(void);
|
||||
static void MX_ADC1_Init(void);
|
||||
static void MX_FDCAN1_Init(void);
|
||||
static void MX_I2C2_Init(void);
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
int main(void) {
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick.
|
||||
*/
|
||||
HAL_Init();
|
||||
|
||||
/* USER CODE BEGIN Init */
|
||||
|
||||
/* USER CODE END Init */
|
||||
|
||||
/* Configure the system clock */
|
||||
SystemClock_Config();
|
||||
|
||||
/* USER CODE BEGIN SysInit */
|
||||
|
||||
/* USER CODE END SysInit */
|
||||
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
MX_ADC1_Init();
|
||||
MX_FDCAN1_Init();
|
||||
MX_I2C2_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
#include "stm32g4xx_hal.h"
|
||||
#include "stm32g4xx_hal_gpio.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PTD */
|
||||
|
||||
/* USER CODE END PTD */
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
/* USER CODE END PD */
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PM */
|
||||
|
||||
/* USER CODE END PM */
|
||||
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
ADC_HandleTypeDef hadc1;
|
||||
|
||||
FDCAN_HandleTypeDef hfdcan1;
|
||||
|
||||
I2C_HandleTypeDef hi2c2;
|
||||
|
||||
/* USER CODE BEGIN PV */
|
||||
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
void SystemClock_Config(void);
|
||||
static void MX_GPIO_Init(void);
|
||||
static void MX_ADC1_Init(void);
|
||||
static void MX_FDCAN1_Init(void);
|
||||
static void MX_I2C2_Init(void);
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
|
||||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
* @brief The application entry point.
|
||||
* @retval int
|
||||
*/
|
||||
int main(void) {
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
|
||||
/* Reset of all peripherals, Initializes the Flash interface and the Systick.
|
||||
*/
|
||||
HAL_Init();
|
||||
|
||||
/* USER CODE BEGIN Init */
|
||||
|
||||
/* USER CODE END Init */
|
||||
|
||||
/* Configure the system clock */
|
||||
SystemClock_Config();
|
||||
|
||||
/* USER CODE BEGIN SysInit */
|
||||
|
||||
/* USER CODE END SysInit */
|
||||
|
||||
/* Initialize all configured peripherals */
|
||||
MX_GPIO_Init();
|
||||
MX_ADC1_Init();
|
||||
MX_FDCAN1_Init();
|
||||
MX_I2C2_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
leds_init();
|
||||
state_init();
|
||||
state_init();
|
||||
vehicle_init(&hfdcan1);
|
||||
rpi_init(&hi2c2);
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
uint32_t rpi_active_since = 0;
|
||||
while (1) {
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
uint32_t now = HAL_GetTick();
|
||||
if (now < 1000) {
|
||||
HAL_GPIO_WritePin(DISP_RESET_GPIO_Port, DISP_RESET_Pin, GPIO_PIN_RESET);
|
||||
} else {
|
||||
HAL_GPIO_WritePin(DISP_RESET_GPIO_Port, DISP_RESET_Pin, GPIO_PIN_SET);
|
||||
}
|
||||
handle_events();
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void) {
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||
|
||||
/** Configure the main internal regulator output voltage
|
||||
*/
|
||||
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
|
||||
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1;
|
||||
RCC_OscInitStruct.PLL.PLLN = 10;
|
||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||||
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
|
||||
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
|
||||
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ADC1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_ADC1_Init(void) {
|
||||
|
||||
/* USER CODE BEGIN ADC1_Init 0 */
|
||||
|
||||
/* USER CODE END ADC1_Init 0 */
|
||||
|
||||
ADC_MultiModeTypeDef multimode = {0};
|
||||
ADC_ChannelConfTypeDef sConfig = {0};
|
||||
|
||||
/* USER CODE BEGIN ADC1_Init 1 */
|
||||
|
||||
/* USER CODE END ADC1_Init 1 */
|
||||
|
||||
/** Common config
|
||||
*/
|
||||
hadc1.Instance = ADC1;
|
||||
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
|
||||
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
|
||||
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
||||
hadc1.Init.GainCompensation = 0;
|
||||
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
|
||||
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
|
||||
hadc1.Init.LowPowerAutoWait = DISABLE;
|
||||
hadc1.Init.ContinuousConvMode = DISABLE;
|
||||
hadc1.Init.NbrOfConversion = 1;
|
||||
hadc1.Init.DiscontinuousConvMode = DISABLE;
|
||||
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
||||
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
|
||||
hadc1.Init.DMAContinuousRequests = DISABLE;
|
||||
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
|
||||
hadc1.Init.OversamplingMode = DISABLE;
|
||||
if (HAL_ADC_Init(&hadc1) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Configure the ADC multi-mode
|
||||
*/
|
||||
multimode.Mode = ADC_MODE_INDEPENDENT;
|
||||
if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Configure Regular Channel
|
||||
*/
|
||||
sConfig.Channel = ADC_CHANNEL_14;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_1;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
|
||||
sConfig.SingleDiff = ADC_SINGLE_ENDED;
|
||||
sConfig.OffsetNumber = ADC_OFFSET_NONE;
|
||||
sConfig.Offset = 0;
|
||||
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN ADC1_Init 2 */
|
||||
|
||||
/* USER CODE END ADC1_Init 2 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief FDCAN1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_FDCAN1_Init(void) {
|
||||
|
||||
/* USER CODE BEGIN FDCAN1_Init 0 */
|
||||
|
||||
/* USER CODE END FDCAN1_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN FDCAN1_Init 1 */
|
||||
|
||||
/* USER CODE END FDCAN1_Init 1 */
|
||||
hfdcan1.Instance = FDCAN1;
|
||||
hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1;
|
||||
hfdcan1.Init.FrameFormat = FDCAN_FRAME_FD_BRS;
|
||||
hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
|
||||
hfdcan1.Init.AutoRetransmission = ENABLE;
|
||||
hfdcan1.Init.TransmitPause = ENABLE;
|
||||
hfdcan1.Init.ProtocolException = DISABLE;
|
||||
hfdcan1.Init.NominalPrescaler = 1;
|
||||
hfdcan1.Init.NominalSyncJumpWidth = 16;
|
||||
hfdcan1.Init.NominalTimeSeg1 = 63;
|
||||
hfdcan1.Init.NominalTimeSeg2 = 16;
|
||||
hfdcan1.Init.DataPrescaler = 1;
|
||||
hfdcan1.Init.DataSyncJumpWidth = 4;
|
||||
hfdcan1.Init.DataTimeSeg1 = 5;
|
||||
hfdcan1.Init.DataTimeSeg2 = 4;
|
||||
hfdcan1.Init.StdFiltersNbr = 2;
|
||||
hfdcan1.Init.ExtFiltersNbr = 0;
|
||||
hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
|
||||
if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN FDCAN1_Init 2 */
|
||||
|
||||
/* USER CODE END FDCAN1_Init 2 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief I2C2 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_I2C2_Init(void) {
|
||||
|
||||
/* USER CODE BEGIN I2C2_Init 0 */
|
||||
|
||||
/* USER CODE END I2C2_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN I2C2_Init 1 */
|
||||
|
||||
/* USER CODE END I2C2_Init 1 */
|
||||
hi2c2.Instance = I2C2;
|
||||
hi2c2.Init.Timing = 0x10909CEC;
|
||||
hi2c2.Init.OwnAddress1 = 64;
|
||||
hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
||||
hi2c2.Init.OwnAddress2 = 0;
|
||||
hi2c2.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
|
||||
hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
||||
hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
||||
if (HAL_I2C_Init(&hi2c2) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Configure Analogue filter
|
||||
*/
|
||||
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c2, I2C_ANALOGFILTER_ENABLE) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Configure Digital filter
|
||||
*/
|
||||
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c2, 0) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN I2C2_Init 2 */
|
||||
|
||||
/* USER CODE END I2C2_Init 2 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief GPIO Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_GPIO_Init(void) {
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOA,
|
||||
TOP_PWM_Pin | LOGO_PWM_Pin | LED_ICLK_Pin | LED_OCLK_Pin |
|
||||
LED_NCLR_Pin | LED_SER_Pin | LED_NOE_Pin |
|
||||
DISP_RESET_Pin,
|
||||
GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pins : TOP_PWM_Pin LOGO_PWM_Pin LED_ICLK_Pin LED_OCLK_Pin
|
||||
LED_NCLR_Pin LED_SER_Pin LED_NOE_Pin DISP_RESET_Pin
|
||||
*/
|
||||
GPIO_InitStruct.Pin = TOP_PWM_Pin | LOGO_PWM_Pin | LED_ICLK_Pin |
|
||||
LED_OCLK_Pin | LED_NCLR_Pin | LED_SER_Pin |
|
||||
LED_NOE_Pin | DISP_RESET_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : BTN0_Pin BTN1_Pin BTN2_Pin BTN3_Pin */
|
||||
GPIO_InitStruct.Pin = BTN0_Pin | BTN1_Pin | BTN2_Pin | BTN3_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : ENC0A_Pin ENC0B_Pin ENC1A_Pin ENC1B_Pin */
|
||||
GPIO_InitStruct.Pin = ENC0A_Pin | ENC0B_Pin | ENC1A_Pin | ENC1B_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/* EXTI interrupt init*/
|
||||
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
|
||||
/* USER CODE END 4 */
|
||||
|
||||
/**
|
||||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
*/
|
||||
void Error_Handler(void) {
|
||||
/* USER CODE BEGIN Error_Handler_Debug */
|
||||
/* User can add his own implementation to report the HAL error return state */
|
||||
__disable_irq();
|
||||
while (1) {
|
||||
}
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief Reports the name of the source file and the source line number
|
||||
* where the assert_param error has occurred.
|
||||
* @param file: pointer to the source file name
|
||||
* @param line: assert_param error line source number
|
||||
* @retval None
|
||||
*/
|
||||
void assert_failed(uint8_t *file, uint32_t line) {
|
||||
/* USER CODE BEGIN 6 */
|
||||
/* 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,
|
||||
line) */
|
||||
/* USER CODE END 6 */
|
||||
}
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
rpi_init(&hi2c2);
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
/* USER CODE BEGIN WHILE */
|
||||
uint32_t last_can = 0;
|
||||
while (1) {
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
/* USER CODE BEGIN 3 */
|
||||
uint32_t now = HAL_GetTick();
|
||||
if (now < 1000) {
|
||||
HAL_GPIO_WritePin(DISP_RESET_GPIO_Port, DISP_RESET_Pin, GPIO_PIN_RESET);
|
||||
} else {
|
||||
HAL_GPIO_WritePin(DISP_RESET_GPIO_Port, DISP_RESET_Pin, GPIO_PIN_SET);
|
||||
}
|
||||
handle_events();
|
||||
if (now - last_can > 100) {
|
||||
// vehicle_send_mission_select(MISSION_ACCELERATION);
|
||||
last_can = now;
|
||||
}
|
||||
}
|
||||
/* USER CODE END 3 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief System Clock Configuration
|
||||
* @retval None
|
||||
*/
|
||||
void SystemClock_Config(void) {
|
||||
RCC_OscInitTypeDef RCC_OscInitStruct = {0};
|
||||
RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
|
||||
|
||||
/** Configure the main internal regulator output voltage
|
||||
*/
|
||||
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
|
||||
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1;
|
||||
RCC_OscInitStruct.PLL.PLLN = 10;
|
||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||||
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
|
||||
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
|
||||
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Initializes the CPU, AHB and APB buses clocks
|
||||
*/
|
||||
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_SYSCLK |
|
||||
RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2;
|
||||
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
||||
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
||||
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
||||
|
||||
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief ADC1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_ADC1_Init(void) {
|
||||
|
||||
/* USER CODE BEGIN ADC1_Init 0 */
|
||||
|
||||
/* USER CODE END ADC1_Init 0 */
|
||||
|
||||
ADC_MultiModeTypeDef multimode = {0};
|
||||
ADC_ChannelConfTypeDef sConfig = {0};
|
||||
|
||||
/* USER CODE BEGIN ADC1_Init 1 */
|
||||
|
||||
/* USER CODE END ADC1_Init 1 */
|
||||
|
||||
/** Common config
|
||||
*/
|
||||
hadc1.Instance = ADC1;
|
||||
hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV2;
|
||||
hadc1.Init.Resolution = ADC_RESOLUTION_12B;
|
||||
hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
||||
hadc1.Init.GainCompensation = 0;
|
||||
hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
|
||||
hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
|
||||
hadc1.Init.LowPowerAutoWait = DISABLE;
|
||||
hadc1.Init.ContinuousConvMode = DISABLE;
|
||||
hadc1.Init.NbrOfConversion = 1;
|
||||
hadc1.Init.DiscontinuousConvMode = DISABLE;
|
||||
hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
||||
hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
|
||||
hadc1.Init.DMAContinuousRequests = DISABLE;
|
||||
hadc1.Init.Overrun = ADC_OVR_DATA_PRESERVED;
|
||||
hadc1.Init.OversamplingMode = DISABLE;
|
||||
if (HAL_ADC_Init(&hadc1) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Configure the ADC multi-mode
|
||||
*/
|
||||
multimode.Mode = ADC_MODE_INDEPENDENT;
|
||||
if (HAL_ADCEx_MultiModeConfigChannel(&hadc1, &multimode) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Configure Regular Channel
|
||||
*/
|
||||
sConfig.Channel = ADC_CHANNEL_14;
|
||||
sConfig.Rank = ADC_REGULAR_RANK_1;
|
||||
sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
|
||||
sConfig.SingleDiff = ADC_SINGLE_ENDED;
|
||||
sConfig.OffsetNumber = ADC_OFFSET_NONE;
|
||||
sConfig.Offset = 0;
|
||||
if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN ADC1_Init 2 */
|
||||
|
||||
/* USER CODE END ADC1_Init 2 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief FDCAN1 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_FDCAN1_Init(void) {
|
||||
|
||||
/* USER CODE BEGIN FDCAN1_Init 0 */
|
||||
|
||||
/* USER CODE END FDCAN1_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN FDCAN1_Init 1 */
|
||||
|
||||
/* USER CODE END FDCAN1_Init 1 */
|
||||
hfdcan1.Instance = FDCAN1;
|
||||
hfdcan1.Init.ClockDivider = FDCAN_CLOCK_DIV1;
|
||||
hfdcan1.Init.FrameFormat = FDCAN_FRAME_FD_BRS;
|
||||
hfdcan1.Init.Mode = FDCAN_MODE_NORMAL;
|
||||
hfdcan1.Init.AutoRetransmission = ENABLE;
|
||||
hfdcan1.Init.TransmitPause = ENABLE;
|
||||
hfdcan1.Init.ProtocolException = DISABLE;
|
||||
hfdcan1.Init.NominalPrescaler = 1;
|
||||
hfdcan1.Init.NominalSyncJumpWidth = 16;
|
||||
hfdcan1.Init.NominalTimeSeg1 = 63;
|
||||
hfdcan1.Init.NominalTimeSeg2 = 16;
|
||||
hfdcan1.Init.DataPrescaler = 1;
|
||||
hfdcan1.Init.DataSyncJumpWidth = 4;
|
||||
hfdcan1.Init.DataTimeSeg1 = 5;
|
||||
hfdcan1.Init.DataTimeSeg2 = 4;
|
||||
hfdcan1.Init.StdFiltersNbr = 2;
|
||||
hfdcan1.Init.ExtFiltersNbr = 0;
|
||||
hfdcan1.Init.TxFifoQueueMode = FDCAN_TX_FIFO_OPERATION;
|
||||
if (HAL_FDCAN_Init(&hfdcan1) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN FDCAN1_Init 2 */
|
||||
|
||||
/* USER CODE END FDCAN1_Init 2 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief I2C2 Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_I2C2_Init(void) {
|
||||
|
||||
/* USER CODE BEGIN I2C2_Init 0 */
|
||||
|
||||
/* USER CODE END I2C2_Init 0 */
|
||||
|
||||
/* USER CODE BEGIN I2C2_Init 1 */
|
||||
|
||||
/* USER CODE END I2C2_Init 1 */
|
||||
hi2c2.Instance = I2C2;
|
||||
hi2c2.Init.Timing = 0x10909CEC;
|
||||
hi2c2.Init.OwnAddress1 = 64;
|
||||
hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
||||
hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
||||
hi2c2.Init.OwnAddress2 = 0;
|
||||
hi2c2.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
|
||||
hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
||||
hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
||||
if (HAL_I2C_Init(&hi2c2) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Configure Analogue filter
|
||||
*/
|
||||
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c2, I2C_ANALOGFILTER_ENABLE) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/** Configure Digital filter
|
||||
*/
|
||||
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c2, 0) != HAL_OK) {
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN I2C2_Init 2 */
|
||||
|
||||
/* USER CODE END I2C2_Init 2 */
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief GPIO Initialization Function
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
static void MX_GPIO_Init(void) {
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
/* GPIO Ports Clock Enable */
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
|
||||
/*Configure GPIO pin Output Level */
|
||||
HAL_GPIO_WritePin(GPIOA,
|
||||
TOP_PWM_Pin | LOGO_PWM_Pin | LED_ICLK_Pin | LED_OCLK_Pin |
|
||||
LED_NCLR_Pin | LED_SER_Pin | LED_NOE_Pin |
|
||||
DISP_RESET_Pin,
|
||||
GPIO_PIN_RESET);
|
||||
|
||||
/*Configure GPIO pins : TOP_PWM_Pin LOGO_PWM_Pin LED_ICLK_Pin LED_OCLK_Pin
|
||||
LED_NCLR_Pin LED_SER_Pin LED_NOE_Pin DISP_RESET_Pin
|
||||
*/
|
||||
GPIO_InitStruct.Pin = TOP_PWM_Pin | LOGO_PWM_Pin | LED_ICLK_Pin |
|
||||
LED_OCLK_Pin | LED_NCLR_Pin | LED_SER_Pin |
|
||||
LED_NOE_Pin | DISP_RESET_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : BTN0_Pin BTN1_Pin BTN2_Pin BTN3_Pin */
|
||||
GPIO_InitStruct.Pin = BTN0_Pin | BTN1_Pin | BTN2_Pin | BTN3_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : ENC0A_Pin ENC0B_Pin ENC1A_Pin ENC1B_Pin */
|
||||
GPIO_InitStruct.Pin = ENC0A_Pin | ENC0B_Pin | ENC1A_Pin | ENC1B_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/* EXTI interrupt init*/
|
||||
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
|
||||
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
|
||||
/* USER CODE END 4 */
|
||||
|
||||
/**
|
||||
* @brief This function is executed in case of error occurrence.
|
||||
* @retval None
|
||||
*/
|
||||
void Error_Handler(void) {
|
||||
/* USER CODE BEGIN Error_Handler_Debug */
|
||||
/* User can add his own implementation to report the HAL error return state */
|
||||
__disable_irq();
|
||||
while (1) {
|
||||
}
|
||||
/* USER CODE END Error_Handler_Debug */
|
||||
}
|
||||
|
||||
#ifdef USE_FULL_ASSERT
|
||||
/**
|
||||
* @brief Reports the name of the source file and the source line number
|
||||
* where the assert_param error has occurred.
|
||||
* @param file: pointer to the source file name
|
||||
* @param line: assert_param error line source number
|
||||
* @retval None
|
||||
*/
|
||||
void assert_failed(uint8_t* file, uint32_t line) {
|
||||
/* USER CODE BEGIN 6 */
|
||||
/* 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,
|
||||
line) */
|
||||
/* USER CODE END 6 */
|
||||
}
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
@ -1,9 +1,12 @@
|
||||
#include "rpi.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "state.h"
|
||||
|
||||
#include "stm32g4xx_hal_def.h"
|
||||
#include "stm32g4xx_hal_gpio.h"
|
||||
#include "stm32g4xx_hal_i2c.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint8_t i2c_rx_buf[I2C_RX_BUF_SIZE];
|
||||
@ -12,10 +15,10 @@ uint8_t i2c_tx_len;
|
||||
RPiI2CState rpi_i2c_state;
|
||||
size_t rpi_num_polls;
|
||||
|
||||
static I2C_HandleTypeDef *bus;
|
||||
static I2C_HandleTypeDef* bus;
|
||||
static uint8_t current_command;
|
||||
|
||||
void rpi_init(I2C_HandleTypeDef *handle) {
|
||||
void rpi_init(I2C_HandleTypeDef* handle) {
|
||||
bus = handle;
|
||||
rpi_i2c_state = RPI_I2C_IDLE;
|
||||
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;
|
||||
}
|
||||
|
||||
void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef *handle) {
|
||||
void HAL_I2C_SlaveTxCpltCallback(I2C_HandleTypeDef* handle) {
|
||||
switch (rpi_i2c_state) {
|
||||
case RPI_I2C_SENDING_DATA_SIZE:
|
||||
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) {
|
||||
// TODO: How do we handle this?
|
||||
return;
|
||||
@ -81,7 +84,7 @@ void HAL_I2C_SlaveRxCpltCallback(I2C_HandleTypeDef *handle) {
|
||||
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) {
|
||||
if (handle != bus) {
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
@ -124,4 +127,4 @@ void HAL_I2C_ListenCpltCallback(I2C_HandleTypeDef *handle) {
|
||||
if (rpi_i2c_state == RPI_I2C_IDLE) {
|
||||
HAL_I2C_EnableListen_IT(bus);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,4 +5,4 @@ STWState stw_state;
|
||||
void state_init() {
|
||||
stw_state.view = VIEW_MISSION_SELECT;
|
||||
stw_state.view_state.mission_select.selection = MISSION_ACCELERATION;
|
||||
}
|
||||
}
|
||||
|
@ -3,9 +3,10 @@
|
||||
#include "events.h"
|
||||
#include "main.h"
|
||||
#include "state.h"
|
||||
#include "stm32g4xx_hal_gpio.h"
|
||||
#include "vehicle.h"
|
||||
|
||||
#include "stm32g4xx_hal_gpio.h"
|
||||
|
||||
void HAL_GPIO_EXTI_Callback(uint16_t pin) {
|
||||
Event ev;
|
||||
|
||||
@ -35,7 +36,7 @@ void HAL_GPIO_EXTI_Callback(uint16_t pin) {
|
||||
event_push(&ev);
|
||||
}
|
||||
|
||||
void handle_button_press(const ButtonPressEvent *ev) {
|
||||
void handle_button_press(const ButtonPressEvent* ev) {
|
||||
switch (stw_state.view) {
|
||||
case VIEW_MISSION_SELECT:
|
||||
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) {
|
||||
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) {
|
||||
*selection = MISSION_MANUAL;
|
||||
} 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);
|
||||
break;
|
||||
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) {
|
||||
*selection = MISSION_ACCELERATION;
|
||||
} else {
|
||||
@ -73,4 +74,4 @@ void handle_button_press_mission_select(const ButtonPressEvent *ev) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,16 @@
|
||||
#include "vehicle.h"
|
||||
|
||||
#include "main.h"
|
||||
#include "state.h"
|
||||
|
||||
#include "stm32g4xx_hal_def.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;
|
||||
|
||||
// RX Filter
|
||||
@ -67,7 +69,7 @@ void vehicle_send_mission_select(Mission mission) {
|
||||
|
||||
/* BEGIN CAN MESSAGE HANDLERS { */
|
||||
|
||||
void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *handle,
|
||||
void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef* handle,
|
||||
uint32_t interrupt_flags) {
|
||||
if (!(interrupt_flags & FDCAN_IT_RX_FIFO0_NEW_MESSAGE)) {
|
||||
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];
|
||||
if (mission_fb == MISSION_NONE) {
|
||||
return;
|
||||
@ -102,4 +104,4 @@ void handle_as_mission_fb(FDCAN_RxHeaderTypeDef *header, uint8_t *data) {
|
||||
stw_state.view = VIEW_AMI;
|
||||
}
|
||||
|
||||
/* } END CAN MESSAGE HANDLERS */
|
||||
/* } END CAN MESSAGE HANDLERS */
|
||||
|
Loading…
x
Reference in New Issue
Block a user