analogIn with DMA

Dependents:   TDEMNucleo

Committer:
willybayot
Date:
Sat Jan 03 14:44:44 2015 +0000
Revision:
3:678ff2edcbe6
Parent:
2:08779d8f1873
revision 2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
willybayot 0:1f6ea9afd585 1 /* mbed Microcontroller Library
willybayot 0:1f6ea9afd585 2 * Copyright (c) 2006-2013 ARM Limited
willybayot 0:1f6ea9afd585 3 *
willybayot 0:1f6ea9afd585 4 * Licensed under the Apache License, Version 2.0 (the "License");
willybayot 0:1f6ea9afd585 5 * you may not use this file except in compliance with the License.
willybayot 0:1f6ea9afd585 6 * You may obtain a copy of the License at
willybayot 0:1f6ea9afd585 7 *
willybayot 0:1f6ea9afd585 8 * http://www.apache.org/licenses/LICENSE-2.0
willybayot 0:1f6ea9afd585 9 *
willybayot 0:1f6ea9afd585 10 * Unless required by applicable law or agreed to in writing, software
willybayot 0:1f6ea9afd585 11 * distributed under the License is distributed on an "AS IS" BASIS,
willybayot 0:1f6ea9afd585 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
willybayot 0:1f6ea9afd585 13 * See the License for the specific language governing permissions and
willybayot 0:1f6ea9afd585 14 * limitations under the License.
willybayot 0:1f6ea9afd585 15 */
willybayot 0:1f6ea9afd585 16 #ifndef MBED_ANALOGINDMA_H
willybayot 0:1f6ea9afd585 17 #define MBED_ANALOGINDMA_H
willybayot 0:1f6ea9afd585 18
willybayot 0:1f6ea9afd585 19 #include "platform.h"
willybayot 0:1f6ea9afd585 20
willybayot 0:1f6ea9afd585 21 #if DEVICE_ANALOGIN
willybayot 0:1f6ea9afd585 22
willybayot 0:1f6ea9afd585 23 #include "analoginDMA_api.h"
willybayot 0:1f6ea9afd585 24
willybayot 0:1f6ea9afd585 25
willybayot 0:1f6ea9afd585 26 namespace mbed {
willybayot 0:1f6ea9afd585 27
willybayot 0:1f6ea9afd585 28 /** An analog input, used for reading the voltage on a pin
willybayot 0:1f6ea9afd585 29 *
willybayot 0:1f6ea9afd585 30 * Example:
willybayot 0:1f6ea9afd585 31 * @code
willybayot 0:1f6ea9afd585 32 * // Print messages when the AnalogIn is greater than 50%
willybayot 0:1f6ea9afd585 33 *
willybayot 0:1f6ea9afd585 34 * #include "mbed.h"
willybayot 0:1f6ea9afd585 35 *
willybayot 3:678ff2edcbe6 36 * AnalogInDMA temperature(p20);
willybayot 0:1f6ea9afd585 37 *
willybayot 0:1f6ea9afd585 38 * int main() {
willybayot 3:678ff2edcbe6 39 * unsigned short t;
willybayot 0:1f6ea9afd585 40 * while(1) {
willybayot 3:678ff2edcbe6 41 * temperature.read(&t,1);
willybayot 3:678ff2edcbe6 42 * if(t > 0.5) {
willybayot 3:678ff2edcbe6 43 * printf("Too hot! (%f)", t);
willybayot 0:1f6ea9afd585 44 * }
willybayot 0:1f6ea9afd585 45 * }
willybayot 0:1f6ea9afd585 46 * }
willybayot 0:1f6ea9afd585 47 * @endcode
willybayot 0:1f6ea9afd585 48 */
willybayot 0:1f6ea9afd585 49 class AnalogInDMA {
willybayot 0:1f6ea9afd585 50
willybayot 0:1f6ea9afd585 51 public:
willybayot 0:1f6ea9afd585 52
willybayot 0:1f6ea9afd585 53 /** Create an AnalogIn, connected to the specified pin
willybayot 0:1f6ea9afd585 54 *
willybayot 0:1f6ea9afd585 55 * @param pin AnalogIn pin to connect to
willybayot 0:1f6ea9afd585 56 * @param name (optional) A string to identify the object
willybayot 0:1f6ea9afd585 57 */
willybayot 0:1f6ea9afd585 58 AnalogInDMA(PinName pin) {
willybayot 0:1f6ea9afd585 59 analoginDMA_init(&_adc, pin);
willybayot 0:1f6ea9afd585 60 }
willybayot 0:1f6ea9afd585 61
willybayot 2:08779d8f1873 62
willybayot 3:678ff2edcbe6 63 /** Read 'Length' input voltage(s), represented as an unsigned short in the buffer 'pData'
willybayot 0:1f6ea9afd585 64 *
willybayot 0:1f6ea9afd585 65 */
willybayot 2:08779d8f1873 66 void read(uint16_t* pData, uint32_t Length) {
willybayot 2:08779d8f1873 67 analoginDMA_read_u16(&_adc, pData, Length);
willybayot 0:1f6ea9afd585 68 }
willybayot 0:1f6ea9afd585 69
willybayot 0:1f6ea9afd585 70
willybayot 0:1f6ea9afd585 71 protected:
willybayot 0:1f6ea9afd585 72 analogin_t _adc;
willybayot 0:1f6ea9afd585 73 };
willybayot 0:1f6ea9afd585 74
willybayot 0:1f6ea9afd585 75 } // namespace mbed
willybayot 0:1f6ea9afd585 76
willybayot 0:1f6ea9afd585 77 #endif
willybayot 0:1f6ea9afd585 78
willybayot 0:1f6ea9afd585 79 #endif