#pragma once

#include "hw/ssi/ssi.h"
#include "qemu/timer.h"
#include "ui/console.h"

#define TYPE_XTEINK_X3_EINK "xteink-x3-eink"
#define TYPE_XTEINK_X4_EINK "xteink-x4-eink"
OBJECT_DECLARE_SIMPLE_TYPE(XteinkX3EinkState, XTEINK_X3_EINK)

#define XTEINK_X3_EINK_DC "dc"
#define XTEINK_X3_EINK_RESET "reset"
#define XTEINK_X3_EINK_BUSY "busy"

#define XTEINK_X3_WIDTH 792
#define XTEINK_X3_HEIGHT 528
#define XTEINK_X3_WIDTH_BYTES (XTEINK_X3_WIDTH / 8)
#define XTEINK_X3_PLANE_SIZE (XTEINK_X3_WIDTH_BYTES * XTEINK_X3_HEIGHT)
#define XTEINK_X3_LUT_COUNT 5
#define XTEINK_X3_LUT_SIZE 42

struct XteinkX3EinkState {
    SSIPeripheral parent_obj;
    QemuConsole *console;
    QEMUTimer *busy_timer;
    qemu_irq busy;
    bool dc;
    uint8_t command;
    uint32_t plane_pos;
    uint8_t old_plane[XTEINK_X3_PLANE_SIZE];
    uint8_t new_plane[XTEINK_X3_PLANE_SIZE];
    uint8_t lut_bank[XTEINK_X3_LUT_COUNT][XTEINK_X3_LUT_SIZE];
    uint8_t lut_pos[XTEINK_X3_LUT_COUNT];
    bool lut_dirty;
    bool lut_known;
    bool grayscale_lut;
    bool unknown_lut_reported;
};
