diff --git a/usrc/main.cpp b/usrc/main.cpp index fe4282d..b32af1c 100644 --- a/usrc/main.cpp +++ b/usrc/main.cpp @@ -2,9 +2,7 @@ #include #include "configs/device_id_mgr.hpp" -#include "gservice.hpp" -#include "public_service/common_hardware_init.h" -#include "public_service/gins.h" +#include "public_service/public_service.hpp" #include "sdk/chip/chip.hpp" #include "sdk/os/zos.hpp" #include "subboards/subboard30_shake_module/subboard30_shake_module.hpp" diff --git a/usrc/public_service/gins.c b/usrc/public_service/gins.c index cf54ef5..2d1710e 100644 --- a/usrc/public_service/gins.c +++ b/usrc/public_service/gins.c @@ -15,6 +15,8 @@ DMA_HandleTypeDef hdma1_stream1; DMA_HandleTypeDef hdma2_stream2; DMA_HandleTypeDef hdma1_stream3; +SPI_HandleTypeDef hspi1; + bool htim6_enable; bool htim7_enable; bool htim11_enable = true; @@ -23,4 +25,6 @@ bool huart1_enable; bool huart3_enable; bool hdma1_stream1_enable; bool hdma2_stream2_enable; -bool hdma1_stream3_enable; \ No newline at end of file +bool hdma1_stream3_enable; + +bool hspi1_enable; diff --git a/usrc/public_service/gins.h b/usrc/public_service/gins.h index 31fa902..c125f63 100644 --- a/usrc/public_service/gins.h +++ b/usrc/public_service/gins.h @@ -4,16 +4,20 @@ #include "main.h" +#ifdef __cplusplus +extern "C" { +#endif + extern TIM_HandleTypeDef htim6; extern TIM_HandleTypeDef htim7; extern TIM_HandleTypeDef htim11; extern CAN_HandleTypeDef hcan1; extern UART_HandleTypeDef huart1; extern UART_HandleTypeDef huart3; - -extern DMA_HandleTypeDef hdma1_stream1; -extern DMA_HandleTypeDef hdma2_stream2; -extern DMA_HandleTypeDef hdma1_stream3; +extern DMA_HandleTypeDef hdma1_stream1; +extern DMA_HandleTypeDef hdma2_stream2; +extern DMA_HandleTypeDef hdma1_stream3; +extern SPI_HandleTypeDef hspi1; extern bool htim6_enable; extern bool htim7_enable; @@ -23,4 +27,8 @@ extern bool huart1_enable; extern bool huart3_enable; extern bool hdma1_stream1_enable; extern bool hdma2_stream2_enable; -extern bool hdma1_stream3_enable; \ No newline at end of file +extern bool hdma1_stream3_enable; +extern bool hspi1_enable; +#ifdef __cplusplus +} +#endif diff --git a/usrc/gservice.cpp b/usrc/public_service/gservice.cpp similarity index 100% rename from usrc/gservice.cpp rename to usrc/public_service/gservice.cpp diff --git a/usrc/gservice.hpp b/usrc/public_service/gservice.hpp similarity index 100% rename from usrc/gservice.hpp rename to usrc/public_service/gservice.hpp diff --git a/usrc/public_service/public_service.h b/usrc/public_service/public_service.h new file mode 100644 index 0000000..2814b05 --- /dev/null +++ b/usrc/public_service/public_service.h @@ -0,0 +1,4 @@ +#pragma once + +#include "common_hardware_init.h" +#include "gins.h" diff --git a/usrc/public_service/public_service.hpp b/usrc/public_service/public_service.hpp new file mode 100644 index 0000000..b579fc3 --- /dev/null +++ b/usrc/public_service/public_service.hpp @@ -0,0 +1,5 @@ +#pragma once + +#include "common_hardware_init.h" +#include "gins.h" +#include "gservice.hpp" diff --git a/usrc/subboards/subboard30_shake_module/subboard30_shake_module.cpp b/usrc/subboards/subboard30_shake_module/subboard30_shake_module.cpp index fac882e..a9d28cd 100644 --- a/usrc/subboards/subboard30_shake_module/subboard30_shake_module.cpp +++ b/usrc/subboards/subboard30_shake_module/subboard30_shake_module.cpp @@ -2,7 +2,7 @@ extern "C" { #include "subboard30_shake_module_board.h" } -#include "usrc/gservice.hpp" + #define TAG "ShakeModule" diff --git a/usrc/subboards/subboard30_shake_module/subboard30_shake_module_board.c b/usrc/subboards/subboard30_shake_module/subboard30_shake_module_board.c index 28d6e8f..abcc36b 100644 --- a/usrc/subboards/subboard30_shake_module/subboard30_shake_module_board.c +++ b/usrc/subboards/subboard30_shake_module/subboard30_shake_module_board.c @@ -1,20 +1,11 @@ #include "main.h" -#include "public_service/common_hardware_init.h" -#if 0 -/* USER CODE BEGIN 0 */ - -/* USER CODE END 0 */ -SPI_HandleTypeDef hspi1; +#include "public_service/public_service.h" /* SPI1 init function */ void MX_SPI1_Init(void) { - /* USER CODE BEGIN SPI1_Init 0 */ - - /* USER CODE END SPI1_Init 0 */ + __HAL_RCC_SPI1_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); - /* USER CODE BEGIN SPI1_Init 1 */ - - /* USER CODE END SPI1_Init 1 */ hspi1.Instance = SPI1; hspi1.Init.Mode = SPI_MODE_MASTER; hspi1.Init.Direction = SPI_DIRECTION_2LINES; @@ -31,41 +22,17 @@ void MX_SPI1_Init(void) { Error_Handler(); } GPIO_InitTypeDef GPIO_InitStruct = {0}; - - - /* USER CODE BEGIN SPI1_Init 2 */ - - /* USER CODE END SPI1_Init 2 */ + GPIO_InitStruct.Pin = GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); + + hspi1_enable = true; } -void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle) { - GPIO_InitTypeDef GPIO_InitStruct = {0}; - if (spiHandle->Instance == SPI1) { - /* USER CODE BEGIN SPI1_MspInit 0 */ - - /* USER CODE END SPI1_MspInit 0 */ - /* SPI1 clock enable */ - __HAL_RCC_SPI1_CLK_ENABLE(); - - __HAL_RCC_GPIOA_CLK_ENABLE(); - /**SPI1 GPIO Configuration - PA5 ------> SPI1_SCK - PA6 ------> SPI1_MISO - PA7 ------> SPI1_MOSI - */ - GPIO_InitStruct.Pin = GPIO_PIN_5 | GPIO_PIN_6 | GPIO_PIN_7; - GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; - GPIO_InitStruct.Pull = GPIO_NOPULL; - GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; - GPIO_InitStruct.Alternate = GPIO_AF5_SPI1; - HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); - - /* USER CODE BEGIN SPI1_MspInit 1 */ - - /* USER CODE END SPI1_MspInit 1 */ - } +void subboard30_shake_module_board_init() { + common_hardware_init(); + MX_SPI1_Init(); } -#endif - -#include "public_service/gins.h" -void subboard30_shake_module_board_init() { common_hardware_init(); }