WILLY BAYOT / anaDMA

Dependents:   TDEMNucleo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers AnaloginDMA.h Source File

AnaloginDMA.h

00001 /* mbed Microcontroller Library
00002  * Copyright (c) 2006-2013 ARM Limited
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *     http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #ifndef MBED_ANALOGINDMA_H
00017 #define MBED_ANALOGINDMA_H
00018 
00019 #include "platform.h"
00020 
00021 #if DEVICE_ANALOGIN
00022 
00023 #include "analoginDMA_api.h"
00024 
00025 
00026 namespace mbed {
00027 
00028 /** An analog input, used for reading the voltage on a pin
00029  *
00030  * Example:
00031  * @code
00032  * // Print messages when the AnalogIn is greater than 50%
00033  *
00034  * #include "mbed.h"
00035  *
00036  * AnalogIn temperature(p20);
00037  *
00038  * int main() {
00039  *     while(1) {
00040  *         if(temperature > 0.5) {
00041  *             printf("Too hot! (%f)", temperature.read());
00042  *         }
00043  *     }
00044  * }
00045  * @endcode
00046  */
00047 class AnalogInDMA {
00048 
00049 public:
00050 
00051     /** Create an AnalogIn, connected to the specified pin
00052      *
00053      * @param pin AnalogIn pin to connect to
00054      * @param name (optional) A string to identify the object
00055      */
00056     AnalogInDMA(PinName pin) {
00057         analoginDMA_init(&_adc, pin);
00058     }
00059 
00060  
00061     /** Read the 'Length' input voltage(s), represented as an array of  unsigned short pData
00062      *
00063      * @returns status: 0 = OK, 1 = ERROR, 2=BUSY, 3 = TIMEOUT
00064      */
00065     HAL_StatusTypeDef read(uint16_t* pData, uint32_t Length) {
00066          return analoginDMA_read_u16(&_adc, pData, Length);
00067     }
00068 
00069 
00070 protected:
00071     analogin_t _adc;
00072 };
00073 
00074 } // namespace mbed
00075 
00076 #endif
00077 
00078 #endif