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

📄 menu.c

📁 silicon wireless开发套件F920+Si4432原理图,源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/*
** ============================================================================
**
** FILE
**  menu.c
**
** DESCRIPTION
**  Realize the menu operation
**
** CREATED
**  Silicon Laboratories Hungary Ltd
**
** COPYRIGHT
**  Copyright 2008 Silicon Laboratories, Inc.  
**	http://www.silabs.com
**
** ============================================================================
*/
/*------------------------------------------------------------------------*/
/*						INCLUDE											  */
/*------------------------------------------------------------------------*/
#include "global_definitions.h"
#include "menu.h"
#include "IA443x_demo.h"
#include "dog_glcd.h"
#include "timers.h"
#include "IAI_EBID.h"

/*------------------------------------------------------------------------*/
/*						GLOBAL variables, constants						  */
/*------------------------------------------------------------------------*/
uint8 CursorPosition;

//menu item declarations
xdata MENU_ITEM_VALUE	MenuItems;
code uint8 t_system_function[2][5] = {"DEMO", "LAB "};
code uint8 t_lab_mode[4][4] = {"CW ", "PN9", "BER", "PER"};
code uint8 t_demo_mode[3][4] = {"TRx", "Tx ", "Rx "};
code uint8 t_data_rate[NMBR_OF_GFSK_SAMPLE_SETTING][4] = {"2.4","4.8","9.6"," 10"," 20"," 40", " 50", "100", "128"};
code uint8 t_arib_data_rate[NMBR_OF_ARIB_SAMPLE_SETTING][5] = {"2.4","4.8"};
code uint8 t_ook_data_rate[NMBR_OF_OOK_SAMPLE_SETTING][4] = {"2.4","4.8","9.6"};
code uint8 t_modulation_mode[3][5] = {"GFSK","FSK ","OOK "};
code uint8 t_antenna_mode[3][4] = {"A&B","A  ","B  "};
code uint8 t_yes_no[2][4] = {"NO ","YES"};
code uint8 t_on_off[2][4] = {"OFF","ON "};
code uint16 v_max_packets[7] = {1, 10, 100, 500, 1000, 5000, 9999};

//extern variables, constans
	//global_constans.c
extern code uint8 FirmwareVersion[5];
extern code DEMO_FREQ demo_freqs[MAX_FREQ_SETTING];
extern code DEMO_FREQ arib_freqs[MAX_ARIB_FREQ_SETTING];
	//pictures.c
extern const code no_packet11x8[];
extern const code rssi12x8[];
extern const code rssi24x8[];
extern const code rssi36x8[];
extern const code rssi48x8[];
extern const code rssi510x8[];
extern const code rssi612x8[];
extern const code rssi714x8[];
extern const code ant9x8[];
extern const code ant1_inverted15x8[];
extern const code ant2_inverted15x8[];
extern const code ok_inverted16x8[];
extern const code rx_inverted16x8[];
extern const code start_inverted29x8[];
extern const code stop_inverted24x8[];
extern const code tx_inverted16x8[];
extern const code txon_inverted29x8[];
extern const code silabs87x40[];
extern const code txoff_inverted32x8[];
extern const code clear_inverted29x8[];
extern const code setting_inverted48x8[];
extern const code minus_inverted16x8[];
extern const code plus_inverted16x8[];
extern const code up_down_inverted16x8[];
extern const code go_inverted16x8[];
	//IAI_EBID.
extern xdata EBID_DATA	TestcardData;
	//dog_glcd.c
extern idata uint8 lcd_data[22];
	//IAI_demo.c
extern xdata ANTENNA_TYPE SelectedAntennaType;


/*------------------------------------------------------------------------*/
/*						LOCAL function prototypes						  */
/*------------------------------------------------------------------------*/
void PrintRssiToLcd(void);
void DecFreqCounter(void);
void IncFreqCounter(void);
uint8 CheckFreqBand(void);
void PrintFreqDr(void);
void PrintRssi(uint8 row, uint8 column, uint8 rssi);
void DrawEmptySettingPage(void);
BUTTON_STATES CheckPushButtons(void);

/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  +
  + FUNCTION NAME:  MENU_RETURN PerformMenu(MENU_ITEM menu_item)
  +
  + DESCRIPTION:    menu handling
  +
  +	INPUT:			next menu page
  +
  + RETURN:         
  +
  + NOTES:          
  +
  +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
MENU_RETURN PerformMenu(MENU_ITEM menu_item)
{
	switch( menu_item )
	{
		case sMenuStartScreen:
			//clear LCD
			LcdClearDisplay();
			//draw startup screen
			LcdSetPictureCursor(LCD_LINE_1,20);
			LcdDrawPicture(silabs87x40);
			memcpy(lcd_data,"EZRadioPRO Evaluation",21);
			LcdWriteLine(LCD_LINE_7,lcd_data);	
			sprintf(lcd_data,"   (Firmware: %s)  ",FirmwareVersion);
			LcdWriteLine(LCD_LINE_8,lcd_data);	
			//print on the USB
			printf("\r\n\r\nSILICON Labs., Si443x Packet Error Rate Demonstration\r\n");
			printf("Firmware: %s\r\n",FirmwareVersion);
		break;

		case sMenuXTALError:
			LcdClearDisplay();
			printf("\r\nERROR: XTAL startup error!");
			printf("\r\nTry a different Testcard!\r\n");
			memcpy(lcd_data,"ERROR: XTAL startup! ",21);
			LcdWriteLine(LCD_LINE_2,lcd_data);
			memcpy(lcd_data,"   Try a different   ",21);
			LcdWriteLine(LCD_LINE_5,lcd_data);
			memcpy(lcd_data,"      Testcard!      ",21);
			LcdWriteLine(LCD_LINE_6,lcd_data);
			while(1);
		break;

		case sMenuPORTimeout:
			//clear LCD
			LcdClearDisplay();
			printf("\r\nERROR: POR timeout! Insert a Testcard or try a different one!\r\n");
			memcpy(lcd_data,"ERROR: POR timeout!  ",21);
			LcdWriteLine(LCD_LINE_2,lcd_data);
			memcpy(lcd_data,"Insert a Testcard or ",21);
			LcdWriteLine(LCD_LINE_5,lcd_data);
			memcpy(lcd_data,"try a different one! ",21);
			LcdWriteLine(LCD_LINE_6,lcd_data);
		break;

		case sMenuTestcardOrEEPROMError:
			//clear LCD
			LcdClearDisplay();
			//EEPROM is empty
			printf("\r\nERROR: no Testcard inserted, or the board identification");  
			printf("\r\nEEPROM is missing or empty!");
			printf("\r\nTry a different Testcard!\r\n");
			memcpy(lcd_data,"ERROR: no Testcard or",21);
			LcdWriteLine(LCD_LINE_1,lcd_data);
			memcpy(lcd_data,"   the board ident.  ",21);
			LcdWriteLine(LCD_LINE_2,lcd_data);
			memcpy(lcd_data,"EEPROM missing/empty!",21);
			LcdWriteLine(LCD_LINE_3,lcd_data);
			memcpy(lcd_data,"   Try a different   ",21);
			LcdWriteLine(LCD_LINE_5,lcd_data);
			memcpy(lcd_data,"      Testcard!      ",21);
			LcdWriteLine(LCD_LINE_6,lcd_data);
		break;

		case sMenuNotSupportedChip:
			//clear LCD
			LcdClearDisplay();
			//EEPROM is empty
			printf("\r\nERROR: the chip is not supported");  
			printf("\r\nby the current firmware!");
			printf("\r\nTry a different Testcard!\r\n");
			memcpy(lcd_data,"ERROR: the chip isn't",21);
			LcdWriteLine(LCD_LINE_2,lcd_data);
			memcpy(lcd_data,"supported by the FW! ",21);
			LcdWriteLine(LCD_LINE_3,lcd_data);
			memcpy(lcd_data,"   Try a different   ",21);
			LcdWriteLine(LCD_LINE_5,lcd_data);
			memcpy(lcd_data,"      Testcard!      ",21);
			LcdWriteLine(LCD_LINE_6,lcd_data);
		break;

	/*SYSTEM FUNCTION MENU*/
		case sMenuDrawSystemFunctionScreen:
			DrawEmptySettingPage();
			memcpy(lcd_data,"SYSTEM FUNCTION  1/3 ",21);
			LcdWriteLine(LCD_LINE_1,lcd_data);
			sprintf(lcd_data," Function:      %s ",&t_system_function[MenuItems.name.system_function][0]);			
			LcdWriteLine(LCD_LINE_3,lcd_data);
			if( MenuItems.name.system_function == LAB_MODE )
			{
				sprintf(lcd_data,"   =>Lab Mode:  %s  ",&t_lab_mode[MenuItems.name.lab_mode][0]);
			}	
			else
			{
				sprintf(lcd_data,"   =>Demo Mode: %s  ",&t_demo_mode[MenuItems.name.demo_mode][0]);
			}			
			LcdWriteLine(LCD_LINE_4,lcd_data);

			//draw cursor
			LcdSetCharCursor((CursorPosition+3),1);
			LcdPutCh(CURSOR);
		break;

		case sMenuChangeSystemFunction:
			//check the state of the push buttons
			switch( CheckPushButtons() )
			{
				case Button1Pressed:
					if(CursorPosition < 1) CursorPosition++; else CursorPosition = 0;
					return UPDATE_PAGE;
				break;
				case Button2Pressed:
					//increase actual variable
					switch( CursorPosition )
					{
						case 0:	
							if( MenuItems.name.system_function < MAX_SF_VALUE ) MenuItems.name.system_function++; else MenuItems.name.system_function = 0; 
						break;
						case 1:	
							if( MenuItems.name.system_function == LAB_MODE )
							{
								switch( TestcardData.chip_type )
								{
									case SI4030: case SI4031: case SI4032:
										if( MenuItems.name.lab_mode < 1 ) MenuItems.name.lab_mode++; else MenuItems.name.lab_mode = 0;
									break;
									case SI4330:
										if( MenuItems.name.lab_mode < MAX_LM_VALUE ) MenuItems.name.lab_mode++; else MenuItems.name.lab_mode = 2;
									break;
									case SI4430: case SI4431: case SI4432:
										if( MenuItems.name.lab_mode < MAX_LM_VALUE ) MenuItems.name.lab_mode++; else MenuItems.name.lab_mode = 0; 
									break;
								}
							}
							else
							{
								switch( TestcardData.chip_type )
								{
									case SI4030: case SI4031: case SI4032:	//TRANSMIT ONLY DEMO
										MenuItems.name.demo_mode = 1;
									break;
									case SI4330:							//RECEIVE ONLY DEMO
										MenuItems.name.demo_mode = 2;
									break;
									case SI4430: case SI4431: case SI4432:	//ONE WAY OR BIDIRECTIONAL LINK DEMO
										if( MenuItems.name.demo_mode < MAX_DM_VALUE ) MenuItems.name.demo_mode++; else MenuItems.name.demo_mode = 0;  
									break;
								}
							}
						break;
						default: break;
					}
					return UPDATE_PAGE;
				break;
				case Button3Pressed:
					switch( CursorPosition )
					{
						case 0: 
							if( MenuItems.name.system_function == 0 ) MenuItems.name.system_function = MAX_SF_VALUE; else MenuItems.name.system_function--; 
						break;
						case 1: 
							if( MenuItems.name.system_function == LAB_MODE )
							{
								switch( TestcardData.chip_type )
								{
									case SI4030: case SI4031: case SI4032:
										if( MenuItems.name.lab_mode == 0 || MenuItems.name.lab_mode > 1 ) MenuItems.name.lab_mode = 1; else MenuItems.name.lab_mode--;
									break;
									case SI4330:
										if( MenuItems.name.lab_mode < 2 ) MenuItems.name.lab_mode = MAX_LM_VALUE; else MenuItems.name.lab_mode--;
									break;
									case SI4430: case SI4431: case SI4432:
										if( MenuItems.name.lab_mode == 0 ) MenuItems.name.lab_mode = MAX_LM_VALUE; else MenuItems.name.lab_mode--; 
									break;
								}
							}
							else
							{
								switch( TestcardData.chip_type )
								{
									case SI4030: case SI4031: case SI4032:	//TRANSMIT ONLY DEMO
										MenuItems.name.demo_mode = 1;
									break;
									case SI4330:							//RECEIVE ONLY DEMO
										MenuItems.name.demo_mode = 2;
									break;
									case SI4430: case SI4431: case SI4432:	//ONE WAY OR BIDIRECTIONAL LINK DEMO
										if( MenuItems.name.demo_mode == 0 ) MenuItems.name.demo_mode = MAX_DM_VALUE; else MenuItems.name.demo_mode--; 
									break;
								}
							}
 						break;
						default: break;
					}
					return UPDATE_PAGE;
				break;
				case Button4Pressed:
					return NEXT_PAGE;
				break;
				default:
					return NONE;
				break;
			}
		break;
	
	/*RF PARAMETERS MENU*/
		case sMenuDrawRfParametersScreen:
			DrawEmptySettingPage();
			memcpy(lcd_data,"RF PARAMETERS    2/3 ",21);
			LcdWriteLine(LCD_LINE_1,lcd_data);
			if( MenuItems.name.arib_mode == FALSE )
				sprintf(lcd_data," Data Rate:   %skbps",&t_data_rate[MenuItems.name.data_rate][0]);			
			else
				sprintf(lcd_data," Data Rate:   %skbps",&t_arib_data_rate[MenuItems.name.data_rate][0]);			
			LcdWriteLine(LCD_LINE_3,lcd_data);
			sprintf(lcd_data," Modulation: %s    ",&t_modulation_mode[MenuItems.name.modulation_mode][0]);
			LcdWriteLine(LCD_LINE_4,lcd_data);
			if( MenuItems.name.arib_mode == FALSE )	
				sprintf(lcd_data," Frequency: %sMHz",demo_freqs[MenuItems.name.frequency].freq_text);
			else 
				sprintf(lcd_data," Frequency: %sMHz",arib_freqs[MenuItems.name.frequency].freq_text);
			LcdWriteLine(LCD_LINE_5,lcd_data);
			//draw cursor
			LcdSetCharCursor((CursorPosition+3),1);
			LcdPutCh(CURSOR);
		break;

		case sMenuChangeRfParameters:
			//check the state of the push buttons
			switch( CheckPushButtons() )
			{
				case Button1Pressed:
					if(CursorPosition < 2) CursorPosition++; else CursorPosition = 0;
					return UPDATE_PAGE;
				break;
				case Button2Pressed:
					//increase actual variable
					switch( CursorPosition )
					{	
						case 0:	//DATA RATE
							if( MenuItems.name.arib_mode == FALSE )
							{
								switch(MenuItems.name.modulation_mode)
								{
									case 0:	//GFSK
									case 1:	//FSK
										if( MenuItems.name.data_rate < MAX_DR_VALUE ) MenuItems.name.data_rate++; else MenuItems.name.data_rate = 0; 
									break;
									default: //OOK
										if( MenuItems.name.data_rate < MAX_OOKDR_VALUE ) MenuItems.name.data_rate++; else MenuItems.name.data_rate = 0; 
									break;
								}
							}
							else
							{
								if( MenuItems.name.data_rate < MAX_ADR_VALUE ) MenuItems.name.data_rate++; else MenuItems.name.data_rate = 0; 
							}
						break;
						case 1:	//MODULATION MODE
							if( MenuItems.name.arib_mode == FALSE )
								if( MenuItems.name.modulation_mode < MAX_MM_VALUE ) MenuItems.name.modulation_mode++; else MenuItems.name.modulation_mode = 0; 
							else
								MenuItems.name.modulation_mode = 0; 
						break;
						case 2:	//FREQUENCY
							if( MenuItems.name.arib_mode == FALSE )
							{
								IncFreqCounter();
								if( MenuItems.name.full_menu == FALSE )
								{
									if( CheckFreqBand() == FALSE )
									{
										do{
											IncFreqCounter();
										}while( CheckFreqBand() == FALSE );
									}
								}
							}
							else
							{
								if( MenuItems.name.frequency < MAX_ARIB_FREQ_SETTING-1 ) MenuItems.name.frequency++; else MenuItems.name.frequency = 0;
							}
						break;
						default: break;
					}
					return UPDATE_PAGE;
				break;
				case Button3Pressed:
					switch( CursorPosition )
					{
						case 0: //DATA RATE
							if( MenuItems.name.arib_mode == FALSE )
							{
								switch(MenuItems.name.modulation_mode)
								{
									case 0:	//GFSK
									case 1:	//FSK
										if( MenuItems.name.data_rate == 0 ) MenuItems.name.data_rate = MAX_DR_VALUE; else MenuItems.name.data_rate--; 
									break;
									default://OOK
										if( MenuItems.name.data_rate == 0 ) MenuItems.name.data_rate = MAX_OOKDR_VALUE; else MenuItems.name.data_rate--; 
									break;
								}
							}
							else
							{
								if( MenuItems.name.data_rate == 0 ) MenuItems.name.data_rate = MAX_ADR_VALUE; else MenuItems.name.data_rate--; 
							}
						break;
						case 1: //MODULATION MODE
							if( MenuItems.name.arib_mode == FALSE )
								if( MenuItems.name.modulation_mode == 0 ) MenuItems.name.modulation_mode = MAX_MM_VALUE; else MenuItems.name.modulation_mode--; 
							else
								MenuItems.name.modulation_mode = 0; 
						break;
						case 2: //FREQUENCY
							if( MenuItems.name.arib_mode == FALSE )
							{
								DecFreqCounter();
								if( MenuItems.name.full_menu == FALSE )
								{
									if( CheckFreqBand() == FALSE )
									{
										do{
											DecFreqCounter();
										}while( CheckFreqBand() == FALSE );
									}
								}
							}
							else
							{
								if( MenuItems.name.frequency == 0 ) MenuItems.name.frequency = MAX_ARIB_FREQ_SETTING-1; else MenuItems.name.frequency--;
							}
						break;
						default: break;
					}
					return UPDATE_PAGE;
				break;
				case Button4Pressed:
					return NEXT_PAGE;
				break;
				default:
					return NONE;
				break;
			}
		break;

	/*NODE PARAMETERS MENU*/
		case sMenuDrawNodeParametersScreen:
			DrawEmptySettingPage();
			memcpy(lcd_data,"NODE PARAMETERS  3/3 ",21);
			LcdWriteLine(LCD_LINE_1,lcd_data);
			sprintf(lcd_data," ID: Self:        %3bu",MenuItems.name.self_id);			
			LcdWriteLine(LCD_LINE_3,lcd_data);

⌨️ 快捷键说明

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