typedefstruct{ i2c_mode_t mode; /*!< I2C mode */ int sda_io_num; /*!< GPIO number for I2C sda signal */ int scl_io_num; /*!< GPIO number for I2C scl signal */ bool sda_pullup_en; /*!< Internal GPIO pull mode for I2C sda signal*/ bool scl_pullup_en; /*!< Internal GPIO pull mode for I2C scl signal*/
union { struct { uint32_t clk_speed; /*!< I2C clock frequency for master mode, (no higher than 1MHz for now) */ } master; /*!< I2C master config */ #if SOC_I2C_SUPPORT_SLAVE struct { uint8_t addr_10bit_en; /*!< I2C 10bit address mode enable for slave mode */ uint16_t slave_addr; /*!< I2C address for slave mode */ uint32_t maximum_speed; /*!< I2C expected clock speed from SCL. */ } slave; /*!< I2C slave config */ #endif// SOC_I2C_SUPPORT_SLAVE }; uint32_t clk_flags; /*!< Bitwise of ``I2C_SCLK_SRC_FLAG_**FOR_DFS**`` for clk source choice*/ } i2c_config_t;
typedefenum { /* @---> X | Y */ TOUCH_DIR_LRTB, /**< From left to right then from top to bottom, this consider as the original direction of the touch panel*/
/* Y | @---> X */ TOUCH_DIR_LRBT, /**< From left to right then from bottom to top */
/* X <---@ | Y */ TOUCH_DIR_RLTB, /**< From right to left then from top to bottom */
/* Y | X <---@ */ TOUCH_DIR_RLBT, /**< From right to left then from bottom to top */
/* @---> Y | X */ TOUCH_DIR_TBLR, /**< From top to bottom then from left to right */
/* X | @---> Y */ TOUCH_DIR_BTLR, /**< From bottom to top then from left to right */
/* Y <---@ | X */ TOUCH_DIR_TBRL, /**< From top to bottom then from right to left */
/* X | Y <---@ */ TOUCH_DIR_BTRL, /**< From bottom to top then from right to left */
uint8_tft6236_init(touch_panel_config_t *config) { uint8_t ret=0; uint8_t cipher=0;//must be 0x64 uint8_t firmid=0;//Firmware Version uint8_t data=0;
g_dev.i2c.addr=config->i2c.addr; g_dev.i2c.i2c_num=config->i2c.i2c_num; g_dev.i2c.scl_pin=config->i2c.i2c_scl; g_dev.i2c.sda_pin=config->i2c.i2c_sda; g_dev.int_pin=config->pin_num_int; g_dev.rst_pin=config->pin_num_rst; g_dev.width=config->width; g_dev.height=config->height; ft6236_set_direction(config->direction); //bsp initialize and test ret += ft6236_interface_init(&g_dev); ret += ft6236_read_reg(&g_dev,FT6236_REG_FIRMID,1,&firmid); ret += ft6236_read_reg(&g_dev,FT6236_REG_CIPHER,1,&cipher); if(ret!=0 ||cipher!=0x64)//chip id changes with chips { ESP_LOGI(TAG,"Initialize interface fail.cipher=%x firmware version=%x.",cipher,firmid); return1; } ESP_LOGI(TAG,"cipher=%x firmware version=%x.",cipher,firmid); //set the interrupt mod to polling(continuous low level) data=0; ret += ft6236_write_one_reg(&g_dev, FT6236_REG_G_MODE, data); //set the touch detect threshold(lower is sensitive) data=22; ret += ft6236_write_one_reg(&g_dev, FT6236_REG_TH_GROUP, data);
/** * confirm if there is touch event * @return 1:touched 0:nothing */ uint8_tft6236_is_press(void) { /** * @note There are two ways to determine weather the touch panel is pressed * 1. Read the IRQ line of touch controller * 2. Read number of points touched in the register */ if (-1 != g_dev.int_pin) { return !gpio_get_level((gpio_num_t)g_dev.int_pin); } uint8_t num; ft6236_read_reg(&g_dev,FT6236_REG_TD_STATUS,1,&num); if((num&0x07) ==0) return0; return1; }