summaryrefslogtreecommitdiff
path: root/chip/lm4/mock_keyboard_scan_stub.c
blob: 6334475dfae74aeb2ad2a5481b1cadcbd6a6f3cf (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/* Mock functions for keyboard scanner module for Chrome EC */

#include "common.h"
#include "console.h"
#include "keyboard_config.h"
#include "keyboard_raw.h"
#include "keyboard_scan.h"
#include "task.h"
#include "uart.h"
#include "util.h"

static int enable_scanning = 1;
static int selected_column = -1;
static int interrupt_enabled = 0;
static uint8_t matrix_status[KEYBOARD_COLS];

void keyboard_raw_init(void)
{
	/* Init matrix status to release all */
	int i;
	for (i = 0; i < KEYBOARD_COLS; ++i)
		matrix_status[i] = 0xff;
}

void keyboard_raw_task_start(void)
{
}

void keyboard_raw_drive_column(int col)
{
	selected_column = col;
}

int keyboard_raw_read_rows(void)
{
	if (selected_column >= 0)
		return matrix_status[selected_column] ^ 0xff;
	else
		return 0;
}

void keyboard_raw_enable_interrupt(int enable)
{
	interrupt_enabled = enable;
}

static int command_mock_matrix(int argc, char **argv)
{
	int r, c, p;
	char *e;

	if (argc < 4)
		return EC_ERROR_PARAM_COUNT;

	c = strtoi(argv[1], &e, 0);
	if (*e || c < 0 || c >= KEYBOARD_COLS)
		return EC_ERROR_PARAM1;

	r = strtoi(argv[2], &e, 0);
	if (*e || r < 0 || r >= KEYBOARD_ROWS)
		return EC_ERROR_PARAM2;

	p = strtoi(argv[3], &e, 0);
	if (*e)
		return EC_ERROR_PARAM3;

	if (p)
		matrix_status[c] &= ~(1 << r);
	else
		matrix_status[c] |= (1 << r);

	if (interrupt_enabled)
		task_wake(TASK_ID_KEYSCAN);

	return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(mockmatrix, command_mock_matrix,
			"<Col> <Row> <0 | 1>",
			"Mock keyboard matrix",
			NULL);