Lines Matching +full:hal +full:- +full:based

5  * SPDX-License-Identifier: Apache-2.0
10 /* Include esp-idf headers first to avoid redefining BIT() macro */
11 #include <hal/ledc_hal.h>
12 #include <hal/ledc_types.h>
37 ledc_hal_context_t hal; member
64 (struct pwm_ledc_esp32_config *) dev->config; in get_channel_config()
66 for (uint8_t i = 0; i < config->channel_len; i++) { in get_channel_config()
67 if (config->channel_config[i].idx == channel_id) { in get_channel_config()
68 return &config->channel_config[i]; in get_channel_config()
76 struct pwm_ledc_esp32_data *data = (struct pwm_ledc_esp32_data *const)(dev)->data; in pwm_led_esp32_low_speed_update()
79 ledc_hal_ls_channel_update(&data->hal, channel); in pwm_led_esp32_low_speed_update()
85 struct pwm_ledc_esp32_data *data = (struct pwm_ledc_esp32_data *const)(dev)->data; in pwm_led_esp32_update_duty()
87 ledc_hal_set_sig_out_en(&data->hal, channel, true); in pwm_led_esp32_update_duty()
88 ledc_hal_set_duty_start(&data->hal, channel, true); in pwm_led_esp32_update_duty()
96 struct pwm_ledc_esp32_data *data = (struct pwm_ledc_esp32_data *const)(dev)->data; in pwm_led_esp32_duty_set()
98 ledc_hal_set_hpoint(&data->hal, channel->channel_num, 0); in pwm_led_esp32_duty_set()
99 ledc_hal_set_duty_int_part(&data->hal, channel->channel_num, channel->duty_val); in pwm_led_esp32_duty_set()
100 ledc_hal_set_duty_direction(&data->hal, channel->channel_num, 1); in pwm_led_esp32_duty_set()
101 ledc_hal_set_duty_num(&data->hal, channel->channel_num, 1); in pwm_led_esp32_duty_set()
102 ledc_hal_set_duty_cycle(&data->hal, channel->channel_num, 1); in pwm_led_esp32_duty_set()
103 ledc_hal_set_duty_scale(&data->hal, channel->channel_num, 0); in pwm_led_esp32_duty_set()
104 pwm_led_esp32_low_speed_update(dev, channel->speed_mode, channel->channel_num); in pwm_led_esp32_duty_set()
105 pwm_led_esp32_update_duty(dev, channel->speed_mode, channel->channel_num); in pwm_led_esp32_duty_set()
111 struct pwm_ledc_esp32_config *config = (struct pwm_ledc_esp32_config *) dev->config; in pwm_led_esp32_configure_pinctrl()
113 ret = pinctrl_apply_state(config->pincfg, PINCTRL_STATE_DEFAULT); in pwm_led_esp32_configure_pinctrl()
124 struct pwm_ledc_esp32_data *data = (struct pwm_ledc_esp32_data *const)(dev)->data; in pwm_led_esp32_bind_channel_timer()
126 ledc_hal_bind_channel_timer(&data->hal, channel->channel_num, channel->timer_num); in pwm_led_esp32_bind_channel_timer()
128 pwm_led_esp32_low_speed_update(dev, channel->speed_mode, channel->channel_num); in pwm_led_esp32_bind_channel_timer()
138 uint64_t clock_freq = channel->clock_src == LEDC_APB_CLK ? APB_CLK_FREQ : REF_CLK_FREQ; in pwm_led_esp32_calculate_max_resolution()
142 uint32_t max_precision_n = clock_freq/channel->freq; in pwm_led_esp32_calculate_max_resolution()
147 channel->resolution = i; in pwm_led_esp32_calculate_max_resolution()
151 return -EINVAL; in pwm_led_esp32_calculate_max_resolution()
158 * Calculate max resolution based on the given frequency and the pwm clock. in pwm_led_esp32_timer_config()
177 channel->clock_src = LEDC_APB_CLK; in pwm_led_esp32_timer_config()
184 channel->clock_src = LEDC_REF_TICK; in pwm_led_esp32_timer_config()
191 * ESP32 - S2,S3 and C3 variants have only 14 bits counter. in pwm_led_esp32_timer_config()
199 channel->resolution = SOC_LEDC_TIMER_BIT_WIDTH; in pwm_led_esp32_timer_config()
207 uint32_t precision = (0x1 << channel->resolution); in pwm_led_esp32_timer_set()
208 struct pwm_ledc_esp32_data *data = (struct pwm_ledc_esp32_data *const)(dev)->data; in pwm_led_esp32_timer_set()
210 __ASSERT_NO_MSG(channel->freq > 0); in pwm_led_esp32_timer_set()
212 switch (channel->clock_src) { in pwm_led_esp32_timer_set()
219 prescaler = ((uint64_t) APB_CLK_FREQ << 8) / channel->freq / precision; in pwm_led_esp32_timer_set()
224 prescaler = ((uint64_t) SCLK_CLK_FREQ << 8) / channel->freq / precision; in pwm_led_esp32_timer_set()
229 prescaler = ((uint64_t) REF_CLK_FREQ << 8) / channel->freq / precision; in pwm_led_esp32_timer_set()
233 LOG_ERR("Invalid clock source (%d)", channel->clock_src); in pwm_led_esp32_timer_set()
234 return -EINVAL; in pwm_led_esp32_timer_set()
239 return -EINVAL; in pwm_led_esp32_timer_set()
242 if (channel->speed_mode == LEDC_LOW_SPEED_MODE) { in pwm_led_esp32_timer_set()
243 ledc_hal_set_slow_clk_sel(&data->hal, channel->clock_src); in pwm_led_esp32_timer_set()
246 ledc_hal_set_clock_divider(&data->hal, channel->timer_num, prescaler); in pwm_led_esp32_timer_set()
247 ledc_hal_set_duty_resolution(&data->hal, channel->timer_num, channel->resolution); in pwm_led_esp32_timer_set()
248 ledc_hal_set_clock_source(&data->hal, channel->timer_num, channel->clock_src); in pwm_led_esp32_timer_set()
250 if (channel->speed_mode == LEDC_LOW_SPEED_MODE) { in pwm_led_esp32_timer_set()
251 ledc_hal_ls_timer_update(&data->hal, channel->timer_num); in pwm_led_esp32_timer_set()
255 ledc_hal_timer_rst(&data->hal, channel->timer_num); in pwm_led_esp32_timer_set()
267 return -EINVAL; in pwm_led_esp32_get_cycles_per_sec()
271 *cycles = channel->clock_src == LEDC_APB_CLK ? APB_CLK_FREQ : REF_CLK_FREQ; in pwm_led_esp32_get_cycles_per_sec()
285 struct pwm_ledc_esp32_data *data = (struct pwm_ledc_esp32_data *const)(dev)->data; in pwm_led_esp32_set_cycles()
290 return -EINVAL; in pwm_led_esp32_set_cycles()
299 channel->freq = (uint32_t) (clk_freq/period_cycles); in pwm_led_esp32_set_cycles()
300 if (!channel->freq) { in pwm_led_esp32_set_cycles()
301 channel->freq = 1; in pwm_led_esp32_set_cycles()
304 k_sem_take(&data->cmd_sem, K_FOREVER); in pwm_led_esp32_set_cycles()
306 ledc_hal_init(&data->hal, channel->speed_mode); in pwm_led_esp32_set_cycles()
310 k_sem_give(&data->cmd_sem); in pwm_led_esp32_set_cycles()
316 k_sem_give(&data->cmd_sem); in pwm_led_esp32_set_cycles()
326 channel->duty_val = (uint32_t)((double) (1 << channel->resolution) * duty_cycle); in pwm_led_esp32_set_cycles()
332 k_sem_give(&data->cmd_sem); in pwm_led_esp32_set_cycles()
336 k_sem_give(&data->cmd_sem); in pwm_led_esp32_set_cycles()
344 const struct pwm_ledc_esp32_config *config = dev->config; in pwm_led_esp32_init()
346 if (!device_is_ready(config->clock_dev)) { in pwm_led_esp32_init()
348 return -ENODEV; in pwm_led_esp32_init()
352 clock_control_on(config->clock_dev, config->clock_subsys); in pwm_led_esp32_init()
388 .hal = {