#include "main.h"
#include "hardware/gpio.h"
#include "pico/stdlib.h"
#include "pico/time.h"
#include "tft.h"

// lcd configuration
const struct tft_config lcd_config = {
	.pio = pio0,
	.sm = 0,
	.gpio_din = PICO_DEFAULT_SPI_TX_PIN,
	.gpio_clk = PICO_DEFAULT_SPI_SCK_PIN,
	.gpio_cs = PICO_DEFAULT_SPI_CSN_PIN,
	.gpio_dc = 26,
	.gpio_rst = 22,
	.gpio_bl = 20,
	.width = 320,
	.height = 480,
};

int main()
{
 	stdio_init_all();
	
	set_sys_clock_khz(200 * 1000, true);

    uint offset = pio_add_program(lcd_config.pio, &tft_program);
    tft_program_init(lcd_config.pio, lcd_config.sm, offset, lcd_config.gpio_din, lcd_config.gpio_clk, 1.f);
	
	tft_init(&lcd_config);
	
	while (true) {
		absolute_time_t start = get_absolute_time();	
		tft_fill(0b0000000000000000);
		tft_fill(0b1111111111111111);
		tft_fill(0b0000000000000000);
		absolute_time_t end = get_absolute_time();	
		volatile int64_t diff = absolute_time_diff_us(start, end);
		printf("test");
	}
	return 0;
}
