|
|
@ -12,14 +12,6 @@ int fputc(int ch, FILE *stream) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
int32_t Hardware::port_tmc4361_get_version(uint8_t channel) { |
|
|
|
int value; |
|
|
|
uint8_t data[5]; |
|
|
|
data[0] = 0x7f; |
|
|
|
tmc_motor_spi_write_and_read(channel, &data[0], 5); |
|
|
|
value = ((uint32_t)data[1] << 24) | ((uint32_t)data[2] << 16) | (data[3] << 8) | data[4]; |
|
|
|
return value; |
|
|
|
} |
|
|
|
void Hardware::registerListener(HardwareListener *listener) { |
|
|
|
if (listener && m_listenerNum < MAX_HARDWARE_LISTENER_NUM) { |
|
|
|
m_listener[m_listenerNum] = listener; |
|
|
@ -37,35 +29,28 @@ void Hardware::hardwareinit() { |
|
|
|
*******************************************************************************/ |
|
|
|
debug_light_init(); |
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* CANSLAVEService初始化 * |
|
|
|
*******************************************************************************/ |
|
|
|
#if ENABLE_CAN
|
|
|
|
/*******************************************************************************
|
|
|
|
* CANSLAVEService初始化 * |
|
|
|
*******************************************************************************/ |
|
|
|
IflytopCanSlave::iflytop_can_slave_config_t *config = canSlaveService.createDefaultConfig(DEVICE_ID); |
|
|
|
canSlaveService.initialize(this, config); |
|
|
|
canSlaveService.activateRxIT(); |
|
|
|
canSlaveService.registerListener(this); |
|
|
|
#endif
|
|
|
|
/*******************************************************************************
|
|
|
|
* 帕尔贴初始化 * |
|
|
|
*******************************************************************************/ |
|
|
|
#if 0
|
|
|
|
peltier_init(); |
|
|
|
#endif
|
|
|
|
/*******************************************************************************
|
|
|
|
* 温度传感器初始化 * |
|
|
|
*******************************************************************************/ |
|
|
|
#if 0
|
|
|
|
tmp117[0].initializate(&hi2c1, TMP117::ID0); |
|
|
|
tmp117[1].initializate(&hi2c1, TMP117::ID1); |
|
|
|
tmp117[2].initializate(&hi2c1, TMP117::ID2); |
|
|
|
tmp117[3].initializate(&hi2c1, TMP117::ID3); |
|
|
|
#endif
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
* 电机初始化 * |
|
|
|
*******************************************************************************/ |
|
|
|
#if 0
|
|
|
|
tmc_init(); |
|
|
|
tmc_extern_clk_enable(); |
|
|
|
// 4361初始化
|
|
|
@ -93,20 +78,16 @@ void Hardware::hardwareinit() { |
|
|
|
} |
|
|
|
// 期望 4361Version:2 ic2160Version:30
|
|
|
|
// tmc4361motor1.stop();
|
|
|
|
#if 1
|
|
|
|
// 测试编码器方向
|
|
|
|
tmc4361motor1.rotate(-300000); |
|
|
|
while (true) { |
|
|
|
HAL_Delay(100); |
|
|
|
ZLOGI(TAG, "TMC4361A: XACTUAL:%d ENC_POS:%d DIFF:%d", tmc4361motor1.getXACTUAL(), tmc4361motor1.getENC_POS(), tmc4361motor1.getENC_POS_DEV()); |
|
|
|
} |
|
|
|
#endif
|
|
|
|
// tmc4361motor1.rotate(-300000);
|
|
|
|
// while (true) {
|
|
|
|
// HAL_Delay(100);
|
|
|
|
// ZLOGI(TAG, "TMC4361A: XACTUAL:%d ENC_POS:%d DIFF:%d", tmc4361motor1.getXACTUAL(), tmc4361motor1.getENC_POS(), tmc4361motor1.getENC_POS_DEV());
|
|
|
|
// }
|
|
|
|
|
|
|
|
#endif
|
|
|
|
/*******************************************************************************
|
|
|
|
* 风扇初始化 * |
|
|
|
*******************************************************************************/ |
|
|
|
#if 0
|
|
|
|
/*******************************************************************************
|
|
|
|
* 风扇初始化 * |
|
|
|
*******************************************************************************/ |
|
|
|
fanInit(1000); |
|
|
|
/**
|
|
|
|
* @brief 风扇反馈初始化 |
|
|
@ -118,13 +99,20 @@ void Hardware::hardwareinit() { |
|
|
|
* FAN4_FB_INT PC7 |
|
|
|
* FAN5_FB_INT PC10 |
|
|
|
*/ |
|
|
|
m_fanStateMonitor[0].initialize(m_os, GPIOC, GPIO_PIN_1, fanGetPowerState(0)); |
|
|
|
m_fanStateMonitor[1].initialize(m_os, GPIOC, GPIO_PIN_4, fanGetPowerState(1)); |
|
|
|
m_fanStateMonitor[2].initialize(m_os, GPIOC, GPIO_PIN_5, fanGetPowerState(2)); |
|
|
|
m_fanStateMonitor[3].initialize(m_os, GPIOC, GPIO_PIN_6, fanGetPowerState(3)); |
|
|
|
m_fanStateMonitor[4].initialize(m_os, GPIOC, GPIO_PIN_7, fanGetPowerState(4)); |
|
|
|
m_fanStateMonitor[5].initialize(m_os, GPIOC, GPIO_PIN_10, fanGetPowerState(5)); |
|
|
|
#endif
|
|
|
|
m_fanStateMonitor[0].initialize(this, GPIOC, GPIO_PIN_1, fanGetPowerState(0)); |
|
|
|
m_fanStateMonitor[1].initialize(this, GPIOC, GPIO_PIN_4, fanGetPowerState(1)); |
|
|
|
m_fanStateMonitor[2].initialize(this, GPIOC, GPIO_PIN_5, fanGetPowerState(2)); |
|
|
|
m_fanStateMonitor[3].initialize(this, GPIOC, GPIO_PIN_6, fanGetPowerState(3)); |
|
|
|
m_fanStateMonitor[4].initialize(this, GPIOC, GPIO_PIN_7, fanGetPowerState(4)); |
|
|
|
m_fanStateMonitor[5].initialize(this, GPIOC, GPIO_PIN_10, fanGetPowerState(5)); |
|
|
|
} |
|
|
|
int32_t Hardware::port_tmc4361_get_version(uint8_t channel) { |
|
|
|
int value; |
|
|
|
uint8_t data[5]; |
|
|
|
data[0] = 0x7f; |
|
|
|
tmc_motor_spi_write_and_read(channel, &data[0], 5); |
|
|
|
value = ((uint32_t)data[1] << 24) | ((uint32_t)data[2] << 16) | (data[3] << 8) | data[4]; |
|
|
|
return value; |
|
|
|
} |
|
|
|
void Hardware::periodicJob() { |
|
|
|
#if 0
|
|
|
@ -137,7 +125,7 @@ void Hardware::periodicJob() { |
|
|
|
#endif
|
|
|
|
do_debug_light_state(); |
|
|
|
#if ENABLE_CAN
|
|
|
|
testCanSlaveTxAndRx(); |
|
|
|
// testCanSlaveTxAndRx();
|
|
|
|
#endif
|
|
|
|
} |
|
|
|
void Hardware::do_debug_light_state() { |
|
|
@ -147,65 +135,6 @@ void Hardware::do_debug_light_state() { |
|
|
|
HAL_GPIO_TogglePin(DEBUG_LIGHT_PORT, DEBUG_LIGHT_PIN); |
|
|
|
} |
|
|
|
} |
|
|
|
/*******************************************************************************
|
|
|
|
* 硬件测试 * |
|
|
|
*******************************************************************************/ |
|
|
|
void Hardware::testTmp117() { |
|
|
|
static uint32_t lastcall; |
|
|
|
if (hasPassedMS(lastcall) > 1000) { |
|
|
|
lastcall = getTicket(); |
|
|
|
for (size_t i = 0; i < 4; i++) { |
|
|
|
float temp = tmp117[i].getTemperature(); |
|
|
|
if (tmp117[i].getLastCallStatus() == HAL_OK) { |
|
|
|
ZLOGI(TAG, "tmp117_%d:%f", i, temp); |
|
|
|
} else { |
|
|
|
ZLOGI(TAG, "tmp117_%d:read fail", i); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 测试CAN的发送和接收 |
|
|
|
*/ |
|
|
|
void Hardware::testCanSlaveTxAndRx() { |
|
|
|
{ |
|
|
|
static uint32_t lastcall; |
|
|
|
static uint8_t tx[8] = {1, 2, 3, 4, 5, 6, 7, 8}; |
|
|
|
if (hasPassedMS(lastcall) > 1000) { |
|
|
|
lastcall = getTicket(); |
|
|
|
// canSlaveService.translate(0x01, tx, 8, 2);
|
|
|
|
canSlaveService.sendReport(1, 2, 3, 100); |
|
|
|
if (canSlaveService.getLastTransmitStatus() == HAL_OK) { |
|
|
|
ZLOGI(TAG, "send ok"); |
|
|
|
} else { |
|
|
|
ZLOGI(TAG, "send fail"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 接收CAN消息 |
|
|
|
*/ |
|
|
|
if (m_canOnRxDataFlag) { |
|
|
|
m_canOnRxDataFlag = false; |
|
|
|
static CAN_RxHeaderTypeDef packetHeader; |
|
|
|
static uint8_t packetData[8]; |
|
|
|
// while (canSlaveService.getRxMessage(&packetHeader, packetData)) {
|
|
|
|
// ZLOGI(TAG, "rx packet:");
|
|
|
|
// ZLOGI(TAG, "\tid:%x len:%d", packetHeader.StdId, packetHeader.DLC);
|
|
|
|
// ZLOGI_HEX(TAG, packetData, packetHeader.DLC);
|
|
|
|
// }
|
|
|
|
|
|
|
|
static IflytopCanSlave::packet_t packet; |
|
|
|
while (canSlaveService.getRxPacket(&packet)) { |
|
|
|
ZLOGI(TAG, "rx packet:"); |
|
|
|
ZLOGI(TAG, "\ttype:%01x, targetId:%01x, sourceId:%02x, seq:%02x, regAdd:%02x, regValue:%04x", //
|
|
|
|
packet.type, packet.targetId, packet.sourceId, packet.seq, packet.regAdd, packet.regValue); |
|
|
|
} |
|
|
|
canSlaveService.activateRxIT(); |
|
|
|
} |
|
|
|
} |
|
|
|
void Hardware::TMC4361APort_setResetPinState(uint16_t channel, bool state) { tmc_nRESET_pin_set_state(channel, state); } |
|
|
|
void Hardware::TMC4361APort_setFREEZEPinState(uint16_t channel, bool state) { tmc_nFREEZE_pin_set_state(channel, state); } |
|
|
|
void Hardware::TMC4361APort_setENNPinState(uint16_t channel, bool state) { tmc_ENN_pin_set_state(channel, state); } |
|
|
@ -213,7 +142,6 @@ bool Hardware::TMC4361APort_getTargetReachedPinState(uint16_t channel) { return |
|
|
|
void Hardware::TMC4361APort_sleepus(int32_t us) { sleepus(us); } |
|
|
|
void Hardware::TMC4361APort_readWriteArray(uint8_t *data, size_t length) { tmc_motor_spi_write_and_read(0, data, length); } |
|
|
|
void Hardware::TMC4361APort_setSubICENNPinState(uint16_t channel, bool state) { tmc_subic_ENN_pin_set_state(channel, state); } |
|
|
|
|
|
|
|
void Hardware::STM32_HAL_onGPIO_EXTI_Callback(uint16_t gpioNum) { |
|
|
|
/**
|
|
|
|
* @brief 赋予盘零位光电触发 |
|
|
@ -391,7 +319,66 @@ void Hardware::tmc_subic_ENN_pin_set_state(uint8_t channel, bool state) { |
|
|
|
} |
|
|
|
} |
|
|
|
void Hardware::tmc_nRESET_pin_set_state(uint8_t channel, bool state) {} |
|
|
|
|
|
|
|
void Hardware::home_ref_switch_init() { //
|
|
|
|
STM32_HAL::gpioInitAsEXIT(TMC_HOME_REF_GPIO_PORT, TMC_HOME_REF_GPIO_PIN, GPIO_NOPULL, TMC_HOME_REF_GPIO_IRQ_MODE); |
|
|
|
} |
|
|
|
bool Hardware::home_ref_switch_get_state() { return (HAL_GPIO_ReadPin(TMC_HOME_REF_GPIO_PORT, TMC_HOME_REF_GPIO_PIN) == TMC_HOME_REF_GPIO_USEFUL_STATE); } |
|
|
|
/*******************************************************************************
|
|
|
|
* 硬件测试 * |
|
|
|
*******************************************************************************/ |
|
|
|
void Hardware::testTmp117() { |
|
|
|
static uint32_t lastcall; |
|
|
|
if (hasPassedMS(lastcall) > 1000) { |
|
|
|
lastcall = getTicket(); |
|
|
|
for (size_t i = 0; i < 4; i++) { |
|
|
|
float temp = tmp117[i].getTemperature(); |
|
|
|
if (tmp117[i].getLastCallStatus() == HAL_OK) { |
|
|
|
ZLOGI(TAG, "tmp117_%d:%f", i, temp); |
|
|
|
} else { |
|
|
|
ZLOGI(TAG, "tmp117_%d:read fail", i); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 测试CAN的发送和接收 |
|
|
|
*/ |
|
|
|
void Hardware::testCanSlaveTxAndRx() { |
|
|
|
{ |
|
|
|
static uint32_t lastcall; |
|
|
|
static uint8_t tx[8] = {1, 2, 3, 4, 5, 6, 7, 8}; |
|
|
|
if (hasPassedMS(lastcall) > 1000) { |
|
|
|
lastcall = getTicket(); |
|
|
|
// canSlaveService.translate(0x01, tx, 8, 2);
|
|
|
|
canSlaveService.sendReport(1, 2, 3, 100); |
|
|
|
if (canSlaveService.getLastTransmitStatus() == HAL_OK) { |
|
|
|
ZLOGI(TAG, "send ok"); |
|
|
|
} else { |
|
|
|
ZLOGI(TAG, "send fail"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief 接收CAN消息 |
|
|
|
*/ |
|
|
|
if (m_canOnRxDataFlag) { |
|
|
|
m_canOnRxDataFlag = false; |
|
|
|
static CAN_RxHeaderTypeDef packetHeader; |
|
|
|
static uint8_t packetData[8]; |
|
|
|
// while (canSlaveService.getRxMessage(&packetHeader, packetData)) {
|
|
|
|
// ZLOGI(TAG, "rx packet:");
|
|
|
|
// ZLOGI(TAG, "\tid:%x len:%d", packetHeader.StdId, packetHeader.DLC);
|
|
|
|
// ZLOGI_HEX(TAG, packetData, packetHeader.DLC);
|
|
|
|
// }
|
|
|
|
|
|
|
|
static IflytopCanSlave::packet_t packet; |
|
|
|
while (canSlaveService.getRxPacket(&packet)) { |
|
|
|
ZLOGI(TAG, "rx packet:"); |
|
|
|
ZLOGI(TAG, "\ttype:%01x, targetId:%01x, sourceId:%02x, seq:%02x, regAdd:%02x, regValue:%04x", //
|
|
|
|
packet.type, packet.targetId, packet.sourceId, packet.seq, packet.regAdd, packet.regValue); |
|
|
|
} |
|
|
|
canSlaveService.activateRxIT(); |
|
|
|
} |
|
|
|
} |