ultrasonic

Dependencies:   EthernetNetIf HTTPServer TextLCD mbed

Fork of ethernet_test_http by Yasushi TAUCHI

Committer:
twinkling
Date:
Tue Sep 08 06:22:48 2015 +0000
Revision:
1:1cda1fafd448
:;

Who changed what in which revision?

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