1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-13 19:40:31 +03:00

Initial exti support, untested

This commit is contained in:
Steve Evans 2025-06-29 20:06:43 +01:00
parent c593629fca
commit 7ac7db556c
2 changed files with 59 additions and 10 deletions

View file

@ -19,22 +19,67 @@
* If not, see <http://www.gnu.org/licenses/>. * If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <string.h>
#include "drivers/exti.h" #include "drivers/exti.h"
#include "common/utils.h" #include "common/utils.h"
#include "drivers/io_impl.h"
#include "hardware/gpio.h"
typedef struct {
extiCallbackRec_t* handler;
} extiChannelRec_t;
static extiChannelRec_t extiChannelRecs[DEFIO_USED_COUNT];
static uint32_t extiEventMask[DEFIO_USED_COUNT];
void EXTIConfig(IO_t io, extiCallbackRec_t *cb, int irqPriority, ioConfig_t config, extiTrigger_t trigger) void EXTIConfig(IO_t io, extiCallbackRec_t *cb, int irqPriority, ioConfig_t config, extiTrigger_t trigger)
{ {
UNUSED(io); uint32_t gpio = IO_Pin(io);
UNUSED(cb);
UNUSED(irqPriority); UNUSED(irqPriority); // Just stick with default GPIO irq priority for now
UNUSED(config); UNUSED(config); // TODO consider pullup/pulldown etc. Needs fixing first in platform.h
UNUSED(trigger);
// Ensure the GPIO is initialised and not being used for some other function
gpio_init(gpio);
extiChannelRec_t *rec = &extiChannelRecs[gpio];
rec->handler = cb;
switch(trigger) {
case BETAFLIGHT_EXTI_TRIGGER_RISING:
default:
extiEventMask[gpio] = GPIO_IRQ_EDGE_RISE;
break;
case BETAFLIGHT_EXTI_TRIGGER_FALLING:
extiEventMask[gpio] = GPIO_IRQ_EDGE_FALL;
break;
case BETAFLIGHT_EXTI_TRIGGER_BOTH:
extiEventMask[gpio] = GPIO_IRQ_EDGE_RISE | GPIO_IRQ_EDGE_FALL;
break;
}
}
static void EXTI_IRQHandler(uint gpio, uint32_t event_mask)
{
// Call the registered handler for this GPIO
if (extiChannelRecs[gpio].handler) {
extiChannelRecs[gpio].handler->fn(extiChannelRecs[gpio].handler);
}
// Acknowledge the interrupt
gpio_acknowledge_irq(gpio, event_mask);
} }
void EXTIInit(void) void EXTIInit(void)
{ {
//TODO: implement // Clear all the callbacks
// NOOP memset(extiChannelRecs, 0, sizeof(extiChannelRecs));
// Register the shared handler for GPIO interrupts
gpio_set_irq_callback(EXTI_IRQHandler);
} }
void EXTIHandlerInit(extiCallbackRec_t *self, extiHandlerCallback *fn) void EXTIHandlerInit(extiCallbackRec_t *self, extiHandlerCallback *fn)
@ -44,6 +89,10 @@ void EXTIHandlerInit(extiCallbackRec_t *self, extiHandlerCallback *fn)
void EXTIEnable(IO_t io) void EXTIEnable(IO_t io)
{ {
//TODO: implement gpio_set_irq_enabled(IO_Pin(io), 0, true);
UNUSED(io); }
void EXTIDisable(IO_t io)
{
gpio_set_irq_enabled(IO_Pin(io), extiEventMask[IO_Pin(io)], false);
} }

View file

@ -45,7 +45,7 @@
#define USBD_PRODUCT_STRING "Betaflight RP2350B" #define USBD_PRODUCT_STRING "Betaflight RP2350B"
#endif #endif
#define USE_MULTICORE //#define USE_MULTICORE
#define USE_IO #define USE_IO
#define USE_UART0 #define USE_UART0
#define USE_UART1 #define USE_UART1