drv_spi.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c) 2006-2018, Synwit Technology Co.,Ltd.
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-12-10 Zohar_Lee first version
  9. * 2020-07-10 lik rewrite
  10. */
  11. #ifndef __DRV_SPI_H__
  12. #define __DRV_SPI_H__
  13. #include "board.h"
  14. struct swm_spi_cs
  15. {
  16. GPIO_TypeDef *GPIOx;
  17. uint32_t gpio_pin;
  18. };
  19. struct swm_spi_cfg
  20. {
  21. const char *name;
  22. SPI_TypeDef *SPIx;
  23. SPI_InitStructure spi_initstruct;
  24. };
  25. /* swm spi dirver class */
  26. struct swm_spi
  27. {
  28. struct swm_spi_cfg *cfg;
  29. struct rt_spi_configuration *configure;
  30. struct rt_spi_bus spi_bus;
  31. };
  32. #ifdef BSP_USING_SPI0
  33. #ifndef SPI0_BUS_CONFIG
  34. #define SPI0_BUS_CONFIG \
  35. { \
  36. .name = "spi0", \
  37. .SPIx = SPI0, \
  38. .spi_initstruct.clkDiv = SPI_CLKDIV_32, \
  39. .spi_initstruct.FrameFormat = SPI_FORMAT_SPI, \
  40. .spi_initstruct.SampleEdge = SPI_SECOND_EDGE, \
  41. .spi_initstruct.IdleLevel = SPI_HIGH_LEVEL, \
  42. .spi_initstruct.WordSize = 8, \
  43. .spi_initstruct.Master = 1, \
  44. .spi_initstruct.RXHFullIEn = 0, \
  45. .spi_initstruct.TXEmptyIEn = 0, \
  46. .spi_initstruct.TXCompleteIEn = 0, \
  47. }
  48. #endif /* SPI1_BUS_CONFIG */
  49. #endif /* BSP_USING_SPI1 */
  50. #ifdef BSP_USING_SPI1
  51. #ifndef SPI1_BUS_CONFIG
  52. #define SPI1_BUS_CONFIG \
  53. { \
  54. .name = "spi1", \
  55. .SPIx = SPI1, \
  56. .spi_initstruct.clkDiv = SPI_CLKDIV_32, \
  57. .spi_initstruct.FrameFormat = SPI_FORMAT_SPI, \
  58. .spi_initstruct.SampleEdge = SPI_SECOND_EDGE, \
  59. .spi_initstruct.IdleLevel = SPI_HIGH_LEVEL, \
  60. .spi_initstruct.WordSize = 8, \
  61. .spi_initstruct.Master = 1, \
  62. .spi_initstruct.RXHFullIEn = 0, \
  63. .spi_initstruct.TXEmptyIEn = 0, \
  64. .spi_initstruct.TXCompleteIEn = 0, \
  65. }
  66. #endif /* SPI1_BUS_CONFIG */
  67. #endif /* BSP_USING_SPI1 */
  68. //cannot be used before completion init
  69. rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, GPIO_TypeDef *GPIOx, uint32_t n);
  70. int rt_hw_spi_init(void);
  71. #endif /* __DRV_SPI_H__ */