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

📄 params.c

📁 一款MP3 Player Firmware 的原代码,非常有参考价值
💻 C
字号:
# include "as31glue.h"#include "main.h"#include "printf.h"#include "sta013.h"#include "display.h"#include "params.h"#include "paulmon2.h"#define EPARAM_ONOFF 0xffff#define EPARAM_NAME_LEN 16#define EPARAM_VALUE_LEN 5#define EPARAM_SCREEN_TIME_COUNT 8#define EPARAM_BACKLIGHT_COUNT 2#define EPARAM_ONOFF_COUNT 2#define EPARAM_COUNT 15#define FIRST_DISPLAY_LINE 1#define LAST_DISPLAY_LINE  8static code unsigned char default_value[PARAM_COUNT] = {   0,    /* UNUSED0 */   20,   /* PARAM_ATTN */   STA013_PARAM_CENTRE, /* PARAM_TREBLE */   STA013_PARAM_CENTRE, /* PARAM_BASS */   0x0b, /* PARAM_TREBLE_FREQ_UNUSED */   6,    /* PARAM_TREBLE_FREQ_INDEX */   0,    /* PARAM_BASS_FREQ_UNUSED */   6,    /* PARAM_BASS_FREQ_INDEX */   MODE_SEQNTIAL, /* PARAM_PLAY_MODE */   0,    /* PARAM_PLST_INDEX_HI */   0,    /* PARAM_PLST_INDEX_LO */   0,    /* PARAM_TRACK_INDEX_HI */   0,    /* PARAM_TRACK_INDEX_LO */   0,	 /* PARM_RAND16_SEED_HI */   0,	 /* PARM_RAND16_SEED_LO */   0,    /* PARAM_RESUME */   4,    /* PARAM_SCROLL_SPEED */   1,    /* PARAM_DISK_SPIN_DOWN_DELAY */   1,    /* PARAM_DISK_SPIN_UP_AHEAD */   2,    /* PARAM_SCREEN_TIMEOUT */   0,    /* PARAM_BACKLIGHT_TIMEOUT */   STA013_PARAM_CENTRE, /* PARAM_BALANCE */   STARTUP_MODE_PLAYING, /* PARAM_STARTUP_MODE */};   xdata unsigned char param_value[PARAM_COUNT];/* A constant structure is used to describe each editable parameter.This contains a name, a maximum, a pointer and a parameter number.  Toadd an editable parameter it must be added to both the param_t enum(in params.h) and this in array.  Parameters will appear under theprevious heading - the first entry is assumed to be a heading.  In thepointer is non zero it is used to display and edit the possible valuesof a parameter */static code unsigned char nothing[][EPARAM_VALUE_LEN+1] = {""};static code unsigned char on_off[EPARAM_ONOFF_COUNT][EPARAM_VALUE_LEN+1] = {"On", "Off"}; static code unsigned char disk_times[EPARAM_DISK_SPIN_COUNT][EPARAM_VALUE_LEN+1] = {   " None",   " ASAP",   " 1Sec",   " 2Sec",   " 5Sec",   "10Sec",   "15Sec",    "20Sec",    "30Sec",    " 1Min",    " 2Min",    " 5Min",    "10Min", };static code unsigned char backlight_times[EPARAM_BACKLIGHT_COUNT][EPARAM_VALUE_LEN+1] = {   "Never",   "On   "};static code unsigned char screen_times[EPARAM_SCREEN_TIME_COUNT][EPARAM_VALUE_LEN+1] = {   "Never",   " 5Sec",    "10Sec",    "15Sec",    "30Sec",    "45Sec",    " 1Min",    " 2Min"};static code unsigned char bass_freq[NUM_BASS_FREQ][EPARAM_VALUE_LEN+1] = {   "40Hz ",   "50Hz ",   "63Hz ",   "80Hz ",   "100Hz",   "125Hz",   "160Hz",   "200Hz",   "250Hz",   "320Hz",   "400Hz",   "500Hz",   "640Hz"};static code unsigned char treble_freq[NUM_TREBLE_FREQ][EPARAM_VALUE_LEN+1] = {   "1kHz ",   "1.25k",   "1.6k ",   "2kHz ",   "2.5k ",   "3.15k",   "4kHz ",   "5kHz ",   "6.3k ",   "8kHz ",   "10kHz",   "12.5k",   "16kHz"};static code unsigned char startup_modes[STARTUP_MODE_COUNT][EPARAM_VALUE_LEN+1] = {   "Play ",   "Pause"};typedef static code struct eparam {      unsigned char name[EPARAM_NAME_LEN+1];      unsigned char max;      unsigned char* values;      param_t param;      void (*update)();} eparam_t;/* parameters and their headings.  max = 0 is used as to denote a heading */eparam_t eparams[EPARAM_COUNT] = {    {"Playing options", 0, nothing, 0, 0},   {"Startup state", STARTUP_MODE_COUNT - 1, startup_modes, PARAM_STARTUP_MODE, 0},   {"Display options", 0, nothing, 0, 0},   {"Screen Timeout", EPARAM_SCREEN_TIME_COUNT - 1, screen_times, PARAM_SCREEN_TIMEOUT, 0},   {"Scroll Rate", 7, nothing, PARAM_SCROLL_SPEED, lcd_set_scroll_speed},   {"Backlight Time", EPARAM_BACKLIGHT_COUNT - 1, backlight_times, PARAM_BACKLIGHT_TIMEOUT, lcd_update_backlight_timer},   {"Audio settings", 0, nothing, 0, 0},   {"Bass Cutoff", NUM_BASS_FREQ - 1, bass_freq, PARAM_BASS_FREQ_INDEX, set_sta013_bass_frequency},   {"Treble Cutoff", NUM_TREBLE_FREQ - 1, treble_freq, PARAM_TREBLE_FREQ_INDEX, set_sta013_treble_frequency},   {"Testing DANGER!!", 0, nothing, 0, 0},   {"Disk Spin Down", EPARAM_DISK_SPIN_COUNT - 1, disk_times, PARAM_DISK_SPIN_DOWN_DELAY, 0},   {"Disk Spin Up", EPARAM_DISK_SPIN_COUNT - 1, disk_times, PARAM_DISK_SPIN_UP_AHEAD, 0},   {"Sample 1", EPARAM_ONOFF_COUNT - 1, on_off, PARAM_UNUSED0, 0},   {"Sample 2", EPARAM_ONOFF_COUNT - 1, on_off, PARAM_UNUSED0, 0},   {"Sample 3", EPARAM_ONOFF_COUNT - 1, on_off, PARAM_UNUSED0, 0},};/* the same array of enums is used to indicate whether a heading is   expanded or a parameter is edited.  Since headings can't be edited   and params can't be expanded these states are mutually exclusive */typedef enum {   NONE = 0,   EXPANDED = 1,   EDITED = 2,   LASTHEADING = 4,} eparam_state_t;static eparam_state_t eparam_state[EPARAM_COUNT];static xdata unsigned char first_displayed_param;static xdata unsigned char eparam_selected;static xdata unsigned char line_selected;void param_restart_write_timer(unsigned char timeout){   clear_timer(TIMER_PARAM_WRITE);   set_timer(TIMER_PARAM_WRITE, timeout);}unsigned char param_default_value(param_t param){   return default_value[param];}void param_write(param_t param){   ibuf[0] = param_value[param];   write_flash_param(param, ibuf);}/* eparam_display displays the list editable parameters on the   lcd_display */voideparam_display(){   xdata unsigned char current_line = 0;   xdata unsigned char current_param = 0;   xdata unsigned char prev_heading = 0;   eparam_t* current_eparam = 0;      // work through all the parameters displaying where on display   for(current_line = FIRST_DISPLAY_LINE, current_param = 0;        (current_line <= LAST_DISPLAY_LINE) && (current_param < EPARAM_COUNT);       current_param++)   {      current_eparam = &eparams[current_param];      // is this a heading and on display?      if (current_eparam->max == 0)      {	 if (current_param >= first_displayed_param)	 {	    // clear line, switch to current line, switch to tree font	    printf("\\L%c\\[\\B %c\\C!",		   (char)(current_line + 31),		   (char)(current_line + 31));		   	    // determine tree character	    if ((eparam_state[current_param] & LASTHEADING) != 0)	    {	       // last entry	       print("\\+");	    }	    else	    {	       // continuation entry	       print("\\*");	    }	    // change font for selection	    if (current_param == eparam_selected)	    {	       // bold	       printf("\\C!");	    }	    else	    {	       // normal	       printf("\\C ");	    }	    // print heading	    printf("%s\\C \\]\r\n",		   current_eparam->name);	    current_line++;	 }	 // always keep track of heading number for expand/contract of	 // its params	 prev_heading = current_param;      }      else if (current_param >= first_displayed_param && 	       (eparam_state[prev_heading] & EXPANDED != 0))      {	 // clear, switch to current line, switch to tree font	 printf("\\L%c\\[\\B %c\\C!",		(char)(current_line + 31),		(char)(current_line + 31));	 // last heading so print without heading tree	 if ((eparam_state[prev_heading] & LASTHEADING) != 0)	 {	    // clear line and print parameter name	    print(" ");	 }	 else	 {	    print("\\!");	 }	 // determine tree character	 if ((current_param == EPARAM_COUNT - 1) ||	     (eparams[current_param + 1].max == 0))	 {	    // last entry	    print("\\+");	 }	 else	 {	    // continuation entry	    print("\\*");	 }	 // change font for selection	 if (current_param == eparam_selected)	 {	    // bold	    print("\\C!");	 }	 else	 {	    // normal	    print("\\C ");	 }	 // print name in appropriate font and move to value position	 printf("%s\\B%c%c",		current_eparam->name,		(char)(EPARAM_NAME_LEN + 3 + 32), // 2 char for tree, 1 for spacing		(char)(current_line + 31)	    );	 {	    unsigned char value;	    value = param_value[current_eparam->param];	    // print value in numeric or string format	    if (current_eparam->values == nothing) 	    {	       printf("%d\\C \\]\r\n", value);	    }	    else if (value <= current_eparam->max)	    {	       printf("%s\\C \\]\r\n", current_eparam->values + (value * (EPARAM_VALUE_LEN+1)));	    }	    else	    {	       print("ERROR\\C \\]\r\n");	    }	 }	 current_line++;      }   }}unsigned chareparam_user_action(event_t event){   xdata unsigned char eparam_temp = 0;   switch(event)    {      case E_DOWN:	 // look for next heading or expanded param	 for(eparam_temp = eparam_selected + 1; eparam_temp < EPARAM_COUNT; eparam_temp++)	 {	    if (eparams[eparam_temp].max == 0 || 		(eparam_state[eparam_temp] & EXPANDED != 0))	    {	       eparam_selected = eparam_temp;	       // pan down if necessary	       if (line_selected != LAST_DISPLAY_LINE)	       {		  line_selected++;	       }	       else	       {		  // look for next heading or expanded param for new first line		  for(first_displayed_param++; first_displayed_param < EPARAM_COUNT; first_displayed_param++)		  {		     if (eparams[first_displayed_param].max == 0 ||			 (eparam_state[first_displayed_param] & EXPANDED != 0))		     {			break;		     }		  }	       }	       return 1;	    }	 }	 	 break;      case E_UP:	 // look for previous heading or expanded param	 if (eparam_selected != 0)	 {	    for(eparam_temp = eparam_selected - 1; eparam_temp != 0; eparam_temp--)	    {	       if (eparams[eparam_temp].max == 0 || 		   eparam_state[eparam_temp] & EXPANDED != 0)	       {		  eparam_selected = eparam_temp;		  // pan up if necessary		  if (line_selected != FIRST_DISPLAY_LINE)		  {		     line_selected--;		  }		  else		  {		     // look for previous heading or expanded param for new first line		     for(first_displayed_param--; first_displayed_param != 0; first_displayed_param--)		     {			if (eparams[first_displayed_param].max == 0 || 			    eparam_state[first_displayed_param] & EXPANDED != 0)			{			   break;			}		     }		  }		  return 1;	       }	    }	    eparam_selected = 0;	    first_displayed_param = 0;	    line_selected = FIRST_DISPLAY_LINE;	    return 1;	 }	 	 break;      case E_LEFT:      case E_RIGHT:      case E_DEC:      case E_INC:	 if (eparams[eparam_selected].max == 0)	 {	    // heading - toggle expand/collapse heading and parameters under the heading	    eparam_temp = eparam_selected;	    do	    {	       eparam_state[eparam_temp] ^= EXPANDED;	       eparam_temp++;	    }	    while (eparams[eparam_temp].max != 0 && (eparam_temp < EPARAM_COUNT));	    return 1;	 }	 else	 {	    eparam_t* current_eparam = 0;	    current_eparam = &eparams[eparam_selected];	    switch(event)	    {	       case E_LEFT:	       case E_DEC:		  if (param_value[current_eparam->param] != 0)		  {		     param_value[current_eparam->param]--;		  }		  else		  {		     param_value[current_eparam->param] = current_eparam->max;		  }		  eparam_state[eparam_selected] |= EDITED;		  if (current_eparam->update != 0)		  {		     // call the update function		     (*current_eparam->update)();		  }		  param_restart_write_timer(100);		  return 1;		  break;	       case E_RIGHT:	       case E_INC:		  if (current_eparam->max != param_value[current_eparam->param])		  {		     param_value[current_eparam->param]++;		  }		  else		  {		     param_value[current_eparam->param] = 0;		  }		  eparam_state[eparam_selected] |= EDITED;		  if (current_eparam->update != 0)		  {		     // call the update function		     (*current_eparam->update)();		  }		  param_restart_write_timer(100);		  return 1;		  break;	       default:		  break;	    }	       	 }	 break;      default:	 printf("Unsupported event %d\r\n", event);	 break;   }   return 0;}// write all changes eparams to flashvoideparam_write_flash(){   xdata unsigned char i = 0;   eparam_t* current_eparam = 0;   for (i=0; i < EPARAM_COUNT; i++)   {      current_eparam = &eparams[i];      if (current_eparam->max != 0 && (eparam_state[i] & EDITED) != 0)      {	 // write	 ibuf[0] = param_value[current_eparam->param];	 write_flash_param(current_eparam->param, ibuf);	 // clear flag	 eparam_state[i] &= ~EDITED;      }   }}voidparam_init(void){   xdata unsigned char i = 0;   xdata unsigned char last_heading = 0;   for (i=0; i < EPARAM_COUNT; i++)   {      if (eparams[i].max == 0)      {	 last_heading = i;	 // workaround for sdcc bug (submitted 13 Jan 2002)	 i = last_heading;      }      eparam_state[i] = NONE;   }   eparam_state[last_heading] = LASTHEADING;   for (i=0; i < PARAM_COUNT; i++)   {      param_value[i] = read_param_1byte(i, default_value[i]);   }   first_displayed_param = 0;   eparam_selected = 0;   line_selected = FIRST_DISPLAY_LINE;}            unsigned int param_screen_timeout(){   static code unsigned int times[EPARAM_SCREEN_TIME_COUNT] = {      0,      50,      100,      150,      300,      450,      600,      1200};   return times[param_value[PARAM_SCREEN_TIMEOUT]];}

⌨️ 快捷键说明

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