1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-19 05:58:09 +00:00

refactor(core): modify i2c driver to allow usage of more i2c peripherals

[no changelog]
This commit is contained in:
tychovrahe 2023-06-16 23:12:51 +02:00 committed by TychoVrahe
parent 02d574b002
commit 9cd59105c1
6 changed files with 166 additions and 119 deletions

View File

@ -13,17 +13,19 @@
#include "displays/ltdc.h"
#define I2C_INSTANCE I2C3
#define I2C_INSTANCE_CLK_EN __HAL_RCC_I2C3_CLK_ENABLE
#define I2C_INSTANCE_CLK_DIS __HAL_RCC_I2C3_CLK_DISABLE
#define I2C_INSTANCE_PIN_AF GPIO_AF4_I2C3
#define I2C_INSTANCE_SDA_PORT GPIOC
#define I2C_INSTANCE_SDA_PIN GPIO_PIN_9
#define I2C_INSTANCE_SDA_CLK_EN __HAL_RCC_GPIOC_CLK_ENABLE
#define I2C_INSTANCE_SCL_PORT GPIOA
#define I2C_INSTANCE_SCL_PIN GPIO_PIN_8
#define I2C_INSTANCE_SCL_CLK_EN __HAL_RCC_GPIOA_CLK_ENABLE
#define I2C_INSTANCE_FORCE_RESET __HAL_RCC_I2C3_FORCE_RESET
#define I2C_INSTANCE_RELEASE_RESET __HAL_RCC_I2C3_RELEASE_RESET
#define I2C_COUNT 1
#define I2C_INSTANCE_1 I2C3
#define I2C_INSTANCE_1_CLK_EN __HAL_RCC_I2C3_CLK_ENABLE
#define I2C_INSTANCE_1_CLK_DIS __HAL_RCC_I2C3_CLK_DISABLE
#define I2C_INSTANCE_1_PIN_AF GPIO_AF4_I2C3
#define I2C_INSTANCE_1_SDA_PORT GPIOC
#define I2C_INSTANCE_1_SDA_PIN GPIO_PIN_9
#define I2C_INSTANCE_1_SDA_CLK_EN __HAL_RCC_GPIOC_CLK_ENABLE
#define I2C_INSTANCE_1_SCL_PORT GPIOA
#define I2C_INSTANCE_1_SCL_PIN GPIO_PIN_8
#define I2C_INSTANCE_1_SCL_CLK_EN __HAL_RCC_GPIOA_CLK_ENABLE
#define I2C_INSTANCE_1_RESET_FLG RCC_APB1RSTR_I2C3RST
#define TOUCH_I2C_NUM 0
#endif //_STM32F429I_DISC1_H

View File

@ -11,18 +11,20 @@
#define USE_RGB_COLORS 1
#define USE_DISP_I8080_8BIT_DW 1
#define I2C_INSTANCE I2C1
#define I2C_INSTANCE_CLK_EN __HAL_RCC_I2C1_CLK_ENABLE
#define I2C_INSTANCE_CLK_DIS __HAL_RCC_I2C1_CLK_DISABLE
#define I2C_INSTANCE_PIN_AF GPIO_AF4_I2C1
#define I2C_INSTANCE_SDA_PORT GPIOB
#define I2C_INSTANCE_SDA_PIN GPIO_PIN_7
#define I2C_INSTANCE_SDA_CLK_EN __HAL_RCC_GPIOB_CLK_ENABLE
#define I2C_INSTANCE_SCL_PORT GPIOB
#define I2C_INSTANCE_SCL_PIN GPIO_PIN_6
#define I2C_INSTANCE_SCL_CLK_EN __HAL_RCC_GPIOB_CLK_ENABLE
#define I2C_INSTANCE_FORCE_RESET __HAL_RCC_I2C1_FORCE_RESET
#define I2C_INSTANCE_RELEASE_RESET __HAL_RCC_I2C1_RELEASE_RESET
#define I2C_COUNT 1
#define I2C_INSTANCE_1 I2C1
#define I2C_INSTANCE_1_CLK_EN __HAL_RCC_I2C1_CLK_ENABLE
#define I2C_INSTANCE_1_CLK_DIS __HAL_RCC_I2C1_CLK_DISABLE
#define I2C_INSTANCE_1_PIN_AF GPIO_AF4_I2C1
#define I2C_INSTANCE_1_SDA_PORT GPIOB
#define I2C_INSTANCE_1_SDA_PIN GPIO_PIN_7
#define I2C_INSTANCE_1_SDA_CLK_EN __HAL_RCC_GPIOB_CLK_ENABLE
#define I2C_INSTANCE_1_SCL_PORT GPIOB
#define I2C_INSTANCE_1_SCL_PIN GPIO_PIN_6
#define I2C_INSTANCE_1_SCL_CLK_EN __HAL_RCC_GPIOB_CLK_ENABLE
#define I2C_INSTANCE_1_RESET_FLG RCC_APB1RSTR_I2C1RST
#define TOUCH_I2C_NUM 0
#include "displays/st7789v.h"

View File

@ -5,27 +5,47 @@
#include "i2c.h"
#include "common.h"
static I2C_HandleTypeDef i2c_handle;
static I2C_HandleTypeDef i2c_handle[I2C_COUNT];
void HAL_I2C_MspInit(I2C_HandleTypeDef *hi2c) {
// enable I2C clock
I2C_INSTANCE_CLK_EN();
I2C_INSTANCE_SCL_CLK_EN();
I2C_INSTANCE_SDA_CLK_EN();
}
typedef struct {
I2C_TypeDef *Instance;
GPIO_TypeDef *SclPort;
GPIO_TypeDef *SdaPort;
uint16_t SclPin;
uint16_t SdaPin;
uint8_t PinAF;
uint32_t Reset;
} i2c_instance_t;
void HAL_I2C_MspDeInit(I2C_HandleTypeDef *hi2c) {
// disable I2C clock
I2C_INSTANCE_CLK_DIS();
}
i2c_instance_t i2c_defs[I2C_COUNT] = {
{
.Instance = I2C_INSTANCE_1,
.SclPort = I2C_INSTANCE_1_SCL_PORT,
.SdaPort = I2C_INSTANCE_1_SDA_PORT,
.SclPin = I2C_INSTANCE_1_SCL_PIN,
.SdaPin = I2C_INSTANCE_1_SDA_PIN,
.PinAF = I2C_INSTANCE_1_PIN_AF,
.Reset = I2C_INSTANCE_1_RESET_FLG,
},
#ifdef I2C_INSTANCE_2
{
.Instance = I2C_INSTANCE_2,
.SclPort = I2C_INSTANCE_2_SCL_PORT,
.SdaPort = I2C_INSTANCE_2_SDA_PORT,
.SclPin = I2C_INSTANCE_2_SCL_PIN,
.SdaPin = I2C_INSTANCE_2_SDA_PIN,
.PinAF = I2C_INSTANCE_2_PIN_AF,
.Reset = I2C_INSTANCE_2_RESET_FLG,
},
#endif
void i2c_init(void) {
if (i2c_handle.Instance) {
};
void i2c_init_instance(uint16_t idx, i2c_instance_t *instance) {
if (i2c_handle[idx].Instance) {
return;
}
HAL_I2C_MspInit(&i2c_handle);
GPIO_InitTypeDef GPIO_InitStructure;
// configure CTP I2C SCL and SDA GPIO lines
@ -35,39 +55,56 @@ void i2c_init(void) {
GPIO_SPEED_FREQ_LOW; // I2C is a KHz bus and low speed is still good into
// the low MHz
GPIO_InitStructure.Alternate = I2C_INSTANCE_PIN_AF;
GPIO_InitStructure.Pin = I2C_INSTANCE_SCL_PIN;
HAL_GPIO_Init(I2C_INSTANCE_SCL_PORT, &GPIO_InitStructure);
GPIO_InitStructure.Alternate = instance->PinAF;
GPIO_InitStructure.Pin = instance->SclPin;
HAL_GPIO_Init(instance->SclPort, &GPIO_InitStructure);
GPIO_InitStructure.Alternate = I2C_INSTANCE_PIN_AF;
GPIO_InitStructure.Pin = I2C_INSTANCE_SDA_PIN;
HAL_GPIO_Init(I2C_INSTANCE_SDA_PORT, &GPIO_InitStructure);
GPIO_InitStructure.Alternate = instance->PinAF;
;
GPIO_InitStructure.Pin = instance->SdaPin;
HAL_GPIO_Init(instance->SdaPort, &GPIO_InitStructure);
i2c_handle.Instance = I2C_INSTANCE;
i2c_handle.Init.ClockSpeed = 200000;
i2c_handle.Init.DutyCycle = I2C_DUTYCYCLE_16_9;
i2c_handle.Init.OwnAddress1 = 0xFE; // master
i2c_handle.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
i2c_handle.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
i2c_handle.Init.OwnAddress2 = 0;
i2c_handle.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
i2c_handle.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
i2c_handle[idx].Instance = instance->Instance;
i2c_handle[idx].Init.ClockSpeed = 200000;
i2c_handle[idx].Init.DutyCycle = I2C_DUTYCYCLE_16_9;
i2c_handle[idx].Init.OwnAddress1 = 0xFE; // master
i2c_handle[idx].Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
i2c_handle[idx].Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
i2c_handle[idx].Init.OwnAddress2 = 0;
i2c_handle[idx].Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
i2c_handle[idx].Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
if (HAL_OK != HAL_I2C_Init(&i2c_handle)) {
if (HAL_OK != HAL_I2C_Init(&i2c_handle[idx])) {
ensure(secfalse, "I2C was not loaded properly.");
return;
}
}
void _i2c_deinit(void) {
if (i2c_handle.Instance) {
HAL_I2C_DeInit(&i2c_handle);
i2c_handle.Instance = NULL;
void i2c_init(void) {
// enable I2C clock
I2C_INSTANCE_1_CLK_EN();
I2C_INSTANCE_1_SCL_CLK_EN();
I2C_INSTANCE_1_SDA_CLK_EN();
i2c_init_instance(0, &i2c_defs[0]);
#ifdef I2C_INSTANCE_2
I2C_INSTANCE_2_CLK_EN();
I2C_INSTANCE_2_SCL_CLK_EN();
I2C_INSTANCE_2_SDA_CLK_EN();
i2c_init_instance(1, &i2c_defs[1]);
#endif
}
void i2c_deinit(uint16_t idx) {
if (i2c_handle[idx].Instance) {
HAL_I2C_DeInit(&i2c_handle[idx]);
i2c_handle[idx].Instance = NULL;
}
}
void _i2c_ensure_pin(GPIO_TypeDef *port, uint16_t GPIO_Pin,
GPIO_PinState PinState) {
void i2c_ensure_pin(GPIO_TypeDef *port, uint16_t GPIO_Pin,
GPIO_PinState PinState) {
HAL_GPIO_WritePin(port, GPIO_Pin, PinState);
while (HAL_GPIO_ReadPin(port, GPIO_Pin) != PinState)
;
@ -77,76 +114,77 @@ void _i2c_ensure_pin(GPIO_TypeDef *port, uint16_t GPIO_Pin,
//
// https://www.st.com/content/ccc/resource/technical/document/errata_sheet/7f/05/b0/bc/34/2f/4c/21/CD00288116.pdf/files/CD00288116.pdf/jcr:content/translations/en.CD00288116.pdf
void i2c_cycle(void) {
// PIN6 is SCL, PIN7 is SDA
void i2c_cycle(uint16_t idx) {
i2c_instance_t *instance = &i2c_defs[0];
// 1. Disable I2C peripheral
_i2c_deinit();
i2c_deinit(idx);
// 2. Configure SCL/SDA as GPIO OUTPUT Open Drain
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStructure.Pin = I2C_INSTANCE_SDA_PIN;
HAL_GPIO_Init(I2C_INSTANCE_SDA_PORT, &GPIO_InitStructure);
GPIO_InitStructure.Pin = I2C_INSTANCE_SCL_PIN;
HAL_GPIO_Init(I2C_INSTANCE_SCL_PORT, &GPIO_InitStructure);
GPIO_InitStructure.Pin = instance->SdaPin;
HAL_GPIO_Init(instance->SdaPort, &GPIO_InitStructure);
GPIO_InitStructure.Pin = instance->SclPin;
HAL_GPIO_Init(instance->SclPort, &GPIO_InitStructure);
HAL_Delay(50);
// 3. Check SCL and SDA High level
_i2c_ensure_pin(I2C_INSTANCE_SCL_PORT, I2C_INSTANCE_SCL_PIN, GPIO_PIN_SET);
_i2c_ensure_pin(I2C_INSTANCE_SDA_PORT, I2C_INSTANCE_SDA_PIN, GPIO_PIN_SET);
i2c_ensure_pin(instance->SclPort, instance->SclPin, GPIO_PIN_SET);
i2c_ensure_pin(instance->SdaPort, instance->SdaPin, GPIO_PIN_SET);
// 4+5. Check SDA Low level
_i2c_ensure_pin(I2C_INSTANCE_SDA_PORT, I2C_INSTANCE_SDA_PIN, GPIO_PIN_RESET);
i2c_ensure_pin(instance->SdaPort, instance->SdaPin, GPIO_PIN_RESET);
// 6+7. Check SCL Low level
_i2c_ensure_pin(I2C_INSTANCE_SCL_PORT, I2C_INSTANCE_SCL_PIN, GPIO_PIN_RESET);
i2c_ensure_pin(instance->SclPort, instance->SclPin, GPIO_PIN_RESET);
// 8+9. Check SCL High level
_i2c_ensure_pin(I2C_INSTANCE_SCL_PORT, I2C_INSTANCE_SCL_PIN, GPIO_PIN_SET);
i2c_ensure_pin(instance->SclPort, instance->SclPin, GPIO_PIN_SET);
// 10+11. Check SDA High level
_i2c_ensure_pin(I2C_INSTANCE_SDA_PORT, I2C_INSTANCE_SDA_PIN, GPIO_PIN_SET);
i2c_ensure_pin(instance->SclPort, instance->SdaPin, GPIO_PIN_SET);
// 12. Configure SCL/SDA as Alternate function Open-Drain
GPIO_InitStructure.Mode = GPIO_MODE_AF_OD;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStructure.Alternate = I2C_INSTANCE_PIN_AF;
GPIO_InitStructure.Pin = I2C_INSTANCE_SCL_PIN;
HAL_GPIO_Init(I2C_INSTANCE_SCL_PORT, &GPIO_InitStructure);
GPIO_InitStructure.Pin = I2C_INSTANCE_SDA_PIN;
HAL_GPIO_Init(I2C_INSTANCE_SDA_PORT, &GPIO_InitStructure);
GPIO_InitStructure.Alternate = instance->PinAF;
GPIO_InitStructure.Pin = instance->SclPin;
HAL_GPIO_Init(instance->SclPort, &GPIO_InitStructure);
GPIO_InitStructure.Pin = instance->SdaPin;
HAL_GPIO_Init(instance->SdaPort, &GPIO_InitStructure);
HAL_Delay(50);
// 13. Set SWRST bit in I2Cx_CR1 register
I2C_INSTANCE_FORCE_RESET();
// 13. Force reset
RCC->APB1RSTR |= instance->Reset;
HAL_Delay(50);
// 14. Clear SWRST bit in I2Cx_CR1 register
I2C_INSTANCE_RELEASE_RESET();
// 14. Release reset
RCC->APB1RSTR &= ~instance->Reset;
// 15. Enable the I2C peripheral
i2c_init();
i2c_init_instance(idx, instance);
HAL_Delay(10);
}
HAL_StatusTypeDef i2c_transmit(uint8_t addr, uint8_t *data, uint16_t len,
uint32_t timeout) {
return HAL_I2C_Master_Transmit(&i2c_handle, addr, data, len, timeout);
HAL_StatusTypeDef i2c_transmit(uint16_t idx, uint8_t addr, uint8_t *data,
uint16_t len, uint32_t timeout) {
return HAL_I2C_Master_Transmit(&i2c_handle[idx], addr, data, len, timeout);
}
HAL_StatusTypeDef i2c_receive(uint8_t addr, uint8_t *data, uint16_t len,
uint32_t timeout) {
return HAL_I2C_Master_Receive(&i2c_handle, addr, data, len, timeout);
HAL_StatusTypeDef i2c_receive(uint16_t idx, uint8_t addr, uint8_t *data,
uint16_t len, uint32_t timeout) {
return HAL_I2C_Master_Receive(&i2c_handle[idx], addr, data, len, timeout);
}
HAL_StatusTypeDef i2c_mem_write(uint8_t addr, uint16_t mem_addr,
HAL_StatusTypeDef i2c_mem_write(uint16_t idx, uint8_t addr, uint16_t mem_addr,
uint16_t mem_addr_size, uint8_t *data,
uint16_t len, uint32_t timeout) {
return HAL_I2C_Mem_Write(&i2c_handle, addr, mem_addr, mem_addr_size, data,
len, timeout);
return HAL_I2C_Mem_Write(&i2c_handle[idx], addr, mem_addr, mem_addr_size,
data, len, timeout);
}
HAL_StatusTypeDef i2c_mem_read(uint8_t addr, uint16_t mem_addr,
HAL_StatusTypeDef i2c_mem_read(uint16_t idx, uint8_t addr, uint16_t mem_addr,
uint16_t mem_addr_size, uint8_t *data,
uint16_t len, uint32_t timeout) {
return HAL_I2C_Mem_Read(&i2c_handle, addr, mem_addr, mem_addr_size, data, len,
timeout);
return HAL_I2C_Mem_Read(&i2c_handle[idx], addr, mem_addr, mem_addr_size, data,
len, timeout);
}

View File

@ -2,14 +2,14 @@
#include STM32_HAL_H
void i2c_init(void);
void i2c_cycle(void);
HAL_StatusTypeDef i2c_transmit(uint8_t addr, uint8_t *data, uint16_t len,
uint32_t timeout);
HAL_StatusTypeDef i2c_receive(uint8_t addr, uint8_t *data, uint16_t len,
uint32_t timeout);
HAL_StatusTypeDef i2c_mem_write(uint8_t addr, uint16_t mem_addr,
void i2c_cycle(uint16_t idx);
HAL_StatusTypeDef i2c_transmit(uint16_t idx, uint8_t addr, uint8_t *data,
uint16_t len, uint32_t timeout);
HAL_StatusTypeDef i2c_receive(uint16_t idx, uint8_t addr, uint8_t *data,
uint16_t len, uint32_t timeout);
HAL_StatusTypeDef i2c_mem_write(uint16_t idx, uint8_t addr, uint16_t mem_addr,
uint16_t mem_addr_size, uint8_t *data,
uint16_t len, uint32_t timeout);
HAL_StatusTypeDef i2c_mem_read(uint8_t addr, uint16_t mem_addr,
HAL_StatusTypeDef i2c_mem_read(uint16_t idx, uint8_t addr, uint16_t mem_addr,
uint16_t mem_addr_size, uint8_t *data,
uint16_t len, uint32_t timeout);

View File

@ -18,6 +18,7 @@
*/
#include STM32_HAL_H
#include TREZOR_BOARD
#include <string.h>
@ -99,11 +100,11 @@ void touch_set_mode(void) {
// generates a pulse when new data is available
uint8_t touch_panel_config[] = {0xA4, 0x01};
for (int i = 0; i < 3; i++) {
if (HAL_OK == i2c_transmit(TOUCH_ADDRESS, touch_panel_config,
if (HAL_OK == i2c_transmit(TOUCH_I2C_NUM, TOUCH_ADDRESS, touch_panel_config,
sizeof(touch_panel_config), 10)) {
return;
}
i2c_cycle();
i2c_cycle(TOUCH_I2C_NUM);
}
ensure(secfalse, "Touch screen panel was not loaded properly.");
@ -142,11 +143,12 @@ void touch_sensitivity(uint8_t value) {
// set panel threshold (TH_GROUP) - default value is 0x12
uint8_t touch_panel_threshold[] = {0x80, value};
for (int i = 0; i < 3; i++) {
if (HAL_OK == i2c_transmit(TOUCH_ADDRESS, touch_panel_threshold,
if (HAL_OK == i2c_transmit(TOUCH_I2C_NUM, TOUCH_ADDRESS,
touch_panel_threshold,
sizeof(touch_panel_threshold), 10)) {
return;
}
i2c_cycle();
i2c_cycle(TOUCH_I2C_NUM);
}
ensure(secfalse, "Touch screen panel was not loaded properly.");
@ -212,13 +214,15 @@ uint32_t touch_read(void) {
last_check_time = hal_ticks_ms();
uint8_t outgoing[] = {0x00}; // start reading from address 0x00
int result = i2c_transmit(TOUCH_ADDRESS, outgoing, sizeof(outgoing), 1);
int result =
i2c_transmit(TOUCH_I2C_NUM, TOUCH_ADDRESS, outgoing, sizeof(outgoing), 1);
if (result != HAL_OK) {
if (result == HAL_BUSY) i2c_cycle();
if (result == HAL_BUSY) i2c_cycle(TOUCH_I2C_NUM);
return 0;
}
if (HAL_OK != i2c_receive(TOUCH_ADDRESS, touch_data, TOUCH_PACKET_SIZE, 1)) {
if (HAL_OK != i2c_receive(TOUCH_I2C_NUM, TOUCH_ADDRESS, touch_data,
TOUCH_PACKET_SIZE, 1)) {
return 0; // read failure
}

View File

@ -18,6 +18,7 @@
*/
#include STM32_HAL_H
#include TREZOR_BOARD
#include <string.h>
@ -182,7 +183,7 @@ uint32_t I2cxTimeout =
/**
* @brief I2Cx error treatment function
*/
static void I2Cx_Error(void) { i2c_cycle(); }
static void I2Cx_Error(void) { i2c_cycle(TOUCH_I2C_NUM); }
/**
* @brief Writes a value in a register of the device through BUS.
@ -193,8 +194,8 @@ static void I2Cx_Error(void) { i2c_cycle(); }
static void I2Cx_WriteData(uint8_t Addr, uint8_t Reg, uint8_t Value) {
HAL_StatusTypeDef status = HAL_OK;
status = i2c_mem_write(Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, &Value, 1,
I2cxTimeout);
status = i2c_mem_write(TOUCH_I2C_NUM, Addr, (uint16_t)Reg,
I2C_MEMADD_SIZE_8BIT, &Value, 1, I2cxTimeout);
/* Check the communication status */
if (status != HAL_OK) {
@ -214,8 +215,8 @@ static void I2Cx_WriteBuffer(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer,
uint16_t Length) {
HAL_StatusTypeDef status = HAL_OK;
status = i2c_mem_write(Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, pBuffer,
Length, I2cxTimeout);
status = i2c_mem_write(TOUCH_I2C_NUM, Addr, (uint16_t)Reg,
I2C_MEMADD_SIZE_8BIT, pBuffer, Length, I2cxTimeout);
/* Check the communication status */
if (status != HAL_OK) {
@ -234,8 +235,8 @@ static uint8_t I2Cx_ReadData(uint8_t Addr, uint8_t Reg) {
HAL_StatusTypeDef status = HAL_OK;
uint8_t value = 0;
status =
i2c_mem_read(Addr, Reg, I2C_MEMADD_SIZE_8BIT, &value, 1, I2cxTimeout);
status = i2c_mem_read(TOUCH_I2C_NUM, Addr, Reg, I2C_MEMADD_SIZE_8BIT, &value,
1, I2cxTimeout);
/* Check the communication status */
if (status != HAL_OK) {
@ -257,8 +258,8 @@ static uint8_t I2Cx_ReadBuffer(uint8_t Addr, uint8_t Reg, uint8_t *pBuffer,
uint16_t Length) {
HAL_StatusTypeDef status = HAL_OK;
status = i2c_mem_read(Addr, (uint16_t)Reg, I2C_MEMADD_SIZE_8BIT, pBuffer,
Length, I2cxTimeout);
status = i2c_mem_read(TOUCH_I2C_NUM, Addr, (uint16_t)Reg,
I2C_MEMADD_SIZE_8BIT, pBuffer, Length, I2cxTimeout);
/* Check the communication status */
if (status == HAL_OK) {