Lines Matching +full:data +full:- +full:role
4 * SPDX-License-Identifier: Apache-2.0
15 #include <zephyr/dt-bindings/clock/mcux_lpc_syscon_clock.h>
29 enum pwm_ctimer_channel_role role; member
53 static bool mcux_ctimer_pwm_is_period_valid(struct pwm_mcux_ctimer_data *data, in mcux_ctimer_pwm_is_period_valid() argument
58 if (data->channel_states[current_period_channel].cycles == new_period_cycles) { in mcux_ctimer_pwm_is_period_valid()
66 if (data->num_active_pulse_chans == 0) { in mcux_ctimer_pwm_is_period_valid()
70 if (data->num_active_pulse_chans > 1) { in mcux_ctimer_pwm_is_period_valid()
78 if (data->channel_states[new_pulse_channel].role != PWM_CTIMER_CHANNEL_ROLE_PULSE) { in mcux_ctimer_pwm_is_period_valid()
92 static int mcux_ctimer_pwm_select_period_channel(struct pwm_mcux_ctimer_data *data, in mcux_ctimer_pwm_select_period_channel() argument
97 if (data->is_period_channel_set) { in mcux_ctimer_pwm_select_period_channel()
98 if (!mcux_ctimer_pwm_is_period_valid(data, new_pulse_channel, new_period_cycles, in mcux_ctimer_pwm_select_period_channel()
99 data->current_period_channel)) { in mcux_ctimer_pwm_select_period_channel()
102 return -EINVAL; in mcux_ctimer_pwm_select_period_channel()
105 *ret_period_channel = data->current_period_channel; in mcux_ctimer_pwm_select_period_channel()
115 while (data->channel_states[*ret_period_channel].role != PWM_CTIMER_CHANNEL_ROLE_NONE) { in mcux_ctimer_pwm_select_period_channel()
118 return -EBUSY; in mcux_ctimer_pwm_select_period_channel()
127 static void mcux_ctimer_pwm_update_state(struct pwm_mcux_ctimer_data *data, uint32_t pulse_channel, in mcux_ctimer_pwm_update_state() argument
131 if (data->channel_states[pulse_channel].role != PWM_CTIMER_CHANNEL_ROLE_PULSE) { in mcux_ctimer_pwm_update_state()
132 data->num_active_pulse_chans++; in mcux_ctimer_pwm_update_state()
135 data->channel_states[pulse_channel].role = PWM_CTIMER_CHANNEL_ROLE_PULSE; in mcux_ctimer_pwm_update_state()
136 data->channel_states[pulse_channel].cycles = pulse_cycles; in mcux_ctimer_pwm_update_state()
138 data->is_period_channel_set = true; in mcux_ctimer_pwm_update_state()
139 data->current_period_channel = period_channel; in mcux_ctimer_pwm_update_state()
140 data->channel_states[period_channel].role = PWM_CTIMER_CHANNEL_ROLE_PERIOD; in mcux_ctimer_pwm_update_state()
141 data->channel_states[period_channel].cycles = period_cycles; in mcux_ctimer_pwm_update_state()
148 const struct pwm_mcux_ctimer_config *config = dev->config; in mcux_ctimer_pwm_set_cycles()
149 struct pwm_mcux_ctimer_data *data = dev->data; in mcux_ctimer_pwm_set_cycles() local
150 uint32_t period_channel = data->current_period_channel; in mcux_ctimer_pwm_set_cycles()
156 return -EINVAL; in mcux_ctimer_pwm_set_cycles()
161 return -ENOTSUP; in mcux_ctimer_pwm_set_cycles()
164 ret = mcux_ctimer_pwm_select_period_channel(data, pulse_channel, period_cycles, in mcux_ctimer_pwm_set_cycles()
176 pulse_cycles = period_cycles - pulse_cycles; in mcux_ctimer_pwm_set_cycles()
180 status = CTIMER_SetupPwmPeriod(config->base, period_channel, pulse_channel, period_cycles, in mcux_ctimer_pwm_set_cycles()
184 return -EIO; in mcux_ctimer_pwm_set_cycles()
186 mcux_ctimer_pwm_update_state(data, pulse_channel, pulse_cycles, period_channel, in mcux_ctimer_pwm_set_cycles()
189 CTIMER_StartTimer(config->base); in mcux_ctimer_pwm_set_cycles()
196 const struct pwm_mcux_ctimer_config *config = dev->config; in mcux_ctimer_pwm_get_cycles_per_sec()
203 err = clock_control_get_rate(config->clock_control, config->clock_id, (uint32_t *)cycles); in mcux_ctimer_pwm_get_cycles_per_sec()
209 if (config->prescale > 0) { in mcux_ctimer_pwm_get_cycles_per_sec()
210 *cycles /= config->prescale; in mcux_ctimer_pwm_get_cycles_per_sec()
218 const struct pwm_mcux_ctimer_config *config = dev->config; in mcux_ctimer_pwm_init()
222 err = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); in mcux_ctimer_pwm_init()
227 if (config->period_channel >= CHANNEL_COUNT) { in mcux_ctimer_pwm_init()
228 LOG_ERR("invalid period_channel: %d. must be less than %d", config->period_channel, in mcux_ctimer_pwm_init()
230 return -EINVAL; in mcux_ctimer_pwm_init()
234 pwm_config.prescale = config->prescale; in mcux_ctimer_pwm_init()
236 CTIMER_Init(config->base, &pwm_config); in mcux_ctimer_pwm_init()
252 [kCTIMER_Match_0] = {.role = PWM_CTIMER_CHANNEL_ROLE_NONE, \
254 [kCTIMER_Match_1] = {.role = PWM_CTIMER_CHANNEL_ROLE_NONE, \
256 [kCTIMER_Match_2] = {.role = PWM_CTIMER_CHANNEL_ROLE_NONE, \
258 [kCTIMER_Match_3] = {.role = PWM_CTIMER_CHANNEL_ROLE_NONE, \