testing

Dependencies:   HTTPClient PowerControl SNICInterface_mod mbed-rtos mbed

Fork of Fx0Hackson by Daisuke Kimura

Committer:
hirobe0913
Date:
Sun Feb 15 04:00:06 2015 +0000
Revision:
9:9fc77f7685b7
testing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hirobe0913 9:9fc77f7685b7 1 /* mbed Library - ADC
hirobe0913 9:9fc77f7685b7 2 * Copyright (c) 2010, sblandford
hirobe0913 9:9fc77f7685b7 3 * released under MIT license http://mbed.org/licence/mit
hirobe0913 9:9fc77f7685b7 4 */
hirobe0913 9:9fc77f7685b7 5
hirobe0913 9:9fc77f7685b7 6 #ifndef MBED_ADC_H
hirobe0913 9:9fc77f7685b7 7 #define MBED_ADC_H
hirobe0913 9:9fc77f7685b7 8
hirobe0913 9:9fc77f7685b7 9 #include "mbed.h"
hirobe0913 9:9fc77f7685b7 10 #define XTAL_FREQ 12000000
hirobe0913 9:9fc77f7685b7 11 #define MAX_ADC_CLOCK 13000000
hirobe0913 9:9fc77f7685b7 12 #define CLKS_PER_SAMPLE 64
hirobe0913 9:9fc77f7685b7 13
hirobe0913 9:9fc77f7685b7 14 class ADC {
hirobe0913 9:9fc77f7685b7 15 public:
hirobe0913 9:9fc77f7685b7 16
hirobe0913 9:9fc77f7685b7 17 //Initialize ADC with ADC maximum sample rate of
hirobe0913 9:9fc77f7685b7 18 //sample_rate and system clock divider of cclk_div
hirobe0913 9:9fc77f7685b7 19 //Maximum recommened sample rate is 184000
hirobe0913 9:9fc77f7685b7 20 ADC(int sample_rate, int cclk_div);
hirobe0913 9:9fc77f7685b7 21
hirobe0913 9:9fc77f7685b7 22 //Enable/disable ADC on pin according to state
hirobe0913 9:9fc77f7685b7 23 //and also select/de-select for next conversion
hirobe0913 9:9fc77f7685b7 24 void setup(PinName pin, int state);
hirobe0913 9:9fc77f7685b7 25
hirobe0913 9:9fc77f7685b7 26 //Return enabled/disabled state of ADC on pin
hirobe0913 9:9fc77f7685b7 27 int setup(PinName pin);
hirobe0913 9:9fc77f7685b7 28
hirobe0913 9:9fc77f7685b7 29 //Enable/disable burst mode according to state
hirobe0913 9:9fc77f7685b7 30 void burst(int state);
hirobe0913 9:9fc77f7685b7 31
hirobe0913 9:9fc77f7685b7 32 //Select channel already setup
hirobe0913 9:9fc77f7685b7 33 void select(PinName pin);
hirobe0913 9:9fc77f7685b7 34
hirobe0913 9:9fc77f7685b7 35 //Return burst mode enabled/disabled
hirobe0913 9:9fc77f7685b7 36 int burst(void);
hirobe0913 9:9fc77f7685b7 37
hirobe0913 9:9fc77f7685b7 38 /*Set start condition and edge according to mode:
hirobe0913 9:9fc77f7685b7 39 0 - No start (this value should be used when clearing PDN to 0).
hirobe0913 9:9fc77f7685b7 40 1 - Start conversion now.
hirobe0913 9:9fc77f7685b7 41 2 - Start conversion when the edge selected by bit 27 occurs on the P2.10 / EINT0 / NMI pin.
hirobe0913 9:9fc77f7685b7 42 3 - Start conversion when the edge selected by bit 27 occurs on the P1.27 / CLKOUT /
hirobe0913 9:9fc77f7685b7 43 USB_OVRCRn / CAP0.1 pin.
hirobe0913 9:9fc77f7685b7 44 4 - Start conversion when the edge selected by bit 27 occurs on MAT0.1. Note that this does
hirobe0913 9:9fc77f7685b7 45 not require that the MAT0.1 function appear on a device pin.
hirobe0913 9:9fc77f7685b7 46 5 - Start conversion when the edge selected by bit 27 occurs on MAT0.3. Note that it is not
hirobe0913 9:9fc77f7685b7 47 possible to cause the MAT0.3 function to appear on a device pin.
hirobe0913 9:9fc77f7685b7 48 6 - Start conversion when the edge selected by bit 27 occurs on MAT1.0. Note that this does
hirobe0913 9:9fc77f7685b7 49 not require that the MAT1.0 function appear on a device pin.
hirobe0913 9:9fc77f7685b7 50 7 - Start conversion when the edge selected by bit 27 occurs on MAT1.1. Note that this does
hirobe0913 9:9fc77f7685b7 51 not require that the MAT1.1 function appear on a device pin.
hirobe0913 9:9fc77f7685b7 52 When mode >= 2, conversion is triggered by edge:
hirobe0913 9:9fc77f7685b7 53 0 - Rising edge
hirobe0913 9:9fc77f7685b7 54 1 - Falling edge
hirobe0913 9:9fc77f7685b7 55 */
hirobe0913 9:9fc77f7685b7 56 void startmode(int mode, int edge);
hirobe0913 9:9fc77f7685b7 57
hirobe0913 9:9fc77f7685b7 58 //Return startmode state according to mode_edge=0: mode and mode_edge=1: edge
hirobe0913 9:9fc77f7685b7 59 int startmode(int mode_edge);
hirobe0913 9:9fc77f7685b7 60
hirobe0913 9:9fc77f7685b7 61 //Start ADC conversion
hirobe0913 9:9fc77f7685b7 62 void start(void);
hirobe0913 9:9fc77f7685b7 63
hirobe0913 9:9fc77f7685b7 64 //Set interrupt enable/disable for pin to state
hirobe0913 9:9fc77f7685b7 65 void interrupt_state(PinName pin, int state);
hirobe0913 9:9fc77f7685b7 66
hirobe0913 9:9fc77f7685b7 67 //Return enable/disable state of interrupt for pin
hirobe0913 9:9fc77f7685b7 68 int interrupt_state(PinName pin);
hirobe0913 9:9fc77f7685b7 69
hirobe0913 9:9fc77f7685b7 70 //Attach custom interrupt handler replacing default
hirobe0913 9:9fc77f7685b7 71 void attach(void(*fptr)(void));
hirobe0913 9:9fc77f7685b7 72
hirobe0913 9:9fc77f7685b7 73 //Restore default interrupt handler
hirobe0913 9:9fc77f7685b7 74 void detach(void);
hirobe0913 9:9fc77f7685b7 75
hirobe0913 9:9fc77f7685b7 76 //Append custom interrupt handler for pin
hirobe0913 9:9fc77f7685b7 77 void append(PinName pin, void(*fptr)(uint32_t value));
hirobe0913 9:9fc77f7685b7 78
hirobe0913 9:9fc77f7685b7 79 //Unappend custom interrupt handler for pin
hirobe0913 9:9fc77f7685b7 80 void unappend(PinName pin);
hirobe0913 9:9fc77f7685b7 81
hirobe0913 9:9fc77f7685b7 82 //Append custom global interrupt handler
hirobe0913 9:9fc77f7685b7 83 void append(void(*fptr)(int chan, uint32_t value));
hirobe0913 9:9fc77f7685b7 84
hirobe0913 9:9fc77f7685b7 85 //Unappend custom global interrupt handler
hirobe0913 9:9fc77f7685b7 86 void unappend(void);
hirobe0913 9:9fc77f7685b7 87
hirobe0913 9:9fc77f7685b7 88 //Set ADC offset to a value 0-7
hirobe0913 9:9fc77f7685b7 89 void offset(int offset);
hirobe0913 9:9fc77f7685b7 90
hirobe0913 9:9fc77f7685b7 91 //Return current ADC offset
hirobe0913 9:9fc77f7685b7 92 int offset(void);
hirobe0913 9:9fc77f7685b7 93
hirobe0913 9:9fc77f7685b7 94 //Return value of ADC on pin
hirobe0913 9:9fc77f7685b7 95 int read(PinName pin);
hirobe0913 9:9fc77f7685b7 96
hirobe0913 9:9fc77f7685b7 97 //Return DONE flag of ADC on pin
hirobe0913 9:9fc77f7685b7 98 int done(PinName pin);
hirobe0913 9:9fc77f7685b7 99
hirobe0913 9:9fc77f7685b7 100 //Return OVERRUN flag of ADC on pin
hirobe0913 9:9fc77f7685b7 101 int overrun(PinName pin);
hirobe0913 9:9fc77f7685b7 102
hirobe0913 9:9fc77f7685b7 103 //Return actual ADC clock
hirobe0913 9:9fc77f7685b7 104 int actual_adc_clock(void);
hirobe0913 9:9fc77f7685b7 105
hirobe0913 9:9fc77f7685b7 106 //Return actual maximum sample rate
hirobe0913 9:9fc77f7685b7 107 int actual_sample_rate(void);
hirobe0913 9:9fc77f7685b7 108
hirobe0913 9:9fc77f7685b7 109 //Return pin ID of ADC channel
hirobe0913 9:9fc77f7685b7 110 PinName channel_to_pin(int chan);
hirobe0913 9:9fc77f7685b7 111
hirobe0913 9:9fc77f7685b7 112 //Return pin number of ADC channel
hirobe0913 9:9fc77f7685b7 113 int channel_to_pin_number(int chan);
hirobe0913 9:9fc77f7685b7 114
hirobe0913 9:9fc77f7685b7 115
hirobe0913 9:9fc77f7685b7 116 private:
hirobe0913 9:9fc77f7685b7 117 int _pin_to_channel(PinName pin);
hirobe0913 9:9fc77f7685b7 118 uint32_t _data_of_pin(PinName pin);
hirobe0913 9:9fc77f7685b7 119
hirobe0913 9:9fc77f7685b7 120 int _adc_clk_freq;
hirobe0913 9:9fc77f7685b7 121 void adcisr(void);
hirobe0913 9:9fc77f7685b7 122 static void _adcisr(void);
hirobe0913 9:9fc77f7685b7 123 static ADC *instance;
hirobe0913 9:9fc77f7685b7 124
hirobe0913 9:9fc77f7685b7 125 uint32_t _adc_data[8];
hirobe0913 9:9fc77f7685b7 126 void(*_adc_isr[8])(uint32_t value);
hirobe0913 9:9fc77f7685b7 127 void(*_adc_g_isr)(int chan, uint32_t value);
hirobe0913 9:9fc77f7685b7 128 void(*_adc_m_isr)(void);
hirobe0913 9:9fc77f7685b7 129 };
hirobe0913 9:9fc77f7685b7 130
hirobe0913 9:9fc77f7685b7 131 #endif