sunxi_drv_spi.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * ===========================================================================================
  3. *
  4. * Filename: sunxi_drv_spi.h
  5. *
  6. * Description: sunxi_driver headfile.
  7. *
  8. * Version: Melis3.0
  9. * Create: 2019-11-14 17:47:21
  10. * Revision: none
  11. * Compiler: GCC:version 9.2.1 20170904 (release),ARM/embedded-7-branch revision 25520
  12. *
  13. * Author: bantao@allwinnertech.com
  14. * Organization: SWC-BPD
  15. * Last Modified: 2019-11-15 13:19:52
  16. *
  17. * ===========================================================================================
  18. */
  19. #ifndef SUNXI_DRV_SPI_H
  20. #define SUNXI_DRV_SPI_H
  21. #ifdef __cplusplus
  22. extern "C"
  23. {
  24. #endif
  25. #include <sunxi_hal_spi.h>
  26. #include <rtthread.h>
  27. typedef struct sunxi_driver_spi
  28. {
  29. struct rt_device base;
  30. int32_t dev_id;
  31. const void *hal_drv;
  32. } sunxi_driver_spi_t;
  33. #if 0
  34. typedef enum
  35. {
  36. SPI_WRITE_READ = 0, /**< SPI master is busy. */
  37. SPI_CONFIG = 1 /**< SPI master is idle. */
  38. } hal_spi_transfer_cmd_t;
  39. typedef struct
  40. {
  41. const uint8_t *tx_buf; /**< Data buffer to send, */
  42. uint32_t tx_len; /**< The total number of bytes to send. */
  43. uint32_t
  44. tx_single_len; /**< The number of bytes to send in single mode. */
  45. uint8_t *rx_buf; /**< Received data buffer, */
  46. uint32_t rx_len; /**< The valid number of bytes received. */
  47. uint8_t tx_nbits : 3; /**< Data buffer to send in nbits mode */
  48. uint8_t rx_nbits : 3; /**< Data buffer to received in nbits mode */
  49. uint8_t dummy_byte; /**< Flash send dummy byte, default 0*/
  50. #define SPI_NBITS_SINGLE 0x01 /* 1bit transfer */
  51. #define SPI_NBITS_DUAL 0x02 /* 2bit transfer */
  52. #define SPI_NBITS_QUAD 0x04 /* 4bit transfer */
  53. uint8_t bits_per_word; /**< transfer bit_per_word */
  54. } hal_spi_master_transfer_t;
  55. #endif
  56. typedef struct sunxi_hal_driver_spi
  57. {
  58. spi_master_status_t (*initialize)(hal_spi_master_port_t port);
  59. spi_master_status_t (*uninitialize)(hal_spi_master_port_t port);
  60. spi_master_status_t (*send)(hal_spi_master_port_t port,
  61. const void *buf, uint32_t size);
  62. spi_master_status_t (*receive)(hal_spi_master_port_t port,
  63. void *buf, uint32_t size);
  64. spi_master_status_t (*hw_config)(hal_spi_master_port_t port, hal_spi_master_config_t *spi_config);
  65. spi_master_status_t (*transfer)(hal_spi_master_port_t port, hal_spi_master_transfer_t *transfer);
  66. } const sunxi_hal_driver_spi_t;
  67. #ifdef __cplusplus
  68. }
  69. #endif
  70. #endif