Basic library for SHARP LCD LS027B4DH01/LS027B7DH01
Dependents: AkiSpiLcd_demo AkiSpiLcd_demo2 LCDRAM AkiSpiLcd_example
Revision 32:7e37fd2ddaa4, committed 2016-10-23
- Comitter:
- Kazuki Yamamoto
- Date:
- Sun Oct 23 17:25:47 2016 +0900
- Parent:
- 31:7c7faf88edcc
- Commit message:
- [ NEW ] MemoryLcd.h/cpp for base class declaration
new class LCD_MODE has basic command definitions
new class AkiLCD_MODE inherits LCD_MODE and overrides command definitions
Changed in this revision
--- a/AkiSpiLcd.cpp Sun Oct 23 02:27:02 2016 +0900
+++ b/AkiSpiLcd.cpp Sun Oct 23 17:25:47 2016 +0900
@@ -1,5 +1,4 @@
-/*
-Copyright (c) 2016 Kazuki Yamamoto <k.yamamoto.08136891@gmail.com>
+/* Copyright (c) 2016 Kazuki Yamamoto <k.yamamoto.08136891@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
@@ -22,7 +21,7 @@
*/
#include "AkiSpiLcd.h"
-#include "mbed.h"
+#include "mbed.h" //NOLINT
// #include "Ser23K256.h"
extern const uint8_t lcd_line[];
@@ -32,21 +31,16 @@
_csl = 0;
_csr = 1;
_spi.format(8, 0);
- _spi.frequency(10000000);
- _comflag = _modeflag = _clearflag = 0;
+ _spi.frequency(1000000);
+ _comflag = 0;
}
void AkiSpiLcd::cls() {
- _modeflag = 0;
- _clearflag = 1;
+ _csl = 1;
- _csl = 1;
- wait_us(5);
-
- _spi.write((_modeflag << 7) | (_comflag << 6) | (_clearflag << 5));
+ _spi.write(AkiLCD_MODE::CLEAR_SCREEN | (_comflag << 6));
_spi.write(0x00);
- wait_us(5);
_csl = 0;
cominvert();
@@ -62,16 +56,10 @@
}
void AkiSpiLcd::directUpdateSingle(int line, uint8_t *data) {
- _modeflag = 1;
- _clearflag = 0;
+ _csl = 1;
+ if (line == 0) line = 1;
- _csl = 1;
- wait_us(1);
-
- if (line == 0)
- line = 1;
-
- _spi.write((_modeflag << 7) | (_comflag << 6) | (_clearflag << 5));
+ _spi.write(AkiLCD_MODE::UPDATE | (_comflag << 6));
_spi.write((uint8_t)lcd_line[line]);
for (int i = 0; i < 50; i++) {
@@ -80,47 +68,39 @@
_spi.write(0x00);
_spi.write(0x00);
- wait_us(5);
_csl = 0;
cominvert();
}
void AkiSpiLcd::directUpdateMulti(int line, int length, uint8_t *data) {
- _modeflag = 1;
- _clearflag = 0;
-
- if (line == 0)
- line = 1;
+ if (line == 0) line = 1;
if (length > 0) {
_csl = 1;
- wait_us(5);
+
for (int j = 1; j <= length; j++) {
- _spi.write((_modeflag << 7) | (_comflag << 6) | (_clearflag << 5));
+ _spi.write(AkiLCD_MODE::UPDATE | (_comflag << 6));
_spi.write((uint8_t)lcd_line[line]);
for (int i = 0; i < 50; i++) {
- _spi.write(*(data + (50 * j + i))); // hogepic[50*j+i]
+ _spi.write(*(data + (50 * j + i)));
}
line += 1;
}
_spi.write(0x00);
_spi.write(0x00);
- wait_us(5);
+
_csl = 0;
}
cominvert();
}
void AkiSpiLcd::cominvert() {
- _modeflag = 0;
- _clearflag = 0;
-
_csl = 1;
- _spi.write((_modeflag << 7) | (_comflag << 6) | (_clearflag << 5));
+ _spi.write(AkiLCD_MODE::COM_INVERT | (_comflag << 6));
_spi.write(0x00);
- // wait_us(5);
+
_csl = 0;
if (_comflag == 0) {
_comflag = 1;
@@ -178,8 +158,6 @@
*/
void AkiSpiLcd::ramWriteMultiLine(int line, int length, uint8_t *data,
int screen) {
- _modeflag = 1;
- _clearflag = 0;
screen &= 1;
if (screen == SCREEN0) {
screen = SCREEN0_BASE;
@@ -193,7 +171,7 @@
_ram_writeStatus(SEQUENTIAL_MODE);
_ram_prepareCommand(WRITE, address);
for (int i = 0; i < length; i++) {
- _spi.write((_modeflag << 7) | (_comflag << 6) | (_clearflag << 5));
+ _spi.write(AkiLCD_MODE::UPDATE | (_comflag << 6));
_spi.write((uint8_t)lcd_line[line]);
for (int j = 0; j < LINE_LENGTH; j++) {
_spi.write(*data);
@@ -209,19 +187,15 @@
/** copies whole data in screen into LCD
*/
void AkiSpiLcd::ram2lcd(int startline, int length, int screen) {
- _modeflag = 1;
- _clearflag = 0;
screen &= 1;
if (screen == SCREEN0) {
screen = SCREEN0_BASE;
} else {
screen = SCREEN1_BASE;
}
- if (startline == 0)
- startline = 1;
+ if (startline == 0) startline = 1;
if (length > 0) {
-
int address = screen + startline * RAMLINE_LENGTH;
// uint8_t dummy[RAMLINE_LENGTH+2];
int dummy = 0;
@@ -324,12 +298,10 @@
void AkiSpiLcd::_ram_deselect() { _csr = 1; }
void AkiSpiLcd::_cls_ram(int address) {
- _modeflag = 1;
- _clearflag = 0;
_ram_writeStatus(SEQUENTIAL_MODE);
_ram_prepareCommand(WRITE, address);
for (int i = 1; i <= (240); i++) {
- _spi.write((_modeflag << 7) | (_comflag << 6) | (_clearflag << 5));
+ _spi.write(AkiLCD_MODE::UPDATE | (_comflag << 6));
_spi.write((uint8_t)lcd_line[i]);
for (int j = 0; j < 50; j++) {
_spi.write(0x00);
--- a/AkiSpiLcd.h Sun Oct 23 02:27:02 2016 +0900
+++ b/AkiSpiLcd.h Sun Oct 23 17:25:47 2016 +0900
@@ -1,5 +1,4 @@
-/*
-Copyright (c) 2016 Kazuki Yamamoto <k.yamamoto.08136891@gmail.com>
+/* Copyright (c) 2016 Kazuki Yamamoto <k.yamamoto.08136891@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
@@ -21,11 +20,11 @@
* by Kazuki Yamamoto, or _K4ZUKI_
*/
-#ifndef __AKISPILCD_H__
+#ifndef __AKISPILCD_H__ // NOLINT
#define __AKISPILCD_H__
-#include "mbed.h"
-
+#include "MemoryLcd.h"
+#include "mbed.h" //NOLINT
/** \class AkiSpiLcd
* \brief mbed library for SHARP LCD LS027B4DH01
*
@@ -83,8 +82,15 @@
0x0F,
};
+class AkiLCD_MODE : public LCD_MODE {
+ public:
+ static const uint8_t COM_INVERT = 0x00;
+ static const uint8_t CLEAR_SCREEN = 0x20;
+ static const uint8_t UPDATE = 0x80;
+};
+
class AkiSpiLcd {
-public:
+ public:
/** \enum BASE_ADDR
\brief base address list for 23K256
@param SCREEN0_BASE = 0x0000,
@@ -94,7 +100,6 @@
enum BASE_ADDR {
SCREEN0_BASE = 0x0000,
SCREEN1_BASE = 0x4000,
- // RAMLINE_BASE = 0x7000,
};
/** Constructor
@@ -209,7 +214,7 @@
*/
void ram_write(int address, uint8_t *buffer, int count);
-private:
+ private:
// Ser23K256 _ram;
enum MODE { BYTE_MODE = 0x00, SEQUENTIAL_MODE = 0x40 };
@@ -217,13 +222,11 @@
enum COMMAND {
READ = 0x03,
WRITE = 0x02,
- READ_STATUS = 0x05, // called RDSR in datasheet
- WRITE_STATUS = 0x01 // called WRSR in datasheet
+ READ_STATUS = 0x05, // called RDSR in datasheet
+ WRITE_STATUS = 0x01 // called WRSR in datasheet
};
int _comflag;
- int _modeflag;
- int _clearflag;
SPI _spi;
DigitalOut _csl;
DigitalOut _csr;
@@ -235,4 +238,4 @@
void _ram_select();
void _ram_deselect();
};
-#endif
+#endif // NOLINT
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MemoryLcd.cpp Sun Oct 23 17:25:47 2016 +0900
@@ -0,0 +1,99 @@
+/*
+Copyright (c) 2016 Kazuki Yamamoto <k.yamamoto.08136891@gmail.com>
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files
+(the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of the Software,
+and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+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.
+*/
+/** this is base class for Memory LCDs from SHARP or JDI
+* by Kazuki Yamamoto, or _K4ZUKI_
+*/
+// #include "MemoryLcd.h"
+//
+// MemoryLCD::MemoryLCD(PinName mosi, PinName miso, PinName sck, PinName csl)
+// : _spi(mosi, miso, sck), _csl(csl) {
+// _csl = 0;
+// _spi.format(8, 0);
+// _spi.frequency(1000000);
+// _comflag = 0;
+// }
+//
+// void MemoryLCD::cls() {
+// _csl = 1;
+//
+// _spi.write(LCD_MODE::CLEAR_SCREEN | (_comflag << 6));
+// _spi.write(0x00);
+//
+// _csl = 0;
+//
+// cominvert();
+// }
+//
+// void MemoryLCD::directUpdateSingle(int line, uint8_t *data) {
+// _csl = 1;
+// if (line == 0) line = 1;
+//
+// _spi.write(LCD_MODE::UPDATE | (_comflag << 6));
+// _spi.write(line);
+//
+// for (int i = 0; i < 50; i++) {
+// _spi.write(*(data + i));
+// }
+// _spi.write(0x00);
+// _spi.write(0x00);
+//
+// _csl = 0;
+//
+// cominvert();
+// }
+//
+// void MemoryLCD::directUpdateMulti(int line, int length, uint8_t *data) {
+// _modeflag = 1;
+// _clearflag = 0;
+//
+// if (line == 0) line = 1;
+//
+// if (length > 0) {
+// _csl = 1;
+//
+// for (int j = 1; j <= length; j++) {
+// _spi.write(LCD_MODE::UPDATE | (_comflag << 6));
+// _spi.write(line);
+// for (int i = 0; i < 50; i++) {
+// _spi.write(*(data + (50 * j + i))); // hogepic[50*j+i]
+// }
+// line += 1;
+// }
+// _spi.write(0x00);
+// _spi.write(0x00);
+//
+// _csl = 0;
+// }
+// cominvert();
+// }
+//
+// void MemoryLCD::cominvert() {
+// _csl = 1;
+//
+// _spi.write(LCD_MODE::COM_INVERT | (_comflag << 6));
+// _spi.write(0x00);
+//
+// _csl = 0;
+// if (_comflag == 0) {
+// _comflag = 1;
+// } else {
+// _comflag = 0;
+// }
+// }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/MemoryLcd.h Sun Oct 23 17:25:47 2016 +0900
@@ -0,0 +1,73 @@
+/* Copyright (c) 2016 Kazuki Yamamoto <k.yamamoto.08136891@gmail.com>
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files
+(the "Software"), to deal in the Software without restriction,
+including without limitation the rights to use, copy, modify, merge,
+publish, distribute, sublicense, and/or sell copies of the Software,
+and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+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.
+*/
+/** this is base class for Memory LCDs from SHARP or JDI
+* by Kazuki Yamamoto, or _K4ZUKI_
+*/
+
+#ifndef __MEMORYLCD_H__ // NOLINT
+#define __MEMORYLCD_H__
+
+#include "mbed.h" // NOLINT
+
+class LCD_MODE {
+ public:
+ static const uint8_t COM_INVERT = 0;
+ static const uint8_t CLEAR_SCREEN = 0;
+ static const uint8_t UPDATE = 0;
+};
+
+// class MemoryLCD {
+// public:
+// // enum LCD_MODE { COM_INVERT, CLEAR_SCREEN, UPDATE };
+//
+// /** Constructor
+// * @param mosi SPI data output from mbed
+// * @param mosi SPI data input from slave
+// * @param sck SPI clock output from mbed
+// * @param csl chip select input for LCD
+// */
+// MemoryLCD(PinName mosi, PinName miso, PinName sck, PinName csl);
+//
+// /** Clear screen
+// */
+// void cls();
+//
+// /** Writes single line(400 bits = 50 bytes)
+// * @param line line number
+// * @param *data pointer to data
+// */
+// void directUpdateSingle(int line, uint8_t *data);
+//
+// /** Writes multi lines
+// * @param line line number
+// * @param length number of line to write
+// * @param *data pointer to data
+// */
+// void directUpdateMulti(int startline, int length, uint8_t *data);
+//
+// /** Inverting internal COM signal
+// */
+// void cominvert();
+//
+// private:
+// int _comflag;
+// SPI _spi;
+// DigitalOut _csl;
+// };
+#endif // __MEMORYLCD_H__ //NOLINT

