analogIn with DMA

Dependents:   TDEMNucleo

AnaloginDMA.h

Committer:
willybayot
Date:
2015-01-03
Revision:
2:08779d8f1873
Parent:
1:4b275a292c9d
Child:
3:678ff2edcbe6
Child:
4:2844a210bd46

File content as of revision 2:08779d8f1873:

/* mbed Microcontroller Library
 * Copyright (c) 2006-2013 ARM Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef MBED_ANALOGINDMA_H
#define MBED_ANALOGINDMA_H

#include "platform.h"

#if DEVICE_ANALOGIN

#include "analoginDMA_api.h"


namespace mbed {

/** An analog input, used for reading the voltage on a pin
 *
 * Example:
 * @code
 * // Print messages when the AnalogIn is greater than 50%
 *
 * #include "mbed.h"
 *
 * AnalogIn temperature(p20);
 *
 * int main() {
 *     while(1) {
 *         if(temperature > 0.5) {
 *             printf("Too hot! (%f)", temperature.read());
 *         }
 *     }
 * }
 * @endcode
 */
class AnalogInDMA {

public:

    /** Create an AnalogIn, connected to the specified pin
     *
     * @param pin AnalogIn pin to connect to
     * @param name (optional) A string to identify the object
     */
    AnalogInDMA(PinName pin) {
        analoginDMA_init(&_adc, pin);
    }

 
    /** Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
     *
     * @returns
     *   16-bit unsigned short representing the current input voltage, normalised to a 16-bit value
     */
    void read(uint16_t* pData, uint32_t Length) {
        analoginDMA_read_u16(&_adc, pData, Length);
    }


protected:
    analogin_t _adc;
};

} // namespace mbed

#endif

#endif