A simple library for SSH1106 controlled GLCDs
SSH1106.h@1:ac9efaadd666, 2016-12-19 (annotated)
- Committer:
- Anaesthetix
- Date:
- Mon Dec 19 23:23:41 2016 +0000
- Revision:
- 1:ac9efaadd666
- Parent:
- 0:3cd0a11a2f91
Added basic drawing functions + buffered versions. More will come soon. Has a minor bug with postioning
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Anaesthetix | 0:3cd0a11a2f91 | 1 | /** |
Anaesthetix | 0:3cd0a11a2f91 | 2 | * This is a simple library for SSH1106 controlled graphic LCD's. |
Anaesthetix | 0:3cd0a11a2f91 | 3 | * Written for a 1.3" OLED GLCD |
Anaesthetix | 0:3cd0a11a2f91 | 4 | * See http://www.banggood.com/1_3-Inch-7Pin-White-OLED-12864-SPI-Interface-LCD-Display-Module-For-Arduino-p-1067872.html |
Anaesthetix | 0:3cd0a11a2f91 | 5 | * |
Anaesthetix | 0:3cd0a11a2f91 | 6 | * Written by: Erik van de Coevering |
Anaesthetix | 0:3cd0a11a2f91 | 7 | * With thanks to Tim Barr from whom I've reused some code |
Anaesthetix | 0:3cd0a11a2f91 | 8 | * Use this code in whatever way you like, as long as it stays free of charge! |
Anaesthetix | 0:3cd0a11a2f91 | 9 | */ |
Anaesthetix | 0:3cd0a11a2f91 | 10 | |
Anaesthetix | 0:3cd0a11a2f91 | 11 | #ifndef SSH1106_H |
Anaesthetix | 0:3cd0a11a2f91 | 12 | #define SSH1106_H |
Anaesthetix | 0:3cd0a11a2f91 | 13 | |
Anaesthetix | 0:3cd0a11a2f91 | 14 | #include "mbed.h" |
Anaesthetix | 0:3cd0a11a2f91 | 15 | #include "font_4x5.h" |
Anaesthetix | 0:3cd0a11a2f91 | 16 | #include "font_5x8.h" |
Anaesthetix | 0:3cd0a11a2f91 | 17 | #include "font_6x6.h" |
Anaesthetix | 0:3cd0a11a2f91 | 18 | #include "font_6x8.h" |
Anaesthetix | 0:3cd0a11a2f91 | 19 | #include "font_7x7.h" |
Anaesthetix | 0:3cd0a11a2f91 | 20 | #include "font_8x8.h" |
Anaesthetix | 0:3cd0a11a2f91 | 21 | #include "font_8x8_1.h" |
Anaesthetix | 0:3cd0a11a2f91 | 22 | #include "bold_font.h" |
Anaesthetix | 0:3cd0a11a2f91 | 23 | #include "font2d_hunter.h" |
Anaesthetix | 0:3cd0a11a2f91 | 24 | #include "font2d_formplex12.h" |
Anaesthetix | 0:3cd0a11a2f91 | 25 | #include "biohazard.h" |
Anaesthetix | 0:3cd0a11a2f91 | 26 | #include "highvoltage.h" |
Anaesthetix | 0:3cd0a11a2f91 | 27 | #include "einstein.h" |
Anaesthetix | 0:3cd0a11a2f91 | 28 | #include "test.h" |
Anaesthetix | 0:3cd0a11a2f91 | 29 | #include "copter.h" |
Anaesthetix | 0:3cd0a11a2f91 | 30 | |
Anaesthetix | 0:3cd0a11a2f91 | 31 | #define LCDWIDTH 128 |
Anaesthetix | 0:3cd0a11a2f91 | 32 | #define LCDHEIGHT 64 |
Anaesthetix | 0:3cd0a11a2f91 | 33 | #define LCDPAGES 8 |
Anaesthetix | 0:3cd0a11a2f91 | 34 | |
Anaesthetix | 0:3cd0a11a2f91 | 35 | class SSH1106 |
Anaesthetix | 0:3cd0a11a2f91 | 36 | { |
Anaesthetix | 0:3cd0a11a2f91 | 37 | public: |
Anaesthetix | 0:3cd0a11a2f91 | 38 | |
Anaesthetix | 0:3cd0a11a2f91 | 39 | // Constructor |
Anaesthetix | 0:3cd0a11a2f91 | 40 | SSH1106(SPI &spi, DigitalOut &lcd_cs, DigitalOut &cd, DigitalOut &rst); |
Anaesthetix | 0:3cd0a11a2f91 | 41 | |
Anaesthetix | 0:3cd0a11a2f91 | 42 | // Initialize LCD |
Anaesthetix | 0:3cd0a11a2f91 | 43 | void init(void); |
Anaesthetix | 0:3cd0a11a2f91 | 44 | |
Anaesthetix | 0:3cd0a11a2f91 | 45 | // Set contrast (0 - 63), initialized to 40 |
Anaesthetix | 0:3cd0a11a2f91 | 46 | void setContrast(char contrast); |
Anaesthetix | 0:3cd0a11a2f91 | 47 | |
Anaesthetix | 0:3cd0a11a2f91 | 48 | // Place cursor at position |
Anaesthetix | 0:3cd0a11a2f91 | 49 | void setCursor(char column, char line); |
Anaesthetix | 0:3cd0a11a2f91 | 50 | |
Anaesthetix | 0:3cd0a11a2f91 | 51 | // Clear screen |
Anaesthetix | 0:3cd0a11a2f91 | 52 | void clear(void); |
Anaesthetix | 0:3cd0a11a2f91 | 53 | |
Anaesthetix | 1:ac9efaadd666 | 54 | // Write text to LCD where font format is a 2-dimensional array (only 96x8 byte, 8x8 pixel fonts supported) |
Anaesthetix | 0:3cd0a11a2f91 | 55 | void writeText2d(char column, char page, const char font_address[96][8], const char *text, int size); |
Anaesthetix | 0:3cd0a11a2f91 | 56 | |
Anaesthetix | 1:ac9efaadd666 | 57 | // Write text to LCD where font format is a 1-dimensional array. >8 pixel fonts are not working yet, will update soon |
Anaesthetix | 0:3cd0a11a2f91 | 58 | void writeText(char column, char page, const char *font_address, const char *str, const uint8_t size); |
Anaesthetix | 0:3cd0a11a2f91 | 59 | |
Anaesthetix | 0:3cd0a11a2f91 | 60 | // Draw a 128x64 pixel bitmap |
Anaesthetix | 0:3cd0a11a2f91 | 61 | void drawBitmap(const char *data); |
Anaesthetix | 1:ac9efaadd666 | 62 | |
Anaesthetix | 1:ac9efaadd666 | 63 | // Draw a horizontal line, start positions / height / width in pixels |
Anaesthetix | 1:ac9efaadd666 | 64 | void drawLineHor(char posx, char posy, char height, char width); |
Anaesthetix | 1:ac9efaadd666 | 65 | |
Anaesthetix | 1:ac9efaadd666 | 66 | // Draw a vertical line, start positions / height / width in pixels |
Anaesthetix | 1:ac9efaadd666 | 67 | void drawLineVert(char posx, char posy, char height, char width); |
Anaesthetix | 1:ac9efaadd666 | 68 | |
Anaesthetix | 1:ac9efaadd666 | 69 | //----------------------------------------------------------------------------------------------------------------------------- |
Anaesthetix | 1:ac9efaadd666 | 70 | // Functions below are buffered versions; possible to write things on top of each other without clearing pixels (ORs all data). |
Anaesthetix | 1:ac9efaadd666 | 71 | // Use update() to write buffer to LCD. |
Anaesthetix | 1:ac9efaadd666 | 72 | // Clear buffer before writing 1st time (initialize all values) |
Anaesthetix | 1:ac9efaadd666 | 73 | // writetext / drawbitmap will be added soon |
Anaesthetix | 1:ac9efaadd666 | 74 | //----------------------------------------------------------------------------------------------------------------------------- |
Anaesthetix | 1:ac9efaadd666 | 75 | |
Anaesthetix | 1:ac9efaadd666 | 76 | // Clear buffer |
Anaesthetix | 1:ac9efaadd666 | 77 | void clearBuffer(void); |
Anaesthetix | 1:ac9efaadd666 | 78 | |
Anaesthetix | 1:ac9efaadd666 | 79 | // Write buffer to LCD |
Anaesthetix | 1:ac9efaadd666 | 80 | void update(void); |
Anaesthetix | 1:ac9efaadd666 | 81 | |
Anaesthetix | 1:ac9efaadd666 | 82 | // Draw a horizontal line, start positions / height / width in pixels. Buffered version; possible to write things on top of each other |
Anaesthetix | 1:ac9efaadd666 | 83 | // without clearing pixels (ORs all data). Use update() to write buffer to LCD |
Anaesthetix | 1:ac9efaadd666 | 84 | void drawbufferLineHor(char posx, char posy, char height, char width); |
Anaesthetix | 1:ac9efaadd666 | 85 | |
Anaesthetix | 1:ac9efaadd666 | 86 | // Draw a vertical line, start positions / height / width in pixels. Buffered version. |
Anaesthetix | 1:ac9efaadd666 | 87 | void drawbufferLineVert(char posx, char posy, char height, char width); |
Anaesthetix | 0:3cd0a11a2f91 | 88 | |
Anaesthetix | 0:3cd0a11a2f91 | 89 | private: |
Anaesthetix | 0:3cd0a11a2f91 | 90 | |
Anaesthetix | 0:3cd0a11a2f91 | 91 | SPI *_lcd; |
Anaesthetix | 0:3cd0a11a2f91 | 92 | DigitalOut *_lcd_cs; |
Anaesthetix | 0:3cd0a11a2f91 | 93 | DigitalOut *_lcd_cd; |
Anaesthetix | 0:3cd0a11a2f91 | 94 | DigitalOut *_lcd_rst; |
Anaesthetix | 0:3cd0a11a2f91 | 95 | uint8_t _lcdbuffer[LCDWIDTH*LCDPAGES]; |
Anaesthetix | 1:ac9efaadd666 | 96 | char buff[LCDWIDTH*LCDPAGES]; |
Anaesthetix | 0:3cd0a11a2f91 | 97 | |
Anaesthetix | 0:3cd0a11a2f91 | 98 | }; |
Anaesthetix | 0:3cd0a11a2f91 | 99 | |
Anaesthetix | 0:3cd0a11a2f91 | 100 | #endif |