mbed-drivers
PwmOut.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_PWMOUT_H
18 #define MBED_PWMOUT_H
19 
20 #include "platform.h"
21 
22 #if DEVICE_PWMOUT
23 #include "pwmout_api.h"
24 
25 namespace mbed {
26 
54 class PwmOut {
55 
56 public:
57 
62  PwmOut(PinName pin) {
63  pwmout_init(&_pwm, pin);
64  }
65 
73  void write(float value) {
74  pwmout_write(&_pwm, value);
75  }
76 
87  float read() {
88  return pwmout_read(&_pwm);
89  }
90 
97  void period(float seconds) {
98  pwmout_period(&_pwm, seconds);
99  }
100 
103  void period_ms(int ms) {
104  pwmout_period_ms(&_pwm, ms);
105  }
106 
109  void period_us(int us) {
110  pwmout_period_us(&_pwm, us);
111  }
112 
115  void pulsewidth(float seconds) {
116  pwmout_pulsewidth(&_pwm, seconds);
117  }
118 
121  void pulsewidth_ms(int ms) {
122  pwmout_pulsewidth_ms(&_pwm, ms);
123  }
124 
127  void pulsewidth_us(int us) {
128  pwmout_pulsewidth_us(&_pwm, us);
129  }
130 
131 #ifdef MBED_OPERATORS
132 
134  PwmOut& operator= (float value) {
135  write(value);
136  return *this;
137  }
138 
139  PwmOut& operator= (PwmOut& rhs) {
140  write(rhs.read());
141  return *this;
142  }
143 
146  operator float() {
147  return read();
148  }
149 #endif
150 
151 protected:
152  pwmout_t _pwm;
153 };
154 
155 } // namespace mbed
156 
157 #endif
158 
159 #endif
void pulsewidth_ms(int ms)
Definition: PwmOut.h:121
void write(float value)
Definition: PwmOut.h:73
void period_us(int us)
Definition: PwmOut.h:109
float read()
Definition: PwmOut.h:87
void period_ms(int ms)
Definition: PwmOut.h:103
Definition: PwmOut.h:54
void pulsewidth_us(int us)
Definition: PwmOut.h:127
PwmOut(PinName pin)
Definition: PwmOut.h:62
void period(float seconds)
Definition: PwmOut.h:97
void pulsewidth(float seconds)
Definition: PwmOut.h:115
PwmOut & operator=(float value)
Definition: PwmOut.h:134
Definition: BusIn.cpp:19