diff --git a/a8000_protocol b/a8000_protocol index 1743a4b..430dd70 160000 --- a/a8000_protocol +++ b/a8000_protocol @@ -1 +1 @@ -Subproject commit 1743a4bfa958a6c9ea286edd4c82a129891a5aea +Subproject commit 430dd705b44a5bb29df6958c6a6af927ca1acc7c diff --git a/sdk b/sdk index 4fbd2bd..77be652 160000 --- a/sdk +++ b/sdk @@ -1 +1 @@ -Subproject commit 4fbd2bdf3a29557a93e7d1ae8d9ce6d14c5b970b +Subproject commit 77be6521422643010153ee3c51f9476c1387b7ad diff --git a/usrc/board.h b/usrc/board.h deleted file mode 100644 index df301f3..0000000 --- a/usrc/board.h +++ /dev/null @@ -1,25 +0,0 @@ -#pragma once - -#define TMC_MOTOR_SPI hspi1 -// JL_CSN -#define MOTOR1_CSN PA4 -#define MOTOR1_ENN PE3 -#define MOTOR1_SPI_MODE_SELECT PinNull -#define MOTOR1_REFL PD13 -#define MOTOR1_REFR PD14 -// SL_CSN -#define MOTOR2_CSN PA8 -#define MOTOR2_ENN PE6 -#define MOTOR2_SPI_MODE_SELECT PinNull -#define MOTOR2_REFL PD11 -#define MOTOR2_REFR PD12 -// CL_CSN -#define MOTOR3_CSN PA15 -#define MOTOR3_ENN PE7 -#define MOTOR3_SPI_MODE_SELECT PinNull -#define MOTOR3_REFL PD9 -#define MOTOR3_REFR PD10 - -#define MOTOR_CFG_FLASH_MARK "MOTOR_CFG_FLASH_MARK" - -#define BOARD_ID 6 diff --git a/usrc/configs/device_id_mgr.cpp b/usrc/configs/device_id_mgr.cpp index 7908d3b..770207c 100644 --- a/usrc/configs/device_id_mgr.cpp +++ b/usrc/configs/device_id_mgr.cpp @@ -47,4 +47,4 @@ int32_t zdevice_id_mgr_get_device_id() { return 0; } return *deviceId; -} \ No newline at end of file +} diff --git a/usrc/gservice.hpp b/usrc/gservice.hpp index 36e3d13..42b09e5 100644 --- a/usrc/gservice.hpp +++ b/usrc/gservice.hpp @@ -1,7 +1,7 @@ #include #include -#include "a8000_protocol\zcan_protocol_parser.hpp" +#include "sdk/components/zcancmder/zcan_protocol_parser.hpp" #include "sdk/chip/chip.hpp" #include "sdk/components/zcancmder/zcanreceiver.hpp" #include "sdk/os/zos.hpp" @@ -17,7 +17,8 @@ class GService { static GService* inst(); - ZCanReceiver* getZCanReceiver() { return &zcanreceiver; } + ZCanReceiver* getZCanReceiver() { return &zcanreceiver; } + ZCanProtocolParser* getZCanProtocolParser() { return &zcan_protocol_parser; } }; } // namespace iflytop diff --git a/usrc/main.cpp b/usrc/main.cpp index 27e963a..42b3377 100644 --- a/usrc/main.cpp +++ b/usrc/main.cpp @@ -1,8 +1,6 @@ #include #include -#include "board.h" -// #include "configs/device_id_mgr.hpp" #include "gservice.hpp" #include "sdk/chip/chip.hpp" diff --git a/usrc/subboards/subboard30_shake_module/subboard30_shake_module.cpp b/usrc/subboards/subboard30_shake_module/subboard30_shake_module.cpp index 03b08bb..0cb9cb4 100644 --- a/usrc/subboards/subboard30_shake_module/subboard30_shake_module.cpp +++ b/usrc/subboards/subboard30_shake_module/subboard30_shake_module.cpp @@ -1,11 +1,110 @@ #include "subboard30_shake_module.hpp" +extern "C" { +#include "subboard30_shake_module_board.h" +} +#include "usrc/gservice.hpp" + +#define TAG "ShakeModule" using namespace iflytop; Subboard30ShakeModule::Subboard30ShakeModule(/* args */) {} Subboard30ShakeModule::~Subboard30ShakeModule() {} -void Subboard30ShakeModule::initialize() {} +int32_t Subboard30ShakeModule::getmoduleId(int off) { return zdevice_id_mgr_get_device_id() + off; } + +void Subboard30ShakeModule::initialize() { + MX_SPI1_Init(); + + /*********************************************************************************************************************** + * ID1 * + ***********************************************************************************************************************/ + { + static TMC5130 motor; + static StepMotorCtrlModule module; + int subid = 1; + + TMC5130::cfg_t tmc5130cfg = { + .spi = &TMC_MOTOR_SPI, // + .csgpio = MOTOR1_CSN, // + .ennPin = MOTOR1_ENN, // + .spi_mode_select = MOTOR1_SPI_MODE_SELECT, // + }; + motor.initialize(&tmc5130cfg); + motor.setMotorShaft(false); + + static ZGPIO input[2]; + input[0].initAsInput(MOTOR1_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); + input[1].initAsInput(MOTOR1_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); + + StepMotorCtrlModule::flash_config_t stepcfg = {0}; + StepMotorCtrlModule::create_default_cfg(stepcfg); + stepcfg.base_param.stepmotor_irun = 15; + + module.initialize(getmoduleId(subid), &motor, input, ZARRAY_SIZE(input), nullptr, &stepcfg); + GService::inst()->getZCanProtocolParser()->registerModule(&module); + + ZLOGI(TAG, "motor%d readic version %x", subid, motor.readICVersion()); + } + /*********************************************************************************************************************** + * ID2 * + ***********************************************************************************************************************/ + { + static TMC5130 motor; + static StepMotorCtrlModule module; + int subid = 2; + + TMC5130::cfg_t tmc5130cfg = { + .spi = &TMC_MOTOR_SPI, // + .csgpio = MOTOR2_CSN, // + .ennPin = MOTOR2_ENN, // + .spi_mode_select = MOTOR2_SPI_MODE_SELECT, // + }; + motor.initialize(&tmc5130cfg); + motor.setMotorShaft(false); + + static ZGPIO input[2]; + input[0].initAsInput(MOTOR2_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); + input[1].initAsInput(MOTOR2_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); + + StepMotorCtrlModule::flash_config_t stepcfg = {0}; + StepMotorCtrlModule::create_default_cfg(stepcfg); + stepcfg.base_param.stepmotor_irun = 15; + + module.initialize(getmoduleId(subid), &motor, input, ZARRAY_SIZE(input), nullptr, &stepcfg); + GService::inst()->getZCanProtocolParser()->registerModule(&module); + ZLOGI(TAG, "motor%d readic version %x", subid, motor.readICVersion()); + } + /*********************************************************************************************************************** + * ID3 * + ***********************************************************************************************************************/ + { + static TMC5130 motor; + static StepMotorCtrlModule module; + int subid = 3; + + TMC5130::cfg_t tmc5130cfg = { + .spi = &TMC_MOTOR_SPI, // + .csgpio = MOTOR3_CSN, // + .ennPin = MOTOR3_ENN, // + .spi_mode_select = MOTOR3_SPI_MODE_SELECT, // + }; + motor.initialize(&tmc5130cfg); + motor.setMotorShaft(false); + + static ZGPIO input[2]; + input[0].initAsInput(MOTOR3_REFL /*REFL*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); + input[1].initAsInput(MOTOR3_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); + + StepMotorCtrlModule::flash_config_t stepcfg = {0}; + StepMotorCtrlModule::create_default_cfg(stepcfg); + stepcfg.base_param.stepmotor_irun = 15; + + module.initialize(getmoduleId(subid), &motor, input, ZARRAY_SIZE(input), nullptr, &stepcfg); + GService::inst()->getZCanProtocolParser()->registerModule(&module); + ZLOGI(TAG, "motor%d readic version %x", subid, motor.readICVersion()); + } +} Subboard30ShakeModule* Subboard30ShakeModule::ins() { static Subboard30ShakeModule instance; diff --git a/usrc/subboards/subboard30_shake_module/subboard30_shake_module.hpp b/usrc/subboards/subboard30_shake_module/subboard30_shake_module.hpp index 5074d89..0136520 100644 --- a/usrc/subboards/subboard30_shake_module/subboard30_shake_module.hpp +++ b/usrc/subboards/subboard30_shake_module/subboard30_shake_module.hpp @@ -1,16 +1,20 @@ #include #include -#include "board.h" // #include "configs/device_id_mgr.hpp" #include "sdk/chip/chip.hpp" #include "sdk/os/zos.hpp" +// +#include "sdk\components\step_motor_ctrl_module\step_motor_ctrl_module.hpp" +#include "sdk\components\tmc\ic\ztmc5130.hpp" namespace iflytop { class Subboard30ShakeModule { private: /* data */ + + public: Subboard30ShakeModule(/* args */); ~Subboard30ShakeModule(); @@ -18,6 +22,9 @@ class Subboard30ShakeModule { static Subboard30ShakeModule* ins(); void initialize(); + + private: + int32_t getmoduleId(int off); }; } // namespace iflytop diff --git a/usrc/subboards/subboard30_shake_module/subboard30_shake_module_board.c b/usrc/subboards/subboard30_shake_module/subboard30_shake_module_board.c new file mode 100644 index 0000000..a9e04cd --- /dev/null +++ b/usrc/subboards/subboard30_shake_module/subboard30_shake_module_board.c @@ -0,0 +1,63 @@ +#include "main.h" + +/* USER CODE BEGIN 0 */ + +/* USER CODE END 0 */ +SPI_HandleTypeDef hspi1; + +/* SPI1 init function */ +void MX_SPI1_Init(void) { + /* USER CODE BEGIN SPI1_Init 0 */ + + /* USER CODE END SPI1_Init 0 */ + + /* 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; + hspi1.Init.DataSize = SPI_DATASIZE_8BIT; + hspi1.Init.CLKPolarity = SPI_POLARITY_LOW; + hspi1.Init.CLKPhase = SPI_PHASE_1EDGE; + hspi1.Init.NSS = SPI_NSS_SOFT; + hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32; + hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB; + hspi1.Init.TIMode = SPI_TIMODE_DISABLE; + hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE; + hspi1.Init.CRCPolynomial = 10; + if (HAL_SPI_Init(&hspi1) != HAL_OK) { + Error_Handler(); + } + /* USER CODE BEGIN SPI1_Init 2 */ + + /* USER CODE END SPI1_Init 2 */ +} + +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 */ + } +} \ No newline at end of file diff --git a/usrc/subboards/subboard30_shake_module/subboard30_shake_module_board.h b/usrc/subboards/subboard30_shake_module/subboard30_shake_module_board.h new file mode 100644 index 0000000..bcc868d --- /dev/null +++ b/usrc/subboards/subboard30_shake_module/subboard30_shake_module_board.h @@ -0,0 +1,28 @@ +#pragma once +#include "main.h" +#define TMC_MOTOR_SPI hspi1 +// JL_CSN +#define MOTOR1_CSN PA4 +#define MOTOR1_ENN PE3 +#define MOTOR1_SPI_MODE_SELECT PinNull +#define MOTOR1_REFL PD13 +#define MOTOR1_REFR PD14 +// SL_CSN +#define MOTOR2_CSN PA8 +#define MOTOR2_ENN PE6 +#define MOTOR2_SPI_MODE_SELECT PinNull +#define MOTOR2_REFL PD11 +#define MOTOR2_REFR PD12 +// CL_CSN +#define MOTOR3_CSN PA15 +#define MOTOR3_ENN PE7 +#define MOTOR3_SPI_MODE_SELECT PinNull +#define MOTOR3_REFL PD9 +#define MOTOR3_REFR PD10 + +#define MOTOR_CFG_FLASH_MARK "MOTOR_CFG_FLASH_MARK" + +#define BOARD_ID 6 + +extern SPI_HandleTypeDef hspi1; +void MX_SPI1_Init(void); \ No newline at end of file