fix(pl18u): reinit I2C when touch screen not working (#7402)
This commit is contained in:
@@ -19,6 +19,8 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "stm32_i2c_driver.h"
|
||||
#include "stm32_gpio.h"
|
||||
#include "stm32_hal_ll.h"
|
||||
@@ -546,7 +548,9 @@ int stm32_i2c_deinit(uint8_t bus)
|
||||
if (!h) return -1;
|
||||
|
||||
if (HAL_I2C_DeInit(h) != HAL_OK) return -1;
|
||||
|
||||
|
||||
memset(&h->Init, 0, sizeof(h->Init));
|
||||
|
||||
if (i2c_disable_clock(h->Instance) < 0) {
|
||||
TRACE("I2C ERROR: HAL_I2C_MspDeInit() I2C misconfiguration");
|
||||
return -1;
|
||||
|
||||
@@ -170,8 +170,21 @@ static void _i2c_init(void)
|
||||
|
||||
static void _i2c_reInit(void)
|
||||
{
|
||||
// stm32_i2c_deinit(TOUCH_I2C_BUS);
|
||||
// _i2c_init();
|
||||
TRACE("I2C reinit: bus reset triggered");
|
||||
|
||||
if (i2c_deinit(TOUCH_I2C_BUS) < 0) {
|
||||
TRACE("I2C reinit WARNING: i2c_deinit failed, proceeding with reinit");
|
||||
}
|
||||
// __HAL_RCC_I2C1_FORCE_RESET();
|
||||
// __HAL_RCC_I2C1_RELEASE_RESET();
|
||||
delay_ms(1);
|
||||
|
||||
if (i2c_init(TOUCH_I2C_BUS) < 0) {
|
||||
TRACE("I2C reinit ERROR: i2c_init failed");
|
||||
return;
|
||||
}
|
||||
// _touch_reset();
|
||||
TRACE("I2C reinit: bus reset complete");
|
||||
}
|
||||
|
||||
static int _i2c_read(uint8_t addr, uint32_t reg, uint8_t regSize, uint8_t* data, uint16_t len, uint32_t timeout)
|
||||
@@ -467,6 +480,16 @@ bool touchPanelEventOccured()
|
||||
|
||||
struct TouchState touchPanelRead()
|
||||
{
|
||||
#if 0
|
||||
// For _i2c_reInit testing
|
||||
static uint8_t reinitPollCnt = 0;
|
||||
TRACE("Polling count: %d", reinitPollCnt);
|
||||
if (++reinitPollCnt >= 50) {
|
||||
reinitPollCnt = 0;
|
||||
_i2c_reInit();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!touchEventOccured) return internalTouchState;
|
||||
|
||||
touchEventOccured = false;
|
||||
|
||||
Reference in New Issue
Block a user