mbed-drivers
DigitalOut.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_DIGITALOUT_H
18 #define MBED_DIGITALOUT_H
19 
20 #include "platform.h"
21 #include "gpio_api.h"
22 
23 namespace mbed {
24 
42 class DigitalOut {
43 
44 public:
49  DigitalOut(PinName pin) : gpio() {
50  gpio_init_out(&gpio, pin);
51  }
52 
58  DigitalOut(PinName pin, int value) : gpio() {
59  gpio_init_out_ex(&gpio, pin, value);
60  }
61 
67  void write(int value) {
68  gpio_write(&gpio, value);
69  }
70 
77  int read() {
78  return gpio_read(&gpio);
79  }
80 
81 #ifdef MBED_OPERATORS
82 
84  DigitalOut& operator= (int value) {
85  write(value);
86  return *this;
87  }
88 
90  write(rhs.read());
91  return *this;
92  }
93 
96  operator int() {
97  return read();
98  }
99 #endif
100 
101 protected:
102  gpio_t gpio;
103 };
104 
105 } // namespace mbed
106 
107 #endif
int read()
Definition: DigitalOut.h:77
DigitalOut(PinName pin, int value)
Definition: DigitalOut.h:58
DigitalOut & operator=(int value)
Definition: DigitalOut.h:84
Definition: DigitalOut.h:42
void write(int value)
Definition: DigitalOut.h:67
Definition: BusIn.cpp:19
DigitalOut(PinName pin)
Definition: DigitalOut.h:49