Martin Werluschnig / Mbed 2 deprecated Diplomarbeit_MW_CW

Dependencies:   mbed

Committer:
martwerl
Date:
Thu Nov 15 17:59:08 2018 +0000
Revision:
1:ff38e3bad33a
Parent:
0:afeca64a6543
Diplomarbeit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
martwerl 0:afeca64a6543 1 /* mbed Microcontroller Library
martwerl 0:afeca64a6543 2 * Copyright (c) 2006-2013 ARM Limited
martwerl 0:afeca64a6543 3 *
martwerl 0:afeca64a6543 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
martwerl 0:afeca64a6543 5 * of this software and associated documentation files (the "Software"), to deal
martwerl 0:afeca64a6543 6 * in the Software without restriction, including without limitation the rights
martwerl 0:afeca64a6543 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
martwerl 0:afeca64a6543 8 * copies of the Software, and to permit persons to whom the Software is
martwerl 0:afeca64a6543 9 * furnished to do so, subject to the following conditions:
martwerl 0:afeca64a6543 10 *
martwerl 0:afeca64a6543 11 * The above copyright notice and this permission notice shall be included in
martwerl 0:afeca64a6543 12 * all copies or substantial portions of the Software.
martwerl 0:afeca64a6543 13 *
martwerl 0:afeca64a6543 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
martwerl 0:afeca64a6543 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
martwerl 0:afeca64a6543 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
martwerl 0:afeca64a6543 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
martwerl 0:afeca64a6543 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
martwerl 0:afeca64a6543 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
martwerl 0:afeca64a6543 20 * SOFTWARE.
martwerl 0:afeca64a6543 21 */
martwerl 0:afeca64a6543 22 #ifndef MBED_DIGITALIN_H
martwerl 0:afeca64a6543 23 #define MBED_DIGITALIN_H
martwerl 0:afeca64a6543 24
martwerl 0:afeca64a6543 25 #include "platform.h"
martwerl 0:afeca64a6543 26
martwerl 0:afeca64a6543 27 #include "gpio_api.h"
martwerl 0:afeca64a6543 28
martwerl 0:afeca64a6543 29 namespace mbed {
martwerl 0:afeca64a6543 30
martwerl 0:afeca64a6543 31 /** A digital input, used for reading the state of a pin
martwerl 0:afeca64a6543 32 *
martwerl 0:afeca64a6543 33 * Example:
martwerl 0:afeca64a6543 34 * @code
martwerl 0:afeca64a6543 35 * // Flash an LED while a DigitalIn is true
martwerl 0:afeca64a6543 36 *
martwerl 0:afeca64a6543 37 * #include "mbed.h"
martwerl 0:afeca64a6543 38 *
martwerl 0:afeca64a6543 39 * DigitalIn enable(p5);
martwerl 0:afeca64a6543 40 * DigitalOut led(LED1);
martwerl 0:afeca64a6543 41 *
martwerl 0:afeca64a6543 42 * int main() {
martwerl 0:afeca64a6543 43 * while(1) {
martwerl 0:afeca64a6543 44 * if(enable) {
martwerl 0:afeca64a6543 45 * led = !led;
martwerl 0:afeca64a6543 46 * }
martwerl 0:afeca64a6543 47 * wait(0.25);
martwerl 0:afeca64a6543 48 * }
martwerl 0:afeca64a6543 49 * }
martwerl 0:afeca64a6543 50 * @endcode
martwerl 0:afeca64a6543 51 */
martwerl 0:afeca64a6543 52 class DigitalIn {
martwerl 0:afeca64a6543 53
martwerl 0:afeca64a6543 54 public:
martwerl 0:afeca64a6543 55 /** Create a DigitalIn connected to the specified pin
martwerl 0:afeca64a6543 56 *
martwerl 0:afeca64a6543 57 * @param pin DigitalIn pin to connect to
martwerl 0:afeca64a6543 58 * @param name (optional) A string to identify the object
martwerl 0:afeca64a6543 59 */
martwerl 0:afeca64a6543 60 DigitalIn(PinName pin) {
martwerl 0:afeca64a6543 61 gpio_init(&gpio, pin, PIN_INPUT);
martwerl 0:afeca64a6543 62 }
martwerl 0:afeca64a6543 63
martwerl 0:afeca64a6543 64 /** Read the input, represented as 0 or 1 (int)
martwerl 0:afeca64a6543 65 *
martwerl 0:afeca64a6543 66 * @returns
martwerl 0:afeca64a6543 67 * An integer representing the state of the input pin,
martwerl 0:afeca64a6543 68 * 0 for logical 0, 1 for logical 1
martwerl 0:afeca64a6543 69 */
martwerl 0:afeca64a6543 70 int read() {
martwerl 0:afeca64a6543 71 return gpio_read(&gpio);
martwerl 0:afeca64a6543 72 }
martwerl 0:afeca64a6543 73
martwerl 0:afeca64a6543 74 /** Set the input pin mode
martwerl 0:afeca64a6543 75 *
martwerl 0:afeca64a6543 76 * @param mode PullUp, PullDown, PullNone, OpenDrain
martwerl 0:afeca64a6543 77 */
martwerl 0:afeca64a6543 78 void mode(PinMode pull) {
martwerl 0:afeca64a6543 79 gpio_mode(&gpio, pull);
martwerl 0:afeca64a6543 80 }
martwerl 0:afeca64a6543 81
martwerl 0:afeca64a6543 82 #ifdef MBED_OPERATORS
martwerl 0:afeca64a6543 83 /** An operator shorthand for read()
martwerl 0:afeca64a6543 84 */
martwerl 0:afeca64a6543 85 operator int() {
martwerl 0:afeca64a6543 86 return read();
martwerl 0:afeca64a6543 87 }
martwerl 0:afeca64a6543 88 #endif
martwerl 0:afeca64a6543 89
martwerl 0:afeca64a6543 90 protected:
martwerl 0:afeca64a6543 91 gpio_t gpio;
martwerl 0:afeca64a6543 92 };
martwerl 0:afeca64a6543 93
martwerl 0:afeca64a6543 94 } // namespace mbed
martwerl 0:afeca64a6543 95
martwerl 0:afeca64a6543 96 #endif
martwerl 0:afeca64a6543 97