Describes predefine macros for mbed online compiler (armcc)

Committer:
MACRUM
Date:
Thu Mar 16 21:58:09 2017 +0900
Revision:
6:40e873bbc5f7
Add licence header info

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MACRUM 6:40e873bbc5f7 1 /* mbed Microcontroller Library
MACRUM 6:40e873bbc5f7 2 * Copyright (c) 2006-2013 ARM Limited
MACRUM 6:40e873bbc5f7 3 *
MACRUM 6:40e873bbc5f7 4 * Licensed under the Apache License, Version 2.0 (the "License");
MACRUM 6:40e873bbc5f7 5 * you may not use this file except in compliance with the License.
MACRUM 6:40e873bbc5f7 6 * You may obtain a copy of the License at
MACRUM 6:40e873bbc5f7 7 *
MACRUM 6:40e873bbc5f7 8 * http://www.apache.org/licenses/LICENSE-2.0
MACRUM 6:40e873bbc5f7 9 *
MACRUM 6:40e873bbc5f7 10 * Unless required by applicable law or agreed to in writing, software
MACRUM 6:40e873bbc5f7 11 * distributed under the License is distributed on an "AS IS" BASIS,
MACRUM 6:40e873bbc5f7 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
MACRUM 6:40e873bbc5f7 13 * See the License for the specific language governing permissions and
MACRUM 6:40e873bbc5f7 14 * limitations under the License.
MACRUM 6:40e873bbc5f7 15 */
MACRUM 6:40e873bbc5f7 16 #ifndef MBED_DIGITALINOUT_H
MACRUM 6:40e873bbc5f7 17 #define MBED_DIGITALINOUT_H
MACRUM 6:40e873bbc5f7 18
MACRUM 6:40e873bbc5f7 19 #include "platform/platform.h"
MACRUM 6:40e873bbc5f7 20
MACRUM 6:40e873bbc5f7 21 #include "hal/gpio_api.h"
MACRUM 6:40e873bbc5f7 22 #include "platform/mbed_critical.h"
MACRUM 6:40e873bbc5f7 23
MACRUM 6:40e873bbc5f7 24 namespace mbed {
MACRUM 6:40e873bbc5f7 25 /** \addtogroup drivers */
MACRUM 6:40e873bbc5f7 26 /** @{*/
MACRUM 6:40e873bbc5f7 27
MACRUM 6:40e873bbc5f7 28 /** A digital input/output, used for setting or reading a bi-directional pin
MACRUM 6:40e873bbc5f7 29 *
MACRUM 6:40e873bbc5f7 30 * @Note Synchronization level: Interrupt safe
MACRUM 6:40e873bbc5f7 31 */
MACRUM 6:40e873bbc5f7 32 class DigitalInOut {
MACRUM 6:40e873bbc5f7 33
MACRUM 6:40e873bbc5f7 34 public:
MACRUM 6:40e873bbc5f7 35 /** Create a DigitalInOut connected to the specified pin
MACRUM 6:40e873bbc5f7 36 *
MACRUM 6:40e873bbc5f7 37 * @param pin DigitalInOut pin to connect to
MACRUM 6:40e873bbc5f7 38 */
MACRUM 6:40e873bbc5f7 39 DigitalInOut(PinName pin) : gpio() {
MACRUM 6:40e873bbc5f7 40 // No lock needed in the constructor
MACRUM 6:40e873bbc5f7 41 gpio_init_in(&gpio, pin);
MACRUM 6:40e873bbc5f7 42 }
MACRUM 6:40e873bbc5f7 43
MACRUM 6:40e873bbc5f7 44 /** Create a DigitalInOut connected to the specified pin
MACRUM 6:40e873bbc5f7 45 *
MACRUM 6:40e873bbc5f7 46 * @param pin DigitalInOut pin to connect to
MACRUM 6:40e873bbc5f7 47 * @param direction the initial direction of the pin
MACRUM 6:40e873bbc5f7 48 * @param mode the initial mode of the pin
MACRUM 6:40e873bbc5f7 49 * @param value the initial value of the pin if is an output
MACRUM 6:40e873bbc5f7 50 */
MACRUM 6:40e873bbc5f7 51 DigitalInOut(PinName pin, PinDirection direction, PinMode mode, int value) : gpio() {
MACRUM 6:40e873bbc5f7 52 // No lock needed in the constructor
MACRUM 6:40e873bbc5f7 53 gpio_init_inout(&gpio, pin, direction, mode, value);
MACRUM 6:40e873bbc5f7 54 }
MACRUM 6:40e873bbc5f7 55
MACRUM 6:40e873bbc5f7 56 /** Set the output, specified as 0 or 1 (int)
MACRUM 6:40e873bbc5f7 57 *
MACRUM 6:40e873bbc5f7 58 * @param value An integer specifying the pin output value,
MACRUM 6:40e873bbc5f7 59 * 0 for logical 0, 1 (or any other non-zero value) for logical 1
MACRUM 6:40e873bbc5f7 60 */
MACRUM 6:40e873bbc5f7 61 void write(int value) {
MACRUM 6:40e873bbc5f7 62 // Thread safe / atomic HAL call
MACRUM 6:40e873bbc5f7 63 gpio_write(&gpio, value);
MACRUM 6:40e873bbc5f7 64 }
MACRUM 6:40e873bbc5f7 65
MACRUM 6:40e873bbc5f7 66 /** Return the output setting, represented as 0 or 1 (int)
MACRUM 6:40e873bbc5f7 67 *
MACRUM 6:40e873bbc5f7 68 * @returns
MACRUM 6:40e873bbc5f7 69 * an integer representing the output setting of the pin if it is an output,
MACRUM 6:40e873bbc5f7 70 * or read the input if set as an input
MACRUM 6:40e873bbc5f7 71 */
MACRUM 6:40e873bbc5f7 72 int read() {
MACRUM 6:40e873bbc5f7 73 // Thread safe / atomic HAL call
MACRUM 6:40e873bbc5f7 74 return gpio_read(&gpio);
MACRUM 6:40e873bbc5f7 75 }
MACRUM 6:40e873bbc5f7 76
MACRUM 6:40e873bbc5f7 77 /** Set as an output
MACRUM 6:40e873bbc5f7 78 */
MACRUM 6:40e873bbc5f7 79 void output() {
MACRUM 6:40e873bbc5f7 80 core_util_critical_section_enter();
MACRUM 6:40e873bbc5f7 81 gpio_dir(&gpio, PIN_OUTPUT);
MACRUM 6:40e873bbc5f7 82 core_util_critical_section_exit();
MACRUM 6:40e873bbc5f7 83 }
MACRUM 6:40e873bbc5f7 84
MACRUM 6:40e873bbc5f7 85 /** Set as an input
MACRUM 6:40e873bbc5f7 86 */
MACRUM 6:40e873bbc5f7 87 void input() {
MACRUM 6:40e873bbc5f7 88 core_util_critical_section_enter();
MACRUM 6:40e873bbc5f7 89 gpio_dir(&gpio, PIN_INPUT);
MACRUM 6:40e873bbc5f7 90 core_util_critical_section_exit();
MACRUM 6:40e873bbc5f7 91 }
MACRUM 6:40e873bbc5f7 92
MACRUM 6:40e873bbc5f7 93 /** Set the input pin mode
MACRUM 6:40e873bbc5f7 94 *
MACRUM 6:40e873bbc5f7 95 * @param mode PullUp, PullDown, PullNone, OpenDrain
MACRUM 6:40e873bbc5f7 96 */
MACRUM 6:40e873bbc5f7 97 void mode(PinMode pull) {
MACRUM 6:40e873bbc5f7 98 core_util_critical_section_enter();
MACRUM 6:40e873bbc5f7 99 gpio_mode(&gpio, pull);
MACRUM 6:40e873bbc5f7 100 core_util_critical_section_exit();
MACRUM 6:40e873bbc5f7 101 }
MACRUM 6:40e873bbc5f7 102
MACRUM 6:40e873bbc5f7 103 /** Return the output setting, represented as 0 or 1 (int)
MACRUM 6:40e873bbc5f7 104 *
MACRUM 6:40e873bbc5f7 105 * @returns
MACRUM 6:40e873bbc5f7 106 * Non zero value if pin is connected to uc GPIO
MACRUM 6:40e873bbc5f7 107 * 0 if gpio object was initialized with NC
MACRUM 6:40e873bbc5f7 108 */
MACRUM 6:40e873bbc5f7 109 int is_connected() {
MACRUM 6:40e873bbc5f7 110 // Thread safe / atomic HAL call
MACRUM 6:40e873bbc5f7 111 return gpio_is_connected(&gpio);
MACRUM 6:40e873bbc5f7 112 }
MACRUM 6:40e873bbc5f7 113
MACRUM 6:40e873bbc5f7 114 /** A shorthand for write()
MACRUM 6:40e873bbc5f7 115 */
MACRUM 6:40e873bbc5f7 116 DigitalInOut& operator= (int value) {
MACRUM 6:40e873bbc5f7 117 // Underlying write is thread safe
MACRUM 6:40e873bbc5f7 118 write(value);
MACRUM 6:40e873bbc5f7 119 return *this;
MACRUM 6:40e873bbc5f7 120 }
MACRUM 6:40e873bbc5f7 121
MACRUM 6:40e873bbc5f7 122 DigitalInOut& operator= (DigitalInOut& rhs) {
MACRUM 6:40e873bbc5f7 123 core_util_critical_section_enter();
MACRUM 6:40e873bbc5f7 124 write(rhs.read());
MACRUM 6:40e873bbc5f7 125 core_util_critical_section_exit();
MACRUM 6:40e873bbc5f7 126 return *this;
MACRUM 6:40e873bbc5f7 127 }
MACRUM 6:40e873bbc5f7 128
MACRUM 6:40e873bbc5f7 129 /** A shorthand for read()
MACRUM 6:40e873bbc5f7 130 */
MACRUM 6:40e873bbc5f7 131 operator int() {
MACRUM 6:40e873bbc5f7 132 // Underlying call is thread safe
MACRUM 6:40e873bbc5f7 133 return read();
MACRUM 6:40e873bbc5f7 134 }
MACRUM 6:40e873bbc5f7 135
MACRUM 6:40e873bbc5f7 136 protected:
MACRUM 6:40e873bbc5f7 137 gpio_t gpio;
MACRUM 6:40e873bbc5f7 138 };
MACRUM 6:40e873bbc5f7 139
MACRUM 6:40e873bbc5f7 140 } // namespace mbed
MACRUM 6:40e873bbc5f7 141
MACRUM 6:40e873bbc5f7 142 #endif
MACRUM 6:40e873bbc5f7 143
MACRUM 6:40e873bbc5f7 144 /** @}*/