Fork of Smoothie to port to mbed non-LPC targets.

Dependencies:   mbed

Fork of Smoothie by Stéphane Cachat

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers RrdGlcd.cpp Source File

RrdGlcd.cpp

00001 #include "RrdGlcd.h"
00002 
00003 #include "platform_memory.h"
00004 
00005 static const uint8_t font5x8[] = {
00006     // 5x8 font each byte is consecutive x bits left aligned then each subsequent byte is Y 8 bytes per character
00007     // TODO probably only need someof these characters not all 256
00008     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x70,0xF8,0xA8,0xF8,0xD8,0x88,0x70,0x00, // 0x00, 0x01
00009     0x70,0xF8,0xA8,0xF8,0x88,0xD8,0x70,0x00, 0x00,0x50,0xF8,0xF8,0xF8,0x70,0x20,0x00, // 0x02, 0x03
00010     0x00,0x20,0x70,0xF8,0xF8,0x70,0x20,0x00, 0x70,0x50,0xF8,0xA8,0xF8,0x20,0x70,0x00, // 0x04, 0x05
00011     0x20,0x70,0xF8,0xF8,0xF8,0x20,0x70,0x00, 0x00,0x00,0x20,0x70,0x70,0x20,0x00,0x00, // 0x06, 0x07
00012     0xF8,0xF8,0xD8,0x88,0x88,0xD8,0xF8,0xF8, 0x00,0x00,0x20,0x50,0x50,0x20,0x00,0x00, // 0x08, 0x09
00013     0xF8,0xF8,0xD8,0xA8,0xA8,0xD8,0xF8,0xF8, 0x00,0x38,0x18,0x68,0xA0,0xA0,0x40,0x00, // 0x0A, 0x0B
00014     0x70,0x88,0x88,0x70,0x20,0xF8,0x20,0x00, 0x78,0x48,0x78,0x40,0x40,0x40,0xC0,0x00, // 0x0C, 0x0D
00015     0x78,0x48,0x78,0x48,0x48,0x58,0xC0,0x00, 0x20,0xA8,0x70,0xD8,0xD8,0x70,0xA8,0x20, // 0x0E, 0x0F
00016     0x80,0xC0,0xF0,0xF8,0xF0,0xC0,0x80,0x00, 0x08,0x18,0x78,0xF8,0x78,0x18,0x08,0x00, // 0x10, 0x11
00017     0x20,0x70,0xA8,0x20,0xA8,0x70,0x20,0x00, 0xD8,0xD8,0xD8,0xD8,0xD8,0x00,0xD8,0x00, // 0x12, 0x13
00018     0x78,0xA8,0xA8,0x68,0x28,0x28,0x28,0x00, 0x30,0x48,0x50,0x28,0x10,0x48,0x48,0x30, // 0x14, 0x15
00019     0x00,0x00,0x00,0x00,0x00,0xF8,0xF8,0x00, 0x20,0x70,0xA8,0x20,0xA8,0x70,0x20,0xF8, // 0x16, 0x17
00020     0x00,0x20,0x70,0xA8,0x20,0x20,0x20,0x00, 0x00,0x20,0x20,0x20,0xA8,0x70,0x20,0x00, // 0x18, 0x19
00021     0x00,0x20,0x10,0xF8,0x10,0x20,0x00,0x00, 0x00,0x20,0x40,0xF8,0x40,0x20,0x00,0x00, // 0x1A, 0x1B
00022     0x00,0x80,0x80,0x80,0xF8,0x00,0x00,0x00, 0x00,0x50,0xF8,0xF8,0x50,0x00,0x00,0x00, // 0x1C, 0x1D
00023     0x00,0x20,0x20,0x70,0xF8,0xF8,0x00,0x00, 0x00,0xF8,0xF8,0x70,0x20,0x20,0x00,0x00, // 0x1E, 0x1F
00024     0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x20,0x20,0x20,0x20,0x20,0x00,0x20,0x00, // 0x20, 0x21
00025     0x50,0x50,0x50,0x00,0x00,0x00,0x00,0x00, 0x50,0x50,0xF8,0x50,0xF8,0x50,0x50,0x00, // 0x22, 0x23
00026     0x20,0x78,0xA0,0x70,0x28,0xF0,0x20,0x00, 0xC0,0xC8,0x10,0x20,0x40,0x98,0x18,0x00, // 0x24, 0x25
00027     0x40,0xA0,0xA0,0x40,0xA8,0x90,0x68,0x00, 0x30,0x30,0x20,0x40,0x00,0x00,0x00,0x00, // 0x26, 0x27
00028     0x10,0x20,0x40,0x40,0x40,0x20,0x10,0x00, 0x40,0x20,0x10,0x10,0x10,0x20,0x40,0x00, // 0x28, 0x29
00029     0x20,0xA8,0x70,0xF8,0x70,0xA8,0x20,0x00, 0x00,0x20,0x20,0xF8,0x20,0x20,0x00,0x00, // 0x2A, 0x2B
00030     0x00,0x00,0x00,0x00,0x30,0x30,0x20,0x40, 0x00,0x00,0x00,0xF8,0x00,0x00,0x00,0x00, // 0x2C, 0x2D
00031     0x00,0x00,0x00,0x00,0x00,0x30,0x30,0x00, 0x00,0x08,0x10,0x20,0x40,0x80,0x00,0x00, // 0x2E, 0x2F
00032     0x70,0x88,0x98,0xA8,0xC8,0x88,0x70,0x00, 0x20,0x60,0x20,0x20,0x20,0x20,0x70,0x00, // 0x30, 0x31
00033     0x70,0x88,0x08,0x70,0x80,0x80,0xF8,0x00, 0xF8,0x08,0x10,0x30,0x08,0x88,0x70,0x00, // 0x32, 0x33
00034     0x10,0x30,0x50,0x90,0xF8,0x10,0x10,0x00, 0xF8,0x80,0xF0,0x08,0x08,0x88,0x70,0x00, // 0x34, 0x35
00035     0x38,0x40,0x80,0xF0,0x88,0x88,0x70,0x00, 0xF8,0x08,0x08,0x10,0x20,0x40,0x80,0x00, // 0x36, 0x37
00036     0x70,0x88,0x88,0x70,0x88,0x88,0x70,0x00, 0x70,0x88,0x88,0x78,0x08,0x10,0xE0,0x00, // 0x38, 0x39
00037     0x00,0x00,0x20,0x00,0x20,0x00,0x00,0x00, 0x00,0x00,0x20,0x00,0x20,0x20,0x40,0x00, // 0x3A, 0x3B
00038     0x08,0x10,0x20,0x40,0x20,0x10,0x08,0x00, 0x00,0x00,0xF8,0x00,0xF8,0x00,0x00,0x00, // 0x3C, 0x3D
00039     0x40,0x20,0x10,0x08,0x10,0x20,0x40,0x00, 0x70,0x88,0x08,0x30,0x20,0x00,0x20,0x00, // 0x3E, 0x3F
00040     0x70,0x88,0xA8,0xB8,0xB0,0x80,0x78,0x00, 0x20,0x50,0x88,0x88,0xF8,0x88,0x88,0x00, // 0x40, 0x41
00041     0xF0,0x88,0x88,0xF0,0x88,0x88,0xF0,0x00, 0x70,0x88,0x80,0x80,0x80,0x88,0x70,0x00, // 0x42, 0x43
00042     0xF0,0x88,0x88,0x88,0x88,0x88,0xF0,0x00, 0xF8,0x80,0x80,0xF0,0x80,0x80,0xF8,0x00, // 0x44, 0x45
00043     0xF8,0x80,0x80,0xF0,0x80,0x80,0x80,0x00, 0x78,0x88,0x80,0x80,0x98,0x88,0x78,0x00, // 0x46, 0x47
00044     0x88,0x88,0x88,0xF8,0x88,0x88,0x88,0x00, 0x70,0x20,0x20,0x20,0x20,0x20,0x70,0x00, // 0x48, 0x49
00045     0x38,0x10,0x10,0x10,0x10,0x90,0x60,0x00, 0x88,0x90,0xA0,0xC0,0xA0,0x90,0x88,0x00, // 0x4A, 0x4B
00046     0x80,0x80,0x80,0x80,0x80,0x80,0xF8,0x00, 0x88,0xD8,0xA8,0xA8,0xA8,0x88,0x88,0x00, // 0x4C, 0x4D
00047     0x88,0x88,0xC8,0xA8,0x98,0x88,0x88,0x00, 0x70,0x88,0x88,0x88,0x88,0x88,0x70,0x00, // 0x4E, 0x4F
00048     0xF0,0x88,0x88,0xF0,0x80,0x80,0x80,0x00, 0x70,0x88,0x88,0x88,0xA8,0x90,0x68,0x00, // 0x50, 0x51
00049     0xF0,0x88,0x88,0xF0,0xA0,0x90,0x88,0x00, 0x70,0x88,0x80,0x70,0x08,0x88,0x70,0x00, // 0x52, 0x53
00050     0xF8,0xA8,0x20,0x20,0x20,0x20,0x20,0x00, 0x88,0x88,0x88,0x88,0x88,0x88,0x70,0x00, // 0x54, 0x55
00051     0x88,0x88,0x88,0x88,0x88,0x50,0x20,0x00, 0x88,0x88,0x88,0xA8,0xA8,0xA8,0x50,0x00, // 0x56, 0x57
00052     0x88,0x88,0x50,0x20,0x50,0x88,0x88,0x00, 0x88,0x88,0x50,0x20,0x20,0x20,0x20,0x00, // 0x58, 0x59
00053     0xF8,0x08,0x10,0x70,0x40,0x80,0xF8,0x00, 0x78,0x40,0x40,0x40,0x40,0x40,0x78,0x00, // 0x5A, 0x5B
00054     0x00,0x80,0x40,0x20,0x10,0x08,0x00,0x00, 0x78,0x08,0x08,0x08,0x08,0x08,0x78,0x00, // 0x5C, 0x5D
00055     0x20,0x50,0x88,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0xF8,0x00, // 0x5E, 0x5F
00056     0x60,0x60,0x20,0x10,0x00,0x00,0x00,0x00, 0x00,0x00,0x60,0x10,0x70,0x90,0x78,0x00, // 0x60, 0x61
00057     0x80,0x80,0xB0,0xC8,0x88,0xC8,0xB0,0x00, 0x00,0x00,0x70,0x88,0x80,0x88,0x70,0x00, // 0x62, 0x63
00058     0x08,0x08,0x68,0x98,0x88,0x98,0x68,0x00, 0x00,0x00,0x70,0x88,0xF8,0x80,0x70,0x00, // 0x64, 0x65
00059     0x10,0x28,0x20,0x70,0x20,0x20,0x20,0x00, 0x00,0x00,0x70,0x98,0x98,0x68,0x08,0x70, // 0x66, 0x67
00060     0x80,0x80,0xB0,0xC8,0x88,0x88,0x88,0x00, 0x20,0x00,0x60,0x20,0x20,0x20,0x70,0x00, // 0x68, 0x69
00061     0x10,0x00,0x10,0x10,0x10,0x90,0x60,0x00, 0x80,0x80,0x90,0xA0,0xC0,0xA0,0x90,0x00, // 0x6A, 0x6B
00062     0x60,0x20,0x20,0x20,0x20,0x20,0x70,0x00, 0x00,0x00,0xD0,0xA8,0xA8,0xA8,0xA8,0x00, // 0x6C, 0x6D
00063     0x00,0x00,0xB0,0xC8,0x88,0x88,0x88,0x00, 0x00,0x00,0x70,0x88,0x88,0x88,0x70,0x00, // 0x6E, 0x6F
00064     0x00,0x00,0xB0,0xC8,0xC8,0xB0,0x80,0x80, 0x00,0x00,0x68,0x98,0x98,0x68,0x08,0x08, // 0x70, 0x71
00065     0x00,0x00,0xB0,0xC8,0x80,0x80,0x80,0x00, 0x00,0x00,0x78,0x80,0x70,0x08,0xF0,0x00, // 0x72, 0x73
00066     0x20,0x20,0xF8,0x20,0x20,0x28,0x10,0x00, 0x00,0x00,0x88,0x88,0x88,0x98,0x68,0x00, // 0x74, 0x75
00067     0x00,0x00,0x88,0x88,0x88,0x50,0x20,0x00, 0x00,0x00,0x88,0x88,0xA8,0xA8,0x50,0x00, // 0x76, 0x77
00068     0x00,0x00,0x88,0x50,0x20,0x50,0x88,0x00, 0x00,0x00,0x88,0x88,0x78,0x08,0x88,0x70, // 0x78, 0x79
00069     0x00,0x00,0xF8,0x10,0x20,0x40,0xF8,0x00, 0x10,0x20,0x20,0x40,0x20,0x20,0x10,0x00, // 0x7A, 0x7B
00070     0x20,0x20,0x20,0x00,0x20,0x20,0x20,0x00, 0x40,0x20,0x20,0x10,0x20,0x20,0x40,0x00, // 0x7C, 0x7D
00071     0x80,0xC0,0xF0,0xF8,0xF0,0xC0,0x80,0x00, 0x20,0x70,0xD8,0x88,0x88,0xF8,0x00,0x00, // 0x7E, 0x7F // 7e ~ = 0x40,0xA8,0x10,0x00,0x00,0x00,0x00,0x00
00072     0x70,0x88,0x80,0x80,0x88,0x70,0x10,0x60, 0x00,0x88,0x00,0x88,0x88,0x98,0x68,0x00, // 0x80, 0x81
00073     0x18,0x00,0x70,0x88,0xF8,0x80,0x78,0x00, 0xF8,0x00,0x60,0x10,0x70,0x90,0x78,0x00, // 0x82, 0x83
00074     0x88,0x00,0x60,0x10,0x70,0x90,0x78,0x00, 0xC0,0x00,0x60,0x10,0x70,0x90,0x78,0x00, // 0x84, 0x85
00075     0x30,0x00,0x60,0x10,0x70,0x90,0x78,0x00, 0x00,0x78,0xC0,0xC0,0x78,0x10,0x30,0x00, // 0x86, 0x87
00076     0xF8,0x00,0x70,0x88,0xF8,0x80,0x78,0x00, 0x88,0x00,0x70,0x88,0xF8,0x80,0x78,0x00, // 0x88, 0x89
00077     0xC0,0x00,0x70,0x88,0xF8,0x80,0x78,0x00, 0x28,0x00,0x30,0x10,0x10,0x10,0x38,0x00, // 0x8A, 0x8B
00078     0x30,0x48,0x30,0x10,0x10,0x10,0x38,0x00, 0x60,0x00,0x30,0x10,0x10,0x10,0x38,0x00, // 0x8C, 0x8D
00079     0x50,0x00,0x20,0x50,0x88,0xF8,0x88,0x88, 0x20,0x00,0x20,0x50,0x88,0xF8,0x88,0x88, // 0x8E, 0x8F
00080     0x30,0x00,0xF0,0x80,0xE0,0x80,0xF0,0x00, 0x00,0x00,0x78,0x10,0x78,0x90,0x78,0x00, // 0x90, 0x91
00081     0x38,0x50,0x90,0xF8,0x90,0x90,0x98,0x00, 0x70,0x88,0x00,0x70,0x88,0x88,0x70,0x00, // 0x92, 0x93
00082     0x00,0x88,0x00,0x70,0x88,0x88,0x70,0x00, 0x00,0xC0,0x00,0x70,0x88,0x88,0x70,0x00, // 0x94, 0x95
00083     0x70,0x88,0x00,0x88,0x88,0x98,0x68,0x00, 0x00,0xC0,0x00,0x88,0x88,0x98,0x68,0x00, // 0x96, 0x97
00084     0x48,0x00,0x48,0x48,0x48,0x38,0x08,0x70, 0x88,0x00,0x70,0x88,0x88,0x88,0x70,0x00, // 0x98, 0x99
00085     0x88,0x00,0x88,0x88,0x88,0x88,0x70,0x00, 0x20,0x20,0xF8,0xA0,0xA0,0xF8,0x20,0x20, // 0x9A, 0x9B
00086     0x30,0x58,0x48,0xE0,0x40,0x48,0xF8,0x00, 0xD8,0xD8,0x70,0xF8,0x20,0xF8,0x20,0x20, // 0x9C, 0x9D
00087     0xE0,0x90,0x90,0xE0,0x90,0xB8,0x90,0x90, 0x18,0x28,0x20,0x70,0x20,0x20,0xA0,0xC0, // 0x9E, 0x9F
00088     0x18,0x00,0x60,0x10,0x70,0x90,0x78,0x00, 0x18,0x00,0x30,0x10,0x10,0x10,0x38,0x00, // 0xA0, 0xA1
00089     0x00,0x18,0x00,0x70,0x88,0x88,0x70,0x00, 0x00,0x18,0x00,0x88,0x88,0x98,0x68,0x00, // 0xA2, 0xA3
00090     0x00,0x78,0x00,0x70,0x48,0x48,0x48,0x00, 0xF8,0x00,0xC8,0xE8,0xB8,0x98,0x88,0x00, // 0xA4, 0xA5
00091     0x70,0x90,0x90,0x78,0x00,0xF8,0x00,0x00, 0x70,0x88,0x88,0x70,0x00,0xF8,0x00,0x00, // 0xA6, 0xA7
00092     0x20,0x00,0x20,0x60,0x80,0x88,0x70,0x00, 0x00,0x00,0x00,0xF8,0x80,0x80,0x00,0x00, // 0xA8, 0xA9
00093     0x00,0x00,0x00,0xF8,0x08,0x08,0x00,0x00, 0x80,0x88,0x90,0xB8,0x48,0x98,0x20,0x38, // 0xAA, 0xAB
00094     0x80,0x88,0x90,0xA8,0x58,0xB8,0x08,0x08, 0x20,0x20,0x00,0x20,0x20,0x20,0x20,0x00, // 0xAC, 0xAD
00095     0x00,0x28,0x50,0xA0,0x50,0x28,0x00,0x00, 0x00,0xA0,0x50,0x28,0x50,0xA0,0x00,0x00, // 0xAE, 0xAF
00096     0x20,0x88,0x20,0x88,0x20,0x88,0x20,0x88, 0x50,0xA8,0x50,0xA8,0x50,0xA8,0x50,0xA8, // 0xB0, 0xB1
00097     0xA8,0x50,0xA8,0x50,0xA8,0x50,0xA8,0x50, 0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10, // 0xB2, 0xB3
00098     0x10,0x10,0x10,0x10,0xF0,0x10,0x10,0x10, 0x10,0x10,0xF0,0x10,0xF0,0x10,0x10,0x10, // 0xB4, 0xB5
00099     0x28,0x28,0x28,0x28,0xE8,0x28,0x28,0x28, 0x00,0x00,0x00,0x00,0xF8,0x28,0x28,0x28, // 0xB6, 0xB7
00100     0x00,0x00,0xF0,0x10,0xF0,0x10,0x10,0x10, 0x28,0x28,0xE8,0x08,0xE8,0x28,0x28,0x28, // 0xB8, 0xB9
00101     0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28, 0x00,0x00,0xF8,0x08,0xE8,0x28,0x28,0x28, // 0xBA, 0xBB
00102     0x28,0x28,0xE8,0x08,0xF8,0x00,0x00,0x00, 0x28,0x28,0x28,0x28,0xF8,0x00,0x00,0x00, // 0xBC, 0xBD
00103     0x10,0x10,0xF0,0x10,0xF0,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0xF0,0x10,0x10,0x10, // 0xBE, 0xBF
00104     0x10,0x10,0x10,0x10,0x18,0x00,0x00,0x00, 0x10,0x10,0x10,0x10,0xF8,0x00,0x00,0x00, // 0xC0, 0xC1
00105     0x00,0x00,0x00,0x00,0xF8,0x10,0x10,0x10, 0x10,0x10,0x10,0x10,0x18,0x10,0x10,0x10, // 0xC2, 0xC3
00106     0x00,0x00,0x00,0x00,0xF8,0x00,0x00,0x00, 0x10,0x10,0x10,0x10,0xF8,0x10,0x10,0x10, // 0xC4, 0xC5
00107     0x10,0x10,0x18,0x10,0x18,0x10,0x10,0x10, 0x28,0x28,0x28,0x28,0x28,0x28,0x28,0x28, // 0xC6, 0xC7
00108     0x28,0x28,0x28,0x20,0x38,0x00,0x00,0x00, 0x00,0x00,0x38,0x20,0x28,0x28,0x28,0x28, // 0xC8, 0xC9
00109     0x28,0x28,0xE8,0x00,0xF8,0x00,0x00,0x00, 0x00,0x00,0xF8,0x00,0xE8,0x28,0x28,0x28, // 0xCA, 0xCB
00110     0x28,0x28,0x28,0x20,0x28,0x28,0x28,0x28, 0x00,0x00,0xF8,0x00,0xF8,0x00,0x00,0x00, // 0xCC, 0xCD
00111     0x28,0x28,0xE8,0x00,0xE8,0x28,0x28,0x28, 0x10,0x10,0xF8,0x00,0xF8,0x00,0x00,0x00, // 0xCE, 0xCF
00112     0x28,0x28,0x28,0x28,0xF8,0x00,0x00,0x00, 0x00,0x00,0xF8,0x00,0xF8,0x10,0x10,0x10, // 0xD0, 0xD1
00113     0x00,0x00,0x00,0x00,0xF8,0x28,0x28,0x28, 0x28,0x28,0x28,0x28,0x38,0x00,0x00,0x00, // 0xD2, 0xD3
00114     0x10,0x10,0x18,0x10,0x18,0x00,0x00,0x00, 0x00,0x00,0x18,0x10,0x18,0x10,0x10,0x10, // 0xD4, 0xD5
00115     0x00,0x00,0x00,0x00,0x38,0x28,0x28,0x28, 0x28,0x28,0x28,0x28,0xF8,0x28,0x28,0x28, // 0xD6, 0xD7
00116     0x10,0x10,0xF8,0x10,0xF8,0x10,0x10,0x10, 0x10,0x10,0x10,0x10,0xF0,0x00,0x00,0x00, // 0xD8, 0xD9
00117     0x00,0x00,0x00,0x00,0x18,0x10,0x10,0x10, 0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8,0xF8, // 0xDA, 0xDB
00118     0x00,0x00,0x00,0x00,0xF8,0xF8,0xF8,0xF8, 0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0,0xE0, // 0xDC, 0xDD
00119     0x18,0x18,0x18,0x18,0x18,0x18,0x18,0x18, 0xF8,0xF8,0xF8,0xF8,0x00,0x00,0x00,0x00, // 0xDE, 0xDF
00120     0x00,0x00,0x68,0x90,0x90,0x90,0x68,0x00, 0x00,0x70,0x98,0xF0,0x98,0xF0,0x80,0x00, // 0xE0, 0xE1
00121     0x00,0xF8,0x98,0x80,0x80,0x80,0x80,0x00, 0x00,0xF8,0x50,0x50,0x50,0x50,0x50,0x00, // 0xE2, 0xE3
00122     0xF8,0x88,0x40,0x20,0x40,0x88,0xF8,0x00, 0x00,0x00,0x78,0x90,0x90,0x90,0x60,0x00, // 0xE4, 0xE5
00123     0x00,0x50,0x50,0x50,0x50,0x68,0xC0,0x00, 0x00,0xF8,0xA0,0x20,0x20,0x20,0x20,0x00, // 0xE6, 0xE7
00124     0xF8,0x20,0x70,0x88,0x88,0x70,0x20,0xF8, 0x20,0x50,0x88,0xF8,0x88,0x50,0x20,0x00, // 0xE8, 0xE9
00125     0x20,0x50,0x88,0x88,0x50,0x50,0xD8,0x00, 0x30,0x40,0x30,0x70,0x88,0x88,0x70,0x00, // 0xEA, 0xEB
00126     0x00,0x00,0x00,0x70,0xA8,0xA8,0x70,0x00, 0x08,0x70,0x98,0xA8,0xA8,0xC8,0x70,0x80, // 0xEC, 0xED
00127     0x70,0x80,0x80,0xF0,0x80,0x80,0x70,0x00, 0x70,0x88,0x88,0x88,0x88,0x88,0x88,0x00, // 0xEE, 0xEF
00128     0x00,0xF8,0x00,0xF8,0x00,0xF8,0x00,0x00, 0x20,0x20,0xF8,0x20,0x20,0x00,0xF8,0x00, // 0xF0, 0xF1
00129     0x40,0x20,0x10,0x20,0x40,0x00,0xF8,0x00, 0x10,0x20,0x40,0x20,0x10,0x00,0xF8,0x00, // 0xF2, 0xF3
00130     0x38,0x28,0x20,0x20,0x20,0x20,0x20,0x20, 0x20,0x20,0x20,0x20,0x20,0xA0,0xA0,0xE0, // 0xF4, 0xF5
00131     0x30,0x30,0x00,0xF8,0x00,0x30,0x30,0x00, 0x00,0xE8,0xB8,0x00,0xE8,0xB8,0x00,0x00, // 0xF6, 0xF7
00132     0x70,0xD8,0xD8,0x70,0x00,0x00,0x00,0x00, 0x50,0x20,0x00,0x00,0x00,0x00,0x08,0x00, // 0xF8, 0xF9
00133     0x00,0x00,0x00,0x00,0x30,0x00,0x00,0x00, 0x38,0x20,0x20,0x20,0xA0,0xA0,0x60,0x20, // 0xFA, 0xFB
00134     0x70,0x48,0x48,0x48,0x48,0x00,0x00,0x00, 0x70,0x18,0x30,0x60,0x78,0x00,0x00,0x00, // 0xFC, 0xFD
00135     0x00,0x00,0x78,0x78,0x78,0x78,0x00,0x00
00136 };
00137 
00138 #define ST7920_CS()              {cs.set(1);wait_us(10);}
00139 #define ST7920_NCS()             {cs.set(0);wait_us(10);}
00140 #define ST7920_WRITE_BYTE(a)     {this->spi->write((a)&0xf0);this->spi->write((a)<<4);wait_us(10);}
00141 #define ST7920_WRITE_BYTES(p,l)  {uint8_t i;for(i=0;i<l;i++){this->spi->write(*p&0xf0);this->spi->write(*p<<4);p++;} wait_us(10); }
00142 #define ST7920_SET_CMD()         {this->spi->write(0xf8);wait_us(10);}
00143 #define ST7920_SET_DAT()         {this->spi->write(0xfa);wait_us(10);}
00144 #define PAGE_HEIGHT 32  //512 byte framebuffer
00145 #define WIDTH 128
00146 #define HEIGHT 64
00147 #define FB_SIZE WIDTH*HEIGHT/8
00148 
00149 RrdGlcd::RrdGlcd(PinName mosi, PinName sclk, Pin cs) {
00150     this->spi= new mbed::SPI(mosi, NC, sclk);
00151      //chip select
00152     this->cs= cs;
00153     this->cs.set(0);
00154     fb= (uint8_t *)AHB0.alloc(FB_SIZE); // grab some memoery from USB_RAM
00155     if(fb == NULL) {
00156         THEKERNEL->streams->printf("Not enough memory available for frame buffer");
00157     }
00158     inited= false;
00159     dirty= false;
00160 }
00161 
00162 RrdGlcd::~RrdGlcd() {
00163     delete this->spi;
00164     AHB0.dealloc(fb);
00165 }
00166 
00167 void RrdGlcd::setFrequency(int freq) {
00168        this->spi->frequency(freq);
00169 }
00170 
00171 void RrdGlcd::initDisplay() {
00172     if(fb == NULL) return;
00173     ST7920_CS();
00174     clearScreen();  // clear framebuffer
00175     wait_ms(90);                 //initial delay for boot up
00176     ST7920_SET_CMD();
00177     ST7920_WRITE_BYTE(0x08);       //display off, cursor+blink off
00178     ST7920_WRITE_BYTE(0x01);       //clear CGRAM ram
00179     wait_ms(10);                 //delay for cgram clear
00180     ST7920_WRITE_BYTE(0x3E);       //extended mode + gdram active
00181     for(int y=0;y<HEIGHT/2;y++)        //clear GDRAM
00182     {
00183         ST7920_WRITE_BYTE(0x80|y);   //set y
00184         ST7920_WRITE_BYTE(0x80);     //set x = 0
00185         ST7920_SET_DAT();
00186         for(int i=0;i<2*WIDTH/8;i++)     //2x width clears both segments
00187             ST7920_WRITE_BYTE(0);
00188         ST7920_SET_CMD();
00189     }
00190     ST7920_WRITE_BYTE(0x0C); //display on, cursor+blink off
00191     ST7920_NCS();
00192     inited= true;
00193 }
00194 
00195 void RrdGlcd::clearScreen() {
00196     if(fb == NULL) return;
00197     memset(this->fb, 0, FB_SIZE);
00198     dirty= true;
00199 }
00200 
00201 // render into local screenbuffer
00202 void RrdGlcd::displayString(int row, int col, const char *ptr, int length) {
00203     for (int i = 0; i < length; ++i) {
00204         displayChar(row, col, ptr[i]);
00205         col+=1;
00206     }
00207     dirty= true;
00208 }
00209 
00210 void RrdGlcd::renderChar(uint8_t *fb, char c, int ox, int oy) {
00211     if(fb == NULL) return;
00212     // using the specific font data where x is in one byte and y is in consecutive bytes
00213     // the x bits are left aligned and right padded
00214     int i= c*8; // character offset in font array
00215     int o= ox%8; // where in fb byte does it go
00216     int a= oy*16 + ox/8; // start address in frame buffer
00217     int mask= ~0xF8 >> o; // mask off top bits
00218     int mask2= ~0xF8 << (8-o); // mask off bottom bits
00219     for(int y=0;y<8;y++) {
00220         int b= font5x8[i+y]; // get font byte
00221         fb[a] &= mask; // clear top bits for font
00222         fb[a] |= (b>>o); // or in the fonts 1 bits
00223         if(o >= 4) { // it spans two fb bytes
00224             fb[a+1] &= mask2; // clear bottom bits for font
00225             fb[a+1] |= (b<<(8-o)); // or in the fonts 1 bits
00226         }
00227         a+=16; // next line
00228     }
00229 }
00230 
00231 void RrdGlcd::displayChar(int row, int col, char c) {
00232     int x= col*6;
00233     // if this wraps the line ignore it
00234     if(x+6 > WIDTH) return;
00235 
00236     // convert row/column into y and x pixel positions based on font size
00237     renderChar(this->fb, c, x, row*8);
00238 }
00239 
00240 void RrdGlcd::renderGlyph(int xp, int yp, const uint8_t *g, int pixelWidth, int pixelHeight) {
00241     if(fb == NULL) return;
00242     // NOTE the source is expected to be byte aligned and the exact number of pixels
00243     // TODO need to optimize by copying bytes instead of pixels...
00244     int xf= xp%8;
00245     int rf= pixelWidth%8;
00246     int a= yp*16 + xp/8; // start address in frame buffer
00247     const uint8_t *src= g;
00248     if(xf == 0) {
00249         // If xp is on a byte boundary simply memcpy each line from source to dest
00250         uint8_t *dest= &fb[a];
00251         int n= pixelWidth/8; // bytes per line to copy
00252         if(rf != 0) n++; // if not a multiple of 8 pixels copy last byte as a byte
00253         if(n > 0) {
00254             for(int y=0;y<pixelHeight;y++) {
00255                 memcpy(dest, src, n);
00256                 src += n;
00257                 dest+=16; // next line
00258             }
00259         }
00260 
00261         // TODO now handle ragged end if we have one but as we always render left to right we probably don't need to
00262         // if(rf != 0) {
00263 
00264         // }
00265         return;
00266     }
00267 
00268     // if xp is not on a byte boundary we do the slow pixel by pixel copy
00269     for(int y=0;y<pixelHeight;y++) {
00270         int m= 0x80;
00271         int b= *g++;
00272         for(int x=0;x<pixelWidth;x++) {
00273             a= (y+yp)*16 + (x+xp)/8;
00274             int p= 1<<(7-(x+xp)%8);
00275             if((b & m) != 0){
00276                 fb[a] |= p;
00277             }else{
00278                 fb[a] &= ~p;
00279             }
00280             m= m>>1;
00281             if(m == 0){
00282                 m= 0x80;
00283                 b= *g++;
00284             }
00285         }
00286     }
00287 }
00288 
00289 // copy frame buffer to graphic buffer on display
00290 void RrdGlcd::fillGDRAM(const uint8_t *bitmap) {
00291     unsigned char i, y;
00292     for ( i = 0 ; i < 2 ; i++ ) {
00293         ST7920_CS();
00294         for ( y = 0 ; y < PAGE_HEIGHT ; y++ ) {
00295             ST7920_SET_CMD();
00296             ST7920_WRITE_BYTE(0x80 | y);
00297             if ( i == 0 ) {
00298                 ST7920_WRITE_BYTE(0x80);
00299             } else {
00300                 ST7920_WRITE_BYTE(0x80 | 0x08);
00301             }
00302             ST7920_SET_DAT();
00303             ST7920_WRITE_BYTES(bitmap, WIDTH/8); // bitmap gets incremented in this macro
00304         }
00305         ST7920_NCS();
00306     }
00307 }
00308 
00309 void RrdGlcd::refresh() {
00310     if(!inited || !dirty) return;
00311     fillGDRAM(this->fb);
00312     dirty= false;
00313 }