|
|
@ -3,7 +3,7 @@ |
|
|
|
#include "i2c.h"
|
|
|
|
using namespace iflytop; |
|
|
|
#define TAG "hardware"
|
|
|
|
#define ENABLE_CAN 0
|
|
|
|
#define ENABLE_CAN 1
|
|
|
|
extern "C" { |
|
|
|
int fputc(int ch, FILE *stream) { |
|
|
|
uint8_t c = ch; |
|
|
@ -42,7 +42,7 @@ void Hardware::hardwareinit() { |
|
|
|
*******************************************************************************/ |
|
|
|
#if ENABLE_CAN
|
|
|
|
IflytopCanSlave::iflytop_can_slave_config_t *config = canSlaveService.createDefaultConfig(DEVICE_ID); |
|
|
|
canSlaveService.initialize(m_os, config); |
|
|
|
canSlaveService.initialize(this, config); |
|
|
|
canSlaveService.activateRxIT(); |
|
|
|
canSlaveService.registerListener(this); |
|
|
|
#endif
|
|
|
@ -65,7 +65,7 @@ void Hardware::hardwareinit() { |
|
|
|
/*******************************************************************************
|
|
|
|
* 电机初始化 * |
|
|
|
*******************************************************************************/ |
|
|
|
#if 1
|
|
|
|
#if 0
|
|
|
|
tmc_init(); |
|
|
|
tmc_extern_clk_enable(); |
|
|
|
// 4361初始化
|
|
|
@ -137,7 +137,7 @@ void Hardware::periodicJob() { |
|
|
|
#endif
|
|
|
|
do_debug_light_state(); |
|
|
|
#if ENABLE_CAN
|
|
|
|
// testCanSlaveTxAndRx();
|
|
|
|
testCanSlaveTxAndRx(); |
|
|
|
#endif
|
|
|
|
} |
|
|
|
void Hardware::do_debug_light_state() { |
|
|
@ -174,7 +174,8 @@ void Hardware::testCanSlaveTxAndRx() { |
|
|
|
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.translate(0x01, tx, 8, 2);
|
|
|
|
canSlaveService.sendReport(1, 2, 3, 100); |
|
|
|
if (canSlaveService.getLastTransmitStatus() == HAL_OK) { |
|
|
|
ZLOGI(TAG, "send ok"); |
|
|
|
} else { |
|
|
@ -190,12 +191,19 @@ void Hardware::testCanSlaveTxAndRx() { |
|
|
|
m_canOnRxDataFlag = false; |
|
|
|
static CAN_RxHeaderTypeDef packetHeader; |
|
|
|
static uint8_t packetData[8]; |
|
|
|
while (canSlaveService.getRxMessage(&packetHeader, packetData)) { |
|
|
|
// 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, "\tid:%x len:%d", packetHeader.StdId, packetHeader.DLC); |
|
|
|
ZLOGI_HEX(TAG, packetData, packetHeader.DLC); |
|
|
|
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();
|
|
|
|
canSlaveService.activateRxIT(); |
|
|
|
} |
|
|
|
} |
|
|
|
void Hardware::TMC4361APort_setResetPinState(uint16_t channel, bool state) { tmc_nRESET_pin_set_state(channel, state); } |
|
|
|