Mbed OS Reference
Loading...
Searching...
No Matches
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
29extern "C" {
30#endif
31
32/** Pwmout hal structure. pwmout_s is declared in the target's hal
33 */
34typedef 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 milliseconds, 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 */
78void 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 */
85void pwmout_init(pwmout_t *obj, PinName pin);
86
87/**
88 * @brief Deinitialize the pwmout object
89 *
90 * After this function is called, the PWM output must stop generating edges.
91 * The logic level is not specified -- it may be left high, low, or tristated.
92 *
93 * @param obj The pwmout object
94 */
96
97/** Set the output duty-cycle in range <0.0f, 1.0f>
98 *
99 * Value 0.0f represents 0 percentage, 1.0f represents 100 percent.
100 * @param obj The pwmout object
101 * @param percent The floating-point percentage number
102 */
103void pwmout_write(pwmout_t *obj, float percent);
104
105/** Read the current float-point output duty-cycle
106 *
107 * @param obj The pwmout object
108 * @return A floating-point output duty-cycle
109 */
111
112/** Set the PWM period specified in seconds, keeping the duty cycle the same
113 *
114 * Periods smaller than microseconds (the lowest resolution) are set to zero.
115 * @param obj The pwmout object
116 * @param seconds The floating-point seconds period
117 */
118void pwmout_period(pwmout_t *obj, float seconds);
119
120/** Set the PWM period specified in miliseconds, keeping the duty cycle the same
121 *
122 * @param obj The pwmout object
123 * @param ms The milisecond period
124 */
125void pwmout_period_ms(pwmout_t *obj, int ms);
126
127/** Set the PWM period specified in microseconds, keeping the duty cycle the same
128 *
129 * @param obj The pwmout object
130 * @param us The microsecond period
131 */
132void pwmout_period_us(pwmout_t *obj, int us);
133
134/** Read the PWM period specified in microseconds
135 *
136 * @param obj The pwmout object
137 * @return A int output period
138 */
140
141/** Set the PWM pulsewidth specified in seconds, keeping the period the same.
142 *
143 * @param obj The pwmout object
144 * @param seconds The floating-point pulsewidth in seconds
145 */
146void pwmout_pulsewidth(pwmout_t *obj, float seconds);
147
148/** Set the PWM pulsewidth specified in miliseconds, keeping the period the same.
149 *
150 * @param obj The pwmout object
151 * @param ms The floating-point pulsewidth in miliseconds
152 */
154
155/** Set the PWM pulsewidth specified in microseconds, keeping the period the same.
156 *
157 * @param obj The pwmout object
158 * @param us The floating-point pulsewidth in microseconds
159 */
161
162/** Read the PWM pulsewidth specified in microseconds
163 *
164 * @param obj The pwmout object
165 * @return A int output pulsewidth
166 */
168
169/** Get the pins that support PWM
170 *
171 * Return a PinMap array of pins that support PWM.
172 * The array is terminated with {NC, NC, 0}.
173 *
174 * @return PinMap array
175 */
177
178/**@}*/
179
180#ifdef __cplusplus
181}
182#endif
183
184#endif
185
186#endif
187
188/** @}*/
void pwmout_write(pwmout_t *obj, float percent)
Set the output duty-cycle in range <0.0f, 1.0f>
void pwmout_pulsewidth_ms(pwmout_t *obj, int ms)
Set the PWM pulsewidth specified in miliseconds, keeping the period the same.
void pwmout_init(pwmout_t *obj, PinName pin)
Initialize the pwm out peripheral and configure the pin.
void pwmout_period_us(pwmout_t *obj, int us)
Set the PWM period specified in microseconds, keeping the duty cycle the same.
int pwmout_read_pulsewidth_us(pwmout_t *obj)
Read the PWM pulsewidth specified in microseconds.
float pwmout_read(pwmout_t *obj)
Read the current float-point output duty-cycle.
void pwmout_init_direct(pwmout_t *obj, const PinMap *pinmap)
Initialize the pwm out peripheral and configure the pin.
void pwmout_free(pwmout_t *obj)
Deinitialize the pwmout object.
void pwmout_pulsewidth(pwmout_t *obj, float seconds)
Set the PWM pulsewidth specified in seconds, 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.
void pwmout_period_ms(pwmout_t *obj, int ms)
Set the PWM period specified in miliseconds, keeping the duty cycle the same.
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.
const PinMap * pwmout_pinmap(void)
Get the pins that support PWM.
struct pwmout_s pwmout_t
Pwmout hal structure.
Definition pwmout_api.h:34