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