summaryrefslogtreecommitdiff
path: root/board/keyborg/touch_scan.h
blob: 88f41560b6bbe26dc64d7ffd6e205e479c0b4441 (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
/* Copyright (c) 2014 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.
 */

/* Touch scanning module */

#ifndef __BOARD_KEYBORG_TOUCH_SCAN_H
#define __BOARD_KEYBORG_TOUCH_SCAN_H

enum pin_type {
	PIN_ROW,
	PIN_COL,
	PIN_PD,
	PIN_Z,
};

/* 8-bit window */
#define ADC_WINDOW_POS 2

/* Threshold for each cell */
#define THRESHOLD 35

/* Threshold for entire column */
#define COL_THRESHOLD 16

/* The span width of active columns */
#define COL_SPAN 5 /* Must not exceed 15 */

/* ADC speed */
#define ADC_SMPR_VAL 0x2 /* 13.5 cycles */
#define ADC_SMPL_CYCLE_2 27
#define ADC_QUNTZ_CYCLE_2 25 /* Quantization always takes 12.5 cycles */

/* CPU clock is 4 times faster than ADC clock */
#define ADC_SMPL_CPU_CYCLE (ADC_SMPL_CYCLE_2 * 2)

struct ts_pin {
	uint8_t port_id; /* GPIO_A = 0, GPIO_B = 1, ... */
	uint8_t pin;
};

#define TS_GPIO_A 0
#define TS_GPIO_B 1
#define TS_GPIO_C 2
#define TS_GPIO_D 3
#define TS_GPIO_E 4
#define TS_GPIO_F 5
#define TS_GPIO_G 6
#define TS_GPIO_H 7
#define TS_GPIO_I 8

extern const struct ts_pin row_pins[];
extern const struct ts_pin col_pins[];

#define ROW_COUNT 41
#define COL_COUNT 60

/* Initialize touch scan module */
void touch_scan_init(void);

/* Start scanning on the slave. This is called by SPI command handler. */
void touch_scan_slave_start(void);

/**
 * Initiate full matrix scan on the master. This also sends SPI command
 * to the slave.
 */
int touch_scan_full_matrix(void);

/* Configure touch scan module to interrupt on touch. */
void touch_scan_enable_interrupt(void);

/* Disable touch scan interrupt. */
void touch_scan_disable_interrupt(void);

#endif /* __BOARD_KEYBORG_TOUCH_SCAN_H */