8 changed files with 280 additions and 1 deletions
-
2sdk
-
9usrc/main.cpp
-
9usrc/public_service/common_hardware_init.c
-
51usrc/subboards/subboard70_incubation_turntable/pri_board.h
-
115usrc/subboards/subboard70_incubation_turntable/subboard70_incubation_turntable.cpp
-
44usrc/subboards/subboard70_incubation_turntable/subboard70_incubation_turntable.hpp
-
39usrc/subboards/subboard70_incubation_turntable/subboard70_incubation_turntable_board.c
-
12usrc/subboards/subboard70_incubation_turntable/subboard70_incubation_turntable_board.h
@ -1 +1 @@ |
|||||
Subproject commit e2dffc30e3184174c4dce5d2eb8748c6ed7bd7b8 |
|
||||
|
Subproject commit 9aee8f2a2c26251c921e81bca81abc3a3a2f6927 |
@ -0,0 +1,51 @@ |
|||||
|
#pragma once |
||||
|
|
||||
|
/*********************************************************************************************************************** |
||||
|
* 板载扩展IO * |
||||
|
***********************************************************************************************************************/ |
||||
|
|
||||
|
#define EXT_INPUT_IO0 PinNull |
||||
|
#define EXT_INPUT_IO1 PinNull |
||||
|
#define EXT_INPUT_IO2 PinNull |
||||
|
#define EXT_INPUT_IO3 PinNull |
||||
|
#define EXT_INPUT_IO4 PinNull |
||||
|
|
||||
|
#define EXT_INPUT_IO0_MIRROR true |
||||
|
#define EXT_INPUT_IO1_MIRROR true |
||||
|
#define EXT_INPUT_IO2_MIRROR true |
||||
|
#define EXT_INPUT_IO3_MIRROR true |
||||
|
#define EXT_INPUT_IO4_MIRROR true |
||||
|
|
||||
|
/*********************************************************************************************************************** |
||||
|
* 转盘电机 * |
||||
|
***********************************************************************************************************************/ |
||||
|
#define TMC_MOTOR_SPI hspi1 |
||||
|
|
||||
|
#define MOTOR1_CSN PA4 |
||||
|
#define MOTOR1_ENN PE3 |
||||
|
#define MOTOR1_SPI_MODE_SELECT PinNull |
||||
|
#define MOTOR1_nFREEZE_IO PE12 |
||||
|
#define MOTOR1_nRESET_IO PinNull |
||||
|
#define MOTOR1_SUB_IC_ENN_IO PE11 |
||||
|
|
||||
|
#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 387096 // 3600 = 93圈, 3600/93 = 38.70967741935484 |
||||
|
#define MOTOR1_MOTOR_ONE_CIRCLE_PULSE_DENOMINATOR 1000 // |
||||
|
#define MOTOR1_STEPMOTOR_IHOLD 1 |
||||
|
#define MOTOR1_STEPMOTOR_IRUN 5 |
||||
|
#define MOTOR1_STEPMOTOR_IHOLDDELAY 100 |
||||
|
#define MOTOR1_STEPMOTOR_IGLOBALSCALER 1 |
||||
|
#define MOTOR1_MOTOR_DEFAULT_ACC 900 |
||||
|
#define MOTOR1_MOTOR_DEFAULT_DEC 900 |
||||
|
#define MOTOR1_MOTOR_DEFAULT_VELOCITY 300 |
||||
|
#define MOTOR1_MIN_D 0 |
||||
|
#define MOTOR1_MAX_D 0 |
||||
|
#define MOTOR1_MOTOR_RUN_TO_ZERO_SPEED 200 |
||||
|
#define MOTOR1_MOTOR_RUN_TO_ZERO_DEC 900 |
||||
|
#define MOTOR1_MOTOR_LOOK_ZERO_EDGE_SPEED 200 |
||||
|
#define MOTOR1_MOTOR_LOOK_ZERO_EDGE_DEC 900 |
@ -0,0 +1,115 @@ |
|||||
|
#include "subboard70_incubation_turntable.hpp"
|
||||
|
extern "C" { |
||||
|
#include "subboard70_incubation_turntable_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"
|
||||
|
#include "sdk/components/tmc/ic/ztmc4361A.hpp"
|
||||
|
|
||||
|
#define TAG "ShakeModule"
|
||||
|
|
||||
|
using namespace iflytop; |
||||
|
|
||||
|
static ZGPIO IO[5]; |
||||
|
|
||||
|
Subboard70IncubationTurntable::Subboard70IncubationTurntable(/* args */) {} |
||||
|
Subboard70IncubationTurntable::~Subboard70IncubationTurntable() {} |
||||
|
int32_t Subboard70IncubationTurntable::getmoduleId(int off) { return zdevice_id_mgr_get_device_id() + off; } |
||||
|
Subboard70IncubationTurntable *Subboard70IncubationTurntable::ins() { |
||||
|
static Subboard70IncubationTurntable instance; |
||||
|
return &instance; |
||||
|
} |
||||
|
/***********************************************************************************************************************
|
||||
|
* PRI * |
||||
|
***********************************************************************************************************************/ |
||||
|
int32_t Subboard70IncubationTurntable::getid(int32_t *id) { |
||||
|
*id = getmoduleId(0); |
||||
|
return 0; |
||||
|
} |
||||
|
int32_t Subboard70IncubationTurntable::module_xxx_reg(int32_t param_id, bool read, int32_t &val) { return err::kmodule_not_find_reg; } |
||||
|
int32_t Subboard70IncubationTurntable::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 Subboard70IncubationTurntable::board_write_ext_io(int32_t ioindex, int32_t val) { return 0; } |
||||
|
|
||||
|
int32_t Subboard70IncubationTurntable::board_read_muti_io(int32_t *val) { |
||||
|
for (int i = 0; i < ZARRAY_SIZE(IO); i++) { |
||||
|
*val |= IO[i].getState() << i; |
||||
|
} |
||||
|
return 0; |
||||
|
} |
||||
|
|
||||
|
/***********************************************************************************************************************
|
||||
|
* IMPL * |
||||
|
***********************************************************************************************************************/ |
||||
|
void Subboard70IncubationTurntable::initialize() { |
||||
|
IO[0].initAsInput(EXT_INPUT_IO0, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, EXT_INPUT_IO0_MIRROR); |
||||
|
IO[1].initAsInput(EXT_INPUT_IO1, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, EXT_INPUT_IO1_MIRROR); |
||||
|
IO[2].initAsInput(EXT_INPUT_IO2, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, EXT_INPUT_IO2_MIRROR); |
||||
|
IO[3].initAsInput(EXT_INPUT_IO3, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, EXT_INPUT_IO3_MIRROR); |
||||
|
IO[4].initAsInput(EXT_INPUT_IO4, ZGPIO::kMode_nopull, ZGPIO::kIRQ_noIrq, EXT_INPUT_IO4_MIRROR); |
||||
|
GService::inst()->getZCanProtocolParser()->registerModule(this); |
||||
|
|
||||
|
#if 1
|
||||
|
|
||||
|
/***********************************************************************************************************************
|
||||
|
* ID1 * |
||||
|
***********************************************************************************************************************/ |
||||
|
{ |
||||
|
static TMC4361A motor; |
||||
|
static StepMotorCtrlModule module; |
||||
|
int subid = 1; |
||||
|
|
||||
|
TMC4361A::cfg_t motorcfg = { |
||||
|
.spi = &TMC_MOTOR_SPI, //
|
||||
|
.csgpio = MOTOR1_CSN, //
|
||||
|
.resetPin = MOTOR1_nRESET_IO, //
|
||||
|
.fREEZEPin = MOTOR1_nFREEZE_IO, //
|
||||
|
.ennPin = MOTOR1_ENN, //
|
||||
|
.driverIC_ennPin = MOTOR1_SUB_IC_ENN_IO, //
|
||||
|
.driverIC_resetPin = PinNull, //
|
||||
|
}; |
||||
|
|
||||
|
motor.initialize(&motorcfg); |
||||
|
|
||||
|
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 module_cfg = {0}; |
||||
|
StepMotorCtrlModule::create_default_cfg(module_cfg); |
||||
|
|
||||
|
module_cfg.motor_shaft = MOTOR1_MOTOR_SHAFT; |
||||
|
module_cfg.motor_one_circle_pulse = MOTOR1_MOTOR_ONE_CIRCLE_PULSE; |
||||
|
module_cfg.motor_one_circle_pulse_denominator = MOTOR1_MOTOR_ONE_CIRCLE_PULSE_DENOMINATOR; |
||||
|
module_cfg.stepmotor_ihold = MOTOR1_STEPMOTOR_IHOLD; |
||||
|
module_cfg.stepmotor_irun = MOTOR1_STEPMOTOR_IRUN; |
||||
|
module_cfg.stepmotor_iholddelay = MOTOR1_STEPMOTOR_IHOLDDELAY; |
||||
|
module_cfg.stepmotor_iglobalscaler = MOTOR1_STEPMOTOR_IGLOBALSCALER; |
||||
|
module_cfg.motor_default_acc = MOTOR1_MOTOR_DEFAULT_ACC; |
||||
|
module_cfg.motor_default_dec = MOTOR1_MOTOR_DEFAULT_DEC; |
||||
|
module_cfg.motor_default_velocity = MOTOR1_MOTOR_DEFAULT_VELOCITY; |
||||
|
module_cfg.min_d = MOTOR1_MIN_D; |
||||
|
module_cfg.max_d = MOTOR1_MAX_D; |
||||
|
module_cfg.motor_run_to_zero_speed = MOTOR1_MOTOR_RUN_TO_ZERO_SPEED; |
||||
|
module_cfg.motor_run_to_zero_dec = MOTOR1_MOTOR_RUN_TO_ZERO_DEC; |
||||
|
module_cfg.motor_look_zero_edge_speed = MOTOR1_MOTOR_LOOK_ZERO_EDGE_SPEED; |
||||
|
module_cfg.motor_look_zero_edge_dec = MOTOR1_MOTOR_LOOK_ZERO_EDGE_DEC; |
||||
|
|
||||
|
module.initialize(getmoduleId(subid), &motor, input, ZARRAY_SIZE(input), &module_cfg); |
||||
|
GService::inst()->getZCanProtocolParser()->registerModule(&module); |
||||
|
|
||||
|
ZLOGI(TAG, "motor%d readic version %x", subid, motor.readICVersion()); |
||||
|
} |
||||
|
|
||||
|
#endif
|
||||
|
} |
@ -0,0 +1,44 @@ |
|||||
|
#include <stddef.h>
|
||||
|
#include <stdio.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 Subboard70IncubationTurntable : public ZIBoard, public ZIModule { |
||||
|
ENABLE_MODULE(Subboard70IncubationTurntable, kboard, 1); |
||||
|
|
||||
|
private: |
||||
|
/* data */ |
||||
|
|
||||
|
public: |
||||
|
Subboard70IncubationTurntable(/* args */); |
||||
|
~Subboard70IncubationTurntable(); |
||||
|
|
||||
|
static Subboard70IncubationTurntable *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
|
@ -0,0 +1,39 @@ |
|||||
|
#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; |
||||
|
} |
||||
|
|
||||
|
void subboard70_incubation_turntable_board_init() { |
||||
|
common_hardware_init(); |
||||
|
MX_SPI1_Init(); |
||||
|
// UART3_Init(); |
||||
|
} |
@ -0,0 +1,12 @@ |
|||||
|
#pragma once |
||||
|
#include "main.h" |
||||
|
|
||||
|
#ifdef __cplusplus |
||||
|
extern "C" { |
||||
|
#endif |
||||
|
|
||||
|
void subboard70_incubation_turntable_board_init(); |
||||
|
|
||||
|
#ifdef __cplusplus |
||||
|
} |
||||
|
#endif |
Write
Preview
Loading…
Cancel
Save
Reference in new issue