You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

199 lines
6.7 KiB

#include "public_board.hpp"
using namespace iflytop;
using namespace transmit_disfection_protocol;
static ZGPIO BID0;
static ZGPIO BID1;
static ZGPIO BID2;
static ZGPIO BID3;
static ZGPIO BID4;
static ZGPIO BID5;
static ZGPIO BID6;
static ZGPIO BID7;
int32_t getDeviceIdFromFlash() {
int32_t *deviceId = (int32_t *)BOARD_TYPE_ID_FLASH_ADD;
if (*deviceId <= 0) {
return 0;
}
return *deviceId;
}
void PublicBoard::debugUartInit(void) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
__HAL_RCC_USART1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
huart1.Instance = USART1;
huart1.Init.BaudRate = 460800;
huart1.Init.WordLength = UART_WORDLENGTH_8B;
huart1.Init.StopBits = UART_STOPBITS_1;
huart1.Init.Parity = UART_PARITY_NONE;
huart1.Init.Mode = UART_MODE_TX_RX;
huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart1.Init.OverSampling = UART_OVERSAMPLING_16;
if (HAL_UART_Init(&huart1) != HAL_OK) {
Error_Handler();
}
// PA9,PA10
GPIO_InitStruct.Pin = GPIO_PIN_9 | GPIO_PIN_10;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF7_USART1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
}
void PublicBoard::canInit() {
__HAL_RCC_CAN1_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();
hcan1.Instance = CAN1;
hcan1.Init.Prescaler = 4;
hcan1.Init.Mode = CAN_MODE_NORMAL;
hcan1.Init.SyncJumpWidth = CAN_SJW_3TQ;
hcan1.Init.TimeSeg1 = CAN_BS1_14TQ;
hcan1.Init.TimeSeg2 = CAN_BS2_3TQ;
hcan1.Init.TimeTriggeredMode = ENABLE;
hcan1.Init.AutoBusOff = ENABLE;
hcan1.Init.AutoWakeUp = DISABLE;
hcan1.Init.AutoRetransmission = ENABLE;
hcan1.Init.ReceiveFifoLocked = ENABLE;
hcan1.Init.TransmitFifoPriority = DISABLE;
if (HAL_CAN_Init(&hcan1) != HAL_OK) {
Error_Handler();
}
GPIO_InitTypeDef GPIO_InitStruct = {0};
// PA11 PA12
GPIO_InitStruct.Pin = GPIO_PIN_11 | GPIO_PIN_12;
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
GPIO_InitStruct.Alternate = GPIO_AF9_CAN1;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
HAL_NVIC_SetPriority(CAN1_TX_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(CAN1_TX_IRQn);
HAL_NVIC_SetPriority(CAN1_RX0_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(CAN1_RX0_IRQn);
HAL_NVIC_SetPriority(CAN1_RX1_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(CAN1_RX1_IRQn);
HAL_NVIC_SetPriority(CAN1_SCE_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(CAN1_SCE_IRQn);
}
void PublicBoard::initialize() {
// if (getDeviceIdFromFlash() <= 0) {
// BID0.initAsInput(PE1, kxs_gpio_pullup, kxs_gpio_no_irq, false);
// BID1.initAsInput(PE2, kxs_gpio_pullup, kxs_gpio_no_irq, false);
// BID2.initAsInput(PE3, kxs_gpio_pullup, kxs_gpio_no_irq, false);
// BID3.initAsInput(PE4, kxs_gpio_pullup, kxs_gpio_no_irq, false);
// BID4.initAsInput(PE5, kxs_gpio_pullup, kxs_gpio_no_irq, false);
// BID5.initAsInput(PE6, kxs_gpio_pullup, kxs_gpio_no_irq, false);
// BID6.initAsInput(PE7, kxs_gpio_pullup, kxs_gpio_no_irq, false);
// BID7.initAsInput(PE8, kxs_gpio_pullup, kxs_gpio_no_irq, false);
// }
debugUartInit();
canInit();
if (getDeviceIdFromFlash() == kH2O2SensorBoard) {
m_debugled.initAsOutput(H2O2_SENSOR_BOARD_DEBUG_LIGHT_GPIO, kxs_gpio_nopull, false, false);
} else {
m_debugled.initAsOutput(DEBUG_LIGHT_GPIO, kxs_gpio_nopull, false, false);
}
}
void PublicBoard::setDebugLightState(bool state) { m_debugled.write(state); }
void PublicBoard::toggleDebugLight() { m_debugled.toggle(); }
int PublicBoard::getProjId() { return IdMgr::ins().getProjId(getBoardTypeId()); }
int PublicBoard::getBoardTypeId() {
if (getDeviceIdFromFlash() > 0) {
return getDeviceIdFromFlash();
} else {
return 0;
// int32_t id = 0;
// id += BID0.read() ? 1 : 0;
// id += BID1.read() ? 2 : 0;
// id += BID2.read() ? 4 : 0;
// id += BID3.read() ? 8 : 0;
// id += BID4.read() ? 16 : 0;
// id += BID5.read() ? 32 : 0;
// id += BID6.read() ? 64 : 0;
// id += BID7.read() ? 128 : 0;
// return id;
}
}
int PublicBoard::getBoardId() {
int boardIdoff = 0;
if (getBoardTypeId() == kH2O2SensorBoard) {
static ZGPIO id_from_machine; // 消毒机上的开关
if (!id_from_machine.isInited()) {
id_from_machine.initAsInput(PE8, kxs_gpio_nopull, kxs_gpio_no_irq, false);
}
boardIdoff = id_from_machine.read() ? 1 : 2;
}
return IdMgr::ins().getBoardId(getBoardTypeId()) + boardIdoff;
}
bool PORT::isLargeSpaceDM() { return PublicBoard::ins()->getProjId() == klarge_space_disinfection_machine; }
bool PORT::isSamllSpaceDM() { return PublicBoard::ins()->getProjId() == ksmall_space_disinfection_machine; }
bool PORT::isPipeDM() { return PublicBoard::ins()->getProjId() == kpipe_disinfection_machine; }
bool PORT::isDrawBarDM() { return PublicBoard::ins()->getProjId() == kdraw_bar_disinfection_box; }
bool PORT::isH2O2Sensor() { return PublicBoard::ins()->getProjId() == kh2o2_ext_sensor; }
bool PORT::isLiquidCtrlBoard() {
if (PublicBoard::ins()->getBoardTypeId() == kLargeSpaceDMLiquidCtrlBoard || //
PublicBoard::ins()->getBoardTypeId() == kSmallSpaceDMLiquidCtrlBoard || //
PublicBoard::ins()->getBoardTypeId() == kPipeDMLiquidCtrlBoard || //
PublicBoard::ins()->getBoardTypeId() == kDrawBarDMLiquidCtrlBoard) {
return true;
}
return false;
}
bool PORT::isPowerCtrlBoard() {
if (PublicBoard::ins()->getBoardTypeId() == kLargeSpaceDMPowerCtrlBoard || //
PublicBoard::ins()->getBoardTypeId() == kSmallSpaceDMPowerCtrlBoard || //
PublicBoard::ins()->getBoardTypeId() == kPipeDMPowerCtrlBoard || //
PublicBoard::ins()->getBoardTypeId() == kDrawBarDMPowerCtrlBoard) {
return true;
}
return false;
}
namespace iflytop {
bool isBoardType(int32_t val0) {
int boardType = PublicBoard::ins()->getBoardTypeId();
if (boardType == val0) {
return true;
}
return false;
}
bool isBoardType(int32_t val0, int32_t val1) {
int boardType = PublicBoard::ins()->getBoardTypeId();
if (boardType == val0 || boardType == val1) {
return true;
}
return false;
}
bool isBoardType(int32_t val0, int32_t val1, int32_t val2) {
int boardType = PublicBoard::ins()->getBoardTypeId();
if (boardType == val0 || boardType == val1 || boardType == val2) {
return true;
}
return false;
}
bool isBoardType(int32_t val0, int32_t val1, int32_t val2, int32_t val3) {
int boardType = PublicBoard::ins()->getBoardTypeId();
if (boardType == val0 || boardType == val1 || boardType == val2 || boardType == val3) {
return true;
}
return false;
}
} // namespace iflytop