Lines Matching refs:obj
117 static cy_rslt_t cyhal_pwm_set_period_and_compare(cyhal_pwm_t *obj, uint32_t period, uint32_t compa… in cyhal_pwm_set_period_and_compare() argument
119 …eriod > (uint32_t)((1 << _CYHAL_TCPWM_DATA[_CYHAL_TCPWM_ADJUST_BLOCK_INDEX(obj->tcpwm.resource.blo… in cyhal_pwm_set_period_and_compare()
122 cyhal_gpio_t pin = obj->pin; in cyhal_pwm_set_period_and_compare()
123 cyhal_gpio_t pin_compl = obj->pin_compl; in cyhal_pwm_set_period_and_compare()
125 Cy_TCPWM_PWM_SetCompare0(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource), 0u); in cyhal_pwm_set_period_and_compare()
126 …Cy_TCPWM_PWM_SetPeriod0(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource), period - 1u… in cyhal_pwm_set_period_and_compare()
130 …(NC == pin || (_CYHAL_UTILS_GET_RESOURCE_INST(pin, cyhal_pin_map_tcpwm_line_compl, &obj->tcpwm.res… in cyhal_pwm_set_period_and_compare()
131 …l || (_CYHAL_UTILS_GET_RESOURCE_INST(pin_compl, cyhal_pin_map_tcpwm_line, &obj->tcpwm.resource) !=… in cyhal_pwm_set_period_and_compare()
139 …uint32_t pwm_ctrl_reg = TCPWM_GRP_CNT_TR_PWM_CTRL(obj->tcpwm.base, _CYHAL_TCPWM_GET_GRP(obj->tcpwm… in cyhal_pwm_set_period_and_compare()
140 _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource)); in cyhal_pwm_set_period_and_compare()
141 uint32_t cc1_ignore_mask = (0 == _CYHAL_TCPWM_GET_GRP(obj->tcpwm.resource.block_num)) ? in cyhal_pwm_set_period_and_compare()
146 …bool is_center_aligned = (TCPWM_CNT_TR_CTRL2(obj->tcpwm.base, obj->tcpwm.resource.channel_num) == … in cyhal_pwm_set_period_and_compare()
147 …(TCPWM_CNT_TR_CTRL2(obj->tcpwm.base, obj->tcpwm.resource.channel_num) == _CYHAL_PWM_MODE_CNTR_OR_A… in cyhal_pwm_set_period_and_compare()
157 …Cy_TCPWM_PWM_SetCompare0(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource), new_compar… in cyhal_pwm_set_period_and_compare()
158 …if (Cy_TCPWM_PWM_GetCounter(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource)) >= new_… in cyhal_pwm_set_period_and_compare()
160 Cy_TCPWM_PWM_SetCounter(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource), 0); in cyhal_pwm_set_period_and_compare()
166 static cy_rslt_t _cyhal_pwm_update_clock_freq(cyhal_pwm_t *obj, uint32_t period_us) in _cyhal_pwm_update_clock_freq() argument
172 if(obj->tcpwm.dedicated_clock && false == obj->dead_time_set) in _cyhal_pwm_update_clock_freq()
174 uint32_t source_hz = _cyhal_utils_get_peripheral_clock_frequency(&(obj->tcpwm.resource)); in _cyhal_pwm_update_clock_freq()
176 …int64_t)((uint64_t)1u << _CYHAL_TCPWM_DATA[_CYHAL_TCPWM_ADJUST_BLOCK_INDEX(obj->tcpwm.resource.blo… in _cyhal_pwm_update_clock_freq()
200 …t)(_CYHAL_TCPWM_DATA[_CYHAL_TCPWM_ADJUST_BLOCK_INDEX(obj->tcpwm.resource.block_num)].clock_dst + o… in _cyhal_pwm_update_clock_freq()
201 result = _cyhal_utils_peri_pclk_set_divider(pclk, &(obj->tcpwm.clock), div - 1); in _cyhal_pwm_update_clock_freq()
204 obj->tcpwm.clock_hz = cyhal_clock_get_frequency(&obj->tcpwm.clock); in _cyhal_pwm_update_clock_freq()
210 static cy_rslt_t _cyhal_pwm_init_clock(cyhal_pwm_t *obj, uint32_t dead_time_us, const cyhal_clock_t… in _cyhal_pwm_init_clock() argument
213 …t)(_CYHAL_TCPWM_DATA[_CYHAL_TCPWM_ADJUST_BLOCK_INDEX(obj->tcpwm.resource.block_num)].clock_dst + o… in _cyhal_pwm_init_clock()
216 obj->tcpwm.clock = *clk; in _cyhal_pwm_init_clock()
217 if (CY_SYSCLK_SUCCESS != _cyhal_utils_peri_pclk_assign_divider(pclk, &(obj->tcpwm.clock))) in _cyhal_pwm_init_clock()
222 …else if (CY_RSLT_SUCCESS == (result = _cyhal_utils_allocate_clock(&obj->tcpwm.clock, &obj->tcpwm.r… in _cyhal_pwm_init_clock()
224 obj->tcpwm.dedicated_clock = true; in _cyhal_pwm_init_clock()
225 uint32_t source_hz = _cyhal_utils_get_peripheral_clock_frequency(&(obj->tcpwm.resource)); in _cyhal_pwm_init_clock()
255 … CY_SYSCLK_SUCCESS != _cyhal_utils_peri_pclk_set_divider(pclk, &(obj->tcpwm.clock), div - 1) || in _cyhal_pwm_init_clock()
256 CY_SYSCLK_SUCCESS != _cyhal_utils_peri_pclk_enable_divider(pclk, &(obj->tcpwm.clock)) || in _cyhal_pwm_init_clock()
257 CY_SYSCLK_SUCCESS != _cyhal_utils_peri_pclk_assign_divider(pclk, &(obj->tcpwm.clock))) in _cyhal_pwm_init_clock()
264 obj->tcpwm.clock_hz = cyhal_clock_get_frequency(&obj->tcpwm.clock); in _cyhal_pwm_init_clock()
270 static cy_rslt_t _cyhal_pwm_init_hw(cyhal_pwm_t *obj, const cy_stc_tcpwm_pwm_config_t* config, bool… in _cyhal_pwm_init_hw() argument
272 …cy_rslt_t result = Cy_TCPWM_PWM_Init(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource)… in _cyhal_pwm_init_hw()
277 …asym_swapped_reg_val = (0 == TCPWM_GRP_CNT_GET_GRP(_CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource))) ? in _cyhal_pwm_init_hw()
281 …TCPWM_GRP_CNT_TR_PWM_CTRL(obj->tcpwm.base, TCPWM_GRP_CNT_GET_GRP(_CYHAL_TCPWM_CNT_NUMBER(obj->tcpw… in _cyhal_pwm_init_hw()
282 _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource)) = cntr_asym_swapped_reg_val; in _cyhal_pwm_init_hw()
284 …TCPWM_CNT_TR_CTRL2(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource)) = _CYHAL_PWM_MOD… in _cyhal_pwm_init_hw()
290 _cyhal_tcpwm_init_data(&obj->tcpwm); in _cyhal_pwm_init_hw()
291 obj->dead_time_set = (0u != config->deadTimeClocks); in _cyhal_pwm_init_hw()
292 Cy_TCPWM_PWM_Enable(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource)); in _cyhal_pwm_init_hw()
298 cy_rslt_t cyhal_pwm_init_cfg(cyhal_pwm_t *obj, const cyhal_pwm_configurator_t *cfg) in cyhal_pwm_init_cfg() argument
300 obj->tcpwm.resource = *cfg->resource; in cyhal_pwm_init_cfg()
301 …obj->tcpwm.base = _CYHAL_TCPWM_DATA[_CYHAL_TCPWM_ADJUST_BLOCK_INDEX(obj->tcpwm.resource.block_… in cyhal_pwm_init_cfg()
304 cy_rslt_t result = _cyhal_pwm_init_clock(obj, 0u, cfg->clock); in cyhal_pwm_init_cfg()
310 result = _cyhal_pwm_init_hw(obj, cfg->config, false); in cyhal_pwm_init_cfg()
315 cyhal_pwm_free(obj); in cyhal_pwm_init_cfg()
322 cy_rslt_t cyhal_pwm_init_adv(cyhal_pwm_t *obj, cyhal_gpio_t pin, cyhal_gpio_t compl_pin, cyhal_pwm_… in cyhal_pwm_init_adv() argument
324 CY_ASSERT(NULL != obj); in cyhal_pwm_init_adv()
327 memset(obj, 0, sizeof(cyhal_pwm_t)); in cyhal_pwm_init_adv()
329 obj->tcpwm.resource.type = CYHAL_RSC_INVALID; in cyhal_pwm_init_adv()
330 obj->pin = CYHAL_NC_PIN_VALUE; in cyhal_pwm_init_adv()
331 obj->pin_compl = CYHAL_NC_PIN_VALUE; in cyhal_pwm_init_adv()
350 _CYHAL_UTILS_ASSIGN_RESOURCE(obj->tcpwm.resource, CYHAL_RSC_TCPWM, map); in cyhal_pwm_init_adv()
351 …obj->tcpwm.base = _CYHAL_TCPWM_DATA[_CYHAL_TCPWM_ADJUST_BLOCK_INDEX(obj->tcpwm.resource.block_… in cyhal_pwm_init_adv()
360 obj->pin = pin; in cyhal_pwm_init_adv()
372 …sizeof(cyhal_pin_map_tcpwm_line) / sizeof(cyhal_resource_pin_mapping_t), &(obj->tcpwm.resource), f… in cyhal_pwm_init_adv()
375 …(cyhal_pin_map_tcpwm_line_compl) / sizeof(cyhal_resource_pin_mapping_t), &(obj->tcpwm.resource), f… in cyhal_pwm_init_adv()
386 obj->pin_compl = compl_pin; in cyhal_pwm_init_adv()
400 result = _cyhal_pwm_init_clock(obj, dead_time_us, clk); in cyhal_pwm_init_adv()
411 uint8_t dead_time = (uint8_t)(dead_time_us * obj->tcpwm.clock_hz / _CYHAL_PWM_US_PER_SEC); in cyhal_pwm_init_adv()
442 result = _cyhal_pwm_init_hw(obj, &pdl_config, swapped); in cyhal_pwm_init_adv()
447 cyhal_pwm_free(obj); in cyhal_pwm_init_adv()
453 void cyhal_pwm_free(cyhal_pwm_t *obj) in cyhal_pwm_free() argument
455 CY_ASSERT(NULL != obj); in cyhal_pwm_free()
456 if(false == obj->tcpwm.owned_by_configurator) in cyhal_pwm_free()
458 _cyhal_utils_release_if_used(&obj->pin); in cyhal_pwm_free()
459 _cyhal_utils_release_if_used(&obj->pin_compl); in cyhal_pwm_free()
462 _cyhal_tcpwm_free(&obj->tcpwm); in cyhal_pwm_free()
465 cy_rslt_t cyhal_pwm_set_period(cyhal_pwm_t *obj, uint32_t period_us, uint32_t pulse_width_us) in cyhal_pwm_set_period() argument
467 CY_ASSERT(NULL != obj); in cyhal_pwm_set_period()
468 cy_rslt_t result = _cyhal_pwm_update_clock_freq(obj, period_us); in cyhal_pwm_set_period()
471 … uint32_t period = (uint32_t)((uint64_t)period_us * obj->tcpwm.clock_hz / _CYHAL_PWM_US_PER_SEC); in cyhal_pwm_set_period()
472 …uint32_t width = (uint32_t)((uint64_t)pulse_width_us * obj->tcpwm.clock_hz / _CYHAL_PWM_US_PER_SEC… in cyhal_pwm_set_period()
473 result = cyhal_pwm_set_period_and_compare(obj, period, width); in cyhal_pwm_set_period()
478 cy_rslt_t cyhal_pwm_set_duty_cycle(cyhal_pwm_t *obj, float duty_cycle, uint32_t frequencyhal_hz) in cyhal_pwm_set_duty_cycle() argument
480 CY_ASSERT(NULL != obj); in cyhal_pwm_set_duty_cycle()
485 cy_rslt_t result = _cyhal_pwm_update_clock_freq(obj, period_us); in cyhal_pwm_set_duty_cycle()
488 uint32_t period = (obj->tcpwm.clock_hz + (frequencyhal_hz >> 1)) / frequencyhal_hz; in cyhal_pwm_set_duty_cycle()
490 result = cyhal_pwm_set_period_and_compare(obj, period, width); in cyhal_pwm_set_duty_cycle()
495 cy_rslt_t cyhal_pwm_start(cyhal_pwm_t *obj) in cyhal_pwm_start() argument
497 CY_ASSERT(NULL != obj); in cyhal_pwm_start()
502 Cy_TCPWM_PWM_Enable(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource)); in cyhal_pwm_start()
504 …Cy_TCPWM_TriggerReloadOrIndex_Single(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource)… in cyhal_pwm_start()
506 … Cy_TCPWM_TriggerReloadOrIndex(obj->tcpwm.base, 1 << _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource)); in cyhal_pwm_start()
511 cy_rslt_t cyhal_pwm_stop(cyhal_pwm_t *obj) in cyhal_pwm_stop() argument
513 CY_ASSERT(NULL != obj); in cyhal_pwm_stop()
514 Cy_TCPWM_PWM_Disable(obj->tcpwm.base, _CYHAL_TCPWM_CNT_NUMBER(obj->tcpwm.resource)); in cyhal_pwm_stop()
556 cy_rslt_t cyhal_pwm_connect_digital2(cyhal_pwm_t *obj, cyhal_source_t source, cyhal_pwm_input_t sig… in cyhal_pwm_connect_digital2() argument
559 return _cyhal_tcpwm_connect_digital(&(obj->tcpwm), source, tcpwm_signal, edge_type); in cyhal_pwm_connect_digital2()
562 cy_rslt_t cyhal_pwm_connect_digital(cyhal_pwm_t *obj, cyhal_source_t source, cyhal_pwm_input_t sign… in cyhal_pwm_connect_digital() argument
569 return cyhal_pwm_connect_digital2(obj, source, signal, edge_type); in cyhal_pwm_connect_digital()
571 CY_UNUSED_PARAMETER(obj); in cyhal_pwm_connect_digital()
578 cy_rslt_t cyhal_pwm_enable_output(cyhal_pwm_t *obj, cyhal_pwm_output_t signal, cyhal_source_t *sour… in cyhal_pwm_enable_output() argument
581 return _cyhal_tcpwm_enable_output(&(obj->tcpwm), tcpwm_signal, source); in cyhal_pwm_enable_output()
584 cy_rslt_t cyhal_pwm_disconnect_digital(cyhal_pwm_t *obj, cyhal_source_t source, cyhal_pwm_input_t s… in cyhal_pwm_disconnect_digital() argument
586 …return _cyhal_tcpwm_disconnect_digital(&(obj->tcpwm), source, _cyhal_pwm_translate_input_signal(si… in cyhal_pwm_disconnect_digital()
589 cy_rslt_t cyhal_pwm_disable_output(cyhal_pwm_t *obj, cyhal_pwm_output_t signal) in cyhal_pwm_disable_output() argument
591 return _cyhal_tcpwm_disable_output(&(obj->tcpwm), _cyhal_pwm_translate_output_signal(signal)); in cyhal_pwm_disable_output()