/*
 * SPI_Driv.h
 *
 *  Created on: 2021年4月2日
 *      Author: dell
 */

#ifndef SRC_SPI_DRIV_H_
#define SRC_SPI_DRIV_H_

#include "sleep.h"
#include "stdio.h"
#include "xgpiops.h"

typedef uint32_t   u32;
typedef uint16_t   u16;
typedef uint8_t    u8;

#define  wr_flag  1
#define  rd_flag  0

#define  GPIO_OUT	  		1
#define  GPIO_IN	  		0

#define  NUM_SCK_CMD	    4
#define  NUM_SCK_ADDR	    8
#define  NUM_SCK_LENGTH	    4
#define  NUM_SCK_ENABLE	    8
#define  NUM_SCK_BYTE	    2

void interface_initial(u32* device);
void rst_CPLD(u32* device,u32 num_wire);

void  rst(char *d);

void spi_write_onewire(u8 addr, u8 *data, u8 width, u32* device);
u32	 spi_read_onewire(char addr,char width,u32* device,char* read_data);

u32	 uspi_read_onewire(char addr, char width, u32* device);

void fourwire_write(u8 txdata, u32 sdi0, u32 sdi1, u32 sdi2, u32 sdi3);
u16	fourwire_read(u32 sdo0, u32 sdo1, u32 sdo2, u32 sdo3);
void spi_write_fourwire(char addr,u16 data,u32* device);
void spi_read_fourwire(char addr,u16* rxdata,u32* device);

void GPIO_dir_set_16(u32* device,char dir);
void GPIO_dir_set_cs_enable(u32* device,u8 dir);

#endif /* SRC_SPI_DRIV_H_ */
