Lines Matching refs:obj
140 static void _cyhal_ssel_switch_state(cyhal_spi_t *obj, uint8_t ssel_idx, bool ssel_activate);
142 static cy_rslt_t _cyhal_spi_int_frequency(cyhal_spi_t *obj, uint32_t hz, uint8_t *over_sample_val) in _cyhal_spi_int_frequency() argument
144 CY_ASSERT(NULL != obj); in _cyhal_spi_int_frequency()
155 uint32_t peri_freq = _cyhal_utils_get_peripheral_clock_frequency(&(obj->resource)); in _cyhal_spi_int_frequency()
156 if (!obj->is_slave) in _cyhal_spi_int_frequency()
170 divider_value = _cyhal_utils_divider_value(&(obj->resource), hz * oversample_value, 0); in _cyhal_spi_int_frequency()
172 if(!_cyhal_clock_is_divider_valid(&(obj->resource), divider_value)) in _cyhal_spi_int_frequency()
229 …l_utils_peri_pclk_disable_divider(_cyhal_scb_get_clock_index(obj->resource.block_num), &(obj->cloc… in _cyhal_spi_int_frequency()
230 …= _cyhal_utils_peri_pclk_set_freq(_cyhal_scb_get_clock_index(obj->resource.block_num), &(obj->cloc… in _cyhal_spi_int_frequency()
233 …al_utils_peri_pclk_enable_divider(_cyhal_scb_get_clock_index(obj->resource.block_num), &(obj->cloc… in _cyhal_spi_int_frequency()
237 result = cyhal_clock_set_enabled(&(obj->clock), false, false); in _cyhal_spi_int_frequency()
240 result = cyhal_clock_set_divider(&(obj->clock), last_dvdr_val); in _cyhal_spi_int_frequency()
244 result = cyhal_clock_set_enabled(&(obj->clock), true, false); in _cyhal_spi_int_frequency()
278 cyhal_spi_t* obj = (cyhal_spi_t*)_cyhal_spi_irq_obj; in _cyhal_spi_irq_handler() local
280 if (NULL == obj) in _cyhal_spi_irq_handler()
285 Cy_SCB_SPI_Interrupt(obj->base, &(obj->context)); in _cyhal_spi_irq_handler()
287 if (!obj->is_async) in _cyhal_spi_irq_handler()
292 if (0 == (Cy_SCB_SPI_GetTransferStatus(obj->base, &obj->context) & CY_SCB_SPI_TRANSFER_ACTIVE)) in _cyhal_spi_irq_handler()
295 if (NULL != obj->tx_buffer) in _cyhal_spi_irq_handler()
298 obj->pending = _CYHAL_SPI_PENDING_TX; in _cyhal_spi_irq_handler()
299 const uint8_t *buf = obj->tx_buffer; in _cyhal_spi_irq_handler()
300 obj->tx_buffer = NULL; in _cyhal_spi_irq_handler()
302 … Cy_SCB_SPI_Transfer(obj->base, (uint8_t *)buf, NULL, obj->tx_buffer_size, &obj->context); in _cyhal_spi_irq_handler()
304 else if (NULL != obj->rx_buffer) in _cyhal_spi_irq_handler()
307 obj->pending = _CYHAL_SPI_PENDING_RX; in _cyhal_spi_irq_handler()
308 uint8_t *rx_buf = obj->rx_buffer; in _cyhal_spi_irq_handler()
310 size_t trx_size = obj->rx_buffer_size; in _cyhal_spi_irq_handler()
312 if (obj->rx_buffer_size > 1) in _cyhal_spi_irq_handler()
325 uint8_t **rx_buffer_p = (uint8_t **) &obj->rx_buffer; in _cyhal_spi_irq_handler()
328 memset(tx_buf, obj->write_fill, trx_size); in _cyhal_spi_irq_handler()
331 obj->rx_buffer_size = 1; // Transfer the last byte on the next interrupt in _cyhal_spi_irq_handler()
335 tx_buf = &obj->write_fill; in _cyhal_spi_irq_handler()
337 obj->rx_buffer = NULL; in _cyhal_spi_irq_handler()
340 Cy_SCB_SPI_Transfer(obj->base, tx_buf, rx_buf, trx_size, &obj->context); in _cyhal_spi_irq_handler()
346 obj->pending = _CYHAL_SPI_PENDING_NONE; in _cyhal_spi_irq_handler()
347 obj->is_async = false; in _cyhal_spi_irq_handler()
348 _cyhal_ssel_switch_state(obj, obj->active_ssel, _CYHAL_SPI_SSEL_DEACTIVATE); in _cyhal_spi_irq_handler()
381 cyhal_spi_t *obj = (cyhal_spi_t*)_cyhal_spi_irq_obj; in _cyhal_spi_cb_wrapper() local
382 …cyhal_spi_event_t anded_events = (cyhal_spi_event_t) (obj->irq_cause & (uint32_t) _cyhal_spi_conve… in _cyhal_spi_cb_wrapper()
385 …nts & (CYHAL_SPI_IRQ_DATA_IN_FIFO | CYHAL_SPI_IRQ_DONE)) && !(obj->rx_buffer == NULL && obj->tx_bu… in _cyhal_spi_cb_wrapper()
393 obj->op_in_callback = true; in _cyhal_spi_cb_wrapper()
394 … cyhal_spi_event_callback_t callback = (cyhal_spi_event_callback_t) obj->callback_data.callback; in _cyhal_spi_cb_wrapper()
395 callback(obj->callback_data.callback_arg, anded_events); in _cyhal_spi_cb_wrapper()
396 obj->op_in_callback = false; in _cyhal_spi_cb_wrapper()
433 cyhal_spi_t *obj = (cyhal_spi_t *)obj_ptr; in _cyhal_spi_pm_callback_instance() local
436 .base = (void *) (obj->base), in _cyhal_spi_pm_callback_instance()
437 .context = (void *) &(obj->context) in _cyhal_spi_pm_callback_instance()
500 static cy_rslt_t _cyhal_spi_ssel_config(cyhal_spi_t *obj, cyhal_gpio_t ssel, in _cyhal_spi_ssel_config() argument
506 if ((NC != ssel) && (_CYHAL_SPI_PENDING_NONE == obj->pending)) in _cyhal_spi_ssel_config()
510 if ((configuring_existing = (ssel == obj->pin_ssel[i]))) in _cyhal_spi_ssel_config()
516 if (!obj->is_slave) in _cyhal_spi_ssel_config()
519 if ((NC == obj->pin_ssel[i])) in _cyhal_spi_ssel_config()
528 if (!configuring_existing && (obj->is_slave)) in _cyhal_spi_ssel_config()
531 … if (CY_RSLT_SUCCESS == _cyhal_spi_get_ssel_map_idx(ssel, &ssel_map, &found_idx, &(obj->resource))) in _cyhal_spi_ssel_config()
534 if ((NULL != ssel_map) && (NC == obj->pin_ssel[found_idx]) && in _cyhal_spi_ssel_config()
535 (ssel_map->block_num == obj->resource.block_num) && in _cyhal_spi_ssel_config()
536 (ssel_map->channel_num == obj->resource.channel_num)) in _cyhal_spi_ssel_config()
547 obj->pin_ssel[found_idx] = ssel; in _cyhal_spi_ssel_config()
548 obj->ssel_pol[found_idx] = _cyhal_spi_pol_from_hal_to_pdl(polarity); in _cyhal_spi_ssel_config()
551 …Cy_SCB_SPI_SetActiveSlaveSelectPolarity(obj->base, (cy_en_scb_spi_slave_select_t)found_idx, obj->s… in _cyhal_spi_ssel_config()
552 if (!obj->is_slave) in _cyhal_spi_ssel_config()
554 _cyhal_ssel_switch_state(obj, found_idx, _CYHAL_SPI_SSEL_DEACTIVATE); in _cyhal_spi_ssel_config()
562 static cy_rslt_t _cyhal_spi_wait_for_op(cyhal_spi_t *obj, uint8_t op, uint32_t* timeout) in _cyhal_spi_wait_for_op() argument
570 if (!(obj->op_in_callback) && *timeout > 0) in _cyhal_spi_wait_for_op()
577 op_condition = (cyhal_spi_readable(obj) == 0 && !cyhal_spi_is_busy(obj)); in _cyhal_spi_wait_for_op()
580 op_condition = (cyhal_spi_readable(obj) == 0 || cyhal_spi_is_busy(obj)); in _cyhal_spi_wait_for_op()
583 …op_condition = ((cyhal_spi_writable(obj) < Cy_SCB_GetFifoSize(obj->base)) || cyhal_spi_is_busy(obj… in _cyhal_spi_wait_for_op()
606 static cy_rslt_t _cyhal_spi_setup_resources(cyhal_spi_t *obj, cyhal_gpio_t mosi, cyhal_gpio_t miso,… in _cyhal_spi_setup_resources() argument
611 obj->resource.type = CYHAL_RSC_INVALID; in _cyhal_spi_setup_resources()
612 obj->pending = _CYHAL_SPI_PENDING_NONE; in _cyhal_spi_setup_resources()
613 obj->write_fill = (uint8_t) CY_SCB_SPI_DEFAULT_TX; in _cyhal_spi_setup_resources()
614 obj->oversample_value = _CYHAL_SPI_OVERSAMPLE_MIN; in _cyhal_spi_setup_resources()
616 obj->pin_mosi = NC; in _cyhal_spi_setup_resources()
617 obj->pin_miso = NC; in _cyhal_spi_setup_resources()
618 obj->pin_sclk = NC; in _cyhal_spi_setup_resources()
627 if (obj->is_slave) in _cyhal_spi_setup_resources()
707 if (obj->is_slave) in _cyhal_spi_setup_resources()
715 result = _cyhal_spi_get_ssel_map_idx(ssel, &ssel_map, &obj->active_ssel, spi_inst_p); in _cyhal_spi_setup_resources()
739 …((obj->is_slave) && ((NC != ssel) && ((NULL == ssel_map) || !_cyhal_utils_map_resources_equal(base… in _cyhal_spi_setup_resources()
748 if (false == obj->dc_configured) in _cyhal_spi_setup_resources()
759 obj->resource = *spi_inst_p; in _cyhal_spi_setup_resources()
760 uint8_t scb_arr_index = _cyhal_scb_get_block_index(obj->resource.block_num); in _cyhal_spi_setup_resources()
761 obj->base = _CYHAL_SCB_BASE_ADDRESSES[scb_arr_index]; in _cyhal_spi_setup_resources()
767 …result = _cyhal_utils_allocate_clock(&(obj->clock), &(obj->resource), CYHAL_CLOCK_BLOCK_PERIPHERAL… in _cyhal_spi_setup_resources()
768 obj->alloc_clock = true; in _cyhal_spi_setup_resources()
769 … result = _cyhal_spi_int_frequency(obj, _CYHAL_SPI_DEFAULT_SPEED, &obj->oversample_value); in _cyhal_spi_setup_resources()
773 obj->clock = *clk; in _cyhal_spi_setup_resources()
774 obj->alloc_clock = false; in _cyhal_spi_setup_resources()
775 … result = _cyhal_spi_int_frequency(obj, _CYHAL_SPI_DEFAULT_SPEED, &obj->oversample_value); in _cyhal_spi_setup_resources()
785 if (false == obj->dc_configured) in _cyhal_spi_setup_resources()
791 obj->pin_mosi = mosi; in _cyhal_spi_setup_resources()
801 if (false == obj->dc_configured) in _cyhal_spi_setup_resources()
807 obj->pin_miso = miso; in _cyhal_spi_setup_resources()
817 if (false == obj->dc_configured) in _cyhal_spi_setup_resources()
823 obj->pin_sclk = sclk; in _cyhal_spi_setup_resources()
831 result = _cyhal_spi_ssel_config(obj, ssel, in _cyhal_spi_setup_resources()
832 … (cyhal_spi_ssel_polarity_t)((ssPolarity >> obj->active_ssel) & 0x1), !obj->dc_configured); in _cyhal_spi_setup_resources()
841 …result = _cyhal_utils_allocate_clock(&(obj->clock), &(obj->resource), CYHAL_CLOCK_BLOCK_PERIPHERAL… in _cyhal_spi_setup_resources()
842 obj->alloc_clock = true; in _cyhal_spi_setup_resources()
846 obj->clock = *clk; in _cyhal_spi_setup_resources()
847 obj->alloc_clock = false; in _cyhal_spi_setup_resources()
851 …if ((_CYHAL_PERIPHERAL_GROUP_GET_DIVIDER_TYPE(obj->clock.block) == (cy_en_divider_types_t)CYHAL_CL… in _cyhal_spi_setup_resources()
852 …(_CYHAL_PERIPHERAL_GROUP_GET_DIVIDER_TYPE(obj->clock.block) == (cy_en_divider_types_t)CYHAL_CLOCK_… in _cyhal_spi_setup_resources()
861 …al_utils_peri_pclk_assign_divider(_cyhal_scb_get_clock_index(obj->resource.block_num), &(obj->cloc… in _cyhal_spi_setup_resources()
863 if ((result == CY_RSLT_SUCCESS) && obj->alloc_clock) in _cyhal_spi_setup_resources()
865 … result = _cyhal_spi_int_frequency(obj, _CYHAL_SPI_DEFAULT_SPEED, &obj->oversample_value); in _cyhal_spi_setup_resources()
872 static cy_rslt_t _cyhal_spi_init_hw(cyhal_spi_t *obj, cy_stc_scb_spi_config_t *cfg) in _cyhal_spi_init_hw() argument
876 …_cyhal_scb_update_instance_data(obj->resource.block_num, (void*)obj, &_cyhal_spi_pm_callback_insta… in _cyhal_spi_init_hw()
877 if ((false != obj->dc_configured) || !(obj->alloc_clock)) in _cyhal_spi_init_hw()
879 obj->oversample_value = cfg->oversample; in _cyhal_spi_init_hw()
881 obj->data_bits = cfg->txDataWidth; in _cyhal_spi_init_hw()
882 obj->msb_first = cfg->enableMsbFirst; in _cyhal_spi_init_hw()
883 obj->clk_mode = cfg->sclkMode; in _cyhal_spi_init_hw()
884 obj->mode = (uint8_t) _cyhal_spi_mode_pdl_to_hal(cfg); in _cyhal_spi_init_hw()
886 result = (cy_rslt_t)Cy_SCB_SPI_Init(obj->base, cfg, &(obj->context)); in _cyhal_spi_init_hw()
891 if (NC != obj->pin_ssel[obj->active_ssel]) in _cyhal_spi_init_hw()
893 result = cyhal_spi_select_active_ssel(obj, obj->pin_ssel[obj->active_ssel]); in _cyhal_spi_init_hw()
899 uint8_t scb_arr_index = _cyhal_scb_get_block_index(obj->resource.block_num); in _cyhal_spi_init_hw()
901 obj->callback_data.callback = NULL; in _cyhal_spi_init_hw()
902 obj->callback_data.callback_arg = NULL; in _cyhal_spi_init_hw()
903 obj->irq_cause = 0; in _cyhal_spi_init_hw()
906 Cy_SCB_RegisterInterruptCallback(obj->base, _cyhal_irq_cb[obj->resource.block_num]); in _cyhal_spi_init_hw()
907 Cy_SCB_EnableInterrupt(obj->base); in _cyhal_spi_init_hw()
912 Cy_SCB_SPI_Enable(obj->base); in _cyhal_spi_init_hw()
916 cyhal_spi_free(obj); in _cyhal_spi_init_hw()
921 cy_rslt_t cyhal_spi_init(cyhal_spi_t *obj, cyhal_gpio_t mosi, cyhal_gpio_t miso, cyhal_gpio_t sclk,… in cyhal_spi_init() argument
924 CY_ASSERT(NULL != obj); in cyhal_spi_init()
925 memset(obj, 0, sizeof(cyhal_spi_t)); in cyhal_spi_init()
945 obj->pin_ssel[i] = NC; in cyhal_spi_init()
946 obj->ssel_pol[i] = CY_SCB_SPI_ACTIVE_LOW; in cyhal_spi_init()
949 obj->active_ssel = 0; in cyhal_spi_init()
950 obj->is_slave = is_slave; in cyhal_spi_init()
952 result = _cyhal_spi_setup_resources(obj, mosi, miso, sclk, ssel, clk, driver_config.ssPolarity); in cyhal_spi_init()
956 result = _cyhal_spi_init_hw(obj, &driver_config); in cyhal_spi_init()
960 cyhal_spi_free(obj); in cyhal_spi_init()
965 cy_rslt_t cyhal_spi_init_cfg(cyhal_spi_t *obj, const cyhal_spi_configurator_t *cfg) in cyhal_spi_init_cfg() argument
967 CY_ASSERT(NULL != obj); in cyhal_spi_init_cfg()
971 memset(obj, 0, sizeof(cyhal_spi_t)); in cyhal_spi_init_cfg()
973 obj->dc_configured = (NULL != cfg->resource); in cyhal_spi_init_cfg()
976 if (obj->dc_configured && in cyhal_spi_init_cfg()
999 obj->pin_ssel[i] = NC; in cyhal_spi_init_cfg()
1000 obj->ssel_pol[i] = CY_SCB_SPI_ACTIVE_LOW; in cyhal_spi_init_cfg()
1003 obj->resource = *cfg->resource; in cyhal_spi_init_cfg()
1004 uint8_t scb_arr_index = _cyhal_scb_get_block_index(obj->resource.block_num); in cyhal_spi_init_cfg()
1005 obj->base = _CYHAL_SCB_BASE_ADDRESSES[scb_arr_index]; in cyhal_spi_init_cfg()
1007 obj->active_ssel = 0; in cyhal_spi_init_cfg()
1008 obj->is_slave = is_slave; in cyhal_spi_init_cfg()
1009 obj->write_fill = (uint8_t) CY_SCB_SPI_DEFAULT_TX; in cyhal_spi_init_cfg()
1012 obj->pin_mosi = cfg->gpios.mosi; in cyhal_spi_init_cfg()
1013 obj->pin_miso = cfg->gpios.miso; in cyhal_spi_init_cfg()
1014 obj->pin_sclk = cfg->gpios.sclk; in cyhal_spi_init_cfg()
1019 obj->pin_ssel[ssel_idx] = cfg->gpios.ssel[ssel_idx]; in cyhal_spi_init_cfg()
1020 obj->active_ssel = ssel_idx; in cyhal_spi_init_cfg()
1021 result = _cyhal_spi_ssel_config(obj, obj->pin_ssel[ssel_idx], in cyhal_spi_init_cfg()
1022 …(cyhal_spi_ssel_polarity_t)((obj->ssel_pol[ssel_idx] >> obj->active_ssel) & 0x1), !obj->dc_configu… in cyhal_spi_init_cfg()
1033 …result = _cyhal_utils_allocate_clock(&(obj->clock), &(obj->resource), CYHAL_CLOCK_BLOCK_PERIPHERAL… in cyhal_spi_init_cfg()
1034 obj->alloc_clock = true; in cyhal_spi_init_cfg()
1038 …al_utils_peri_pclk_assign_divider(_cyhal_scb_get_clock_index(obj->resource.block_num), &(obj->cloc… in cyhal_spi_init_cfg()
1043 … result = _cyhal_spi_int_frequency(obj, _CYHAL_SPI_DEFAULT_SPEED, &obj->oversample_value); in cyhal_spi_init_cfg()
1048 obj->clock = *cfg->clock; in cyhal_spi_init_cfg()
1049 obj->alloc_clock = false; in cyhal_spi_init_cfg()
1053 …if ((_CYHAL_PERIPHERAL_GROUP_GET_DIVIDER_TYPE(obj->clock.block) == (cy_en_divider_types_t)CYHAL_CL… in cyhal_spi_init_cfg()
1054 …(_CYHAL_PERIPHERAL_GROUP_GET_DIVIDER_TYPE(obj->clock.block) == (cy_en_divider_types_t)CYHAL_CLOCK_… in cyhal_spi_init_cfg()
1064 result = _cyhal_spi_init_hw(obj, &cfg_local); in cyhal_spi_init_cfg()
1068 size_t ssel_idx = obj->active_ssel; in cyhal_spi_init_cfg()
1074 result = _cyhal_spi_ssel_config(obj, cfg->gpios.ssel[ssel_idx], in cyhal_spi_init_cfg()
1076 !obj->dc_configured); in cyhal_spi_init_cfg()
1081 cyhal_spi_free(obj); in cyhal_spi_init_cfg()
1086 void cyhal_spi_free(cyhal_spi_t *obj) in cyhal_spi_free() argument
1088 if (NULL != obj->base) in cyhal_spi_free()
1090 _cyhal_scb_update_instance_data(obj->resource.block_num, NULL, NULL); in cyhal_spi_free()
1091 Cy_SCB_SPI_Disable(obj->base, NULL); in cyhal_spi_free()
1092 Cy_SCB_SPI_DeInit(obj->base); in cyhal_spi_free()
1093 obj->base = NULL; in cyhal_spi_free()
1096 if (obj->resource.type != CYHAL_RSC_INVALID) in cyhal_spi_free()
1098 uint8_t scb_arr_index = _cyhal_scb_get_block_index(obj->resource.block_num); in cyhal_spi_free()
1102 if (false == obj->dc_configured) in cyhal_spi_free()
1104 …t_t rsc_to_free = { CYHAL_RSC_SCB, _cyhal_scb_get_block_index(obj->resource.block_num), obj->resou… in cyhal_spi_free()
1107 obj->resource.type = CYHAL_RSC_INVALID; in cyhal_spi_free()
1110 if (false == obj->dc_configured) in cyhal_spi_free()
1112 _cyhal_utils_release_if_used(&(obj->pin_miso)); in cyhal_spi_free()
1113 _cyhal_utils_release_if_used(&(obj->pin_mosi)); in cyhal_spi_free()
1114 _cyhal_utils_release_if_used(&(obj->pin_sclk)); in cyhal_spi_free()
1118 if(obj->is_slave == false) in cyhal_spi_free()
1125 cyhal_gpio_free((obj->pin_ssel[i])); in cyhal_spi_free()
1130 _cyhal_utils_release_if_used(&(obj->pin_ssel[i])); in cyhal_spi_free()
1135 if (obj->alloc_clock) in cyhal_spi_free()
1137 cyhal_clock_free(&(obj->clock)); in cyhal_spi_free()
1138 obj->alloc_clock = false; in cyhal_spi_free()
1142 static void _cyhal_ssel_switch_state(cyhal_spi_t *obj, uint8_t ssel_idx, bool ssel_activate) in _cyhal_ssel_switch_state() argument
1144 if ((!obj->is_slave) && (CYHAL_NC_PIN_VALUE != obj->pin_ssel[ssel_idx])) in _cyhal_ssel_switch_state()
1153 …bool ssel_state = (CY_SCB_SPI_ACTIVE_LOW == obj->ssel_pol[ssel_idx]) ? !ssel_activate : ssel_activ… in _cyhal_ssel_switch_state()
1154 cyhal_gpio_write(obj->pin_ssel[ssel_idx], ssel_state); in _cyhal_ssel_switch_state()
1158 cy_rslt_t cyhal_spi_set_frequency(cyhal_spi_t *obj, uint32_t hz) in cyhal_spi_set_frequency() argument
1164 if (NULL == obj) in cyhal_spi_set_frequency()
1170 if (obj->alloc_clock) in cyhal_spi_set_frequency()
1172 Cy_SCB_SPI_Disable(obj->base, &obj->context); in cyhal_spi_set_frequency()
1173 result = _cyhal_spi_int_frequency(obj, hz, &ovr_sample_val); in cyhal_spi_set_frequency()
1176 … if ((CY_RSLT_SUCCESS == result) && !obj->is_slave && (obj->oversample_value != ovr_sample_val)) in cyhal_spi_set_frequency()
1179 Cy_SCB_SPI_DeInit(obj->base); in cyhal_spi_set_frequency()
1180 config_structure.spiMode = obj->is_slave == false in cyhal_spi_set_frequency()
1183 config_structure.enableMsbFirst = obj->msb_first; in cyhal_spi_set_frequency()
1184 config_structure.sclkMode = obj->clk_mode; in cyhal_spi_set_frequency()
1185 config_structure.rxDataWidth = obj->data_bits; in cyhal_spi_set_frequency()
1186 config_structure.txDataWidth = obj->data_bits; in cyhal_spi_set_frequency()
1188 obj->oversample_value = ovr_sample_val; in cyhal_spi_set_frequency()
1189 … scb_init_result = (cy_rslt_t)Cy_SCB_SPI_Init(obj->base, &config_structure, &(obj->context)); in cyhal_spi_set_frequency()
1193 Cy_SCB_SPI_Enable(obj->base); in cyhal_spi_set_frequency()
1204 cy_rslt_t cyhal_spi_select_active_ssel(cyhal_spi_t *obj, cyhal_gpio_t ssel) in cyhal_spi_select_active_ssel() argument
1206 CY_ASSERT(NULL != obj); in cyhal_spi_select_active_ssel()
1207 CY_ASSERT(NULL != obj->base); in cyhal_spi_select_active_ssel()
1213 if(obj->pin_ssel[ssel_idx] != NC) in cyhal_spi_select_active_ssel()
1225 if ((NC != ssel) && (_CYHAL_SPI_PENDING_NONE == obj->pending)) in cyhal_spi_select_active_ssel()
1229 if(obj->pin_ssel[i] == ssel) in cyhal_spi_select_active_ssel()
1231 Cy_SCB_SPI_SetActiveSlaveSelect(obj->base, (cy_en_scb_spi_slave_select_t)i); in cyhal_spi_select_active_ssel()
1232 obj->active_ssel = i; in cyhal_spi_select_active_ssel()
1240 cy_rslt_t cyhal_spi_slave_select_config(cyhal_spi_t *obj, cyhal_gpio_t ssel, cyhal_spi_ssel_polarit… in cyhal_spi_slave_select_config() argument
1242 CY_ASSERT(NULL != obj); in cyhal_spi_slave_select_config()
1243 return _cyhal_spi_ssel_config(obj, ssel, polarity, true); in cyhal_spi_slave_select_config()
1246 cy_rslt_t cyhal_spi_recv(cyhal_spi_t *obj, uint32_t *value) in cyhal_spi_recv() argument
1248 if (NULL == obj) in cyhal_spi_recv()
1258 if (!obj->is_slave) in cyhal_spi_recv()
1260 _cyhal_ssel_switch_state(obj, obj->active_ssel, _CYHAL_SPI_SSEL_ACTIVATE); in cyhal_spi_recv()
1263 Cy_SCB_SPI_ClearTxFifo(obj->base); in cyhal_spi_recv()
1264 Cy_SCB_SPI_ClearRxFifo(obj->base); in cyhal_spi_recv()
1268 count = Cy_SCB_SPI_Write(obj->base, fill_in); in cyhal_spi_recv()
1271 while (Cy_SCB_SPI_IsTxComplete(obj->base) == false) { } in cyhal_spi_recv()
1272 while (Cy_SCB_SPI_GetNumInRxFifo(obj->base) == 0) { } /* Wait for RX FIFO not empty */ in cyhal_spi_recv()
1273 _cyhal_ssel_switch_state(obj, obj->active_ssel, _CYHAL_SPI_SSEL_DEACTIVATE); in cyhal_spi_recv()
1278 read_value = Cy_SCB_SPI_Read(obj->base); in cyhal_spi_recv()
1284 cy_rslt_t cyhal_spi_send(cyhal_spi_t *obj, uint32_t value) in cyhal_spi_send() argument
1286 if (NULL == obj) in cyhal_spi_send()
1295 if (!obj->is_slave) in cyhal_spi_send()
1297 _cyhal_ssel_switch_state(obj, obj->active_ssel, _CYHAL_SPI_SSEL_ACTIVATE); in cyhal_spi_send()
1300 Cy_SCB_SPI_ClearTxFifo(obj->base); in cyhal_spi_send()
1301 Cy_SCB_SPI_ClearRxFifo(obj->base); in cyhal_spi_send()
1306 count = Cy_SCB_SPI_Write(obj->base, value); in cyhal_spi_send()
1309 if (!obj->is_slave) in cyhal_spi_send()
1311 while (Cy_SCB_SPI_IsTxComplete(obj->base) == false) { } in cyhal_spi_send()
1312 while (Cy_SCB_SPI_GetNumInRxFifo(obj->base) == 0) { } /* Wait for RX FIFO not empty */ in cyhal_spi_send()
1313 _cyhal_ssel_switch_state(obj, obj->active_ssel, _CYHAL_SPI_SSEL_DEACTIVATE); in cyhal_spi_send()
1314 (void)Cy_SCB_SPI_Read(obj->base); in cyhal_spi_send()
1321 cy_rslt_t cyhal_spi_slave_read(cyhal_spi_t *obj, uint8_t *dst_buff, uint16_t *size, uint32_t timeou… in cyhal_spi_slave_read() argument
1328 status = _cyhal_spi_wait_for_op(obj, _CYHAL_SPI_WAIT_OP_RD_NOT_BUSY, &timeout); in cyhal_spi_slave_read()
1333 status = _cyhal_spi_wait_for_op(obj, _CYHAL_SPI_WAIT_OP_RD_BUSY, &timeout); in cyhal_spi_slave_read()
1338 *size = _CYHAL_SCB_BYTES_TO_COPY(cyhal_spi_readable(obj), *size); in cyhal_spi_slave_read()
1339 *size = Cy_SCB_SPI_ReadArray(obj->base, (void*)dst_buff, (uint32_t)*size); in cyhal_spi_slave_read()
1345 cy_rslt_t cyhal_spi_slave_write(cyhal_spi_t *obj, const uint8_t *src_buff, uint16_t *size, uint32_t… in cyhal_spi_slave_write() argument
1351 status = cyhal_spi_transfer_async(obj, src_buff, (size_t)*size, NULL, 0U); in cyhal_spi_slave_write()
1356 status = _cyhal_spi_wait_for_op(obj, _CYHAL_SPI_WAIT_OP_WR, &timeout); in cyhal_spi_slave_write()
1362 cy_rslt_t cyhal_spi_transfer(cyhal_spi_t *obj, const uint8_t *tx, size_t tx_length, uint8_t *rx, si… in cyhal_spi_transfer() argument
1364 if (NULL == obj) in cyhal_spi_transfer()
1370 obj->write_fill = write_fill; in cyhal_spi_transfer()
1371 cy_rslt_t rslt = cyhal_spi_transfer_async(obj, tx, tx_length, rx, rx_length); in cyhal_spi_transfer()
1374 … while (obj->pending != _CYHAL_SPI_PENDING_NONE) { } /* Wait for async transfer to complete */ in cyhal_spi_transfer()
1376 obj->write_fill = (uint8_t) CY_SCB_SPI_DEFAULT_TX; in cyhal_spi_transfer()
1380 cy_rslt_t cyhal_spi_transfer_async(cyhal_spi_t *obj, const uint8_t *tx, size_t tx_length, uint8_t *… in cyhal_spi_transfer_async() argument
1382 if (NULL == obj) in cyhal_spi_transfer_async()
1390 _cyhal_ssel_switch_state(obj, obj->active_ssel, _CYHAL_SPI_SSEL_ACTIVATE); in cyhal_spi_transfer_async()
1391 obj->is_async = true; in cyhal_spi_transfer_async()
1394 if (obj->data_bits <= 8) in cyhal_spi_transfer_async()
1398 else if (obj->data_bits <= 16) in cyhal_spi_transfer_async()
1415 obj->rx_buffer = NULL; in cyhal_spi_transfer_async()
1416 obj->tx_buffer = NULL; in cyhal_spi_transfer_async()
1424 obj->pending = _CYHAL_SPI_PENDING_TX_RX; in cyhal_spi_transfer_async()
1426 obj->tx_buffer = tx + (rx_words * arr_size_modifier); in cyhal_spi_transfer_async()
1427 obj->tx_buffer_size = tx_words - rx_words; in cyhal_spi_transfer_async()
1434 obj->pending = _CYHAL_SPI_PENDING_TX; in cyhal_spi_transfer_async()
1444 obj->pending = _CYHAL_SPI_PENDING_TX_RX; in cyhal_spi_transfer_async()
1446 obj->rx_buffer = rx + (tx_words * arr_size_modifier); in cyhal_spi_transfer_async()
1447 obj->rx_buffer_size = rx_words - tx_words; in cyhal_spi_transfer_async()
1452 obj->pending = _CYHAL_SPI_PENDING_RX; in cyhal_spi_transfer_async()
1454 obj->rx_buffer = rx_words > 1 ? rx + 1 : NULL; in cyhal_spi_transfer_async()
1455 obj->rx_buffer_size = rx_words - 1; in cyhal_spi_transfer_async()
1456 tx = &obj->write_fill; in cyhal_spi_transfer_async()
1463 obj->pending = _CYHAL_SPI_PENDING_TX_RX; in cyhal_spi_transfer_async()
1465 spi_status = Cy_SCB_SPI_Transfer(obj->base, (void *)tx, rx, tx_words, &obj->context); in cyhal_spi_transfer_async()
1473 obj->pending = _CYHAL_SPI_PENDING_RX; in cyhal_spi_transfer_async()
1478 obj->pending = _CYHAL_SPI_PENDING_TX; in cyhal_spi_transfer_async()
1483 obj->pending = _CYHAL_SPI_PENDING_TX_RX; in cyhal_spi_transfer_async()
1485 …i_status = Cy_SCB_SPI_Transfer_Buffer(obj->base, (void *)tx, (void *)rx, tx_words, rx_words, obj->… in cyhal_spi_transfer_async()
1489 obj->pending = _CYHAL_SPI_PENDING_TX_RX; in cyhal_spi_transfer_async()
1490 spi_status = Cy_SCB_SPI_Transfer(obj->base, (void *)tx, rx, tx_words, &obj->context); in cyhal_spi_transfer_async()
1499 bool cyhal_spi_is_busy(cyhal_spi_t *obj) in cyhal_spi_is_busy() argument
1501 return Cy_SCB_SPI_IsBusBusy(obj->base) || (_CYHAL_SPI_PENDING_NONE != obj->pending); in cyhal_spi_is_busy()
1504 cy_rslt_t cyhal_spi_abort_async(cyhal_spi_t *obj) in cyhal_spi_abort_async() argument
1506 if (NULL == obj) in cyhal_spi_abort_async()
1511 Cy_SCB_SPI_AbortTransfer(obj->base, &(obj->context)); in cyhal_spi_abort_async()
1512 obj->pending = _CYHAL_SPI_PENDING_NONE; in cyhal_spi_abort_async()
1516 void cyhal_spi_register_callback(cyhal_spi_t *obj, cyhal_spi_event_callback_t callback, void *callb… in cyhal_spi_register_callback() argument
1519 obj->callback_data.callback = (cy_israddress) callback; in cyhal_spi_register_callback()
1520 obj->callback_data.callback_arg = callback_arg; in cyhal_spi_register_callback()
1522 Cy_SCB_SPI_RegisterCallback(obj->base, _cyhal_spi_cb_wrapper, &(obj->context)); in cyhal_spi_register_callback()
1524 obj->irq_cause = 0; in cyhal_spi_register_callback()
1527 void cyhal_spi_enable_event(cyhal_spi_t *obj, cyhal_spi_event_t event, uint8_t intr_priority, bool … in cyhal_spi_enable_event() argument
1531 obj->irq_cause |= event; in cyhal_spi_enable_event()
1535 obj->irq_cause &= ~event; in cyhal_spi_enable_event()
1538 uint8_t scb_arr_index = _cyhal_scb_get_block_index(obj->resource.block_num); in cyhal_spi_enable_event()
1543 cy_rslt_t cyhal_spi_set_fifo_level(cyhal_spi_t *obj, cyhal_spi_fifo_type_t type, uint16_t level) in cyhal_spi_set_fifo_level() argument
1545 return _cyhal_scb_set_fifo_level(obj->base, (cyhal_scb_fifo_type_t)type, level); in cyhal_spi_set_fifo_level()
1548 cy_rslt_t cyhal_spi_enable_output(cyhal_spi_t *obj, cyhal_spi_output_t output, cyhal_source_t *sour… in cyhal_spi_enable_output() argument
1550 return _cyhal_scb_enable_output(obj->resource, (cyhal_scb_output_t)output, source); in cyhal_spi_enable_output()
1553 cy_rslt_t cyhal_spi_disable_output(cyhal_spi_t *obj, cyhal_spi_output_t output) in cyhal_spi_disable_output() argument
1555 CY_UNUSED_PARAMETER(obj); in cyhal_spi_disable_output()
1559 uint32_t cyhal_spi_readable(cyhal_spi_t *obj) in cyhal_spi_readable() argument
1561 return Cy_SCB_SPI_GetNumInRxFifo(obj->base); in cyhal_spi_readable()
1564 uint32_t cyhal_spi_writable(cyhal_spi_t *obj) in cyhal_spi_writable() argument
1566 return Cy_SCB_GetFifoSize(obj->base) - Cy_SCB_SPI_GetNumInTxFifo(obj->base); in cyhal_spi_writable()
1569 cy_rslt_t cyhal_spi_clear(cyhal_spi_t *obj) in cyhal_spi_clear() argument
1571 Cy_SCB_SPI_ClearRxFifo(obj->base); in cyhal_spi_clear()
1572 Cy_SCB_SPI_ClearTxFifo(obj->base); in cyhal_spi_clear()