Lines Matching refs:obj
116 static cy_rslt_t _cyhal_usb_dev_hf_clock_setup(cyhal_usb_dev_t *obj);
117 static cy_rslt_t _cyhal_usb_dev_peri_clock_setup(cyhal_usb_dev_t *obj, const cyhal_clock_t *clk);
119 static cy_rslt_t _cyhal_usb_dev_pin_setup(cyhal_usb_dev_t *obj, cyhal_gpio_t dp, cyhal_gpio_t dm);
120 static void _cyhal_usb_dev_free_resources(cyhal_usb_dev_t *obj);
282 static cy_rslt_t _cyhal_usb_dev_hf_clock_setup(cyhal_usb_dev_t *obj) in _cyhal_usb_dev_hf_clock_setup() argument
319 result = _cyhal_usb_dev_reserve_pll(&(obj->pll_resource)); in _cyhal_usb_dev_hf_clock_setup()
324 …result = _cyhal_usb_dev_init_pll(clock, obj->pll_resource.block_num, _CYHAL_USB_DEV_USB_CLK_HF_FRE… in _cyhal_usb_dev_hf_clock_setup()
339 static cy_rslt_t _cyhal_usb_dev_peri_clock_setup(cyhal_usb_dev_t *obj, const cyhal_clock_t *clk) in _cyhal_usb_dev_peri_clock_setup() argument
346 obj->shared_clock = false; in _cyhal_usb_dev_peri_clock_setup()
349 …result = _cyhal_utils_allocate_clock(&(obj->clock), &(obj->resource), CYHAL_CLOCK_BLOCK_PERIPHERAL… in _cyhal_usb_dev_peri_clock_setup()
354 …uint32_t div_value = (_cyhal_utils_get_peripheral_clock_frequency(&(obj->resource)) / _CYHAL_USB_D… in _cyhal_usb_dev_peri_clock_setup()
356 (void) _cyhal_utils_peri_pclk_disable_divider(PCLK_USB_CLOCK_DEV_BRS, &(obj->clock)); in _cyhal_usb_dev_peri_clock_setup()
357 … status = _cyhal_utils_peri_pclk_set_divider(PCLK_USB_CLOCK_DEV_BRS, &(obj->clock), div_value); in _cyhal_usb_dev_peri_clock_setup()
358 (void) _cyhal_utils_peri_pclk_enable_divider(PCLK_USB_CLOCK_DEV_BRS, &(obj->clock)); in _cyhal_usb_dev_peri_clock_setup()
363 obj->clock = *clk; in _cyhal_usb_dev_peri_clock_setup()
364 obj->shared_clock = true; in _cyhal_usb_dev_peri_clock_setup()
370 status = _cyhal_utils_peri_pclk_assign_divider(PCLK_USB_CLOCK_DEV_BRS, &(obj->clock)); in _cyhal_usb_dev_peri_clock_setup()
378 static cy_rslt_t _cyhal_usb_dev_pin_setup(cyhal_usb_dev_t *obj, cyhal_gpio_t dp, cyhal_gpio_t dm) in _cyhal_usb_dev_pin_setup() argument
387 _CYHAL_UTILS_ASSIGN_RESOURCE(obj->resource, CYHAL_RSC_USB, dp_map); in _cyhal_usb_dev_pin_setup()
393 obj->pin_dp = dp; in _cyhal_usb_dev_pin_setup()
398 obj->pin_dm = dm; in _cyhal_usb_dev_pin_setup()
406 static void _cyhal_usb_dev_free_resources(cyhal_usb_dev_t *obj) in _cyhal_usb_dev_free_resources() argument
409 if (CYHAL_RSC_INVALID != obj->resource.type) in _cyhal_usb_dev_free_resources()
410 cyhal_hwmgr_free(&(obj->resource)); in _cyhal_usb_dev_free_resources()
411 if (CYHAL_RSC_INVALID != obj->pll_resource.type) in _cyhal_usb_dev_free_resources()
412 cyhal_hwmgr_free(&(obj->pll_resource)); in _cyhal_usb_dev_free_resources()
413 if (!obj->shared_clock) in _cyhal_usb_dev_free_resources()
414 cyhal_clock_free(&(obj->clock)); in _cyhal_usb_dev_free_resources()
416 _cyhal_utils_release_if_used(&(obj->pin_dp)); in _cyhal_usb_dev_free_resources()
417 _cyhal_utils_release_if_used(&(obj->pin_dm)); in _cyhal_usb_dev_free_resources()
424 cyhal_usb_dev_t *obj = (cyhal_usb_dev_t *)callback_arg; in _cyhal_usb_dev_pm_callback() local
425 return USBFS_DEV_LPM_POWER_CTL(obj->base) & USBFS_USBLPM_POWER_CTL_SUSPEND_Msk; in _cyhal_usb_dev_pm_callback()
433 cy_rslt_t cyhal_usb_dev_init(cyhal_usb_dev_t *obj, cyhal_gpio_t dp, cyhal_gpio_t dm, const cyhal_cl… in cyhal_usb_dev_init() argument
437 CY_ASSERT(NULL != obj); in cyhal_usb_dev_init()
438 memset(obj, 0, sizeof(cyhal_usb_dev_t)); in cyhal_usb_dev_init()
441 obj->base = NULL; in cyhal_usb_dev_init()
442 obj->resource.type = CYHAL_RSC_INVALID; in cyhal_usb_dev_init()
443 obj->pll_resource.type = CYHAL_RSC_INVALID; in cyhal_usb_dev_init()
444 obj->shared_clock = true; in cyhal_usb_dev_init()
445 obj->pin_dp = CYHAL_NC_PIN_VALUE; in cyhal_usb_dev_init()
446 obj->pin_dm = CYHAL_NC_PIN_VALUE; in cyhal_usb_dev_init()
448 result = _cyhal_usb_dev_pin_setup(obj, dp, dm); in cyhal_usb_dev_init()
453 result = _cyhal_usb_dev_hf_clock_setup(obj); in cyhal_usb_dev_init()
457 result = _cyhal_usb_dev_peri_clock_setup(obj, clk); in cyhal_usb_dev_init()
463 result = cyhal_hwmgr_reserve(&(obj->resource)); in cyhal_usb_dev_init()
464 obj->base = _CYHAL_USB_DEV_BASE_ADDRESSES[obj->resource.block_num]; in cyhal_usb_dev_init()
481 … if (CY_USBFS_DEV_DRV_SUCCESS != Cy_USBFS_Dev_Drv_Init(obj->base, &default_cfg, &(obj->context))) in cyhal_usb_dev_init()
489 uint32_t instance = obj->resource.block_num; in cyhal_usb_dev_init()
492 Cy_USBFS_Dev_Drv_RegisterServiceCallback(obj->base, CY_USB_DEV_BUS_RESET, in cyhal_usb_dev_init()
494 &(obj->context)); in cyhal_usb_dev_init()
495 Cy_USBFS_Dev_Drv_RegisterServiceCallback(obj->base, CY_USB_DEV_EP0_SETUP, in cyhal_usb_dev_init()
497 &(obj->context)); in cyhal_usb_dev_init()
498 Cy_USBFS_Dev_Drv_RegisterServiceCallback(obj->base, CY_USB_DEV_EP0_IN, in cyhal_usb_dev_init()
500 &(obj->context)); in cyhal_usb_dev_init()
501 Cy_USBFS_Dev_Drv_RegisterServiceCallback(obj->base, CY_USB_DEV_EP0_OUT, in cyhal_usb_dev_init()
503 &(obj->context)); in cyhal_usb_dev_init()
506 Cy_USBFS_Dev_Drv_RegisterSofCallback(obj->base, _cyhal_usb_dev_drv_sof_cb_table[instance], in cyhal_usb_dev_init()
507 &(obj->context)); in cyhal_usb_dev_init()
508 cyhal_usb_dev_sof_enable(obj, false); in cyhal_usb_dev_init()
510 …obj->pm_callback.states = (cyhal_syspm_callback_state_t)(CYHAL_SYSPM_CB_CPU_DEEPSLEEP | CYHAL_SYSP… in cyhal_usb_dev_init()
511 obj->pm_callback.callback = &_cyhal_usb_dev_pm_callback; in cyhal_usb_dev_init()
512 obj->pm_callback.args = (void *)obj; in cyhal_usb_dev_init()
513 obj->pm_callback.next = NULL; in cyhal_usb_dev_init()
514 …obj->pm_callback.ignore_modes = (cyhal_syspm_callback_mode_t)(CYHAL_SYSPM_CHECK_FAIL | CYHAL_SYSPM… in cyhal_usb_dev_init()
515 _cyhal_syspm_register_peripheral_callback(&(obj->pm_callback)); in cyhal_usb_dev_init()
520 Cy_USBFS_Dev_Drv_RegisterEndpointCallback(obj->base, in cyhal_usb_dev_init()
523 &(obj->context)); in cyhal_usb_dev_init()
529 _cyhal_usb_dev_free_resources(obj); in cyhal_usb_dev_init()
535 void cyhal_usb_dev_free(cyhal_usb_dev_t *obj) in cyhal_usb_dev_free() argument
537 _cyhal_syspm_unregister_peripheral_callback(&(obj->pm_callback)); in cyhal_usb_dev_free()
538 cyhal_usb_dev_irq_enable(obj, false); in cyhal_usb_dev_free()
539 cyhal_usb_dev_disconnect(obj); in cyhal_usb_dev_free()
540 _cyhal_usb_dev_free_resources(obj); in cyhal_usb_dev_free()
543 void cyhal_usb_dev_connect(cyhal_usb_dev_t *obj) in cyhal_usb_dev_connect() argument
545 Cy_USBFS_Dev_Drv_Enable(obj->base, &(obj->context)); in cyhal_usb_dev_connect()
548 void cyhal_usb_dev_disconnect(cyhal_usb_dev_t *obj) in cyhal_usb_dev_disconnect() argument
550 Cy_USBFS_Dev_Drv_Disable(obj->base, &(obj->context)); in cyhal_usb_dev_disconnect()
553 void cyhal_usb_dev_suspend(cyhal_usb_dev_t *obj) in cyhal_usb_dev_suspend() argument
555 Cy_USBFS_Dev_Drv_Suspend(obj->base, &(obj->context)); in cyhal_usb_dev_suspend()
558 void cyhal_usb_dev_resume(cyhal_usb_dev_t *obj) in cyhal_usb_dev_resume() argument
560 Cy_USBFS_Dev_Drv_Resume(obj->base, &(obj->context)); in cyhal_usb_dev_resume()
563 void cyhal_usb_dev_set_configured(cyhal_usb_dev_t *obj) in cyhal_usb_dev_set_configured() argument
565 Cy_USBFS_Dev_Drv_ConfigDevice(obj->base, &(obj->context)); in cyhal_usb_dev_set_configured()
568 void cyhal_usb_dev_set_unconfigured(cyhal_usb_dev_t *obj) in cyhal_usb_dev_set_unconfigured() argument
570 Cy_USBFS_Dev_Drv_UnConfigureDevice(obj->base, &(obj->context)); in cyhal_usb_dev_set_unconfigured()
573 void cyhal_usb_dev_sof_enable(cyhal_usb_dev_t *obj, bool enable) in cyhal_usb_dev_sof_enable() argument
575 uint32_t mask = Cy_USBFS_Dev_Drv_GetSieInterruptMask(obj->base); in cyhal_usb_dev_sof_enable()
580 Cy_USBFS_Dev_Drv_ClearSieInterrupt(obj->base, CY_USBFS_DEV_DRV_INTR_SIE_SOF); in cyhal_usb_dev_sof_enable()
587 Cy_USBFS_Dev_Drv_SetSieInterruptMask(obj->base, mask); in cyhal_usb_dev_sof_enable()
590 void cyhal_usb_dev_set_address(cyhal_usb_dev_t *obj, uint8_t address) in cyhal_usb_dev_set_address() argument
592 Cy_USBFS_Dev_Drv_SetAddress(obj->base, address, &(obj->context)); in cyhal_usb_dev_set_address()
595 uint32_t cyhal_usb_dev_ep0_get_max_packet(cyhal_usb_dev_t *obj) in cyhal_usb_dev_ep0_get_max_packet() argument
597 return Cy_USBFS_Dev_Drv_GetEp0MaxPacket(obj->base); in cyhal_usb_dev_ep0_get_max_packet()
600 void cyhal_usb_dev_ep0_setup_read_result(cyhal_usb_dev_t *obj, uint8_t *buffer, uint32_t size) in cyhal_usb_dev_ep0_setup_read_result() argument
605 Cy_USBFS_Dev_Drv_Ep0GetSetup(obj->base, buffer, &(obj->context)); in cyhal_usb_dev_ep0_setup_read_result()
608 void cyhal_usb_dev_ep0_read(cyhal_usb_dev_t *obj, uint8_t *buffer, uint32_t size) in cyhal_usb_dev_ep0_read() argument
610 Cy_USBFS_Dev_Drv_Ep0Read(obj->base, buffer, size, &(obj->context)); in cyhal_usb_dev_ep0_read()
613 uint32_t cyhal_usb_dev_ep0_read_result(cyhal_usb_dev_t *obj) in cyhal_usb_dev_ep0_read_result() argument
615 return Cy_USBFS_Dev_Drv_Ep0ReadResult(obj->base, &(obj->context)); in cyhal_usb_dev_ep0_read_result()
618 uint32_t cyhal_usb_dev_ep0_write(cyhal_usb_dev_t *obj, uint8_t *buffer, uint32_t size) in cyhal_usb_dev_ep0_write() argument
620 return Cy_USBFS_Dev_Drv_Ep0Write(obj->base, buffer, size, &(obj->context)); in cyhal_usb_dev_ep0_write()
623 void cyhal_usb_dev_ep0_stall(cyhal_usb_dev_t *obj) in cyhal_usb_dev_ep0_stall() argument
625 Cy_USBFS_Dev_Drv_Ep0Stall(obj->base); in cyhal_usb_dev_ep0_stall()
628 cy_rslt_t cyhal_usb_dev_endpoint_add(cyhal_usb_dev_t *obj, bool alloc, bool enable, in cyhal_usb_dev_endpoint_add() argument
643 …return (CY_USBFS_DEV_DRV_SUCCESS == Cy_USBFS_Dev_Drv_AddEndpoint(obj->base, &ep_config, &(obj->con… in cyhal_usb_dev_endpoint_add()
647 cy_rslt_t cyhal_usb_dev_endpoint_remove(cyhal_usb_dev_t *obj, cyhal_usb_dev_ep_t endpoint) in cyhal_usb_dev_endpoint_remove() argument
649 …return (CY_USBFS_DEV_DRV_SUCCESS == Cy_USBFS_Dev_Drv_RemoveEndpoint(obj->base, endpoint, &(obj->co… in cyhal_usb_dev_endpoint_remove()
653 cy_rslt_t cyhal_usb_dev_endpoint_stall(cyhal_usb_dev_t *obj, cyhal_usb_dev_ep_t endpoint) in cyhal_usb_dev_endpoint_stall() argument
655 …DEV_DRV_SUCCESS == Cy_USBFS_Dev_Drv_StallEndpoint(obj->base, CYHAL_USB_DEV_GET_EP_NUM(endpoint), &… in cyhal_usb_dev_endpoint_stall()
659 cy_rslt_t cyhal_usb_dev_endpoint_unstall(cyhal_usb_dev_t *obj, cyhal_usb_dev_ep_t endpoint) in cyhal_usb_dev_endpoint_unstall() argument
661 …V_DRV_SUCCESS == Cy_USBFS_Dev_Drv_UnStallEndpoint(obj->base, CYHAL_USB_DEV_GET_EP_NUM(endpoint), &… in cyhal_usb_dev_endpoint_unstall()
665 bool cyhal_usb_dev_endpoint_is_stalled(cyhal_usb_dev_t *obj, cyhal_usb_dev_ep_t endpoint) in cyhal_usb_dev_endpoint_is_stalled() argument
667 …V_EP_STALLED == Cy_USBFS_Dev_Drv_GetEndpointState(obj->base, CYHAL_USB_DEV_GET_EP_NUM(endpoint), &… in cyhal_usb_dev_endpoint_is_stalled()
670 cy_rslt_t cyhal_usb_dev_endpoint_read(cyhal_usb_dev_t *obj, cyhal_usb_dev_ep_t endpoint, uint8_t *d… in cyhal_usb_dev_endpoint_read() argument
677 ep_state = Cy_USBFS_Dev_Drv_GetEndpointState(obj->base, ep_num, &(obj->context)); in cyhal_usb_dev_endpoint_read()
681 obj->rd_data[CYHAL_USB_DEV_GET_EP_IDX(endpoint)] = data; in cyhal_usb_dev_endpoint_read()
682 obj->rd_size[CYHAL_USB_DEV_GET_EP_IDX(endpoint)] = size; in cyhal_usb_dev_endpoint_read()
684 Cy_USBFS_Dev_Drv_EnableOutEndpoint(obj->base, ep_num, &obj->context); in cyhal_usb_dev_endpoint_read()
692 cy_rslt_t cyhal_usb_dev_endpoint_read_result(cyhal_usb_dev_t *obj, cyhal_usb_dev_ep_t endpoint, uin… in cyhal_usb_dev_endpoint_read_result() argument
698 …if (CY_USB_DEV_EP_COMPLETED == Cy_USBFS_Dev_Drv_GetEndpointState(obj->base, ep_num, &(obj->context… in cyhal_usb_dev_endpoint_read_result()
700 result = (CY_USBFS_DEV_DRV_SUCCESS == Cy_USBFS_Dev_Drv_ReadOutEndpoint(obj->base, in cyhal_usb_dev_endpoint_read_result()
702 … obj->rd_data[CYHAL_USB_DEV_GET_EP_IDX(endpoint)], in cyhal_usb_dev_endpoint_read_result()
703 … obj->rd_size[CYHAL_USB_DEV_GET_EP_IDX(endpoint)], in cyhal_usb_dev_endpoint_read_result()
705 … &(obj->context))) ? CY_RSLT_SUCCESS : CYHAL_USB_DEV_RSLT_ERR; in cyhal_usb_dev_endpoint_read_result()
711 cy_rslt_t cyhal_usb_dev_endpoint_write(cyhal_usb_dev_t *obj, cyhal_usb_dev_ep_t endpoint, uint8_t c… in cyhal_usb_dev_endpoint_write() argument
717 …cy_en_usb_dev_ep_state_t ep_state = Cy_USBFS_Dev_Drv_GetEndpointState(obj->base, ep_num, &(obj->co… in cyhal_usb_dev_endpoint_write()
720 result = (CY_USBFS_DEV_DRV_SUCCESS == Cy_USBFS_Dev_Drv_LoadInEndpoint(obj->base, in cyhal_usb_dev_endpoint_write()
724 … &(obj->context))) ? CY_RSLT_SUCCESS : CYHAL_USB_DEV_RSLT_ERR; in cyhal_usb_dev_endpoint_write()
730 cy_rslt_t cyhal_usb_dev_endpoint_abort(cyhal_usb_dev_t *obj, cyhal_usb_dev_ep_t endpoint) in cyhal_usb_dev_endpoint_abort() argument
732 …Y_USBFS_DEV_DRV_SUCCESS == Cy_USBFS_Dev_Drv_Abort(obj->base, CYHAL_USB_DEV_GET_EP_NUM(endpoint), &… in cyhal_usb_dev_endpoint_abort()
736 void cyhal_usb_dev_irq_enable(cyhal_usb_dev_t *obj, bool enable) in cyhal_usb_dev_irq_enable() argument
738 uint32_t instance = (uint32_t)obj->resource.block_num; in cyhal_usb_dev_irq_enable()
751 void cyhal_usb_dev_process_irq(cyhal_usb_dev_t *obj) in cyhal_usb_dev_process_irq() argument
753 …Cy_USBFS_Dev_Drv_Interrupt(obj->base, Cy_USBFS_Dev_Drv_GetInterruptCauseLo(obj->base), &(obj->cont… in cyhal_usb_dev_process_irq()
756 cy_rslt_t cyhal_usb_dev_register_irq_callback(cyhal_usb_dev_t *obj, cyhal_usb_dev_irq_callback_t ca… in cyhal_usb_dev_register_irq_callback() argument
758 uint32_t instance = (uint32_t)obj->resource.block_num; in cyhal_usb_dev_register_irq_callback()
765 void cyhal_usb_dev_register_event_callback(cyhal_usb_dev_t *obj, cyhal_usb_dev_event_t event, cyhal… in cyhal_usb_dev_register_event_callback() argument
768 uint32_t instance = (uint32_t)obj->resource.block_num; in cyhal_usb_dev_register_event_callback()
773 void cyhal_usb_dev_register_sof_callback( cyhal_usb_dev_t *obj, cyhal_usb_dev_sof_callback_t callba… in cyhal_usb_dev_register_sof_callback() argument
775 uint32_t instance = (uint32_t)obj->resource.block_num; in cyhal_usb_dev_register_sof_callback()
779 void cyhal_usb_dev_register_endpoint_callback(cyhal_usb_dev_t *obj, cyhal_usb_dev_ep_t endpoint, cy… in cyhal_usb_dev_register_endpoint_callback() argument
782 uint32_t instance = (uint32_t)obj->resource.block_num; in cyhal_usb_dev_register_endpoint_callback()