Touch panel library for GR-PEACH LCD Shield.

Dependents:   GR-PEACH_LCD_shield_touch_sample LCD_shield_config

Committer:
dkato
Date:
Wed Jun 29 03:28:06 2016 +0000
Revision:
0:da3d7ba2674b
first commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dkato 0:da3d7ba2674b 1 /* mbed Microcontroller Library
dkato 0:da3d7ba2674b 2 * Copyright (C) 2016 Renesas Electronics Corporation. All rights reserved.
dkato 0:da3d7ba2674b 3 *
dkato 0:da3d7ba2674b 4 * Licensed under the Apache License, Version 2.0 (the "License");
dkato 0:da3d7ba2674b 5 * you may not use this file except in compliance with the License.
dkato 0:da3d7ba2674b 6 * You may obtain a copy of the License at
dkato 0:da3d7ba2674b 7 *
dkato 0:da3d7ba2674b 8 * http://www.apache.org/licenses/LICENSE-2.0
dkato 0:da3d7ba2674b 9 *
dkato 0:da3d7ba2674b 10 * Unless required by applicable law or agreed to in writing, software
dkato 0:da3d7ba2674b 11 * distributed under the License is distributed on an "AS IS" BASIS,
dkato 0:da3d7ba2674b 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
dkato 0:da3d7ba2674b 13 * See the License for the specific language governing permissions and
dkato 0:da3d7ba2674b 14 * limitations under the License.
dkato 0:da3d7ba2674b 15 */
dkato 0:da3d7ba2674b 16
dkato 0:da3d7ba2674b 17 #include "TouchKey_7_1inch.h"
dkato 0:da3d7ba2674b 18
dkato 0:da3d7ba2674b 19 TouchKey_7_1inch::TouchKey_7_1inch(PinName tprst, PinName tpint, PinName sda, PinName scl) :
dkato 0:da3d7ba2674b 20 TouchKey(tprst, tpint), i2c(sda, scl) {
dkato 0:da3d7ba2674b 21 }
dkato 0:da3d7ba2674b 22
dkato 0:da3d7ba2674b 23 int TouchKey_7_1inch::GetMaxTouchNum(void) {
dkato 0:da3d7ba2674b 24 return 2;
dkato 0:da3d7ba2674b 25 }
dkato 0:da3d7ba2674b 26
dkato 0:da3d7ba2674b 27 int TouchKey_7_1inch::GetCoordinates(int touch_buff_num, touch_pos_t * p_touch) {
dkato 0:da3d7ba2674b 28 char buf[10];
dkato 0:da3d7ba2674b 29 stx_report_data_t *pdata;
dkato 0:da3d7ba2674b 30 touch_pos_t * wk_touch;
dkato 0:da3d7ba2674b 31 int count = 0;
dkato 0:da3d7ba2674b 32 int i;
dkato 0:da3d7ba2674b 33 int read_size;
dkato 0:da3d7ba2674b 34
dkato 0:da3d7ba2674b 35 if (touch_buff_num > GetMaxTouchNum()) {
dkato 0:da3d7ba2674b 36 touch_buff_num = GetMaxTouchNum();
dkato 0:da3d7ba2674b 37 }
dkato 0:da3d7ba2674b 38 if (touch_buff_num < 2) {
dkato 0:da3d7ba2674b 39 read_size = 6;
dkato 0:da3d7ba2674b 40 } else {
dkato 0:da3d7ba2674b 41 read_size = 10;
dkato 0:da3d7ba2674b 42 }
dkato 0:da3d7ba2674b 43
dkato 0:da3d7ba2674b 44 if (p_touch != NULL) {
dkato 0:da3d7ba2674b 45 for (i = 0; i < touch_buff_num; i++) {
dkato 0:da3d7ba2674b 46 wk_touch = &p_touch[i];
dkato 0:da3d7ba2674b 47 wk_touch->x = 0;
dkato 0:da3d7ba2674b 48 wk_touch->y = 0;
dkato 0:da3d7ba2674b 49 wk_touch->valid = false;
dkato 0:da3d7ba2674b 50 }
dkato 0:da3d7ba2674b 51 if (i2c.read((0x55 << 1), buf, read_size) == 0) {
dkato 0:da3d7ba2674b 52 pdata = (stx_report_data_t *)buf;
dkato 0:da3d7ba2674b 53 if (pdata->fingers) {
dkato 0:da3d7ba2674b 54 for (i = 0; i < touch_buff_num; i++) {
dkato 0:da3d7ba2674b 55 if (pdata->xyz_data[i].valid) {
dkato 0:da3d7ba2674b 56 wk_touch = &p_touch[i];
dkato 0:da3d7ba2674b 57 wk_touch->x = (pdata->xyz_data[i].x_h << 8) | pdata->xyz_data[i].x_l;
dkato 0:da3d7ba2674b 58 wk_touch->y = (pdata->xyz_data[i].y_h << 8) | pdata->xyz_data[i].y_l;
dkato 0:da3d7ba2674b 59 wk_touch->valid = true;
dkato 0:da3d7ba2674b 60 count++;
dkato 0:da3d7ba2674b 61 }
dkato 0:da3d7ba2674b 62 }
dkato 0:da3d7ba2674b 63 }
dkato 0:da3d7ba2674b 64 }
dkato 0:da3d7ba2674b 65 }
dkato 0:da3d7ba2674b 66
dkato 0:da3d7ba2674b 67 return count;
dkato 0:da3d7ba2674b 68 }
dkato 0:da3d7ba2674b 69
dkato 0:da3d7ba2674b 70