mbed lib with startup delay fixed for Nucleo401RE

Fork of mbed-src by mbed official

Committer:
emilmont
Date:
Mon Feb 18 11:44:18 2013 +0000
Revision:
2:143cac498751
Parent:
0:fd0d7bdfcdc2
Update mbed sources to Rev 59

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:fd0d7bdfcdc2 1 /* mbed Microcontroller Library
emilmont 2:143cac498751 2 * Copyright (c) 2006-2013 ARM Limited
mbed_official 0:fd0d7bdfcdc2 3 *
emilmont 2:143cac498751 4 * Licensed under the Apache License, Version 2.0 (the "License");
emilmont 2:143cac498751 5 * you may not use this file except in compliance with the License.
emilmont 2:143cac498751 6 * You may obtain a copy of the License at
mbed_official 0:fd0d7bdfcdc2 7 *
emilmont 2:143cac498751 8 * http://www.apache.org/licenses/LICENSE-2.0
mbed_official 0:fd0d7bdfcdc2 9 *
emilmont 2:143cac498751 10 * Unless required by applicable law or agreed to in writing, software
emilmont 2:143cac498751 11 * distributed under the License is distributed on an "AS IS" BASIS,
emilmont 2:143cac498751 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
emilmont 2:143cac498751 13 * See the License for the specific language governing permissions and
emilmont 2:143cac498751 14 * limitations under the License.
mbed_official 0:fd0d7bdfcdc2 15 */
mbed_official 0:fd0d7bdfcdc2 16 #ifndef MBED_ANALOGIN_H
mbed_official 0:fd0d7bdfcdc2 17 #define MBED_ANALOGIN_H
mbed_official 0:fd0d7bdfcdc2 18
mbed_official 0:fd0d7bdfcdc2 19 #include "platform.h"
mbed_official 0:fd0d7bdfcdc2 20
mbed_official 0:fd0d7bdfcdc2 21 #if DEVICE_ANALOGIN
mbed_official 0:fd0d7bdfcdc2 22
mbed_official 0:fd0d7bdfcdc2 23 #include "analogin_api.h"
mbed_official 0:fd0d7bdfcdc2 24
mbed_official 0:fd0d7bdfcdc2 25 namespace mbed {
mbed_official 0:fd0d7bdfcdc2 26
mbed_official 0:fd0d7bdfcdc2 27 /** An analog input, used for reading the voltage on a pin
mbed_official 0:fd0d7bdfcdc2 28 *
mbed_official 0:fd0d7bdfcdc2 29 * Example:
mbed_official 0:fd0d7bdfcdc2 30 * @code
mbed_official 0:fd0d7bdfcdc2 31 * // Print messages when the AnalogIn is greater than 50%
emilmont 2:143cac498751 32 *
mbed_official 0:fd0d7bdfcdc2 33 * #include "mbed.h"
emilmont 2:143cac498751 34 *
mbed_official 0:fd0d7bdfcdc2 35 * AnalogIn temperature(p20);
emilmont 2:143cac498751 36 *
mbed_official 0:fd0d7bdfcdc2 37 * int main() {
mbed_official 0:fd0d7bdfcdc2 38 * while(1) {
mbed_official 0:fd0d7bdfcdc2 39 * if(temperature > 0.5) {
mbed_official 0:fd0d7bdfcdc2 40 * printf("Too hot! (%f)", temperature.read());
mbed_official 0:fd0d7bdfcdc2 41 * }
mbed_official 0:fd0d7bdfcdc2 42 * }
mbed_official 0:fd0d7bdfcdc2 43 * }
mbed_official 0:fd0d7bdfcdc2 44 * @endcode
mbed_official 0:fd0d7bdfcdc2 45 */
mbed_official 0:fd0d7bdfcdc2 46 class AnalogIn {
mbed_official 0:fd0d7bdfcdc2 47
mbed_official 0:fd0d7bdfcdc2 48 public:
mbed_official 0:fd0d7bdfcdc2 49
mbed_official 0:fd0d7bdfcdc2 50 /** Create an AnalogIn, connected to the specified pin
mbed_official 0:fd0d7bdfcdc2 51 *
emilmont 2:143cac498751 52 * @param pin AnalogIn pin to connect to
mbed_official 0:fd0d7bdfcdc2 53 * @param name (optional) A string to identify the object
mbed_official 0:fd0d7bdfcdc2 54 */
mbed_official 0:fd0d7bdfcdc2 55 AnalogIn(PinName pin) {
mbed_official 0:fd0d7bdfcdc2 56 analogin_init(&_adc, pin);
mbed_official 0:fd0d7bdfcdc2 57 }
emilmont 2:143cac498751 58
mbed_official 0:fd0d7bdfcdc2 59 /** Read the input voltage, represented as a float in the range [0.0, 1.0]
mbed_official 0:fd0d7bdfcdc2 60 *
mbed_official 0:fd0d7bdfcdc2 61 * @returns A floating-point value representing the current input voltage, measured as a percentage
mbed_official 0:fd0d7bdfcdc2 62 */
mbed_official 0:fd0d7bdfcdc2 63 float read() {
mbed_official 0:fd0d7bdfcdc2 64 return analogin_read(&_adc);
mbed_official 0:fd0d7bdfcdc2 65 }
mbed_official 0:fd0d7bdfcdc2 66
mbed_official 0:fd0d7bdfcdc2 67 /** Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
mbed_official 0:fd0d7bdfcdc2 68 *
mbed_official 0:fd0d7bdfcdc2 69 * @returns
emilmont 2:143cac498751 70 * 16-bit unsigned short representing the current input voltage, normalised to a 16-bit value
mbed_official 0:fd0d7bdfcdc2 71 */
mbed_official 0:fd0d7bdfcdc2 72 unsigned short read_u16() {
mbed_official 0:fd0d7bdfcdc2 73 return analogin_read_u16(&_adc);
mbed_official 0:fd0d7bdfcdc2 74 }
mbed_official 0:fd0d7bdfcdc2 75
mbed_official 0:fd0d7bdfcdc2 76 #ifdef MBED_OPERATORS
mbed_official 0:fd0d7bdfcdc2 77 /** An operator shorthand for read()
mbed_official 0:fd0d7bdfcdc2 78 *
mbed_official 0:fd0d7bdfcdc2 79 * The float() operator can be used as a shorthand for read() to simplify common code sequences
mbed_official 0:fd0d7bdfcdc2 80 *
mbed_official 0:fd0d7bdfcdc2 81 * Example:
mbed_official 0:fd0d7bdfcdc2 82 * @code
mbed_official 0:fd0d7bdfcdc2 83 * float x = volume.read();
mbed_official 0:fd0d7bdfcdc2 84 * float x = volume;
emilmont 2:143cac498751 85 *
mbed_official 0:fd0d7bdfcdc2 86 * if(volume.read() > 0.25) { ... }
mbed_official 0:fd0d7bdfcdc2 87 * if(volume > 0.25) { ... }
mbed_official 0:fd0d7bdfcdc2 88 * @endcode
mbed_official 0:fd0d7bdfcdc2 89 */
mbed_official 0:fd0d7bdfcdc2 90 operator float() {
mbed_official 0:fd0d7bdfcdc2 91 return read();
mbed_official 0:fd0d7bdfcdc2 92 }
mbed_official 0:fd0d7bdfcdc2 93 #endif
mbed_official 0:fd0d7bdfcdc2 94
mbed_official 0:fd0d7bdfcdc2 95 protected:
mbed_official 0:fd0d7bdfcdc2 96 analogin_t _adc;
mbed_official 0:fd0d7bdfcdc2 97 };
mbed_official 0:fd0d7bdfcdc2 98
mbed_official 0:fd0d7bdfcdc2 99 } // namespace mbed
mbed_official 0:fd0d7bdfcdc2 100
mbed_official 0:fd0d7bdfcdc2 101 #endif
mbed_official 0:fd0d7bdfcdc2 102
mbed_official 0:fd0d7bdfcdc2 103 #endif