Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
NbAnalogIn.h
00001 #include "mbed.h" 00002 #include "pinmap.h" 00003 00004 #ifndef NBANALOGIN_H 00005 #define NBANALOGIN_H 00006 00007 #define ADC_BUF_SIZE 100 00008 #define ADC_CHANNELS 8 00009 00010 /** Library for non blocking ADC operation 00011 */ 00012 00013 class NbAnalogIn{ 00014 public: 00015 00016 00017 /** 00018 * Create a NbAnalogIn object, sets up ADC 00019 * 00020 * @param pin AnalogIn pin to connect to 00021 */ 00022 NbAnalogIn( PinName pin ); 00023 00024 /** 00025 * Set interrupt options 00026 * 00027 * @param irqfunc - callback function executed at the end of interrupts 00028 * @param priority - set interrupt priority level. -1 (default) leaves them unchanged 00029 */ 00030 void setInterrupt(void (*irqfunc)() = 0, int prio = -1); 00031 00032 /** 00033 * does a single blocking read and returns a 12 bit output 00034 */ 00035 int readBl(); 00036 00037 /** 00038 * starts a conversion and sets the interrupt to fire when ADC is finished 00039 * the result will be put into the internal buffer 00040 * 00041 * @param wait - If true, wait for current adc conversion to finish, 00042 * if false (default), stop the current conversion replace it 00043 */ 00044 void triggerConv(bool wait = false); 00045 00046 /** 00047 * checks if the buffer has new results that can be read 00048 */ 00049 bool readable(); 00050 00051 /** 00052 * returns the next value from the buffer 00053 */ 00054 int read(); 00055 00056 /** An operator shorthand for read() 00057 */ 00058 operator int() { 00059 return read(); 00060 } 00061 00062 00063 private: 00064 00065 int buffer[ADC_BUF_SIZE]; 00066 int write_pos; // next position to be written to 00067 int read_pos; // next position to be read from 00068 00069 static volatile bool converting; 00070 00071 uint8_t channel; // channel of current object (ADC0-7) 00072 void handler( int adc_result ); 00073 00074 static void irq(); 00075 static NbAnalogIn* handlers[ADC_CHANNELS]; 00076 00077 // custom interrupt handler which, if set, is called after the internal 00078 // interrupt handling 00079 void (* cirq)(); 00080 00081 }; 00082 00083 00084 #endif
Generated on Sat Jul 16 2022 02:50:33 by
1.7.2