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 pinmap pointer to structure which holds static pinmap
75  */
76 void pwmout_init_direct(pwmout_t *obj, const PinMap *pinmap);
77 
78 /** Initialize the pwm out peripheral and configure the pin
79  *
80  * @param obj The pwmout object to initialize
81  * @param pin The pwmout pin to initialize
82  */
83 void pwmout_init(pwmout_t *obj, PinName pin);
84 
85 /** Deinitialize the pwmout object
86  *
87  * @param obj The pwmout object
88  */
89 void pwmout_free(pwmout_t *obj);
90 
91 /** Set the output duty-cycle in range <0.0f, 1.0f>
92  *
93  * Value 0.0f represents 0 percentage, 1.0f represents 100 percent.
94  * @param obj The pwmout object
95  * @param percent The floating-point percentage number
96  */
97 void pwmout_write(pwmout_t *obj, float percent);
98 
99 /** Read the current float-point output duty-cycle
100  *
101  * @param obj The pwmout object
102  * @return A floating-point output duty-cycle
103  */
104 float pwmout_read(pwmout_t *obj);
105 
106 /** Set the PWM period specified in seconds, keeping the duty cycle the same
107  *
108  * Periods smaller than microseconds (the lowest resolution) are set to zero.
109  * @param obj The pwmout object
110  * @param seconds The floating-point seconds period
111  */
112 void pwmout_period(pwmout_t *obj, float seconds);
113 
114 /** Set the PWM period specified in miliseconds, keeping the duty cycle the same
115  *
116  * @param obj The pwmout object
117  * @param ms The milisecond period
118  */
119 void pwmout_period_ms(pwmout_t *obj, int ms);
120 
121 /** Set the PWM period specified in microseconds, keeping the duty cycle the same
122  *
123  * @param obj The pwmout object
124  * @param us The microsecond period
125  */
126 void pwmout_period_us(pwmout_t *obj, int us);
127 
128 /** Set the PWM pulsewidth specified in seconds, keeping the period the same.
129  *
130  * @param obj The pwmout object
131  * @param seconds The floating-point pulsewidth in seconds
132  */
133 void pwmout_pulsewidth(pwmout_t *obj, float seconds);
134 
135 /** Set the PWM pulsewidth specified in miliseconds, keeping the period the same.
136  *
137  * @param obj The pwmout object
138  * @param ms The floating-point pulsewidth in miliseconds
139  */
140 void pwmout_pulsewidth_ms(pwmout_t *obj, int ms);
141 
142 /** Set the PWM pulsewidth specified in microseconds, keeping the period the same.
143  *
144  * @param obj The pwmout object
145  * @param us The floating-point pulsewidth in microseconds
146  */
147 void pwmout_pulsewidth_us(pwmout_t *obj, int us);
148 
149 /** Get the pins that support PWM
150  *
151  * Return a PinMap array of pins that support PWM.
152  * The array is terminated with {NC, NC, 0}.
153  *
154  * @return PinMap array
155  */
156 const PinMap *pwmout_pinmap(void);
157 
158 /**@}*/
159 
160 #ifdef __cplusplus
161 }
162 #endif
163 
164 #endif
165 
166 #endif
167 
168 /** @}*/
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.
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
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.