Fork of David Smart's RA8875 library
Fork of RA8875 by
Revision 19:3f82c1161fd2, committed 2014-01-12
- Comitter:
- WiredHome
- Date:
- Sun Jan 12 17:40:32 2014 +0000
- Parent:
- 18:52cbeede86f0
- Child:
- 20:6e2e4a8372eb
- Commit message:
- Initial commit - mostly working (not Triangles, Externals Fonts). Not ready for other users.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Arial12x12.h Sun Jan 12 17:40:32 2014 +0000 @@ -0,0 +1,106 @@ + + +//GLCD FontName : Arial12x12 +//GLCD FontSize : 12 x 12 + +/** Arial Font with 12*12 matrix to use with SPI_TFT lib */ +__align(2) +const unsigned char Arial12x12[] = { + 25,12,12,2, // Length,horz,vert,byte/vert + 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char + 0x02, 0x00, 0x00, 0x7F, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ! + 0x03, 0x07, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char " + 0x07, 0x24, 0x00, 0xA4, 0x01, 0x7C, 0x00, 0xA7, 0x01, 0x7C, 0x00, 0x27, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char # + 0x06, 0x00, 0x00, 0xCE, 0x00, 0x11, 0x01, 0xFF, 0x03, 0x11, 0x01, 0xE2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char $ + 0x0A, 0x00, 0x00, 0x0E, 0x00, 0x11, 0x00, 0x11, 0x01, 0xCE, 0x00, 0x38, 0x00, 0xE6, 0x00, 0x11, 0x01, 0x10, 0x01, 0xE0, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char % + 0x08, 0x00, 0x00, 0xE0, 0x00, 0x1E, 0x01, 0x11, 0x01, 0x29, 0x01, 0xC6, 0x00, 0xA0, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char & + 0x02, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ' + 0x04, 0x00, 0x00, 0xF8, 0x00, 0x06, 0x03, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ( + 0x03, 0x01, 0x04, 0x06, 0x03, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ) + 0x05, 0x02, 0x00, 0x0A, 0x00, 0x07, 0x00, 0x0A, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char * + 0x06, 0x00, 0x00, 0x10, 0x00, 0x10, 0x00, 0x7C, 0x00, 0x10, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char + + 0x02, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char , + 0x03, 0x20, 0x00, 0x20, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char - + 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char . + 0x03, 0x80, 0x01, 0x7C, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char / + 0x06, 0x00, 0x00, 0xFE, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 0 + 0x06, 0x00, 0x00, 0x04, 0x00, 0x02, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 1 + 0x06, 0x00, 0x00, 0x02, 0x01, 0x81, 0x01, 0x41, 0x01, 0x31, 0x01, 0x0E, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 2 + 0x06, 0x00, 0x00, 0x82, 0x00, 0x01, 0x01, 0x11, 0x01, 0x11, 0x01, 0xEE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 3 + 0x06, 0x00, 0x00, 0x60, 0x00, 0x58, 0x00, 0x46, 0x00, 0xFF, 0x01, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 4 + 0x06, 0x00, 0x00, 0x9C, 0x00, 0x0B, 0x01, 0x09, 0x01, 0x09, 0x01, 0xF1, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 5 + 0x06, 0x00, 0x00, 0xFE, 0x00, 0x11, 0x01, 0x09, 0x01, 0x09, 0x01, 0xF2, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 6 + 0x06, 0x00, 0x00, 0x01, 0x00, 0xC1, 0x01, 0x39, 0x00, 0x07, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 7 + 0x06, 0x00, 0x00, 0xEE, 0x00, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0xEE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 8 + 0x06, 0x00, 0x00, 0x9E, 0x00, 0x21, 0x01, 0x21, 0x01, 0x11, 0x01, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char 9 + 0x02, 0x00, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char : + 0x02, 0x00, 0x00, 0x40, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ; + 0x06, 0x00, 0x00, 0x10, 0x00, 0x28, 0x00, 0x28, 0x00, 0x44, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char < + 0x06, 0x48, 0x00, 0x48, 0x00, 0x48, 0x00, 0x48, 0x00, 0x48, 0x00, 0x48, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char = + 0x06, 0x00, 0x00, 0x44, 0x00, 0x44, 0x00, 0x28, 0x00, 0x28, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char > + 0x06, 0x00, 0x00, 0x06, 0x00, 0x01, 0x00, 0x61, 0x01, 0x11, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ? + 0x0C, 0x00, 0x00, 0xF0, 0x01, 0x0C, 0x02, 0xE2, 0x04, 0x12, 0x09, 0x09, 0x09, 0x09, 0x09, 0xF1, 0x09, 0x19, 0x09, 0x02, 0x05, 0x86, 0x04, 0x78, 0x02, // Code for char @ + 0x07, 0x80, 0x01, 0x70, 0x00, 0x2E, 0x00, 0x21, 0x00, 0x2E, 0x00, 0x70, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char A + 0x07, 0x00, 0x00, 0xFF, 0x01, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char B + 0x08, 0x00, 0x00, 0x7C, 0x00, 0x82, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x82, 0x00, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char C + 0x08, 0x00, 0x00, 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x82, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char D + 0x07, 0x00, 0x00, 0xFF, 0x01, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char E + 0x06, 0x00, 0x00, 0xFF, 0x01, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char F + 0x08, 0x00, 0x00, 0x7C, 0x00, 0x82, 0x00, 0x01, 0x01, 0x01, 0x01, 0x11, 0x01, 0x92, 0x00, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char G + 0x08, 0x00, 0x00, 0xFF, 0x01, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0x10, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char H + 0x02, 0x00, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char I + 0x05, 0xC0, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char J + 0x08, 0x00, 0x00, 0xFF, 0x01, 0x20, 0x00, 0x10, 0x00, 0x28, 0x00, 0x44, 0x00, 0x82, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char K + 0x07, 0x00, 0x00, 0xFF, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char L + 0x08, 0x00, 0x00, 0xFF, 0x01, 0x06, 0x00, 0x78, 0x00, 0x80, 0x01, 0x78, 0x00, 0x06, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char M + 0x08, 0x00, 0x00, 0xFF, 0x01, 0x02, 0x00, 0x0C, 0x00, 0x10, 0x00, 0x60, 0x00, 0x80, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char N + 0x08, 0x00, 0x00, 0x7C, 0x00, 0x82, 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x82, 0x00, 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char O + 0x07, 0x00, 0x00, 0xFF, 0x01, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x0E, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char P + 0x08, 0x00, 0x00, 0x7C, 0x00, 0x82, 0x00, 0x01, 0x01, 0x41, 0x01, 0x41, 0x01, 0x82, 0x00, 0x7C, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Q + 0x08, 0x00, 0x00, 0xFF, 0x01, 0x11, 0x00, 0x11, 0x00, 0x11, 0x00, 0x31, 0x00, 0xD1, 0x00, 0x0E, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char R + 0x07, 0x00, 0x00, 0xCE, 0x00, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0x11, 0x01, 0xE6, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char S + 0x07, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0xFF, 0x01, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char T + 0x08, 0x00, 0x00, 0x7F, 0x00, 0x80, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x80, 0x00, 0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char U + 0x07, 0x03, 0x00, 0x1C, 0x00, 0x60, 0x00, 0x80, 0x01, 0x60, 0x00, 0x1C, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char V + 0x0B, 0x07, 0x00, 0x78, 0x00, 0x80, 0x01, 0x70, 0x00, 0x0E, 0x00, 0x01, 0x00, 0x0E, 0x00, 0x70, 0x00, 0x80, 0x01, 0x7C, 0x00, 0x03, 0x00, 0x00, 0x00, // Code for char W + 0x07, 0x01, 0x01, 0xC6, 0x00, 0x28, 0x00, 0x10, 0x00, 0x28, 0x00, 0xC6, 0x00, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char X + 0x07, 0x01, 0x00, 0x06, 0x00, 0x08, 0x00, 0xF0, 0x01, 0x08, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Y + 0x07, 0x00, 0x01, 0x81, 0x01, 0x61, 0x01, 0x11, 0x01, 0x0D, 0x01, 0x03, 0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char Z + 0x03, 0x00, 0x00, 0xFF, 0x07, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char [ + 0x03, 0x03, 0x00, 0x7C, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char BackSlash + 0x02, 0x01, 0x04, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ] + 0x05, 0x18, 0x00, 0x06, 0x00, 0x01, 0x00, 0x06, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ^ + 0x07, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char _ + 0x03, 0x00, 0x00, 0x01, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ` + 0x06, 0x00, 0x00, 0xC8, 0x00, 0x24, 0x01, 0x24, 0x01, 0xA4, 0x00, 0xF8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char a + 0x06, 0x00, 0x00, 0xFF, 0x01, 0x88, 0x00, 0x04, 0x01, 0x04, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char b + 0x05, 0x00, 0x00, 0xF8, 0x00, 0x04, 0x01, 0x04, 0x01, 0x88, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char c + 0x06, 0x00, 0x00, 0xF8, 0x00, 0x04, 0x01, 0x04, 0x01, 0x08, 0x01, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char d + 0x06, 0x00, 0x00, 0xF8, 0x00, 0x24, 0x01, 0x24, 0x01, 0x24, 0x01, 0xB8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char e + 0x04, 0x04, 0x00, 0xFE, 0x01, 0x05, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char f + 0x06, 0x00, 0x00, 0xF8, 0x04, 0x04, 0x05, 0x04, 0x05, 0x88, 0x04, 0xFC, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char g + 0x06, 0x00, 0x00, 0xFF, 0x01, 0x08, 0x00, 0x04, 0x00, 0x04, 0x00, 0xF8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char h + 0x02, 0x00, 0x00, 0xFD, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char i + 0x02, 0x00, 0x04, 0xFD, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char j + 0x06, 0x00, 0x00, 0xFF, 0x01, 0x20, 0x00, 0x30, 0x00, 0xC8, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char k + 0x02, 0x00, 0x00, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char l + 0x0A, 0x00, 0x00, 0xFC, 0x01, 0x08, 0x00, 0x04, 0x00, 0x04, 0x00, 0xF8, 0x01, 0x08, 0x00, 0x04, 0x00, 0x04, 0x00, 0xF8, 0x01, 0x00, 0x00, 0x00, 0x00, // Code for char m + 0x06, 0x00, 0x00, 0xFC, 0x01, 0x08, 0x00, 0x04, 0x00, 0x04, 0x00, 0xF8, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char n + 0x06, 0x00, 0x00, 0xF8, 0x00, 0x04, 0x01, 0x04, 0x01, 0x04, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char o + 0x06, 0x00, 0x00, 0xFC, 0x07, 0x88, 0x00, 0x04, 0x01, 0x04, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char p + 0x06, 0x00, 0x00, 0xF8, 0x00, 0x04, 0x01, 0x04, 0x01, 0x88, 0x00, 0xFC, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char q + 0x04, 0x00, 0x00, 0xFC, 0x01, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char r + 0x06, 0x00, 0x00, 0x98, 0x00, 0x24, 0x01, 0x24, 0x01, 0x24, 0x01, 0xC8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char s + 0x03, 0x04, 0x00, 0xFF, 0x01, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char t + 0x06, 0x00, 0x00, 0xFC, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0xFC, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char u + 0x05, 0x0C, 0x00, 0x70, 0x00, 0x80, 0x01, 0x70, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char v + 0x09, 0x0C, 0x00, 0x70, 0x00, 0x80, 0x01, 0x70, 0x00, 0x0C, 0x00, 0x70, 0x00, 0x80, 0x01, 0x70, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char w + 0x05, 0x04, 0x01, 0xD8, 0x00, 0x20, 0x00, 0xD8, 0x00, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char x + 0x05, 0x0C, 0x00, 0x70, 0x04, 0x80, 0x03, 0x70, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char y + 0x05, 0x04, 0x01, 0xC4, 0x01, 0x24, 0x01, 0x1C, 0x01, 0x04, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char z + 0x03, 0x20, 0x00, 0xDE, 0x03, 0x01, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char { + 0x02, 0x00, 0x00, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char | + 0x04, 0x00, 0x00, 0x01, 0x04, 0xDE, 0x03, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char } + 0x07, 0x00, 0x00, 0x20, 0x00, 0x10, 0x00, 0x10, 0x00, 0x20, 0x00, 0x20, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Code for char ~ + 0x08, 0x00, 0x00, 0xFE, 0x01, 0x02, 0x01, 0x02, 0x01, 0x02, 0x01, 0x02, 0x01, 0x02, 0x01, 0xFE, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Code for char +};
--- a/GraphicsDisplay.cpp Tue Oct 22 20:17:29 2013 +0000 +++ b/GraphicsDisplay.cpp Sun Jan 12 17:40:32 2014 +0000 @@ -2,118 +2,124 @@ * Copyright (c) 2007-2009 sford * Released under the MIT License: http://mbed.org/license/mit */ - + #include "GraphicsDisplay.h" const unsigned char FONT8x8[97][8] = { -0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00, // columns, rows, num_bytes_per_char -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20 -0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00, // ! -0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00, // " -0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00, // # -0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00, // $ -0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00, // % -0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00, // & -0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00, // ' -0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00, // ( -0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00, // ) -0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, // * -0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00, // + -0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30, // , -0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00, // - -0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00, // . -0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, // / (forward slash) -0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00, // 0 0x30 -0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00, // 1 -0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00, // 2 -0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00, // 3 -0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00, // 4 -0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00, // 5 -0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00, // 6 -0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00, // 7 -0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00, // 8 -0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00, // 9 -0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00, // : -0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30, // ; -0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00, // < -0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00, // = -0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00, // > -0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00, // ? -0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00, // @ 0x40 -0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00, // A -0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00, // B -0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00, // C -0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00, // D -0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00, // E -0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00, // F -0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00, // G -0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00, // H -0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // I -0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00, // J -0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00, // K -0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00, // L -0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00, // M -0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00, // N -0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00, // O -0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00, // P 0x50 -0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00, // Q -0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00, // R -0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00, // S -0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00, // T -0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00, // U -0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00, // V -0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, // W -0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00, // X -0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00, // Y -0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00, // Z -0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, // [ -0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, // \ (back slash) -0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, // ] -0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, // ^ -0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, // _ -0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00, // ` 0x60 -0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00, // a -0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00, // b -0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00, // c -0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00, // d -0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00, // e -0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00, // f -0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C, // g -0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00, // h -0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00, // i -0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C, // j -0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00, // k -0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // l -0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00, // m -0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00, // n -0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00, // o -0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78, // p -0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F, // q -0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00, // r -0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00, // s -0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00, // t -0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00, // u -0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00, // v -0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00, // w -0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00, // x -0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C, // y -0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00, // z -0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00, // { -0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00, // | -0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00, // } -0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00, // ~ -0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00}; // DEL - -GraphicsDisplay::GraphicsDisplay(const char *name):TextDisplay(name) { - foreground(0xFFFF); - background(0x0000); + 0x08,0x08,0x08,0x00,0x00,0x00,0x00,0x00, // columns, rows, num_bytes_per_char + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, // space 0x20 + 0x30,0x78,0x78,0x30,0x30,0x00,0x30,0x00, // ! + 0x6C,0x6C,0x6C,0x00,0x00,0x00,0x00,0x00, // " + 0x6C,0x6C,0xFE,0x6C,0xFE,0x6C,0x6C,0x00, // # + 0x18,0x3E,0x60,0x3C,0x06,0x7C,0x18,0x00, // $ + 0x00,0x63,0x66,0x0C,0x18,0x33,0x63,0x00, // % + 0x1C,0x36,0x1C,0x3B,0x6E,0x66,0x3B,0x00, // & + 0x30,0x30,0x60,0x00,0x00,0x00,0x00,0x00, // ' + 0x0C,0x18,0x30,0x30,0x30,0x18,0x0C,0x00, // ( + 0x30,0x18,0x0C,0x0C,0x0C,0x18,0x30,0x00, // ) + 0x00,0x66,0x3C,0xFF,0x3C,0x66,0x00,0x00, // * + 0x00,0x30,0x30,0xFC,0x30,0x30,0x00,0x00, // + + 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x30, // , + 0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00, // - + 0x00,0x00,0x00,0x00,0x00,0x18,0x18,0x00, // . + 0x03,0x06,0x0C,0x18,0x30,0x60,0x40,0x00, // / (forward slash) + 0x3E,0x63,0x63,0x6B,0x63,0x63,0x3E,0x00, // 0 0x30 + 0x18,0x38,0x58,0x18,0x18,0x18,0x7E,0x00, // 1 + 0x3C,0x66,0x06,0x1C,0x30,0x66,0x7E,0x00, // 2 + 0x3C,0x66,0x06,0x1C,0x06,0x66,0x3C,0x00, // 3 + 0x0E,0x1E,0x36,0x66,0x7F,0x06,0x0F,0x00, // 4 + 0x7E,0x60,0x7C,0x06,0x06,0x66,0x3C,0x00, // 5 + 0x1C,0x30,0x60,0x7C,0x66,0x66,0x3C,0x00, // 6 + 0x7E,0x66,0x06,0x0C,0x18,0x18,0x18,0x00, // 7 + 0x3C,0x66,0x66,0x3C,0x66,0x66,0x3C,0x00, // 8 + 0x3C,0x66,0x66,0x3E,0x06,0x0C,0x38,0x00, // 9 + 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x00, // : + 0x00,0x18,0x18,0x00,0x00,0x18,0x18,0x30, // ; + 0x0C,0x18,0x30,0x60,0x30,0x18,0x0C,0x00, // < + 0x00,0x00,0x7E,0x00,0x00,0x7E,0x00,0x00, // = + 0x30,0x18,0x0C,0x06,0x0C,0x18,0x30,0x00, // > + 0x3C,0x66,0x06,0x0C,0x18,0x00,0x18,0x00, // ? + 0x3E,0x63,0x6F,0x69,0x6F,0x60,0x3E,0x00, // @ 0x40 + 0x18,0x3C,0x66,0x66,0x7E,0x66,0x66,0x00, // A + 0x7E,0x33,0x33,0x3E,0x33,0x33,0x7E,0x00, // B + 0x1E,0x33,0x60,0x60,0x60,0x33,0x1E,0x00, // C + 0x7C,0x36,0x33,0x33,0x33,0x36,0x7C,0x00, // D + 0x7F,0x31,0x34,0x3C,0x34,0x31,0x7F,0x00, // E + 0x7F,0x31,0x34,0x3C,0x34,0x30,0x78,0x00, // F + 0x1E,0x33,0x60,0x60,0x67,0x33,0x1F,0x00, // G + 0x66,0x66,0x66,0x7E,0x66,0x66,0x66,0x00, // H + 0x3C,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // I + 0x0F,0x06,0x06,0x06,0x66,0x66,0x3C,0x00, // J + 0x73,0x33,0x36,0x3C,0x36,0x33,0x73,0x00, // K + 0x78,0x30,0x30,0x30,0x31,0x33,0x7F,0x00, // L + 0x63,0x77,0x7F,0x7F,0x6B,0x63,0x63,0x00, // M + 0x63,0x73,0x7B,0x6F,0x67,0x63,0x63,0x00, // N + 0x3E,0x63,0x63,0x63,0x63,0x63,0x3E,0x00, // O + 0x7E,0x33,0x33,0x3E,0x30,0x30,0x78,0x00, // P 0x50 + 0x3C,0x66,0x66,0x66,0x6E,0x3C,0x0E,0x00, // Q + 0x7E,0x33,0x33,0x3E,0x36,0x33,0x73,0x00, // R + 0x3C,0x66,0x30,0x18,0x0C,0x66,0x3C,0x00, // S + 0x7E,0x5A,0x18,0x18,0x18,0x18,0x3C,0x00, // T + 0x66,0x66,0x66,0x66,0x66,0x66,0x7E,0x00, // U + 0x66,0x66,0x66,0x66,0x66,0x3C,0x18,0x00, // V + 0x63,0x63,0x63,0x6B,0x7F,0x77,0x63,0x00, // W + 0x63,0x63,0x36,0x1C,0x1C,0x36,0x63,0x00, // X + 0x66,0x66,0x66,0x3C,0x18,0x18,0x3C,0x00, // Y + 0x7F,0x63,0x46,0x0C,0x19,0x33,0x7F,0x00, // Z + 0x3C,0x30,0x30,0x30,0x30,0x30,0x3C,0x00, // [ + 0x60,0x30,0x18,0x0C,0x06,0x03,0x01,0x00, // \ (back slash) + 0x3C,0x0C,0x0C,0x0C,0x0C,0x0C,0x3C,0x00, // ] + 0x08,0x1C,0x36,0x63,0x00,0x00,0x00,0x00, // ^ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF, // _ + 0x18,0x18,0x0C,0x00,0x00,0x00,0x00,0x00, // ` 0x60 + 0x00,0x00,0x3C,0x06,0x3E,0x66,0x3B,0x00, // a + 0x70,0x30,0x3E,0x33,0x33,0x33,0x6E,0x00, // b + 0x00,0x00,0x3C,0x66,0x60,0x66,0x3C,0x00, // c + 0x0E,0x06,0x3E,0x66,0x66,0x66,0x3B,0x00, // d + 0x00,0x00,0x3C,0x66,0x7E,0x60,0x3C,0x00, // e + 0x1C,0x36,0x30,0x78,0x30,0x30,0x78,0x00, // f + 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x7C, // g + 0x70,0x30,0x36,0x3B,0x33,0x33,0x73,0x00, // h + 0x18,0x00,0x38,0x18,0x18,0x18,0x3C,0x00, // i + 0x06,0x00,0x06,0x06,0x06,0x66,0x66,0x3C, // j + 0x70,0x30,0x33,0x36,0x3C,0x36,0x73,0x00, // k + 0x38,0x18,0x18,0x18,0x18,0x18,0x3C,0x00, // l + 0x00,0x00,0x66,0x7F,0x7F,0x6B,0x63,0x00, // m + 0x00,0x00,0x7C,0x66,0x66,0x66,0x66,0x00, // n + 0x00,0x00,0x3C,0x66,0x66,0x66,0x3C,0x00, // o + 0x00,0x00,0x6E,0x33,0x33,0x3E,0x30,0x78, // p + 0x00,0x00,0x3B,0x66,0x66,0x3E,0x06,0x0F, // q + 0x00,0x00,0x6E,0x3B,0x33,0x30,0x78,0x00, // r + 0x00,0x00,0x3E,0x60,0x3C,0x06,0x7C,0x00, // s + 0x08,0x18,0x3E,0x18,0x18,0x1A,0x0C,0x00, // t + 0x00,0x00,0x66,0x66,0x66,0x66,0x3B,0x00, // u + 0x00,0x00,0x66,0x66,0x66,0x3C,0x18,0x00, // v + 0x00,0x00,0x63,0x6B,0x7F,0x7F,0x36,0x00, // w + 0x00,0x00,0x63,0x36,0x1C,0x36,0x63,0x00, // x + 0x00,0x00,0x66,0x66,0x66,0x3E,0x06,0x7C, // y + 0x00,0x00,0x7E,0x4C,0x18,0x32,0x7E,0x00, // z + 0x0E,0x18,0x18,0x70,0x18,0x18,0x0E,0x00, // { + 0x0C,0x0C,0x0C,0x00,0x0C,0x0C,0x0C,0x00, // | + 0x70,0x18,0x18,0x0E,0x18,0x18,0x70,0x00, // } + 0x3B,0x6E,0x00,0x00,0x00,0x00,0x00,0x00, // ~ + 0x1C,0x36,0x36,0x1C,0x00,0x00,0x00,0x00 +}; // DEL + +GraphicsDisplay::GraphicsDisplay(const char *name):TextDisplay(name) +{ + //foreground(0xFFFF); + //background(0x0000); } - -void GraphicsDisplay::character(int column, int row, int value) { + + +void GraphicsDisplay::character(int column, int row, int value) +{ blitbit(column * 8, row * 8, 8, 8, (char*)&(FONT8x8[value - 0x1F][0])); } -void GraphicsDisplay::window(unsigned int x,unsigned int y,unsigned int w,unsigned int h) { + +void GraphicsDisplay::window(unsigned int x,unsigned int y,unsigned int w,unsigned int h) +{ // current pixel location _x = x; _y = y; @@ -123,8 +129,9 @@ _y1 = y; _y2 = y + h - 1; } - -void GraphicsDisplay::putp(int colour) { + +void GraphicsDisplay::putp(int colour) +{ // put pixel at current pixel location pixel(_x, _y, colour); // update pixel location based on window settings @@ -138,25 +145,30 @@ } } -void GraphicsDisplay::fill(int x, int y, int w, int h, int colour) { +void GraphicsDisplay::fill(int x, int y, int w, int h, int colour) +{ window(x, y, w, h); for(int i=0; i<w*h; i++) { putp(colour); } } - -void GraphicsDisplay::cls() { + +RetCode_t GraphicsDisplay::cls() +{ fill(0, 0, width(), height(), _background); + return noerror; } - -void GraphicsDisplay::blit(int x, int y, int w, int h, const int *colour) { + +void GraphicsDisplay::blit(int x, int y, int w, int h, const int *colour) +{ window(x, y, w, h); for(int i=0; i<w*h; i++) { putp(colour[i]); } } - -void GraphicsDisplay::blitbit(int x, int y, int w, int h, const char* colour) { + +void GraphicsDisplay::blitbit(int x, int y, int w, int h, const char* colour) +{ window(x, y, w, h); for(int i = 0; i < w*h; i++) { char byte = colour[i >> 3]; @@ -164,13 +176,17 @@ int c = ((byte << offset) & 0x80) ? _foreground : _background; putp(c); } -} - -int GraphicsDisplay::columns() { - return width() / 8; + _foreground = 0xFFFF; + printf("blitbit colors %d,%d\r\n", _foreground, _background); } -int GraphicsDisplay::rows() { - return height() / 8; +int GraphicsDisplay::columns() +{ + return width() / 8; } +int GraphicsDisplay::rows() +{ + return height() / 8; +} +
--- a/GraphicsDisplay.h Tue Oct 22 20:17:29 2013 +0000 +++ b/GraphicsDisplay.h Sun Jan 12 17:40:32 2014 +0000 @@ -22,14 +22,14 @@ GraphicsDisplay(const char* name); - virtual void pixel(int x, int y, int colour) = 0; + virtual RetCode_t pixel(unsigned int x, unsigned int y, color_t colour) = 0; virtual int width() = 0; virtual int height() = 0; virtual void window(unsigned int x,unsigned int y,unsigned int w,unsigned int h); virtual void putp(int colour); - virtual void cls(); + virtual RetCode_t cls(); virtual void fill(int x, int y, int w, int h, int colour); virtual void blit(int x, int y, int w, int h, const int *colour); virtual void blitbit(int x, int y, int w, int h, const char* colour);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RA8875.cpp Sun Jan 12 17:40:32 2014 +0000 @@ -0,0 +1,842 @@ +/// RA8875 Display Controller Library. +/// +/// This is being created for a specific display from buydisplay.com, +/// which is 480 x xxx. It has other attributes (like display controller +/// managed backlight brightness. So, there are expectations and some +/// defined constants based on that specific display. +/// +#include "RA8875.h" + +//#define DEBUG "RAIO" +// ... +// INFO("Stuff to show %d", var); // new-line is automatically appended +// +#if (defined(DEBUG) && !defined(TARGET_LPC11U24)) +#define INFO(x, ...) std::printf("[INF %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); +#define WARN(x, ...) std::printf("[WRN %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); +#define ERR(x, ...) std::printf("[ERR %s %3d] "x"\r\n", DEBUG, __LINE__, ##__VA_ARGS__); +#else +#define INFO(x, ...) +#define WARN(x, ...) +#define ERR(x, ...) +#endif + + +#define RA8875_DISPLAY_WIDTH 480 +#define RA8875_DISPLAY_HEIGHT 272 + +/// @TODO what is the size? +/// If we're using the built-in font, read it from the chip. +/// If we're using a custom font, get it from the font metrics. +const int size_x = 16; +const int size_y = 16; + + +#ifdef PERF_METRICS +#define PERFORMANCE_RESET performance.reset() +#define REGISTERPERFORMANCE(a) RegisterPerformance(a) +static const char *metricsName[] = +{ + "Point", "Line", "Rectangle", "Rounded Rectangle", "Triangle", "Circle", "Ellipse" +}; +#else +#define PERFORMANCE_RESET +#define REGISTERPERFORMANCE(a) +#endif + +// When it is going to poll a register for completion, how many +// uSec should it wait between each polling activity. +#define POLLWAITuSec 10 + + +RA8875::RA8875(PinName mosi, PinName miso, PinName sclk, PinName csel, PinName reset, const char *name) + : spi(mosi, miso, sclk) + , cs(csel) + , res(reset) + , GraphicsDisplay(name) +{ + font = NULL; // no external font, use internal. + select(false); // deselect the display + frequency(RA8875_DEFAULT_SPI_FREQ); // data rate + init(); +#ifdef PERF_METRICS + performance.start(); + ClearPerformance(); +#endif +} + +//RA8875::~RA8875() +//{ +//} + +#ifdef PERF_METRICS +void RA8875::ClearPerformance() +{ + for (int i=0; i<METRICCOUNT; i++) + metrics[i] = 0; +} + +void RA8875::RegisterPerformance(method_e method) +{ + unsigned long elapsed = performance.read_us(); + + if (method < METRICCOUNT && elapsed > metrics[method]) + metrics[method] = elapsed; +} + +void RA8875::ReportPerformance() +{ + for (int i=0; i<METRICCOUNT; i++) { + printf("%10d uS %s\r\n", metrics[i], metricsName[i]); + } +} +#endif + +RetCode_t RA8875::WriteCommand(unsigned char command, unsigned int data) +{ + select(true); + spiwrite(0x80); + spiwrite(command); + if (data <= 0xFF) { // only if in the valid range + spiwrite(0x00); + spiwrite(data); + } + select(false); + return noerror; +} + +RetCode_t RA8875::WriteData(unsigned char data) +{ + select(true); + spiwrite(0x00); + spiwrite(data); + select(false); + return noerror; +} + +unsigned char RA8875::ReadCommand(unsigned char command) +{ + WriteCommand(command); + return ReadData(); +} + +unsigned char RA8875::ReadData(void) +{ + unsigned char data; + + select(true); + spiwrite(0x40); + data = spiread(); + select(false); + return data; +} + +unsigned char RA8875::ReadStatus(void) +{ + unsigned char data; + + select(true); + spiwrite(0xC0); + data = spiread(); + select(false); + return data; +} + +unsigned int RA8875::fontwidth(void) +{ + if (font == NULL) + return size_x; + else + return width() / font[1]; +} + +unsigned int RA8875::fontheight(void) +{ + if (font == NULL) + return size_y; + else + return height() / font[2]; +} + +RetCode_t RA8875::locate(unsigned int x, unsigned int y) +{ + return SetTextCursor(x * fontwidth(), y * fontheight()); +} + +int RA8875::columns(void) +{ + return width() / fontwidth(); +} + +int RA8875::rows(void) +{ + return height() / fontheight(); +} + +int RA8875::width(void) +{ + return RA8875_DISPLAY_WIDTH; +} + +int RA8875::height(void) +{ + return RA8875_DISPLAY_HEIGHT; +} + +RetCode_t RA8875::SetTextCursor(unsigned int x, unsigned int y) +{ + WriteCommand(0x2A, x & 0xFF); + WriteCommand(0x2B, x >> 8); + WriteCommand(0x2C, y & 0xFF); + WriteCommand(0x2D, y >> 8); + INFO("SetTextCursor(%d,%d)", x,y); + return noerror; +} + +RetCode_t RA8875::SetTextFont(RA8875::font_t font) +{ + if (/*font >= RA8875::ISO8859_1 && */ font <= RA8875::ISO8859_4) { + WriteCommand(0x21, (unsigned int)(font)); + return noerror; + } else { + return bad_parameter; + } +} + +RetCode_t RA8875::SetTextFontControl(fill_t fillit, + RA8875::font_angle_t angle, + RA8875::HorizontalScale hScale, + RA8875::VerticalScale vScale, + RA8875::alignment_t alignment) +{ + if (hScale >= 1 && hScale <= 4 && + vScale >= 1 && vScale <= 4) { + unsigned char x = 0; + + if (alignment == align_full) + x |= 0x80; + if (fillit == NOFILL) + x |= 0x40; + if (angle == rotated) + x |= 0x10; + x |= ((hScale - 1) << 2); + x |= ((vScale - 1) << 0); + WriteCommand(0x22, x); + return noerror; + } else { + return bad_parameter; + } +} + +RetCode_t RA8875::SetTextFontSize(RA8875::HorizontalScale hScale, RA8875::VerticalScale vScale) +{ + unsigned char reg = ReadCommand(0x22); + + if (hScale >= 1 && hScale <= 4 && vScale >= 1 && vScale <= 4) { + reg &= 0xF0; // keep the high nibble as is. + reg |= ((hScale - 1) << 2); + reg |= ((vScale - 1) << 0); + WriteCommand(0x22, reg); + return noerror; + } else { + return bad_parameter; + } +} + +int RA8875::_putc(int c) +{ + if (c) { + if (c == '\r') { + unsigned int x; + x = ReadCommand(0x30) | (ReadCommand(0x31) << 8); // Left edge of active window + WriteCommand(0x2A, x & 0xFF); + WriteCommand(0x2B, x >> 8); + } else if (c == '\n') { + unsigned int y; + y = ReadCommand(0x2C) | (ReadCommand(0x2D) << 8); // current y location + y += fontheight(); + if (y > height()) // @TODO > active window, then scroll? + y = 0; + WriteCommand(0x2C, y & 0xFF); + WriteCommand(0x2D, y >> 8); + } else { + if (font == NULL) { + WriteCommand(0x40,0x80); + WriteCommand(0x02); + select(true); + WriteData(c); + while (ReadStatus() & 0x80) + wait_us(POLLWAITuSec); // Chk_Busy(); + select(false); + } else { + unsigned int x = (ReadCommand(0x2A) | (ReadCommand(0x2B) << 8)) / fontwidth(); + unsigned int y = (ReadCommand(0x2C) | (ReadCommand(0x2D) << 8)) / fontheight(); + character(x,y,c); + } + // @TODO right of active window, then wrap? + } + } + return c; +} + +void RA8875::puts(unsigned int x, unsigned int y, const char * string) +{ + SetTextCursor(x,y); + puts(string); +} + +void RA8875::puts(const char * string) +{ + if (*string != '\0') { + INFO("puts(%s)", string); + #if 1 + while (*string) { // @TODO calling individual _putc is slower... anything to do? + _putc(*string++); + } + #else + WriteCommand(0x40,0x80); // Put display into text mode + WriteCommand(0x02); + select(true); + while (*string != '\0') { + WriteData(*string); + ++string; + while (ReadStatus() & 0x80) + wait_us(POLLWAITuSec); // Chk_Busy(); + } + select(false); + #endif + } +} + +RetCode_t RA8875::SetMemoryCursor(unsigned int x, unsigned int y) + +{ + WriteCommand(0x46, x & 0xFF); + WriteCommand(0x47, x >> 8); + WriteCommand(0x48, y & 0xFF); + WriteCommand(0x49, y >> 8); + return noerror; +} + +RetCode_t RA8875::SetWindow(unsigned int x, unsigned int y, unsigned int width, unsigned int height) +{ + WriteCommand(0x30, x & 0xFF); // HSAW0 + WriteCommand(0x31, x >> 8); // HSAW1 + WriteCommand(0x32, y & 0xFF); // VSAW0 + WriteCommand(0x33, y >> 8); // VSAW1 + WriteCommand(0x34, (x+width-1) & 0xFF); // HEAW0 + WriteCommand(0x35, (x+width-1) >> 8); // HEAW1 + WriteCommand(0x36, (y+height-1) & 0xFF); // VEAW0 + WriteCommand(0x37, (y+height-1) >> 8); // VEAW1 + return noerror; +} + +RetCode_t RA8875::cls(void) +{ + PERFORMANCE_RESET; + clsw(FULLWINDOW); + REGISTERPERFORMANCE(PRF_CLS); + return noerror; +} + +RetCode_t RA8875::clsw(RA8875::Region_t region) +{ + PERFORMANCE_RESET; + WriteCommand(0x8E, (region == ACTIVEWINDOW) ? 0xC0 : 0x80); + while (ReadCommand(0x8E) & 0x80) + wait_us(POLLWAITuSec); + REGISTERPERFORMANCE(PRF_CLS); + return noerror; +} + +RetCode_t RA8875::pixel(unsigned int x, unsigned int y, color_t color) +{ + foreground(color); + return pixel(x,y); +} + +RetCode_t RA8875::pixel(unsigned int x, unsigned int y) +{ + RetCode_t ret; + + PERFORMANCE_RESET; + #if 1 + color_t color = GetForeColor(); + WriteCommand(0x40,0x00); // Graphics write mode + SetMemoryCursor(x, y); + WriteCommand(0x02); //start data write + WriteData(color & 0xFF); + WriteData(color >> 8); + ret = noerror; + #else + // There isn't actually a set pixel function that I found + // so we'll emulate it as we can. + ret = line(x,y, x,y); + #endif + REGISTERPERFORMANCE(PRF_DRAWPOINT); + return ret; +} + +RetCode_t RA8875::line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, color_t color) +{ + foreground(color); + return line(x1,y1,x2,y2); +} + +RetCode_t RA8875::line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2) +{ + PERFORMANCE_RESET; + WriteCommand(0x91, x1 & 0xFF); + WriteCommand(0x92, x1 >> 8); + WriteCommand(0x93, y1 & 0xFF); + WriteCommand(0x94, y1 >> 8); + WriteCommand(0x95, x2 & 0xFF); + WriteCommand(0x96, x2 >> 8); + WriteCommand(0x97, y2 & 0xFF); + WriteCommand(0x98, y2 >> 8); + + unsigned char drawCmd = 0x00; // Line + WriteCommand(0x90, drawCmd); + WriteCommand(0x90, 0x80 + drawCmd); // Start drawing. + while (ReadCommand(0x90) & 0x80) // await completion. + wait_us(POLLWAITuSec); + REGISTERPERFORMANCE(PRF_DRAWLINE); + return noerror; +} + +RetCode_t RA8875::fillrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + color_t color, fill_t fillit) +{ + return rect(x1,y1,x2,y2,color,fillit); +} + +RetCode_t RA8875::rect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + color_t color, fill_t fillit) +{ + foreground(color); + return rect(x1,y1,x2,y2,fillit); +} + +RetCode_t RA8875::rect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + fill_t fillit) +{ + PERFORMANCE_RESET; + if (x1 == x2 && y1 == y2) { + pixel(x1, y1); + } else if (x1 == x2) { + line(x1, y1, x2, y2); + } else if (y1 == y2) { + line(x1, y1, x2, y2); + } else { + WriteCommand(0x91, x1 & 0xFF); + WriteCommand(0x92, x1 >> 8); + WriteCommand(0x93, y1 & 0xFF); + WriteCommand(0x94, y1 >> 8); + WriteCommand(0x95, x2 & 0xFF); + WriteCommand(0x96, x2 >> 8); + WriteCommand(0x97, y2 & 0xFF); + WriteCommand(0x98, y2 >> 8); + + unsigned char drawCmd = 0x10; // Rectangle + if (fillit == FILL) + drawCmd |= 0x20; + WriteCommand(0x90, drawCmd); + WriteCommand(0x90, 0x80 + drawCmd); // Start drawing. + while (ReadCommand(0x90) & 0x80) // await completion. + wait_us(POLLWAITuSec); + } + REGISTERPERFORMANCE(PRF_DRAWRECTANGLE); + return noerror; +} + +RetCode_t RA8875::fillroundrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + unsigned int radius1, unsigned int radius2, color_t color, fill_t fillit) +{ + foreground(color); + return roundrect(x1,y1,x2,y2,radius1,radius2,fillit); +} + +RetCode_t RA8875::roundrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + unsigned int radius1, unsigned int radius2, color_t color, fill_t fillit) +{ + foreground(color); + return roundrect(x1,y1,x2,y2,radius1,radius2,fillit); +} + +RetCode_t RA8875::roundrect(unsigned int x1, unsigned int y1 ,unsigned int x2, unsigned int y2, + unsigned int radius1, unsigned int radius2, fill_t fillit) +{ + RetCode_t ret = noerror; + + PERFORMANCE_RESET; + if (x1 == x2 && y1 == y2) { + pixel(x1, y1); + } else if (x1 == x2) { + line(x1, y1, x2, y2); + } else if (y1 == y2) { + line(x1, y1, x2, y2); + } else { + WriteCommand(0x91, x1 & 0xFF); + WriteCommand(0x92, x1 >> 8); + WriteCommand(0x93, y1 & 0xFF); + WriteCommand(0x94, y1 >> 8); + WriteCommand(0x95, x2 & 0xFF); + WriteCommand(0x96, x2 >> 8); + WriteCommand(0x97, y2 & 0xFF); + WriteCommand(0x98, y2 >> 8); + + //while (r && r > (x2 - x1) || r > (y2 - y1)) + // r--; + WriteCommand(0xA1, radius1 & 0xFF); + WriteCommand(0xA2, radius1 >> 8); + WriteCommand(0xA3, radius2 & 0xFF); + WriteCommand(0xA4, radius2 >> 8); + + unsigned char drawCmd = 0x20; // Rounded Rectangle + if (fillit == FILL) + drawCmd |= 0x40; + WriteCommand(0xA0, drawCmd); + WriteCommand(0xA0, 0x80 + drawCmd); // Start drawing. + while (ReadCommand(0xA0) & 0x80) { // await completion. + wait_us(POLLWAITuSec); + } + } + REGISTERPERFORMANCE(PRF_DRAWROUNDEDRECTANGLE); + return ret; +} + +RetCode_t RA8875::triangle(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + unsigned int x3, unsigned int y3, color_t color, fill_t fillit) +{ + foreground(color); + return triangle(x1,y1,x2,y2,x3,y3,color,fillit); +} + +RetCode_t RA8875::filltriangle(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + unsigned int x3, unsigned int y3, color_t color, fill_t fillit) +{ + foreground(color); + return triangle(x1,y1,x2,y2,x3,y3,color,fillit); +} + +RetCode_t RA8875::triangle(unsigned int x1, unsigned int y1 ,unsigned int x2, unsigned int y2, + unsigned int x3, unsigned int y3, fill_t fillit) +{ + RetCode_t ret = noerror; + + PERFORMANCE_RESET; + if (x1 == x2 && y1 == y2 && x1 == x3 && y1 == y3) { + pixel(x1, y1); + } else { + WriteCommand(0x91, x1 & 0xFF); + WriteCommand(0x92, x1 >> 8); + WriteCommand(0x93, y1 & 0xFF); + WriteCommand(0x94, y1 >> 8); + + WriteCommand(0x95, x2 & 0xFF); + WriteCommand(0x96, x2 >> 8); + WriteCommand(0x97, y2 & 0xFF); + WriteCommand(0x98, y2 >> 8); + + WriteCommand(0xA9, x3 & 0xFF); + WriteCommand(0xAA, x3 >> 8); + WriteCommand(0xAB, y3 & 0xFF); + WriteCommand(0xAC, y3 >> 8); + + unsigned char drawCmd = 0x01; // Triangle + if (fillit == FILL) + drawCmd |= 0x20; + WriteCommand(0x90, drawCmd); + WriteCommand(0x90, 0x80 + drawCmd); // Start drawing. + while (ReadCommand(0x90) & 0x80) // await completion. + wait_us(POLLWAITuSec); + } + REGISTERPERFORMANCE(PRF_DRAWTRIANGLE); + return ret; +} + +RetCode_t RA8875::circle(unsigned int x, unsigned int y, unsigned int radius, + color_t color, fill_t fillit) +{ + foreground(color); + return circle(x,y,radius,fillit); +} + +RetCode_t RA8875::fillcircle(unsigned int x, unsigned int y, unsigned int radius, + color_t color, fill_t fillit) +{ + foreground(color); + return circle(x,y,radius,fillit); +} + +RetCode_t RA8875::circle(unsigned int x, unsigned int y, unsigned int radius, fill_t fillit) +{ + RetCode_t ret = noerror; + + PERFORMANCE_RESET; + if (radius <= 0) { + ret = bad_parameter; + } else if (radius == 1) { + pixel(x,y); + } else { + WriteCommand(0x99, x & 0xFF); + WriteCommand(0x9a, x >> 8); + WriteCommand(0x9b, y & 0xFF); + WriteCommand(0x9c, y >> 8); + WriteCommand(0x9d, radius & 0xFF); + + unsigned char drawCmd = 0x00; // Circle + if (fillit == FILL) + drawCmd |= 0x20; + WriteCommand(0x90, drawCmd); + WriteCommand(0x90, 0x40 + drawCmd); // Start drawing. + while (ReadCommand(0x90) & 0x40) // await completion. + wait_us(POLLWAITuSec); + } + REGISTERPERFORMANCE(PRF_DRAWCIRCLE); + return ret; +} + +RetCode_t RA8875::ellipse(unsigned int x, unsigned int y, unsigned int R1, unsigned int R2, color_t color, fill_t fillit) +{ + foreground(color); + return ellipse(x,y,R1,R2,fillit); +} + +RetCode_t RA8875::ellipse(unsigned int x, unsigned int y, unsigned int R1, unsigned int R2, fill_t fillit) +{ + RetCode_t ret = noerror; + + PERFORMANCE_RESET; + if (R1 <= 0 || R2 <= 0) { + ; // do nothing + } else if (R1 == 1 && R2 == 1) { + pixel(x, y); + } else { + WriteCommand(0xA5, x & 0xFF); + WriteCommand(0xA6, x >> 8); + WriteCommand(0xA7, y & 0xFF); + WriteCommand(0xA8, y >> 8); + WriteCommand(0xA1, R1 & 0xFF); + WriteCommand(0xA2, R1 >> 8); + WriteCommand(0xA3, R2 & 0xFF); + WriteCommand(0xA4, R2 >> 8); + + unsigned char drawCmd = 0x00; // Ellipse + if (fillit == FILL) + drawCmd |= 0x40; + WriteCommand(0xA0, drawCmd); + WriteCommand(0xA0, 0x80 + drawCmd); // Start drawing. + while (ReadCommand(0xA0) & 0x80) // await completion. + wait_us(POLLWAITuSec); + } + REGISTERPERFORMANCE(PRF_DRAWELLIPSE); + return ret; +} + + +RetCode_t RA8875::frequency(unsigned long Hz) +{ + spi.frequency(Hz); + // __ ___ + // Clock ___A Rising edge latched + // ___ ____ + // Data ___X____ + spi.format(8, 3); // 8 bits and clock to data phase 0 + init(); + return noerror; +} + +RetCode_t RA8875::Power(bool on) +{ + WriteCommand(0x01, (on) ? 0x80 : 0x00); + return noerror; +} + +RetCode_t RA8875::Reset(void) +{ + WriteCommand(0x01, 0x01); // Apply Display Off, Reset + wait_ms(2); // no idea if I need to wait, or how long + WriteCommand(0x01, 0x00); // Display off, Remove reset + wait_ms(2); // no idea if I need to wait, or how long + init(); + return noerror; +} + + +RetCode_t RA8875::Backlight_u8(unsigned char brightness) +{ + static bool is_enabled = false; + if (brightness == 0) { + WriteCommand(0x8a); // Disable the PWM + WriteData(0x00); + is_enabled = false; + } else if (!is_enabled) { + WriteCommand(0x8a); // Enable the PWM + WriteData(0x80); + WriteCommand(0x8a); // Not sure why this is needed, but following the pattern + WriteData(0x81); // open PWM (SYS_CLK / 2 as best I can tell) + is_enabled = true; + } + WriteCommand(0x8b, brightness); // Brightness parameter 0xff-0x00 + return noerror; +} + +RetCode_t RA8875::Backlight(float brightness) +{ + unsigned char b; + + if (brightness > 1.0) + b = 255; + else if (brightness < 0) + b = 0; + else + b = (unsigned char)(brightness * 255); + return Backlight_u8(b); +} + + +RetCode_t RA8875::set_font(const unsigned char * _font) +{ + font = _font; + return noerror; // trusting them, but we could put some checks in here... +} + +RetCode_t RA8875::background(color_t color) +{ + WriteCommand(0x60, (color>>11)); // BGCR0 + WriteCommand(0x61, (unsigned char)(color>>5)); // BGCR0 + WriteCommand(0x62, (unsigned char)(color)); // BGCR0 + return noerror; +} + +RetCode_t RA8875::background(unsigned char r, unsigned char g, unsigned char b) +{ + WriteCommand(0x60, r); + WriteCommand(0x61, g); + WriteCommand(0x62, b); + return noerror; +} + +RetCode_t RA8875::foreground(color_t color) +{ + WriteCommand(0x63, (unsigned char)(color>>11)); + WriteCommand(0x64, (unsigned char)(color>>5)); + WriteCommand(0x65, (unsigned char)(color)); + return noerror; +} + +RetCode_t RA8875::foreground(unsigned char setR, unsigned char setG, unsigned char setB) +{ + WriteCommand(0x63, setR); + WriteCommand(0x64, setG); + WriteCommand(0x65, setB); + return noerror; +} + +unsigned int RA8875::GetForeColor(void) +{ + color_t color; + + color = (ReadCommand(0x63) & 0x1F) << 11; + color |= (ReadCommand(0x64) & 0x3F) << 5; + color |= (ReadCommand(0x65) & 0x1F); + return color; +} + +color_t RA8875::DOSColor(int i) + { + const color_t colors[16] = + { + Black, Blue, Green, Cyan, + Red, Magenta, Brown, Gray, + Charcoal, BrightBlue, BrightGreen, BrightCyan, + Orange, Pink, Yellow, White + }; + if (i < 16) + return colors[i]; + else + return 0; + } + +const char * RA8875::DOSColorNames(int i) + { + const char * names[16] = + { + "Black", "Blue", "Green", "Cyan", + "Red", "Magenta", "Brown", "Gray", + "Charcoal", "BrightBlue", "BrightGreen", "BrightCyan", + "Orange", "Pink", "Yellow", "White" + }; + if (i < 16) + return names[i]; + else + return NULL; + } + + +/////////////////////////////////////////////////////////////// +// Private functions + +unsigned char RA8875::spiwrite(unsigned char data) +{ + unsigned char retval; + + retval = spi.write(data); + return retval; +} + +unsigned char RA8875::spiread(void) +{ + unsigned char retval; + unsigned char data = 0; + + retval = spi.write(data); + return retval; +} + +RetCode_t RA8875::select(bool chipsel) +{ + cs = (chipsel == true) ? 0 : 1; + return noerror; +} + +RetCode_t RA8875::init(void) +{ + Backlight_u8(0); + WriteCommand(0x88, 0x0a); // PLLC1 - Phase Lock Loop registers + wait_ms(1); + WriteCommand(0x89, 0x02); + wait_ms(1); + + //? + WriteCommand(0x10, 0x0C); //SYSR bit[4:3]=00 256 color bit[2:1]= 00 8bit MPU interface, 1x 64k color 1x 16bit + + //? + WriteCommand(0x04, 0x82); //PCLK + wait_ms(1); + + // Horizontal Settings + WriteCommand(0x14, RA8875_DISPLAY_WIDTH/8 - 1); //HDWR//Horizontal Display Width Setting Bit[6:0] + WriteCommand(0x15, 0x02); //HNDFCR//Horizontal Non-Display Period fine tune Bit[3:0] + WriteCommand(0x16, 0x03); //HNDR//Horizontal Non-Display Period Bit[4:0] + WriteCommand(0x17, 0x01); //HSTR//HSYNC Start Position[4:0] + WriteCommand(0x18, 0x03); //HPWR//HSYNC Polarity ,The period width of HSYNC. + + // Vertical Settings + WriteCommand(0x19, (RA8875_DISPLAY_HEIGHT-1)&0xFF); //VDHR0 //Vertical Display Height Bit [7:0] + WriteCommand(0x1a, (RA8875_DISPLAY_HEIGHT-1)>>8); //VDHR1 //Vertical Display Height Bit [8] + WriteCommand(0x1b, 0x0F); //VNDR0 //Vertical Non-Display Period Bit [7:0] + WriteCommand(0x1c, 0x00); //VNDR1 //Vertical Non-Display Period Bit [8] + WriteCommand(0x1d, 0x0e); //VSTR0 //VSYNC Start Position[7:0] + WriteCommand(0x1e, 0x06); //VSTR1 //VSYNC Start Position[8] + WriteCommand(0x1f, 0x01); //VPWR //VSYNC Polarity ,VSYNC Pulse Width[6:0] + + // Clear ram image + SetWindow(0,0, width(), height()); // Initialize to full screen + foreground(Black); + background(Black); + cls(); + return noerror; +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/RA8875.h Sun Jan 12 17:40:32 2014 +0000 @@ -0,0 +1,802 @@ +#ifndef RA8875_H +#define RA8875_H +#include <mbed.h> + +#include "GraphicsDisplay.h" + +#define RA8875_DEFAULT_SPI_FREQ 1000000 + +// Define this to enable code that monitors the performance of various +// graphics commands. +//#define PERF_METRICS + +// What better place for some test code than in here... +#define TESTENABLE + +#define RGB(r,g,b) ( ((r<<8)&0xF800) | ((g<<3)&0x07E0) | (b>>3) ) + +/// DOS colors - slightly color enhanced +#define Black RGB(0,0,0) +#define Blue RGB(0,0,187) +#define Green RGB(0,187,0) +#define Cyan RGB(0,187,187) +#define Red RGB(187,0,0) +#define Magenta RGB(187,0,187) +#define Brown RGB(187,187,0) +#define Gray RGB(187,187,187) +#define Charcoal RGB(85,85,85) +#define BrightBlue RGB(85,85,255) +#define BrightGreen RGB(85,255,85) +#define BrightCyan RGB(85,255,255) +#define Orange RGB(255,85,85) +#define Pink RGB(255,85,255) +#define Yellow RGB(255,255,85) +#define White RGB(255,255,255) + +//namespace SW_graphics +//{ + +/// color type definition to let the compiler help keep us honest. +/// +/// colors can be defined with the RGB(r,g,b) macro, and there +/// are a number of predefined colors: +/// - Black, Blue, Green, Cyan, +/// - Red, Magenta, Brown, Gray, +/// - Charcoal, BrightBlue, BrightGreen, BrightCyan, +/// - Orange, Pink, Yellow, White +/// +typedef uint16_t color_t; + +/// background fill info for drawing Text, Rectangles, RoundedRectanges, Circles, Ellipses and Triangles. +typedef enum +{ + NOFILL, ///< do not fill the object with the background color + FILL ///< fill the object space with the background color +} fill_t; + +/// return values from functions +//typedef enum +//{ +// noerror, +// bad_parameter +//} RetCode_t; + +class RA8875 : public GraphicsDisplay +{ +public: + /// font type selection. + typedef enum + { + ISO8859_1, + ISO8859_2, + ISO8859_3, + ISO8859_4 + } font_t; + + /// font rotation selection + typedef enum + { + normal, + rotated + } font_angle_t; + + /// alignment + typedef enum + { + align_none, + align_full + } alignment_t; + + /// Scale factor - 1, 2, 3 4 + typedef unsigned int HorizontalScale; + + /// Scale factor - 1, 2, 3, 4 + typedef unsigned int VerticalScale; + + /// Clear screen region + typedef enum + { + FULLWINDOW, + ACTIVEWINDOW + } Region_t; + + /// Constructor for a display based on the RAiO RA8875 + /// display controller. + /// + /// @param mosi is the SPI master out slave in pin on the mbed. + /// @param miso is the SPI master in slave out pin on the mbed. + /// @param sclk is the SPI shift clock pin on the mbed. + /// @param csel is the DigitalOut pin on the mbed to use as the + /// active low chip select for the display controller. + /// @param reset is the DigitalOut pin on the mbed to use as the + /// active low reset input on the display controller - + /// but this is not currently used. + /// @param name is a text name for this object, which will permit + /// capturing stdout and printf() directly to it. + /// + RA8875(PinName mosi, PinName miso, PinName sclk, PinName csel, PinName reset, const char * name = "lcd"); + + /// Destructor doesn't have much to do. + //~RA8875(); + + /// Write a command to the display + /// + /// This is a high level command, and may invoke several primitives. + /// + /// @param command is the command to write. + /// @data is optional data to be written to the command register + /// and only occurs if the data is in the range [0 - 0xFF]. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t WriteCommand(unsigned char command, unsigned int data = 0xFFFF); + + /// Write a data byte to the display + /// + /// This is a high level command, and may invoke several primitives. + /// + /// @param data is the data to write. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t WriteData(unsigned char data); + + /// Read a command register + /// + /// @param command is the command register to read. + /// @returns the value read from the register. + /// + unsigned char ReadCommand(unsigned char command); + + /// Read a data byte to the display + /// + /// This is a high level command, and may invoke several primitives. + /// + /// @returns data that was read. + /// + unsigned char ReadData(void); + + /// Read the display status + /// + /// This is a high level command, and may invoke several primitives. + /// + /// @returns data that was read. + /// + unsigned char ReadStatus(void); + + /// get the width in pixels of the currently active font + /// + /// @returns font width in pixels. + /// + unsigned int fontwidth(void); + + /// get the height in pixels of the currently active font + /// + /// @returns font height in pixels. + /// + unsigned int fontheight(void); + + /// get the number of colums based on the currently active font + /// + /// @returns number of columns. + /// + virtual int columns(void); + + /// get the number of rows based on the currently active font + /// + /// @returns number of rows. + /// + virtual int rows(void); + + /// get the screen width in pixels + /// + /// @returns screen width in pixels. + /// + virtual int width(void); + + /// get the screen height in pixels + /// + /// @returns screen height in pixels. + /// + virtual int height(void); + + /// Set cursor position based on the current font size. + /// + /// @param x is the horizontal position in character positions + /// @param y is the vertical position in character positions + /// @returns success/failure code. @see RetCode_t. + /// + virtual RetCode_t locate(unsigned int x, unsigned int y); + + /// Prepare the controller to write text to the screen by positioning + /// the cursor. + /// + /// @param x is the horizontal position in pixels (from the left edge) + /// @param y is the vertical position in pixels (from the top edge) + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t SetTextCursor(unsigned int x, unsigned int y); + + /// Select the ISO 8859-X font to use next. + /// + /// Supported fonts: ISO 8859-1, -2, -3, -4 + /// + /// @param font selects the font for the subsequent text rendering. + /// + /// @note if either hScale or vScale is outside of its permitted range, + /// the command is not executed. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t SetTextFont(font_t font = ISO8859_1); + + /// Control the font behavior. + /// + /// This command lets you make several modifications to any text that + /// is written. + /// + /// Options can be combined: + /// Default: + /// @li Full alignment disabled, + /// @li Font with Background color, + /// @li Font in normal orientiation, + /// @li Horizontal scale x 1 + /// @li Vertical scale x 1 + /// @li alignment + /// + /// @param fillit defaults to FILL, but can be NOFILL + /// @param angle defaults to normal, but can be rotated + /// @param hScale defaults to 1, but can be 1, 2, 3, or 4, + /// and scales the font size by this amount. + /// @param vScale defaults to 1, but can be 1, 2, 3, or 4, + /// and scales the font size by this amount. + /// @param alignment defaults to align_none, but can be + /// align_full. + /// + /// @note if either hScale or vScale is outside of its permitted range, + /// the command is not executed. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t SetTextFontControl(fill_t fillit = FILL, + font_angle_t angle = normal, + HorizontalScale hScale = 1, + VerticalScale vScale = 1, + alignment_t alignment = align_none); + + /// Control the font size + /// + /// This command lets you set the font enlargement for both horizontal + /// and vertical, independent of the rotation, background, and + /// alignment. @see SetTextFontControl. + /// + /// @param hScale defaults to 1, but can be 1, 2, 3, or 4, + /// and scales the font size by this amount. + /// @param vScale defaults to 1, but can be 1, 2, 3, or 4, + /// and scales the font size by this amount. + /// + /// @note if either hScale or vScale is outside of its permitted range, + /// the command is not executed. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t SetTextFontSize(HorizontalScale hScale = 1, VerticalScale vScale = 1); + + /// put a character on the screen. + /// + /// @param c is the character. + /// @returns the character, or EOF if there is an error. + /// + virtual int _putc(int c); + + /// Write string of text to the display + /// + /// @param string is the null terminated string to send to the display. + /// + void puts(const char * string); + + /// Write string of text to the display at the specified location. + /// + /// @param x is the horizontal position in pixels (from the left edge) + /// @param y is the vertical position in pixels (from the top edge) + /// @param string is the null terminated string to send to the display. + /// + void puts(unsigned int x, unsigned int y, const char * string); + + /// Prepare the controller to write binary data to the screen by positioning + /// the memory cursor. + /// + /// @param x is the horizontal position in pixels (from the left edge) + /// @param y is the vertical position in pixels (from the top edge) + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t SetMemoryCursor(unsigned int x, unsigned int y); + + /// Set the window, which controls where items are written to the screen. + /// + /// When something hits the window width, it wraps back to the left side + /// and down a row. If the initial write is outside the window, it will + /// be captured into the window when it crosses a boundary. + /// + /// @param x is the left edge in pixels. + /// @param y is the top edge in pixels. + /// @param width is the window width in pixels. + /// @param height is the window height in pixels. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t SetWindow(unsigned int x, unsigned int y, unsigned int width, unsigned int height); + + /// Clear the screen. + /// + /// The behavior is to clear the whole screen. @see clsw(). + /// + /// @returns success/failure code. @see RetCode_t. + /// + virtual RetCode_t cls(void); + + /// Clear the screen, or clear only the active window. + /// + /// The default behavior is to clear the whole screen. With the optional + /// parameter, the action can be restricted to the active window, which + /// can be set with the @see SetWindow method. + /// + /// @param region is an optional parameter that defaults to FULLWINDOW + /// or may be set to ACTIVEWINDOW. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t clsw(RA8875::Region_t region = FULLWINDOW); + + /// Set the background color. + /// + /// @param color is expressed in 16-bit format. + /// @returns success/failure code. @see RetCode_t. + /// + virtual RetCode_t background(color_t color); + + /// Set the background color. + /// + /// @param r is the red element of the color. + /// @param g is the green element of the color. + /// @param b is the blue element of the color. + /// @returns success/failure code. @see RetCode_t. + /// + virtual RetCode_t background(unsigned char r, unsigned char g, unsigned char b); + + /// Set the foreground color. + /// + /// @param color is expressed in 16-bit format. + /// @returns success/failure code. @see RetCode_t. + /// + virtual RetCode_t foreground(color_t color); + + /// Set the foreground color. + /// + /// @param R is the red element of the color. + /// @param G is the green element of the color. + /// @param B is the blue element of the color. + /// @returns success/failure code. @see RetCode_t. + /// + virtual RetCode_t foreground(unsigned char R, unsigned char G, unsigned char B); + + /// Get the current foreground color value. + /// + /// @returns the current foreground color. + /// + unsigned int GetForeColor(void); + + /// Draw a pixel in the specified color. + /// + /// @note As a side effect, this also sets the foreground color + /// affecting all subsequent operations. + /// + /// @param x is the horizontal offset to this pixel. + /// @param y is the vertical offset to this pixel. + /// @param color defines the color for the pixel. + /// @returns success/failure code. @see RetCode_t. + /// + virtual RetCode_t pixel(unsigned int x, unsigned int y, color_t color); + + /// Draw a pixel in the current foreground color. + /// + /// @param x is the horizontal offset to this pixel. + /// @param y is the veritical offset to this pixel. + /// @returns success/failure code. @see RetCode_t. + /// + virtual RetCode_t pixel(unsigned int x, unsigned int y); + + /// Draw a line in the specified color + /// + /// @note As a side effect, this changes the current + /// foreground color for subsequent operations. + /// + /// @param x1 is the horizontal start of the line. + /// @param y1 is the vertical start of the line. + /// @param x2 is the horizontal end of the line. + /// @param y2 is the vertical end of the line. + /// @param color defines the foreground color. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + color_t color); + + /// Draw a line + /// + /// Draws a line using the foreground color setting. + /// + /// @param x1 is the horizontal start of the line. + /// @param y1 is the vertical start of the line. + /// @param x2 is the horizontal end of the line. + /// @param y2 is the vertical end of the line. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t line(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2); + + /// Draw a rectangle in the specified color + /// + /// @note As a side effect, this changes the current + /// foreground color for subsequent operations. + /// + /// @param x1 is the horizontal start of the line. + /// @param y1 is the vertical start of the line. + /// @param x2 is the horizontal end of the line. + /// @param y2 is the vertical end of the line. + /// @param color defines the foreground color. + /// @param fillit is optional to FILL the rectangle. default is NOFILL. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t rect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + color_t color, fill_t fillit = NOFILL); + + /// Draw a filled rectangle in the specified color + /// + /// @note As a side effect, this changes the current + /// foreground color for subsequent operations. + /// + /// @param x1 is the horizontal start of the line. + /// @param y1 is the vertical start of the line. + /// @param x2 is the horizontal end of the line. + /// @param y2 is the vertical end of the line. + /// @param color defines the foreground color. + /// @param fillit is optional to NOFILL the rectangle. default is FILL. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t fillrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + color_t color, fill_t fillit = FILL); + + /// Draw a rectangle + /// + /// Draws a rectangle using the foreground color setting. + /// + /// @param x1 is the horizontal start of the line. + /// @param y1 is the vertical start of the line. + /// @param x2 is the horizontal end of the line. + /// @param y2 is the vertical end of the line. + /// @param fillit is optional to FILL the rectangle. default is NOFILL. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t rect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + fill_t fillit = NOFILL); + + /// Draw a filled rectangle with rounded corners using the specified color. + /// + /// @note As a side effect, this changes the current + /// foreground color for subsequent operations. + /// + /// @param x1 is the horizontal start of the line. + /// @param y1 is the vertical start of the line. + /// @param x2 is the horizontal end of the line. + /// @param y2 is the vertical end of the line. + /// @param radius1 defines the horizontal width of the curved corner. + /// @param radius2 defines the vertical width of the curved corner. + /// @param color defines the foreground color. + /// @param fillit is optional to FILL the rectangle. default is NOFILL. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t fillroundrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + unsigned int radius1, unsigned int radius2, color_t color, fill_t fillit = FILL); + + /// Draw a rectangle with rounded corners using the specified color. + /// + /// @note As a side effect, this changes the current + /// foreground color for subsequent operations. + /// + /// @param x1 is the horizontal start of the line. + /// @param y1 is the vertical start of the line. + /// @param x2 is the horizontal end of the line. + /// @param y2 is the vertical end of the line. + /// @param radius1 defines the horizontal width of the curved corner. + /// @param radius2 defines the vertical width of the curved corner. + /// @param color defines the foreground color. + /// @param fillit is optional to FILL the rectangle. default is NOFILL. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t roundrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + unsigned int radius1, unsigned int radius2, color_t color, fill_t fillit = NOFILL); + + /// Draw a rectangle with rounded corners. + /// + /// Draws a rectangle with rounded corners using the foreground color setting. + /// + /// @param x1 is the horizontal start of the line. + /// @param y1 is the vertical start of the line. + /// @param x2 is the horizontal end of the line. + /// @param y2 is the vertical end of the line. + /// @param radius1 defines the horizontal width of the curved corner. + /// @param radius2 defines the vertical width of the curved corner. + /// @param fillit is optional to FILL the rectangle. default is NOFILL. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t roundrect(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + unsigned int radius1, unsigned int radius2, fill_t fillit = NOFILL); + + /// Draw a triangle in the specified color. + /// + /// @note As a side effect, this changes the current + /// foreground color for subsequent operations. + /// + /// @param x1 is the horizontal for point 1. + /// @param y1 is the vertical for point 1. + /// @param x2 is the horizontal for point 2. + /// @param y2 is the vertical for point 2. + /// @param x3 is the horizontal for point 3. + /// @param y3 is the vertical for point 3. + /// @param color defines the foreground color. + /// @param fillit is optional to FILL the rectangle. default is NOFILL. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t triangle(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + unsigned int x3, unsigned int y3, color_t color, fill_t fillit = NOFILL); + + /// Draw a filled triangle in the specified color. + /// + /// @note As a side effect, this changes the current + /// foreground color for subsequent operations. + /// + /// @param x1 is the horizontal for point 1. + /// @param y1 is the vertical for point 1. + /// @param x2 is the horizontal for point 2. + /// @param y2 is the vertical for point 2. + /// @param x3 is the horizontal for point 3. + /// @param y3 is the vertical for point 3. + /// @param color defines the foreground color. + /// @param fillit is optional to FILL the rectangle. default is NOFILL. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t filltriangle(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + unsigned int x3, unsigned int y3, color_t color, fill_t fillit = FILL); + + /// Draw a triangle + /// + /// Draws a triangle using the foreground color setting. + /// + /// @param x1 is the horizontal for point 1. + /// @param y1 is the vertical for point 1. + /// @param x2 is the horizontal for point 2. + /// @param y2 is the vertical for point 2. + /// @param x3 is the horizontal for point 3. + /// @param y3 is the vertical for point 3. + /// @param fillit is optional to FILL the rectangle. default is NOFILL. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t triangle(unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2, + unsigned int x3, unsigned int y3, fill_t fillit = NOFILL); + + /// Draw a circle using the specified color. + /// + /// @note As a side effect, this changes the current + /// foreground color for subsequent operations. + /// + /// @param x is the horizontal center of the circle. + /// @param y is the vertical center of the circle. + /// @param radius defines the size of the circle. + /// @param color defines the foreground color. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t circle(unsigned int x, unsigned int y, unsigned int radius, color_t color, fill_t fillit = NOFILL); + + /// Draw a filled circle using the specified color. + /// + /// @note As a side effect, this changes the current + /// foreground color for subsequent operations. + /// + /// @param x is the horizontal center of the circle. + /// @param y is the vertical center of the circle. + /// @param radius defines the size of the circle. + /// @param color defines the foreground color. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t fillcircle(unsigned int x, unsigned int y, unsigned int radius, color_t color, fill_t fillit = FILL); + + /// Draw a circle. + /// + /// Draws a circle using the foreground color setting. + /// + /// @param x is the horizontal center of the circle. + /// @param y is the vertical center of the circle. + /// @param radius defines the size of the circle. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t circle(unsigned int x, unsigned int y, unsigned int radius, fill_t fillit = NOFILL); + + /// Draw an Ellipse using the specified color + /// + /// @note As a side effect, this changes the current + /// foreground color for subsequent operations. + /// + /// @param x is the horizontal center of the ellipse. + /// @param y is the vertical center of the ellipse. + /// @param radius1 defines the horizontal width of the ellipse. + /// @param radius2 defines the vertical width of the ellipse. + /// @param color defines the foreground color. + /// @param fillit defines whether the circle is filled or not. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t ellipse(unsigned int x, unsigned int y, unsigned int radius1, unsigned int radius1, + color_t color, fill_t fillit = NOFILL); + + /// Draw an Ellipse + /// + /// Draws it using the foreground color setting. + /// + /// @param x is the horizontal center of the ellipse. + /// @param y is the vertical center of the ellipse. + /// @param radius1 defines the horizontal width of the ellipse. + /// @param radius2 defines the vertical width of the ellipse. + /// @param fillit defines whether the circle is filled or not. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t ellipse(unsigned int x, unsigned int y, unsigned int radius1, unsigned int radius1, fill_t fillit = NOFILL); + + /// Control display power + /// + /// @param on when set to true will turn on the display, when false it is turned off. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t Power(bool on); + + /// Reset the display controller via the Software Reset interface. + /// + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t Reset(void); + + /// Set backlight brightness. + /// + /// When the built-in PWM is used to control the backlight, this + /// API can be used to set the brightness. + /// + /// @param brightness ranges from 0 (off) to 255 (full on) + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t Backlight_u8(unsigned char brightness); + + /// Set backlight brightness. + /// + /// When the built-in PWM is used to control the backlight, this + /// API can be used to set the brightness. + /// + /// @param brightness ranges from 0.0 (off) to 1.0 (full on) + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t Backlight(float brightness); + + /// Set a reference to a bitmap font, provided by the user. + /// + /// @note Tool to create the fonts is accessible from its creator + /// available at http://www.mikroe.com. + /// Change the data to an array of type char[]. + /// + /// @param font is a pointer to a specially formed font array. + /// This special font array has a 4-byte header, followed by + /// the data: + /// - the number of bytes per char + /// - the vertical size in pixels for each character + /// - the horizontal size in pixels for each character + /// - the number of bytes per vertical line (width of the array) + /// @returns error code. + /// + RetCode_t set_font(const unsigned char * font); + + /// Get the RGB value for a DOS color. + /// + /// @param i is the color, in the range 0 to 15; + /// @returns the RGB color of the selected index, or 0 + /// if the index is out of bounds. + /// + color_t DOSColor(int i); + + /// Get the color name (string) for a DOS color. + /// + /// @param i is the color, in the range 0 to 15; + /// @returns a pointer to a string with the color name, + /// or NULL if the index is out of bounds. + /// + const char * DOSColorNames(int i); + + +#ifdef PERF_METRICS + /// Clear the performance metrics to zero. + void ClearPerformance(); + + /// Report the performance metrics for drawing functions using + /// printf() + void ReportPerformance(); +#endif + +private: + /// Set the SPI port frequency (in Hz). + /// + /// @note attempts to call this API at runtime, with the display + /// already online, cause the system to lockup. + /// Not sure why, so moving this to private to run once. + /// + /// This uses the mbed SPI driver, and is therefore dependent on + /// its capabilities. Limited tests were performed for the display + /// in the range of 1,000,000 to 50,000,000 Hz. The display was + /// a bit erratic above 20,000,000 Hz, so this became the default, + /// even though it might have been the bench-level wiring that posed + /// the limit. + /// + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t frequency(unsigned long Hz = RA8875_DEFAULT_SPI_FREQ); + + + /// Initialize the chip, which is normally done as part of the + /// constructor, so not called by the user. + /// + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t init(void); + + /// Select the peripheral to use it. + /// + /// @param chipsel when true will select the peripheral, and when false + /// will deselect the chip. This is the logical selection, and + /// the pin selection is the invert of this. + /// @returns success/failure code. @see RetCode_t. + /// + RetCode_t select(bool chipsel); + + /// The most primitive - to write a data value to the SPI interface. + /// + /// @param data is the value to write. + /// @returns a value read from the port, since SPI is often shift + /// in while shifting out. + /// + unsigned char spiwrite(unsigned char data); + + /// The most primitive - to read a data value to the SPI interface. + /// + /// This is really just a specialcase of the write command, where + /// the value zero is written in order to read. + /// + /// @returns a value read from the port, since SPI is often shift + /// in while shifting out. + /// + unsigned char spiread(); + + SPI spi; ///< spi port + DigitalOut cs; ///< chip select pin, assumed active low + DigitalOut res; ///< reset pin, assumed active low + const unsigned char * font; ///< reference to an external font somewhere in memory + + #ifdef PERF_METRICS + typedef enum + { + PRF_CLS, + PRF_DRAWPOINT, + PRF_DRAWLINE, + PRF_DRAWRECTANGLE, + PRF_DRAWROUNDEDRECTANGLE, + PRF_DRAWTRIANGLE, + PRF_DRAWCIRCLE, + PRF_DRAWELLIPSE, + METRICCOUNT + } method_e; + unsigned long metrics[METRICCOUNT]; + void RegisterPerformance(method_e method); + Timer performance; + #endif +}; + +//} // namespace + +//using namespace SW_graphics; + +#endif \ No newline at end of file
--- a/SPI_TFT.cpp Tue Oct 22 20:17:29 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1264 +0,0 @@ -/* mbed library for 240*320 pixel display TFT based on HX8347D LCD Controller - * Copyright (c) 2011 Peter Drescher - DC2PD - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - - -// fix bmp padding for Bitmap function -// speed up pixel -// 30.12.11 fix cls -// 11.03.12 use DMA to speed up -// 15.03.12 use SSEL for TFT CS to enable DMA Register writes -// 06.04.12 fix SSEL CS problem -// 06.04.12 use direct access to the spi register to speed up the library. -// 11.09.12 switch back to using io pin as cs to avoid problems with SSEL CS. -// 21.09.12 fix Bug in BMP_16 -// 11.10.12 patch from Hans Bergles to get SPI1 working again -// 03.02.13 add a switch to switch off DMA use for LPC11U24 -// 04.03.13 add support for new Kinetis board -// 25.03.13 fix Bug in bitmap for Kinetis board -// 18.10.13 Better Circle function from Michael Ammann - -#include "SPI_TFT.h" -#include "mbed.h" - -#define BPP 16 // Bits per pixel - -#if defined TARGET_LPC1768 -#define USE_DMA // we use dma to speed up -#define NO_MBED_LIB // we write direct to the SPI register to speed up -#endif - -#if defined NO_DMA // if LPC1768 user want no DMA -#undef USE_DMA -#endif - - -//extern Serial pc; -//extern DigitalOut xx; // debug !! - -SPI_TFT::SPI_TFT(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset, const char *name) - : _spi(mosi, miso, sclk), _cs(cs), _reset(reset),GraphicsDisplay(name) -{ - orientation = 0; - char_x = 0; - #if defined TARGET_LPC1768 - if (mosi == p11 || mosi == P0_18){ - spi_port = 0; // we must know the used SPI port to setup the DMA - } - else { - spi_port = 1; - } - #endif - tft_reset(); -} - -int SPI_TFT::width() -{ - if (orientation == 0 || orientation == 2) return 240; - else return 320; -} - - -int SPI_TFT::height() -{ - if (orientation == 0 || orientation == 2) return 320; - else return 240; -} - - -void SPI_TFT::set_orientation(unsigned int o) -{ - orientation = o; - switch (orientation) { - case 0: - wr_reg(0x16, 0x08); - break; - case 1: - wr_reg(0x16, 0x68); - break; - case 2: - wr_reg(0x16, 0xC8); - break; - case 3: - wr_reg(0x16, 0xA8); - break; - } - WindowMax(); -} - - -// write command to tft register - -void SPI_TFT::wr_cmd(unsigned char cmd) -{ - _cs = 0; - #if defined NO_MBED_LIB - unsigned short spi_d; - spi_d = 0x7000 | cmd ; - if (spi_port == 0) { // TFT on SSP0 - LPC_SSP0->DR = spi_d; - // we have to wait for SPI IDLE to set CS back to high - do { - } while ((LPC_SSP0->SR & 0x10) == 0x10); // SPI0 not idle - } else { - LPC_SSP1->DR = spi_d; - do { - } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle - } - #else // use mbed lib - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(0x70); - _spi.write(cmd); - #else // 16 Bit SPI - unsigned short spi_d; - spi_d = 0x7000 | cmd ; - _spi.write(spi_d); // mbed lib - #endif - #endif - _cs = 1; -} - - -// write data to tft register -void SPI_TFT::wr_dat(unsigned char dat) -{ - _cs = 0; - #if defined NO_MBED_LIB - unsigned short spi_d; - spi_d = 0x7200 | dat; - if (spi_port == 0) { // TFT on SSP0 - LPC_SSP0->DR = spi_d; - // we have to wait for SPI IDLE to set CS back to high - do { - } while ((LPC_SSP0->SR & 0x10) == 0x10); // SPI0 not idle - } else { - LPC_SSP1->DR = spi_d; - do { - } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle - } - #else // use mbed lib - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(0x72); - _spi.write(dat); - #else // 16 Bit SPI - unsigned short spi_d; - spi_d = 0x7200 | dat; - _spi.write(spi_d); - #endif - #endif - _cs = 1; -} - - - -// the HX8347-D controller do not use the MISO (SDO) Signal. -// This is a bug - ? -// A read will return 0 at the moment - -unsigned short SPI_TFT::rd_dat (void) -{ - unsigned short val = 0; - - //val = _spi.write(0x73ff); /* Dummy read 1 */ - //val = _spi.write(0x0000); /* Read D8..D15 */ - return (val); -} - -// write to a TFT register -void SPI_TFT::wr_reg (unsigned char reg, unsigned char val) -{ - wr_cmd(reg); - wr_dat(val); -} - -// read from a TFT register -unsigned short SPI_TFT::rd_reg (unsigned char reg) -{ - wr_cmd(reg); - return(rd_dat()); -} - -// setup TFT controller - this is called by constructor -void SPI_TFT::tft_reset() -{ -#if defined TARGET_KL25Z // 8 Bit SPI - _spi.format(8,3); -#else // 16 Bit SPI - _spi.format(16,3); // 16 bit spi mode 3 -#endif - _spi.frequency(48000000); // 48 Mhz SPI clock - _cs = 1; // cs high - _reset = 0; // display reset - - wait_us(50); - _reset = 1; // end reset - wait_ms(5); - - /* Start Initial Sequence ----------------------------------------------------*/ - wr_reg(0xEA, 0x00); /* Reset Power Control 1 */ - wr_reg(0xEB, 0x20); /* Power Control 2 */ - wr_reg(0xEC, 0x0C); /* Power Control 3 */ - wr_reg(0xED, 0xC4); /* Power Control 4 */ - wr_reg(0xE8, 0x40); /* Source OPON_N */ - wr_reg(0xE9, 0x38); /* Source OPON_I */ - wr_reg(0xF1, 0x01); /* */ - wr_reg(0xF2, 0x10); /* */ - wr_reg(0x27, 0xA3); /* Display Control 2 */ - - /* Power On sequence ---------------------------------------------------------*/ - wr_reg(0x1B, 0x1B); /* Power Control 2 */ - wr_reg(0x1A, 0x01); /* Power Control 1 */ - wr_reg(0x24, 0x2F); /* Vcom Control 2 */ - wr_reg(0x25, 0x57); /* Vcom Control 3 */ - wr_reg(0x23, 0x8D); /* Vcom Control 1 */ - - /* Gamma settings -----------------------------------------------------------*/ - wr_reg(0x40,0x00); // default setup - wr_reg(0x41,0x00); // - wr_reg(0x42,0x01); // - wr_reg(0x43,0x13); // - wr_reg(0x44,0x10); // - wr_reg(0x45,0x26); // - wr_reg(0x46,0x08); // - wr_reg(0x47,0x51); // - wr_reg(0x48,0x02); // - wr_reg(0x49,0x12); // - wr_reg(0x4A,0x18); // - wr_reg(0x4B,0x19); // - wr_reg(0x4C,0x14); // - wr_reg(0x50,0x19); // - wr_reg(0x51,0x2F); // - wr_reg(0x52,0x2C); // - wr_reg(0x53,0x3E); // - wr_reg(0x54,0x3F); // - wr_reg(0x55,0x3F); // - wr_reg(0x56,0x2E); // - wr_reg(0x57,0x77); // - wr_reg(0x58,0x0B); // - wr_reg(0x59,0x06); // - wr_reg(0x5A,0x07); // - wr_reg(0x5B,0x0D); // - wr_reg(0x5C,0x1D); // - wr_reg(0x5D,0xCC); // - - /* Power + Osc ---------------------------------------------------------------*/ - wr_reg(0x18, 0x36); /* OSC Control 1 */ - wr_reg(0x19, 0x01); /* OSC Control 2 */ - wr_reg(0x01, 0x00); /* Display Mode Control */ - wr_reg(0x1F, 0x88); /* Power Control 6 */ - wait_ms(5); /* Delay 5 ms */ - wr_reg(0x1F, 0x80); /* Power Control 6 */ - wait_ms(5); /* Delay 5 ms */ - wr_reg(0x1F, 0x90); /* Power Control 6 */ - wait_ms(5); /* Delay 5 ms */ - wr_reg(0x1F, 0xD0); /* Power Control 6 */ - wait_ms(5); /* Delay 5 ms */ - - wr_reg(0x17, 0x05); /* Colmod 16Bit/Pixel */ - - wr_reg(0x36, 0x00); /* Panel Characteristic */ - wr_reg(0x28, 0x38); /* Display Control 3 */ - wait_ms(40); - wr_reg(0x28, 0x3C); /* Display Control 3 */ - switch (orientation) { - case 0: - wr_reg(0x16, 0x08); - break; - case 2: - wr_reg(0x16, 0xC8); - break; - case 3: - wr_reg(0x16, 0xA8); - break; - case 1: - default: - wr_reg(0x16, 0x68); - break; - - } -#if defined USE_DMA // setup DMA channel 0 - LPC_SC->PCONP |= (1UL << 29); // Power up the GPDMA. - LPC_GPDMA->DMACConfig = 1; // enable DMA controller - LPC_GPDMA->DMACIntTCClear = 0x1; // Reset the Interrupt status - LPC_GPDMA->DMACIntErrClr = 0x1; - LPC_GPDMACH0->DMACCLLI = 0; -#endif - WindowMax (); -} - -// Set one pixel -void SPI_TFT::pixel(int x, int y, int color) -{ - wr_reg(0x03, (x >> 0)); - wr_reg(0x02, (x >> 8)); - wr_reg(0x07, (y >> 0)); - wr_reg(0x06, (y >> 8)); - wr_cmd(0x22); - _cs = 0; - #if defined NO_MBED_LIB - if (spi_port == 0) { // TFT on SSP0 - LPC_SSP0->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP0->DR = 0x72; // start Data - LPC_SSP0->CR0 |= 0x08UL; // set back to 16 bit - LPC_SSP0->DR = color; // Pixel - // we have to wait for SPI IDLE to set CS back to high - do { - } while ((LPC_SSP0->SR & 0x10) == 0x10); // SPI0 not idle - } else { // TFT on SSP1 - LPC_SSP1->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP1->DR = 0x72; // start Data - LPC_SSP1->CR0 |= 0x08UL; // set back to 16 bit - LPC_SSP1->DR = color; - // we have to wait for SPI IDLE to set CS back to high - do { - } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle - } - #else // use mbed lib - - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - _spi.write(color >> 8); - _spi.write(color & 0xff); - #else - _spi.format(8,3); // 8 bit Mode 3 - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - _spi.format(16,3); // switch to 16 bit Mode 3 - _spi.write(color); // Write D0..D15 - #endif - #endif - _cs = 1; -} - -// define draw area -void SPI_TFT::window (unsigned int x, unsigned int y, unsigned int w, unsigned int h) -{ - wr_reg(0x03, x ); - wr_reg(0x02, (x >> 8)); - wr_reg(0x05, x+w-1 ); - wr_reg(0x04, (x+w-1 >> 8)); - wr_reg(0x07, y ); - wr_reg(0x06, ( y >> 8)); - wr_reg(0x09, ( y+h-1 )); - wr_reg(0x08, ( y+h-1 >> 8)); -} - -// set draw area to max -void SPI_TFT::WindowMax (void) -{ - window (0, 0, width(), height()); -} - - -// clear screen -void SPI_TFT::cls (void) -{ - fprintf(stderr, "CLS \n\r"); - int pixel = ( width() * height()); - #if defined USE_DMA - int dma_count; - int color = _background; - #endif - WindowMax(); - wr_cmd(0x22); - - #if defined NO_MBED_LIB - #if defined USE_DMA - LPC_GPDMACH0->DMACCSrcAddr = (uint32_t)&color; - #endif - _cs = 0; - if (spi_port == 0) { // TFT on SSP0 - #if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP0->DR; // we send to SSP0 - /* Enable SSP0 for DMA. */ - LPC_SSP0->DMACR = 0x2; - #endif - LPC_SSP0->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP0->DR = 0x72; // start byte - LPC_SSP0->CR0 |= 0x08UL; // set to 16 bit - } else { // TFT on SSP1 - #if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP1->DR; // we send to SSP1 - /* Enable SSP1 for DMA. */ - LPC_SSP1->DMACR = 0x2; - #endif - LPC_SSP1->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP1->DR = 0x72; // start Data - LPC_SSP1->CR0 |= 0x08UL; // set to 16 bit - } - - #if defined USE_DMA - // start DMA - do { - if (pixel > 4095) { - dma_count = 4095; - pixel = pixel - 4095; - } else { - dma_count = pixel; - pixel = 0; - } - LPC_GPDMA->DMACIntTCClear = 0x1; - LPC_GPDMA->DMACIntErrClr = 0x1; - LPC_GPDMACH0->DMACCControl = dma_count | (1UL << 18) | (1UL << 21) | (1UL << 31) ; // 16 bit transfer , no address increment, interrupt - LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | (spi_port ? DMA_DEST_SSP1_TX : DMA_DEST_SSP0_TX); - LPC_GPDMA->DMACSoftSReq = 0x1; // DMA request - do { - } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running - } while (pixel > 0); - if (spi_port == 0) { // TFT on SSP0 - do { - } while ((0x0010 & LPC_SSP0->SR) == 0x10); // SPI FIFO not empty - /* disable SSP0 for DMA. */ - LPC_SSP0->DMACR = 0x0; - } else { // TFT on SSP1 - do { - } while ((0x0010 & LPC_SSP1->SR) == 0x10); // SPI FIFO not empty - /* disable SSP1 for DMA. */ - LPC_SSP1->DMACR = 0x0; - } - - #else // no DMA - unsigned int i; - for (i = 0; i < ( width() * height()); i++) - _spi.write(_background); - #endif - - #else // use mbed lib - _cs = 0; - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - unsigned int i; - for (i = 0; i < ( width() * height()); i++) { - _spi.write(_background >> 8); - _spi.write(_background & 0xff); - } - #else // 16 bit SPI - _spi.format(8,3); // 8 bit Mode 3 - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - _spi.format(16,3); // switch back to 16 bit Mode 3 - unsigned int i; - for (i = 0; i < ( width() * height()); i++) - _spi.write(_background); - #endif - #endif - _cs = 1; -} - -void SPI_TFT::circle(int x0, int y0, int r, int color) -{ - int x = -r, y = 0, err = 2-2*r, e2; - do { - pixel(x0-x, y0+y,color); - pixel(x0+x, y0+y,color); - pixel(x0+x, y0-y,color); - pixel(x0-x, y0-y,color); - e2 = err; - if (e2 <= y) { - err += ++y*2+1; - if (-x == y && e2 <= x) e2 = 0; - } - if (e2 > x) err += ++x*2+1; - } while (x <= 0); - -} - -void SPI_TFT::fillcircle(int x0, int y0, int r, int color) -{ - int x = -r, y = 0, err = 2-2*r, e2; - do { - vline(x0-x, y0-y, y0+y, color); - vline(x0+x, y0-y, y0+y, color); - e2 = err; - if (e2 <= y) { - err += ++y*2+1; - if (-x == y && e2 <= x) e2 = 0; - } - if (e2 > x) err += ++x*2+1; - } while (x <= 0); -} - - -// draw horizontal line -void SPI_TFT::hline(int x0, int x1, int y, int color) -{ - int w; - w = x1 - x0 + 1; - window(x0,y,w,1); - wr_cmd(0x22); - _cs = 0; - #if defined NO_MBED_LIB - if (spi_port == 0) { // TFT on SSP0 - #if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP0->DR; // we send to SSP0 - /* Enable SSP0 for DMA. */ - LPC_SSP0->DMACR = 0x2; - #endif - LPC_SSP0->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP0->DR = 0x72; // start Data - LPC_SSP0->CR0 |= 0x08UL; // set to 16 bit - } else { // TFT on SSP1 - #if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP1->DR; // we send to SSP1 - /* Enable SSP1 for DMA. */ - LPC_SSP1->DMACR = 0x2; - #endif - LPC_SSP1->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP1->DR = 0x72; // start Data - LPC_SSP1->CR0 |= 0x08UL; // set to 16 bit - } - #if defined USE_DMA - LPC_GPDMA->DMACIntTCClear = 0x1; - LPC_GPDMA->DMACIntErrClr = 0x1; - LPC_GPDMACH0->DMACCSrcAddr = (uint32_t)&color; - LPC_GPDMACH0->DMACCControl = w | (1UL << 18) | (1UL << 21) | (1UL << 31) ; // 16 bit transfer , no address increment, interrupt - LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | (spi_port ? DMA_DEST_SSP1_TX : DMA_DEST_SSP0_TX); - LPC_GPDMA->DMACSoftSReq = 0x1; // start DMA - do { - } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running - if (spi_port == 0) { // TFT on SSP0 - do { - } while ((LPC_SSP0->SR & 0x10) == 0x10); // SPI FIFO not empty - } else { // TFT on SSP1 - do { - } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI FIFO not empty - } - #else // no DMA - int i; - for (i=0; i<w; i++) { - _spi.write(color); - } - #endif - #else // use mbed lib - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - for (int j=0; j<w; j++) { - _spi.write(color >> 8); - _spi.write(color & 0xff); - } - #else // 16 Bit SPI - _spi.format(8,3); // 8 bit Mode 3 - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - _spi.format(16,3); // switch back to 16 bit Mode 3 - for (int j=0; j<w; j++) { - _spi.write(color); - } - #endif - #endif - _cs = 1; - WindowMax(); - return; -} - -// draw vertical line -void SPI_TFT::vline(int x, int y0, int y1, int color) -{ - int h; - h = y1 - y0 + 1; - window(x,y0,1,h); - wr_cmd(0x22); - _cs = 0; - #if defined NO_MBED_LIB - if (spi_port == 0) { // TFT on SSP0 - #if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP0->DR; // we send to SSP0 - /* Enable SSP0 for DMA. */ - LPC_SSP0->DMACR = 0x2; - #endif - LPC_SSP0->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP0->DR = 0x72; // start Data - LPC_SSP0->CR0 |= 0x08UL; // set to 16 bit - } else { // TFT on SSP1 - #if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP1->DR; // we send to SSP1 - /* Enable SSP1 for DMA. */ - LPC_SSP1->DMACR = 0x2; - #endif - LPC_SSP1->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP1->DR = 0x72; // start Data - LPC_SSP1->CR0 |= 0x08UL; // set to 16 bit - } - #if defined USE_DMA - LPC_GPDMA->DMACIntTCClear = 0x1; - LPC_GPDMA->DMACIntErrClr = 0x1; - LPC_GPDMACH0->DMACCSrcAddr = (uint32_t)&color; - LPC_GPDMACH0->DMACCControl = h | (1UL << 18) | (1UL << 21) | (1UL << 31) ; // 16 bit transfer , no address increment, interrupt - LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | (spi_port ? DMA_DEST_SSP1_TX : DMA_DEST_SSP0_TX); - LPC_GPDMA->DMACSoftSReq = 0x1; - do { - } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running - - if (spi_port == 0) { // TFT on SSP0 - do { - } while ((LPC_SSP0->SR & 0x10) == 0x10); // SPI FIFO not empty - } else { // TFT on SSP1 - do { - } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI FIFO not empty - } - #else // no DMA - for (int y=0; y<h; y++) { - _spi.write(color); - } - #endif - #else // use mbed lib - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - for (int y=0; y<h; y++) { - _spi.write(color >> 8); - _spi.write(color & 0xff); - } - #else // 16 bit SPI - _spi.format(8,3); // 8 bit Mode 3 - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - _spi.format(16,3); // switch to 16 bit Mode 3 - for (int y=0; y<h; y++) { - _spi.write(color); - } - #endif - #endif - _cs = 1; - WindowMax(); - return; -} - - -// draw line -void SPI_TFT::line(int x0, int y0, int x1, int y1, int color) -{ - //WindowMax(); - int dx = 0, dy = 0; - int dx_sym = 0, dy_sym = 0; - int dx_x2 = 0, dy_x2 = 0; - int di = 0; - - dx = x1-x0; - dy = y1-y0; - - if (dx == 0) { /* vertical line */ - if (y1 > y0) vline(x0,y0,y1,color); - else vline(x0,y1,y0,color); - return; - } - - if (dx > 0) { - dx_sym = 1; - } else { - dx_sym = -1; - } - if (dy == 0) { /* horizontal line */ - if (x1 > x0) hline(x0,x1,y0,color); - else hline(x1,x0,y0,color); - return; - } - - if (dy > 0) { - dy_sym = 1; - } else { - dy_sym = -1; - } - - dx = dx_sym*dx; - dy = dy_sym*dy; - - dx_x2 = dx*2; - dy_x2 = dy*2; - - if (dx >= dy) { - di = dy_x2 - dx; - while (x0 != x1) { - - pixel(x0, y0, color); - x0 += dx_sym; - if (di<0) { - di += dy_x2; - } else { - di += dy_x2 - dx_x2; - y0 += dy_sym; - } - } - pixel(x0, y0, color); - } else { - di = dx_x2 - dy; - while (y0 != y1) { - pixel(x0, y0, color); - y0 += dy_sym; - if (di < 0) { - di += dx_x2; - } else { - di += dx_x2 - dy_x2; - x0 += dx_sym; - } - } - pixel(x0, y0, color); - } - return; -} - -// draw rect -void SPI_TFT::rect(int x0, int y0, int x1, int y1, int color) -{ - - if (x1 > x0) hline(x0,x1,y0,color); - else hline(x1,x0,y0,color); - - if (y1 > y0) vline(x0,y0,y1,color); - else vline(x0,y1,y0,color); - - if (x1 > x0) hline(x0,x1,y1,color); - else hline(x1,x0,y1,color); - - if (y1 > y0) vline(x1,y0,y1,color); - else vline(x1,y1,y0,color); - - return; -} - - -// fill rect -void SPI_TFT::fillrect(int x0, int y0, int x1, int y1, int color) -{ - - int h = y1 - y0 + 1; - int w = x1 - x0 + 1; - int pixel = h * w; - #if defined USE_DMA - int dma_count; - #endif - window(x0,y0,w,h); - wr_cmd(0x22); - _cs = 0; - #if defined NO_MBED_LIB - if (spi_port == 0) { // TFT on SSP0 - #if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP0->DR; // we send to SSP0 - /* Enable SSP0 for DMA. */ - LPC_SSP0->DMACR = 0x2; - #endif - LPC_SSP0->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP0->DR = 0x72; // start Data - LPC_SSP0->CR0 |= 0x08UL; // set to 16 bit - } else { // TFT on SSP1 - #if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP1->DR; // we send to SSP1 - /* Enable SSP1 for DMA. */ - LPC_SSP1->DMACR = 0x2; - #endif - LPC_SSP1->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP1->DR = 0x72; // start Data - LPC_SSP1->CR0 |= 0x08UL; // set to 16 bit - } - #if defined USE_DMA - do { - if (pixel > 4095) { - dma_count = 4095; - pixel = pixel - 4095; - } else { - dma_count = pixel; - pixel = 0; - } - LPC_GPDMA->DMACIntTCClear = 0x1; - LPC_GPDMA->DMACIntErrClr = 0x1; - LPC_GPDMACH0->DMACCSrcAddr = (uint32_t)&color; - LPC_GPDMACH0->DMACCControl = dma_count | (1UL << 18) | (1UL << 21) | (1UL << 31) ; // 16 bit transfer , no address increment, interrupt - LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | (spi_port ? DMA_DEST_SSP1_TX : DMA_DEST_SSP0_TX); - LPC_GPDMA->DMACSoftSReq = 0x1; - do { - } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running - - } while (pixel > 0); - - if (spi_port == 0) { // TFT on SSP0 - do { - } while ((LPC_SSP0->SR & 0x10) == 0x10); // SPI FIFO not empty - } else { // TFT on SSP1 - do { - } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI FIFO not empty - } - - #else // no DMA - for (int p=0; p<pixel; p++) { - _spi.write(color); - } - #endif - - #else // use mbed lib - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - for (int p=0; p<pixel; p++) { - _spi.write(color >> 8); - _spi.write(color & 0xff); - } - - #else // 16 bit SPI - _spi.format(8,3); // 8 bit Mode 3 - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - _spi.format(16,3); // switch to 16 bit Mode 3 - for (int p=0; p<pixel; p++) { - _spi.write(color); - } - #endif - #endif - _cs = 1; - WindowMax(); - return; -} - -// set cursor position -void SPI_TFT::locate(int x, int y) -{ - char_x = x; - char_y = y; -} - - -// calculate num of chars in a row -int SPI_TFT::columns() -{ - return width() / font[1]; -} - -// calculate num of rows on the screen -int SPI_TFT::rows() -{ - return height() / font[2]; -} - -// print a char on the screen -int SPI_TFT::_putc(int value) -{ - if (value == '\n') { // new line - char_x = 0; - char_y = char_y + font[2]; - if (char_y >= height() - font[2]) { - char_y = 0; - } - } else { - character(char_x, char_y, value); - } - return value; -} - -// consrtuct the char out of the font -void SPI_TFT::character(int x, int y, int c) -{ - unsigned int hor,vert,offset,bpl,j,i,b; - unsigned char* zeichen; - unsigned char z,w; - #if defined USE_DMA - unsigned int pixel; - unsigned int p; - unsigned int dma_count,dma_off; - uint16_t *buffer; - #endif - - if ((c < 31) || (c > 127)) return; // test char range - - // read font parameter from start of array - offset = font[0]; // bytes / char - hor = font[1]; // get hor size of font - vert = font[2]; // get vert size of font - bpl = font[3]; // bytes per line - - if (char_x + hor > width()) { - char_x = 0; - char_y = char_y + vert; - if (char_y >= height() - font[2]) { - char_y = 0; - } - } - window(char_x, char_y,hor,vert); // char box - wr_cmd(0x22); - - #if defined USE_DMA - pixel = hor * vert; // calculate buffer size - - buffer = (uint16_t *) malloc (2*pixel); // we need a buffer for the 16 bit - if (buffer == NULL) { - //led = 1; - //pc.printf("Malloc error !\n\r"); - return; // error no memory - } - - zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap - w = zeichen[0]; // width of actual char - p = 0; - // construct the char into the buffer - for (j=0; j<vert; j++) { // vert line - for (i=0; i<hor; i++) { // horz line - z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; - b = 1 << (j & 0x07); - if (( z & b ) == 0x00) { - buffer[p] = _background; - } else { - buffer[p] = _foreground; - } - p++; - } - } - - // copy the buffer with DMA SPI to display - dma_off = 0; // offset for DMA transfer - _cs = 0; - if (spi_port == 0) { // TFT on SSP0 - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP0->DR; // we send to SSP0 - /* Enable SSP0 for DMA. */ - LPC_SSP0->DMACR = 0x2; - LPC_SSP0->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP0->DR = 0x72; // start Data - LPC_SSP0->CR0 |= 0x08UL; // set to 16 bit - } else { // TFT on SSP1 - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP1->DR; // we send to SSP1 - /* Enable SSP1 for DMA. */ - LPC_SSP1->DMACR = 0x2; - LPC_SSP1->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP1->DR = 0x72; // start Data - LPC_SSP1->CR0 |= 0x08UL; // set to 16 bit - } - - // start DMA - do { - if (pixel > 4095) { // this is a giant font ! - dma_count = 4095; - pixel = pixel - 4095; - } else { - dma_count = pixel; - pixel = 0; - } - LPC_GPDMA->DMACIntTCClear = 0x1; - LPC_GPDMA->DMACIntErrClr = 0x1; - LPC_GPDMACH0->DMACCSrcAddr = (uint32_t) (buffer + dma_off); - LPC_GPDMACH0->DMACCControl = dma_count | (1UL << 18) | (1UL << 21) | (1UL << 31) | DMA_CHANNEL_SRC_INC ; // 16 bit transfer , address increment, interrupt - LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | (spi_port ? DMA_DEST_SSP1_TX : DMA_DEST_SSP0_TX); - LPC_GPDMA->DMACSoftSReq = 0x1; - do { - } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running - dma_off = dma_off + dma_count; - } while (pixel > 0); - - free ((uint16_t *) buffer); - - if (spi_port == 0) { // TFT on SSP0 - do { - } while ((LPC_SSP0->SR & 0x10) == 0x10); // SPI0 not idle - /* disable SSP0 for DMA. */ - LPC_SSP0->DMACR = 0x0; - } else { // TFT on SSP1 - do { - } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI1 not idle - /* disable SSP1 for DMA. */ - LPC_SSP1->DMACR = 0x0; - } - - #else // no dma - _cs = 0; - #if defined NO_MBED_LIB - if (spi_port == 0) { // TFT on SSP0 - LPC_SSP0->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP0->DR = 0x72; // start Data - LPC_SSP0->CR0 |= 0x08UL; // set to 16 bit - } else { // TFT on SSP1 - LPC_SSP1->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP1->DR = 0x72; // start Data - LPC_SSP1->CR0 |= 0x08UL; // set to 16 bit - } - #else // mbed lib - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - #else // 16 bit SPI - _spi.format(8,3); // 8 bit Mode 3 - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - _spi.format(16,3); // switch back to 16 bit Mode 3 - #endif - #endif - - zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap - w = zeichen[0]; // width of actual char - for (j=0; j<vert; j++) { // vert line - for (i=0; i<hor; i++) { // horz line - z = zeichen[bpl * i + ((j & 0xF8) >> 3)+1]; - b = 1 << (j & 0x07); - if (( z & b ) == 0x00) { - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(_background >> 8); - _spi.write(_background & 0xff); - #else - _spi.write(_background); - #endif - } else { - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(_foreground >> 8); - _spi.write(_foreground & 0xff); - #else - _spi.write(_foreground); - #endif - } - } - } - #endif // no DMA - _cs = 1; - WindowMax(); - if ((w + 2) < hor) { // x offset to next char - char_x += w + 2; - } else char_x += hor; -} - - -void SPI_TFT::set_font(unsigned char* f) -{ - font = f; -} - - -void SPI_TFT::Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *bitmap) -{ - unsigned int j; - int padd; - - unsigned short *bitmap_ptr = (unsigned short *)bitmap; - #if defined TARGET_KL25Z // 8 Bit SPI - unsigned short pix_temp; - #endif - - // the lines are padded to multiple of 4 bytes in a bitmap - padd = -1; - do { - padd ++; - } while (2*(w + padd)%4 != 0); - window(x, y, w, h); - wr_cmd(0x22); - _cs = 0; -#if defined NO_MBED_LIB - if (spi_port == 0) { // TFT on SSP0 - #if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP0->DR; // we send to SSP0 - /* Enable SSP0 for DMA. */ - LPC_SSP0->DMACR = 0x2; - #endif - LPC_SSP0->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP0->DR = 0x72; // start Data - LPC_SSP0->CR0 |= 0x08UL; // set to 16 bit - - } else { - #if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP1->DR; // we send to SSP1 - /* Enable SSP1 for DMA. */ - LPC_SSP1->DMACR = 0x2; - #endif - LPC_SSP1->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP1->DR = 0x72; // start Data command - LPC_SSP1->CR0 |= 0x08UL; // set to 16 bit - } - - bitmap_ptr += ((h - 1)* (w + padd)); - #if defined USE_DMA - for (j = 0; j < h; j++) { //Lines - LPC_GPDMA->DMACIntTCClear = 0x1; - LPC_GPDMA->DMACIntErrClr = 0x1; - LPC_GPDMACH0->DMACCSrcAddr = (uint32_t)bitmap_ptr; - LPC_GPDMACH0->DMACCControl = w | (1UL << 18) | (1UL << 21) | (1UL << 31) | DMA_CHANNEL_SRC_INC ; // 16 bit transfer , address increment, interrupt - LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | (spi_port ? DMA_DEST_SSP1_TX : DMA_DEST_SSP0_TX); - LPC_GPDMA->DMACSoftSReq = 0x1; - do { - } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running - - bitmap_ptr -= w; - bitmap_ptr -= padd; - } - #else - unsigned int i; - for (j = 0; j < h; j++) { //Lines - for (i = 0; i < w; i++) { // copy pixel data to TFT - _spi.write(*bitmap_ptr); // one line - bitmap_ptr++; - } - bitmap_ptr -= 2*w; - bitmap_ptr -= padd; - } - #endif - if (spi_port == 0) { // TFT on SSP0 - do { - } while ((LPC_SSP0->SR & 0x10) == 0x10); // SPI FIFO not empty - } else { - do { - } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI FIFO not empty - } -#else // use mbed lib - #if defined TARGET_KL25Z // 8 Bit SPI - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - #else - _spi.format(8,3); // 8 bit Mode 3 - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - _spi.format(16,3); // switch to 16 bit Mode 3 - #endif - bitmap_ptr += ((h - 1)* (w + padd)); - unsigned int i; - for (j = 0; j < h; j++) { //Lines - for (i = 0; i < w; i++) { // copy pixel data to TFT - #if defined TARGET_KL25Z // 8 Bit SPI - pix_temp = *bitmap_ptr; - _spi.write(pix_temp >> 8); - _spi.write(pix_temp); - bitmap_ptr++; - #else - _spi.write(*bitmap_ptr); // one line - bitmap_ptr++; - #endif - } - bitmap_ptr -= 2*w; - bitmap_ptr -= padd; - } -#endif // USE MBED LIB - _cs = 1; - WindowMax(); -} - - -// local filesystem is not implemented in kinetis board -#if defined TARGET_LPC1768 || defined TARGET_LPC11U24 - - -int SPI_TFT::BMP_16(unsigned int x, unsigned int y, const char *Name_BMP) -{ - -#define OffsetPixelWidth 18 -#define OffsetPixelHeigh 22 -#define OffsetFileSize 34 -#define OffsetPixData 10 -#define OffsetBPP 28 - - char filename[50]; - unsigned char BMP_Header[54]; - unsigned short BPP_t; - unsigned int PixelWidth,PixelHeigh,start_data; - unsigned int i,off; - int padd,j; - unsigned short *line; - - // get the filename - LocalFileSystem local("local"); - sprintf(&filename[0],"/local/"); - i=7; - while (*Name_BMP!='\0') { - filename[i++]=*Name_BMP++; - } - - fprintf(stderr, "filename : %s \n\r",filename); - - FILE *Image = fopen((const char *)&filename[0], "rb"); // open the bmp file - if (!Image) { - return(0); // error file not found ! - } - - fread(&BMP_Header[0],1,54,Image); // get the BMP Header - - if (BMP_Header[0] != 0x42 || BMP_Header[1] != 0x4D) { // check magic byte - fclose(Image); - return(-1); // error no BMP file - } - - BPP_t = BMP_Header[OffsetBPP] + (BMP_Header[OffsetBPP + 1] << 8); - if (BPP_t != 0x0010) { - fclose(Image); - return(-2); // error no 16 bit BMP - } - - PixelHeigh = BMP_Header[OffsetPixelHeigh] + (BMP_Header[OffsetPixelHeigh + 1] << 8) + (BMP_Header[OffsetPixelHeigh + 2] << 16) + (BMP_Header[OffsetPixelHeigh + 3] << 24); - PixelWidth = BMP_Header[OffsetPixelWidth] + (BMP_Header[OffsetPixelWidth + 1] << 8) + (BMP_Header[OffsetPixelWidth + 2] << 16) + (BMP_Header[OffsetPixelWidth + 3] << 24); - if (PixelHeigh > height() + y || PixelWidth > width() + x) { - fclose(Image); - return(-3); // to big - } - - start_data = BMP_Header[OffsetPixData] + (BMP_Header[OffsetPixData + 1] << 8) + (BMP_Header[OffsetPixData + 2] << 16) + (BMP_Header[OffsetPixData + 3] << 24); - - line = (unsigned short *) malloc (2 * PixelWidth); // we need a buffer for a line - if (line == NULL) { - return(-4); // error no memory - } - - // the bmp lines are padded to multiple of 4 bytes - padd = -1; - do { - padd ++; - } while ((PixelWidth * 2 + padd)%4 != 0); - - -//fseek(Image, 70 ,SEEK_SET); - window(x, y,PixelWidth ,PixelHeigh); - wr_cmd(0x22); - _cs = 0; -#if defined NO_MBED_LIB - if (spi_port == 0) { // TFT on SSP0 -#if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP0->DR; // we send to SSP0 - /* Enable SSP0 for DMA. */ - LPC_SSP0->DMACR = 0x2; -#endif - LPC_SSP0->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP0->DR = 0x72; // start Data - LPC_SSP0->CR0 |= 0x08UL; // set to 16 bit - - } else { -#if defined USE_DMA - LPC_GPDMACH0->DMACCDestAddr = (uint32_t)&LPC_SSP1->DR; // we send to SSP1 - /* Enable SSP1 for DMA. */ - LPC_SSP1->DMACR = 0x2; -#endif - LPC_SSP1->CR0 &= ~(0x08UL); // set to 8 bit - LPC_SSP1->DR = 0x72; // start Data - LPC_SSP1->CR0 |= 0x08UL; // set to 16 bit - } - for (j = PixelHeigh - 1; j >= 0; j--) { //Lines bottom up - off = j * (PixelWidth * 2 + padd) + start_data; // start of line - fseek(Image, off ,SEEK_SET); - fread(line,1,PixelWidth * 2,Image); // read a line - slow ! -#if defined USE_DMA - LPC_GPDMA->DMACIntTCClear = 0x1; - LPC_GPDMA->DMACIntErrClr = 0x1; - LPC_GPDMACH0->DMACCSrcAddr = (uint32_t)line; - LPC_GPDMACH0->DMACCControl = PixelWidth | (1UL << 18) | (1UL << 21) | (1UL << 31) | DMA_CHANNEL_SRC_INC ; // 16 bit transfer , address increment, interrupt - LPC_GPDMACH0->DMACCConfig = DMA_CHANNEL_ENABLE | DMA_TRANSFER_TYPE_M2P | (spi_port ? DMA_DEST_SSP1_TX : DMA_DEST_SSP0_TX); - LPC_GPDMA->DMACSoftSReq = 0x1; - do { - } while ((LPC_GPDMA->DMACRawIntTCStat & 0x01) == 0); // DMA is running -#else - for (i = 0; i < PixelWidth; i++) { // copy pixel data to TFT - _spi.write(line[i]); // one 16 bit pixel - } -#endif - } - if (spi_port == 0) { // TFT on SSP0 - do { - } while ((LPC_SSP0->SR & 0x10) == 0x10); // SPI FIFO not empty - } else { - do { - } while ((LPC_SSP1->SR & 0x10) == 0x10); // SPI FIFO not empty - } - -#else // use mbed lib - _spi.format(8,3); // 8 bit Mode 3 - _spi.write(SPI_START | SPI_WR | SPI_DATA); // Write : RS = 1, RW = 0 - _spi.format(16,3); // switch to 16 bit Mode 3 - for (j = PixelHeigh - 1; j >= 0; j--) { //Lines bottom up - off = j * (PixelWidth * 2 + padd) + start_data; // start of line - fseek(Image, off ,SEEK_SET); - fread(line,1,PixelWidth * 2,Image); // read a line - slow ! - for (i = 0; i < PixelWidth; i++) { // copy pixel data to TFT - _spi.write(line[i]); // one 16 bit pixel - } - } -#endif - _cs = 1; - free (line); - fclose(Image); - WindowMax(); - return(1); -} - -#endif
--- a/SPI_TFT.h Tue Oct 22 20:17:29 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,408 +0,0 @@ -/* mbed library for 240*320 pixel display TFT based on HX8347D LCD Controller - * Copyright (c) 2011 Peter Drescher - DC2PD - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - - /* change the char position handling - * use pixel (x,y) instadt of colum row */ - - -#ifndef MBED_SPI_TFT_H -#define MBED_SPI_TFT_H - -//#define NO_DMA - -#include "mbed.h" -#include "GraphicsDisplay.h" - -#define RGB(r,g,b) (((r&0xF8)<<8)|((g&0xFC)<<3)|((b&0xF8)>>3)) //5 red | 6 green | 5 blue - -#define SPI_START (0x70) /* Start byte for SPI transfer */ -#define SPI_RD (0x01) /* WR bit 1 within start */ -#define SPI_WR (0x00) /* WR bit 0 within start */ -#define SPI_DATA (0x02) /* RS bit 1 within start byte */ -#define SPI_INDEX (0x00) /* RS bit 0 within start byte */ - - -/* some RGB color definitions */ -#define Black 0x0000 /* 0, 0, 0 */ -#define Navy 0x000F /* 0, 0, 128 */ -#define DarkGreen 0x03E0 /* 0, 128, 0 */ -#define DarkCyan 0x03EF /* 0, 128, 128 */ -#define Maroon 0x7800 /* 128, 0, 0 */ -#define Purple 0x780F /* 128, 0, 128 */ -#define Olive 0x7BE0 /* 128, 128, 0 */ -#define LightGrey 0xC618 /* 192, 192, 192 */ -#define DarkGrey 0x7BEF /* 128, 128, 128 */ -#define Blue 0x001F /* 0, 0, 255 */ -#define Green 0x07E0 /* 0, 255, 0 */ -#define Cyan 0x07FF /* 0, 255, 255 */ -#define Red 0xF800 /* 255, 0, 0 */ -#define Magenta 0xF81F /* 255, 0, 255 */ -#define Yellow 0xFFE0 /* 255, 255, 0 */ -#define White 0xFFFF /* 255, 255, 255 */ -#define Orange 0xFD20 /* 255, 165, 0 */ -#define GreenYellow 0xAFE5 /* 173, 255, 47 */ - - -// some defines for the DMA use -#define DMA_CHANNEL_ENABLE 1 -#define DMA_TRANSFER_TYPE_M2P (1UL << 11) -#define DMA_CHANNEL_TCIE (1UL << 31) -#define DMA_CHANNEL_SRC_INC (1UL << 26) -#define DMA_MASK_IE (1UL << 14) -#define DMA_MASK_ITC (1UL << 15) -#define DMA_SSP1_TX (1UL << 2) -#define DMA_SSP0_TX (0) -#define DMA_DEST_SSP1_TX (2UL << 6) -#define DMA_DEST_SSP0_TX (0UL << 6) - - -/** Display control class, based on GraphicsDisplay and TextDisplay - * - * Example: - * @code - * #include "stdio.h" - * #include "mbed.h" - * #include "SPI_TFT.h" - * #include "string" - * #include "Arial12x12.h" - * #include "Arial24x23.h" - * - * - * - * // the TFT is connected to SPI pin 5-7 - * SPI_TFT TFT(p5, p6, p7, p8, p15,"TFT"); // mosi, miso, sclk, cs, reset - * - * int main() { - * TFT.claim(stdout); // send stdout to the TFT display - * //TFT.claim(stderr); // send stderr to the TFT display - * - * TFT.background(Black); // set background to black - * TFT.foreground(White); // set chars to white - * TFT.cls(); // clear the screen - * TFT.set_font((unsigned char*) Arial12x12); // select the font - * - * TFT.set_orientation(0); - * TFT.locate(0,0); - * printf(" Hello Mbed 0"); - * TFT.set_font((unsigned char*) Arial24x23); // select font 2 - * TFT.locate(48,115); - * TFT.printf("Bigger Font"); - * } - * @endcode - */ - class SPI_TFT : public GraphicsDisplay { - public: - - /** Create a SPI_TFT object connected to SPI and two pins - * - * @param mosi,miso,sclk SPI - * @param cs pin connected to CS of display - * @param reset pin connected to RESET of display - * - */ - SPI_TFT(PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset,const char* name ="TFT"); - - /** Get the width of the screen in pixel - * - * @param - * @returns width of screen in pixel - * - */ - virtual int width(); - - /** Get the height of the screen in pixel - * - * @returns height of screen in pixel - * - */ - virtual int height(); - - /** Draw a pixel at x,y with color - * - * @param x horizontal position - * @param y vertical position - * @param color 16 bit pixel color - */ - virtual void pixel(int x, int y,int colour); - - /** draw a circle - * - * @param x0,y0 center - * @param r radius - * @param color 16 bit color * - * - */ - void circle(int x, int y, int r, int colour); - - /** draw a filled circle - * - * @param x0,y0 center - * @param r radius - * @param color 16 bit color * - * - * use circle with different radius, - * can miss some pixel - */ - void fillcircle(int x, int y, int r, int colour); - - - - /** draw a 1 pixel line - * - * @param x0,y0 start point - * @param x1,y1 stop point - * @param color 16 bit color - * - */ - void line(int x0, int y0, int x1, int y1, int colour); - - /** draw a rect - * - * @param x0,y0 top left corner - * @param x1,y1 down right corner - * @param color 16 bit color - * * - */ - void rect(int x0, int y0, int x1, int y1, int colour); - - /** draw a filled rect - * - * @param x0,y0 top left corner - * @param x1,y1 down right corner - * @param color 16 bit color - * - */ - void fillrect(int x0, int y0, int x1, int y1, int colour); - - /** setup cursor position - * - * @param x x-position (top left) - * @param y y-position - */ - virtual void locate(int x, int y); - - /** Fill the screen with _backgroun color - * - */ - virtual void cls (void); - - /** calculate the max number of char in a line - * - * @returns max columns - * depends on actual font size - * - */ - virtual int columns(void); - - /** calculate the max number of columns - * - * @returns max column - * depends on actual font size - * - */ - virtual int rows(void); - - /** put a char on the screen - * - * @param value char to print - * @returns printed char - * - */ - virtual int _putc(int value); - - /** draw a character on given position out of the active font to the TFT - * - * @param x x-position of char (top left) - * @param y y-position - * @param c char to print - * - */ - virtual void character(int x, int y, int c); - - /** paint a bitmap on the TFT - * - * @param x,y : upper left corner - * @param w width of bitmap - * @param h high of bitmap - * @param *bitmap pointer to the bitmap data - * - * bitmap format: 16 bit R5 G6 B5 - * - * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 - * use winhex to load this file and mark data stating at offset 0x46 to end - * use edit -> copy block -> C Source to export C array - * paste this array into your program - * - * define the array as static const unsigned char to put it into flash memory - * cast the pointer to (unsigned char *) : - * tft.Bitmap(10,40,309,50,(unsigned char *)scala); - */ - void Bitmap(unsigned int x, unsigned int y, unsigned int w, unsigned int h,unsigned char *bitmap); - - - /** paint a 16 bit BMP from local filesytem on the TFT (slow) - * - * @param x,y : upper left corner - * @param *Name_BMP name of the BMP file - * @returns 1 if bmp file was found and painted - * @returns -1 if bmp file was found not found - * @returns -2 if bmp file is not 16bit - * @returns -3 if bmp file is to big for screen - * @returns -4 if buffer malloc go wrong - * - * bitmap format: 16 bit R5 G6 B5 - * - * use Gimp to create / load , save as BMP, option 16 bit R5 G6 B5 - * copy to internal file system - * - */ - - int BMP_16(unsigned int x, unsigned int y, const char *Name_BMP); - - - - /** select the font to use - * - * @param f pointer to font array - * - * font array can created with GLCD Font Creator from http://www.mikroe.com - * you have to add 4 parameter at the beginning of the font array to use: - * - the number of byte / char - * - the vertial size in pixel - * - the horizontal size in pixel - * - the number of byte per vertical line - * you also have to change the array to char[] - * - */ - void set_font(unsigned char* f); - - /** Set the orientation of the screen - * x,y: 0,0 is always top left - * - * @param o direction to use the screen (0-3) 90� Steps - * - */ - void set_orientation(unsigned int o); - - SPI _spi; - DigitalOut _cs; - DigitalOut _reset; - unsigned char* font; - - - - -protected: - - /** Set draw window region to whole screen - * - */ - void WindowMax (void); - - - /** draw a horizontal line - * - * @param x0 horizontal start - * @param x1 horizontal stop - * @param y vertical position - * @param color 16 bit color - * - */ - void hline(int x0, int x1, int y, int colour); - - /** draw a vertical line - * - * @param x horizontal position - * @param y0 vertical start - * @param y1 vertical stop - * @param color 16 bit color - */ - void vline(int y0, int y1, int x, int colour); - - /** Set draw window region - * - * @param x horizontal position - * @param y vertical position - * @param w window width in pixel - * @param h window height in pixels - */ - virtual void window (unsigned int x,unsigned int y, unsigned int w, unsigned int h); - - - - /** Init the HX8347D controller - * - */ - void tft_reset(); - - /** Write data to the LCD controller - * - * @param dat data written to LCD controller - * - */ - //void wr_dat(unsigned int value); - void wr_dat(unsigned char value); - - /** Write a command the LCD controller - * - * @param cmd: command to be written - * - */ - void wr_cmd(unsigned char value); - - /** Start data sequence to the LCD controller - * - */ - //void wr_dat_start(); - - /** Stop of data writing to the LCD controller - * - */ - //void wr_dat_stop(); - - /** write data to the LCD controller - * - * @param data to be written - * * - */ - void wr_dat_only(unsigned short dat); - - /** Read data from the LCD controller - * - * @returns data from LCD controller - * - */ - unsigned short rd_dat(void); - - /** Write a value to the to a LCD register - * - * @param reg register to be written - * @param val data to be written - */ - void wr_reg (unsigned char reg, unsigned char val); - - /** Read a LCD register - * - * @param reg register to be read - * @returns value of the register - */ - unsigned short rd_reg (unsigned char reg); - - unsigned char spi_port; - unsigned int orientation; - unsigned int char_x; - unsigned int char_y; - - -}; - -#endif
--- a/TextDisplay.cpp Tue Oct 22 20:17:29 2013 +0000 +++ b/TextDisplay.cpp Sun Jan 12 17:40:32 2014 +0000 @@ -2,10 +2,11 @@ * Copyright (c) 2007-2009 sford * Released under the MIT License: http://mbed.org/license/mit */ - + #include "TextDisplay.h" -TextDisplay::TextDisplay(const char *name) : Stream(name){ +TextDisplay::TextDisplay(const char *name) : Stream(name) +{ _row = 0; _column = 0; if (name == NULL) { @@ -15,8 +16,9 @@ sprintf(_path, "/%s", name); } } - -int TextDisplay::_putc(int value) { + +int TextDisplay::_putc(int value) +{ if(value == '\n') { _column = 0; _row++; @@ -38,33 +40,43 @@ } // crude cls implementation, should generally be overwritten in derived class -void TextDisplay::cls() { +RetCode_t TextDisplay::cls() +{ locate(0, 0); for(int i=0; i<columns()*rows(); i++) { putc(' '); } + return noerror; } -void TextDisplay::locate(int column, int row) { +RetCode_t TextDisplay::locate(unsigned int column, unsigned int row) +{ _column = column; _row = row; + return noerror; } -int TextDisplay::_getc() { +int TextDisplay::_getc() +{ return -1; } - -void TextDisplay::foreground(uint16_t colour) { + +RetCode_t TextDisplay::foreground(uint16_t colour) +{ _foreground = colour; + return noerror; } -void TextDisplay::background(uint16_t colour) { +RetCode_t TextDisplay::background(uint16_t colour) +{ _background = colour; + return noerror; } -bool TextDisplay::claim (FILE *stream) { +bool TextDisplay::claim (FILE *stream) +{ if ( _path == NULL) { - fprintf(stderr, "claim requires a name to be given in the instantioator of the TextDisplay instance!\r\n"); + fprintf(stderr, "claim requires a name to be given in the instantiator of the TextDisplay instance!\r\n"); return false; } if (freopen(_path, "w", stream) == NULL) { @@ -74,4 +86,4 @@ // make sure we use line buffering setvbuf(stdout, NULL, _IOLBF, columns()); return true; -} +}
--- a/TextDisplay.h Tue Oct 22 20:17:29 2013 +0000 +++ b/TextDisplay.h Sun Jan 12 17:40:32 2014 +0000 @@ -9,7 +9,7 @@ * Everything else (locate, printf, putc, cls) will come for free * * The model is the display will wrap at the right and bottom, so you can - * keep writing and will always get valid characters. The location is + * keep writing and will always get valid characters. The location is * maintained internally to the class to make this easy */ @@ -18,14 +18,24 @@ #include "mbed.h" -class TextDisplay : public Stream { +typedef uint16_t color_t; + +/// return values from functions +typedef enum +{ + noerror, + bad_parameter +} RetCode_t; + +class TextDisplay : public Stream +{ public: - // functions needing implementation in derived implementation class - /** Create a TextDisplay interface - * - * @param name The name used in the path to access the strean through the filesystem - */ + // functions needing implementation in derived implementation class + /** Create a TextDisplay interface + * + * @param name The name used in the path to access the strean through the filesystem + */ TextDisplay(const char *name = NULL); /** output a character at the given position @@ -45,7 +55,7 @@ * @result number of rows */ virtual int columns() = 0; - + // functions that come for free, but can be overwritten /** redirect output from a stream (stoud, sterr) to display @@ -55,15 +65,14 @@ /** clear screen */ - virtual void cls(); - virtual void locate(int column, int row); - virtual void foreground(uint16_t colour); - virtual void background(uint16_t colour); + virtual RetCode_t cls(); + virtual RetCode_t locate(unsigned int column, unsigned int row) = 0; + virtual RetCode_t foreground(uint16_t colour) = 0; + virtual RetCode_t background(uint16_t colour) = 0; // putc (from Stream) // printf (from Stream) - -protected: +protected: virtual int _putc(int value); virtual int _getc();