use mbed os
Dependents: Seeed_Grove_I2C_Touch_Example
Fork of MPR121 by
MPR121.cpp@25:534ca7bbccf1, 2017-07-02 (annotated)
- Committer:
- Nathan Yonkee
- Date:
- Sun Jul 02 16:33:37 2017 -0600
- Revision:
- 25:534ca7bbccf1
- Parent:
- 24:3fda4fe39ac6
remove everything we can't use with seeed version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Nate Yonkee |
9:8cb5ce483be3 | 1 | /** |
Nate Yonkee |
9:8cb5ce483be3 | 2 | * @file MPR121.cpp |
Nate Yonkee |
9:8cb5ce483be3 | 3 | * @brief Device driver - MPR121 capactiive touch IC |
Nate Yonkee |
9:8cb5ce483be3 | 4 | * @author sam grove |
Nate Yonkee |
9:8cb5ce483be3 | 5 | * @version 1.0 |
Nate Yonkee |
9:8cb5ce483be3 | 6 | * @see http://cache.freescale.com/files/sensors/doc/data_sheet/MPR121.pdf |
Nate Yonkee |
9:8cb5ce483be3 | 7 | * |
Nate Yonkee |
9:8cb5ce483be3 | 8 | * Copyright (c) 2013 |
Nate Yonkee |
9:8cb5ce483be3 | 9 | * |
Nate Yonkee |
9:8cb5ce483be3 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Nate Yonkee |
9:8cb5ce483be3 | 11 | * you may not use this file except in compliance with the License. |
Nate Yonkee |
9:8cb5ce483be3 | 12 | * You may obtain a copy of the License at |
Nate Yonkee |
9:8cb5ce483be3 | 13 | * |
Nate Yonkee |
9:8cb5ce483be3 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
Nate Yonkee |
9:8cb5ce483be3 | 15 | * |
Nate Yonkee |
9:8cb5ce483be3 | 16 | * Unless required by applicable law or agreed to in writing, software |
Nate Yonkee |
9:8cb5ce483be3 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
Nate Yonkee |
9:8cb5ce483be3 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Nate Yonkee |
9:8cb5ce483be3 | 19 | * See the License for the specific language governing permissions and |
Nate Yonkee |
9:8cb5ce483be3 | 20 | * limitations under the License. |
Nate Yonkee |
9:8cb5ce483be3 | 21 | */ |
Nate Yonkee |
9:8cb5ce483be3 | 22 | |
Nate Yonkee |
9:8cb5ce483be3 | 23 | #include "MPR121.h" |
Nate Yonkee |
9:8cb5ce483be3 | 24 | #include "mbed_debug.h" |
Nate Yonkee |
9:8cb5ce483be3 | 25 | |
Nate Yonkee |
9:8cb5ce483be3 | 26 | #define DEBUG 1 |
Nate Yonkee |
9:8cb5ce483be3 | 27 | |
Nathan Yonkee |
25:534ca7bbccf1 | 28 | MPR121::MPR121(I2C &i2c) { |
Nathan Yonkee |
12:22d36da8df91 | 29 | _i2c = &i2c; |
Nathan Yonkee |
12:22d36da8df91 | 30 | _i2c_addr = (0x1b << 1); |
Nathan Yonkee |
12:22d36da8df91 | 31 | } |
Nathan Yonkee |
12:22d36da8df91 | 32 | |
Nathan Yonkee |
12:22d36da8df91 | 33 | |
Nathan Yonkee |
25:534ca7bbccf1 | 34 | bool MPR121::isPressed(void) { |
Nathan Yonkee |
25:534ca7bbccf1 | 35 | bool result = buttonPressed() == 0 ? false : true; |
Nathan Yonkee |
25:534ca7bbccf1 | 36 | return result; |
Nathan Yonkee |
12:22d36da8df91 | 37 | } |
Nathan Yonkee |
12:22d36da8df91 | 38 | |
Nathan Yonkee |
25:534ca7bbccf1 | 39 | uint16_t MPR121::buttonPressed(void) { |
Nathan Yonkee |
12:22d36da8df91 | 40 | char reg[1] = { 0x03 }; |
Nathan Yonkee |
12:22d36da8df91 | 41 | int result=0; |
Nathan Yonkee |
12:22d36da8df91 | 42 | char data = -1; |
Nathan Yonkee |
12:22d36da8df91 | 43 | result = _i2c->write(_i2c_addr, reg, 1, true); |
Nathan Yonkee |
25:534ca7bbccf1 | 44 | if(result == 0 ) debug("result is 0"); |
Nathan Yonkee |
25:534ca7bbccf1 | 45 | result = _i2c->read(_i2c_addr, &data, 1); |
Nathan Yonkee |
25:534ca7bbccf1 | 46 | if(result == 0 ) debug("result is 0"); |
Nathan Yonkee |
12:22d36da8df91 | 47 | if(data == 4) data = 3; |
Nathan Yonkee |
12:22d36da8df91 | 48 | if(data == 2) data = 2; |
Nathan Yonkee |
12:22d36da8df91 | 49 | if(data == 1) data = 1; |
Nathan Yonkee |
12:22d36da8df91 | 50 | return data; |
Nathan Yonkee |
12:22d36da8df91 | 51 | } |