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