1 /* 2 * Copyright ( C) 2015-2020 Alibaba Group Holding Limited 3 */ 4 5 #ifndef _IO_SPI_H_ 6 #define _IO_SPI_H_ 7 8 #define IOC_SPI_BASE 'S' 9 #define IOC_SPI_SET_CFLAG IOC_SPI_BASE + 1 10 #define IOC_SPI_SET_FREQ IOC_SPI_BASE + 2 11 #define IOC_SPI_SEND_RECV IOC_SPI_BASE + 3 12 #define IOC_SPI_SEND_AND_RECV IOC_SPI_BASE + 4 13 #define IOC_SPI_SEND_AND_SEND IOC_SPI_BASE + 5 14 #define IOC_SPI_SET_SERIAL_LEN IOC_SPI_BASE + 6 //default DEFAULT_SPI_SERAIL_LEN 15 16 #define SPI_CPHA (1<<0) /**< spi communication is master mode */ 17 #define SPI_CPOL (1<<1) /**< spi communication is slave mode */ 18 19 #define SPI_MSB (0<<2) /**< spi communication is master mode */ 20 #define SPI_LSB (1<<2) /**< spi communication is slave mode */ 21 22 #define SPI_MASTER (0<<3) /**< spi communication is master mode */ 23 #define SPI_SLAVE (1<<3) /**< spi communication is slave mode */ 24 25 #define SPI_3WIRE 0x10 /**< spi si\so shared */ 26 #define SPI_LOOP 0x20 /**< loop mode */ 27 #define SPI_NO_CS 0x40 /**< NO CS select */ 28 #define SPI_READY 0x80 29 #define SPI_CS_HIGH 0x100 /**< CS high */ 30 31 #define SPI_TRANSFER_MODE_MASK 0x600 32 #define SPI_TRANSFER_DMA_MODE 0x200 33 #define SPI_TRANSFER_NORMAL_MODE 0x400 34 35 #define SPI_DATA_SIZE_MASK 0x000f000 36 #define SPI_DATA_4BIT 0x0001000 37 #define SPI_DATA_5BIT 0x0002000 38 #define SPI_DATA_6BIT 0x0003000 39 #define SPI_DATA_7BIT 0x0004000 40 #define SPI_DATA_8BIT 0x0005000 41 #define SPI_DATA_9BIT 0x0006000 42 #define SPI_DATA_10BIT 0x0007000 43 #define SPI_DATA_11BIT 0x0008000 44 #define SPI_DATA_12BIT 0x0009000 45 #define SPI_DATA_13BIT 0x000a000 46 #define SPI_DATA_14BIT 0x000b000 47 #define SPI_DATA_15BIT 0x000c000 48 #define SPI_DATA_16BIT 0x000d000 49 50 #define SPI_MASK SPI_CPHA | SPI_CPOL | SPI_MSB | SPI_3WIRE | SPI_LOOP | SPI_NO_CS | SPI_READY | SPI_CS_HIGH | SPI_TRANSFER_MODE_MASK | SPI_DATA_SIZE_MASK 51 52 #define SPI_MODE_0 (0|0) 53 #define SPI_MODE_1 (0|SPI_CPHA) 54 #define SPI_MODE_2 (SPI_CPOL|0) 55 #define SPI_MODE_3 (SPI_CPOL|SPI_CPHA) 56 57 typedef struct { 58 uint8_t * tx_buf; 59 uint8_t * rx_buf; 60 uint16_t tx_size; 61 uint16_t rx_size; 62 } ioc_spi_transfer_t; 63 64 typedef int (*spi_rx_cb) (void *spi); // spi's actual type is spi_dev_t * 65 66 int vfs_spi_drv_init (void); 67 68 #endif //_IO_SPI_H_ 69