From ae73c2d31ab760a7a34dc7579510bd50779525e3 Mon Sep 17 00:00:00 2001 From: zhaohe Date: Tue, 4 Jun 2024 21:10:01 +0800 Subject: [PATCH] add code scaner --- a8000_protocol | 2 +- sdk | 2 +- .../subboard30_shake_module.cpp | 7 +- .../subboard30_shake_module.hpp | 1 + .../subboard60_inlet_and_outlet_module/pri_board.h | 89 +++++++++ .../subboard60_inlet_and_outlet_module.cpp | 217 +++++++++++++++++++++ .../subboard60_inlet_and_outlet_module.hpp | 44 +++++ .../subboard60_inlet_and_outlet_module_board.c | 109 +++++++++++ .../subboard60_inlet_and_outlet_module_board.h | 12 ++ 9 files changed, 480 insertions(+), 3 deletions(-) create mode 100644 usrc/subboards/subboard60_inlet_and_outlet_module/pri_board.h create mode 100644 usrc/subboards/subboard60_inlet_and_outlet_module/subboard60_inlet_and_outlet_module.cpp create mode 100644 usrc/subboards/subboard60_inlet_and_outlet_module/subboard60_inlet_and_outlet_module.hpp create mode 100644 usrc/subboards/subboard60_inlet_and_outlet_module/subboard60_inlet_and_outlet_module_board.c create mode 100644 usrc/subboards/subboard60_inlet_and_outlet_module/subboard60_inlet_and_outlet_module_board.h diff --git a/a8000_protocol b/a8000_protocol index 7e554cc..a85673b 160000 --- a/a8000_protocol +++ b/a8000_protocol @@ -1 +1 @@ -Subproject commit 7e554cc4d7040f8e680dad8f3f470551a1f87d90 +Subproject commit a85673b9c1b9a54c0e91a3e3f4299106a749e56d diff --git a/sdk b/sdk index 234f88f..0923cba 160000 --- a/sdk +++ b/sdk @@ -1 +1 @@ -Subproject commit 234f88f7bd3531684e19b52c7bf65737f788ac1c +Subproject commit 0923cbacbdd6c1c5858d5ec160a6f3dd3b23560e diff --git a/usrc/subboards/subboard30_shake_module/subboard30_shake_module.cpp b/usrc/subboards/subboard30_shake_module/subboard30_shake_module.cpp index efa668e..b94fdca 100644 --- a/usrc/subboards/subboard30_shake_module/subboard30_shake_module.cpp +++ b/usrc/subboards/subboard30_shake_module/subboard30_shake_module.cpp @@ -39,6 +39,12 @@ int32_t Subboard30ShakeModule::board_read_ext_io(int32_t ioindex, int32_t *val) return 0; } int32_t Subboard30ShakeModule::board_write_ext_io(int32_t ioindex, int32_t val) { return 0; } +int32_t Subboard30ShakeModule::board_read_muti_io(int32_t *val) { + for (int i = 0; i < ZARRAY_SIZE(IO); i++) { + *val |= IO[i].getState() << i; + } + return 0; +} void Subboard30ShakeModule::initialize() { IO[0].initAsInput(PinNull, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); @@ -164,7 +170,6 @@ void Subboard30ShakeModule::initialize() { StepMotorCtrlModule::config_t stepcfg = {0}; StepMotorCtrlModule::create_default_cfg(stepcfg); - stepcfg.motor_shaft = MOTOR3_MOTOR_SHAFT; stepcfg.motor_one_circle_pulse = MOTOR3_MOTOR_ONE_CIRCLE_PULSE; stepcfg.motor_one_circle_pulse_denominator = MOTOR3_MOTOR_ONE_CIRCLE_PULSE_DENOMINATOR; diff --git a/usrc/subboards/subboard30_shake_module/subboard30_shake_module.hpp b/usrc/subboards/subboard30_shake_module/subboard30_shake_module.hpp index 9dc59e4..a5c1a88 100644 --- a/usrc/subboards/subboard30_shake_module/subboard30_shake_module.hpp +++ b/usrc/subboards/subboard30_shake_module/subboard30_shake_module.hpp @@ -35,6 +35,7 @@ class Subboard30ShakeModule : public ZIBoard, public ZIModule { ***********************************************************************************************************************/ virtual int32_t board_read_ext_io(int32_t ioindex, int32_t *val); virtual int32_t board_write_ext_io(int32_t ioindex, int32_t val); + virtual int32_t board_read_muti_io(int32_t *val); private: int32_t getmoduleId(int off); diff --git a/usrc/subboards/subboard60_inlet_and_outlet_module/pri_board.h b/usrc/subboards/subboard60_inlet_and_outlet_module/pri_board.h new file mode 100644 index 0000000..849ff32 --- /dev/null +++ b/usrc/subboards/subboard60_inlet_and_outlet_module/pri_board.h @@ -0,0 +1,89 @@ +#pragma once + +#define TMC_MOTOR_SPI hspi1 +/*********************************************************************************************************************** + * 进料电机 * + ***********************************************************************************************************************/ +#define MOTOR1_CSN PA4 +#define MOTOR1_ENN PE3 +#define MOTOR1_SPI_MODE_SELECT PinNull + +#define MOTOR1_REFL PinNull +#define MOTOR1_REFR PinNull +#define MOTOR1_REFL_MIRROR false +#define MOTOR1_REFR_MIRROR false + +#define MOTOR1_MOTOR_SHAFT false // +#define MOTOR1_MOTOR_ONE_CIRCLE_PULSE 100 // +#define MOTOR1_MOTOR_ONE_CIRCLE_PULSE_DENOMINATOR 1 +#define MOTOR1_STEPMOTOR_IHOLD 2 +#define MOTOR1_STEPMOTOR_IRUN 24 +#define MOTOR1_STEPMOTOR_IHOLDDELAY 100 +#define MOTOR1_STEPMOTOR_IGLOBALSCALER 1 +#define MOTOR1_MOTOR_DEFAULT_ACC 300 +#define MOTOR1_MOTOR_DEFAULT_DEC 300 +#define MOTOR1_MOTOR_DEFAULT_VELOCITY 300 +#define MOTOR1_MIN_D 0 +#define MOTOR1_MAX_D 0 +#define MOTOR1_MOTOR_RUN_TO_ZERO_SPEED 0 +#define MOTOR1_MOTOR_RUN_TO_ZERO_DEC 0 +#define MOTOR1_MOTOR_LOOK_ZERO_EDGE_SPEED 0 +#define MOTOR1_MOTOR_LOOK_ZERO_EDGE_DEC 0 + +/*********************************************************************************************************************** + * 送料电机 * + ***********************************************************************************************************************/ +#define MOTOR2_CSN PA8 +#define MOTOR2_ENN PE6 +#define MOTOR2_SPI_MODE_SELECT PinNull + +#define MOTOR2_REFL PD11 +#define MOTOR2_REFR PinNull +#define MOTOR2_REFL_MIRROR true +#define MOTOR2_REFR_MIRROR true + +#define MOTOR2_MOTOR_SHAFT false +#define MOTOR2_MOTOR_ONE_CIRCLE_PULSE 80 // 单位0.1mm +#define MOTOR2_MOTOR_ONE_CIRCLE_PULSE_DENOMINATOR 1 +#define MOTOR2_STEPMOTOR_IHOLD 3 +#define MOTOR2_STEPMOTOR_IRUN 10 +#define MOTOR2_STEPMOTOR_IHOLDDELAY 100 +#define MOTOR2_STEPMOTOR_IGLOBALSCALER 1 +#define MOTOR2_MOTOR_DEFAULT_ACC 300 +#define MOTOR2_MOTOR_DEFAULT_DEC 300 +#define MOTOR2_MOTOR_DEFAULT_VELOCITY 500 +#define MOTOR2_MIN_D 0 +#define MOTOR2_MAX_D 0 +#define MOTOR2_MOTOR_RUN_TO_ZERO_SPEED 100 +#define MOTOR2_MOTOR_RUN_TO_ZERO_DEC 300 +#define MOTOR2_MOTOR_LOOK_ZERO_EDGE_SPEED 50 +#define MOTOR2_MOTOR_LOOK_ZERO_EDGE_DEC 300 + +/*********************************************************************************************************************** + * 出料电机 * + ***********************************************************************************************************************/ +#define MOTOR3_CSN PA15 +#define MOTOR3_ENN PE7 +#define MOTOR3_SPI_MODE_SELECT PinNull + +#define MOTOR3_REFL PinNull +#define MOTOR3_REFR PinNull +#define MOTOR3_REFL_MIRROR false +#define MOTOR3_REFR_MIRROR false + +#define MOTOR3_MOTOR_SHAFT true // +#define MOTOR3_MOTOR_ONE_CIRCLE_PULSE 100 // +#define MOTOR3_MOTOR_ONE_CIRCLE_PULSE_DENOMINATOR 1 +#define MOTOR3_STEPMOTOR_IHOLD 2 +#define MOTOR3_STEPMOTOR_IRUN 24 +#define MOTOR3_STEPMOTOR_IHOLDDELAY 100 +#define MOTOR3_STEPMOTOR_IGLOBALSCALER 1 +#define MOTOR3_MOTOR_DEFAULT_ACC 300 +#define MOTOR3_MOTOR_DEFAULT_DEC 300 +#define MOTOR3_MOTOR_DEFAULT_VELOCITY 300 +#define MOTOR3_MIN_D 0 +#define MOTOR3_MAX_D 0 +#define MOTOR3_MOTOR_RUN_TO_ZERO_SPEED 0 +#define MOTOR3_MOTOR_RUN_TO_ZERO_DEC 0 +#define MOTOR3_MOTOR_LOOK_ZERO_EDGE_SPEED 0 +#define MOTOR3_MOTOR_LOOK_ZERO_EDGE_DEC 0 diff --git a/usrc/subboards/subboard60_inlet_and_outlet_module/subboard60_inlet_and_outlet_module.cpp b/usrc/subboards/subboard60_inlet_and_outlet_module/subboard60_inlet_and_outlet_module.cpp new file mode 100644 index 0000000..e2f4272 --- /dev/null +++ b/usrc/subboards/subboard60_inlet_and_outlet_module/subboard60_inlet_and_outlet_module.cpp @@ -0,0 +1,217 @@ +#include "subboard60_inlet_and_outlet_module.hpp" +extern "C" { +#include "subboard60_inlet_and_outlet_module_board.h" +} +#include "pri_board.h" +#include "public_service/public_service.hpp" +#include "sdk/components/mini_servo_motor/feite_servo_motor.hpp" +#include "sdk/components/mini_servo_motor/mini_servo_motor_ctrl_module.hpp" +#include "sdk\components\sensors\m3078\m3078_code_scaner.hpp" +#include "sdk\components\step_motor_ctrl_module\step_motor_ctrl_module.hpp" + +#define TAG "ShakeModule" + +using namespace iflytop; + +Subboard60InjectAndOutletModule::Subboard60InjectAndOutletModule(/* args */) {} +Subboard60InjectAndOutletModule::~Subboard60InjectAndOutletModule() {} +int32_t Subboard60InjectAndOutletModule::getmoduleId(int off) { return zdevice_id_mgr_get_device_id() + off; } +Subboard60InjectAndOutletModule *Subboard60InjectAndOutletModule::ins() { + static Subboard60InjectAndOutletModule instance; + return &instance; +} + +/*********************************************************************************************************************** + * PRI * + ***********************************************************************************************************************/ + +static ZGPIO IO[5]; + +int32_t Subboard60InjectAndOutletModule::getid(int32_t *id) { + *id = getmoduleId(0); + return 0; +} +int32_t Subboard60InjectAndOutletModule::module_xxx_reg(int32_t param_id, bool read, int32_t &val) { return err::kmodule_not_find_reg; } +int32_t Subboard60InjectAndOutletModule::board_read_ext_io(int32_t ioindex, int32_t *val) { + if (ioindex < 0 || ioindex >= ZARRAY_SIZE(IO)) { + return err::kparam_out_of_range; + } + *val = IO[ioindex].getState(); + + return 0; +} +int32_t Subboard60InjectAndOutletModule::board_write_ext_io(int32_t ioindex, int32_t val) { return 0; } + +int32_t Subboard60InjectAndOutletModule::board_read_muti_io(int32_t *val) { + for (int i = 0; i < ZARRAY_SIZE(IO); i++) { + *val |= IO[i].getState() << i; + } + return 0; +} + +void Subboard60InjectAndOutletModule::initialize() { + IO[0].initAsInput(PD0, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); + IO[1].initAsInput(PD1, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); + IO[2].initAsInput(PD2, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); + IO[3].initAsInput(PD3, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); + IO[4].initAsInput(PD4, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, true); + GService::inst()->getZCanProtocolParser()->registerModule(this); + +#if 1 + + /*********************************************************************************************************************** + * 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, MOTOR1_REFL_MIRROR); + input[1].initAsInput(MOTOR1_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, MOTOR1_REFR_MIRROR); + + StepMotorCtrlModule::config_t stepcfg = {0}; + StepMotorCtrlModule::create_default_cfg(stepcfg); + + stepcfg.motor_shaft = MOTOR1_MOTOR_SHAFT; + stepcfg.motor_one_circle_pulse = MOTOR1_MOTOR_ONE_CIRCLE_PULSE; + stepcfg.motor_one_circle_pulse_denominator = MOTOR1_MOTOR_ONE_CIRCLE_PULSE_DENOMINATOR; + stepcfg.stepmotor_ihold = MOTOR1_STEPMOTOR_IHOLD; + stepcfg.stepmotor_irun = MOTOR1_STEPMOTOR_IRUN; + stepcfg.stepmotor_iholddelay = MOTOR1_STEPMOTOR_IHOLDDELAY; + stepcfg.stepmotor_iglobalscaler = MOTOR1_STEPMOTOR_IGLOBALSCALER; + stepcfg.motor_default_acc = MOTOR1_MOTOR_DEFAULT_ACC; + stepcfg.motor_default_dec = MOTOR1_MOTOR_DEFAULT_DEC; + stepcfg.motor_default_velocity = MOTOR1_MOTOR_DEFAULT_VELOCITY; + stepcfg.min_d = MOTOR1_MIN_D; + stepcfg.max_d = MOTOR1_MAX_D; + stepcfg.motor_run_to_zero_speed = MOTOR1_MOTOR_RUN_TO_ZERO_SPEED; + stepcfg.motor_run_to_zero_dec = MOTOR1_MOTOR_RUN_TO_ZERO_DEC; + stepcfg.motor_look_zero_edge_speed = MOTOR1_MOTOR_LOOK_ZERO_EDGE_SPEED; + stepcfg.motor_look_zero_edge_dec = MOTOR1_MOTOR_LOOK_ZERO_EDGE_DEC; + + module.initialize(getmoduleId(subid), &motor, input, ZARRAY_SIZE(input), &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, MOTOR2_REFL_MIRROR); + input[1].initAsInput(MOTOR2_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, MOTOR2_REFR_MIRROR); + + StepMotorCtrlModule::config_t stepcfg = {0}; + StepMotorCtrlModule::create_default_cfg(stepcfg); + + stepcfg.motor_shaft = MOTOR2_MOTOR_SHAFT; + stepcfg.motor_one_circle_pulse = MOTOR2_MOTOR_ONE_CIRCLE_PULSE; + stepcfg.motor_one_circle_pulse_denominator = MOTOR2_MOTOR_ONE_CIRCLE_PULSE_DENOMINATOR; + stepcfg.stepmotor_ihold = MOTOR2_STEPMOTOR_IHOLD; + stepcfg.stepmotor_irun = MOTOR2_STEPMOTOR_IRUN; + stepcfg.stepmotor_iholddelay = MOTOR2_STEPMOTOR_IHOLDDELAY; + stepcfg.stepmotor_iglobalscaler = MOTOR2_STEPMOTOR_IGLOBALSCALER; + stepcfg.motor_default_acc = MOTOR2_MOTOR_DEFAULT_ACC; + stepcfg.motor_default_dec = MOTOR2_MOTOR_DEFAULT_DEC; + stepcfg.motor_default_velocity = MOTOR2_MOTOR_DEFAULT_VELOCITY; + stepcfg.min_d = MOTOR2_MIN_D; + stepcfg.max_d = MOTOR2_MAX_D; + stepcfg.motor_run_to_zero_speed = MOTOR2_MOTOR_RUN_TO_ZERO_SPEED; + stepcfg.motor_run_to_zero_dec = MOTOR2_MOTOR_RUN_TO_ZERO_DEC; + stepcfg.motor_look_zero_edge_speed = MOTOR2_MOTOR_LOOK_ZERO_EDGE_SPEED; + stepcfg.motor_look_zero_edge_dec = MOTOR2_MOTOR_LOOK_ZERO_EDGE_DEC; + + module.initialize(getmoduleId(subid), &motor, input, ZARRAY_SIZE(input), &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, MOTOR3_REFL_MIRROR); + input[1].initAsInput(MOTOR3_REFR /*REFR*/, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, MOTOR3_REFR_MIRROR); + + StepMotorCtrlModule::config_t stepcfg = {0}; + StepMotorCtrlModule::create_default_cfg(stepcfg); + + stepcfg.motor_shaft = MOTOR3_MOTOR_SHAFT; + stepcfg.motor_one_circle_pulse = MOTOR3_MOTOR_ONE_CIRCLE_PULSE; + stepcfg.motor_one_circle_pulse_denominator = MOTOR3_MOTOR_ONE_CIRCLE_PULSE_DENOMINATOR; + stepcfg.stepmotor_ihold = MOTOR3_STEPMOTOR_IHOLD; + stepcfg.stepmotor_irun = MOTOR3_STEPMOTOR_IRUN; + stepcfg.stepmotor_iholddelay = MOTOR3_STEPMOTOR_IHOLDDELAY; + stepcfg.stepmotor_iglobalscaler = MOTOR3_STEPMOTOR_IGLOBALSCALER; + stepcfg.motor_default_acc = MOTOR3_MOTOR_DEFAULT_ACC; + stepcfg.motor_default_dec = MOTOR3_MOTOR_DEFAULT_DEC; + stepcfg.motor_default_velocity = MOTOR3_MOTOR_DEFAULT_VELOCITY; + stepcfg.min_d = MOTOR3_MIN_D; + stepcfg.max_d = MOTOR3_MAX_D; + stepcfg.motor_run_to_zero_speed = MOTOR3_MOTOR_RUN_TO_ZERO_SPEED; + stepcfg.motor_run_to_zero_dec = MOTOR3_MOTOR_RUN_TO_ZERO_DEC; + stepcfg.motor_look_zero_edge_speed = MOTOR3_MOTOR_LOOK_ZERO_EDGE_SPEED; + stepcfg.motor_look_zero_edge_dec = MOTOR3_MOTOR_LOOK_ZERO_EDGE_DEC; + + module.initialize(getmoduleId(subid), &motor, input, ZARRAY_SIZE(input), &stepcfg); + GService::inst()->getZCanProtocolParser()->registerModule(&module); + ZLOGI(TAG, "motor%d readic version %x", subid, motor.readICVersion()); + } + + { + static M3078CodeScanner codescanner; + int subid = 4; + + static M3078CodeScanner::hardware_config_t cfg = { + .uart = &huart3, + .hdma_rx = nullptr, + .hdma_tx = nullptr, + + .codeReadOkPin = PinNull, + .rstPin = PinNull, + .triggerPin = PE15, + }; + codescanner.initialize(getmoduleId(subid), &cfg); + GService::inst()->getZCanProtocolParser()->registerModule(&codescanner); + } + +#endif +} diff --git a/usrc/subboards/subboard60_inlet_and_outlet_module/subboard60_inlet_and_outlet_module.hpp b/usrc/subboards/subboard60_inlet_and_outlet_module/subboard60_inlet_and_outlet_module.hpp new file mode 100644 index 0000000..0f54b03 --- /dev/null +++ b/usrc/subboards/subboard60_inlet_and_outlet_module/subboard60_inlet_and_outlet_module.hpp @@ -0,0 +1,44 @@ +#include +#include + +// +#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 Subboard60InjectAndOutletModule : public ZIBoard, public ZIModule { + ENABLE_MODULE(Subboard60InjectAndOutletModule, kboard, 1); + + private: + /* data */ + + public: + Subboard60InjectAndOutletModule(/* args */); + ~Subboard60InjectAndOutletModule(); + + static Subboard60InjectAndOutletModule *ins(); + + void initialize(); + + public: + /*********************************************************************************************************************** + * ZIModule * + ***********************************************************************************************************************/ + virtual int32_t getid(int32_t *id); + virtual int32_t module_xxx_reg(int32_t param_id, bool read, int32_t &val); + /*********************************************************************************************************************** + * ZIBoard * + ***********************************************************************************************************************/ + virtual int32_t board_read_ext_io(int32_t ioindex, int32_t *val); + virtual int32_t board_write_ext_io(int32_t ioindex, int32_t val); + virtual int32_t board_read_muti_io(int32_t *val); + + private: + int32_t getmoduleId(int off); +}; + +} // namespace iflytop diff --git a/usrc/subboards/subboard60_inlet_and_outlet_module/subboard60_inlet_and_outlet_module_board.c b/usrc/subboards/subboard60_inlet_and_outlet_module/subboard60_inlet_and_outlet_module_board.c new file mode 100644 index 0000000..38e4603 --- /dev/null +++ b/usrc/subboards/subboard60_inlet_and_outlet_module/subboard60_inlet_and_outlet_module_board.c @@ -0,0 +1,109 @@ +#include "main.h" +#include "public_service/public_service.h" + +/* SPI1 init function */ +static void MX_SPI1_Init(void) { + __HAL_RCC_SPI1_CLK_ENABLE(); + __HAL_RCC_GPIOA_CLK_ENABLE(); + + 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(); + } + GPIO_InitTypeDef GPIO_InitStruct = {0}; + 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; +} + +static void UART3_Init() { + GPIO_InitTypeDef GPIO_InitStruct = {0}; + + __HAL_RCC_USART3_CLK_ENABLE(); + __HAL_RCC_GPIOB_CLK_ENABLE(); + __HAL_RCC_DMA1_CLK_ENABLE(); + + huart3.Instance = USART3; + huart3.Init.BaudRate = 9600; + huart3.Init.WordLength = UART_WORDLENGTH_8B; + huart3.Init.StopBits = UART_STOPBITS_1; + huart3.Init.Parity = UART_PARITY_NONE; + huart3.Init.Mode = UART_MODE_TX_RX; + huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart3.Init.OverSampling = UART_OVERSAMPLING_16; + if (HAL_UART_Init(&huart3) != HAL_OK) { + Error_Handler(); + } + + GPIO_InitStruct.Pin = GPIO_PIN_10 | GPIO_PIN_11; + GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; + GPIO_InitStruct.Pull = GPIO_NOPULL; + GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; + GPIO_InitStruct.Alternate = GPIO_AF7_USART3; + HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); + + hdma1_stream1.Instance = DMA1_Stream1; + hdma1_stream1.Init.Channel = DMA_CHANNEL_4; + hdma1_stream1.Init.Direction = DMA_PERIPH_TO_MEMORY; + hdma1_stream1.Init.PeriphInc = DMA_PINC_DISABLE; + hdma1_stream1.Init.MemInc = DMA_MINC_ENABLE; + hdma1_stream1.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; + hdma1_stream1.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; + hdma1_stream1.Init.Mode = DMA_NORMAL; + hdma1_stream1.Init.Priority = DMA_PRIORITY_LOW; + hdma1_stream1.Init.FIFOMode = DMA_FIFOMODE_DISABLE; + if (HAL_DMA_Init(&hdma1_stream1) != HAL_OK) { + Error_Handler(); + } + + __HAL_LINKDMA(&huart3, hdmarx, hdma1_stream1); + + hdma1_stream3.Instance = DMA1_Stream3; + hdma1_stream3.Init.Channel = DMA_CHANNEL_4; + hdma1_stream3.Init.Direction = DMA_MEMORY_TO_PERIPH; + hdma1_stream3.Init.PeriphInc = DMA_PINC_DISABLE; + hdma1_stream3.Init.MemInc = DMA_MINC_ENABLE; + hdma1_stream3.Init.PeriphDataAlignment = DMA_PDATAALIGN_BYTE; + hdma1_stream3.Init.MemDataAlignment = DMA_MDATAALIGN_BYTE; + hdma1_stream3.Init.Mode = DMA_NORMAL; + hdma1_stream3.Init.Priority = DMA_PRIORITY_LOW; + hdma1_stream3.Init.FIFOMode = DMA_FIFOMODE_DISABLE; + if (HAL_DMA_Init(&hdma1_stream3) != HAL_OK) { + Error_Handler(); + } + + __HAL_LINKDMA(&huart3, hdmatx, hdma1_stream3); + + hdma_usart3_rx = &hdma1_stream1; + hdma_usart3_tx = &hdma1_stream3; + hdma1_stream1_enable = true; + hdma1_stream3_enable = true; + + HAL_NVIC_SetPriority(DMA1_Stream1_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(DMA1_Stream1_IRQn); + + HAL_NVIC_SetPriority(DMA1_Stream3_IRQn, 5, 0); + HAL_NVIC_EnableIRQ(DMA1_Stream3_IRQn); +} + +void subboard60_inlet_and_outlet_module_board_init() { + common_hardware_init(); + MX_SPI1_Init(); + UART3_Init(); +} diff --git a/usrc/subboards/subboard60_inlet_and_outlet_module/subboard60_inlet_and_outlet_module_board.h b/usrc/subboards/subboard60_inlet_and_outlet_module/subboard60_inlet_and_outlet_module_board.h new file mode 100644 index 0000000..59e4378 --- /dev/null +++ b/usrc/subboards/subboard60_inlet_and_outlet_module/subboard60_inlet_and_outlet_module_board.h @@ -0,0 +1,12 @@ +#pragma once +#include "main.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void subboard60_inlet_and_outlet_module_board_init(); + +#ifdef __cplusplus +} +#endif