Simple library for UC1701 based GLCD's

Dependents:   Opensmart_LCD_UC1701

With lots of fonts! Will include more in the future. A couple bitmaps have also been added.

Committer:
Anaesthetix
Date:
Mon Dec 19 23:26:17 2016 +0000
Revision:
5:7494bdca926b
Parent:
3:baaa16e24adc
Added basic drawing functions + buffered versions. More will come soon. Has a minor bug with postioning

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Anaesthetix 0:a8cfaf48d064 1 /**
Anaesthetix 0:a8cfaf48d064 2 * This is a simple library for UC1701 controlled graphic LCD's.
Anaesthetix 0:a8cfaf48d064 3 * Written for a cheap OPEN-SMART 1.8" 128x64 display
Anaesthetix 0:a8cfaf48d064 4 * See http://www.dx.com/p/open-smart-1-8-128-64-lcd-display-breakout-module-w-blue-backlit-444694
Anaesthetix 1:f396898c2963 5 *
Anaesthetix 0:a8cfaf48d064 6 * Written by: Erik van de Coevering
Anaesthetix 5:7494bdca926b 7 * With thanks to Tim Barr from whom I've reused some code
Anaesthetix 0:a8cfaf48d064 8 * Use this code in whatever way you like, as long as it stays free of charge!
Anaesthetix 0:a8cfaf48d064 9 */
Anaesthetix 0:a8cfaf48d064 10
Anaesthetix 0:a8cfaf48d064 11 #ifndef UC1701_H
Anaesthetix 0:a8cfaf48d064 12 #define UC1701_H
Anaesthetix 0:a8cfaf48d064 13
Anaesthetix 0:a8cfaf48d064 14 #include "mbed.h"
Anaesthetix 0:a8cfaf48d064 15 #include "font_4x5.h"
Anaesthetix 0:a8cfaf48d064 16 #include "font_5x8.h"
Anaesthetix 0:a8cfaf48d064 17 #include "font_6x6.h"
Anaesthetix 0:a8cfaf48d064 18 #include "font_6x8.h"
Anaesthetix 0:a8cfaf48d064 19 #include "font_7x7.h"
Anaesthetix 0:a8cfaf48d064 20 #include "font_8x8.h"
Anaesthetix 0:a8cfaf48d064 21 #include "font_8x8_1.h"
Anaesthetix 0:a8cfaf48d064 22 #include "bold_font.h"
Anaesthetix 0:a8cfaf48d064 23 #include "font2d_hunter.h"
Anaesthetix 0:a8cfaf48d064 24 #include "font2d_formplex12.h"
Anaesthetix 0:a8cfaf48d064 25 #include "biohazard.h"
Anaesthetix 0:a8cfaf48d064 26 #include "highvoltage.h"
Anaesthetix 0:a8cfaf48d064 27 #include "einstein.h"
Anaesthetix 0:a8cfaf48d064 28 #include "test.h"
Anaesthetix 0:a8cfaf48d064 29 #include "copter.h"
Anaesthetix 0:a8cfaf48d064 30
Anaesthetix 0:a8cfaf48d064 31 #define LCDWIDTH 128
Anaesthetix 0:a8cfaf48d064 32 #define LCDHEIGHT 64
Anaesthetix 0:a8cfaf48d064 33 #define LCDPAGES 8
Anaesthetix 0:a8cfaf48d064 34
Anaesthetix 0:a8cfaf48d064 35 class UC1701
Anaesthetix 0:a8cfaf48d064 36 {
Anaesthetix 0:a8cfaf48d064 37 public:
Anaesthetix 0:a8cfaf48d064 38
Anaesthetix 0:a8cfaf48d064 39 // Constructor
Anaesthetix 0:a8cfaf48d064 40 UC1701(SPI &spi, DigitalOut &lcd_cs, DigitalOut &cd);
Anaesthetix 0:a8cfaf48d064 41
Anaesthetix 0:a8cfaf48d064 42 // Initialize LCD
Anaesthetix 0:a8cfaf48d064 43 void init(void);
Anaesthetix 3:baaa16e24adc 44
Anaesthetix 3:baaa16e24adc 45 // Set contrast (0 - 63), initialized to 40
Anaesthetix 3:baaa16e24adc 46 void setContrast(char contrast);
Anaesthetix 0:a8cfaf48d064 47
Anaesthetix 0:a8cfaf48d064 48 // Place cursor at position
Anaesthetix 0:a8cfaf48d064 49 void setCursor(char column, char line);
Anaesthetix 0:a8cfaf48d064 50
Anaesthetix 0:a8cfaf48d064 51 // Clear screen
Anaesthetix 0:a8cfaf48d064 52 void clear(void);
Anaesthetix 0:a8cfaf48d064 53
Anaesthetix 0:a8cfaf48d064 54 // Fill screen by writing each pixel -> used for optimizing. Use command 0xA5
Anaesthetix 0:a8cfaf48d064 55 void fill(void);
Anaesthetix 0:a8cfaf48d064 56
Anaesthetix 0:a8cfaf48d064 57 // Write text to LCD where font format is a 2-dimensional array (only 96x8, 8x8 pixel fonts supported)
Anaesthetix 0:a8cfaf48d064 58 void writeText2d(char column, char page, const char font_address[96][8], const char *text, int size);
Anaesthetix 0:a8cfaf48d064 59
Anaesthetix 3:baaa16e24adc 60 // Write text to LCD where font format is a 1-dimensional array. Fonts bigger than 8 pix high should work but isn't tested
Anaesthetix 0:a8cfaf48d064 61 void writeText(char column, char page, const char *font_address, const char *str, const uint8_t size);
Anaesthetix 0:a8cfaf48d064 62
Anaesthetix 0:a8cfaf48d064 63 // Draw a 128x64 pixel bitmap
Anaesthetix 0:a8cfaf48d064 64 void drawBitmap(const char *data);
Anaesthetix 5:7494bdca926b 65
Anaesthetix 5:7494bdca926b 66 // Draw a horizontal line, start positions / height / width in pixels
Anaesthetix 5:7494bdca926b 67 void drawLineHor(char posx, char posy, char height, char width);
Anaesthetix 5:7494bdca926b 68
Anaesthetix 5:7494bdca926b 69 // Draw a vertical line, start positions / height / width in pixels
Anaesthetix 5:7494bdca926b 70 void drawLineVert(char posx, char posy, char height, char width);
Anaesthetix 5:7494bdca926b 71
Anaesthetix 5:7494bdca926b 72 //-----------------------------------------------------------------------------------------------------------------------------
Anaesthetix 5:7494bdca926b 73 // Functions below are buffered versions; possible to write things on top of each other without clearing pixels (ORs all data).
Anaesthetix 5:7494bdca926b 74 // Use update() to write buffer to LCD.
Anaesthetix 5:7494bdca926b 75 // Clear buffer before writing 1st time (initialize all values)
Anaesthetix 5:7494bdca926b 76 // writetext / drawbitmap will be added soon
Anaesthetix 5:7494bdca926b 77 //-----------------------------------------------------------------------------------------------------------------------------
Anaesthetix 5:7494bdca926b 78
Anaesthetix 5:7494bdca926b 79 // Clear buffer
Anaesthetix 5:7494bdca926b 80 void clearBuffer(void);
Anaesthetix 5:7494bdca926b 81
Anaesthetix 5:7494bdca926b 82 // Write buffer to LCD
Anaesthetix 5:7494bdca926b 83 void update(void);
Anaesthetix 5:7494bdca926b 84
Anaesthetix 5:7494bdca926b 85 // Draw a horizontal line, start positions / height / width in pixels. Buffered version; possible to write things on top of each other
Anaesthetix 5:7494bdca926b 86 // without clearing pixels (ORs all data). Use update() to write buffer to LCD
Anaesthetix 5:7494bdca926b 87 void drawbufferLineHor(char posx, char posy, char height, char width);
Anaesthetix 5:7494bdca926b 88
Anaesthetix 5:7494bdca926b 89 // Draw a vertical line, start positions / height / width in pixels. Buffered version.
Anaesthetix 5:7494bdca926b 90 void drawbufferLineVert(char posx, char posy, char height, char width);
Anaesthetix 0:a8cfaf48d064 91
Anaesthetix 0:a8cfaf48d064 92 private:
Anaesthetix 0:a8cfaf48d064 93
Anaesthetix 0:a8cfaf48d064 94 SPI *_lcd;
Anaesthetix 0:a8cfaf48d064 95 DigitalOut *_lcd_cs;
Anaesthetix 0:a8cfaf48d064 96 DigitalOut *_lcd_cd;
Anaesthetix 0:a8cfaf48d064 97 uint8_t _lcdbuffer[LCDWIDTH*LCDPAGES];
Anaesthetix 5:7494bdca926b 98 char buff[LCDWIDTH*LCDPAGES];
Anaesthetix 0:a8cfaf48d064 99
Anaesthetix 0:a8cfaf48d064 100 };
Anaesthetix 0:a8cfaf48d064 101
Anaesthetix 0:a8cfaf48d064 102 #endif