⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uiser.c

📁 基于EP7312的MP3播放器源代码,包括MCU和PC端代码.
💻 C
📖 第 1 页 / 共 4 页
字号:
        // We are playing a file.        //        case MODE_PLAY:        {            //            // Tell the user that we are playing.            //            SerialSendString("\rPlaying ");            //            // Print out the name of the codec being used.            //            SerialSendChar(sUI.pusCodec[0]);            SerialSendChar(sUI.pusCodec[1]);            SerialSendChar(sUI.pusCodec[2]);            SerialSendChar(sUI.pusCodec[3]);            //            // Print out the bitrate of the current file.            //            SerialSendChar(' ');            UIPrintBitRate(sUI.ulBitRate);            //            // Print out the current position in the file.            //            SerialSendChar(' ');            UIPrintTime(sUI.ulCurrentMS);            //            // We're done with this state.            //            break;        }        //        // We are paused in the middle of the playback of a file.        //        case MODE_PAUSE:        {            //            // Tell the user that we are paused.            //            SerialSendString("\rPaused  ");            //            // Print out the name of the codec being used.            //            SerialSendChar(sUI.pusCodec[0]);            SerialSendChar(sUI.pusCodec[1]);            SerialSendChar(sUI.pusCodec[2]);            SerialSendChar(sUI.pusCodec[3]);            //            // Print out the bitrate of the current file.            //            SerialSendChar(' ');            UIPrintBitRate(sUI.ulBitRate);            //            // Print out the current position in the file.            //            SerialSendChar(' ');            UIPrintTime(sUI.ulCurrentMS);            //            // We're done with this state.            //            break;        }        //        // We are recording.        //        case MODE_RECORD:        {            //            // Tell the user that we are recording.            //            SerialSendString("\rRecord  ");            //            // Print out the name of the codec being used.            //            SerialSendChar(sUI.pusCodec[0]);            SerialSendChar(sUI.pusCodec[1]);            SerialSendChar(sUI.pusCodec[2]);            SerialSendChar(sUI.pusCodec[3]);            //            // Print out the bitrate of the current file.            //            SerialSendChar(' ');            UIPrintBitRate(sUI.ulBitRate);            //            // Print out the current position in the file.            //            SerialSendChar(' ');            UIPrintTime(sUI.ulCurrentMS);            //            // We're done with this state.            //            break;        }    }}//****************************************************************************//// UISetMode is called to inform us of changes in the current transport state.////****************************************************************************voidUISetMode(unsigned long ulMode){    //    // If the current mode is download or power on, then we need to enable the    // timer.    //    if(((sUI.ucMode & 0x1f) == MODE_DOWNLOAD) ||       ((sUI.ucMode & 0x1f) == MODE_POWER_ON))    {        //        // Enable the timer interrupt.        //        EnableTimer();    }    //    // Remember the current mode.    //    sUI.ucMode = ulMode;    //    // Some modes we handle directly.  See if we are powering off.    //    if(ulMode == MODE_POWER_OFF)    {        //        // Disable the timer interrupt.        //        DisableTimer();    }    //    // See if we are powering on.    //    else if(ulMode == MODE_POWER_ON)    {        //        // Since we were just powered on, we want to wait until all the buttons        // are released before we process any buttons.        //        sUI.ulFlags |= FLAG_WAIT_FOR_ALL_UP;        //        // Clear any keys that might have already been pressed.        //        sUI.ulKeys = 0;    }    //    // See if we are starting a download.    //    else if(ulMode == MODE_DOWNLOAD)    {        //        // Disable the timer interrupt.        //        DisableTimer();    }    //    // We need to move the target time so that we do not get an automatic    // power off.    //    sUI.usTargetTime = sUI.usTickCount +                       (3000 * (((sUI.ulFlags & FLAG_SLEEP_MASK) >>                                 FLAG_SLEEP_SHIFT) + 1));    //    // Update the display.    //    UIUpdateDisplay();}//****************************************************************************//// UIFileLoaded is called when a new file has been opened.  It is up to the UI// code to determine whatever information it needs about the file and to// update any indicators which are based on the currently opened file.////****************************************************************************voidUIFileLoaded(unsigned short *pusFileName, unsigned long ulTrack){    //    // Get the name of the current codec.    //    CodecGetName(&sUI.pusCodec);    //    // Get the bitrate of the current file.    //    CodecGetBitRate(&sUI.ulBitRate);    //    // Get the length of the current file.    //    CodecGetLength(&sUI.ulTotalMS);    //    // When a file is loaded, the current time defaults to zero.    //    sUI.ulCurrentMS = 0;    //    // Update the display.    //    UIUpdateDisplay();}//****************************************************************************//// UINoTracks is called when there are no tracks on the device.  It is up to// the UI to clear any variables and/or indicators which are related to a// currently opened file.////****************************************************************************voidUINoTracks(void){    //    // Clear the variables which relate to the currently loaded file.    //    sUI.pusCodec = 0;    sUI.ulBitRate = 0;    sUI.ulTotalMS = 0;    sUI.ulCurrentMS = 0;}//****************************************************************************//// UISetCurrentTime is called to inform us of a change in the current position// (in milliseconds) within the current file.////****************************************************************************voidUISetCurrentTime(unsigned long ulMS){    unsigned long ulT1, ulT2;    //    // Remember the current position.    //    ulT1 = sUI.ulCurrentMS / 1000;    sUI.ulCurrentMS = ulMS;    ulT2 = sUI.ulCurrentMS / 1000;    //    // Print the current time.    //    if((sUI.ucMode != MODE_STOP) && (ulT1 != ulT2))    {        SerialSendString("\b\b\b\b\b");        UIPrintTime(ulMS);    }}//****************************************************************************//// UIGetButtons returns the current state of the buttons.  This performs a// mapping of the physical buttons to a logical set of buttons.  In fact, a// physical button may correspond to more than one logical button (based on// any criteria, such as being pressed in combination with another button or// being held for a certain amount of time).////****************************************************************************unsigned longUIGetButtons(void){    unsigned long ulRet, ulIdx, ulLoop;    //    // Disable interrupts so that the buttons can not be modified while we are    // reading them.    //    DisableIRQ();    //    // Get the current set of pressed buttons.    //    ulRet = sUI.ulKeys;    //    // Clear the current set of pressed buttons.    //    sUI.ulKeys = 0;    //    // See if we need to update the menu on the serial port.    //    if(sUI.ulFlags & FLAG_UPDATE_MENU)    {        //        // Get the current menu item.        //        ulIdx = (sUI.ulFlags & FLAG_MENU_ITEM_MASK) >> FLAG_MENU_ITEM_SHIFT;        //        // First, clear the previous menu text.        //        SerialSendString("                      ");        SerialSendString("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");        //        // Print the current menu item.        //        for(ulLoop = 0; ulLoop < 16; ulLoop++)        {            if(sMenuItems[ulIdx].pcName[ulLoop])            {                SerialSendChar(sMenuItems[ulIdx].pcName[ulLoop]);            }            else            {                break;            }        }        //        // If there is a display function for this menu item, then call it now.        //        if(sMenuItems[ulIdx].pfnDisplay)        {            ulLoop += (sMenuItems[ulIdx].pfnDisplay)(ulIdx);        }        //        // Skip back to the original cursor position.        //        ulLoop += 2;        while(ulLoop--)        {            SerialSendChar('\b');        }                    //        // Indicate that we no longer need to update the menu.        //        sUI.ulFlags &= ~FLAG_UPDATE_MENU;    }    //    // Re-enable interrupts.    //    EnableIRQ();    //    // Return the set of pressed buttons.    //    return(ulRet);}//****************************************************************************//// Scans the buttons on the player and determines which ones were pressed,// held, and released.////****************************************************************************static __inline unsigned longScanButtons(void){    volatile unsigned long *pulPtr = (unsigned long *)HwBaseAddress;    unsigned long ulKeys, ulDiff, ulIdx, ulButtons = 0;    //    // Get the current state of the keys.    //    ulKeys = pulPtr[HwPortABCD >> 2] & HwPortABCD_Button_Mask;    //    // See which keys have changed.    //    ulDiff = ulKeys ^ sUI.ucState;    //    // Advance the clock for all the keys.    //    sUI.ucClock ^= 0xff;    //    // Mask off the clock for the keys which did not change state.    //    sUI.ucClock &= ulDiff;    //    // Now, the bit positions of clock which are zero indicate keys that either    // have not changed state or which have been in their new state for two    // consecutive sampling periods.  So, update the key state based on the new    // state of the clock.    //    sUI.ucState &= sUI.ucClock;    sUI.ucState |= ~sUI.ucClock & ulKeys;     //    // Loop through the keys and perform press, release, and hold processing    // on them.    //    for(ulIdx = 0; ulIdx < 6; ulIdx++)    {        //        // If this key did not change state, then there is nothing to do.        //        if(!((ulDiff ^ sUI.ucClock) & (1 << ulIdx)))        {            continue;        }        //        // If this key was just pressed, save the time at which it was pressed.        //        if(ulKeys & (1 << ulIdx))        {            //            // Save the time at which this button was pressed.            //            sUI.usPressTime[ulIdx] = sUI.usTickCount;            //            // If there is no hold time for this button (i.e. it does not have            // separate functions for press and for hold), then indicate that            // this button has been pressed.            //            if(ucHoldTimes[ulIdx] == 0)            {                ulButtons |= 0x00000001 << ulIdx;            }            //            // There is a hold time for this button, so at least indicate that            // it has just been pressed (for buttons that are accelerated, such            // as the volume up button).            //            else            {                ulButtons |= 0x00010000 << ulIdx;            }        }        //        // This key was just released, so determine if it was pressed or held,        // based on the elapsed time it was pressed.        //        else        {            //            // If the button was pressed for less than the hold time, then the            // button was pressed, not held.            //            if((((sUI.usTickCount - sUI.usPressTime[ulIdx]) & 0xffff) <                ucHoldTimes[ulIdx]) && (ucHoldTimes[ulIdx] != 0))            {                ulButtons |= 0x00000001 << ulIdx;            }            //            // Indicate that this button has been released.            //            ulButtons |= 0x01000000 << ulIdx;        }    }    //    // Return the current button state.    //    return(ulButtons);}//****************************************************************************//// Takes care of converting physical button presses/holds into virtual button// presses.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -