2 * Author: Brendan Le Foll <brendan.le.foll@intel.com>
3 * Copyright (c) 2014 Intel Corporation.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 * @brief C++ API to Pulse Width Modulation
34 * This file defines the PWM C++ interface for libmaa
36 * @snippet Pwm3-cycle.cpp Interesting
41 * instanciates a PWM object on a pin
43 * @param pin the pin number used on your board
44 * @param chipid the pwmchip to use, use only in raw mode
45 * @param owner if you are the owner of the pin the destructor will
46 * unexport the pin from sysfs, default behaviour is you are the owner
47 * if the pinmapper exported it
49 Pwm(int pin, int chipid=-1, bool owner = true) {
51 m_pwm = maa_pwm_init(pin);
53 m_pwm = maa_pwm_init_raw(pin, chipid);
55 maa_pwm_owner(m_pwm, 0);
64 * Set the output duty-cycle percentage, as a float
66 * @param percentage A floating-point value representing percentage of
67 * output. The value should lie between 0.0f (representing on 0%) and
68 * 1.0f Values above or below this range will be set at either 0.0f or
70 * @return Result of operation
72 maa_result_t write(float percentage) {
73 return maa_pwm_write(m_pwm, percentage);
76 * Read the ouput duty-cycle percentage, as a float
78 * @return A floating-point value representing percentage of
79 * output. The value should lie between 0.0f (representing on 0%) and
80 * 1.0f Values above or below this range will be set at either 0.0f or
84 return maa_pwm_read(m_pwm);
87 * Set the PWM period as seconds represented in a float
89 * @param period Period represented as a float in seconds
90 * @return Result of operation
92 maa_result_t period(float period) {
93 return maa_pwm_period(m_pwm, period);
96 * Set period, milliseconds
98 * @param ms milliseconds for period
99 * @return Result of operation
101 maa_result_t period_ms(int ms) {
102 return maa_pwm_period_ms(m_pwm, ms);
105 * Set period, microseconds
107 * @param us microseconds as period
108 * @return Result of operation
110 maa_result_t period_us(int us) {
111 return maa_pwm_period_us(m_pwm, us);
114 * Set pulsewidth, As represnted by seconds in a (float)
116 * @param seconds The duration of a pulse
117 * @return Result of operation
119 maa_result_t pulsewidth(float seconds) {
120 return maa_pwm_pulsewidth(m_pwm, seconds);
123 * Set pulsewidth, milliseconds
125 * @param ms milliseconds for pulsewidth
126 * @return Result of operation
128 maa_result_t pulsewidth_ms(int ms) {
129 return maa_pwm_pulsewidth_ms(m_pwm, ms);
132 * The pulsewidth, microseconds
134 * @param us microseconds for pulsewidth
135 * @return Result of operation
137 maa_result_t pulsewidth_us(int us) {
138 return maa_pwm_pulsewidth_us(m_pwm, us);
141 * Set the enable status of the PWM pin. None zero will assume on with
142 * output being driven and 0 will disable the output
144 * @param enable enable status of pin
145 * @return Result of operation
147 maa_result_t enable(bool enable) {
149 return maa_pwm_enable(m_pwm, 1);
151 return maa_pwm_enable(m_pwm, 0);
154 maa_pwm_context m_pwm;