ch32v30x_sdio.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /********************************** (C) COPYRIGHT *******************************
  2. * File Name : ch32v30x_sdio.h
  3. * Author : WCH
  4. * Version : V1.0.0
  5. * Date : 2021/06/06
  6. * Description : This file contains all the functions prototypes for the SDIO
  7. * firmware library.
  8. *********************************************************************************
  9. * Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
  10. * Attention: This software (modified or not) and binary are used for
  11. * microcontroller manufactured by Nanjing Qinheng Microelectronics.
  12. *******************************************************************************/
  13. #ifndef __CH32V30x_SDIO_H
  14. #define __CH32V30x_SDIO_H
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. #include "ch32v30x.h"
  19. /* SDIO Init structure definition */
  20. typedef struct
  21. {
  22. uint32_t SDIO_ClockEdge; /* Specifies the clock transition on which the bit capture is made.
  23. This parameter can be a value of @ref SDIO_Clock_Edge */
  24. uint32_t SDIO_ClockBypass; /* Specifies whether the SDIO Clock divider bypass is
  25. enabled or disabled.
  26. This parameter can be a value of @ref SDIO_Clock_Bypass */
  27. uint32_t SDIO_ClockPowerSave; /* Specifies whether SDIO Clock output is enabled or
  28. disabled when the bus is idle.
  29. This parameter can be a value of @ref SDIO_Clock_Power_Save */
  30. uint32_t SDIO_BusWide; /* Specifies the SDIO bus width.
  31. This parameter can be a value of @ref SDIO_Bus_Wide */
  32. uint32_t SDIO_HardwareFlowControl; /* Specifies whether the SDIO hardware flow control is enabled or disabled.
  33. This parameter can be a value of @ref SDIO_Hardware_Flow_Control */
  34. uint8_t SDIO_ClockDiv; /* Specifies the clock frequency of the SDIO controller.
  35. This parameter can be a value between 0x00 and 0xFF. */
  36. } SDIO_InitTypeDef;
  37. typedef struct
  38. {
  39. uint32_t SDIO_Argument; /* Specifies the SDIO command argument which is sent
  40. to a card as part of a command message. If a command
  41. contains an argument, it must be loaded into this register
  42. before writing the command to the command register */
  43. uint32_t SDIO_CmdIndex; /* Specifies the SDIO command index. It must be lower than 0x40. */
  44. uint32_t SDIO_Response; /* Specifies the SDIO response type.
  45. This parameter can be a value of @ref SDIO_Response_Type */
  46. uint32_t SDIO_Wait; /* Specifies whether SDIO wait-for-interrupt request is enabled or disabled.
  47. This parameter can be a value of @ref SDIO_Wait_Interrupt_State */
  48. uint32_t SDIO_CPSM; /* Specifies whether SDIO Command path state machine (CPSM)
  49. is enabled or disabled.
  50. This parameter can be a value of @ref SDIO_CPSM_State */
  51. } SDIO_CmdInitTypeDef;
  52. typedef struct
  53. {
  54. uint32_t SDIO_DataTimeOut; /* Specifies the data timeout period in card bus clock periods. */
  55. uint32_t SDIO_DataLength; /* Specifies the number of data bytes to be transferred. */
  56. uint32_t SDIO_DataBlockSize; /* Specifies the data block size for block transfer.
  57. This parameter can be a value of @ref SDIO_Data_Block_Size */
  58. uint32_t SDIO_TransferDir; /* Specifies the data transfer direction, whether the transfer
  59. is a read or write.
  60. This parameter can be a value of @ref SDIO_Transfer_Direction */
  61. uint32_t SDIO_TransferMode; /* Specifies whether data transfer is in stream or block mode.
  62. This parameter can be a value of @ref SDIO_Transfer_Type */
  63. uint32_t SDIO_DPSM; /* Specifies whether SDIO Data path state machine (DPSM)
  64. is enabled or disabled.
  65. This parameter can be a value of @ref SDIO_DPSM_State */
  66. } SDIO_DataInitTypeDef;
  67. /* SDIO_Clock_Edge */
  68. #define SDIO_ClockEdge_Rising ((uint32_t)0x00000000)
  69. #define SDIO_ClockEdge_Falling ((uint32_t)0x00002000)
  70. /* SDIO_Clock_Bypass */
  71. #define SDIO_ClockBypass_Disable ((uint32_t)0x00000000)
  72. #define SDIO_ClockBypass_Enable ((uint32_t)0x00000400)
  73. /* SDIO_Clock_Power_Save */
  74. #define SDIO_ClockPowerSave_Disable ((uint32_t)0x00000000)
  75. #define SDIO_ClockPowerSave_Enable ((uint32_t)0x00000200)
  76. /* SDIO_Bus_Wide */
  77. #define SDIO_BusWide_1b ((uint32_t)0x00000000)
  78. #define SDIO_BusWide_4b ((uint32_t)0x00000800)
  79. #define SDIO_BusWide_8b ((uint32_t)0x00001000)
  80. /* SDIO_Hardware_Flow_Control */
  81. #define SDIO_HardwareFlowControl_Disable ((uint32_t)0x00000000)
  82. #define SDIO_HardwareFlowControl_Enable ((uint32_t)0x00004000)
  83. /* SDIO_Power_State */
  84. #define SDIO_PowerState_OFF ((uint32_t)0x00000000)
  85. #define SDIO_PowerState_ON ((uint32_t)0x00000003)
  86. /* SDIO_Interrupt_sources */
  87. #define SDIO_IT_CCRCFAIL ((uint32_t)0x00000001)
  88. #define SDIO_IT_DCRCFAIL ((uint32_t)0x00000002)
  89. #define SDIO_IT_CTIMEOUT ((uint32_t)0x00000004)
  90. #define SDIO_IT_DTIMEOUT ((uint32_t)0x00000008)
  91. #define SDIO_IT_TXUNDERR ((uint32_t)0x00000010)
  92. #define SDIO_IT_RXOVERR ((uint32_t)0x00000020)
  93. #define SDIO_IT_CMDREND ((uint32_t)0x00000040)
  94. #define SDIO_IT_CMDSENT ((uint32_t)0x00000080)
  95. #define SDIO_IT_DATAEND ((uint32_t)0x00000100)
  96. #define SDIO_IT_STBITERR ((uint32_t)0x00000200)
  97. #define SDIO_IT_DBCKEND ((uint32_t)0x00000400)
  98. #define SDIO_IT_CMDACT ((uint32_t)0x00000800)
  99. #define SDIO_IT_TXACT ((uint32_t)0x00001000)
  100. #define SDIO_IT_RXACT ((uint32_t)0x00002000)
  101. #define SDIO_IT_TXFIFOHE ((uint32_t)0x00004000)
  102. #define SDIO_IT_RXFIFOHF ((uint32_t)0x00008000)
  103. #define SDIO_IT_TXFIFOF ((uint32_t)0x00010000)
  104. #define SDIO_IT_RXFIFOF ((uint32_t)0x00020000)
  105. #define SDIO_IT_TXFIFOE ((uint32_t)0x00040000)
  106. #define SDIO_IT_RXFIFOE ((uint32_t)0x00080000)
  107. #define SDIO_IT_TXDAVL ((uint32_t)0x00100000)
  108. #define SDIO_IT_RXDAVL ((uint32_t)0x00200000)
  109. #define SDIO_IT_SDIOIT ((uint32_t)0x00400000)
  110. #define SDIO_IT_CEATAEND ((uint32_t)0x00800000)
  111. /* SDIO_Response_Type */
  112. #define SDIO_Response_No ((uint32_t)0x00000000)
  113. #define SDIO_Response_Short ((uint32_t)0x00000040)
  114. #define SDIO_Response_Long ((uint32_t)0x000000C0)
  115. /* SDIO_Wait_Interrupt_State */
  116. #define SDIO_Wait_No ((uint32_t)0x00000000)
  117. #define SDIO_Wait_IT ((uint32_t)0x00000100)
  118. #define SDIO_Wait_Pend ((uint32_t)0x00000200)
  119. /* SDIO_CPSM_State */
  120. #define SDIO_CPSM_Disable ((uint32_t)0x00000000)
  121. #define SDIO_CPSM_Enable ((uint32_t)0x00000400)
  122. /* SDIO_Response_Registers */
  123. #define SDIO_RESP1 ((uint32_t)0x00000000)
  124. #define SDIO_RESP2 ((uint32_t)0x00000004)
  125. #define SDIO_RESP3 ((uint32_t)0x00000008)
  126. #define SDIO_RESP4 ((uint32_t)0x0000000C)
  127. /* SDIO_Data_Block_Size */
  128. #define SDIO_DataBlockSize_1b ((uint32_t)0x00000000)
  129. #define SDIO_DataBlockSize_2b ((uint32_t)0x00000010)
  130. #define SDIO_DataBlockSize_4b ((uint32_t)0x00000020)
  131. #define SDIO_DataBlockSize_8b ((uint32_t)0x00000030)
  132. #define SDIO_DataBlockSize_16b ((uint32_t)0x00000040)
  133. #define SDIO_DataBlockSize_32b ((uint32_t)0x00000050)
  134. #define SDIO_DataBlockSize_64b ((uint32_t)0x00000060)
  135. #define SDIO_DataBlockSize_128b ((uint32_t)0x00000070)
  136. #define SDIO_DataBlockSize_256b ((uint32_t)0x00000080)
  137. #define SDIO_DataBlockSize_512b ((uint32_t)0x00000090)
  138. #define SDIO_DataBlockSize_1024b ((uint32_t)0x000000A0)
  139. #define SDIO_DataBlockSize_2048b ((uint32_t)0x000000B0)
  140. #define SDIO_DataBlockSize_4096b ((uint32_t)0x000000C0)
  141. #define SDIO_DataBlockSize_8192b ((uint32_t)0x000000D0)
  142. #define SDIO_DataBlockSize_16384b ((uint32_t)0x000000E0)
  143. /* SDIO_Transfer_Direction */
  144. #define SDIO_TransferDir_ToCard ((uint32_t)0x00000000)
  145. #define SDIO_TransferDir_ToSDIO ((uint32_t)0x00000002)
  146. /* SDIO_Transfer_Type */
  147. #define SDIO_TransferMode_Block ((uint32_t)0x00000000)
  148. #define SDIO_TransferMode_Stream ((uint32_t)0x00000004)
  149. /* SDIO_DPSM_State */
  150. #define SDIO_DPSM_Disable ((uint32_t)0x00000000)
  151. #define SDIO_DPSM_Enable ((uint32_t)0x00000001)
  152. /* SDIO_Flags */
  153. #define SDIO_FLAG_CCRCFAIL ((uint32_t)0x00000001)
  154. #define SDIO_FLAG_DCRCFAIL ((uint32_t)0x00000002)
  155. #define SDIO_FLAG_CTIMEOUT ((uint32_t)0x00000004)
  156. #define SDIO_FLAG_DTIMEOUT ((uint32_t)0x00000008)
  157. #define SDIO_FLAG_TXUNDERR ((uint32_t)0x00000010)
  158. #define SDIO_FLAG_RXOVERR ((uint32_t)0x00000020)
  159. #define SDIO_FLAG_CMDREND ((uint32_t)0x00000040)
  160. #define SDIO_FLAG_CMDSENT ((uint32_t)0x00000080)
  161. #define SDIO_FLAG_DATAEND ((uint32_t)0x00000100)
  162. #define SDIO_FLAG_STBITERR ((uint32_t)0x00000200)
  163. #define SDIO_FLAG_DBCKEND ((uint32_t)0x00000400)
  164. #define SDIO_FLAG_CMDACT ((uint32_t)0x00000800)
  165. #define SDIO_FLAG_TXACT ((uint32_t)0x00001000)
  166. #define SDIO_FLAG_RXACT ((uint32_t)0x00002000)
  167. #define SDIO_FLAG_TXFIFOHE ((uint32_t)0x00004000)
  168. #define SDIO_FLAG_RXFIFOHF ((uint32_t)0x00008000)
  169. #define SDIO_FLAG_TXFIFOF ((uint32_t)0x00010000)
  170. #define SDIO_FLAG_RXFIFOF ((uint32_t)0x00020000)
  171. #define SDIO_FLAG_TXFIFOE ((uint32_t)0x00040000)
  172. #define SDIO_FLAG_RXFIFOE ((uint32_t)0x00080000)
  173. #define SDIO_FLAG_TXDAVL ((uint32_t)0x00100000)
  174. #define SDIO_FLAG_RXDAVL ((uint32_t)0x00200000)
  175. #define SDIO_FLAG_SDIOIT ((uint32_t)0x00400000)
  176. #define SDIO_FLAG_CEATAEND ((uint32_t)0x00800000)
  177. /* SDIO_Read_Wait_Mode */
  178. #define SDIO_ReadWaitMode_CLK ((uint32_t)0x00000001)
  179. #define SDIO_ReadWaitMode_DATA2 ((uint32_t)0x00000000)
  180. #define SDIO_DataControl_DTEN ((uint32_t)0x00000001)
  181. #define SDIO_DataControl_DTDIR ((uint32_t)0x00000002)
  182. #define SDIO_DataControl_DTMODE ((uint32_t)0x00000004)
  183. #define SDIO_DataControl_DMAEN ((uint32_t)0x00000008)
  184. #define SDIO_DataControl_DBLOCKSIZE ((uint32_t)0x000000F0)
  185. #define SDIO_DataControl_RWSTART ((uint32_t)0x00000100)
  186. #define SDIO_DataControl_RWSTOP ((uint32_t)0x00000200)
  187. #define SDIO_DataControl_RWMOD ((uint32_t)0x00000400)
  188. #define SDIO_DataControl_SDIOEN ((uint32_t)0x00000800)
  189. void SDIO_DeInit(void);
  190. void SDIO_Init(SDIO_InitTypeDef* SDIO_InitStruct);
  191. void SDIO_StructInit(SDIO_InitTypeDef* SDIO_InitStruct);
  192. void SDIO_ClockCmd(FunctionalState NewState);
  193. void SDIO_SetPowerState(uint32_t SDIO_PowerState);
  194. uint32_t SDIO_GetPowerState(void);
  195. void SDIO_ITConfig(uint32_t SDIO_IT, FunctionalState NewState);
  196. void SDIO_DMACmd(FunctionalState NewState);
  197. void SDIO_SendCommand(SDIO_CmdInitTypeDef *SDIO_CmdInitStruct);
  198. void SDIO_CmdStructInit(SDIO_CmdInitTypeDef* SDIO_CmdInitStruct);
  199. uint8_t SDIO_GetCommandResponse(void);
  200. uint32_t SDIO_GetResponse(uint32_t SDIO_RESP);
  201. void SDIO_DataConfig(SDIO_DataInitTypeDef* SDIO_DataInitStruct);
  202. void SDIO_DataStructInit(SDIO_DataInitTypeDef* SDIO_DataInitStruct);
  203. uint32_t SDIO_GetDataCounter(void);
  204. uint32_t SDIO_ReadData(void);
  205. void SDIO_WriteData(uint32_t Data);
  206. uint32_t SDIO_GetFIFOCount(void);
  207. void SDIO_StartSDIOReadWait(FunctionalState NewState);
  208. void SDIO_StopSDIOReadWait(FunctionalState NewState);
  209. void SDIO_SetSDIOReadWaitMode(uint32_t SDIO_ReadWaitMode);
  210. void SDIO_SetSDIOOperation(FunctionalState NewState);
  211. void SDIO_SendSDIOSuspendCmd(FunctionalState NewState);
  212. void SDIO_CommandCompletionCmd(FunctionalState NewState);
  213. void SDIO_CEATAITCmd(FunctionalState NewState);
  214. void SDIO_SendCEATACmd(FunctionalState NewState);
  215. FlagStatus SDIO_GetFlagStatus(uint32_t SDIO_FLAG);
  216. void SDIO_ClearFlag(uint32_t SDIO_FLAG);
  217. ITStatus SDIO_GetITStatus(uint32_t SDIO_IT);
  218. void SDIO_ClearITPendingBit(uint32_t SDIO_IT);
  219. #ifdef __cplusplus
  220. }
  221. #endif
  222. #endif