@ -19,29 +19,20 @@
# ifdef TARGET_LPC1768
# include "../../inc/MarlinConfig.h"
# include <Arduino.h>
# include <pinmapping.h>
//#include "HAL_timers.h"
# include "fastio.h"
# define GNUM 31
typedef void ( * interruptCB ) ( void ) ;
static interruptCB callbacksP0 [ GNUM ] ;
static interruptCB callbacksP2 [ GNUM ] ;
static interruptCB callbacksP0 [ GNUM ] = { } ;
static interruptCB callbacksP2 [ GNUM ] = { } ;
extern " C " void GpioEnableInt ( const uint32_t port , const uint32_t pin , const uint32_t mode ) ;
extern " C " void GpioDisableInt ( const uint32_t port , const uint32_t pin ) ;
//void deadloop(void) {}
/* Configure PIO interrupt sources */
static void __initialize ( ) {
for ( uint8_t i = 0 ; i < GNUM ; i + + ) {
callbacksP0 [ i ] = 0 ;
callbacksP2 [ i ] = 0 ;
}
NVIC_SetPriority ( EINT3_IRQn , NVIC_EncodePriority ( 0 , 1 , 0 ) ) ;
NVIC_EnableIRQ ( EINT3_IRQn ) ;
}
@ -54,6 +45,7 @@ void attachInterrupt(const pin_t pin, void (*callback)(void), uint32_t mode) {
__initialize ( ) ;
+ + enabled ;
}
uint8_t myport = LPC1768_PIN_PORT ( pin ) ,
mypin = LPC1768_PIN_PIN ( pin ) ;
@ -130,18 +122,6 @@ extern "C" void GpioDisableInt(const uint32_t port, const uint32_t pin) {
}
}
constexpr bool isPowerOf2 ( const uint16_t n ) {
return IS_POWER_OF_2 ( n ) ;
}
#if 0
extern " C " void EINT3_IRQHandler ( ) {
LPC_GPIOINT - > IO0IntClr = LPC_GPIOINT - > IO2IntClr = 0xFFFFFFFF ;
TOGGLE ( 13 ) ;
//NVIC_ClearPendingIRQ(EINT3_IRQn);
}
# else
extern " C " void EINT3_IRQHandler ( void ) {
// Read in all current interrupt registers. We do this once as the
// GPIO interrupt registers are on the APB bus, and this is slow.
@ -149,41 +129,34 @@ constexpr bool isPowerOf2(const uint16_t n) {
fall0 = LPC_GPIOINT - > IO0IntStatF ,
rise2 = LPC_GPIOINT - > IO2IntStatR ,
fall2 = LPC_GPIOINT - > IO2IntStatF ;
// Clear the interrupts ASAP
LPC_GPIOINT - > IO0IntClr = LPC_GPIOINT - > IO2IntClr = 0xFFFFFFFF ;
NVIC_ClearPendingIRQ ( EINT3_IRQn ) ;
/* multiple pins changes happened.*/
if ( rise0 ) while ( rise0 > 0 ) { // Continue as long as there are interrupts pending
while ( rise0 > 0 ) { // If multiple pins changes happened continue as long as there are interrupts pending
const uint8_t bitloc = 31 - __CLZ ( rise0 ) ; // CLZ returns number of leading zeros, 31 minus that is location of first pending interrupt
if ( callbacksP0 [ bitloc ] ! = NULL ) callbacksP0 [ bitloc ] ( ) ;
rise0 - = _BV ( bitloc ) ;
}
if ( fall0 ) while ( fall0 > 0 ) {
while ( fall0 > 0 ) {
const uint8_t bitloc = 31 - __CLZ ( fall0 ) ;
if ( callbacksP0 [ bitloc ] ! = NULL ) callbacksP0 [ bitloc ] ( ) ;
fall0 - = _BV ( bitloc ) ;
}
if ( rise2 ) while ( rise2 > 0 ) {
while ( rise2 > 0 ) {
const uint8_t bitloc = 31 - __CLZ ( rise2 ) ;
if ( callbacksP2 [ bitloc ] ! = NULL ) callbacksP2 [ bitloc ] ( ) ;
//LPC_GPIOINT->IO2IntClr = 1 << bitloc;
rise2 - = _BV ( bitloc ) ;
}
if ( fall2 ) while ( fall2 > 0 ) {
while ( fall2 > 0 ) {
const uint8_t bitloc = 31 - __CLZ ( fall2 ) ;
if ( callbacksP2 [ bitloc ] ! = NULL ) callbacksP2 [ bitloc ] ( ) ;
//LPC_GPIOINT->IO2IntClr = 1 << bitloc;
fall2 - = _BV ( bitloc ) ;
}
//NVIC_ClearPendingIRQ(EINT3_IRQn);
//LPC_GPIOINT->IO0IntClr = LPC_GPIOINT->IO2IntClr = 0xFFFFFFFF;
//NVIC_ClearPendingIRQ(EINT3_IRQn);
}
# endif
# endif // TARGET_LPC1768