You are on page 1of 235

M5661 Firmware Programming Guide

M5661 Firmware Programming Guide

www.ali.com.tw

M5661 Firmware Programming Guide

This document contains confidential proprietary information that is solely for authorized personnel. It is not to be disclosed to any unauthorized person without prior written consent of ALi Corporation.

ALi Corporation

ALi Corporation makes no representations or warranties with respect to the accuracy or completeness of the contents of this document. No license, whether express, implied, arising by estoppel or otherwise, to any intellectual property right is granted by this document.

ALi Corporation also reserves the right to make changes to these specifications and product description at any time without notice. Contact your local sales office to obtain the latest specifications before placing your order.

Third-party brands and name mentioned in this publication are for identification purpose only and may be the property of their respective owners.

Copyright ALi Corporation, 2004. All rights reserved

www.ali.com.tw

M5661 Firmware Programming Guide

Version History
Date 12/15/2004 8/15/2005 10/22/2005 10/22/2005 Version 1.0 1.1 1.2 1.3 Description First release Update functions Update functions and append OLED and Classification functions Append the OledString function.

www.ali.com.tw

M5661 Firmware Programming Guide

CONTENTS Copyright ALi Corporation, 2004. All rights reserved ............................ 2 Version History................................................................................................. 3 1 2 Firmware Architecture ............................................................................. 6 Programming Guide ................................................................................. 7
2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10 2.11 2.12 2.13 2.14 2.15 2.16 2.17 2.18 2.19 2.20 2.21 2.22 2.23 2.24 2.25 2.26 2.27 2.28 2.29 2.30 FILE SYSTEM (FILESYSTEM.C) ........................................................................... 7 NAND FLASH (NANDFLASH.C)......................................................................... 18 SD (SD.C)........................................................................................................ 27 PLAYBACK (PLAYBACK.C) ............................................................................... 32 RECORD (RECORD.C) ....................................................................................... 36 IMAADPCM (IMAADPCM.C) ............................................................................. 39 KEY (KEY.C) .................................................................................................... 42 FM (FMCHIP.C)................................................................................................ 44 BASE64 (BASE64.C)......................................................................................... 47 LCD (LCD.C) ................................................................................................... 48 OLED (OLED.C)................................................................................................ 69 OLEDSTRING (OLEDSTRING.C) ........................................................................ 86 IDMA (IDMA.C)............................................................................................... 92 USB (USB.C) ................................................................................................. 102 USBHOST (USBHOST.C) ............................................................................... 105 USB HOST COMMON (USBHOSTCOMMON.C)............................................... 109 USB HOST FAT (USBHOSTFAT.C)...................................................................111 ATA (ATA.C) .................................................................................................. 125 COMMON (COMMON.C).................................................................................. 126 DDM (DDM.C) ............................................................................................. 139 DRM (DRM.C) ................................................................................................ 140 INTCODEC (INTCODEC.C) .............................................................................. 144 EXTCODEC (EXTCODEC.C) ............................................................................ 148 MTP (MTP.C) .................................................................................................. 149 SAVESETTING (SAVESETTING.C) .................................................................... 153 UI COMMON (UICOMMON.C)......................................................................... 154 UI PLAY (UIPLAY.C)....................................................................................... 170 UI PLAY DVR (UIPLAY.C) ............................................................................. 181 UI RECORD (UIREC.C)................................................................................... 184 UI FM (UIFM.C) ........................................................................................... 189 4

www.ali.com.tw

M5661 Firmware Programming Guide 2.31 2.32 2.33 2.34 2.35 2.36 2.37 2.38 UI SYSTEM (UISYS.C).................................................................................... 196 UI FILE LIST (UIFILELIST.C).......................................................................... 202 UI PLAY COMMON (UIPLAYCOMMON.C)....................................................... 203 UI PLAY MENU (UIPLAYMENU.C) ................................................................. 209 UI PLAY MENU2 (UIPLAYMENU2.C) ............................................................. 211 UI USB DEVICE (UIUSBDEVICE.C) ................................................................ 213 UI USB HOST (UIUSBHOST.C) ....................................................................... 214 UI CLASS LIST (UICLASSLIST.C) ................................................................... 216

www.ali.com.tw

M5661 Firmware Programming Guide 1 Firmware Architecture

User Interface

DDM

Initial

LCD

Key

USB

Playback

DVR

Record

FM

System

ATA

File System

Nand Flash

SD

www.ali.com.tw

M5661 Firmware Programming Guide 2 Programming Guide 2.1 File System (FileSystem.c) 2.1.1 API Functions

FsInit( )
Check MBR, FAT version, PBR. Make sure that bytes per sector is 512. bit FsInit(void) Parameters None Return values bit type TRUE: file system initialed OK. FALSE: file system initialed FAILED. Global variable XBYTE gxbErrCode If FsInit( ) fail, gxbErrCode will be set as ERR_FS_INIT_ERROR; BOOL gfKeptDataModified XDWORD gxdwKeptDataSec Example

See also FsRecInit(void)

FsRead()
This function would read the data from NAND FLASH and you can get it from global array gxbFsData. bit FsRead(DWORD dwStorLba, BYTE bStorLen, BYTE bStorPath) Parameters DWORD dwStorLba NAND FLASH start sector you want to read. BYTE bStorLen Data length in sector you want to read. BYTE bStorPath There are several Storage Path FS_DATA_0_0, FS_FAT and FS_LRC that you can use. The data you read from the NAND FLASH would be stored in the selected

www.ali.com.tw

M5661 Firmware Programming Guide


Storage Path. On another point, the constant FS_FAT1_EXT1 indicates the same Storage Path as FS_LRC and FS_FAT1_EXT2 is the same as FS_FAT if the constant REC_PRE_SEARCH has defined. Global variable XBYTE gxbFsData[2048], gxbLyrics[2048], gxbFsFat[2048] Every Storage Path is assigned a global array, so you can get the data from the Storage Path by using this global array. For the relation between Storage Path and Global Array is listed as below. Storage Type FS_DATA_0_0 FS_LRC, FS_FAT1_EXT1 FS_FAT, FS_FAT1_EXT2 Relative Global Array gxbFsData[2048] gxbLyrics[2048] gxbFsFat[2048]

There is one other important note that getting data from the global array must have offset index by using the global variable gxwOffsetDataSec. This global variable would be stored with proper value after executing this function. XBYTE gxbStorType STOR_NAND: To read data from Nand Flash. STOR_SD: To read data from SD card. Return values Bit type TRUE: Success. FALSE: Fail or read I/O error. Example For below example is to read the data at the 5s sector with 1 sector length in Nand Flash. The data would be stored in the Storage Path FS_DATA_0_0. FsRead(5,1,FS_DATA_0_0); To get the fourth data byte. BYTE a=gxbFsData[3+gxwOffsetDataSec];

See also

FsWrite()
This function can write data to NAND FLASH. bit FsWrite(DWORD dwStorLba, BYTE bStorLen, BYTE bStorPath) Parameters DWORD dwStorLba

www.ali.com.tw

M5661 Firmware Programming Guide


NAND FLASH start sector you want to write. BYTE bStorLen Data length in sector you want to write. BYTE bStorPath Storage Path you want to write. For detail description, you can refer FsRead(). Global Variable XBYTE gxbStorType STOR_NAND: To read data from Nand Flash. STOR_SD: To read data from SD card. Return values Bit type Return TRUE if write data success, or else. Example

See also

FsFindDir()
To finds a directory. bit FsFindDir(PBYTE pbDirName, BOOL fCreate) Parameters PBYTE pbDirName Directory name you want to find. BOOL fCreate TRUE: The function would create this directory if cant find the directory. FALSE: The function wouldnt create this directory if cant find the directory. Return values Bit type TRUE: Success. FALSE: Cant find (create) directory, or i/o read error. Global variable XBYTE gxbStorType STOR_NAND: To read data from Nand Flash STOR_SD: To read data from SD card IBYTE gbStorPath: The data path you want to read, this value of argument you can take on is following, FS_DATA_0_0, FS_FAT, FS_FAT1_EXT2, FS_LRC and FS_FAT1_EXT1. For more description, you can refer the function of FsRead().

www.ali.com.tw

M5661 Firmware Programming Guide


gxbMusicType: The type of music, the value which can be assigned is following, M_MP3, M_WMA_UNKNOWN, M_OGG, M_WAV, etc. For more defined constant of music type are defined in const.h. Example

See also

FsFullFormat()
This function would be a full format to reconstruct PBR and erase all the space of flash. bit FsFullFormat(void) Parameters None Global arguments: XBYTE gxbStorType STOR_NAND: To read data from Nand Flash STOR_SD: To read data from SD card IBYTE gbStorPath: The data path you want to read, this value of argument you can take on is following, FS_DATA_0_0, FS_FAT, FS_FAT1_EXT2, FS_LRC and FS_FAT1_EXT1. For more description, you can refer the function of FsRead(). Return values Bit type TRUE: format successfully. FALSE: format fail or I/O error. Example

See also

FsQuickFormat()
This function is not a low level format that is different from fsFullFormat(). What it does is keeping MBR and PMR, and clearing occupied cluster# at FAT and root. bit FsQuickFormat(void) Parameters None

www.ali.com.tw

10

M5661 Firmware Programming Guide


Global Variable XBYTE gxbStorType STOR_NAND: To read data from Nand Flash. STOR_SD: To read data from SD card. IBYTE gbStorPath The data path you want to read, this value of argument you can take on is following, FS_DATA_0_0, FS_FAT, FS_FAT1_EXT2, FS_LRC and FS_FAT1_EXT1. For more description, you can refer the function of FsRead(). Return values Bit type TRUE: format successfully. FALSE: format fail or I/O error. Example

See also

FsOpenNewFile()
Open a new file. bit FsOpenNewFile(BYTE bDirIndex, bit fFindEmptyClu) Parameters BYTE bDirIndex, The Index of Directory where the Rec file would be stored. The range of this parameter is from 0 to REC_DIR_NUM defined in const.h. bit fFindEmptyClu TRUE: Find Empty cluster for record. FALSE: It would not to find empty cluster. Global Variable XBYTE gxbFileName: gxbFileName[0]~gxbFileName[REC_PREFIX_LEN] need to assign proper value before using this function. Return values Bit type Return TRUE if write data success, or else. Example

See also

www.ali.com.tw

11

M5661 Firmware Programming Guide FsOpenFile()


This function would open an existed file. bit FsOpenFile(BYTE bOpenType) Parameters BYTE bOpenType This parameter to be decided by which type of file you want to open. The parameter could have the const value defined in const.h as follows. FIRST_FILE NEXT_FILE PREV_FILE FIRST_PLAYBACK NEXT_PLAYBACK PREV_PLATBACK LYRICS_FILE The file you assign the LYRICS_FILE parameter to find a Lyrics file is on the same directory of mp3, and the filename is the same with current mp3 filename which defined in the global array gbFileName[0~7]. For another note, open a Lyrics file will not change any information of current file. Global Variable XBYTE gxbStorType STOR_NAND: To read data from Nand Flash STOR_SD: To read data from SD card IBYTE gbStorPath The data path you want to read, this value of argument you can take on is following, FS_DATA_0_0, FS_FAT, FS_FAT1_EXT2, FS_LRC and FS_FAT1_EXT1. For more description, you can refer the function of FsRead(). XBYTE gxbMusicType The type of music, the value which can be assigned is following, M_MP3, M_WMA_UNKNOWN, M_OGG, M_WAV, etc. For more defined constant of music type are defined in const.h.

Return values Bit type TRUE: file open successfully. FALSE: cant find file or I/O read error. Example

www.ali.com.tw

12

M5661 Firmware Programming Guide


See also

FsCloseFile()
Close the current file. bit FsCloseFile(BYTE bDirIndex) Parameters BYTE bDirIndex, The parameter of index is determined by what directory you want to close at. The range of this parameter is from 0 to REC_DIR_NUM defined in const.h. Return values Bit type TRUE: file open successfully. FALSE: cant find file or I/O read error. Global Variable

Example

See also

FsDeleteFile()
Delete a current exist file. It would also clear the occupied cluster# at FAT. After deletion of the file, the file pointer would point to the previous file. bit FsDeleteFile(void) Parameters None Return values Bit type TRUE: delete file successfully FALSE: cant delete file or i/o read error Global variable XBYTE gxbStorTyp The storage which you want to read from. IBYTE gbStorPath The data path you want to read, this value of argument you can take on is as follows.

www.ali.com.tw

13

M5661 Firmware Programming Guide


FS_DATA_0_0, FS_FAT, FS_FAT1_EXT2, FS_LRC, FS_FAT1_EXT1 For more description, you can refer the function of FsRead(). XBYTE gxbMusicType The type of music, the value which can be assigned is following, M_MP3, M_WMA_UNKNOWN, M_OGG, M_WAV, etc. For more defined constant of music type are defined in const.h. Example

See also

FsReadFileSector()
Read the data from a file with the size of a sector. bit FsReadFileSector(DWORD dwSector, BOOL fLrcfile , BYTE bSrampath) Parameters DWORD dwSector Sector Number based on a file. BOOL fLrcfile This parameter is determined by which file would be read. The file type has defined constant value of READ_LYRICS_SECTOR and READ_PLAYBACK_SECTOR that you can assign. READ_LYRICS_SECTOR: Current playback file. READ_PLAYBACK_SECTOR: Lyrics file. BYTE bSrampath The parameter indicates where the data would be store in. It is the same as the parameter IBYTE gbStorPath in the function of fsRead(). For the detail, you can refer to this function. Return values Bit type TRUE: FALSE: Global variable FILE_INF_DATA gpstFileIndex Which file structure be used XBYTE gxbStorType STOR_NAND: To read data from Nand Flash STOR_SD: To read data from SD card IBYTE gbStorPath

www.ali.com.tw

14

M5661 Firmware Programming Guide


The data path you want to read, this value of argument you can take on is following, FS_DATA_0_0, FS_FAT, FS_FAT1_EXT2, FS_LRC and FS_FAT1_EXT1. For more description, you can refer the function of FsRead(). Example

See also

FsChangeDir()
Change system directory. BOOL FsChangeDir(BYTE bChangeType) Parameters BYTE bChagneType The type of Directory you want to change. Directory Type are defined as following constant value, ENTER_DIR, BACK_DIR, RESTORE_DIR. Return values Bit type TURE: Success. FALSE: Fail. Global variable

Example

See also

FsWriteFileSector()
Get an empty sector for the sake of writing file data to this sector. bit FsWriteFileSector(DWORD dwSector) Parameters DWORD dwSector Return values Bit type TURE: Success. FALSE: Fail. Global variable

www.ali.com.tw

15

M5661 Firmware Programming Guide


Example

See also

FsWriteFileHeader()
Write WAVE File Header. bit FsWriteFileHeader(void) Parameters None Return values Bit type TURE: Success. FALSE: Fail. Global variable

Example

See also

2.1.2 FsWrite( )

SYS Functions

Write data from SRAM to NAND flash with low-level function. bit FsWrite(DWORD dwStorLba, BYTE bStorLen, BYTE bStorPath) Parameters DWORD dwStorLba Specifies the logical block address (LBA) to put data. BYTE bStorLen Specifies the number of sector to write. BYTE bStorPath Specifies the index of SRAM buffer with data. Return values Bit type Example The following example use FsWrite( ) to close a FAT32 file. FatWrite(gxdwFileCurrentClu, FAT32_EOC_TAG); dwCurrentWriteSec=gxdwFat1+((gxdwFileCurrentClu * gxbFatType)>>12); if(gxdwFileCurrentClu%1024==682) dwCurrentWriteSec+=1;

www.ali.com.tw

16

M5661 Firmware Programming Guide


if(!FsWrite(dwCurrentWriteSec,1,FS_FAT)) return FALSE; See also FsInit() | FsRead()

www.ali.com.tw

17

M5661 Firmware Programming Guide 2.2 Nand Flash (NandFlash.c) 2.2.1 API Functions

NandInit()
Initialization Nand Flash. Divide into 3 Parts: NandInitPre: Variable and Register Init, Identify Nand Type. NandDefaultSetting1: Get and set Configure. NandDefaultSetting2: Build LUT. API bit NandInit(void) Parameters None Return values Bit type TRUE: FALSE: Global variables

Example

See also

NandWrite()
Write function to Nand flash. bit NandWrite(void) Parameters None Return values Bit type TRUE: FALSE: Global variables

Example

www.ali.com.tw

18

M5661 Firmware Programming Guide


See also

NandRead()
Read function from Nand flash. bit NandRead(void) Parameters None Return values Bit type TRUE: FALSE: Global variables gbSpecialRW: gdwStorLba: gbStorTransLen: gbStorPath: Example The sector number that will be read. Number of sectors will be read. The assigned area that data will be read to.

See also

NandFinishJob()

bit NandFinishJob(void) Parameters None Return values Bit type TRUE: FALSE: Global variables

Example

See also

www.ali.com.tw

19

M5661 Firmware Programming Guide NandStepJob()


Speed up function for playback. bit NandStepJob(void) Parameters None Return values Bit type TRUE: FALSE: Global variables

Example

See also

NandEraseBlock()
Erase one block. void NandEraseBlock(WORD wLogBlk) Parameters WORD wLogBlk Return values None Global variables

Example

See also

NandInitPre()
. void NandInitPre(void) Parameters None Return values None

www.ali.com.tw

20

M5661 Firmware Programming Guide


Global variables

Example

See also

NandReadCapa()
Handle UFI command. void NandReadCapa(void) Parameters None Return values None Global variables

Example

See also

PhyAccessNand_pm()

bit PhyAccessNand_pm(BYTE bType) Parameters BYTE bType Return values Bit type TRUE: FALSE: Global variables

Example

See also

www.ali.com.tw

21

M5661 Firmware Programming Guide PhyBlockEraseAll()

bit PhyBlockEraseAll(BYTE blevel) Parameters BYTE blevel Return values Bit type TRUE: FALSE: Global variables

Example

See also

ReadBadBlock ()
Physical Write Configure Data from HOST -> SRAM -> gwConfigBlock LBA 0~3: 0xD000 LBA 4~7: 0xD800 .... LBA 28~31: 0xD800 => BadBlockInfo => => Config BadBlockInfo

void PhyWriteConfig(void) Parameters None Return values None Global variables

Example

See also

ReadBadBlock()
Special ATAPI command: send bad block info to host. void ReadBadBlock(BYTE bType)

www.ali.com.tw

22

M5661 Firmware Programming Guide


Parameters BYTE bType Return values None Global variables

Example

See also

ReadDevice()

void ReadDevice(void) Parameters None Return values None Global variables

Example

See also

ReadSecurity()
Password locates in Configure Block 0, Lab 8. Every set contains 32-byte. bit ReadSecurity(BYTE n) Parameters BYTE n Return values Bit type TRUE: FALSE: Global variables

www.ali.com.tw

23

M5661 Firmware Programming Guide


Example

See also

UsbAccessDataSram()
Write data from USB to SRAM, or Read from SRAM to USB bit UsbAccessDataSram(WORD wRaAddr, WORD wLen, bit fWrite) Parameters wRaAddr: wLen: fWrite: DATA SRAM address. transfer len (unit is BYTE). TRUE FALSE Return values Bit type TRUE: FALSE: Global variables => => WRITE READ

Example

See also

WriteSecurity()
Password locates in Configure Block 0, Lab 8. Every set contains 32-byte. bit WriteSecurity(BYTE n) Parameters BYTE n Return values Bit type TRUE: FALSE: Global variables

www.ali.com.tw

24

M5661 Firmware Programming Guide


Example

See also

EraseNandBlock()
Erase block sequential. bit EraseNandBlock(WORD wStartBlk, BYTE bBlkLen) Parameters wStartBlk: Physical Block Address. bBlkLen: Len.

Return values Bit type TRUE: always TRUE. FALSE: Global variables

Example

See also

GetIniDefectBlock()

void GetIniDefectBlock(void) Parameters None Return values None Global variables

Example

See also

www.ali.com.tw

25

M5661 Firmware Programming Guide NandFormatCapa()


Handle UFI command. bit NandFormatCapa(XBYTE type) Parameters XBYTE type Return values Bit type TRUE: FALSE: Global variables

Example

See also

2.2.2

SYS Functions

www.ali.com.tw

26

M5661 Firmware Programming Guide 2.3 SD (SD.c) 2.3.1 API Functions

SD_Init_400K()
SD Initialization. bit SD_Init_400K(void) Parameters None Return values Bit type TRUE: FALSE: SD/MMC card was initialized successfully. SD/MMC card was not initialized successfully. (Include SD/MMC was not inserted) Global variables gfSDinit: gxbSd_cmd: gfMediumChange: Indicate that SD/MMC card had been initialized. The divisor to control the SD/MMC Clock (<400KHZ). Indicate that FW need to let Host know medium change. (Since SD insert and init OK). Example

See also

SD_Read()
Read data from SD. (data target: SRAM). bit SD_Read(void) Parameters None Return values Bit type TRUE: FALSE: All data transfer was completed. Error occurs.

Global variables gbStorTransLen: gbStorPath: gdwStorLba: The number of blocks to be transfer. The address of Target (in SRAM). The LBA of Source (in SD/MMC Card).

www.ali.com.tw

27

M5661 Firmware Programming Guide


gxbSD_Error: gxbSDCardType: gfR1Err: Example Error code. SD_MODE(SD),MMC_MODE(MMC). TRUE,R1 report error.

See also

SD_Write()
Write data to SD. (data source: SRAM). bit SD_Write(void) Parameters None Return values Bit type TRUE: FALSE: All data transfer was completed. Error occurs.

Global variables gbStorTransLen: gbStorPath: gdwStorLba: gxbSD_Error: gxbSDCardType: gfR1Err: Example The number of blocks to be transfer. The address of Target (in SRAM). The LBA of Source (in SD/MMC Card). Error code. SD_MODE(SD),MMC_MODE(MMC). TRUE,R1 report error.

See also

SD_Det()
Check whether SD/MMC card is inserted or not. bit SD_Det(void) Parameters None Return values Bit type TRUE SD/MMC card was installed.

www.ali.com.tw

28

M5661 Firmware Programming Guide


FALSE SD/MMC card was not installed. Global variables

Example

See also

CardDetach()
Detach SD/MMC card. void CardDetach(void) Parameters None Return values None Global variables

Example

See also

SDModeSense6Data()
ATAPI Function. (Send 8 bytes data to PC, including card's write-protected information.) When accepted Modesense6 CMD (opcode=0x1A). void SDModeSense6Data(void) Parameters None Return values None Global variables gxbSDCardType: gfSDWP: Example SD_MODE(SD),MMC_MODE(MMC). TRUE, the SD/MMC card is write-protected.

See also

www.ali.com.tw

29

M5661 Firmware Programming Guide SDReadCapa()


ATAPI Function. Send 8 bytes data to PC, including the number of blocks in card (4 bytes), the number of bytes in a block (4bytes). When accepted Read-Capacity CMD (opcode=0x25). void SDReadCapa(void) Parameters None Return values None Global variables gxdwSD_Blocknum: gxdwSD_Blocklen: Example The number of blocks in SD/MMC Card. The number of bytes in a block.

See also

SD_USBRead()
Read data from SD. (data Target: USB ) bit SD_USBRead(void) Parameters None Return values Bit type TRUE: FALSE: All data was transfer to USB. Error occurs.

Global variables gdwCBWDataTransferLength: gxdwLBA_address: gxdwSD_Blocknum: gxwSD_SecCnt: The number of bytes to be transfer. The LBA of Source (in SD/MMC Card).

The number of blocks in SD/MMC Card. Anytime the number of Blocks to be transferred ,when SD_USBRead() is called.

gxbSDCardType: gfSplitCommand:

SD_MODE(SD),MMC_MODE(MMC). TRUE, the number of Blocks to be transfer is more than 255.

gfR1Err: gxbSD_Error:

TRUE,R1 report error. Error code(the most significant nibble: SD CMD, the

www.ali.com.tw

30

M5661 Firmware Programming Guide


least significant nibble: error condition). Example

See also

SD_USBWrite()
Write data from SD. (data Target: USB) bit SD_USBWrite(void) Parameters None Return values Bit type TRUE: FALSE: All data was transfer to USB. Error occurs.

Global variables gdwCBWDataTransferLength: gxdwLBA_address: gxdwSD_Blocknum: gxwSD_SecCnt: The number of bytes to be transfer. The LBA of Source (in SD/MMC Card).

The number of blocks in SD/MMC Card. Anytime the number of Blocks to be transferred ,when SD_USBRead() is called.

gxbSDCardType: gfSplitCommand:

SD_MODE(SD),MMC_MODE(MMC). TRUE, the number of Blocks to be transfer is more than 255.

gfR1Err: gxbSD_Error:

TRUE,R1 report error. Error code(the most significant nibble: SD CMD, the least significant nibble: error condition).

Example

See also

2.3.2

SYS Functions

www.ali.com.tw

31

M5661 Firmware Programming Guide 2.4 Playback (Playback.c) 2.4.1 API Functions

DetermineDspClock()
Because DSP clock is determined by user setting, for example music type and so on, a function is created to handle it (according to global variable setting). void DetermineDspClock() Parameters None Return values None Global variables

Example

See also

PeFillDspBuf()
Try to fill DSP buffer. void PeFillDspBuf(void) Parameters None Return values None Global variables

Example

See also

PeInit( )
Playback initialization. This function initializes play engine. Call this function when player program starts. bit PeInit(void)

www.ali.com.tw

32

M5661 Firmware Programming Guide


Parameters None Return values Bit type TRUE: FALSE: Global variables

Example Please see PlayEngine( ) example. See also

PlayEngine( ) PeReptAdjust()
. WORD PeReptAdjust(void) Parameters None Return values WORD type Global variables

Example

See also

PeSetPlaybackRate()
. void PeSetPlaybackRate(BYTE bRate) Parameters BYTE bRate Return values None Global variables

Example

www.ali.com.tw

33

M5661 Firmware Programming Guide


See also

PeStart ( )
Start playback. bit PeStart(void) Parameters None Return values Bit type Global variables

Example

See also

PlayEngine( )
This function executes play command. bit PlayEngine(BYTE bCommand) Parameters BYTE bCommand Specify which command to execute. Commands could be following values: P_PLAYBACK Use this command to start playing back, or return from pause to playback mode. P_PAUSE Use this command to pause current playing job. P_PREV Use this command to switch to previous MP3 file for playing. P_NEXT Use this command to switch to next MP3 file for playing. P_FIRST Use this command to switch to first MP3 file for playing. P_LAST Use this command to switch to last MP3 file for playing. P_STOP

www.ali.com.tw

34

M5661 Firmware Programming Guide


Use this command to stop current playing job. P_RESTART Use this command to repeat playing same music file (single repeat mode). P_AB_REPT_START Use this command to inform playing engine the start point of AB-repeat segment. P_AB_REPT_END Use this command to inform playing engine the endpoint of AB-repeat segment. P_AB_REPT_RETURN_A Use this command to let playing engine jump to start point of AB-repeat segment. P_AB_REPT_RESET No action. P_NOP Use this command to drive playing engine to check output buffer status, and perform bit stream decoding. P_RND_NEXT This command let playing engine select next music file and standby. P_RND_FIRST This command let playing engine select first music file and standby. P_RND_START This command let playing engine start to play current selected file. Return values Bit type TRUE: Command executed OK. FALSE: Theres some error occurs during command execution. Global variables Omitted. Example

See also

2.4.2

SYS Functions

www.ali.com.tw

35

M5661 Firmware Programming Guide 2.5 Record (Record.c) 2.5.1 API Functions

ReInit( )
Initialize variables and settings for recording. Once the recording program is started, you should call this function to initialize the recording file pointer, recording settings and CODEC setting. bit ReInit(void) Parameters None Return values Bit type TRUE: Initialize successfully FALSE: Initialization failed Global variables Omitted. Example The following example shows how to start a recording task. if(ReInit()) { ReStart(); } See also ReStart( ) | ReEngine( )

ReStart( )
Start recording. This function will change system state to recording state. bit ReStart(void) Parameters None Return values Bit type TRUE: Start successfully. FALSE: Something error. Global variables Omitted. Example The following example shows how to start a recording task.

www.ali.com.tw

36

M5661 Firmware Programming Guide


if(ReInit()) { ReStart(); } See also ReInit( ) | ReEngine( )

RecEngine( )
Perform recording functions. bit RecEngine(BYTE bCommand) Parameters BYTE bCommand Specify which action to be performed. The command could be: R_NOP (value = 0x00)

This command will drive recording engine to detect input buffer status, perform encoding, and write encoded stream into storing media. R_REC (value = 0x01)

This command brings system state from pause to recording. R_PAUSE (value = 0x02)

This command brings system state from recording to pause. R_STOP (value = 0x03)

This command will terminate current recording job and finish the file. then brings system state to stop. Commands that not listed above will be discarded by recording engine. Return values Bit type TRUE: No error occurs. FALSE: Something error occurs. Global variables Omitted. Example

See also ReInit( ) | ReStart( )

FsRead()
Call storage read function. bit FsRead(DWORD dwStorLba, BYTE bStorLen, BYTE bStorPath)

www.ali.com.tw

37

M5661 Firmware Programming Guide


Parameters DWORD dwStorLba BYTE bStorLen BYTE bStorPath Return values Bit type TRUE: FALSE: Global variables gxbStorType: Example Read from which storage.

See also

UpdateRecSaveInf()
Write recording recover information (Update file sector). void UpdateRecSaveInf(void) Parameters None Return values None Global variables

Example

See also

2.5.2

SYS Functions

www.ali.com.tw

38

M5661 Firmware Programming Guide 2.6 ImaAdpcm (ImaAdpcm.c) 2.6.1 API Functions

ImaAdpcmEncInit( )
Initial buffer read/write pointer, and ADPCM encode engines state for ADPCM encode. void ImaAdpcmEncInit( ) Parameters None Return values None Global variables XBYTE gxbFsData XBYTE gxwOffsetDataSec Example

See also

ImaAdpcmEncode( )
Use ADPCM to encode a sample. void ImaAdpcmEncode(INT wInputSample) Parameters INT wInputSample Return values None Global variable

Example The following code uses ImaAdpcmEncode( ) to encode a block of PCM data. for ( i =0; i <BUFFER_SIZE; i ++) { ImaAdpcmEncode( PcmBuffer[i] ); } See also ImaAdpcmDecode()

ImaAdpcmDecode( )
Use ADPCM to decode a sample.

www.ali.com.tw

39

M5661 Firmware Programming Guide


void ImaAdpcmDecode(void) Parameters None Return values None Global variables

Example

See also ImaAdpcmEncode( )

CdcPlayIsr( )
Get two samples (left-channel and a dummy) from ADPCM buffer and push to CODEC. void CdcPlayIsr(void) Parameters None Return values None Global variable

Example The following example shows how to consecutively play ADPCM data. void ExtInt0(void) interrupt 0 using 1 { if(bIntFlag & DAC_FIFO_EMPTY) { if(PCM_EMPTY) { ImaAdpcmDecode( ); } CdcPlayIsr( ); // put two samples to DAC FIFO } } See also CdcRecIsr()

CdcRecIsr( )
Get two samples (left-channel and a dummy) from CODEC FIFO, and store it into buffer. void CdcRecIsr(void) Parameters None

www.ali.com.tw

40

M5661 Firmware Programming Guide


Return values None Global variables

Example The following example use CdcRecIsr() to record data from ADC to buffer. void ExtInt0(void) interrupt 0 using 1 { if(bIntFlag & ADC_FIFO_FULL) { CdcRecIsr( ); // get two samples from ADC FIFO } } See also CdcPlayIsr()

2.6.2

SYS Functions

www.ali.com.tw

41

M5661 Firmware Programming Guide 2.7 Key (Key.c) 2.7.1 API Functions

KeyInit( )
Initials variables and GPIO settings of Keys. void KeyInit(void) Parameters None Return values None Global variables gbKeyRept: gxbKeyId: Key pressed repeat counter. Keep the key status until be read.

gxbKeyLastId: The key ID for next time use. gfKeyPressed: Key pressed status flag. Example

See also

KeyDetect( )
Detect key(s) status. Use 3*3 matrix to detect keys. Output: GPIO_B_2, GPIO_B_3, GPIO_B_4. Input: GPIO_B_5, GPIO_B_6, GPIO_B_7. void KeyDetect(void) Parameters None Return values None Global variables gbKeyRept: gxbKeyId: Key pressed repeat counter. Keep the key status until be read.

gxbKeyLastId: The key ID for next time use. gfKeyPressed: Key pressed status flag. Example

www.ali.com.tw

42

M5661 Firmware Programming Guide


See also

2.7.2

SYS Functions

www.ali.com.tw

43

M5661 Firmware Programming Guide 2.8 FM (FmChip.c) 2.8.1 API Functions

FmCheckStereo()
Check Fm is stereo or mono. bit FmCheckStereo(void) Parameters None Return values Bit type TRUE: Stereo FALSE: Mono Global variables

Example

See also

FmDataInit()
Initials FM Module. void FmDataInit(void) Parameters None Return values None Global variables

Example

See also

FmInit() FmInit()
Initials FM Module. bit FmInit(void)

www.ali.com.tw

44

M5661 Firmware Programming Guide


Parameters None Return values None Global variables

Example

See also FmDataInit()

FmEnd()
Stop FM Module, sets IC mute and standby. void FmEnd(void) Parameters None Return values None Global variables

Example

See also

FmSearch()
Search Up/Down from currently frequency. BOOL FmSearch(BOOL fSearchUp) Parameters BOOL fSearchUp Return values Bit type Global variables 1: Up 0: Down

Example

www.ali.com.tw

45

M5661 Firmware Programming Guide


See also

FmSetFreq()
Set FM IC's PLL by "gxwFmFreq". bit FmSetFreq(void) Parameters None Return values Bit type TRUE: Set Freq successful.

FALSE: Busy time out or error. Global variables gxwFmFreq : FM frequency based on 100KHz. Example

See also

FmSetMute()
Sets FM in mute mode, this function will set Frequency too. If want to cancel mute, just call FmSetFreq(). void FmSetMute(void) Parameters None Return values None Global variables gxwFmFreq : FM frequency based on 100KHz. Example

See also

2.8.2

SYS Functions

www.ali.com.tw

46

M5661 Firmware Programming Guide 2.9 Base64 (Base64.c) 2.9.1 API Functions

MS_Base64D()

WORD MS_Base64D(BYTE *psrc, BYTE *pdes, WORD wLen, BYTE bWchar) Parameters BYTE *psrc WORD wLen BYTE bWchar Return values WORD type Global variables

Example

See also

2.9.2

SYS Functions

www.ali.com.tw

47

M5661 Firmware Programming Guide 2.10


Index FEFAh FF08h FF34h FF35h FFD0h FFD1h FFD2h

LCD (Lcd.c)
Mnemonic Name LDC_CLK_CTRL LCD Clock Control Register MODE SELECT2 Mode Select Register2 GPIOC_DAT GPIOC_DIR LCDCTRL LCD Control Register LCD_PAR_RDDAT LCD Parallel Read Data Register LCD_WRDAT LCD Write Data Register Type R/W R/W R/W R/W R/W R/W R/W Default 00h 00h 00h 00h 00h 00h 00h

LCD Clock Control/Division Registers (FEFAh)


FEFAh D7 D6 D5 LCD_CLK_CTRL LCD Clock Control Register D4 D3 D2 CLKEN D1 CLKSEL D0 Type R/W Default 00h

Reserved

SYS_DIV2 AUDIO_DI Reserved V2 SYS_CLK Divide 2 Enable

SYS_DIV2 1: Enable. 0: Disable. AUDIO_DIV2 1: Enable. 0: Disable.

AUDIO_CLK Divide 2 Enable

CLKEN LCD Clock Enable 1: LCD Clock Enable. 0: LCD Clock Disable. CLKSEL 00: 01: 10: 11: LCD Clock Source Select Source Clock = 6Mhz Source Clock = 3 MHz Source Clock = 1.5 MHz Source Clock = 0.75Mhz

MODE SELECT2 Mode Select Register 2 (FF08h)


FF08h D7
MCSJ

MODE_SEL2 Mode Select Register2 D6


N

D5
N

D4
I2CS_EN

D3
I2CM_EN

D2
I2S1_PIN_S EL

D1
I2S2_EN

D0
I2S1_EN

Type R/W

Default 00h

FORCE_RO LCD_SERE LCD_PARE

Bit 7: FORCE_ROMCSJ Bit 6: LCD_SEREN This bit is used to enable serial LCD controller and switch function onto GPIOC[7:4]. 1: Serial LCD interface Enable. 0: Serial LCD interface Disable. Bit 5: LCD_PAREN This bit is used to enable parallel LCD controller and switch control/data signals to GPIOC[7:4]/GPIOF[7:0]. 1: Parallel LCD interface Enable. 0: Parallel LCD interface Disable. Bit 4: I2CS_EN 1: I2C Slave Enable. 0: I2C Slave Disable. Bit 3: I2CM_EN

www.ali.com.tw

48

M5661 Firmware Programming Guide


1: I2C Matster Enable. 0: I2C Matster Disable. Bit 2: I2S1_PIN_SEL This bit is used to switch the I2S-1 function onto alternate pin. 1: Switch the pins of I2S1 to GPIOC[3:1] 0: Switch the pins of I2S1 to GPIOG[3:1] Bit 0: I2S2_EN I2S-2 Enable 1: I2S-2 Enable. 0: I2S-2 Disable. Bit 0: I2S1_EN I2S-1 Enable 1: I2S-1 Enable. 0: I2S-1 Disable.

GPIOC GPIOC FF35h)


FF34h D7 D6

Data Port and Direction Registers (FF34h

GPIOC_DAT GPIOC Data Port D5 D4 D3 D2 D1 D0 Type R/W Default 00h

GPIOC_DAT[7:0] FF35h D7 D6 D5 GPIOC_DIR GPIOC Direction Register D4 D3 D2 D1 D0

Type R/W

Default 00h

GPIOC_DIR[7:0] GPIOC_DAT[7:0] GPIOC Out/In Data Register GPIOC out/in data port, If GPIOC_DIR[n]=1, the corresponding GPIOC_DAT[n] will show on XGPIOC[n] pin. If GPIOC_DIR[n]=0, reading GPIOC_DAT[n] will get the status on XGPIOC[n] pin. GPIOC_DIR[7:0] GPIOC Direction Register This register specifies the direction of XGPIOC pins. 1: Output 0: Input

LCDCTRL LCD Control Register (FFD0h)


FFD0h D7 D6 D5 CS polarity Bit 7-6: Reserved Bit 5: CS_POR 0: Low active 1: High active Bit 4: DOE 0: disabling 1: enabling LCD Chip Select Polarity PARLCD D4 DOE Parallel LCD Control Register D2 WR D1 A0 D0 CS Type R/W Default 00h

D3 RD

LCD Parallel Data Output Enabling

Bit 3: RD LCD Parallel Read Signal This bit control GPIOC[7] when LCD_EN is enabling Bit 2: WR LCD Parallel Write Signal This bit control GPIOC[6] when LCD_EN is enabling Bit 1: A0 LCD Parallel A0 Signal This bit control GPIOC[5] when LCD_EN is enabling

www.ali.com.tw

49

M5661 Firmware Programming Guide


Bit 0: CS LCD Parallel A0 Signal This bit control GPIOC[4] when LCD_EN is enabling

LCD_PAR_RDDAT LCD Parallel Read Data Register (FFD1h)


FFD1h D7 D6 D5 PARLCD_RDAT Parallel LCD Read Data D4 D3 D2 D1 D0 Type R/W Default 00h

LCD_PAR_RDDAT[7:0]

Bit 7-0: LCD_PAR_RDDAT LCD Parallel Read Data The register reflects GPIOF[7:0] status when LCD_EN is enabling.

LCD_WRDAT LCD Write Data Register (FFD2h)


FFD2h D7 D6 LCD_WRDAT Parallel LCD Write Data/Serial LCD Data Register D5 D4 D3 D2 D1 D0 Type R/W Default 00h

LCD_WRDAT[7:0]

Bit 7-0: LCD_WRDAT LCD Parallel Mode Write Data In the parallel mode, MCU write this register to direct control LCD data signal GPIOF[7:0] In the serial mode, this register is used as LCD display data mapping port, whenever MCU write this register, LCD serial signals will be auto-generated on GPIOC[7:4]

2.10.1 API Functions

LcdInit( )
LCD initialization: set register, power on LCD and clear LCD memory data. bit LcdInit(none) Parameters None Return values Bit type TRUE: LCD initialed successfully. FALSE: LCD initialed time out. Global variable

Example

See also

LcdCtrlEn( )
Switch share bus for LCD control.

www.ali.com.tw

50

M5661 Firmware Programming Guide


Note: You should not call this function again when bus has shared for LCD. That would let system crashed. void LcdCtrlEn(void) Parameters None Return values None Global variable

Example

See also LcdCtrlDis()

LcdCtrlDis( )
Switch share bus for Nand Flash control. Note: You should not call this function again when bus has shared for LCD. That would let system crashed. void LcdCtrlDis(void) Parameters None Return values None Global variable

Example

See also LcdCtrlEn()

LcdSendCommand ( )
Send command to LCD. void LcdSendCommand(BYTE bCommandVal) Parameters BYTE bCommandVal Commands form DB7-DB0.

www.ali.com.tw

51

M5661 Firmware Programming Guide


Return values None Global variable

Example

See also

LcdWriteData( )
Write data to LCD. (show data) void LcdWriteData(BYTE bLcdData) Parameters BYTE bLcdData Display data. Return values None Global variable

Example

See also LcdReadData() | LcdGoto()

LcdReadData( )
Read data from LCD. Note: Before read data, you should read a dummy data first. BYTE LcdReadData (void) Parameters None Return values BYTE type LCD data Global variable

Example

www.ali.com.tw

52

M5661 Firmware Programming Guide


See also LcdWriteData() | LcdGoto()

LcdGoto( )
Set the LCD read/write position. void LcdGoto(BYTE bPage, BYTE bColumn) Parameters BYTE bPage Specifies the display page number. BYTE bColNum Specifies the display column number. Return values None Global variable

Example

See also LcdWriteData() | LcdReadData()

LcdBackLightControl( )
Control LCD backlight on/off void LcdBackLightControl(BYTE bSwitch) Parameters BYTE bSwitch LCD_BACKLIGHT_ON: Back Light ON. LCD_BACKLIGHT_OFF: Back Light OFF. Return values None Global variable

Example

See also

www.ali.com.tw

53

M5661 Firmware Programming Guide LcdClearAll( )


Clean LCD. void LcdClearAll (void) Parameters None Return values None Global variable

Example

See also LcdClearPage()

LcdClearBlock( )
Clean one block on LCD. void LcdClearBlock(BYTE bPage, BYTE bColNum, BYTE bHeight, BYTE bWidth) Parameters BYTE bPage Specifies the display page number. BYTE bColNum Specifies the display column number. BYTE bHeight Specifies the picture height. BYTE bWidth Specifies the picture width. Return values None Global variable

Example

See also LcdClearAll()

LcdScrollText( )
Scroll data on LCD.

www.ali.com.tw

54

M5661 Firmware Programming Guide


void LcdScrollText(BYTE bPage1, BYTE bColNum1, BYTE bPage2, BYTE bColNum2) Parameters BYTE bPage1 Specifies the scrolled page number of the left side. BYTE bColNum1 Specifies the scrolled column number of the top side. BYTE bPage2 Specifies the scrolled page number of the right side. BYTE bColNum2 Specifies the scrolled page number of the bottom side. Return values None Global variable

Example

See also

LcdCopyPage()
Copy a page data to another page. void LcdCopyPage(BYTE bPage1,BYTE bPage2) Parameters BYTE bPage1: BYTE bPage2: Return values None Example source page target page

See also

LcdReverse( )
Reverse a block on LCD. PS: If you want to reverse screen, just send LCD command "LCD_REVERSE_DISPLAY" void LcdReverse(BYTE bPage, BYTE bColNum, BYTE bHeight, BYTE bWidth)

www.ali.com.tw

55

M5661 Firmware Programming Guide


Parameters BYTE bPage Specifies the display page number. BYTE bColNum Specifies the display column number. BYTE bHeight Specifies the display height. BYTE bWidth Specifies the display width. Return values None Global variable

Example

See also

LcdWritePic( )
Write serial data to LCD void LcdWritePic(PBYTE pbDataSource, BYTE bPage, BYTE bColNum, BYTE bHeight, BYTE bWidth) Parameters BYTE pbDataSource Point to binary data. BYTE bPage Specifies the display page number. BYTE bColNum Specifies the display column number. BYTE bHeight Specifies the picture hight. BYTE bWidth Specifies the picture width. Return values None Global variable BYTE gxbLcdLimitCol The limit column number of the right side. Any data over the limit column would be

www.ali.com.tw

56

M5661 Firmware Programming Guide


skipped BYTE gxbLcdDispLimPix If some data have been skipped (over the limit column), how many pixels have been displayed.

Example

See also

LcdShowString( )
Show String on LCD. You should set the font size by LCD_SMALL_FONT_WIDTH and LCD_BIG_FONT_WIDTH BYTE LcdShowString(PBYTE pbShowStr, BYTE bPage, BYTE bColNum, BYTE bLen) Parameters BYTE pbShowStr Point to string array you want to show. BYTE bPage Specifies the display page number. BYTE bColNum Specifies the display column number. BYTE bLen Specifies the string length. Return values BYTE type: (Scroll function need that information). Next display string index (0 base and byte unit) EX. In standard SDK, if you want to show "ABCDE" in column 104, "ABC" will be shown, and "DE" will be skip (Over Lcd Screen). This function will return 3 (Point to D). If you show "ABCDE" in column 108, "AB" will be shown, Half of "C" will be shown, and "DE" will be skip. This function will return 2 (Point to C). If you show "ABCDE" in column 0, all string would be shown. This function will return 5 (Point over the string) Global variable BOOL gxfSourceUnicode: Specifies string type: STRING_TYPE_ASCII or STRING_TYPE_UNICODE Example The following example will show ABC string. gxfSourceUnicode=STRING_TYPE_ASCII BYTE bString[3]={A,B,C};

www.ali.com.tw

57

M5661 Firmware Programming Guide


LcdShowString(bString,0,0,3); See also LcdShowSysString()

LcdShowSysString( )
Show system string on LCD. This function will read a string form Nand Flash and then show it. BYTE LcdShowSysString(WORD wStrNum, BYTE bPage, BYTE bColNum) Parameters BYTE wStrNum The system string code number. It should be defined in SysStrDef.h BYTE bPage Specifies the display page number. BYTE bColNum Specifies the display column number. Return values The length of system string (pixel) Global variable

Example

See also LcdShowString()

LcdShowSysFont( )
Show System font on LCD. void LcdShowSysFont(PBYTE pbFontCode, BYTE bPage, BYTE bColNum, BYTE bLen) Parameters BYTE pbFontCode Display font code. It show be defined in SysFontDef.h by the AP LCD Bitmap Convert. BYTE bPage Specifies the display page number. BYTE bColNum Specifies the display column number. BYTE bLen Specifies the string length.

www.ali.com.tw

58

M5661 Firmware Programming Guide


Return values none Global variable

Example

See also

LcdShowTitleNum( )
Show 6x16 number on LCD (Only number and decimal). This function use the same font with system font, but 6x16 pixels, and this function is faster. (It use CBYTE data, and not load Nand Flash) void LcdShowTitleNum(WORD wShowNum, BYTE bPage, BYTE bColNum, BYTE bLen) Parameters BYTE wShowNum Display number BYTE bPage Specifies the display page number. BYTE bColNum Specifies the display column number. BYTE bLen Display length. For short number, this function would add zero, for long number this function would cut number. EX: wShowNum=23, bLen=3 will show 023 wShowNum=128, bLen=2 will show 28 Return values None Global variable

Example

See also

LcdCenterColumn( )
Get the string display column if you want it show in the center. This function should

www.ali.com.tw

59

M5661 Firmware Programming Guide


operate with LcdShowString() function. If you call LcdShowSysString, you just need to set column number as LCD_AUTO_CENTER_COL. BYTE LcdCenterColumn(BYTE bNum) Parameters BYTE bNum String length (pixel) Return values BYTE type The center column number Global variable

Example

See also LcdShowSysString() | LcdShowString()

LcdGetStrLen( )
Get string length (pixel). BYTE LcdGetStrLen(PBYTE pbString, BYTE bLen) Parameters BYTE pbString String buffer. BYTE bLen String Length (byte) Return values BYTE type: String Length (pixel) Global variable BOOL gxfSourceUnicode: Specifies string type: STRING_TYPE_ASCII or STRING_TYPE_UNICODE

Example

See also

www.ali.com.tw

60

M5661 Firmware Programming Guide LcdShowAnimation( )


Show one picture (for animation). Note: This function use pm107 data. Use 1 sector (512 bytes) per picture. void LcdShowAnimation(BYTE bPicNum, BYTE bPage, BYTE bColNum, BYTE bHeight, BYTE bWidth) Parameters BYTE bPicNum Specifies the picture number in pm107. BYTE bPage Specifies the display page number. BYTE bColNum Specifies the display column number. BYTE bHeight Specifies the picture hight. BYTE bWidth Specifies the picture width. Return values None Global variable

Example The following example will show 5 pictures. for(bI=0;bI<5;bI++) { for(wDelayTime=0;wDelayTime<0xFFFF;wDelayTime++) { }; LcdShowAnimation(bI,2,0,4,128) } See also

LcdShowTagTitle( )
Start to show Tag Title on LCD. If Tag Title not exists, it would show file name. Note: You should call this function first, and then call LcdScrollTag() to scroll it void LcdShowTagTitle(void) Parameters None Return values None

www.ali.com.tw

61

M5661 Firmware Programming Guide


Global variable XBYTE gxbMusicType Point out the music tag type XBYTE gxbLcdTagStatus Set the tag state flag bit 1-3: Which tag is shown LCD_TAG_TURN_DEFAULT: Default state, changing new song, or unknown tag state. LCD_TAG_TURN_FILEONLY: No tag, only show File name LCD_TAG_TURN_TITLE: Showing tag title LCD_TAG_TURN_ARTIST: Showing tag artist LCD_TAG_TURN_ALBUM: Showing tag album

Example

See also LcdScrollTag()

LcdScrollTag( )
Scroll Tag on LCD. You should call LcdShowTagTitle() first. void LcdScrollTag(void) Parameters None Return values None Global variable XBYTE gxbLcdTagStatus Set the tag state flag, see LcdShowTagTitle() function Example

See also LcdShowTagTitle()

www.ali.com.tw

62

M5661 Firmware Programming Guide LcdShowLyrics( )


Show new Lyrics. Note: You should call this function first, and then call LcdScrollLyrics() to scroll it. void LcdShowLyrics(void) Parameters None Return values None Global variable XBYTE gxbLcdLyricStatus Set lyric state. bit 1: Lyric scroll done flag LCD_LYRIC_SCROLL_DONE: Lyric scroll done. LCD_LYRIC_SCROLLING: Lyric scrolling. Example

See also LcdSetLyricDone() | LcdScrollLyric()

LcdScrollLyric( )
Scroll Lyrics on LCD. Note: You should call LcdShowLyrics() first. If gxbMusicType&M_LYRICS_FLAG is False, you should not call this function void LcdScrollLyric (void) Parameters None Return values None Global variable XBYTE gxbLcdLyricStatus Set lyric state, see LcdShowLyrics() function. Example

See also LcdShowLyrics() | LcdSetLyricDone()

www.ali.com.tw

63

M5661 Firmware Programming Guide LcdSetLyricDone( )


Sets Lyric state was done, when one line lyric display finish. void LcdSetLyricDone(void) Parameters None Return values None Global variable XBYTE gxbLcdLyricStatus Set lyric state done, see LcdShowLyrics() function. Example

See also LcdShowLyrics() | LcdScrollLyric()

LcdShowFileList()
Display a file name in file list. You should call this function before calling LcdScrollFileList(). void LcdShowFileList(PBYTE pbFileName, PBYTE pbLongFileName, BYTE bPage) Parameters PBYTE pbFileName: short filename buffer PBYTE pbLongFileName: Long filename buffer BYTE bPage: Specifies the display page number Return values None Global variable

Example

See also LcdScrollFileList() | LcdShowClassList()

LcdScrollFileList()
Scroll long file name in file list.

www.ali.com.tw

64

M5661 Firmware Programming Guide


void LcdScrollFileList(PBYTE pbFileName, BYTE bPage) Parameters PBYTE pbFileName: display long file name array. BYTE bPage: display LCD page. Return values None Global variable

Example

See also LcdShowFileList()

LcdShowClassList()
Display a file name in file list. You should call this function before calling LcdScrollFileList(). void LcdShowClassList(PBYTE pbClassName, BYTE bPage) Parameters PBYTE pbClassName: Display classification name array BYTE bPage Display LCD pafge Return values None Global variable

Example

See also LcdShowFileList()

LcdShowDirName()
Display dir-name. void LcdShowDirName(void)

www.ali.com.tw

65

M5661 Firmware Programming Guide


Parameters None Return values None Global variable

Example

See also

LcdShowSpectrum( )
Show Spectrum (only left-right channel volume). void LcdShowSpectrum(BYTE bDispType) Parameters BYTE bDispType: The display type of spectrum Return values None Global variable

Example

See also

LcdShowInitLowPower()
Show Low Power in init module. void LcdShowInitLowPower(void) Parameters None Return values None Global variable

Example

www.ali.com.tw

66

M5661 Firmware Programming Guide


See also

2.10.2 SYS Functions LcdReadStatus( )


Load LCD state. BYTE LcdReadStatus(void) Parameters None Return values byte type (LCD Status) Bit7 Bit6 Bit5 Bit4 Busy flag (1:busy 0:normal) ADC (1:normal direction 0:reverse direction) Display On/Off (1:Display Off 0:Display On) Restb (1:being reset 0:not reset)

Bit0-3 Don't care Example

See also LcdWaitBusy()

LcdWaitBusy( )
Wait while LCD is busy bit LcdWaitBusy(void) Parameters None Return values Bit type TRUE: Not busy FALSE: Time out for waiting Example

See also LcdReadStatus()

BYTE_DELAY( )
Add command delay time void BYTE_DELAY(BYTE bDelay) Parameters BYTE bDelay Delay time.

www.ali.com.tw

67

M5661 Firmware Programming Guide


Return values None Example

See also

LcdTurnTag( )
Switch Tag on LCD (Title->Artist->Album) void LcdTurnTag(void) Parameters None Return values None Example

See also

LcdCopyShortFileName()
Copy short file name to gxbLcdShowFileName buffer. This function will cut down space character (ASCII32) and add a point . character before sub filename. void LcdCopyShortFileName(PBYTE pbFileName) large Parameters PBYTE pbFileName: Filename buffer Return values None Example

See also LcdShowFileList()

www.ali.com.tw

68

M5661 Firmware Programming Guide 2.11 Oled (Oled.c)

2.11.1 API Functions

OledInit( )
Oled initialization: set register, power on LCD and clear LCD memory data. void OledInit(void) Parameters None Return values None Global variable

Example

See also

OledCtrlEn( )
Switch share bus for Oled control. Note: Before using OLED command,you must call OledCtrlEn(), and then call OledCtrlDis() after finish the sake of display. And another point, there are several Oled functions already accomolish this job. void LcdCtrlEn(void) Parameters None Return values None Global variable

Example

See also OledCtrlDis()

OledCtrlDis( )
Switch share bus for Nand Flash control.

www.ali.com.tw

69

M5661 Firmware Programming Guide


void LcdCtrlDis(void) Parameters None Return values None Global variable

Example

See also OledCtrlEn()

OLED_SET_CMD()
Set the operation mode in Command mode. Before read/write command to oled, call this macro to set the operation as command. OLED_SET_CMD() Parameters None Return values None Global variable

Example

See also OLED_SET_DAT(),OLED_SET_STS(),OLED_WRITE(bData), OLED_READ(bData).

OLED_SET_STS()
Before reading oled status, call this macro to set the operation as read status. OLED_SET_DAT() Parameters None Return values None Global variable

www.ali.com.tw

70

M5661 Firmware Programming Guide


Example

See also OLED_SET_DAT(),OLED_SET_STS(),OLED_WRITE(bData), OLED_READ(bData).

OLED_WRITE(bData)
Write command or data to OLED. Note: If the current operation mode is Command mode(OLED_SET_CMD()), this function writes command to OLED, else data. OLED_WRITE(bData) Parameters BYTE bData Write command or data to oled Return values None Global variable

Example OLED_SET_CMD() OLED_WRITE(cmd1) //write command cmd1 to oled OLED_WRITE(cmd2) //write command cmd2 to oled OLED_SET_DAT() OLED_WRITE(data1) //write command data1 to oled See also OLED_SET_DAT(),OLED_SET_STS(),OLED_WRITE(bData), OLED_READ(bData)

OLED_READ(bData)
Read status or data from OLED Note: Before reading data ,you must read a dummy data first. OLED_READ(bData) Parameters BYTE bData bData will be store data or status getting form OLED. Return values None Global variable

Example OLED_SET_DAT(); OLED_READ(bData); //dummy read

www.ali.com.tw

71

M5661 Firmware Programming Guide


OLED_READ(bData); //read 1 byte data from OLED OLED_SET_STS(); OLED_READ(bStatus); //read oled status See also OLED_SET_DAT(),OLED_SET_STS(),OLED_WRITE(bData), OLED_READ(bData)

OledDisplayPowerOn( )
Power on or power off Oled. void OledDisplayPowerOn(BOOL fPowerOn) Parameters BOOL fPowerOn TRUE: Oled display power on FLASE: Oled display power off Return values None Global variable

Example

See also

OledSetContrast()
Set oled contrast. Void OledSetContrast(BYTE bContrast) Parameters BYTE bContrast It can be set in the range of 0~255 Return values None Global variable

Example

See also BACKLIGHT_ON(),BACKLIGHT_OFF()

OledDisplayFade()
Display fade in or display fade out.

www.ali.com.tw

72

M5661 Firmware Programming Guide


void OledDisplayFade(BOOL fFadeIn,WORD wDelay) Parameters BOOL fFadeIn TRUE : Display fade in FALSE: Display fade out WORD wDelay Fade delay Return values None Global variable

Example

See also

BACKLIGHT_ON()
Set current contrast according to global variable gxbLcdContrast. BACKLIGHT_ON() Parameters None Return values None Global variable GxbLcdContrast Current contrast value. Example

See also BACKLIGHT_OFF(),OledSetContrast().

BACKLIGHT_OFF()
Set contrast 0 Note: This function just the macro of OledSetContrast(0) to simulate the backlight off for the sake of power save issue. BACKLIGHT_OFF()

www.ali.com.tw

73

M5661 Firmware Programming Guide


Parameters BYTE bPage Specifies the scrolled page number. Return values None Global variable None Example None See also BACKLIGHT_OFF(),OledSetContrast().

OledClearArea()
Clear the rectangular area display. void OledClearArea(BYTE bColStart, BYTE bRowStart, BYTE bWidth, BYTE bHeight) Parameters BYTE bColStart Specifies the start column of rectangular area. BYTE bRowStart Specifies the start row of rectangular area. BYTE bWidth Specifies the width of rectangular area. BYTE bHeight Specifies the height of rectangular area. Return values None Global variable None Example None See also OLED_CLEAR_ALL();

OLED_CLEAR_ALL()
Clear all area of display window OLED_CLEAR_ALL()

www.ali.com.tw

74

M5661 Firmware Programming Guide


Parameters None Return values None Global variable

Example

See also

OledCopyArea()
Copy rectangular area to another rectangular area. Note: Hardware acceleration command void OledCopyArea(BYTE bColStart, BYTE bRowStart, BYTE bWidth, BYTE bHeight, BYTE bColTarget, BYTE bRowTarget) ; Parameters BYTE bColStart Start column of the copied area. BYTE bRowStart Start row of the copied area. BYTE bWidth Width of the copied area. BYTE bHeight Height of the copied area. BYTE bColTarget Specifies start column of the target area. BYTE bRowTarget Specifies start row of the target area. Return values None Global variable None Example

See also

www.ali.com.tw

75

M5661 Firmware Programming Guide OledReverse ( )


Reverse color in specific rectangular area. void OledReverse(BYTE bColStart,BYTE bRowStart,BYTE bWidth,BYTE bHeight) Parameters BYTE bColStart Start column of the target area. BYTE bRowStart Start row of the target area. BYTE bWidth Width of the target area. BYTE bHeight Height of the target area. Return values None Global variable

Example

See also

OledDrawPoint ()
Draw a pixel. Note: If OLED_USE_MASK_DISPLAY has been defined and gfIconMaskEn is true, draw point with mask will be enable. Details will be described as following parameter. Void OledDrawPoint(BYTE bCol,BYTE bRow,WORD wColor); Parameters BYTE bCol Column of point. BYTE bRow Row of point. WORD wColor Point color. Return values none Global variable BYTE gxbMaskLeft

www.ali.com.tw

76

M5661 Firmware Programming Guide


BYTE GxbMaskRight BYTE GxbMaskTop BYTE GxbMaskBottom Above global variables are defined the mask window. BYTE gfMaskInside TRUE: mask inside FALSE: mask ouside Example

See also

OledDrawLine ()
Draw a line. Note: Hardware acceleration command void OledDrawLine(BYTE bColStart, BYTE bRowStart, BYTE ColEnd, BYTE bRowEnd) Parameters BYTE bColStart Start point column of this line. BYTE bRowStart Start point row of this line. BYTE ColEnd End point column of this line. BYTE bRowEnd End point row of this line. Return values None Global variable WORD gxwFGColor Color of line Example

See also OledDrawRect ();

OledDrawRect ()
Draw rectangle with foreground color

www.ali.com.tw

77

M5661 Firmware Programming Guide


void OledDrawRect(BYTE bColStart, BYTE bRowStart, BYTE bWidth, BYTE bHeight) Parameters BYTE bColStart BYTE bRowStart BYTE bWidth BYTE bHeight Above parameters determine a rantangle to draw. Return values

Global variable WORD gxwBGColor Background color, determine the rectangle filled color. WORD gxwFGColor Foreground color, determine the line color) BOOL gfTransparent TRUE: draw a rectangle filled with background color. FALSE: draw a rectangle without filling background color. Example None See also OledDrawLine ();

OledDrawDirection()
Change the graphic sram increased direction. Note: Write data to oled, the graphyic sram will be auto increased address. And increased direction is column first in default. Call this function could change increased direction. void OledDrawDirection(BYTE bAccessDir) Parameters BYTE bAccessDir OLED_RAM_ACCESS_MODE_COLUMN_FIRST: Increased direction is column first. OLED_RAM_ACCESS_MODE_ROW_FIRST: Increased direction is row first. Return values None Global variable None Example None

www.ali.com.tw

78

M5661 Firmware Programming Guide


See also

OledShowIconFromSram ()
Get the Icon data from sram and send it to OLED. void OledShowIconFromSram(WORD wSramAdd,BYTE bColStart,BYTE bRowStart,BYTE bWidth,BYTE bHeight); Parameters WORD wSramAdd Start sram address of data BYTE bColStart BYTE bRowStart BYTE bWidth BYTE bHeight Above parameters determine a drawing rectangle area. Return values

Global variable BOOL gfIconMaskEn TURE: Calls the OledDrawPoint() to accomplish this function. So, it has the effect of Mask,but slowly; (refer to OledDrawPoint()). FALSE: Uses the DMA to copy data from SRAM to OLED. So it more faster and efficient. Note: On another important point, be sure that SRAM address must be in the range of 0xc000~0xe000(8K) if using the DMA access, and data size(bWidth*bHeight*2) can not large then 2k bytes in once calling. BYTE gxbMaskLeft BYTE GxbMaskRight BYTE GxbMaskTop BYTE GxbMaskBottom Above global variables are defined the mask window. BYTE gfMaskInside TRUE: mask inside FALSE: mask ouside Example

See also OledShowIcon()

www.ali.com.tw

79

M5661 Firmware Programming Guide OledReadIconToSram()


Read the data form Oled display sram and store in specific MCU sram void OledReadIconToSram(WORD wSramAdd,BYTE bColStart,BYTE bRowStart,BYTE bWidth,BYTE bHeight); Parameters WORD wSramAdd Sram addres you want to store in. Note: This function uses DMA access, and be sure that SRAM address must be in the range of 0xc000~0xe000(8K), and data size(bWidth*bHeight*2) can not large then 2k in once calling. About the SRAM address, strongly recommand to use the 0xC800~0xCFFF PS. gxbLyrics[2048] _AT_ (SRAM_LYRICS_ADDR); //C800-CFFF

BYTE bColStart BYTE bRowStart BYTE bWidth BYTE bHeight The rectangular area you want to read. Return values None Global variable None Example None See also

OledDMASramToSM()
Send data from sram to smart media interface(Oled share this interface with nand flash) void OledDMASramToSM(WORD wDMASramAdd,WORD wDataSize); Parameters WORD wDMASramAdd Offset address of DMA start address. Note: DMA accessible sram is in the range of 0xc000~0xe000(8K), and this parameter is offset address of 0xc000. WORD wDataSize Send data size.

www.ali.com.tw

80

M5661 Firmware Programming Guide


Return values None Global variable None Example Send sram data 0xc800~0xc400(1K) to SM OledDMASramToSM(0xc800-0xc000,1024); See also

OledShowBitsIcon ( )
Display the 1bit bitmap icon to OLED. Note: This function often be used to display string. void OledShowBitsIcon(PBYTE pbDataSource,BYTE bColStart,BYTE bRowStart,BYTE bWidth,BYTE bPageHeight); Parameters PBYTE pbDataSource Pointer to bitmap data source BYTE bColStart BYTE bRowStart BYTE bWidth BYTE bPageHeight Above parameters specific a rectangular area be drawn. bPageHeight is in the unit of page(8 pixels) Return values None Global variable BOOL gfIconMaskEn TURE: Oled display mask will be enable if OLED_USE_MASK_DISPLAY defined and call the OledDrawPoint() to accomplish this function. So, it has the effect of Mask,but slowly; (refer to OledDrawPoint()). BYTE gxbMaskLeft BYTE GxbMaskRight BYTE GxbMaskTop BYTE GxbMaskBottom Above global variables are defined the mask window. BOOL gfTransparent TRUE: display the bitmap with background.

www.ali.com.tw

81

M5661 Firmware Programming Guide


FALSE:display the bitmap without background. BYTE gxbLcdLimitCol It dosent display if the display column large than gxbLcdLimitCol,please refer to example. WORD gxwFGColor Display foreground color WORD gxwBGColor Display background color BYTE gfMaskInside TRUE: mask inside FALSE: mask ouside Example Displaying a bitmap icon of 5 upon a image with background color. gfIconMaskEn=FALSE gfTransparent=FALSE; gxwFGColor = OLED_GREEN; gxwBGColor = OLED_RED; OledShowBitsIcon(BITMAP_ADDRESS,5,10,8,2); Displaying a bitmap icon of 5 upon a image without background color. gfIconMaskEn=FALSE; gfTransparent=TRUE; gxwFGColor = OLED_GREEN; gxwBGColor = OLED_RED; OledShowBitsIcon(BITMAP_ADDRESS,5,10,8,2); See also

OledShowIcon( )
Display high color Icon to Oled. Note: Icon data file (099Icon_BGR_v11.bin) will be download to device storage, and you could get the Icon storing information from "IconDefine.h". This header file define icon start Address and Icon width and Height info. etc... "IconGenerator.exe". converts BMP

Icon and generates the icon binary file compatible with our device required format. About the details that how to use the application,please refer to IconGenerator document. void OledShowIcon(WORD wIconIndex,BYTE bColStart,BYTE bRowStart); Paramete WORD wIconIndex Icon offset bytes(address) at the binary file. (All define in BYTE bColStart BYTE bRowStart Icon will be displayed start column and start row. "IconData.h")

www.ali.com.tw

82

M5661 Firmware Programming Guide


Return values None Global variable BOOL gfIconMaskEn TURE: Calls the OledDrawPoint() to accomplish this function. So, it has the effect of Mask,but slowly; (refer to OledDrawPoint()). FALSE: Uses the DMA to copy data from SRAM to OLED. So it more faster and efficient. Note that the icon information (width,height) will be got from binary files. so, don't not care about it. IconGenerator will automatically add the some information about bmp to binary file. BYTE gxbMaskLeft BYTE gxbMaskRight BYTE gxbMaskTop BYTE gxbMaskBottom Above global variables are defined the mask window. BYTE gfMaskInside TRUE: mask inside FALSE: mask ouside Example Show Icon with mask enable gfIconMaskEn=TRUE; gfMaskInside=TRUE; gxbMaskLeft=64; gxbMaskRight=96; gxbMaskTop=0; gxbMaskBottom=32; OledShowIcon(FULL_SCREEN_PIC,0,0); See also OledShowBitsIcon(),OledDMASramToSM()

OledShowNumber ( )
Display digit number. void OledShowNumber(WORD wShowNum,BYTE bColStart,BYTE bRowStart,BYTE bNumLen); Paramete WORD wShowNum Value you want to display. BYTE bColStart BYTE bRowStart Display column and row

www.ali.com.tw

83

M5661 Firmware Programming Guide


BYTE bNumLen Display length Return values None Global variable

Example Display number of 321 WORD wNumber=321; OledShowNumber(wNumber,0,0,5); It will display as result of 00321 See also

ShowProgress()
Display progress bar ShowProgress(BYTE bColStart,BYTE bRowStart,BYTE bValue) Paramete BYTE bColStart, BYTE bRowStart, Progress bar start column and start row postion BYTE bValue Value of progress in the range of 0~72(PROGRESS_MAX) Return values None Global variable

Example

See also

ShowAnimation ()
Display the animation void ShowAnimation(WORD wOffsetIndex,BYTE bFrameNum,BYTE bColStart,BYTE bRowStart,WORD wDelayTime) Paramete WORD wOffsetIndex Animation offset address

www.ali.com.tw

84

M5661 Firmware Programming Guide


Note: Animation binary data is stored in 107AnimBGR_v03.bin,and it will be download to our device as private area data.This function will get required data and imformation while playing animation. IconGenerator application also convert bmp to oled displaying format. BYTE bFrameNum Display frame number BYTE bColStart BYTE bRowStart Display start position WORD wDelayTime Display delay between every image frame Return values None Global variable

Example

www.ali.com.tw

85

M5661 Firmware Programming Guide 2.12 OledString (OledString.c)

StrShowString()
Show String on LCD. You should set the font size by LCD_SMALL_FONT_WIDTH and LCD_BIG_FONT_WIDTH BYTE StrShowString(PBYTE pbShowStr,BYTE bColStart,BYTE bRowStart,BYTE bStrLen); Parameters BYTE pbShowStr Point to string array you want to show. BYTE bColStart Specifies the display column number. BYTE bRowStart Specifies the display row number. BYTE bStrLen Specifies the string length. Return values BYTE type: (Scroll function need that information). Next display string index (0 base and byte unit) EX. In standard SDK, if you want to show "ABCDE" in column 104, "ABC" will be shown, and "DE" will be skip (Over Lcd Screen). This function will return 3 (Point to D). If you show "ABCDE" in column 108, "AB" will be shown, Half of "C" will be shown, and "DE" will be skip. This function will return 2 (Point to C). If you show "ABCDE" in column 0, all string would be shown. This function will return 5 (Point over the string) Global variable BOOL gxfSourceUnicode: Specifies string type: STRING_TYPE_ASCII or STRING_TYPE_UNICODE Example The following example will show ABC string. gxfSourceUnicode=STRING_TYPE_ASCII BYTE bString[3]={A,B,C}; StrShowString(bString,0,0,3); See also LcdShowString(), StrShowSysString()

StrShowSysString()
Show system string on LCD. This function will read a string form Nand Flash and then show it.

www.ali.com.tw

86

M5661 Firmware Programming Guide


BYTE StrShowSysString(WORD wStrNum,BYTE bColStart,BYTE bRowStart) large Parameters BYTE wStrNum The system string code number. It should be defined in SysStrDef.h BYTE bColStart Specifies the display column number. BYTE bRowStart Specifies the display row number. Return values The length of system string (pixel) Global variable

Example

See also StrShowSysString() , LcdShowString()

StrStrAnsiLen()
Get string length in pixel BYTE StrStrAnsiLen(PBYTE pbString,BYTE bLen) Parameters BYTE pbString String buffer. BYTE bLen String Length (byte) Return values BYTE type: String Length (pixel) Global variable BOOL gxfSourceUnicode: Specifies string type: STRING_TYPE_ASCII or STRING_TYPE_UNICODE

Example

See also LcdGetStrLen().

www.ali.com.tw

87

M5661 Firmware Programming Guide LcdShowTagTitle()


Start to show Tag Title on LCD. If Tag Title not exists, it would show file name. Note: You should call this function first, and then call LcdScrollTag() to scroll it void LcdShowTagTitle(void) Parameters None Return values None Global variable XBYTE gxbMusicType Point out the music tag type XBYTE gxbLcdTagStatus Set the tag state flag bit 1-3: Which tag is shown LCD_TAG_TURN_DEFAULT: Default state, changing new song, or unknown tag state. LCD_TAG_TURN_FILEONLY: No tag, only show File name LCD_TAG_TURN_TITLE: Showing tag title LCD_TAG_TURN_ARTIST: Showing tag artist LCD_TAG_TURN_ALBUM: Showing tag album Example

See also LcdScrollTag()

LcdScrollTag()
Scroll Tag on LCD. You should call LcdShowTagTitle() first. void LcdScrollTag(void) Parameters None Return values None

www.ali.com.tw

88

M5661 Firmware Programming Guide


Global variable XBYTE gxbLcdTagStatus Set the tag state flag, see LcdShowTagTitle() function Example

See also LcdShowTagTitle()

LcdShowLyrics()
Show new Lyrics. Note: You should call this function first, and then call LcdScrollLyrics() to scroll it. void LcdShowLyrics(void) Parameters None Return values None Global variable XBYTE gxbLcdLyricStatus Set lyric state. bit 1: Lyric scroll done flag LCD_LYRIC_SCROLL_DONE: Lyric scroll done. LCD_LYRIC_SCROLLING: Lyric scrolling. Example

See also LcdSetLyricDone() | LcdScrollLyric()

LcdScrollLyric()
Scroll Lyrics on LCD. Note: You should call LcdShowLyrics() first. If gxbMusicType&M_LYRICS_FLAG is False, you should not call this function void LcdScrollLyric (void) Parameters None

www.ali.com.tw

89

M5661 Firmware Programming Guide


Return values None Global variable XBYTE gxbLcdLyricStatus Set lyric state, see LcdShowLyrics() function. Example

See also LcdShowLyrics() | LcdSetLyricDone()

LcdSetLyricDone()
Sets Lyric state was done, when one line lyric display finish. void LcdSetLyricDone(void) Parameters None Return values None Global variable XBYTE gxbLcdLyricStatus Set lyric state done, see LcdShowLyrics() function. Example

See also LcdShowLyrics() | LcdScrollLyric()

LcdShowFileList()
Display a file name in file list. You should call this function before calling LcdScrollFileList(). void LcdShowFileList(PBYTE pbFileName, PBYTE pbLongFileName, BYTE bPage) Parameters PBYTE pbFileName: short filename buffer PBYTE pbLongFileName: Long filename buffer BYTE bPage: Specifies the display page number

www.ali.com.tw

90

M5661 Firmware Programming Guide


Return values None Global variable

Example

See also LcdScrollFileList() | LcdShowClassList()

LcdScrollFileList()
Scroll long file name in file list. void LcdScrollFileList(PBYTE pbFileName, BYTE bPage) Parameters PBYTE pbFileName: display long file name array. BYTE bPage: display LCD page. Return values None Global variable

Example

See also LcdShowFileList()

LcdShowClassList()
Display a file name in file list. You should call this function before calling LcdScrollFileList(). void LcdShowClassList(PBYTE pbClassName, BYTE bPage) Parameters PBYTE pbClassName: Display classification name array BYTE bPage Display LCD pafge Return values None

www.ali.com.tw

91

M5661 Firmware Programming Guide


Global variable

Example

See also LcdShowFileList()

LcdShowDirName()
Display dir-name. void LcdShowDirName(void) Parameters None Return values None Global variable

Example

See also

2.13

IDMA (Idma.c)

2.13.1 API Functions

IdmaPioPmW( )
Write date to DSP PM with IDMA PIO mode void IdmaPioPmW(void *pbSourceAddr, WORD wTargetAddr, WORD wLen) Parameters void *pbSourceAddr Source data address was in SRAM. WORD wTargetAddr Target data address in DSP-PM. WORD wLen Data Length. Its word unit, for example, if source data is 99 bytes, wLen=33. Return values None

www.ali.com.tw

92

M5661 Firmware Programming Guide


Global variable None Example

See also IdmaPioPmR() | IdmaPmW()

IdmaPioPmR( )
Reads date from DSP PM with IDMA PIO mode. Note: This function will just read 24bits data. If you use a double-word variable to get the value, you should clear the 8bits over data yourself. void IdmaPioPmR(WORD wSourceAddr, void *pbTargetAddr, WORD wLen) Parameters WORD wSourceAddr Source data address was in DSP-PM. void *pbTargetAddr Target data address in SRAM. WORD wLen Data Length. Its word unit, for example, if target data is 99 bytes, wLen=33. Return values None Global variable

Example

See also IdmaPioPmW()

IdmaPioDmyW( )
Write date to DSP DMY with IDMA PIO mode void IdmaPioDmyW(void *pbSourceAddr, WORD wTargetAddr, WORD wLen, BOOL fWidth24) Parameters void *pbSourceAddr Source data address was in SRAM. WORD wTargetAddr Target data address in DSP-DMY.

www.ali.com.tw

93

M5661 Firmware Programming Guide


WORD wLen Data Length. Its word unit, for example, if source data is 96 bytes: 24bits source data: wLen=32. 16bits source data: wLen=48. BOOL fWidth24 TRUE: 24bits source data. FALSE: 16bits source data. Note: In DSP 24bits mode this arguments would be ignore. Return values None Global variable

Example

See also IdmaPioDmyR() | IdmaDmyW()

IdmaPioDmyR( )
Read date from DSP DMY with IDMA PIO mode. Note: In DSP 24bits mode, this function will just read 24bits data. If you use a double-word variable to get the value, you should clear the 8bits over data yourself. void IdmaPioDmyR(WORD wSourceAddr, void *pbTargetAddr, WORD wLen, BOOL fWidth24) Parameters WORD wSourceAddr Source data address was in DSP-DMY. void *pbTargetAddr Target data address in SRAM. WORD wLen Data Length. Its word unit, for example, if source data is 96 bytes: 24bits source data: wLen=32. 16bits source data: wLen=48. BOOL fWidth24 TRUE: 24bits source data. FALSE: 16bits source data. Note: In DSP 16bits mode this arguments would be ignore. Return values None

www.ali.com.tw

94

M5661 Firmware Programming Guide


Global variable

Example

See also IdmaPioDmyW() | IdmaDmyR()

IdmaPioDmxW( )
Write date to DSP DMX with IDMA PIO mode. Note1: To write a word variable data, the result of this function is different with IdmaDmxW(). For example, we want to write data 00 01 02 03 (LH) to DSP DMX. H 03 02 01 L (DMX) 00

The first word data is 0x0100 for us. But 8051 word pointer will point to 01, low byte in SRAM. If you use word pointer write 0x0100, 0x0302, the data in SRAM is: H 02 03 00 L (SRAM) 01 (Word Pointer) L (DMX) 01

If you use pure IDMA sequence would write 01 00 03 02 (LH) to DSP DMX: H 02 03 00

To solve this problem, this function will reverse high-low byte data every 2 bytes. You can write word data to DMX by calling this function immediately and not need to reverse data. If you want to write serial byte data to DMX, this function would make error about sequence. Use IdmaDmxW() function instead of this function.

Note2: In DSP 24bits mode and set fWidth24=FALSE (16bits source data), the result of the function is different with IdmaDmxW(). For example, source data in SRAM is: H 03 02 H 03 02 function. The IdmaDmxPioW() function will write data to DMX (add zero value in high byte): H 00 03 02 00 01 L (DMX) 00 01 L (SRAM) 00 L (DMX) 00

The IdmaDmxW() function will write data to DMX (add zero value in low byte): 00 01 00

Its real to transfer 16bits data to 24bits. The zero value will auto drop by IdmaDmxR()

Its for writing 24bits data but small value. You can do the same job by setting fWidth24=TRUE and use a double-word variable. But its not effective because we will need two kinds of code to handle this and more variable size. The zero value will auto drop by IdmaPioDmxR() function. In most of application, we

www.ali.com.tw

95

M5661 Firmware Programming Guide


just need a word variable to read/write it.

void IdmaPioDmxW(void *pbSourceAddr, WORD wTargetAddr, WORD wLen, BOOL fWidth24) Parameters void *pbSourceAddr Source data address was in SRAM. WORD wTargetAddr Target data address in DSP-DMX. WORD wLen Data Length. Its word unit, for example, if source data is 96 bytes: 24bits source data: wLen=32. 16bits source data: wLen=48. BOOL fWidth24 TRUE: 24bits source data. FALSE: 16bits source data. Note: In DSP 16bits mode this arguments would be ignore. Return values None Global variable

Example

See also IdmaPioDmxR() | IdmaDmxW()

IdmaPioDmxR( )
Read date from DSP DMX with IDMA PIO mode Note1: In DSP 24bits mode, this function will just read 24bits data. If you use a double-word variable to get the value, you should clear the 8bits over data yourself.

Note2: To read a word variable data, the result of this function is different with IdmaDmxR(). For example, the data is 00 01 02 03 (LH) in DSP DMX. The first word data should be 0x0100 for us. H 03 02 H 03 02 01 L (DSP DMX) 00 L (SRAM) 00

If you use pure IDMA sequence to get data, it would be the same data with DMX. 01

www.ali.com.tw

96

M5661 Firmware Programming Guide


(Word Pointer) If you use 8051 word pointer to point first word, it will point to 00, low byte in SRAM. We will get the value 0x0001, not 0x0100. To solve this problem, this function will reverse high-low byte data every 2 bytes. You can read word data to DMX by calling this function immediately and not need to reverse data. If you want to read serial byte data to DMX, this function would make error about sequence. Use IdmaDmxR() function instead of this function.

Note3: In DSP 24bits mode and set fWidth24=FALSE (16bits source data), the result of the function is different with IdmaDmxR(). In application, we often use a small value in 24bits mode (although it still allocate 24bit space in DMX). For example, source data in DMX is: H 00 04 03 00 02 L (DMX) 01

Its correct to read it by setting fWidth24=TRUE and use a double-word variable. If we have known the highest byte is always zero, its not effective, because we will need two kinds of code to handle this and more variable size. This function will auto drop the highest byte when set fWidth24=FALSE in 24bit mode. In most of application, we just need a word variable to read/write it. The IdmaDmxR() function will auto drop the lowest byte when set fWidth24=FALSE in 24bit mode. Its real to transfer 24bits data to 16bits. For example, if source 16bits data in SRAM is: H 04 03 H 04 03 02 L (SRAM) 01 L (DMX) 00

The IdmaDmxW() function will write data to DMX (add zero value in low byte): 00 02 01

So the IsmaDmyR() function should drop the lowest byte zero value to get correct value. H 04 03 fWidth24) Parameters WORD wSourceAddr Source data address was in DSP-DMX. void *pbTargetAddr Target data address in SRAM. WORD wLen Data Length. Its word unit, for example, if source data is 96 bytes: 24bits source data: wLen=32. 16bits source data: wLen=48. 02 L (SRAM) 01

void IdmaPioDmxR(WORD wSourceAddr, void *pbTargetAddr, WORD wLen, BOOL

www.ali.com.tw

97

M5661 Firmware Programming Guide


BOOL fWidth24 TRUE: 24bits source data. FALSE: 16bits source data. Note: In DSP 16bits mode this arguments would be ignore. Return values None Global variable

Example

See also IdmaPioDmxW() | IdmaDmxR()

IdmaPmW( )
Write date to DSP PM with IDMA mode. This function will use IDMA bank0 to transfer data. Note: If wDSPAddr is odd, the 3 bytes of begining data would be drop by IDMA hardware. At this statue, wLen should be subtractive 1 word. void void IdmaPmW(WORD wDSPAddr, WORD wLen) Parameters WORD wDSPAddr Target data address in DSP-PM. WORD wLen Data Length. Its word unit, for example, if source data is 99 bytes, wLen=33. Return values None Global variable

Example

See also IdmaPioPmW()

IdmaDmyW( )
Write date to DSP DMY with IDMA mode. This function will use IDMA bank0 to transfer data. void void IdmaDmyW(WORD wDSPAddr, WORD wLen, BOOL fWidth24)

www.ali.com.tw

98

M5661 Firmware Programming Guide


Parameters WORD wDSPAddr Target data address in DSP-DMY. WORD wLen Data Length. Its word unit, for example, if source data is 96 bytes: 24bits source data: wLen=32. 16bits source data: wLen=48. BOOL fWidth24 TRUE: 24bits source data. FALSE: 16bits source data. Note: In DSP 16bits mode this arguments would be ignore. Return values None Global variable

Example

See also IdmaPioDmyW() | IdmaDmyR()

IdmaDmyR( )
Read date from DSP DMY with IDMA mode. This function will use IDMA bank0 to transfer data. Note: IDMA DMY Read always get 16bits data (It always drop the lowest byte data). If you want to read 24bits data, use IdmaPioDmyR() function instead of this function. void void IdmaDmyR(WORD wDSPAddr, WORD wLen) Parameters WORD wDSPAddr Target data address in DSP-DMY. WORD wLen Data Length. Its word unit, for example, if source data is 99 bytes, wLen=33. Return values None Global variable

Example

www.ali.com.tw

99

M5661 Firmware Programming Guide


See also IdmaPioDmyR() | IdmaDmyW()

IdmaDmxW( )
Write date to DSP DMX with IDMA mode. This function will use IDMA bank0 to transfer data. void void IdmaDmxW(WORD wDSPAddr, WORD wLen, BOOL fWidth24) Parameters WORD wDSPAddr Target data address in DSP-DMX. WORD wLen Data Length. Its word unit, for example, if source data is 96 bytes: 24bits source data: wLen=32. 16bits source data: wLen=48. BOOL fWidth24 TRUE: 24bits source data. FALSE: 16bits source data. Note: In DSP 16bits mode this arguments would be ignore. Return values None Global variable

Example

See also IdmaPioDmxW() | IdmaDmxR()

IdmaDmxR( )
Read date from DSP DMX with IDMA mode. This function will use IDMA bank0 to transfer data. Note: IDMA DMX always get 16bits data (If source data in DSP is 24 bits, it always drop the lowest byte data). If you want to read 24bits data, use IdmaPioDmxR() function instead of this function. void void IdmaDmxR(WORD wDSPAddr, WORD wLen) Parameters WORD wDSPAddr Target data address in DSP-DMX.

www.ali.com.tw

100

M5661 Firmware Programming Guide


WORD wLen Data Length. Its word unit, for example, if source data is 99 bytes, wLen=33. Return values None Global variable

Example

See also IdmaPioDmxR() | IdmaDmxW()

2.13.2 SYS Functions

IdmaPioDebugW( )
Write date to DSP DMX with IDMA PIO mode in DSP 24bits mode and use 16bits data source. The result of this function is the same with IdmaDmxW() function. In application, its useless for us. The function is only for debugging. void IdmaPioDebugW(void *pbSourceAddr, WORD wTargetAddr, WORD wLen) Parameters void *pbSourceAddr Source data address was in SRAM. WORD wTargetAddr Target data address in DSP-DMX. WORD wLen Data Length. Its word unit, for example, if source data is 96 bytes, wLen=48. Return values None Global variable

Example

See also IdmaPioDebugR()

IdmaPioDebugR( )
Read date from DSP DMX with IDMA PIO mode in DSP 24bits mode and use 16bits data source. The result of this function is the same IdmaDmxR() function. In application, its

www.ali.com.tw

101

M5661 Firmware Programming Guide


useless for us. The function is only for debugging. API void IdmaPioDebugR(WORD wSourceAddr, void *pbTargetAddr, WORD wLen) Parameters WORD wSourceAddr Source data address was in DSP-DMX. void pbTargetAddr Target data address in SRAM. WORD wLen Data Length. Its word unit, for example, if source data is 96 bytes, wLen=48. Return values None Global variable

Example

See also IdmaPioDebugW()

2.14

USB (Usb.c)

2.14.1 API Functions

CheckReceiveCBW()
Check CBW in EP0. void CheckReceiveCBW(void) Parameters None Return values None Global variable

Example

See also

www.ali.com.tw

102

M5661 Firmware Programming Guide GetPacketData()


Get descriptor packet data. BYTE GetPacketData(WORD wIndex) Parameters WORD wIndex Return values BYTE type Global variable

Example

See also

UsbDevice()
Main loop. void UsbDevice(void) Parameters None Return values None Global variable

Example

See also

UsbDeviceInit()
Initialization device. void UsbDeviceInit(void) Parameters None Return values None Global variable

www.ali.com.tw

103

M5661 Firmware Programming Guide

Example

See also

UsbSuspend_DPLL()
. void UsbSuspend_DPLL(void) Parameters None Return values None Global variable

Example

See also

UsbSuspend_WaitCmd()
. void UsbSuspend_WaitCmd(void) Parameters None Return values None Global variable

Example

See also

2.14.2 SYS Functions

www.ali.com.tw

104

M5661 Firmware Programming Guide

2.15

USBHost (USBHost.c)

2.15.1 API Functions

UmsRequestSense()
Send Inquiry command. void UmsRequestSense(void) Parameters None Return values None Global variable

Example

See also

www.ali.com.tw

105

M5661 Firmware Programming Guide UsbHostCopyRw()


Divide Read/Write operation into 3 phases. (Command, Data, Status.) bit UsbHostCopyRw(bit Readflag,BYTE bType) Parameters Bit Readflag BYTE bType Return values Bit type TRUE: FALSE: Global variable gdwStorLba: gbStorTransLen: gbStorPath: Example The sector number that will be read. Number of sectors will be read. The assigned area that data will be read to.

See also

UsbHostDetect()
Detect device Connect Function. bit UsbHostDetect(void) Parameters None Return values Bit type TRUE: FALSE: Global variable

Example

See also

UsbHostInit()
Initialization host.

www.ali.com.tw

106

M5661 Firmware Programming Guide


bit UsbHostInit(void) Parameters None Return values Bit type TRUE: FALSE: Global variable

Example

See also

UsbHostIsWriteProtect()
Determine Write Protect function. bit UsbHostIsWriteProtect(void) Parameters None Return values Bit type TRUE: FALSE: Global variable Write-Protect. Normal.

Example

See also

UsbHostRead()
Host read function. bit UsbHostRead(void) Parameters None Return values Bit type

www.ali.com.tw

107

M5661 Firmware Programming Guide


TRUE: FALSE: Global variable gdwStorLba: gbStorTransLen: gbStorPath: Example The sector number that will be read. Number of sectors will be read. The assigned area that data will be read to.

See also

UsbHostWrite()
Host writes function. bit UsbHostWrite(void) Parameters None Return values Bit type TRUE: FALSE: Global variable gdwStorLba: gbStorTransLen: gbStorPath: Example The sector number that will be read. Number of sectors will be read. The assigned area that data will be read to.

See also

www.ali.com.tw

108

M5661 Firmware Programming Guide

2.16

USB Host Common (USBHostCommon.c)

2.16.1 API Functions

HostDelay()
Delay loop time. void HostDelay(WORD DelayTime) Parameters WORD DelayTime Return values None Global variable

Example

See also

UsbHostNormalCheck()

bit UsbHostNormalCheck(void)

www.ali.com.tw

109

M5661 Firmware Programming Guide


Parameters None Return values Bit type TRUE: FALSE: Global variable

Example

See also

UsbHostPowerOff()
Host was power off. bit UsbHostPowerOff(void) Parameters None Return values Bit type TRUE: FALSE: Global variable

Example

See also

UsbHostPowerOn()
Host was power on. bit UsbHostPowerOn(void) Parameters None Return values Bit type TRUE:

www.ali.com.tw

110

M5661 Firmware Programming Guide


FALSE: Global variable

Example

See also

2.17

USB Host Fat (USBHostFat.c)

2.17.1 API Functions

CntFreeCluster()
Count free clusters of current partition, and set First Free cluster. DWORD CntFreeCluster(BYTE DiskIndex) Parameters BYTE DiskIndex Return values DWORD type Free cluster number, if -1 failure. Global variable

Example

See also

www.ali.com.tw

111

M5661 Firmware Programming Guide FatAnalyseDisk()


Analyses partition information on a disk. BYTE FatAnalyseDisk(BYTE DiskIndex) Parameters BYTE DiskIndex Decide USB disk or IDE disk. Return values BYTE type Global variable

Example

See also

FatChangePartition()
Change to the Nth partition, get the essence information. BYTE FatChangePartition(BYTE DiskIndex, BYTE ParIndex) Parameters BYTE DiskIndex Disk type should be checked. Its value should be one of SOURCE_DEV or TARGET_DEV. BYTE ParIndex Partition index. Its' value should less than the partition number. Return values BYTE type TRUE if success, and FALSE for failure Global variable

Example

See also

FATCheckExistFile()
Check whether the file exists in the dir given by g_UIDesEntry. DWORD FATCheckExistFile(void)

www.ali.com.tw

112

M5661 Firmware Programming Guide


Parameters None Return values DWORD type If the file exists, it's offset will be returned else 1 will be returned. If error occurs, it will return -1 Global variable

Example

See also

FATCreateDir()
Create a dir in the folder represented by g_UIDesEntry. bit FATCreateDir(void) Parameters None Return values Bit type TRUE: FALSE: Global variable

Example

See also

FATDeleteAll()
Deletes the whole partition, it can be used as format. BYTE FATDeleteAll(BYTE DiskIndex) Parameters BYTE DiskIndex Return values BYTE type True if succeed, otherwise False.

www.ali.com.tw

113

M5661 Firmware Programming Guide


Global variable

Example

See also

FATDirCopy()
Copies one dir to the other one, it's a reentrant function. BYTE FATDirCopy(P_FILE_ENTRY pSrcEntry,P_FILE_ENTRY pDesEntry,BYTE Mode) Parameters IN P_FILE_ENTRY pSrcEntry: the src dir entry. IN P_FILE_ENTRY pDesEntry: the des dir entry. IN BYTE Mode: there are four modes: 1,Duplicating the whole dir (WHOLE_DIR|NEW_ENTRY)

2,Copy the whole dir to a certain dir (WHOLE_DIR|EXIST_ENTRY) 3,Duplicating files and subfolders (CONTENT_ONLY|NEW_ENTRY) 4,Copy files and subfolders to a certain dir(CONTENT_ONLY|EXISR_ENTRY) Return values BYTE type True if succeed, otherwise False. Global variable

Example

See also

FATDirDelete()
Delete dir(s), it's a reentrant function. BYTE FATDirDelete(BYTE DiskIndex,P_FILE_ENTRY pFileEntry,BYTE Mode) Parameters BYTE DiskIndex: P_FILE_ENTRY pFileEntry: the dir file entry BYTE Mode: there are two delete modes: 1, Delete the dir given by pFileEntry(DEL_THE_DIR)

www.ali.com.tw

114

M5661 Firmware Programming Guide


2, Delete the dir given by pFileEntry and all those after it. (DEL_ALL_DIR) Return values BYTE type True if succeed, otherwise False. Global variable

Example

See also

FATFileCopy()
Copy one fat file. BYTE FATFileCopy(P_FILE_ENTRY pSrcEntry,P_FILE_ENTRY pDesEntry) Parameters P_FILE_ENTRY pSrcEntry: Source file entry. IN P_FILE_ENTRY pDesEntry: Destination file entry. Return values BYTE type True if succeed, otherwise False. Global variable

Example

See also

FATFileEntryCopy()
Copy the source entry to the destination one. BYTE FATFileEntryCopy(P_FILE_ENTRY pSrcEntry,P_FILE_ENTRY pDesEntry) Parameters P_FILE_ENTRY pSrcEntry: source entry. P_FILE_ENTRY pDesEntry: destination entry. Return values BYTE type True if succeed, otherwise False.

www.ali.com.tw

115

M5661 Firmware Programming Guide


Global variable

Example

See also

GetFirstClusterInChain()
Find the first cluster of the dir entry. DWORD GetFirstClusterInChain(BYTE DiskIndex,P_FILE_ENTRY pFileEntry) Parameters BYTE DiskIndex: disk type. P_FILE_ENTRY pFileEntry: the destination dir to which the cluster chain attached. Return values BYTE type True if succeed, otherwise False. Global variable

Example

See also

GetNextEntryOffset()
Get the next valid file entry. DWORD GetNextEntryOffset(BYTE DiskIndex, P_FILE_ENTRY pFileEntry,BYTE fBackward,BYTE fExcluded) Parameters BYTE DiskIndex: USB or ATA disk P_FILE_ENTRY pFileEntry: The current file entry, it's not necessary a valid one. BYTE fBackward: 1 if search backwards, else search forwards. BYTE fExcluded: 1 mean search the next valid entry, skip the current one; 0 was search a valid entry from the current position. Return values DWORD type The last offset if success and -1 if failure, -2 if it reaches the end.

www.ali.com.tw

116

M5661 Firmware Programming Guide


Global variable

Example

See also

ReadSectorOfFileEntry()
Read the sector of the file entry to buffer and return the sector number. bit ReadSectorOfFileEntry(BYTE DiskIndex, P_FILE_ENTRY pFileEntry, DWORD CurClu) Parameters BYTE DiskIndex: USB disk or IDE disk. P_FILE_ENTRY pFileEntry: The current file entry, it's must be a valid one. DWORD CurClu: The cluster where the entry stores, if we don't know the cluster number would be set zero. Return values BYTE type TRUE was success, and FALSE for failure. Global variable

Example

See also

UIClearSelectBuff()
Clear the UIbuffer with 0xff. void UIClearSelectBuff(void) Parameters None Return values None Global variable

Example

www.ali.com.tw

117

M5661 Firmware Programming Guide


See also

UIDeleteAll()
Delete all the files on the partition. BYTE UIDeleteAll(BYTE DiskIndex) Parameters BYTE DiskIndex Return values BYTE type True was success else FALSE. Global variable

Example

See also

UIDeleteSelected()
Delete selected files. BYTE UIDeleteSelected(BYTE DiskIndex) Parameters BYTE DiskIndex: Decide USB disk or IDE disk Return values BYTE type True was success else FALSE. Global variable

Example

See also

UIDiskInit()
Initialization disk. BYTE UIDiskInit(BYTE DiskIndex)

www.ali.com.tw

118

M5661 Firmware Programming Guide


Parameters BYTE DiskIndex: Return values BYTE type 0: failure, otherwise: number of logical partition. Global variable

Example

See also

UIEnter()
Enter a dir represented by g_UICurEntry. BYTE UIEnter(BYTE DiskIndex) Parameters BYTE DiskIndex: SOURCE_DEV or TARGET_DEV. Return values BYTE type True if succeed, otherwise False. Global variable

Example

See also

UIEscape()
Go to the parent dir. BYTE UIEscape(BYTE DiskIndex) Parameters BYTE DiskIndex Decide USB disk or IDE disk. Return values BYTE type TRUE was success, else FALSE. If reach end, it returns 2.

www.ali.com.tw

119

M5661 Firmware Programming Guide


Global variable

Example

See also

UIGetDiskInfo()
Get partition count of the disk. BYTE UIGetDiskInfo(BYTE DiskIndex) Parameters BYTE DiskIndex: Decide USB disk or IDE disk. Return values BYTE type The count of partition a disk. Global variable

Example

See also

UIGetFileInformation()
Get the file information. DWORD UIGetFileInformation(BYTE DiskIndex,BYTE Attr) Parameters BYTE DiskIndex: SOURCE_DEV or TARGET_DEV. BYTE Attr: The kind of information we need. Return values DWORD type -1 if Failure, otherwise return specific disk information. Global variable

www.ali.com.tw

120

M5661 Firmware Programming Guide


Example

See also

UIGetSelectFileSize()
Get selected files' total size by sector. DWORD UIGetSelectFileSize(void) Parameters None Return values DWORD type Selected files size. (Unit is sector). Global variable

Example

See also

UIIsSelect()
Judge if the file or dir is selected. BYTE UIIsSelect(BYTE DiskIndex) Parameters BYTE DiskIndex: USB disk or IDE disk Return values BYTE type: True if selected else FALSE. Global variable

Example

See also

www.ali.com.tw

121

M5661 Firmware Programming Guide UINext()


Get the next dir or file. When reach end, the offset won't change. BYTE UINext(BYTE DiskIndex) Parameters BYTE DiskIndex: SOURCE_DEV or TARGET_DEV. Return values BYTE type: TRUE was success, else FALSE. If reach end, it returns 2. Global variable

Example

See also

UIPrevious()
Get the previous dir or file. When reach the head, the offset won't change. BYTE UIPrevious(BYTE DiskIndex) Parameters BYTE DiskIndex: SOURCE_DEV or TARGET_DEV. Return values BYTE type: TRUE was success, else FALSE. If reach end, it returns 2. Global variable

Example

See also

UISelect()
Select a file, put it into the UIBuffer. If already in buffer, unselect it. BYTE UISelect(BYTE DiskIndex) Parameters BYTE DiskIndex:

www.ali.com.tw

122

M5661 Firmware Programming Guide


Return values BYTE type: True was success else FALSE. Global variable

Example

See also

UISetDefaultDir()
Set to the default dir when a disk is chosen. BYTE UISetDefaultDir(BYTE DiskIndex) Parameters BYTE DiskIndex: Decide USB disk or IDE disk. Return values BYTE type: True was success otherwise False. Global variable

Example

See also

UITop()
Go to the top of the current dir. BYTE UITop(BYTE DiskIndex) Parameters BYTE DiskIndex: SOURCE_DEV or TARGET_DEV Return values BYTE type: TRUE was success else FALSE. Global variable

www.ali.com.tw

123

M5661 Firmware Programming Guide


Example

See also

www.ali.com.tw

124

M5661 Firmware Programming Guide 2.18 ATA (Ata.c)

2.18.1 API Functions

DoAtaCommand()

void DoAtaCommand(void) Parameters None Return values None Global variable

Example

See also

SpecialAtapiHandle()
Handle special ATAPI command. This command will update the content of serial-interface memory. bit SpecialAtapiHandle(void) Parameters None Return values Bit type TRUE: FALSE: Global variable

Example

See also

2.18.2 SYS Functions

www.ali.com.tw

125

M5661 Firmware Programming Guide 2.19 Common (Common.c)

2.19.1 API Functions

BattCheck()
Check Battery. BYTE BattCheck(void) Parameters None Return values BYTE type Global variable

Example

See also

ConvertStorLba()
. DWORD ConvertStorLba(void) Parameters None Return values DWORD type Global variable

Example

See also

DisableTimer1()
Disable timer 1 interrupt. void DisableTimer1(void) Parameters None

www.ali.com.tw

126

M5661 Firmware Programming Guide


Return values None Global variable

Example

See also

EnableTimer0()
Enable Timer 0 interrupt. void EnableTimer0(void) Parameters None Return values None Global variable

Example

See also

EnableTimer1()
Enable Timer 1 interrupt. void EnableTimer1(WORD wWatchTimer) Parameters WORD wWatchTimer Return values None Global variable

Example

See also

www.ali.com.tw

127

M5661 Firmware Programming Guide FileTypeCheck()


Compare file name and file type. bit FileTypeCheck(PBYTE pbFileName) Parameters PBYTE pbfileName Return values Bit type TRUE: File name match file type.

FALSE: File name not match file type. Global variable

Example

See also

GetExtTime2Counter()
Get external timer2 counter. void GetExtTime2Counter(void) Parameters None Return values None Global variable

Example

See also

LoadExtendMemCode()
. void LoadExtendMemCode(void) Parameters None Return values None

www.ali.com.tw

128

M5661 Firmware Programming Guide


Global variable

Example

See also

LoadProgram()
Load assigned Program Module. void LoadProgram(WORD wIndex, BYTE bCodePart) Parameters WORD wIndex: Load Which PM. "1": Extend Code only. "2": Basic Code only. Others: Whole Code. Return values None Global variable gxwProgramIndex: Load which PM, and keep data in external memory. Example

See also

LoadRecInfo()
. void LoadRecInfo(void) Parameters None Return values None Global variable

Example

www.ali.com.tw

129

M5661 Firmware Programming Guide


See also

LoadStringTableIndex()
Load string table index. void LoadStringTableIndex(void) Parameters None Return values None Global variable

Example

See also

LoadTransTableIndex()
Load transfer table index. void LoadTransTableIndex(void) Parameters None Return values None Global variable

Example

See also

NandPrivateDis()
Nand private disable. void NandPrivateDis(void) Parameters None

www.ali.com.tw

130

M5661 Firmware Programming Guide


Return values None Global variable

Example

See also

NandPrivateEn()
Nand private enable. void NandPrivateEn(void) Parameters None Return values None Global variable

Example

See also

NandReadPhySec()
. bit NandReadPhySec(wPhysec, bLength, wSramAddr) Parameters wPhysec bLength wSramAddr Return values Bit type TRUE: FALSE: Global variable

www.ali.com.tw

131

M5661 Firmware Programming Guide


Example

See also

ReadSClockFromSram()
Get secure clock offset from DCV SRAM. void ReadSClockFromSram(void) Parameters None Return values None Global variable

Example

See also

ReadSettingData()
Read setting data from Nand Flash private area. void ReadSettingData(BYTE bStorPath) Parameters bStorPath: DMA path Return values None Global variable

Example

See also

ReCheckStorage()
Check storage again. bit ReCheckStorage(BYTE bStorage)

www.ali.com.tw

132

M5661 Firmware Programming Guide


Parameters BYTE bStorage Return values Bit type TURE: FALSE: Global variable

Example

See also

RestoreSramData()
Restore SRAM data from Nand Flash setting data. Note: You should read and check Nand Flash setting data ready first. void RestoreSramData(void) Parameters None Return values None Global variable

Example

See also

SetPowerOff()
Turn off power. void SetPowerOff(void) Parameters None Return values None Global variable

www.ali.com.tw

133

M5661 Firmware Programming Guide


Example

See also

SetSettingToVariable()
Set setting from FsData[] to variable. void SetSettingToVariable(void) Parameters None Return values None Global variable

Example

See also

SettingCheck()
Check setting data in Nand Flash private area has written correctly last time. bit SettingCheck(void) Parameters None Return values Bit type TRUE: FALSE: Global variable

Example

See also

SramCheck()
Check backup SRAM if data has written correctly last time.

www.ali.com.tw

134

M5661 Firmware Programming Guide


bit SramCheck(void) Parameters None Return values Bit type TRUE: FALSE: data ready. data not ready.

Global variable

Example

See also

SramRead()
Read data from backup SRAM. void SramRead(BYTE bAddr, void *pbData) Parameters BYTE bAddr: The address of SRAM will be read. Void *pbData: Point to a variable that the data value of SRAM will be read. Return values None Global variable

Example

See also

SramWrite()
Write data for backup SRAM. void SramWrite(BYTE bAddr, void *pbData) Parameters BYTE bAddr: The address of SRAM that will be write.

www.ali.com.tw

135

M5661 Firmware Programming Guide


Void *pbData: Point to a variable that the data value of variable will be writes. Return values None Global variable

Example

See also

StrComp()
Compare two strings. bit StrComp(PBYTE pbString1, PBYTE pbString2, BYTE xbLength ) Parameters PBYTE pbString1: string 1. PBYTE pbString2: string 2. BYTE xbLength: number of letters will be compared. Return values Bit type TRUE: The same. FALSE: Not same. Global variable

Example

See also

SystemPowerOff()
System turns off power. void SystemPowerOff(void) Parameters None Return values None

www.ali.com.tw

136

M5661 Firmware Programming Guide


Global variable

Example

See also

SystemPowerOn()
System turns on power. void SystemPowerOn(void) Parameters None Return values None Global variable

Example

See also

VbusCheck()
Check Vbus status. bit VbusCheck(void) Parameters None Return values Bit type TRUE: FALSE: Global variable

Example

See also

www.ali.com.tw

137

M5661 Firmware Programming Guide WriteSClockToSram()


Get secure clock offset from DCV SRAM. void WriteSClockToSram(void) Parameters None Return values None Global variable

Example

See also

2.19.2 SYS Functions

www.ali.com.tw

138

M5661 Firmware Programming Guide 2.20 DDM (DDM.c)

2.20.1 API Functions

DynamicDownloadManager()
Dynamics Download program from Nand Flash to SRAM. void DynamicDownloadManager(void) Parameters None Return values None Global variable gxwAddrPMI: Number of sector the program module index. gwProgramIndex: Number of Program module. Set the variable before enter this function. Example

See also

NandReadPhySecFunc()
Read physical page(s) to SRAM (program ram). void NandReadPhySecFunc(void) Parameters None Return values None Global variable gfLargeBlock: gf16bit: gfAddress4Cycle: Example Nand flash type variable. Nand flash type variable. Nand flash type variable.

See also

www.ali.com.tw

139

M5661 Firmware Programming Guide 2.20.2 SYS Functions

2.21

Drm (Drm.c)

2.21.1 API Functions

DrmGetDeviceCertificate()

void DrmGetDeviceCertificate(void) Parameters None Return values None Global variable

Example

See also

DrmGetLicenseStat()

void DrmGetLicenseStat(void) Parameters None Return values None Global variable

Example

See also

DrmGetSecureClock()

www.ali.com.tw

140

M5661 Firmware Programming Guide


void DrmGetSecureClock(void) Parameters None Return values None Global variable

Example

See also

DrmGetSecureTimeChallenge()

void DrmGetSecureTimeChallenge(void) Parameters None Return values None Global variable

Example

See also

DrmGetSyncList()

void DrmGetSyncList(void) Parameters None Return values None Global variable

Example

www.ali.com.tw

141

M5661 Firmware Programming Guide


See also

DrmSetLicenseResponse()

void DrmSetLicenseResponse(void) Parameters None Return values None Global variable

Example

See also

DrmSetSecureTimeResponse()

void DrmSetSecureTimeResponse(void) Parameters None Return values None Global variable

Example

See also

TurnTextTime()

void TurnTextTime(DWORD *dwSetTime) Parameters DWORD *dwSetTime

www.ali.com.tw

142

M5661 Firmware Programming Guide


Return values None Global variable

Example

See also

TurnTimeText()

void TurnTimeText(DWORD dwGetTime) Parameters DWORD dwGetTime Return values None Global variable

Example

See also

2.21.2 SYS Functions

www.ali.com.tw

143

M5661 Firmware Programming Guide 2.22 IntCodec (IntCodec.c)

2.22.1 API Functions

IntCdcAdcGain()

void IntCdcAdcGain(BYTE bPsetVal) Parameters BYTE bPsetVal Return values None Global variable

Example

See also

IntCdcCtrl()

void IntCdcCtrl(BYTE bCommand) Parameters BYTE bCommand Return values None Global variable

Example

See also

IntCdcGetAdcGain()

BYTE IntCdcGetAdcGain(void) Parameters None

www.ali.com.tw

144

M5661 Firmware Programming Guide


Return values Byte type Global variable

Example

See also

IntCdcPowerDownPa()

void IntCdcPowerDownPa(void) Parameters None Return values None Global variable

Example

See also

IntCdcRStringPowerOn()

void IntCdcRStringPowerOn(void) Parameters None Return values None Global variable

Example

See also

www.ali.com.tw

145

M5661 Firmware Programming Guide IntCdcSetPaGain()

void IntCdcSetPaGain(BYTE bVol) Parameters Byte bVol Return values None Global variable

Example

See also

IntCdcSetPaGainTask()

void IntCdcSetPaGainTask(bit fImmediatelySet) Parameters bit fImmediatelySet Return values None Global variable

Example

See also

IntCdcSetSampleRate()

void IntCdcSetSampleRate(void) Parameters None Return values None Global variable

www.ali.com.tw

146

M5661 Firmware Programming Guide


Example

See also

2.22.2 SYS Functions

www.ali.com.tw

147

M5661 Firmware Programming Guide 2.23 ExtCodec (ExtCodec.c)

2.23.1 API Functions

ExtCdcCtrl()

void ExtCdcCtrl(BYTE bCommand) Parameters BYTE bCommand Return values None Global variable

Example

See also

ExtCdcSetSampleRate()

void ExtCdcSetSampleRate(void) Parameters None Return values None Global variable

Example

See also

2.23.2 SYS Functions

www.ali.com.tw

148

M5661 Firmware Programming Guide 2.24 Mtp (Mtp.c)

2.24.1 API Functions

CardDetect()

void CardDetect(void) Parameters None Return values None Global variable

Example

See also

FillMemory()

void FillMemory(IN PBYTE pbBuf, IN WORD wBufLen, IN BYTE bFilledVal) Parameters PBYTE pbBuf WORD wBufLen BYTE bFilledVal Return values None Global variable

Example

See also

MemoryCopy()

void MemoryCopy(IN PBYTE pbTargetBuf, IN PBYTE pbSourceBuf, IN WORD wCpyLen)

www.ali.com.tw

149

M5661 Firmware Programming Guide


Parameters PBYTE pbTargetBuf PBYTE pbSourceBuf WORD wCpyLen Return values None Global variable

Example

See also

MtpDeviceInit()

void MtpDeviceInit(void) Parameters None Return values None Global variable

Example

See also

MtpFinishJob()

void MtpFinishJob(void) Parameters None Return values None Global variable

www.ali.com.tw

150

M5661 Firmware Programming Guide


Example

See also

MtpProcess()
Process function for MTP protocol. void MtpProcess(void) Parameters None Return values None Global variable

Example

See also

SaveFsInfo()

void SaveFsInfo(OUT FS_INF_DATA* pFs) Parameters OUT FS_INF_DATA* pFs Return values None Global variable

Example

See also

SendMtpDataBlock()
Send MTP Data Block to Host. void SendMtpDataBlock(PBYTE pBuf, DWORD dwLen)

www.ali.com.tw

151

M5661 Firmware Programming Guide


Parameters PBYTE pBuf: The pointer of DataBuf. DWORD wLen: DataBuf Length in Bytes. Return values None Global variable

Example

See also

2.24.2 SYS Functions

www.ali.com.tw

152

M5661 Firmware Programming Guide 2.25 SaveSetting (SaveSetting.c)

2.25.1 API Functions

RestoreDefaultSetting()
Restore default setting from Nand Flash private area. void RestoreDefaultSetting(void) Parameters None Return values None Global variable

Example

See also

2.25.2 SYS Functions

www.ali.com.tw

153

M5661 Firmware Programming Guide 2.26 UI Common (UiCommon.c)

2.26.1 Registers
DCV_INT_FLAG INT0 Flag Register (FF1Ah) FF1Ah D7 D6 D5 D4 INT0_FLAG INT0 Flag Register D3 D2 D1 D0 Type R/W Default 00h

PASCPPR_I PASCPPL_I PASCPNR_I PASCPNL_I DCV_RTC_I DCV_BAT_ DCV_BRN_ ALARM_INT NT NT NT BRN_DET DET NT NT

Bit 7: PASCPPR_INT Bit 6: PASCPPL_INT Bit 5: PASCPNR_INT Bit 4: PASCPNL_INT Bit 3: ALARM_INT Bit 2: DCV_RTC_INT Bit 1: DCV_BAT_BRN_DET Bit 0: DCV_BRN_DET

PASCPPR Interrupt Flag PASCPPL Interrupt Flag PASCPNR Interrupt Flag PASCPNL Interrupt Flag ALARM Interrupt Flag DCV-RTC Interrupt Flag DCV Battery Brown Out Detect Interrupt Flag DCV Brown Out Detect Interrupt Flag

DCV_ADDR DCV Address Register (FFD4h) FFD4h D7 D6 D5 D4 DCV_ADDR DCV Address Register D3 D2 D1 D0 Type R/W Default 00h

DCV_ADDR

Bits 7-0: DCV Address Register DCV_WRDATA DCV Write Data Register (FFD5h) FFD5h D7 D6 D5 DCV_WRDATA DCV Write Data Register D4 D3 D2 D1 D0 Type R/W Default 00h

DCV_WRDATA[7:0] Bits 7-0: DCV Write Data Register DCV_RDDATA DCV Read Data Register (FFD6h) FFD6h D7 D6 D5 DCV_RDDATA DCV Read Data Register D4 D3 D2 D1 D0

Type R/W

Default 00h

DCV_RDDATA[7:0] Bits 7-0: DCV Read Data Register DC-DC Registers

www.ali.com.tw

154

M5661 Firmware Programming Guide


Index 15h 16h 17h 18h 19h 1Ah 1Bh 1Ch Mnemonic Name RTC Timer/Counter Register 0 RTC Timer/Counter Register 1 RTC Timer/Counter Register 2 RTC Timer/Counter Register 3 Alarm Register 0 Alarm Register 1 Alarm Register 2 Alarm Register 3 Type R/W R/W R/W R/W R/W R/W R/W R/W Default 00h 00h 00h 00h 00h 00h 00h 00h

RTC Timer/Counter Register 0 15h Bit 7 Bit 6 Bit 5 RTC0 The First Byte of the 32-bit RTC Register Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Type R/W Default 00h

RTC[7:0]

Bit 7~0: RTC[7:0] register.

A write access the RTC counter register, while a read access the RTC timer

RTC Timer/Counter Register 1 16h Bit 7 Bit 6 Bit 5 RTC1 The Second Byte of the 32-bit RTC Register Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Type R/W Default 00h

RTC[15:8]

Bit 7~0: RTC[15:8] register.

A write access the RTC counter register, while a read access the RTC timer

RTC Timer/Counter Register 2 17h Bit 7 Bit 6 Bit 5 RTC2 The Third Byte of the 32-bit RTC Register Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Type R/W Default 00h

RTC[23:16]

Bit 7~0: RTC[23:16] register.

A write access the RTC counter register, while a read access the RTC timer

RTC Timer/Counter Register 3 18h Bit 7 Bit 6 Bit 5 RTC3 The Fourth Byte of the 32-bit RTC Register Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Type R/W Default 00h

RTC[31:24]

Bit 7~0: RTC[31:24] register.

A write access the RTC counter register, while a read access the RTC timer

www.ali.com.tw

155

M5661 Firmware Programming Guide


Alarm Register 0 19h Bit 7 Bit 6 Bit 5 ALARM0 The First Byte of the 32-bit Alarm Register Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Type R/W Default 00h

ALARM0[7:0]

Bit 7~0: ALARM0[7:0] Set alarm register Alarm Register 1 1Ah Bit 7 Bit 6 Bit 5 ALARM1 The Second Byte of the 32-bit Alarm Register Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Type R/W Default 00h

ALARM0[15:8]

Bit 7~0: ALARM1[15:8] Alarm Register 2 1Bh Bit 7 Bit 6

Set alarm register

ALARM2 The Third Byte of the 32-bit Alarm Register Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Type R/W Default 00h

ALARM0[23:16]

Bit 7~0: ALARM2[23:16] Alarm Register 3 1Ch Bit 7 Bit 6

Set alarm register

ALARM3 The Fourth Byte of the 32-bit Alarm Register Bit 5 Bit 4 Bit 3 Bit 2 Bit 1 Bit 0 Type R/W Default 00h

ALARM0[31:24]

Bit 7~0: ALARM2[23:16]

Set alarm register

2.26.2 API Functions

SettingForIceStart( )
Init and set default value in ICE mode. It is because real system running in normal mode will change program module, and running in ICE mode is one program module you download only. void SettingForIceStart(void ) Parameters None Return values None

www.ali.com.tw

156

M5661 Firmware Programming Guide


Global variable Many variables be assigned value, see source code for details.

SystemOff( )
Let system power off (Display power off and save setting etc). void SystemOff(void ) Parameters None Return values None Global variable

UiShowLowPower( )
When low battery, show message and power down. void UiShowLowPower(void ) Parameters None Return values None Global variable

Example

See also UiShowBattSts()

UiShowAutoPowerOff( )
When auto power off time up, let LCD display flash. void UiShowAutoPowerOff(void ) Parameters None Return values None Global variable XBYTE gxbDisplayCounter Display flash delay time.

www.ali.com.tw

157

M5661 Firmware Programming Guide


XBYTE gxbFlashTime Control for display 8 times See also UiNormalCheck()

UiShowStorageSts( )
If use the external card (such as SD card), show a card icon. void UiShowStorageSts(void ) Parameters None Return values None Global variable

UiCheckIniErr( )
Check Init Error and display it. void UiCheckIniErr( ) Parameters None Return values None Global variable XBYTE gxbLastErrCode Initial module should set the error code in this variable.

SaveSetting( )
Save settings and states in RTC SRAM. void SaveSetting( ) Parameters None Return values None Global variable

www.ali.com.tw

158

M5661 Firmware Programming Guide UiShowAlarmPic( )


If alarm switch turned on, show an alarm icon. void UiShowAlarmPic( ) Parameters None Return values None Global variable

UiCheckCardRemoved( )
Check SD card, if card removed, change to Nand Flash. This function will swap to system module to show message and change media if SD card removed, then change back to original module. void UiCheckCardRemoved(void ) Parameters None Return values None Global variable

See also UiNormalCheck()

UiNormalCheck( )
Check system state. (VBus, KeyHold, Battery, Alarm, SD card...) void UiNormalCheck(void ) Parameters None Return values None Global variable

See also UiShowAutoPowerOff() | UiShowBattSts() | UiCheckCardRemoved() | UiShowKeyHold

www.ali.com.tw

159

M5661 Firmware Programming Guide UiCheckBackLight( )


Check and control backlight turn on/off. For code size, this function will check Power Off, too. Note: This function must to be called after you get a key value. void UiCheckBackLight(BYTE bKey) Parameters BYTE bKey User input key value. Return values None Global variable

UiGoMainMenu( )
Go into main menu state, and display main menu. void UiGoMainMenu(void ) Parameters None Return values None Global variable

UiFixAlarmTime( )
When user edit time or alarm up, alarm may illegal, so need to call this function to fix alarm to today. You should set gxdwAlarmTime before you call this function. void UiFixAlarmTime( ) Parameters None Return values None Global variable XDWORD gxdwAlarmTime Fixed alarm time. Example

www.ali.com.tw

160

M5661 Firmware Programming Guide


See also UiSysGetAlarmTime() | UiSysSetAlarmTime()

UiSysGetAlarmTime( )
Get DCV alarm time. void UiSysGetAlarmTime( ) Parameters None Return values None Global variable XDWORD gxdwAlarmTime Alarm time Example

See also UiSysFixAlarmTime() | UiSysSetAlarmTime()

UiSysSetAlarmTime( )
Set DCV alarm time. (This function will call UiFixAlarmTime() to fix alarm time first) void UiSysSetAlarmTime( ) Parameters None Return values None Global variable XDWORD gxdwAlarmTime Alarm time. Example

See also UiSysFixAlarmTime() | UiSysGetAlarmTime()

UiSysGetNowTimeText( )
Transfer time counter number to global string array gxbStringEditTime. void UiSysGetNowTimeText(DWORD dwGetTime)

www.ali.com.tw

161

M5661 Firmware Programming Guide


Parameters DWORD dwGetTime Number of Time counter. Return values None Global variable XDWORD gxbStringEditTime Time String. Example

See also

UiShowKeyHold( )
If key hold, show a key hold icon on screen. void UiShowKeyHold() Parameters None Return values None Global variable

Example

See also UiNormalCheck()

UiGoVolMenu( )
Go to volume control state. void UiGoVolMenu() Parameters None Return values None Global variable

www.ali.com.tw

162

M5661 Firmware Programming Guide


Example

See also

UiDrawSubMenu( )
Show sub menu. void UiDrawSubMenu(BYTE bMarkNum, WORD wTitleStr, BYTE bTitleLen) Parameters BYTE bMarkNum Display icon number. WORD wTitleStr. Display title string BYTE bTitleLen Display title string length. Return values None Global variable

Example

See also UiShowSubMenuNum()

UiShowSubMenuNum( )
Show sub menu number. void UiShowSubMenuNum(BYTE bCurrentNum, BYTE bTotalNum) Parameters BYTE bCurrentNum Number of Current menu item. BYTE bTotalNum Number of Total menu item. Return values None Global variable None

www.ali.com.tw

163

M5661 Firmware Programming Guide


Example

See also UiDrawSubMenu()

UiShowRecFile( )
Show playback DVR mode file name (8.1 short name). void UiShowRecFile() Parameters None Return values None Global variable

Example

See also

UiShowUdefEqVal( )
Show the user defines EQ value. void UiShowUdefEqVal(BYTE bSelNum, BYTE bEqVal) Parameters BYTE bSelNum Musical scale (0-5) BYTE bEqVal Equalizer level (0-15) Return values None Global variable

Example The following example will show total user define EQ value. for(bI=0;bI<=5;bI++) UiShowUdefEqVal(bI,gxbUserDefEq[bI]); See also UiEditUDefEq() | UiShowUDefEqSel() | UiClearUDefEqSel() | UiDrawUserDefEq

www.ali.com.tw

164

M5661 Firmware Programming Guide UiEditUdefEq( )


Edit the user define EQ value. void UiEditUdefEq(BYTE bEditOption) Parameters BYTE bEditOption UI_EDIT_EQ_UP: Normal scale EQ volume up. UI_EDIT_EQ_DOWN: Normal scale EQ volume down. UI_EDIT_ALL_EQ_UP: All scale EQ volume up. UI_EDIT_ALL_EQ_DOWN: All scale EQ volume down. Return values None Global variable XBYTE gxbSelUserDefEq User selects which scale number. Example

See also UiShowUdefEqVal | UiShowUDefEqSel() | UiClearUDefEqSel() | UiDrawUserDefEq

UiShowUDefEqSel( )
Show a selected frame when selects another user define EQ musical scale. void UiShowUDefEqSel() Parameters None Return values None Global variable XBYTE gxbSelUserDefEq User selects which scale number. Example

See also UiShowUdefEqVal | UiEditUDefEq() | UiClearUDefEqSel() | UiDrawUserDefEq

UiClearUDefEqSel( )
Clear a selected frame that user select user define EQ musical scale. UiShowUDefEqSel() function didnt clear the selected frame because it didnt remember

www.ali.com.tw

165

M5661 Firmware Programming Guide


user select which scale. Main program should call this function first. void UiClearUDefEqSel() Parameters None Return values None Global variable XBYTE gxbSelUserDefEq User selects which scale number Example

See also UiShowUdefEqVal | UiEditUDefEq() | UiShowUDefEqSel() | UiDrawUserDefEq

UiDrawUserDefEq( )
Display user defines EQ edit. void UiDrawUserDefEq() Parameters None Return values None Global variable

Example

See also UiShowUdefEqVal | UiEditUDefEq() | UiShowUDefEqSel() | UiClearUDefEqSel()

UiGoRecQtyMenu( )
Go to record quality menu state. void UiGoRecQtyMenu() Parameters None Return values None Global variable

www.ali.com.tw

166

M5661 Firmware Programming Guide


Example

See also

UiGoRecMenuFrom( )
In record menu, go to record source menu state. void UiGoRecMenuFrom() Parameters None Return values None Global variable

Example

See also

UiGoRecFromMenu( )
Go to record source menu state. void UiGoRecFromMenu() Parameters None Return values None Global variable

Example

See also

UiGoRecMenuQty( )
In record menu, go to record source menu state. void UiGoRecMenuQty()

www.ali.com.tw

167

M5661 Firmware Programming Guide


Parameters None Return values None Global variable

Example

See also

UiSaveScreen( )
Save LCD data to memory. Note: buffer size should be more than 1024 bytes. void UiSaveScreen(PBYTE pbBuffer) Parameters PBYTE pbBuffer Point to memory buffer. Return values None Global variable

Example

See also UiLoadScreen()

UiLoadScreen( )
Restore LCD data from memory. void UiLoadScreen(PBYTE pbBuffer) Parameters PBYTE pbBuffer Point to memory buffer Return values None Global variable

www.ali.com.tw

168

M5661 Firmware Programming Guide


Example

See also UiSaveScreen()

www.ali.com.tw

169

M5661 Firmware Programming Guide 2.27 UI Play (UiPlay.c)

2.27.1 Simple Architecture

UI Play Play Module Initial

Super Loop

Common State Job

Error Handle

Base on State and User Input Control Job

2.27.2 System State UI should response base on system state. For example, when system state is in playing state and user input Key 2, UI should send P_PAUSE command to play engine, not P_PLAYBACK command. You can get the system state by reading gxbSysState variable. 2.27.3 Menu State UI should response base on menu state. For example, when EQ menu is appeared and user input Key 2, UI should set the EQ value, not send any command to play engine. You can get the menu state by reading gxbUiMenuMainStates and gxbUiMenuSubStates variable. gxbUiMenuMainStates means which kind menu it entered. gxbUiMenuSubStates means which item user selected. For example, when user enter EQ menu and select POP, gxbUiMenuMainStates is
www.ali.com.tw

170

M5661 Firmware Programming Guide UI_EQ_MENU and gxbUiMenuSubStates is UI_EQ_POP_MENU. 2.27.4 A-B Repeat State

AB_REPT_RESET

AB_REPT_END

AB_REPT_START

UI should set gxbAbRepeatSts variable to handle the A-B repeat state. The state is: AB_REPT_RESET: Default state. User didnt set A-B repeat or has canceled A-B repeat. AB_REPT_START: User has set A-B repeat start point. AB_REPT_END: Use has set A-B repeat end point. After setting A-B repeat state, UI should send A-B repeat command to play engine. For more detail, see section Play Engine Command below. 2.27.5 Random Play List UI should handle random play list. That is, UI should decide which music would be played in random mode. Use below function to get a random number: UiRndPlayInit( ): This function will get a random seed from RTC timer and the current file number. UI should call this function when random play mode starts. UiGetRndPlayNum( ): This function will return a random number. Parameters fGetNext means to get the next random number or previous random number. For example, if the random play list is 325 and we are playing the second music. Call this function and set fGetNext = UI_RND_PLAY_NEXT will get the random number 5, set fGetNext = UI_RND_PLAY_PREV will get the random number 3. Parameters: bit fGetNext UI_RND_PLAY_NEXT: Get next random number UI_RND_PLAY_PREV Get previous random number

After getting a random number, UI should send random play command to play engine. For more detail, see section Play Engine Command below.

www.ali.com.tw

171

M5661 Firmware Programming Guide 2.27.6 UiDispCtrl function UI would call some service function. When these service function cause some events, for example, play engine ready to start playing, UI might need to display or control something at this time. The service function would call back UiDispCtrl() function and let UI to do his job at this time. Parameters: BYTE bStatus The service function set the event in the variable. These are useful event for UI: UI_PE_INIT_END Play engine initial has finished. UI_PE_START_START Play engine is preparing to start to play a song. UI_PE_START_END Play engine is ready to start to play a song. UI_PE_PLAY_UPDATE Play engine has updated the music information. (Ex. Playing time) UI_PE_STOP Play engine has stopped. UI_PE_PAUSE Play engine has paused. UI_PE_RETURN_PLAY Play engine has continued to play music. UI_SCROLL_DISPLAY UI call itself event. UI could scroll tag or lyric at this time. 2.27.7 Music Tag Display UI should call LcdShowTagTitle() function first, and then call LcdScrollTag() function if tag exist. For more detail, see LcdShowTagTitle() and LcdScrollTag() function. 2.27.8 Lyric Display UI should handshake with play engine and Lcd function to display lyric. You can get the play engines lyric state by reading gxbLrcState variable. The useful meaning of value for UI is:
LRC_STS_DISP_STR: Play engine has completed get a lyric and its time to show the lyric. UI should display a new lyric now. www.ali.com.tw

172

M5661 Firmware Programming Guide


LRC_STS_FORCE_DISP_STR: Next lyric will come soon. UI should speed up scrolling lyric for showing next lyric.

You can get the Lcd lyric state by reading gxbLcdLyricStatus variable. The useful meaning of value for UI is: gxbLcdLyricStatus
bit 1: Lyric scroll done flag. UI can read this bit to know the scroll state. If UI need to force finish a lyric, call LcdSetLyricDone() function to set this bit. LCD_LYRIC_SCROLL_DONE: Lyric scroll done. LCD_LYRIC_SCROLLING: Lyric scrolling. bit 4-7: Subtitle state. UI can read these bits to know lyric state. NO_SUBTITLE: Default status, not load lyric yet or no lyric SHORT_SUBTITLE: Short lyric less than 16 words LONG_SUBTITLE: Long lyric more than 16 words

For more detail, see LcdShowLyrics(), LcdScrollLyric, PeLyrics() function in section Lcd (Lcd.c) above. 2.27.9 User Define EQ You can enable user define EQ option by setting definition UI_USE_USER_EQ = 1. If set UI_PLAY_USER_EQ_EDIT = 1, user can change user define EQ value in Playback module. You can call UiSetUdefEqVal() function to send user define EQ value to DSP. These value is stored in array gxbUserDefEq[]. To edit or display user define EQ, you can call UiShowUdefEqVal( ), UiEditUDefEq(), UiShowUDefEqSel(), UiClearUDefEqSel(), UiDrawUserDefEq function. For more detail, see section Ui Common (UiCommon.c) above. 2.27.10 Display function and micro You could call these function to display some information. UiReDrawMusicPlayer() Clear and redraw music player screen. UiShowMusicType() Display music type in title (MP3 or WMA) UiShowPlayStatus() Display play state icon (Play, Pause, Stop, etc) UiShowEqMode() Display EQ state icon UiShowPlayTime()
www.ali.com.tw

173

M5661 Firmware Programming Guide Display music play time UiShowAbRepeat() Display A-B repeat icon PS. This function will call UiShowRepeatMode() function if no A-B repeat UiShow3dMode() Display 3D mode icon UI_SHOW_CURRENT_FILE() Display current play file number UI_SHOW_TOTAL_FILE() Display total play file number UI_SHOW_BITRATE() Display music bit rate. (gxwUiLastBitRate variable value) UI_SHOW_BATTERY() Display battery icon. (gxbLastBattSts variable value) PS. UiNormalCheck() function will show battery icon. You just use the micro if you want to force display battery icon. 2.27.11 DSP Information UI could get or send information to DSP by using Idma Pio R/W. These are useful DSP address for UI: DSP_EQ_ADDR Get or set EQ value. DSP_3D_ADDR Get or set 3D value DSP_LEFT_VOLUME_ADDR Get or set music left volume DSP_RIGHT_VOLUME_ADDR Get or set music right volume DSP_BIT_RATE_ADDR Get music bit rate value For more detail, see section IDMA (Idma.c). 2.27.12 Play Engine Command UI should send command to play engine base on user input. The useful meaning of value for UI is: P_NOP: No command. Play engine will continue playing or waiting. P_PLAYBACK: Play command. Play engine will start to play music.
www.ali.com.tw

174

M5661 Firmware Programming Guide P_PAUSE: Pause command. Play engine will pause. P_PREV: Previous music command. Play engine will play previous music. P_NEXT: Next music command. Play engine will play next music. P_STOP: Stop command. Play engine will stop playing. P_FIRST: First music command. Play engine will play first music. P_LAST: Last music command. Play engine will play last music. P_RESTART: Restart command. Play engine will play the same music again. P_RND_NEXT: For random play next music command. Play engine will go to next music but would not play it. P_RND_FIRST: For random play first music command. Play engine will go to first music but would not play it. P_RND_START: For random start to play command. Play engine will start playing music. P_AB_REPT_START: A-B repeat start command. Play engine will get the A-B repeat start point. P_AB_REPT_END: A-B repeat end command. Play engine will get the A-B repeat end point. P_AB_REPT_RESET: A-B repeat cancel command. Play engine will stop A-B repeat. P_AB_REPT_RETURN_A: A-B repeat return command. Play engine will return to start point.

UI should handle to play next music by comparing gdwFileSector and gxdwFileTotalSector. If gdwFileSector is larger than gxdwFileTotalSector, UI should send P_NEXT command. UI should handle the first or last music control by comparing gxwCurrentFileNum and gxwNumTotalFiles. For example, when player is playing last music, and user press Key 6, UI should send P_FIRST command, not P_NEXT command. UI should handle the A-B repeat by comparing gdwFileSector and gxdwFileSectorReptB. If gdwFileSector is larger than gxdwFileSectorReptB, UI should send P_AB_REPT_RETURN_A command. UI should send P_RND_FIRST, P_RND_NEXT, P_RND_NEXT, P_RND_START command to control random play. For example, for playing third music, UI should send command: P_RND_FIRST (Let play engine go back first music) P_RND_NEXT (Second music) 175

www.ali.com.tw

M5661 Firmware Programming Guide P_RND_NEXT (Third music) P_RND_START (Start playing) 2.27.13 Flow Description 2.27.13.1 Play Module Initial

Set variable default value (common setting) Set variable default value (play module setting) Initial error handle Restore last setting Play engine initial and start Play module display

Set variable default value (common setting) Set variable default value. If some variable use the same kind default value in any module, for example, gxbUiMenuMainStates should be UI_NO_MENU in any module starting, set the default value at this time. You could do this job easily by calling UI_SET_DEFAULT define. Set variable default value (play module setting) Set variable default value. That default value might not be the same or variable might not be used in other modules, set the default value as this time. Initial error handle Some error might be detected in init module. Ui should handle these errors. If any error detected in init module, gxbLastErrCode would be set the error code. You could check the error code ERR_INIT_xxx (xxx is the error kind) in const.h You could do this job by calling UiCheckIniErr() function. Restore last setting Most of setting value would be restored in init module. UI only need to restore last play file number (gxwCurrentFileNum). Play engine initial and start Just call PeInit() function to do this job. Note: If file system init failed, dont call this function to avoid system crash. Play module display Just call UiReDrawMusicPlayer() function to do this job.

www.ali.com.tw

176

M5661 Firmware Programming Guide 2.27.13.2 Super Loop(Common State Job)

Common State Job


Get Key

Check Backlight (power off)

Volume Control

Lyric and Tag Display

Normal Check Base on State and User Input Control Job (Call Service Function and Change State) Error Handle Get Key
Just call KeyGet() function to do this job. Check Backlight Just call UiCheckBackLight() function to do this job. (This function will check power long key for power off, too) Volume Control Display and control volume when user input volume key. Lyric and Tag Display Display and scroll lyric or tag. For more detail, see section Music Tag Display and Lyric Display above. Normal Check Check system state. Just call UiNormalCheck() function to do this job.

Base on State and User Input Control Job


See next section. Error Handle If gxbErrCode is non-zero, call UiErrHandle() function to control error.

2.27.13.3

Super Loop (Wait/Pause State Job)

www.ali.com.tw

177

M5661 Firmware Programming Guide Wait/Pause State Job


Common State Job

Main Menu

Send Command to Play Engine Base on User Input

Error Handle

Base on User Input Sending Command to Play Engine When system state is wait or pause, UIs job is simple. Just send command to play engine base on user input. An exception is pressing Key 5 would enter main menu.

2.27.13.4

Super Loop (Play State Job) Play State Job


Common State Job

UI_NO_MENU UiGoNoMenu() Key 5 Key 5 Key 2 UI_MUSIC_MENU UI_MUSIC_REPEAT_MENU UiGoMusicMenuRepeat() Key 5 Key 4 Key 6 Key 2 UI_MUSIC_MENU UI_MUSIC_EQ_MENU UiGoMusicMenuEQ() Key 5 Key 4 Key 6 Key 2 UI_MUSIC_MENU UI_MUSIC_3D_MENU UiGoMusicMenu3D() Key 5 UI_3D_MENU ??? UiGoMusic3DMenu() Key 2 Set 3D Mode Key 4 Key 6 UI_EQ_MENU ??? UiGoMusicEqMenu() Key 2 Set EQ Mode Key 4 Key 6 UI_REPEAT_MENU ??? UiGoMusicRepeatMenu() Key 2 Set Repeat Mode Key 4 Key 6

Error Handle
Description When system state is play, UIs job is more complex. See Play State Job picture above. In dotted line box, any block is a state. In the state block, First line is gxbUiMenuMainStates value, second line is gxbUiMenuSubStates value, and last line is the entry function (UI will call this function to enter this state). The symbol

www.ali.com.tw

178

M5661 Firmware Programming Guide


means the value in this state isnt important (dont care). The symbol ??? means the value isnt fixed (dependent on user input or other states). UI No Menu State Default state. No menu appear, and sub menu state is dont care. UI should send command to play engine base on user input. In any program module, when system enter main menu state, UiGoMainMenu() function in UiCommon.c might call back UiGoNoMenu() to enter UI No Menu state if user press Key 5. Ui Music Menu State Music menu appear, and sub menu default state is repeat menu. Menu sub state list is: UI_MUSIC_REPEAT_MENU UI_MUSIC_EQ_MENU UI_MUSIC_3D_MENU User could press Key 4 or Key 5 to change sub menu state. Ui Repeat Menu State Repeat mode select menu appear, and sub menu state is the repeat mode value that user selected. Menu sub state list is: UI_REPEAT_NO_MENU UI_REPEAT_ONE_MENU UI_REPEAT_ALL_MENU UI_REPEAT_RND_ALL_MENU UI_REPEAT_RND_MENU UI_REPEAT_LIST_MENU User could press Key 4 or Key 5 to change sub menu state. PS. This define is effected by UI_USE_RND_PLAY_ONE_EN and UI_USE_PLAY_LIST_EN define in UiCommon.h Ui EQ Menu State EQ mode select menu appear, and sub menu state is the EQ mode value that user selected. Menu sub state list is: UI_EQ_NORMAL_MENU UI_EQ_POP_MENU UI_EQ_CLASSIC_MENU UI_EQ_ROCK_MENU UI_EQ_DANCE_MENU UI_EQ_BASS_MENU UI_EQ_UDEF_MENU User could press Key 4 or Key 5 to change sub menu state. PS. This define is effected by UI_USE_USER_EQ define in TypeDef.h Ui 3D Menu State 3D Mode select menu appear, and sub menu state is the 3D mode value that user selected. Menu sub state list is:

www.ali.com.tw

179

M5661 Firmware Programming Guide


UI_3D_ON_MENU UI_3D_OFF_MENU User could press Key 4 or Key 5 to change sub menu state.

2.27.14 API Functions

UiDispCtrl()
Display and control for TARGET Playback. void UiDispCtrl(BYTE bStatus) Parameters PBYTE bStatus Return values None Global variable

Example

See also

UiGoNoMenu()
Default state. No menu appear, and sub menu state is dont care. UI should send command to play engine base on user input. void UiGoNoMenu(void) Parameters None Return values None Global variable

Example

See also

www.ali.com.tw

180

M5661 Firmware Programming Guide 2.28 UI Play DVR (UiPlay.c)

2.28.1 UI Play and UI Play DVR The Architecture of UI play and UI play DVR module is similar. You can get the information about System State, Menu State, A-B Repeat State, Random Play List, UiDispCtrl function, and Play Engine Command from section UI Play (UiPlay.c) above. Their contents are the same. The differentia in play DVR module is: Not display tag information Not display music type & bit rate information Not support EQ and 3D function Let user select record source or quality You could separate out not used function by definition _PM_DVR_ 2.28.2 Display function and micro
Display function is almost the same with play module. The different function is: UiShowRecFile() Show record file name (8+3 short file name). Because UI play DVR module not display tag informat, use this function instead of LcdShowTagTitle() function.

2.28.3

Volume Information

If recorded file is mp3 file, UI could get volume information from DSP. Please see section DSP information above. If recorded file is adpcm file, UI should get volume information form gwLastVolIndicator viraible.

www.ali.com.tw

181

M5661 Firmware Programming Guide Play State Job


Common State Job

UI_NO_MENU UiGoNoMenu() Key 5 Key 7 Long Key 2 UI_REC_MENU UI_REC_FROM_MENU UiGoRecMenuFrom () Key 5 Key 4 Key 6 Key 2 UI_REC_MENU UI_REC_QTY_MENU UiGoRecQtyMenu() Key 5 Key 4 Key 2 UI_MUSIC_MENU UI_MUSIC_REPEAT_MENU UiGoMusicMenuRepeat() Key 5 UI_REPEAT_MENU ??? UiGoMusicRepeatMenu() Key 2 Set Repeat Mode Key 6 UI_QTY_MENU ??? UiGoRecQtyMenu() Key 2 Set Record Quality Key 4 Key 6 UI_FROM_MENU ??? UiGoRecFromMenu() Key 2 Set Record Source Key 4 Key 6

www.ali.com.tw

Key 5

Error Handle

2.28.4 UI Play DVR Super Loop


Description In dotted line box, any block is a state. In the state block, First line is gxbUiMenuMainStates value, second line is gxbUiMenuSubStates value, and last line is the entry function (UI will call this function to enter this state). The symbol means the value in this state isnt important (dont care). The symbol ??? means the value isnt fixed (dependent on user input or other states). PS. The record menu could be affected by UI_USE_REC_SOURCE in UiCommon.h UI No Menu State Default state. No menu appear, and sub menu state is dont care. UI should send command to play engine base on user input. In any program module, when system enter main menu state, UiGoMainMenu() function in UiCommon.c might call back UiGoNoMenu() to enter UI No Menu state if user press Key 5. Ui Music Menu State Music menu appear, and sub menu state is always repeat menu. Ui From Menu State Record source mode select menu appear, and sub menu state is the record source

182

M5661 Firmware Programming Guide


value that user selected. Menu sub state list is: UI_FROM_MIC_MENU UI_FROM_LINE_MENU User could press Key 4 or Key 5 to change sub menu state. Ui QTY Menu State Record quality mode select menu appear, and sub menu state is the record quality value that user selected. Menu sub state list is: UI_QTY_HIGHT UI_QTY_NORMAL UI_QTY_LONG User could press Key 4 or Key 5 to change sub menu state.

www.ali.com.tw

183

M5661 Firmware Programming Guide 2.29 UI Record (UiRec.c)

2.29.1 Simple Architecture

UI Record Record Module Initial

Super Loop

Common State Job

Error Handle

Base on State and User Input Control Job

2.29.2 System State UI should response base on system state. For example, when system state is in recording state and user input Key 7, UI should send R_PAUSE command to record engine. You can get the system state by reading gxbSysState variable. 2.29.3 UiDispCtrl function UI would call some service function. When these service function cause some events, for example, record engine ready to start recording, UI might need to display or control something at this time. The service function would call back UiDispCtrl() function and let UI to do his job at this time. Parameters: BYTE bStatus The service function set the event in the variable.
www.ali.com.tw

184

M5661 Firmware Programming Guide These are useful event for UI: UI_RE_INIT_START Record engine is preparing to initial. UI_RE_INIT_END Record engine initial has finished. UI_RE_START_START Record engine is preparing to start to record. UI_RE_START_END Record engine is ready to start to record. UI_RE_REC_UPDATE Record engine has updated the recording information. (Ex. Recording time) UI_RE_STOP Record engine has stopped. UI_RE_PAUSE Record engine has paused. UI_RE_RETURN_REC Record engine has continued to record. 2.29.4 Display function and micro You could call these functions to display some information. UiReDrawRec() Clear and redraw record module screen. UiShowRecStatus() Display recording state icon (Record, Pause, Stop, etc) UiShowRecTime() Display recording time UI_SHOW_BATTERY() Display battery icon. (gxbLastBattSts variable value) PS. UiNormalCheck() function will show battery icon. You just use the micro if you want to force display battery icon. 2.29.5 Record Engine Command UI should send command to record engine base on user input. The useful meaning of value for UI is: R_NOP: No command. Record engine will continue recording or waiting. R_REC:
www.ali.com.tw

185

M5661 Firmware Programming Guide Record command. Record engine will continue to record. R_PAUSE: Pause command. Record engine will pause. R_STOP: Stop command. Record engine will stop recording.
Note: UI should send R_STOP command before swaping to another module or power off, or it will lose the recording file.

2.29.6 Flow Description 2.29.6.1 Record Module Initial

Set variable default value (common setting) Set variable default value (record module setting) Initial error handle Record engine initial and start Play module display
Set variable default value (common setting) Set variable default value. If some variable use the same kind default value in any module, for example, gxbUiMenuMainStates should be UI_NO_MENU in any module starting, set the default value at this time. You could do this job easily by calling UI_SET_DEFAULT define. Set variable default value (record module setting) Set variable default value. That default value might not be the same or variable might not be used in other modules, set the default value as this time. Initial error handle Some error might be detected in init module. UI should handle these errors. If any error detected in init module, gxbLastErrCode would be set the error code. You could check the error code ERR_INIT_xxx (xxx is the error kind) in const.h You could do this job by calling UiCheckIniErr() function. Record engine initial and start Just call ReInit() and ReStart() function to do this job. Play module display Just call UiReDrawMusicPlayer() function to do this job.

www.ali.com.tw

186

M5661 Firmware Programming Guide 2.29.6.2 Super Loop(Common State Job)

Common State Job


Get Key

Check Backlight (power off)

Normal Check

Base on State and User Input Control Job (Call Service Function and Change State)

Error Handle Get Key


Just call KeyGet() function to do this job. Check Backlight Just call UiCheckBackLight() function to do this job. (This function will check power long key for power off, too) Normal Check Check system state. Except v-bus detecting, just call UiNormalCheck() function to do this job. Because UI must send R_STOP command to record engine before swaping to USB module, it should handle v-bus detecting alone.

Base on State and User Input Control Job


See next section. Error Handle If gxbErrCode is non-zero, call UiErrHandle() function to control error.

2.29.6.3 Super Loop(Record State Job) Record State Job


Common State Job

Play DVR or FM module

Send Command to Record Engine Base on User Input

Error Handle

www.ali.com.tw

187

M5661 Firmware Programming Guide


Base on User Input Sending Command to Play Engine In record module, UIs job is simple. Just send command to play engine base on user input. When user stop to record, UI should send R_STOP command to record engine and return to Play DVR or FM module.

2.29.7 API Functions

UiDispCtrl()
Display and control for TARGET Playback. void UiDispCtrl(BYTE bStatus) Parameters BYTE bStatus Return values None Global variable

Example

See also

UiShowWakeUp()
Show alarm display. void UiShowWakeUp(void) Parameters None Return values None Global variable

Example

See also

www.ali.com.tw

188

M5661 Firmware Programming Guide 2.30 UI FM (UiFM.c)

2.30.1 Simple Architecture

UI FM FM Module Initial

Super Loop

Common State Job

Error Handle

Base on State and User Input Control Job

2.30.2 Menu State UI should response base on menu state. For example, when record quality menu is appeared and user input Key 2, UI should set the record quality value, not control FM chip. You can get the menu state by reading gxbUiMenuMainStates and gxbUiMenuSubStates variable. gxbUiMenuMainStates means which kind menu it entered. gxbUiMenuSubStates means which item user selected. For example, when user enter record quality menu and select Long Time, gxbUiMenuMainStates is UI_QTY_MENU and gxbUiMenuSubStates is UI_QTY_LONG. 2.30.3 UiDispCtrl function UI would call some service function. When these service function cause some events UI might need to display or control something at this time. In FM module, there is only one
www.ali.com.tw

189

M5661 Firmware Programming Guide event that FmChip.c will call back UiDispCtrl. Its UI_FM_SEARCHING. Other events are UI call itself event. Parameters: BYTE bStatus The service function set the event in the variable. These are useful event for UI: UI_FM_SEARCHING FM is searching station. UI_SEL_PRESET_START UI call itself event. User is starting to select a preset station. UI_SEL_PRESET_SELECT UI call itself event. User is selecting preset stations. UI_SAVE_PRESET_START UI call itself event. User is starting to save a preset station. UI_SAVE_PRESET_SELECT UI call itself event. User is selecting preset channel to save preset station. UI_SAVE_PRESET_SAVE UI call itself event. User is saving a preset station. UI_FM_SEARCH_DOWN UI call itself event. User is searching station down. UI_FM_SEARCH_UP UI call itself event. User is searching station up. 2.30.4 Display function and micro You could call these function to display some information. UiReDrawFM() Clear and redraw FM module screen. UiShowFreq() Display current frequency UiShowStereo() Check and display stereo state. UiRedrawStero() Display stereo state. (Call this function to force display stereo state) UiShowPreset() Display preset channel. UiScrollPrset() Scroll preset channel.
www.ali.com.tw

190

M5661 Firmware Programming Guide 2.30.5 Flow Description 2.30.5.1 FM Module Initial

Set variable default value (common setting) Set variable default value (FM module setting) Initial error handle FM chip initial and start FM module display
Set variable default value (common setting) Set variable default value. If some variable use the same kind default value in any module, for example, gxbUiMenuMainStates should be UI_NO_MENU in any module starting, set the default value at this time. You could do this job easily by calling UI_SET_DEFAULT define. Set variable default value (FM module setting) Set variable default value. That default value might not be the same or variable might not be used in other modules, set the default value as this time. Initial error handle Some error might be detected in init module. Ui should handle these errors. If any error detected in init module, gxbLastErrCode would be set the error code. You could check the error code ERR_INIT_xxx (xxx is the error kind) in const.h You could do this job by calling UiCheckIniErr() function. FM chip initial and start Just call FmInit() function to do this job. FM module display Just call UiReDrawFM() function to do this job.

www.ali.com.tw

191

M5661 Firmware Programming Guide 2.30.5.2 Super Loop Common State Job
Get Key

Check Backlight (power off)

Volume Control

Display Stereo State

Normal Check Base on State and User Input Control Job (Call Service Function and Change State) Error Handle Get Key
Just call KeyGet() function to do this job. Check Backlight Just call UiCheckBackLight() function to do this job. (This function will check power long key for power off, too) Display Stereo State Just call UiShowStereo() function to do this job. Normal Check Check system state. Just call UiNormalCheck() function to do this job.

Base on State and User Input Control Job


See next section. Error Handle If gxbErrCode is non-zero, call UiErrHandle() function to control error.

www.ali.com.tw

192

M5661 Firmware Programming Guide 2.30.6 UI FM Super Loop FM Job


Swap to Record Module

Common State Job

Key 7

UI_NO_MENU UiGoNoMenu() Key 2 UI_SEL_PRESET_MENU xxx xxx Select Preset

Key 2

Key 5 Long UI_SAVE_PRESET_MENU xxx xxx

Key 2 Select Preset

FM Chip Control Set Frequency or Search Station

Key 7 Save Preset

Key 5 Key 4 Key 7 Long Key 6 Key 2 Set Record Quality UI_QTY_MENU ??? UiGoRecQtyMenu()

Error Handle
Description In black dotted line box, any block is a state. In the state block, First line is gxbUiMenuMainStates value, second line is gxbUiMenuSubStates value, and last line is the entry function (UI will call this function to enter this state). The symbol means the value in this state isnt important (dont care). The symbol ??? means the value isnt fixed (dependent on user input or other states). FM Chip Control In red dotted line box, UI should set frequency or search station base on user input in those states. For more detail, see section Fm (FmChip.c) above. UI No Menu State Default state. No menu appear, and sub menu state is dont care. In any program module, when system enter main menu state, UiGoMainMenu() function in UiCommon.c might call back UiGoNoMenu() to enter UI No Menu state if user press Key 5.

www.ali.com.tw

193

M5661 Firmware Programming Guide


UI Select Preset Menu State Select preset channel bar appear, and sub menu state is dont care. UI should set FM frequency when user select another preset channel. Ui Save Preset Menu State Select preset channel bar appear, and sub menu state is dont care. UI should save the frequency when user press Key 7. Ui QTY Menu State Record quality mode select menu appear, and sub menu state is the record quality value that user selected. Menu sub state list is: UI_QTY_HIGHT UI_QTY_NORMAL UI_QTY_LONG User could press Key 4 or Key 5 to change sub menu state.

2.30.7 API Functions

UiDispCtrl()
Display and control for TARGET Playback. void UiDispCtrl(BYTE bStatus) Parameters BYTE bStatus Return values None Global variable

Example

See also

UiGoNoMenu()
Default state. No menu appear, and sub menu state is dont care. UI should send command to play engine base on user input. void UiGoNoMenu(void) Parameters None

www.ali.com.tw

194

M5661 Firmware Programming Guide


Return values None Global variable

Example

See also

UiShowWakeUp()
Show alarm display. void UiShowWakeUp(void) Parameters None Return values None Global variable

Example

See also

www.ali.com.tw

195

M5661 Firmware Programming Guide 2.31 UI System (UiSys.c)

2.31.1 Simple Architecture

Time

Adjust Alarm

Adjust On/Off

On Off

Power Setup Language English Chinese(Trad) Chinese(Simp) Contrast Backlight Source Quality Line In MIC Long Time Normal Quality High Quality

Display

Record

User Define EQ
Storage

Internal SD/MMC Card MS Card xD Card

2.31.2 Menu State In system module, UI should control menu state. You can get the menu state by reading gxbUiMenuMainStates and gxbUiMenuSubStates variable. gxbUiMenuMainStates means which kind menu it entered. gxbUiMenuSubStates means which item user selected. For example, when user enter Time menu and select Adjust, gxbUiMenuMainStates is UI_SYS_TIME_MENU and gxbUiMenuSubStates is UI_TIME_NOW_MENU. 2.31.3 Small Loop Job

www.ali.com.tw

196

M5661 Firmware Programming Guide

Small Loop Job


Get Key

Check Backlight (power off)

Normal Check

Base on State and User Input Control Job

UI system module is a tree architecture module. Any tree node is a small loop.
Get Key
Just call KeyGet() function to do this job. Check Backlight Just call UiCheckBackLight() function to do this job. (This function will check power long key for power off, too) Normal Check Check system state. Just call UiNormalCheck() function to do this job.

Base on State and User Input Control Job


Base on menu state and user input to change state or set value.

2.31.4 Architecture Definitions

UI System module architecture would be affected by these definitions in UiCommon.h. UI_USE_REC_SOURCE Define this if hardware support different record source. This define will affect record source menu. UI_USE_STORAGE_SOURCE Define this if hardware support different storage (card reader). This define will affect storage menu. UI_STORAGE_SOURCE_MAX When UI_USE_STORAGE_SOURCE define, how many storages support. UI_SYS_MAX_MENU How many top menu item in system module.
2.31.5 Time Setting

Any module get current time variable gxdwNowTime by hardware RTC counter. For display,
www.ali.com.tw

197

M5661 Firmware Programming Guide

you can call UiSysGetNowTimeText() function to transfer time number to ASCII time string in gxbStringEditTime[] arrary. For more detail, see section UI Common (UiCommon.c) above. For saving time setting, you can call UiTurnTimeText() function to transfer ASCII time string to time number, and then call UiSetNowTime() to save time.
2.31.6 Alarm Setting

You can call UiSysGetAlarmTime() function to get alarm time in variable gxdwAlarmTime. Its the same with time setting, for display, you can call UiSysGetNowTimeText() function to transfer time number to ASCII time string in gxbStringEditTime[] arrary. For saving alarm time setting, you can call UiTurnTimeText() function to transfer ASCII time string to time number, and then call UiSetNewAlarmTime() to save time. Sometime, we need to adjust the alarm time number. For example, current time is 01:00 AM (time number 60), if user set alarm time 00:00 AM, it mean alarm time is 00:00 AM tomorrow. We should adjust alarm time number to 86400 (24hr=86400sec). You can call UiFixAlarmTime() function to do this job.
2.31.7 Power Setting

Initial module will get the power setting in variable gxwAutoOff. You can call UiGetPSaveTime() function to transfer time number to ASCII time string in gxbStringEditPSaveTime[] variable. The meaning of gxwAutoOff is: Bit 15:Auto off option. Set to 1 if auto off enable. Bit 14:Dont auto off when playback option. Set to 1 to enable this option. Bit 13-0:Auto off time value (minutes) UiNormalCheck() function will check this variable and handle auto off job.
2.31.8 Language Setting

You can change system language by setting variable gxbLangueType. The setting value is: LANGUAGE_TYPE_EN: English LANGUAGE_TYPE_TW: Tradition Chinese LANGUAGE_TYPE_CN: Simplified Chinese
2.31.9 Contrast Setting

You can get Lcd contrast value by reading variable gxbLcdContrast. You can call UiShowContrast() function to change Lcd contrast value.
www.ali.com.tw

198

M5661 Firmware Programming Guide 2.31.10 Backlight Setting

You can change backlight time setting by setting variable gxbBackLightCounter. UiCheckBackLight() function will check this variable and handle backlight job.
2.31.11 Record Setting

See section Ui Common (UiCommon.c) and Ui Play DVR (UiPlay.c) above.


2.31.12 User Define EQ Setting

See section Ui Play (UiPlay.c) above.


2.31.13 Storage Setting

You can change system storage by setting variable gxbStorType and gxbStorage. File system use variable gxbStorType and UI use gxbStorage variable. These two variable is usally the same but not always. UI should initial job (SD init, Nand Flash init, file system init, record system init) after user select another storage. For more detail, see section SD (SD.c), NandFlash (NandFlash.c), File System (FileSystem.c), Record (Record.c) above.
2.31.14 API Functions

UiDispCtrl()
Display and control for TARGET Playback. void UiDispCtrl(BYTE bStatus,BYTE bSubStatus) Parameters BYTE bStatus BYTE bSubStatus Return values None Global variable

Example

See also

www.ali.com.tw

199

M5661 Firmware Programming Guide UiGoNoMenu()


Default state. No menu appear, and sub menu state is dont care. UI should send command to play engine base on user input. void UiGoNoMenu(void) Parameters None Return values None Global variable

Example

See also

UiShowWakeUp()
Show alarm display. void UiShowWakeUp(void) Parameters None Return values None Global variable

Example

See also

UiShwCardRemoved()
Card was removed. void UiShwCardRemoved(void) Parameters None Return values None

www.ali.com.tw

200

M5661 Firmware Programming Guide


Global variable

Example

See also

www.ali.com.tw

201

M5661 Firmware Programming Guide

2.32

UI File List (UiFileList.c)

2.32.1 API Functions

UiDispCtrl()
Display and control for TARGET Playback. void UiDispCtrl(BYTE bStatus) Parameters BYTE bStatus Return values None Global variable

Example

See also

UiGoNoMenu()
Default state. No menu appear, and sub menu state is dont care. UI should send command to play engine base on user input. void UiGoNoMenu(void) Parameters None Return values None Global variable

Example

See also

www.ali.com.tw

202

M5661 Firmware Programming Guide

2.33

UI Play Common (UIPlayCommon.c)

2.33.1 API Functions

UiCancelIntroMode()
Cancel intro mode. void UiCancelIntroMode(void) Parameters None Return values None Global variable

Example

See also

UiCountCurtFileNum()
Count curt file numbers. void UiCountCurtFileNum(struct FILE_INF_DATA xdata *stOldFileInf,struct FILE_INF_DATA xdata *stNewFileInf) Parameters struct FILE_INF_DATA xdata *stOldFileInf struct FILE_INF_DATA xdata *stNewFileInf Return values None Global variable

Example

See also

www.ali.com.tw

203

M5661 Firmware Programming Guide UiDrawBasicMusicMenu()


Show basic music menu. void UiDrawBasicMusicMenu(void) Parameters None Return values None Global variable

Example

See also

UiGetCurtDirName()
Get curt directory name. void UiGetCurtDirName(void) Parameters None Return values None Global variable

Example

See also

UiGetRndPlayNum()
Gets a random play list num. WORD UiGetRndPlayNum(bit fGetNext) Parameters bit fGetNext If fGetNext==TRUE, get the next song number. If fGetNext==FALSE, get the prev song number. Return values WORD type

www.ali.com.tw

204

M5661 Firmware Programming Guide


Global variable

Example

See also

UiGoIntroMode()
Set intro mode. void UiGoIntroMode(void) Parameters None Return values None Global variable

Example

See also

UiKeepLastLyric()
Keep last lyric. void UiKeepLastLyric(void) Parameters None Return values None Global variable

Example

See also

UiNextMenuItem()
.

www.ali.com.tw

205

M5661 Firmware Programming Guide


void UiNextMenuItem(void) Parameters None Return values None Global variable

Example

See also

UiPlayLyricControl()
Lyric function. void UiPlayLyricControl(void) Parameters None Return values None Global variable

Example

See also

void UiPrevMenuItem(void)

void UiPrevMenuItem(void) Parameters None Return values None Global variable

Example

www.ali.com.tw

206

M5661 Firmware Programming Guide


See also

UiRndPlayInit()
Get a random seed from RTC timer and the current file number. UI should call this function when random play mode starts. void UiRndPlayInit(void) Parameters None Return values None Global variable

Example

See also

UiSetUdefEqVal()
Send user define EQ value to DSP. These value is stored in array gxbUserDefEq[]. void UiSetUdefEqVal(void) Parameters None Return values None Global variable

Example

See also

UiShowWakeUp()
Show alarm display. void UiShowWakeUp(void) Parameters None

www.ali.com.tw

207

M5661 Firmware Programming Guide


Return values None Global variable

Example

See also

www.ali.com.tw

208

M5661 Firmware Programming Guide 2.34 UI Play Menu (UIPlayMenu.c)

2.34.1 API Functions

UiDispCtrl()
Display and control for TARGET Playback. void UiDispCtrl(BYTE bStatus) Parameters BYTE bStatus Return values None Global variable

Example

See also

UiGoNoMenu()
Default state. No menu appear, and sub menu state is dont care. UI should send command to play engine base on user input. void UiGoNoMenu(void) Parameters None Return values None Global variable

Example

See also

UiSelectItemControl()
Select item for control. void UiSelectItemControl(void)

www.ali.com.tw

209

M5661 Firmware Programming Guide


Parameters None Return values None Global variable

Example

See also

UiShowMusicMenuText()
Show music menu text. void UiShowMusicMenuText(void) Parameters None Return values None Global variable

Example

See also

www.ali.com.tw

210

M5661 Firmware Programming Guide

2.35

UI Play Menu2 (UIPlayMenu2.c)

2.35.1 API Functions

UiDispCtrl()
Display and control for TARGET Playback. void UiDispCtrl(BYTE bStatus) Parameters BYTE bStatus Return values None Global variable

Example

See also

UiGoNoMenu()
Default state. No menu appear, and sub menu state is dont care. UI should send command to play engine base on user input. void UiGoNoMenu(void) Parameters None Return values None Global variable

Example

See also

UiShowMusicMenuText()
Show Music Menu Text.

www.ali.com.tw

211

M5661 Firmware Programming Guide


void UiShowMusicMenuText(void) Parameters None Return values None Global variable

Example

See also

www.ali.com.tw

212

M5661 Firmware Programming Guide

2.36

UI Usb Device (UIUsbDevice.c)

2.36.1 API Functions

USB_Suspend()
Handle USB suspend and resume. void USB_Suspend(void) Parameters None Return values None Global variable

Example

See also

www.ali.com.tw

213

M5661 Firmware Programming Guide

2.37

UI Usb Host (UIUsbHost.c)

2.37.1 API Functions

UiDispCtrl()
Display and control for TARGET Playback. void UiDispCtrl(BYTE bStatus) Parameters BYTE bStatus Return values None Global variable

Example

See also

UiShowSizeNumber()
Display size number (ex: 1024 will show 1K). void UiShowSizeNumber(DWORD dwSecNum, BYTE bPage, BYTE bColNum) Parameters DWORD dwSecNum BYTE bPage BYTE bColNum Return values None Global variable

Example

See also

www.ali.com.tw

214

M5661 Firmware Programming Guide UiShowWakeUp()


Show alarm display. void UiShowWakeUp(void) Parameters None Return values None Global variable

Example

See also

www.ali.com.tw

215

M5661 Firmware Programming Guide 2.38 UI Class List (UIClassList.c)

2.38.1 API Functions

CdbGetDbSector( )
Get class database start sector in private area. You should call the function before accessing class database. void CdbGetDbSector(void) Parameters None Return values None Global variable gxdwCdbStartSec: Class database start sector gxwCdbMaxSec: The max length of class database (sector) Example

See also

CdbInit()
Class database initial (building database) BOOL CdbInit(void) Parameters None Return values Bit type TRUE: Initialed successfully. FALSE: Initialed failed Global variable

Example

www.ali.com.tw

216

M5661 Firmware Programming Guide


See also

CdbReadSector()
Read a sector from class database PS. While creating database, this function will use a read-write cache system. You should read data from cache and handle it carefully. BOOL CdbReadSector(DWORD dwCdbSec) Parameters DWORD dwCdbSec The sector in class database you want to read Return values Bit type TRUE: successfully. FALSE: failed Global variable

Example

See also

CdbWriteSector()
Write a sector into class database BOOL CdbWriteSector(DWORD dwCdbSec) Parameters DWORD dwCdbSec The sector in class database you want to write Return values Bit type TRUE: successfully. FALSE: failed Global variable

Example

www.ali.com.tw

217

M5661 Firmware Programming Guide


See also

CdbSearchData()
Search a data in class database and load class header info BOOL CdbSearchData(BYTE bSearchType) Parameters BYTE bSearchType The type of searching class database, all supported type is: CDB_SEARCH_FIRST_GENRE CDB_SEARCH_FIRST_ARTIST CDB_SEARCH_FIRST_ALBUM CDB_SEARCH_FIRST_TITLE CDB_SEARCH_LAST_GENRE CDB_SEARCH_LAST_ARTIST CDB_SEARCH_LAST_ALBUM CDB_SEARCH_LAST_TITLE CDB_SEARCH_NEXT CDB_SEARCH_PREV CDB_SEARCH_ENTER CDB_SEARCH_BACK CDB_SEARCH_ENTER_LAST

Return values Bit type TRUE: successfully. FALSE: failed Global variable gdwCdbAddPoint: Current loading address in class database Example

See also

www.ali.com.tw

218

M5661 Firmware Programming Guide CdbGetClassHeader()


Load and copy class info header BOOL CdbGetClassHeader (DWORD dwCdbPoint) Parameters DWORD dwCdbPoint Reading address in class database Return values Bit type TRUE: successfully. FALSE: faile Global variable stCdbClassInfo: To store the header info Example

See also

CdbGetClassString()
Load and copy class string BOOL CdbGetClassString(DWORD dwCdbPoint, PBYTE pbStrBuf) Parameters DWORD dwCdbPoint Reading address in class database PBYTE pbStrBuf String buffer for saving class string Return values Bit type TRUE: successfully. FALSE: failed Global variable

Example

See also

www.ali.com.tw

219

M5661 Firmware Programming Guide

CdbGetDataBaseHeader()
Get class database header info DWORD CdbGetDataBaseHeader(BYTE bInfAdd) Parameters BYTE bInfAdd The address of header info Return values DWORD type The class database header info Global variable

Example

See also

CdbLoadDirInfo()
Load dir info PBYTE CdbLoadDirInfo(WORD wDirNum) Parameters WORD wDirNum The dir number Return values PBYTE type Success: Dir info point Failed: CDB_NULL_POINT Global variable

Example

See also

www.ali.com.tw

220

M5661 Firmware Programming Guide

CdbDelLeafNode()
Delete a leaf node (title node) in class database. If no other brother nodes, the function will delete parent node, too. The variable gdwCdbAddPoint would not be changed after calling this function void CdbDelLeafNode(void) Parameters None Return values None Global variable DWORD gdwCdbAddPoint: Current loading address in class database Example

See also

CdbClearHeaderInfo()
Clear class database header info (empty database) void CdbClearHeaderInfo(void) Parameters None Return values None Global variable

Example

See also

www.ali.com.tw

221

M5661 Firmware Programming Guide 2.38.2 SYS Functions CdbUpdateDirInfo( )


Updat dir info in class database void CdbUpdateDirInfo(DWORD dwDirInfAdd, WORD wParentDirNum) Parameters DWORD dwDirInfAdd The address in class database. WORD wParentDirNum The parents dir info number Return values None Global variable

Example

See also

CdbBulitDirInfo( )
Built dir infor in class database WORD CdbBulitDirInfo(void) Parameters None Return values WORD type Total dir info number Global variable

Example

See also

CdbSearchDirInf( )
Search Dir Info for making class database WORD CdbSearchDirInf(DWORD dwDirSec,WORD wDirOff) Parameters DWORD dwDirSec The sector of the dir entry WORD wDirOff

www.ali.com.tw

222

M5661 Firmware Programming Guide


The sector of the dir entry Return values WORD type Success: Dir info number Failed: 0 Global variable

Example

See also

CdbCompClassStr( )
Compare Class string BOOL CdbCompClassStr(DWORD dwCdbPoint, PBYTE pbStr) Parameters DWORD dwCdbPoint: The address in class database PBYTE pbStr: The compared string buffer Return values BOOL type TRUE: The string is the same FALSE: The string is different Global variable

Example

See also

CdbClearNode( )
Clean and set current class info struct (stCdbClassInfo) void CdbClearNode(BYTE bClassMode) Parameters BYTE bClassMode: The class mode of the node Return values None

www.ali.com.tw

223

M5661 Firmware Programming Guide


Global variable

Example

See also

CdbNewNode( )
Built a new class node in class database DWORD CdbNewNode(BYTE bClassMode, DWORD dwParentPoint, BOOL fNextNode) Parameters BYTE bClassMode: The class mode of the node DWORD dwParentPoint The address of the parent node in class database BOOL fNextNode TRUE: Building next node FALSE: Building enter node Return values DWORD type The address of new node in class database (original gxdwCdbEmptyPoint) Global variable gxdwCdbEmptyPoint: The empty address in class database. The variable will point to next empty address after calling the function. Example

See also

CdbLoadAllUnKnownTag( )
Load all of unkown tag string to sram void CdbLoadAllUnKnownTag(void) Parameters None Return values None Global variable

www.ali.com.tw

224

M5661 Firmware Programming Guide


Example

See also

CdbNewFirstNode( )
Built first node of one class DWORD CdbNewFirstNode(BYTE bClassMode) Parameters BYTE bClassMode: The class mode of the node Return values DWORD type The address of new node in class database (original gxdwCdbEmptyPoint) Global variable gxdwCdbEmptyPoint: The empty address in class database. The variable will point to next empty address after calling the function. Example

See also CdbNewNode()

CdbIncMusicNumInNode( )
Increase Total Music Number in class node void CdbIncMusicNumInNode(void) Parameters None Return values None Global variable

Example

See also

CdbFindAndBulitClass( )
Find the parent node and built new node in class database BOOL CdbFindAndBulitClass(BYTE bSearchType, BYTE bClassMode)

www.ali.com.tw

225

M5661 Firmware Programming Guide


Parameters BYTE bSearchType The searching type to find his parent node BYTE bClassMode: The class mode of the node Return values Bit type TRUE: successfully. FALSE: failed Global variable gxdwCdbEmptyPoint: The empty address in class database. The variable will point to next empty address after calling the function. Example

See also CdbNewNode()

CdbUpdateHeaderEndInf( )
Update header info about the end point and number void CdbUpdateHeaderEndInf(void) Parameters None Return values None Global variable

Example

See also

CdbScanChildNode( )
Get child node number and end point void CdbScanChildNode(void) Parameters None Return values None

www.ali.com.tw

226

M5661 Firmware Programming Guide


Global variable DWORD gdwCdbAddPoint: The address of the first parent node which you want to scan Example

See also

CdbBulitClassEndInf( )
Built class info about end point void CdbBulitClassEndInf(void) Parameters None Return values None Global variable

Example

See also

CdbBulitClassInfo( )
Built class info in class database BOOL CdbBulitClassInfo(void) Parameters None Return values Bit type TRUE: successfully. FALSE: failed Global variable gxdwCdbEmptyPoint: The empty address in class database. gxwNumTotalFiles: Total music file number Example

See also CdbFindAndBulitClass()

www.ali.com.tw

227

M5661 Firmware Programming Guide CdbSetUnknownTag( )


If tag is unknow, set a default unknow string in buffer void CdbSetUnknownTag(void) Parameters None Return values None Global variable

Example

See also

CdbReadFlashSector( )
Read a sector (I/O read, No cache) BOOL CdbReadFlashSector(DWORD dwCdbSec) Parameters DWORD dwCdbSec The sector number in class database Return values Bit type TRUE: successfully. FALSE: failed Global variable

Example

See also CdbReadSector()

CdbUpdateOneBlock( )
Update 1 block(16bytes) memory data in class database BOOL CdbUpdateOneBlock(DWORD dwCdbPoint, PBYTE pbSoureceData) Parameters DWORD dwCdbPoint The address in class database PBYTE pbSourceData

www.ali.com.tw

228

M5661 Firmware Programming Guide


Point to source data memory Return values Bit type TRUE: successfully. FALSE: failed Global variable

Example

See also

CdbLoadGenreString( )
Load Genre String (GenreTable) from NnadFlash void CdbLoadGenreString(BYTE bGenreNum, PBYTE pbBuffer) Parameters BYTE bGenreNum The genre number of ID3v1 PBYTE pbBuffer String buffer Return values None Global variable

Example

See also

CdbGenreNumToString( )
Transfer ID3v2 genre number to string. Ex. (0) will be transfer to Blues void CdbGenreNumToString(void) Parameters None Return values None Global variable

Example

www.ali.com.tw

229

M5661 Firmware Programming Guide


See also

CdbGetTagInfo( )
Get Music Tag Info BOOL CdbGetTagInfo(void) Parameters None Return values Bit type TRUE: successfully. FALSE: failed Global variable

Example

See also

CdbAnsiToUnicode( )
Transfer Ansi string to Unicode String void CdbAnsiToUnicode(PBYTE pbString,BYTE bStrMaxLen) Parameters PBYTE pbString Source string buffer BYTE bStrMaxLen Max length of target buffer Return values None Global variable

Example

See also

CdbModifyNodeLink( )
Read and modify a node link (DWORD) void CdbModifyNodeLink(DWORD dwAddrPoint,DWORD dwNewLink) Parameters DWORD dwAddrPoint

www.ali.com.tw

230

M5661 Firmware Programming Guide


The address in class database DWORD dwNewLink The new address in class database Return values None Global variable

Example

See also

CdbDecreaseNodeItemNum( )
Decrease item number after current node void CdbDecreaseNodeItemNum(void) Parameters None Return values None Global variable

Example

See also

CdbInitDataCache( )
Init CDB data cache void CdbInitDataCache(void) Parameters None Return values None Global variable

Example

See also

www.ali.com.tw

231

M5661 Firmware Programming Guide CdbSearchDataCache( )


Search CDB data cache for building database BOOL CdbSearchDataCache(PBYTE pbClassStrBuf) Parameters PBYTE pbClassStrBuf The class string buffer Return values BOOL Type: CDB_SEARCH_CACHE_HIT: Data found in data cache CDB_SEARCH_CACHE_MISS: Data not found in data cache Global variable gxbCdbCacheModuleNum: Select data cache module Example

See also

CdbUpdateDataCache( )
Update CDB cache for building database void CdbUpdateDataCache(PBYTE pbClassStrBuf) Parameters PBYTE pbClassStrBuf The class string buffer Return values None Global variable gxbCdbCacheModuleNum: Select data cache module Example

See also

CdbInitSysCache( )
Init CDB system cache void CdbInitSysCache(void) Parameters None

www.ali.com.tw

232

M5661 Firmware Programming Guide


Return values None Global variable

Example

See also

CdbSearchSysCache( )
Search CDB system cache for building database PS. Do NOT call this function if you read the same sector BOOL CdbSearchSysCache(DWORD dwCdbSec) Parameters DWORD dwCdbSec The sector in class database Return values BOOL Type: CDB_SEARCH_CACHE_HIT: Sector found in data cache CDB_SEARCH_CACHE_MISS: Sector not found in data cache Global variable gxbCurtSysCacheNum: Current system cache number to read/write gxwSysCacheTimeStamp: Current system cache time stemp Example

See also

CdbSysCacheReadNewSector( )
Read a new sector to sys cache, you should call this function after searching system cache miss BOOL CdbSysCacheReadNewSector(DWORD dwCdbSec) Parameters DWORD dwCdbSec The sector in class database Return values Bit type TRUE: successfully.

www.ali.com.tw

233

M5661 Firmware Programming Guide


FALSE: failed Global variable

Example

See also

CdbMoveBufAndSysCache( )
Move one sector system cache data void CdbMoveBufAndSysCache(BYTE bSysCacheNum,BOOL fBuf2Cache) Parameters BYTE bSysCacheNum The system cache number you want to access BOOL fBuf2Cache TRUE: Move data from I/O buffer to system cache FALSE: Move data from system cache to I/O buffer Return values None Global variable

Example

See also

CdbGet2kStartAddr( )
Get Nand-Flash 2K page start address DWORD CdbGet2kStartAddr(DWORD dwCdbSec) Parameters DWORD dwCdbSec The sector in class database Return values DWORD Type: 2K page start address Global variable

Example

www.ali.com.tw

234

M5661 Firmware Programming Guide


See also

CdbWriteDownDirtySysCache( )
Write down dirty (modified) system cache data. (It will write down the same 2K page data if necessary) BOOL CdbWriteDownDirtySysCache(BYTE bSysCacheNum) Parameters BYTE bSysCacheNum The system cache number Return values Bit type TRUE: successfully. FALSE: failed Global variable

Example

See also

www.ali.com.tw

235

You might also like