aed83b5a1f27f8d010ab151b84e11459db996622
[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 #include <stdio.h>
22 #include <fcntl.h>
23
24 #include "maa.h"
25
26 typedef struct {
27     int chipid, pin;
28     FILE *duty_fp;
29 } pwm_t;
30
31 maa_result_t maa_pwm_init(pwm_t* pwm, int chipin, int pin);
32
33 /** Set the ouput duty-cycle percentage, as a float
34  *
35  *  @param percentage A floating-point value representing percentage of output.
36  *    The value should lie between 0.0f (representing on 0%) and 1.0f
37  *    Values above or below this range will be set at either 0.0f or 1.0f.
38  */
39 void maa_pwm_write(pwm_t* pwm, float percentage);
40
41 /** Read the ouput duty-cycle percentage, as a float
42  *
43  *  @return percentage A floating-point value representing percentage of output.
44  *    The value should lie between 0.0f (representing on 0%) and 1.0f
45  *    Values above or below this range will be set at either 0.0f or 1.0f.
46  */
47 float maa_pwm_read(pwm_t* pwm);
48
49 /** Set the PWM period as seconds represented in a float
50  *
51  *  @param seconds Peroid represented as a float in seconds.
52  */
53 void maa_pwm_period(pwm_t* pwm, float seconds);
54
55 /** Set period. milli-oseconds.
56  *  @param ms milli-seconds for period.
57  */
58 void maa_pwm_period_ms(pwm_t* pwm, int ms);
59
60 /** Set period. microseconds
61  *  @param ns microseconds as period.
62  */
63 void maa_pwm_period_us(pwm_t* pwm, int us);
64
65 /** Set pulsewidth, As represnted by seconds in a (float).
66  *  @param seconds The duration of a pulse
67  */
68 void maa_pwm_pulsewidth(pwm_t* pwm, float seconds);
69
70  /** Set pulsewidth. Milliseconds
71  *  @param ms milliseconds for pulsewidth.
72  */
73 void maa_pwm_pulsewidth_ms(pwm_t* pwm, int ms);
74
75   /** Set pulsewidth, microseconds.
76  *  @param us microseconds for pulsewidth.
77  */
78 void maa_pwm_pulsewidth_us(pwm_t* pwm, int us);
79
80 /** Set the enable status of the PWM pin. None zero will assume on with output being driven.
81  *   and 0 will disable the output.
82  *  @param enable enable status of pin
83  */
84 void maa_pwm_enable(pwm_t* pwm, int enable);
85
86  /** Close and unexport the PWM pin.
87  */
88 void maa_pwm_close(pwm_t* pwm);