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

Dependents:   Oled-SSD1331 PJ12_device

Committer:
star297
Date:
Fri May 06 21:40:50 2016 +0000
Revision:
2:1204274fad8f
Parent:
1:f3f6624f45d4
Child:
3:a4caac512e13
Added bitmap functions

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 2:1204274fad8f 115 spi.frequency(24000000); // 12Mhz max for KL25z
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 2:1204274fad8f 189 Maxwindow();
star297 0:3d7d1aec706b 190 background(0);
star297 1:f3f6624f45d4 191 }
star297 1:f3f6624f45d4 192
star297 1:f3f6624f45d4 193 void ssd1331::set_font(unsigned char* f)
star297 1:f3f6624f45d4 194 {
star297 1:f3f6624f45d4 195 font = f;
star297 1:f3f6624f45d4 196 if (font==NULL) {
star297 1:f3f6624f45d4 197 externalfont=0; // set display.font
star297 1:f3f6624f45d4 198 } else {
star297 1:f3f6624f45d4 199 externalfont=1;
star297 1:f3f6624f45d4 200 }
star297 1:f3f6624f45d4 201 }
star297 1:f3f6624f45d4 202
star297 1:f3f6624f45d4 203 void ssd1331::PutChar(int column,int row,unsigned int value)
star297 1:f3f6624f45d4 204 {
star297 1:f3f6624f45d4 205 if(externalfont) { // external font
star297 1:f3f6624f45d4 206 unsigned int hor,vert,offset,bpl,j,i,b;
star297 1:f3f6624f45d4 207 const unsigned char* sign;
star297 1:f3f6624f45d4 208 unsigned char z,w;
star297 1:f3f6624f45d4 209 // read font parameter from start of array
star297 1:f3f6624f45d4 210 offset = font[0]; // bytes / char
star297 1:f3f6624f45d4 211 hor = font[1]; // get hor size of font
star297 1:f3f6624f45d4 212 vert = font[2]; // get vert size of font
star297 1:f3f6624f45d4 213 bpl = font[3]; // bytes per line
star297 1:f3f6624f45d4 214 if(value == '\n') {
star297 1:f3f6624f45d4 215 char_x = 0;
star297 1:f3f6624f45d4 216 char_y = char_y + vert;
star297 1:f3f6624f45d4 217 }
star297 1:f3f6624f45d4 218 if ((value < 31) || (value > 127)) return; // test char range
star297 1:f3f6624f45d4 219 if (char_x + hor > 95) {
star297 1:f3f6624f45d4 220 char_x = 0;
star297 1:f3f6624f45d4 221 char_y = char_y + vert;
star297 1:f3f6624f45d4 222 if (char_y >= 63 - font[2]) {
star297 1:f3f6624f45d4 223 char_y = 0;
star297 1:f3f6624f45d4 224 }
star297 1:f3f6624f45d4 225 }
star297 1:f3f6624f45d4 226 window(char_x, char_y,hor,vert);
star297 1:f3f6624f45d4 227 sign = &font[((value -32) * offset) + 4];
star297 1:f3f6624f45d4 228 w = sign[0];
star297 1:f3f6624f45d4 229 for (j=0; j<vert; j++) {
star297 1:f3f6624f45d4 230 for (i=0; i<hor; i++) {
star297 1:f3f6624f45d4 231 z = sign[bpl * i + ((j & 0xF8) >> 3)+1];
star297 1:f3f6624f45d4 232 b = 1 << (j & 0x07);
star297 1:f3f6624f45d4 233 if (( z & b ) == 0x00) {
star297 1:f3f6624f45d4 234 putp(BGround_Color);
star297 1:f3f6624f45d4 235 } else {
star297 1:f3f6624f45d4 236 putp(Char_Color);
star297 1:f3f6624f45d4 237 }
star297 1:f3f6624f45d4 238 }
star297 1:f3f6624f45d4 239 }
star297 1:f3f6624f45d4 240 if ((w + 2) < hor) { // x offset to next char
star297 1:f3f6624f45d4 241 char_x += w + 2;
star297 1:f3f6624f45d4 242 } else char_x += hor;
star297 1:f3f6624f45d4 243
star297 1:f3f6624f45d4 244 } else {
star297 1:f3f6624f45d4 245 // internal font
star297 1:f3f6624f45d4 246 if(value == '\n') {
star297 1:f3f6624f45d4 247 char_x = 0;
star297 1:f3f6624f45d4 248 char_y = char_y + Y_height;
star297 1:f3f6624f45d4 249 }
star297 1:f3f6624f45d4 250 if ((value < 31) || (value > 127)) return; // test char range
star297 1:f3f6624f45d4 251 if (char_x + X_width > width) {
star297 1:f3f6624f45d4 252 char_x = 0;
star297 1:f3f6624f45d4 253 char_y = char_y + Y_height;
star297 1:f3f6624f45d4 254 if (char_y >= height - Y_height) {
star297 1:f3f6624f45d4 255 char_y = 0;
star297 1:f3f6624f45d4 256 }
star297 1:f3f6624f45d4 257 }
star297 1:f3f6624f45d4 258 int i,j,w,lpx,lpy,k,l,xw;
star297 1:f3f6624f45d4 259 unsigned char Temp=0;
star297 1:f3f6624f45d4 260 j = 0; i = 0;
star297 1:f3f6624f45d4 261 w = X_width;
star297 1:f3f6624f45d4 262 FontSizeConvert(&lpx, &lpy);
star297 1:f3f6624f45d4 263 xw = X_width;
star297 1:f3f6624f45d4 264
star297 1:f3f6624f45d4 265 for(i=0; i<xw; i++) {
star297 1:f3f6624f45d4 266 for ( l=0; l<lpx; l++) {
star297 1:f3f6624f45d4 267 Temp = font6x8[value-32][i];
star297 1:f3f6624f45d4 268 for(j=Y_height-1; j>=0; j--) {
star297 1:f3f6624f45d4 269 for (k=0; k<lpy; k++) {
star297 1:f3f6624f45d4 270 pixel(char_x+(i*lpx)+l, char_y+(((j+1)*lpy)-1)-k, ((Temp & 0x80)==0x80) ? Char_Color : BGround_Color);
star297 1:f3f6624f45d4 271 }
star297 1:f3f6624f45d4 272 Temp = Temp << 1;
star297 1:f3f6624f45d4 273 }
star297 1:f3f6624f45d4 274 }
star297 1:f3f6624f45d4 275 }
star297 1:f3f6624f45d4 276 FontSizeConvert(&lpx, &lpy);
star297 1:f3f6624f45d4 277 char_x += (w*lpx);
star297 1:f3f6624f45d4 278 }
star297 1:f3f6624f45d4 279 }
star297 1:f3f6624f45d4 280
star297 1:f3f6624f45d4 281 void ssd1331::dim()
star297 1:f3f6624f45d4 282 {
star297 1:f3f6624f45d4 283 unsigned char cmd[5]= {GAC_DIM_WINDOW,0,0,width,height};
star297 1:f3f6624f45d4 284 RegWriteM(cmd,5);
star297 1:f3f6624f45d4 285 }
star297 1:f3f6624f45d4 286
star297 1:f3f6624f45d4 287 void ssd1331::contrast(char value)
star297 1:f3f6624f45d4 288 {
star297 1:f3f6624f45d4 289 int v = value*20;
star297 1:f3f6624f45d4 290 if(v>180) {
star297 1:f3f6624f45d4 291 v=180;
star297 1:f3f6624f45d4 292 }
star297 1:f3f6624f45d4 293 unsigned char cmd[7];
star297 1:f3f6624f45d4 294 cmd[0] = contrastA;
star297 1:f3f6624f45d4 295 cmd[1] = v;
star297 1:f3f6624f45d4 296 cmd[2] = contrastB;
star297 1:f3f6624f45d4 297 cmd[3] = v;
star297 1:f3f6624f45d4 298 cmd[4] = contrastC;
star297 1:f3f6624f45d4 299 cmd[5] = v;
star297 1:f3f6624f45d4 300 RegWriteM(cmd, 6);
star297 1:f3f6624f45d4 301 }
star297 1:f3f6624f45d4 302
star297 1:f3f6624f45d4 303 int ssd1331::toRGB(int R,int G,int B)
star297 2:1204274fad8f 304 {
star297 1:f3f6624f45d4 305 uint16_t c;
star297 1:f3f6624f45d4 306 c = R >> 3;
star297 1:f3f6624f45d4 307 c <<= 6;
star297 1:f3f6624f45d4 308 c |= G >> 2;
star297 1:f3f6624f45d4 309 c <<= 5;
star297 1:f3f6624f45d4 310 c |= B >> 3;
star297 1:f3f6624f45d4 311 return c;
star297 1:f3f6624f45d4 312 }
star297 1:f3f6624f45d4 313
star297 2:1204274fad8f 314 void ssd1331::rect(int x1,int y1,int x2,int y2,unsigned int colorline)
star297 1:f3f6624f45d4 315 {
star297 1:f3f6624f45d4 316 if ( x1 < 0 ) x1 = 0;
star297 1:f3f6624f45d4 317 else if ( x1 > width ) x1 = width;
star297 1:f3f6624f45d4 318 if ( y1 < 0 ) y1 = 0;
star297 1:f3f6624f45d4 319 else if ( y1 > height ) y1 = height;
star297 1:f3f6624f45d4 320 if ( x2 < 0 ) x2 = 0;
star297 1:f3f6624f45d4 321 else if ( x2 > width ) x2 = width;
star297 1:f3f6624f45d4 322 if ( y2 < 0 ) y2 = 0;
star297 1:f3f6624f45d4 323 else if ( y2 > height ) y2 = height;
star297 1:f3f6624f45d4 324
star297 1:f3f6624f45d4 325 unsigned char cmd[11]= { 0 };
star297 1:f3f6624f45d4 326 cmd[0] = GAC_FILL_ENABLE_DISABLE;
star297 1:f3f6624f45d4 327 cmd[1] = 0; // fill 1, empty 0
star297 1:f3f6624f45d4 328 RegWriteM(cmd, 2);
star297 1:f3f6624f45d4 329 cmd[0] = GAC_DRAW_RECTANGLE;
star297 1:f3f6624f45d4 330 cmd[1] = (unsigned char)x1;
star297 1:f3f6624f45d4 331 cmd[2] = (unsigned char)y1;
star297 1:f3f6624f45d4 332 cmd[3] = (unsigned char)x2;
star297 1:f3f6624f45d4 333 cmd[4] = (unsigned char)y2;
star297 1:f3f6624f45d4 334 cmd[5] = (unsigned char)((colorline>> 11) << 1); // Outline Blue
star297 1:f3f6624f45d4 335 cmd[6] = (unsigned char)((colorline>> 5 ) & 0x3F); // Outline Green
star297 1:f3f6624f45d4 336 cmd[7] = (unsigned char)((colorline<< 1 ) & 0x3F); // Outline Red
star297 1:f3f6624f45d4 337 cmd[8] = (0);
star297 1:f3f6624f45d4 338 cmd[9] = (0);
star297 1:f3f6624f45d4 339 cmd[10]= (0);
star297 1:f3f6624f45d4 340 RegWriteM(cmd, 11);
star297 1:f3f6624f45d4 341 wait_us(500);
star297 1:f3f6624f45d4 342 }
star297 1:f3f6624f45d4 343
star297 2:1204274fad8f 344 void ssd1331::fillrect(int x1,int y1,int x2,int y2,unsigned int colorline,unsigned int colorfill)
star297 1:f3f6624f45d4 345 {
star297 1:f3f6624f45d4 346 if ( x1 < 0 ) x1 = 0;
star297 1:f3f6624f45d4 347 else if ( x1 > width ) x1 = width;
star297 1:f3f6624f45d4 348 if ( y1 < 0 ) y1 = 0;
star297 1:f3f6624f45d4 349 else if ( y1 > height ) y1 = height;
star297 1:f3f6624f45d4 350 if ( x2 < 0 ) x2 = 0;
star297 1:f3f6624f45d4 351 else if ( x2 > width ) x2 = width;
star297 1:f3f6624f45d4 352 if ( y2 < 0 ) y2 = 0;
star297 1:f3f6624f45d4 353 else if ( y2 > height ) y2 = height;
star297 1:f3f6624f45d4 354
star297 1:f3f6624f45d4 355 unsigned char cmd[11]= { 0 };
star297 1:f3f6624f45d4 356 cmd[0] = GAC_FILL_ENABLE_DISABLE;
star297 1:f3f6624f45d4 357 cmd[1] = 1; // fill 1, empty 0
star297 1:f3f6624f45d4 358 RegWriteM(cmd, 2);
star297 1:f3f6624f45d4 359 cmd[0] = GAC_DRAW_RECTANGLE;
star297 1:f3f6624f45d4 360 cmd[1] = (unsigned char)x1;
star297 1:f3f6624f45d4 361 cmd[2] = (unsigned char)y1;
star297 1:f3f6624f45d4 362 cmd[3] = (unsigned char)x2;
star297 1:f3f6624f45d4 363 cmd[4] = (unsigned char)y2;
star297 1:f3f6624f45d4 364 cmd[5] = (unsigned char)((colorline>> 11) << 1); // Outline Blue
star297 1:f3f6624f45d4 365 cmd[6] = (unsigned char)((colorline>> 5 ) & 0x3F); // Outline Green
star297 1:f3f6624f45d4 366 cmd[7] = (unsigned char)((colorline<< 1 ) & 0x3F); // Outline Red
star297 1:f3f6624f45d4 367 cmd[8] = (unsigned char)((colorfill>> 11) << 1); // fill Blue
star297 1:f3f6624f45d4 368 cmd[9] = (unsigned char)((colorfill>> 5 ) & 0x3F); // fill Green
star297 1:f3f6624f45d4 369 cmd[10]= (unsigned char)((colorfill<< 1 ) & 0x3F); // fill Red
star297 1:f3f6624f45d4 370 RegWriteM(cmd, 11);
star297 1:f3f6624f45d4 371 wait_us(500);
star297 1:f3f6624f45d4 372 }
star297 1:f3f6624f45d4 373
star297 1:f3f6624f45d4 374 void ssd1331::line(int x1,int y1,int x2,int y2,unsigned int color)
star297 1:f3f6624f45d4 375 {
star297 1:f3f6624f45d4 376 if ( x1 < 0 ) x1 = 0;
star297 1:f3f6624f45d4 377 else if ( x1 > width ) x1 = width;
star297 1:f3f6624f45d4 378 if ( y1 < 0 ) y1 = 0;
star297 1:f3f6624f45d4 379 else if ( y1 > height ) y1 = height;
star297 1:f3f6624f45d4 380 if ( x2 < 0 ) x2 = 0;
star297 1:f3f6624f45d4 381 else if ( x2 > width ) x2 = width;
star297 1:f3f6624f45d4 382 if ( y2 < 0 ) y2 = 0;
star297 1:f3f6624f45d4 383 else if ( y2 > height ) y2 = height;
star297 1:f3f6624f45d4 384
star297 1:f3f6624f45d4 385 unsigned char cmd[11]= { 0 };
star297 1:f3f6624f45d4 386 cmd[0] = GAC_FILL_ENABLE_DISABLE;
star297 1:f3f6624f45d4 387 cmd[1] = 0; // fill 0, empty 0
star297 1:f3f6624f45d4 388 RegWriteM(cmd, 2);
star297 1:f3f6624f45d4 389 cmd[0] = GAC_DRAW_LINE;
star297 1:f3f6624f45d4 390 cmd[1] = (unsigned char)x1;
star297 1:f3f6624f45d4 391 cmd[2] = (unsigned char)y1;
star297 1:f3f6624f45d4 392 cmd[3] = (unsigned char)x2;
star297 1:f3f6624f45d4 393 cmd[4] = (unsigned char)y2;
star297 1:f3f6624f45d4 394 cmd[5] = (unsigned char)(((color>>11)&0x1F)<<1); // Blue
star297 1:f3f6624f45d4 395 cmd[6] = (unsigned char)((color>>5)&0x3F); // Green
star297 1:f3f6624f45d4 396 cmd[7] = (unsigned char)((color&0x1F)<<1); // Red
star297 1:f3f6624f45d4 397 RegWriteM(cmd, 8);
star297 1:f3f6624f45d4 398 wait_us(500);
star297 1:f3f6624f45d4 399 }
star297 1:f3f6624f45d4 400
star297 1:f3f6624f45d4 401 void ssd1331::circle (int radius, int x, int y , unsigned int col, int fill)
star297 1:f3f6624f45d4 402 {
star297 1:f3f6624f45d4 403 int cx, cy, d;
star297 1:f3f6624f45d4 404 d = 3 - 2 * radius;
star297 1:f3f6624f45d4 405 cy = radius;
star297 1:f3f6624f45d4 406 pixel(x, radius+y, col);
star297 1:f3f6624f45d4 407 pixel(x, -radius+y, col);
star297 1:f3f6624f45d4 408 pixel(radius+x, y, col);
star297 1:f3f6624f45d4 409 pixel(-radius+x, y, col);
star297 1:f3f6624f45d4 410 if(fill) {
star297 1:f3f6624f45d4 411 line(x,radius+y,x,-radius+y,col);
star297 1:f3f6624f45d4 412 line( radius+x,y,-radius+x,y,col);
star297 1:f3f6624f45d4 413 }
star297 1:f3f6624f45d4 414
star297 1:f3f6624f45d4 415 for (cx = 0; cx <= cy; cx++) {
star297 1:f3f6624f45d4 416 if(d>=0) {
star297 1:f3f6624f45d4 417 d+=10+4*cx-4*cy;
star297 1:f3f6624f45d4 418 cy--;
star297 1:f3f6624f45d4 419 } else {
star297 1:f3f6624f45d4 420 d+=6+4*cx;
star297 1:f3f6624f45d4 421 }
star297 1:f3f6624f45d4 422 pixel(cy+x, cx+y, col);
star297 1:f3f6624f45d4 423 pixel(cx+x, cy+y, col);
star297 1:f3f6624f45d4 424 pixel(-cx+x, cy+y, col);
star297 1:f3f6624f45d4 425 pixel(-cy+x, cx+y, col);
star297 1:f3f6624f45d4 426 pixel(-cy+x, -cx+y, col);
star297 1:f3f6624f45d4 427 pixel(-cx+x, -cy+y, col);
star297 1:f3f6624f45d4 428 pixel(cx+x, -cy+y, col);
star297 1:f3f6624f45d4 429 pixel(cy+x, -cx+y, col);
star297 1:f3f6624f45d4 430 if(fill) {
star297 1:f3f6624f45d4 431 line(cy+x, cx+y, cy+x, -cx+y, col);
star297 1:f3f6624f45d4 432 line(cx+x, cy+y, cx+x, -cy + y, col);
star297 1:f3f6624f45d4 433 line(-cx+x, cy+y, -cx+x, cy+y, col);
star297 1:f3f6624f45d4 434 line(-cy+x, cx+y, -cy+x, cx+y, col);
star297 1:f3f6624f45d4 435 line(-cy+x, -cx+y, -cy+x, cx+y, col);
star297 1:f3f6624f45d4 436 line(-cx+x, -cy+y, -cx+x, cy+y, col);
star297 1:f3f6624f45d4 437 line(cx+x, -cy+y, cx+x, cy+y, col);
star297 1:f3f6624f45d4 438 line(cy+x, -cx+y, cy+x, cx+y, col);
star297 1:f3f6624f45d4 439 }
star297 1:f3f6624f45d4 440 }
star297 1:f3f6624f45d4 441 }
star297 1:f3f6624f45d4 442
star297 1:f3f6624f45d4 443 void ssd1331::ScrollSet(int horizontal, int startline, int linecount, int vertical , int frame_interval)
star297 1:f3f6624f45d4 444 {
star297 1:f3f6624f45d4 445 unsigned char cmd[7];
star297 1:f3f6624f45d4 446 if((startline>height+1)||((startline+linecount)>height+1)) return ;
star297 1:f3f6624f45d4 447 if ( frame_interval > 3 ) frame_interval = 3;
star297 1:f3f6624f45d4 448 cmd[0] = SCROLL_SETUP; //
star297 1:f3f6624f45d4 449 cmd[1] = horizontal;
star297 1:f3f6624f45d4 450 cmd[2] = startline;
star297 1:f3f6624f45d4 451 cmd[3] = linecount;
star297 1:f3f6624f45d4 452 cmd[4] = vertical;
star297 1:f3f6624f45d4 453 cmd[5] = frame_interval;
star297 1:f3f6624f45d4 454 RegWriteM(cmd,6);
star297 1:f3f6624f45d4 455 }
star297 2:1204274fad8f 456
star297 2:1204274fad8f 457 void ssd1331::Bitmap(const uint8_t *bitmap, int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color) {
star297 1:f3f6624f45d4 458
star297 1:f3f6624f45d4 459 int16_t i, j, byteWidth = (w + 7) / 8;
star297 1:f3f6624f45d4 460 for(j=0; j<h; j++) {
star297 1:f3f6624f45d4 461 for(i=0; i<w; i++ ) {
star297 1:f3f6624f45d4 462 if(bitmap[ j * byteWidth + i / 8] & (128 >> (i & 7))) {
star297 1:f3f6624f45d4 463 pixel(x+i, y+j, color);
star297 1:f3f6624f45d4 464 }
star297 1:f3f6624f45d4 465 }
star297 1:f3f6624f45d4 466 }
star297 1:f3f6624f45d4 467 }
star297 1:f3f6624f45d4 468
star297 2:1204274fad8f 469 void ssd1331::Bitmap16( unsigned int x, unsigned int y, unsigned int w, unsigned int h, unsigned char *bitmap)
star297 2:1204274fad8f 470 {
star297 2:1204274fad8f 471 unsigned int i,j;
star297 2:1204274fad8f 472 int padd;
star297 2:1204274fad8f 473 unsigned short *bitmap_ptr = (unsigned short *)bitmap;
star297 2:1204274fad8f 474
star297 2:1204274fad8f 475 window(x, y, w, h);
star297 2:1204274fad8f 476 // the lines are padded to multiple of 4 bytes in a bitmap
star297 2:1204274fad8f 477 padd = -1;
star297 2:1204274fad8f 478 do {
star297 2:1204274fad8f 479 padd ++;
star297 2:1204274fad8f 480 } while (2*(w + padd)%4 != 0);
star297 2:1204274fad8f 481 window(x, y, w, h);
star297 2:1204274fad8f 482 bitmap_ptr += ((h - 1)* (w + padd));
star297 2:1204274fad8f 483
star297 2:1204274fad8f 484 for (j = 0; j < h; j++) { //Lines
star297 2:1204274fad8f 485 for (i = 0; i < w; i++) { // one line
star297 2:1204274fad8f 486 DataWrite_to(*bitmap_ptr);
star297 2:1204274fad8f 487 bitmap_ptr++;
star297 2:1204274fad8f 488 }
star297 2:1204274fad8f 489 bitmap_ptr -= 2*w;
star297 2:1204274fad8f 490 bitmap_ptr -= padd;
star297 2:1204274fad8f 491 }
star297 2:1204274fad8f 492 }
star297 1:f3f6624f45d4 493
star297 2:1204274fad8f 494 int ssd1331::Bitmap16SD( unsigned int x, unsigned int y, unsigned char *Name_BMP)
star297 2:1204274fad8f 495 {
star297 2:1204274fad8f 496 #define OffsetPixelWidth 18
star297 2:1204274fad8f 497 #define OffsetPixelHeigh 22
star297 2:1204274fad8f 498 #define OffsetFileSize 34
star297 2:1204274fad8f 499 #define OffsetPixData 10
star297 2:1204274fad8f 500 #define OffsetBPP 28
star297 1:f3f6624f45d4 501 char filename[50];
star297 1:f3f6624f45d4 502 unsigned char BMP_Header[54];
star297 1:f3f6624f45d4 503 unsigned short BPP_t;
star297 1:f3f6624f45d4 504 unsigned int PixelWidth,PixelHeigh,start_data;
star297 2:1204274fad8f 505 char * buffer;
star297 2:1204274fad8f 506 size_t result;
star297 2:1204274fad8f 507 int fileSize,padd,i,j;
star297 2:1204274fad8f 508
star297 1:f3f6624f45d4 509 i=0;
star297 1:f3f6624f45d4 510 while (*Name_BMP!='\0') {
star297 1:f3f6624f45d4 511 filename[i++]=*Name_BMP++;
star297 2:1204274fad8f 512 }
star297 2:1204274fad8f 513
star297 2:1204274fad8f 514 filename[i] = 0;
star297 1:f3f6624f45d4 515 FILE *Image = fopen((const char *)&filename[0], "rb"); // open the bmp file
star297 1:f3f6624f45d4 516 if (!Image) {
star297 1:f3f6624f45d4 517 return(0); // error file not found !
star297 1:f3f6624f45d4 518 }
star297 2:1204274fad8f 519
star297 1:f3f6624f45d4 520 fread(&BMP_Header[0],1,54,Image); // get the BMP Header
star297 2:1204274fad8f 521
star297 1:f3f6624f45d4 522 if (BMP_Header[0] != 0x42 || BMP_Header[1] != 0x4D) { // check magic byte
star297 1:f3f6624f45d4 523 fclose(Image);
star297 2:1204274fad8f 524 return(-1); // error not BMP file
star297 1:f3f6624f45d4 525 }
star297 2:1204274fad8f 526
star297 1:f3f6624f45d4 527 BPP_t = BMP_Header[OffsetBPP] + (BMP_Header[OffsetBPP + 1] << 8);
star297 1:f3f6624f45d4 528 if (BPP_t != 0x0010) {
star297 1:f3f6624f45d4 529 fclose(Image);
star297 2:1204274fad8f 530 return(-2); // error not 16 bit BMP
star297 1:f3f6624f45d4 531 }
star297 1:f3f6624f45d4 532 PixelHeigh = BMP_Header[OffsetPixelHeigh] + (BMP_Header[OffsetPixelHeigh + 1] << 8) + (BMP_Header[OffsetPixelHeigh + 2] << 16) + (BMP_Header[OffsetPixelHeigh + 3] << 24);
star297 1:f3f6624f45d4 533 PixelWidth = BMP_Header[OffsetPixelWidth] + (BMP_Header[OffsetPixelWidth + 1] << 8) + (BMP_Header[OffsetPixelWidth + 2] << 16) + (BMP_Header[OffsetPixelWidth + 3] << 24);
star297 2:1204274fad8f 534 if (PixelHeigh > height+1 + y || PixelWidth > width+1 + x) {
star297 1:f3f6624f45d4 535 fclose(Image);
star297 1:f3f6624f45d4 536 return(-3); // to big
star297 1:f3f6624f45d4 537 }
star297 1:f3f6624f45d4 538 start_data = BMP_Header[OffsetPixData] + (BMP_Header[OffsetPixData + 1] << 8) + (BMP_Header[OffsetPixData + 2] << 16) + (BMP_Header[OffsetPixData + 3] << 24);
star297 2:1204274fad8f 539
star297 2:1204274fad8f 540
star297 2:1204274fad8f 541 // obtain file size:
star297 2:1204274fad8f 542 fseek (Image , 0 , SEEK_END);
star297 2:1204274fad8f 543 fileSize = ftell (Image)-start_data;
star297 2:1204274fad8f 544 rewind (Image);
star297 2:1204274fad8f 545
star297 2:1204274fad8f 546 // allocate memory to contain the whole file:
star297 2:1204274fad8f 547 buffer = (char*) malloc (sizeof(char)*fileSize);
star297 2:1204274fad8f 548 if (buffer == NULL) {return (-4);}
star297 2:1204274fad8f 549
star297 2:1204274fad8f 550 // copy the file into the buffer:
star297 2:1204274fad8f 551 fseek (Image, start_data , SEEK_SET ); // set SD file data start position
star297 2:1204274fad8f 552 result = fread (buffer,1,fileSize,Image);
star297 2:1204274fad8f 553 fclose (Image);
star297 2:1204274fad8f 554 if (result != fileSize) {return (-5);}
star297 2:1204274fad8f 555
star297 2:1204274fad8f 556 unsigned short *bitmap_ptr = (unsigned short *)buffer;
star297 2:1204274fad8f 557
star297 2:1204274fad8f 558 window(x, y, PixelWidth, PixelHeigh);
star297 2:1204274fad8f 559 // the lines are padded to multiple of 4 bytes in a bitmap
star297 1:f3f6624f45d4 560 padd = -1;
star297 1:f3f6624f45d4 561 do {
star297 1:f3f6624f45d4 562 padd ++;
star297 2:1204274fad8f 563 } while (2*(PixelWidth + padd)%4 != 0);
star297 2:1204274fad8f 564
star297 2:1204274fad8f 565 bitmap_ptr += ((PixelHeigh - 1)* (PixelWidth + padd));
star297 1:f3f6624f45d4 566
star297 2:1204274fad8f 567 for (j = 0; j < PixelHeigh; j++) { //Lines
star297 2:1204274fad8f 568 for (i = 0; i < PixelWidth; i++) { // one line
star297 2:1204274fad8f 569 DataWrite_to(*bitmap_ptr);
star297 2:1204274fad8f 570 bitmap_ptr++;
star297 1:f3f6624f45d4 571 }
star297 2:1204274fad8f 572 bitmap_ptr -= 2*PixelWidth ;
star297 2:1204274fad8f 573 bitmap_ptr -= padd;
star297 2:1204274fad8f 574 }
star297 2:1204274fad8f 575 // terminate
star297 2:1204274fad8f 576 free (buffer);
star297 2:1204274fad8f 577 return (fileSize);
star297 1:f3f6624f45d4 578 }
star297 1:f3f6624f45d4 579
star297 1:f3f6624f45d4 580 void ssd1331::Copy(int src_x1,int src_y1,int src_x2,int src_y2, int dst_x,int dst_y)
star297 1:f3f6624f45d4 581 {
star297 1:f3f6624f45d4 582 unsigned char cmd[8]= { 0 };
star297 1:f3f6624f45d4 583 if ((src_x1>width)||(src_y1>height)||(src_x2>width)||(src_y2>height)) return;
star297 1:f3f6624f45d4 584 if ((dst_x>width)||(dst_y>height))return;
star297 1:f3f6624f45d4 585 cmd[0] = GAC_COPY_AREA; //
star297 1:f3f6624f45d4 586 cmd[1] = (unsigned char)src_x1;
star297 1:f3f6624f45d4 587 cmd[2] = (unsigned char)src_y1;
star297 1:f3f6624f45d4 588 cmd[3] = (unsigned char)src_x2;
star297 1:f3f6624f45d4 589 cmd[4] = (unsigned char)src_y2;
star297 1:f3f6624f45d4 590 cmd[5] = (unsigned char)dst_x;
star297 1:f3f6624f45d4 591 cmd[6] = (unsigned char)dst_y;
star297 1:f3f6624f45d4 592 RegWriteM(cmd,7);
star297 1:f3f6624f45d4 593 }
star297 1:f3f6624f45d4 594
star297 1:f3f6624f45d4 595 void ssd1331::Fill_Screen(unsigned int color)
star297 1:f3f6624f45d4 596 {
star297 1:f3f6624f45d4 597 BGround_Color = color;
star297 2:1204274fad8f 598 fillrect(0,0,width,height,color,color);
star297 1:f3f6624f45d4 599 }
star297 0:3d7d1aec706b 600
star297 0:3d7d1aec706b 601 void ssd1331::locate(int column, int row)
star297 0:3d7d1aec706b 602 {
star297 1:f3f6624f45d4 603 char_x = column;
star297 1:f3f6624f45d4 604 char_y = row;
star297 0:3d7d1aec706b 605 }
star297 0:3d7d1aec706b 606
star297 0:3d7d1aec706b 607 void ssd1331::foreground(unsigned int color)
star297 0:3d7d1aec706b 608 {
star297 0:3d7d1aec706b 609 Char_Color = color;
star297 0:3d7d1aec706b 610 }
star297 0:3d7d1aec706b 611 void ssd1331::background(unsigned int color)
star297 0:3d7d1aec706b 612 {
star297 0:3d7d1aec706b 613 BGround_Color = color;
star297 0:3d7d1aec706b 614 }
star297 0:3d7d1aec706b 615
star297 0:3d7d1aec706b 616 void ssd1331::SetFontSize(int Csize)
star297 0:3d7d1aec706b 617 {
star297 0:3d7d1aec706b 618 chr_size = Csize;
star297 0:3d7d1aec706b 619 }
star297 0:3d7d1aec706b 620
star297 1:f3f6624f45d4 621 void ssd1331::putp(int colour)
star297 0:3d7d1aec706b 622 {
star297 1:f3f6624f45d4 623 pixel(_x, _y, colour);
star297 1:f3f6624f45d4 624 // wait_us(1000);
star297 1:f3f6624f45d4 625 _x++;
star297 1:f3f6624f45d4 626 if(_x > _x2) {
star297 1:f3f6624f45d4 627 _x = _x1;
star297 1:f3f6624f45d4 628 _y++;
star297 1:f3f6624f45d4 629 if(_y > _y2) {
star297 1:f3f6624f45d4 630 _y = _y1;
star297 0:3d7d1aec706b 631 }
star297 0:3d7d1aec706b 632 }
star297 0:3d7d1aec706b 633 }
star297 0:3d7d1aec706b 634
star297 0:3d7d1aec706b 635 int ssd1331::_putc( int c )
star297 1:f3f6624f45d4 636 {
star297 1:f3f6624f45d4 637 PutChar( char_x , char_y ,c);
star297 0:3d7d1aec706b 638 return c;
star297 0:3d7d1aec706b 639 }
star297 0:3d7d1aec706b 640
star297 1:f3f6624f45d4 641 void ssd1331::pixel(int x,int y,unsigned int Color)
star297 1:f3f6624f45d4 642 {
star297 1:f3f6624f45d4 643 unsigned char cmd[7]= {Set_Column_Address,0x00,0x00,Set_Row_Address,0x00,0x00};
star297 1:f3f6624f45d4 644 if ((x<0)||(y<0)||(x>width)||(y>height)) return ;
star297 1:f3f6624f45d4 645 cmd[1] = (unsigned char)x;
star297 1:f3f6624f45d4 646 cmd[2] = (unsigned char)x;
star297 1:f3f6624f45d4 647 cmd[4] = (unsigned char)y;
star297 1:f3f6624f45d4 648 cmd[5] = (unsigned char)y;
star297 1:f3f6624f45d4 649 RegWriteM(cmd, 6);
star297 1:f3f6624f45d4 650 DataWrite_to(Color);
star297 1:f3f6624f45d4 651 }
star297 1:f3f6624f45d4 652
star297 2:1204274fad8f 653 void ssd1331::Maxwindow()
star297 2:1204274fad8f 654 {
star297 2:1204274fad8f 655 RegWrite(0x75); /* Set Row Address */
star297 2:1204274fad8f 656 RegWrite(0); /* Start = 0 */
star297 2:1204274fad8f 657 RegWrite(0x3F); /* End = 63 */
star297 2:1204274fad8f 658 RegWrite(0x15); /* Set Column Address */
star297 2:1204274fad8f 659 RegWrite(0); /* Start = 0 */
star297 2:1204274fad8f 660 RegWrite(0x5F); /* End = 95 */
star297 2:1204274fad8f 661 char_x = 0;
star297 2:1204274fad8f 662 char_y = 0;
star297 2:1204274fad8f 663 }
star297 2:1204274fad8f 664
star297 1:f3f6624f45d4 665 void ssd1331::window(int x, int y, int w, int h)
star297 1:f3f6624f45d4 666 {
star297 1:f3f6624f45d4 667 _x = x;
star297 1:f3f6624f45d4 668 _y = y;
star297 1:f3f6624f45d4 669 // window settings
star297 1:f3f6624f45d4 670 _x1 = x;
star297 1:f3f6624f45d4 671 _x2 = x + w - 1;
star297 1:f3f6624f45d4 672 _y1 = y;
star297 1:f3f6624f45d4 673 _y2 = y + h - 1;
star297 2:1204274fad8f 674 RegWrite(0x75); // Set Row Address
star297 2:1204274fad8f 675 RegWrite(_y); // Start y
star297 2:1204274fad8f 676 RegWrite(_y2); // End y
star297 2:1204274fad8f 677 RegWrite(0x15); // Set Column Address
star297 2:1204274fad8f 678 RegWrite(_x); // Start = x
star297 2:1204274fad8f 679 RegWrite(_x2); // End = x
star297 1:f3f6624f45d4 680 }
star297 1:f3f6624f45d4 681
star297 1:f3f6624f45d4 682 void ssd1331::Scrollstart()
star297 1:f3f6624f45d4 683 {
star297 1:f3f6624f45d4 684 RegWrite(SCROLL_START);
star297 1:f3f6624f45d4 685 }
star297 1:f3f6624f45d4 686
star297 1:f3f6624f45d4 687 void ssd1331::Scrollstop()
star297 1:f3f6624f45d4 688 {
star297 1:f3f6624f45d4 689 RegWrite(SCROLL_STOP);
star297 1:f3f6624f45d4 690 }
star297 1:f3f6624f45d4 691
star297 1:f3f6624f45d4 692 int ssd1331::_getc()
star297 0:3d7d1aec706b 693 {
star297 0:3d7d1aec706b 694 return -1;
star297 0:3d7d1aec706b 695 }
star297 0:3d7d1aec706b 696
star297 0:3d7d1aec706b 697 int ssd1331::row()
star297 0:3d7d1aec706b 698 {
star297 1:f3f6624f45d4 699 return char_y;
star297 0:3d7d1aec706b 700 }
star297 0:3d7d1aec706b 701 int ssd1331::column()
star297 0:3d7d1aec706b 702 {
star297 1:f3f6624f45d4 703 return char_x;
star297 0:3d7d1aec706b 704 }
star297 0:3d7d1aec706b 705
star297 0:3d7d1aec706b 706 void ssd1331::FontSizeConvert(int *lpx,int *lpy)
star297 0:3d7d1aec706b 707 {
star297 1:f3f6624f45d4 708 switch( chr_size ) {
star297 1:f3f6624f45d4 709 case WIDE:
star297 1:f3f6624f45d4 710 *lpx=2;
star297 1:f3f6624f45d4 711 *lpy=1;
star297 1:f3f6624f45d4 712 break;
star297 1:f3f6624f45d4 713 case HIGH:
star297 1:f3f6624f45d4 714 *lpx=1;
star297 1:f3f6624f45d4 715 *lpy=2;
star297 1:f3f6624f45d4 716 break;
star297 1:f3f6624f45d4 717 case WH :
star297 1:f3f6624f45d4 718 *lpx=2;
star297 1:f3f6624f45d4 719 *lpy=2;
star297 1:f3f6624f45d4 720 break;
star297 1:f3f6624f45d4 721 case WHx36 :
star297 1:f3f6624f45d4 722 *lpx=6;
star297 1:f3f6624f45d4 723 *lpy=6;
star297 1:f3f6624f45d4 724 break;
star297 1:f3f6624f45d4 725 case NORMAL:
star297 1:f3f6624f45d4 726 default:
star297 1:f3f6624f45d4 727 *lpx=1;
star297 1:f3f6624f45d4 728 *lpy=1;
star297 1:f3f6624f45d4 729 break;
star297 1:f3f6624f45d4 730 }
star297 0:3d7d1aec706b 731 }
star297 0:3d7d1aec706b 732
star297 0:3d7d1aec706b 733 void ssd1331::RegWrite(unsigned char Command)
star297 0:3d7d1aec706b 734 {
star297 0:3d7d1aec706b 735 DC = 0; // Command
star297 0:3d7d1aec706b 736 CS = 0; // CS enable
star297 0:3d7d1aec706b 737 spi.write(Command);
star297 0:3d7d1aec706b 738 CS = 1; // CS dissable
star297 0:3d7d1aec706b 739 }
star297 0:3d7d1aec706b 740
star297 0:3d7d1aec706b 741 void ssd1331::RegWriteM(unsigned char *Command, int count)
star297 0:3d7d1aec706b 742 {
star297 0:3d7d1aec706b 743 int i;
star297 0:3d7d1aec706b 744 DC = 0; // Command
star297 0:3d7d1aec706b 745 CS = 0; // CS enable
star297 1:f3f6624f45d4 746 for( i=0; i<count; i++) {
star297 1:f3f6624f45d4 747 spi.write(*Command++);
star297 0:3d7d1aec706b 748 }
star297 0:3d7d1aec706b 749 CS = 1; // CS dissable
star297 0:3d7d1aec706b 750 }
star297 0:3d7d1aec706b 751
star297 0:3d7d1aec706b 752 void ssd1331::DataWrite(unsigned char c)
star297 0:3d7d1aec706b 753 {
star297 1:f3f6624f45d4 754 DC = 1; // DATA
star297 1:f3f6624f45d4 755 CS = 0; // CS enable
star297 1:f3f6624f45d4 756 spi.write(c);
star297 1:f3f6624f45d4 757 CS = 1; // CS dissable
star297 0:3d7d1aec706b 758 }
star297 0:3d7d1aec706b 759
star297 0:3d7d1aec706b 760 void ssd1331::DataWrite_to(unsigned int Dat)
star297 0:3d7d1aec706b 761 {
star297 1:f3f6624f45d4 762 DC = 1; // DATA
star297 2:1204274fad8f 763 CS = 0; // CS enable
star297 1:f3f6624f45d4 764 spi.write((unsigned char)((Dat >> 8)));
star297 1:f3f6624f45d4 765 spi.write((unsigned char)(Dat));
star297 1:f3f6624f45d4 766 CS = 1; // CS dissable
star297 0:3d7d1aec706b 767 }