avr_t * avr = NULL;
ssd1306_t ssd1306;
+int win_width, win_height;
+
static void *
avr_run_thread (void * ignore)
{
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 ();
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
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