Commit 5a400abf authored by Sandeep Mistry's avatar Sandeep Mistry

Functional attachInterrupt/deattachInterrupt for change, falling, rising

parent b8aa8a73
...@@ -16,36 +16,28 @@ ...@@ -16,36 +16,28 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/ */
#include <nrf_gpiote.h>
#include "Arduino.h" #include "Arduino.h"
#include "wiring_private.h" #include "wiring_private.h"
#include <string.h> #include <string.h>
// static voidFuncPtr callbacksInt[EXTERNAL_NUM_INTERRUPTS]; static voidFuncPtr callbacksInt[NUMBER_OF_GPIO_TE];
static int8_t channelMap[NUMBER_OF_GPIO_TE];
// /* Configure I/O interrupt sources */ static int enabled = 0;
// static void __initialize()
// {
// memset(callbacksInt, 0, sizeof(callbacksInt));
// NVIC_DisableIRQ(EIC_IRQn);
// NVIC_ClearPendingIRQ(EIC_IRQn);
// NVIC_SetPriority(EIC_IRQn, 0);
// NVIC_EnableIRQ(EIC_IRQn);
// // Enable GCLK for IEC (External Interrupt Controller) /* Configure I/O interrupt sources */
// GCLK->CLKCTRL.reg = (uint16_t) (GCLK_CLKCTRL_CLKEN | GCLK_CLKCTRL_GEN_GCLK0 | GCLK_CLKCTRL_ID(GCM_EIC)); static void __initialize()
{
// /* Shall we do that? memset(callbacksInt, 0, sizeof(callbacksInt));
// // Do a software reset on EIC memset(channelMap, -1, sizeof(channelMap));
// EIC->CTRL.SWRST.bit = 1 ;
// while ((EIC->CTRL.SWRST.bit == 1) && (EIC->STATUS.SYNCBUSY.bit == 1)) { }
// */
// // Enable EIC NVIC_DisableIRQ(GPIOTE_IRQn);
// EIC->CTRL.bit.ENABLE = 1; NVIC_ClearPendingIRQ(GPIOTE_IRQn);
// while (EIC->STATUS.bit.SYNCBUSY == 1) { } NVIC_SetPriority(GPIOTE_IRQn, 1);
// } NVIC_EnableIRQ(GPIOTE_IRQn);
}
/* /*
* \brief Specifies a named Interrupt Service Routine (ISR) to call when an interrupt occurs. * \brief Specifies a named Interrupt Service Routine (ISR) to call when an interrupt occurs.
...@@ -53,62 +45,42 @@ ...@@ -53,62 +45,42 @@
*/ */
void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode) void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
{ {
// static int enabled = 0; if (!enabled) {
// uint32_t config; __initialize();
// uint32_t pos; enabled = 1;
}
// EExt_Interrupts in = digitalPinToInterrupt(pin);
// if (in == NOT_AN_INTERRUPT || in == EXTERNAL_INT_NMI) nrf_gpiote_polarity_t polarity;
// return;
switch (mode) {
// if (!enabled) { case CHANGE:
// __initialize(); polarity = NRF_GPIOTE_POLARITY_TOGGLE;
// enabled = 1; break;
// }
case FALLING:
// // Enable wakeup capability on pin in case being used during sleep polarity = NRF_GPIOTE_POLARITY_HITOLO;
// EIC->WAKEUP.reg |= (1 << in); break;
// // Assign pin to EIC case RISING:
// pinPeripheral(pin, PIO_EXTINT); polarity = NRF_GPIOTE_POLARITY_LOTOHI;
break;
// // Assign callback to interrupt
// callbacksInt[in] = callback; default:
return;
// // Look for right CONFIG register to be addressed }
// if (in > EXTERNAL_INT_7) {
// config = 1; for (int ch = 0; ch < NUMBER_OF_GPIO_TE; ch++) {
// } else { if (channelMap[ch] == -1 || (uint32_t)channelMap[ch] == pin) {
// config = 0; channelMap[ch] = pin;
// } callbacksInt[ch] = callback;
// // Configure the interrupt mode nrf_gpiote_event_configure(ch, pin, polarity);
// pos = (in - (8 * config)) << 2; nrf_gpiote_event_enable(ch);
// switch (mode) nrf_gpiote_int_enable(1 << ch);
// {
// case LOW: break;
// EIC->CONFIG[config].reg |= EIC_CONFIG_SENSE0_LOW_Val << pos; }
// break; }
// case HIGH:
// EIC->CONFIG[config].reg |= EIC_CONFIG_SENSE0_HIGH_Val << pos;
// break;
// case CHANGE:
// EIC->CONFIG[config].reg |= EIC_CONFIG_SENSE0_BOTH_Val << pos;
// break;
// case FALLING:
// EIC->CONFIG[config].reg |= EIC_CONFIG_SENSE0_FALL_Val << pos;
// break;
// case RISING:
// EIC->CONFIG[config].reg |= EIC_CONFIG_SENSE0_RISE_Val << pos;
// break;
// }
// // Enable the interrupt
// EIC->INTENSET.reg = EIC_INTENSET_EXTINT(1 << in);
} }
/* /*
...@@ -116,33 +88,32 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode) ...@@ -116,33 +88,32 @@ void attachInterrupt(uint32_t pin, voidFuncPtr callback, uint32_t mode)
*/ */
void detachInterrupt(uint32_t pin) void detachInterrupt(uint32_t pin)
{ {
// EExt_Interrupts in = digitalPinToInterrupt(pin); for (int ch = 0; ch < NUMBER_OF_GPIO_TE; ch++) {
// if (in == NOT_AN_INTERRUPT || in == EXTERNAL_INT_NMI) if ((uint32_t)channelMap[ch] == pin) {
// return; channelMap[ch] = -1;
callbacksInt[ch] = NULL;
// EIC->INTENCLR.reg = EIC_INTENCLR_EXTINT(1 << in); nrf_gpiote_event_disable(ch);
nrf_gpiote_int_disable(1 << ch);
// // Disable wakeup capability on pin during sleep break;
// EIC->WAKEUP.reg &= ~(1 << in); }
}
} }
// /* void GPIOTE_IRQHandler()
// * External Interrupt Controller NVIC Interrupt Handler {
// */ nrf_gpiote_events_t event = NRF_GPIOTE_EVENTS_IN_0;
// void EIC_Handler(void)
// { for (int ch = 0; ch < NUMBER_OF_GPIO_TE; ch++) {
// // Test the 16 normal interrupts if (nrf_gpiote_event_is_set(event) && nrf_gpiote_int_is_enabled(1 << ch)) {
// for (uint32_t i=EXTERNAL_INT_0; i<=EXTERNAL_INT_15; i++) if (channelMap[ch] != -1 && callbacksInt[ch]) {
// { callbacksInt[ch]();
// if ((EIC->INTFLAG.reg & (1 << i)) != 0) }
// {
// // Call the callback function if assigned nrf_gpiote_event_clear(event);
// if (callbacksInt[i]) { }
// callbacksInt[i]();
// } event = (nrf_gpiote_events_t)((uint32_t)event + 4);
}
// // Clear the interrupt }
// EIC->INTFLAG.reg = 1 << i;
// }
// }
// }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment