Skip to content

Commit

Permalink
Making default ssd1327 display to have com even/odd split bit enabled…
Browse files Browse the repository at this point in the history
… by default #86
  • Loading branch information
lexus2k committed Aug 4, 2019
1 parent fc9dabe commit f56c26a
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 17 deletions.
62 changes: 52 additions & 10 deletions src/lcd/oled_ssd1325.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Copyright (c) 2018-2019, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -37,15 +37,15 @@ static const PROGMEM uint8_t s_oled_128x64_initData[] =
{
#ifdef SDL_EMULATION
SDL_LCD_SSD1325,
0x00,
SDL_LCD_SSD1325_GENERIC,
#endif
0xAE, // OFF /* display off */
0xB3, 0x91, // CLK
0xA8, 0x3F, // multiplex 64
0xA2, 0x00, // Display offset
0xA1, 0x00, // Start line
0xAD, 0x02, // VCOMH
0xA0, 0x10 | 0x04 | 0x02 | 0x01, // REMAP: vertical increment mode
0xA0, 0x40 | 0x10 | 0x04 | 0x02 | 0x01, // REMAP: vertical increment mode
0x86, // CURRENT
0x81, 0x70, // CONTRAST
0xB2, 0x51, // FREQ
Expand All @@ -60,22 +60,64 @@ static const PROGMEM uint8_t s_oled_128x64_initData[] =

//////////////////////// SSD1306 COMPATIBLE MODE ///////////////////////////////

SSD1306_COMPAT_SPI_BLOCK_8BIT_CMDS( 0x15, 0x75 );
static uint8_t __s_column;
static uint8_t __s_w;
static uint8_t __s_w2;
static uint8_t __s_page;
static uint8_t __s_leftPixel;
static uint8_t __s_pos;

static void set_block_compat(lcduint_t x, lcduint_t y, lcduint_t w)
{
uint8_t rx = w ? (x + w - 1) : (ssd1306_lcd.width - 1);
rx = rx < ssd1306_lcd.width ? rx : (ssd1306_lcd.width - 1);
__s_column = x;
__s_page = y;
__s_w = w;
__s_w2 = rx - x + 1;
__s_leftPixel = 0;
__s_pos = __s_column;
ssd1306_intf.start();
ssd1306_spiDataMode(0);
ssd1306_intf.send(0x15);
ssd1306_intf.send(x / 2);
ssd1306_intf.send(rx / 2);
ssd1306_intf.send(0x75);
ssd1306_intf.send(y<<3);
ssd1306_intf.send(((y<<3) + 7) < ssd1306_lcd.height ? ((y<<3) + 7) : (ssd1306_lcd.height - 1));
ssd1306_spiDataMode(1);
}

static void next_page_compat(void)
{
ssd1306_intf.stop();
set_block_compat(__s_column,__s_page + 1, __s_w);
}

static void ssd1325_sendPixels(uint8_t data)
{
for (uint8_t i=4; i>0; i--)
if (!(__s_pos & 0x01))
{
__s_leftPixel = data;
data = 0x00;
}
if ((__s_pos & 0x01) || (__s_pos == __s_column + __s_w2 - 1))
{
uint8_t color = (data & 0x01) ? ssd1306_color : 0;
color |= (((data & 0x02) ? ssd1306_color: 0) << 4);
ssd1306_intf.send(color);
data >>= 2;
for (uint8_t i=8; i>0; i--)
{
uint8_t color = (__s_leftPixel & 0x01) ? (ssd1306_color & 0x0F) : 0;
color |= (((data & 0x01) ? (ssd1306_color & 0x0F): 0) << 4);
ssd1306_intf.send(color);
data >>= 1;
__s_leftPixel >>= 1;
}
}
__s_pos++;
}

static void ssd1325_sendPixelsBuffer(const uint8_t *buffer, uint16_t len)
{
while(len--)
while (len--)
{
ssd1325_sendPixels(*buffer);
buffer++;
Expand Down
6 changes: 3 additions & 3 deletions src/lcd/oled_ssd1327.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ extern uint16_t ssd1306_color;
static const PROGMEM uint8_t s_oled_128x128_initData[] =
{
#ifdef SDL_EMULATION
SDL_LCD_SSD1325,
0x01,
SDL_LCD_SSD1327,
SDL_LCD_SSD1327_GENERIC,
#endif
0xFD, 0x12, // Unlock OLED
0xAE, // OFF /* display off */
0xA8, 0x7F, // multiplex 128
0xA1, 0x00, // Start line
0xA2, 0x00, // Display offset
0xA0, 0x10 | 0x04 | (0x02 | 0x01), // REMAP: vertical increment mode
0xA0, 0x40 | 0x10 | 0x04 | (0x02 | 0x01), // REMAP: vertical increment mode
0xAB, 0x01, // VDD internal
0x81, 0x70, // CONTRAST
0xB1, 0x55, // PHASE 0x51
Expand Down
9 changes: 9 additions & 0 deletions tools/sdl/sdl_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ enum
SDL_LCD_SH1106,
SDL_LCD_PCD8544,
SDL_LCD_SSD1325,
SDL_LCD_SSD1327,
SDL_LCD_SSD1331_X8,
SDL_LCD_SSD1331_X16,
SDL_LCD_SSD1351,
Expand All @@ -46,6 +47,14 @@ enum
SDL_LCD_ILI9341,
};

/** ssd1325 / ssd1327 types */
enum
{
SDL_LCD_SSD1325_GENERIC,
SDL_LCD_SSD1327_GENERIC,
SDL_LCD_SSD1327_NO_COM_SPLIT,
};

extern void sdl_core_init(void);
extern void sdl_core_draw(void);

Expand Down
20 changes: 16 additions & 4 deletions tools/sdl/sdl_ssd1325.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
MIT License
Copyright (c) 2018, Alexey Dynda
Copyright (c) 2018-2019, Alexey Dynda
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down Expand Up @@ -36,6 +36,8 @@ static int s_rowEnd = 7;
static int s_newColumn;
static int s_newPage;
static uint8_t detected = 0;
static uint8_t s_subtype = SDL_LCD_SSD1325_GENERIC;
static uint8_t s_hwComSplit = 0;


static void copyBlock()
Expand All @@ -60,15 +62,25 @@ static int sdl_ssd1325_detect(uint8_t data)
{
switch (data)
{
case 0b00000001:
case SDL_LCD_SSD1325_GENERIC:
s_hwComSplit = 1;
sdl_ssd1325.height = 64;
break;
case SDL_LCD_SSD1327_GENERIC:
s_hwComSplit = 1;
sdl_ssd1325.height = 128;
break;
case SDL_LCD_SSD1327_NO_COM_SPLIT:
s_hwComSplit = 0;
sdl_ssd1325.height = 128;
break;
default:
break;
}
s_subtype = data;
return 1;
}
detected = (data == SDL_LCD_SSD1325);
detected = (data == SDL_LCD_SSD1325 || data == SDL_LCD_SSD1327);
return 0;
}

Expand Down Expand Up @@ -181,7 +193,7 @@ static void sdl_ssd1325_data(uint8_t data)
{
int y = s_topToBottom ? s_activeRow : (sdl_ssd1325.height - s_activeRow - 1);
int x = s_leftToRight ? s_activeColumn: (sdl_ssd1325.width - s_activeColumn - 1);
if (s_comSplit)
if ( (s_comSplit && !s_hwComSplit) || (!s_comSplit && s_hwComSplit) )
{
y = ((y & 0x3F) * 2) + ((y > 0x3F) ? 1: 0);
}
Expand Down

0 comments on commit f56c26a

Please sign in to comment.