Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add FT63XX touch #43

Merged
merged 1 commit into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions components/micropython/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,12 @@ if(CONFIG_COMPONENT_MICROPYTHON_ENABLE)
append_srcs_dir(ADD_SRCS "port/src/touchscreen/ft52xx")
append_srcs_dir(ADD_SRCS "port/src/touchscreen/ns2009")
endif()
if(CONFIG_MAIXPY_TOUCH_SCREEN_DRIVER_FT63XX)
list(APPEND ADD_INCLUDE "${mpy_port_dir}/src/touchscreen/ft63xx"
"${mpy_port_dir}/src/touchscreen/ns2009/include")
append_srcs_dir(ADD_SRCS "port/src/touchscreen/ft63xx")
append_srcs_dir(ADD_SRCS "port/src/touchscreen/ns2009")
endif()
endif()
# omv minimum
if(CONFIG_MAIXPY_OMV_MINIMUM)
Expand Down
2 changes: 2 additions & 0 deletions components/micropython/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ menu "Micropython configurations"
bool "Select ns2009 touch screen driver"
config MAIXPY_TOUCH_SCREEN_DRIVER_FT52XX
bool "Select ft52xx touch screen driver"
config MAIXPY_TOUCH_SCREEN_DRIVER_FT63XX
bool "Select ft63xx touch screen driver"
endchoice

config MAIXPY_OMV_MINIMUM
Expand Down
106 changes: 106 additions & 0 deletions components/micropython/port/src/touchscreen/ft63xx/ft63xx.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#include "ft63xx.h"
#include <string.h>
#include <stdlib.h>
#include <tsfilter.h>
#include <stdio.h>
#include "fpioa.h"
#include "sleep.h"
#include <math.h>
#include "machine_i2c.h"
#include "py/obj.h"


static i2c_device_number_t m_i2c_num;

static inline int hi2c_mem_recv(uint8_t addr,uint8_t mem_addr,uint8_t *read_buf,uint16_t read_size)
{
return maix_i2c_recv_data(m_i2c_num, addr, &mem_addr, 1, read_buf, read_size, 100);
}

int ts_ft63xx_probe(ts_ft63xx_t *ts,touchscreen_config_t *config,ts_lcd_cfg cfg)
{
ts->i2c_num = config->i2c->i2c;
ts->last_type = TOUCHSCREEN_STATUS_IDLE;
memcpy(&ts->cfg,&cfg,sizeof(ts_lcd_cfg));
ts->last_x = ts->last_y = 0;

uint8_t reg_val;

if (hi2c_mem_recv(FT63XX_SLAVE_ADDR,FT_ID_G_FOCALTECH_ID,&reg_val,1) != 0)
return EIO;

if (reg_val != 0x11)
return EXDEV;

return 0;
}


void ts_ft63xx_poll(ts_ft63xx_t *ts,int *x,int *y,touchscreen_type_t *type)
{
union
{
struct
{
uint8_t touch_num;
uint8_t p1_xh;
uint8_t p1_xl;
uint8_t p1_yh;
uint8_t p1_yl;
};
uint8_t dat[5];
}reg_val;


if (hi2c_mem_recv(FT63XX_SLAVE_ADDR,FT_REG_NUM_FINGER,reg_val.dat,5) != 0)
{
*type = TOUCHSCREEN_STATUS_IDLE;
return;
}

if (reg_val.touch_num&7)
{
*type = TOUCHSCREEN_STATUS_PRESS;
int reg_x = ((reg_val.p1_xh&0x0f)<<8) + reg_val.p1_xl;
int reg_y = ((reg_val.p1_yh&0x0f)<<8) + reg_val.p1_yl;

switch (ts->cfg.dir)
{
case 0:
*x = reg_x;
*y = reg_y;
break;
case 1:
*x = reg_y;
*y = ts->cfg.height - reg_x;
break;
case 2:
*x = ts->cfg.width - reg_x;
*y = ts->cfg.height - reg_y;
break;
case 3:
*x = ts->cfg.width - reg_y;
*y = reg_x;
break;
default:
break;
}

}
else
{
*type = TOUCHSCREEN_STATUS_RELEASE;
*x = ts->last_x;
*y = ts->last_y;
}

if (ts->last_type == TOUCHSCREEN_STATUS_PRESS && (*x != ts->last_x || *y != ts->last_y))
{
*type = TOUCHSCREEN_STATUS_MOVE;
}


ts->last_type = *type;
ts->last_x = *x;
ts->last_y = *y;
}
35 changes: 35 additions & 0 deletions components/micropython/port/src/touchscreen/ft63xx/ft63xx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef _FT63XX_H_
#define _FT63XX_H_

#include <stdint.h>
#include "touchscreen.h"

#define FT63XX_SLAVE_ADDR 56
#define FT_ID_G_FOCALTECH_ID 0xA8
#define FT_REG_NUM_FINGER 0x02 //触摸状态寄存器
#define FT_TP1_REG 0X03 //第一个触摸点数据地址

typedef struct
{
uint8_t dir;
uint32_t width;
uint32_t height;
}ts_lcd_cfg;


typedef struct
{
i2c_device_number_t i2c_num;
touchscreen_type_t last_type;
int last_x;
int last_y;
ts_lcd_cfg cfg;
}ts_ft63xx_t;


int ts_ft63xx_probe(ts_ft63xx_t *ts,touchscreen_config_t *config,ts_lcd_cfg cfg);
void ts_ft63xx_poll(ts_ft63xx_t *ts,int *x,int *y,touchscreen_type_t *type);


#endif //

89 changes: 74 additions & 15 deletions components/micropython/port/src/touchscreen/ns2009/touchscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,25 @@
#include "touchscreen.h"
#include "machine_i2c.h"
#include "errno.h"
#include "ns2009.h"
#include "tscal.h"
#if defined(CONFIG_MAIXPY_TOUCH_SCREEN_DRIVER_FT52XX)

#if defined(CONFIG_MAIXPY_TOUCH_SCREEN_DRIVER_NS2009)
#include "ns2009.h"
static struct ts_ns2009_pdata_t *ts_ns2009_pdata;
int ns2009_hal_i2c_init_default();
#elif defined(CONFIG_MAIXPY_TOUCH_SCREEN_DRIVER_FT52XX)
#include "ns2009.h"
#include "ft52xx.h"
static uint8_t drives_type = 0;
static struct ts_ns2009_pdata_t *ts_ns2009_pdata;
#elif defined(CONFIG_MAIXPY_TOUCH_SCREEN_DRIVER_FT63XX)
#include "ft63xx.h"
static ts_ft63xx_t *p_ts_ft63xx = NULL;
#endif

static struct ts_ns2009_pdata_t *ts_ns2009_pdata;

i2c_device_number_t m_i2c_num = 0;
static bool is_init = false;
static uint8_t drives_type = 0;

int ns2009_hal_i2c_init_default();

int touchscreen_init( void* arg)
{
Expand All @@ -25,11 +32,15 @@ int touchscreen_init( void* arg)
{
m_i2c_num = config->i2c->i2c;
}
#if defined(CONFIG_MAIXPY_TOUCH_SCREEN_DRIVER_NS2009)
else
{
ns2009_hal_i2c_init_default();
}
#if defined(CONFIG_MAIXPY_TOUCH_SCREEN_DRIVER_FT52XX)
ts_ns2009_pdata = ts_ns2009_probe(config->calibration, &err);
if (ts_ns2009_pdata == NULL || err!=0)
return err;
#elif defined(CONFIG_MAIXPY_TOUCH_SCREEN_DRIVER_FT52XX)
switch (config->drives_type)
{
case TOUCHSCREEN_TYPE_NS2009:
Expand All @@ -47,9 +58,19 @@ int touchscreen_init( void* arg)
default:
break;
}
#else
ts_ns2009_pdata = ts_ns2009_probe(config->calibration, &err);
if (ts_ns2009_pdata == NULL || err!=0)
#elif defined(CONFIG_MAIXPY_TOUCH_SCREEN_DRIVER_FT63XX)

if (p_ts_ft63xx != NULL)
return 0;

p_ts_ft63xx = malloc(sizeof(ts_ft63xx_t));
if (p_ts_ft63xx == NULL)
return EIO;

ts_lcd_cfg cfg = {1,320,240};

err = ts_ft63xx_probe(p_ts_ft63xx,config,cfg);
if (err)
return err;
#endif
is_init = true;
Expand All @@ -73,10 +94,36 @@ int touchscreen_read( int* type, int* x, int* y)
default:
break;
}
*x = 0;
*y = 0;
switch (ts_ns2009_pdata->event->type)
{
case TOUCH_BEGIN:
*x = ts_ns2009_pdata->event->x;
*y = ts_ns2009_pdata->event->y;
*type = TOUCHSCREEN_STATUS_PRESS;
break;

case TOUCH_MOVE:
*x = ts_ns2009_pdata->event->x;
*y = ts_ns2009_pdata->event->y;
*type = TOUCHSCREEN_STATUS_MOVE;
break;

case TOUCH_END:
*x= ts_ns2009_pdata->event->x;
*y= ts_ns2009_pdata->event->y;
*type = TOUCHSCREEN_STATUS_RELEASE;
break;
default:
break;
}
return 0;
#elif defined(CONFIG_MAIXPY_TOUCH_SCREEN_DRIVER_FT63XX)
ts_ft63xx_poll(p_ts_ft63xx,x,y,(touchscreen_type_t *)type);
return 0;
#else
ts_ns2009_poll(ts_ns2009_pdata);
#endif /*CONFIG_MAIXPY_TOUCH_SCREEN_DRIVER_FT52XX*/

*x = 0;
*y = 0;
switch (ts_ns2009_pdata->event->type)
Expand All @@ -102,6 +149,7 @@ int touchscreen_read( int* type, int* x, int* y)
break;
}
return 0;
#endif /*CONFIG_MAIXPY_TOUCH_SCREEN_DRIVER_FT52XX*/
}

int touchscreen_deinit()
Expand All @@ -117,6 +165,12 @@ int touchscreen_deinit()
default:
break;
}
#elif defined(CONFIG_MAIXPY_TOUCH_SCREEN_DRIVER_FT63XX)
if (p_ts_ft63xx)
{
free(p_ts_ft63xx);
}

#else
ts_ns2009_remove(ts_ns2009_pdata);
#endif
Expand All @@ -126,15 +180,15 @@ int touchscreen_deinit()

int touchscreen_calibrate(int w, int h, int* cal)
{
#if defined(CONFIG_MAIXPY_TOUCH_SCREEN_DRIVER_FT52XX)
#if defined(CONFIG_MAIXPY_TOUCH_SCREEN_DRIVER_FT52XX) || defined(CONFIG_MAIXPY_TOUCH_SCREEN_DRIVER_FT63XX)
return 0;
#else
return do_tscal(ts_ns2009_pdata, w, h, cal);
#endif
}

//////////// HAL ////////////

#if defined(CONFIG_MAIXPY_TOUCH_SCREEN_DRIVER_NS2009)
int ns2009_hal_i2c_init_default()
{
m_i2c_num = 0; // default i2c 0
Expand All @@ -144,13 +198,18 @@ int ns2009_hal_i2c_init_default()
return 0;
}

int ns2009_hal_i2c_recv(const uint8_t *send_buf, size_t send_buf_len, uint8_t *receive_buf,
size_t receive_buf_len)
{
return maix_i2c_recv_data(m_i2c_num, NS2009_SLV_ADDR, send_buf, send_buf_len, receive_buf, receive_buf_len, 20);
}
#elif defined(CONFIG_MAIXPY_TOUCH_SCREEN_DRIVER_FT52XX)
int ns2009_hal_i2c_recv(const uint8_t *send_buf, size_t send_buf_len, uint8_t *receive_buf,
size_t receive_buf_len)
{
return maix_i2c_recv_data(m_i2c_num, NS2009_SLV_ADDR, send_buf, send_buf_len, receive_buf, receive_buf_len, 20);
}

#if defined(CONFIG_MAIXPY_TOUCH_SCREEN_DRIVER_FT52XX)
int ft52xx_hal_i2c_recv(const uint8_t *send_buf, size_t send_buf_len, uint8_t *receive_buf,
size_t receive_buf_len)
{
Expand Down
Loading