ButterflyMP3
|
00001 00032 #ifdef NOKIA 00033 00034 #include <avr/io.h> 00035 #include <avr/pgmspace.h> 00036 #include <avr/interrupt.h> 00037 #include "main.h" 00038 #include "types.h" 00039 #include "lcdgraphics.h" 00040 #include "BCD.h" 00041 #include "avrfat16.h" // Included for long filename / ID3 stuff. 00042 00043 00044 #include "pcd8544.h" 00045 #include "fontset0.h" 00046 #include "font_ttuf1.h" 00047 #include "font_ttuf2.h" 00048 00049 00050 00051 // 00052 #include "uart.h" 00053 00054 00055 00056 00057 00058 //Butterfly MP3 title graphic 00059 // static unsigned char 00060 __attribute__((progmem)) 00061 static const char __attribute__((progmem)) bfMP3Title[] = 00062 { 00063 0x41, 0x51, 0x47, //'B' 00064 0x7F, 00065 0x41, 0x5F, 0x41, //'U' 00066 0x7F, 00067 0x7D, 0x41, 0x7D, //'T' 00068 0x7F, 00069 0x7D, 0x41, 0x7D, //'T' 00070 0x7F, 00071 0x41, 0x55, 0x5D, //'E' 00072 0x7F, 00073 0x41, 0x75, 0x4B, //'R' 00074 0x7F, 00075 0x41, 0x75, 0x7D, //'F' 00076 0x7F, 00077 0x41, 0x5F, 0x5F, //'L' 00078 0x7F, 00079 0x71, 0x47, 0x71, //'Y' 00080 0x7F, 00081 0x7F, 0x7F, 0x7F, //' ' 00082 0x7F, 00083 0x41, 0x79, 0x41, //'M' 00084 0x7F, 00085 0x41, 0x75, 0x71, //'P' 00086 0x7F, 00087 0x5D, 0x55, 0x41, //'3' 00088 00089 }; 00090 00091 00095 void LCD_Initialize(void) 00096 { 00097 lcdInit(); 00098 00099 } 00100 00101 00105 void LCD_Blank(void) 00106 { 00107 00108 uint8 i; 00109 00110 lcdClr(); 00111 lcdXY(0, 0); 00112 lcdModeData; 00113 00114 for (i = 0; i < 16; i++) 00115 lcdByte(0x7F); 00116 for (i = 0; i < sizeof(bfMP3Title); i++) { 00117 lcdByte(pgm_read_byte(bfMP3Title + i)); 00118 } 00119 for (i = 0; i < 17; i++) 00120 lcdByte(0x7F); 00121 00122 00123 } 00124 00125 00129 void LCD_Sleep(void) 00130 { 00131 lcdClr(); 00132 lcdSuspend; 00133 lcdReset; 00134 } 00135 00136 00140 void LCD_Wake(void) 00141 { 00142 extern uint8 gLCD_Refresh; 00143 lcdResume; 00144 lcdInit(); 00145 LCD_Blank(); 00146 //Make sure backgound image only is set 00147 00148 gLCD_Refresh = TRUE; 00149 } 00150 00151 00157 void LCD_PrintfU4(uint8 Data) 00158 { 00159 /* Send 4-bit hex value */ 00160 uint8 Character[2]; 00161 Character[0] = Data & 0x0f; 00162 if (Character[0] > 9) { 00163 Character[0] += 'A' - 10; 00164 } else { 00165 Character[0] += '0'; 00166 } 00167 00168 //load a pointer to the font 00169 uint8 * font = (uint8 *) fontSet0; 00170 //uint8 * font2 = (uint8 *) fontSet1; 00171 //uint8 * font2 = (uint8 *) fontSet1; 00172 00173 //uint8 fontSize = pgm_read_byte(font + 0); 00174 //chars in this font 00175 // uint8 fontX = pgm_read_byte(font + 1); 00176 //font width 00177 // uint8 fontY = pgm_read_byte(font + 2); 00178 //font hieght 00179 00180 Character[1] = 0x00; 00181 lcdWrite(font, Character, 0, 1); 00182 00183 00184 } 00185 00190 void LCD_PrintfU8(uint8 Data) 00191 { 00192 /* Send 8-bit hex value */ 00193 LCD_PrintfU4(Data >> 4); 00194 LCD_PrintfU4(Data); 00195 } 00196 00197 00198 00199 00200 00201 00209 uint8 LCD_Time(uint16 data) 00210 { 00211 00212 uint8 *font = (uint8 *) fontSet1; 00213 uint8 cBuff[6]; 00214 00215 lcdModeData; 00216 00217 //fbXY[0] = 43; 00218 //x 00219 // fbXY[1] = 2; 00220 //y 00221 // LCD_PrintfU8(data >> 8); 00222 //LCD_PrintfU8(data & 0xFF); 00223 00224 fbXY[0] = 65; 00225 //x 00226 fbXY[1] = 3; 00227 //y 00228 00229 cBuff[0] = (data / 600); 00230 data -= 600 * cBuff[0]; 00231 cBuff[1] = (data / 60); 00232 data -= 60 * cBuff[1]; 00233 00234 cBuff[2] = 58; 00235 //':' 00236 00237 cBuff[3] = (data / 10); 00238 data -= 10 * cBuff[3]; 00239 cBuff[4] = (data); 00240 00241 cBuff[5] = '\0'; 00242 00243 cBuff[0] += 0x30; 00244 cBuff[1] += 0x30; 00245 cBuff[3] += 0x30; 00246 cBuff[4] += 0x30; 00247 00248 lcdWrite(font, cBuff, 0, 0xFF); 00249 00250 return 0; 00251 } 00252 00258 uint8 LCD_FileName(uint8 resetScroll) 00259 { 00260 static uint8 byte = 0; 00261 static uint8 textIndex = LFN_TITLE_INDEX; 00262 static uint8 *textLen = &FAT16_LFNTitleLen; 00263 uint8 *font = (uint8 *) fontSet1; 00264 00265 if (resetScroll) { 00266 byte = 0; 00267 textIndex = LFN_TITLE_INDEX; 00268 textLen = &FAT16_LFNTitleLen; 00269 } 00270 fbXY[0] = 0; 00271 //x 00272 fbXY[1] = 2; 00273 //y 00274 00275 // Blank out the whole line(artist could be shorter than track and 00276 // vice - versa) 00277 lcdClrLine(2); 00278 00279 lcdModeData; 00280 if (byte < SONG_TITLE_PAUSE) 00281 lcdWrite(font, FAT16_longfilename + textIndex, 0, SONG_TITLE_WIDTH); 00282 else { 00283 lcdWrite(font, 00284 FAT16_longfilename + textIndex + byte - SONG_TITLE_PAUSE, 00285 0, 00286 SONG_TITLE_WIDTH); 00287 } 00288 00289 byte++; 00290 00291 if (*textLen >= SONG_TITLE_WIDTH) 00292 //We are scrolling 00293 { 00294 if (byte > *textLen - SONG_TITLE_WIDTH + SONG_TITLE_PAUSE) 00295 goto toggleText; 00296 } else 00297 //We are not scrolling 00298 { 00299 if (byte > SONG_TITLE_PAUSE) 00300 goto toggleText; 00301 } 00302 00303 return 0; 00304 00305 //Only efficient way of doing(without yet another function call with a lot 00306 // of parameters was a goto 00307 toggleText: 00308 { 00309 byte = 0; 00310 00311 //Toggle between displaying artist and title 00312 if ((FAT16_longfilename[LFN_TYPE_INDEX] == LFN_TYPE_FILENAME) || 00313 (textIndex == LFN_ARTIST_INDEX)) { 00314 textIndex = LFN_TITLE_INDEX; 00315 textLen = &FAT16_LFNTitleLen; 00316 } else if ((FAT16_longfilename[LFN_TYPE_INDEX] & LFN_TYPE_ID3_ARTIST) 00317 == LFN_TYPE_ID3_ARTIST) { 00318 textIndex = LFN_ARTIST_INDEX; 00319 textLen = &FAT16_LFNArtistLen; 00320 } 00321 return 0; 00322 } 00323 00324 00325 } 00326 00330 void LCD_Play(void) 00331 { 00332 lcdXY(0, 3); 00333 lcdModeData; 00334 lcdByte(0x1F); 00335 lcdByte(0x1F); 00336 lcdByte(0x0E); 00337 lcdByte(0x0E); 00338 lcdByte(0x04); 00339 lcdByte(0x04); 00340 00341 } 00342 00343 00347 void LCD_Stop(void) 00348 { 00349 lcdXY(0, 3); 00350 lcdModeData; 00351 lcdByte(0x1F); 00352 lcdByte(0x1F); 00353 lcdByte(0x1F); 00354 lcdByte(0x1F); 00355 lcdByte(0x1F); 00356 00357 } 00358 00359 00363 void LCD_Pause(void) 00364 { 00365 00366 lcdXY(0, 3); 00367 lcdModeData; 00368 lcdByte(0x1F); 00369 lcdByte(0x1F); 00370 lcdByte(0); 00371 lcdByte(0x1F); 00372 lcdByte(0x1F); 00373 00374 00375 } 00376 00381 void LCD_Vol(uint8 volume, uint8 boostOn) 00382 { 00383 uint8 i; 00384 uint8 level; 00385 00386 lcdXY(0, 5); 00387 lcdModeData; 00388 00389 //draw speaker icon 00390 lcdByte(60); 00391 lcdByte(60); 00392 lcdByte(126); 00393 lcdByte(255); 00394 lcdByte(0); 00395 lcdByte(0); 00396 00397 //draw volume graphic 00398 for (i = 0; i < 10; i++) { 00399 if (volume >= i) { 00400 if (i < 8) { 00401 level = 0xFF << (7 - i); 00402 if (boostOn) 00403 level |= 0x01 << (5 - i); 00404 } else 00405 level = 0xFF; 00406 00407 00408 lcdByte(level); 00409 lcdByte(level); 00410 lcdByte(level); 00411 lcdByte(0x00); 00412 } else { 00413 lcdByte(0x00); 00414 lcdByte(0x00); 00415 lcdByte(0x00); 00416 lcdByte(0x00); 00417 } 00418 } 00419 00420 //draw volume level 00421 // fbXY[0] = 10; 00422 //x 00423 // fbXY[1] = 4; 00424 //y 00425 // LCD_PrintfU4(volume); 00426 00427 00428 } 00429 00434 uint8 LCD_Tester(void) 00435 { 00436 00437 00438 //load a pointer to the font 00439 uint8 * font = (uint8 *) fontSet1; 00440 //uint8 * font2 = (uint8 *) fontSet2; 00441 00442 //uint8 fontSize = pgm_read_byte(font + 0); 00443 //chars in this font 00444 // uint8 fontX = pgm_read_byte(font + 1); 00445 //font width 00446 // uint8 fontY = pgm_read_byte(font + 2); 00447 //font hieght 00448 00449 00450 lcdModeData; 00451 // 00452 00453 fbXY[0] = 0; 00454 //x 00455 fbXY[1] = 1; 00456 //y 00457 lcdWrite(font,(uint8 *) VERSIONINFO2, 1, 0xFF); 00458 //lcdWrite(font, PSTR(__TIME__), 1, 0xFF); 00459 //fbXY[0] = 0; 00460 //x 00461 // fbXY[1] = 2; 00462 //y 00463 // lcdWrite(font, (uint8 *) PSTR(__DATE__), 1, 0xFF); 00464 00465 fbXY[0] = 0; 00466 //x 00467 fbXY[1] = 3; 00468 //y 00469 lcdWrite(font, (uint8 *) VERSIONINFO1, 1, 0xFF); 00470 00471 fbXY[0] = 0; 00472 //x 00473 fbXY[1] = 5; 00474 //y 00475 lcdWrite(font, (uint8 *) PSTR("NO MMC\0"), 1, 0xFF); 00476 00477 00478 return 0; 00479 } 00480 00481 00482 00486 void LCD_Scanning(void) 00487 { 00488 //load a pointer to the font 00489 uint8 * font = (uint8 *) fontSet1; 00490 00491 lcdModeData; 00492 00493 fbXY[0] = 0; 00494 //x 00495 fbXY[1] = 5; 00496 //y 00497 lcdWrite(font, (uint8 *) PSTR("SCANNING\0"), 1, 0xFF); 00498 00499 } 00500 00504 void LCD_Battery(uint8 percentage) 00505 { 00506 uint8 i; 00507 00508 lcdXY(71, 5); 00509 00510 lcdModeData; 00511 //fbXY[0] = 10; 00512 //x 00513 // fbXY[1] = 5; 00514 //y 00515 00516 // LCD_PrintfU8(percentage); 00517 //lcdCh(font, 04); 00518 //'%' 00519 00520 // Draw battery graphic 00521 00522 lcdByte(0x7E); 00523 //lcdByte(0x42); 00524 00525 for (i = 0; i < 100; i += 10) { 00526 if (percentage > i) { 00527 lcdByte(0x5A); 00528 } else { 00529 lcdByte(0x42); 00530 } 00531 } 00532 00533 lcdByte(0x42); 00534 lcdByte(0x3C); 00535 00536 00537 00538 } 00539 #endif