mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Mar 20 11:45:07 2014 +0000
Revision:
129:0182c99221bc
Parent:
84:f54042cbc282
Child:
174:8bb9f3a33240
Synchronized with git revision 93e44fb5a5aa010177943aaaec0126ed8b8e014d

Full URL: https://github.com/mbedmicro/mbed/commit/93e44fb5a5aa010177943aaaec0126ed8b8e014d/

[NUCLEO_F302R8] and [NUCLEO_L152RE] updates

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 76:aeb1df146756 1 /* mbed Microcontroller Library
mbed_official 76:aeb1df146756 2 *******************************************************************************
mbed_official 76:aeb1df146756 3 * Copyright (c) 2014, STMicroelectronics
mbed_official 76:aeb1df146756 4 * All rights reserved.
mbed_official 76:aeb1df146756 5 *
mbed_official 76:aeb1df146756 6 * Redistribution and use in source and binary forms, with or without
mbed_official 76:aeb1df146756 7 * modification, are permitted provided that the following conditions are met:
mbed_official 76:aeb1df146756 8 *
mbed_official 76:aeb1df146756 9 * 1. Redistributions of source code must retain the above copyright notice,
mbed_official 76:aeb1df146756 10 * this list of conditions and the following disclaimer.
mbed_official 76:aeb1df146756 11 * 2. Redistributions in binary form must reproduce the above copyright notice,
mbed_official 76:aeb1df146756 12 * this list of conditions and the following disclaimer in the documentation
mbed_official 76:aeb1df146756 13 * and/or other materials provided with the distribution.
mbed_official 76:aeb1df146756 14 * 3. Neither the name of STMicroelectronics nor the names of its contributors
mbed_official 76:aeb1df146756 15 * may be used to endorse or promote products derived from this software
mbed_official 76:aeb1df146756 16 * without specific prior written permission.
mbed_official 76:aeb1df146756 17 *
mbed_official 76:aeb1df146756 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
mbed_official 76:aeb1df146756 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
mbed_official 76:aeb1df146756 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mbed_official 76:aeb1df146756 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
mbed_official 76:aeb1df146756 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
mbed_official 76:aeb1df146756 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
mbed_official 76:aeb1df146756 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
mbed_official 76:aeb1df146756 25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
mbed_official 76:aeb1df146756 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
mbed_official 76:aeb1df146756 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
mbed_official 76:aeb1df146756 28 *******************************************************************************
mbed_official 76:aeb1df146756 29 */
mbed_official 76:aeb1df146756 30 #include "pwmout_api.h"
mbed_official 76:aeb1df146756 31
mbed_official 76:aeb1df146756 32 #include "cmsis.h"
mbed_official 76:aeb1df146756 33 #include "pinmap.h"
mbed_official 76:aeb1df146756 34 #include "error.h"
mbed_official 76:aeb1df146756 35
mbed_official 129:0182c99221bc 36 // TIM5 cannot be used because already used by the us_ticker
mbed_official 76:aeb1df146756 37 static const PinMap PinMap_PWM[] = {
mbed_official 129:0182c99221bc 38 //{PA_0, PWM_5, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM5)}, // TIM5_CH1
mbed_official 129:0182c99221bc 39 {PA_1, PWM_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM2)}, // TIM2_CH2
mbed_official 129:0182c99221bc 40 //{PA_1, PWM_5, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM5)}, // TIM5_CH1
mbed_official 129:0182c99221bc 41 {PA_2, PWM_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM2)}, // TIM2_CH3
mbed_official 129:0182c99221bc 42 //{PA_2, PWM_5, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM5)}, // TIM5_CH3
mbed_official 129:0182c99221bc 43 //{PA_2, PWM_9, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM9)}, // TIM9_CH1
mbed_official 129:0182c99221bc 44 {PA_3, PWM_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM2)}, // TIM2_CH4
mbed_official 129:0182c99221bc 45 //{PA_3, PWM_5, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM5)}, // TIM5_CH4
mbed_official 129:0182c99221bc 46 //{PA_3, PWM_9, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM9)}, // TIM9_CH2
mbed_official 129:0182c99221bc 47 {PA_6, PWM_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM3)}, // TIM3_CH1
mbed_official 129:0182c99221bc 48 //{PA_6, PWM_10, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM10)}, // TIM10_CH1
mbed_official 129:0182c99221bc 49 {PA_7, PWM_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM3)}, // TIM3_CH2
mbed_official 129:0182c99221bc 50 //{PA_7, PWM_11, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM11)}, // TIM11_CH1
mbed_official 129:0182c99221bc 51 {PB_0, PWM_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM3)}, // TIM3_CH3
mbed_official 129:0182c99221bc 52 {PB_1, PWM_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM3)}, // TIM3_CH4
mbed_official 129:0182c99221bc 53 {PB_3, PWM_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM2)}, // TIM2_CH2
mbed_official 129:0182c99221bc 54 {PB_4, PWM_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM3)}, // TIM3_CH1
mbed_official 129:0182c99221bc 55 {PB_5, PWM_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM3)}, // TIM3_CH2
mbed_official 129:0182c99221bc 56 {PB_6, PWM_4, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM4)}, // TIM4_CH1
mbed_official 129:0182c99221bc 57 {PB_7, PWM_4, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM4)}, // TIM4_CH2
mbed_official 129:0182c99221bc 58 {PB_8, PWM_4, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM4)}, // TIM4_CH3
mbed_official 129:0182c99221bc 59 //{PB_8, PWM_10, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM10)}, // TIM10_CH1
mbed_official 129:0182c99221bc 60 {PB_9, PWM_4, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM4)}, // TIM4_CH4
mbed_official 129:0182c99221bc 61 //{PB_9, PWM_11, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM11)}, // TIM11_CH1
mbed_official 129:0182c99221bc 62 {PB_10, PWM_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM2)}, // TIM2_CH3
mbed_official 129:0182c99221bc 63 {PB_11, PWM_2, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM2)}, // TIM2_CH4
mbed_official 129:0182c99221bc 64 {PB_12, PWM_10, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM10)}, // TIM10_CH1
mbed_official 129:0182c99221bc 65 {PB_13, PWM_9, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM9)}, // TIM9_CH1
mbed_official 129:0182c99221bc 66 {PB_14, PWM_9, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM9)}, // TIM9_CH2
mbed_official 129:0182c99221bc 67 {PB_15, PWM_11, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM11)}, // TIM11_CH1
mbed_official 129:0182c99221bc 68 {PC_6, PWM_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM3)}, // TIM3_CH1
mbed_official 129:0182c99221bc 69 {PC_7, PWM_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM3)}, // TIM3_CH2
mbed_official 129:0182c99221bc 70 {PC_8, PWM_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM3)}, // TIM3_CH3
mbed_official 129:0182c99221bc 71 {PC_9, PWM_3, STM_PIN_DATA(GPIO_Mode_AF, GPIO_OType_PP, GPIO_PuPd_UP, GPIO_AF_TIM3)}, // TIM3_CH4
mbed_official 129:0182c99221bc 72 {NC, NC, 0}
mbed_official 76:aeb1df146756 73 };
mbed_official 76:aeb1df146756 74
mbed_official 76:aeb1df146756 75 void pwmout_init(pwmout_t* obj, PinName pin) {
mbed_official 76:aeb1df146756 76 // Get the peripheral name from the pin and assign it to the object
mbed_official 76:aeb1df146756 77 obj->pwm = (PWMName)pinmap_peripheral(pin, PinMap_PWM);
mbed_official 76:aeb1df146756 78
mbed_official 76:aeb1df146756 79 if (obj->pwm == (PWMName)NC) {
mbed_official 76:aeb1df146756 80 error("PWM pinout mapping failed");
mbed_official 76:aeb1df146756 81 }
mbed_official 76:aeb1df146756 82
mbed_official 76:aeb1df146756 83 // Enable TIM clock
mbed_official 76:aeb1df146756 84 if (obj->pwm == PWM_2) RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
mbed_official 76:aeb1df146756 85 if (obj->pwm == PWM_3) RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
mbed_official 84:f54042cbc282 86 if (obj->pwm == PWM_4) RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
mbed_official 129:0182c99221bc 87 if (obj->pwm == PWM_5) RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM5, ENABLE);
mbed_official 129:0182c99221bc 88 if (obj->pwm == PWM_9) RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM9, ENABLE);
mbed_official 129:0182c99221bc 89 if (obj->pwm == PWM_10) RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM10, ENABLE);
mbed_official 129:0182c99221bc 90 if (obj->pwm == PWM_11) RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM11, ENABLE);
mbed_official 84:f54042cbc282 91
mbed_official 76:aeb1df146756 92 // Configure GPIO
mbed_official 76:aeb1df146756 93 pinmap_pinout(pin, PinMap_PWM);
mbed_official 76:aeb1df146756 94
mbed_official 76:aeb1df146756 95 obj->pin = pin;
mbed_official 76:aeb1df146756 96 obj->period = 0;
mbed_official 76:aeb1df146756 97 obj->pulse = 0;
mbed_official 76:aeb1df146756 98
mbed_official 76:aeb1df146756 99 pwmout_period_us(obj, 20000); // 20 ms per default
mbed_official 76:aeb1df146756 100 }
mbed_official 76:aeb1df146756 101
mbed_official 76:aeb1df146756 102 void pwmout_free(pwmout_t* obj) {
mbed_official 76:aeb1df146756 103 TIM_TypeDef *tim = (TIM_TypeDef *)(obj->pwm);
mbed_official 76:aeb1df146756 104 TIM_DeInit(tim);
mbed_official 76:aeb1df146756 105 }
mbed_official 76:aeb1df146756 106
mbed_official 76:aeb1df146756 107 void pwmout_write(pwmout_t* obj, float value) {
mbed_official 76:aeb1df146756 108 TIM_TypeDef *tim = (TIM_TypeDef *)(obj->pwm);
mbed_official 76:aeb1df146756 109 TIM_OCInitTypeDef TIM_OCInitStructure;
mbed_official 129:0182c99221bc 110
mbed_official 76:aeb1df146756 111 if (value < 0.0) {
mbed_official 76:aeb1df146756 112 value = 0.0;
mbed_official 76:aeb1df146756 113 } else if (value > 1.0) {
mbed_official 76:aeb1df146756 114 value = 1.0;
mbed_official 76:aeb1df146756 115 }
mbed_official 84:f54042cbc282 116
mbed_official 76:aeb1df146756 117 obj->pulse = (uint32_t)((float)obj->period * value);
mbed_official 76:aeb1df146756 118
mbed_official 129:0182c99221bc 119 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
mbed_official 76:aeb1df146756 120 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
mbed_official 129:0182c99221bc 121 TIM_OCInitStructure.TIM_Pulse = obj->pulse;
mbed_official 129:0182c99221bc 122 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
mbed_official 76:aeb1df146756 123
mbed_official 129:0182c99221bc 124 // Configure the channels
mbed_official 129:0182c99221bc 125 switch (obj->pin) {
mbed_official 129:0182c99221bc 126 // Channels 1
mbed_official 129:0182c99221bc 127 //case PA_0:
mbed_official 129:0182c99221bc 128 //case PA_1:
mbed_official 129:0182c99221bc 129 //case PA_2:
mbed_official 129:0182c99221bc 130 case PA_6:
mbed_official 129:0182c99221bc 131 //case PA_7:
mbed_official 129:0182c99221bc 132 case PB_4:
mbed_official 129:0182c99221bc 133 case PB_6:
mbed_official 129:0182c99221bc 134 //case PB_8:
mbed_official 129:0182c99221bc 135 //case PB_9:
mbed_official 129:0182c99221bc 136 case PB_12:
mbed_official 129:0182c99221bc 137 case PB_13:
mbed_official 129:0182c99221bc 138 case PB_15:
mbed_official 129:0182c99221bc 139 case PC_6:
mbed_official 129:0182c99221bc 140 TIM_OC1PreloadConfig(tim, TIM_OCPreload_Enable);
mbed_official 129:0182c99221bc 141 TIM_OC1Init(tim, &TIM_OCInitStructure);
mbed_official 129:0182c99221bc 142 break;
mbed_official 129:0182c99221bc 143 // Channels 2
mbed_official 129:0182c99221bc 144 case PA_1:
mbed_official 129:0182c99221bc 145 //case PA_3:
mbed_official 129:0182c99221bc 146 case PA_7:
mbed_official 129:0182c99221bc 147 case PB_3:
mbed_official 129:0182c99221bc 148 case PB_5:
mbed_official 129:0182c99221bc 149 case PB_7:
mbed_official 129:0182c99221bc 150 case PB_14:
mbed_official 129:0182c99221bc 151 case PC_7:
mbed_official 129:0182c99221bc 152 TIM_OC2PreloadConfig(tim, TIM_OCPreload_Enable);
mbed_official 129:0182c99221bc 153 TIM_OC2Init(tim, &TIM_OCInitStructure);
mbed_official 129:0182c99221bc 154 break;
mbed_official 129:0182c99221bc 155 // Channels 3
mbed_official 129:0182c99221bc 156 case PA_2:
mbed_official 129:0182c99221bc 157 case PB_0:
mbed_official 129:0182c99221bc 158 case PB_8:
mbed_official 129:0182c99221bc 159 case PB_10:
mbed_official 129:0182c99221bc 160 case PC_8:
mbed_official 129:0182c99221bc 161 TIM_OC3PreloadConfig(tim, TIM_OCPreload_Enable);
mbed_official 129:0182c99221bc 162 TIM_OC3Init(tim, &TIM_OCInitStructure);
mbed_official 129:0182c99221bc 163 break;
mbed_official 129:0182c99221bc 164 // Channels 4
mbed_official 129:0182c99221bc 165 case PA_3:
mbed_official 129:0182c99221bc 166 case PB_1:
mbed_official 129:0182c99221bc 167 case PB_9:
mbed_official 129:0182c99221bc 168 case PB_11:
mbed_official 129:0182c99221bc 169 case PC_9:
mbed_official 129:0182c99221bc 170 TIM_OC4PreloadConfig(tim, TIM_OCPreload_Enable);
mbed_official 129:0182c99221bc 171 TIM_OC4Init(tim, &TIM_OCInitStructure);
mbed_official 129:0182c99221bc 172 break;
mbed_official 129:0182c99221bc 173 default:
mbed_official 129:0182c99221bc 174 return;
mbed_official 76:aeb1df146756 175 }
mbed_official 76:aeb1df146756 176 }
mbed_official 76:aeb1df146756 177
mbed_official 76:aeb1df146756 178 float pwmout_read(pwmout_t* obj) {
mbed_official 76:aeb1df146756 179 float value = 0;
mbed_official 76:aeb1df146756 180 if (obj->period > 0) {
mbed_official 76:aeb1df146756 181 value = (float)(obj->pulse) / (float)(obj->period);
mbed_official 76:aeb1df146756 182 }
mbed_official 76:aeb1df146756 183 return ((value > 1.0) ? (1.0) : (value));
mbed_official 76:aeb1df146756 184 }
mbed_official 76:aeb1df146756 185
mbed_official 76:aeb1df146756 186 void pwmout_period(pwmout_t* obj, float seconds) {
mbed_official 76:aeb1df146756 187 pwmout_period_us(obj, seconds * 1000000.0f);
mbed_official 76:aeb1df146756 188 }
mbed_official 76:aeb1df146756 189
mbed_official 76:aeb1df146756 190 void pwmout_period_ms(pwmout_t* obj, int ms) {
mbed_official 76:aeb1df146756 191 pwmout_period_us(obj, ms * 1000);
mbed_official 76:aeb1df146756 192 }
mbed_official 76:aeb1df146756 193
mbed_official 76:aeb1df146756 194 void pwmout_period_us(pwmout_t* obj, int us) {
mbed_official 76:aeb1df146756 195 TIM_TypeDef *tim = (TIM_TypeDef *)(obj->pwm);
mbed_official 76:aeb1df146756 196 TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
mbed_official 76:aeb1df146756 197 float dc = pwmout_read(obj);
mbed_official 76:aeb1df146756 198
mbed_official 76:aeb1df146756 199 TIM_Cmd(tim, DISABLE);
mbed_official 76:aeb1df146756 200
mbed_official 76:aeb1df146756 201 obj->period = us;
mbed_official 76:aeb1df146756 202
mbed_official 129:0182c99221bc 203 TIM_TimeBaseStructure.TIM_Period = obj->period - 1;
mbed_official 129:0182c99221bc 204 TIM_TimeBaseStructure.TIM_Prescaler = (uint16_t)(SystemCoreClock / 1000000) - 1; // 1 µs tick
mbed_official 76:aeb1df146756 205 TIM_TimeBaseStructure.TIM_ClockDivision = 0;
mbed_official 129:0182c99221bc 206 TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
mbed_official 76:aeb1df146756 207 TIM_TimeBaseInit(tim, &TIM_TimeBaseStructure);
mbed_official 76:aeb1df146756 208
mbed_official 76:aeb1df146756 209 // Set duty cycle again
mbed_official 76:aeb1df146756 210 pwmout_write(obj, dc);
mbed_official 76:aeb1df146756 211
mbed_official 76:aeb1df146756 212 TIM_ARRPreloadConfig(tim, ENABLE);
mbed_official 76:aeb1df146756 213 TIM_Cmd(tim, ENABLE);
mbed_official 76:aeb1df146756 214 }
mbed_official 76:aeb1df146756 215
mbed_official 76:aeb1df146756 216 void pwmout_pulsewidth(pwmout_t* obj, float seconds) {
mbed_official 76:aeb1df146756 217 pwmout_pulsewidth_us(obj, seconds * 1000000.0f);
mbed_official 76:aeb1df146756 218 }
mbed_official 76:aeb1df146756 219
mbed_official 76:aeb1df146756 220 void pwmout_pulsewidth_ms(pwmout_t* obj, int ms) {
mbed_official 76:aeb1df146756 221 pwmout_pulsewidth_us(obj, ms * 1000);
mbed_official 76:aeb1df146756 222 }
mbed_official 76:aeb1df146756 223
mbed_official 76:aeb1df146756 224 void pwmout_pulsewidth_us(pwmout_t* obj, int us) {
mbed_official 76:aeb1df146756 225 float value = (float)us / (float)obj->period;
mbed_official 76:aeb1df146756 226 pwmout_write(obj, value);
mbed_official 76:aeb1df146756 227 }