|
|
@ -7,6 +7,7 @@ |
|
|
|
#include "project.hpp"
|
|
|
|
//
|
|
|
|
#include "sdk/hal/zhal.hpp"
|
|
|
|
#include "sdk\components\iflytop_can_slave_v1\iflytop_can_slave.hpp"
|
|
|
|
#include "sdk\components\tmc\ic\ztmc4361A.hpp"
|
|
|
|
|
|
|
|
#define TAG "main"
|
|
|
@ -15,6 +16,41 @@ Main gmain; |
|
|
|
}; |
|
|
|
|
|
|
|
using namespace iflytop; |
|
|
|
|
|
|
|
IflytopCanProtocolStackProcesser m_protocolStack; |
|
|
|
TMC4361A m_motora; |
|
|
|
TMC4361A m_motorb; |
|
|
|
|
|
|
|
void input_sensors_init() { |
|
|
|
ARM_SENSOR1_GPIO.initAsInput(STM32_GPIO::kInput_risingAndFallingIrq, true); |
|
|
|
ARM_SENSOR2_GPIO.initAsInput(STM32_GPIO::kInput_risingAndFallingIrq, true); |
|
|
|
ARM_SENSOR3_GPIO.initAsInput(); |
|
|
|
ARM_SENSOR4_GPIO.initAsInput(); |
|
|
|
ARM_SENSOR5_GPIO.initAsInput(); |
|
|
|
ARM_SENSOR6_GPIO.initAsInput(); |
|
|
|
ARM_SENSOR7_GPIO.initAsInput(STM32_GPIO::kInput_risingAndFallingIrq, true); |
|
|
|
ARM_SENSOR8_GPIO.initAsInput(STM32_GPIO::kInput_risingAndFallingIrq, true); |
|
|
|
} |
|
|
|
uint32_t intput_sensors_get_table0() { |
|
|
|
uint32_t val = 0; |
|
|
|
val |= ARM_SENSOR1_GPIO.getStateUint32() << 1; |
|
|
|
val |= ARM_SENSOR2_GPIO.getStateUint32() << 2; |
|
|
|
val |= ARM_SENSOR3_GPIO.getStateUint32() << 3; |
|
|
|
val |= ARM_SENSOR4_GPIO.getStateUint32() << 4; |
|
|
|
val |= ARM_SENSOR5_GPIO.getStateUint32() << 5; |
|
|
|
val |= ARM_SENSOR6_GPIO.getStateUint32() << 6; |
|
|
|
val |= ARM_SENSOR7_GPIO.getStateUint32() << 7; |
|
|
|
val |= ARM_SENSOR8_GPIO.getStateUint32() << 8; |
|
|
|
return val; |
|
|
|
} |
|
|
|
|
|
|
|
STM32_GPIO *input_sensors_get_arm1_homegpio() { return &ARM_SENSOR8_GPIO; } |
|
|
|
STM32_GPIO *input_sensors_get_arm2_homegpio() { return &ARM_SENSOR7_GPIO; } |
|
|
|
|
|
|
|
icps::error_t Main::onHostRegisterWriteEvent(IflytopCanProtocolStackProcesser *processer, icps::WriteEvent *event) {} |
|
|
|
icps::error_t Main::onHostRegisterReadEvent(IflytopCanProtocolStackProcesser *processer, icps::ReadEvent *event) {} |
|
|
|
void Main::onHostRegisterReportEvent(IflytopCanProtocolStackProcesser *processer, icps::ReportEvent *event) {} |
|
|
|
|
|
|
|
void Main::run() { |
|
|
|
iflytop_no_os_cfg_t oscfg = { |
|
|
|
.delayhtim = &DELAY_US_TIMER, |
|
|
@ -27,12 +63,15 @@ void Main::run() { |
|
|
|
DEBUG_LIGHT_GPIO.initAsOutput(true); |
|
|
|
ZHAL_CORE_REG(200, { DEBUG_LIGHT_GPIO.toggleState(); }); |
|
|
|
|
|
|
|
// while (true) {
|
|
|
|
// chip_delay_us(1000 * 1000);
|
|
|
|
// ZLOGI(TAG, ".....");
|
|
|
|
// }
|
|
|
|
TMC4361A motora; |
|
|
|
TMC4361A motorb; |
|
|
|
/*******************************************************************************
|
|
|
|
* GPIO输入初始化 * |
|
|
|
*******************************************************************************/ |
|
|
|
input_sensors_init(); |
|
|
|
intput_sensors_get_table0(); |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* 电机初始化 * |
|
|
|
*******************************************************************************/ |
|
|
|
TMC_MOTOR1_SPI_SELECT1_IO.initAsOutput(true); |
|
|
|
TMC_MOTOR1_nFREEZE_IO.initAsOutput(true); |
|
|
|
TMC_MOTOR1_nRESET_IO.initAsOutput(true); |
|
|
@ -50,10 +89,10 @@ void Main::run() { |
|
|
|
.driverIC_ennPin = &TMC_MOTOR1_SUB_IC_ENN_IO, |
|
|
|
.driverIC_resetPin = NULL}; |
|
|
|
|
|
|
|
motora.initialize(&motora_cfg); |
|
|
|
int32_t ic4361Version = motora.readICVersion(); |
|
|
|
int32_t ic2160Version = motora.readSubICVersion(); |
|
|
|
ZLOGI(TAG, "motora:TMC4361Version:%lx TMC2160VERSION:%lx", ic4361Version, ic2160Version); |
|
|
|
m_motora.initialize(&motora_cfg); |
|
|
|
int32_t ic4361Version = m_motora.readICVersion(); |
|
|
|
int32_t ic2160Version = m_motora.readSubICVersion(); |
|
|
|
ZLOGI(TAG, "m_motora:TMC4361Version:%lx TMC2160VERSION:%lx", ic4361Version, ic2160Version); |
|
|
|
} |
|
|
|
|
|
|
|
{ |
|
|
@ -65,20 +104,50 @@ void Main::run() { |
|
|
|
.driverIC_ennPin = &TMC_MOTOR2_SUB_IC_ENN_IO, |
|
|
|
.driverIC_resetPin = NULL}; |
|
|
|
|
|
|
|
motorb.initialize(&motorb_cfg); |
|
|
|
int32_t ic4361Version = motorb.readICVersion(); |
|
|
|
int32_t ic2160Version = motorb.readSubICVersion(); |
|
|
|
ZLOGI(TAG, "motorb:TMC4361Version:%lx TMC2160VERSION:%lx", ic4361Version, ic2160Version); |
|
|
|
m_motorb.initialize(&motorb_cfg); |
|
|
|
int32_t ic4361Version = m_motorb.readICVersion(); |
|
|
|
int32_t ic2160Version = m_motorb.readSubICVersion(); |
|
|
|
ZLOGI(TAG, "m_motorb:TMC4361Version:%lx TMC2160VERSION:%lx", ic4361Version, ic2160Version); |
|
|
|
} |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* 扫码枪初始化 * |
|
|
|
*******************************************************************************/ |
|
|
|
{ |
|
|
|
// static ZUART uart;
|
|
|
|
// PB6.initAsOutput(STM32_GPIO::kOutput_nopull, true, false);
|
|
|
|
// ZUART::cfg_t cfg = {
|
|
|
|
// .name = "CODE_SCANER_UART",
|
|
|
|
// .huart = &CODE_SCANER_UART,
|
|
|
|
// .rxbuffersize = 300,
|
|
|
|
// .rxovertime_ms = 10,
|
|
|
|
// };
|
|
|
|
// uart.initialize(&cfg,[](){})
|
|
|
|
// uart.initialize_basic("CODE_SCANER_UART", &m_hardware, &CODE_SCANER_UART);
|
|
|
|
// uart.initialize_setRxBuffer(300);
|
|
|
|
// uart.initialize_setRxOvertime(33);
|
|
|
|
// uart.initialize_finished();
|
|
|
|
} |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* 协议栈初始化 * |
|
|
|
*******************************************************************************/ |
|
|
|
{ |
|
|
|
auto *cfg = IflytopCanProtocolStackProcesser::createDefaultConfig(DEVICE_ID, 128); |
|
|
|
m_protocolStack.initialize(cfg); |
|
|
|
m_protocolStack.setDumpPacketFlag(false); |
|
|
|
m_protocolStack.registerListener(this); |
|
|
|
m_protocolStack.activeReg(REG_GPIO_INPUT0, icps::kwr, 0); |
|
|
|
} |
|
|
|
|
|
|
|
motora.setIHOLD_IRUN(1, 12, 0); // 小臂
|
|
|
|
motora.setMotorShaft(0); |
|
|
|
m_motora.setIHOLD_IRUN(1, 12, 0); // 小臂
|
|
|
|
m_motora.setMotorShaft(0); |
|
|
|
|
|
|
|
motorb.setIHOLD_IRUN(1, 12, 0); // 小臂
|
|
|
|
motorb.setMotorShaft(0); |
|
|
|
m_motorb.setIHOLD_IRUN(1, 12, 0); // 小臂
|
|
|
|
m_motorb.setMotorShaft(0); |
|
|
|
|
|
|
|
motora.rotate(1200000); |
|
|
|
motorb.rotate(1200000); |
|
|
|
m_motora.rotate(1200000); |
|
|
|
m_motorb.rotate(1200000); |
|
|
|
|
|
|
|
while (1) { |
|
|
|
ZHALCORE::getInstance()->loop(); |
|
|
|