test

Dependencies:   mbed Watchdog

Dependents:   STM32-MC_node

Committer:
ommpy
Date:
Mon Jul 06 17:18:59 2020 +0530
Revision:
0:d383e2dee0f7
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ommpy 0:d383e2dee0f7 1 /* mbed Microcontroller Library
ommpy 0:d383e2dee0f7 2 * Copyright (c) 2006-2013 ARM Limited
ommpy 0:d383e2dee0f7 3 *
ommpy 0:d383e2dee0f7 4 * Licensed under the Apache License, Version 2.0 (the "License");
ommpy 0:d383e2dee0f7 5 * you may not use this file except in compliance with the License.
ommpy 0:d383e2dee0f7 6 * You may obtain a copy of the License at
ommpy 0:d383e2dee0f7 7 *
ommpy 0:d383e2dee0f7 8 * http://www.apache.org/licenses/LICENSE-2.0
ommpy 0:d383e2dee0f7 9 *
ommpy 0:d383e2dee0f7 10 * Unless required by applicable law or agreed to in writing, software
ommpy 0:d383e2dee0f7 11 * distributed under the License is distributed on an "AS IS" BASIS,
ommpy 0:d383e2dee0f7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ommpy 0:d383e2dee0f7 13 * See the License for the specific language governing permissions and
ommpy 0:d383e2dee0f7 14 * limitations under the License.
ommpy 0:d383e2dee0f7 15 */
ommpy 0:d383e2dee0f7 16 #ifndef MBED_DIGITALIN_H
ommpy 0:d383e2dee0f7 17 #define MBED_DIGITALIN_H
ommpy 0:d383e2dee0f7 18
ommpy 0:d383e2dee0f7 19 #include "platform.h"
ommpy 0:d383e2dee0f7 20
ommpy 0:d383e2dee0f7 21 #include "gpio_api.h"
ommpy 0:d383e2dee0f7 22
ommpy 0:d383e2dee0f7 23 namespace mbed {
ommpy 0:d383e2dee0f7 24
ommpy 0:d383e2dee0f7 25 /** A digital input, used for reading the state of a pin
ommpy 0:d383e2dee0f7 26 *
ommpy 0:d383e2dee0f7 27 * Example:
ommpy 0:d383e2dee0f7 28 * @code
ommpy 0:d383e2dee0f7 29 * // Flash an LED while a DigitalIn is true
ommpy 0:d383e2dee0f7 30 *
ommpy 0:d383e2dee0f7 31 * #include "mbed.h"
ommpy 0:d383e2dee0f7 32 *
ommpy 0:d383e2dee0f7 33 * DigitalIn enable(p5);
ommpy 0:d383e2dee0f7 34 * DigitalOut led(LED1);
ommpy 0:d383e2dee0f7 35 *
ommpy 0:d383e2dee0f7 36 * int main() {
ommpy 0:d383e2dee0f7 37 * while(1) {
ommpy 0:d383e2dee0f7 38 * if(enable) {
ommpy 0:d383e2dee0f7 39 * led = !led;
ommpy 0:d383e2dee0f7 40 * }
ommpy 0:d383e2dee0f7 41 * wait(0.25);
ommpy 0:d383e2dee0f7 42 * }
ommpy 0:d383e2dee0f7 43 * }
ommpy 0:d383e2dee0f7 44 * @endcode
ommpy 0:d383e2dee0f7 45 */
ommpy 0:d383e2dee0f7 46 class DigitalIn {
ommpy 0:d383e2dee0f7 47
ommpy 0:d383e2dee0f7 48 public:
ommpy 0:d383e2dee0f7 49 /** Create a DigitalIn connected to the specified pin
ommpy 0:d383e2dee0f7 50 *
ommpy 0:d383e2dee0f7 51 * @param pin DigitalIn pin to connect to
ommpy 0:d383e2dee0f7 52 */
ommpy 0:d383e2dee0f7 53 DigitalIn(PinName pin) : gpio() {
ommpy 0:d383e2dee0f7 54 gpio_init_in(&gpio, pin);
ommpy 0:d383e2dee0f7 55 }
ommpy 0:d383e2dee0f7 56
ommpy 0:d383e2dee0f7 57 /** Create a DigitalIn connected to the specified pin
ommpy 0:d383e2dee0f7 58 *
ommpy 0:d383e2dee0f7 59 * @param pin DigitalIn pin to connect to
ommpy 0:d383e2dee0f7 60 * @param mode the initial mode of the pin
ommpy 0:d383e2dee0f7 61 */
ommpy 0:d383e2dee0f7 62 DigitalIn(PinName pin, PinMode mode) : gpio() {
ommpy 0:d383e2dee0f7 63 gpio_init_in_ex(&gpio, pin, mode);
ommpy 0:d383e2dee0f7 64 }
ommpy 0:d383e2dee0f7 65 /** Read the input, represented as 0 or 1 (int)
ommpy 0:d383e2dee0f7 66 *
ommpy 0:d383e2dee0f7 67 * @returns
ommpy 0:d383e2dee0f7 68 * An integer representing the state of the input pin,
ommpy 0:d383e2dee0f7 69 * 0 for logical 0, 1 for logical 1
ommpy 0:d383e2dee0f7 70 */
ommpy 0:d383e2dee0f7 71 int read() {
ommpy 0:d383e2dee0f7 72 return gpio_read(&gpio);
ommpy 0:d383e2dee0f7 73 }
ommpy 0:d383e2dee0f7 74
ommpy 0:d383e2dee0f7 75 /** Set the input pin mode
ommpy 0:d383e2dee0f7 76 *
ommpy 0:d383e2dee0f7 77 * @param mode PullUp, PullDown, PullNone, OpenDrain
ommpy 0:d383e2dee0f7 78 */
ommpy 0:d383e2dee0f7 79 void mode(PinMode pull) {
ommpy 0:d383e2dee0f7 80 gpio_mode(&gpio, pull);
ommpy 0:d383e2dee0f7 81 }
ommpy 0:d383e2dee0f7 82
ommpy 0:d383e2dee0f7 83 /** Return the output setting, represented as 0 or 1 (int)
ommpy 0:d383e2dee0f7 84 *
ommpy 0:d383e2dee0f7 85 * @returns
ommpy 0:d383e2dee0f7 86 * Non zero value if pin is connected to uc GPIO
ommpy 0:d383e2dee0f7 87 * 0 if gpio object was initialized with NC
ommpy 0:d383e2dee0f7 88 */
ommpy 0:d383e2dee0f7 89 int is_connected() {
ommpy 0:d383e2dee0f7 90 return gpio_is_connected(&gpio);
ommpy 0:d383e2dee0f7 91 }
ommpy 0:d383e2dee0f7 92
ommpy 0:d383e2dee0f7 93 #ifdef MBED_OPERATORS
ommpy 0:d383e2dee0f7 94 /** An operator shorthand for read()
ommpy 0:d383e2dee0f7 95 */
ommpy 0:d383e2dee0f7 96 operator int() {
ommpy 0:d383e2dee0f7 97 return read();
ommpy 0:d383e2dee0f7 98 }
ommpy 0:d383e2dee0f7 99 #endif
ommpy 0:d383e2dee0f7 100
ommpy 0:d383e2dee0f7 101 protected:
ommpy 0:d383e2dee0f7 102 gpio_t gpio;
ommpy 0:d383e2dee0f7 103 };
ommpy 0:d383e2dee0f7 104
ommpy 0:d383e2dee0f7 105 } // namespace mbed
ommpy 0:d383e2dee0f7 106
ommpy 0:d383e2dee0f7 107 #endif