drv_spi.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*
  2. * Copyright (c) 2006-2025, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-12-20 BruceOu first implementation
  9. */
  10. #ifndef __DRV_SPI_H__
  11. #define __DRV_SPI_H__
  12. #include <rthw.h>
  13. #include <rtthread.h>
  14. #include <rtdevice.h>
  15. #include <board.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. struct gd32_spi_cs
  20. {
  21. uint32_t GPIOx;
  22. uint32_t GPIO_Pin;
  23. };
  24. /* gd32 spi dirver class */
  25. struct gd32_spi
  26. {
  27. uint32_t spi_periph;
  28. char *bus_name;
  29. rcu_periph_enum spi_clk;
  30. rcu_periph_enum sck_gpio_clk;
  31. rcu_periph_enum miso_gpio_clk;
  32. rcu_periph_enum mosi_gpio_clk;
  33. struct rt_spi_bus *spi_bus;
  34. uint32_t sck_spi_port;
  35. uint32_t miso_spi_port;
  36. uint32_t mosi_spi_port;
  37. #if defined SOC_SERIES_GD32F4xx || defined SOC_SERIES_GD32E23x || defined SOC_SERIES_GD32H7xx || defined SOC_SERIES_GD32F5xx
  38. uint32_t alt_func_num;
  39. #endif
  40. uint16_t sck_pin;
  41. uint16_t miso_pin;
  42. uint16_t mosi_pin;
  43. };
  44. rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin);
  45. #ifdef __cplusplus
  46. }
  47. #endif
  48. #endif /* __DRV_SPI_H__ */