yc11xx_spi(1).h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright 2016, yichip Semiconductor(shenzhen office)
  3. * All Rights Reserved.
  4. *
  5. * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Yichip Semiconductor;
  6. * the contents of this file may not be disclosed to third parties, copied
  7. * or duplicated in any form, in whole or in part, without the prior
  8. * written permission of Yichip Semiconductor.
  9. */
  10. /** @file
  11. *
  12. * spi support for application
  13. */
  14. #ifndef _SPI_H_
  15. #define _SPI_H_
  16. #include <stdio.h>
  17. #include <stdint.h>
  18. #include <stdbool.h>
  19. #include "yc11xx.h"
  20. #include "yc_drv_common.h"
  21. /** @
  22. * @defgroup SPI_Mode
  23. */
  24. #define SPI_Mode_Four_Wire 4
  25. #define SPI_Mode_Three_Wire 3
  26. #define SPI_Mode_Two_Wire 2
  27. #define IS_SPI_MODE(MODE) (((MODE) == SPI_Mode_Two_Wire) || \
  28. ((MODE) == SPI_Mode_Three_Wire)) || \
  29. ((MODE) == SPI_Mode_Four_Wire)
  30. /** @
  31. * @defgroup SPI_CPOL
  32. */
  33. #define SPI_CPOL_Active_High ((uint8_t)0<<4)
  34. #define SPI_CPOL_Active_Low ((uint8_t)1<<4)
  35. #define IS_SPI_CPOL(CPOL) (((CPOL) == SPI_CPOL_Active_High) || \
  36. ((CPOL) == SPI_CPOL_Active_Low))
  37. /** @
  38. * @defgroup SPI_CPHA
  39. */
  40. #define SPI_CPHA_First_Edge ((uint8_t)0<<5)
  41. #define SPI_CPHA_Second_Edge ((uint8_t)1<<5)
  42. #define IS_SPI_CPHA(CPHA) (((CPHA) == SPI_CPHA_First_Edge) || \
  43. ((CPHA) == SPI_CPHA_Second_Edge))
  44. /** @
  45. * @defgroup SPI_BaudSpeed
  46. */
  47. #define SPI_BAUDSPEED_2MHz 4
  48. #define SPI_BAUDSPEED_750KHz 5
  49. #define SPI_BAUDSPEED_375KHz 6
  50. #define SPI_BAUDSPEED_187KHz 7
  51. #define IS_SPI_BAUDSPEED(BAUDSPEED) (((BAUDSPEED) >=SPI_BAUDSPEED_2MHz) && ((BAUDSPEED) <= SPI_BAUDSPEED_187KHz))
  52. /** @defgroup SPI_TXLen
  53. * @{
  54. */
  55. #define IS_SPI_TXLen(TxLen) (TxLen != 0)
  56. /**
  57. * @}
  58. */
  59. /** @defgroup SPI_RXlen
  60. * @{
  61. */
  62. #define IS_SPI_RXLen(RxLen) (RxLen != 0)
  63. /**
  64. * @}
  65. */
  66. /**
  67. * @brief SPI Init structure definition
  68. */
  69. typedef struct
  70. {
  71. uint16_t SPI_Mode; /*!< Specifies the SPI operating mode.
  72. This parameter can be a value of @ref SPI_mode */
  73. uint16_t SPI_CPOL; /*!< Specifies the serial clock steady state.
  74. This parameter can be a value of @ref SPI_Clock_Polarity */
  75. uint16_t SPI_CPHA; /*!< Specifies the clock active edge for the bit capture.
  76. This parameter can be a value of @ref SPI_Clock_Phase */
  77. uint16_t SPI_BaudSpeed; /*!< Specifies the Baud Rate prescaler value which will be
  78. used to configure the transmit and receive SCK clock.
  79. This parameter can be a value of @ref SPI_BaudRate_Prescaler.
  80. @note The communication clock is derived from the master
  81. clock. The slave clock does not need to be set. */
  82. uint16_t SPI_TXLen; /*!< Specifies Tx DMA buff len */
  83. uint16_t SPI_RXlen; /*!< Specifies Rx DMA buff len */
  84. }SPI_InitTypeDef;
  85. void SPI_Init(SPI_InitTypeDef* SPI_InitStruct);
  86. void SPI_DeInit(void);
  87. void SPI_SendData(uint16_t Data);
  88. uint16_t SPI_ReadRegister(uint16_t RegAdr);
  89. void SPI_SendDataFromBuff(uint8_t *Buff, uint16_t Len);
  90. void SPI_ReceiveDataToBuff(uint8_t *TxBuff, uint16_t TxLen, uint8_t *RxBuff, uint16_t RxLen);
  91. void SPI_ReceiveDataToBuff2(uint8_t *TxBuff, uint16_t TxLen, uint8_t *RxBuff, uint16_t RxLen);
  92. void SPI_SendDataFromBuffWithoutDMAdone(uint8_t *Buff, uint16_t Len);
  93. bool SPI_WaitDone(void);
  94. #endif /* _SPI_H_ */