Fast AnalogIn module which asks for a single non blocking reading and causes and interrupt when done.

Files at this revision

API Documentation at this revision

Comitter:
dontknowhow
Date:
Tue Apr 04 22:35:34 2017 +0000
Parent:
2:336af413f75c
Commit message:
set interrupt priority;

Changed in this revision

NbAnalogIn.cpp Show annotated file Show diff for this revision Revisions of this file
NbAnalogIn.h Show annotated file Show diff for this revision Revisions of this file
--- a/NbAnalogIn.cpp	Mon Apr 03 10:59:17 2017 +0000
+++ b/NbAnalogIn.cpp	Tue Apr 04 22:35:34 2017 +0000
@@ -26,12 +26,12 @@
 NbAnalogIn* NbAnalogIn::handlers[ADC_CHANNELS] = {0}; 
 volatile bool NbAnalogIn::converting = false; 
 
-NbAnalogIn::NbAnalogIn( PinName pin, void (*irqfunc)() ) {
+NbAnalogIn::NbAnalogIn( PinName pin) {
     
     NVIC_EnableIRQ(ADC_IRQn);
     NVIC_SetVector(ADC_IRQn, (uint32_t)irq);
     
-    cirq = irqfunc;
+ 
     
     channel = (ADCName)pinmap_peripheral(pin, PinMap_ADC);
     if (channel == (uint32_t)NC)
@@ -65,6 +65,13 @@
     LPC_ADC->ADINTEN |= (1 << 8);
 }
 
+void NbAnalogIn::setInterrupt(void (*irqfunc)() , int prio) {
+    cirq = irqfunc;
+    
+    if( prio >=0 && prio <=32 ) {
+        NVIC_SetPriority(ADC_IRQn, prio);  //set priority of these interrupts
+    }
+}
 
 int NbAnalogIn::readBl() {
     
--- a/NbAnalogIn.h	Mon Apr 03 10:59:17 2017 +0000
+++ b/NbAnalogIn.h	Tue Apr 04 22:35:34 2017 +0000
@@ -14,13 +14,20 @@
 public:
 
     
-    
     /**
     * Create a NbAnalogIn object, sets up ADC
     *
     * @param pin AnalogIn pin to connect to
     */
-    NbAnalogIn( PinName pin, void (*irqfunc)() = 0 );
+    NbAnalogIn( PinName pin );
+    
+    /**
+    * Set interrupt options
+    *
+    * @param irqfunc - callback function executed at the end of interrupts
+    * @param priority - set interrupt priority level. -1 (default) leaves them unchanged
+    */
+    void setInterrupt(void (*irqfunc)() = 0, int prio = -1);
     
     /**
     * does a single blocking read and returns a 12 bit output
@@ -52,11 +59,6 @@
         return read();
     }
     
-    
-    // custom interrupt handler which, if set, is called after the internal
-    // interrupt handling
-    void (* cirq)(); 
-    
         
 private:
     
@@ -72,7 +74,9 @@
     static void irq();
     static NbAnalogIn* handlers[ADC_CHANNELS]; 
     
-    
+    // custom interrupt handler which, if set, is called after the internal
+    // interrupt handling
+    void (* cirq)(); 
     
 };