drv_spi.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. * 2018-11-5 SummerGift first version
  9. */
  10. #ifndef __DRV_SPI_H__
  11. #define __DRV_SPI_H__
  12. #include <rtthread.h>
  13. #include "rtdevice.h"
  14. #include <rthw.h>
  15. #include <drv_common.h>
  16. #include "drv_dma.h"
  17. #include <ipc/completion.h>
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. rt_err_t rt_hw_spi_device_attach(const char *bus_name, const char *device_name, rt_base_t cs_pin);
  22. rt_err_t rt_hw_spi_device_detach(const char *device_name);
  23. #ifdef __cplusplus
  24. }
  25. #endif
  26. struct stm32_spi_config
  27. {
  28. SPI_TypeDef *Instance;
  29. char *bus_name;
  30. IRQn_Type irq_type;
  31. struct dma_config *dma_rx, *dma_tx;
  32. };
  33. struct stm32_spi_device
  34. {
  35. rt_uint32_t pin;
  36. char *bus_name;
  37. char *device_name;
  38. };
  39. #define SPI_USING_RX_DMA_FLAG (1<<0)
  40. #define SPI_USING_TX_DMA_FLAG (1<<1)
  41. /* stm32 spi dirver class */
  42. struct stm32_spi
  43. {
  44. SPI_HandleTypeDef handle;
  45. struct stm32_spi_config *config;
  46. struct rt_spi_configuration *cfg;
  47. struct
  48. {
  49. DMA_HandleTypeDef handle_rx;
  50. DMA_HandleTypeDef handle_tx;
  51. } dma;
  52. rt_uint8_t spi_dma_flag;
  53. struct rt_spi_bus spi_bus;
  54. struct rt_completion cpt;
  55. };
  56. #endif /*__DRV_SPI_H__ */