diff options
Diffstat (limited to 'main/touch.c')
| -rw-r--r-- | main/touch.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/main/touch.c b/main/touch.c index 5a1eec9..a28d13e 100644 --- a/main/touch.c +++ b/main/touch.c | |||
| @@ -11,6 +11,7 @@ static const char *TAG = "touch"; | |||
| 11 | static i2c_master_bus_handle_t s_bus = NULL; | 11 | static i2c_master_bus_handle_t s_bus = NULL; |
| 12 | static i2c_master_dev_handle_t s_dev = NULL; | 12 | static i2c_master_dev_handle_t s_dev = NULL; |
| 13 | static bool s_initialized = false; | 13 | static bool s_initialized = false; |
| 14 | static int s_rotation = 0; | ||
| 14 | 15 | ||
| 15 | static const uint8_t s_read_cmd[11] = { | 16 | static const uint8_t s_read_cmd[11] = { |
| 16 | 0xb5, 0xab, 0xa5, 0x5a, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00 | 17 | 0xb5, 0xab, 0xa5, 0x5a, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00 |
| @@ -115,9 +116,33 @@ bool touch_read(touch_point_t *pt) { | |||
| 115 | } | 116 | } |
| 116 | 117 | ||
| 117 | touch_parse_raw(data, pt); | 118 | touch_parse_raw(data, pt); |
| 119 | |||
| 120 | if (pt->touched && s_rotation != 0) { | ||
| 121 | uint16_t raw_x = pt->x; | ||
| 122 | uint16_t raw_y = pt->y; | ||
| 123 | switch (s_rotation) { | ||
| 124 | case 1: | ||
| 125 | pt->x = raw_y; | ||
| 126 | pt->y = TOUCH_MAX_X - raw_x; | ||
| 127 | break; | ||
| 128 | case 2: | ||
| 129 | pt->x = TOUCH_MAX_X - raw_x; | ||
| 130 | pt->y = TOUCH_MAX_Y - raw_y; | ||
| 131 | break; | ||
| 132 | case 3: | ||
| 133 | pt->x = TOUCH_MAX_Y - raw_y; | ||
| 134 | pt->y = raw_x; | ||
| 135 | break; | ||
| 136 | } | ||
| 137 | } | ||
| 138 | |||
| 118 | return pt->touched; | 139 | return pt->touched; |
| 119 | } | 140 | } |
| 120 | 141 | ||
| 142 | void touch_set_rotation(int rotation) { | ||
| 143 | s_rotation = rotation; | ||
| 144 | } | ||
| 145 | |||
| 121 | void touch_deinit(void) { | 146 | void touch_deinit(void) { |
| 122 | if (s_dev) { | 147 | if (s_dev) { |
| 123 | i2c_master_bus_rm_device(s_dev); | 148 | i2c_master_bus_rm_device(s_dev); |