/*
 * ADS7843.h
 *
 *  Created on: Aug 6, 2023
 *      Author: leo
 */

#ifndef INC_ADS7843_H_
#define INC_ADS7843_H_

#include <stm32f1xx_hal.h>

#define ADS7843_CHANNEL 4
#define ADS7843_BIT_MODE 3
#define ADS7843_DIFF_MODE 2
#define ADS7843_POW_MODE 0

#define ADS7843_X_CHANNEL 0x1
#define ADS7843_Y_CHANNEL 0x5
#define ADS7843_SER 0x1
#define ADS7843_DFR 0x0
#define ADS7843_12BIT 0x0
#define ADS7843_8BIT 0x1
#define ADS7843_POWER_PENIRQ 0x0

#define ADS7843_X_MIN 300
#define ADS7843_X_MAX 1900

#define ADS7843_Y_MIN 200
#define ADS7843_Y_MAX 1900

#define ADS7843_WIDTH 320
#define ADS7843_HEIGHT 240

typedef struct {
	GPIO_TypeDef* CS_GPIO_Port;
	uint16_t CS_GPIO_Pin;

	GPIO_TypeDef* SCK_GPIO_Port;
	uint16_t SCK_GPIO_Pin;

	GPIO_TypeDef* MOSI_GPIO_Port;
	uint16_t MOSI_GPIO_Pin;

	GPIO_TypeDef* MISO_GPIO_Port;
	uint16_t MISO_GPIO_Pin;

	GPIO_TypeDef* Int_GPIO_Port;
	uint16_t Int_GPIO_Pin;
} ADS7843_Def;

void ADS7843_Init(ADS7843_Def* def);
uint16_t ADS7843_GetData(ADS7843_Def* def, uint8_t control);
GPIO_PinState ADS7843_Touched(ADS7843_Def* def);
uint16_t ADS7843_GetX_Raw(ADS7843_Def* def);
uint16_t ADS7843_GetY_Raw(ADS7843_Def* def);

int16_t ADS7843_GetX(ADS7843_Def* def);
int16_t ADS7843_GetY(ADS7843_Def* def);

#endif /* INC_ADS7843_H_ */
