Lines Matching +full:reset +full:- +full:pulse +full:- +full:length

4  * SPDX-License-Identifier: Apache-2.0
46 const struct pwm_mcux_sctimer_config *config = dev->config; in mcux_sctimer_new_channel()
47 struct pwm_mcux_sctimer_data *data = dev->data; in mcux_sctimer_new_channel()
51 data->match_period = period_cycles; in mcux_sctimer_new_channel()
53 if (clock_control_get_rate(config->clock_dev, config->clock_subsys, in mcux_sctimer_new_channel()
55 return -EINVAL; in mcux_sctimer_new_channel()
58 pwm_freq = (clock_freq / config->prescale) / period_cycles; in mcux_sctimer_new_channel()
62 return -EINVAL; in mcux_sctimer_new_channel()
65 SCTIMER_StopTimer(config->base, kSCTIMER_Counter_U); in mcux_sctimer_new_channel()
68 data->channel[channel].dutyCyclePercent = duty_cycle; in mcux_sctimer_new_channel()
69 if (SCTIMER_SetupPwm(config->base, &data->channel[channel], in mcux_sctimer_new_channel()
71 clock_freq, &data->event_number[channel]) == kStatus_Fail) { in mcux_sctimer_new_channel()
73 return -ENOTSUP; in mcux_sctimer_new_channel()
76 SCTIMER_StartTimer(config->base, kSCTIMER_Counter_U); in mcux_sctimer_new_channel()
77 data->configured_chan++; in mcux_sctimer_new_channel()
85 const struct pwm_mcux_sctimer_config *config = dev->config; in mcux_sctimer_pwm_set_cycles()
86 struct pwm_mcux_sctimer_data *data = dev->data; in mcux_sctimer_pwm_set_cycles()
92 return -EINVAL; in mcux_sctimer_pwm_set_cycles()
97 return -ENOTSUP; in mcux_sctimer_pwm_set_cycles()
101 data->channel[channel].level = kSCTIMER_HighTrue; in mcux_sctimer_pwm_set_cycles()
103 data->channel[channel].level = kSCTIMER_LowTrue; in mcux_sctimer_pwm_set_cycles()
108 if (duty_cycle == 0 && data->configured_chan == 1) { in mcux_sctimer_pwm_set_cycles()
112 SCT_Type *base = config->base; in mcux_sctimer_pwm_set_cycles()
118 if (data->channel[channel].level == kSCTIMER_HighTrue) { in mcux_sctimer_pwm_set_cycles()
119 base->OUTPUT &= ~(1UL << channel); in mcux_sctimer_pwm_set_cycles()
121 base->OUTPUT |= (1UL << channel); in mcux_sctimer_pwm_set_cycles()
131 * - one match register is used to set PWM output high, and reset in mcux_sctimer_pwm_set_cycles()
133 * - one match register is used to set PWM output low. This sets the in mcux_sctimer_pwm_set_cycles()
134 * pulse length in mcux_sctimer_pwm_set_cycles()
139 if (period_cycles != data->match_period && in mcux_sctimer_pwm_set_cycles()
140 data->event_number[channel] == EVENT_NOT_SET && in mcux_sctimer_pwm_set_cycles()
141 data->match_period == 0U) { in mcux_sctimer_pwm_set_cycles()
150 } else if (data->event_number[channel] == EVENT_NOT_SET) { in mcux_sctimer_pwm_set_cycles()
155 if (period_cycles != data->match_period) { in mcux_sctimer_pwm_set_cycles()
158 return -ENOTSUP; in mcux_sctimer_pwm_set_cycles()
163 } else if (period_cycles != data->match_period) { in mcux_sctimer_pwm_set_cycles()
164 uint32_t period_event = data->event_number[channel]; in mcux_sctimer_pwm_set_cycles()
169 if (data->configured_chan != 1) { in mcux_sctimer_pwm_set_cycles()
172 return -ENOTSUP; in mcux_sctimer_pwm_set_cycles()
177 * (which the SDK will setup as the pulse match event) in mcux_sctimer_pwm_set_cycles()
179 SCTIMER_StopTimer(config->base, kSCTIMER_Counter_U); in mcux_sctimer_pwm_set_cycles()
180 config->base->MATCHREL[period_event] = period_cycles - 1U; in mcux_sctimer_pwm_set_cycles()
181 config->base->MATCHREL[period_event + 1] = pulse_cycles - 1U; in mcux_sctimer_pwm_set_cycles()
182 SCTIMER_StartTimer(config->base, kSCTIMER_Counter_U); in mcux_sctimer_pwm_set_cycles()
183 data->match_period = period_cycles; in mcux_sctimer_pwm_set_cycles()
186 SCTIMER_UpdatePwmDutycycle(config->base, channel, duty_cycle, in mcux_sctimer_pwm_set_cycles()
187 data->event_number[channel]); in mcux_sctimer_pwm_set_cycles()
197 const struct pwm_mcux_sctimer_config *config = dev->config; in mcux_sctimer_pwm_get_cycles_per_sec()
200 if (clock_control_get_rate(config->clock_dev, config->clock_subsys, in mcux_sctimer_pwm_get_cycles_per_sec()
202 return -EINVAL; in mcux_sctimer_pwm_get_cycles_per_sec()
205 *cycles = clock_freq / config->prescale; in mcux_sctimer_pwm_get_cycles_per_sec()
212 const struct pwm_mcux_sctimer_config *config = dev->config; in mcux_sctimer_pwm_init()
213 struct pwm_mcux_sctimer_data *data = dev->data; in mcux_sctimer_pwm_init()
219 err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); in mcux_sctimer_pwm_init()
226 pwm_config.prescale_l = config->prescale - 1; in mcux_sctimer_pwm_init()
228 status = SCTIMER_Init(config->base, &pwm_config); in mcux_sctimer_pwm_init()
231 return -EIO; in mcux_sctimer_pwm_init()
235 data->channel[i].output = i; in mcux_sctimer_pwm_init()
236 data->channel[i].level = kSCTIMER_HighTrue; in mcux_sctimer_pwm_init()
237 data->channel[i].dutyCyclePercent = 0; in mcux_sctimer_pwm_init()
238 data->event_number[i] = EVENT_NOT_SET; in mcux_sctimer_pwm_init()
240 data->match_period = 0; in mcux_sctimer_pwm_init()
241 data->configured_chan = 0; in mcux_sctimer_pwm_init()