[SSD1322] add a copy_to_lcd method that accepts an area draft

Wed, 21 Sep 2016 20:09:21 +0200

author
David Douard <david.douard@logilab.fr>
date
Wed, 21 Sep 2016 20:09:21 +0200
changeset 6
8cb67d7afd79
parent 5
f1c85c2500f2
child 7
5cf4034ba4e0

[SSD1322] add a copy_to_lcd method that accepts an area

lib/unigraphic/SSD1322.cpp file | annotate | diff | comparison | revisions
lib/unigraphic/SSD1322.h file | annotate | diff | comparison | revisions
--- a/lib/unigraphic/SSD1322.cpp	Tue Sep 20 23:50:45 2016 +0200
+++ b/lib/unigraphic/SSD1322.cpp	Wed Sep 21 20:09:21 2016 +0200
@@ -337,22 +337,24 @@
 
 
 
-// Set row address 0~32
-void SSD1322::set_row_address(unsigned char add)
+// Set row address 0~64
+void SSD1322::set_row_address(unsigned char start_row, unsigned char end_row)
 {
   wr_cmd8(SSD1322_CMD_SET_ROW_ADDR);
-  add &= 0x3F;
-  wr_data8(add);
-  wr_data8(0x3F);
+  start_row &= 0x3F;
+  wr_data8(start_row);
+  end_row &= 0x3F;
+  wr_data8(end_row);
 }
 
 // Set col address 0~64  for Gray mode)
-void SSD1322::set_column_address(unsigned char add)
+void SSD1322::set_column_address(unsigned char start_col, unsigned char end_col)
 {
   wr_cmd8(SSD1322_CMD_SET_COLUMN_ADDR);
-  add &= 0x3F;
-  wr_data8(0x1c+add); // where does this 0x1C (28) comes from???
-  wr_data8(0x5b); // this 0x5B (91) seems 28+64 (-1)
+  start_col = (start_col & 0x3F) + 0x1C;
+  wr_data8(start_col); // where does this 0x1C (28) comes from???
+  end_col = (end_col & 0x3F) + 0x1C;
+  wr_data8(end_col);
 }
 
 void SSD1322::copy_to_lcd(void)
@@ -370,6 +372,23 @@
       wr_data8(buffer[i++]);
 }
 
+void SSD1322::copy_to_lcd(unsigned char from_col, unsigned char to_col,
+			  unsigned char from_row, unsigned char to_row)
+{
+  unsigned char x, y;
+
+  set_row_address(from_row, to_row);
+  set_column_address(from_col, to_col);
+
+  wr_cmd8(SSD1322_CMD_WRITE_RAM);
+  for(y=from_row; y<=to_row; y++) {
+    for(x=from_col; x<=to_col; x++) { 
+      wr_data8(buffer[y*128 + 2*x]);
+      wr_data8(buffer[y*128 + 2*x + 1]);
+    }
+  }
+}
+
 unsigned long SSD1322::buffaddr(unsigned int i)
 {
   return (unsigned long) &(buffer[i]);
--- a/lib/unigraphic/SSD1322.h	Tue Sep 20 23:50:45 2016 +0200
+++ b/lib/unigraphic/SSD1322.h	Wed Sep 21 20:09:21 2016 +0200
@@ -152,11 +152,14 @@
     unsigned long buffaddr(unsigned int i);
     void fills(const unsigned char value=0xFF);
     void ll_fill(const unsigned char value=0xFF, const unsigned char w=0x78, const unsigned char=0x80);
-    void set_row_address(unsigned char add);
-    void set_column_address(unsigned char add);
+    void set_row_address(unsigned char start_row=0x00, unsigned char end_row=0x3F);
+    void set_column_address(unsigned char start_col=0x00, unsigned char end_col=0x3F);
 
     void start_loop(float tick);
     void stop_loop(void);
+
+    virtual void copy_to_lcd(unsigned char from_col, unsigned char to_col,
+			     unsigned char from_row, unsigned char to_row);
     
 protected:
     /** Setup some stuff (malloc the buffer, etc)

mercurial