analogIn with DMA

Dependents:   TDEMNucleo

AnaloginDMA.h

Committer:
willybayot
Date:
2015-01-03
Revision:
3:678ff2edcbe6
Parent:
2:08779d8f1873

File content as of revision 3:678ff2edcbe6:

/* 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"
 *
 * AnalogInDMA temperature(p20);
 *
 * int main() {
 * unsigned short t;
 *     while(1) {
 *          temperature.read(&t,1);
 *          if(t > 0.5) {
 *             printf("Too hot! (%f)", t);
 *         }
 *     }
 * }
 * @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  'Length' input voltage(s), represented as an unsigned short in the buffer 'pData'
     *
     */
    void read(uint16_t* pData, uint32_t Length) {
        analoginDMA_read_u16(&_adc, pData, Length);
    }


protected:
    analogin_t _adc;
};

} // namespace mbed

#endif

#endif