Commit a8fcebb51bb864d111cc2fee9029f3578028cd20
authorTorbjorn Tyridal <ttyridal@cisco.com>
Fri, 15 Sep 2017 12:50:02 +0000 (14:50 +0200)
committerMichel Pollet <github.com@pollet.net>
Tue, 19 Sep 2017 09:02:21 +0000 (10:02 +0100)
In particular, it's used by the adafruit driver for arduino

2 files changed:
examples/parts/ssd1306_virt.c
examples/parts/ssd1306_virt.h

index 24d2372c8a882910792f07e992399589d101ce86..681ba1626212f4bba0c910f73fe3926d1433a877 100644 (file)
@@ -41,7 +41,8 @@ ssd1306_write_data (ssd1306_t *part)
        if (++(part->cursor.column) >= SSD1306_VIRT_COLUMNS)
        {
                part->cursor.column = 0;
-               if (++(part->cursor.page) >= SSD1306_VIRT_PAGES)
+               if ( part->addr_mode == SSD1306_ADDR_MODE_HORZ &&
+                       (++(part->cursor.page) >= SSD1306_VIRT_PAGES))
                {
                        part->cursor.page = 0;
                }
@@ -57,6 +58,7 @@ ssd1306_write_data (ssd1306_t *part)
 void
 ssd1306_update_command_register (ssd1306_t *part)
 {
+       part->reg_write_sz = 1;
        switch (part->spi_data)
        {
                case SSD1306_VIRT_SET_CONTRAST:
@@ -137,6 +139,14 @@ ssd1306_update_command_register (ssd1306_t *part)
                        //printf ("SSD1306: SET COM OUTPUT SCAN DIRECTION REMAPPED \n");
                        SSD1306_CLEAR_COMMAND_REG(part);
                        return;
+               case SSD1306_VIRT_MEM_ADDRESSING:
+                       part->command_register = part->spi_data;
+                       return;
+               case SSD1306_VIRT_SET_PAGE_ADDR:
+               case SSD1306_VIRT_SET_COL_ADDR:
+                       part->reg_write_sz = 2;
+                       part->command_register = part->spi_data;
+                       return;
                default:
                        // Unknown command
                        return;
@@ -157,6 +167,34 @@ ssd1306_update_setting (ssd1306_t *part)
                        SSD1306_CLEAR_COMMAND_REG(part);
                        //printf ("SSD1306: CONTRAST SET: 0x%02x\n", part->contrast_register);
                        return;
+               case SSD1306_VIRT_SET_PAGE_ADDR:
+                       switch (--part->reg_write_sz) {
+                               case 1:
+                                       part->cursor.page = part->spi_data;
+                                       break;
+                               case 0:
+                                       //TODO handle virtual page end
+                                       SSD1306_CLEAR_COMMAND_REG(part);
+                       }
+                       return;
+
+               case SSD1306_VIRT_SET_COL_ADDR:
+                       switch (--part->reg_write_sz) {
+                               case 1:
+                                       part->cursor.column = part->spi_data;
+                                       break;
+                               case 0:
+                                       //TODO handle virtual col end
+                                       SSD1306_CLEAR_COMMAND_REG(part);
+                       }
+                       return;
+               case SSD1306_VIRT_MEM_ADDRESSING:
+                       if (part->spi_data > SSD1306_ADDR_MODE_PAGE)
+                               printf ("SSD1306: error ADDRESSING_MODE invalid value %x\n", part->spi_data);
+                       part->addr_mode = part->spi_data;
+                       //printf ("SSD1306: ADDRESSING MODE: 0x%02x\n", part->addr_mode);
+                       SSD1306_CLEAR_COMMAND_REG(part);
+                       return;
                default:
                        // Unknown command
                        return;
@@ -250,6 +288,7 @@ ssd1306_reset_hook (struct avr_irq_t * irq, uint32_t value, void * param)
                part->flags = 0;
                part->command_register = 0x00;
                part->contrast_register = 0x7F;
+               part->addr_mode = SSD1306_ADDR_MODE_PAGE;
                ssd1306_set_flag (part, SSD1306_FLAG_COM_SCAN_NORMAL, 1);
                ssd1306_set_flag (part, SSD1306_FLAG_SEGMENT_REMAP_0, 1);
        }
index 8ad4b35acfdbfe3f5cdd9e7dfff1197e10a86de4..ab5edbe88f4e20af8506f5ce5da3f631d2fd6f37 100644 (file)
@@ -124,6 +124,13 @@ enum
        SSD1306_FLAG_DIRTY,                     // 1: Needs redisplay...
 };
 
+enum ssd1306_addressing_mode_t
+{
+       SSD1306_ADDR_MODE_HORZ = 0,
+       SSD1306_ADDR_MODE_VERT,
+       SSD1306_ADDR_MODE_PAGE
+};
+
 /*
  * Cursor position in VRAM
  */
@@ -146,6 +153,8 @@ typedef struct ssd1306_t
        uint8_t cs_pin;
        uint8_t di_pin;
        uint8_t spi_data;
+       uint8_t reg_write_sz;
+       enum ssd1306_addressing_mode_t addr_mode;
 } ssd1306_t;
 
 typedef struct ssd1306_pin_t