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 * @brief Pulse Width Modulation module
31 * PWM is the Pulse Width Modulation interface to libmaa. It allows the
32 * generation of a signal on a pin. Some boards may have higher or lower levels
33 * of resolution so make sure you check the board & pin you are using before
36 * @snippet cycle-pwm3.c Interesting
48 typedef struct _pwm* maa_pwm_context;
51 * Initialise pwm_context, uses board mapping
53 * @param pin The PWM PIN
54 * @return pwm context or NULL
56 maa_pwm_context maa_pwm_init(int pin);
59 * Initialise pwm_context, raw mode
61 * @param chipid The chip inwhich the PWM is under in SYSFS
62 * @param pin The PWM PIN.
63 * @return pwm context or NULL
65 maa_pwm_context maa_pwm_init_raw(int chipid, int pin);
68 * Set the ouput duty-cycle percentage, as a float
70 * @param dev The Pwm context to use
71 * @param percentage A floating-point value representing percentage of output.
72 * The value should lie between 0.0f (representing on 0%) and 1.0f
73 * Values above or below this range will be set at either 0.0f or 1.0f
74 * @return Result of operation
76 maa_result_t maa_pwm_write(maa_pwm_context dev, float percentage);
79 * Read the ouput duty-cycle percentage, as a float
81 * @param dev The Pwm context to use
82 * @return percentage A floating-point value representing percentage of output.
83 * The value should lie between 0.0f (representing on 0%) and 1.0f
84 * Values above or below this range will be set at either 0.0f or 1.0f
86 float maa_pwm_read(maa_pwm_context dev);
89 * Set the PWM period as seconds represented in a float
91 * @param dev The Pwm context to use
92 * @param seconds Period represented as a float in seconds
93 * @return Result of operation
95 maa_result_t maa_pwm_period(maa_pwm_context dev, float seconds);
98 * Set period, milliseconds.
100 * @param dev The Pwm context to use
101 * @param ms Milliseconds for period
102 * @return Result of operation
104 maa_result_t maa_pwm_period_ms(maa_pwm_context dev, int ms);
107 * Set period, microseconds
109 * @param dev The Pwm context to use
110 * @param us Microseconds as period
111 * @return Result of operation
113 maa_result_t maa_pwm_period_us(maa_pwm_context dev, int us);
116 * Set pulsewidth, As represnted by seconds in a (float)
118 * @param dev The Pwm context to use
119 * @param seconds The duration of a pulse
120 * @return Result of operation
122 maa_result_t maa_pwm_pulsewidth(maa_pwm_context dev, float seconds);
125 * Set pulsewidth, milliseconds
127 * @param dev The Pwm context to use
128 * @param ms Milliseconds for pulsewidth
129 * @return Result of operation
131 maa_result_t maa_pwm_pulsewidth_ms(maa_pwm_context dev, int ms);
134 * Set pulsewidth, microseconds
136 * @param dev The Pwm context to use
137 * @param us Microseconds for pulsewidth
138 * @return Result of operation
140 maa_result_t maa_pwm_pulsewidth_us(maa_pwm_context dev, int us);
143 * Set the enable status of the PWM pin. None zero will assume on with output being driven.
144 * and 0 will disable the output.
146 * @param dev The pwm context to use
147 * @param enable Toggle status of pin
148 * @return Result of operation.
150 maa_result_t maa_pwm_enable(maa_pwm_context dev, int enable);
153 * Change ownership of context
155 * @param dev the context
156 * @param owner Ownership boolean
157 * @return Result of operation
159 maa_result_t maa_pwm_owner(maa_pwm_context dev, maa_boolean_t owner);
162 * Close and unexport the PWM pin
164 * @param dev The pwm context to use
165 * @return Result of operation
167 maa_result_t maa_pwm_close(maa_pwm_context dev);