Library for New Haven NHD_0420DZW OLED

Committer:
JackB
Date:
Wed Oct 26 12:19:43 2016 +0000
Revision:
0:91420dff6791
Library for New Haven NHD_0420DZW OLED

Who changed what in which revision?

UserRevisionLine numberNew contents of line
JackB 0:91420dff6791 1 #ifndef _NHD_0420DZW_OLED_H_
JackB 0:91420dff6791 2 #define _NHD_0420DZW_OLED_H_
JackB 0:91420dff6791 3
JackB 0:91420dff6791 4 /**
JackB 0:91420dff6791 5 * @file NHD_0420DZW_OLED.h
JackB 0:91420dff6791 6 * @brief this header file will contain the definitions to interface the New Haven
JackB 0:91420dff6791 7 * NHD-0420DZW-AY5 display using a 4-wire software spi bus bus.
JackB 0:91420dff6791 8 * @author Jack Berkhout
JackB 0:91420dff6791 9 *
JackB 0:91420dff6791 10 * @date 2016-10-21
JackB 0:91420dff6791 11 */
JackB 0:91420dff6791 12
JackB 0:91420dff6791 13 /**
JackB 0:91420dff6791 14 * Class for the New Haven NHD-0420DZW-AY5 SPI LCD 4x20
JackB 0:91420dff6791 15 * @author Jack Berkhout
JackB 0:91420dff6791 16 * @date 2016-10-21
JackB 0:91420dff6791 17 */
JackB 0:91420dff6791 18
JackB 0:91420dff6791 19 #include "mbed.h"
JackB 0:91420dff6791 20 //#include "TextDisplay.h"
JackB 0:91420dff6791 21
JackB 0:91420dff6791 22 #define LCD_COMMAND 0
JackB 0:91420dff6791 23 #define LCD_DATA 1
JackB 0:91420dff6791 24 #define LCD_WRITE 0
JackB 0:91420dff6791 25 #define LCD_READ 1
JackB 0:91420dff6791 26
JackB 0:91420dff6791 27 #define LCD_CLEAR_DISPLAY 0x01
JackB 0:91420dff6791 28 #define LCD_RETURN_HOME 0x02
JackB 0:91420dff6791 29 #define LCD_CURSOR_INCR 0x06
JackB 0:91420dff6791 30 #define LCD_DISPLAY_OFF 0x08
JackB 0:91420dff6791 31 #define LCD_DISPLAY_ON 0x0C
JackB 0:91420dff6791 32 #define LCD_FUNCTION_SET 0x38
JackB 0:91420dff6791 33 #define LCD_BUSSY_FLAG 0x80
JackB 0:91420dff6791 34 #define LCD_NUMBER_OF_CHARACTERS 20
JackB 0:91420dff6791 35 #define LCD_NUMBER_OF_LINES 4
JackB 0:91420dff6791 36
JackB 0:91420dff6791 37 #define LCD_LINE_1 0x80
JackB 0:91420dff6791 38 #define LCD_LINE_2 0xC0
JackB 0:91420dff6791 39 #define LCD_LINE_3 0x94
JackB 0:91420dff6791 40 #define LCD_LINE_4 0xD4
JackB 0:91420dff6791 41
JackB 0:91420dff6791 42 #define LCD_CLOCK_PULSE_LENGTH 1
JackB 0:91420dff6791 43 #define LCD_RS_BIT_MASK 0x0200
JackB 0:91420dff6791 44 #define LCD_Rw_BIT_MASK 0x0100
JackB 0:91420dff6791 45
JackB 0:91420dff6791 46 /* set CGRAM addr */
JackB 0:91420dff6791 47 #define LCD_CGRAM(n) (0x40 + ((n) << 3))
JackB 0:91420dff6791 48 // *.... 16
JackB 0:91420dff6791 49 // **... 24
JackB 0:91420dff6791 50 // ***.. 28
JackB 0:91420dff6791 51 // ****. 30
JackB 0:91420dff6791 52 // ***** 31
JackB 0:91420dff6791 53 // *..*. 18
JackB 0:91420dff6791 54 // *..*. 18
JackB 0:91420dff6791 55 // .***. 14
JackB 0:91420dff6791 56
JackB 0:91420dff6791 57 //#define CHARACTERBYTES { \
JackB 0:91420dff6791 58 // 0, 0, 0, 0, 0, 0, 0, 0, \
JackB 0:91420dff6791 59 // 16, 16, 16, 16, 16, 16, 16, 16, \
JackB 0:91420dff6791 60 // 24, 24, 24, 24, 24, 24, 24, 24, \
JackB 0:91420dff6791 61 // 28, 28, 28, 28, 28, 28, 28, 28, \
JackB 0:91420dff6791 62 // 30, 30, 30, 30, 30, 30, 30, 30, \
JackB 0:91420dff6791 63 // 31, 31, 31, 31, 31, 31, 31, 31, \
JackB 0:91420dff6791 64 // 1, 1, 1, 1, 1, 1, 1, 1 \
JackB 0:91420dff6791 65 //}
JackB 0:91420dff6791 66
JackB 0:91420dff6791 67 #define CHARACTERBYTES { \
JackB 0:91420dff6791 68 0, 0, 0, 0, 0, 0, 0, 0, \
JackB 0:91420dff6791 69 0, 0, 0, 16, 16, 0, 0, 0, \
JackB 0:91420dff6791 70 0, 0, 0, 24, 24, 0, 0, 0, \
JackB 0:91420dff6791 71 0, 0, 0, 28, 28, 0, 0, 0, \
JackB 0:91420dff6791 72 0, 0, 0, 30, 30, 0, 0, 0, \
JackB 0:91420dff6791 73 0, 0, 0, 31, 31, 0, 0, 0, \
JackB 0:91420dff6791 74 0, 0, 0, 0, 0, 0, 0, 0, \
JackB 0:91420dff6791 75 0, 0, 0, 0, 0, 0, 0, 0 \
JackB 0:91420dff6791 76 }
JackB 0:91420dff6791 77
JackB 0:91420dff6791 78 //class NHD_0420DZW_OLED {
JackB 0:91420dff6791 79 class NHD_0420DZW_OLED : public Stream {
JackB 0:91420dff6791 80 public:
JackB 0:91420dff6791 81 /**
JackB 0:91420dff6791 82 * @brief Create a new Class to interface to an NH-0216K3Z-NSW-BBW 2x16 Character LCD from New Haven
JackB 0:91420dff6791 83 **/
JackB 0:91420dff6791 84 NHD_0420DZW_OLED(PinName mosi, PinName miso, PinName sck, PinName cs, const char *name);
JackB 0:91420dff6791 85
JackB 0:91420dff6791 86 void init(void);
JackB 0:91420dff6791 87
JackB 0:91420dff6791 88 void cls(void);
JackB 0:91420dff6791 89 void cursorHome(void);
JackB 0:91420dff6791 90
JackB 0:91420dff6791 91 void writeCharacter(int column, int row, int c);
JackB 0:91420dff6791 92 void writeCharacter(char character);
JackB 0:91420dff6791 93 void writeString(char *charString);
JackB 0:91420dff6791 94 void writeString(int y, char *charString);
JackB 0:91420dff6791 95 void writeString(int x, int y, char *charString);
JackB 0:91420dff6791 96 void clearLine(int y);
JackB 0:91420dff6791 97 void clearRegion(int x, int y, int length);
JackB 0:91420dff6791 98 void locate(int X, int Y);
JackB 0:91420dff6791 99 void drawBar(int X, int Y, int Value, int Max);
JackB 0:91420dff6791 100
JackB 0:91420dff6791 101 virtual bool claim (FILE *stream);
JackB 0:91420dff6791 102
JackB 0:91420dff6791 103 private:
JackB 0:91420dff6791 104 DigitalOut _lcd_csb;
JackB 0:91420dff6791 105 DigitalOut _lcd_scl;
JackB 0:91420dff6791 106 DigitalOut _lcd_sdi;
JackB 0:91420dff6791 107 DigitalIn _lcd_sdo;
JackB 0:91420dff6791 108
JackB 0:91420dff6791 109 void writeCommand(int data);
JackB 0:91420dff6791 110 void writeData(int data);
JackB 0:91420dff6791 111 int readAddress(void);
JackB 0:91420dff6791 112 void waitBusy(void);
JackB 0:91420dff6791 113 int readBusyFlag(void);
JackB 0:91420dff6791 114 void writeSerial(int rs, int rw, int data);
JackB 0:91420dff6791 115 int serialInstruction(int rs, int rw, int data1, int data2);
JackB 0:91420dff6791 116 int serialData(int rs, int rw, int data1, int data2);
JackB 0:91420dff6791 117 int clockSerial(int dataOut, int bits);
JackB 0:91420dff6791 118 void selectSerial(bool select);
JackB 0:91420dff6791 119
JackB 0:91420dff6791 120 // https://developer.mbed.org/users/4180_1/notebook/how-to-get-printf-to-work-in-a-new-display-driver-/
JackB 0:91420dff6791 121 //and add this to the end of the class
JackB 0:91420dff6791 122 protected:
JackB 0:91420dff6791 123 //used by printf - supply a new _putc virtual function for the new device
JackB 0:91420dff6791 124 virtual int _putc(int c) {
JackB 0:91420dff6791 125 writeData(c); //your new LCD put to print an ASCII character on LCD
JackB 0:91420dff6791 126 return 0;
JackB 0:91420dff6791 127 };
JackB 0:91420dff6791 128 //assuming no reads from LCD
JackB 0:91420dff6791 129 virtual int _getc() {
JackB 0:91420dff6791 130 return -1;
JackB 0:91420dff6791 131 }
JackB 0:91420dff6791 132
JackB 0:91420dff6791 133 // character location
JackB 0:91420dff6791 134 uint16_t _column;
JackB 0:91420dff6791 135 uint16_t _row;
JackB 0:91420dff6791 136 char *_path;
JackB 0:91420dff6791 137
JackB 0:91420dff6791 138 };
JackB 0:91420dff6791 139 #endif