aboutsummaryrefslogtreecommitdiffstats
path: root/tests/tools/cmp_tbdata.c
blob: c0b12cd9b1d4c901e2db12e55f149eabf050a800 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>

int line = 0;
char buffer1[8192];
char buffer2[8192];

void check(bool ok)
{
	if (ok)
		return;
	fprintf(stderr, "Error in testbench output compare (line=%d):\n-%s\n+%s\n", line, buffer1, buffer2);
	exit(1);
}

int main(int argc, char **argv)
{
	FILE *f1, *f2;
	bool eof1, eof2;
	int i;

	check(argc == 3);

	f1 = fopen(argv[1], "r");
	f2 = fopen(argv[2], "r");

	check(f1 && f2);

	while (!feof(f1) && !feof(f2))
	{
		line++;
		buffer1[0] = 0;
		buffer2[0] = 0;

		eof1 = fgets(buffer1, 1024, f1) == NULL;
		eof2 = fgets(buffer2, 1024, f2) == NULL;

		if (*buffer1 && buffer1[strlen(buffer1)-1] == '\n')
			buffer1[strlen(buffer1)-1] = 0;

		if (*buffer2 && buffer2[strlen(buffer2)-1] == '\n')
			buffer2[strlen(buffer2)-1] = 0;

		check(eof1 == eof2);

		for (i = 0; buffer1[i] || buffer2[i]; i++)
		{
			check(buffer1[i] != 0 && buffer2[i] != 0);

			// first argument is the reference. An 'z' or 'x'
			// here means we don't care about the result.
			if (buffer1[i] == 'z' || buffer1[i] == 'x')
				continue;
			if (buffer1[i] == 'Z' || buffer1[i] == 'X')
				continue;

			check(buffer1[i] == buffer2[i]);
		}
	}

	check(feof(f1) && feof(f2));

	fclose(f1);
	fclose(f2);
	return 0;
}
"n">matrix_cols(void) { return MATRIX_COLS; } void matrix_init(void) { matrix_init_quantum(); } uint8_t matrix_scan(void) { SERIAL_UART_INIT(); uint32_t timeout = 0; //the s character requests the RF slave to send the matrix SERIAL_UART_DATA = 's'; //trust the external keystates entirely, erase the last data uint8_t uart_data[11] = {0}; //there are 10 bytes corresponding to 10 columns, and an end byte for (uint8_t i = 0; i < 11; i++) { //wait for the serial data, timeout if it's been too long //this only happened in testing with a loose wire, but does no //harm to leave it in here while(!SERIAL_UART_RXD_PRESENT){ timeout++; if (timeout > 10000){ break; } } uart_data[i] = SERIAL_UART_DATA; } //check for the end packet, the key state bytes use the LSBs, so 0xE0 //will only show up here if the correct bytes were recieved if (uart_data[10] == 0xE0) { //shifting and transferring the keystates to the QMK matrix variable for (uint8_t i = 0; i < MATRIX_ROWS; i++) { matrix[i] = (uint16_t) uart_data[i*2] | (uint16_t) uart_data[i*2+1] << 5; } } matrix_scan_quantum(); return 1; } inline bool matrix_is_on(uint8_t row, uint8_t col) { return (matrix[row] & ((matrix_row_t)1<<col)); } inline matrix_row_t matrix_get_row(uint8_t row) { return matrix[row]; } void matrix_print(void) { print_matrix_header(); for (uint8_t row = 0; row < MATRIX_ROWS; row++) { phex(row); print(": "); print_matrix_row(row); print("\n"); } } uint8_t matrix_key_count(void) { uint8_t count = 0; for (uint8_t i = 0; i < MATRIX_ROWS; i++) { count += matrix_bitpop(i); } return count; }