Skip to content

Instantly share code, notes, and snippets.

@notro
Created December 23, 2018 16:00
Show Gist options
  • Save notro/2558d4fe1b0699e175c7dc33b9a74d22 to your computer and use it in GitHub Desktop.
Save notro/2558d4fe1b0699e175c7dc33b9a74d22 to your computer and use it in GitHub Desktop.
diff --git a/samd/external_interrupts.c b/samd/external_interrupts.c
index 384ff99..42e315d 100644
--- a/samd/external_interrupts.c
+++ b/samd/external_interrupts.c
@@ -36,6 +36,7 @@
// has one user.
static void *channel_data[EIC_EXTINT_NUM];
static uint8_t channel_handler[EIC_EXTINT_NUM];
+static channel_handler_t *channel_handler_func[EIC_EXTINT_NUM];
void external_interrupt_handler(uint8_t channel) {
uint8_t handler = channel_handler[channel];
@@ -43,6 +44,11 @@ void external_interrupt_handler(uint8_t channel) {
pulsein_interrupt_handler(channel);
} else if (handler == EIC_HANDLER_INCREMENTAL_ENCODER) {
incrementalencoder_interrupt_handler(channel);
+ } else if (handler == EIC_HANDLER_FUNC) {
+ channel_handler_t *func = channel_handler_func[channel];
+ if (func != NULL) {
+ func(channel);
+ }
}
EIC->INTFLAG.reg = (1 << channel) << EIC_INTFLAG_EXTINT_Pos;
}
@@ -96,6 +102,10 @@ void turn_off_eic_channel(uint8_t eic_channel) {
}
}
+void set_eic_channel_handler(uint8_t eic_channel, channel_handler_t *handler) {
+ channel_handler_func[eic_channel] = handler;
+}
+
void* get_eic_channel_data(uint8_t eic_channel) {
return channel_data[eic_channel];
}
diff --git a/samd/external_interrupts.h b/samd/external_interrupts.h
index 12d8206..86eb0a4 100644
--- a/samd/external_interrupts.h
+++ b/samd/external_interrupts.h
@@ -33,6 +33,9 @@
#define EIC_HANDLER_NO_INTERRUPT 0x0
#define EIC_HANDLER_PULSEIN 0x1
#define EIC_HANDLER_INCREMENTAL_ENCODER 0x2
+#define EIC_HANDLER_FUNC 0x3
+
+typedef void channel_handler_t(uint8_t);
void turn_on_external_interrupt_controller(void);
void turn_off_external_interrupt_controller(void);
@@ -46,6 +49,8 @@ bool eic_get_enable(void);
void eic_set_enable(bool value);
void eic_reset(void);
+void set_eic_channel_handler(uint8_t eic_channel, channel_handler_t *handler);
+
void* get_eic_channel_data(uint8_t eic_channel);
void set_eic_channel_data(uint8_t eic_channel, void* data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment