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

📄 uiser.c

📁 基于EP7312的MP3播放器源代码,包括MCU和PC端代码.
💻 C
📖 第 1 页 / 共 4 页
字号:
//****************************************************************************//// UISER.C - Functions for handling the user interface for the player, using//           the serial port as the display.//// Copyright (c) 1999,2000,2001 Cirrus Logic, Inc.////****************************************************************************#include "globals.h"#include "../hwport.h"#include "../hwdefs.h"//****************************************************************************//// We only include the remainder of this file if the serial port is used for// our user interface.////****************************************************************************#ifdef UI_IS_SERIAL_PORT//****************************************************************************//// Definitions for the various delays in the user interface, specified in// counts of the 50Hz user interface system clock.////     POWER_DELAY         The amount of time the power button must be//                         pressed to power down the player.//     RECORD_DELAY        The amount of time the record button must be//                         pressed to start voice recording.//     SEEK_DELAY          The amount of time the fast forward and rewind//                         buttons must be pressed to start seeking within the//                         track when playing or paused or to start skipping//                         tracks when stopped.//     SEEK_ACCEL          The amount of time the fast forward and rewind//                         buttons must be pressed to continue seeking within//                         the track when the player is playing or paused.//                         Should be a power of two.//     SEEK1_ACCEL         The amount of time the fast forward and rewind//                         buttons must be pressed to start the first notch of//                         accelerated seeking within the track when the//                         player is playing or paused.//     SEEK2_ACCEL         The amount of time the fast forward and rewind//                         buttons must be pressed to start the second notch//                         of accelerated seeking within the track when the//                         player is playing or paused.//     SEEK3_ACCEL         The amount of time the fast forward and rewind//                         buttons must be pressed to start the third notch of//                         accelerated seeking within the track when the//                         player is playing or paused.//     TRACK_ACCEL         The amount of time the fast forward and rewind//                         buttons must be pressed to continue skipping tracks//                         when the player is stopped.  Should be a power of//                         two.//     MENU_DELAY          The amount of time the menu arrow buttons must be//                         pressed to start scrolling in the given direction.//     MENU_LR_ACCEL       The amount of time the left and right menu arrow//                         buttons must be pressed to continue scrolling in//                         the given direction.  Should be a power of two.//     MENU_UD_ACCEL       The amount of time the up and down menu arrow//                         buttons must be pressed to continue adjusting in//                         the given direction.  Should be a power of two.//// For values which have a xxx_DELAY and xxx_ACCEL pair, the xxx_DELAY// determines the amount of the time the button must be pressed to start// performing that function, and the xxx_ACCEL determines the amount of time// between iterative operations of that function.  For example, after holding// the volume up button for VOLUME_DELAY time, the player will turn up the// volume by one.  Then, every VOLUME_ACCEL time after that until the button// is released, the player will turn up the volume by one.////****************************************************************************#define POWER_DELAY                             75      // 1.5 seconds#define RECORD_DELAY                            50      // 1 second#define SEEK_DELAY                              25      // .5 seconds#define SEEK_ACCEL                              8       // .16 seconds#define SEEK1_ACCEL                             150     // 3 seconds#define SEEK2_ACCEL                             300     // 6 seconds#define SEEK3_ACCEL                             450     // 9 seconds#define TRACK_ACCEL                             8       // .16 seconds#define MENU_DELAY                              25      // .5 seconds#define MENU_LR_ACCEL                           8       // .16 seconds#define MENU_UD_ACCEL                           4       // .08 seconds//****************************************************************************//// The number of clock ticks (which runs at 50Hz) that each button must be// pressed for the hold function to occur instead of the press function (i.e.// skipping forward within a song instead of advancing to the next song).////****************************************************************************static const unsigned char ucHoldTimes[6] = { POWER_DELAY,                                              RECORD_DELAY,                                              MENU_DELAY,                                              MENU_DELAY,                                              MENU_DELAY,                                              MENU_DELAY };//****************************************************************************//// The various bit fields in the flags member of the user interface persistent// state.////****************************************************************************#define FLAG_VOLUME_MASK                        0x0000001f#define FLAG_BASS_BOOST_MASK                    0x000001e0#define FLAG_TREBLE_BOOST_MASK                  0x00001e00#define FLAG_WAIT_FOR_ALL_UP                    0x00002000#define FLAG_SLEEP_MASK                         0x0000c000#define FLAG_SLEEP_1                            0x00000000#define FLAG_SLEEP_2                            0x00004000#define FLAG_SLEEP_3                            0x00008000#define FLAG_SLEEP_4                            0x0000c000#define FLAG_MENU_ITEM_MASK                     0x001f0000#define FLAG_UPDATE_MENU                        0x00200000#define FLAG_VOLUME_SHIFT                       0#define FLAG_BASS_BOOST_SHIFT                   5#define FLAG_TREBLE_BOOST_SHIFT                 9#define FLAG_SLEEP_SHIFT                        14#define FLAG_MENU_ITEM_SHIFT                    16//****************************************************************************//// The various bit fields in the ulSRSState member of the user interface// persistent state.////****************************************************************************#define FLAG_SRS_WIDTH_MASK                     0x0000001f#define FLAG_SRS_TRU_BASS_MASK                  0x000003e0#define FLAG_SRS_WIDTH_SHIFT                    0#define FLAG_SRS_TRU_BASS_SHIFT                 5//****************************************************************************//// The various bit fields in the ulQSoundState member of the user interface// persistent state.////****************************************************************************#define FLAG_QSOUND_WIDTH_MASK                  0x0000001f#define FLAG_QSOUND_MODE_MASK                   0x00000020#define FLAG_QSOUND_WIDTH_SHIFT                 0#define FLAG_QSOUND_MODE_SHIFT                  5//****************************************************************************//// The various bit fields in the ulSpatializerState member of the user// interface persistent state.////****************************************************************************#define FLAG_SPATIALIZER_BASS_MASK              0x0000001f#define FLAG_SPATIALIZER_VBASS_MASK             0x000003e0#define FLAG_SPATIALIZER_GAIN_MASK              0x00007c00#define FLAG_SPATIALIZER_BASS_SHIFT             0#define FLAG_SPATIALIZER_VBASS_SHIFT            5#define FLAG_SPATIALIZER_GAIN_SHIFT             10//****************************************************************************//// The persistent state of the user interface code.////****************************************************************************static struct{    //    // Various flags indicating the current state of the user interface.    //    unsigned long ulFlags;    //    // The count of the number of clock ticks that have occurred.  This is our    // time base for the various time-based elements of the user interface    // (such as automatically powering down the player after 30 seconds of    // inactivity).    //    unsigned short usTickCount;    //    // The time at which the next time delayed action is to occur.  This is    // used to automatically power down the player.    //    unsigned short usTargetTime;    //    // The value of usTickCount when each of the buttons was pressed.  These    // values only have a real meaning when the corresponding bit in ucState    // is set.    //    unsigned short usPressTime[6];    //    // The current set of virtual buttons that are pressed.  This is returned    // to the player to control the playback of audio.    //    unsigned long ulKeys;    //    // The current de-bounced state of the buttons.    //    unsigned char ucState;    //    // A two-cycle clock used to de-bounce the buttons.    //    unsigned char ucClock;    //    // The current mode of the player.    //    unsigned char ucMode;    //    // An unused byte to pad the next member to a word boundary.    //    unsigned char ucUnused;    //    // The name of the codec being used to decode the current file.    //    const unsigned short *pusCodec;    //    // The bitrate of the current file.    //    unsigned long ulBitRate;    //    // The length of the current file in milliseconds.    //    unsigned long ulTotalMS;    //    // The current position within the current file in milliseconds.    //    unsigned long ulCurrentMS;#ifdef SUPPORT_SRS    //    // The current settings of the SRS control.    //    unsigned long ulSRSState;#endif#ifdef SUPPORT_QSOUND    //    // The current settings of the QSound control.    //    unsigned long ulQSoundState;#endif#ifdef SUPPORT_SPATIALIZER    //    // The current settings of the Spatializer control.    //    unsigned long ulSpatializerState;#endif} sUI;//****************************************************************************//// Prototypes for the functions used to display the various menu controls, as// well as to update the player settings based on the value of a menu item.////****************************************************************************static unsigned long DisplayStringRing(unsigned long ulIndex);static unsigned long DisplayValue(unsigned long ulIndex);static unsigned long DisplayCodecs(unsigned long ulIndex);//****************************************************************************//// Descriptions of the items in the menu.////****************************************************************************static const struct{    //    // The name of this menu item.    //    char *pcName;    //    // The routine which prints the menu value to the serial port.    //    unsigned long (*pfnDisplay)(unsigned long ulIndex);    //    // The routine which updates the player state based on a change in the    // menu item value.    //    void (*pfnUpdate)(long lValue);    //    // The string of values for string rings.    //    char *pcValues;    //    // The number of values in the string ring, or the number of steps in the    // decible slider.    //    unsigned long ulNumValues;    //    // A pointer to the unsigned long which contains the flags for this menu    // item.    //    unsigned long *pulFlags;    //    // The bitmask of the bits in the flags which should be modified when this    // menu item is changed.    //    unsigned long ulFlagMask;    //    // The number of bits to shift to get to the bit field for this menu item.    //    unsigned long ulFlagShift;} sMenuItems[] ={    //    // The "Seek" menu item.    //    { "Seek", 0, 0, 0, 0, 0, 0, 0 },    //    // The "Volume" menu item.    //#if defined(ADDR_CS43L43) || defined(SOFTWARE_VOLUME_CONTROL)    { "Volume", DisplayValue, OutputSetVolume, 0, 21, &sUI.ulFlags,      FLAG_VOLUME_MASK, FLAG_VOLUME_SHIFT },#endif    //    // The "Repeat" menu item.    //    { "Repeat", DisplayStringRing, 0, "Off\0One\0All", 3,      (unsigned long *)&ulSystemFlags, SYSFLAG_REPEAT_MASK,      SYSFLAG_REPEAT_SHIFT },#ifdef SUPPORT_SRS#if defined(SUPPORT_WOW_FULL) || defined(SUPPORT_WOW_MINIMAL)    //    // The "WOW" menu item.    //    { "WOW", DisplayValue, OutputSetSRSWidth, 0, 21, &sUI.ulSRSState,      FLAG_SRS_WIDTH_MASK, FLAG_SRS_WIDTH_SHIFT },#endif#if defined(SUPPORT_WOW_FULL) || defined(SUPPORT_WOW_MINIMAL) || \    defined(SUPPORT_TRU_BASS)    //    // The "TruBass" menu item.    //    { "TruBass", DisplayValue, OutputSetSRSTruBass, 0, 21, &sUI.ulSRSState,      FLAG_SRS_TRU_BASS_MASK, FLAG_SRS_TRU_BASS_SHIFT },#endif#ifdef SUPPORT_SRS_HEADPHONE    //    // The "SRS" menu item.    //    { "SRS", DisplayValue, OutputSetSRSWidth, 0, 21, &sUI.ulSRSState,      FLAG_SRS_WIDTH_MASK, FLAG_SRS_WIDTH_SHIFT },#endif#endif#ifdef SUPPORT_QSOUND    //    // The "Q2X" menu item.    //    { "Q2X", DisplayValue, OutputSetQSoundWidth, 0, 21, &sUI.ulQSoundState,      FLAG_QSOUND_WIDTH_MASK, FLAG_QSOUND_WIDTH_SHIFT },    //    // The "Q2X Mode" menu item.    //    { "Q2X Mode", DisplayStringRing, OutputSetQSoundMode, "0\0001", 2,      &sUI.ulQSoundState, FLAG_QSOUND_MODE_MASK, FLAG_QSOUND_MODE_SHIFT },#endif#ifdef SUPPORT_SPATIALIZER    //    // The "Bass" menu item.    //    { "Bass", DisplayValue, OutputSetSpatializerBass, 0, 21,      &sUI.ulSpatializerState, FLAG_SPATIALIZER_BASS_MASK,      FLAG_SPATIALIZER_BASS_SHIFT },    //    // The "Vi.B.E." menu item.    //    { "Vi.B.E.", DisplayValue, OutputSetSpatializerVirtualBass, 0, 21,      &sUI.ulSpatializerState, FLAG_SPATIALIZER_VBASS_MASK,      FLAG_SPATIALIZER_VBASS_SHIFT },    //    // The "Gain" menu item.    //    { "Gain", DisplayValue, OutputSetSpatializerGain, 0, 21,      &sUI.ulSpatializerState, FLAG_SPATIALIZER_GAIN_MASK,      FLAG_SPATIALIZER_GAIN_SHIFT },#endif    //    // The "Treble" menu item.    //#if defined(ADDR_CS43L43) || defined(SOFTWARE_TONE_CONTROL)    { "Treble", DisplayValue, OutputSetTreble, 0, 13, &sUI.ulFlags,      FLAG_TREBLE_BOOST_MASK, FLAG_TREBLE_BOOST_SHIFT },#endif    //    // The "Bass" menu item.    //#if defined(ADDR_CS43L43) || defined(SOFTWARE_TONE_CONTROL)    { "Bass", DisplayValue, OutputSetBass, 0, 13, &sUI.ulFlags,      FLAG_BASS_BOOST_MASK, FLAG_BASS_BOOST_SHIFT },#endif    //    // The "Sleep" menu item.    //    { "Sleep", DisplayStringRing, 0, "1 min\0002 min\0003 min\0004 min",      4, &sUI.ulFlags, FLAG_SLEEP_MASK, FLAG_SLEEP_SHIFT },    //    // The "Version" menu item.    //    { "Release 16", 0, 0, 0, 0, 0, 0 },    //    // The "Codecs" menu item.    //    { "Codecs ", DisplayCodecs, 0, 0, 1, 0, 0 },};//****************************************************************************//// Initializes the serial port and configures it for 115,200, 8-N-1.////****************************************************************************static voidSerialInit(void){    volatile unsigned long *pulPtr = (unsigned long *)HwBaseAddress;    //    // Configure the serial port for 115,200, 8-N-1.    //    pulPtr[HwUartControl >> 2] = HwUartControlFifoEnable |                                 HwUartControlDataLength8 |                                 HwUartControlRate115200;    //    // Enable the serial port.    //    pulPtr[HwControl >> 2] |= HwControlUartEnable;}//****************************************************************************//// Sends a character to the serial port.////****************************************************************************static voidSerialSendChar(char cChar){    volatile unsigned long *pulPtr = (unsigned long *)HwBaseAddress;    //    // Wait until there is space available in the transmit FIFO.    //    while(pulPtr[HwStatus >> 2] & HwStatusUartTxFifoFull)    {    }    //    // Write the character to the transmit FIFO.    //    pulPtr[HwUartData >> 2] = cChar;}//****************************************************************************//// Sends a string of characters to the serial port.//

⌨️ 快捷键说明

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