dhgdh

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by joey shelton

Committer:
cyberjoey
Date:
Sat Oct 22 01:31:58 2016 +0000
Revision:
9:6bb35cef007d
Parent:
1:55a6170b404f
WORKING

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nexpaq 1:55a6170b404f 1 /* mbed Microcontroller Library
nexpaq 1:55a6170b404f 2 * Copyright (c) 2006-2013 ARM Limited
nexpaq 1:55a6170b404f 3 *
nexpaq 1:55a6170b404f 4 * Licensed under the Apache License, Version 2.0 (the "License");
nexpaq 1:55a6170b404f 5 * you may not use this file except in compliance with the License.
nexpaq 1:55a6170b404f 6 * You may obtain a copy of the License at
nexpaq 1:55a6170b404f 7 *
nexpaq 1:55a6170b404f 8 * http://www.apache.org/licenses/LICENSE-2.0
nexpaq 1:55a6170b404f 9 *
nexpaq 1:55a6170b404f 10 * Unless required by applicable law or agreed to in writing, software
nexpaq 1:55a6170b404f 11 * distributed under the License is distributed on an "AS IS" BASIS,
nexpaq 1:55a6170b404f 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
nexpaq 1:55a6170b404f 13 * See the License for the specific language governing permissions and
nexpaq 1:55a6170b404f 14 * limitations under the License.
nexpaq 1:55a6170b404f 15 */
nexpaq 1:55a6170b404f 16 #ifndef MBED_PORTINOUT_H
nexpaq 1:55a6170b404f 17 #define MBED_PORTINOUT_H
nexpaq 1:55a6170b404f 18
nexpaq 1:55a6170b404f 19 #include "platform.h"
nexpaq 1:55a6170b404f 20
nexpaq 1:55a6170b404f 21 #if DEVICE_PORTINOUT
nexpaq 1:55a6170b404f 22
nexpaq 1:55a6170b404f 23 #include "port_api.h"
nexpaq 1:55a6170b404f 24 #include "critical.h"
nexpaq 1:55a6170b404f 25
nexpaq 1:55a6170b404f 26 namespace mbed {
nexpaq 1:55a6170b404f 27
nexpaq 1:55a6170b404f 28 /** A multiple pin digital in/out used to set/read multiple bi-directional pins
nexpaq 1:55a6170b404f 29 *
nexpaq 1:55a6170b404f 30 * @Note Synchronization level: Interrupt safe
nexpaq 1:55a6170b404f 31 */
nexpaq 1:55a6170b404f 32 class PortInOut {
nexpaq 1:55a6170b404f 33 public:
nexpaq 1:55a6170b404f 34
nexpaq 1:55a6170b404f 35 /** Create an PortInOut, connected to the specified port
nexpaq 1:55a6170b404f 36 *
nexpaq 1:55a6170b404f 37 * @param port Port to connect to (Port0-Port5)
nexpaq 1:55a6170b404f 38 * @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
nexpaq 1:55a6170b404f 39 */
nexpaq 1:55a6170b404f 40 PortInOut(PortName port, int mask = 0xFFFFFFFF) {
nexpaq 1:55a6170b404f 41 core_util_critical_section_enter();
nexpaq 1:55a6170b404f 42 port_init(&_port, port, mask, PIN_INPUT);
nexpaq 1:55a6170b404f 43 core_util_critical_section_exit();
nexpaq 1:55a6170b404f 44 }
nexpaq 1:55a6170b404f 45
nexpaq 1:55a6170b404f 46 /** Write the value to the output port
nexpaq 1:55a6170b404f 47 *
nexpaq 1:55a6170b404f 48 * @param value An integer specifying a bit to write for every corresponding port pin
nexpaq 1:55a6170b404f 49 */
nexpaq 1:55a6170b404f 50 void write(int value) {
nexpaq 1:55a6170b404f 51 port_write(&_port, value);
nexpaq 1:55a6170b404f 52 }
nexpaq 1:55a6170b404f 53
nexpaq 1:55a6170b404f 54 /** Read the value currently output on the port
nexpaq 1:55a6170b404f 55 *
nexpaq 1:55a6170b404f 56 * @returns
nexpaq 1:55a6170b404f 57 * An integer with each bit corresponding to associated port pin setting
nexpaq 1:55a6170b404f 58 */
nexpaq 1:55a6170b404f 59 int read() {
nexpaq 1:55a6170b404f 60 return port_read(&_port);
nexpaq 1:55a6170b404f 61 }
nexpaq 1:55a6170b404f 62
nexpaq 1:55a6170b404f 63 /** Set as an output
nexpaq 1:55a6170b404f 64 */
nexpaq 1:55a6170b404f 65 void output() {
nexpaq 1:55a6170b404f 66 core_util_critical_section_enter();
nexpaq 1:55a6170b404f 67 port_dir(&_port, PIN_OUTPUT);
nexpaq 1:55a6170b404f 68 core_util_critical_section_exit();
nexpaq 1:55a6170b404f 69 }
nexpaq 1:55a6170b404f 70
nexpaq 1:55a6170b404f 71 /** Set as an input
nexpaq 1:55a6170b404f 72 */
nexpaq 1:55a6170b404f 73 void input() {
nexpaq 1:55a6170b404f 74 core_util_critical_section_enter();
nexpaq 1:55a6170b404f 75 port_dir(&_port, PIN_INPUT);
nexpaq 1:55a6170b404f 76 core_util_critical_section_exit();
nexpaq 1:55a6170b404f 77 }
nexpaq 1:55a6170b404f 78
nexpaq 1:55a6170b404f 79 /** Set the input pin mode
nexpaq 1:55a6170b404f 80 *
nexpaq 1:55a6170b404f 81 * @param mode PullUp, PullDown, PullNone, OpenDrain
nexpaq 1:55a6170b404f 82 */
nexpaq 1:55a6170b404f 83 void mode(PinMode mode) {
nexpaq 1:55a6170b404f 84 core_util_critical_section_enter();
nexpaq 1:55a6170b404f 85 port_mode(&_port, mode);
nexpaq 1:55a6170b404f 86 core_util_critical_section_exit();
nexpaq 1:55a6170b404f 87 }
nexpaq 1:55a6170b404f 88
nexpaq 1:55a6170b404f 89 /** A shorthand for write()
nexpaq 1:55a6170b404f 90 */
nexpaq 1:55a6170b404f 91 PortInOut& operator= (int value) {
nexpaq 1:55a6170b404f 92 write(value);
nexpaq 1:55a6170b404f 93 return *this;
nexpaq 1:55a6170b404f 94 }
nexpaq 1:55a6170b404f 95
nexpaq 1:55a6170b404f 96 PortInOut& operator= (PortInOut& rhs) {
nexpaq 1:55a6170b404f 97 write(rhs.read());
nexpaq 1:55a6170b404f 98 return *this;
nexpaq 1:55a6170b404f 99 }
nexpaq 1:55a6170b404f 100
nexpaq 1:55a6170b404f 101 /** A shorthand for read()
nexpaq 1:55a6170b404f 102 */
nexpaq 1:55a6170b404f 103 operator int() {
nexpaq 1:55a6170b404f 104 return read();
nexpaq 1:55a6170b404f 105 }
nexpaq 1:55a6170b404f 106
nexpaq 1:55a6170b404f 107 private:
nexpaq 1:55a6170b404f 108 port_t _port;
nexpaq 1:55a6170b404f 109 };
nexpaq 1:55a6170b404f 110
nexpaq 1:55a6170b404f 111 } // namespace mbed
nexpaq 1:55a6170b404f 112
nexpaq 1:55a6170b404f 113 #endif
nexpaq 1:55a6170b404f 114
nexpaq 1:55a6170b404f 115 #endif