Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: AsciiFont GR-PEACH_video GraphicsFramework LCD_shield_config R_BSP TLV320_RBSP mbed-rtos mbed
LCD.cpp
00001 #include "LCD.hpp" 00002 #include "rtos.h" 00003 00004 #define GRAPHICS_FORMAT (DisplayBase::GRAPHICS_FORMAT_RGB565) 00005 #define WR_RD_WRSWA (DisplayBase::WR_RD_WRSWA_32_16BIT) 00006 00007 volatile int32_t LCD::vsync_count = 0; 00008 uint8_t LCD::user_frame_buffer1[]; 00009 uint8_t LCD::user_frame_buffer2[]; 00010 frame_buffer_t LCD::frame_buffer_info; 00011 LCD LCD::instance; 00012 00013 void LCD::IntCallbackFunc_LoVsync(DisplayBase::int_type_t MBED_UNUSED int_type) { 00014 /* Interrupt callback function for Vsync interruption */ 00015 if (vsync_count > 0) { 00016 vsync_count--; 00017 } 00018 } 00019 00020 LCD::LCD() : lcd_pwon(P7_15), lcd_blon(P8_1), lcd_cntrst(P8_15) 00021 { 00022 } 00023 00024 void LCD::start() 00025 { 00026 DisplayBase::graphics_error_t error; 00027 DisplayBase::lcd_config_t lcd_config; 00028 PinName lvds_pin[8] = { 00029 /* data pin */ 00030 P5_7, P5_6, P5_5, P5_4, P5_3, P5_2, P5_1, P5_0 00031 }; 00032 00033 lcd_pwon = 0; 00034 lcd_blon = 0; 00035 rtos::Thread::wait(100); 00036 lcd_pwon = 1; 00037 lcd_blon = 1; 00038 00039 Display.Graphics_Lvds_Port_Init(lvds_pin, 8); 00040 00041 /* Graphics initialization process */ 00042 lcd_config = LcdCfgTbl_LCD_shield; 00043 error = Display.Graphics_init(&lcd_config); 00044 if (error != DisplayBase::GRAPHICS_OK) { 00045 printf("Line %d, error %d\n", __LINE__, error); 00046 mbed_die(); 00047 } 00048 00049 /* Interrupt callback function setting (Vsync signal output from scaler 0) */ 00050 error = Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_LO_VSYNC, 0, LCD::IntCallbackFunc_LoVsync); 00051 if (error != DisplayBase::GRAPHICS_OK) { 00052 printf("Line %d, error %d\n", __LINE__, error); 00053 mbed_die(); 00054 } 00055 00056 memset(user_frame_buffer1, 0, sizeof(user_frame_buffer1)); 00057 memset(user_frame_buffer2, 0, sizeof(user_frame_buffer2)); 00058 frame_buffer_info.buffer_address[0] = user_frame_buffer1; 00059 frame_buffer_info.buffer_address[1] = user_frame_buffer2; 00060 frame_buffer_info.buffer_count = 2; 00061 frame_buffer_info.show_buffer_index = 0; 00062 frame_buffer_info.draw_buffer_index = 0; 00063 frame_buffer_info.width = LCD_PIXEL_WIDTH; 00064 frame_buffer_info.byte_per_pixel = FRAME_BUFFER_BYTE_PER_PIXEL; 00065 frame_buffer_info.stride = LCD_PIXEL_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL; 00066 frame_buffer_info.height = LCD_PIXEL_HEIGHT; 00067 frame_buffer_info.pixel_format = PIXEL_FORMAT_RGB565; 00068 00069 DisplayBase::rect_t rect; 00070 00071 rect.vs = 0; 00072 rect.vw = LCD_PIXEL_HEIGHT; 00073 rect.hs = 0; 00074 rect.hw = LCD_PIXEL_WIDTH; 00075 Display.Graphics_Read_Setting(DisplayBase::GRAPHICS_LAYER_0, (void *)frame_buffer_info.buffer_address[0], 00076 FRAME_BUFFER_STRIDE, GRAPHICS_FORMAT, WR_RD_WRSWA, &rect); 00077 Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_0); 00078 00079 rtos::Thread::wait(200); 00080 lcd_cntrst.period_us(491); 00081 lcd_cntrst = 0.1; 00082 00083 errnum_t err; 00084 Canvas2D_ContextConfigClass config; 00085 config.frame_buffer = &frame_buffer_info; 00086 canvas2d = R_RGA_New_Canvas2D_ContextClass(config); 00087 err = R_OSPL_GetErrNum(); 00088 if (err != 0) { 00089 printf("Line %d, error %d\n", __LINE__, err); 00090 while (1); 00091 } 00092 00093 graphics = canvas2d.c_LanguageContext; 00094 } 00095 00096 void LCD::stop() 00097 { 00098 lcd_pwon = 0; 00099 lcd_blon = 0; 00100 } 00101 00102 void LCD::Wait_Vsync(const int32_t wait_count) 00103 { 00104 /* Wait for the specified number of times Vsync occurs */ 00105 vsync_count = wait_count; 00106 while (vsync_count > 0) { 00107 /* Do nothing */ 00108 } 00109 } 00110 00111 void LCD::Swap_FrameBuffer() 00112 { 00113 if (frame_buffer_info.draw_buffer_index == 1) { 00114 frame_buffer_info.draw_buffer_index = 0; 00115 } else { 00116 frame_buffer_info.draw_buffer_index = 1; 00117 } 00118 } 00119 00120 void LCD::Update_LCD_Display() 00121 { 00122 Display.Graphics_Read_Change(DisplayBase::GRAPHICS_LAYER_0, 00123 (void *)frame_buffer_info.buffer_address[frame_buffer_info.draw_buffer_index]); 00124 Wait_Vsync(1); 00125 } 00126
Generated on Fri Jul 15 2022 12:17:04 by
1.7.2