#ifndef DW3000_SPI_H
#define DW3000_SPI_H

#include <stdint.h>

#if ESP_PLATFORM
#include <sdkconfig.h>
#endif

#ifndef CONFIG_DW3000_SPI_TRACE
#define CONFIG_DW3000_SPI_TRACE 0
#endif

typedef struct __attribute__((packed))
{
	uint8_t dw3000_pin_reset;				// 27, 1, DW3000 复位引脚
	uint8_t dw3000_pin_wakeup;				// 28, 1, DW3000 唤醒引脚
	uint8_t dw3000_pin_irq;					// 29, 1, DW3000 中断引脚	
	uint8_t dw3000_pin_cs;					// 30, 1, DW3000 CS 引脚
	uint8_t dw3000_pin_clk;					// 31, 1, DW3000 CLK 引脚
	uint8_t dw3000_pin_miso;				// 32, 1, DW3000 MISO 引脚
	uint8_t dw3000_pin_mosi;				// 33, 1, DW3000 MOSI 引脚
} DW3000_PIN_CONFIG;

extern DW3000_PIN_CONFIG* pin_config;

int dw3000_spi_init();
void dw3000_spi_fini(void);
void dw3000_spi_wakeup(void);
void dw3000_spi_speed_slow(void);
void dw3000_spi_speed_fast(void);
int32_t dw3000_spi_read(uint16_t headerLength, uint8_t* headerBuffer,
	uint16_t readLength, uint8_t* readBuffer);
int32_t dw3000_spi_write(uint16_t headerLength, const uint8_t* headerBuffer,
	uint16_t bodyLength, const uint8_t* bodyBuffer);
int32_t dw3000_spi_write_crc(uint16_t headerLength, const uint8_t* headerBuffer,
	uint16_t bodyLength, const uint8_t* bodyBuffer,
	uint8_t crc8);

void dw3000_spi_trace_output(void);

#endif
