drivers/pwm/pwm_k64_ftm.c
/**
 * @brief API call to set the duty cycle
 *
 * Duty cycle describes the percentage of time a signal is in the ON state.
 *
 * @param dev Device struct
 * @param access_op Access operation (pin or port)
 * @param channel The pwm channel number
 * @param duty Percentage of time signal is on (value between 0 and 100)
 *
 * @return 0 if successful, failed otherwise
 */
@brief API call to set the duty cycle
Duty cycle describes the percentage of time a signal is in the ON state.

@param dev Device struct
@param access_op Access operation (pin or port)
@param channel The pwm channel number
@param duty Percentage of time signal is on (value between 0 and 100)

@return 0 if successful, failed otherwise
@brief API call to set the duty cycle Duty cycle describes the percentage of time a signal is in the ON state . @param dev Device struct @param access_op Access operation ( pin or port ) @param channel The pwm channel number @param duty Percentage of time signal is on ( value between 0 and 100 ) @return 0 if successful failed otherwise
static int pwm_ftm_set_duty_cycle(struct device *dev, int access_op,
				  u32_t channel, u8_t duty)
{
	u32_t on, off;
	const struct pwm_ftm_config * const config =
		dev->config->config_info;
	struct pwm_ftm_drv_data * const drv_data =
		(struct pwm_ftm_drv_data * const)dev->driver_data;
	ARG_UNUSED(access_op);
	SYS_LOG_DBG("...");
	if (duty == 0) {
		on = 0;
		off = 0;
	} else if (duty >= 100) {
		on = 0;
		off = config->period + 1;
	} else {
		on = 0;
		switch (channel) {
		case 0:
			if (config->phase_enable0)
				on = drv_data->phase[0];
			break;
		case 2:
			if (config->phase_enable2)
				on = drv_data->phase[1];
			break;
		case 4:
			if (config->phase_enable4)
				on = drv_data->phase[2];
			break;
		case 6:
			if (config->phase_enable6)
				on = drv_data->phase[3];
			break;
		default:
			break;
		}
		off = on + config->period * duty / 100;
		SYS_LOG_DBG("on=%d, off=%d, period=%d, duty=%d.",
		    on, off, config->period, duty);
		if (off > config->period)
			return  -ENOTSUP;
	}
	return pwm_ftm_set_values(dev, access_op, channel, on, off);
	SYS_LOG_DBG("done.");
}
static int pwm_ftm_set_duty_cycle ( struct device * dev , int access_op , u32_t channel , u8_t duty ) { u32_t on , off ; const struct pwm_ftm_config * const config = dev -> config -> config_info ; struct pwm_ftm_drv_data * const drv_data = ( struct pwm_ftm_drv_data * const ) dev -> driver_data ; ARG_UNUSED ( access_op ) ; SYS_LOG_DBG ( " " ) ; if ( duty == 0 ) { on = 0 ; off = 0 ; } else if ( duty >= 100 ) { on = 0 ; off = config -> period + 1 ; } else { on = 0 ; switch ( channel ) { case 0 : if ( config -> phase_enable0 ) on = drv_data -> phase [ 0 ] ; break ; case 2 : if ( config -> phase_enable2 ) on = drv_data -> phase [ 1 ] ; break ; case 4 : if ( config -> phase_enable4 ) on = drv_data -> phase [ 2 ] ; break ; case 6 : if ( config -> phase_enable6 ) on = drv_data -> phase [ 3 ] ; break ; default : break ; } off = on + config -> period * duty / 100 ; SYS_LOG_DBG ( " " , on , off , config -> period , duty ) ; if ( off > config -> period ) return - ENOTSUP ; } return pwm_ftm_set_values ( dev , access_op , channel , on , off ) ; SYS_LOG_DBG ( " " ) ; }
@brief API call to set the duty cycle
 Duty cycle describes the percentage of time a signal is in the ON state.
@brief API call to set the duty cycle Duty cycle describes the percentage of time a signal is in the ON state .
/* Turn off PWM */ /* Force PWM to be 100% */ /*
		 * Set the "on" value to the phase offset if it was set by
		 * pwm_ftm_set_phase()
		 */ /* Calculate the timer value for when to stop the pulse */ /* check for valid off value */