summaryrefslogtreecommitdiff
path: root/zephyr/shim/src/keyboard_raw.c
blob: ef2dadb29c1ddeb26d6fad56b66eeb22fa0dafc9 (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
/* Copyright 2021 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.
 */

/* Functions needed by keyboard scanner module for Chrome EC */

#include <zephyr/device.h>
#include <zephyr/logging/log.h>
#include <soc.h>
#include <zephyr/zephyr.h>

#include "drivers/cros_kb_raw.h"
#include "keyboard_raw.h"

LOG_MODULE_REGISTER(shim_cros_kb_raw, LOG_LEVEL_ERR);

BUILD_ASSERT(DT_HAS_CHOSEN(cros_ec_raw_kb),
	     "a cros-ec,raw-kb device must be chosen");
#define cros_kb_raw_dev DEVICE_DT_GET(DT_CHOSEN(cros_ec_raw_kb))

/**
 * Initialize the raw keyboard interface.
 */
void keyboard_raw_init(void)
{
	if (!device_is_ready(cros_kb_raw_dev))
		k_oops();

	LOG_INF("%s", __func__);
	cros_kb_raw_init(cros_kb_raw_dev);
}

/**
 * Finish initialization after task scheduling has started.
 */
void keyboard_raw_task_start(void)
{
	keyboard_raw_enable_interrupt(1);
}

/**
 * Drive the specified column low.
 */
test_mockable void keyboard_raw_drive_column(int col)
{
	cros_kb_raw_drive_column(cros_kb_raw_dev, col);
}

/**
 * Read raw row state.
 * Bits are 1 if signal is present, 0 if not present.
 */
test_mockable int keyboard_raw_read_rows(void)
{
	return cros_kb_raw_read_rows(cros_kb_raw_dev);
}

/**
 * Enable or disable keyboard interrupts.
 */
void keyboard_raw_enable_interrupt(int enable)
{
	cros_kb_raw_enable_interrupt(cros_kb_raw_dev, enable);
}