change some io settings for TWR-K22F-120M

Dependents:   twr_helloworld

Committer:
Jasper_lee
Date:
Tue Dec 23 03:35:08 2014 +0000
Revision:
0:b16d94660a33
change some io setting used in TWR-K22F120M

Who changed what in which revision?

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