2 * Author: Thomas Ingleby <thomas.c.ingleby@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 interface for libmaa
42 typedef struct _pwm* maa_pwm_context;
44 /** Initialise pwm_context, uses board mapping.
46 * @param pin The PWM PIN.
48 * @return maa_pwm_context The returned initialised pwm context
50 maa_pwm_context maa_pwm_init(int pin);
52 /** Initialise pwm_context, raw mode.
54 * @param chipid The chip inwhich the PWM is under in SYSFS
55 * @param pin The PWM PIN.
57 * @return maa_pwm_context The returned initialised pwm context
59 maa_pwm_context maa_pwm_init_raw(int chipid, int pin);
61 /** Set the ouput duty-cycle percentage, as a float
63 * @param pwm The PWM context to use.
64 * @param percentage A floating-point value representing percentage of output.
65 * The value should lie between 0.0f (representing on 0%) and 1.0f
66 * Values above or below this range will be set at either 0.0f or 1.0f.
68 * @return maa_result_t the maa result.
70 maa_result_t maa_pwm_write(maa_pwm_context pwm, float percentage);
72 /** Read the ouput duty-cycle percentage, as a float
74 * @param pwm The PWM context to use.
75 * @return percentage A floating-point value representing percentage of output.
76 * The value should lie between 0.0f (representing on 0%) and 1.0f
77 * Values above or below this range will be set at either 0.0f or 1.0f.
79 float maa_pwm_read(maa_pwm_context pwm);
81 /** Set the PWM period as seconds represented in a float
83 * @param pwm The PWM context to use.
84 * @param seconds Peroid represented as a float in seconds.
86 * @return maa_result_t the maa result.
88 maa_result_t maa_pwm_period(maa_pwm_context pwm, float seconds);
90 /** Set period, milli-oseconds.
92 * @param pwm The PWM context to use.
93 * @param ms milli-seconds for period.
95 * @return maa_result_t the maa result.
97 maa_result_t maa_pwm_period_ms(maa_pwm_context pwm, int ms);
99 /** Set period, microseconds
101 * @param pwm The PWM context to use.
102 * @param ns microseconds as period.
104 * @return maa_result_t the maa result.
106 maa_result_t maa_pwm_period_us(maa_pwm_context pwm, int us);
108 /** Set pulsewidth, As represnted by seconds in a (float).
110 * @param pwm The PWM context to use.
111 * @param seconds The duration of a pulse
113 * @return maa_result_t the maa result.
115 maa_result_t maa_pwm_pulsewidth(maa_pwm_context pwm, float seconds);
117 /** Set pulsewidth, milliseconds
119 * @param pwm The PWM context to use.
120 * @param ms milliseconds for pulsewidth.
122 * @return maa_result_t the maa result.
124 maa_result_t maa_pwm_pulsewidth_ms(maa_pwm_context pwm, int ms);
126 /** Set pulsewidth, microseconds.
128 * @param pwm The PWM context to use.
129 * @param us microseconds for pulsewidth.
131 * @return maa_result_t the maa result.
133 maa_result_t maa_pwm_pulsewidth_us(maa_pwm_context pwm, int us);
135 /** Set the enable status of the PWM pin. None zero will assume on with output being driven.
136 * and 0 will disable the output.
138 * @param pwm The PWM context to use.
139 * @param enable enable status of pin
141 * @return maa_result_t the maa result.
143 maa_result_t maa_pwm_enable(maa_pwm_context pwm, int enable);
145 /** Change ownership of context
147 * @param pwm the context
148 * @param owner ownership , 1 to own
150 maa_result_t maa_pwm_owner(maa_pwm_context pwm, maa_boolean_t owner);
152 /** Close and unexport the PWM pin.
154 * @param pwm The PWM context to use.
156 * @return maa_result_t the maa result.
158 maa_result_t maa_pwm_close(maa_pwm_context pwm);