fixed library.
Dependents: Sharp_Memory_LCD_Test hello_GT20L16J1Y_FONT_mlcd
Fork of sharp_mlcd by
Revision 2:c36cdd3ad7ba, committed 2014-09-12
- Comitter:
- ban4jp
- Date:
- Fri Sep 12 18:04:58 2014 +0000
- Parent:
- 1:f8ba3b236d12
- Child:
- 3:d2aed1df064c
- Commit message:
- Add pin selectable constructor.; Fix copy_to_lcd(): add dummy clock.; Fix _putc(), character(): character warp mistake.; Fix print_bm(): can't draw, 256px width over.; ... and more fix.
Changed in this revision
| sharp_mlcd.cpp | Show annotated file Show diff for this revision Revisions of this file |
| sharp_mlcd.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/sharp_mlcd.cpp Sun May 11 14:03:39 2014 +0000
+++ b/sharp_mlcd.cpp Fri Sep 12 18:04:58 2014 +0000
@@ -33,10 +33,14 @@
#include "Small_7.h"
sharp_mlcd::sharp_mlcd(const char* name)
- : _spi(D11,NC,D13),_EXTCOM(D9),_DISP(D8),_CS(D10), GraphicsDisplay(name) // for nucleo L152RE or other
+ : GraphicsDisplay(name), _spi(D11, NC, D13), _EXTCOM(D9), _DISP(D8), _CS(D10) // for nucleo L152RE or other
{
- draw_mode = NORMAL;
- char_x = 0;
+ lcd_reset();
+}
+
+sharp_mlcd::sharp_mlcd(PinName mosi, PinName sclk, PinName scs, PinName extcomin, PinName disp, const char* name)
+ : GraphicsDisplay(name), _spi(mosi, NC, sclk), _EXTCOM(extcomin), _DISP(disp), _CS(scs)
+{
lcd_reset();
}
@@ -72,6 +76,8 @@
wait_us(2);
_CS = 0;
+ setmode(NORMAL);
+
// clear and update LCD
cls();
// memset(buffer,0xff,BUFFER_SIZE); // clear display buffer
@@ -93,16 +99,16 @@
void sharp_mlcd::pixel(int x, int y, int color)
{
// first check parameter
- if(x > WIDTH || y > HEIGHT || x < 0 || y < 0) return;
+ if(x >= width() || y >= height() || x < 0 || y < 0) return;
if(draw_mode == NORMAL) {
if(color != reverse)
- buffer[x/8 + (y*WIDTH/8)] &= ~(1 << (7-(x%8))); // set pixel
+ buffer[x/8 + (y*width()/8)] &= ~(1 << (7-(x%8))); // set pixel
else
- buffer[x/8 + (y*WIDTH/8)] |= (1 << (7-(x%8))); // erase pixel
+ buffer[x/8 + (y*width()/8)] |= (1 << (7-(x%8))); // erase pixel
} else { // XOR mode
if(color != reverse)
- buffer[x/8 + (y*WIDTH/8)] ^= (1 << (7-(x%8))); // xor pixel
+ buffer[x/8 + (y*width()/8)] ^= (1 << (7-(x%8))); // xor pixel
}
}
@@ -122,22 +128,23 @@
return u;
}
-void sharp_mlcd::copy_to_lcd(void)
+void sharp_mlcd::copy_to_lcd(int start)
{
- const int start = 0;
int x, y;
unsigned char *p = (unsigned char*)buffer; // image;
_CS = 1;
wait_us(4); // min 3us
//
- for (y = 0; y < HEIGHT; y++) {
+ for (y = 0; y < height(); y++) {
_spi.write(0x80); // update mode (multi line)
- _spi.write(bit_reverse((y + 1 + start) % HEIGHT)); // set gate line address
- for (x = 0; x < (WIDTH / 8); x++) {
+ _spi.write(bit_reverse((y + start) % height() + 1)); // set gate line address
+ for (x = 0; x < (width() / 8); x++) {
_spi.write(*p++); // (((y / 8) + x + mode) % 2)? 0xff: 0);
}
}
+ _spi.write(0x00); // dummy (16ck)
+ _spi.write(0x00);
//
wait_us(2); // min 1us
_CS = 0;
@@ -145,7 +152,7 @@
void sharp_mlcd::cls(void)
{
- memset(buffer, reverse? 0x00: 0xff, BUFFER_SIZE); // clear display buffer
+ memset(buffer, reverse ? 0x00 : 0xff, BUFFER_SIZE); // clear display buffer
copy_to_lcd();
}
@@ -301,7 +308,7 @@
draw_x5 = draw_x7 = x0 - r;
draw_y5 = draw_y7 = y0;
- if (draw_x5>=0) {
+ if (draw_x5 >= 0) {
pixel(draw_x5, draw_y5, color); /* 180 degree */
}
@@ -338,7 +345,7 @@
draw_y6--;
draw_y7--;
- if ( (draw_x0 <= width()) && (draw_y0>=0) ) {
+ if ( (draw_x0 <= width()) && (draw_y0 >= 0) ) {
pixel(draw_x0, draw_y0, color);
}
@@ -350,7 +357,7 @@
pixel(draw_x2, draw_y2, color);
}
- if ( (draw_x3 >=0 ) && (draw_y3 <= height()) ) {
+ if ( (draw_x3 >= 0 ) && (draw_y3 <= height()) ) {
pixel(draw_x3, draw_y3, color);
}
@@ -361,7 +368,7 @@
if ( (draw_x5 >= 0) && (draw_y5 >= 0) ) {
pixel(draw_x5, draw_y5, color);
}
- if ( (draw_x6 <=width()) && (draw_y6 <= height()) ) {
+ if ( (draw_x6 <= width()) && (draw_y6 <= height()) ) {
pixel(draw_x6, draw_y6, color);
}
if ( (draw_x7 >= 0) && (draw_y7 <= height()) ) {
@@ -414,7 +421,7 @@
if (value == '\n') { // new line
char_x = 0;
char_y = char_y + font[2];
- if (char_y >= height() - font[2]) {
+ if (char_y > height() - font[2]) {
char_y = 0;
}
} else {
@@ -438,20 +445,27 @@
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]) {
+ zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap
+ w = zeichen[0]; // width of actual char
+
+ if (char_x > width() - w) {
+ char_x = w;
+ char_y += vert;
+ if (char_y > height() - vert) {
char_y = 0;
}
+
+ x = 0;
+ y = char_y;
+
+ } else {
+ char_x += w;
}
- zeichen = &font[((c -32) * offset) + 4]; // start of char bitmap
- w = zeichen[0]; // width of actual char
// 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];
+ z = zeichen[bpl * i + ((j & 0xFFF8) >> 3)+1];
b = 1 << (j & 0x07);
if (( z & b ) == 0x00) {
pixel(x+i,y+j,0);
@@ -461,8 +475,6 @@
}
}
-
- char_x += w;
}
void sharp_mlcd::set_font(unsigned char* f)
@@ -472,8 +484,11 @@
void sharp_mlcd::set_auto_up(unsigned int up)
{
- if(up ) auto_up = 1;
- else auto_up = 0;
+ if (up) {
+ auto_up = 1;
+ } else {
+ auto_up = 0;
+ }
}
unsigned int sharp_mlcd::get_auto_up(void)
@@ -488,9 +503,9 @@
for(v=0; v < bm.ySize; v++) { // lines
for(h=0; h < bm.xSize; h++) { // pixel
- if(h + x > WIDTH-1) break;
- if(v + y > HEIGHT-1) break;
- d = bm.data[bm.Byte_in_Line * v + ((h & 0xF8) >> 3)];
+ if(h + x >= width()) break;
+ if(v + y >= height()) break;
+ d = bm.data[bm.Byte_in_Line * v + ((h & 0xFFF8) >> 3)];
b = 0x80 >> (h & 0x07);
if((d & b) == 0) {
pixel(x+h,y+v,!color);
--- a/sharp_mlcd.h Sun May 11 14:03:39 2014 +0000
+++ b/sharp_mlcd.h Fri Sep 12 18:04:58 2014 +0000
@@ -60,6 +60,8 @@
sharp_mlcd(const char* name = "LCD");
+ sharp_mlcd(PinName mosi, PinName sclk, PinName scs, PinName extcomin, PinName disp, const char* name = "LCD");
+
/** Get the width of the screen in pixel
*
* @param
@@ -134,7 +136,7 @@
*
*/
- void copy_to_lcd(void);
+ void copy_to_lcd(int start = 0);
/** clear the screen
*
ban4jp -
