1 /* 2 * Copyright (c) 2020 - 2024 Renesas Electronics Corporation and/or its affiliates 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 7 #ifndef R_SPI_B_H 8 #define R_SPI_B_H 9 10 /*******************************************************************************************************************//** 11 * @addtogroup SPI_B 12 * @{ 13 **********************************************************************************************************************/ 14 15 /*********************************************************************************************************************** 16 * Includes 17 **********************************************************************************************************************/ 18 #include "r_spi_api.h" 19 20 /* Common macro for FSP header files. There is also a corresponding FSP_FOOTER macro at the end of this file. */ 21 FSP_HEADER 22 23 /*********************************************************************************************************************** 24 * Macro definitions 25 **********************************************************************************************************************/ 26 27 /************************************************************************************************* 28 * Type defines for the SPI interface API 29 *************************************************************************************************/ 30 31 /** 3-Wire or 4-Wire mode. */ 32 typedef enum e_spi_b_ssl_mode 33 { 34 SPI_B_SSL_MODE_SPI, ///< SPI operation (4-wire method) 35 SPI_B_SSL_MODE_CLK_SYN ///< Clock Synchronous operation (3-wire method) 36 } spi_b_ssl_mode_t; 37 38 /** Transmit Only (Half Duplex), or Full Duplex. */ 39 typedef enum e_spi_b_communication 40 { 41 SPI_B_COMMUNICATION_FULL_DUPLEX, ///< Full-Duplex synchronous serial communication 42 SPI_B_COMMUNICATION_TRANSMIT_ONLY, ///< Transit only serial communication 43 } spi_b_communication_t; 44 45 /** Slave Select Polarity. */ 46 typedef enum e_spi_b_sslp 47 { 48 SPI_B_SSLP_LOW, ///< SSLP signal polarity active low 49 SPI_B_SSLP_HIGH ///< SSLP signal polarity active high 50 } spi_b_ssl_polarity_t; 51 52 /** The Slave Select Line */ 53 typedef enum e_spi_b_ssl_select 54 { 55 SPI_B_SSL_SELECT_SSL0, ///< Select SSL0 56 SPI_B_SSL_SELECT_SSL1, ///< Select SSL1 57 SPI_B_SSL_SELECT_SSL2, ///< Select SSL2 58 SPI_B_SSL_SELECT_SSL3 ///< Select SSL3 59 } spi_b_ssl_select_t; 60 61 /** MOSI Idle Behavior. */ 62 typedef enum e_spi_b_mosi_idle_value_fixing 63 { 64 SPI_B_MOSI_IDLE_VALUE_FIXING_DISABLE, ///< MOSI output value=value set in MOIFV bit 65 SPI_B_MOSI_IDLE_VALUE_FIXING_LOW, ///< MOSIn level low during MOSI idling 66 SPI_B_MOSI_IDLE_VALUE_FIXING_HIGH ///< MOSIn level high during MOSI idling 67 } spi_b_mosi_idle_value_fixing_t; 68 69 /** Parity Mode */ 70 typedef enum e_spi_b_parity_mode 71 { 72 SPI_B_PARITY_MODE_DISABLE, ///< Disable parity 73 SPI_B_PARITY_MODE_ODD, ///< Select even parity 74 SPI_B_PARITY_MODE_EVEN ///< Select odd parity 75 } spi_b_parity_t; 76 77 /** Byte Swapping Enable/Disable. */ 78 typedef enum 79 { 80 SPI_B_BYTE_SWAP_DISABLE = 0, ///< Disable Byte swapping for 16/32-Bit transfers 81 SPI_B_BYTE_SWAP_ENABLE ///< Enable Byte swapping for 16/32-Bit transfers 82 } spi_b_byte_swap_t; 83 84 /** Delay count for SPI delay settings. */ 85 typedef enum e_spi_b_clock_delay_count 86 { 87 SPI_B_DELAY_COUNT_1, ///< Set RSPCK delay count to 1 RSPCK 88 SPI_B_DELAY_COUNT_2, ///< Set RSPCK delay count to 2 RSPCK 89 SPI_B_DELAY_COUNT_3, ///< Set RSPCK delay count to 3 RSPCK 90 SPI_B_DELAY_COUNT_4, ///< Set RSPCK delay count to 4 RSPCK 91 SPI_B_DELAY_COUNT_5, ///< Set RSPCK delay count to 5 RSPCK 92 SPI_B_DELAY_COUNT_6, ///< Set RSPCK delay count to 6 RSPCK 93 SPI_B_DELAY_COUNT_7, ///< Set RSPCK delay count to 7 RSPCK 94 SPI_B_DELAY_COUNT_8 ///< Set RSPCK delay count to 8 RSPCK 95 } spi_b_delay_count_t; 96 97 /** SPI communication clock source. */ 98 typedef enum e_spi_b_clock_source 99 { 100 SPI_B_CLOCK_SOURCE_SCISPICLK, 101 SPI_B_CLOCK_SOURCE_PCLK 102 } spi_b_clock_source_t; 103 104 /** SPI Clock Divider settings. */ 105 typedef struct 106 { 107 uint8_t spbr; ///< SPBR register setting 108 uint8_t brdv : 2; ///< BRDV setting in SPCMD0 109 } rspck_div_setting_t; 110 111 /** Extended SPI interface configuration */ 112 typedef struct st_spi_b_extended_cfg 113 { 114 spi_b_ssl_mode_t spi_clksyn; ///< Select SPI or Clock Synchronous mode operation 115 spi_b_communication_t spi_comm; ///< Select full-duplex or transmit-only communication 116 spi_b_ssl_polarity_t ssl_polarity; ///< Select SSLn signal polarity 117 spi_b_ssl_select_t ssl_select; ///< Select which slave to use: 0-SSL0, 1-SSL1, 2-SSL2, 3-SSL3 118 spi_b_mosi_idle_value_fixing_t mosi_idle; ///< Select MOSI idle fixed value and selection 119 spi_b_parity_t parity; ///< Select parity and enable/disable parity 120 spi_b_byte_swap_t byte_swap; ///< Select byte swap mode 121 spi_b_clock_source_t clock_source; ///< Communication clock source (TCLK). 122 rspck_div_setting_t spck_div; ///< Register values for configuring the SPI Clock Divider. 123 spi_b_delay_count_t spck_delay; ///< SPI Clock Delay Register Setting 124 spi_b_delay_count_t ssl_negation_delay; ///< SPI Slave Select Negation Delay Register Setting 125 spi_b_delay_count_t next_access_delay; ///< SPI Next-Access Delay Register Setting 126 } spi_b_extended_cfg_t; 127 128 /** Channel control block. DO NOT INITIALIZE. Initialization occurs when @ref spi_api_t::open is called. */ 129 typedef struct st_spi_b_instance_ctrl 130 { 131 uint32_t open; ///< Indicates whether the open() API has been successfully called. 132 spi_cfg_t const * p_cfg; ///< Pointer to instance configuration 133 R_SPI_B0_Type * p_regs; ///< Base register for this channel 134 void const * p_tx_data; ///< Buffer to transmit 135 void * p_rx_data; ///< Buffer to receive 136 uint32_t tx_count; ///< Number of Data Frames to transfer (8-bit, 16-bit, 32-bit) 137 uint32_t rx_count; ///< Number of Data Frames to transfer (8-bit, 16-bit, 32-bit) 138 uint32_t count; ///< Number of Data Frames to transfer (8-bit, 16-bit, 32-bit) 139 spi_bit_width_t bit_width; ///< Bits per Data frame (8-bit, 16-bit, 32-bit) 140 141 /* Pointer to callback and optional working memory */ 142 void (* p_callback)(spi_callback_args_t *); 143 spi_callback_args_t * p_callback_memory; 144 145 /* Pointer to context to be passed into callback function */ 146 void const * p_context; 147 } spi_b_instance_ctrl_t; 148 149 /********************************************************************************************************************** 150 * Exported global variables 151 **********************************************************************************************************************/ 152 153 /** @cond INC_HEADER_DEFS_SEC */ 154 /** Filled in Interface API structure for this Instance. */ 155 extern const spi_api_t g_spi_on_spi_b; 156 157 /** @endcond */ 158 159 /*********************************************************************************************************************** 160 * Public APIs 161 **********************************************************************************************************************/ 162 fsp_err_t R_SPI_B_Open(spi_ctrl_t * p_api_ctrl, spi_cfg_t const * const p_cfg); 163 164 fsp_err_t R_SPI_B_Read(spi_ctrl_t * const p_api_ctrl, 165 void * p_dest, 166 uint32_t const length, 167 spi_bit_width_t const bit_width); 168 169 fsp_err_t R_SPI_B_Write(spi_ctrl_t * const p_api_ctrl, 170 void const * p_src, 171 uint32_t const length, 172 spi_bit_width_t const bit_width); 173 174 fsp_err_t R_SPI_B_WriteRead(spi_ctrl_t * const p_api_ctrl, 175 void const * p_src, 176 void * p_dest, 177 uint32_t const length, 178 spi_bit_width_t const bit_width); 179 180 fsp_err_t R_SPI_B_Close(spi_ctrl_t * const p_api_ctrl); 181 182 fsp_err_t R_SPI_B_CalculateBitrate(uint32_t bitrate, spi_b_clock_source_t clock_source, rspck_div_setting_t * spck_div); 183 fsp_err_t R_SPI_B_CallbackSet(spi_ctrl_t * const p_api_ctrl, 184 void ( * p_callback)(spi_callback_args_t *), 185 void const * const p_context, 186 spi_callback_args_t * const p_callback_memory); 187 188 /*******************************************************************************************************************//** 189 * @} (end ingroup SPI_B) 190 **********************************************************************************************************************/ 191 192 /** Common macro for FSP header files. There is also a corresponding FSP_HEADER macro at the top of this file. */ 193 FSP_FOOTER 194 195 #endif 196