summaryrefslogtreecommitdiffhomepage
path: root/digital/lcd
diff options
context:
space:
mode:
Diffstat (limited to 'digital/lcd')
-rw-r--r--digital/lcd/src/font.hh191
-rw-r--r--digital/lcd/src/lcd.cc174
-rw-r--r--digital/lcd/src/lcd.hh21
-rw-r--r--digital/lcd/src/main.cc149
4 files changed, 532 insertions, 3 deletions
diff --git a/digital/lcd/src/font.hh b/digital/lcd/src/font.hh
new file mode 100644
index 00000000..aeeeaacf
--- /dev/null
+++ b/digital/lcd/src/font.hh
@@ -0,0 +1,191 @@
+static unsigned char const Ascii[95][16] = {
+{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*" ",0*/
+
+{0x00,0x00,0x00,0x18,0x3C,0x3C,0x3C,0x18,0x18,0x00,0x18,0x18,0x00,0x00,0x00,0x00},/*"!",1*/
+
+{0x00,0x00,0x00,0x66,0x66,0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*""",2*/
+
+{0x00,0x00,0x00,0x36,0x36,0x7F,0x36,0x36,0x36,0x7F,0x36,0x36,0x00,0x00,0x00,0x00},/*"#",3*/
+
+{0x00,0x18,0x18,0x3C,0x66,0x60,0x30,0x18,0x0C,0x06,0x66,0x3C,0x18,0x18,0x00,0x00},/*"$",4*/
+
+{0x00,0x00,0x70,0xD8,0xDA,0x76,0x0C,0x18,0x30,0x6E,0x5B,0x1B,0x0E,0x00,0x00,0x00},/*"%",5*/
+
+{0x00,0x00,0x00,0x38,0x6C,0x6C,0x38,0x60,0x6F,0x66,0x66,0x3B,0x00,0x00,0x00,0x00},/*"&",6*/
+
+{0x00,0x00,0x00,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",7*/
+
+{0x00,0x00,0x00,0x0C,0x18,0x18,0x30,0x30,0x30,0x30,0x30,0x18,0x18,0x0C,0x00,0x00},/*"(",8*/
+
+{0x00,0x00,0x00,0x30,0x18,0x18,0x0C,0x0C,0x0C,0x0C,0x0C,0x18,0x18,0x30,0x00,0x00},/*")",9*/
+
+{0x00,0x00,0x00,0x00,0x00,0x36,0x1C,0x7F,0x1C,0x36,0x00,0x00,0x00,0x00,0x00,0x00},/*"*",10*/
+
+{0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x7E,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00},/*"+",11*/
+
+{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x0C,0x18,0x00,0x00},/*",",12*/
+
+{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"-",13*/
+
+{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,0x00,0x00},/*".",14*/
+
+{0x00,0x00,0x00,0x06,0x06,0x0C,0x0C,0x18,0x18,0x30,0x30,0x60,0x60,0x00,0x00,0x00},/*"/",15*/
+
+{0x00,0x00,0x00,0x1E,0x33,0x37,0x37,0x33,0x3B,0x3B,0x33,0x1E,0x00,0x00,0x00,0x00},/*"0",16*/
+
+{0x00,0x00,0x00,0x0C,0x1C,0x7C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x00,0x00,0x00,0x00},/*"1",17*/
+
+{0x00,0x00,0x00,0x3C,0x66,0x66,0x06,0x0C,0x18,0x30,0x60,0x7E,0x00,0x00,0x00,0x00},/*"2",18*/
+
+{0x00,0x00,0x00,0x3C,0x66,0x66,0x06,0x1C,0x06,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"3",19*/
+
+{0x00,0x00,0x00,0x30,0x30,0x36,0x36,0x36,0x66,0x7F,0x06,0x06,0x00,0x00,0x00,0x00},/*"4",20*/
+
+{0x00,0x00,0x00,0x7E,0x60,0x60,0x60,0x7C,0x06,0x06,0x0C,0x78,0x00,0x00,0x00,0x00},/*"5",21*/
+
+{0x00,0x00,0x00,0x1C,0x18,0x30,0x7C,0x66,0x66,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"6",22*/
+
+{0x00,0x00,0x00,0x7E,0x06,0x0C,0x0C,0x18,0x18,0x30,0x30,0x30,0x00,0x00,0x00,0x00},/*"7",23*/
+
+{0x00,0x00,0x00,0x3C,0x66,0x66,0x76,0x3C,0x6E,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"8",24*/
+
+{0x00,0x00,0x00,0x3C,0x66,0x66,0x66,0x66,0x3E,0x0C,0x18,0x38,0x00,0x00,0x00,0x00},/*"9",25*/
+
+{0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,0x00,0x00},/*":",26*/
+
+{0x00,0x00,0x00,0x00,0x00,0x1C,0x1C,0x00,0x00,0x00,0x1C,0x1C,0x0C,0x18,0x00,0x00},/*";",27*/
+
+{0x00,0x00,0x00,0x06,0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x06,0x00,0x00,0x00,0x00},/*"<",28*/
+
+{0x00,0x00,0x00,0x00,0x00,0x00,0x7E,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"=",29*/
+
+{0x00,0x00,0x00,0x60,0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x60,0x00,0x00,0x00,0x00},/*">",30*/
+
+{0x00,0x00,0x00,0x3C,0x66,0x66,0x0C,0x18,0x18,0x00,0x18,0x18,0x00,0x00,0x00,0x00},/*"?",31*/
+
+{0x00,0x00,0x00,0x7E,0xC3,0xC3,0xCF,0xDB,0xDB,0xCF,0xC0,0x7F,0x00,0x00,0x00,0x00},/*"@",32*/
+
+{0x00,0x00,0x00,0x18,0x3C,0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00,0x00,0x00,0x00},/*"A",33*/
+
+{0x00,0x00,0x00,0x7C,0x66,0x66,0x66,0x7C,0x66,0x66,0x66,0x7C,0x00,0x00,0x00,0x00},/*"B",34*/
+
+{0x00,0x00,0x00,0x3C,0x66,0x66,0x60,0x60,0x60,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"C",35*/
+
+{0x00,0x00,0x00,0x78,0x6C,0x66,0x66,0x66,0x66,0x66,0x6C,0x78,0x00,0x00,0x00,0x00},/*"D",36*/
+
+{0x00,0x00,0x00,0x7E,0x60,0x60,0x60,0x7C,0x60,0x60,0x60,0x7E,0x00,0x00,0x00,0x00},/*"E",37*/
+
+{0x00,0x00,0x00,0x7E,0x60,0x60,0x60,0x7C,0x60,0x60,0x60,0x60,0x00,0x00,0x00,0x00},/*"F",38*/
+
+{0x00,0x00,0x00,0x3C,0x66,0x66,0x60,0x60,0x6E,0x66,0x66,0x3E,0x00,0x00,0x00,0x00},/*"G",39*/
+
+{0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x66,0x00,0x00,0x00,0x00},/*"H",40*/
+
+{0x00,0x00,0x00,0x3C,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x3C,0x00,0x00,0x00,0x00},/*"I",41*/
+
+{0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x06,0x06,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"J",42*/
+
+{0x00,0x00,0x00,0x66,0x66,0x6C,0x6C,0x78,0x6C,0x6C,0x66,0x66,0x00,0x00,0x00,0x00},/*"K",43*/
+
+{0x00,0x00,0x00,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x60,0x7E,0x00,0x00,0x00,0x00},/*"L",44*/
+
+{0x00,0x00,0x00,0x63,0x63,0x77,0x6B,0x6B,0x6B,0x63,0x63,0x63,0x00,0x00,0x00,0x00},/*"M",45*/
+
+{0x00,0x00,0x00,0x63,0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x63,0x00,0x00,0x00,0x00},/*"N",46*/
+
+{0x00,0x00,0x00,0x3C,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"O",47*/
+
+{0x00,0x00,0x00,0x7C,0x66,0x66,0x66,0x7C,0x60,0x60,0x60,0x60,0x00,0x00,0x00,0x00},/*"P",48*/
+
+{0x00,0x00,0x00,0x3C,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x3C,0x0C,0x06,0x00,0x00},/*"Q",49*/
+
+{0x00,0x00,0x00,0x7C,0x66,0x66,0x66,0x7C,0x6C,0x66,0x66,0x66,0x00,0x00,0x00,0x00},/*"R",50*/
+
+{0x00,0x00,0x00,0x3C,0x66,0x60,0x30,0x18,0x0C,0x06,0x66,0x3C,0x00,0x00,0x00,0x00},/*"S",51*/
+
+{0x00,0x00,0x00,0x7E,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x00,0x00,0x00,0x00},/*"T",52*/
+
+{0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"U",53*/
+
+{0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00,0x00,0x00,0x00},/*"V",54*/
+
+{0x00,0x00,0x00,0x63,0x63,0x63,0x6B,0x6B,0x6B,0x36,0x36,0x36,0x00,0x00,0x00,0x00},/*"W",55*/
+
+{0x00,0x00,0x00,0x66,0x66,0x34,0x18,0x18,0x2C,0x66,0x66,0x66,0x00,0x00,0x00,0x00},/*"X",56*/
+
+{0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x3C,0x18,0x18,0x18,0x18,0x00,0x00,0x00,0x00},/*"Y",57*/
+
+{0x00,0x00,0x00,0x7E,0x06,0x06,0x0C,0x18,0x30,0x60,0x60,0x7E,0x00,0x00,0x00,0x00},/*"Z",58*/
+
+{0x00,0x00,0x00,0x3C,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x30,0x3C,0x00},/*"[",59*/
+
+{0x00,0x00,0x00,0x60,0x60,0x30,0x30,0x18,0x18,0x0C,0x0C,0x06,0x06,0x00,0x00,0x00},/*"\",60*/
+
+{0x00,0x00,0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00},/*"]",61*/
+
+{0x00,0x18,0x3C,0x66,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"^",62*/
+
+{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00},/*"_",63*/
+
+{0x00,0x00,0x00,0x18,0x18,0x18,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"'",64*/
+
+{0x00,0x00,0x00,0x00,0x00,0x3C,0x06,0x06,0x3E,0x66,0x66,0x3E,0x00,0x00,0x00,0x00},/*"a",65*/
+
+{0x00,0x00,0x00,0x60,0x60,0x7C,0x66,0x66,0x66,0x66,0x66,0x7C,0x00,0x00,0x00,0x00},/*"b",66*/
+
+{0x00,0x00,0x00,0x00,0x00,0x3C,0x66,0x60,0x60,0x60,0x66,0x3C,0x00,0x00,0x00,0x00},/*"c",67*/
+
+{0x00,0x00,0x00,0x06,0x06,0x3E,0x66,0x66,0x66,0x66,0x66,0x3E,0x00,0x00,0x00,0x00},/*"d",68*/
+
+{0x00,0x00,0x00,0x00,0x00,0x3C,0x66,0x66,0x7E,0x60,0x60,0x3C,0x00,0x00,0x00,0x00},/*"e",69*/
+
+{0x00,0x00,0x00,0x1E,0x30,0x30,0x30,0x7E,0x30,0x30,0x30,0x30,0x00,0x00,0x00,0x00},/*"f",70*/
+
+{0x00,0x00,0x00,0x00,0x00,0x3E,0x66,0x66,0x66,0x66,0x66,0x3E,0x06,0x06,0x7C,0x00},/*"g",71*/
+
+{0x00,0x00,0x00,0x60,0x60,0x7C,0x66,0x66,0x66,0x66,0x66,0x66,0x00,0x00,0x00,0x00},/*"h",72*/
+
+{0x00,0x00,0x18,0x18,0x00,0x78,0x18,0x18,0x18,0x18,0x18,0x7E,0x00,0x00,0x00,0x00},/*"i",73*/
+
+{0x00,0x00,0x0C,0x0C,0x00,0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x0C,0x78,0x00},/*"j",74*/
+
+{0x00,0x00,0x00,0x60,0x60,0x66,0x66,0x6C,0x78,0x6C,0x66,0x66,0x00,0x00,0x00,0x00},/*"k",75*/
+
+{0x00,0x00,0x00,0x78,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x7E,0x00,0x00,0x00,0x00},/*"l",76*/
+
+{0x00,0x00,0x00,0x00,0x00,0x7E,0x6B,0x6B,0x6B,0x6B,0x6B,0x63,0x00,0x00,0x00,0x00},/*"m",77*/
+
+{0x00,0x00,0x00,0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x66,0x66,0x00,0x00,0x00,0x00},/*"n",78*/
+
+{0x00,0x00,0x00,0x00,0x00,0x3C,0x66,0x66,0x66,0x66,0x66,0x3C,0x00,0x00,0x00,0x00},/*"o",79*/
+
+{0x00,0x00,0x00,0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x66,0x7C,0x60,0x60,0x60,0x00},/*"p",80*/
+
+{0x00,0x00,0x00,0x00,0x00,0x3E,0x66,0x66,0x66,0x66,0x66,0x3E,0x06,0x06,0x06,0x00},/*"q",81*/
+
+{0x00,0x00,0x00,0x00,0x00,0x66,0x6E,0x70,0x60,0x60,0x60,0x60,0x00,0x00,0x00,0x00},/*"r",82*/
+
+{0x00,0x00,0x00,0x00,0x00,0x3E,0x60,0x60,0x3C,0x06,0x06,0x7C,0x00,0x00,0x00,0x00},/*"s",83*/
+
+{0x00,0x00,0x00,0x30,0x30,0x7E,0x30,0x30,0x30,0x30,0x30,0x1E,0x00,0x00,0x00,0x00},/*"t",84*/
+
+{0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0x3E,0x00,0x00,0x00,0x00},/*"u",85*/
+
+{0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00,0x00,0x00,0x00},/*"v",86*/
+
+{0x00,0x00,0x00,0x00,0x00,0x63,0x6B,0x6B,0x6B,0x6B,0x36,0x36,0x00,0x00,0x00,0x00},/*"w",87*/
+
+{0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x3C,0x18,0x3C,0x66,0x66,0x00,0x00,0x00,0x00},/*"x",88*/
+
+{0x00,0x00,0x00,0x00,0x00,0x66,0x66,0x66,0x66,0x66,0x66,0x3C,0x0C,0x18,0xF0,0x00},/*"y",89*/
+
+{0x00,0x00,0x00,0x00,0x00,0x7E,0x06,0x0C,0x18,0x30,0x60,0x7E,0x00,0x00,0x00,0x00},/*"z",90*/
+
+{0x00,0x00,0x00,0x0C,0x18,0x18,0x18,0x30,0x60,0x30,0x18,0x18,0x18,0x0C,0x00,0x00},/*"{",91*/
+
+{0x00,0x00,0x00,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x00},/*"|",92*/
+
+{0x00,0x00,0x00,0x30,0x18,0x18,0x18,0x0C,0x06,0x0C,0x18,0x18,0x18,0x30,0x00,0x00},/*"}",93*/
+
+{0x00,0x00,0x00,0x71,0xDB,0x8E,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},/*"~",94*/
+};
diff --git a/digital/lcd/src/lcd.cc b/digital/lcd/src/lcd.cc
index f2171025..38fbc25f 100644
--- a/digital/lcd/src/lcd.cc
+++ b/digital/lcd/src/lcd.cc
@@ -23,6 +23,8 @@
// }}}
#include "lcd.hh"
#include "ucoolib/utils/delay.hh"
+#include "font.hh"
+
LCD::LCD ()
: cs_ (GPIOB, 10), rs_ (GPIOB, 11), wr_ (GPIOC, 9), rd_ (GPIOC, 6),
@@ -221,4 +223,176 @@ LCD::read_reg (uint16_t index)
cs_.set ();
return data;
}
+void
+LCD::rectangle_fill (uint16_t color,Rect format, Rect pos)//make a filled rectangle
+{
+ set_cursor(pos.x , pos.y);
+ if(format.x+pos.x> x_max){format.x=x_max-pos.x;}
+ if(format.y+pos.y> y_max){format.y=y_max-pos.y;}
+ if(format.x>=0 && format.y >=0)
+ {
+ for(int i=0 ; i<format.y ; i++)
+ {
+ cs_.reset();
+ write_index (0x0022);
+ for(int j=0 ; j<format.x ; j++)
+ {
+ write_data(color);
+ }
+ cs_.set();
+ pos.y++;
+ set_cursor(pos.x , pos.y);
+ }
+ }
+
+}
+void
+LCD::rectangle_empty (uint16_t color,Rect format, Rect pos) //make the border of the rectangle
+{//to make the code better: " use a window HSA in the datasheet"
+ Rect format_line;
+ format_line.x=1;
+ format_line.y=format.y;
+
+ set_cursor(pos.x,pos.y);
+ cs_.reset();
+ write_index (0x0022);
+ for(int j=0 ; j<format.x ; j++)
+ {
+ write_data(color);
+ }
+ cs_.set();
+ rectangle_fill( color , format_line , pos);
+
+ pos.x += format.x;
+ rectangle_fill( color , format_line , pos);
+ pos.y += format.y;
+ pos.x -= format.x;
+
+ set_cursor(pos.x,pos.y);
+
+ cs_.reset();
+ write_index (0x0022);
+ for(int j=0 ; j<format.x ; j++)
+ {
+ write_data(color);
+ }
+ cs_.set();
+
+}
+void
+LCD::blit_pixel ( uint16_t color , int x , int y)//blit a pixel if he is on the screen
+{
+ if(x<0 || x>x_max ||y<0 || y>y_max){return;}
+ set_cursor(x,y);
+ cs_.reset();
+ write_index (0x0022);
+ write_data(color);
+ cs_.set();
+}
+
+void
+LCD::circle ( uint16_t color , int radius , Rect pos) //draw a circle (no problem if a part of the circle is not on the screen)
+{
+ int x=0;
+ int y=radius;
+ int m=5-4*radius;
+ while(x<=y)
+ {
+ if(belong (x+pos.x , y+pos.y))
+ {blit_pixel(color , x+pos.x , y+pos.y);}
+
+ if(belong ( y+pos.x , x+pos.y))
+ {blit_pixel(color , y+pos.x , x+pos.y);}
+
+ if(belong (-x+pos.x , y+pos.y))
+ {blit_pixel(color , -x+pos.x , y+pos.y);}
+
+ if(belong (-y+pos.x , x+pos.y))
+ {blit_pixel(color , -y+pos.x , x+pos.y);}
+
+ if(belong (x+pos.x , -y+pos.y))
+ {blit_pixel(color , x+pos.x , -y+pos.y);}
+
+ if(belong ( y+pos.x , -x+pos.y))
+ {blit_pixel(color , y+pos.x , -x+pos.y);}
+
+ if(belong (-x+pos.x , -y+pos.y))
+ {blit_pixel(color , -x+pos.x , -y+pos.y);}
+
+ if(belong (-y+pos.x , -x+pos.y))
+ {blit_pixel(color , -y+pos.x , -x+pos.y);}
+
+ if(m > 0)
+ {
+ y=y-1;
+ m = m-8*y;
+ }
+ x=x+1;
+ m=m+8*x+4;
+ }
+}
+int
+LCD::belong (int x , int y) //test if the point A(x,y) belong to the screen
+{
+ if(0<=x && x<=x_max && 0<=y && y<=y_max)
+ {return 1;}
+ return 0;
+}
+void
+LCD::draw_char( uint16_t color ,char caract, Rect pos)//draw a caracter
+{
+ if(pos.x+8> x_max || pos.y+16>y_max){return;}
+ caract =caract-32;
+ for( int i = 0 ; i<=16 ; i++)
+ {
+ for( int j =7 ; j>=0 ; j--)
+ {
+ if(Ascii[caract][i]&(1<<j)){blit_pixel(color,8-j+pos.x,i+pos.y);}
+ }
+ }
+}
+void
+LCD::draw_sentence( uint16_t color ,const char *sentence, Rect pos) //write a sentence center on pos
+{
+ char car_act='A'; //carat actuel
+ int i=0;
+ car_act =sentence[i];
+ while(car_act!='\0')
+ {
+ i++;
+ car_act =sentence[i];
+ }
+ pos.x=pos.x-4*i;
+ i=0;
+ car_act =sentence[i];
+ while(car_act!='\0')
+ {
+ draw_char (color ,car_act,pos);
+ pos.x=pos.x+8;
+ i++;
+ car_act =sentence[i];
+ }
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/digital/lcd/src/lcd.hh b/digital/lcd/src/lcd.hh
index e054c2e5..5540c179 100644
--- a/digital/lcd/src/lcd.hh
+++ b/digital/lcd/src/lcd.hh
@@ -27,6 +27,13 @@
#include "ucoolib/hal/gpio/gpio.hh"
/// Control LCD.
+
+struct Rect
+{
+ int x;
+ int y;
+};
+
class LCD
{
public:
@@ -47,6 +54,18 @@ class LCD
{
return (r >> 3 << 11) | (g >> 2 << 5) | (b >> 3);
}
+ ///draw a pixel if he belong to the screen
+ void blit_pixel ( uint16_t color , int x , int y);
+ ///make a border of a rectangle
+ void rectangle_empty (uint16_t color,Rect format, Rect pos);
+ ///make a filled rectangle with one color
+ void rectangle_fill (uint16_t color,Rect format, Rect pos);
+ ///draw a circle
+ void circle ( uint16_t color , int radius , Rect pos); //position of the center of the circle
+ ///write a caracter
+ void draw_char( uint16_t color ,char caract, Rect pos);
+ ///write a sentence center on pos
+ void draw_sentence( uint16_t color ,const char *sentence, Rect pos);
private:
void set_cursor (int x, int y);
void write_index (uint16_t index);
@@ -54,8 +73,8 @@ class LCD
uint16_t read_data ();
void write_reg (uint16_t index, uint16_t data);
uint16_t read_reg (uint16_t index);
+ int belong ( int x, int y); //does the point belong to the screen?
private:
ucoo::Gpio cs_, rs_, wr_, rd_, reset_, bl_;
};
-
#endif // lcd_hh
diff --git a/digital/lcd/src/main.cc b/digital/lcd/src/main.cc
index 38016cd2..34dcbfe8 100644
--- a/digital/lcd/src/main.cc
+++ b/digital/lcd/src/main.cc
@@ -26,9 +26,23 @@
#include "ucoolib/arch/arch.hh"
#include "ucoolib/utils/delay.hh"
#include <libopencm3/stm32/f4/rcc.h>
+#include <cstring>
+
#include "ucoolib/hal/i2c/i2c.hh"
#include "ucoolib/utils/crc.hh"
+#include "ucoolib/utils/bytes.hh"
+//uint16_t ucoo::bytes_pack (arg 1 ,arg 2 );
+
+
+
+static char i2c_color[3];
+static int i2c_time;
+static char i2c_cmd[100]="...";
+static Rect pos_r;//position du robot
+static int nb_obs=0;//nb d'obstacle
+static Rect pos_obs[4];
+static Rect pos_r_n; //next position of the robot
static const int i2c_status_size = 3;
static const int i2c_command_size = 16;
@@ -56,14 +70,41 @@ i2c_handle (LCD &lcd, const char *buf, int size)
char cmd = buf[2];
const char *arg = &buf[3];
int arg_nb = size - 3;
+ int j;
switch (cmd)
{
case 'c':
// Team color.
if (arg_nb != 3)
return;
- lcd.clear (LCD::color (arg[0], arg[1], arg[2]));
+ i2c_color[0]=arg[0];
+ i2c_color[1]=arg[1];
+ i2c_color[2]=arg[2];
break;
+ case 't':
+ i2c_time=arg[0];
+ break;
+ case 'p': //position of the robot
+ pos_r.x=ucoo::bytes_pack (arg[0] ,arg [1] )*0.10666;
+ pos_r.y=ucoo::bytes_pack (arg[2] ,arg [3] )*0.10666;
+ break;
+ case 'm': //message
+ strcpy(i2c_cmd,arg);
+ case 'o': //obstacle (barrier)
+ j=0;
+ nb_obs=arg[0];
+ for(int i=1 ; i<=nb_obs*4 ; i=i+4)
+ {
+ pos_obs[j].x=ucoo::bytes_pack (arg[i] ,arg [i+1] )*0.10666;
+
+ pos_obs[j].y=ucoo::bytes_pack (arg[i+2] ,arg [i+3] )*0.10666;
+ j++;
+ }
+ break;
+ case 'n'://next position of the robot
+ pos_r_n.x=ucoo::bytes_pack (arg[0] ,arg [1] )*0.10666;
+ pos_r_n.y=ucoo::bytes_pack (arg[2] ,arg [3] )*0.10666;
+ break;
default:
// Unknown command.
return;
@@ -89,6 +130,99 @@ i2c_poll (LCD &lcd, ucoo::I2cSlaveDataBuffer &i2c_data)
sizeof (status) - 1);
i2c_data.update (status, sizeof (status));
}
+void
+draw_bar (LCD lcd)//draw barrier (make a red circle where is approximatly the barrier)
+{
+ for(int i=0; i<nb_obs ;i++)
+ {
+ lcd.circle (LCD::color(255,0,0),10 ,pos_obs[i]);
+ }
+}
+
+void
+draw_robot (LCD lcd) //draw of the robot and his barriers
+{
+ Rect pos_rob;pos_rob.x=pos_r.x-12;pos_rob.y=pos_r.y-12;//center the bild of the robot
+ Rect size;size.x=24;size.y=24; //size of the robot
+ Rect pos_rob_n;pos_rob_n.x=pos_r_n.x-2;pos_rob_n.y=pos_r_n.y-2;//center the bild of the next position of the robot
+ Rect size_dest;size_dest.x=5;size_dest.y=5;//size of the robot next position
+ lcd.rectangle_fill (LCD::color ( 100,100,100),size, pos_rob);
+ draw_bar(lcd);
+ lcd.rectangle_fill (LCD::color (0,255,0),size_dest ,pos_rob_n);
+
+}
+
+
+
+void
+draw_time (LCD lcd) //write the remaining time
+{
+
+
+ Rect pos_u;pos_u.x=300;pos_u.y=223;//digit two
+ Rect pos_d;pos_d.x=292;pos_d.y=223;//digit one
+ char dizaine = i2c_time/10 +48;
+ char unite = i2c_time%10 +48;
+ if(i2c_time<0){lcd.draw_sentence (0,"ERROR",pos_d);}
+ else{
+ if(i2c_time/10!=0){lcd.draw_char( 0 ,dizaine,pos_d);}
+ lcd.draw_char( 0 ,unite,pos_u);}
+
+}
+void
+draw_table (LCD lcd) //draw the table on the screen
+{
+ Rect pos_i2c_cmd;pos_i2c_cmd.x=160;pos_i2c_cmd.y=223;
+ char commande [100]="msg: ";
+ strcat(commande, i2c_cmd);
+ Rect pos_cake;pos_cake.x=160;pos_cake.y=0; //position of the center of the cake
+
+ Rect pos_table; pos_table.x=43;pos_table.y=0; //position of the table on the screen
+ Rect for_table; for_table.x= 234; for_table.y=214;//size of the table
+
+ Rect pos_cons; pos_cons.x=0;pos_cons.y=214;//position of the console
+ Rect for_cons; for_cons.x= 320; for_cons.y=27;//size of the console
+
+ Rect for_base;for_base.x=43;for_base.y=43;//size of a base
+
+ Rect pos_base_b_a;pos_base_b_a.x=0;pos_base_b_a.y=0; //position of the 3 blue bases
+ Rect pos_base_b_b;pos_base_b_b.x=0;pos_base_b_b.y=87;
+ Rect pos_base_b_c;pos_base_b_c.x=0;pos_base_b_c.y=172;
+
+ Rect pos_base_r_a;pos_base_r_a.x=277;pos_base_r_a.y=0;//position of the 3 red bases
+ Rect pos_base_r_b;pos_base_r_b.x=277;pos_base_r_b.y=87;
+ Rect pos_base_r_c;pos_base_r_c.x=277;pos_base_r_c.y=172;
+
+ Rect pos_base_n_a;pos_base_n_a.x=0;pos_base_n_a.y=44; //position of the 4 white bases
+ Rect pos_base_n_b;pos_base_n_b.x=0;pos_base_n_b.y=130;
+ Rect pos_base_n_c;pos_base_n_c.x=277;pos_base_n_c.y=44;
+ Rect pos_base_n_d;pos_base_n_d.x=277;pos_base_n_d.y=130;
+
+ Rect pos_color;pos_color.x=10;pos_color.y=223;//position of the team's color rectangle
+ Rect for_color;for_color.x=10;for_color.y=10;//size of the rectangle
+
+ lcd.rectangle_fill (LCD::color(255,255,0),for_table,pos_table);
+
+ lcd.circle (LCD::color(255,200,255), 53 , pos_cake);//pink circle of the cake
+ lcd.rectangle_fill (0xffff , for_cons , pos_cons);//the white rectangle
+ ucoo::delay_ms (15);
+ lcd.rectangle_fill (LCD::color(0,0,255) , for_base, pos_base_b_a);
+ lcd.rectangle_fill (LCD::color(0,0,255) , for_base, pos_base_b_b);
+ lcd.rectangle_fill (LCD::color(0,0,255) , for_base, pos_base_b_c);
+
+ lcd.rectangle_fill (LCD::color(255,0,0) , for_base, pos_base_r_a);
+ lcd.rectangle_fill (LCD::color(255,0,0) , for_base, pos_base_r_b);
+ lcd.rectangle_fill (LCD::color(255,0,0) , for_base, pos_base_r_c);
+
+ lcd.rectangle_fill (LCD::color(255,255,255) , for_base, pos_base_n_a);
+ lcd.rectangle_fill (LCD::color(255,255,255) , for_base, pos_base_n_b);
+ lcd.rectangle_fill (LCD::color(255,255,255) , for_base, pos_base_n_c);
+ lcd.rectangle_fill (LCD::color(255,255,255) , for_base, pos_base_n_d);
+
+ lcd.rectangle_fill (LCD::color(i2c_color[0],i2c_color[1],i2c_color[2]),for_color,pos_color);
+ draw_time (lcd);
+ lcd.draw_sentence (0,commande,pos_i2c_cmd);
+}
int
main (int argc, const char **argv)
@@ -104,12 +238,23 @@ main (int argc, const char **argv)
i2c.enable ();
ucoo::I2cSlaveDataBufferSize<i2c_status_size, i2c_command_size> i2c_data;
i2c.register_data (0x20, i2c_data);
+ //Init global variable
+ i2c_color[0]=0;i2c_color[1]=0;i2c_color[2]=0;
+ i2c_time=90;
+ pos_r_n.x=160;pos_r_n.y=120;
+ pos_r.x=160;pos_r.y=120;
// Init.
+
LCD lcd;
+ //ucoo::delay_ms (1000);
+ draw_table (lcd);
// Wait orders.
while (1)
{
+ draw_table (lcd);//draw the table
+ draw_robot (lcd);//draw the robot and his destination on the table
i2c_poll (lcd, i2c_data);
- ucoo::delay_ms (1);
+ ucoo::delay_ms (1000);
+
}
}