Touch panel sample for GR-PEACH LCD Shield.

Dependencies:   GR-PEACH_video LCD_shield_config TouchKey_LCD_shield mbed-rtos mbed

What is this ?

Information on a touch panel is shown to a screen. The touch location of the blue and the 2nd point becomes pink in the 1st touch location in case of a multi-touch.
While touching the screen, a white square in the upper left corner of the screen will be displayed.
Touch information is being output in printf. When doing terminal designation, please set 921600 as a baud rate.

LCD shield can be changed by changing the following macro.

LCD_shield_config.h

/**** User Selection *********/
#define LCD_TYPE                            (0)  // 0: 4.3inch  1:7.1inch
/*****************************/


Composition

GR-PEACH, GR-PEACH 4.3 inch LCD Shield or GR-PEACH 7.1 inch LCD Shield.


概要

タッチパネルの情報を画面に表示します。マルチタッチの場合は1点目のタッチ位置は青、2点目のタッチ位置はピンクになります。
画面がタッチされている間、画面左上に白い四角が表示されます。
printfでもタッチ情報を出力しています。ターミナル表示を行う際は、ボーレートに921600を設定してください。

下記のマクロを変更することで、LCD shieldの切り替えができます。

LCD_shield_config.h

/**** User Selection *********/
#define LCD_TYPE                            (0)  // 0: 4.3inch  1:7.1inch
/*****************************/


構成

GR-PEACH、GR-PEACH 4.3 inch LCD Shield または GR-PEACH 7.1 inch LCD Shield

Committer:
dkato
Date:
Wed Jun 29 03:31:37 2016 +0000
Revision:
0:a3f0de3891b2
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:a3f0de3891b2 1 #include "mbed.h"
dkato 0:a3f0de3891b2 2 #include "DisplayBace.h"
dkato 0:a3f0de3891b2 3 #include "rtos.h"
dkato 0:a3f0de3891b2 4 #include "LCD_shield_config.h"
dkato 0:a3f0de3891b2 5 #if (LCD_TYPE == 0)
dkato 0:a3f0de3891b2 6 #include "TouchKey_4_3inch.h"
dkato 0:a3f0de3891b2 7 #define TouckKey_LCD_shield TouchKey_4_3inch
dkato 0:a3f0de3891b2 8 #else
dkato 0:a3f0de3891b2 9 #include "TouchKey_7_1inch.h"
dkato 0:a3f0de3891b2 10 #define TouckKey_LCD_shield TouchKey_7_1inch
dkato 0:a3f0de3891b2 11 #endif
dkato 0:a3f0de3891b2 12
dkato 0:a3f0de3891b2 13 /* FRAME BUFFER Parameter */
dkato 0:a3f0de3891b2 14 #define FRAME_BUFFER_BYTE_PER_PIXEL (2)
dkato 0:a3f0de3891b2 15 #define FRAME_BUFFER_STRIDE (((LCD_PIXEL_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL) + 31u) & ~31u)
dkato 0:a3f0de3891b2 16
dkato 0:a3f0de3891b2 17 #define TOUCH_NUM (2)
dkato 0:a3f0de3891b2 18 #define DROW_POINT (3)
dkato 0:a3f0de3891b2 19
dkato 0:a3f0de3891b2 20 DisplayBase Display;
dkato 0:a3f0de3891b2 21 DigitalOut lcd_pwon(P7_15);
dkato 0:a3f0de3891b2 22 DigitalOut lcd_blon(P8_1);
dkato 0:a3f0de3891b2 23 PwmOut lcd_cntrst(P8_15);
dkato 0:a3f0de3891b2 24 Serial pc(USBTX, USBRX);
dkato 0:a3f0de3891b2 25 Semaphore sem_touch_int(0);
dkato 0:a3f0de3891b2 26 TouckKey_LCD_shield touch(P4_0, P2_13, I2C_SDA, I2C_SCL);
dkato 0:a3f0de3891b2 27
dkato 0:a3f0de3891b2 28 static uint8_t user_frame_buffer[FRAME_BUFFER_STRIDE * LCD_PIXEL_HEIGHT]__attribute((section("NC_BSS"),aligned(32))); /* 32 bytes aligned */
dkato 0:a3f0de3891b2 29 static volatile int32_t vsync_count = 0;
dkato 0:a3f0de3891b2 30
dkato 0:a3f0de3891b2 31 static void IntCallbackFunc_Vsync(DisplayBase::int_type_t int_type) {
dkato 0:a3f0de3891b2 32 /* Interrupt callback function for Vsync interruption */
dkato 0:a3f0de3891b2 33 if (vsync_count > 0) {
dkato 0:a3f0de3891b2 34 vsync_count--;
dkato 0:a3f0de3891b2 35 }
dkato 0:a3f0de3891b2 36 }
dkato 0:a3f0de3891b2 37
dkato 0:a3f0de3891b2 38 static void Wait_Vsync(const int32_t wait_count) {
dkato 0:a3f0de3891b2 39 /* Wait for the specified number of times Vsync occurs */
dkato 0:a3f0de3891b2 40 vsync_count = wait_count;
dkato 0:a3f0de3891b2 41 while (vsync_count > 0) {
dkato 0:a3f0de3891b2 42 /* Do nothing */
dkato 0:a3f0de3891b2 43 }
dkato 0:a3f0de3891b2 44 }
dkato 0:a3f0de3891b2 45
dkato 0:a3f0de3891b2 46 static void Init_LCD_Display(void) {
dkato 0:a3f0de3891b2 47 /* Create DisplayBase object */
dkato 0:a3f0de3891b2 48 DisplayBase::graphics_error_t error;
dkato 0:a3f0de3891b2 49 DisplayBase::lcd_config_t lcd_config;
dkato 0:a3f0de3891b2 50 PinName lvds_pin[8] = {
dkato 0:a3f0de3891b2 51 /* data pin */
dkato 0:a3f0de3891b2 52 P5_7, P5_6, P5_5, P5_4, P5_3, P5_2, P5_1, P5_0
dkato 0:a3f0de3891b2 53 };
dkato 0:a3f0de3891b2 54
dkato 0:a3f0de3891b2 55 lcd_pwon = 0;
dkato 0:a3f0de3891b2 56 lcd_blon = 0;
dkato 0:a3f0de3891b2 57 Thread::wait(100);
dkato 0:a3f0de3891b2 58 lcd_pwon = 1;
dkato 0:a3f0de3891b2 59 lcd_blon = 1;
dkato 0:a3f0de3891b2 60 Thread::wait(100);
dkato 0:a3f0de3891b2 61 lcd_cntrst.write(1.0);
dkato 0:a3f0de3891b2 62
dkato 0:a3f0de3891b2 63 /* Graphics initialization process */
dkato 0:a3f0de3891b2 64 GetLcdConfig(&lcd_config);
dkato 0:a3f0de3891b2 65 error = Display.Graphics_init(&lcd_config);
dkato 0:a3f0de3891b2 66 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:a3f0de3891b2 67 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:a3f0de3891b2 68 while (1);
dkato 0:a3f0de3891b2 69 }
dkato 0:a3f0de3891b2 70
dkato 0:a3f0de3891b2 71 /* Interrupt callback function setting (Vsync signal output from scaler 0) */
dkato 0:a3f0de3891b2 72 error = Display.Graphics_Irq_Handler_Set(DisplayBase::INT_TYPE_S0_LO_VSYNC, 0, IntCallbackFunc_Vsync);
dkato 0:a3f0de3891b2 73 if (error != DisplayBase::GRAPHICS_OK) {
dkato 0:a3f0de3891b2 74 printf("Line %d, error %d\n", __LINE__, error);
dkato 0:a3f0de3891b2 75 while (1);
dkato 0:a3f0de3891b2 76 }
dkato 0:a3f0de3891b2 77
dkato 0:a3f0de3891b2 78 Display.Graphics_Lvds_Port_Init(lvds_pin, 8);
dkato 0:a3f0de3891b2 79 }
dkato 0:a3f0de3891b2 80
dkato 0:a3f0de3891b2 81 static void drow_touch_pos(int id, int x, int y) {
dkato 0:a3f0de3891b2 82 int idx_base;
dkato 0:a3f0de3891b2 83 int wk_idx;
dkato 0:a3f0de3891b2 84 int i;
dkato 0:a3f0de3891b2 85 int j;
dkato 0:a3f0de3891b2 86 uint8_t coller_pix[2];
dkato 0:a3f0de3891b2 87
dkato 0:a3f0de3891b2 88 if ((x - (DROW_POINT / 2)) >= 0) {
dkato 0:a3f0de3891b2 89 x -= (DROW_POINT / 2);
dkato 0:a3f0de3891b2 90 }
dkato 0:a3f0de3891b2 91 if (x > (LCD_PIXEL_WIDTH - DROW_POINT)) {
dkato 0:a3f0de3891b2 92 x = (LCD_PIXEL_WIDTH - DROW_POINT);
dkato 0:a3f0de3891b2 93 }
dkato 0:a3f0de3891b2 94 if ((y - (DROW_POINT / 2)) >= 0) {
dkato 0:a3f0de3891b2 95 y -= (DROW_POINT / 2);
dkato 0:a3f0de3891b2 96 }
dkato 0:a3f0de3891b2 97 if (y > (LCD_PIXEL_HEIGHT - DROW_POINT)) {
dkato 0:a3f0de3891b2 98 y = (LCD_PIXEL_HEIGHT - DROW_POINT);
dkato 0:a3f0de3891b2 99 }
dkato 0:a3f0de3891b2 100 idx_base = (x + (LCD_PIXEL_WIDTH * y)) * FRAME_BUFFER_BYTE_PER_PIXEL;
dkato 0:a3f0de3891b2 101
dkato 0:a3f0de3891b2 102 if (id == 0) {
dkato 0:a3f0de3891b2 103 coller_pix[0] = 0xDD;
dkato 0:a3f0de3891b2 104 coller_pix[1] = 0x9E;
dkato 0:a3f0de3891b2 105 } else {
dkato 0:a3f0de3891b2 106 coller_pix[0] = 0x34;
dkato 0:a3f0de3891b2 107 coller_pix[1] = 0xDB;
dkato 0:a3f0de3891b2 108 }
dkato 0:a3f0de3891b2 109
dkato 0:a3f0de3891b2 110 for (i = 0; i < DROW_POINT; i++) {
dkato 0:a3f0de3891b2 111 wk_idx = idx_base + (LCD_PIXEL_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL * i);
dkato 0:a3f0de3891b2 112 for (j = 0; j < DROW_POINT; j++) {
dkato 0:a3f0de3891b2 113 user_frame_buffer[wk_idx++] = coller_pix[0];
dkato 0:a3f0de3891b2 114 user_frame_buffer[wk_idx++] = coller_pix[1];
dkato 0:a3f0de3891b2 115 }
dkato 0:a3f0de3891b2 116 }
dkato 0:a3f0de3891b2 117 }
dkato 0:a3f0de3891b2 118
dkato 0:a3f0de3891b2 119 static void drow_touch_keyonoff(int id, bool onoff) {
dkato 0:a3f0de3891b2 120 int idx_base;
dkato 0:a3f0de3891b2 121 int wk_idx;
dkato 0:a3f0de3891b2 122 int i;
dkato 0:a3f0de3891b2 123 int j;
dkato 0:a3f0de3891b2 124 uint8_t coller_pix[2];
dkato 0:a3f0de3891b2 125
dkato 0:a3f0de3891b2 126 if (id == 0) {
dkato 0:a3f0de3891b2 127 idx_base = 0;
dkato 0:a3f0de3891b2 128 } else {
dkato 0:a3f0de3891b2 129 idx_base = 5 * FRAME_BUFFER_BYTE_PER_PIXEL;
dkato 0:a3f0de3891b2 130 }
dkato 0:a3f0de3891b2 131
dkato 0:a3f0de3891b2 132 if (onoff == false) {
dkato 0:a3f0de3891b2 133 coller_pix[0] = 0x00;
dkato 0:a3f0de3891b2 134 coller_pix[1] = 0x00;
dkato 0:a3f0de3891b2 135 } else {
dkato 0:a3f0de3891b2 136 coller_pix[0] = 0xff;
dkato 0:a3f0de3891b2 137 coller_pix[1] = 0xff;
dkato 0:a3f0de3891b2 138 }
dkato 0:a3f0de3891b2 139
dkato 0:a3f0de3891b2 140 for (i = 0; i < 5; i++) {
dkato 0:a3f0de3891b2 141 wk_idx = idx_base + (LCD_PIXEL_WIDTH * FRAME_BUFFER_BYTE_PER_PIXEL * i);
dkato 0:a3f0de3891b2 142 for (j = 0; j < 5; j++) {
dkato 0:a3f0de3891b2 143 user_frame_buffer[wk_idx++] = coller_pix[0];
dkato 0:a3f0de3891b2 144 user_frame_buffer[wk_idx++] = coller_pix[1];
dkato 0:a3f0de3891b2 145 }
dkato 0:a3f0de3891b2 146 }
dkato 0:a3f0de3891b2 147 }
dkato 0:a3f0de3891b2 148
dkato 0:a3f0de3891b2 149 static void touch_int_callback(void) {
dkato 0:a3f0de3891b2 150 sem_touch_int.release();
dkato 0:a3f0de3891b2 151 }
dkato 0:a3f0de3891b2 152
dkato 0:a3f0de3891b2 153 int main(void) {
dkato 0:a3f0de3891b2 154 // Change the baud rate of the printf()
dkato 0:a3f0de3891b2 155 pc.baud(921600);
dkato 0:a3f0de3891b2 156
dkato 0:a3f0de3891b2 157 // Initialization of LCD
dkato 0:a3f0de3891b2 158 DisplayBase::rect_t rect;
dkato 0:a3f0de3891b2 159
dkato 0:a3f0de3891b2 160 Init_LCD_Display();
dkato 0:a3f0de3891b2 161 memset(user_frame_buffer, 0, sizeof(user_frame_buffer));
dkato 0:a3f0de3891b2 162 rect.vs = 0;
dkato 0:a3f0de3891b2 163 rect.vw = LCD_PIXEL_HEIGHT;
dkato 0:a3f0de3891b2 164 rect.hs = 0;
dkato 0:a3f0de3891b2 165 rect.hw = LCD_PIXEL_WIDTH;
dkato 0:a3f0de3891b2 166 Display.Graphics_Read_Setting(
dkato 0:a3f0de3891b2 167 DisplayBase::GRAPHICS_LAYER_0,
dkato 0:a3f0de3891b2 168 (void *)user_frame_buffer,
dkato 0:a3f0de3891b2 169 FRAME_BUFFER_STRIDE,
dkato 0:a3f0de3891b2 170 DisplayBase::GRAPHICS_FORMAT_RGB565,
dkato 0:a3f0de3891b2 171 DisplayBase::WR_RD_WRSWA_32_16BIT,
dkato 0:a3f0de3891b2 172 &rect
dkato 0:a3f0de3891b2 173 );
dkato 0:a3f0de3891b2 174 Wait_Vsync(2);
dkato 0:a3f0de3891b2 175 Display.Graphics_Start(DisplayBase::GRAPHICS_LAYER_0);
dkato 0:a3f0de3891b2 176
dkato 0:a3f0de3891b2 177 // Touch panel processing
dkato 0:a3f0de3891b2 178 TouchKey::touch_pos_t touch_pos[TOUCH_NUM];
dkato 0:a3f0de3891b2 179 int touch_num = 0;
dkato 0:a3f0de3891b2 180 int touch_num_last = 0;
dkato 0:a3f0de3891b2 181 int i;
dkato 0:a3f0de3891b2 182
dkato 0:a3f0de3891b2 183 touch.SetCallback(&touch_int_callback);
dkato 0:a3f0de3891b2 184 touch.Reset();
dkato 0:a3f0de3891b2 185 while (1) {
dkato 0:a3f0de3891b2 186 sem_touch_int.wait();
dkato 0:a3f0de3891b2 187 touch_num = touch.GetCoordinates(TOUCH_NUM, touch_pos);
dkato 0:a3f0de3891b2 188 if ((touch_num != 0) && (touch_num_last == 0)) {
dkato 0:a3f0de3891b2 189 memset(user_frame_buffer, 0, sizeof(user_frame_buffer));
dkato 0:a3f0de3891b2 190 }
dkato 0:a3f0de3891b2 191 for (i = 0; i < TOUCH_NUM; i ++) {
dkato 0:a3f0de3891b2 192 printf("{valid=%d,x=%d,y=%d} ", touch_pos[i].valid, touch_pos[i].x, touch_pos[i].y);
dkato 0:a3f0de3891b2 193 drow_touch_keyonoff(i, touch_pos[i].valid);
dkato 0:a3f0de3891b2 194 if (touch_pos[i].valid) {
dkato 0:a3f0de3891b2 195 drow_touch_pos(i, touch_pos[i].x, touch_pos[i].y);
dkato 0:a3f0de3891b2 196 }
dkato 0:a3f0de3891b2 197 }
dkato 0:a3f0de3891b2 198 printf("\n");
dkato 0:a3f0de3891b2 199 touch_num_last = touch_num;
dkato 0:a3f0de3891b2 200 }
dkato 0:a3f0de3891b2 201 }