|
|
|
@@ -17,6 +17,7 @@ typedef struct {
|
|
|
|
|
void *param; //!< Parameter for the callback
|
|
|
|
|
}exti_cb_list_t;
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
//! \brief Contains call back data for all 16 exti lines.
|
|
|
|
|
static struct {
|
|
|
|
|
exti_cb_list_t callback_list[16]; //!< Call back data list for the exti lines.
|
|
|
|
@@ -45,83 +46,34 @@ static uint8_t gpio_bin2dec(uint16_t bin)
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void gpio_init(const struct stm32f4_gpio *gpio)
|
|
|
|
|
{
|
|
|
|
|
uint8_t m_port = 0;
|
|
|
|
|
uint8_t m_pin = 0;
|
|
|
|
|
uint32_t clock = 0;
|
|
|
|
|
if(gpio == NULL)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if(gpio->port == GPIOA) {
|
|
|
|
|
clock = RCC_AHB1Periph_GPIOA;
|
|
|
|
|
m_port = EXTI_PortSourceGPIOA;
|
|
|
|
|
}
|
|
|
|
|
else if(gpio->port == GPIOB) {
|
|
|
|
|
clock = RCC_AHB1Periph_GPIOB;
|
|
|
|
|
m_port = EXTI_PortSourceGPIOB;
|
|
|
|
|
}
|
|
|
|
|
else if(gpio->port == GPIOC) {
|
|
|
|
|
clock = RCC_AHB1Periph_GPIOC;
|
|
|
|
|
m_port = EXTI_PortSourceGPIOC;
|
|
|
|
|
}
|
|
|
|
|
else if(gpio->port == GPIOD) {
|
|
|
|
|
clock = RCC_AHB1Periph_GPIOD;
|
|
|
|
|
m_port = EXTI_PortSourceGPIOD;
|
|
|
|
|
}
|
|
|
|
|
else if(gpio->port == GPIOE) {
|
|
|
|
|
clock = RCC_AHB1Periph_GPIOE;
|
|
|
|
|
m_port = EXTI_PortSourceGPIOE;
|
|
|
|
|
}
|
|
|
|
|
else if(gpio->port == GPIOF) {
|
|
|
|
|
clock = RCC_AHB1Periph_GPIOF;
|
|
|
|
|
m_port = EXTI_PortSourceGPIOF;
|
|
|
|
|
}
|
|
|
|
|
else if(gpio->port == GPIOG) {
|
|
|
|
|
clock = RCC_AHB1Periph_GPIOG;
|
|
|
|
|
m_port = EXTI_PortSourceGPIOG;
|
|
|
|
|
}
|
|
|
|
|
else if(gpio->port == GPIOH) {
|
|
|
|
|
clock = RCC_AHB1Periph_GPIOH;
|
|
|
|
|
m_port = EXTI_PortSourceGPIOH;
|
|
|
|
|
}
|
|
|
|
|
else if(gpio->port == GPIOI) {
|
|
|
|
|
clock = RCC_AHB1Periph_GPIOI;
|
|
|
|
|
m_port = EXTI_PortSourceGPIOI;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RCC_AHB1PeriphClockCmd(clock, ENABLE);
|
|
|
|
|
m_pin = gpio_bin2dec(gpio->pin->GPIO_Pin);
|
|
|
|
|
|
|
|
|
|
SYSCFG_EXTILineConfig(m_port, m_pin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
int stm32f4_gpio_open(const void *gpio)
|
|
|
|
|
{
|
|
|
|
|
struct stm32f4_gpio *this;
|
|
|
|
|
uint8_t m_pin = 0;
|
|
|
|
|
|
|
|
|
|
if(gpio == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
|
|
this = (struct stm32f4_gpio *)gpio;
|
|
|
|
|
gpio_init(this);
|
|
|
|
|
m_pin = gpio_bin2dec(this->pin->GPIO_Pin);
|
|
|
|
|
|
|
|
|
|
GPIO_Init(this->port, (GPIO_InitTypeDef*)this->pin);
|
|
|
|
|
|
|
|
|
|
if(this->ext_it_cb != NULL) {
|
|
|
|
|
gpio_obj.callback_list[m_pin].callback = this->ext_it_cb;
|
|
|
|
|
gpio_obj.callback_list[m_pin].param = this->param;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if((this->exti != NULL) && (this->nvic != NULL)) {
|
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
|
|
|
|
|
EXTI_Init((EXTI_InitTypeDef*)this->exti);
|
|
|
|
|
NVIC_Init((NVIC_InitTypeDef*)this->nvic);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(this->port == GPIOA)
|
|
|
|
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
|
|
|
else if(this->port == GPIOB)
|
|
|
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
|
|
|
else if(this->port == GPIOC)
|
|
|
|
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
|
|
|
else if(this->port == GPIOD)
|
|
|
|
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
|
|
|
else if(this->port == GPIOE)
|
|
|
|
|
__HAL_RCC_GPIOE_CLK_ENABLE();
|
|
|
|
|
else if(this->port == GPIOF)
|
|
|
|
|
__HAL_RCC_GPIOF_CLK_ENABLE();
|
|
|
|
|
else if(this->port == GPIOG)
|
|
|
|
|
__HAL_RCC_GPIOG_CLK_ENABLE();
|
|
|
|
|
else if(this->port == GPIOH)
|
|
|
|
|
__HAL_RCC_GPIOH_CLK_ENABLE();
|
|
|
|
|
else if(this->port == GPIOI)
|
|
|
|
|
__HAL_RCC_GPIOI_CLK_ENABLE();
|
|
|
|
|
HAL_GPIO_Init(this->port, (GPIO_InitTypeDef*)this->pin);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -129,7 +81,8 @@ int stm32f4_gpio_close(const void *gpio)
|
|
|
|
|
{
|
|
|
|
|
if(gpio == NULL)
|
|
|
|
|
return -1;
|
|
|
|
|
// TODO: deinit exti, nvic & gpio
|
|
|
|
|
struct stm32f4_gpio *this = (struct stm32f4_gpio *)gpio;
|
|
|
|
|
HAL_GPIO_DeInit(this->port, this->pin->Pin);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -140,7 +93,7 @@ char stm32f4_gpio_read(const void *gpio)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
this = (struct stm32f4_gpio *)gpio;
|
|
|
|
|
return GPIO_ReadOutputDataBit(this->port, this->pin->GPIO_Pin);
|
|
|
|
|
return HAL_GPIO_ReadPin(this->port, this->pin->Pin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void stm32f4_gpio_write(const void *gpio, char byte) {
|
|
|
|
@@ -149,7 +102,7 @@ void stm32f4_gpio_write(const void *gpio, char byte) {
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
this = (struct stm32f4_gpio *)gpio;
|
|
|
|
|
GPIO_WriteBit(this->port, this->pin->GPIO_Pin, (BitAction)byte);
|
|
|
|
|
HAL_GPIO_WritePin(this->port, this->pin->Pin, (GPIO_PinState)(byte & 0x01));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void stm32f4_gpio_toggle(const void *gpio)
|
|
|
|
@@ -159,16 +112,13 @@ void stm32f4_gpio_toggle(const void *gpio)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
this = (struct stm32f4_gpio *)gpio;
|
|
|
|
|
BitAction act = Bit_SET;
|
|
|
|
|
if(GPIO_ReadOutputDataBit(this->port, this->pin->GPIO_Pin))
|
|
|
|
|
act = Bit_RESET;
|
|
|
|
|
|
|
|
|
|
GPIO_WriteBit(this->port, this->pin->GPIO_Pin, act);
|
|
|
|
|
HAL_GPIO_TogglePin(this->port, this->pin->Pin);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int stm32f4_gpio_set_exti_callback(const void *gpio,
|
|
|
|
|
const void *callback, const void *param)
|
|
|
|
|
{
|
|
|
|
|
#if 0
|
|
|
|
|
struct stm32f4_gpio *this;
|
|
|
|
|
uint8_t pin;
|
|
|
|
|
if((gpio == NULL) || (callback == NULL))
|
|
|
|
@@ -179,10 +129,11 @@ int stm32f4_gpio_set_exti_callback(const void *gpio,
|
|
|
|
|
|
|
|
|
|
gpio_obj.callback_list[pin].callback = (gpio_ext_it_cb_t)callback;
|
|
|
|
|
gpio_obj.callback_list[pin].param = (void*)param;
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
|
//! \brief The ISR for the EXTI0_IRQn interrupt.
|
|
|
|
|
void EXTI0_IRQHandler(void)
|
|
|
|
|
{
|
|
|
|
@@ -258,3 +209,4 @@ void EXTI9_5_IRQHandler(void) {
|
|
|
|
|
void EXTI15_10_IRQHandler(void) {
|
|
|
|
|
// TODO: detect & clear pending bit
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|