|
|
@ -49,69 +49,69 @@ void ZGPIO::regListener(onirq_t listener) { m_onirq = listener; } |
|
|
|
/*******************************************************************************
|
|
|
|
* BASE_FUNC * |
|
|
|
*******************************************************************************/ |
|
|
|
bool ZGPIO::enableClock() { |
|
|
|
bool ZGPIO::enableClock(GPIO_TypeDef *port) { |
|
|
|
#ifdef GPIOA
|
|
|
|
if (m_gpio == GPIOA) { |
|
|
|
if (port == GPIOA) { |
|
|
|
__HAL_RCC_GPIOA_CLK_ENABLE(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
#endif
|
|
|
|
#ifdef GPIOB
|
|
|
|
if (m_gpio == GPIOB) { |
|
|
|
if (port == GPIOB) { |
|
|
|
__HAL_RCC_GPIOB_CLK_ENABLE(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
#endif
|
|
|
|
#ifdef GPIOC
|
|
|
|
if (m_gpio == GPIOC) { |
|
|
|
if (port == GPIOC) { |
|
|
|
__HAL_RCC_GPIOC_CLK_ENABLE(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
#endif
|
|
|
|
#ifdef GPIOD
|
|
|
|
if (m_gpio == GPIOD) { |
|
|
|
if (port == GPIOD) { |
|
|
|
__HAL_RCC_GPIOD_CLK_ENABLE(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
#endif
|
|
|
|
#ifdef GPIOE
|
|
|
|
if (m_gpio == GPIOE) { |
|
|
|
if (port == GPIOE) { |
|
|
|
__HAL_RCC_GPIOE_CLK_ENABLE(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
#endif
|
|
|
|
#ifdef GPIOF
|
|
|
|
if (m_gpio == GPIOF) { |
|
|
|
if (port == GPIOF) { |
|
|
|
__HAL_RCC_GPIOF_CLK_ENABLE(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
#endif
|
|
|
|
#ifdef GPIOG
|
|
|
|
if (m_gpio == GPIOG) { |
|
|
|
if (port == GPIOG) { |
|
|
|
__HAL_RCC_GPIOG_CLK_ENABLE(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
#endif
|
|
|
|
#ifdef GPIOH
|
|
|
|
if (m_gpio == GPIOH) { |
|
|
|
if (port == GPIOH) { |
|
|
|
__HAL_RCC_GPIOH_CLK_ENABLE(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
#endif
|
|
|
|
#ifdef GPIOI
|
|
|
|
if (m_gpio == GPIOI) { |
|
|
|
if (port == GPIOI) { |
|
|
|
__HAL_RCC_GPIOI_CLK_ENABLE(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
#endif
|
|
|
|
#ifdef GPIOJ
|
|
|
|
if (m_gpio == GPIOJ) { |
|
|
|
if (port == GPIOJ) { |
|
|
|
__HAL_RCC_GPIOJ_CLK_ENABLE(); |
|
|
|
return true; |
|
|
|
} |
|
|
|
#endif
|
|
|
|
#ifdef GPIOK
|
|
|
|
if (m_gpio == GPIOK) { |
|
|
|
if (port == GPIOK) { |
|
|
|
__HAL_RCC_GPIOK_CLK_ENABLE(); |
|
|
|
return true; |
|
|
|
} |
|
|
@ -119,6 +119,8 @@ bool ZGPIO::enableClock() { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
bool ZGPIO::enableClock() { enableClock(m_gpio); } |
|
|
|
|
|
|
|
void regIRQGPIO(ZGPIO *gpio) { |
|
|
|
for (int i = 0; i < s_irqGPIO_num; i++) { |
|
|
|
if (s_irqGPIO[i] == gpio) { |
|
|
@ -188,6 +190,45 @@ void ZGPIO::initAsInput(Pin_t pin, GPIOMode_t mode, GPIOIrqType_t irqtype, bool |
|
|
|
m_initflag = true; |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
void ZGPIO::initAsOutputStatic(Pin_t pin, GPIOMode_t mode, bool mirror, bool initLevel) { |
|
|
|
if (pin == PinNull) return; |
|
|
|
|
|
|
|
GPIO_TypeDef *m_gpio = chip_get_gpio(pin); |
|
|
|
uint16_t m_pinoff = chip_get_pinoff(pin); |
|
|
|
|
|
|
|
enableClock(m_gpio); |
|
|
|
|
|
|
|
GPIO_InitTypeDef m_GPIO_InitStruct = {0}; |
|
|
|
initLevel = mirror ? !initLevel : initLevel; |
|
|
|
GPIO_PinState pinState = initLevel ? GPIO_PIN_SET : GPIO_PIN_RESET; |
|
|
|
|
|
|
|
HAL_GPIO_WritePin(m_gpio, m_pinoff, pinState); |
|
|
|
if (mode == kMode_nopull) { |
|
|
|
m_GPIO_InitStruct.Pin = m_pinoff; |
|
|
|
m_GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
|
|
|
m_GPIO_InitStruct.Pull = GPIO_NOPULL; |
|
|
|
m_GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
|
|
|
} else if (mode == kMode_pullup) { |
|
|
|
m_GPIO_InitStruct.Pin = m_pinoff; |
|
|
|
m_GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
|
|
|
m_GPIO_InitStruct.Pull = GPIO_PULLUP; |
|
|
|
m_GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
|
|
|
} else if (mode == kMode_pulldown) { |
|
|
|
m_GPIO_InitStruct.Pin = m_pinoff; |
|
|
|
m_GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP; |
|
|
|
m_GPIO_InitStruct.Pull = GPIO_PULLDOWN; |
|
|
|
m_GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
|
|
|
} else if (mode == kMode_od) { |
|
|
|
m_GPIO_InitStruct.Pin = m_pinoff; |
|
|
|
m_GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD; |
|
|
|
m_GPIO_InitStruct.Pull = 0; |
|
|
|
m_GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; |
|
|
|
} |
|
|
|
HAL_GPIO_Init(m_gpio, &m_GPIO_InitStruct); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
void ZGPIO::initAsOutput(Pin_t pin, GPIOMode_t mode, bool mirror, bool initLevel) { |
|
|
|
if (pin == PinNull) return; |
|
|
|
|
|
|
@ -195,9 +236,9 @@ void ZGPIO::initAsOutput(Pin_t pin, GPIOMode_t mode, bool mirror, bool initLevel |
|
|
|
m_mode = mode; |
|
|
|
m_irqtype = kIRQ_noIrq; |
|
|
|
m_gpiotype = kType_Output; |
|
|
|
m_pin = pin; |
|
|
|
m_gpio = chip_get_gpio(pin); |
|
|
|
m_pinoff = chip_get_pinoff(pin); |
|
|
|
m_pin = pin; |
|
|
|
m_gpio = chip_get_gpio(pin); |
|
|
|
m_pinoff = chip_get_pinoff(pin); |
|
|
|
|
|
|
|
enableClock(); |
|
|
|
|
|
|
|