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