mbed library sources
Dependents: Freedman_v2 Nucleo_i2c_OLED_BME280_copy
Fork of mbed-src by
Diff: targets/hal/TARGET_Maxim/TARGET_MAX32610/pwmout_api.c
- Revision:
- 603:3c75ef011213
- Parent:
- 599:efb83a170500
--- a/targets/hal/TARGET_Maxim/TARGET_MAX32610/pwmout_api.c Wed Aug 05 14:30:08 2015 +0100 +++ b/targets/hal/TARGET_Maxim/TARGET_MAX32610/pwmout_api.c Thu Aug 13 10:30:09 2015 +0100 @@ -52,55 +52,31 @@ // Check if there is a pulse train already active on this port int pin_func = (MXC_GPIO->func_sel[port] & (0xF << (port_pin*4))) >> (port_pin*4); - if((pin_func > 0) && (pin_func < 4)) { - // Search through PinMap_PWM to find the active PT - while(pwm.pin != (PinName)NC) { - if((pwm.pin == pin) && (pwm.function == pin_func)) { - break; - } - pwm = PinMap_PWM[++i]; + MBED_ASSERT((pin_func < 1) || (pin_func > 3)); + + // Search through PinMap_PWM to find the pin + while(pwm.pin != pin) { + pwm = PinMap_PWM[++i]; + } + + // Find a free PT instance on this pin + while(pwm.pin == pin) { + + // Check to see if this PT instance is free + if((((mxc_pt_regs_t*)pwm.peripheral)->rate_length & + MXC_F_PT_RATE_LENGTH_MODE)) { + break; } - } else { - // Search through PinMap_PWM to find an available PT - int i = 0; - while(pwm.pin != (PinName)NC && (i > -1)) { - pwm = PinMap_PWM[i++]; - if(pwm.pin == pin) { - // Check each instance of PT - while(1) { - // Check to see if this PT instance is already in use - if((((mxc_pt_regs_t*)pwm.peripheral)->rate_length & - MXC_F_PT_RATE_LENGTH_MODE)) { - i = -1; - break; - } + pwm = PinMap_PWM[++i]; - // If all instances are in use, overwrite the last - pwm = PinMap_PWM[i++]; - if(pwm.pin != pin) { - pwm = PinMap_PWM[(i-1)]; - i = -1; - break; - } - - } - } - } + // Raise an assertion if we can not allocate another PT instance. + MBED_ASSERT(pwm.pin == pin); } - // Make sure we found an available PWM generator - MBED_ASSERT(pwm.pin != (PinName)NC); - - // Disable all pwm output - MXC_PTG->ctrl = 0; - // Enable the clock MXC_CLKMAN->clk_ctrl_2_pt = MXC_E_CLKMAN_CLK_SCALE_ENABLED; - // Set the drive mode to normal - MXC_SET_FIELD(&MXC_GPIO->out_mode[port], (0x7 << (port_pin*4)), (MXC_V_GPIO_OUT_MODE_NORMAL_DRIVE << (port_pin*4))); - // Set the obj pointer to the propper PWM instance obj->pwm = (mxc_pt_regs_t*)pwm.peripheral; @@ -120,6 +96,9 @@ pwmout_period_us(obj, 20000); pwmout_write (obj, 0); + // Set the drive mode to normal + MXC_SET_FIELD(&MXC_GPIO->out_mode[port], (0x7 << (port_pin*4)), (MXC_V_GPIO_OUT_MODE_NORMAL_DRIVE << (port_pin*4))); + // Enable the global pwm MXC_PTG->ctrl = MXC_F_PT_CTRL_ENABLE_ALL; }