/*=====================================================================================================*/ void R61581_Init( void ) { // Reset LCD_RST = 0; Delay_1ms(15); LCD_RST = 1; Delay_1ms(5); Delay_1ms(50); LCD_WriteReg(0x00, 0x01); Delay_1ms(50); LCD_WriteCmd(0xB0); // {setc, [107], W, 0x000B0} LCD_WriteData(0x00); // {setp, [104], W, 0x00000} LCD_WriteCmd(0xB3); LCD_WriteData(0x02); LCD_WriteData(0x00); LCD_WriteData(0x00); LCD_WriteData(0x00); LCD_WriteCmd(0xB4); LCD_WriteData(0x00); LCD_WriteCmd(0xC0); LCD_WriteData(0x13); // LCD_WriteData(0x3B); // 480 LCD_WriteData(0x00); LCD_WriteData(0x03); // 02 LCD_WriteData(0x00); LCD_WriteData(0x01); LCD_WriteData(0x00); LCD_WriteData(0x43); LCD_WriteCmd(0xC1); LCD_WriteData(0x08); // 08 LCD_WriteData(0x10); // CLOCK//0x12 LCD_WriteData(0x08); LCD_WriteData(0x08); LCD_WriteCmd(0xC4); LCD_WriteData(0x11); LCD_WriteData(0x07); LCD_WriteData(0x03); LCD_WriteData(0x03); // Gamma For 3.5inch LCD_WriteCmd(0xC8); // Gamma setting LCD_WriteData(0x00); LCD_WriteData(0x25); LCD_WriteData(0x21); LCD_WriteData(0x05); LCD_WriteData(0x00); LCD_WriteData(0x0A); LCD_WriteData(0x65); LCD_WriteData(0x25); LCD_WriteData(0x77); LCD_WriteData(0x50); LCD_WriteData(0x0F); LCD_WriteData(0x00); LCD_WriteCmd(0x2A); LCD_WriteData(0x00); LCD_WriteData(0x00); LCD_WriteData(0x01); LCD_WriteData(0x3F); // 320 LCD_WriteCmd(0x2B); LCD_WriteData(0x00); LCD_WriteData(0x00); LCD_WriteData(0x01); LCD_WriteData(0xDF); // 480 LCD_WriteCmd(0x35); LCD_WriteData(0x00); LCD_WriteCmd(0x36); LCD_WriteData(0x31); LCD_WriteCmd(0x3A); LCD_WriteData(0x55); LCD_WriteCmd(0x44); LCD_WriteData(0x00); LCD_WriteData(0x01); LCD_WriteCmd(0x2C); LCD_WriteCmd(0x11); Delay_1ms(150); LCD_WriteCmd(0xD0); LCD_WriteData(0x07); LCD_WriteData(0x07); LCD_WriteData(0x1E); LCD_WriteData(0x03); // LCD_WriteData(0x0703); LCD_WriteCmd(0xD1); LCD_WriteData(0x03); LCD_WriteData(0x52); // VCM LCD_WriteData(0x10); // VDV LCD_WriteCmd(0xD2); LCD_WriteData(0x03); LCD_WriteData(0x24); LCD_WriteCmd(0xB0); // {setc, [107], W, 0x000B0} LCD_WriteData(0x00); // {setp, [104], W, 0x00000} LCD_WriteCmd(0x29); Delay_1ms(10); LCD_WriteReg(0x36, 0x31); LCD_Clear(BLACK); LCD_SetBackLight(BLIGHT_DEFAULT); }
enum MENU_code fTest_Mgr( void ) { int fRedrawn = 0; static bool fFirstTime = 1; static bool AUDIO_BuzzerOn_bak = 0; if ( fFirstTime ) { fFirstTime = 0; MenuFirstDisplay = 1; } // Hide menu. CurrentMenu = 0; fDisplayTime = 0; // force display time - battery status // Character magnify. DRAW_SetCharMagniCoeff( 2 ); // If screen orientation has changed, redraw screen. if ( MenuFirstDisplay == 0 ) { if ( LCD_GetScreenOrientation() != previous_Screen_Orientation ) { MenuFirstDisplay = 1; } } if ( MenuFirstDisplay ) { previous_Screen_Orientation = LCD_GetScreenOrientation(); POINTER_SetMode( POINTER_OFF ); LCD_SetRotateScreen( 0 ); LCD_SetScreenOrientation( V12 ); // Red LED blinks at high frequency. LED_Set( LED_RED, LED_BLINKING_HF ); // Green LED blinks at low frequency. LED_Set( LED_GREEN, LED_BLINKING_LF ); // Draw a little message on the LCD screen. DRAW_SetDefaultColor(); DRAW_DisplayStringWithMode( 0, Screen_Height - 2 * Char_Height, "Hardware Test", ALL_SCREEN, INVERTED_TEXT, CENTER ); MenuFirstDisplay = 0; // Drawn that rectangle on the screen. LCD_FillRect_Circle( BAR_LEFT + 1, BAR_BOTTOM + 1, MAXLEVEL * WIDTH_SQUARE , WIDTH_SQUARE - 2, RGB_YELLOW ); LCD_DrawRect( BAR_LEFT, BAR_BOTTOM, MAXLEVEL * WIDTH_SQUARE + 2 , WIDTH_SQUARE, RGB_BLUE ); // Restrict the move of the pointer to a rectangle. POINTER_SetRect( BAR_LEFT + 1, BAR_BOTTOM + 1, MAXLEVEL * WIDTH_SQUARE - POINTER_WIDTH - 2, WIDTH_SQUARE - POINTER_WIDTH - 2 ); POINTER_SetMode( POINTER_ON ); // Force buzzer activation AUDIO_BuzzerOn_bak = AUDIO_BuzzerOn; AUDIO_BuzzerOn = 1; } // end FirstDisplay // The button is pushed, let's get out of here! if ( BUTTON_GetState() == BUTTON_PUSHED ) { int i; BUTTON_WaitForRelease(); // Reset CircleOS state. MENU_ClearCurrentCommand(); DRAW_SetDefaultColor(); DRAW_Clear(); POINTER_SetMode( POINTER_ON ); BUTTON_SetMode( BUTTON_ONOFF_FORMAIN ); POINTER_SetRectScreen(); DRAW_SetCharMagniCoeff( 1 ); #if BACKLIGHT_INTERFACE // Reset backlight PWM rate to its default value. LCD_SetBackLight( 0 ); #endif // BACKLIGHT_INTERFACE // Switch LEDs off. LED_Set( LED_RED, LED_OFF ); LED_Set( LED_GREEN, LED_OFF ); fFirstTime = 1; // Search if test aplication present in flash for ( i = 0; i < MAXAPP; i++ ) { extern tMenuItem*(( *ApplicationTable )[] ); tMenuItem* curapp; unsigned addr; if (( *ApplicationTable )[ -i ] == APP_VOID ) //has been programmed { break; } else { addr = ( long unsigned )( *ApplicationTable )[ -i ] ; addr &= 0x00FFFFFF; addr |= 0x08000000; curapp = ( tMenuItem* ) addr; if ( !strcmp( curapp->Text, "COMMTEST" ) ) { LCD_SetOffset( OFFSET_ON ); CurrentCommand = curapp; CurrentMenu = 0; BUTTON_SetMode( BUTTON_ONOFF ); return CurrentCommand ->Fct_Init(); } } } LCD_SetRotateScreen( 1 ); LCD_SetScreenOrientation( previous_Screen_Orientation ); AUDIO_BuzzerOn = AUDIO_BuzzerOn_bak; return MENU_LEAVE; } #if BACKLIGHT_INTERFACE // Increment the backlight PWM. Current_CCR_BackLightStart += 0x800; // If backlight PWM is too high, restart with a lower value. if ( Current_CCR_BackLightStart > 0xF000 ) { Current_CCR_BackLightStart = 0x2000; } #endif // BACKLIGHT_INTERFACE // Every 59th calls display battery voltage and replay melody sample. // Note: due to the fRedrawn == 0, the first time the % 59 == 0 // (when divider_coord is null), the code block isn't executed. if ((( menu_divider_coord++ % 37 ) == 0 ) && ( fRedrawn == 0 ) ) { char TextBuffer[5]; *TextBuffer = '%'; *( TextBuffer + 1 ) = 0; // YRT20080204 : to avoid memcpy DRAW_DisplayVbat( 20, 12 ); UTIL_uint2str( TextBuffer + 1, PWR_BatteryLevel, 3, 0 ); DRAW_DisplayString( 170, 12, TextBuffer, 4 ); BUZZER_PlayMusic( Test_Melody ); } return MENU_CONTINUE; }
/*====================================================================================================*/ void ILI9341_Init( void ) { // Reset LCD_RST_L; Delay_100ms(1); LCD_RST_H; Delay_10ms(5); LCD_WriteCmd(0xCB); LCD_WriteData(0x39); LCD_WriteData(0x2C); LCD_WriteData(0x00); LCD_WriteData(0x34); LCD_WriteData(0x02); LCD_WriteCmd(0xCF); LCD_WriteData(0x00); LCD_WriteData(0XC1); LCD_WriteData(0X30); LCD_WriteCmd(0xE8); LCD_WriteData(0x85); LCD_WriteData(0x00); LCD_WriteData(0x78); LCD_WriteCmd(0xEA); LCD_WriteData(0x00); LCD_WriteData(0x00); LCD_WriteCmd(0xED); LCD_WriteData(0x64); LCD_WriteData(0x03); LCD_WriteData(0X12); LCD_WriteData(0X81); LCD_WriteCmd(0xF7); LCD_WriteData(0x20); LCD_WriteCmd(0xC0); // Power control LCD_WriteData(0x23); // VRH[5:0] LCD_WriteCmd(0xC1); // Power control LCD_WriteData(0x10); // SAP[2:0];BT[3:0] LCD_WriteCmd(0xC5); // VCM control LCD_WriteData(0x3e); // 對比度調節 LCD_WriteData(0x28); LCD_WriteCmd(0xC7); // VCM control2 LCD_WriteData(0x86); // -- LCD_WriteCmd(0x36); // Memory Access Control #ifdef H_VIEW LCD_WriteData(0x48); // 豎屏 #else LCD_WriteData(0xE8); // 橫屏 #endif LCD_WriteCmd(0x3A); LCD_WriteData(0x55); LCD_WriteCmd(0xB1); LCD_WriteData(0x00); LCD_WriteData(0x18); LCD_WriteCmd(0xB6); // Display Function Control LCD_WriteData(0x08); LCD_WriteData(0x82); LCD_WriteData(0x27); LCD_WriteCmd(0xF2); // 3Gamma Function Disable LCD_WriteData(0x00); LCD_WriteCmd(0x26); // Gamma curve selected LCD_WriteData(0x01); LCD_WriteCmd(0xE0); // Set Gamma LCD_WriteData(0x0F); LCD_WriteData(0x31); LCD_WriteData(0x2B); LCD_WriteData(0x0C); LCD_WriteData(0x0E); LCD_WriteData(0x08); LCD_WriteData(0x4E); LCD_WriteData(0xF1); LCD_WriteData(0x37); LCD_WriteData(0x07); LCD_WriteData(0x10); LCD_WriteData(0x03); LCD_WriteData(0x0E); LCD_WriteData(0x09); LCD_WriteData(0x00); LCD_WriteCmd(0XE1); // Set Gamma LCD_WriteData(0x00); LCD_WriteData(0x0E); LCD_WriteData(0x14); LCD_WriteData(0x03); LCD_WriteData(0x11); LCD_WriteData(0x07); LCD_WriteData(0x31); LCD_WriteData(0xC1); LCD_WriteData(0x48); LCD_WriteData(0x08); LCD_WriteData(0x0F); LCD_WriteData(0x0C); LCD_WriteData(0x31); LCD_WriteData(0x36); LCD_WriteData(0x0F); LCD_WriteCmd(0x11); // Exit Sleep Delay_10ms(12); LCD_WriteCmd(0x29); // Display on LCD_WriteCmd(0x2C); LCD_Clear(BLACK); LCD_SetBackLight(BLIGHT_DEFAULT); }
enum MENU_code fTest_Mgr( void ) { int fRedrawn = 0; static bool fFirstTime = 1; static s8 AUDIO_SpeakerOn_bak; static s8 AUDIO_Volume_bak; if ( fFirstTime ) { AUDIO_SpeakerOn_bak = AUDIO_SpeakerOn; AUDIO_Volume_bak = AUDIO_Volume; AUDIO_Volume = AUDIO_MIN_ATTENUATION; AUDIO_SpeakerOn = 1; UTIL_SetPll( SPEED_VERY_HIGH ); fFirstTime = 0; MenuFirstDisplay = 1; } // Hide menu. CurrentMenu = 0; fDisplayTime = 0; // force display time - battery status // Character magnify. DRAW_SetCharMagniCoeff( 2 ); // If screen orientation has changed, redraw screen. if ( MenuFirstDisplay == 0 ) { if ( LCD_GetScreenOrientation() != previous_Screen_Orientation ) { MenuFirstDisplay = 1; } } if ( MenuFirstDisplay ) { previous_Screen_Orientation = LCD_GetScreenOrientation(); POINTER_SetMode( POINTER_OFF ); LCD_SetRotateScreen( 0 ); LCD_SetScreenOrientation( V12 ); // Red LED blinks at high frequency. LED_Set( LED_RED, LED_BLINKING_HF ); // Green LED blinks at low frequency. LED_Set( LED_GREEN, LED_BLINKING_LF ); // Init daughter board LED DB_LED_Init(); // Draw a little message on the LCD screen. DRAW_SetDefaultColor(); DRAW_DisplayStringWithMode( 0, Screen_Height - 2 * Char_Height, "Hardware Test", ALL_SCREEN, INVERTED_TEXT, CENTER ); MenuFirstDisplay = 0; // Drawn that rectangle on the screen. LCD_FillRect_Circle( BAR_LEFT + 1, BAR_BOTTOM + 1, MAXLEVEL * WIDTH_SQUARE , WIDTH_SQUARE - 2, RGB_YELLOW ); LCD_DrawRect( BAR_LEFT, BAR_BOTTOM, MAXLEVEL * WIDTH_SQUARE + 2 , WIDTH_SQUARE, RGB_BLUE ); // Restrict the move of the pointer to a rectangle. POINTER_SetRect( BAR_LEFT + 1, BAR_BOTTOM + 1, MAXLEVEL * WIDTH_SQUARE - POINTER_WIDTH - 2, WIDTH_SQUARE - POINTER_WIDTH - 2 ); POINTER_SetMode( POINTER_ON ); fRedrawn = 1; RecordPlaySeq = -1; AUDIO_Welcome_Msg(); } // end FirstDisplay // The button is pushed, let's get out of here! if ( BUTTON_GetState() == BUTTON_PUSHED ) { int i; BUTTON_WaitForRelease(); // Reset CircleOS state. MENU_ClearCurrentCommand(); DRAW_SetDefaultColor(); DRAW_Clear(); POINTER_SetMode( POINTER_ON ); BUTTON_SetMode( BUTTON_ONOFF_FORMAIN ); POINTER_SetRectScreen(); DRAW_SetCharMagniCoeff( 1 ); // Reset backlight PWM rate to its default value. LCD_SetBackLight( 0 ); // Switch LEDs off. LED_Set( LED_RED, LED_OFF ); LED_Set( LED_GREEN, LED_OFF ); GPIO_WriteBit( GPIOx_DB_LED, GPIO_Pin_DB_LED1, Bit_SET ); GPIO_WriteBit( GPIOx_DB_LED, GPIO_Pin_DB_LED2, Bit_SET ); // No sound AUDIO_Playback_status = NO_SOUND; AUDIO_Recording_status = NO_RECORD; // Restore default mode AUDIO_SetMode( AUDIO_MODE, LG_8_BITS, FRQ_16KHZ, MONO ); // Restore the previous config AUDIO_SpeakerOn = AUDIO_SpeakerOn_bak; AUDIO_Volume = AUDIO_Volume_bak; fFirstTime = 1; for ( i = 0; i < MAXAPP; i++ ) { extern tMenuItem*(( *ApplicationTable )[] ); tMenuItem* curapp; unsigned addr; if (( *ApplicationTable )[ -i ] == APP_VOID ) //has been programmed { break; } else { addr = ( long unsigned )( *ApplicationTable )[ -i ] ; addr &= 0x00FFFFFF; addr |= 0x08000000; curapp = ( tMenuItem* ) addr; if ( !strcmp( curapp->Text, "COMMTEST" ) ) { LCD_SetOffset( OFFSET_ON ); CurrentCommand = curapp; CurrentMenu = 0; BUTTON_SetMode( BUTTON_ONOFF ); return CurrentCommand ->Fct_Init(); } } } LCD_SetRotateScreen( 1 ); LCD_SetScreenOrientation( previous_Screen_Orientation ); return MENU_LEAVE; } // Increment the backlight PWM. Current_CCR_BackLightStart += 0x800; //-- Parrot mode in order to test microphone and speaker if (( AUDIO_Playback_status == NO_SOUND ) && ( AUDIO_Recording_status == NO_RECORD ) ) { // Values -1 and 2 for RecordPlaySeq correspond to the first loop. // Recording requires a delay (internal to the Codec?) before // getting non-zero values. The first cycle provides this delay if (( RecordPlaySeq == 0 ) || ( RecordPlaySeq == -1 ) ) { // End of playback, launch the record if ( AUDIO_Playback_status == NO_SOUND ) { AUDIO_SetMode( VOICE_MODE, LG_16_BITS, FRQ_16KHZ, MONO ); // Take all the available memory for the record (= RAM_BASE - data size - 500 bytes for the stack) AUDIO_Record(( sound_type* ) RAM_BASE , (( CIRCLEOS_RAM_OFS ) / sizeof( voice_type ) ) - 500 ) ; } if ( RecordPlaySeq != -1 ) { // Red LED blinks at high frequency. LED_Set( LED_GREEN, LED_OFF ); LED_Set( LED_RED, LED_ON ); DRAW_DisplayStringWithMode( 0, 160, "** RECORDING **", ALL_SCREEN, NORMAL_TEXT, CENTER ); RecordPlaySeq = 1; } else RecordPlaySeq = 2; } else { if ( AUDIO_Recording_status == NO_RECORD ) { // End of recording, launch the playback AUDIO_SetMode( AUDIO_MODE, LG_16_BITS, FRQ_16KHZ, MONO ); AUDIO_Play(( sound_type* ) RAM_BASE , (( CIRCLEOS_RAM_OFS ) / sizeof( voice_type ) ) - 500 ) ; } if ( RecordPlaySeq != 2 ) { // Red LED blinks at high frequency. LED_Set( LED_GREEN, LED_ON ); LED_Set( LED_RED, LED_OFF ); DRAW_DisplayStringWithMode( 0, 160, "** PLAYING **", ALL_SCREEN, NORMAL_TEXT, CENTER ); } RecordPlaySeq = 0; } } if (( AUDIO_Recording_status == IS_RECORDING ) && (( AUDIO_RecordBuffer_GetStatus( 0 ) & HIGH_FULL ) ) ) AUDIO_Record_Stop(); // If backlight PWM is too high, restart with a lower value. if ( Current_CCR_BackLightStart > 0xF000 ) { Current_CCR_BackLightStart = 0x2000; } // Every 59th calls display battery voltage and replay melody sample. // Note: due to the fRedrawn == 0, the first time the % 59 == 0 // (when divider_coord is null), the code block isn't executed. if ((( menu_divider_coord++ % 37 ) == 0 ) && ( fRedrawn == 0 ) ) { char TextBuffer[5]; *TextBuffer = '%'; *( TextBuffer + 1 ) = 0; // YRT20080204 : to avoid memcpy DRAW_DisplayVbat( 20, 12 ); UTIL_uint2str( TextBuffer + 1, PWR_BatteryLevel, 3, 0 ); DRAW_DisplayString( 170, 12, TextBuffer, 4 ); } // Toggle daughter card leds if (( menu_divider_coord % 2 ) == 0 ) { GPIO_WriteBit( GPIOx_DB_LED, GPIO_Pin_DB_LED1, Bit_SET ); GPIO_WriteBit( GPIOx_DB_LED, GPIO_Pin_DB_LED2, Bit_RESET ); } else { GPIO_WriteBit( GPIOx_DB_LED, GPIO_Pin_DB_LED1, Bit_RESET ); GPIO_WriteBit( GPIOx_DB_LED, GPIO_Pin_DB_LED2, Bit_SET ); } return MENU_CONTINUE; }