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
43 * A strucutre representing a PWM pin
47 int pin; /**< the pin number, as known to the os. */
48 int chipid; /**< the chip id, which the pwm resides */
49 FILE *duty_fp; /**< File pointer to duty file */
53 /** Initialise pwm_context, uses board mapping.
55 * @param pin The PWM PIN.
57 * @return maa_pwm_context The returned initialised pwm context
59 maa_pwm_context* maa_pwm_init(int pin);
61 /** Initialise pwm_context, raw mode.
63 * @param chipid The chip inwhich the PWM is under in SYSFS
64 * @param pin The PWM PIN.
66 * @return maa_pwm_context The returned initialised pwm context
68 maa_pwm_context* maa_pwm_init_raw(int chipid, int pin);
70 /** Set the ouput duty-cycle percentage, as a float
72 * @param pwm The PWM context to use.
73 * @param percentage A floating-point value representing percentage of output.
74 * The value should lie between 0.0f (representing on 0%) and 1.0f
75 * Values above or below this range will be set at either 0.0f or 1.0f.
77 * @return maa_result_t the maa result.
79 maa_result_t maa_pwm_write(maa_pwm_context* pwm, float percentage);
81 /** Read the ouput duty-cycle percentage, as a float
83 * @param pwm The PWM context to use.
84 * @return percentage A floating-point value representing percentage of output.
85 * The value should lie between 0.0f (representing on 0%) and 1.0f
86 * Values above or below this range will be set at either 0.0f or 1.0f.
88 float maa_pwm_read(maa_pwm_context* pwm);
90 /** Set the PWM period as seconds represented in a float
92 * @param pwm The PWM context to use.
93 * @param seconds Peroid represented as a float in seconds.
95 * @return maa_result_t the maa result.
97 maa_result_t maa_pwm_period(maa_pwm_context* pwm, float seconds);
99 /** Set period, milli-oseconds.
101 * @param pwm The PWM context to use.
102 * @param ms milli-seconds for period.
104 * @return maa_result_t the maa result.
106 maa_result_t maa_pwm_period_ms(maa_pwm_context* pwm, int ms);
108 /** Set period, microseconds
110 * @param pwm The PWM context to use.
111 * @param ns microseconds as period.
113 * @return maa_result_t the maa result.
115 maa_result_t maa_pwm_period_us(maa_pwm_context* pwm, int us);
117 /** Set pulsewidth, As represnted by seconds in a (float).
119 * @param pwm The PWM context to use.
120 * @param seconds The duration of a pulse
122 * @return maa_result_t the maa result.
124 maa_result_t maa_pwm_pulsewidth(maa_pwm_context* pwm, float seconds);
126 /** Set pulsewidth, milliseconds
128 * @param pwm The PWM context to use.
129 * @param ms milliseconds for pulsewidth.
131 * @return maa_result_t the maa result.
133 maa_result_t maa_pwm_pulsewidth_ms(maa_pwm_context* pwm, int ms);
135 /** Set pulsewidth, microseconds.
137 * @param pwm The PWM context to use.
138 * @param us microseconds for pulsewidth.
140 * @return maa_result_t the maa result.
142 maa_result_t maa_pwm_pulsewidth_us(maa_pwm_context* pwm, int us);
144 /** Set the enable status of the PWM pin. None zero will assume on with output being driven.
145 * and 0 will disable the output.
147 * @param pwm The PWM context to use.
148 * @param enable enable status of pin
150 * @return maa_result_t the maa result.
152 maa_result_t maa_pwm_enable(maa_pwm_context* pwm, int enable);
154 /** Close and unexport the PWM pin.
156 * @param pwm The PWM context to use.
158 * @return maa_result_t the maa result.
160 maa_result_t maa_pwm_close(maa_pwm_context* pwm);