Commit c6d5375c668ccac3bb67ac285bb8041da8b92c79
authorDelio Brignoli <brignoli.delio@gmail.com>
Wed, 7 Jul 2021 07:20:26 +0000 (09:20 +0200)
committerDelio Brignoli <brignoli.delio@gmail.com>
Wed, 7 Jul 2021 07:51:06 +0000 (09:51 +0200)
2 files changed:
examples/parts/ssd1306_virt.c
examples/parts/ssd1306_virt.h

index 84d25aa62b39b0c25c450ea228c0edb494799d1e..0641592e3269a0fbbb6eb6313d1681d2f1042e4d 100644 (file)
@@ -37,16 +37,34 @@ static void
 ssd1306_write_data (ssd1306_t *part)
 {
        part->vram[part->cursor.page][part->cursor.column] = part->spi_data;
-
-       // Scroll the cursor
-       if (++(part->cursor.column) >= SSD1306_VIRT_COLUMNS)
+       switch (part->addr_mode)
        {
-               part->cursor.column = 0;
-               if ( part->addr_mode == SSD1306_ADDR_MODE_HORZ &&
-                       (++(part->cursor.page) >= SSD1306_VIRT_PAGES))
-               {
-                       part->cursor.page = 0;
-               }
+               case SSD1306_ADDR_MODE_VERT:
+                       if (++(part->cursor.page) > part->write_cursor_end.page)
+                       {
+                               part->cursor.page = part->write_cursor_start.column;
+                               if (++(part->cursor.column) > part->write_cursor_end.column)
+                               {
+                                       part->cursor.column = part->write_cursor_start.page;
+                               }
+                       }
+                       break;
+               case SSD1306_ADDR_MODE_HORZ:
+                       if (++(part->cursor.column) > part->write_cursor_end.column)
+                       {
+                               part->cursor.column = part->write_cursor_start.column;
+                               if (++(part->cursor.page) > part->write_cursor_end.page)
+                               {
+                                       part->cursor.page = part->write_cursor_start.page;
+                               }
+                       }
+                       break;
+               case SSD1306_ADDR_MODE_PAGE:
+                       if (++(part->cursor.column) >= SSD1306_VIRT_COLUMNS)
+                       {
+                               part->cursor.column = 0;
+                       }
+                       break;
        }
 
        ssd1306_set_flag (part, SSD1306_FLAG_DIRTY, 1);
@@ -201,9 +219,10 @@ ssd1306_update_setting (ssd1306_t *part)
                        switch (--part->reg_write_sz) {
                                case 1:
                                        part->cursor.page = part->spi_data;
+                                       part->write_cursor_start.page = part->spi_data;
                                        break;
                                case 0:
-                                       //TODO handle virtual page end
+                                       part->write_cursor_end.page = part->spi_data;
                                        SSD1306_CLEAR_COMMAND_REG(part);
                        }
                        return;
@@ -212,9 +231,10 @@ ssd1306_update_setting (ssd1306_t *part)
                        switch (--part->reg_write_sz) {
                                case 1:
                                        part->cursor.column = part->spi_data;
+                                       part->write_cursor_start.column = part->spi_data;
                                        break;
                                case 0:
-                                       //TODO handle virtual col end
+                                       part->write_cursor_end.column = part->spi_data;
                                        SSD1306_CLEAR_COMMAND_REG(part);
                        }
                        return;
@@ -478,6 +498,8 @@ ssd1306_init (struct avr_t *avr, struct ssd1306_t * part, int width, int height)
        part->columns = width;
        part->rows = height;
        part->pages = height / 8;       // 8 pixels per page
+       part->write_cursor_end.page = SSD1306_VIRT_PAGES-1;
+       part->write_cursor_end.column = SSD1306_VIRT_COLUMNS-1;
 
        /*
         * Register callbacks on all our IRQs
index fdf810379f53618a30ce714402e57877db968868..f47794b2c821336aa19e22eadf12c584aafef32a 100644 (file)
@@ -150,7 +150,7 @@ typedef struct ssd1306_t
        avr_irq_t * irq;
        struct avr_t * avr;
        uint8_t columns, rows, pages;
-       struct ssd1306_virt_cursor_t cursor;
+       struct ssd1306_virt_cursor_t cursor, write_cursor_start, write_cursor_end;
        uint8_t vram[SSD1306_VIRT_PAGES][SSD1306_VIRT_COLUMNS];
        uint16_t flags;
        uint8_t command_register;