mbed-drivers
AnalogOut.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_ANALOGOUT_H
18 #define MBED_ANALOGOUT_H
19 
20 #include "platform.h"
21 
22 #if DEVICE_ANALOGOUT
23 
24 #include "analogout_api.h"
25 
26 namespace mbed {
27 
48 class AnalogOut {
49 
50 public:
51 
56  AnalogOut(PinName pin) {
57  analogout_init(&_dac, pin);
58  }
59 
67  void write(float value) {
68  analogout_write(&_dac, value);
69  }
70 
76  void write_u16(unsigned short value) {
77  analogout_write_u16(&_dac, value);
78  }
79 
90  float read() {
91  return analogout_read(&_dac);
92  }
93 
94 #ifdef MBED_OPERATORS
95 
97  AnalogOut& operator= (float percent) {
98  write(percent);
99  return *this;
100  }
101 
103  write(rhs.read());
104  return *this;
105  }
106 
109  operator float() {
110  return read();
111  }
112 #endif
113 
114 protected:
115  dac_t _dac;
116 };
117 
118 } // namespace mbed
119 
120 #endif
121 
122 #endif
Definition: AnalogOut.h:48
float read()
Definition: AnalogOut.h:90
void write(float value)
Definition: AnalogOut.h:67
AnalogOut & operator=(float percent)
Definition: AnalogOut.h:97
void write_u16(unsigned short value)
Definition: AnalogOut.h:76
Definition: BusIn.cpp:19
AnalogOut(PinName pin)
Definition: AnalogOut.h:56