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