diff --git a/OAT.xml b/OAT.xml index fb055b744ac1b58cb5c9b6b58d2f0ad2b3db5ae6..80b2a2620eaf5870219c1ab320634dc2d03127b7 100644 --- a/OAT.xml +++ b/OAT.xml @@ -42,6 +42,8 @@ + + diff --git a/vendor/others/build_config.json b/vendor/others/build_config.json new file mode 100644 index 0000000000000000000000000000000000000000..437b3454271b4bcaf9522fc1d7821af87816e940 --- /dev/null +++ b/vendor/others/build_config.json @@ -0,0 +1,7 @@ +{ + "buildTarget": "ws63-liteos-app", + "relativePath": "samples/touch_by_si12t", + "chip": "WS63", + "buildDef": "CONFIG_SAMPLE_ENABLE = y,CONFIG_SI12T_APP = y", + "needSmoke": "false" +} \ No newline at end of file diff --git a/vendor/others/touch_by_si12t/CMakeLists.txt b/vendor/others/touch_by_si12t/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..8c9d1a87b320ed51c0f269f726dc2d3b1c38f2fb --- /dev/null +++ b/vendor/others/touch_by_si12t/CMakeLists.txt @@ -0,0 +1,7 @@ +#=============================================================================== +# @brief cmake file. +# Copyright (c) wangjinmin +#=============================================================================== + +set(SOURCES "${SOURCES}" "${CMAKE_CURRENT_SOURCE_DIR}/si12t_touch.c" PARENT_SCOPE) +set(PUBLIC_HEADER "${PUBLIC_HEADER}" "${CMAKE_CURRENT_SOURCE_DIR}" PARENT_SCOPE) diff --git a/vendor/others/touch_by_si12t/Kconfig b/vendor/others/touch_by_si12t/Kconfig new file mode 100644 index 0000000000000000000000000000000000000000..cbe880d6f8af6e3dad51ddbb0ac6eaf30baa40f9 --- /dev/null +++ b/vendor/others/touch_by_si12t/Kconfig @@ -0,0 +1,54 @@ +#=============================================================================== +# @brief Kconfig file. +# Copyright (c) wangjinmin +#=============================================================================== + +config SI12T_APP + bool + prompt "Enable the si12t app." + default n + depends on SAMPLE_ENABLE + help + This option means enable the sample of NFC. + +config I2C_MASTER_BUS_ID + int + prompt "Choose I2C master bus id." + depends on SI12T_APP + default 1 + +config I2C_SCL_MASTER_PIN + int + prompt "Choose I2C SCL master pin." + depends on SI12T_APP + default 16 + +config I2C_SDA_MASTER_PIN + int + prompt "Choose I2C SDA master pin." + depends on SI12T_APP + default 15 + +config I2C_MASTER_PIN_MODE + int + prompt "Choose I2C master pin mode." + depends on SI12T_APP + default 2 + +config I2C_SLAVE_ADDR + hex + prompt "Choose I2C slave addr." + depends on SI12T_APP + default 0x68 + +config I2C_TRANSFER_LEN + int + prompt "Choose I2C transfer length." + depends on SI12T_APP + default 1 + +config SI12T_EN_PIN + int + prompt "Choose SI12T EN PIN." + depends on SI12T_APP + default 14 \ No newline at end of file diff --git a/vendor/others/touch_by_si12t/media/1.jpg b/vendor/others/touch_by_si12t/media/1.jpg new file mode 100644 index 0000000000000000000000000000000000000000..667a7710e5cdee7ab6fb451d23819dacf19016ce Binary files /dev/null and b/vendor/others/touch_by_si12t/media/1.jpg differ diff --git a/vendor/others/touch_by_si12t/media/2.png b/vendor/others/touch_by_si12t/media/2.png new file mode 100644 index 0000000000000000000000000000000000000000..6a71ff24c05d186a7541cf6835d3091c62b558be Binary files /dev/null and b/vendor/others/touch_by_si12t/media/2.png differ diff --git a/vendor/others/touch_by_si12t/si12t_touch.c b/vendor/others/touch_by_si12t/si12t_touch.c new file mode 100644 index 0000000000000000000000000000000000000000..e0c2ac67e26bd193cc219b2bcb73419aab34f9e3 --- /dev/null +++ b/vendor/others/touch_by_si12t/si12t_touch.c @@ -0,0 +1,181 @@ +/** + * Copyright (c) HiSilicon (Shanghai) Technologies Co., Ltd. 2023-2023. All rights reserved. + * Copyright (c) wangjinmin + * + * Description: 0-12 num touch by si12t. \n + * + * History: \n + * 2025-11-20, Create file. \n + */ +#include "pinctrl.h" +#include "i2c.h" +#include "gpio.h" +#include "soc_osal.h" +#include "app_init.h" +#include "si12t_touch.h" + +#define I2C_MASTER_ADDR 0x0 +#define I2C_SET_BAUDRATE 100000 +#define I2C_TASK_DURATION_MS 100 + +#define APP_TASK_PRIO 24 +#define APP_TASK_STACK_SIZE 0x1000 + +/* I2C pinmux. */ +static void app_i2c_init_pin(void) { + uapi_pin_set_mode(CONFIG_I2C_SCL_MASTER_PIN, CONFIG_I2C_MASTER_PIN_MODE); + uapi_pin_set_mode(CONFIG_I2C_SDA_MASTER_PIN, CONFIG_I2C_MASTER_PIN_MODE); +} + +/* si12t en pin control. PIN LOW enbale HIGH disable */ +static void si12t_en_enable(void) { + uapi_gpio_set_val(CONFIG_SI12T_EN_PIN, GPIO_LEVEL_LOW); +} + +static void si12t_en_disable(void) { + uapi_gpio_set_val(CONFIG_SI12T_EN_PIN, GPIO_LEVEL_HIGH); +} + +/* si12t i2c write one data */ +static int si12t_i2c_write_one(uint8_t reg, uint8_t val) { + uint8_t buf[2] = {0}; + buf[0] = reg; + buf[1] = val; + uint8_t once_send_len = 2; + i2c_data_t data = {0}; + data.send_buf = buf; + data.send_len = once_send_len; + return uapi_i2c_master_write(CONFIG_I2C_MASTER_BUS_ID, CONFIG_I2C_SLAVE_ADDR, &data); +} + +/* si12t i2c read bytes */ +static int si12t_i2c_read_bytes(uint8_t reg, uint8_t* buf, uint8_t len) { + i2c_data_t data = {0}; + uint8_t write_addr_len = 1; // write address length is 1 byte + data.send_buf = ® + data.send_len = write_addr_len; + data.receive_buf = buf; + data.receive_len = len; + int st = uapi_i2c_master_write(CONFIG_I2C_MASTER_BUS_ID, CONFIG_I2C_SLAVE_ADDR, &data); + if (st != ERRCODE_SUCC) { + return st; + } + return uapi_i2c_master_read(CONFIG_I2C_MASTER_BUS_ID, CONFIG_I2C_SLAVE_ADDR, &data); +} + +/* si12t start init */ +static void si12t_start_init(void) { + si12t_en_enable(); + uint8_t set_data; + + // soft reset chip + set_data = 0x0f; + si12t_i2c_write_one(SI12T_CTRL2, set_data); + // enable sleep mode + set_data = 0x07; + si12t_i2c_write_one(SI12T_CTRL2, set_data); + + // basic setting + set_data = 0x28; + si12t_i2c_write_one(SI12T_CTRL1, set_data); + + // channels 1 to 8 is not performed. + set_data = 0x00; + si12t_i2c_write_one(SI12T_REF_RST1, set_data); + // channels 9 to 12 is not performed. + set_data = 0x00; + si12t_i2c_write_one(SI12T_REF_RST2, set_data); + // set sensitivity for channels 1-2 + set_data = 0x11; + si12t_i2c_write_one(SI12T_SENSITIVITY1, set_data); + + // set sensitivity for channels 3-4 + si12t_i2c_write_one(SI12T_SENSITIVITY2, set_data); + // set sensitivity for channels 5-6 + si12t_i2c_write_one(SI12T_SENSITIVITY3, set_data); + // set sensitivity for channels 7-8 + si12t_i2c_write_one(SI12T_SENSITIVITY4, set_data); + // set sensitivity for channels 9-10 + si12t_i2c_write_one(SI12T_SENSITIVITY5, set_data); + // set sensitivity for channels 11-12 + si12t_i2c_write_one(SI12T_SENSITIVITY6, set_data); + // open channels 1-8 + set_data = 0x00; + si12t_i2c_write_one(SI12T_CH_HOLD1, set_data); + // open channels 9-12 + set_data = 0x30; + si12t_i2c_write_one(SI12T_CH_HOLD2, set_data); + si12t_en_disable(); +} + +/* key map by touch board */ +uint8_t key_map[12] = {0x0a, 0x00, 0x0b, 0x07, 0x08, 0x04, 0x05, 0x01, 0x03, 0x02, 0x06, 0x09}; + +/* si12t key scan */ +static void si12t_key_scan(void) { + uint8_t key_buf[3] = {0}; + uint8_t read_size = 3; + si12t_en_enable(); + si12t_i2c_read_bytes(SI12T_OUTPUT1, key_buf, read_size); // read output registers + si12t_en_disable(); + + uint8_t key_trigger_count = 0; + uint8_t single_key; + uint32_t touch_key = (key_buf[2] << 16) + (key_buf[1] << 8) + key_buf[0]; + // find which key is touched + uint8_t channel_num = 12; + int touched_compare = 0x00000003; + uint8_t offset = 2; + for (uint8_t z = 0; z < channel_num; z++) { + if (((touch_key >> offset) * z) & touched_compare) { + single_key = z; + key_trigger_count++; + } + } + /* only one key is touched. */ + if (key_trigger_count == 1) { + osal_printk("key %d is touched\n", key_map[single_key]); + } +} + +static void* si12t_app_task(const char* arg) { + unused(arg); + uint32_t baudrate = I2C_SET_BAUDRATE; + uint8_t hscode = I2C_MASTER_ADDR; + uint16_t dev_addr = CONFIG_I2C_SLAVE_ADDR; + + osal_printk("i2c dev addr 0x%x\n", dev_addr); + + /* SI12T EN PIN init. */ + uapi_pin_set_mode(CONFIG_SI12T_EN_PIN, HAL_PIO_FUNC_GPIO); + uapi_gpio_set_dir(CONFIG_SI12T_EN_PIN, GPIO_DIRECTION_OUTPUT); + uapi_gpio_set_val(CONFIG_SI12T_EN_PIN, GPIO_LEVEL_LOW); + + /* I2C master init config. */ + app_i2c_init_pin(); + uapi_i2c_master_init(CONFIG_I2C_MASTER_BUS_ID, baudrate, hscode); + + si12t_start_init(); + + while (1) { + si12t_key_scan(); + osal_msleep(I2C_TASK_DURATION_MS); + } + + return NULL; +} + +static void si12t_app_entry(void) { + osal_task* task_handle = NULL; + osal_kthread_lock(); + task_handle = osal_kthread_create((osal_kthread_handler)si12t_app_task, 0, "Si12tAppTask", APP_TASK_STACK_SIZE); + if (task_handle != NULL) { + osal_kthread_set_priority(task_handle, APP_TASK_PRIO); + osal_kfree(task_handle); + } + osal_kthread_unlock(); + osal_printk("SI12T I2C master demo task created!\r\n"); +} + +/* Run the si12t app entry. */ +app_run(si12t_app_entry); \ No newline at end of file diff --git a/vendor/others/touch_by_si12t/si12t_touch.h b/vendor/others/touch_by_si12t/si12t_touch.h new file mode 100644 index 0000000000000000000000000000000000000000..e3a7ecd0d2b654883add7e3ceea29df23b10e2ee --- /dev/null +++ b/vendor/others/touch_by_si12t/si12t_touch.h @@ -0,0 +1,48 @@ +#ifndef SI12T_TOUCH_H +#define SI12T_TOUCH_H +/* + * Copyright (c) wangjinmin + * + * Description: si12t register control Source. \n + */ + + +/**************SI12T_TOUCH register****************/ + +#define SI12T_SENSITIVITY1 0x02 +#define SI12T_SENSITIVITY2 0x03 +#define SI12T_SENSITIVITY3 0x04 +#define SI12T_SENSITIVITY4 0x05 +#define SI12T_SENSITIVITY5 0x06 +#define SI12T_SENSITIVITY6 0x07 +#define SI12T_SENSITIVITYX_RST_VAL 10111011b + +#define SI12T_CTRL1 0x08 +#define SI12T_CTRL2 0x09 +#define SI12T_CTRL1_RST_VAL 00100010b + +#define SI12T_REF_RST1 0x0A +#define SI12T_REF_RST2 0x0B +#define SI12T_REF_RST1_RST_VAL 11111110b +#define SI12T_REF_RST2_RST_VAL 00001111b + +#define SI12T_CH_HOLD1 0x0C +#define SI12T_CH_HOLD2 0x0D +#define SI12T_CH_HOLD1_RST_VAL 11111110b +#define SI12T_CH_HOLD2_RST_VAL 00001111b + +#define SI12T_CAL_HOLD1 0x0E +#define SI12T_CAL_HOLD2 0x0F +#define SI12T_CAL_HOLD1_RST_VAL 00000000b +#define SI12T_CAL_HOLD2_RST_VAL 00000000b + +#define SI12T_OUTPUT1 0x10 +#define SI12T_OUTPUT2 0x11 +#define SI12T_OUTPUT3 0x12 +#define SI12T_OUTPUT1_RST_VAL 00000000b +#define SI12T_OUTPUT2_RST_VAL 00000000b +#define SI12T_OUTPUT3_RST_VAL 00000000b + +/*********************************************/ + +#endif \ No newline at end of file