mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-13 19:40:31 +03:00
More cleanup of MPU driver code. Support MPU INT on CC3D and Naze32
Rev6.
This commit is contained in:
parent
026afb22c7
commit
9b054f6fde
20 changed files with 210 additions and 211 deletions
|
@ -31,45 +31,61 @@
|
|||
|
||||
#include "system.h"
|
||||
|
||||
|
||||
#ifndef EXTI15_10_CALLBACK_HANDLER_COUNT
|
||||
#define EXTI15_10_CALLBACK_HANDLER_COUNT 1
|
||||
#ifndef EXTI_CALLBACK_HANDLER_COUNT
|
||||
#define EXTI_CALLBACK_HANDLER_COUNT 1
|
||||
#endif
|
||||
|
||||
static extiCallbackHandler* exti15_10_handlers[EXTI15_10_CALLBACK_HANDLER_COUNT];
|
||||
typedef struct extiCallbackHandlerConfig_s {
|
||||
IRQn_Type irqn;
|
||||
extiCallbackHandlerFunc* fn;
|
||||
} extiCallbackHandlerConfig_t;
|
||||
|
||||
void registerExti15_10_CallbackHandler(extiCallbackHandler *fn)
|
||||
static extiCallbackHandlerConfig_t extiHandlerConfigs[EXTI_CALLBACK_HANDLER_COUNT];
|
||||
|
||||
void registerExtiCallbackHandler(IRQn_Type irqn, extiCallbackHandlerFunc *fn)
|
||||
{
|
||||
for (int index = 0; index < EXTI15_10_CALLBACK_HANDLER_COUNT; index++) {
|
||||
extiCallbackHandler *candidate = exti15_10_handlers[index];
|
||||
if (!candidate) {
|
||||
exti15_10_handlers[index] = fn;
|
||||
for (int index = 0; index < EXTI_CALLBACK_HANDLER_COUNT; index++) {
|
||||
extiCallbackHandlerConfig_t *candidate = &extiHandlerConfigs[index];
|
||||
if (!candidate->fn) {
|
||||
candidate->fn = fn;
|
||||
candidate->irqn = irqn;
|
||||
return;
|
||||
}
|
||||
}
|
||||
failureMode(FAILURE_DEVELOPER); // EXTI15_10_CALLBACK_HANDLER_COUNT is too low for the amount of handlers required.
|
||||
failureMode(FAILURE_DEVELOPER); // EXTI_CALLBACK_HANDLER_COUNT is too low for the amount of handlers required.
|
||||
}
|
||||
|
||||
void unregisterExti15_10_CallbackHandler(extiCallbackHandler *fn)
|
||||
void unregisterExtiCallbackHandler(IRQn_Type irqn, extiCallbackHandlerFunc *fn)
|
||||
{
|
||||
for (int index = 0; index < EXTI15_10_CALLBACK_HANDLER_COUNT; index++) {
|
||||
extiCallbackHandler *candidate = exti15_10_handlers[index];
|
||||
if (candidate == fn) {
|
||||
exti15_10_handlers[index] = 0;
|
||||
for (int index = 0; index < EXTI_CALLBACK_HANDLER_COUNT; index++) {
|
||||
extiCallbackHandlerConfig_t *candidate = &extiHandlerConfigs[index];
|
||||
if (candidate->fn == fn && candidate->irqn == irqn) {
|
||||
candidate->fn = NULL;
|
||||
candidate->irqn = 0;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void extiHandler(IRQn_Type irqn)
|
||||
{
|
||||
for (int index = 0; index < EXTI_CALLBACK_HANDLER_COUNT; index++) {
|
||||
extiCallbackHandlerConfig_t *candidate = &extiHandlerConfigs[index];
|
||||
if (candidate->fn && candidate->irqn == irqn) {
|
||||
candidate->fn();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void EXTI15_10_IRQHandler(void)
|
||||
{
|
||||
for (int index = 0; index < EXTI15_10_CALLBACK_HANDLER_COUNT; index++) {
|
||||
extiCallbackHandler *fn = exti15_10_handlers[index];
|
||||
if (!fn) {
|
||||
continue;
|
||||
}
|
||||
fn();
|
||||
}
|
||||
extiHandler(EXTI15_10_IRQn);
|
||||
}
|
||||
|
||||
void EXTI3_IRQHandler(void)
|
||||
{
|
||||
extiHandler(EXTI3_IRQn);
|
||||
}
|
||||
|
||||
// cycles per microsecond
|
||||
|
@ -149,7 +165,7 @@ void systemInit(void)
|
|||
cycleCounterInit();
|
||||
|
||||
|
||||
memset(&exti15_10_handlers, 0x00, sizeof(exti15_10_handlers));
|
||||
memset(extiHandlerConfigs, 0x00, sizeof(extiHandlerConfigs));
|
||||
// SysTick
|
||||
SysTick_Config(SystemCoreClock / 1000);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue