#include <stdio.h>
#include <io.h>
#include <unistd.h>

#include "system.h"
#include "TLA2528.h"

void main(void){
	bool bSuccess;
	const bool bShowData = false;
	uint16_t szMeasured[8], data16;
	int ch, loop=0;
	const float fAVDD = 3.3;

	// softreset
	bSuccess = TLA2518_Softreset(SPI_MASTER_BASE);
	if (!bSuccess)
		printf("failed to reset TLA2518\r\n");


	while (bSuccess){
		bSuccess = TLA2518_Read_8CH_ManualMode(SPI_MASTER_BASE, szMeasured, bShowData);
		if (!bSuccess){
			printf("Failed to read data!\r\n");
		}else{

			printf("========== %d ========== \r\n",loop++);
			for(ch=0;ch<8;ch++){
				data16 = (szMeasured[ch] >> 4) & 0x0FFFF;
				printf("ch%d=%.2fV (%04xh)\r\n", ch, (float)data16/4095.0 * fAVDD,  data16);
			}
			usleep(5*1000*1000);

		}

	}
	return 0;
}
