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 
22 #ifdef __cplusplus
23 extern "C"
24 {
25 #endif
26 
27 #include <sunxi_hal_spi.h>
28 #include <rtthread.h>
29 
30 typedef struct sunxi_driver_spi
31 {
32     struct rt_device   base;
33     int32_t            dev_id;
34     const void        *hal_drv;
35 } sunxi_driver_spi_t;
36 
37 #if 0
38 typedef enum
39 {
40     SPI_WRITE_READ = 0, /**< SPI master is busy. */
41     SPI_CONFIG = 1  /**< SPI master is idle. */
42 } hal_spi_transfer_cmd_t;
43 
44 typedef struct
45 {
46     const uint8_t *tx_buf; /**< Data buffer to send, */
47     uint32_t tx_len; /**< The total number of bytes to send. */
48     uint32_t
49         tx_single_len; /**< The number of bytes to send in single mode. */
50     uint8_t *rx_buf;   /**< Received data buffer, */
51     uint32_t rx_len;   /**< The valid number of bytes received. */
52     uint8_t tx_nbits : 3;  /**< Data buffer to send in nbits mode */
53     uint8_t rx_nbits : 3;  /**< Data buffer to received in nbits mode */
54     uint8_t dummy_byte;    /**< Flash send dummy byte, default 0*/
55 #define SPI_NBITS_SINGLE 0x01  /* 1bit transfer */
56 #define SPI_NBITS_DUAL 0x02    /* 2bit transfer */
57 #define SPI_NBITS_QUAD 0x04    /* 4bit transfer */
58     uint8_t bits_per_word; /**< transfer bit_per_word */
59 } hal_spi_master_transfer_t;
60 #endif
61 
62 typedef struct sunxi_hal_driver_spi
63 {
64     spi_master_status_t (*initialize)(hal_spi_master_port_t port);
65     spi_master_status_t (*uninitialize)(hal_spi_master_port_t port);
66     spi_master_status_t (*send)(hal_spi_master_port_t port,
67                                 const void *buf, uint32_t size);
68     spi_master_status_t (*receive)(hal_spi_master_port_t port,
69                                    void *buf, uint32_t size);
70     spi_master_status_t (*hw_config)(hal_spi_master_port_t port, hal_spi_master_config_t *spi_config);
71     spi_master_status_t (*transfer)(hal_spi_master_port_t port, hal_spi_master_transfer_t *transfer);
72 } const sunxi_hal_driver_spi_t;
73 
74 #ifdef __cplusplus
75 }
76 #endif
77 
78 #endif
79