75 lines
2.0 KiB
C
75 lines
2.0 KiB
C
#ifndef __SPIS_H__
|
|
#define __SPIS_H__
|
|
#include "lib.h"
|
|
#include "gpios.h"
|
|
|
|
typedef struct SPIS spi_t;
|
|
|
|
typedef enum
|
|
{
|
|
SPI_TYPE_NORMAL = 0, ///< SPI1:NORMAL
|
|
SPI_TYPE_LCD, ///< SPI2:LCD
|
|
SPI_TYPE_MAX,
|
|
} spi_type_e;
|
|
|
|
/**
|
|
* @brief SPI GPIO group structure
|
|
*/
|
|
typedef struct
|
|
{
|
|
gpio_t *mosi; ///< MOSI
|
|
gpio_t *miso; ///< MISO
|
|
gpio_t *sck; ///< SCK
|
|
gpio_t *cs; ///< CS
|
|
gpio_t *rst; ///< RST
|
|
gpio_t *rdy; ///< DRDY
|
|
gpio_t *dc; ///< DC
|
|
} spi_gpio_group_t;
|
|
|
|
/**
|
|
* @brief SPI LCD interface structure
|
|
*/
|
|
typedef struct
|
|
{
|
|
uint8_t (*write_cmd)(spi_t *handle, uint8_t cmd); ///< Write a command via SPI
|
|
uint8_t (*write_data)(spi_t *handle, uint8_t *data, uint16_t len); ///< Write data via SPI
|
|
} spi_lcd_interface_t;
|
|
|
|
typedef struct
|
|
{
|
|
union
|
|
{
|
|
// spi_normal_interface_t normal;
|
|
spi_lcd_interface_t lcd;
|
|
} u;
|
|
void (*hardware_enable)(spi_t *handle, SPI_HandleTypeDef *spi); ///< Enable hardware SPI
|
|
// void (*dma_enable)(spi_t *handle, DMA_TypeDef *dma, uint32_t dma_rx_channel, spis_dma_callback *dma_rx_cb,
|
|
// uint32_t dma_tx_channel, spis_dma_callback *dma_tx_cb); ///< Enable DMA SPI
|
|
// void (*spi_dma_callback)(spi_t *spi); ///< DMA send completion callback
|
|
// BOOL(*spi_dma_send)
|
|
// (spi_t *handle, uint8_t *data, uint16_t length); ///< DMA send
|
|
} spi_interface_t;
|
|
|
|
struct SPIS
|
|
{
|
|
uint16_t delay_ticks; ///< Delay in NOP ticks
|
|
spi_gpio_group_t gpios; ///< SPI GPIOs
|
|
SPI_HandleTypeDef *spi; ///< SPI handle
|
|
|
|
spi_interface_t interface; ///< SPI interface
|
|
spi_type_e spi_type; ///< SPI type
|
|
BOOL simualte_gpio; ///< Simulate GPIO
|
|
};
|
|
|
|
/**
|
|
* @brief Create a new SPI instance
|
|
*
|
|
* @param spi_type The type of SPI
|
|
* @param gpios The SPI GPIO group
|
|
* @param delay_ticks The delay in NOP ticks
|
|
* @return spi_t* The created SPI instance
|
|
*/
|
|
extern spi_t *spi_create(spi_type_e spi_type, spi_gpio_group_t gpios, uint16_t delay_ticks);
|
|
|
|
#endif ///< __SPIS_H__
|