summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx233/creative-zenxfi3/mpr121-zenxfi3.h
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/imx233/creative-zenxfi3/mpr121-zenxfi3.h')
-rw-r--r--firmware/target/arm/imx233/creative-zenxfi3/mpr121-zenxfi3.h176
1 files changed, 176 insertions, 0 deletions
diff --git a/firmware/target/arm/imx233/creative-zenxfi3/mpr121-zenxfi3.h b/firmware/target/arm/imx233/creative-zenxfi3/mpr121-zenxfi3.h
new file mode 100644
index 0000000000..eb8b00eeee
--- /dev/null
+++ b/firmware/target/arm/imx233/creative-zenxfi3/mpr121-zenxfi3.h
@@ -0,0 +1,176 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2016 Amaury Pouly
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#ifndef __MPR121_ZENXFI3_H__
22#define __MPR121_ZENXFI3_H__
23
24/** Driver for the Freescale MPR121 Capacitive Proximity Sensor */
25#include "system.h"
26
27#define ELECTRODE_COUNT 12
28#define ELE_GPIO_FIRST 4
29#define ELE_GPIO_LAST 11
30
31/* gpio config (encoding: [0]=en,[1]=dir,[2]=ctl[1],[3]=ctl[0]) */
32#define ELE_GPIO_DISABLE 0
33#define ELE_GPIO_INPUT 1
34#define ELE_GPIO_INPUT_PULLDOWN 9 /* input with pull-down */
35#define ELE_GPIO_INPUT_PULLUP 13 /* input with pull-up */
36#define ELE_GPIO_OUTPUT 3
37#define ELE_GPIO_OUTPUT_OPEN 11 /* open drain low-side */
38#define ELE_GPIO_OUTPUT_OPEN_LED 15 /* open drain high-side (led driver) */
39
40/* internal use */
41#define ELE_GPIO_EN(val) ((val) & 1)
42#define ELE_GPIO_DIR(val) (((val) >> 1) & 1)
43#define ELE_GPIO_CTL0(val) (((val) >> 3) & 1)
44#define ELE_GPIO_CTL1(val) (((val) >> 1) & 1)
45
46struct mpr121_electrode_config_t
47{
48 uint8_t bv; /* baseline value */
49 uint8_t tth; /* touch threshold */
50 uint8_t rth; /* release threshold */
51 uint8_t cdc; /* charge current (optional if auto-conf) */
52 uint8_t cdt; /* charge time (optional if auto-conf) */
53 int gpio; /* gpio config */
54};
55
56struct mpr121_baseline_filter_config_t
57{
58 uint8_t mhd; /* max half delta (except for touched) */
59 uint8_t nhd; /* noise half delta */
60 uint8_t ncl; /* noise count limit */
61 uint8_t fdl; /* filter delay count limit */
62};
63
64struct mpr121_baseline_filters_config_t
65{
66 struct mpr121_baseline_filter_config_t rising;
67 struct mpr121_baseline_filter_config_t falling;
68 struct mpr121_baseline_filter_config_t touched;
69};
70
71struct mpr121_debounce_config_t
72{
73 uint8_t dt; /* debounce count for touch */
74 uint8_t dr; /* debounce count for release */
75};
76
77/* first filter iterations */
78#define FFI_6_SAMPLES 0
79#define FFI_10_SAMPLES 1
80#define FFI_18_SAMPLES 2
81#define FFI_34_SAMPLES 3
82/* charge discharge current */
83#define CDC_DISABLE 0
84#define CDC_uA(ua) (ua)
85/* charge discharge time */
86#define CDT_DISABLE 0
87#define CDT_log_us(lus) (lus) /* actual value = 2^{us-2} µs */
88/* second filter iterations */
89#define SFI_4_SAMPLES 0
90#define SFI_6_SAMPLES 1
91#define SFI_10_SAMPLES 2
92#define SFI_18_SAMPLES 3
93/* Eletrode sample interval */
94#define ESI_log_ms(lms) (lms) /* actual value = 2^{lms} ms */
95
96struct mpr121_global_config_t
97{
98 uint8_t ffi; /* first filter iterations */
99 uint8_t cdc; /* global charge discharge current */
100 uint8_t cdt; /* global charge discharge time */
101 uint8_t sfi; /* second first iterations */
102 uint8_t esi; /* electrode sample interval */
103};
104
105#define RETRY_NEVER 0
106#define RETRY_2_TIMES 1
107#define RETRY_4_TIMES 2
108#define RETRY_8_TIMES 3
109
110struct mpr121_auto_config_t
111{
112 bool en; /* auto-conf enable */
113 bool ren; /* auto-reconf enable */
114 uint8_t retry; /* retry count */
115 bool scts; /* skip charge time search */
116 uint8_t usl; /* upper-side limit */
117 uint8_t lsl; /* lower-side limit */
118 uint8_t tl; /* target level */
119 bool acfie; /* auto-conf fail interrupt en */
120 bool arfie; /* auto-reconf fail interrupt en */
121 bool oorie; /* out of range interrupt en */
122};
123
124/* electrode mode */
125#define ELE_DISABLE 0
126#define ELE_EN0_x(x) ((x) + 1)
127/* eleprox mode */
128#define ELEPROX_DISABLE 0
129#define ELEPROX_EN0_1 1
130#define ELEPROX_EN0_3 2
131#define ELEPROX_EN0_11 3
132/* calibration lock */
133#define CL_SLOW_TRACK 0
134#define CL_DISABLE 1
135#define CL_TRACK 2
136#define CL_FAST_TRACK 3
137
138struct mpr121_config_t
139{
140 struct mpr121_electrode_config_t ele[ELECTRODE_COUNT];
141 struct mpr121_electrode_config_t eleprox;
142 struct
143 {
144 struct mpr121_baseline_filters_config_t ele;
145 struct mpr121_baseline_filters_config_t eleprox;
146 }filters;
147 struct mpr121_debounce_config_t debounce;
148 struct mpr121_global_config_t global;
149 struct mpr121_auto_config_t autoconf;
150 uint8_t ele_en; /* eletroce mode */
151 uint8_t eleprox_en; /* proximity mode */
152 uint8_t cal_lock; /* calibration lock */
153};
154
155/* gpio value */
156#define ELE_GPIO_CLR 0
157#define ELE_GPIO_SET 1
158#define ELE_GPIO_TOG 2
159/* pwm value */
160#define ELE_PWM_DISABLE 0
161#define ELE_PWM_DUTY(x) (x)
162#define ELE_PWM_MIN_DUTY 1
163#define ELE_PWM_MAX_DUTY 15
164
165void mpr121_init(void);
166void mpr121_set_config(struct mpr121_config_t *conf);
167/* gpios are only implemented for electrode>=4, use ELE_GPIO_* for value */
168void mpr121_set_gpio_output(int ele, int gpio_val);
169/* pwm value is between 0 and 15, use ELE_PWM_DISABLE or ELE_PWM_DUTY */
170void mpr121_set_gpio_pwm(int ele, int pwm);
171/* get electrode status (bitmap)
172 * NOTE this function merely returns the last electrode status read from the
173 * device and does not actively ask the device for touch status. */
174unsigned mpr121_get_touch_status(void);
175
176#endif /* __MPR121_ZENXFI3_H__ */