Adafruit ssd1331 OLED 96x64 SPI model
Fork of OledLib by
spioled96x64.cpp@8:a6060524095f, 2016-02-02 (annotated)
- Committer:
- AhJie
- Date:
- Tue Feb 02 15:11:54 2016 +0000
- Revision:
- 8:a6060524095f
- Parent:
- 7:60b2f555f3b7
Adafruit ssd1331
; 96x64 OLED
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TETSUYA | 4:b68843c0269c | 1 | |
TETSUYA | 2:e331851128c1 | 2 | // ALO-095BWNN-J9 test program |
TETSUYA | 2:e331851128c1 | 3 | // See also "http://www.aitendo.co.jp/product/2099" |
TETSUYA | 3:eab8d193745a | 4 | // Ver1.00 初版完成 |
TETSUYA | 3:eab8d193745a | 5 | // Ver1.01 フォントをk6x8フォントに変更。定義Hファイルも全角とは分離 |
TETSUYA | 3:eab8d193745a | 6 | // フォント描画ルーチンが1ドットすくなく動くのを修正 |
TETSUYA | 3:eab8d193745a | 7 | // 任意カラーパターンを描画できるように修正 |
TETSUYA | 4:b68843c0269c | 8 | // Ver1.02 SD1331/1332用 GACcommand対応 |
TETSUYA | 4:b68843c0269c | 9 | // ただし現状ではRectangeしか機能しない模様 |
TETSUYA | 5:730724f253a4 | 10 | // Ver1.03 Box (GAC) Color Bug fix |
TETSUYA | 6:7c25a9403243 | 11 | // Ver.104 Font Position Convert Bug fix |
TETSUYA | 6:7c25a9403243 | 12 | // Position Clip is refine. |
TETSUYA | 2:e331851128c1 | 13 | |
TETSUYA | 2:e331851128c1 | 14 | #include "mbed.h" |
TETSUYA | 2:e331851128c1 | 15 | #include "spioled96x64.h" |
TETSUYA | 2:e331851128c1 | 16 | |
TETSUYA | 2:e331851128c1 | 17 | //Serial pc(USBTX, USBRX); |
TETSUYA | 2:e331851128c1 | 18 | #define countof(x) ( sizeof(x) / sizeof(x[0]) ) |
TETSUYA | 2:e331851128c1 | 19 | |
TETSUYA | 2:e331851128c1 | 20 | |
TETSUYA | 3:eab8d193745a | 21 | // コンストラクタ |
TETSUYA | 2:e331851128c1 | 22 | SPIOLED96x64::SPIOLED96x64(PinName cs_pin, PinName rst_pin, PinName a0_pin, PinName mosi_pin, PinName miso_pin, PinName sclk_pin) |
TETSUYA | 2:e331851128c1 | 23 | : CS(cs_pin), RES(rst_pin), DC(a0_pin), spi(mosi_pin, miso_pin, sclk_pin) |
TETSUYA | 2:e331851128c1 | 24 | { |
TETSUYA | 2:e331851128c1 | 25 | Init(); |
TETSUYA | 2:e331851128c1 | 26 | } |
TETSUYA | 2:e331851128c1 | 27 | |
TETSUYA | 3:eab8d193745a | 28 | // イニシャライザ |
TETSUYA | 2:e331851128c1 | 29 | void SPIOLED96x64::Init(void) |
TETSUYA | 2:e331851128c1 | 30 | { |
TETSUYA | 2:e331851128c1 | 31 | |
TETSUYA | 2:e331851128c1 | 32 | spi.format(8,3); //8bit frame and POL=1 /PHA=1(UpEdge Sampled) |
TETSUYA | 2:e331851128c1 | 33 | spi.frequency(25000000); // modify later |
TETSUYA | 2:e331851128c1 | 34 | //spi.frequency(42000000); // modify later |
TETSUYA | 2:e331851128c1 | 35 | |
TETSUYA | 2:e331851128c1 | 36 | // reset |
TETSUYA | 2:e331851128c1 | 37 | wait_ms(200); |
TETSUYA | 2:e331851128c1 | 38 | RES = 0; //Reset active |
TETSUYA | 2:e331851128c1 | 39 | wait_ms(200); |
TETSUYA | 2:e331851128c1 | 40 | RES = 1; |
TETSUYA | 2:e331851128c1 | 41 | |
TETSUYA | 2:e331851128c1 | 42 | |
TETSUYA | 2:e331851128c1 | 43 | // initialize sequence |
TETSUYA | 2:e331851128c1 | 44 | RegWrite(0xae); //OLED display OFF |
TETSUYA | 2:e331851128c1 | 45 | |
TETSUYA | 2:e331851128c1 | 46 | //Row Address |
TETSUYA | 2:e331851128c1 | 47 | RegWrite(0x75); /* Set Row Address */ |
TETSUYA | 2:e331851128c1 | 48 | RegWrite(0x00); /* Start = 0 */ |
TETSUYA | 2:e331851128c1 | 49 | RegWrite(0x3f); /* End = 63 */ |
TETSUYA | 2:e331851128c1 | 50 | RegWrite(0x15); /* Set Column Address */ |
TETSUYA | 2:e331851128c1 | 51 | RegWrite(0x00); /* Start = 0 */ |
TETSUYA | 2:e331851128c1 | 52 | RegWrite(0x5F); /* End = 95 */ |
TETSUYA | 2:e331851128c1 | 53 | |
TETSUYA | 2:e331851128c1 | 54 | //Contrast |
TETSUYA | 2:e331851128c1 | 55 | RegWrite(0xa0); //Set remap & data format 0111 0000 |
TETSUYA | 2:e331851128c1 | 56 | RegWrite(0x74); // 65k Color/8bit buswidth/format1 |
TETSUYA | 2:e331851128c1 | 57 | RegWrite(0xa1); //set display start row RAM |
TETSUYA | 2:e331851128c1 | 58 | RegWrite(0x00); |
TETSUYA | 2:e331851128c1 | 59 | RegWrite(0xa2); //set dispaly offset |
TETSUYA | 2:e331851128c1 | 60 | RegWrite(0x00); |
TETSUYA | 2:e331851128c1 | 61 | RegWrite(0xa4); //Set Display Mode |
TETSUYA | 2:e331851128c1 | 62 | RegWrite(0xa8); //Set Multiplex Ratio |
TETSUYA | 2:e331851128c1 | 63 | RegWrite(0x3f); |
TETSUYA | 2:e331851128c1 | 64 | RegWrite(0xad); //Set Master Configuration |
TETSUYA | 2:e331851128c1 | 65 | RegWrite(0x8f); //(External VCC Supply Selected) |
TETSUYA | 2:e331851128c1 | 66 | RegWrite(0xB0); //Set Power Saving Mode |
TETSUYA | 2:e331851128c1 | 67 | RegWrite(0x1a); |
TETSUYA | 2:e331851128c1 | 68 | RegWrite(0xB1); //Set Phase 1 & 2 Period Adjustment |
TETSUYA | 2:e331851128c1 | 69 | RegWrite(0x74); |
TETSUYA | 2:e331851128c1 | 70 | RegWrite(0xb3); //Set Display Clock Divide Ratio / Oscillator Frequency |
TETSUYA | 2:e331851128c1 | 71 | RegWrite(0xd0); |
TETSUYA | 2:e331851128c1 | 72 | RegWrite(0x8A); //Set Second Pre-charge Speed of Color A |
TETSUYA | 2:e331851128c1 | 73 | RegWrite(0x81); |
TETSUYA | 2:e331851128c1 | 74 | RegWrite(0x8B); //Set Second Pre-charge Speed of Color B |
TETSUYA | 2:e331851128c1 | 75 | RegWrite(0x82); |
TETSUYA | 2:e331851128c1 | 76 | RegWrite(0x8C); //Set Second Pre-charge Speed of Color C |
TETSUYA | 2:e331851128c1 | 77 | RegWrite(0x83); |
TETSUYA | 2:e331851128c1 | 78 | RegWrite(0xBB); //Set Pre-charge Level |
TETSUYA | 2:e331851128c1 | 79 | RegWrite(0x3e); |
TETSUYA | 2:e331851128c1 | 80 | RegWrite(0xBE); //Set VCOMH |
TETSUYA | 2:e331851128c1 | 81 | RegWrite(0x3e); |
TETSUYA | 2:e331851128c1 | 82 | RegWrite(0x87); //Set Master Current Control |
TETSUYA | 2:e331851128c1 | 83 | RegWrite(0x0f); |
TETSUYA | 2:e331851128c1 | 84 | RegWrite(0x81); //Set Contrast Control for Color gAh |
TETSUYA | 2:e331851128c1 | 85 | RegWrite(0x80); |
TETSUYA | 2:e331851128c1 | 86 | RegWrite(0x82); //Set Contrast Control for Color gBh |
TETSUYA | 2:e331851128c1 | 87 | RegWrite(0x80); |
TETSUYA | 2:e331851128c1 | 88 | RegWrite(0x83); //Set Contrast Control for Color gCh |
TETSUYA | 2:e331851128c1 | 89 | RegWrite(0x80); |
TETSUYA | 2:e331851128c1 | 90 | RegWrite(0xaf); //display ON |
TETSUYA | 2:e331851128c1 | 91 | |
TETSUYA | 2:e331851128c1 | 92 | x_locate = 0; |
TETSUYA | 2:e331851128c1 | 93 | y_locate = 0; |
TETSUYA | 2:e331851128c1 | 94 | chr_size = CS_NORMAL; |
TETSUYA | 2:e331851128c1 | 95 | Fill_Screen(0); |
TETSUYA | 4:b68843c0269c | 96 | GAC_Useflag = 0; |
TETSUYA | 2:e331851128c1 | 97 | } |
TETSUYA | 2:e331851128c1 | 98 | |
TETSUYA | 3:eab8d193745a | 99 | // レジスタライト |
TETSUYA | 2:e331851128c1 | 100 | void SPIOLED96x64::RegWrite(unsigned char Command) |
TETSUYA | 2:e331851128c1 | 101 | { |
TETSUYA | 2:e331851128c1 | 102 | DC = 0; // Command |
TETSUYA | 2:e331851128c1 | 103 | CS = 0; // CS active(toggle OLED) |
TETSUYA | 2:e331851128c1 | 104 | spi.write(Command); |
TETSUYA | 2:e331851128c1 | 105 | CS = 1; |
TETSUYA | 2:e331851128c1 | 106 | } |
TETSUYA | 3:eab8d193745a | 107 | // マルチバイト レジスタ設定 |
TETSUYA | 2:e331851128c1 | 108 | void SPIOLED96x64::RegWriteM(unsigned char *Command, int count) |
TETSUYA | 2:e331851128c1 | 109 | { |
TETSUYA | 2:e331851128c1 | 110 | int i; |
TETSUYA | 2:e331851128c1 | 111 | DC = 0; // Command |
TETSUYA | 2:e331851128c1 | 112 | CS = 0; // CS active(toggle OLED) |
TETSUYA | 2:e331851128c1 | 113 | for( i=0;i<count;i++){ |
TETSUYA | 2:e331851128c1 | 114 | spi.write(*Command++); |
TETSUYA | 2:e331851128c1 | 115 | } |
TETSUYA | 2:e331851128c1 | 116 | CS = 1; |
TETSUYA | 2:e331851128c1 | 117 | } |
TETSUYA | 2:e331851128c1 | 118 | |
TETSUYA | 2:e331851128c1 | 119 | |
TETSUYA | 3:eab8d193745a | 120 | // データライト |
TETSUYA | 2:e331851128c1 | 121 | void SPIOLED96x64::DataWrite(unsigned char c) |
TETSUYA | 2:e331851128c1 | 122 | { |
TETSUYA | 2:e331851128c1 | 123 | DC = 1; // DATA |
TETSUYA | 2:e331851128c1 | 124 | CS = 0; // CS active(toggle OLED) |
TETSUYA | 2:e331851128c1 | 125 | spi.write(c); |
TETSUYA | 2:e331851128c1 | 126 | CS = 1; |
TETSUYA | 2:e331851128c1 | 127 | } |
TETSUYA | 2:e331851128c1 | 128 | |
TETSUYA | 3:eab8d193745a | 129 | // 16ビット書き込み |
TETSUYA | 2:e331851128c1 | 130 | void SPIOLED96x64::DataWrite_to(unsigned int Dat) |
TETSUYA | 2:e331851128c1 | 131 | { |
TETSUYA | 2:e331851128c1 | 132 | DC = 1; // DATA |
TETSUYA | 2:e331851128c1 | 133 | CS = 0; // CS active(toggle OLED) |
TETSUYA | 2:e331851128c1 | 134 | spi.write((unsigned char)((Dat >> 8)& 0x00ff)); |
TETSUYA | 2:e331851128c1 | 135 | spi.write((unsigned char)(Dat & 0x00ff)); |
TETSUYA | 2:e331851128c1 | 136 | CS = 1; |
TETSUYA | 2:e331851128c1 | 137 | /* |
TETSUYA | 2:e331851128c1 | 138 | DataWrite((unsigned char)((Dat >> 8)& 0x00ff)); |
TETSUYA | 2:e331851128c1 | 139 | DataWrite((unsigned char)(Dat & 0x00ff)); |
TETSUYA | 2:e331851128c1 | 140 | */ |
TETSUYA | 2:e331851128c1 | 141 | } |
TETSUYA | 2:e331851128c1 | 142 | |
TETSUYA | 2:e331851128c1 | 143 | |
TETSUYA | 2:e331851128c1 | 144 | |
TETSUYA | 3:eab8d193745a | 145 | // 指定座標に指定色でドット描画 |
TETSUYA | 2:e331851128c1 | 146 | void SPIOLED96x64::Draw_Dot(int x,int y,unsigned int Color) |
TETSUYA | 2:e331851128c1 | 147 | { |
TETSUYA | 2:e331851128c1 | 148 | unsigned char cmd[7]={0x15,0x00,0x00,0x75,0x00,0x00,0x00}; |
TETSUYA | 6:7c25a9403243 | 149 | if ( ( x < 0 )||( y < 0 ) |
TETSUYA | 6:7c25a9403243 | 150 | ||( x > Dis_X_MAX )||( y > Dis_Y_MAX ) ) return ; |
TETSUYA | 2:e331851128c1 | 151 | cmd[1] = (unsigned char)x; |
TETSUYA | 2:e331851128c1 | 152 | cmd[2] = (unsigned char)x; |
TETSUYA | 2:e331851128c1 | 153 | cmd[4] = (unsigned char)y; |
TETSUYA | 2:e331851128c1 | 154 | cmd[5] = (unsigned char)y; |
TETSUYA | 2:e331851128c1 | 155 | RegWriteM(cmd, 6); |
TETSUYA | 2:e331851128c1 | 156 | DataWrite_to(Color); |
TETSUYA | 2:e331851128c1 | 157 | //DataWrite_to(Color); |
TETSUYA | 2:e331851128c1 | 158 | } |
TETSUYA | 2:e331851128c1 | 159 | |
TETSUYA | 2:e331851128c1 | 160 | |
TETSUYA | 2:e331851128c1 | 161 | |
TETSUYA | 2:e331851128c1 | 162 | void SPIOLED96x64::ChangeFontColor(unsigned int color) |
TETSUYA | 2:e331851128c1 | 163 | { |
TETSUYA | 2:e331851128c1 | 164 | Char_Color = color; |
TETSUYA | 2:e331851128c1 | 165 | } |
TETSUYA | 2:e331851128c1 | 166 | void SPIOLED96x64::ChangeBGColor(unsigned int color) |
TETSUYA | 2:e331851128c1 | 167 | { |
TETSUYA | 2:e331851128c1 | 168 | BGround_Color = color; |
TETSUYA | 2:e331851128c1 | 169 | } |
TETSUYA | 2:e331851128c1 | 170 | |
TETSUYA | 2:e331851128c1 | 171 | |
TETSUYA | 2:e331851128c1 | 172 | // CS_NORMAL/CS_WIDE/CS_HIGH/CS_WH |
TETSUYA | 2:e331851128c1 | 173 | void SPIOLED96x64::SetFontSize(int Csize) |
TETSUYA | 2:e331851128c1 | 174 | { |
TETSUYA | 2:e331851128c1 | 175 | chr_size = Csize; |
TETSUYA | 2:e331851128c1 | 176 | } |
TETSUYA | 3:eab8d193745a | 177 | // 縦横の倍率変化量を返す |
TETSUYA | 2:e331851128c1 | 178 | void SPIOLED96x64::CS_Conv(int *lpx,int *lpy) |
TETSUYA | 2:e331851128c1 | 179 | { |
TETSUYA | 2:e331851128c1 | 180 | switch( chr_size ){ |
TETSUYA | 2:e331851128c1 | 181 | case CS_WIDE: |
TETSUYA | 2:e331851128c1 | 182 | *lpx=2; |
TETSUYA | 2:e331851128c1 | 183 | *lpy=1; |
TETSUYA | 2:e331851128c1 | 184 | break; |
TETSUYA | 2:e331851128c1 | 185 | case CS_HIGH: |
TETSUYA | 2:e331851128c1 | 186 | *lpx=1; |
TETSUYA | 2:e331851128c1 | 187 | *lpy=2; |
TETSUYA | 2:e331851128c1 | 188 | break; |
AhJie | 7:60b2f555f3b7 | 189 | case CS_WHx4 : |
TETSUYA | 2:e331851128c1 | 190 | *lpx=2; |
TETSUYA | 2:e331851128c1 | 191 | *lpy=2; |
TETSUYA | 2:e331851128c1 | 192 | break; |
AhJie | 7:60b2f555f3b7 | 193 | case CS_WHx9 : |
AhJie | 7:60b2f555f3b7 | 194 | *lpx=3; |
AhJie | 7:60b2f555f3b7 | 195 | *lpy=3; |
AhJie | 7:60b2f555f3b7 | 196 | break; |
AhJie | 7:60b2f555f3b7 | 197 | case CS_WHx16 : |
AhJie | 7:60b2f555f3b7 | 198 | *lpx=4; |
AhJie | 7:60b2f555f3b7 | 199 | *lpy=4; |
AhJie | 7:60b2f555f3b7 | 200 | break; |
AhJie | 7:60b2f555f3b7 | 201 | case CS_WHx25 : |
AhJie | 7:60b2f555f3b7 | 202 | *lpx=5; |
AhJie | 7:60b2f555f3b7 | 203 | *lpy=5; |
AhJie | 7:60b2f555f3b7 | 204 | break; |
TETSUYA | 2:e331851128c1 | 205 | case CS_WHx36 : |
TETSUYA | 2:e331851128c1 | 206 | *lpx=6; |
TETSUYA | 2:e331851128c1 | 207 | *lpy=6; |
TETSUYA | 2:e331851128c1 | 208 | break; |
AhJie | 7:60b2f555f3b7 | 209 | case CS_WHx49 : |
AhJie | 7:60b2f555f3b7 | 210 | *lpx=7; |
AhJie | 7:60b2f555f3b7 | 211 | *lpy=7; |
AhJie | 7:60b2f555f3b7 | 212 | break; |
AhJie | 7:60b2f555f3b7 | 213 | case CS_WHx64 : |
AhJie | 7:60b2f555f3b7 | 214 | *lpx=8; |
AhJie | 7:60b2f555f3b7 | 215 | *lpy=8; |
AhJie | 7:60b2f555f3b7 | 216 | break; |
TETSUYA | 2:e331851128c1 | 217 | case CS_NORMAL: |
TETSUYA | 2:e331851128c1 | 218 | default: |
TETSUYA | 2:e331851128c1 | 219 | *lpx=1; |
TETSUYA | 2:e331851128c1 | 220 | *lpy=1; |
TETSUYA | 2:e331851128c1 | 221 | break; |
TETSUYA | 2:e331851128c1 | 222 | } |
TETSUYA | 2:e331851128c1 | 223 | |
TETSUYA | 2:e331851128c1 | 224 | } |
TETSUYA | 2:e331851128c1 | 225 | |
TETSUYA | 3:eab8d193745a | 226 | // 全角キャラクタの描画処理 |
TETSUYA | 3:eab8d193745a | 227 | // アスキーキャラクタの位置指定表示(5x7dotフォント) |
TETSUYA | 3:eab8d193745a | 228 | // フォントの特性上、最上位ビットから順に↑方向に記述される |
TETSUYA | 2:e331851128c1 | 229 | void SPIOLED96x64::PutChar(int x,int y,unsigned int a) |
TETSUYA | 2:e331851128c1 | 230 | { |
TETSUYA | 2:e331851128c1 | 231 | int i,j; |
TETSUYA | 2:e331851128c1 | 232 | unsigned char Temp=0; |
TETSUYA | 2:e331851128c1 | 233 | int lpx, lpy, k,l; |
TETSUYA | 2:e331851128c1 | 234 | int xw; |
TETSUYA | 2:e331851128c1 | 235 | j = 0; |
TETSUYA | 2:e331851128c1 | 236 | i = 0; |
TETSUYA | 2:e331851128c1 | 237 | |
TETSUYA | 2:e331851128c1 | 238 | CS_Conv(&lpx, &lpy); |
TETSUYA | 2:e331851128c1 | 239 | if ( a < 0x80 ) { xw = X_WitchASC; if(a < 32)a=32; } // ASCII |
TETSUYA | 2:e331851128c1 | 240 | else xw = X_Witch; // Kanji |
TETSUYA | 2:e331851128c1 | 241 | |
TETSUYA | 2:e331851128c1 | 242 | for(i=0; i<xw; i++){ |
TETSUYA | 2:e331851128c1 | 243 | for ( l=0;l<lpx;l++){ |
TETSUYA | 2:e331851128c1 | 244 | if ( a < 0x80 ) Temp = FontLookup_ABC[a-32][i]; // ASCII(0x20~0x7f)==> 0x00~0x5f |
TETSUYA | 2:e331851128c1 | 245 | else Temp = FontLookup[a][i]; // Kanji |
TETSUYA | 2:e331851128c1 | 246 | |
TETSUYA | 2:e331851128c1 | 247 | for(j=Y_Witch-1;j>=0;j--){ |
TETSUYA | 2:e331851128c1 | 248 | for ( k=0;k<lpy;k++){ |
TETSUYA | 6:7c25a9403243 | 249 | Draw_Dot(x+(i*lpx)+l,y+(((j+1)*lpy)-1)-k, ((Temp & 0x80)==0x80) ? Char_Color : BGround_Color); |
TETSUYA | 2:e331851128c1 | 250 | } |
TETSUYA | 2:e331851128c1 | 251 | Temp = Temp << 1; |
TETSUYA | 2:e331851128c1 | 252 | } |
TETSUYA | 2:e331851128c1 | 253 | } |
TETSUYA | 2:e331851128c1 | 254 | } |
TETSUYA | 2:e331851128c1 | 255 | } |
TETSUYA | 2:e331851128c1 | 256 | |
TETSUYA | 2:e331851128c1 | 257 | |
TETSUYA | 3:eab8d193745a | 258 | // 純粋仮想関数でputcを実現 |
TETSUYA | 2:e331851128c1 | 259 | int SPIOLED96x64::_putc( int c ) |
TETSUYA | 2:e331851128c1 | 260 | { |
TETSUYA | 2:e331851128c1 | 261 | static bool kstate = false; |
TETSUYA | 2:e331851128c1 | 262 | static unsigned int kbuf = 0; |
TETSUYA | 2:e331851128c1 | 263 | unsigned int p; |
TETSUYA | 2:e331851128c1 | 264 | int lpx, lpy, w; |
TETSUYA | 2:e331851128c1 | 265 | |
TETSUYA | 2:e331851128c1 | 266 | if(!kstate && ((0x81 <= c && c <= 0x9f) || (0xe0 <= c && c <= 0xfc))){ |
TETSUYA | 2:e331851128c1 | 267 | kstate = true; |
TETSUYA | 2:e331851128c1 | 268 | kbuf = c; |
TETSUYA | 2:e331851128c1 | 269 | return c; |
TETSUYA | 2:e331851128c1 | 270 | } |
TETSUYA | 2:e331851128c1 | 271 | |
TETSUYA | 2:e331851128c1 | 272 | if(kstate){ // 2nd byte of shift-jis |
TETSUYA | 2:e331851128c1 | 273 | kstate = false; |
TETSUYA | 2:e331851128c1 | 274 | p = findface(kbuf << 8 | c); |
TETSUYA | 2:e331851128c1 | 275 | w = X_Witch; |
TETSUYA | 2:e331851128c1 | 276 | } else { |
TETSUYA | 2:e331851128c1 | 277 | p = c; |
TETSUYA | 3:eab8d193745a | 278 | w = X_WitchASC; // 半角は近接するので、1ドットあける |
TETSUYA | 2:e331851128c1 | 279 | } |
TETSUYA | 2:e331851128c1 | 280 | PutChar( x_locate , y_locate ,p); |
TETSUYA | 2:e331851128c1 | 281 | CS_Conv(&lpx, &lpy); |
TETSUYA | 2:e331851128c1 | 282 | x_locate += (w*lpx); |
TETSUYA | 2:e331851128c1 | 283 | |
TETSUYA | 2:e331851128c1 | 284 | |
TETSUYA | 2:e331851128c1 | 285 | /* |
TETSUYA | 2:e331851128c1 | 286 | if(kstate== false){ |
TETSUYA | 3:eab8d193745a | 287 | //画面右端でのクリッピング |
TETSUYA | 2:e331851128c1 | 288 | if(x_locate + (xsize - 1) >= Dis_X_MAX){ |
TETSUYA | 2:e331851128c1 | 289 | x_locate = 0; |
TETSUYA | 2:e331851128c1 | 290 | y_locate += Y_Witch; |
TETSUYA | 2:e331851128c1 | 291 | if(y_locate >= Dis_Y_MAX) y_locate=0; |
TETSUYA | 2:e331851128c1 | 292 | } |
TETSUYA | 2:e331851128c1 | 293 | } |
TETSUYA | 2:e331851128c1 | 294 | */ |
TETSUYA | 2:e331851128c1 | 295 | return c; |
TETSUYA | 2:e331851128c1 | 296 | } |
TETSUYA | 2:e331851128c1 | 297 | |
TETSUYA | 2:e331851128c1 | 298 | int SPIOLED96x64::_getc() |
TETSUYA | 2:e331851128c1 | 299 | { |
TETSUYA | 2:e331851128c1 | 300 | return -1; |
TETSUYA | 2:e331851128c1 | 301 | } |
TETSUYA | 2:e331851128c1 | 302 | |
TETSUYA | 2:e331851128c1 | 303 | /* |
TETSUYA | 2:e331851128c1 | 304 | void SPIOLED96x64::puts( char *s ) |
TETSUYA | 2:e331851128c1 | 305 | { |
TETSUYA | 2:e331851128c1 | 306 | unsigned char c; |
TETSUYA | 2:e331851128c1 | 307 | while((c = *s++) != '\0') putc((int)c & 0xff); |
TETSUYA | 2:e331851128c1 | 308 | } |
TETSUYA | 2:e331851128c1 | 309 | */ |
TETSUYA | 2:e331851128c1 | 310 | |
TETSUYA | 2:e331851128c1 | 311 | |
TETSUYA | 2:e331851128c1 | 312 | void SPIOLED96x64::locate(int column, int row) |
TETSUYA | 2:e331851128c1 | 313 | { |
TETSUYA | 2:e331851128c1 | 314 | x_locate = column; |
TETSUYA | 2:e331851128c1 | 315 | y_locate = row; |
TETSUYA | 2:e331851128c1 | 316 | } |
TETSUYA | 2:e331851128c1 | 317 | |
TETSUYA | 2:e331851128c1 | 318 | int SPIOLED96x64::row() |
TETSUYA | 2:e331851128c1 | 319 | { |
TETSUYA | 2:e331851128c1 | 320 | return y_locate; |
TETSUYA | 2:e331851128c1 | 321 | } |
TETSUYA | 2:e331851128c1 | 322 | int SPIOLED96x64::column() |
TETSUYA | 2:e331851128c1 | 323 | { |
TETSUYA | 2:e331851128c1 | 324 | return x_locate; |
TETSUYA | 2:e331851128c1 | 325 | } |
TETSUYA | 2:e331851128c1 | 326 | |
TETSUYA | 3:eab8d193745a | 327 | // SJIS漢字コードテーブルから指定の配列アドレスを算出する |
TETSUYA | 2:e331851128c1 | 328 | unsigned int SPIOLED96x64::findface(unsigned short c) |
TETSUYA | 2:e331851128c1 | 329 | { |
TETSUYA | 2:e331851128c1 | 330 | unsigned int p = 0; |
TETSUYA | 2:e331851128c1 | 331 | int i, sum; |
TETSUYA | 2:e331851128c1 | 332 | for(sum = i = 0; i < countof(font8table); i++){ |
TETSUYA | 2:e331851128c1 | 333 | if(font8table[i].start <= c && c <= font8table[i].end){ |
TETSUYA | 2:e331851128c1 | 334 | p = (sum + c - font8table[i].start); |
TETSUYA | 2:e331851128c1 | 335 | break; |
TETSUYA | 2:e331851128c1 | 336 | } |
TETSUYA | 2:e331851128c1 | 337 | sum += font8table[i].end - font8table[i].start + 1; |
TETSUYA | 2:e331851128c1 | 338 | } |
TETSUYA | 2:e331851128c1 | 339 | return p; |
TETSUYA | 2:e331851128c1 | 340 | } |
TETSUYA | 2:e331851128c1 | 341 | |
TETSUYA | 3:eab8d193745a | 342 | // RGB(555)をRGB565値に変換 |
TETSUYA | 2:e331851128c1 | 343 | // 00~1F(0~31) |
TETSUYA | 2:e331851128c1 | 344 | unsigned int SPIOLED96x64::ColorConv(unsigned int R,unsigned int G,unsigned int B) |
TETSUYA | 2:e331851128c1 | 345 | { |
TETSUYA | 2:e331851128c1 | 346 | unsigned int ret = 0; |
TETSUYA | 2:e331851128c1 | 347 | unsigned int rv, gv, bv; |
TETSUYA | 2:e331851128c1 | 348 | |
TETSUYA | 2:e331851128c1 | 349 | if ( R > 0x1f ) rv= 0x1f; |
TETSUYA | 2:e331851128c1 | 350 | else rv= (unsigned int)( R & 0x1F ); |
TETSUYA | 2:e331851128c1 | 351 | if ( G > 0x1f ) gv= 0x3f; |
TETSUYA | 2:e331851128c1 | 352 | else gv= (unsigned int)( (G<<1) & 0x3F ); |
TETSUYA | 2:e331851128c1 | 353 | if ( B > 0x1f ) bv= 0x1f; |
TETSUYA | 2:e331851128c1 | 354 | else bv= (unsigned int)( B & 0x1F ); |
TETSUYA | 2:e331851128c1 | 355 | |
TETSUYA | 2:e331851128c1 | 356 | ret = (bv << 11) + (gv << 5) + rv; |
TETSUYA | 2:e331851128c1 | 357 | return ret; |
TETSUYA | 2:e331851128c1 | 358 | } |
TETSUYA | 3:eab8d193745a | 359 | // 画面の指定色塗りつぶし指定領域し |
TETSUYA | 2:e331851128c1 | 360 | void SPIOLED96x64::Box(int x1,int y1, int x2, int y2, unsigned int Color, int fill) |
TETSUYA | 2:e331851128c1 | 361 | { |
TETSUYA | 4:b68843c0269c | 362 | |
TETSUYA | 4:b68843c0269c | 363 | if ( !GAC_Useflag ){ |
TETSUYA | 4:b68843c0269c | 364 | unsigned char i,j; |
TETSUYA | 2:e331851128c1 | 365 | |
TETSUYA | 4:b68843c0269c | 366 | switch( fill ) { |
TETSUYA | 4:b68843c0269c | 367 | case 0: // box |
TETSUYA | 4:b68843c0269c | 368 | line( x1, y1, x2, y1, Color, 0 ); |
TETSUYA | 4:b68843c0269c | 369 | line( x2, y1, x2, y2, Color, 0 ); |
TETSUYA | 4:b68843c0269c | 370 | line( x2, y2, x1, y2, Color, 0 ); |
TETSUYA | 4:b68843c0269c | 371 | line( x1, y2, x1, y1, Color, 0 ); |
TETSUYA | 4:b68843c0269c | 372 | break; |
TETSUYA | 4:b68843c0269c | 373 | default: // fill |
TETSUYA | 4:b68843c0269c | 374 | for(i=y1;i<=y2;i++) |
TETSUYA | 2:e331851128c1 | 375 | { |
TETSUYA | 4:b68843c0269c | 376 | for(j=x1;j<=x2;j++) |
TETSUYA | 4:b68843c0269c | 377 | { |
TETSUYA | 4:b68843c0269c | 378 | Draw_Dot(j,i,Color); |
TETSUYA | 4:b68843c0269c | 379 | // DataWrite_to(Dot); |
TETSUYA | 4:b68843c0269c | 380 | } |
TETSUYA | 2:e331851128c1 | 381 | } |
TETSUYA | 4:b68843c0269c | 382 | break; |
TETSUYA | 2:e331851128c1 | 383 | } |
TETSUYA | 4:b68843c0269c | 384 | }else{ |
TETSUYA | 4:b68843c0269c | 385 | // SSD1331/1332用 GAC(アクセラレートコマンド) |
TETSUYA | 4:b68843c0269c | 386 | unsigned char cmd[11]={ 0 }; |
TETSUYA | 4:b68843c0269c | 387 | |
TETSUYA | 6:7c25a9403243 | 388 | if ( x1 < 0 ) x1 = 0; |
TETSUYA | 6:7c25a9403243 | 389 | else if ( x1 > Dis_X_MAX ) x1 = Dis_X_MAX; |
TETSUYA | 6:7c25a9403243 | 390 | if ( y1 < 0 ) y1 = 0; |
TETSUYA | 6:7c25a9403243 | 391 | else if ( y1 > Dis_Y_MAX ) y1 = Dis_Y_MAX; |
TETSUYA | 6:7c25a9403243 | 392 | if ( x2 < 0 ) x2 = 0; |
TETSUYA | 6:7c25a9403243 | 393 | else if ( x2 > Dis_X_MAX ) x2 = Dis_X_MAX; |
TETSUYA | 6:7c25a9403243 | 394 | if ( y2 < 0 ) y2 = 0; |
TETSUYA | 6:7c25a9403243 | 395 | else if ( y2 > Dis_Y_MAX ) y2 = Dis_Y_MAX; |
TETSUYA | 4:b68843c0269c | 396 | |
TETSUYA | 4:b68843c0269c | 397 | cmd[0] = GAC_FILL_ENABLE_DISABLE; // |
TETSUYA | 4:b68843c0269c | 398 | cmd[1] = (unsigned char)fill; //( fill ) ? 0 : 0; |
TETSUYA | 4:b68843c0269c | 399 | RegWriteM(cmd, 2); |
TETSUYA | 4:b68843c0269c | 400 | |
TETSUYA | 4:b68843c0269c | 401 | cmd[0] = GAC_DRAW_RECTANGLE; // |
TETSUYA | 4:b68843c0269c | 402 | cmd[1] = (unsigned char)x1; |
TETSUYA | 4:b68843c0269c | 403 | cmd[2] = (unsigned char)y1; |
TETSUYA | 4:b68843c0269c | 404 | cmd[3] = (unsigned char)x2; |
TETSUYA | 4:b68843c0269c | 405 | cmd[4] = (unsigned char)y2; |
TETSUYA | 5:730724f253a4 | 406 | cmd[5] = (unsigned char)(((Color>>11)&0x1f)<<1); // Outline Blue |
TETSUYA | 5:730724f253a4 | 407 | cmd[6] = (unsigned char) ((Color>>5 )&0x3f); // Outline Green |
TETSUYA | 5:730724f253a4 | 408 | cmd[7] = (unsigned char)(( Color &0x1f)<<1); // Outline Red |
TETSUYA | 5:730724f253a4 | 409 | cmd[8] = (unsigned char)(((Color>>11)&0x1f)<<1); // Outline Blue |
TETSUYA | 5:730724f253a4 | 410 | cmd[9] = (unsigned char) ((Color>>5 )&0x3f); // Outline Green |
TETSUYA | 5:730724f253a4 | 411 | cmd[10]= (unsigned char)(( Color &0x1f)<<1); // Outline Red |
TETSUYA | 4:b68843c0269c | 412 | |
TETSUYA | 4:b68843c0269c | 413 | RegWriteM(cmd, 11); |
TETSUYA | 4:b68843c0269c | 414 | wait_ms( 1 ); |
TETSUYA | 4:b68843c0269c | 415 | |
TETSUYA | 2:e331851128c1 | 416 | } |
TETSUYA | 2:e331851128c1 | 417 | } |
TETSUYA | 2:e331851128c1 | 418 | |
TETSUYA | 3:eab8d193745a | 419 | // 画面の指定色塗りつぶし |
TETSUYA | 2:e331851128c1 | 420 | void SPIOLED96x64::Fill_Screen(unsigned int Color) |
TETSUYA | 2:e331851128c1 | 421 | { |
TETSUYA | 2:e331851128c1 | 422 | BGround_Color = Color; |
TETSUYA | 2:e331851128c1 | 423 | Box( 0,0, Dis_X_MAX, Dis_Y_MAX , Color , 1); |
TETSUYA | 2:e331851128c1 | 424 | } |
TETSUYA | 2:e331851128c1 | 425 | |
TETSUYA | 3:eab8d193745a | 426 | // Bresenhamの線分発生アルゴリズム |
TETSUYA | 3:eab8d193745a | 427 | // 整数のみによる線分描画 |
TETSUYA | 3:eab8d193745a | 428 | // (x0,y0)-(x1,y1)へのライン描画 参照:http //www2.starcat.ne.jp/~fussy/algo/algo1-1.htm |
TETSUYA | 3:eab8d193745a | 429 | // pat : 0:実線 1:破線 |
TETSUYA | 2:e331851128c1 | 430 | void SPIOLED96x64::line( int x0, int y0, int x1, int y1, unsigned int fore_col ,int pat ) |
TETSUYA | 2:e331851128c1 | 431 | { |
TETSUYA | 2:e331851128c1 | 432 | int E,x,y; |
TETSUYA | 2:e331851128c1 | 433 | int dx,dy,sx,sy,i; |
TETSUYA | 2:e331851128c1 | 434 | int cl=1 ; |
TETSUYA | 3:eab8d193745a | 435 | int clc=0; // 破線用のカウンタ |
TETSUYA | 2:e331851128c1 | 436 | |
TETSUYA | 3:eab8d193745a | 437 | sx = ( x1 > x0 ) ? 1 : -1; // xの移動方向 |
TETSUYA | 3:eab8d193745a | 438 | dx = ( x1 > x0 ) ? x1 - x0 : x0 - x1; // xの移動量 |
TETSUYA | 3:eab8d193745a | 439 | sy = ( y1 > y0 ) ? 1 : -1; // yの移動方向 |
TETSUYA | 3:eab8d193745a | 440 | dy = ( y1 > y0 ) ? y1 - y0 : y0 - y1; // yの移動量 |
TETSUYA | 2:e331851128c1 | 441 | |
TETSUYA | 2:e331851128c1 | 442 | x = x0; |
TETSUYA | 2:e331851128c1 | 443 | y = y0; |
TETSUYA | 2:e331851128c1 | 444 | |
TETSUYA | 2:e331851128c1 | 445 | if( dx >= dy ) { |
TETSUYA | 3:eab8d193745a | 446 | /* 傾きが1以下の場合 */ |
TETSUYA | 2:e331851128c1 | 447 | E = -dx; |
TETSUYA | 2:e331851128c1 | 448 | for( i = 0; i <= dx; i++ ) { |
TETSUYA | 2:e331851128c1 | 449 | switch( pat ) { |
TETSUYA | 3:eab8d193745a | 450 | case 0: // 実線 |
TETSUYA | 2:e331851128c1 | 451 | cl = fore_col; |
TETSUYA | 2:e331851128c1 | 452 | break; |
TETSUYA | 3:eab8d193745a | 453 | default: // 破線 |
TETSUYA | 2:e331851128c1 | 454 | if ( clc>=3 ) { |
TETSUYA | 2:e331851128c1 | 455 | if ( cl==fore_col ) cl=BGround_Color; |
TETSUYA | 2:e331851128c1 | 456 | else cl=fore_col; |
TETSUYA | 2:e331851128c1 | 457 | clc=0; |
TETSUYA | 2:e331851128c1 | 458 | }else{ |
TETSUYA | 2:e331851128c1 | 459 | clc++; |
TETSUYA | 2:e331851128c1 | 460 | } |
TETSUYA | 2:e331851128c1 | 461 | break; |
TETSUYA | 2:e331851128c1 | 462 | } |
TETSUYA | 2:e331851128c1 | 463 | |
TETSUYA | 2:e331851128c1 | 464 | Draw_Dot(x,y,cl); |
TETSUYA | 2:e331851128c1 | 465 | x += sx; |
TETSUYA | 2:e331851128c1 | 466 | E += 2 * dy; |
TETSUYA | 2:e331851128c1 | 467 | if( E >= 0 ) { |
TETSUYA | 2:e331851128c1 | 468 | y += sy; |
TETSUYA | 2:e331851128c1 | 469 | E -= 2 * dx; |
TETSUYA | 2:e331851128c1 | 470 | } |
TETSUYA | 2:e331851128c1 | 471 | } |
TETSUYA | 2:e331851128c1 | 472 | }else{ |
TETSUYA | 3:eab8d193745a | 473 | /* 傾きが1より大きい場合 */ |
TETSUYA | 2:e331851128c1 | 474 | E = -dy; |
TETSUYA | 2:e331851128c1 | 475 | for( i = 0; i <= dy; i++ ) { |
TETSUYA | 2:e331851128c1 | 476 | switch( pat ) { |
TETSUYA | 3:eab8d193745a | 477 | case 0: // 実線 |
TETSUYA | 2:e331851128c1 | 478 | cl = fore_col; |
TETSUYA | 2:e331851128c1 | 479 | break; |
TETSUYA | 3:eab8d193745a | 480 | default: // 破線 |
TETSUYA | 2:e331851128c1 | 481 | if ( clc>=3 ) { |
TETSUYA | 2:e331851128c1 | 482 | if ( cl==fore_col ) cl=BGround_Color; |
TETSUYA | 2:e331851128c1 | 483 | else cl=fore_col; |
TETSUYA | 2:e331851128c1 | 484 | clc=0; |
TETSUYA | 2:e331851128c1 | 485 | }else{ |
TETSUYA | 2:e331851128c1 | 486 | clc++; |
TETSUYA | 2:e331851128c1 | 487 | } |
TETSUYA | 2:e331851128c1 | 488 | break; |
TETSUYA | 2:e331851128c1 | 489 | } |
TETSUYA | 2:e331851128c1 | 490 | |
TETSUYA | 2:e331851128c1 | 491 | Draw_Dot(x,y,cl); |
TETSUYA | 2:e331851128c1 | 492 | y += sy; |
TETSUYA | 2:e331851128c1 | 493 | E += 2 * dx; |
TETSUYA | 2:e331851128c1 | 494 | if( E >= 0 ) { |
TETSUYA | 2:e331851128c1 | 495 | x += sx; |
TETSUYA | 2:e331851128c1 | 496 | E -= 2 * dy; |
TETSUYA | 2:e331851128c1 | 497 | } |
TETSUYA | 2:e331851128c1 | 498 | } |
TETSUYA | 2:e331851128c1 | 499 | } |
TETSUYA | 2:e331851128c1 | 500 | } |
TETSUYA | 2:e331851128c1 | 501 | |
TETSUYA | 3:eab8d193745a | 502 | // ミッチェナー(Miechener) の円描画 参考:http://dencha.ojaru.jp/programs_07/pg_graphic_09a1.html |
TETSUYA | 3:eab8d193745a | 503 | // x,y : 中心点 |
TETSUYA | 3:eab8d193745a | 504 | // radius: 半径 |
TETSUYA | 2:e331851128c1 | 505 | void SPIOLED96x64::circle (int radius, int x, int y , unsigned int col, int fill) |
TETSUYA | 2:e331851128c1 | 506 | { |
TETSUYA | 2:e331851128c1 | 507 | int cx, cy, d; |
TETSUYA | 2:e331851128c1 | 508 | |
TETSUYA | 2:e331851128c1 | 509 | d = 3 - 2 * radius; |
TETSUYA | 2:e331851128c1 | 510 | cy = radius; |
TETSUYA | 2:e331851128c1 | 511 | |
TETSUYA | 3:eab8d193745a | 512 | // 初期座標をあらかじめ描画する |
TETSUYA | 3:eab8d193745a | 513 | Draw_Dot( x, radius+y, col ); // 座標 ( 0, R ); |
TETSUYA | 3:eab8d193745a | 514 | Draw_Dot( x, -radius+y, col ); // 座標 ( 0, -R); |
TETSUYA | 3:eab8d193745a | 515 | Draw_Dot( radius+x, y, col ); // 座標 ( R, 0 ); |
TETSUYA | 3:eab8d193745a | 516 | Draw_Dot( -radius+x, y, col ); // 座標 (-R, 0); |
TETSUYA | 2:e331851128c1 | 517 | if ( fill ) { |
TETSUYA | 2:e331851128c1 | 518 | line( x, radius+y, x, -radius+y, col ,0 ); |
TETSUYA | 2:e331851128c1 | 519 | line( radius+x, y, -radius+x, y, col ,0 ); |
TETSUYA | 2:e331851128c1 | 520 | } |
TETSUYA | 2:e331851128c1 | 521 | |
TETSUYA | 2:e331851128c1 | 522 | for (cx = 0; cx <= cy; cx++){ |
TETSUYA | 2:e331851128c1 | 523 | if (d >= 0) { |
TETSUYA | 2:e331851128c1 | 524 | d += 10 + 4 * cx - 4 * cy; |
TETSUYA | 2:e331851128c1 | 525 | cy--; |
TETSUYA | 2:e331851128c1 | 526 | } else { |
TETSUYA | 2:e331851128c1 | 527 | d += 6 + 4 * cx; |
TETSUYA | 2:e331851128c1 | 528 | } |
TETSUYA | 2:e331851128c1 | 529 | |
TETSUYA | 3:eab8d193745a | 530 | // 描画 |
TETSUYA | 3:eab8d193745a | 531 | Draw_Dot( cy + x, cx + y, col); // 0-45 度の間 |
TETSUYA | 3:eab8d193745a | 532 | Draw_Dot( cx + x, cy + y, col); // 45-90 度の間 |
TETSUYA | 3:eab8d193745a | 533 | Draw_Dot( -cx + x, cy + y, col); // 90-135 度の間 |
TETSUYA | 3:eab8d193745a | 534 | Draw_Dot( -cy + x, cx + y, col); // 135-180 度の間 |
TETSUYA | 2:e331851128c1 | 535 | |
TETSUYA | 3:eab8d193745a | 536 | Draw_Dot( -cy + x, -cx + y, col); // 180-225 度の間 |
TETSUYA | 3:eab8d193745a | 537 | Draw_Dot( -cx + x, -cy + y, col); // 225-270 度の間 |
TETSUYA | 3:eab8d193745a | 538 | Draw_Dot( cx + x, -cy + y, col); // 270-315 度の間 |
TETSUYA | 3:eab8d193745a | 539 | Draw_Dot( cy + x, -cx + y, col); // 315-360 度の間 |
TETSUYA | 2:e331851128c1 | 540 | |
TETSUYA | 2:e331851128c1 | 541 | if ( fill ) { |
TETSUYA | 2:e331851128c1 | 542 | line( cy + x, cx + y, cy + x, -cx + y, col ,0 ); |
TETSUYA | 3:eab8d193745a | 543 | line( cx + x, cy + y, cx + x, -cy + y, col ,0 ); // 45-90 度の間 |
TETSUYA | 3:eab8d193745a | 544 | line( -cx + x, cy + y, -cx + x, cy + y, col ,0 ) ; // 90-135 度の間 |
TETSUYA | 3:eab8d193745a | 545 | line( -cy + x, cx + y, -cy + x, cx + y, col ,0 ); // 135-180 度の間 |
TETSUYA | 2:e331851128c1 | 546 | |
TETSUYA | 3:eab8d193745a | 547 | line( -cy + x, -cx + y, -cy + x, cx + y, col ,0 ); // 180-225 度の間 |
TETSUYA | 3:eab8d193745a | 548 | line( -cx + x, -cy + y, -cx + x, cy + y, col ,0 ); // 225-270 度の間 |
TETSUYA | 3:eab8d193745a | 549 | line( cx + x, -cy + y, cx + x, cy + y, col ,0 ); // 270-315 度の間 |
TETSUYA | 3:eab8d193745a | 550 | line( cy + x, -cx + y, cy + x, cx + y, col ,0 ); // 315-360 度の間 |
TETSUYA | 2:e331851128c1 | 551 | } |
TETSUYA | 2:e331851128c1 | 552 | |
TETSUYA | 2:e331851128c1 | 553 | } |
TETSUYA | 2:e331851128c1 | 554 | } |
TETSUYA | 2:e331851128c1 | 555 | |
TETSUYA | 2:e331851128c1 | 556 | // Color Pattern |
TETSUYA | 3:eab8d193745a | 557 | // pattern *P はRGB565(2バイト型)のデータ配列で渡す |
TETSUYA | 2:e331851128c1 | 558 | void SPIOLED96x64::Pattern(int x,int y,int width, int height, unsigned int *p) |
TETSUYA | 2:e331851128c1 | 559 | { |
TETSUYA | 2:e331851128c1 | 560 | |
TETSUYA | 2:e331851128c1 | 561 | int i,j; |
TETSUYA | 4:b68843c0269c | 562 | |
TETSUYA | 2:e331851128c1 | 563 | for(i=0; i<width; i++){ |
TETSUYA | 2:e331851128c1 | 564 | for(j=height-1;j>=0;j--){ |
TETSUYA | 2:e331851128c1 | 565 | Draw_Dot(x+i,y+j,*p++); |
TETSUYA | 2:e331851128c1 | 566 | } |
TETSUYA | 2:e331851128c1 | 567 | } |
TETSUYA | 2:e331851128c1 | 568 | |
TETSUYA | 2:e331851128c1 | 569 | } |
TETSUYA | 4:b68843c0269c | 570 | void SPIOLED96x64::GACEnable(int enable) |
TETSUYA | 4:b68843c0269c | 571 | { |
TETSUYA | 4:b68843c0269c | 572 | GAC_Useflag = enable; |
TETSUYA | 4:b68843c0269c | 573 | } |
TETSUYA | 6:7c25a9403243 | 574 | |
TETSUYA | 2:e331851128c1 | 575 | |
TETSUYA | 4:b68843c0269c | 576 | // 任意領域のコピー |
TETSUYA | 4:b68843c0269c | 577 | // SSD1332では機能しない模様... |
TETSUYA | 4:b68843c0269c | 578 | void SPIOLED96x64::Copy(int src_x1,int src_y1,int src_x2,int src_y2, int dst_x,int dst_y) |
TETSUYA | 4:b68843c0269c | 579 | { |
TETSUYA | 4:b68843c0269c | 580 | |
TETSUYA | 4:b68843c0269c | 581 | if ( GAC_Useflag ){ |
TETSUYA | 4:b68843c0269c | 582 | // SSD1331/1332用 GAC(アクセラレートコマンド) |
TETSUYA | 4:b68843c0269c | 583 | unsigned char cmd[11]={ 0 }; |
TETSUYA | 4:b68843c0269c | 584 | int p; |
TETSUYA | 4:b68843c0269c | 585 | if ( ( src_x1 > Dis_X_MAX )||( src_y1 > Dis_Y_MAX ) |
TETSUYA | 4:b68843c0269c | 586 | ||( src_x2 > Dis_X_MAX )||( src_y2 > Dis_Y_MAX ) ) return ; |
TETSUYA | 4:b68843c0269c | 587 | //if ( dst_x > Dis_X_MAX )||( dst_y > Dis_Y_MAX ) return; |
TETSUYA | 4:b68843c0269c | 588 | |
TETSUYA | 4:b68843c0269c | 589 | |
TETSUYA | 4:b68843c0269c | 590 | p=0; |
TETSUYA | 4:b68843c0269c | 591 | cmd[p++] = GAC_COPY_AREA; // |
TETSUYA | 4:b68843c0269c | 592 | cmd[p++] = (unsigned char)src_x1; |
TETSUYA | 4:b68843c0269c | 593 | cmd[p++] = (unsigned char)src_y1; |
TETSUYA | 4:b68843c0269c | 594 | cmd[p++] = (unsigned char)src_x2; |
TETSUYA | 4:b68843c0269c | 595 | cmd[p++] = (unsigned char)src_y2; |
TETSUYA | 4:b68843c0269c | 596 | cmd[p++] = (unsigned char)dst_x; |
TETSUYA | 4:b68843c0269c | 597 | cmd[p++] = (unsigned char)dst_y; |
TETSUYA | 4:b68843c0269c | 598 | |
TETSUYA | 4:b68843c0269c | 599 | RegWriteM(cmd, p); |
TETSUYA | 4:b68843c0269c | 600 | |
TETSUYA | 4:b68843c0269c | 601 | } |
TETSUYA | 4:b68843c0269c | 602 | } |
TETSUYA | 2:e331851128c1 | 603 | |
TETSUYA | 4:b68843c0269c | 604 | // スクロール設定 |
TETSUYA | 4:b68843c0269c | 605 | void SPIOLED96x64::ScrollSet(int a, int b, int c, int d , int frame_interval) |
TETSUYA | 4:b68843c0269c | 606 | { |
TETSUYA | 4:b68843c0269c | 607 | if ( GAC_Useflag ){ |
TETSUYA | 4:b68843c0269c | 608 | // SSD1331/1332用 GAC(アクセラレートコマンド) |
TETSUYA | 4:b68843c0269c | 609 | unsigned char cmd[11]={ 0 }; |
TETSUYA | 4:b68843c0269c | 610 | int p; |
TETSUYA | 4:b68843c0269c | 611 | //if ( ( startline > Dis_Y_MAX+1 )||( (startline+lincount) > Dis_Y_MAX+1 ) ) return ; |
TETSUYA | 4:b68843c0269c | 612 | if ( frame_interval > 3 ) frame_interval = 3; |
TETSUYA | 4:b68843c0269c | 613 | |
TETSUYA | 4:b68843c0269c | 614 | p=0; |
TETSUYA | 4:b68843c0269c | 615 | cmd[p++] = GAC_SCROLL_SETUP; // |
TETSUYA | 4:b68843c0269c | 616 | cmd[p++] = (unsigned char)a; |
TETSUYA | 4:b68843c0269c | 617 | cmd[p++] = (unsigned char)b; |
TETSUYA | 4:b68843c0269c | 618 | cmd[p++] = (unsigned char)c; |
TETSUYA | 4:b68843c0269c | 619 | cmd[p++] = (unsigned char)d; |
TETSUYA | 4:b68843c0269c | 620 | cmd[p++] = (unsigned char)frame_interval; |
TETSUYA | 4:b68843c0269c | 621 | |
TETSUYA | 4:b68843c0269c | 622 | RegWriteM(cmd, p); |
TETSUYA | 4:b68843c0269c | 623 | |
TETSUYA | 4:b68843c0269c | 624 | } |
TETSUYA | 4:b68843c0269c | 625 | |
TETSUYA | 4:b68843c0269c | 626 | } |
TETSUYA | 4:b68843c0269c | 627 | void SPIOLED96x64::Scroll(int enable) |
TETSUYA | 4:b68843c0269c | 628 | { |
TETSUYA | 4:b68843c0269c | 629 | if ( GAC_Useflag ){ |
TETSUYA | 4:b68843c0269c | 630 | // SSD1331/1332用 GAC(アクセラレートコマンド) |
TETSUYA | 4:b68843c0269c | 631 | unsigned char cmd = (enable) ? GAC_SCROLL_START : GAC_SCROLL_STOP; // |
TETSUYA | 4:b68843c0269c | 632 | |
TETSUYA | 4:b68843c0269c | 633 | RegWrite(cmd); |
TETSUYA | 4:b68843c0269c | 634 | |
TETSUYA | 4:b68843c0269c | 635 | } |
AhJie | 7:60b2f555f3b7 | 636 | |
TETSUYA | 4:b68843c0269c | 637 | } |
TETSUYA | 2:e331851128c1 | 638 |