forked from RIOT-OS/RIOT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cst816s: Initial include of cst816s touch screen driver
- Loading branch information
Showing
7 changed files
with
384 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include $(RIOTBASE)/Makefile.base |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (C) 2020 Koen Zandberg | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup drivers_cst816s | ||
* @{ | ||
* | ||
* @file | ||
* @brief Device driver implementation for cst816s touch screen | ||
* | ||
* @author koen Zandberg <[email protected]> | ||
* | ||
* @} | ||
*/ | ||
|
||
#include "log.h" | ||
#include "periph/gpio.h" | ||
#include "periph/i2c.h" | ||
#include "xtimer.h" | ||
|
||
#include "cst816s.h" | ||
#include "cst816s_internal.h" | ||
|
||
#define ENABLE_DEBUG (0) | ||
#include "debug.h" | ||
|
||
static void _gpio_irq(void *arg) | ||
{ | ||
cst816s_t *dev = arg; | ||
|
||
dev->cb(dev, dev->cb_arg); | ||
} | ||
|
||
static void _cst816s_reset(cst816s_t *dev) | ||
{ | ||
/* Reset, sleep durations based on | ||
* https://github.com/lupyuen/hynitron_i2c_cst0xxse/blob/master/cst0xx_core.c#L1078-L1085 */ | ||
gpio_clear(dev->params->reset); | ||
xtimer_usleep(CST816S_RESET_DURATION_LOW); | ||
gpio_set(dev->params->reset); | ||
xtimer_usleep(CST816S_RESET_DURATION_HIGH); | ||
} | ||
|
||
int cst816s_read(cst816s_t *dev, cst816s_touch_data_t *data) | ||
{ | ||
uint8_t buf[9]; /* 3 bytes "header" and 6 bytes touch info */ | ||
|
||
i2c_acquire(dev->params->i2c_dev); | ||
int res = i2c_read_regs(dev->params->i2c_dev, dev->params->i2c_addr, | ||
0, buf, sizeof(buf), 0); | ||
i2c_release(dev->params->i2c_dev); | ||
|
||
if (res < 0) { | ||
return res; | ||
} | ||
|
||
data->gesture = buf[1]; | ||
data->action = buf[3] >> 6; | ||
data->x = (buf[3] & 0x0f) << 8 | buf[4]; | ||
data->y = (buf[5] & 0x0f) << 8 | buf[6]; | ||
|
||
return 0; | ||
} | ||
|
||
int cst816s_init(cst816s_t *dev, const cst816s_params_t *params, | ||
cst816s_irq_cb_t cb, void *arg) | ||
{ | ||
assert(dev && params); | ||
dev->params = params; | ||
dev->cb = cb; | ||
dev->cb_arg = arg; | ||
|
||
gpio_init(dev->params->reset, GPIO_OUT); | ||
_cst816s_reset(dev); | ||
|
||
if (cb) { | ||
int res = gpio_init_int(dev->params->irq, GPIO_IN, | ||
dev->params->irq_flank, | ||
_gpio_irq, dev); | ||
if (res < 0) { | ||
return CST816S_ERR_IRQ; | ||
} | ||
} | ||
return CST816S_OK; | ||
/* The device will not respond until the first touch event */ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (C) 2020 Koen Zandberg | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
#ifndef CST816S_INTERNAL_H | ||
#define CST816S_INTERNAL_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#define CST816S_RESET_DURATION_LOW (20 * US_PER_MS) | ||
#define CST816S_RESET_DURATION_HIGH (400 * US_PER_MS) | ||
|
||
#define CST816S_REG_INT_CNT 0x8F | ||
#define CST816S_REG_FLOW_WORK_CNT 0x91 | ||
#define CST816S_REG_WORKMODE 0x00 | ||
#define CST816S_REG_WORKMODE_FACTORY_VALUE 0x40 | ||
#define CST816S_REG_WORKMODE_WORK_VALUE 0x00 | ||
#define CST816S_REG_CHIP_ID 0xA3 | ||
#define CST816S_REG_CHIP_ID2 0x9F | ||
#define CST816S_REG_POWER_MODE 0xA5 | ||
#define CST816S_REG_FW_VER 0xA6 | ||
#define CST816S_REG_VENDOR_ID 0xA8 | ||
#define CST816S_REG_LCD_BUSY_NUM 0xAB | ||
#define CST816S_REG_FACE_DEC_MODE_EN 0xB0 | ||
#define CST816S_REG_GLOVE_MODE_EN 0xC0 | ||
#define CST816S_REG_COVER_MODE_EN 0xC1 | ||
#define CST816S_REG_CHARGER_MODE_EN 0x8B | ||
#define CST816S_REG_GESTURE_EN 0xD0 | ||
#define CST816S_REG_GESTURE_OUTPUT_ADDRESS 0xD3 | ||
#define CST816S_REG_ESD_SATURATE 0xED | ||
|
||
#define CST816S_REG_POWER_MODE_SLEEP_VALUE 0x03 | ||
|
||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* CST816_INTERNAL_H */ | ||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Copyright (C) 2020 Koen Zandberg | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
|
||
/** | ||
* @ingroup drivers_cst816s | ||
* | ||
* @brief Default configuration for the CST816S touch screen driver | ||
* | ||
* | ||
* @author koen Zandberg <[email protected]> | ||
*/ | ||
|
||
#ifndef CST816S_PARAMS_H | ||
#define CST816S_PARAMS_H | ||
|
||
#include "board.h" | ||
#include "cst816s.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
/** | ||
* @name Set default configuration parameters for the CST816S | ||
* @{ | ||
*/ | ||
/* I2C configuration */ | ||
#ifndef CST816S_PARAM_I2C_DEV | ||
#define CST816S_PARAM_I2C_DEV I2C_DEV(0) | ||
#endif | ||
|
||
#ifndef CST816S_PARAM_I2C_ADDR | ||
#define CST816S_PARAM_I2C_ADDR (0x15) | ||
#endif | ||
|
||
#ifndef CST816S_PARAM_IRQ | ||
#define CST816S_PARAM_IRQ GPIO_PIN(0, 28) | ||
#endif | ||
|
||
#ifndef CST816S_PARAM_IRQ_FLANK | ||
#define CST816S_PARAM_IRQ_FLANK GPIO_FALLING | ||
#endif | ||
|
||
#ifndef CST816S_PARAM_RESET | ||
#define CST816S_PARAM_RESET GPIO_PIN(0, 10) | ||
#endif | ||
|
||
|
||
#define CST816S_PARAMS \ | ||
{ \ | ||
.i2c_dev = CST816S_PARAM_I2C_DEV, \ | ||
.i2c_addr = CST816S_PARAM_I2C_ADDR, \ | ||
.irq = CST816S_PARAM_IRQ, \ | ||
.irq_flank = CST816S_PARAM_IRQ_FLANK, \ | ||
.reset = CST816S_PARAM_RESET, \ | ||
} | ||
/**@}*/ | ||
|
||
/** | ||
* @brief Configure BMX280 | ||
*/ | ||
static const cst816s_params_t cst816s_params[] = | ||
{ | ||
CST816S_PARAMS | ||
}; | ||
|
||
/** | ||
* @brief The number of configured sensors | ||
*/ | ||
#define CST816S_NUMOF ARRAY_SIZE(cst816s_params) | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* BMX280_PARAMS_H */ | ||
/** @} */ | ||
|
Oops, something went wrong.