|
|
@ -1,6 +1,8 @@ |
|
|
|
#include "device_io_service.hpp"
|
|
|
|
|
|
|
|
#include "libiflytop_micro/stm32/basic/stm32_hal_utils.hpp"
|
|
|
|
#include "libiflytop_micro\stm32\basic\stm32_hal_res_manager.hpp"
|
|
|
|
#include "project_board.hpp"
|
|
|
|
#define TAG "DEVICE_IO_SERVICE"
|
|
|
|
extern "C" { |
|
|
|
int fputc(int ch, FILE *stream) { |
|
|
@ -12,21 +14,36 @@ int fputc(int ch, FILE *stream) { |
|
|
|
|
|
|
|
using namespace iflytop; |
|
|
|
namespace iflytop {} |
|
|
|
void DeviceIoService::initialize() { //
|
|
|
|
// STM32_HAL.connect(this, &DeviceIoService::onGPIO_EXTI_Callback);
|
|
|
|
} |
|
|
|
|
|
|
|
void DeviceIoService::onGPIO_EXTI_Callback(uint16_t gpioNum) { |
|
|
|
/**
|
|
|
|
* @brief 赋予盘零位光电触发 |
|
|
|
*/ |
|
|
|
if (gpioNum == TMC_HOME_REF_GPIO_PIN) { |
|
|
|
if (STM32_HAL_GPIO_IS_THIS_PIN_TRIGGER_IRQ(TMC_HOME_REF_GPIO)) { |
|
|
|
onHomeRefSwitch.trigger(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void DeviceIoService::debug_light_init() { |
|
|
|
Stm32HalUtils::gpioInit(DEBUG_LIGHT_PORT, DEBUG_LIGHT_PIN, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_LOW, GPIO_PIN_RESET); |
|
|
|
STM32_HAL.gpioInit(DEBUG_LIGHT_PORT, DEBUG_LIGHT_PIN, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_LOW, GPIO_PIN_RESET); |
|
|
|
} |
|
|
|
|
|
|
|
void DeviceIoService::fanInit(int freq) { |
|
|
|
Stm32HalUtils::setPWMFreq(&htim2, freq); // fan0->fan3
|
|
|
|
Stm32HalUtils::setPWMFreq(&htim4, freq); // fan4
|
|
|
|
Stm32HalUtils::setPWMFreq(&htim8, freq); // fan5
|
|
|
|
STM32_HAL.setPWMFreq(&htim2, freq); // fan0->fan3
|
|
|
|
STM32_HAL.setPWMFreq(&htim4, freq); // fan4
|
|
|
|
STM32_HAL.setPWMFreq(&htim8, freq); // fan5
|
|
|
|
|
|
|
|
// fan0 fan1 fan2 fan3
|
|
|
|
Stm32HalUtils::gpioInit(GPIOC, GPIO_PIN_0, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_LOW, GPIO_PIN_RESET); |
|
|
|
STM32_HAL.gpioInit(GPIOC, GPIO_PIN_0, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_LOW, GPIO_PIN_RESET); |
|
|
|
// fan4
|
|
|
|
Stm32HalUtils::gpioInit(GPIOC, GPIO_PIN_2, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_LOW, GPIO_PIN_RESET); |
|
|
|
STM32_HAL.gpioInit(GPIOC, GPIO_PIN_2, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_LOW, GPIO_PIN_RESET); |
|
|
|
// fan5
|
|
|
|
Stm32HalUtils::gpioInit(GPIOC, GPIO_PIN_3, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_LOW, GPIO_PIN_RESET); |
|
|
|
STM32_HAL.gpioInit(GPIOC, GPIO_PIN_3, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_LOW, GPIO_PIN_RESET); |
|
|
|
} |
|
|
|
|
|
|
|
void DeviceIoService::fanSetDutyCycle(int fanIndex, uint16_t dutyCycle) { |
|
|
@ -37,7 +54,7 @@ void DeviceIoService::fanSetDutyCycle(int fanIndex, uint16_t dutyCycle) { |
|
|
|
} |
|
|
|
|
|
|
|
if (fanIndex <= 3) { |
|
|
|
Stm32HalUtils::setPWMDuty(&htim2, TIM_CHANNEL_2, dutyCycle); |
|
|
|
STM32_HAL.setPWMDuty(&htim2, TIM_CHANNEL_2, dutyCycle); |
|
|
|
m_fanState[0] = dutyCycle > 0; |
|
|
|
m_fanState[1] = dutyCycle > 0; |
|
|
|
m_fanState[2] = dutyCycle > 0; |
|
|
@ -50,7 +67,7 @@ void DeviceIoService::fanSetDutyCycle(int fanIndex, uint16_t dutyCycle) { |
|
|
|
} |
|
|
|
|
|
|
|
} else if (fanIndex == 4) { |
|
|
|
Stm32HalUtils::setPWMDuty(&htim4, TIM_CHANNEL_3, dutyCycle); |
|
|
|
STM32_HAL.setPWMDuty(&htim4, TIM_CHANNEL_3, dutyCycle); |
|
|
|
m_fanState[4] = dutyCycle > 0; |
|
|
|
|
|
|
|
if (dutyCycle > 0) { |
|
|
@ -59,7 +76,7 @@ void DeviceIoService::fanSetDutyCycle(int fanIndex, uint16_t dutyCycle) { |
|
|
|
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_2, GPIO_PIN_RESET); |
|
|
|
} |
|
|
|
} else if (fanIndex == 5) { |
|
|
|
Stm32HalUtils::setPWMDuty(&htim8, TIM_CHANNEL_3, dutyCycle); |
|
|
|
STM32_HAL.setPWMDuty(&htim8, TIM_CHANNEL_3, dutyCycle); |
|
|
|
m_fanState[5] = dutyCycle > 0; |
|
|
|
|
|
|
|
if (dutyCycle > 0) { |
|
|
@ -94,8 +111,8 @@ void DeviceIoService::peltier_hot_ctr_pwm(int pwm) { |
|
|
|
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3); |
|
|
|
} |
|
|
|
void DeviceIoService::peltier_init() { //
|
|
|
|
Stm32HalUtils::gpioInit(GPIOB, GPIO_PIN_1, GPIO_MODE_AF_PP, GPIO_PULLUP, GPIO_SPEED_FREQ_LOW, GPIO_PIN_RESET); |
|
|
|
Stm32HalUtils::gpioInit(GPIOE, GPIO_PIN_10, GPIO_MODE_AF_PP, GPIO_PULLUP, GPIO_SPEED_FREQ_LOW, GPIO_PIN_RESET); |
|
|
|
STM32_HAL.gpioInit(GPIOB, GPIO_PIN_1, GPIO_MODE_AF_PP, GPIO_PULLUP, GPIO_SPEED_FREQ_LOW, GPIO_PIN_RESET); |
|
|
|
STM32_HAL.gpioInit(GPIOE, GPIO_PIN_10, GPIO_MODE_AF_PP, GPIO_PULLUP, GPIO_SPEED_FREQ_LOW, GPIO_PIN_RESET); |
|
|
|
} |
|
|
|
void DeviceIoService::peltier_set_pwm(int pwm) { |
|
|
|
/**
|
|
|
@ -139,11 +156,11 @@ void DeviceIoService::peltier_set_pwm(int pwm) { |
|
|
|
* tmc芯片驱动相关 * |
|
|
|
*******************************************************************************/ |
|
|
|
void DeviceIoService::tmc_init() { |
|
|
|
Stm32HalUtils::gpioInit( //
|
|
|
|
STM32_HAL.gpioInit( //
|
|
|
|
GPIOA, GPIO_PIN_4, GPIO_MODE_OUTPUT_PP, GPIO_PULLUP, GPIO_SPEED_FREQ_LOW, GPIO_PIN_SET); |
|
|
|
Stm32HalUtils::gpioInit( //
|
|
|
|
STM32_HAL.gpioInit( //
|
|
|
|
GPIOE, GPIO_PIN_12, GPIO_MODE_OUTPUT_PP, GPIO_PULLUP, GPIO_SPEED_FREQ_LOW, GPIO_PIN_SET); |
|
|
|
Stm32HalUtils::gpioInit( //
|
|
|
|
STM32_HAL.gpioInit( //
|
|
|
|
GPIOE, GPIO_PIN_11, GPIO_MODE_OUTPUT_PP, GPIO_PULLUP, GPIO_SPEED_FREQ_LOW, GPIO_PIN_SET); |
|
|
|
} |
|
|
|
|
|
|
@ -176,3 +193,7 @@ void DeviceIoService::tmc_subic_ENN_pin_set_state(uint8_t channel, bool state) { |
|
|
|
} |
|
|
|
} |
|
|
|
void DeviceIoService::tmc_nRESET_pin_set_state(uint8_t channel, bool state) {} |
|
|
|
|
|
|
|
void DeviceIoService::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); |
|
|
|
} |