|
| 1 | +/* |
| 2 | +* Copyright (c) 2020 - 2025 Renesas Electronics Corporation and/or its affiliates |
| 3 | +* |
| 4 | +* SPDX-License-Identifier: BSD-3-Clause |
| 5 | +*/ |
| 6 | + |
| 7 | +#ifndef R_SCI_B_SPI_H |
| 8 | +#define R_SCI_B_SPI_H |
| 9 | + |
| 10 | +/*********************************************************************************************************************** |
| 11 | + * Includes |
| 12 | + **********************************************************************************************************************/ |
| 13 | +#include "r_spi_api.h" |
| 14 | + |
| 15 | +/* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */ |
| 16 | +FSP_HEADER |
| 17 | + |
| 18 | +/*****************************************************************************************************************//** |
| 19 | + * @ingroup SCI_B_SPI |
| 20 | + * @{ |
| 21 | + ********************************************************************************************************************/ |
| 22 | + |
| 23 | +/*********************************************************************************************************************** |
| 24 | + * Macro definitions |
| 25 | + **********************************************************************************************************************/ |
| 26 | + |
| 27 | +/*********************************************************************************************************************** |
| 28 | + * Typedef definitions |
| 29 | + **********************************************************************************************************************/ |
| 30 | + |
| 31 | +/** Settings for adjusting the SPI CLK. */ |
| 32 | +typedef struct |
| 33 | +{ |
| 34 | + uint8_t brr; |
| 35 | + uint8_t cks : 2; |
| 36 | + uint8_t bgdm : 1; |
| 37 | +} sci_b_spi_div_setting_t; |
| 38 | + |
| 39 | +/** Source clock selection options for SCI. */ |
| 40 | +typedef enum e_sci_b_spi_clock_source |
| 41 | +{ |
| 42 | + SCI_B_SPI_SOURCE_CLOCK_SCISPICLK = 0, |
| 43 | + SCI_B_SPI_SOURCE_CLOCK_PCLK = 1, |
| 44 | +} sci_b_spi_clock_source_t; |
| 45 | + |
| 46 | +/** SCI SPI extended configuration */ |
| 47 | +typedef struct st_sci_b_spi_extended_cfg |
| 48 | +{ |
| 49 | + sci_b_spi_div_setting_t clk_div; |
| 50 | + |
| 51 | + /** Clock source to generate SCK can either be selected as PCLK or SCISPICLK. */ |
| 52 | + sci_b_spi_clock_source_t clock_source; |
| 53 | +} sci_b_spi_extended_cfg_t; |
| 54 | + |
| 55 | +/** SPI instance control block. DO NOT INITIALIZE. */ |
| 56 | +typedef struct st_sci_b_spi_instance_ctrl |
| 57 | +{ |
| 58 | + uint32_t open; |
| 59 | + spi_cfg_t const * p_cfg; |
| 60 | + R_SCI_B0_Type * p_reg; |
| 61 | + uint8_t * p_src; |
| 62 | + uint8_t * p_dest; |
| 63 | + uint32_t tx_count; |
| 64 | + uint32_t rx_count; |
| 65 | + uint32_t count; |
| 66 | + |
| 67 | + /* Pointer to callback and optional working memory */ |
| 68 | + void (* p_callback)(spi_callback_args_t *); |
| 69 | + spi_callback_args_t * p_callback_memory; |
| 70 | + |
| 71 | + /* Pointer to context to be passed into callback function */ |
| 72 | + void * p_context; |
| 73 | +} sci_b_spi_instance_ctrl_t; |
| 74 | + |
| 75 | +/********************************************************************************************************************** |
| 76 | + * Exported global variables |
| 77 | + **********************************************************************************************************************/ |
| 78 | + |
| 79 | +/** @cond INC_HEADER_DEFS_SEC */ |
| 80 | +/** Filled in Interface API structure for this Instance. */ |
| 81 | +extern const spi_api_t g_spi_on_sci_b; |
| 82 | + |
| 83 | +/** @endcond */ |
| 84 | + |
| 85 | +/********************************************************************************************************************** |
| 86 | + * Public Function Prototypes |
| 87 | + **********************************************************************************************************************/ |
| 88 | +fsp_err_t R_SCI_B_SPI_Open(spi_ctrl_t * p_api_ctrl, spi_cfg_t const * const p_cfg); |
| 89 | +fsp_err_t R_SCI_B_SPI_Read(spi_ctrl_t * const p_api_ctrl, |
| 90 | + void * p_dest, |
| 91 | + uint32_t const length, |
| 92 | + spi_bit_width_t const bit_width); |
| 93 | +fsp_err_t R_SCI_B_SPI_Write(spi_ctrl_t * const p_api_ctrl, |
| 94 | + void const * p_src, |
| 95 | + uint32_t const length, |
| 96 | + spi_bit_width_t const bit_width); |
| 97 | +fsp_err_t R_SCI_B_SPI_WriteRead(spi_ctrl_t * const p_api_ctrl, |
| 98 | + void const * p_src, |
| 99 | + void * p_dest, |
| 100 | + uint32_t const length, |
| 101 | + spi_bit_width_t const bit_width); |
| 102 | +fsp_err_t R_SCI_B_SPI_Close(spi_ctrl_t * const p_api_ctrl); |
| 103 | +fsp_err_t R_SCI_B_SPI_CalculateBitrate(uint32_t bitrate, |
| 104 | + sci_b_spi_clock_source_t clock_source, |
| 105 | + sci_b_spi_div_setting_t * sclk_div); |
| 106 | +fsp_err_t R_SCI_B_SPI_CallbackSet(spi_ctrl_t * const p_api_ctrl, |
| 107 | + void ( * p_callback)(spi_callback_args_t *), |
| 108 | + void * const p_context, |
| 109 | + spi_callback_args_t * const p_callback_memory); |
| 110 | + |
| 111 | +/* Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */ |
| 112 | +FSP_FOOTER |
| 113 | + |
| 114 | +#endif |
| 115 | + |
| 116 | +/*******************************************************************************************************************//** |
| 117 | + * @} (end ingroup SCI_B_SPI) |
| 118 | + **********************************************************************************************************************/ |
0 commit comments