drv_spi.h 1.3 KB

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