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.
29 * This file defines the pwm C++ interface for libmaa
39 Pwm(int pin, int chipid=-1, bool owner = true) {
41 m_pwm = maa_pwm_init(pin);
43 m_pwm = maa_pwm_init_raw(pin, chipid);
45 maa_pwm_owner(m_pwm, 0);
50 maa_result_t write(float percentage) {
51 return maa_pwm_write(m_pwm, percentage);
54 return maa_pwm_read(m_pwm);
56 maa_result_t period(float period) {
57 return maa_pwm_period(m_pwm, period);
59 maa_result_t period_ms(int ms) {
60 return maa_pwm_period_ms(m_pwm, ms);
62 maa_result_t period_us(int us) {
63 return maa_pwm_period_us(m_pwm, us);
65 maa_result_t pulsewidth(float seconds) {
66 return maa_pwm_pulsewidth(m_pwm, seconds);
68 maa_result_t pulsewidth_ms(int ms) {
69 return maa_pwm_pulsewidth_ms(m_pwm, ms);
71 maa_result_t pulsewidth_us(int us) {
72 return maa_pwm_pulsewidth_us(m_pwm, us);
74 maa_result_t enable(bool enable) {
76 return maa_pwm_enable(m_pwm, 1);
78 return maa_pwm_enable(m_pwm, 0);
81 maa_pwm_context m_pwm;