doc: initial documentation of api
[contrib/mraa.git] / api / pwm.h
1 /*
2  * Originally from mbed Microcontroller Library
3  * Copyright (c) 2006-2013 ARM Limited
4  * Copyright (c) 2014 Intel Corporation
5  *
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
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
19 #pragma once
20
21 /** @file
22  *
23  * This file defines the pwm interface for libmaa
24  *
25  */
26
27 #include <stdio.h>
28 #include <fcntl.h>
29
30 #include "maa.h"
31
32 typedef struct {
33     int chipid, pin;
34     FILE *duty_fp;
35 } maa_pwm_context;
36
37 maa_pwm_context* maa_pwm_init(int chipin, int pin);
38
39 /** Set the ouput duty-cycle percentage, as a float
40  *
41  *  @param percentage A floating-point value representing percentage of output.
42  *    The value should lie between 0.0f (representing on 0%) and 1.0f
43  *    Values above or below this range will be set at either 0.0f or 1.0f.
44  */
45 void maa_pwm_write(maa_pwm_context* pwm, float percentage);
46
47 /** Read the ouput duty-cycle percentage, as a float
48  *
49  *  @return percentage A floating-point value representing percentage of output.
50  *    The value should lie between 0.0f (representing on 0%) and 1.0f
51  *    Values above or below this range will be set at either 0.0f or 1.0f.
52  */
53 float maa_pwm_read(maa_pwm_context* pwm);
54
55 /** Set the PWM period as seconds represented in a float
56  *
57  *  @param seconds Peroid represented as a float in seconds.
58  */
59 void maa_pwm_period(maa_pwm_context* pwm, float seconds);
60
61 /** Set period. milli-oseconds.
62  *  @param ms milli-seconds for period.
63  */
64 void maa_pwm_period_ms(maa_pwm_context* pwm, int ms);
65
66 /** Set period. microseconds
67  *  @param ns microseconds as period.
68  */
69 void maa_pwm_period_us(maa_pwm_context* pwm, int us);
70
71 /** Set pulsewidth, As represnted by seconds in a (float).
72  *  @param seconds The duration of a pulse
73  */
74 void maa_pwm_pulsewidth(maa_pwm_context* pwm, float seconds);
75
76  /** Set pulsewidth. Milliseconds
77  *  @param ms milliseconds for pulsewidth.
78  */
79 void maa_pwm_pulsewidth_ms(maa_pwm_context* pwm, int ms);
80
81   /** Set pulsewidth, microseconds.
82  *  @param us microseconds for pulsewidth.
83  */
84 void maa_pwm_pulsewidth_us(maa_pwm_context* pwm, int us);
85
86 /** Set the enable status of the PWM pin. None zero will assume on with output being driven.
87  *   and 0 will disable the output.
88  *  @param enable enable status of pin
89  */
90 void maa_pwm_enable(maa_pwm_context* pwm, int enable);
91
92  /** Close and unexport the PWM pin.
93  */
94 void maa_pwm_close(maa_pwm_context* pwm);