2 * Originally from mbed Microcontroller Library
3 * Copyright (c) 2006-2013 ARM Limited
4 * Copyright (c) 2014 Intel Corporation
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
23 * This file defines the pwm interface for libmaa
37 * A strucutre representing a PWM pin
41 int pin; /**< the pin number, as known to the os. */
42 int chipid; /**< the chip id, which the pwm resides */
43 FILE *duty_fp; /**< File pointer to duty file */
47 /** Initialise pwm_context, uses board mapping.
49 * @param pin The PWM PIN.
51 * @return maa_pwm_context The returned initialised pwm context
53 maa_pwm_context* maa_pwm_init(int pin);
55 /** Initialise pwm_context, raw mode.
57 * @param chipid The chip inwhich the PWM is under in SYSFS
58 * @param pin The PWM PIN.
60 * @return maa_pwm_context The returned initialised pwm context
62 maa_pwm_context* maa_pwm_init_raw(int chipid, int pin);
64 /** Set the ouput duty-cycle percentage, as a float
66 * @param pwm The PWM context to use.
67 * @param percentage A floating-point value representing percentage of output.
68 * The value should lie between 0.0f (representing on 0%) and 1.0f
69 * Values above or below this range will be set at either 0.0f or 1.0f.
71 * @return maa_result_t the maa result.
73 maa_result_t maa_pwm_write(maa_pwm_context* pwm, float percentage);
75 /** Read the ouput duty-cycle percentage, as a float
77 * @param pwm The PWM context to use.
78 * @return percentage A floating-point value representing percentage of output.
79 * The value should lie between 0.0f (representing on 0%) and 1.0f
80 * Values above or below this range will be set at either 0.0f or 1.0f.
82 float maa_pwm_read(maa_pwm_context* pwm);
84 /** Set the PWM period as seconds represented in a float
86 * @param pwm The PWM context to use.
87 * @param seconds Peroid represented as a float in seconds.
89 * @return maa_result_t the maa result.
91 maa_result_t maa_pwm_period(maa_pwm_context* pwm, float seconds);
93 /** Set period. milli-oseconds.
95 * @param pwm The PWM context to use.
96 * @param ms milli-seconds for period.
98 * @return maa_result_t the maa result.
100 maa_result_t maa_pwm_period_ms(maa_pwm_context* pwm, int ms);
102 /** Set period. microseconds
104 * @param pwm The PWM context to use.
105 * @param ns microseconds as period.
107 * @return maa_result_t the maa result.
109 maa_result_t maa_pwm_period_us(maa_pwm_context* pwm, int us);
111 /** Set pulsewidth, As represnted by seconds in a (float).
113 * @param pwm The PWM context to use.
114 * @param seconds The duration of a pulse
116 * @return maa_result_t the maa result.
118 maa_result_t maa_pwm_pulsewidth(maa_pwm_context* pwm, float seconds);
120 /** Set pulsewidth. Milliseconds
122 * @param pwm The PWM context to use.
123 * @param ms milliseconds for pulsewidth.
125 * @return maa_result_t the maa result.
127 maa_result_t maa_pwm_pulsewidth_ms(maa_pwm_context* pwm, int ms);
129 /** Set pulsewidth, microseconds.
131 * @param pwm The PWM context to use.
132 * @param us microseconds for pulsewidth.
134 * @return maa_result_t the maa result.
136 maa_result_t maa_pwm_pulsewidth_us(maa_pwm_context* pwm, int us);
138 /** Set the enable status of the PWM pin. None zero will assume on with output being driven.
139 * and 0 will disable the output.
141 * @param pwm The PWM context to use.
142 * @param enable enable status of pin
144 * @return maa_result_t the maa result.
146 maa_result_t maa_pwm_enable(maa_pwm_context* pwm, int enable);
148 /** Close and unexport the PWM pin.
150 * @param pwm The PWM context to use.
152 * @return maa_result_t the maa result.
154 maa_result_t maa_pwm_close(maa_pwm_context* pwm);