drv_spim.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #include <rtthread.h>
  2. #include <rtdevice.h>
  3. #include <rthw.h>
  4. #ifndef __DRV_SPIM_H_
  5. #define __DRV_SPIM_H_
  6. #ifdef BSP_USING_SPIM
  7. #include "nrfx_spim.h"
  8. #include "nrf_spi.h"
  9. #include "rtconfig.h"
  10. struct spi_dma_message
  11. {
  12. rt_base_t cs_pin;
  13. unsigned cs_take;
  14. unsigned cs_release;
  15. #if NRFX_CHECK(NRFX_SPIM_EXTENDED_ENABLED)
  16. bool use_hw_ss;
  17. #endif
  18. bool ss_active_high;
  19. struct rt_completion *cpt;
  20. uint32_t flags;
  21. NRF_SPIM_Type* spim;
  22. };
  23. /**
  24. * @brief Attach the spi device to SPIM bus, this function must be used after initialization.
  25. * @param bus_name spim bus name "spim0"/"spim1"/"spim2"/"spim3"
  26. * @param device_name spim device name "spim0x"/"spim1x"/"spim2x"/"spim3x"
  27. * @param ss_pin spim ss pin number
  28. * @retval -RT_ERROR / RT_EOK
  29. */
  30. rt_err_t rt_hw_spim_device_attach(const char *bus_name, const char *device_name, rt_uint32_t ss_pin);
  31. /* SPIM bus config */
  32. #ifdef BSP_USING_SPIM0
  33. #define NRFX_SPIM0_CONFIG \
  34. { \
  35. .bus_name = "spim0", \
  36. .spi = NRFX_SPIM_INSTANCE(0) \
  37. }
  38. #endif
  39. #ifdef BSP_USING_SPIM1
  40. #define NRFX_SPIM1_CONFIG \
  41. { \
  42. .bus_name = "spim1", \
  43. .spi = NRFX_SPIM_INSTANCE(1) \
  44. }
  45. #endif
  46. #ifdef BSP_USING_SPIM2
  47. #define NRFX_SPIM2_CONFIG \
  48. { \
  49. .bus_name = "spim2", \
  50. .spi = NRFX_SPIM_INSTANCE(2) \
  51. }
  52. #endif
  53. #ifdef BSP_USING_SPIM3
  54. #define NRFX_SPIM3_CONFIG \
  55. { \
  56. .bus_name = "spim3", \
  57. .spi = NRFX_SPIM_INSTANCE(3) \
  58. }
  59. #endif
  60. struct nrfx_drv_spim_config
  61. {
  62. char *bus_name;
  63. nrfx_spim_t spi;
  64. };
  65. struct nrfx_drv_spim
  66. {
  67. nrfx_spim_t spim; /* nrfx spim driver instance. */
  68. nrfx_spim_config_t spim_config; /* nrfx spim config Configuration */
  69. struct rt_spi_configuration *cfg;
  70. struct rt_spi_bus spim_bus;
  71. };
  72. struct nrfx_drv_spim_pin_config
  73. {
  74. rt_uint8_t sck_pin;
  75. rt_uint8_t mosi_pin;
  76. rt_uint8_t miso_pin;
  77. rt_uint8_t ss_pin;
  78. };
  79. #endif /* BSP_USING_SPIM */
  80. #endif /* __DRV_SPIM_H_ */