pwm: made export functions static
[contrib/mraa.git] / api / pwm.h
1 /*
2  * Author: Thomas Ingleby <thomas.c.ingleby@intel.com>
3  * Copyright (c) 2014 Intel Corporation.
4  *
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:
12  *
13  * The above copyright notice and this permission notice shall be
14  * included in all copies or substantial portions of the Software.
15  *
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.
23  */
24
25 #pragma once
26
27 /** @file
28  *
29  * This file defines the pwm interface for libmaa
30  *
31  */
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 #include <stdio.h>
38 #include <fcntl.h>
39
40 #include "maa.h"
41
42 typedef struct _pwm* maa_pwm_context;
43
44 /** Initialise pwm_context, uses board mapping.
45  *
46  * @param pin The PWM PIN.
47  *
48  * @return maa_pwm_context The returned initialised pwm context
49  */
50 maa_pwm_context maa_pwm_init(int pin);
51
52 /** Initialise pwm_context, raw mode.
53  *
54  * @param chipid The chip inwhich the PWM is under in SYSFS
55  * @param pin The PWM PIN.
56  *
57  * @return maa_pwm_context The returned initialised pwm context
58  */
59 maa_pwm_context maa_pwm_init_raw(int chipid, int pin);
60
61 /** Set the ouput duty-cycle percentage, as a float
62  *
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.
67  *
68  * @return maa_result_t the maa result.
69  */
70 maa_result_t maa_pwm_write(maa_pwm_context pwm, float percentage);
71
72 /** Read the ouput duty-cycle percentage, as a float
73  *
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.
78  */
79 float maa_pwm_read(maa_pwm_context pwm);
80
81 /** Set the PWM period as seconds represented in a float
82  *
83  * @param pwm The PWM context to use.
84  * @param seconds Peroid represented as a float in seconds.
85  *
86  * @return maa_result_t the maa result.
87  */
88 maa_result_t maa_pwm_period(maa_pwm_context pwm, float seconds);
89
90 /** Set period, milli-oseconds.
91  *
92  * @param pwm The PWM context to use.
93  * @param ms milli-seconds for period.
94  *
95  * @return maa_result_t the maa result.
96  */
97 maa_result_t maa_pwm_period_ms(maa_pwm_context pwm, int ms);
98
99 /** Set period, microseconds
100  *
101  * @param pwm The PWM context to use.
102  * @param ns microseconds as period.
103  *
104  * @return maa_result_t the maa result.
105  */
106 maa_result_t maa_pwm_period_us(maa_pwm_context pwm, int us);
107
108 /** Set pulsewidth, As represnted by seconds in a (float).
109  *
110  * @param pwm The PWM context to use.
111  * @param seconds The duration of a pulse
112  *
113  * @return maa_result_t the maa result.
114  */
115 maa_result_t maa_pwm_pulsewidth(maa_pwm_context pwm, float seconds);
116
117 /** Set pulsewidth, milliseconds
118  *
119  * @param pwm The PWM context to use.
120  * @param ms milliseconds for pulsewidth.
121  *
122  * @return maa_result_t the maa result.
123  */
124 maa_result_t maa_pwm_pulsewidth_ms(maa_pwm_context pwm, int ms);
125
126 /** Set pulsewidth, microseconds.
127  *
128  * @param pwm The PWM context to use.
129  * @param us microseconds for pulsewidth.
130  *
131  * @return maa_result_t the maa result.
132  */
133 maa_result_t maa_pwm_pulsewidth_us(maa_pwm_context pwm, int us);
134
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.
137  *
138  * @param pwm The PWM context to use.
139  * @param enable enable status of pin
140  *
141  * @return maa_result_t the maa result.
142  */
143 maa_result_t maa_pwm_enable(maa_pwm_context pwm, int enable);
144
145 /** Change ownership of context
146  *
147  * @param pwm the context
148  * @param owner ownership , 1 to own
149  */
150 maa_result_t maa_pwm_owner(maa_pwm_context pwm, maa_boolean_t owner);
151
152 /** Close and unexport the PWM pin.
153  *
154  * @param pwm The PWM context to use.
155  *
156  * @return maa_result_t the maa result.
157  */
158 maa_result_t maa_pwm_close(maa_pwm_context pwm);
159
160 #ifdef __cplusplus
161 }
162 #endif