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_PORTOUT_H
Jasper_lee 0:b16d94660a33 17 #define MBED_PORTOUT_H
Jasper_lee 0:b16d94660a33 18
Jasper_lee 0:b16d94660a33 19 #include "platform.h"
Jasper_lee 0:b16d94660a33 20
Jasper_lee 0:b16d94660a33 21 #if DEVICE_PORTOUT
Jasper_lee 0:b16d94660a33 22
Jasper_lee 0:b16d94660a33 23 #include "port_api.h"
Jasper_lee 0:b16d94660a33 24
Jasper_lee 0:b16d94660a33 25 namespace mbed {
Jasper_lee 0:b16d94660a33 26 /** A multiple pin digital out
Jasper_lee 0:b16d94660a33 27 *
Jasper_lee 0:b16d94660a33 28 * Example:
Jasper_lee 0:b16d94660a33 29 * @code
Jasper_lee 0:b16d94660a33 30 * // Toggle all four LEDs
Jasper_lee 0:b16d94660a33 31 *
Jasper_lee 0:b16d94660a33 32 * #include "mbed.h"
Jasper_lee 0:b16d94660a33 33 *
Jasper_lee 0:b16d94660a33 34 * // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23
Jasper_lee 0:b16d94660a33 35 * #define LED_MASK 0x00B40000
Jasper_lee 0:b16d94660a33 36 *
Jasper_lee 0:b16d94660a33 37 * PortOut ledport(Port1, LED_MASK);
Jasper_lee 0:b16d94660a33 38 *
Jasper_lee 0:b16d94660a33 39 * int main() {
Jasper_lee 0:b16d94660a33 40 * while(1) {
Jasper_lee 0:b16d94660a33 41 * ledport = LED_MASK;
Jasper_lee 0:b16d94660a33 42 * wait(1);
Jasper_lee 0:b16d94660a33 43 * ledport = 0;
Jasper_lee 0:b16d94660a33 44 * wait(1);
Jasper_lee 0:b16d94660a33 45 * }
Jasper_lee 0:b16d94660a33 46 * }
Jasper_lee 0:b16d94660a33 47 * @endcode
Jasper_lee 0:b16d94660a33 48 */
Jasper_lee 0:b16d94660a33 49 class PortOut {
Jasper_lee 0:b16d94660a33 50 public:
Jasper_lee 0:b16d94660a33 51
Jasper_lee 0:b16d94660a33 52 /** Create an PortOut, connected to the specified port
Jasper_lee 0:b16d94660a33 53 *
Jasper_lee 0:b16d94660a33 54 * @param port Port to connect to (Port0-Port5)
Jasper_lee 0:b16d94660a33 55 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
Jasper_lee 0:b16d94660a33 56 */
Jasper_lee 0:b16d94660a33 57 PortOut(PortName port, int mask = 0xFFFFFFFF) {
Jasper_lee 0:b16d94660a33 58 port_init(&_port, port, mask, PIN_OUTPUT);
Jasper_lee 0:b16d94660a33 59 }
Jasper_lee 0:b16d94660a33 60
Jasper_lee 0:b16d94660a33 61 /** Write the value to the output port
Jasper_lee 0:b16d94660a33 62 *
Jasper_lee 0:b16d94660a33 63 * @param value An integer specifying a bit to write for every corresponding PortOut pin
Jasper_lee 0:b16d94660a33 64 */
Jasper_lee 0:b16d94660a33 65 void write(int value) {
Jasper_lee 0:b16d94660a33 66 port_write(&_port, value);
Jasper_lee 0:b16d94660a33 67 }
Jasper_lee 0:b16d94660a33 68
Jasper_lee 0:b16d94660a33 69 /** Read the value currently output on the port
Jasper_lee 0:b16d94660a33 70 *
Jasper_lee 0:b16d94660a33 71 * @returns
Jasper_lee 0:b16d94660a33 72 * An integer with each bit corresponding to associated PortOut pin setting
Jasper_lee 0:b16d94660a33 73 */
Jasper_lee 0:b16d94660a33 74 int read() {
Jasper_lee 0:b16d94660a33 75 return port_read(&_port);
Jasper_lee 0:b16d94660a33 76 }
Jasper_lee 0:b16d94660a33 77
Jasper_lee 0:b16d94660a33 78 /** A shorthand for write()
Jasper_lee 0:b16d94660a33 79 */
Jasper_lee 0:b16d94660a33 80 PortOut& operator= (int value) {
Jasper_lee 0:b16d94660a33 81 write(value);
Jasper_lee 0:b16d94660a33 82 return *this;
Jasper_lee 0:b16d94660a33 83 }
Jasper_lee 0:b16d94660a33 84
Jasper_lee 0:b16d94660a33 85 PortOut& operator= (PortOut& rhs) {
Jasper_lee 0:b16d94660a33 86 write(rhs.read());
Jasper_lee 0:b16d94660a33 87 return *this;
Jasper_lee 0:b16d94660a33 88 }
Jasper_lee 0:b16d94660a33 89
Jasper_lee 0:b16d94660a33 90 /** A shorthand for read()
Jasper_lee 0:b16d94660a33 91 */
Jasper_lee 0:b16d94660a33 92 operator int() {
Jasper_lee 0:b16d94660a33 93 return read();
Jasper_lee 0:b16d94660a33 94 }
Jasper_lee 0:b16d94660a33 95
Jasper_lee 0:b16d94660a33 96 private:
Jasper_lee 0:b16d94660a33 97 port_t _port;
Jasper_lee 0:b16d94660a33 98 };
Jasper_lee 0:b16d94660a33 99
Jasper_lee 0:b16d94660a33 100 } // namespace mbed
Jasper_lee 0:b16d94660a33 101
Jasper_lee 0:b16d94660a33 102 #endif
Jasper_lee 0:b16d94660a33 103
Jasper_lee 0:b16d94660a33 104 #endif