mbed-drivers
PortOut.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_PORTOUT_H
18 #define MBED_PORTOUT_H
19 
20 #include "platform.h"
21 
22 #if DEVICE_PORTOUT
23 
24 #include "port_api.h"
25 
26 namespace mbed {
50 class PortOut {
51 public:
52 
58  PortOut(PortName port, int mask = 0xFFFFFFFF) {
59  port_init(&_port, port, mask, PIN_OUTPUT);
60  }
61 
66  void write(int value) {
67  port_write(&_port, value);
68  }
69 
75  int read() {
76  return port_read(&_port);
77  }
78 
81  PortOut& operator= (int value) {
82  write(value);
83  return *this;
84  }
85 
86  PortOut& operator= (PortOut& rhs) {
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: PortOut.h:50
PortOut(PortName port, int mask=0xFFFFFFFF)
Definition: PortOut.h:58
PortOut & operator=(int value)
Definition: PortOut.h:81
void write(int value)
Definition: PortOut.h:66
int read()
Definition: PortOut.h:75
Definition: BusIn.cpp:19