Touch panel library for GR-PEACH LCD Shield.
Dependents: GR-PEACH_LCD_shield_touch_sample LCD_shield_config
TouchKey_RSK_TFT.cpp@1:538027089976, 2016-09-27 (annotated)
- Committer:
- dkato
- Date:
- Tue Sep 27 12:36:07 2016 +0000
- Revision:
- 1:538027089976
Add LCD type RSK TFT.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dkato | 1:538027089976 | 1 | /* mbed Microcontroller Library |
dkato | 1:538027089976 | 2 | * Copyright (C) 2016 Renesas Electronics Corporation. All rights reserved. |
dkato | 1:538027089976 | 3 | * |
dkato | 1:538027089976 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
dkato | 1:538027089976 | 5 | * you may not use this file except in compliance with the License. |
dkato | 1:538027089976 | 6 | * You may obtain a copy of the License at |
dkato | 1:538027089976 | 7 | * |
dkato | 1:538027089976 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
dkato | 1:538027089976 | 9 | * |
dkato | 1:538027089976 | 10 | * Unless required by applicable law or agreed to in writing, software |
dkato | 1:538027089976 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
dkato | 1:538027089976 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
dkato | 1:538027089976 | 13 | * See the License for the specific language governing permissions and |
dkato | 1:538027089976 | 14 | * limitations under the License. |
dkato | 1:538027089976 | 15 | */ |
dkato | 1:538027089976 | 16 | |
dkato | 1:538027089976 | 17 | #include "TouchKey_RSK_TFT.h" |
dkato | 1:538027089976 | 18 | |
dkato | 1:538027089976 | 19 | TouchKey_RSK_TFT::TouchKey_RSK_TFT(PinName tprst, PinName tpint, PinName sda, PinName scl) : |
dkato | 1:538027089976 | 20 | TouchKey(tprst, tpint), i2c(sda, scl) { |
dkato | 1:538027089976 | 21 | } |
dkato | 1:538027089976 | 22 | |
dkato | 1:538027089976 | 23 | int TouchKey_RSK_TFT::GetMaxTouchNum(void) { |
dkato | 1:538027089976 | 24 | return 5; |
dkato | 1:538027089976 | 25 | } |
dkato | 1:538027089976 | 26 | |
dkato | 1:538027089976 | 27 | int TouchKey_RSK_TFT::GetCoordinates(int touch_buff_num, touch_pos_t * p_touch) { |
dkato | 1:538027089976 | 28 | char buf[32]; |
dkato | 1:538027089976 | 29 | uint32_t wk_x; |
dkato | 1:538027089976 | 30 | uint32_t wk_y; |
dkato | 1:538027089976 | 31 | touch_pos_t * wk_touch; |
dkato | 1:538027089976 | 32 | int count = 0; |
dkato | 1:538027089976 | 33 | int i; |
dkato | 1:538027089976 | 34 | int read_size; |
dkato | 1:538027089976 | 35 | |
dkato | 1:538027089976 | 36 | if (touch_buff_num > GetMaxTouchNum()) { |
dkato | 1:538027089976 | 37 | touch_buff_num = GetMaxTouchNum(); |
dkato | 1:538027089976 | 38 | } |
dkato | 1:538027089976 | 39 | read_size = 2 + 6 * touch_buff_num; |
dkato | 1:538027089976 | 40 | |
dkato | 1:538027089976 | 41 | if (p_touch != NULL) { |
dkato | 1:538027089976 | 42 | for (i = 0; i < touch_buff_num; i++) { |
dkato | 1:538027089976 | 43 | wk_touch = &p_touch[i]; |
dkato | 1:538027089976 | 44 | wk_touch->x = 0; |
dkato | 1:538027089976 | 45 | wk_touch->y = 0; |
dkato | 1:538027089976 | 46 | wk_touch->valid = false; |
dkato | 1:538027089976 | 47 | } |
dkato | 1:538027089976 | 48 | if (i2c.read((0x38 << 1), buf, read_size) == 0) { |
dkato | 1:538027089976 | 49 | for (i = 0; i < touch_buff_num; i++) { |
dkato | 1:538027089976 | 50 | if (buf[2] > i) { |
dkato | 1:538027089976 | 51 | wk_touch = &p_touch[i]; |
dkato | 1:538027089976 | 52 | wk_x = (((uint32_t)buf[3 + (6 * i)] & 0x0F) << 8) | buf[4 + (6 * i)]; |
dkato | 1:538027089976 | 53 | if (wk_x < 800) { |
dkato | 1:538027089976 | 54 | wk_touch->x = 800 - wk_x; |
dkato | 1:538027089976 | 55 | } else { |
dkato | 1:538027089976 | 56 | wk_touch->x = 0; |
dkato | 1:538027089976 | 57 | } |
dkato | 1:538027089976 | 58 | wk_y = (((uint32_t)buf[5 + (6 * i)] & 0x0F) << 8) | buf[6 + (6 * i)]; |
dkato | 1:538027089976 | 59 | if (wk_y < 480) { |
dkato | 1:538027089976 | 60 | wk_touch->y = 480 - wk_y; |
dkato | 1:538027089976 | 61 | } else { |
dkato | 1:538027089976 | 62 | wk_touch->y = 0; |
dkato | 1:538027089976 | 63 | } |
dkato | 1:538027089976 | 64 | wk_touch->valid = 1; |
dkato | 1:538027089976 | 65 | count++; |
dkato | 1:538027089976 | 66 | } |
dkato | 1:538027089976 | 67 | } |
dkato | 1:538027089976 | 68 | } |
dkato | 1:538027089976 | 69 | } |
dkato | 1:538027089976 | 70 | |
dkato | 1:538027089976 | 71 | return count; |
dkato | 1:538027089976 | 72 | } |
dkato | 1:538027089976 | 73 | |
dkato | 1:538027089976 | 74 |