|
@ -29,29 +29,17 @@ void port_do_debug_light_state() { |
|
|
HAL_GPIO_TogglePin(DEBUG_LIGHT_PORT, DEBUG_LIGHT_PIN); |
|
|
HAL_GPIO_TogglePin(DEBUG_LIGHT_PORT, DEBUG_LIGHT_PIN); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void port_spi_cs_select(uint8_t channel, bool select) { |
|
|
|
|
|
if (channel == MOTOR_1_TMC4361A_CHANNEL) { |
|
|
|
|
|
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, select ? GPIO_PIN_SET : GPIO_PIN_RESET); |
|
|
|
|
|
} else if (channel == MOTOR_1_TMC2160_CHANNEL) { |
|
|
|
|
|
/**
|
|
|
|
|
|
* @brief TMC2160 连接到了 TMC4361A 的 SPI 接口上,所以不需要单独的片选 |
|
|
|
|
|
*/ |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void port_delay_us(uint32_t us) { sys_delay_us(&DELAY_US_TIMER, us); } |
|
|
void port_delay_us(uint32_t us) { sys_delay_us(&DELAY_US_TIMER, us); } |
|
|
|
|
|
|
|
|
void port_motor_spi_write_and_read(uint8_t channel, uint8_t* data, size_t length) { |
|
|
|
|
|
|
|
|
void port_spi_cs_select(bool select) { //
|
|
|
|
|
|
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, select ? GPIO_PIN_SET : GPIO_PIN_RESET); |
|
|
|
|
|
} |
|
|
|
|
|
void port_tmc4361_spi_write_and_read(uint8_t* data, size_t length) { |
|
|
//
|
|
|
//
|
|
|
if (channel == MOTOR_1_TMC4361A_CHANNEL) { |
|
|
|
|
|
port_spi_cs_select(channel, false); |
|
|
|
|
|
port_delay_us(1); |
|
|
|
|
|
HAL_SPI_TransmitReceive(&hspi1, data, data, length, 1000); |
|
|
|
|
|
port_spi_cs_select(channel, true); |
|
|
|
|
|
} else if (channel == MOTOR_1_TMC2160_CHANNEL) { |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
port_spi_cs_select(false); |
|
|
|
|
|
port_delay_us(1); |
|
|
|
|
|
HAL_SPI_TransmitReceive(&hspi1, data, data, length, 1000); |
|
|
|
|
|
port_spi_cs_select(true); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void port_tmc_extern_clk_enable() { |
|
|
void port_tmc_extern_clk_enable() { |
|
@ -65,12 +53,11 @@ void port_tmc_extern_clk_enable() { |
|
|
HAL_TIM_PWM_Start(&htim8, TIM_CHANNEL_4); |
|
|
HAL_TIM_PWM_Start(&htim8, TIM_CHANNEL_4); |
|
|
#endif
|
|
|
#endif
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int32_t port_tmc4361_get_version(uint8_t channel) { |
|
|
int32_t port_tmc4361_get_version(uint8_t channel) { |
|
|
int value; |
|
|
int value; |
|
|
uint8_t data[5]; |
|
|
uint8_t data[5]; |
|
|
data[0] = 0x7f; |
|
|
data[0] = 0x7f; |
|
|
port_motor_spi_write_and_read(channel, &data[0], 5); |
|
|
|
|
|
|
|
|
port_tmc4361_spi_write_and_read(&data[0], 5); |
|
|
value = ((uint32_t)data[1] << 24) | ((uint32_t)data[2] << 16) | (data[3] << 8) | data[4]; |
|
|
value = ((uint32_t)data[1] << 24) | ((uint32_t)data[2] << 16) | (data[3] << 8) | data[4]; |
|
|
return value; |
|
|
return value; |
|
|
} |
|
|
} |