Skip to content

Commit 399459a

Browse files
committed
Initial commit
0 parents  commit 399459a

File tree

80 files changed

+26110
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+26110
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

NKKSmartDisplayLCD.cpp

Lines changed: 637 additions & 0 deletions
Large diffs are not rendered by default.

NKKSmartDisplayLCD.h

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
/*********************************************************************
2+
This is a library for NKK LCD 64x32 SmartDisplay
3+
https://www.nkkswitches.com/smartdisplay/
4+
5+
Copyright (c) 2021, IFH
6+
All rights reserved.
7+
8+
GNU General Public License, check license.txt for more information
9+
All text above must be included in any redistribution
10+
*********************************************************************/
11+
/*********************************************************************
12+
2021-02-25
13+
Version: v01 , initial version
14+
Status: Works OK
15+
16+
Key Features:
17+
- Requres an native SPI object (like Arduino one) which handles SPI communications
18+
- Supports two image formats:
19+
1)Normal GFX (first pixel is top left corner, represented by bit0 in the first byte)
20+
2)Native NKK (first pixel is top right corner, represented by bit7 in the first byte, as per NKK specs)
21+
- Supports Landscape (64*32) and Portrait (32*64) display configurations
22+
- Configured by default for LCD 64x32 SmartDisplay but settings could be easily changed
23+
for other resolutions
24+
- Supports two formats for background colour - three bytes RGB and Native NKK (RRGGBBxx)
25+
- Supports a rotation of an image by 180 degrees to accommodate different possible footprints
26+
of an NKK device on your pcb.
27+
- Generates SPI Slave Select(Chip Select) signal to allow management of multiple NKK devices
28+
- Can be used with Adafruit GFX Graphics core which does all the circles, text and fonts,
29+
rectangles, etc. You can get it from https://github.com/adafruit/Adafruit-GFX-Library.
30+
See /examples folder for implementation examples.
31+
- Tested with hardware SPI for Arduino Pro Mini board
32+
- Tested with NKK IS15EBFP4RGB-09YN LCD 64 x 32 Pushbutton, shall work with these models as well:
33+
S15DBFP4RGB
34+
IS15DBFP4RGB-09YN
35+
S15DSBFP4RGB
36+
IS01DBFRGB
37+
IS15EBFP4RGB
38+
IS15ESBFP4RGB
39+
IS01EBFRGB
40+
*********************************************************************/
41+
#ifndef _NKK_SmartDisplayLCD_H_
42+
#define _NKK_SmartDisplayLCD_H_
43+
44+
45+
#include <SPI.h>
46+
47+
/**************************************************************************/
48+
/*!
49+
@brief Class that stores state and functions for interacting with NKK SmartDisplay LCD device.
50+
*/
51+
/**************************************************************************/
52+
class NKK_SmartDisplayLCD {
53+
54+
#define NKK_SmartDisplayLCD_Img_Upload 0x55 /** int 85**/
55+
#define NKK_SmartDisplayLCD_Set_RGB 0x40 /**int 64 **/
56+
#define NKK_SmartDisplayLCD_Set_Bright 0x41 /**int 65**/
57+
#define NKK_SmartDisplayLCD_Reset 0x5e /**int 94**/
58+
#define NKK_SmartDisplayLCD_Reset_data 0x03 /**int 3**/
59+
60+
public:
61+
NKK_SmartDisplayLCD( uint8_t w=64,
62+
uint8_t h=32,
63+
uint8_t isRotate180=0, //0- no rotation* 1 - 180 degree rotation
64+
uint8_t cspin = SS,
65+
uint32_t freqSPI=1000000, // in Hz
66+
SPIClass *SPI_A=&SPI);
67+
68+
69+
~NKK_SmartDisplayLCD(void);
70+
71+
72+
73+
//Setups the SPI interface and hardware
74+
void begin(void);
75+
76+
//Current image
77+
// Note - Arduino compiler (C++ v.11) require the size of the array declared as we use independent arrays per a class instance.
78+
// NKK Smart Display is 64bit*32bit so array size is 256 bytes. Cannot use undefined length like imageBufferGFX[] and initialise
79+
// with values forvided. The library code supports array size up to 65535.
80+
//current image (GFX format)
81+
byte imageBufferGFX[256] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
82+
// current image (NKK native format)
83+
byte imageBufferNKK[256] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
84+
85+
//Colour and Brightness settings for NKK device, in NKK format as per NKK specs
86+
byte bkgColour=255; //background colour, WHITE
87+
byte bkgBrightnes= 31; //background colour brightness, 0FF
88+
89+
//Get current NKK device and Image Buffer settings
90+
uint8_t getWidth(void);
91+
uint8_t getHeigth(void);
92+
uint16_t getImageBufferLength(void);
93+
94+
//NKK commands
95+
//Set background colour
96+
void setColourNKK(byte data); // set as per NKK specs
97+
void setColourRGB(byte R, byte G, byte B); // RGB get converted to the closest colour as per NKK specs (64 colours available)
98+
//Set background colour brightness level
99+
void setBrightness(byte data); //set as per NKK specs
100+
//Reset NKK device
101+
void reset(void);
102+
//Upload an image to the NKK device from imageBufferGFX[], set background colour and brightness
103+
void display(void); // display the GFX format
104+
//Upload an image to the NKK device from imageBufferNKK[], set background colour and brightness
105+
void display_NKK(void); // display the native NKK format
106+
107+
108+
//Image Buffer commands
109+
// Note - these commands need a separate call to display() methods to make the results visible in the display device.
110+
//Draw a pixel in the imageBufferGFX[]
111+
void drawPixel( uint8_t x, uint8_t y, uint8_t color);
112+
//Clear imageBufferGFX[]
113+
void clearImageBufferGFX(void);
114+
//Clear imageBufferNKK[]
115+
void clearImageBufferNKK(void);
116+
//Invert imageBufferGFX[]
117+
void invertImageBufferGFX(void);
118+
//Invert imageBufferNKK[]
119+
void invertImageBufferNKK(void);
120+
//Convert current image buffers from GFX format to NKK native format and vice versa
121+
void convertGFX2NKK(void);
122+
123+
124+
private:
125+
SPIClass *_SPI;
126+
SPISettings *_spiSetting;
127+
uint32_t _freqSPI=1000000;
128+
129+
uint8_t _w=64; //Max w is 256 and Max w*h/8 = 65535 for this library code.
130+
uint8_t _h=32; //Max h is 256 and Max w*h/8 = 65535 for this library code.
131+
uint16_t _imageBufferLength =256; // in bytes, _w*_h/8 , 65535 max
132+
uint8_t _isRotate180 = 0; // no rotation
133+
uint8_t _cs = SS; // SPI Slave Select(Chip Select) pin
134+
135+
136+
//Image Buffer commands and helpers
137+
void convertGFX2NKK(byte imageBufferGFX[], byte imageBufferNKK[]);
138+
void rotate180_NKK(byte imageBufferNKK[]);
139+
byte reverseByte(byte b);
140+
141+
//SPI operations & Slave Select(Chip Select) pin handling per NKK_SmartDisplayLCD instance (thus allows management of multiple NKK devices)
142+
void sendArrayToSPI(byte buffer[], uint16_t length);
143+
void sendImageToSPI(byte buffer[], uint16_t length);
144+
void sendCommandAndDataToSPI(byte command, byte data);
145+
void beginTransaction(void);
146+
void endTransaction(void);
147+
};
148+
#endif // _NKK_SmartDisplayLCD_H_

README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
## Overview:
2+
This is a library for **NKK LCD 64x32 SmartDisplay** (https://www.nkkswitches.com/smartdisplay/)
3+
It has been designed and tested for NKK IS15EBFP4RGB-09YN LCD 64 x 32 Pushbutton and shall work with these models as well:
4+
S15DBFP4RGB
5+
IS15DBFP4RGB-09YN
6+
S15DSBFP4RGB
7+
IS01DBFRGB
8+
IS15EBFP4RGB
9+
IS15ESBFP4RGB
10+
IS01EBFRGB
11+
12+
With minimal changes in configuration settings it shall suppot other LCD resolutions if required.
13+
14+
The library supports:
15+
1. Two image formats:
16+
-Normal GFX (first pixel is top left corner, represented by bit0 in the first byte)
17+
-Native NKK (first pixel is top right corner, represented by bit7 in the first byte, as per NKK specs)
18+
2. Landscape (64x32) and Portrait (32x64) display configurations
19+
3. Two formats for background colour - three bytes RGB format and native NKK format (RRGGBBxx)
20+
4. A rotation of an image by 180 degrees to accommodate different possible footprints of an NKK device on your pcb.
21+
22+
## Library usage:
23+
1. Create a NKK_SmartDisplayLCD object. At this step specify:
24+
w: The NKK LCD screen width in pixels. Maximum w is 256 and Maximum w*h/8 = 65535 for this library code.
25+
h: The NKK LCD screen height in pixels Maximum h is 256 and Maximum w*h/8 = 65535 for this library code.
26+
isRotate180: A flag to indicate that the picture need to be rotated by 180 degrees to accommodate different possible footprints of an NKK device on your pcb. Applied just before the picture is uploaded to the NKK device by the *display()* or *display_NKK()* functions.
27+
cspin: Slave Select(Chip Select) signal (to allow use more than one NKK device with their own SS signals).
28+
freqSPI: SPI frequency, Hz.
29+
pointer: A reference (pointer) to native SPI object which handles SPI communications.
30+
31+
2. Execute *begin()* method. That would start SPI interface and reset the NKK device.
32+
33+
3. Set required background colour and brightness:
34+
- By using library methods that would communicate directly to the NKK device:
35+
```C++
36+
setColourNKK(byte data); // set as per NKK specs (RRGGBBxx)
37+
setColourRGB(byte R, byte G, byte B); // RGB get converted to the closest colour as per NKK specs (64 colours available)
38+
setBrightness(byte data); //set as per NKK specs (BBBxxxxx)
39+
```
40+
- By setting library variables *bkgColour* and *bkgBrightnes* which will be used when the *display()* and *display_NKK()* methods are called
41+
42+
4. Set an image in a GFX or NKK format to library variables *imageBufferGFX[]* and *imageBufferNKK[]*. No need to set both.
43+
You can use an NKK Bitmap bilder (MS Excel file) in the */documentation* folder to build an image in GFX or NKK formats, landscape or portrait.
44+
45+
5. Use *drawPixel(x,y,color)* to set a pixel in the *imageBufferGFX[]*. X and Y are pixel coordunates, starting from 0. For this monochrome
46+
LCD display *color* can be any value, it will be converted either 0 or 1 in the library. This method is also used for integration with Adafruit_GFX library (https://github.com/adafruit/Adafruit-GFX-Library).
47+
48+
6. Execute *display()* or *display_NKK()* methods which will do the following:
49+
- upload an image to the NKK device from *imageBufferGFX[]* or *imageBufferNKK[]* and make the image visible.
50+
*display()* will use *imageBufferGFX[]* as a source and will overwrite *imageBufferNKK[]*.
51+
*display_NKK()* use *imageBufferNKK[]* as a source and does NOT change *imageBufferGFX[]*.
52+
AND
53+
- set NKK device background colour and brightness as per library's variables *bkgColour* and *bkgBrightnes*.
54+
55+
*display()* method is also used for integration with Adafruit_GFX library.
56+
57+
7. Use other NKK_SmartDisplayLCD library methods like *clearImageBufferGFX()*, *invertImageBufferGFX()* etc to manage content of the image bugger you use.
58+
59+
8. Use Adafruit_GFX_Ext object to access to Adafruit_GFX library methods like *setCursor()*, *print()*, *drawPixel()*, *fillRect()* etc to build
60+
or adjust your image in the *imageBufferGFX[]* image buffer. Do not forget to call *display()* method to transfer your image to the NKK device
61+
and make it visible.
62+
63+
See the examples and descriptions of the library functions provided in the code for more details.
64+
65+
66+
## Known Limitations:
67+
Requres a native SPI object (like Arduino one) which handles SPI communications.
68+
With a mimimal changes to the library (an update to the class constructor) it can use
69+
a separate SPI handler such as https://github.com/adafruit/Adafruit_BusIO
70+
71+
72+
## Repository Contents:
73+
*/documentation* - Image Builder (MS Excel file), NKK LCD 64x32 SmartDisplay application notes
74+
*/examples* - examples on how the libraries can be used
75+
76+
77+
## License:
78+
Copyright (c) 2021, IFH
79+
All rights reserved.
80+
81+
NKK_SmartDisplayLCD is free software: you can redistribute it
82+
and/or modify it under the terms of the GNU General Public
83+
License as published by the Free Software Foundation, either
84+
version 3 of the License, or (at your option) any later version
85+
provided that the following conditions are met:
86+
87+
1. Redistributions of source code must retain the above copyright
88+
notice, this list of conditions and the following disclaimer.
89+
2. Redistributions in binary form must reproduce the above copyright
90+
notice, this list of conditions and the following disclaimer in the
91+
documentation and/or other materials provided with the distribution.
92+
3. Neither the name of the copyright holders nor the
93+
names of its contributors may be used to endorse or promote products
94+
derived from this software without specific prior written permission.
95+
96+
97+
NKK_SmartDisplayLCD is provided ''AS IS'' in the hope that it will
98+
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
99+
of MERCHANTABILITY or FITNESS FOR ANY PARTICULAR PURPOSE.
100+
101+
IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
102+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
103+
DAMAGES INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
104+
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
105+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
106+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
107+
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
108+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
109+
110+
See the GNU General Public License for more details.
111+
112+

0 commit comments

Comments
 (0)