1 /*
2 * Copyright (c) 2021 HPMicro
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8 #include "hpm_ft5406.h"
9
ft5406_read_register(ft5406_context_t * context,uint8_t reg,uint8_t * buf)10 hpm_stat_t ft5406_read_register(ft5406_context_t *context, uint8_t reg, uint8_t *buf)
11 {
12 return i2c_master_address_read(context->ptr, FT5406_I2C_ADDR, ®, 1, buf, 1);
13 }
14
ft5406_write_register(ft5406_context_t * context,uint8_t reg,uint8_t val)15 hpm_stat_t ft5406_write_register(ft5406_context_t *context, uint8_t reg, uint8_t val)
16 {
17 return i2c_master_address_write(context->ptr, FT5406_I2C_ADDR, ®, 1, &val, 1);
18 }
19
ft5406_set_mode(ft5406_context_t * context,uint8_t mode)20 hpm_stat_t ft5406_set_mode(ft5406_context_t *context, uint8_t mode)
21 {
22 return ft5406_write_register(context, FT5406_DEVICE_MODE, 1);
23 }
24
ft5406_init(ft5406_context_t * context)25 hpm_stat_t ft5406_init(ft5406_context_t *context)
26 {
27 return ft5406_set_mode(context, FT5406_DEVICE_MODE_NORMAL);
28 }
29
ft5406_get_sys_info(ft5406_context_t * context,ft5406_sys_info_t * info)30 hpm_stat_t ft5406_get_sys_info(ft5406_context_t *context, ft5406_sys_info_t *info)
31 {
32 hpm_stat_t stat = status_success;
33 uint8_t reg_addr = FT5406_DEVICE_MODE;
34
35 stat = ft5406_set_mode(context, FT5406_DEVICE_MODE_SYS_INFO);
36 if (stat != status_success) {
37 return stat;
38 }
39 return i2c_master_address_read(context->ptr, FT5406_I2C_ADDR, ®_addr, 1, (uint8_t *)info, sizeof(ft5406_sys_info_t));
40 }
41
ft5406_read_data(ft5406_context_t * context,uint8_t addr,uint8_t * buf,uint32_t size)42 hpm_stat_t ft5406_read_data(ft5406_context_t *context, uint8_t addr, uint8_t *buf, uint32_t size)
43 {
44 return i2c_master_address_read(context->ptr, FT5406_I2C_ADDR, &addr, 1, buf, size);
45 }
46
ft5406_read_touch_data(ft5406_context_t * context,ft5406_touch_data_t * touch_data)47 hpm_stat_t ft5406_read_touch_data(ft5406_context_t *context, ft5406_touch_data_t *touch_data)
48 {
49 return ft5406_read_data(context, FT5406_GEST_ID, (uint8_t *)touch_data, sizeof(ft5406_touch_data_t));
50 }
51