summaryrefslogtreecommitdiff
path: root/include/keyboard_raw.h
blob: 7b21898f9155172346477e994290ef727c5bb830 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/* 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.
 *
 * Raw access to keyboard GPIOs.
 *
 * The keyboard matrix is read by driving output signals on the column lines
 * and reading the row lines.
 */

#ifndef __CROS_EC_KEYBOARD_RAW_H
#define __CROS_EC_KEYBOARD_RAW_H

#include "assert.h"
#include "common.h"
#include "gpio.h"
#include "keyboard_config.h"

/* Column values for keyboard_raw_drive_column() */
enum keyboard_column_index {
	KEYBOARD_COLUMN_ALL = -2,  /* Drive all columns */
	KEYBOARD_COLUMN_NONE = -1, /* Drive no columns (tri-state all) */
	/* 0 ~ KEYBOARD_COLS_MAX-1 for the corresponding column */
};

/**
 * Initialize the raw keyboard interface.
 *
 * Must be called before any other functions in this interface.
 */
void keyboard_raw_init(void);

/**
 * Finish intitialization after task scheduling has started.
 *
 * Call from the keyboard scan task.
 */
void keyboard_raw_task_start(void);

/**
 * Drive the specified column low.
 *
 * Other columns are tristated.  See enum keyboard_column_index for special
 * values for <col>.
 */
void keyboard_raw_drive_column(int col);

/**
 * Read raw row state.
 *
 * Bits are 1 if signal is present, 0 if not present.
 */
int keyboard_raw_read_rows(void);

/**
 * Enable or disable keyboard interrupts.
 *
 * Enabling interrupts will clear any pending interrupt bits.  To avoid missing
 * any interrupts that occur between the end of scanning and then, you should
 * call keyboard_raw_read_rows() after this.  If it returns non-zero, disable
 * interrupts and go back to polling mode instead of waiting for an interrupt.
 */
void keyboard_raw_enable_interrupt(int enable);

#ifdef HAS_TASK_KEYSCAN

/**
 * GPIO interrupt for raw keyboard input
 */
void keyboard_raw_gpio_interrupt(enum gpio_signal signal);

#else
static inline void keyboard_raw_gpio_interrupt(enum gpio_signal signal) { }
#endif /* !HAS_TASK_KEYSCAN */

/**
 * Run keyboard factory test scanning.
 *
 * @return non-zero if keyboard pins are shorted.
 */
int keyboard_factory_test_scan(void);

static inline int keyboard_raw_get_cols(void) {
	return keyboard_cols;
}

static inline void keyboard_raw_set_cols(int cols) {
#ifdef CONFIG_KEYBOARD_LANGUAGE_ID
	/* Keyboard ID is probably encoded right after the last column. Scanner
	 * would read keyboard ID if the column size is decreased. */
	assert(cols == KEYBOARD_COLS_MAX);
#else
	/* We can only decrease the column size. You have to assume a larger
	 * grid (and reduce scanning size if the keyboard has no keypad). */
	assert(cols <= KEYBOARD_COLS_MAX);
#endif
	keyboard_cols = cols;
}

#endif  /* __CROS_EC_KEYBOARD_RAW_H */