1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 22:38:08 +00:00

feat(core/prodtest): add more touch layer tests

This commit is contained in:
tychovrahe 2024-07-29 13:13:35 +02:00 committed by TychoVrahe
parent fbf380caba
commit e30fe7769a
3 changed files with 184 additions and 5 deletions

View File

@ -0,0 +1 @@
Added TOUCH_CUSTOM and TOUCH_IDLE commands

View File

@ -88,7 +88,7 @@ OK
``` ```
### TOUCH ### TOUCH
The `TOUCH` command test the functionality of the display's touch screen. The `TOUCH` command tests the functionality of the display's touch screen.
It draws a filled rectangle in one of the four display quadrants and waits for user interaction. It draws a filled rectangle in one of the four display quadrants and waits for user interaction.
The command requires two input parameters: The command requires two input parameters:
@ -106,6 +106,48 @@ TOUCH 09
OK 50 90 OK 50 90
``` ```
### TOUCH_CUSTOM
The `TOUCH_CUSTOM` command tests the functionality of the display's touch screen.
It draws a filled rectangle on custom coordinates and waits for user interaction.
The command requires five input parameters:
* X position of the top-left corner of the rectangle
* Y position of the top-left corner of the rectangle
* Width of the rectangle
* Height of the rectangle
* The timeout in seconds
If the display is not touched within the specified timeout, the command will return an `ERROR TIMEOUT`.
The device report touch events, coordinates and timestamps (in ms), correctness of the touch point is not checked and is left to the test equipment.
The test ends with first lift-up event.
Example (to draw a 100x100 rectangle in the top-left (10,10) position and wait for 15 seconds for touch input):
```
TOUCH_CUSTOM 10 10 100 100 15
TOUCH D 69 35 357300
TOUCH U 69 35 357328
OK
```
### TOUCH_IDLE
The `TOUCH_IDLE` command tests the functionality of the display's touch screen.
It waits for a specific time period without any touch input.
The command requires one input parameter:
* The timeout in seconds
If a touch activity is detected within the specified timeout, the command will return an `ERROR TOUCH DETECTED`.
Example - wait ten seconds for no touch input:
```
TOUCH_IDLE 10
OK
```
### SENS ### SENS
The `SENS` command is used to evaluating the touch screen sensitivity. The `SENS` command is used to evaluating the touch screen sensitivity.
It draws a filled box around the touch coordinates. It draws a filled box around the touch coordinates.

View File

@ -17,6 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <ctype.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
@ -160,6 +161,30 @@ static void usb_init_all(void) {
ensure(usb_start(), NULL); ensure(usb_start(), NULL);
} }
void extract_params(const char *str, int *numbers, int *count, int max_count) {
int i = 0;
int num_index = 0;
int len = strlen(str);
char buffer[20]; // buffer to hold the current number string
while (i < len && num_index < max_count) {
if (isdigit((int)str[i])) {
int buffer_index = 0;
// Extract the number
while (isdigit((int)str[i]) && i < len) {
buffer[buffer_index++] = str[i++];
}
buffer[buffer_index] = '\0'; // null-terminate the string
// Convert the extracted string to an integer
numbers[num_index++] = atoi(buffer);
} else {
i++;
}
}
*count = num_index;
}
static void draw_border(int width, int padding) { static void draw_border(int width, int padding) {
const int W = width, P = padding, RX = DISPLAY_RESX, RY = DISPLAY_RESY; const int W = width, P = padding, RX = DISPLAY_RESX, RY = DISPLAY_RESY;
display_clear(); display_clear();
@ -331,19 +356,22 @@ static void test_touch(const char *args) {
int column = args[0] - '0'; int column = args[0] - '0';
int timeout = args[1] - '0'; int timeout = args[1] - '0';
const int width = DISPLAY_RESX / 2;
const int height = DISPLAY_RESY / 2;
display_clear(); display_clear();
switch (column) { switch (column) {
case 1: case 1:
display_bar(0, 0, 120, 120, 0xFFFF); display_bar(0, 0, width, height, 0xFFFF);
break; break;
case 2: case 2:
display_bar(120, 0, 120, 120, 0xFFFF); display_bar(width, 0, width, height, 0xFFFF);
break; break;
case 3: case 3:
display_bar(120, 120, 120, 120, 0xFFFF); display_bar(width, height, width, height, 0xFFFF);
break; break;
default: default:
display_bar(0, 120, 120, 120, 0xFFFF); display_bar(0, height, width, height, 0xFFFF);
break; break;
} }
display_refresh(); display_refresh();
@ -364,6 +392,108 @@ static void test_touch(const char *args) {
touch_deinit(); touch_deinit();
} }
static void test_touch_custom(const char *args) {
static const int expected_params = 5;
int params[expected_params];
int num_params = 0;
extract_params(args, params, &num_params, expected_params);
if (num_params != expected_params) {
vcp_println("ERROR PARAM");
return;
}
#undef NUM_PARAMS
int x = params[0];
int y = params[1];
int width = params[2];
int height = params[3];
int timeout = params[4];
uint32_t ticks_start = hal_ticks_ms();
display_clear();
display_bar(x, y, width, height, 0xFFFF);
display_refresh();
touch_init();
while (true) {
if (hal_ticks_ms() - ticks_start > timeout * 1000) {
vcp_println("ERROR TIMEOUT");
break;
}
uint32_t touch_event = touch_get_event();
if (touch_event != 0) {
uint16_t touch_x = touch_unpack_x(touch_event);
uint16_t touch_y = touch_unpack_y(touch_event);
if (touch_event & TOUCH_START) {
vcp_println("TOUCH D %d %d %d", touch_x, touch_y, hal_ticks_ms());
}
if (touch_event & TOUCH_MOVE) {
vcp_println("TOUCH C %d %d %d", touch_x, touch_y, hal_ticks_ms());
}
if (touch_event & TOUCH_END) {
vcp_println("TOUCH U %d %d %d", touch_x, touch_y, hal_ticks_ms());
vcp_println("OK");
break;
}
}
}
display_clear();
display_refresh();
touch_deinit();
}
static void test_touch_idle(const char *args) {
static const int expected_params = 5;
int num_params = 0;
int params[expected_params];
extract_params(args, params, &num_params, expected_params);
if (num_params != expected_params) {
vcp_println("ERROR PARAM");
return;
}
int timeout = params[0];
uint32_t ticks_start = hal_ticks_ms();
display_clear();
display_text_center(DISPLAY_RESX / 2, DISPLAY_RESY / 2, "DON'T TOUCH", -1,
FONT_BOLD, COLOR_WHITE, COLOR_BLACK);
display_refresh();
touch_init();
while (true) {
if (hal_ticks_ms() - ticks_start > timeout * 1000) {
vcp_println("OK");
break;
}
if (touch_activity() == sectrue) {
vcp_println("ERROR TOUCH DETECTED");
break;
}
}
display_clear();
display_refresh();
touch_deinit();
}
static void test_sensitivity(const char *args) { static void test_sensitivity(const char *args) {
int v = atoi(args); int v = atoi(args);
@ -703,6 +833,12 @@ int main(void) {
} else if (startswith(line, "TOUCH ")) { } else if (startswith(line, "TOUCH ")) {
test_touch(line + 6); test_touch(line + 6);
} else if (startswith(line, "TOUCH_CUSTOM ")) {
test_touch_custom(line + 13);
} else if (startswith(line, "TOUCH_IDLE ")) {
test_touch_idle(line + 11);
} else if (startswith(line, "SENS ")) { } else if (startswith(line, "SENS ")) {
test_sensitivity(line + 5); test_sensitivity(line + 5);