?? player.c
字號:
/**\file player.c * VLSI Modular Player Main file * * * This file contains the main() function. * It's also the main playground for player UI development. * Many functions will be transferred to a new module when they're ok. *//** \mainpage * * This is a preliminary version of the new MP3 player * evaluation kit source code. Some bugs still exist. * * This is pure C code. No inline assembly. * It compiles with SDCC 2.4.0. Upload with Atmel Flip. * Connect a terminal with settings 115200bps,N81 to the * serial port to see the console output. * * The code is written for VLSI Evakit 1.5-1.6 that has VS1011/1002 * and AT89C51RD2 microcontroller. * Now also Evakit 2.0-2.5 with VS1011, VS1002 or VS1003 is supported. * It should be easily portable * for other microcontrollers. * * All microcontroller/pcb -specific definitions should * be in board.h and board.c but some board specific * features may still lurk in the code elsewhere. * Due to SDCC requirements, interrupts are defined in player.c (main file). * They are of course board/cpu dependent. * * Throughout the code, SDCC memory allocation pragmas "code" "data" and "xdata" * are used, sorry. "Code" allocates from ROM, "data" allocates from fast RAM, * "xdata" allocates from slow RAM. You may need to remove/adjust these to make * code compatible with your compiler. * * It is strongly suggested that you use the free SDCC 2.4.0 to compile the * code. SDCC 2.5.0 fails to compile the code: Although it has advantages * over v2.4, it tries to allocate more extra temporary memory than is * available if you compile all the modules (incl. recording). * * <B>How to get started</b> * * - Look at "File list" to see what kind of modules are in the project. * - Look at vs10xx.c and vs10xx.h file documentations to see how the * vs10xx is reset and how to send MP3 data to it (PlayDiskSectors()). * - Function AvailableProcessorTime() handles the user interface. It is * called by PlayDiskSectors() whenever the player seems to have some free * time. Additionally, a timer interrupt routine sets the * <b>userInterfaceDelayElapsed</b> flag every 50ms or so. To avoid unnecessary * CPU load, AvailableProcessorTime() * checks this flag and updates display etc only when this flag is set. * - The user interface commands the player routine by setting a special * state variable <b>playingState</b>. For instance if the user pushes a "Next Song" * button, the ui should set <b>playingState</b> to <i>PS_NEXT_SONG</i>. * PlayDiskSectors() detects this, stops playing and returns to caller. * - Much of the main functionality is still in player.c and main(). Much * of it will be transferred to a new file ui.c at some time. * * The description of how the program works and the module structure will be * written here soon. Please check http://www.vlsi.fi/ * often to see if the final code is released. Email to * mp3@vlsi.fi about bugs. * * <b>Changes in version 0.5:</b> * * Filesystem and Storage are affected. Code has been added to handle new * MMC cards with manufacturer id 21 and possibly others that seem to * (sometimes) require resetting CRC calculation before they agree to work. * Storage.c is divided into submodules storage.c and mmc.c and a new * file buffer.c is created to hold the global I/O buffer. This clarifies * the code a lot. Lots of documentation is added to MMC and filing system * functions, do yourself a favor and read it through. * * In storage.c, mmc.c and filesys.c a "dummy" declarator Public is added * in declarations for functions that are called from outside the module * and thus form module interface. It has no code effect in C but is a * reminder for the programmer that the functions need to be adjusted * carefully. * * Storage.c is now a "middle-level" disk handler that takes advantage of * lower level functions in mmc.c. It handles decisions of when to seek * based on testing whether the underlying storage module supports * separate seeks before reads. A new function PrepareToReadDiskSector() is * for telling the storage that it can do a seek now if the storage * supports it. * * Adding support for different storage media that MMC is easy: only mmc.c * needs to be rewritten. Currently it only has 3 public functions: * Init, Seek sector and Read sector. As the code uses ONLY the address * granularity of 512 bytes, called a "disk sector", supporting hard * disks etc should be very simple. * * * <b>Support for compiling under Windows:</b> * * The code is natively developed under Linux and Makefile for GNU Make is * included. Now also .bat files for compiling in Dos window under Win32 * are included, plus a readme.txt file. Use them at your own risk :) * * <B>Changes in version 0.6</b> * * The major improvement is adding recording support. Recording for * VS1003 is supported. See the Record() function documentation for * instructions. The Record() function can only create a single file * fragment. If a fragment boundary is reached, recording continues * to a new file. * Also there is an experimental function PlayAVI() in * module aviplay.c that often succeeds in demuxing an avifile and * sending just the audio stream for decoding. * * Much of the FAT code is rewritten for speedups. * * \todo VFAT long file names, * * \remarks If you are usind SDCC 2.4.0 and you need just a little bit * of more DSEG memory (now how on Earth that might happen...) you * can hand-allocate global variables to unused addresses 0x08..0x1F, * for instance: declaring * <pre> * data at 0x08 unsigned int myVariable; * </pre> * would place myVariable in DSEG addresses 0x08..0x09. * * Note for HyperTerminal users: Check the "Append Line Feeds" checkbox * in terminal settings -> ascii setup. * * Example output to console: When the code runs it prints out something like: * (from a little older version) * <pre> * * Board: Console is up. * Init: Board; supports: AT89C51RD2, MMC, VS10xx, RS232 * * VLSI Modular Player * Starting up. * * Init: Filesystem; supports: MBR, FAT16, FAT32 * Trying to bring up storage... * Init: Storage v2: supports: MMC,SD,miniSD in SPI mode * Init: MMC * Card found, starting... Ok. * * MMC Manufacturer#: 30 Product Name: MMC Production date: 10 / 2004 * Media serial number: 00000468 * This MMC has no support for interrupted read. Using compatibility mode. * Storage initialized in seek-and-read mode. * Storage ok. * Sector 0 read...ok. * Sector signature...ok. * Partition 1... at sector 00000020 * Formatter signature: %j!BFIHC * Bytes per sector: 512 * Bytes per sector: 512 * Reserved sectors: 1 * Number of FATs: 2 * Root entries: 512 * Total Sectors 16: 0 * Fat Size 16: 123 * Hidden Sectors: 32 * Total Sectors 32: 125408 * File system is FAT16 * File system signature is FAT16 * Volume Label is NO NAME * Sectors per Cluster: 4 * FAT Start sector: 33 * Root start sector: 279 * Data start sector: 303 * * Init: VS10XX * Loading patch. * * Filesystem: Looking for file 1 ... found, FAT name is "UTOPIA~1MP3" * File size: 1471792 bytes. Start cluster: 0003h, sector 315 decimal. * Building file fragment table... * Fragment Start: 315 Fragment End: 3190 Fragment length: 2876 * * Fragments: 1 * Player: Playing from sector 315 * * </pre> * ...and so on. * */#include "board.h"#include "lcd.h"#include "filesys.h"#include "vs10xx.h"#include "storage.h"#include "display.h"#include "string.h"#include "ui.h"#include "mmc.h"#include "record.h"/** typedef for loading patch code */#define u_int8 code unsigned char /** typedef for loading patch code */#define u_int16 code unsigned int //include a patch code module#ifdef VS1003#include "spec_rew.c"#else#include "loud_sa.c"#endif/** How much to wait for button pressed before returning to title */#define UI_RETURN_DELAY 150/** Playing State Global */xdata playingstatetype playingState = PS_NORMAL;/** Current interrupt level */unsigned char intlevel = 0;/** Interrupt-driven flag to reduce unnecessary UI updates. * This is set to 1 by timer interrupt every n milliseconds. */xdata unsigned char userInterfaceDelayElapsed = 0;/** Current User Interface mode (Title, Volume, ...) */xdata uimodetype uiMode = UI_SPEC;xdata unsigned char SPMax=0;/** User Interface Timer interrupt. * Does NOT do any screen/button handling, only updates * screen scroll variable and the * userInterfaceDelayElapsed flag. */void timer0_interrupt(void) interrupt 1{ static char displayDelay; userInterfaceDelayElapsed = 1; if (++displayDelay==12){ displayDelay = 0; displayPosition++; if (displayPosition>displayLength+7){ displayPosition = -7; } } if (SP>SPMax) SPMax = SP; }/** Load a patch code to VS10xx */void LoadPatch(){ ConsoleWrite ("Loading patch.\r"); for (temp.i=0; temp.i < CODELEN; temp.i++) { Mp3WriteRegister(atab[temp.i], dtab[temp.i]>>8, dtab[temp.i]&0xff); } Delay(10);}/** Start patch code */void StartPatch(){#ifdef VS1003 // Mp3WriteRegister(SPI_AIADDR, 0x00, 0x50); #else //Mp3WriteRegister(SPI_AIADDR, 0x02, 0x00); //Mp3WriteRegister(SPI_AICTRL0, 0x00, 0x00); //Mp3WriteRegister(SPI_AICTRL0, 0x00, 0x01);#endif}/** Sets playing time and mode icon to left display title */void ScreenSetPlayTime(){ unsigned int playTime; unsigned char minutes, seconds; playTime = Mp3ReadRegister(SPI_DECODE_TIME); minutes = playTime/60; seconds = playTime%60; displayTitle[0]=('0'+minutes/10); displayTitle[1]=('0'+minutes%10); displayTitle[2]=(':'); displayTitle[3]=('0'+seconds/10); displayTitle[4]=('0'+seconds%10); displayTitle[5]=(' '); displayTitle[6]=(' '); displayTitle[7]=(' '); if (seconds&1){ if (playingState == PS_RECORDING){ displayTitle[6]='o'; }else{ displayTitle[6]='\x7e'; } } if ((playingState != PS_NORMAL)&&(playingState != PS_RECORDING)){ displayTitle[6]='\xdb'; } }/** This function is called when the player is playing a song and there is free processor time. The basic task of this function is to implement the player user interface. */void AvailableProcessorTime(){ /** Local variables: */ /** - <b>volume</b>: Current volume setting */ static xdata unsigned char volume = 20; /** - <b>bass</b>: Current bass enhancer setting */ static xdata unsigned char bass = 0; /** - <b>treble</b>: Current treble enhancer setting */ static xdata unsigned char treble = 64; //middle setting = 0 /** - <b>reclevel</b>: Current recording level setting */ static xdata unsigned char reclevel = 50; unsigned int i; //temp variable static bit bassUpdateNeeded; /** - <b>uiReturnDelay</b>: Counts down to returning to UI mode 0 (title screen) */ static unsigned char uiReturnDelay=0; if (!userInterfaceDelayElapsed){ return; /* Not yet time to do user interface stuff */ } userInterfaceDelayElapsed = 0; // User Interface Modes // Return to UI_TITLE after long period of button inactivity if (uiReturnDelay == 0){ if ((uiMode != UI_SPEC)&&(uiMode != UI_CUE)) uiMode = UI_TITLE; else{ } }else{ uiReturnDelay--; } #ifndef VS1003 if (uiMode==UI_SPEC) //Only VS1003 has spectrum analyzer uiMode++; if (uiMode==UI_RECLEVEL) //Only record in VS1003 chips uiMode++;#endif if (uiMode==UI_INFO) uiMode++; //Nothing interesting currently in screen UI_INFO. if (uiMode==UI_STOP) uiMode++; //Nothing interesting currently in screen UI_STOP. /* Screen updates */ switch(uiMode){ case UI_TITLE: //Playing time, song title displayStyle = DS_TEXT; ScreenSetPlayTime(); if (playingState==PS_RECORDING){ displayStyle = DS_PERCENTAGE; } break; case UI_STOP: //Ask if the user wants to stop displayStyle = DS_NO_YES; strcpy (displayTitle, "Stop? "); break; case UI_CUE: //Ask if the user wants to fast forward or rewind displayStyle = DS_RAWTEXT; strcpy (displayTitle, "REW/CUE <- ->"); //i = Mp3ReadRegister(SPI_HDAT1); //displayTitle[5] = lcd_hexchars[i>>12]; //displayTitle[6] = lcd_hexchars[(i>>8)&0x0f]; //displayTitle[7] = lcd_hexchars[(i>>4)&0x0f]; //displayTitle[8] = lcd_hexchars[i&0x0f]; break; case UI_VOLUME: //Show volume bar LcdSelectFont(lcdFont_barchars); displayStyle = DS_PERCENTAGE; strcpy(displayTitle,"Volume: "); displayValue = (100-(volume>>1)); if (displayValue<0) displayValue = 0; break; case UI_BASS: //Show bass bar LcdSelectFont(lcdFont_barchars); displayStyle = DS_PERCENTAGE; strcpy(displayTitle,"Bass: "); displayValue = (bass/5)*4; if (displayValue<1) displayValue = 1; break;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -