SSD1331 Oled driver library for 96x64 colour Oled display. Demo included in .h file

Dependents:   Oled-SSD1331 PJ12_device

Committer:
star297
Date:
Sun May 01 12:37:44 2016 +0000
Revision:
1:f3f6624f45d4
Parent:
0:3d7d1aec706b
Child:
2:1204274fad8f
Added external font and bitmap handling.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
star297 0:3d7d1aec706b 1
star297 0:3d7d1aec706b 2 #include "mbed.h"
star297 0:3d7d1aec706b 3 #include "ssd1331.h"
star297 0:3d7d1aec706b 4
star297 0:3d7d1aec706b 5 #define countof(x) ( sizeof(x) / sizeof(x[0]) )
star297 0:3d7d1aec706b 6
star297 0:3d7d1aec706b 7 static const char font6x8[0x60][6] = {
star297 1:f3f6624f45d4 8 { 0x00,0x00,0x00,0x00,0x00,0x00 } , /*SPC */
star297 1:f3f6624f45d4 9 { 0x00,0x00,0x5F,0x00,0x00,0x00 } , /* ! */
star297 1:f3f6624f45d4 10 { 0x04,0x03,0x04,0x03,0x00,0x00 } , /* " */
star297 1:f3f6624f45d4 11 { 0x28,0x7E,0x14,0x3F,0x0A,0x00 } , /* # */
star297 1:f3f6624f45d4 12 { 0x24,0x2A,0x7F,0x2A,0x12,0x00 } , /* $ */
star297 1:f3f6624f45d4 13 { 0x23,0x13,0x08,0x64,0x62,0x00 } , /* % */
star297 1:f3f6624f45d4 14 { 0x30,0x4E,0x59,0x26,0x50,0x00 } , /* & */
star297 1:f3f6624f45d4 15 { 0x00,0x00,0x02,0x01,0x00,0x00 } , /* ' */
star297 1:f3f6624f45d4 16 { 0x00,0x00,0x1C,0x22,0x41,0x00 } , /* ( */
star297 1:f3f6624f45d4 17 { 0x41,0x22,0x1C,0x00,0x00,0x00 } , /* ) */
star297 1:f3f6624f45d4 18 { 0x22,0x14,0x08,0x14,0x22,0x00 } , /* * */
star297 1:f3f6624f45d4 19 { 0x08,0x08,0x3E,0x08,0x08,0x00 } , /* + */
star297 1:f3f6624f45d4 20 { 0x50,0x30,0x00,0x00,0x00,0x00 } , /* , */
star297 1:f3f6624f45d4 21 { 0x08,0x08,0x08,0x08,0x08,0x00 } , /* - */
star297 1:f3f6624f45d4 22 { 0x60,0x60,0x00,0x00,0x00,0x00 } , /* . */
star297 1:f3f6624f45d4 23 { 0x20,0x10,0x08,0x04,0x02,0x00 } , /* / */
star297 1:f3f6624f45d4 24 { 0x3E,0x51,0x49,0x45,0x3E,0x00 } , /* 0 */
star297 1:f3f6624f45d4 25 { 0x00,0x42,0x7F,0x40,0x00,0x00 } , /* 1 */
star297 1:f3f6624f45d4 26 { 0x62,0x51,0x49,0x49,0x46,0x00 } , /* 2 */
star297 1:f3f6624f45d4 27 { 0x22,0x41,0x49,0x49,0x36,0x00 } , /* 3 */
star297 1:f3f6624f45d4 28 { 0x18,0x14,0x12,0x7F,0x10,0x00 } , /* 4 */
star297 1:f3f6624f45d4 29 { 0x2F,0x45,0x45,0x45,0x39,0x00 } , /* 5 */
star297 1:f3f6624f45d4 30 { 0x3E,0x49,0x49,0x49,0x32,0x00 } , /* 6 */
star297 1:f3f6624f45d4 31 { 0x01,0x61,0x19,0x05,0x03,0x00 } , /* 7 */
star297 1:f3f6624f45d4 32 { 0x36,0x49,0x49,0x49,0x36,0x00 } , /* 8 */
star297 1:f3f6624f45d4 33 { 0x26,0x49,0x49,0x49,0x3E,0x00 } , /* 9 */
star297 1:f3f6624f45d4 34 { 0x00,0x36,0x36,0x00,0x00,0x00 } , /* : */
star297 1:f3f6624f45d4 35 { 0x00,0x56,0x36,0x00,0x00,0x00 } , /* ; */
star297 1:f3f6624f45d4 36 { 0x00,0x08,0x14,0x22,0x41,0x00 } , /* < */
star297 1:f3f6624f45d4 37 { 0x14,0x14,0x14,0x14,0x14,0x00 } , /* = */
star297 1:f3f6624f45d4 38 { 0x41,0x22,0x14,0x08,0x00,0x00 } , /* > */
star297 1:f3f6624f45d4 39 { 0x02,0x01,0x59,0x09,0x06,0x00 } , /* ? */
star297 1:f3f6624f45d4 40 { 0x3E,0x41,0x5D,0x55,0x2E,0x00 } , /* @ */
star297 1:f3f6624f45d4 41 { 0x60,0x1C,0x13,0x1C,0x60,0x00 } , /* A */
star297 1:f3f6624f45d4 42 { 0x7F,0x49,0x49,0x49,0x36,0x00 } , /* B */
star297 1:f3f6624f45d4 43 { 0x3E,0x41,0x41,0x41,0x22,0x00 } , /* C */
star297 1:f3f6624f45d4 44 { 0x7F,0x41,0x41,0x22,0x1C,0x00 } , /* D */
star297 1:f3f6624f45d4 45 { 0x7F,0x49,0x49,0x49,0x41,0x00 } , /* E */
star297 1:f3f6624f45d4 46 { 0x7F,0x09,0x09,0x09,0x01,0x00 } , /* F */
star297 1:f3f6624f45d4 47 { 0x1C,0x22,0x41,0x49,0x3A,0x00 } , /* G */
star297 1:f3f6624f45d4 48 { 0x7F,0x08,0x08,0x08,0x7F,0x00 } , /* H */
star297 1:f3f6624f45d4 49 { 0x00,0x41,0x7F,0x41,0x00,0x00 } , /* I */
star297 1:f3f6624f45d4 50 { 0x20,0x40,0x40,0x40,0x3F,0x00 } , /* J */
star297 1:f3f6624f45d4 51 { 0x7F,0x08,0x14,0x22,0x41,0x00 } , /* K */
star297 1:f3f6624f45d4 52 { 0x7F,0x40,0x40,0x40,0x00,0x00 } , /* L */
star297 1:f3f6624f45d4 53 { 0x7F,0x04,0x18,0x04,0x7F,0x00 } , /* M */
star297 1:f3f6624f45d4 54 { 0x7F,0x04,0x08,0x10,0x7F,0x00 } , /* N */
star297 1:f3f6624f45d4 55 { 0x3E,0x41,0x41,0x41,0x3E,0x00 } , /* O */
star297 1:f3f6624f45d4 56 { 0x7F,0x09,0x09,0x09,0x06,0x00 } , /* P */
star297 1:f3f6624f45d4 57 { 0x3E,0x41,0x51,0x21,0x5E,0x00 } , /* Q */
star297 1:f3f6624f45d4 58 { 0x7F,0x09,0x19,0x29,0x46,0x00 } , /* R */
star297 1:f3f6624f45d4 59 { 0x26,0x49,0x49,0x49,0x32,0x00 } , /* S */
star297 1:f3f6624f45d4 60 { 0x01,0x01,0x7F,0x01,0x01,0x00 } , /* T */
star297 1:f3f6624f45d4 61 { 0x3F,0x40,0x40,0x40,0x3F,0x00 } , /* U */
star297 1:f3f6624f45d4 62 { 0x03,0x1C,0x60,0x1C,0x03,0x00 } , /* V */
star297 1:f3f6624f45d4 63 { 0x0F,0x70,0x0F,0x70,0x0F,0x00 } , /* W */
star297 1:f3f6624f45d4 64 { 0x41,0x36,0x08,0x36,0x41,0x00 } , /* X */
star297 1:f3f6624f45d4 65 { 0x01,0x06,0x78,0x02,0x01,0x00 } , /* Y */
star297 1:f3f6624f45d4 66 { 0x61,0x51,0x49,0x45,0x43,0x00 } , /* Z */
star297 1:f3f6624f45d4 67 { 0x00,0x00,0x7F,0x41,0x41,0x00 } , /* [ */
star297 1:f3f6624f45d4 68 { 0x15,0x16,0x7C,0x16,0x11,0x00 } , /* \ */
star297 1:f3f6624f45d4 69 { 0x41,0x41,0x7F,0x00,0x00,0x00 } , /* ] */
star297 1:f3f6624f45d4 70 { 0x00,0x02,0x01,0x02,0x00,0x00 } , /* ^ */
star297 1:f3f6624f45d4 71 { 0x40,0x40,0x40,0x40,0x40,0x00 } , /* _ */
star297 1:f3f6624f45d4 72 { 0x00,0x01,0x02,0x00,0x00,0x00 } , /* ` */
star297 1:f3f6624f45d4 73 { 0x00,0x20,0x54,0x54,0x78,0x00 } , /* a */
star297 1:f3f6624f45d4 74 { 0x00,0x7F,0x44,0x44,0x38,0x00 } , /* b */
star297 1:f3f6624f45d4 75 { 0x00,0x38,0x44,0x44,0x28,0x00 } , /* c */
star297 1:f3f6624f45d4 76 { 0x00,0x38,0x44,0x44,0x7F,0x00 } , /* d */
star297 1:f3f6624f45d4 77 { 0x00,0x38,0x54,0x54,0x18,0x00 } , /* e */
star297 1:f3f6624f45d4 78 { 0x00,0x04,0x3E,0x05,0x01,0x00 } , /* f */
star297 1:f3f6624f45d4 79 { 0x00,0x08,0x54,0x54,0x3C,0x00 } , /* g */
star297 1:f3f6624f45d4 80 { 0x00,0x7F,0x04,0x04,0x78,0x00 } , /* h */
star297 1:f3f6624f45d4 81 { 0x00,0x00,0x7D,0x00,0x00,0x00 } , /* i */
star297 1:f3f6624f45d4 82 { 0x00,0x40,0x40,0x3D,0x00,0x00 } , /* j */
star297 1:f3f6624f45d4 83 { 0x00,0x7F,0x10,0x28,0x44,0x00 } , /* k */
star297 1:f3f6624f45d4 84 { 0x00,0x01,0x7F,0x00,0x00,0x00 } , /* l */
star297 1:f3f6624f45d4 85 { 0x7C,0x04,0x7C,0x04,0x78,0x00 } , /* m */
star297 1:f3f6624f45d4 86 { 0x00,0x7C,0x04,0x04,0x78,0x00 } , /* n */
star297 1:f3f6624f45d4 87 { 0x00,0x38,0x44,0x44,0x38,0x00 } , /* o */
star297 1:f3f6624f45d4 88 { 0x00,0x7C,0x14,0x14,0x08,0x00 } , /* p */
star297 1:f3f6624f45d4 89 { 0x00,0x08,0x14,0x14,0x7C,0x00 } , /* q */
star297 1:f3f6624f45d4 90 { 0x00,0x7C,0x08,0x04,0x04,0x00 } , /* r */
star297 1:f3f6624f45d4 91 { 0x00,0x48,0x54,0x54,0x24,0x00 } , /* s */
star297 1:f3f6624f45d4 92 { 0x00,0x04,0x3E,0x44,0x40,0x00 } , /* t */
star297 1:f3f6624f45d4 93 { 0x00,0x3C,0x40,0x40,0x7C,0x00 } , /* u */
star297 1:f3f6624f45d4 94 { 0x00,0x7C,0x20,0x10,0x0C,0x00 } , /* v */
star297 1:f3f6624f45d4 95 { 0x1C,0x60,0x1C,0x60,0x1C,0x00 } , /* w */
star297 1:f3f6624f45d4 96 { 0x00,0x6C,0x10,0x10,0x6C,0x00 } , /* x */
star297 1:f3f6624f45d4 97 { 0x00,0x4C,0x50,0x30,0x1C,0x00 } , /* y */
star297 1:f3f6624f45d4 98 { 0x00,0x44,0x64,0x54,0x4C,0x00 } , /* z */
star297 1:f3f6624f45d4 99 { 0x00,0x08,0x36,0x41,0x41,0x00 } , /* { */
star297 1:f3f6624f45d4 100 { 0x00,0x00,0x7F,0x00,0x00,0x00 } , /* | */
star297 1:f3f6624f45d4 101 { 0x41,0x41,0x36,0x08,0x00,0x00 } , /* } */
star297 1:f3f6624f45d4 102 { 0x08,0x04,0x08,0x10,0x08,0x00 } , /* ~ */
star297 1:f3f6624f45d4 103 { 0x00,0x00,0x00,0x00,0x00,0x00 } /*null*/
star297 0:3d7d1aec706b 104 };
star297 0:3d7d1aec706b 105
star297 0:3d7d1aec706b 106 ssd1331::ssd1331(PinName cs_pin, PinName rst_pin, PinName a0_pin, PinName mosi_pin, PinName miso_pin, PinName sclk_pin)
star297 1:f3f6624f45d4 107 : CS(cs_pin), RES(rst_pin), DC(a0_pin), spi(mosi_pin, miso_pin, sclk_pin)
star297 0:3d7d1aec706b 108 {
star297 0:3d7d1aec706b 109 Init();
star297 0:3d7d1aec706b 110 }
star297 0:3d7d1aec706b 111
star297 0:3d7d1aec706b 112 void ssd1331::Init(void)
star297 0:3d7d1aec706b 113 {
star297 0:3d7d1aec706b 114 spi.format(8,3);
star297 1:f3f6624f45d4 115 spi.frequency(48000000); // 24Mhz suggested but works at 48MHz
star297 1:f3f6624f45d4 116
star297 0:3d7d1aec706b 117 // reset
star297 0:3d7d1aec706b 118 wait_ms(200);
star297 0:3d7d1aec706b 119 RES = 0; //Reset active
star297 0:3d7d1aec706b 120 wait_ms(200);
star297 1:f3f6624f45d4 121 RES = 1;
star297 1:f3f6624f45d4 122
star297 0:3d7d1aec706b 123 // initialize sequence
star297 1:f3f6624f45d4 124 RegWrite(0xAE); //OLED display OFF
star297 0:3d7d1aec706b 125 RegWrite(0x75); /* Set Row Address */
star297 0:3d7d1aec706b 126 RegWrite(0x00); /* Start = 0 */
star297 0:3d7d1aec706b 127 RegWrite(0x3F); /* End = 63 */
star297 0:3d7d1aec706b 128 RegWrite(0x15); /* Set Column Address */
star297 0:3d7d1aec706b 129 RegWrite(0x00); /* Start = 0 */
star297 0:3d7d1aec706b 130 RegWrite(0x5F); /* End = 95 */
star297 0:3d7d1aec706b 131 RegWrite(0xA0); //Set remap & data format 0111 0000
star297 0:3d7d1aec706b 132 RegWrite(0x72); // RGB colour
star297 0:3d7d1aec706b 133 RegWrite(0xA1); //set display start row RAM
star297 0:3d7d1aec706b 134 RegWrite(0x00);
star297 0:3d7d1aec706b 135 RegWrite(0xA2); //set dispaly offset
star297 0:3d7d1aec706b 136 RegWrite(0x00);
star297 0:3d7d1aec706b 137 RegWrite(0xA4); //Set Display Mode
star297 0:3d7d1aec706b 138 RegWrite(0xA8); //Set Multiplex Ratio
star297 0:3d7d1aec706b 139 RegWrite(0x3F);
star297 0:3d7d1aec706b 140 RegWrite(0xAD); //Set Master Configuration
star297 0:3d7d1aec706b 141 RegWrite(0x8F); //(External VCC Supply Selected)
star297 0:3d7d1aec706b 142 RegWrite(0xB0); //Set Power Saving Mode
star297 0:3d7d1aec706b 143 RegWrite(0x1A);
star297 0:3d7d1aec706b 144 RegWrite(0xB1); //Set Phase 1 & 2 Period Adjustment
star297 0:3d7d1aec706b 145 RegWrite(0x74);
star297 0:3d7d1aec706b 146 RegWrite(0xB3); //Set Display Clock Divide Ratio / Oscillator Frequency
star297 0:3d7d1aec706b 147 RegWrite(0xD0);
star297 0:3d7d1aec706b 148 RegWrite(0x8A); //Set Second Pre-charge Speed of Color A
star297 0:3d7d1aec706b 149 RegWrite(0x81);
star297 0:3d7d1aec706b 150 RegWrite(0x8B); //Set Second Pre-charge Speed of Color B
star297 0:3d7d1aec706b 151 RegWrite(0x82);
star297 0:3d7d1aec706b 152 RegWrite(0x8C); //Set Second Pre-charge Speed of Color C
star297 0:3d7d1aec706b 153 RegWrite(0x83);
star297 0:3d7d1aec706b 154 RegWrite(0xBB); //Set Pre-charge Level
star297 0:3d7d1aec706b 155 RegWrite(0x3E);
star297 0:3d7d1aec706b 156 RegWrite(0xBE); //Set VCOMH
star297 0:3d7d1aec706b 157 RegWrite(0x3E);
star297 0:3d7d1aec706b 158 RegWrite(0x87); //Set Master Current Control
star297 0:3d7d1aec706b 159 RegWrite(0x0F);
star297 0:3d7d1aec706b 160 RegWrite(0x81); //Set Contrast Control for Color &#129;gA&#129;h
star297 0:3d7d1aec706b 161 RegWrite(0x80);
star297 0:3d7d1aec706b 162 RegWrite(0x82); //Set Contrast Control for Color &#129;gB&#129;h
star297 0:3d7d1aec706b 163 RegWrite(0x80);
star297 0:3d7d1aec706b 164 RegWrite(0x83); //Set Contrast Control for Color &#129;gC&#129;h
star297 0:3d7d1aec706b 165 RegWrite(0x80);
star297 0:3d7d1aec706b 166 RegWrite(0xAF); //display ON
star297 0:3d7d1aec706b 167
star297 1:f3f6624f45d4 168 char_x = 0;
star297 1:f3f6624f45d4 169 char_y = 0;
star297 0:3d7d1aec706b 170 chr_size = NORMAL;
star297 0:3d7d1aec706b 171 cls();
star297 0:3d7d1aec706b 172 }
star297 0:3d7d1aec706b 173
star297 0:3d7d1aec706b 174 void ssd1331::on()
star297 0:3d7d1aec706b 175 {
star297 0:3d7d1aec706b 176 RegWrite(display_on);
star297 0:3d7d1aec706b 177 }
star297 0:3d7d1aec706b 178
star297 0:3d7d1aec706b 179 void ssd1331::off()
star297 0:3d7d1aec706b 180 {
star297 1:f3f6624f45d4 181 RegWrite(display_off);
star297 0:3d7d1aec706b 182 }
star297 0:3d7d1aec706b 183
star297 0:3d7d1aec706b 184 void ssd1331::cls()
star297 1:f3f6624f45d4 185 {
star297 1:f3f6624f45d4 186 unsigned char cmd[5]= {GAC_CLEAR_WINDOW,0,0,width,height};
star297 0:3d7d1aec706b 187 RegWriteM(cmd,5);
star297 0:3d7d1aec706b 188 wait_us(500);
star297 0:3d7d1aec706b 189 background(0);
star297 1:f3f6624f45d4 190 }
star297 1:f3f6624f45d4 191
star297 1:f3f6624f45d4 192 void ssd1331::set_font(unsigned char* f)
star297 1:f3f6624f45d4 193 {
star297 1:f3f6624f45d4 194 font = f;
star297 1:f3f6624f45d4 195 if (font==NULL) {
star297 1:f3f6624f45d4 196 externalfont=0; // set display.font
star297 1:f3f6624f45d4 197 } else {
star297 1:f3f6624f45d4 198 externalfont=1;
star297 1:f3f6624f45d4 199 }
star297 1:f3f6624f45d4 200 }
star297 1:f3f6624f45d4 201
star297 1:f3f6624f45d4 202 void ssd1331::PutChar(int column,int row,unsigned int value)
star297 1:f3f6624f45d4 203 {
star297 1:f3f6624f45d4 204 if(externalfont) { // external font
star297 1:f3f6624f45d4 205 unsigned int hor,vert,offset,bpl,j,i,b;
star297 1:f3f6624f45d4 206 const unsigned char* sign;
star297 1:f3f6624f45d4 207 unsigned char z,w;
star297 1:f3f6624f45d4 208 // read font parameter from start of array
star297 1:f3f6624f45d4 209 offset = font[0]; // bytes / char
star297 1:f3f6624f45d4 210 hor = font[1]; // get hor size of font
star297 1:f3f6624f45d4 211 vert = font[2]; // get vert size of font
star297 1:f3f6624f45d4 212 bpl = font[3]; // bytes per line
star297 1:f3f6624f45d4 213 if(value == '\n') {
star297 1:f3f6624f45d4 214 char_x = 0;
star297 1:f3f6624f45d4 215 char_y = char_y + vert;
star297 1:f3f6624f45d4 216 }
star297 1:f3f6624f45d4 217 if ((value < 31) || (value > 127)) return; // test char range
star297 1:f3f6624f45d4 218 if (char_x + hor > 95) {
star297 1:f3f6624f45d4 219 char_x = 0;
star297 1:f3f6624f45d4 220 char_y = char_y + vert;
star297 1:f3f6624f45d4 221 if (char_y >= 63 - font[2]) {
star297 1:f3f6624f45d4 222 char_y = 0;
star297 1:f3f6624f45d4 223 }
star297 1:f3f6624f45d4 224 }
star297 1:f3f6624f45d4 225 window(char_x, char_y,hor,vert);
star297 1:f3f6624f45d4 226 sign = &font[((value -32) * offset) + 4];
star297 1:f3f6624f45d4 227 w = sign[0];
star297 1:f3f6624f45d4 228 for (j=0; j<vert; j++) {
star297 1:f3f6624f45d4 229 for (i=0; i<hor; i++) {
star297 1:f3f6624f45d4 230 z = sign[bpl * i + ((j & 0xF8) >> 3)+1];
star297 1:f3f6624f45d4 231 b = 1 << (j & 0x07);
star297 1:f3f6624f45d4 232 if (( z & b ) == 0x00) {
star297 1:f3f6624f45d4 233 putp(BGround_Color);
star297 1:f3f6624f45d4 234 } else {
star297 1:f3f6624f45d4 235 putp(Char_Color);
star297 1:f3f6624f45d4 236 }
star297 1:f3f6624f45d4 237 }
star297 1:f3f6624f45d4 238 }
star297 1:f3f6624f45d4 239 if ((w + 2) < hor) { // x offset to next char
star297 1:f3f6624f45d4 240 char_x += w + 2;
star297 1:f3f6624f45d4 241 } else char_x += hor;
star297 1:f3f6624f45d4 242
star297 1:f3f6624f45d4 243 } else {
star297 1:f3f6624f45d4 244 // internal font
star297 1:f3f6624f45d4 245 if(value == '\n') {
star297 1:f3f6624f45d4 246 char_x = 0;
star297 1:f3f6624f45d4 247 char_y = char_y + Y_height;
star297 1:f3f6624f45d4 248 }
star297 1:f3f6624f45d4 249 if ((value < 31) || (value > 127)) return; // test char range
star297 1:f3f6624f45d4 250 if (char_x + X_width > width) {
star297 1:f3f6624f45d4 251 char_x = 0;
star297 1:f3f6624f45d4 252 char_y = char_y + Y_height;
star297 1:f3f6624f45d4 253 if (char_y >= height - Y_height) {
star297 1:f3f6624f45d4 254 char_y = 0;
star297 1:f3f6624f45d4 255 }
star297 1:f3f6624f45d4 256 }
star297 1:f3f6624f45d4 257 int i,j,w,lpx,lpy,k,l,xw;
star297 1:f3f6624f45d4 258 unsigned char Temp=0;
star297 1:f3f6624f45d4 259 j = 0; i = 0;
star297 1:f3f6624f45d4 260 w = X_width;
star297 1:f3f6624f45d4 261 FontSizeConvert(&lpx, &lpy);
star297 1:f3f6624f45d4 262 xw = X_width;
star297 1:f3f6624f45d4 263
star297 1:f3f6624f45d4 264 for(i=0; i<xw; i++) {
star297 1:f3f6624f45d4 265 for ( l=0; l<lpx; l++) {
star297 1:f3f6624f45d4 266 Temp = font6x8[value-32][i];
star297 1:f3f6624f45d4 267 for(j=Y_height-1; j>=0; j--) {
star297 1:f3f6624f45d4 268 for (k=0; k<lpy; k++) {
star297 1:f3f6624f45d4 269 pixel(char_x+(i*lpx)+l, char_y+(((j+1)*lpy)-1)-k, ((Temp & 0x80)==0x80) ? Char_Color : BGround_Color);
star297 1:f3f6624f45d4 270 }
star297 1:f3f6624f45d4 271 Temp = Temp << 1;
star297 1:f3f6624f45d4 272 }
star297 1:f3f6624f45d4 273 }
star297 1:f3f6624f45d4 274 }
star297 1:f3f6624f45d4 275 FontSizeConvert(&lpx, &lpy);
star297 1:f3f6624f45d4 276 char_x += (w*lpx);
star297 1:f3f6624f45d4 277 }
star297 1:f3f6624f45d4 278 }
star297 1:f3f6624f45d4 279
star297 1:f3f6624f45d4 280 void ssd1331::dim()
star297 1:f3f6624f45d4 281 {
star297 1:f3f6624f45d4 282 unsigned char cmd[5]= {GAC_DIM_WINDOW,0,0,width,height};
star297 1:f3f6624f45d4 283 RegWriteM(cmd,5);
star297 1:f3f6624f45d4 284 }
star297 1:f3f6624f45d4 285
star297 1:f3f6624f45d4 286 void ssd1331::contrast(char value)
star297 1:f3f6624f45d4 287 {
star297 1:f3f6624f45d4 288 int v = value*20;
star297 1:f3f6624f45d4 289 if(v>180) {
star297 1:f3f6624f45d4 290 v=180;
star297 1:f3f6624f45d4 291 }
star297 1:f3f6624f45d4 292 unsigned char cmd[7];
star297 1:f3f6624f45d4 293 cmd[0] = contrastA;
star297 1:f3f6624f45d4 294 cmd[1] = v;
star297 1:f3f6624f45d4 295 cmd[2] = contrastB;
star297 1:f3f6624f45d4 296 cmd[3] = v;
star297 1:f3f6624f45d4 297 cmd[4] = contrastC;
star297 1:f3f6624f45d4 298 cmd[5] = v;
star297 1:f3f6624f45d4 299 RegWriteM(cmd, 6);
star297 1:f3f6624f45d4 300 }
star297 1:f3f6624f45d4 301
star297 1:f3f6624f45d4 302 int ssd1331::toRGB(int R,int G,int B)
star297 1:f3f6624f45d4 303 {
star297 1:f3f6624f45d4 304 uint16_t c;
star297 1:f3f6624f45d4 305 c = R >> 3;
star297 1:f3f6624f45d4 306 c <<= 6;
star297 1:f3f6624f45d4 307 c |= G >> 2;
star297 1:f3f6624f45d4 308 c <<= 5;
star297 1:f3f6624f45d4 309 c |= B >> 3;
star297 1:f3f6624f45d4 310 return c;
star297 1:f3f6624f45d4 311 }
star297 1:f3f6624f45d4 312
star297 1:f3f6624f45d4 313 void ssd1331::rectangle(int x1,int y1,int x2,int y2,unsigned int colorline)
star297 1:f3f6624f45d4 314 {
star297 1:f3f6624f45d4 315 if ( x1 < 0 ) x1 = 0;
star297 1:f3f6624f45d4 316 else if ( x1 > width ) x1 = width;
star297 1:f3f6624f45d4 317 if ( y1 < 0 ) y1 = 0;
star297 1:f3f6624f45d4 318 else if ( y1 > height ) y1 = height;
star297 1:f3f6624f45d4 319 if ( x2 < 0 ) x2 = 0;
star297 1:f3f6624f45d4 320 else if ( x2 > width ) x2 = width;
star297 1:f3f6624f45d4 321 if ( y2 < 0 ) y2 = 0;
star297 1:f3f6624f45d4 322 else if ( y2 > height ) y2 = height;
star297 1:f3f6624f45d4 323
star297 1:f3f6624f45d4 324 unsigned char cmd[11]= { 0 };
star297 1:f3f6624f45d4 325 cmd[0] = GAC_FILL_ENABLE_DISABLE;
star297 1:f3f6624f45d4 326 cmd[1] = 0; // fill 1, empty 0
star297 1:f3f6624f45d4 327 RegWriteM(cmd, 2);
star297 1:f3f6624f45d4 328 cmd[0] = GAC_DRAW_RECTANGLE;
star297 1:f3f6624f45d4 329 cmd[1] = (unsigned char)x1;
star297 1:f3f6624f45d4 330 cmd[2] = (unsigned char)y1;
star297 1:f3f6624f45d4 331 cmd[3] = (unsigned char)x2;
star297 1:f3f6624f45d4 332 cmd[4] = (unsigned char)y2;
star297 1:f3f6624f45d4 333 cmd[5] = (unsigned char)((colorline>> 11) << 1); // Outline Blue
star297 1:f3f6624f45d4 334 cmd[6] = (unsigned char)((colorline>> 5 ) & 0x3F); // Outline Green
star297 1:f3f6624f45d4 335 cmd[7] = (unsigned char)((colorline<< 1 ) & 0x3F); // Outline Red
star297 1:f3f6624f45d4 336 cmd[8] = (0);
star297 1:f3f6624f45d4 337 cmd[9] = (0);
star297 1:f3f6624f45d4 338 cmd[10]= (0);
star297 1:f3f6624f45d4 339 RegWriteM(cmd, 11);
star297 1:f3f6624f45d4 340 wait_us(500);
star297 1:f3f6624f45d4 341 }
star297 1:f3f6624f45d4 342
star297 1:f3f6624f45d4 343 void ssd1331::fillrectangle(int x1,int y1,int x2,int y2,unsigned int colorline,unsigned int colorfill)
star297 1:f3f6624f45d4 344 {
star297 1:f3f6624f45d4 345 if ( x1 < 0 ) x1 = 0;
star297 1:f3f6624f45d4 346 else if ( x1 > width ) x1 = width;
star297 1:f3f6624f45d4 347 if ( y1 < 0 ) y1 = 0;
star297 1:f3f6624f45d4 348 else if ( y1 > height ) y1 = height;
star297 1:f3f6624f45d4 349 if ( x2 < 0 ) x2 = 0;
star297 1:f3f6624f45d4 350 else if ( x2 > width ) x2 = width;
star297 1:f3f6624f45d4 351 if ( y2 < 0 ) y2 = 0;
star297 1:f3f6624f45d4 352 else if ( y2 > height ) y2 = height;
star297 1:f3f6624f45d4 353
star297 1:f3f6624f45d4 354 unsigned char cmd[11]= { 0 };
star297 1:f3f6624f45d4 355 cmd[0] = GAC_FILL_ENABLE_DISABLE;
star297 1:f3f6624f45d4 356 cmd[1] = 1; // fill 1, empty 0
star297 1:f3f6624f45d4 357 RegWriteM(cmd, 2);
star297 1:f3f6624f45d4 358 cmd[0] = GAC_DRAW_RECTANGLE;
star297 1:f3f6624f45d4 359 cmd[1] = (unsigned char)x1;
star297 1:f3f6624f45d4 360 cmd[2] = (unsigned char)y1;
star297 1:f3f6624f45d4 361 cmd[3] = (unsigned char)x2;
star297 1:f3f6624f45d4 362 cmd[4] = (unsigned char)y2;
star297 1:f3f6624f45d4 363 cmd[5] = (unsigned char)((colorline>> 11) << 1); // Outline Blue
star297 1:f3f6624f45d4 364 cmd[6] = (unsigned char)((colorline>> 5 ) & 0x3F); // Outline Green
star297 1:f3f6624f45d4 365 cmd[7] = (unsigned char)((colorline<< 1 ) & 0x3F); // Outline Red
star297 1:f3f6624f45d4 366 cmd[8] = (unsigned char)((colorfill>> 11) << 1); // fill Blue
star297 1:f3f6624f45d4 367 cmd[9] = (unsigned char)((colorfill>> 5 ) & 0x3F); // fill Green
star297 1:f3f6624f45d4 368 cmd[10]= (unsigned char)((colorfill<< 1 ) & 0x3F); // fill Red
star297 1:f3f6624f45d4 369 RegWriteM(cmd, 11);
star297 1:f3f6624f45d4 370 wait_us(500);
star297 1:f3f6624f45d4 371 }
star297 1:f3f6624f45d4 372
star297 1:f3f6624f45d4 373 void ssd1331::line(int x1,int y1,int x2,int y2,unsigned int color)
star297 1:f3f6624f45d4 374 {
star297 1:f3f6624f45d4 375 if ( x1 < 0 ) x1 = 0;
star297 1:f3f6624f45d4 376 else if ( x1 > width ) x1 = width;
star297 1:f3f6624f45d4 377 if ( y1 < 0 ) y1 = 0;
star297 1:f3f6624f45d4 378 else if ( y1 > height ) y1 = height;
star297 1:f3f6624f45d4 379 if ( x2 < 0 ) x2 = 0;
star297 1:f3f6624f45d4 380 else if ( x2 > width ) x2 = width;
star297 1:f3f6624f45d4 381 if ( y2 < 0 ) y2 = 0;
star297 1:f3f6624f45d4 382 else if ( y2 > height ) y2 = height;
star297 1:f3f6624f45d4 383
star297 1:f3f6624f45d4 384 unsigned char cmd[11]= { 0 };
star297 1:f3f6624f45d4 385 cmd[0] = GAC_FILL_ENABLE_DISABLE;
star297 1:f3f6624f45d4 386 cmd[1] = 0; // fill 0, empty 0
star297 1:f3f6624f45d4 387 RegWriteM(cmd, 2);
star297 1:f3f6624f45d4 388 cmd[0] = GAC_DRAW_LINE;
star297 1:f3f6624f45d4 389 cmd[1] = (unsigned char)x1;
star297 1:f3f6624f45d4 390 cmd[2] = (unsigned char)y1;
star297 1:f3f6624f45d4 391 cmd[3] = (unsigned char)x2;
star297 1:f3f6624f45d4 392 cmd[4] = (unsigned char)y2;
star297 1:f3f6624f45d4 393 cmd[5] = (unsigned char)(((color>>11)&0x1F)<<1); // Blue
star297 1:f3f6624f45d4 394 cmd[6] = (unsigned char)((color>>5)&0x3F); // Green
star297 1:f3f6624f45d4 395 cmd[7] = (unsigned char)((color&0x1F)<<1); // Red
star297 1:f3f6624f45d4 396 RegWriteM(cmd, 8);
star297 1:f3f6624f45d4 397 wait_us(500);
star297 1:f3f6624f45d4 398 }
star297 1:f3f6624f45d4 399
star297 1:f3f6624f45d4 400 void ssd1331::circle (int radius, int x, int y , unsigned int col, int fill)
star297 1:f3f6624f45d4 401 {
star297 1:f3f6624f45d4 402 int cx, cy, d;
star297 1:f3f6624f45d4 403 d = 3 - 2 * radius;
star297 1:f3f6624f45d4 404 cy = radius;
star297 1:f3f6624f45d4 405 pixel(x, radius+y, col);
star297 1:f3f6624f45d4 406 pixel(x, -radius+y, col);
star297 1:f3f6624f45d4 407 pixel(radius+x, y, col);
star297 1:f3f6624f45d4 408 pixel(-radius+x, y, col);
star297 1:f3f6624f45d4 409 if(fill) {
star297 1:f3f6624f45d4 410 line(x,radius+y,x,-radius+y,col);
star297 1:f3f6624f45d4 411 line( radius+x,y,-radius+x,y,col);
star297 1:f3f6624f45d4 412 }
star297 1:f3f6624f45d4 413
star297 1:f3f6624f45d4 414 for (cx = 0; cx <= cy; cx++) {
star297 1:f3f6624f45d4 415 if(d>=0) {
star297 1:f3f6624f45d4 416 d+=10+4*cx-4*cy;
star297 1:f3f6624f45d4 417 cy--;
star297 1:f3f6624f45d4 418 } else {
star297 1:f3f6624f45d4 419 d+=6+4*cx;
star297 1:f3f6624f45d4 420 }
star297 1:f3f6624f45d4 421 pixel(cy+x, cx+y, col);
star297 1:f3f6624f45d4 422 pixel(cx+x, cy+y, col);
star297 1:f3f6624f45d4 423 pixel(-cx+x, cy+y, col);
star297 1:f3f6624f45d4 424 pixel(-cy+x, cx+y, col);
star297 1:f3f6624f45d4 425 pixel(-cy+x, -cx+y, col);
star297 1:f3f6624f45d4 426 pixel(-cx+x, -cy+y, col);
star297 1:f3f6624f45d4 427 pixel(cx+x, -cy+y, col);
star297 1:f3f6624f45d4 428 pixel(cy+x, -cx+y, col);
star297 1:f3f6624f45d4 429 if(fill) {
star297 1:f3f6624f45d4 430 line(cy+x, cx+y, cy+x, -cx+y, col);
star297 1:f3f6624f45d4 431 line(cx+x, cy+y, cx+x, -cy + y, col);
star297 1:f3f6624f45d4 432 line(-cx+x, cy+y, -cx+x, cy+y, col);
star297 1:f3f6624f45d4 433 line(-cy+x, cx+y, -cy+x, cx+y, col);
star297 1:f3f6624f45d4 434 line(-cy+x, -cx+y, -cy+x, cx+y, col);
star297 1:f3f6624f45d4 435 line(-cx+x, -cy+y, -cx+x, cy+y, col);
star297 1:f3f6624f45d4 436 line(cx+x, -cy+y, cx+x, cy+y, col);
star297 1:f3f6624f45d4 437 line(cy+x, -cx+y, cy+x, cx+y, col);
star297 1:f3f6624f45d4 438 }
star297 1:f3f6624f45d4 439 }
star297 1:f3f6624f45d4 440 }
star297 1:f3f6624f45d4 441
star297 1:f3f6624f45d4 442 void ssd1331::ScrollSet(int horizontal, int startline, int linecount, int vertical , int frame_interval)
star297 1:f3f6624f45d4 443 {
star297 1:f3f6624f45d4 444 unsigned char cmd[7];
star297 1:f3f6624f45d4 445 if((startline>height+1)||((startline+linecount)>height+1)) return ;
star297 1:f3f6624f45d4 446 if ( frame_interval > 3 ) frame_interval = 3;
star297 1:f3f6624f45d4 447 cmd[0] = SCROLL_SETUP; //
star297 1:f3f6624f45d4 448 cmd[1] = horizontal;
star297 1:f3f6624f45d4 449 cmd[2] = startline;
star297 1:f3f6624f45d4 450 cmd[3] = linecount;
star297 1:f3f6624f45d4 451 cmd[4] = vertical;
star297 1:f3f6624f45d4 452 cmd[5] = frame_interval;
star297 1:f3f6624f45d4 453 RegWriteM(cmd,6);
star297 1:f3f6624f45d4 454 }
star297 1:f3f6624f45d4 455 void ssd1331::drawBitmap( const uint8_t *bitmap, int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) {
star297 1:f3f6624f45d4 456
star297 1:f3f6624f45d4 457 int16_t i, j, byteWidth = (w + 7) / 8;
star297 1:f3f6624f45d4 458 for(j=0; j<h; j++) {
star297 1:f3f6624f45d4 459 for(i=0; i<w; i++ ) {
star297 1:f3f6624f45d4 460 if(bitmap[ j * byteWidth + i / 8] & (128 >> (i & 7))) {
star297 1:f3f6624f45d4 461 pixel(x+i, y+j, color);
star297 1:f3f6624f45d4 462 }
star297 1:f3f6624f45d4 463 }
star297 1:f3f6624f45d4 464 }
star297 1:f3f6624f45d4 465 }
star297 1:f3f6624f45d4 466
star297 1:f3f6624f45d4 467 int ssd1331::BMP_16(const char *Name_BMP, unsigned int x, unsigned int y)
star297 1:f3f6624f45d4 468 {
star297 1:f3f6624f45d4 469 #define OffsetPixelWidth 18
star297 1:f3f6624f45d4 470 #define OffsetPixelHeigh 22
star297 1:f3f6624f45d4 471 #define OffsetFileSize 34
star297 1:f3f6624f45d4 472 #define OffsetPixData 10
star297 1:f3f6624f45d4 473 #define OffsetBPP 28
star297 1:f3f6624f45d4 474
star297 1:f3f6624f45d4 475 char filename[50];
star297 1:f3f6624f45d4 476 unsigned char BMP_Header[54];
star297 1:f3f6624f45d4 477 unsigned short BPP_t;
star297 1:f3f6624f45d4 478 unsigned int PixelWidth,PixelHeigh,start_data;
star297 1:f3f6624f45d4 479 unsigned int i,off;
star297 1:f3f6624f45d4 480 int padd,j;
star297 1:f3f6624f45d4 481 unsigned short *line;
star297 1:f3f6624f45d4 482
star297 1:f3f6624f45d4 483 // get the filename
star297 1:f3f6624f45d4 484 i=0;
star297 1:f3f6624f45d4 485 while (*Name_BMP!='\0') {
star297 1:f3f6624f45d4 486 filename[i++]=*Name_BMP++;
star297 1:f3f6624f45d4 487 }
star297 1:f3f6624f45d4 488 filename[i] = 0;
star297 1:f3f6624f45d4 489
star297 1:f3f6624f45d4 490 FILE *Image = fopen((const char *)&filename[0], "rb"); // open the bmp file
star297 1:f3f6624f45d4 491 if (!Image) {
star297 1:f3f6624f45d4 492 return(0); // error file not found !
star297 1:f3f6624f45d4 493 }
star297 1:f3f6624f45d4 494
star297 1:f3f6624f45d4 495 fread(&BMP_Header[0],1,54,Image); // get the BMP Header
star297 1:f3f6624f45d4 496
star297 1:f3f6624f45d4 497 if (BMP_Header[0] != 0x42 || BMP_Header[1] != 0x4D) { // check magic byte
star297 1:f3f6624f45d4 498 fclose(Image);
star297 1:f3f6624f45d4 499 return(-1); // error no BMP file
star297 1:f3f6624f45d4 500 }
star297 1:f3f6624f45d4 501
star297 1:f3f6624f45d4 502 BPP_t = BMP_Header[OffsetBPP] + (BMP_Header[OffsetBPP + 1] << 8);
star297 1:f3f6624f45d4 503 if (BPP_t != 0x0010) {
star297 1:f3f6624f45d4 504 fclose(Image);
star297 1:f3f6624f45d4 505 return(-2); // error no 16 bit BMP
star297 1:f3f6624f45d4 506 }
star297 1:f3f6624f45d4 507
star297 1:f3f6624f45d4 508 PixelHeigh = BMP_Header[OffsetPixelHeigh] + (BMP_Header[OffsetPixelHeigh + 1] << 8) + (BMP_Header[OffsetPixelHeigh + 2] << 16) + (BMP_Header[OffsetPixelHeigh + 3] << 24);
star297 1:f3f6624f45d4 509 PixelWidth = BMP_Header[OffsetPixelWidth] + (BMP_Header[OffsetPixelWidth + 1] << 8) + (BMP_Header[OffsetPixelWidth + 2] << 16) + (BMP_Header[OffsetPixelWidth + 3] << 24);
star297 1:f3f6624f45d4 510 if (PixelHeigh > height + y || PixelWidth > width + x) {
star297 1:f3f6624f45d4 511 fclose(Image);
star297 1:f3f6624f45d4 512 return(-3); // to big
star297 1:f3f6624f45d4 513 }
star297 1:f3f6624f45d4 514
star297 1:f3f6624f45d4 515 start_data = BMP_Header[OffsetPixData] + (BMP_Header[OffsetPixData + 1] << 8) + (BMP_Header[OffsetPixData + 2] << 16) + (BMP_Header[OffsetPixData + 3] << 24);
star297 1:f3f6624f45d4 516
star297 1:f3f6624f45d4 517 line = (unsigned short *) malloc (2 * PixelHeigh); // we need a buffer for a line
star297 1:f3f6624f45d4 518 if (line == NULL) {
star297 1:f3f6624f45d4 519 return(-4); // error no memory
star297 1:f3f6624f45d4 520 }
star297 1:f3f6624f45d4 521 // the bmp lines are padded to multiple of 4 bytes
star297 1:f3f6624f45d4 522 padd = -1;
star297 1:f3f6624f45d4 523 do {
star297 1:f3f6624f45d4 524 padd ++;
star297 1:f3f6624f45d4 525 } while ((PixelHeigh * 2 + padd)%4 != 0);
star297 1:f3f6624f45d4 526
star297 1:f3f6624f45d4 527 window(x, y,PixelWidth ,PixelHeigh);
star297 1:f3f6624f45d4 528
star297 1:f3f6624f45d4 529 for (j = PixelWidth - 1; j >= 0; j--) { //Lines bottom up
star297 1:f3f6624f45d4 530 off = j * (PixelHeigh * 2 + padd) + start_data; // start of line
star297 1:f3f6624f45d4 531 fseek(Image, off ,SEEK_SET);
star297 1:f3f6624f45d4 532 fread(line,1,PixelHeigh * 2,Image); // read a line - slow
star297 1:f3f6624f45d4 533 for (i = 0; i < PixelHeigh; i++) { // copy pixel data to TFT
star297 1:f3f6624f45d4 534
star297 1:f3f6624f45d4 535 DataWrite(line[i]);
star297 1:f3f6624f45d4 536 }
star297 1:f3f6624f45d4 537 }
star297 1:f3f6624f45d4 538 free (line);
star297 1:f3f6624f45d4 539 fclose(Image);
star297 1:f3f6624f45d4 540 window(0,0,width,height);
star297 1:f3f6624f45d4 541 return(1);
star297 1:f3f6624f45d4 542 }
star297 1:f3f6624f45d4 543
star297 1:f3f6624f45d4 544 void ssd1331::Copy(int src_x1,int src_y1,int src_x2,int src_y2, int dst_x,int dst_y)
star297 1:f3f6624f45d4 545 {
star297 1:f3f6624f45d4 546 unsigned char cmd[8]= { 0 };
star297 1:f3f6624f45d4 547 if ((src_x1>width)||(src_y1>height)||(src_x2>width)||(src_y2>height)) return;
star297 1:f3f6624f45d4 548 if ((dst_x>width)||(dst_y>height))return;
star297 1:f3f6624f45d4 549 cmd[0] = GAC_COPY_AREA; //
star297 1:f3f6624f45d4 550 cmd[1] = (unsigned char)src_x1;
star297 1:f3f6624f45d4 551 cmd[2] = (unsigned char)src_y1;
star297 1:f3f6624f45d4 552 cmd[3] = (unsigned char)src_x2;
star297 1:f3f6624f45d4 553 cmd[4] = (unsigned char)src_y2;
star297 1:f3f6624f45d4 554 cmd[5] = (unsigned char)dst_x;
star297 1:f3f6624f45d4 555 cmd[6] = (unsigned char)dst_y;
star297 1:f3f6624f45d4 556 RegWriteM(cmd,7);
star297 1:f3f6624f45d4 557 }
star297 1:f3f6624f45d4 558
star297 1:f3f6624f45d4 559 void ssd1331::Fill_Screen(unsigned int color)
star297 1:f3f6624f45d4 560 {
star297 1:f3f6624f45d4 561 BGround_Color = color;
star297 1:f3f6624f45d4 562 fillrectangle(0,0,width,height,color,color);
star297 1:f3f6624f45d4 563 }
star297 0:3d7d1aec706b 564
star297 0:3d7d1aec706b 565 void ssd1331::locate(int column, int row)
star297 0:3d7d1aec706b 566 {
star297 1:f3f6624f45d4 567 char_x = column;
star297 1:f3f6624f45d4 568 char_y = row;
star297 0:3d7d1aec706b 569 }
star297 0:3d7d1aec706b 570
star297 0:3d7d1aec706b 571 void ssd1331::foreground(unsigned int color)
star297 0:3d7d1aec706b 572 {
star297 0:3d7d1aec706b 573 Char_Color = color;
star297 0:3d7d1aec706b 574 }
star297 0:3d7d1aec706b 575 void ssd1331::background(unsigned int color)
star297 0:3d7d1aec706b 576 {
star297 0:3d7d1aec706b 577 BGround_Color = color;
star297 0:3d7d1aec706b 578 }
star297 0:3d7d1aec706b 579
star297 0:3d7d1aec706b 580 void ssd1331::SetFontSize(int Csize)
star297 0:3d7d1aec706b 581 {
star297 0:3d7d1aec706b 582 chr_size = Csize;
star297 0:3d7d1aec706b 583 }
star297 0:3d7d1aec706b 584
star297 1:f3f6624f45d4 585 void ssd1331::putp(int colour)
star297 0:3d7d1aec706b 586 {
star297 1:f3f6624f45d4 587 pixel(_x, _y, colour);
star297 1:f3f6624f45d4 588 // wait_us(1000);
star297 1:f3f6624f45d4 589 _x++;
star297 1:f3f6624f45d4 590 if(_x > _x2) {
star297 1:f3f6624f45d4 591 _x = _x1;
star297 1:f3f6624f45d4 592 _y++;
star297 1:f3f6624f45d4 593 if(_y > _y2) {
star297 1:f3f6624f45d4 594 _y = _y1;
star297 0:3d7d1aec706b 595 }
star297 0:3d7d1aec706b 596 }
star297 0:3d7d1aec706b 597 }
star297 0:3d7d1aec706b 598
star297 0:3d7d1aec706b 599 int ssd1331::_putc( int c )
star297 1:f3f6624f45d4 600 {
star297 1:f3f6624f45d4 601 PutChar( char_x , char_y ,c);
star297 0:3d7d1aec706b 602 return c;
star297 0:3d7d1aec706b 603 }
star297 0:3d7d1aec706b 604
star297 1:f3f6624f45d4 605 void ssd1331::pixel(int x,int y,unsigned int Color)
star297 1:f3f6624f45d4 606 {
star297 1:f3f6624f45d4 607 unsigned char cmd[7]= {Set_Column_Address,0x00,0x00,Set_Row_Address,0x00,0x00};
star297 1:f3f6624f45d4 608 if ((x<0)||(y<0)||(x>width)||(y>height)) return ;
star297 1:f3f6624f45d4 609 cmd[1] = (unsigned char)x;
star297 1:f3f6624f45d4 610 cmd[2] = (unsigned char)x;
star297 1:f3f6624f45d4 611 cmd[4] = (unsigned char)y;
star297 1:f3f6624f45d4 612 cmd[5] = (unsigned char)y;
star297 1:f3f6624f45d4 613 RegWriteM(cmd, 6);
star297 1:f3f6624f45d4 614 DataWrite_to(Color);
star297 1:f3f6624f45d4 615 }
star297 1:f3f6624f45d4 616
star297 1:f3f6624f45d4 617 void ssd1331::window(int x, int y, int w, int h)
star297 1:f3f6624f45d4 618 {
star297 1:f3f6624f45d4 619 // current pixel location
star297 1:f3f6624f45d4 620 _x = x;
star297 1:f3f6624f45d4 621 _y = y;
star297 1:f3f6624f45d4 622 // window settings
star297 1:f3f6624f45d4 623 _x1 = x;
star297 1:f3f6624f45d4 624 _x2 = x + w - 1;
star297 1:f3f6624f45d4 625 _y1 = y;
star297 1:f3f6624f45d4 626 _y2 = y + h - 1;
star297 1:f3f6624f45d4 627 }
star297 1:f3f6624f45d4 628
star297 1:f3f6624f45d4 629 void ssd1331::Scrollstart()
star297 1:f3f6624f45d4 630 {
star297 1:f3f6624f45d4 631 RegWrite(SCROLL_START);
star297 1:f3f6624f45d4 632 }
star297 1:f3f6624f45d4 633
star297 1:f3f6624f45d4 634 void ssd1331::Scrollstop()
star297 1:f3f6624f45d4 635 {
star297 1:f3f6624f45d4 636 RegWrite(SCROLL_STOP);
star297 1:f3f6624f45d4 637 }
star297 1:f3f6624f45d4 638
star297 1:f3f6624f45d4 639 int ssd1331::_getc()
star297 0:3d7d1aec706b 640 {
star297 0:3d7d1aec706b 641 return -1;
star297 0:3d7d1aec706b 642 }
star297 0:3d7d1aec706b 643
star297 0:3d7d1aec706b 644 int ssd1331::row()
star297 0:3d7d1aec706b 645 {
star297 1:f3f6624f45d4 646 return char_y;
star297 0:3d7d1aec706b 647 }
star297 0:3d7d1aec706b 648 int ssd1331::column()
star297 0:3d7d1aec706b 649 {
star297 1:f3f6624f45d4 650 return char_x;
star297 0:3d7d1aec706b 651 }
star297 0:3d7d1aec706b 652
star297 0:3d7d1aec706b 653 void ssd1331::FontSizeConvert(int *lpx,int *lpy)
star297 0:3d7d1aec706b 654 {
star297 1:f3f6624f45d4 655 switch( chr_size ) {
star297 1:f3f6624f45d4 656 case WIDE:
star297 1:f3f6624f45d4 657 *lpx=2;
star297 1:f3f6624f45d4 658 *lpy=1;
star297 1:f3f6624f45d4 659 break;
star297 1:f3f6624f45d4 660 case HIGH:
star297 1:f3f6624f45d4 661 *lpx=1;
star297 1:f3f6624f45d4 662 *lpy=2;
star297 1:f3f6624f45d4 663 break;
star297 1:f3f6624f45d4 664 case WH :
star297 1:f3f6624f45d4 665 *lpx=2;
star297 1:f3f6624f45d4 666 *lpy=2;
star297 1:f3f6624f45d4 667 break;
star297 1:f3f6624f45d4 668 case WHx36 :
star297 1:f3f6624f45d4 669 *lpx=6;
star297 1:f3f6624f45d4 670 *lpy=6;
star297 1:f3f6624f45d4 671 break;
star297 1:f3f6624f45d4 672 case NORMAL:
star297 1:f3f6624f45d4 673 default:
star297 1:f3f6624f45d4 674 *lpx=1;
star297 1:f3f6624f45d4 675 *lpy=1;
star297 1:f3f6624f45d4 676 break;
star297 1:f3f6624f45d4 677 }
star297 0:3d7d1aec706b 678 }
star297 0:3d7d1aec706b 679
star297 0:3d7d1aec706b 680 void ssd1331::RegWrite(unsigned char Command)
star297 0:3d7d1aec706b 681 {
star297 0:3d7d1aec706b 682 DC = 0; // Command
star297 0:3d7d1aec706b 683 CS = 0; // CS enable
star297 0:3d7d1aec706b 684 spi.write(Command);
star297 0:3d7d1aec706b 685 CS = 1; // CS dissable
star297 0:3d7d1aec706b 686 }
star297 0:3d7d1aec706b 687
star297 0:3d7d1aec706b 688 void ssd1331::RegWriteM(unsigned char *Command, int count)
star297 0:3d7d1aec706b 689 {
star297 0:3d7d1aec706b 690 int i;
star297 0:3d7d1aec706b 691 DC = 0; // Command
star297 0:3d7d1aec706b 692 CS = 0; // CS enable
star297 1:f3f6624f45d4 693 for( i=0; i<count; i++) {
star297 1:f3f6624f45d4 694 spi.write(*Command++);
star297 0:3d7d1aec706b 695 }
star297 0:3d7d1aec706b 696 CS = 1; // CS dissable
star297 0:3d7d1aec706b 697 }
star297 0:3d7d1aec706b 698
star297 0:3d7d1aec706b 699 void ssd1331::DataWrite(unsigned char c)
star297 0:3d7d1aec706b 700 {
star297 1:f3f6624f45d4 701 DC = 1; // DATA
star297 1:f3f6624f45d4 702 CS = 0; // CS enable
star297 1:f3f6624f45d4 703 spi.write(c);
star297 1:f3f6624f45d4 704 CS = 1; // CS dissable
star297 0:3d7d1aec706b 705 }
star297 0:3d7d1aec706b 706
star297 0:3d7d1aec706b 707 void ssd1331::DataWrite_to(unsigned int Dat)
star297 0:3d7d1aec706b 708 {
star297 1:f3f6624f45d4 709 DC = 1; // DATA
star297 1:f3f6624f45d4 710 CS = 0; // CS enable
star297 1:f3f6624f45d4 711 spi.write((unsigned char)((Dat >> 8)));
star297 1:f3f6624f45d4 712 spi.write((unsigned char)(Dat));
star297 1:f3f6624f45d4 713 CS = 1; // CS dissable
star297 0:3d7d1aec706b 714 }