Lines Matching +full:pwm +full:- +full:mode
4 * SPDX-License-Identifier: Apache-2.0
10 #include <zephyr/drivers/pwm.h>
30 pwm_mode_t mode; member
46 const struct pwm_mcux_config *config = dev->config; in mcux_pwm_set_cycles_internal()
47 struct pwm_mcux_data *data = dev->data; in mcux_pwm_set_cycles_internal()
56 if (period_cycles != data->period_cycles[channel] in mcux_pwm_set_cycles_internal()
57 || level != data->channel[channel].level) { in mcux_pwm_set_cycles_internal()
61 data->period_cycles[channel] = period_cycles; in mcux_pwm_set_cycles_internal()
63 if (clock_control_get_rate(config->clock_dev, config->clock_subsys, in mcux_pwm_set_cycles_internal()
65 return -EINVAL; in mcux_pwm_set_cycles_internal()
68 data->channel[channel].pwmchannelenable = true; in mcux_pwm_set_cycles_internal()
70 PWM_StopTimer(config->base, 1U << config->index); in mcux_pwm_set_cycles_internal()
75 * setup PWM with higher resolution. in mcux_pwm_set_cycles_internal()
79 data->channel[channel].dutyCyclePercent = 0; in mcux_pwm_set_cycles_internal()
80 data->channel[channel].level = level; in mcux_pwm_set_cycles_internal()
82 status = PWM_SetupPwm(config->base, config->index, in mcux_pwm_set_cycles_internal()
83 &data->channel[channel], 1U, in mcux_pwm_set_cycles_internal()
84 config->mode, 1U, clock_freq); in mcux_pwm_set_cycles_internal()
86 LOG_ERR("Could not set up pwm"); in mcux_pwm_set_cycles_internal()
87 return -ENOTSUP; in mcux_pwm_set_cycles_internal()
90 /* Setup VALx values directly for edge aligned PWM */ in mcux_pwm_set_cycles_internal()
93 PWM_SetVALxValue(config->base, config->index, in mcux_pwm_set_cycles_internal()
96 PWM_SetVALxValue(config->base, config->index, in mcux_pwm_set_cycles_internal()
98 (uint16_t)(period_cycles - 1U)); in mcux_pwm_set_cycles_internal()
99 PWM_SetVALxValue(config->base, config->index, in mcux_pwm_set_cycles_internal()
101 PWM_SetVALxValue(config->base, config->index, in mcux_pwm_set_cycles_internal()
106 PWM_SetVALxValue(config->base, config->index, in mcux_pwm_set_cycles_internal()
109 PWM_SetVALxValue(config->base, config->index, in mcux_pwm_set_cycles_internal()
111 (uint16_t)(period_cycles - 1U)); in mcux_pwm_set_cycles_internal()
112 PWM_SetVALxValue(config->base, config->index, in mcux_pwm_set_cycles_internal()
114 PWM_SetVALxValue(config->base, config->index, in mcux_pwm_set_cycles_internal()
119 PWM_SetPwmLdok(config->base, 1U << config->index, true); in mcux_pwm_set_cycles_internal()
121 PWM_StartTimer(config->base, 1U << config->index); in mcux_pwm_set_cycles_internal()
123 /* Setup VALx values directly for edge aligned PWM */ in mcux_pwm_set_cycles_internal()
126 PWM_SetVALxValue(config->base, config->index, in mcux_pwm_set_cycles_internal()
128 PWM_SetVALxValue(config->base, config->index, in mcux_pwm_set_cycles_internal()
133 PWM_SetVALxValue(config->base, config->index, in mcux_pwm_set_cycles_internal()
135 PWM_SetVALxValue(config->base, config->index, in mcux_pwm_set_cycles_internal()
139 PWM_SetPwmLdok(config->base, 1U << config->index, true); in mcux_pwm_set_cycles_internal()
149 struct pwm_mcux_data *data = dev->data; in mcux_pwm_set_cycles()
154 return -EINVAL; in mcux_pwm_set_cycles()
159 return -ENOTSUP; in mcux_pwm_set_cycles()
163 /* 16-bit resolution */ in mcux_pwm_set_cycles()
164 LOG_ERR("Too long period (%u), adjust pwm prescaler!", in mcux_pwm_set_cycles()
167 return -EINVAL; in mcux_pwm_set_cycles()
169 k_mutex_lock(&data->lock, K_FOREVER); in mcux_pwm_set_cycles()
171 k_mutex_unlock(&data->lock); in mcux_pwm_set_cycles()
178 const struct pwm_mcux_config *config = dev->config; in mcux_pwm_get_cycles_per_sec()
181 if (clock_control_get_rate(config->clock_dev, config->clock_subsys, in mcux_pwm_get_cycles_per_sec()
183 return -EINVAL; in mcux_pwm_get_cycles_per_sec()
185 *cycles = clock_freq >> config->prescale; in mcux_pwm_get_cycles_per_sec()
192 const struct pwm_mcux_config *config = dev->config; in pwm_mcux_init()
193 struct pwm_mcux_data *data = dev->data; in pwm_mcux_init()
198 k_mutex_init(&data->lock); in pwm_mcux_init()
200 if (!device_is_ready(config->clock_dev)) { in pwm_mcux_init()
202 return -ENODEV; in pwm_mcux_init()
205 err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); in pwm_mcux_init()
210 LOG_DBG("Set prescaler %d, reload mode %d", in pwm_mcux_init()
211 1 << config->prescale, config->reload); in pwm_mcux_init()
214 pwm_config.prescale = config->prescale; in pwm_mcux_init()
215 pwm_config.reloadLogic = config->reload; in pwm_mcux_init()
217 pwm_config.enableDebugMode = config->run_debug; in pwm_mcux_init()
219 pwm_config.enableWait = config->run_wait; in pwm_mcux_init()
222 status = PWM_Init(config->base, config->index, &pwm_config); in pwm_mcux_init()
224 LOG_ERR("Unable to init PWM"); in pwm_mcux_init()
225 return -EIO; in pwm_mcux_init()
230 config->base->SM[config->index].DISMAP[i] = 0x0000; in pwm_mcux_init()
233 data->channel[0].pwmChannel = kPWM_PwmA; in pwm_mcux_init()
234 data->channel[0].level = kPWM_HighTrue; in pwm_mcux_init()
235 data->channel[1].pwmChannel = kPWM_PwmB; in pwm_mcux_init()
236 data->channel[1].level = kPWM_HighTrue; in pwm_mcux_init()
241 static DEVICE_API(pwm, pwm_mcux_driver_api) = {
253 .mode = kPWM_EdgeAligned, \