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

NbAnalogIn.h

Committer:
dontknowhow
Date:
2017-04-02
Revision:
1:2666729acca1
Parent:
0:058d32b78e5d
Child:
2:336af413f75c

File content as of revision 1:2666729acca1:

#include "mbed.h"

#ifndef NBANALOGIN_H
#define NBANALOGIN_H

#define ADC_BUF_SIZE 100

/** Library for non blocking ADC operation
  */
  
class NbAnalogIn{
public:

    
    
    /**
    * Create a NbAnalogIn object, sets up ADC
    */
    NbAnalogIn();
    
    /**
    * does a single blocking read and returns a 12 bit output
    */
    unsigned int read();
    
    /**
    * sets the interrupt to fire when ADC is finished
    */
    void triggerConv();
    
    
    
    bool readable();
    
    int readNb();
    
    static void irq();
    static NbAnalogIn* handlers[2]; 
    void handler( int adc_result );
        
private:
    
    int buffer[ADC_BUF_SIZE];
    int write_pos;      // next position to be written to
    int read_pos;       // next position to be read from
    
    
    
    
    
};


#endif