mbed-drivers
PortInOut.h
1 /*
2  * Copyright (c) 2006-2016, ARM Limited, All Rights Reserved
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may
6  * not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #ifndef MBED_PORTINOUT_H
18 #define MBED_PORTINOUT_H
19 
20 #include "platform.h"
21 
22 #if DEVICE_PORTINOUT
23 
24 #include "port_api.h"
25 
26 namespace mbed {
27 
30 class PortInOut {
31 public:
32 
38  PortInOut(PortName port, int mask = 0xFFFFFFFF) {
39  port_init(&_port, port, mask, PIN_INPUT);
40  }
41 
46  void write(int value) {
47  port_write(&_port, value);
48  }
49 
55  int read() {
56  return port_read(&_port);
57  }
58 
61  void output() {
62  port_dir(&_port, PIN_OUTPUT);
63  }
64 
67  void input() {
68  port_dir(&_port, PIN_INPUT);
69  }
70 
75  void mode(PinMode mode) {
76  port_mode(&_port, mode);
77  }
78 
81  PortInOut& operator= (int value) {
82  write(value);
83  return *this;
84  }
85 
87  write(rhs.read());
88  return *this;
89  }
90 
93  operator int() {
94  return read();
95  }
96 
97 private:
98  port_t _port;
99 };
100 
101 } // namespace mbed
102 
103 #endif
104 
105 #endif
Definition: PortInOut.h:30
void input()
Definition: PortInOut.h:67
void mode(PinMode mode)
Definition: PortInOut.h:75
int read()
Definition: PortInOut.h:55
void output()
Definition: PortInOut.h:61
PortInOut & operator=(int value)
Definition: PortInOut.h:81
PortInOut(PortName port, int mask=0xFFFFFFFF)
Definition: PortInOut.h:38
Definition: BusIn.cpp:19
void write(int value)
Definition: PortInOut.h:46