drv_spi.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-05-19 Sherman first version
  9. */
  10. #include <rtthread.h>
  11. #include <rtdevice.h>
  12. #include <rthw.h>
  13. #ifndef __DRV_SPI_H_
  14. #define __DRV_SPI_H_
  15. #ifdef BSP_USING_SPI
  16. #include "nrfx_spi.h"
  17. /**
  18. * @brief Attach the spi device to SPI bus, this function must be used after initialization.
  19. * @param bus_name spi bus name "spi0"/"spi1"/"spi2"
  20. * @param device_name spi device name "spi0x"/"spi1x"/"spi2x"
  21. * @param ss_pin spi ss pin number
  22. * @retval RT_ERROR / RT_EOK
  23. */
  24. rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_uint32_t ss_pin);
  25. //SPI bus config
  26. #ifdef BSP_USING_SPI0
  27. #define NRFX_SPI0_CONFIG \
  28. { \
  29. .bus_name = "spi0", \
  30. .spi = NRFX_SPI_INSTANCE(0) \
  31. }
  32. #endif
  33. #ifdef BSP_USING_SPI1
  34. #define NRFX_SPI1_CONFIG \
  35. { \
  36. .bus_name = "spi1", \
  37. .spi = NRFX_SPI_INSTANCE(1) \
  38. }
  39. #endif
  40. #ifdef BSP_USING_SPI2
  41. #define NRFX_SPI2_CONFIG \
  42. { \
  43. .bus_name = "spi2", \
  44. .spi = NRFX_SPI_INSTANCE(2) \
  45. }
  46. #endif
  47. struct nrfx_drv_spi_config
  48. {
  49. char *bus_name;
  50. nrfx_spi_t spi;
  51. };
  52. struct nrfx_drv_spi
  53. {
  54. nrfx_spi_t spi; /* nrfx spi driver instance. */
  55. nrfx_spi_config_t spi_config; /* nrfx spi config Configuration */
  56. struct rt_spi_configuration *cfg;
  57. struct rt_spi_bus spi_bus;
  58. };
  59. struct nrfx_drv_spi_pin_config
  60. {
  61. rt_uint8_t sck_pin;
  62. rt_uint8_t mosi_pin;
  63. rt_uint8_t miso_pin;
  64. rt_uint8_t ss_pin;
  65. };
  66. #endif /* BSP_USING_SPI */
  67. #endif /*__DRV_SPI_H_*/