|
|
@ -19,7 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
|
|
|
|
#if GFX_USE_GDISP
|
|
|
|
#if GFX_USE_GDISP
|
|
|
|
|
|
|
|
|
|
|
|
#define GDISP_DRIVER_VMT GDISPVMT_IS31FL3731C_QMK
|
|
|
|
#define GDISP_DRIVER_VMT GDISPVMT_IS31FL3731C_QMK
|
|
|
|
#include "gdisp_lld_config.h"
|
|
|
|
#include "gdisp_lld_config.h"
|
|
|
|
#include "src/gdisp/gdisp_driver.h"
|
|
|
|
#include "src/gdisp/gdisp_driver.h"
|
|
|
|
|
|
|
|
|
|
|
@ -34,26 +34,26 @@ extern const uint8_t CIE1931_CURVE[];
|
|
|
|
/*===========================================================================*/
|
|
|
|
/*===========================================================================*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef GDISP_SCREEN_HEIGHT
|
|
|
|
#ifndef GDISP_SCREEN_HEIGHT
|
|
|
|
#define GDISP_SCREEN_HEIGHT 9
|
|
|
|
#define GDISP_SCREEN_HEIGHT 9
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifndef GDISP_SCREEN_WIDTH
|
|
|
|
#ifndef GDISP_SCREEN_WIDTH
|
|
|
|
#define GDISP_SCREEN_WIDTH 16
|
|
|
|
#define GDISP_SCREEN_WIDTH 16
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifndef GDISP_INITIAL_CONTRAST
|
|
|
|
#ifndef GDISP_INITIAL_CONTRAST
|
|
|
|
#define GDISP_INITIAL_CONTRAST 0
|
|
|
|
#define GDISP_INITIAL_CONTRAST 0
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifndef GDISP_INITIAL_BACKLIGHT
|
|
|
|
#ifndef GDISP_INITIAL_BACKLIGHT
|
|
|
|
#define GDISP_INITIAL_BACKLIGHT 0
|
|
|
|
#define GDISP_INITIAL_BACKLIGHT 0
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#define GDISP_FLG_NEEDFLUSH (GDISP_FLG_DRIVER<<0)
|
|
|
|
#define GDISP_FLG_NEEDFLUSH (GDISP_FLG_DRIVER<<0)
|
|
|
|
|
|
|
|
|
|
|
|
#define IS31_ADDR_DEFAULT 0x74
|
|
|
|
#define IS31_ADDR_DEFAULT 0x74
|
|
|
|
|
|
|
|
|
|
|
|
#define IS31_REG_CONFIG 0x00
|
|
|
|
#define IS31_REG_CONFIG 0x00
|
|
|
|
// bits in reg
|
|
|
|
// bits in reg
|
|
|
|
#define IS31_REG_CONFIG_PICTUREMODE 0x00
|
|
|
|
#define IS31_REG_CONFIG_PICTUREMODE 0x00
|
|
|
|
#define IS31_REG_CONFIG_AUTOPLAYMODE 0x08
|
|
|
|
#define IS31_REG_CONFIG_AUTOPLAYMODE 0x08
|
|
|
|
#define IS31_REG_CONFIG_AUDIOPLAYMODE 0x18
|
|
|
|
#define IS31_REG_CONFIG_AUDIOPLAYMODE 0x18
|
|
|
|
// D2:D0 bits are starting frame for autoplay mode
|
|
|
|
// D2:D0 bits are starting frame for autoplay mode
|
|
|
|
|
|
|
|
|
|
|
@ -144,14 +144,14 @@ static GFXINLINE void write_ram(GDisplay *g, uint8_t page, uint16_t offset, uint
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
|
|
|
|
LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
|
|
|
|
// The private area is the display surface.
|
|
|
|
// The private area is the display surface.
|
|
|
|
g->priv = gfxAlloc(sizeof(PrivData));
|
|
|
|
g->priv = gfxAlloc(sizeof(PrivData));
|
|
|
|
__builtin_memset(PRIV(g), 0, sizeof(PrivData));
|
|
|
|
__builtin_memset(PRIV(g), 0, sizeof(PrivData));
|
|
|
|
PRIV(g)->page = 0;
|
|
|
|
PRIV(g)->page = 0;
|
|
|
|
|
|
|
|
|
|
|
|
// Initialise the board interface
|
|
|
|
// Initialise the board interface
|
|
|
|
init_board(g);
|
|
|
|
init_board(g);
|
|
|
|
gfxSleepMilliseconds(10);
|
|
|
|
gfxSleepMilliseconds(10);
|
|
|
|
|
|
|
|
|
|
|
|
// zero function page, all registers (assuming full_page is all zeroes)
|
|
|
|
// zero function page, all registers (assuming full_page is all zeroes)
|
|
|
|
write_ram(g, IS31_FUNCTIONREG, 0, IS31_FUNCTIONREG_SIZE);
|
|
|
|
write_ram(g, IS31_FUNCTIONREG, 0, IS31_FUNCTIONREG_SIZE);
|
|
|
@ -179,134 +179,134 @@ LLDSPEC bool_t gdisp_lld_init(GDisplay *g) {
|
|
|
|
// Finish Init
|
|
|
|
// Finish Init
|
|
|
|
post_init_board(g);
|
|
|
|
post_init_board(g);
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialise the GDISP structure */
|
|
|
|
/* Initialise the GDISP structure */
|
|
|
|
g->g.Width = GDISP_SCREEN_WIDTH;
|
|
|
|
g->g.Width = GDISP_SCREEN_WIDTH;
|
|
|
|
g->g.Height = GDISP_SCREEN_HEIGHT;
|
|
|
|
g->g.Height = GDISP_SCREEN_HEIGHT;
|
|
|
|
g->g.Orientation = GDISP_ROTATE_0;
|
|
|
|
g->g.Orientation = GDISP_ROTATE_0;
|
|
|
|
g->g.Powermode = powerOff;
|
|
|
|
g->g.Powermode = powerOff;
|
|
|
|
g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
|
|
|
|
g->g.Backlight = GDISP_INITIAL_BACKLIGHT;
|
|
|
|
g->g.Contrast = GDISP_INITIAL_CONTRAST;
|
|
|
|
g->g.Contrast = GDISP_INITIAL_CONTRAST;
|
|
|
|
return TRUE;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if GDISP_HARDWARE_FLUSH
|
|
|
|
#if GDISP_HARDWARE_FLUSH
|
|
|
|
LLDSPEC void gdisp_lld_flush(GDisplay *g) {
|
|
|
|
LLDSPEC void gdisp_lld_flush(GDisplay *g) {
|
|
|
|
// Don't flush if we don't need it.
|
|
|
|
// Don't flush if we don't need it.
|
|
|
|
if (!(g->flags & GDISP_FLG_NEEDFLUSH))
|
|
|
|
if (!(g->flags & GDISP_FLG_NEEDFLUSH))
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
PRIV(g)->page++;
|
|
|
|
PRIV(g)->page++;
|
|
|
|
PRIV(g)->page %= 2;
|
|
|
|
PRIV(g)->page %= 2;
|
|
|
|
// TODO: some smarter algorithm for this
|
|
|
|
// TODO: some smarter algorithm for this
|
|
|
|
// We should run only one physical page at a time
|
|
|
|
// We should run only one physical page at a time
|
|
|
|
// This way we don't need to send so much data, and
|
|
|
|
// This way we don't need to send so much data, and
|
|
|
|
// we could use slightly less memory
|
|
|
|
// we could use slightly less memory
|
|
|
|
uint8_t* src = PRIV(g)->frame_buffer;
|
|
|
|
uint8_t* src = PRIV(g)->frame_buffer;
|
|
|
|
for (int y=0;y<GDISP_SCREEN_HEIGHT;y++) {
|
|
|
|
for (int y=0;y<GDISP_SCREEN_HEIGHT;y++) {
|
|
|
|
for (int x=0;x<GDISP_SCREEN_WIDTH;x++) {
|
|
|
|
for (int x=0;x<GDISP_SCREEN_WIDTH;x++) {
|
|
|
|
uint8_t val = (uint16_t)*src * g->g.Backlight / 100;
|
|
|
|
uint8_t val = (uint16_t)*src * g->g.Backlight / 100;
|
|
|
|
PRIV(g)->write_buffer[get_led_address(g, x, y)]=CIE1931_CURVE[val];
|
|
|
|
PRIV(g)->write_buffer[get_led_address(g, x, y)]=CIE1931_CURVE[val];
|
|
|
|
++src;
|
|
|
|
++src;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
write_ram(g, PRIV(g)->page, IS31_PWM_REG, IS31_PWM_SIZE);
|
|
|
|
write_ram(g, PRIV(g)->page, IS31_PWM_REG, IS31_PWM_SIZE);
|
|
|
|
gfxSleepMilliseconds(1);
|
|
|
|
gfxSleepMilliseconds(1);
|
|
|
|
write_register(g, IS31_FUNCTIONREG, IS31_REG_PICTDISP, PRIV(g)->page);
|
|
|
|
write_register(g, IS31_FUNCTIONREG, IS31_REG_PICTDISP, PRIV(g)->page);
|
|
|
|
|
|
|
|
|
|
|
|
g->flags &= ~GDISP_FLG_NEEDFLUSH;
|
|
|
|
g->flags &= ~GDISP_FLG_NEEDFLUSH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if GDISP_HARDWARE_DRAWPIXEL
|
|
|
|
#if GDISP_HARDWARE_DRAWPIXEL
|
|
|
|
LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) {
|
|
|
|
LLDSPEC void gdisp_lld_draw_pixel(GDisplay *g) {
|
|
|
|
coord_t x, y;
|
|
|
|
coord_t x, y;
|
|
|
|
|
|
|
|
|
|
|
|
switch(g->g.Orientation) {
|
|
|
|
switch(g->g.Orientation) {
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
case GDISP_ROTATE_0:
|
|
|
|
case GDISP_ROTATE_0:
|
|
|
|
x = g->p.x;
|
|
|
|
x = g->p.x;
|
|
|
|
y = g->p.y;
|
|
|
|
y = g->p.y;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case GDISP_ROTATE_180:
|
|
|
|
case GDISP_ROTATE_180:
|
|
|
|
x = GDISP_SCREEN_WIDTH-1 - g->p.x;
|
|
|
|
x = GDISP_SCREEN_WIDTH-1 - g->p.x;
|
|
|
|
y = g->p.y;
|
|
|
|
y = g->p.y;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PRIV(g)->frame_buffer[y * GDISP_SCREEN_WIDTH + x] = gdispColor2Native(g->p.color);
|
|
|
|
PRIV(g)->frame_buffer[y * GDISP_SCREEN_WIDTH + x] = gdispColor2Native(g->p.color);
|
|
|
|
g->flags |= GDISP_FLG_NEEDFLUSH;
|
|
|
|
g->flags |= GDISP_FLG_NEEDFLUSH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if GDISP_HARDWARE_PIXELREAD
|
|
|
|
#if GDISP_HARDWARE_PIXELREAD
|
|
|
|
LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) {
|
|
|
|
LLDSPEC color_t gdisp_lld_get_pixel_color(GDisplay *g) {
|
|
|
|
coord_t x, y;
|
|
|
|
coord_t x, y;
|
|
|
|
|
|
|
|
|
|
|
|
switch(g->g.Orientation) {
|
|
|
|
switch(g->g.Orientation) {
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
case GDISP_ROTATE_0:
|
|
|
|
case GDISP_ROTATE_0:
|
|
|
|
x = g->p.x;
|
|
|
|
x = g->p.x;
|
|
|
|
y = g->p.y;
|
|
|
|
y = g->p.y;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case GDISP_ROTATE_180:
|
|
|
|
case GDISP_ROTATE_180:
|
|
|
|
x = GDISP_SCREEN_WIDTH-1 - g->p.x;
|
|
|
|
x = GDISP_SCREEN_WIDTH-1 - g->p.x;
|
|
|
|
y = g->p.y;
|
|
|
|
y = g->p.y;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return gdispNative2Color(PRIV(g)->frame_buffer[y * GDISP_SCREEN_WIDTH + x]);
|
|
|
|
return gdispNative2Color(PRIV(g)->frame_buffer[y * GDISP_SCREEN_WIDTH + x]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
|
|
|
|
#if GDISP_NEED_CONTROL && GDISP_HARDWARE_CONTROL
|
|
|
|
LLDSPEC void gdisp_lld_control(GDisplay *g) {
|
|
|
|
LLDSPEC void gdisp_lld_control(GDisplay *g) {
|
|
|
|
switch(g->p.x) {
|
|
|
|
switch(g->p.x) {
|
|
|
|
case GDISP_CONTROL_POWER:
|
|
|
|
case GDISP_CONTROL_POWER:
|
|
|
|
if (g->g.Powermode == (powermode_t)g->p.ptr)
|
|
|
|
if (g->g.Powermode == (powermode_t)g->p.ptr)
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
switch((powermode_t)g->p.ptr) {
|
|
|
|
switch((powermode_t)g->p.ptr) {
|
|
|
|
case powerOff:
|
|
|
|
case powerOff:
|
|
|
|
case powerSleep:
|
|
|
|
case powerSleep:
|
|
|
|
case powerDeepSleep:
|
|
|
|
case powerDeepSleep:
|
|
|
|
write_register(g, IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_OFF);
|
|
|
|
write_register(g, IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_OFF);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case powerOn:
|
|
|
|
case powerOn:
|
|
|
|
write_register(g, IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_ON);
|
|
|
|
write_register(g, IS31_FUNCTIONREG, IS31_REG_SHUTDOWN, IS31_REG_SHUTDOWN_ON);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
g->g.Powermode = (powermode_t)g->p.ptr;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case GDISP_CONTROL_ORIENTATION:
|
|
|
|
|
|
|
|
if (g->g.Orientation == (orientation_t)g->p.ptr)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch((orientation_t)g->p.ptr) {
|
|
|
|
|
|
|
|
/* Rotation is handled by the drawing routines */
|
|
|
|
|
|
|
|
case GDISP_ROTATE_0:
|
|
|
|
|
|
|
|
case GDISP_ROTATE_180:
|
|
|
|
|
|
|
|
g->g.Height = GDISP_SCREEN_HEIGHT;
|
|
|
|
|
|
|
|
g->g.Width = GDISP_SCREEN_WIDTH;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDISP_ROTATE_90:
|
|
|
|
|
|
|
|
case GDISP_ROTATE_270:
|
|
|
|
|
|
|
|
g->g.Height = GDISP_SCREEN_WIDTH;
|
|
|
|
|
|
|
|
g->g.Width = GDISP_SCREEN_HEIGHT;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
g->g.Orientation = (orientation_t)g->p.ptr;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case GDISP_CONTROL_BACKLIGHT:
|
|
|
|
|
|
|
|
if (g->g.Backlight == (unsigned)g->p.ptr)
|
|
|
|
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
unsigned val = (unsigned)g->p.ptr;
|
|
|
|
}
|
|
|
|
g->g.Backlight = val > 100 ? 100 : val;
|
|
|
|
g->g.Powermode = (powermode_t)g->p.ptr;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case GDISP_CONTROL_ORIENTATION:
|
|
|
|
|
|
|
|
if (g->g.Orientation == (orientation_t)g->p.ptr)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch((orientation_t)g->p.ptr) {
|
|
|
|
|
|
|
|
/* Rotation is handled by the drawing routines */
|
|
|
|
|
|
|
|
case GDISP_ROTATE_0:
|
|
|
|
|
|
|
|
case GDISP_ROTATE_180:
|
|
|
|
|
|
|
|
g->g.Height = GDISP_SCREEN_HEIGHT;
|
|
|
|
|
|
|
|
g->g.Width = GDISP_SCREEN_WIDTH;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDISP_ROTATE_90:
|
|
|
|
|
|
|
|
case GDISP_ROTATE_270:
|
|
|
|
|
|
|
|
g->g.Height = GDISP_SCREEN_WIDTH;
|
|
|
|
|
|
|
|
g->g.Width = GDISP_SCREEN_HEIGHT;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
g->g.Orientation = (orientation_t)g->p.ptr;
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case GDISP_CONTROL_BACKLIGHT:
|
|
|
|
|
|
|
|
if (g->g.Backlight == (unsigned)g->p.ptr)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
unsigned val = (unsigned)g->p.ptr;
|
|
|
|
|
|
|
|
g->g.Backlight = val > 100 ? 100 : val;
|
|
|
|
g->flags |= GDISP_FLG_NEEDFLUSH;
|
|
|
|
g->flags |= GDISP_FLG_NEEDFLUSH;
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif // GDISP_NEED_CONTROL
|
|
|
|
#endif // GDISP_NEED_CONTROL
|
|
|
|
|
|
|
|
|
|
|
|
#endif // GFX_USE_GDISP
|
|
|
|
#endif // GFX_USE_GDISP
|
|
|
|