Skip to content

Commit

Permalink
ssd1306: move display vertical and horizontal mirroring to OpenGL sce…
Browse files Browse the repository at this point in the history
…ne setup

The idea is that the display orientation related code belongs in the
board's implementation. Prior to this commit boards which mount the
display with a different orientation would end up mirroring the pixels
twice: once when reading them from the framebuffer and again in the
OpenGL scene rendering. As a sideeffect now reading pixels from the
vram array is simplified.
  • Loading branch information
dxxb authored and buserror committed Sep 21, 2017
1 parent b3c4ad7 commit 4c9efe1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 39 deletions.
31 changes: 20 additions & 11 deletions examples/board_ssd1306/ssd1306demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ int window_identifier;
avr_t * avr = NULL;
ssd1306_t ssd1306;

int win_width, win_height;

static void *
avr_run_thread (void * ignore)
{
Expand All @@ -71,7 +73,22 @@ keyCB (unsigned char key, int x, int y)
void
displayCB (void)
{
const uint8_t seg_remap_default = ssd1306_get_flag (
&ssd1306, SSD1306_FLAG_SEGMENT_REMAP_0);
const uint8_t seg_comscan_default = ssd1306_get_flag (
&ssd1306, SSD1306_FLAG_COM_SCAN_NORMAL);

glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// Set up projection matrix
glMatrixMode (GL_PROJECTION);
// Start with an identity matrix
glLoadIdentity ();
glOrtho (0, win_width, 0, win_height, 0, 10);
// Apply vertical and horizontal display mirroring
glScalef (seg_remap_default ? 1 : -1, seg_comscan_default ? -1 : 1, 1);
glTranslatef (seg_remap_default ? 0 : -win_width, seg_comscan_default ? -win_height : 0, 0);

// Select modelview matrix
glMatrixMode (GL_MODELVIEW);
glPushMatrix ();
Expand All @@ -94,22 +111,14 @@ timerCB (int i)
int
initGL (int w, int h, float pix_size)
{
w *= pix_size;
h *= pix_size;
win_width = w * pix_size;
win_height = h * pix_size;

// Double buffered, RGB disp mode.
glutInitDisplayMode (GLUT_RGB | GLUT_DOUBLE);
glutInitWindowSize (w, h);
glutInitWindowSize (win_width, win_height);
window_identifier = glutCreateWindow ("SSD1306 128x64 OLED");

// Set up projection matrix
glMatrixMode (GL_PROJECTION);
// Start with an identity matrix
glLoadIdentity ();
glOrtho (0, w, 0, h, 0, 10);
glScalef (1, -1, 1);
glTranslatef (0, -1 * h, 0);

// Set window's display callback
glutDisplayFunc (displayCB);
// Set window's key callback
Expand Down
29 changes: 1 addition & 28 deletions examples/parts/ssd1306_glut.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,34 +112,7 @@ ssd1306_gl_put_pixel_column (uint8_t block_pixel_column, float pixel_opacity,
static uint8_t
ssd1306_gl_get_vram_byte (ssd1306_t *part, uint8_t page, uint8_t column)
{
uint8_t seg_remap_default = ssd1306_get_flag (
part, SSD1306_FLAG_SEGMENT_REMAP_0);
uint8_t seg_comscan_default = ssd1306_get_flag (
part, SSD1306_FLAG_COM_SCAN_NORMAL);

if (seg_remap_default && seg_comscan_default)
{
// Normal display
return part->vram[page][column];
} else if (seg_remap_default && !seg_comscan_default)
{
// Normal display, mirrored from upper edge
return ssd1306_gl_reverse_byte (
part->vram[part->pages - 1 - page][column]);
}

else if (!seg_remap_default && !seg_comscan_default)
{
// Upside down display
return ssd1306_gl_reverse_byte (
part->vram[part->pages - 1 - page][part->columns - 1 - column]);
} else if (!seg_remap_default && seg_comscan_default)
{
// Upside down display, mirrored from upper edge
return part->vram[page][part->columns - 1 - column];
}

return 0;
return part->vram[page][column];
}

static void
Expand Down

0 comments on commit 4c9efe1

Please sign in to comment.