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_read_period_us reads the PWM period specified in microseconds
48  * * ::pwmout_pulsewidth sets the PWM pulsewidth specified in seconds, keeping the period the same
49  * * ::pwmout_pulsewidth_ms sets the PWM pulsewidth specified in miliseconds, keeping the period the same
50  * * ::pwmout_pulsewidth_us sets the PWM pulsewidth specified in microseconds, keeping the period the same
51  * * ::pwmout_read_pulsewidth_us read the PWM pulsewidth specified in microseconds
52  * * The accuracy of the PWM is +/- 10%
53  * * The PWM operations ::pwmout_write, ::pwmout_read, ::pwmout_read, ::pwmout_period_ms, ::pwmout_period_us
54  * ::pwmout_pulsewidth, ::pwmout_pulsewidth_ms, ::pwmout_pulsewidth_us take less than 20us to complete
55  *
56  * # Undefined behavior
57  * * Calling other function before ::pwmout_init
58  * * Calling ::pwmout_init with NC as pwmout pin
59  *
60  * @{
61  */
62 
63 /**
64  * \defgroup hal_pwmout_tests GPIO IRQ HAL tests
65  * The Pwmout HAL tests ensure driver conformance to defined behaviour.
66  *
67  * To run the Pwmout hal tests use the command:
68  *
69  * mbed test -t <toolchain> -m <target> -n tests-mbed_hal_fpga_ci_test_shield-pwm
70  *
71  */
72 
73 /** Initialize the pwm out peripheral and configure the pin
74  *
75  * @param obj The pwmout object to initialize
76  * @param pinmap pointer to structure which holds static pinmap
77  */
78 void pwmout_init_direct(pwmout_t *obj, const PinMap *pinmap);
79 
80 /** Initialize the pwm out peripheral and configure the pin
81  *
82  * @param obj The pwmout object to initialize
83  * @param pin The pwmout pin to initialize
84  */
85 void pwmout_init(pwmout_t *obj, PinName pin);
86 
87 /** Deinitialize the pwmout object
88  *
89  * @param obj The pwmout object
90  */
91 void pwmout_free(pwmout_t *obj);
92 
93 /** Set the output duty-cycle in range <0.0f, 1.0f>
94  *
95  * Value 0.0f represents 0 percentage, 1.0f represents 100 percent.
96  * @param obj The pwmout object
97  * @param percent The floating-point percentage number
98  */
99 void pwmout_write(pwmout_t *obj, float percent);
100 
101 /** Read the current float-point output duty-cycle
102  *
103  * @param obj The pwmout object
104  * @return A floating-point output duty-cycle
105  */
106 float pwmout_read(pwmout_t *obj);
107 
108 /** Set the PWM period specified in seconds, keeping the duty cycle the same
109  *
110  * Periods smaller than microseconds (the lowest resolution) are set to zero.
111  * @param obj The pwmout object
112  * @param seconds The floating-point seconds period
113  */
114 void pwmout_period(pwmout_t *obj, float seconds);
115 
116 /** Set the PWM period specified in miliseconds, keeping the duty cycle the same
117  *
118  * @param obj The pwmout object
119  * @param ms The milisecond period
120  */
121 void pwmout_period_ms(pwmout_t *obj, int ms);
122 
123 /** Set the PWM period specified in microseconds, keeping the duty cycle the same
124  *
125  * @param obj The pwmout object
126  * @param us The microsecond period
127  */
128 void pwmout_period_us(pwmout_t *obj, int us);
129 
130 /** Read the PWM period specified in microseconds
131  *
132  * @param obj The pwmout object
133  * @return A int output period
134  */
136 
137 /** Set the PWM pulsewidth specified in seconds, keeping the period the same.
138  *
139  * @param obj The pwmout object
140  * @param seconds The floating-point pulsewidth in seconds
141  */
142 void pwmout_pulsewidth(pwmout_t *obj, float seconds);
143 
144 /** Set the PWM pulsewidth specified in miliseconds, keeping the period the same.
145  *
146  * @param obj The pwmout object
147  * @param ms The floating-point pulsewidth in miliseconds
148  */
149 void pwmout_pulsewidth_ms(pwmout_t *obj, int ms);
150 
151 /** Set the PWM pulsewidth specified in microseconds, keeping the period the same.
152  *
153  * @param obj The pwmout object
154  * @param us The floating-point pulsewidth in microseconds
155  */
156 void pwmout_pulsewidth_us(pwmout_t *obj, int us);
157 
158 /** Read the PWM pulsewidth specified in microseconds
159  *
160  * @param obj The pwmout object
161  * @return A int output pulsewitdth
162  */
164 
165 /** Get the pins that support PWM
166  *
167  * Return a PinMap array of pins that support PWM.
168  * The array is terminated with {NC, NC, 0}.
169  *
170  * @return PinMap array
171  */
172 const PinMap *pwmout_pinmap(void);
173 
174 /**@}*/
175 
176 #ifdef __cplusplus
177 }
178 #endif
179 
180 #endif
181 
182 #endif
183 
184 /** @}*/
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_init_direct(pwmout_t *obj, const PinMap *pinmap)
Initialize the pwm out peripheral and configure the pin.
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.
int pwmout_read_period_us(pwmout_t *obj)
Read the PWM period specified in microseconds.
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:31
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
int pwmout_read_pulsewidth_us(pwmout_t *obj)
Read the PWM pulsewidth specified in microseconds.
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.