2014-12-22 12:35:05 +01:00
|
|
|
#ifndef SPI_APP_H
|
|
|
|
#define SPI_APP_H
|
|
|
|
|
|
|
|
#include "spi_register.h"
|
2016-01-20 09:37:03 +01:00
|
|
|
#include "rom.h"
|
2014-12-22 12:35:05 +01:00
|
|
|
#include "osapi.h"
|
|
|
|
#include "uart.h"
|
|
|
|
#include "os_type.h"
|
|
|
|
|
|
|
|
/*SPI number define*/
|
|
|
|
#define SPI 0
|
|
|
|
#define HSPI 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//lcd drive function
|
|
|
|
void spi_lcd_mode_init(uint8 spi_no);
|
|
|
|
void spi_lcd_9bit_write(uint8 spi_no,uint8 high_bit,uint8 low_8bit);
|
|
|
|
|
|
|
|
//spi master init funtion
|
2015-10-27 23:30:33 +01:00
|
|
|
void spi_master_init(uint8 spi_no, unsigned cpol, unsigned cpha, uint32_t clock_div);
|
2015-10-11 13:42:03 +02:00
|
|
|
// fill MOSI buffer
|
2016-01-22 22:34:31 +01:00
|
|
|
void spi_mast_set_mosi(uint8 spi_no, uint8 offset, uint8 bitlen, uint32 data);
|
2015-10-11 13:42:03 +02:00
|
|
|
// retrieve data from MISO buffer
|
2016-01-22 22:34:31 +01:00
|
|
|
uint32 spi_mast_get_miso(uint8 spi_no, uint8 offset, uint8 bitlen);
|
2015-10-11 13:42:03 +02:00
|
|
|
// initiate SPI transaction
|
2015-10-08 23:13:31 +02:00
|
|
|
void spi_mast_transaction(uint8 spi_no, uint8 cmd_bitlen, uint16 cmd_data, uint8 addr_bitlen, uint32 addr_data,
|
2015-10-27 23:30:33 +01:00
|
|
|
uint16 mosi_bitlen, uint8 dummy_bitlen, sint16 miso_bitlen);
|
2015-10-08 23:13:31 +02:00
|
|
|
|
2014-12-22 12:35:05 +01:00
|
|
|
//transmit data to esp8266 slave buffer,which needs 16bit transmission ,
|
|
|
|
//first byte is master command 0x04, second byte is master data
|
|
|
|
void spi_byte_write_espslave(uint8 spi_no,uint8 data);
|
|
|
|
//read data from esp8266 slave buffer,which needs 16bit transmission ,
|
|
|
|
//first byte is master command 0x06, second byte is to read slave data
|
|
|
|
void spi_byte_read_espslave(uint8 spi_no,uint8 *data);
|
|
|
|
|
|
|
|
//esp8266 slave mode initial
|
|
|
|
void spi_slave_init(uint8 spi_no);
|
|
|
|
//esp8266 slave isr handle funtion,tiggered when any transmission is finished.
|
|
|
|
//the function is registered in spi_slave_init.
|
|
|
|
void spi_slave_isr_handler(void *para);
|
|
|
|
|
|
|
|
|
|
|
|
//hspi test function, used to test esp8266 spi slave
|
|
|
|
void hspi_master_readwrite_repeat(void);
|
|
|
|
|
|
|
|
|
|
|
|
void ICACHE_FLASH_ATTR
|
|
|
|
spi_test_init(void);
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|