SSD1331 Oled driver library for 96x64 colour Oled display. Demo included in .h file
Dependents: Oled-SSD1331 PJ12_device
ssd1331.cpp@5:4385fd242db0, 2016-05-29 (annotated)
- Committer:
- star297
- Date:
- Sun May 29 17:59:51 2016 +0000
- Revision:
- 5:4385fd242db0
- Parent:
- 4:062b4708eb35
Minor update
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 | 4:062b4708eb35 | 201 | void ssd1331::PutChar(uint8_t column,uint8_t row, int value) |
star297 | 1:f3f6624f45d4 | 202 | { |
star297 | 1:f3f6624f45d4 | 203 | if(externalfont) { // external font |
star297 | 4:062b4708eb35 | 204 | uint8_t 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 | 4:062b4708eb35 | 301 | uint16_t ssd1331::toRGB(uint16_t R,uint16_t G,uint16_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 | 4:062b4708eb35 | 312 | void ssd1331::rect(uint8_t x1,uint8_t y1,uint8_t x2,uint8_t y2,uint16_t colorline) |
star297 | 1:f3f6624f45d4 | 313 | { |
star297 | 4:062b4708eb35 | 314 | if ( x1 > width ) x1 = width; |
star297 | 4:062b4708eb35 | 315 | if ( y1 > height ) y1 = height; |
star297 | 4:062b4708eb35 | 316 | if ( x2 > width ) x2 = width; |
star297 | 4:062b4708eb35 | 317 | if ( y2 > height ) y2 = height; |
star297 | 1:f3f6624f45d4 | 318 | |
star297 | 1:f3f6624f45d4 | 319 | unsigned char cmd[11]= { 0 }; |
star297 | 1:f3f6624f45d4 | 320 | cmd[0] = GAC_FILL_ENABLE_DISABLE; |
star297 | 1:f3f6624f45d4 | 321 | cmd[1] = 0; // fill 1, empty 0 |
star297 | 1:f3f6624f45d4 | 322 | RegWriteM(cmd, 2); |
star297 | 1:f3f6624f45d4 | 323 | cmd[0] = GAC_DRAW_RECTANGLE; |
star297 | 1:f3f6624f45d4 | 324 | cmd[1] = (unsigned char)x1; |
star297 | 1:f3f6624f45d4 | 325 | cmd[2] = (unsigned char)y1; |
star297 | 1:f3f6624f45d4 | 326 | cmd[3] = (unsigned char)x2; |
star297 | 1:f3f6624f45d4 | 327 | cmd[4] = (unsigned char)y2; |
star297 | 1:f3f6624f45d4 | 328 | cmd[5] = (unsigned char)((colorline>> 11) << 1); // Outline Blue |
star297 | 1:f3f6624f45d4 | 329 | cmd[6] = (unsigned char)((colorline>> 5 ) & 0x3F); // Outline Green |
star297 | 1:f3f6624f45d4 | 330 | cmd[7] = (unsigned char)((colorline<< 1 ) & 0x3F); // Outline Red |
star297 | 1:f3f6624f45d4 | 331 | cmd[8] = (0); |
star297 | 1:f3f6624f45d4 | 332 | cmd[9] = (0); |
star297 | 1:f3f6624f45d4 | 333 | cmd[10]= (0); |
star297 | 1:f3f6624f45d4 | 334 | RegWriteM(cmd, 11); |
star297 | 1:f3f6624f45d4 | 335 | wait_us(500); |
star297 | 1:f3f6624f45d4 | 336 | } |
star297 | 1:f3f6624f45d4 | 337 | |
star297 | 4:062b4708eb35 | 338 | void ssd1331::fillrect(uint8_t x1,uint8_t y1,uint8_t x2,uint8_t y2,uint16_t colorline,uint16_t colorfill) |
star297 | 1:f3f6624f45d4 | 339 | { |
star297 | 4:062b4708eb35 | 340 | if ( x1 > width ) x1 = width; |
star297 | 4:062b4708eb35 | 341 | if ( y1 > height ) y1 = height; |
star297 | 4:062b4708eb35 | 342 | if ( x2 > width ) x2 = width; |
star297 | 4:062b4708eb35 | 343 | if ( y2 > height ) y2 = height; |
star297 | 1:f3f6624f45d4 | 344 | |
star297 | 1:f3f6624f45d4 | 345 | unsigned char cmd[11]= { 0 }; |
star297 | 1:f3f6624f45d4 | 346 | cmd[0] = GAC_FILL_ENABLE_DISABLE; |
star297 | 1:f3f6624f45d4 | 347 | cmd[1] = 1; // fill 1, empty 0 |
star297 | 1:f3f6624f45d4 | 348 | RegWriteM(cmd, 2); |
star297 | 1:f3f6624f45d4 | 349 | cmd[0] = GAC_DRAW_RECTANGLE; |
star297 | 1:f3f6624f45d4 | 350 | cmd[1] = (unsigned char)x1; |
star297 | 1:f3f6624f45d4 | 351 | cmd[2] = (unsigned char)y1; |
star297 | 1:f3f6624f45d4 | 352 | cmd[3] = (unsigned char)x2; |
star297 | 1:f3f6624f45d4 | 353 | cmd[4] = (unsigned char)y2; |
star297 | 1:f3f6624f45d4 | 354 | cmd[5] = (unsigned char)((colorline>> 11) << 1); // Outline Blue |
star297 | 1:f3f6624f45d4 | 355 | cmd[6] = (unsigned char)((colorline>> 5 ) & 0x3F); // Outline Green |
star297 | 1:f3f6624f45d4 | 356 | cmd[7] = (unsigned char)((colorline<< 1 ) & 0x3F); // Outline Red |
star297 | 1:f3f6624f45d4 | 357 | cmd[8] = (unsigned char)((colorfill>> 11) << 1); // fill Blue |
star297 | 1:f3f6624f45d4 | 358 | cmd[9] = (unsigned char)((colorfill>> 5 ) & 0x3F); // fill Green |
star297 | 1:f3f6624f45d4 | 359 | cmd[10]= (unsigned char)((colorfill<< 1 ) & 0x3F); // fill Red |
star297 | 1:f3f6624f45d4 | 360 | RegWriteM(cmd, 11); |
star297 | 1:f3f6624f45d4 | 361 | wait_us(500); |
star297 | 1:f3f6624f45d4 | 362 | } |
star297 | 1:f3f6624f45d4 | 363 | |
star297 | 4:062b4708eb35 | 364 | void ssd1331::line(uint8_t x1,uint8_t y1,uint8_t x2,uint8_t y2,uint16_t color) |
star297 | 1:f3f6624f45d4 | 365 | { |
star297 | 4:062b4708eb35 | 366 | if ( x1 > width ) x1 = width; |
star297 | 4:062b4708eb35 | 367 | if ( y1 > height ) y1 = height; |
star297 | 4:062b4708eb35 | 368 | if ( x2 > width ) x2 = width; |
star297 | 4:062b4708eb35 | 369 | if ( y2 > height ) y2 = height; |
star297 | 1:f3f6624f45d4 | 370 | |
star297 | 1:f3f6624f45d4 | 371 | unsigned char cmd[11]= { 0 }; |
star297 | 1:f3f6624f45d4 | 372 | cmd[0] = GAC_FILL_ENABLE_DISABLE; |
star297 | 1:f3f6624f45d4 | 373 | cmd[1] = 0; // fill 0, empty 0 |
star297 | 1:f3f6624f45d4 | 374 | RegWriteM(cmd, 2); |
star297 | 1:f3f6624f45d4 | 375 | cmd[0] = GAC_DRAW_LINE; |
star297 | 1:f3f6624f45d4 | 376 | cmd[1] = (unsigned char)x1; |
star297 | 1:f3f6624f45d4 | 377 | cmd[2] = (unsigned char)y1; |
star297 | 1:f3f6624f45d4 | 378 | cmd[3] = (unsigned char)x2; |
star297 | 1:f3f6624f45d4 | 379 | cmd[4] = (unsigned char)y2; |
star297 | 1:f3f6624f45d4 | 380 | cmd[5] = (unsigned char)(((color>>11)&0x1F)<<1); // Blue |
star297 | 1:f3f6624f45d4 | 381 | cmd[6] = (unsigned char)((color>>5)&0x3F); // Green |
star297 | 1:f3f6624f45d4 | 382 | cmd[7] = (unsigned char)((color&0x1F)<<1); // Red |
star297 | 1:f3f6624f45d4 | 383 | RegWriteM(cmd, 8); |
star297 | 1:f3f6624f45d4 | 384 | wait_us(500); |
star297 | 1:f3f6624f45d4 | 385 | } |
star297 | 1:f3f6624f45d4 | 386 | |
star297 | 4:062b4708eb35 | 387 | void ssd1331::circle (uint8_t radius, uint8_t x, uint8_t y , uint16_t col, uint16_t fill) |
star297 | 1:f3f6624f45d4 | 388 | { |
star297 | 4:062b4708eb35 | 389 | if ( x > width ) x = width; |
star297 | 4:062b4708eb35 | 390 | if ( y > height ) y = height; |
star297 | 4:062b4708eb35 | 391 | |
star297 | 4:062b4708eb35 | 392 | int16_t cx, cy, d; |
star297 | 1:f3f6624f45d4 | 393 | d = 3 - 2 * radius; |
star297 | 1:f3f6624f45d4 | 394 | cy = radius; |
star297 | 1:f3f6624f45d4 | 395 | pixel(x, radius+y, col); |
star297 | 1:f3f6624f45d4 | 396 | pixel(x, -radius+y, col); |
star297 | 1:f3f6624f45d4 | 397 | pixel(radius+x, y, col); |
star297 | 1:f3f6624f45d4 | 398 | pixel(-radius+x, y, col); |
star297 | 1:f3f6624f45d4 | 399 | if(fill) { |
star297 | 1:f3f6624f45d4 | 400 | line(x,radius+y,x,-radius+y,col); |
star297 | 1:f3f6624f45d4 | 401 | line( radius+x,y,-radius+x,y,col); |
star297 | 1:f3f6624f45d4 | 402 | } |
star297 | 1:f3f6624f45d4 | 403 | |
star297 | 1:f3f6624f45d4 | 404 | for (cx = 0; cx <= cy; cx++) { |
star297 | 1:f3f6624f45d4 | 405 | if(d>=0) { |
star297 | 1:f3f6624f45d4 | 406 | d+=10+4*cx-4*cy; |
star297 | 1:f3f6624f45d4 | 407 | cy--; |
star297 | 1:f3f6624f45d4 | 408 | } else { |
star297 | 1:f3f6624f45d4 | 409 | d+=6+4*cx; |
star297 | 1:f3f6624f45d4 | 410 | } |
star297 | 1:f3f6624f45d4 | 411 | pixel(cy+x, cx+y, col); |
star297 | 1:f3f6624f45d4 | 412 | pixel(cx+x, cy+y, col); |
star297 | 1:f3f6624f45d4 | 413 | pixel(-cx+x, cy+y, col); |
star297 | 1:f3f6624f45d4 | 414 | pixel(-cy+x, cx+y, col); |
star297 | 1:f3f6624f45d4 | 415 | pixel(-cy+x, -cx+y, col); |
star297 | 1:f3f6624f45d4 | 416 | pixel(-cx+x, -cy+y, col); |
star297 | 1:f3f6624f45d4 | 417 | pixel(cx+x, -cy+y, col); |
star297 | 1:f3f6624f45d4 | 418 | pixel(cy+x, -cx+y, col); |
star297 | 1:f3f6624f45d4 | 419 | if(fill) { |
star297 | 1:f3f6624f45d4 | 420 | line(cy+x, cx+y, cy+x, -cx+y, col); |
star297 | 1:f3f6624f45d4 | 421 | line(cx+x, cy+y, cx+x, -cy + y, col); |
star297 | 1:f3f6624f45d4 | 422 | line(-cx+x, cy+y, -cx+x, cy+y, col); |
star297 | 1:f3f6624f45d4 | 423 | line(-cy+x, cx+y, -cy+x, cx+y, col); |
star297 | 1:f3f6624f45d4 | 424 | line(-cy+x, -cx+y, -cy+x, cx+y, col); |
star297 | 1:f3f6624f45d4 | 425 | line(-cx+x, -cy+y, -cx+x, cy+y, col); |
star297 | 1:f3f6624f45d4 | 426 | line(cx+x, -cy+y, cx+x, cy+y, col); |
star297 | 1:f3f6624f45d4 | 427 | line(cy+x, -cx+y, cy+x, cx+y, col); |
star297 | 1:f3f6624f45d4 | 428 | } |
star297 | 1:f3f6624f45d4 | 429 | } |
star297 | 1:f3f6624f45d4 | 430 | } |
star297 | 1:f3f6624f45d4 | 431 | |
star297 | 4:062b4708eb35 | 432 | void ssd1331::ScrollSet(int8_t horizontal, int8_t startline, int8_t linecount, int8_t vertical , int8_t frame_interval) |
star297 | 1:f3f6624f45d4 | 433 | { |
star297 | 1:f3f6624f45d4 | 434 | unsigned char cmd[7]; |
star297 | 1:f3f6624f45d4 | 435 | if((startline>height+1)||((startline+linecount)>height+1)) return ; |
star297 | 1:f3f6624f45d4 | 436 | if ( frame_interval > 3 ) frame_interval = 3; |
star297 | 1:f3f6624f45d4 | 437 | cmd[0] = SCROLL_SETUP; // |
star297 | 1:f3f6624f45d4 | 438 | cmd[1] = horizontal; |
star297 | 1:f3f6624f45d4 | 439 | cmd[2] = startline; |
star297 | 1:f3f6624f45d4 | 440 | cmd[3] = linecount; |
star297 | 1:f3f6624f45d4 | 441 | cmd[4] = vertical; |
star297 | 1:f3f6624f45d4 | 442 | cmd[5] = frame_interval; |
star297 | 1:f3f6624f45d4 | 443 | RegWriteM(cmd,6); |
star297 | 1:f3f6624f45d4 | 444 | } |
star297 | 2:1204274fad8f | 445 | |
star297 | 4:062b4708eb35 | 446 | void ssd1331::Bitmap(const uint8_t *bitmap, uint8_t x, uint8_t y, uint8_t w, uint8_t h, unsigned char color) { |
star297 | 1:f3f6624f45d4 | 447 | |
star297 | 3:a4caac512e13 | 448 | window(x, y, w, h); |
star297 | 3:a4caac512e13 | 449 | int16_t i, j, byteWidth = (w + 7) / 8; |
star297 | 3:a4caac512e13 | 450 | for(j=0; j<h; j++) { |
star297 | 3:a4caac512e13 | 451 | for(i=0; i<w; i++ ) { |
star297 | 3:a4caac512e13 | 452 | if(bitmap[ j * byteWidth + i / 8] & (128 >> (i & 7))) { |
star297 | 3:a4caac512e13 | 453 | pixel(x+i, y+j, color); |
star297 | 3:a4caac512e13 | 454 | } |
star297 | 1:f3f6624f45d4 | 455 | } |
star297 | 1:f3f6624f45d4 | 456 | } |
star297 | 3:a4caac512e13 | 457 | Maxwindow(); |
star297 | 1:f3f6624f45d4 | 458 | } |
star297 | 1:f3f6624f45d4 | 459 | |
star297 | 4:062b4708eb35 | 460 | void ssd1331::Bitmap16(uint8_t x, uint8_t y, uint8_t w, uint8_t h, const uint8_t *bitmap) |
star297 | 2:1204274fad8f | 461 | { |
star297 | 5:4385fd242db0 | 462 | int8_t i,j; |
star297 | 5:4385fd242db0 | 463 | int8_t padd; |
star297 | 2:1204274fad8f | 464 | unsigned short *bitmap_ptr = (unsigned short *)bitmap; |
star297 | 2:1204274fad8f | 465 | |
star297 | 2:1204274fad8f | 466 | window(x, y, w, h); |
star297 | 2:1204274fad8f | 467 | // the lines are padded to multiple of 4 bytes in a bitmap |
star297 | 2:1204274fad8f | 468 | padd = -1; |
star297 | 2:1204274fad8f | 469 | do { |
star297 | 2:1204274fad8f | 470 | padd ++; |
star297 | 2:1204274fad8f | 471 | } while (2*(w + padd)%4 != 0); |
star297 | 4:062b4708eb35 | 472 | |
star297 | 2:1204274fad8f | 473 | window(x, y, w, h); |
star297 | 4:062b4708eb35 | 474 | |
star297 | 2:1204274fad8f | 475 | bitmap_ptr += ((h - 1)* (w + padd)); |
star297 | 2:1204274fad8f | 476 | |
star297 | 2:1204274fad8f | 477 | for (j = 0; j < h; j++) { //Lines |
star297 | 2:1204274fad8f | 478 | for (i = 0; i < w; i++) { // one line |
star297 | 2:1204274fad8f | 479 | DataWrite_to(*bitmap_ptr); |
star297 | 2:1204274fad8f | 480 | bitmap_ptr++; |
star297 | 2:1204274fad8f | 481 | } |
star297 | 2:1204274fad8f | 482 | bitmap_ptr -= 2*w; |
star297 | 2:1204274fad8f | 483 | bitmap_ptr -= padd; |
star297 | 2:1204274fad8f | 484 | } |
star297 | 3:a4caac512e13 | 485 | Maxwindow(); |
star297 | 2:1204274fad8f | 486 | } |
star297 | 1:f3f6624f45d4 | 487 | |
star297 | 4:062b4708eb35 | 488 | int ssd1331::Bitmap16RAM(uint8_t x, uint8_t y, unsigned char *Name_BMP) |
star297 | 2:1204274fad8f | 489 | { |
star297 | 2:1204274fad8f | 490 | #define OffsetPixelWidth 18 |
star297 | 2:1204274fad8f | 491 | #define OffsetPixelHeigh 22 |
star297 | 2:1204274fad8f | 492 | #define OffsetFileSize 34 |
star297 | 2:1204274fad8f | 493 | #define OffsetPixData 10 |
star297 | 2:1204274fad8f | 494 | #define OffsetBPP 28 |
star297 | 1:f3f6624f45d4 | 495 | char filename[50]; |
star297 | 1:f3f6624f45d4 | 496 | unsigned char BMP_Header[54]; |
star297 | 1:f3f6624f45d4 | 497 | unsigned short BPP_t; |
star297 | 1:f3f6624f45d4 | 498 | unsigned int PixelWidth,PixelHeigh,start_data; |
star297 | 2:1204274fad8f | 499 | char * buffer; |
star297 | 2:1204274fad8f | 500 | size_t result; |
star297 | 2:1204274fad8f | 501 | int fileSize,padd,i,j; |
star297 | 2:1204274fad8f | 502 | |
star297 | 1:f3f6624f45d4 | 503 | i=0; |
star297 | 1:f3f6624f45d4 | 504 | while (*Name_BMP!='\0') { |
star297 | 1:f3f6624f45d4 | 505 | filename[i++]=*Name_BMP++; |
star297 | 2:1204274fad8f | 506 | } |
star297 | 2:1204274fad8f | 507 | |
star297 | 2:1204274fad8f | 508 | filename[i] = 0; |
star297 | 1:f3f6624f45d4 | 509 | FILE *Image = fopen((const char *)&filename[0], "rb"); // open the bmp file |
star297 | 1:f3f6624f45d4 | 510 | if (!Image) { |
star297 | 1:f3f6624f45d4 | 511 | return(0); // error file not found ! |
star297 | 1:f3f6624f45d4 | 512 | } |
star297 | 2:1204274fad8f | 513 | |
star297 | 1:f3f6624f45d4 | 514 | fread(&BMP_Header[0],1,54,Image); // get the BMP Header |
star297 | 2:1204274fad8f | 515 | |
star297 | 1:f3f6624f45d4 | 516 | if (BMP_Header[0] != 0x42 || BMP_Header[1] != 0x4D) { // check magic byte |
star297 | 1:f3f6624f45d4 | 517 | fclose(Image); |
star297 | 2:1204274fad8f | 518 | return(-1); // error not BMP file |
star297 | 1:f3f6624f45d4 | 519 | } |
star297 | 2:1204274fad8f | 520 | |
star297 | 1:f3f6624f45d4 | 521 | BPP_t = BMP_Header[OffsetBPP] + (BMP_Header[OffsetBPP + 1] << 8); |
star297 | 1:f3f6624f45d4 | 522 | if (BPP_t != 0x0010) { |
star297 | 1:f3f6624f45d4 | 523 | fclose(Image); |
star297 | 2:1204274fad8f | 524 | return(-2); // error not 16 bit BMP |
star297 | 1:f3f6624f45d4 | 525 | } |
star297 | 1:f3f6624f45d4 | 526 | PixelHeigh = BMP_Header[OffsetPixelHeigh] + (BMP_Header[OffsetPixelHeigh + 1] << 8) + (BMP_Header[OffsetPixelHeigh + 2] << 16) + (BMP_Header[OffsetPixelHeigh + 3] << 24); |
star297 | 1:f3f6624f45d4 | 527 | PixelWidth = BMP_Header[OffsetPixelWidth] + (BMP_Header[OffsetPixelWidth + 1] << 8) + (BMP_Header[OffsetPixelWidth + 2] << 16) + (BMP_Header[OffsetPixelWidth + 3] << 24); |
star297 | 2:1204274fad8f | 528 | if (PixelHeigh > height+1 + y || PixelWidth > width+1 + x) { |
star297 | 1:f3f6624f45d4 | 529 | fclose(Image); |
star297 | 1:f3f6624f45d4 | 530 | return(-3); // to big |
star297 | 1:f3f6624f45d4 | 531 | } |
star297 | 3:a4caac512e13 | 532 | |
star297 | 1:f3f6624f45d4 | 533 | start_data = BMP_Header[OffsetPixData] + (BMP_Header[OffsetPixData + 1] << 8) + (BMP_Header[OffsetPixData + 2] << 16) + (BMP_Header[OffsetPixData + 3] << 24); |
star297 | 2:1204274fad8f | 534 | |
star297 | 2:1204274fad8f | 535 | // obtain file size: |
star297 | 2:1204274fad8f | 536 | fseek (Image , 0 , SEEK_END); |
star297 | 2:1204274fad8f | 537 | fileSize = ftell (Image)-start_data; |
star297 | 2:1204274fad8f | 538 | rewind (Image); |
star297 | 2:1204274fad8f | 539 | |
star297 | 2:1204274fad8f | 540 | // allocate memory to contain the whole file: |
star297 | 3:a4caac512e13 | 541 | buffer = (char*) malloc (sizeof(char)*fileSize/2); |
star297 | 3:a4caac512e13 | 542 | if (buffer == NULL) {return (fileSize/2);} |
star297 | 2:1204274fad8f | 543 | |
star297 | 2:1204274fad8f | 544 | // copy the file into the buffer: |
star297 | 2:1204274fad8f | 545 | fseek (Image, start_data , SEEK_SET ); // set SD file data start position |
star297 | 2:1204274fad8f | 546 | result = fread (buffer,1,fileSize,Image); |
star297 | 2:1204274fad8f | 547 | fclose (Image); |
star297 | 3:a4caac512e13 | 548 | if (result != fileSize) {return (-5);} |
star297 | 2:1204274fad8f | 549 | |
star297 | 3:a4caac512e13 | 550 | unsigned short *bitmap_ptr = (unsigned short *)buffer; |
star297 | 3:a4caac512e13 | 551 | |
star297 | 2:1204274fad8f | 552 | // the lines are padded to multiple of 4 bytes in a bitmap |
star297 | 1:f3f6624f45d4 | 553 | padd = -1; |
star297 | 1:f3f6624f45d4 | 554 | do { |
star297 | 1:f3f6624f45d4 | 555 | padd ++; |
star297 | 2:1204274fad8f | 556 | } while (2*(PixelWidth + padd)%4 != 0); |
star297 | 3:a4caac512e13 | 557 | |
star297 | 2:1204274fad8f | 558 | bitmap_ptr += ((PixelHeigh - 1)* (PixelWidth + padd)); |
star297 | 3:a4caac512e13 | 559 | |
star297 | 3:a4caac512e13 | 560 | window(x, y, PixelWidth, PixelHeigh); |
star297 | 1:f3f6624f45d4 | 561 | |
star297 | 2:1204274fad8f | 562 | for (j = 0; j < PixelHeigh; j++) { //Lines |
star297 | 2:1204274fad8f | 563 | for (i = 0; i < PixelWidth; i++) { // one line |
star297 | 2:1204274fad8f | 564 | DataWrite_to(*bitmap_ptr); |
star297 | 2:1204274fad8f | 565 | bitmap_ptr++; |
star297 | 1:f3f6624f45d4 | 566 | } |
star297 | 2:1204274fad8f | 567 | bitmap_ptr -= 2*PixelWidth ; |
star297 | 2:1204274fad8f | 568 | bitmap_ptr -= padd; |
star297 | 2:1204274fad8f | 569 | } |
star297 | 2:1204274fad8f | 570 | // terminate |
star297 | 2:1204274fad8f | 571 | free (buffer); |
star297 | 3:a4caac512e13 | 572 | Maxwindow(); |
star297 | 2:1204274fad8f | 573 | return (fileSize); |
star297 | 1:f3f6624f45d4 | 574 | } |
star297 | 1:f3f6624f45d4 | 575 | |
star297 | 4:062b4708eb35 | 576 | int ssd1331::Bitmap16FS(uint8_t x, uint8_t y, unsigned char *Name_BMP) { |
star297 | 3:a4caac512e13 | 577 | #define OffsetPixelWidth 18 |
star297 | 3:a4caac512e13 | 578 | #define OffsetPixelHeigh 22 |
star297 | 3:a4caac512e13 | 579 | #define OffsetFileSize 34 |
star297 | 3:a4caac512e13 | 580 | #define OffsetPixData 10 |
star297 | 3:a4caac512e13 | 581 | #define OffsetBPP 28 |
star297 | 3:a4caac512e13 | 582 | char filename[50]; |
star297 | 3:a4caac512e13 | 583 | unsigned char BMP_Header[54]; |
star297 | 3:a4caac512e13 | 584 | unsigned short BPP_t; |
star297 | 3:a4caac512e13 | 585 | unsigned int PixelWidth,PixelHeigh,start_data; |
star297 | 3:a4caac512e13 | 586 | unsigned int i,off; |
star297 | 3:a4caac512e13 | 587 | int padd,j; |
star297 | 3:a4caac512e13 | 588 | unsigned short *line; |
star297 | 3:a4caac512e13 | 589 | |
star297 | 3:a4caac512e13 | 590 | i=0; |
star297 | 3:a4caac512e13 | 591 | while (*Name_BMP!='\0') { |
star297 | 3:a4caac512e13 | 592 | filename[i++]=*Name_BMP++; |
star297 | 3:a4caac512e13 | 593 | } |
star297 | 3:a4caac512e13 | 594 | |
star297 | 3:a4caac512e13 | 595 | filename[i] = 0; |
star297 | 3:a4caac512e13 | 596 | FILE *Image = fopen((const char *)&filename[0], "rb"); // open the bmp file |
star297 | 3:a4caac512e13 | 597 | if (!Image) { |
star297 | 3:a4caac512e13 | 598 | return(0); // error file not found ! |
star297 | 3:a4caac512e13 | 599 | } |
star297 | 3:a4caac512e13 | 600 | |
star297 | 3:a4caac512e13 | 601 | fread(&BMP_Header[0],1,54,Image); // get the BMP Header |
star297 | 3:a4caac512e13 | 602 | |
star297 | 3:a4caac512e13 | 603 | if (BMP_Header[0] != 0x42 || BMP_Header[1] != 0x4D) { // check magic byte |
star297 | 3:a4caac512e13 | 604 | fclose(Image); |
star297 | 3:a4caac512e13 | 605 | return(-1); // error no BMP file |
star297 | 3:a4caac512e13 | 606 | } |
star297 | 3:a4caac512e13 | 607 | BPP_t = BMP_Header[OffsetBPP] + (BMP_Header[OffsetBPP + 1] << 8); |
star297 | 3:a4caac512e13 | 608 | if (BPP_t != 0x0010) { |
star297 | 3:a4caac512e13 | 609 | fclose(Image); |
star297 | 3:a4caac512e13 | 610 | return(-2); // error no 16 bit BMP |
star297 | 3:a4caac512e13 | 611 | } |
star297 | 3:a4caac512e13 | 612 | PixelHeigh = BMP_Header[OffsetPixelHeigh] + (BMP_Header[OffsetPixelHeigh + 1] << 8) + (BMP_Header[OffsetPixelHeigh + 2] << 16) + (BMP_Header[OffsetPixelHeigh + 3] << 24); |
star297 | 3:a4caac512e13 | 613 | PixelWidth = BMP_Header[OffsetPixelWidth] + (BMP_Header[OffsetPixelWidth + 1] << 8) + (BMP_Header[OffsetPixelWidth + 2] << 16) + (BMP_Header[OffsetPixelWidth + 3] << 24); |
star297 | 3:a4caac512e13 | 614 | if (PixelHeigh > height+1 + y || PixelWidth > width+1 + x) { |
star297 | 3:a4caac512e13 | 615 | fclose(Image); |
star297 | 3:a4caac512e13 | 616 | return(-3); // to big |
star297 | 3:a4caac512e13 | 617 | } |
star297 | 3:a4caac512e13 | 618 | start_data = BMP_Header[OffsetPixData] + (BMP_Header[OffsetPixData + 1] << 8) + (BMP_Header[OffsetPixData + 2] << 16) + (BMP_Header[OffsetPixData + 3] << 24); |
star297 | 3:a4caac512e13 | 619 | |
star297 | 3:a4caac512e13 | 620 | line = (unsigned short *) malloc (PixelWidth); // we need a buffer for a line |
star297 | 3:a4caac512e13 | 621 | if (line == NULL) { |
star297 | 3:a4caac512e13 | 622 | return(-4); // error no memory |
star297 | 3:a4caac512e13 | 623 | } |
star297 | 3:a4caac512e13 | 624 | // the lines are padded to multiple of 4 bytes |
star297 | 3:a4caac512e13 | 625 | padd = -1; |
star297 | 3:a4caac512e13 | 626 | do { |
star297 | 3:a4caac512e13 | 627 | padd ++; |
star297 | 3:a4caac512e13 | 628 | } while ((PixelWidth * 2 + padd)%4 != 0); |
star297 | 3:a4caac512e13 | 629 | |
star297 | 3:a4caac512e13 | 630 | window(x, y,PixelWidth,PixelHeigh); |
star297 | 3:a4caac512e13 | 631 | |
star297 | 3:a4caac512e13 | 632 | for (j = PixelHeigh - 1; j >= 0; j--) { //Lines bottom up |
star297 | 3:a4caac512e13 | 633 | off = j * (PixelWidth * 2 + padd) + start_data; // start of line |
star297 | 3:a4caac512e13 | 634 | fseek(Image, off ,SEEK_SET); |
star297 | 3:a4caac512e13 | 635 | fread(line,1,PixelWidth * 2,Image); // read a line - slow ! |
star297 | 3:a4caac512e13 | 636 | for (i = 0; i < PixelWidth; i++) { // copy pixel data to TFT |
star297 | 3:a4caac512e13 | 637 | DataWrite_to(line[i]); |
star297 | 3:a4caac512e13 | 638 | } |
star297 | 3:a4caac512e13 | 639 | } |
star297 | 3:a4caac512e13 | 640 | free (line); |
star297 | 3:a4caac512e13 | 641 | fclose(Image); |
star297 | 3:a4caac512e13 | 642 | Maxwindow(); |
star297 | 3:a4caac512e13 | 643 | return(PixelWidth); |
star297 | 3:a4caac512e13 | 644 | } |
star297 | 3:a4caac512e13 | 645 | |
star297 | 4:062b4708eb35 | 646 | void ssd1331::Copy(uint8_t src_x1,uint8_t src_y1,uint8_t src_x2,uint8_t src_y2,uint8_t dst_x,uint8_t dst_y) |
star297 | 1:f3f6624f45d4 | 647 | { |
star297 | 1:f3f6624f45d4 | 648 | unsigned char cmd[8]= { 0 }; |
star297 | 1:f3f6624f45d4 | 649 | if ((src_x1>width)||(src_y1>height)||(src_x2>width)||(src_y2>height)) return; |
star297 | 1:f3f6624f45d4 | 650 | if ((dst_x>width)||(dst_y>height))return; |
star297 | 1:f3f6624f45d4 | 651 | cmd[0] = GAC_COPY_AREA; // |
star297 | 1:f3f6624f45d4 | 652 | cmd[1] = (unsigned char)src_x1; |
star297 | 1:f3f6624f45d4 | 653 | cmd[2] = (unsigned char)src_y1; |
star297 | 1:f3f6624f45d4 | 654 | cmd[3] = (unsigned char)src_x2; |
star297 | 1:f3f6624f45d4 | 655 | cmd[4] = (unsigned char)src_y2; |
star297 | 1:f3f6624f45d4 | 656 | cmd[5] = (unsigned char)dst_x; |
star297 | 1:f3f6624f45d4 | 657 | cmd[6] = (unsigned char)dst_y; |
star297 | 1:f3f6624f45d4 | 658 | RegWriteM(cmd,7); |
star297 | 1:f3f6624f45d4 | 659 | } |
star297 | 1:f3f6624f45d4 | 660 | |
star297 | 4:062b4708eb35 | 661 | void ssd1331::Fill_Screen(uint16_t color) |
star297 | 1:f3f6624f45d4 | 662 | { |
star297 | 1:f3f6624f45d4 | 663 | BGround_Color = color; |
star297 | 2:1204274fad8f | 664 | fillrect(0,0,width,height,color,color); |
star297 | 1:f3f6624f45d4 | 665 | } |
star297 | 0:3d7d1aec706b | 666 | |
star297 | 4:062b4708eb35 | 667 | void ssd1331::locate(uint8_t column, uint8_t row) |
star297 | 0:3d7d1aec706b | 668 | { |
star297 | 1:f3f6624f45d4 | 669 | char_x = column; |
star297 | 1:f3f6624f45d4 | 670 | char_y = row; |
star297 | 0:3d7d1aec706b | 671 | } |
star297 | 0:3d7d1aec706b | 672 | |
star297 | 4:062b4708eb35 | 673 | void ssd1331::foreground(uint16_t color) |
star297 | 0:3d7d1aec706b | 674 | { |
star297 | 0:3d7d1aec706b | 675 | Char_Color = color; |
star297 | 0:3d7d1aec706b | 676 | } |
star297 | 4:062b4708eb35 | 677 | void ssd1331::background(uint16_t color) |
star297 | 0:3d7d1aec706b | 678 | { |
star297 | 0:3d7d1aec706b | 679 | BGround_Color = color; |
star297 | 0:3d7d1aec706b | 680 | } |
star297 | 0:3d7d1aec706b | 681 | |
star297 | 4:062b4708eb35 | 682 | void ssd1331::SetFontSize(uint8_t Csize) |
star297 | 0:3d7d1aec706b | 683 | { |
star297 | 0:3d7d1aec706b | 684 | chr_size = Csize; |
star297 | 0:3d7d1aec706b | 685 | } |
star297 | 0:3d7d1aec706b | 686 | |
star297 | 1:f3f6624f45d4 | 687 | void ssd1331::putp(int colour) |
star297 | 0:3d7d1aec706b | 688 | { |
star297 | 1:f3f6624f45d4 | 689 | pixel(_x, _y, colour); |
star297 | 1:f3f6624f45d4 | 690 | _x++; |
star297 | 1:f3f6624f45d4 | 691 | if(_x > _x2) { |
star297 | 1:f3f6624f45d4 | 692 | _x = _x1; |
star297 | 1:f3f6624f45d4 | 693 | _y++; |
star297 | 1:f3f6624f45d4 | 694 | if(_y > _y2) { |
star297 | 1:f3f6624f45d4 | 695 | _y = _y1; |
star297 | 0:3d7d1aec706b | 696 | } |
star297 | 0:3d7d1aec706b | 697 | } |
star297 | 0:3d7d1aec706b | 698 | } |
star297 | 0:3d7d1aec706b | 699 | |
star297 | 0:3d7d1aec706b | 700 | int ssd1331::_putc( int c ) |
star297 | 1:f3f6624f45d4 | 701 | { |
star297 | 1:f3f6624f45d4 | 702 | PutChar( char_x , char_y ,c); |
star297 | 0:3d7d1aec706b | 703 | return c; |
star297 | 0:3d7d1aec706b | 704 | } |
star297 | 0:3d7d1aec706b | 705 | |
star297 | 4:062b4708eb35 | 706 | void ssd1331::pixel(uint8_t x,uint8_t y,uint16_t Color) |
star297 | 1:f3f6624f45d4 | 707 | { |
star297 | 1:f3f6624f45d4 | 708 | unsigned char cmd[7]= {Set_Column_Address,0x00,0x00,Set_Row_Address,0x00,0x00}; |
star297 | 4:062b4708eb35 | 709 | if ((x>width)||(y>height)) return ; |
star297 | 1:f3f6624f45d4 | 710 | cmd[1] = (unsigned char)x; |
star297 | 1:f3f6624f45d4 | 711 | cmd[2] = (unsigned char)x; |
star297 | 1:f3f6624f45d4 | 712 | cmd[4] = (unsigned char)y; |
star297 | 1:f3f6624f45d4 | 713 | cmd[5] = (unsigned char)y; |
star297 | 1:f3f6624f45d4 | 714 | RegWriteM(cmd, 6); |
star297 | 1:f3f6624f45d4 | 715 | DataWrite_to(Color); |
star297 | 1:f3f6624f45d4 | 716 | } |
star297 | 1:f3f6624f45d4 | 717 | |
star297 | 2:1204274fad8f | 718 | void ssd1331::Maxwindow() |
star297 | 4:062b4708eb35 | 719 | { |
star297 | 3:a4caac512e13 | 720 | unsigned char cmd[7]= {Set_Column_Address,0x00,0x5F,Set_Row_Address,0x00,0x3F}; |
star297 | 3:a4caac512e13 | 721 | RegWriteM(cmd, 6); |
star297 | 2:1204274fad8f | 722 | } |
star297 | 2:1204274fad8f | 723 | |
star297 | 4:062b4708eb35 | 724 | void ssd1331::window(uint8_t x, uint8_t y, uint8_t w, uint8_t h) |
star297 | 1:f3f6624f45d4 | 725 | { |
star297 | 1:f3f6624f45d4 | 726 | _x = x; |
star297 | 1:f3f6624f45d4 | 727 | _y = y; |
star297 | 1:f3f6624f45d4 | 728 | // window settings |
star297 | 3:a4caac512e13 | 729 | _x1 = x; // start y |
star297 | 3:a4caac512e13 | 730 | _x2 = x + w - 1; // end x |
star297 | 3:a4caac512e13 | 731 | _y1 = y; // start y |
star297 | 3:a4caac512e13 | 732 | _y2 = y + h - 1; // end y |
star297 | 3:a4caac512e13 | 733 | unsigned char cmd[7]= {Set_Column_Address,0x00,0x00,Set_Row_Address,0x00,0x00}; |
star297 | 3:a4caac512e13 | 734 | RegWriteM(cmd, 6); |
star297 | 3:a4caac512e13 | 735 | unsigned char cmd2[7]= {Set_Column_Address,_x1,_x2,Set_Row_Address,_y1,_y2}; |
star297 | 3:a4caac512e13 | 736 | RegWriteM(cmd2, 6); |
star297 | 1:f3f6624f45d4 | 737 | } |
star297 | 1:f3f6624f45d4 | 738 | |
star297 | 1:f3f6624f45d4 | 739 | void ssd1331::Scrollstart() |
star297 | 1:f3f6624f45d4 | 740 | { |
star297 | 1:f3f6624f45d4 | 741 | RegWrite(SCROLL_START); |
star297 | 1:f3f6624f45d4 | 742 | } |
star297 | 1:f3f6624f45d4 | 743 | |
star297 | 1:f3f6624f45d4 | 744 | void ssd1331::Scrollstop() |
star297 | 1:f3f6624f45d4 | 745 | { |
star297 | 1:f3f6624f45d4 | 746 | RegWrite(SCROLL_STOP); |
star297 | 1:f3f6624f45d4 | 747 | } |
star297 | 1:f3f6624f45d4 | 748 | |
star297 | 1:f3f6624f45d4 | 749 | int ssd1331::_getc() |
star297 | 0:3d7d1aec706b | 750 | { |
star297 | 0:3d7d1aec706b | 751 | return -1; |
star297 | 0:3d7d1aec706b | 752 | } |
star297 | 0:3d7d1aec706b | 753 | |
star297 | 4:062b4708eb35 | 754 | uint8_t ssd1331::row() |
star297 | 0:3d7d1aec706b | 755 | { |
star297 | 1:f3f6624f45d4 | 756 | return char_y; |
star297 | 0:3d7d1aec706b | 757 | } |
star297 | 4:062b4708eb35 | 758 | uint8_t ssd1331::column() |
star297 | 0:3d7d1aec706b | 759 | { |
star297 | 1:f3f6624f45d4 | 760 | return char_x; |
star297 | 0:3d7d1aec706b | 761 | } |
star297 | 0:3d7d1aec706b | 762 | |
star297 | 0:3d7d1aec706b | 763 | void ssd1331::FontSizeConvert(int *lpx,int *lpy) |
star297 | 0:3d7d1aec706b | 764 | { |
star297 | 1:f3f6624f45d4 | 765 | switch( chr_size ) { |
star297 | 1:f3f6624f45d4 | 766 | case WIDE: |
star297 | 1:f3f6624f45d4 | 767 | *lpx=2; |
star297 | 1:f3f6624f45d4 | 768 | *lpy=1; |
star297 | 1:f3f6624f45d4 | 769 | break; |
star297 | 1:f3f6624f45d4 | 770 | case HIGH: |
star297 | 1:f3f6624f45d4 | 771 | *lpx=1; |
star297 | 1:f3f6624f45d4 | 772 | *lpy=2; |
star297 | 1:f3f6624f45d4 | 773 | break; |
star297 | 1:f3f6624f45d4 | 774 | case WH : |
star297 | 1:f3f6624f45d4 | 775 | *lpx=2; |
star297 | 1:f3f6624f45d4 | 776 | *lpy=2; |
star297 | 1:f3f6624f45d4 | 777 | break; |
star297 | 1:f3f6624f45d4 | 778 | case WHx36 : |
star297 | 1:f3f6624f45d4 | 779 | *lpx=6; |
star297 | 1:f3f6624f45d4 | 780 | *lpy=6; |
star297 | 1:f3f6624f45d4 | 781 | break; |
star297 | 1:f3f6624f45d4 | 782 | case NORMAL: |
star297 | 1:f3f6624f45d4 | 783 | default: |
star297 | 1:f3f6624f45d4 | 784 | *lpx=1; |
star297 | 1:f3f6624f45d4 | 785 | *lpy=1; |
star297 | 1:f3f6624f45d4 | 786 | break; |
star297 | 1:f3f6624f45d4 | 787 | } |
star297 | 0:3d7d1aec706b | 788 | } |
star297 | 0:3d7d1aec706b | 789 | |
star297 | 0:3d7d1aec706b | 790 | void ssd1331::RegWrite(unsigned char Command) |
star297 | 0:3d7d1aec706b | 791 | { |
star297 | 0:3d7d1aec706b | 792 | DC = 0; // Command |
star297 | 0:3d7d1aec706b | 793 | CS = 0; // CS enable |
star297 | 0:3d7d1aec706b | 794 | spi.write(Command); |
star297 | 0:3d7d1aec706b | 795 | CS = 1; // CS dissable |
star297 | 0:3d7d1aec706b | 796 | } |
star297 | 0:3d7d1aec706b | 797 | |
star297 | 4:062b4708eb35 | 798 | void ssd1331::RegWriteM(unsigned char *Command, uint8_t count) |
star297 | 0:3d7d1aec706b | 799 | { |
star297 | 0:3d7d1aec706b | 800 | int i; |
star297 | 0:3d7d1aec706b | 801 | DC = 0; // Command |
star297 | 0:3d7d1aec706b | 802 | CS = 0; // CS enable |
star297 | 1:f3f6624f45d4 | 803 | for( i=0; i<count; i++) { |
star297 | 1:f3f6624f45d4 | 804 | spi.write(*Command++); |
star297 | 0:3d7d1aec706b | 805 | } |
star297 | 0:3d7d1aec706b | 806 | CS = 1; // CS dissable |
star297 | 0:3d7d1aec706b | 807 | } |
star297 | 0:3d7d1aec706b | 808 | |
star297 | 0:3d7d1aec706b | 809 | void ssd1331::DataWrite(unsigned char c) |
star297 | 0:3d7d1aec706b | 810 | { |
star297 | 1:f3f6624f45d4 | 811 | DC = 1; // DATA |
star297 | 1:f3f6624f45d4 | 812 | CS = 0; // CS enable |
star297 | 1:f3f6624f45d4 | 813 | spi.write(c); |
star297 | 1:f3f6624f45d4 | 814 | CS = 1; // CS dissable |
star297 | 0:3d7d1aec706b | 815 | } |
star297 | 0:3d7d1aec706b | 816 | |
star297 | 4:062b4708eb35 | 817 | void ssd1331::DataWrite_to(uint16_t Dat) |
star297 | 0:3d7d1aec706b | 818 | { |
star297 | 1:f3f6624f45d4 | 819 | DC = 1; // DATA |
star297 | 2:1204274fad8f | 820 | CS = 0; // CS enable |
star297 | 1:f3f6624f45d4 | 821 | spi.write((unsigned char)((Dat >> 8))); |
star297 | 1:f3f6624f45d4 | 822 | spi.write((unsigned char)(Dat)); |
star297 | 1:f3f6624f45d4 | 823 | CS = 1; // CS dissable |
star297 | 0:3d7d1aec706b | 824 | } |
star297 | 3:a4caac512e13 | 825 | |
star297 | 4:062b4708eb35 | 826 | |
star297 | 4:062b4708eb35 | 827 | |
star297 | 4:062b4708eb35 | 828 | |
star297 | 4:062b4708eb35 | 829 |