Alvaro Cassinelli / Mbed 2 deprecated skinGames_forktest

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers adc.h Source File

adc.h

00001 /* mbed Library - ADC
00002  * Copyright (c) 2010, sblandford
00003  * released under MIT license http://mbed.org/licence/mit
00004  */
00005 
00006 #ifndef MBED_ADC_H
00007 #define MBED_ADC_H
00008  
00009 #include "mbed.h"
00010 
00011 #define XTAL_FREQ       12000000
00012 #define MAX_ADC_CLOCK   13000000
00013 #define CLKS_PER_SAMPLE 64
00014 
00015 #define ADC_SAMPLE_RATE 150000
00016 
00017 
00018 class ADC {
00019 public:
00020 
00021     //Initialize ADC with ADC maximum sample rate of
00022     //sample_rate and system clock divider of cclk_div
00023     //Maximum recommened sample rate is 184000
00024     ADC(int sample_rate, int cclk_div);
00025 
00026     //Enable/disable ADC on pin according to state
00027     //and also select/de-select for next conversion
00028     void setup(PinName pin, int state);
00029 
00030     //Return enabled/disabled state of ADC on pin
00031     int setup(PinName pin);
00032 
00033     //Enable/disable burst mode according to state
00034     void burst(int state);
00035 
00036     //Select channel already setup
00037     void select(PinName pin);
00038 
00039     //Return burst mode enabled/disabled
00040     int burst(void);
00041 
00042     /*Set start condition and edge according to mode:
00043     0 - No start (this value should be used when clearing PDN to 0).
00044     1 - Start conversion now.
00045     2 - Start conversion when the edge selected by bit 27 occurs on the P2.10 / EINT0 / NMI pin.
00046     3 - Start conversion when the edge selected by bit 27 occurs on the P1.27 / CLKOUT /
00047         USB_OVRCRn / CAP0.1 pin.
00048     4 - Start conversion when the edge selected by bit 27 occurs on MAT0.1. Note that this does
00049         not require that the MAT0.1 function appear on a device pin.
00050     5 - Start conversion when the edge selected by bit 27 occurs on MAT0.3. Note that it is not
00051         possible to cause the MAT0.3 function to appear on a device pin.
00052     6 - Start conversion when the edge selected by bit 27 occurs on MAT1.0. Note that this does
00053         not require that the MAT1.0 function appear on a device pin.
00054     7 - Start conversion when the edge selected by bit 27 occurs on MAT1.1. Note that this does
00055         not require that the MAT1.1 function appear on a device pin.
00056     When mode >= 2, conversion is triggered by edge:
00057     0 - Rising edge
00058     1 - Falling edge
00059     */
00060     void startmode(int mode, int edge);
00061     
00062     //Return startmode state according to mode_edge=0: mode and mode_edge=1: edge
00063     int startmode(int mode_edge);
00064     
00065     //Start ADC conversion
00066     void start(void);
00067 
00068     //Set interrupt enable/disable for pin to state
00069     void interrupt_state(PinName pin, int state);
00070     
00071     //Return enable/disable state of interrupt for pin
00072     int interrupt_state(PinName pin);
00073 
00074     //Attach custom interrupt handler replacing default
00075     void attach(void(*fptr)(void));
00076 
00077     //Restore default interrupt handler
00078     void detach(void);
00079 
00080     //Append custom interrupt handler for pin
00081     void append(PinName pin, void(*fptr)(uint32_t value));
00082 
00083     //Unappend custom interrupt handler for pin
00084     void unappend(PinName pin);
00085 
00086     //Append custom global interrupt handler
00087     void append(void(*fptr)(int chan, uint32_t value));
00088 
00089     //Unappend custom global interrupt handler
00090     void unappend(void);
00091 
00092     //Set ADC offset to a value 0-7
00093     void offset(int offset);
00094     
00095     //Return current ADC offset
00096     int offset(void);
00097 
00098     //Return value of ADC on pin
00099     int read(PinName pin);
00100 
00101     //Return DONE flag of ADC on pin
00102     int done(PinName pin);
00103     
00104     //Return OVERRUN flag of ADC on pin
00105     int overrun(PinName pin);
00106 
00107     //Return actual ADC clock
00108     int actual_adc_clock(void);
00109     
00110     //Return actual maximum sample rate
00111     int actual_sample_rate(void);
00112 
00113     //Return pin ID of ADC channel
00114     PinName channel_to_pin(int chan);
00115 
00116     //Return pin number of ADC channel
00117     int channel_to_pin_number(int chan);
00118 
00119 
00120 private:
00121     int _pin_to_channel(PinName pin);
00122     uint32_t _data_of_pin(PinName pin);
00123 
00124     int _adc_clk_freq;
00125     void adcisr(void);
00126     static void _adcisr(void);
00127     static ADC *instance;
00128     
00129     uint32_t _adc_data[8];
00130     void(*_adc_isr[8])(uint32_t value);
00131     void(*_adc_g_isr)(int chan, uint32_t value);
00132     void(*_adc_m_isr)(void);
00133 };
00134 
00135 extern ADC adc;
00136 
00137 #endif