Fast AnalogIn module which asks for a single non blocking reading and causes and interrupt when done.
NbAnalogIn.h@1:2666729acca1, 2017-04-02 (annotated)
- Committer:
- dontknowhow
- Date:
- Sun Apr 02 11:16:24 2017 +0000
- Revision:
- 1:2666729acca1
- Parent:
- 0:058d32b78e5d
- Child:
- 2:336af413f75c
IRQ handlers in class
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dontknowhow | 0:058d32b78e5d | 1 | #include "mbed.h" |
dontknowhow | 0:058d32b78e5d | 2 | |
dontknowhow | 0:058d32b78e5d | 3 | #ifndef NBANALOGIN_H |
dontknowhow | 0:058d32b78e5d | 4 | #define NBANALOGIN_H |
dontknowhow | 0:058d32b78e5d | 5 | |
dontknowhow | 1:2666729acca1 | 6 | #define ADC_BUF_SIZE 100 |
dontknowhow | 1:2666729acca1 | 7 | |
dontknowhow | 0:058d32b78e5d | 8 | /** Library for non blocking ADC operation |
dontknowhow | 0:058d32b78e5d | 9 | */ |
dontknowhow | 0:058d32b78e5d | 10 | |
dontknowhow | 0:058d32b78e5d | 11 | class NbAnalogIn{ |
dontknowhow | 0:058d32b78e5d | 12 | public: |
dontknowhow | 1:2666729acca1 | 13 | |
dontknowhow | 1:2666729acca1 | 14 | |
dontknowhow | 1:2666729acca1 | 15 | |
dontknowhow | 0:058d32b78e5d | 16 | /** |
dontknowhow | 0:058d32b78e5d | 17 | * Create a NbAnalogIn object, sets up ADC |
dontknowhow | 0:058d32b78e5d | 18 | */ |
dontknowhow | 0:058d32b78e5d | 19 | NbAnalogIn(); |
dontknowhow | 0:058d32b78e5d | 20 | |
dontknowhow | 0:058d32b78e5d | 21 | /** |
dontknowhow | 0:058d32b78e5d | 22 | * does a single blocking read and returns a 12 bit output |
dontknowhow | 0:058d32b78e5d | 23 | */ |
dontknowhow | 0:058d32b78e5d | 24 | unsigned int read(); |
dontknowhow | 0:058d32b78e5d | 25 | |
dontknowhow | 0:058d32b78e5d | 26 | /** |
dontknowhow | 0:058d32b78e5d | 27 | * sets the interrupt to fire when ADC is finished |
dontknowhow | 0:058d32b78e5d | 28 | */ |
dontknowhow | 1:2666729acca1 | 29 | void triggerConv(); |
dontknowhow | 1:2666729acca1 | 30 | |
dontknowhow | 1:2666729acca1 | 31 | |
dontknowhow | 1:2666729acca1 | 32 | |
dontknowhow | 1:2666729acca1 | 33 | bool readable(); |
dontknowhow | 1:2666729acca1 | 34 | |
dontknowhow | 1:2666729acca1 | 35 | int readNb(); |
dontknowhow | 1:2666729acca1 | 36 | |
dontknowhow | 1:2666729acca1 | 37 | static void irq(); |
dontknowhow | 1:2666729acca1 | 38 | static NbAnalogIn* handlers[2]; |
dontknowhow | 1:2666729acca1 | 39 | void handler( int adc_result ); |
dontknowhow | 0:058d32b78e5d | 40 | |
dontknowhow | 0:058d32b78e5d | 41 | private: |
dontknowhow | 0:058d32b78e5d | 42 | |
dontknowhow | 1:2666729acca1 | 43 | int buffer[ADC_BUF_SIZE]; |
dontknowhow | 1:2666729acca1 | 44 | int write_pos; // next position to be written to |
dontknowhow | 1:2666729acca1 | 45 | int read_pos; // next position to be read from |
dontknowhow | 1:2666729acca1 | 46 | |
dontknowhow | 1:2666729acca1 | 47 | |
dontknowhow | 1:2666729acca1 | 48 | |
dontknowhow | 1:2666729acca1 | 49 | |
dontknowhow | 1:2666729acca1 | 50 | |
dontknowhow | 0:058d32b78e5d | 51 | }; |
dontknowhow | 1:2666729acca1 | 52 | |
dontknowhow | 1:2666729acca1 | 53 | |
dontknowhow | 0:058d32b78e5d | 54 | #endif |