/*
 * XS65_port.h
 *
 *  Created on: 2020Äê10ÔÂ30ÈÕ
 *      Author: nxa16228
 */

#ifndef XS65_DRV_XS65_PORT_H_
#define XS65_DRV_XS65_PORT_H_

#include "Mcal.h"

#define XS65_SPI_INST   0
#define XS65_SPI_CS     2

#define XS65_ADC_INST   2
#define XS65_ADC_CH_IDX 6

/* reset pin controlled by PTG27 */
#define XS65_RSTB_PIN_INST (32*6+27)
/* limphome pin controlled by PTE19 */
#define XS65_LIMP_PIN_INST (19+32*4)

#define ERR_OK 				0
#define ERR_PARAM_VALUE 	1
#define ERR_PARAM_ADDRESS	2
#define ERR_PARAM_RANGE		3
#define ERR_BUSOFF			4

extern uint16_t adc2RsltArray[10];

void SPI_Device1_Select(void);
void SPI_Device1_Unselect(void);

uint8_t SPI_Device1_RequestBus(void);

uint8_t SPI_Device1_ReleaseBus(void);

uint8_t SPI_Device1_TransferBlock(void* SendDataPtr, void* ReceiveDataPtr, uint32_t Length, bool UnselectAfterTransfer);

uint8_t XS65_ADC_GetCsnsValue(uint32_t adcInst, uint32_t adcChanIdx, uint16_t *pData);

void XS65_RstPinHigh(void);

void XS65_RstPinLow(void);

void XS65_LimphomeDisable(void);

void XS65_LimphomeEnable(void);

#endif /* XS65_DRV_XS65_PORT_H_ */
