1 /** mbed Microcontroller Library
2   ******************************************************************************
3   * @file    pwmout_api.h
4   * @author
5   * @version V1.0.0
6   * @brief   This file provides mbed pwm API
7   ******************************************************************************
8   * @attention
9   *
10   * Copyright (c) 2006-2013 ARM Limited
11   *
12   * Licensed under the Apache License, Version 2.0 (the "License");
13   * you may not use this file except in compliance with the License.
14   * You may obtain a copy of the License at
15   *
16   *     http://www.apache.org/licenses/LICENSE-2.0
17   *
18   * Unless required by applicable law or agreed to in writing, software
19   * distributed under the License is distributed on an "AS IS" BASIS,
20   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21   * See the License for the specific language governing permissions and
22   * limitations under the License.
23   ******************************************************************************
24   */
25 #ifndef MBED_PWMOUT_API_H
26 #define MBED_PWMOUT_API_H
27 
28 #include "device.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /** @addtogroup pwm PWM
35  *  @ingroup    hal
36  *  @brief      pwm functions
37  *  @{
38  */
39 
40 ///@name Ameba Common
41 ///@{
42 
43 typedef struct pwmout_s pwmout_t;
44 /**
45   * @brief  Initializes the PWM function/registers of the specified pin with default parameters.
46   * @param  obj: PWM object define in application software.
47   * @param  pin: the pinname of specified channel to be set.
48   * @retval none
49   * @note
50   *             - default period: 1638us
51   *             - default pulse width: 102us
52   *             - default duty cycle: 6.227%
53   */
54 void pwmout_init(pwmout_t* obj, PinName pin);
55 
56 /**
57   * @brief  Deinitializes the PWM device of the specified channel.
58   * @param  obj: PWM object define in application software.
59   * @retval none
60   * @note  If all channels are released, TIM5 will also be disabled.
61   */
62 void pwmout_free(pwmout_t* obj);
63 
64 /**
65   * @brief  Set the duty cycle of the specified channel.
66   * @param  obj: PWM object define in application software.
67   * @param  percent: The duty cycle value to be set.
68   * @retval none
69   */
70 void pwmout_write(pwmout_t* obj, float percent);
71 
72 /**
73   * @brief  Get the duty cycle value of the specified channel.
74   * @param  obj: PWM object define in application software.
75   * @retval : the duty cycle value of the specified channel.
76   */
77 float pwmout_read(pwmout_t* obj);
78 
79 /**
80   * @brief  Set the period of the specified channel in seconds.
81   * @param  obj: PWM object define in application software.
82   * @param  seconds: The period value to be set in seconds.
83   * @retval none
84   */
85 void pwmout_period(pwmout_t* obj, float seconds);
86 
87 /**
88   * @brief  Set the period of the specified channel in millseconds.
89   * @param  obj: PWM object define in application software.
90   * @param  ms: The period value to be set in millseconds.
91   * @retval none
92   */
93 void pwmout_period_ms(pwmout_t* obj, int ms);
94 
95 /**
96   * @brief  Set the period of the specified channel in microseconds.
97   * @param  obj: PWM object define in application software.
98   * @param  us: The period value to be set in microseconds.
99   * @retval none
100   */
101 void pwmout_period_us(pwmout_t* obj, int us);
102 
103 /**
104   * @brief  Set the pulse width of the specified channel in seconds.
105   * @param  obj: PWM object define in application software.
106   * @param  seconds: The pulse width value to be set in seconds.
107   * @retval none
108   */
109 void pwmout_pulsewidth(pwmout_t* obj, float seconds);
110 
111 /**
112   * @brief  Set the pulse width of the specified channel in milliseconds.
113   * @param  obj: PWM object define in application software.
114   * @param  ms: The pulse width value to be set in milliseconds.
115   * @retval none
116   */
117 void pwmout_pulsewidth_ms(pwmout_t* obj, int ms);
118 
119 /**
120   * @brief  Set the pulse width of the specified channel in microseconds.
121   * @param  obj: PWM object define in application software.
122   * @param  us: The pulse width value to be set in microseconds.
123   * @retval none
124   */
125 void pwmout_pulsewidth_us(pwmout_t* obj, int us);
126 
127 ///@}
128 
129 /*\@}*/
130 
131 #ifdef __cplusplus
132 }
133 #endif
134 
135 #endif
136