Final version.
Dependencies: F746_GUI F746_SAI_IO UIT_FFT_Real
Fork of F746_Spectrogram by
mbed_src_STM32F7/api/DigitalInOut.h@4:c1beacfc42c7, 2016-10-02 (annotated)
- Committer:
- MikamiUitOpen
- Date:
- Sun Oct 02 10:51:10 2016 +0000
- Revision:
- 4:c1beacfc42c7
5
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MikamiUitOpen | 4:c1beacfc42c7 | 1 | /* mbed Microcontroller Library |
MikamiUitOpen | 4:c1beacfc42c7 | 2 | * Copyright (c) 2006-2013 ARM Limited |
MikamiUitOpen | 4:c1beacfc42c7 | 3 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
MikamiUitOpen | 4:c1beacfc42c7 | 5 | * you may not use this file except in compliance with the License. |
MikamiUitOpen | 4:c1beacfc42c7 | 6 | * You may obtain a copy of the License at |
MikamiUitOpen | 4:c1beacfc42c7 | 7 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
MikamiUitOpen | 4:c1beacfc42c7 | 9 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 10 | * Unless required by applicable law or agreed to in writing, software |
MikamiUitOpen | 4:c1beacfc42c7 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
MikamiUitOpen | 4:c1beacfc42c7 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
MikamiUitOpen | 4:c1beacfc42c7 | 13 | * See the License for the specific language governing permissions and |
MikamiUitOpen | 4:c1beacfc42c7 | 14 | * limitations under the License. |
MikamiUitOpen | 4:c1beacfc42c7 | 15 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 16 | #ifndef MBED_DIGITALINOUT_H |
MikamiUitOpen | 4:c1beacfc42c7 | 17 | #define MBED_DIGITALINOUT_H |
MikamiUitOpen | 4:c1beacfc42c7 | 18 | |
MikamiUitOpen | 4:c1beacfc42c7 | 19 | #include "platform.h" |
MikamiUitOpen | 4:c1beacfc42c7 | 20 | |
MikamiUitOpen | 4:c1beacfc42c7 | 21 | #include "gpio_api.h" |
MikamiUitOpen | 4:c1beacfc42c7 | 22 | |
MikamiUitOpen | 4:c1beacfc42c7 | 23 | namespace mbed { |
MikamiUitOpen | 4:c1beacfc42c7 | 24 | |
MikamiUitOpen | 4:c1beacfc42c7 | 25 | /** A digital input/output, used for setting or reading a bi-directional pin |
MikamiUitOpen | 4:c1beacfc42c7 | 26 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 27 | class DigitalInOut { |
MikamiUitOpen | 4:c1beacfc42c7 | 28 | |
MikamiUitOpen | 4:c1beacfc42c7 | 29 | public: |
MikamiUitOpen | 4:c1beacfc42c7 | 30 | /** Create a DigitalInOut connected to the specified pin |
MikamiUitOpen | 4:c1beacfc42c7 | 31 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 32 | * @param pin DigitalInOut pin to connect to |
MikamiUitOpen | 4:c1beacfc42c7 | 33 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 34 | DigitalInOut(PinName pin) : gpio() { |
MikamiUitOpen | 4:c1beacfc42c7 | 35 | gpio_init_in(&gpio, pin); |
MikamiUitOpen | 4:c1beacfc42c7 | 36 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 37 | |
MikamiUitOpen | 4:c1beacfc42c7 | 38 | /** Create a DigitalInOut connected to the specified pin |
MikamiUitOpen | 4:c1beacfc42c7 | 39 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 40 | * @param pin DigitalInOut pin to connect to |
MikamiUitOpen | 4:c1beacfc42c7 | 41 | * @param direction the initial direction of the pin |
MikamiUitOpen | 4:c1beacfc42c7 | 42 | * @param mode the initial mode of the pin |
MikamiUitOpen | 4:c1beacfc42c7 | 43 | * @param value the initial value of the pin if is an output |
MikamiUitOpen | 4:c1beacfc42c7 | 44 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 45 | DigitalInOut(PinName pin, PinDirection direction, PinMode mode, int value) : gpio() { |
MikamiUitOpen | 4:c1beacfc42c7 | 46 | gpio_init_inout(&gpio, pin, direction, mode, value); |
MikamiUitOpen | 4:c1beacfc42c7 | 47 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 48 | |
MikamiUitOpen | 4:c1beacfc42c7 | 49 | /** Set the output, specified as 0 or 1 (int) |
MikamiUitOpen | 4:c1beacfc42c7 | 50 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 51 | * @param value An integer specifying the pin output value, |
MikamiUitOpen | 4:c1beacfc42c7 | 52 | * 0 for logical 0, 1 (or any other non-zero value) for logical 1 |
MikamiUitOpen | 4:c1beacfc42c7 | 53 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 54 | void write(int value) { |
MikamiUitOpen | 4:c1beacfc42c7 | 55 | gpio_write(&gpio, value); |
MikamiUitOpen | 4:c1beacfc42c7 | 56 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 57 | |
MikamiUitOpen | 4:c1beacfc42c7 | 58 | /** Return the output setting, represented as 0 or 1 (int) |
MikamiUitOpen | 4:c1beacfc42c7 | 59 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 60 | * @returns |
MikamiUitOpen | 4:c1beacfc42c7 | 61 | * an integer representing the output setting of the pin if it is an output, |
MikamiUitOpen | 4:c1beacfc42c7 | 62 | * or read the input if set as an input |
MikamiUitOpen | 4:c1beacfc42c7 | 63 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 64 | int read() { |
MikamiUitOpen | 4:c1beacfc42c7 | 65 | return gpio_read(&gpio); |
MikamiUitOpen | 4:c1beacfc42c7 | 66 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 67 | |
MikamiUitOpen | 4:c1beacfc42c7 | 68 | /** Set as an output |
MikamiUitOpen | 4:c1beacfc42c7 | 69 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 70 | void output() { |
MikamiUitOpen | 4:c1beacfc42c7 | 71 | gpio_dir(&gpio, PIN_OUTPUT); |
MikamiUitOpen | 4:c1beacfc42c7 | 72 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 73 | |
MikamiUitOpen | 4:c1beacfc42c7 | 74 | /** Set as an input |
MikamiUitOpen | 4:c1beacfc42c7 | 75 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 76 | void input() { |
MikamiUitOpen | 4:c1beacfc42c7 | 77 | gpio_dir(&gpio, PIN_INPUT); |
MikamiUitOpen | 4:c1beacfc42c7 | 78 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 79 | |
MikamiUitOpen | 4:c1beacfc42c7 | 80 | /** Set the input pin mode |
MikamiUitOpen | 4:c1beacfc42c7 | 81 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 82 | * @param mode PullUp, PullDown, PullNone, OpenDrain |
MikamiUitOpen | 4:c1beacfc42c7 | 83 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 84 | void mode(PinMode pull) { |
MikamiUitOpen | 4:c1beacfc42c7 | 85 | gpio_mode(&gpio, pull); |
MikamiUitOpen | 4:c1beacfc42c7 | 86 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 87 | |
MikamiUitOpen | 4:c1beacfc42c7 | 88 | /** Return the output setting, represented as 0 or 1 (int) |
MikamiUitOpen | 4:c1beacfc42c7 | 89 | * |
MikamiUitOpen | 4:c1beacfc42c7 | 90 | * @returns |
MikamiUitOpen | 4:c1beacfc42c7 | 91 | * Non zero value if pin is connected to uc GPIO |
MikamiUitOpen | 4:c1beacfc42c7 | 92 | * 0 if gpio object was initialized with NC |
MikamiUitOpen | 4:c1beacfc42c7 | 93 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 94 | int is_connected() { |
MikamiUitOpen | 4:c1beacfc42c7 | 95 | return gpio_is_connected(&gpio); |
MikamiUitOpen | 4:c1beacfc42c7 | 96 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 97 | |
MikamiUitOpen | 4:c1beacfc42c7 | 98 | #ifdef MBED_OPERATORS |
MikamiUitOpen | 4:c1beacfc42c7 | 99 | /** A shorthand for write() |
MikamiUitOpen | 4:c1beacfc42c7 | 100 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 101 | DigitalInOut& operator= (int value) { |
MikamiUitOpen | 4:c1beacfc42c7 | 102 | write(value); |
MikamiUitOpen | 4:c1beacfc42c7 | 103 | return *this; |
MikamiUitOpen | 4:c1beacfc42c7 | 104 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 105 | |
MikamiUitOpen | 4:c1beacfc42c7 | 106 | DigitalInOut& operator= (DigitalInOut& rhs) { |
MikamiUitOpen | 4:c1beacfc42c7 | 107 | write(rhs.read()); |
MikamiUitOpen | 4:c1beacfc42c7 | 108 | return *this; |
MikamiUitOpen | 4:c1beacfc42c7 | 109 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 110 | |
MikamiUitOpen | 4:c1beacfc42c7 | 111 | /** A shorthand for read() |
MikamiUitOpen | 4:c1beacfc42c7 | 112 | */ |
MikamiUitOpen | 4:c1beacfc42c7 | 113 | operator int() { |
MikamiUitOpen | 4:c1beacfc42c7 | 114 | return read(); |
MikamiUitOpen | 4:c1beacfc42c7 | 115 | } |
MikamiUitOpen | 4:c1beacfc42c7 | 116 | #endif |
MikamiUitOpen | 4:c1beacfc42c7 | 117 | |
MikamiUitOpen | 4:c1beacfc42c7 | 118 | protected: |
MikamiUitOpen | 4:c1beacfc42c7 | 119 | gpio_t gpio; |
MikamiUitOpen | 4:c1beacfc42c7 | 120 | }; |
MikamiUitOpen | 4:c1beacfc42c7 | 121 | |
MikamiUitOpen | 4:c1beacfc42c7 | 122 | } // namespace mbed |
MikamiUitOpen | 4:c1beacfc42c7 | 123 | |
MikamiUitOpen | 4:c1beacfc42c7 | 124 | #endif |