16 changed files with 340 additions and 537 deletions
-
154app/MDK-ARM/app.uvguix.h_zha
-
66app/MDK-ARM/app.uvoptx
-
19app/MDK-ARM/app.uvprojx
-
2dep/libiflytop_micro
-
199src/board/device_io_service.cpp
-
83src/board/device_io_service.hpp
-
4src/board/fan_state_monitor.cpp
-
242src/board/hardware.cpp
-
72src/board/hardware.hpp
-
4src/board/libtmcimpl.cpp
-
6src/board/libtmcimpl.hpp
-
6src/lncubator_rotating_control_service.cpp
-
13src/lncubator_rotating_control_service.hpp
-
4src/lncubator_temperature_control_service.cpp
-
1src/lncubator_temperature_control_service.hpp
-
2src/umain.cpp
154
app/MDK-ARM/app.uvguix.h_zha
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -1 +1 @@ |
|||
Subproject commit 160fa668ad40f8abac72d2634ee54fa4f3ad9188 |
|||
Subproject commit ffc78e8dc163fe8baea44325f3aeaca9ee05c146 |
@ -1,199 +0,0 @@ |
|||
#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) { |
|||
uint8_t c = ch; |
|||
HAL_UART_Transmit(&DEBUG_UART, &c, 1, 100); |
|||
return ch; |
|||
} |
|||
} |
|||
|
|||
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() { |
|||
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) { |
|||
STM32_HAL.setPWMFreq(&htim2, freq); // fan0->fan3
|
|||
STM32_HAL.setPWMFreq(&htim4, freq); // fan4
|
|||
STM32_HAL.setPWMFreq(&htim8, freq); // fan5
|
|||
|
|||
// fan0 fan1 fan2 fan3
|
|||
STM32_HAL.gpioInit(GPIOC, GPIO_PIN_0, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_LOW, GPIO_PIN_RESET); |
|||
// fan4
|
|||
STM32_HAL.gpioInit(GPIOC, GPIO_PIN_2, GPIO_MODE_OUTPUT_PP, GPIO_NOPULL, GPIO_SPEED_FREQ_LOW, GPIO_PIN_RESET); |
|||
// fan5
|
|||
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) { |
|||
if (fanIndex > 5) { |
|||
while (1) { |
|||
ZLOGE(TAG, "fanIndex is out of range!"); |
|||
} |
|||
} |
|||
|
|||
if (fanIndex <= 3) { |
|||
STM32_HAL.setPWMDuty(&htim2, TIM_CHANNEL_2, dutyCycle); |
|||
m_fanState[0] = dutyCycle > 0; |
|||
m_fanState[1] = dutyCycle > 0; |
|||
m_fanState[2] = dutyCycle > 0; |
|||
m_fanState[3] = dutyCycle > 0; |
|||
|
|||
if (dutyCycle > 0) { |
|||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_SET); |
|||
} else { |
|||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_RESET); |
|||
} |
|||
|
|||
} else if (fanIndex == 4) { |
|||
STM32_HAL.setPWMDuty(&htim4, TIM_CHANNEL_3, dutyCycle); |
|||
m_fanState[4] = dutyCycle > 0; |
|||
|
|||
if (dutyCycle > 0) { |
|||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_2, GPIO_PIN_SET); |
|||
} else { |
|||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_2, GPIO_PIN_RESET); |
|||
} |
|||
} else if (fanIndex == 5) { |
|||
STM32_HAL.setPWMDuty(&htim8, TIM_CHANNEL_3, dutyCycle); |
|||
m_fanState[5] = dutyCycle > 0; |
|||
|
|||
if (dutyCycle > 0) { |
|||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_3, GPIO_PIN_SET); |
|||
} else { |
|||
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_3, GPIO_PIN_RESET); |
|||
} |
|||
} |
|||
} |
|||
bool *DeviceIoService::fanGetPowerState(int fanIndex) { |
|||
if (fanIndex >= 5) { |
|||
while (1) { |
|||
ZLOGE(TAG, "fanIndex is out of range!"); |
|||
} |
|||
} |
|||
return &m_fanState[fanIndex]; |
|||
} |
|||
void DeviceIoService::fanSetState0to3(uint16_t dutyCycle) { fanSetDutyCycle(0, dutyCycle); } |
|||
void DeviceIoService::fanSetState4(uint16_t dutyCycle) { fanSetDutyCycle(4, dutyCycle); } |
|||
void DeviceIoService::fanSetState5(uint16_t dutyCycle) { fanSetDutyCycle(5, dutyCycle); } |
|||
|
|||
/*******************************************************************************
|
|||
* 帕尔贴驱动电路 * |
|||
*******************************************************************************/ |
|||
void DeviceIoService::peltier_cold_ctr_pwm(int pwm) { |
|||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, pwm); |
|||
HAL_TIM_PWM_Start(&htim1, TIM_CHANNEL_1); |
|||
} |
|||
// PB0 HOT_CTR_PWM0
|
|||
void DeviceIoService::peltier_hot_ctr_pwm(int pwm) { |
|||
__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_3, pwm); |
|||
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_3); |
|||
} |
|||
void DeviceIoService::peltier_init() { //
|
|||
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) { |
|||
/**
|
|||
* @brief |
|||
* |
|||
* 待机状态 |
|||
* HOT_CTR_PWM0(AL) = 0 |
|||
* HOT_CTR(AH) = 0 |
|||
* COLD_CTR_PWM0(BL) = 0 |
|||
* COLD_CTR(BH) = 0 |
|||
* 加热时 |
|||
* HOT_CTR_PWM0(AL) = 1(PWM) |
|||
* HOT_CTR(AH) = 0 |
|||
* COLD_CTR_PWM0(BL) = 0 |
|||
* COLD_CTR(BH) = 1(IO/保持) |
|||
* 制冷时 |
|||
* HOT_CTR_PWM0(AL) = 0 |
|||
* HOT_CTR(AH) = 1(IO/保持) |
|||
* COLD_CTR_PWM0(BL) = 1(PWM) |
|||
* COLD_CTR(BH) = 0 |
|||
*/ |
|||
pwm = pwm * 1000; |
|||
if (pwm == 0) { |
|||
peltier_hot_ctr_pwm(0); /*HOT_CTR_PWM0*/ |
|||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_RESET); /*HOT_CTR*/ |
|||
peltier_cold_ctr_pwm(0); /*COLD_CTR_PWM0*/ |
|||
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_10, GPIO_PIN_RESET); /*COLD_CTR*/ |
|||
} else if (pwm > 0) { |
|||
peltier_hot_ctr_pwm(pwm); /*HOT_CTR_PWM0*/ |
|||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_RESET); /*HOT_CTR*/ |
|||
peltier_cold_ctr_pwm(0); /*COLD_CTR_PWM0*/ |
|||
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_10, GPIO_PIN_SET); /*COLD_CTR*/ |
|||
} else { |
|||
peltier_hot_ctr_pwm(0); /*HOT_CTR_PWM0*/ |
|||
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_1, GPIO_PIN_SET); /*HOT_CTR*/ |
|||
peltier_cold_ctr_pwm(-pwm); /*COLD_CTR_PWM0*/ |
|||
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_10, GPIO_PIN_RESET); /*COLD_CTR*/ |
|||
} |
|||
} |
|||
/*******************************************************************************
|
|||
* tmc芯片驱动相关 * |
|||
*******************************************************************************/ |
|||
void DeviceIoService::tmc_init() { |
|||
STM32_HAL.gpioInit( //
|
|||
GPIOA, GPIO_PIN_4, GPIO_MODE_OUTPUT_PP, GPIO_PULLUP, GPIO_SPEED_FREQ_LOW, GPIO_PIN_SET); |
|||
STM32_HAL.gpioInit( //
|
|||
GPIOE, GPIO_PIN_12, GPIO_MODE_OUTPUT_PP, GPIO_PULLUP, GPIO_SPEED_FREQ_LOW, GPIO_PIN_SET); |
|||
STM32_HAL.gpioInit( //
|
|||
GPIOE, GPIO_PIN_11, GPIO_MODE_OUTPUT_PP, GPIO_PULLUP, GPIO_SPEED_FREQ_LOW, GPIO_PIN_SET); |
|||
} |
|||
|
|||
void DeviceIoService::tmc_motor_spi_select(int channel, bool state) { HAL_GPIO_WritePin(GPIOA, GPIO_PIN_4, state ? GPIO_PIN_SET : GPIO_PIN_RESET); } |
|||
void DeviceIoService::tmc_motor_spi_write_and_read(int channel, uint8_t *data, size_t length) { |
|||
if (channel == MOTOR_1_TMC4361A_CHANNEL) { |
|||
tmc_motor_spi_select(channel, false); |
|||
sleepus(10); |
|||
HAL_SPI_TransmitReceive(&hspi1, data, data, length, 1000); |
|||
tmc_motor_spi_select(channel, true); |
|||
} |
|||
} |
|||
void DeviceIoService::tmc_extern_clk_enable() { |
|||
#if 1
|
|||
/**
|
|||
* @brief TMC使用的外部时钟在stm32cubemx中已经进行配置,输出时钟为16MHZ |
|||
* 配置可以参考https://iflytop1.feishu.cn/wiki/wikcnog3hFm6dGFLMRksnhLb7Aw
|
|||
*/ |
|||
#endif
|
|||
} |
|||
void DeviceIoService::tmc_nFREEZE_pin_set_state(uint8_t channel, bool state) { |
|||
if (channel == MOTOR_1_TMC4361A_CHANNEL) { |
|||
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_12, state ? GPIO_PIN_SET : GPIO_PIN_RESET); |
|||
} |
|||
} |
|||
void DeviceIoService::tmc_ENN_pin_set_state(uint8_t channel, bool state) {} |
|||
void DeviceIoService::tmc_subic_ENN_pin_set_state(uint8_t channel, bool state) { |
|||
if (channel == MOTOR_1_TMC4361A_CHANNEL) { |
|||
HAL_GPIO_WritePin(GPIOE, GPIO_PIN_11, state ? GPIO_PIN_SET : GPIO_PIN_RESET); |
|||
} |
|||
} |
|||
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); |
|||
} |
@ -1,83 +0,0 @@ |
|||
#pragma once
|
|||
#include <stdint.h>
|
|||
#include <stdio.h>
|
|||
|
|||
#include "board/project_board.hpp"
|
|||
#include "libiflytop_micro/stm32/basic/basic.h"
|
|||
#include "libiflytop_micro\stm32\basic\iflytop_micro_os.hpp"
|
|||
#include "libiflytop_micro\stm32\basic\stm32_hal_res_manager.hpp"
|
|||
#include "libtrinamic/src/ic/tmc2160.hpp"
|
|||
#include "libtrinamic\src\ic\tmc4361A.hpp"
|
|||
#include "main.h"
|
|||
#include "spi.h"
|
|||
#include "tim.h"
|
|||
#include "usart.h"
|
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
|
|||
class DeviceIoService : public IflytopMicroOS { |
|||
private: |
|||
/* data */ |
|||
bool m_fanState[6]; |
|||
ZSLOT1(DeviceIoService, onGPIO_EXTI_Callback, uint16_t); // GPIO中断回调
|
|||
|
|||
public: |
|||
DeviceIoService(/* args */) {} |
|||
~DeviceIoService() {} |
|||
|
|||
void initialize(); |
|||
|
|||
/*******************************************************************************
|
|||
* 调试指示灯初始化 * |
|||
*******************************************************************************/ |
|||
|
|||
void debug_light_init(); |
|||
|
|||
/*******************************************************************************
|
|||
* 风扇控制 * |
|||
*******************************************************************************/ |
|||
void fanInit(int freq); |
|||
void fanSetDutyCycle(int fanIndex, uint16_t dutyCycle); |
|||
bool *fanGetPowerState(int fanIndex); |
|||
void fanSetState0to3(uint16_t dutyCycle); |
|||
void fanSetState4(uint16_t dutyCycle); |
|||
void fanSetState5(uint16_t dutyCycle); |
|||
/*******************************************************************************
|
|||
* 帕尔贴驱动电路 * |
|||
*******************************************************************************/ |
|||
void peltier_init(); |
|||
void peltier_set_pwm(int pwm); |
|||
/*******************************************************************************
|
|||
* tmc芯片驱动相关 * |
|||
*******************************************************************************/ |
|||
void tmc_init(); |
|||
void tmc_motor_spi_write_and_read(int channel, uint8_t *data, size_t length); |
|||
void tmc_extern_clk_enable(); |
|||
void tmc_nFREEZE_pin_set_state(uint8_t channel, bool state); |
|||
void tmc_ENN_pin_set_state(uint8_t channel, bool state); |
|||
void tmc_subic_ENN_pin_set_state(uint8_t channel, bool state); |
|||
void tmc_nRESET_pin_set_state(uint8_t channel, bool state); |
|||
|
|||
ZSignal0<void> onHomeRefSwitch; |
|||
void home_ref_switch_init(); |
|||
|
|||
/*******************************************************************************
|
|||
* OVERRIDE IflytopMicroOS * |
|||
*******************************************************************************/ |
|||
virtual void sleepMS(int ms) { HAL_Delay(ms); }; |
|||
virtual uint32_t hasPassedMS(uint32_t ticket) { return sys_haspassedms(ticket); }; |
|||
virtual uint32_t getTicket() { return HAL_GetTick(); }; |
|||
virtual uint32_t getNowMS() { return HAL_GetTick(); }; |
|||
virtual void sleepus(uint32_t us) { sys_delay_us(&DELAY_US_TIMER, us); } |
|||
|
|||
private: |
|||
// PE9 COLD_CTR_PWM0
|
|||
void peltier_cold_ctr_pwm(int pwm); |
|||
// PB0 HOT_CTR_PWM0
|
|||
void peltier_hot_ctr_pwm(int pwm); |
|||
|
|||
void tmc_motor_spi_select(int channel, bool state); |
|||
}; |
|||
|
|||
} // namespace iflytop
|
@ -1,4 +0,0 @@ |
|||
#pragma once
|
|||
#include "libtmcimpl.hpp"
|
|||
|
|||
#include "device_io_service.hpp"
|
@ -1,6 +0,0 @@ |
|||
#pragma once
|
|||
|
|||
#include "board/device_io_service.hpp"
|
|||
#include "libiflytop_micro/stm32/basic/basic.h"
|
|||
#include "libtrinamic/src/ic/tmc2160.hpp"
|
|||
#include "libtrinamic\src\ic\tmc4361A.hpp"
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue