drv_spi.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright (c) 2006-2023, 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. #ifdef __cplusplus
  23. }
  24. #endif
  25. struct stm32_spi_config
  26. {
  27. SPI_TypeDef *Instance;
  28. char *bus_name;
  29. IRQn_Type irq_type;
  30. struct dma_config *dma_rx, *dma_tx;
  31. };
  32. struct stm32_spi_device
  33. {
  34. rt_uint32_t pin;
  35. char *bus_name;
  36. char *device_name;
  37. };
  38. #define SPI_USING_RX_DMA_FLAG (1<<0)
  39. #define SPI_USING_TX_DMA_FLAG (1<<1)
  40. /* stm32 spi dirver class */
  41. struct stm32_spi
  42. {
  43. SPI_HandleTypeDef handle;
  44. struct stm32_spi_config *config;
  45. struct rt_spi_configuration *cfg;
  46. struct
  47. {
  48. DMA_HandleTypeDef handle_rx;
  49. DMA_HandleTypeDef handle_tx;
  50. } dma;
  51. rt_uint8_t spi_dma_flag;
  52. struct rt_spi_bus spi_bus;
  53. struct rt_completion cpt;
  54. };
  55. #endif /*__DRV_SPI_H__ */