Mistake on this page?
Report an issue in GitHub or email us
pwmout_api.h
1 
2 /** \addtogroup hal */
3 /** @{*/
4 /* mbed Microcontroller Library
5  * Copyright (c) 2006-2013 ARM Limited
6  * SPDX-License-Identifier: Apache-2.0
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 #ifndef MBED_PWMOUT_API_H
21 #define MBED_PWMOUT_API_H
22 
23 #include "device.h"
24 #include "pinmap.h"
25 
26 #if DEVICE_PWMOUT
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 /** Pwmout hal structure. pwmout_s is declared in the target's hal
33  */
34 typedef struct pwmout_s pwmout_t;
35 
36 /**
37  * \defgroup hal_pwmout Pwmout hal functions
38  *
39  * # Defined behavior
40  * * ::pwmout_init initializes the pwmout_t control structure
41  * * ::pwmout_free deinitializes the pwmout object
42  * * ::pwmout_write sets the output duty-cycle in range <0.0f, 1.0f>
43  * * ::pwmout_read returns the current float-point output duty-cycle in range <0.0f, 1.0f>
44  * * ::pwmout_period sets the PWM period specified in seconds, keeping the duty cycle the same
45  * * ::pwmout_period_ms sets the PWM period specified in miliseconds, keeping the duty cycle the same
46  * * ::pwmout_period_us sets the PWM period specified in microseconds, keeping the duty cycle the same
47  * * ::pwmout_pulsewidth sets the PWM pulsewidth specified in seconds, keeping the period the same
48  * * ::pwmout_pulsewidth_ms sets the PWM pulsewidth specified in miliseconds, keeping the period the same
49  * * ::pwmout_pulsewidth_us sets the PWM pulsewidth specified in microseconds, keeping the period the same
50  * * The accuracy of the PWM is +/- 10%
51  * * The PWM operations ::pwmout_write, ::pwmout_read, ::pwmout_read, ::pwmout_period_ms, ::pwmout_period_us
52  * ::pwmout_pulsewidth, ::pwmout_pulsewidth_ms, ::pwmout_pulsewidth_us take less than 20us to complete
53  *
54  * # Undefined behavior
55  * * Calling other function before ::pwmout_init
56  * * Calling ::pwmout_init with NC as pwmout pin
57  *
58  * @{
59  */
60 
61 /**
62  * \defgroup hal_pwmout_tests GPIO IRQ HAL tests
63  * The Pwmout HAL tests ensure driver conformance to defined behaviour.
64  *
65  * To run the Pwmout hal tests use the command:
66  *
67  * mbed test -t <toolchain> -m <target> -n tests-mbed_hal_fpga_ci_test_shield-pwm
68  *
69  */
70 
71 /** Initialize the pwm out peripheral and configure the pin
72  *
73  * @param obj The pwmout object to initialize
74  * @param pin The pwmout pin to initialize
75  */
76 void pwmout_init(pwmout_t *obj, PinName pin);
77 
78 /** Deinitialize the pwmout object
79  *
80  * @param obj The pwmout object
81  */
82 void pwmout_free(pwmout_t *obj);
83 
84 /** Set the output duty-cycle in range <0.0f, 1.0f>
85  *
86  * Value 0.0f represents 0 percentage, 1.0f represents 100 percent.
87  * @param obj The pwmout object
88  * @param percent The floating-point percentage number
89  */
90 void pwmout_write(pwmout_t *obj, float percent);
91 
92 /** Read the current float-point output duty-cycle
93  *
94  * @param obj The pwmout object
95  * @return A floating-point output duty-cycle
96  */
97 float pwmout_read(pwmout_t *obj);
98 
99 /** Set the PWM period specified in seconds, keeping the duty cycle the same
100  *
101  * Periods smaller than microseconds (the lowest resolution) are set to zero.
102  * @param obj The pwmout object
103  * @param seconds The floating-point seconds period
104  */
105 void pwmout_period(pwmout_t *obj, float seconds);
106 
107 /** Set the PWM period specified in miliseconds, keeping the duty cycle the same
108  *
109  * @param obj The pwmout object
110  * @param ms The milisecond period
111  */
112 void pwmout_period_ms(pwmout_t *obj, int ms);
113 
114 /** Set the PWM period specified in microseconds, keeping the duty cycle the same
115  *
116  * @param obj The pwmout object
117  * @param us The microsecond period
118  */
119 void pwmout_period_us(pwmout_t *obj, int us);
120 
121 /** Set the PWM pulsewidth specified in seconds, keeping the period the same.
122  *
123  * @param obj The pwmout object
124  * @param seconds The floating-point pulsewidth in seconds
125  */
126 void pwmout_pulsewidth(pwmout_t *obj, float seconds);
127 
128 /** Set the PWM pulsewidth specified in miliseconds, keeping the period the same.
129  *
130  * @param obj The pwmout object
131  * @param ms The floating-point pulsewidth in miliseconds
132  */
133 void pwmout_pulsewidth_ms(pwmout_t *obj, int ms);
134 
135 /** Set the PWM pulsewidth specified in microseconds, keeping the period the same.
136  *
137  * @param obj The pwmout object
138  * @param us The floating-point pulsewidth in microseconds
139  */
140 void pwmout_pulsewidth_us(pwmout_t *obj, int us);
141 
142 /** Get the pins that support PWM
143  *
144  * Return a PinMap array of pins that support PWM.
145  * The array is terminated with {NC, NC, 0}.
146  *
147  * @return PinMap array
148  */
149 const PinMap *pwmout_pinmap(void);
150 
151 /**@}*/
152 
153 #ifdef __cplusplus
154 }
155 #endif
156 
157 #endif
158 
159 #endif
160 
161 /** @}*/
void pwmout_period_us(pwmout_t *obj, int us)
Set the PWM period specified in microseconds, keeping the duty cycle the same.
void pwmout_pulsewidth_ms(pwmout_t *obj, int ms)
Set the PWM pulsewidth specified in miliseconds, keeping the period the same.
void pwmout_write(pwmout_t *obj, float percent)
Set the output duty-cycle in range <0.0f, 1.0f>
void pwmout_pulsewidth_us(pwmout_t *obj, int us)
Set the PWM pulsewidth specified in microseconds, keeping the period the same.
void pwmout_period(pwmout_t *obj, float seconds)
Set the PWM period specified in seconds, keeping the duty cycle the same.
const PinMap * pwmout_pinmap(void)
Get the pins that support PWM.
void pwmout_init(pwmout_t *obj, PinName pin)
Initialize the pwm out peripheral and configure the pin.
void pwmout_period_ms(pwmout_t *obj, int ms)
Set the PWM period specified in miliseconds, keeping the duty cycle the same.
Definition: pinmap.h:30
float pwmout_read(pwmout_t *obj)
Read the current float-point output duty-cycle.
struct pwmout_s pwmout_t
Pwmout hal structure.
Definition: pwmout_api.h:34
void pwmout_pulsewidth(pwmout_t *obj, float seconds)
Set the PWM pulsewidth specified in seconds, keeping the period the same.
void pwmout_free(pwmout_t *obj)
Deinitialize the pwmout object.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.