#ifndef DISPLAY_H
#define DISPLAY_H

#include "main.h"

#define DISPLAY_WIDTH 240
#define DISPLAY_HEIGHT 320
#define PIXEL_FORMAT_565
//#define PIXEL_FORMAT_888

typedef uint16_t rgb565_pixel_t;
typedef uint32_t rgb888_pixel_t;

#ifdef PIXEL_FORMAT_565
typedef rgb565_pixel_t pixel_t;

#define PIXEL_RED(p)   (((p) >> 11) & 0x1F)
#define PIXEL_GREEN(p) (((p) >> 5)  & 0x3F)
#define PIXEL_BLUE(p)  ((p) & 0x1F)

#define MAKE_PIXEL(r,g,b) \
    (((r & 0x1F) << 11) | ((g & 0x3F) << 5) | (b & 0x1F))
#endif // PIXEL_FORMAT_565


#ifdef PIXEL_FORMAT_888
typedef rgb888_pixel_t pixel_t;

#define PIXEL_RED(p)   (((p) >> 16) & 0xFF)
#define PIXEL_GREEN(p) (((p) >> 8)  & 0xFF)
#define PIXEL_BLUE(p)  ((p) & 0xFF)

#define MAKE_PIXEL(r,g,b) \
    (((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF))
#endif // PIXEL_FORMAT_888

extern volatile pixel_t framebuffer[DISPLAY_HEIGHT * DISPLAY_WIDTH];

#endif