pkarashchenko commented on code in PR #6413: URL: https://github.com/apache/incubator-nuttx/pull/6413#discussion_r895217928
########## arch/arm/src/stm32wl5/hardware/stm32wl5_exti.h: ########## @@ -103,4 +108,84 @@ #define EXTI2_RADIOBSY (1 << 14) /* EXTI line 45: Radio busy wakeup */ #define EXTI2_CDBGPWRUPREQ (1 << 15) /* EXTI line 46: Debug power-up request wakup */ +/* Rising Trigger selection register */ + +#define EXTI_RTSR1_BIT(n) (1 << n) /* 1=Rising trigger enabled (for Event and Interrupt) for input line */ Review Comment: ```suggestion #define EXTI_RTSR1_BIT(n) (1 << (n)) /* 1=Rising trigger enabled (for Event and Interrupt) for input line */ ``` here and similar palces ########## arch/arm/src/stm32wl5/stm32wl5_exti_gpio.c: ########## @@ -62,35 +61,168 @@ static struct gpio_callback_s g_gpio_handlers[16]; ****************************************************************************/ /**************************************************************************** - * Interrupt Service Routine - Dispatcher + * Interrupt Service Routines - Dispatchers ****************************************************************************/ -static int stm32wl5_exti0_15_isr(int irq, void *context, FAR void *arg) +static int stm32wl5_exti0_isr(int irq, void *context, void *arg) { int ret = OK; - int exti; - (void)arg; - exti = irq - STM32WL5_IRQ_EXTI0; - DEBUGASSERT((exti >= 0) && (exti <= 15)); + /* Clear the pending interrupt */ - /* Clear the pending interrupt for both rising and falling edges. */ + putreg32(0x0001, STM32WL5_EXTI_PR1); - putreg32(0x0001 << exti, STM32WL5_EXTI_PR1); + /* And dispatch the interrupt to the handler */ + + if (g_gpio_handlers[0].callback != NULL) + { + xcpt_t callback = g_gpio_handlers[0].callback; + void *cbarg = g_gpio_handlers[0].arg; + + ret = callback(irq, context, cbarg); + } + + return ret; +} + +static int stm32wl5_exti1_isr(int irq, void *context, void *arg) +{ + int ret = OK; + + /* Clear the pending interrupt */ + + putreg32(0x0002, STM32WL5_EXTI_PR1); /* And dispatch the interrupt to the handler */ - if (g_gpio_handlers[exti].callback != NULL) + if (g_gpio_handlers[1].callback != NULL) { - xcpt_t callback = g_gpio_handlers[exti].callback; - void *cbarg = g_gpio_handlers[exti].arg; + xcpt_t callback = g_gpio_handlers[1].callback; + void *cbarg = g_gpio_handlers[1].arg; ret = callback(irq, context, cbarg); } return ret; } +static int stm32wl5_exti2_isr(int irq, void *context, void *arg) +{ + int ret = OK; + + /* Clear the pending interrupt */ + + putreg32(0x0004, STM32WL5_EXTI_PR1); + + /* And dispatch the interrupt to the handler */ + + if (g_gpio_handlers[2].callback != NULL) + { + xcpt_t callback = g_gpio_handlers[2].callback; + void *cbarg = g_gpio_handlers[2].arg; + + ret = callback(irq, context, cbarg); + } + + return ret; +} + +static int stm32wl5_exti3_isr(int irq, void *context, void *arg) +{ + int ret = OK; + + /* Clear the pending interrupt */ + + putreg32(0x0008, STM32WL5_EXTI_PR1); + + /* And dispatch the interrupt to the handler */ + + if (g_gpio_handlers[3].callback != NULL) + { + xcpt_t callback = g_gpio_handlers[3].callback; + void *cbarg = g_gpio_handlers[3].arg; + + ret = callback(irq, context, cbarg); + } + + return ret; +} + +static int stm32wl5_exti4_isr(int irq, void *context, void *arg) +{ + int ret = OK; + + /* Clear the pending interrupt */ + + putreg32(0x0010, STM32WL5_EXTI_PR1); + + /* And dispatch the interrupt to the handler */ + + if (g_gpio_handlers[4].callback != NULL) + { + xcpt_t callback = g_gpio_handlers[4].callback; + void *cbarg = g_gpio_handlers[4].arg; + + ret = callback(irq, context, cbarg); + } + + return ret; +} + +static int stm32wl5_exti_multiisr(int irq, void *context, void *arg, + int first, int last) +{ + uint32_t pr; + int pin; + int ret = OK; + + /* Examine the state of each pin in the group */ + + pr = getreg32(STM32WL5_EXTI_PR1); + + /* And dispatch the interrupt to the handler */ + + for (pin = first; pin <= last; pin++) + { + /* Is an interrupt pending on this pin? */ + + uint32_t mask = (1 << pin); Review Comment: minor ```suggestion uint32_t mask = 1 << pin; ``` ########## boards/arm/stm32wl5/nucleo-wl55jc/src/stm32_buttons.c: ########## @@ -0,0 +1,150 @@ +/**************************************************************************** + * boards/arm/stm32wl5/nucleo-wl55jc/src/stm32_buttons.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> +#include <errno.h> + +#include <nuttx/arch.h> +#include <nuttx/board.h> +#include <arch/board/board.h> + +#include "nucleo-wl55jc.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_button_initialize + * + * Description: + * board_button_initialize() must be called to initialize button resources. + * After that, board_buttons() may be called to collect the current state + * of all buttons or board_button_irq() may be called to register button + * interrupt handlers. + * + ****************************************************************************/ + +uint32_t board_button_initialize(void) +{ + /* Configure the single button as an input. NOTE that EXTI interrupts are + * also configured for the pin. + */ + + stm32wl5_configgpio(GPIO_BUTTON1); + stm32wl5_configgpio(GPIO_BUTTON2); +#ifndef CONFIG_ARCH_BOARD_NUCLEO_WL55JC_DEMO_LED_IRQ + stm32wl5_configgpio(GPIO_BUTTON3); + return 3; /* number of buttons */ +#else + return 2; /* number of buttons */ +#endif +} + +/**************************************************************************** + * Name: board_buttons + ****************************************************************************/ + +uint32_t board_buttons(void) +{ + uint32_t state; + + /* Check that state of each USER button. + * A LOW value means that the key is pressed. + */ + + state = 0; + + if (stm32wl5_gpioread(GPIO_BUTTON1) == 0) + { + state |= 1 << 0; Review Comment: ```suggestion state |= BUTTON1_BIT; ``` ########## boards/arm/stm32wl5/nucleo-wl55jc/src/stm32_buttons.c: ########## @@ -0,0 +1,150 @@ +/**************************************************************************** + * boards/arm/stm32wl5/nucleo-wl55jc/src/stm32_buttons.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> +#include <errno.h> + +#include <nuttx/arch.h> +#include <nuttx/board.h> +#include <arch/board/board.h> + +#include "nucleo-wl55jc.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_button_initialize + * + * Description: + * board_button_initialize() must be called to initialize button resources. + * After that, board_buttons() may be called to collect the current state + * of all buttons or board_button_irq() may be called to register button + * interrupt handlers. + * + ****************************************************************************/ + +uint32_t board_button_initialize(void) +{ + /* Configure the single button as an input. NOTE that EXTI interrupts are + * also configured for the pin. + */ + + stm32wl5_configgpio(GPIO_BUTTON1); + stm32wl5_configgpio(GPIO_BUTTON2); +#ifndef CONFIG_ARCH_BOARD_NUCLEO_WL55JC_DEMO_LED_IRQ + stm32wl5_configgpio(GPIO_BUTTON3); + return 3; /* number of buttons */ +#else + return 2; /* number of buttons */ +#endif +} + +/**************************************************************************** + * Name: board_buttons + ****************************************************************************/ + +uint32_t board_buttons(void) +{ + uint32_t state; + + /* Check that state of each USER button. + * A LOW value means that the key is pressed. + */ + + state = 0; + + if (stm32wl5_gpioread(GPIO_BUTTON1) == 0) + { + state |= 1 << 0; + } + + if (stm32wl5_gpioread(GPIO_BUTTON2) == 0) + { + state |= 1 << 1; Review Comment: ```suggestion state |= BUTTON2_BIT; ``` ########## boards/arm/stm32wl5/nucleo-wl55jc/src/stm32_buttons.c: ########## @@ -0,0 +1,150 @@ +/**************************************************************************** + * boards/arm/stm32wl5/nucleo-wl55jc/src/stm32_buttons.c + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> +#include <errno.h> + +#include <nuttx/arch.h> +#include <nuttx/board.h> +#include <arch/board/board.h> + +#include "nucleo-wl55jc.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: board_button_initialize + * + * Description: + * board_button_initialize() must be called to initialize button resources. + * After that, board_buttons() may be called to collect the current state + * of all buttons or board_button_irq() may be called to register button + * interrupt handlers. + * + ****************************************************************************/ + +uint32_t board_button_initialize(void) +{ + /* Configure the single button as an input. NOTE that EXTI interrupts are + * also configured for the pin. + */ + + stm32wl5_configgpio(GPIO_BUTTON1); + stm32wl5_configgpio(GPIO_BUTTON2); +#ifndef CONFIG_ARCH_BOARD_NUCLEO_WL55JC_DEMO_LED_IRQ + stm32wl5_configgpio(GPIO_BUTTON3); + return 3; /* number of buttons */ +#else + return 2; /* number of buttons */ +#endif +} + +/**************************************************************************** + * Name: board_buttons + ****************************************************************************/ + +uint32_t board_buttons(void) +{ + uint32_t state; + + /* Check that state of each USER button. + * A LOW value means that the key is pressed. + */ + + state = 0; + + if (stm32wl5_gpioread(GPIO_BUTTON1) == 0) + { + state |= 1 << 0; + } + + if (stm32wl5_gpioread(GPIO_BUTTON2) == 0) + { + state |= 1 << 1; + } + +#ifndef CONFIG_ARCH_BOARD_NUCLEO_WL55JC_DEMO_LED_IRQ + if (stm32wl5_gpioread(GPIO_BUTTON3) == 0) + { + state |= 1 << 2; Review Comment: ```suggestion state |= BUTTON3_BIT; ``` ########## arch/arm/src/stm32wl5/stm32wl5_exti_gpio.c: ########## @@ -62,35 +61,168 @@ static struct gpio_callback_s g_gpio_handlers[16]; ****************************************************************************/ /**************************************************************************** - * Interrupt Service Routine - Dispatcher + * Interrupt Service Routines - Dispatchers ****************************************************************************/ -static int stm32wl5_exti0_15_isr(int irq, void *context, FAR void *arg) +static int stm32wl5_exti0_isr(int irq, void *context, void *arg) { int ret = OK; - int exti; - (void)arg; - exti = irq - STM32WL5_IRQ_EXTI0; - DEBUGASSERT((exti >= 0) && (exti <= 15)); + /* Clear the pending interrupt */ - /* Clear the pending interrupt for both rising and falling edges. */ + putreg32(0x0001, STM32WL5_EXTI_PR1); - putreg32(0x0001 << exti, STM32WL5_EXTI_PR1); + /* And dispatch the interrupt to the handler */ + + if (g_gpio_handlers[0].callback != NULL) + { + xcpt_t callback = g_gpio_handlers[0].callback; + void *cbarg = g_gpio_handlers[0].arg; + + ret = callback(irq, context, cbarg); + } + + return ret; +} + +static int stm32wl5_exti1_isr(int irq, void *context, void *arg) +{ + int ret = OK; + + /* Clear the pending interrupt */ + + putreg32(0x0002, STM32WL5_EXTI_PR1); /* And dispatch the interrupt to the handler */ - if (g_gpio_handlers[exti].callback != NULL) + if (g_gpio_handlers[1].callback != NULL) { - xcpt_t callback = g_gpio_handlers[exti].callback; - void *cbarg = g_gpio_handlers[exti].arg; + xcpt_t callback = g_gpio_handlers[1].callback; + void *cbarg = g_gpio_handlers[1].arg; ret = callback(irq, context, cbarg); } return ret; } +static int stm32wl5_exti2_isr(int irq, void *context, void *arg) +{ + int ret = OK; + + /* Clear the pending interrupt */ + + putreg32(0x0004, STM32WL5_EXTI_PR1); + + /* And dispatch the interrupt to the handler */ + + if (g_gpio_handlers[2].callback != NULL) + { + xcpt_t callback = g_gpio_handlers[2].callback; + void *cbarg = g_gpio_handlers[2].arg; + + ret = callback(irq, context, cbarg); + } + + return ret; +} + +static int stm32wl5_exti3_isr(int irq, void *context, void *arg) +{ + int ret = OK; + + /* Clear the pending interrupt */ + + putreg32(0x0008, STM32WL5_EXTI_PR1); + + /* And dispatch the interrupt to the handler */ + + if (g_gpio_handlers[3].callback != NULL) + { + xcpt_t callback = g_gpio_handlers[3].callback; + void *cbarg = g_gpio_handlers[3].arg; + + ret = callback(irq, context, cbarg); + } + + return ret; +} + +static int stm32wl5_exti4_isr(int irq, void *context, void *arg) +{ + int ret = OK; + + /* Clear the pending interrupt */ + + putreg32(0x0010, STM32WL5_EXTI_PR1); + + /* And dispatch the interrupt to the handler */ + + if (g_gpio_handlers[4].callback != NULL) + { + xcpt_t callback = g_gpio_handlers[4].callback; + void *cbarg = g_gpio_handlers[4].arg; + + ret = callback(irq, context, cbarg); + } + + return ret; +} + +static int stm32wl5_exti_multiisr(int irq, void *context, void *arg, + int first, int last) +{ + uint32_t pr; + int pin; + int ret = OK; + + /* Examine the state of each pin in the group */ + + pr = getreg32(STM32WL5_EXTI_PR1); + + /* And dispatch the interrupt to the handler */ + + for (pin = first; pin <= last; pin++) + { + /* Is an interrupt pending on this pin? */ + + uint32_t mask = (1 << pin); + if ((pr & mask) != 0) + { + /* Clear the pending interrupt */ + + putreg32(mask, STM32WL5_EXTI_PR1); + + /* And dispatch the interrupt to the handler */ + + if (g_gpio_handlers[pin].callback != NULL) + { + xcpt_t callback = g_gpio_handlers[pin].callback; + void *cbarg = g_gpio_handlers[pin].arg; + int tmp; Review Comment: ```suggestion xcpt_t callback = g_gpio_handlers[pin].callback; void *cbarg = g_gpio_handlers[pin].arg; int tmp; ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org