tmc2240加上注释

This commit is contained in:
许晟昊 2024-12-31 09:20:29 +08:00
parent f8a9b8e22a
commit 8064eae0d9
2 changed files with 94 additions and 6 deletions

View File

@ -38,10 +38,7 @@
"C_Cpp_Runner.compilerArgs": [],
"C_Cpp_Runner.linkerArgs": [],
"C_Cpp_Runner.includePaths": [],
"C_Cpp_Runner.includeSearch": [
"*",
"**/*"
],
"C_Cpp_Runner.includeSearch": ["*", "**/*"],
"C_Cpp_Runner.excludeSearch": [
"**/build",
"**/build/**",
@ -55,5 +52,6 @@
"C_Cpp_Runner.useLeakSanitizer": false,
"C_Cpp_Runner.showCompilationTime": false,
"C_Cpp_Runner.useLinkTimeOptimization": false,
"C_Cpp_Runner.msvcSecureNoWarnings": false
"C_Cpp_Runner.msvcSecureNoWarnings": false,
"C_Cpp.errorSquiggles": "disabled"
}

View File

@ -43,6 +43,15 @@ static void tmc2240_read(tmc2240_index_e index, uint8_t *wdata, uint8_t *rdata)
tmc->spi->gpios.cs->set(*tmc->spi->gpios.cs);
}
/**
* @brief TMC2240寄存器写入数据
*
* TMC2240的指定寄存器写入32位数据
*
* @param index TMC2240索引
* @param reg
* @param data
*/
static void tmc2240_reg_write(tmc2240_index_e index, uint8_t reg, uint32_t data)
{
DBG_ASSERT(index < TMC2240_MAX __DBG_LINE);
@ -59,6 +68,16 @@ static void tmc2240_reg_write(tmc2240_index_e index, uint8_t reg, uint32_t data)
tmc2240_write(index, wdata);
}
/**
* @brief TMC2240寄存器中读取数据
*
* TMC2240驱动器的指定寄存器中读取数据
*
* @param index TMC2240驱动器的索引
* @param reg
*
* @return 32
*/
static uint32_t tmc2240_reg_read(tmc2240_index_e index, uint8_t reg)
{
DBG_ASSERT(index < TMC2240_MAX __DBG_LINE);
@ -110,6 +129,13 @@ static void tmc2240_config_write(tmc2240_index_e index)
tmc2240_reg_write(index, TMC2240_GSTAT, tmc->config.gstat.data);
}
/**
* @brief TMC2240步进电机的步进角度和每圈脉冲数
*
* TMC2240的配置更新步进电机的步进角度和每圈脉冲数
*
* @param index TMC2240步进电机的索引
*/
static void _tmc2240_motor_update(tmc2240_index_e index)
{
DBG_ASSERT(index < TMC2240_MAX __DBG_LINE);
@ -152,6 +178,14 @@ static void _tmc2240_motor_update(tmc2240_index_e index)
tmc->motor.circle_pulse = 360 / tmc->motor.step_angle;
}
/**
* @brief TMC2240电机驱动器
*
* TMC2240电机驱动器
*
* @param index TMC2240驱动器的索引
* @param enable TRUE表示启用FALSE表示禁用
*/
static void _tmc2240_enable(tmc2240_index_e index, BOOL enable)
{
DBG_ASSERT(index < TMC2240_MAX __DBG_LINE);
@ -182,6 +216,14 @@ static void _tmc2240_enable(tmc2240_index_e index, BOOL enable)
}
}
/**
* @brief TMC2240驱动器的方向
*
* TMC2240驱动器的方向
*
* @param index TMC2240驱动器的索引
* @param dir TMC2240_FORWARD表示正向TMC2240_BACKWARD表示反向
*/
static void _tmc2240_direction(tmc2240_index_e index, tmc2240_direction_e dir)
{
DBG_ASSERT(index < TMC2240_MAX __DBG_LINE);
@ -198,6 +240,17 @@ static void _tmc2240_direction(tmc2240_index_e index, tmc2240_direction_e dir)
}
}
/**
* @brief TMC2240电机驱动器
*
* TMC2240电机驱动器SPI通信GPIO引脚
*
* @param index TMC2240的索引号
* @param SPIx SPI外设指针
* @param timer
* @param time_ch
* @param gpios SPI通信相关的GPIO引脚组
*/
void tmc2240_init(tmc2240_index_e index, SPI_TypeDef *SPIx, TIM_TypeDef *timer, uint32_t time_ch, spi_gpio_group_t *gpios)
{
DBG_ASSERT(index < TMC2240_MAX __DBG_LINE);
@ -230,6 +283,14 @@ tmc2240_t *tmc2240_get(tmc2240_index_e index)
return &_tmc2240[index];
}
/**
* @brief TMC2240的占空比
*
* TMC2240的占空比
*
* @param index TMC2240的索引
* @param percent -100100
*/
void tmc2240_percent(tmc2240_index_e index, float32 percent)
{
DBG_ASSERT(index < TMC2240_MAX __DBG_LINE);
@ -239,6 +300,13 @@ void tmc2240_percent(tmc2240_index_e index, float32 percent)
PWM_SET_DUTY(tmc->timer, tmc->time_ch, ABS(percent));
}
/**
* @brief TMC2240的配置参数
*
* TMC2240电机驱动器的寄存器中读取多个配置参数
*
* @param index TMC2240电机驱动器的索引
*/
void tmc2240_config_read(tmc2240_index_e index)
{
DBG_ASSERT(index < TMC2240_MAX __DBG_LINE);
@ -256,6 +324,13 @@ void tmc2240_config_read(tmc2240_index_e index)
tmc->data.tmc2240_temperature = (float32)(tmc->data.tmc2240_adc_temp - 2038) / 7.7;
}
/**
* @brief TMC2240电机驱动器
*
* TMC2240电机驱动器
*
* @param index TMC2240电机驱动器的索引
*/
void tmc2240_test(tmc2240_index_e index)
{
DBG_ASSERT(index < TMC2240_MAX __DBG_LINE);
@ -288,6 +363,14 @@ void tmc2240_test(tmc2240_index_e index)
}
}
/**
* @brief TMC2240电机的角度
*
* TMC2240电机的目标角度
*
* @param index
* @param angle
*/
void tmc2240_motor_set_angle(tmc2240_index_e index, int32_t angle)
{
DBG_ASSERT(index < TMC2240_MAX __DBG_LINE);
@ -334,6 +417,13 @@ void tmc2240_motor_set_angle(tmc2240_index_e index, int32_t angle)
_tmc2240_enable(index, tmc->params.enable);
}
/**
* @brief TMC2240步进电机的状态
*
* TMC2240步进电机的状态
*
* @param index TMC2240步进电机的索引
*/
void tmc2240_motor_update(tmc2240_index_e index)
{
DBG_ASSERT(index < TMC2240_MAX __DBG_LINE);