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.
|
* GNU General Public License for more details.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
#include "stm32_i2c_driver.h"
|
#include "stm32_i2c_driver.h"
|
||||||
#include "stm32_gpio.h"
|
#include "stm32_gpio.h"
|
||||||
#include "stm32_hal_ll.h"
|
#include "stm32_hal_ll.h"
|
||||||
@@ -547,6 +549,8 @@ int stm32_i2c_deinit(uint8_t bus)
|
|||||||
|
|
||||||
if (HAL_I2C_DeInit(h) != HAL_OK) 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) {
|
if (i2c_disable_clock(h->Instance) < 0) {
|
||||||
TRACE("I2C ERROR: HAL_I2C_MspDeInit() I2C misconfiguration");
|
TRACE("I2C ERROR: HAL_I2C_MspDeInit() I2C misconfiguration");
|
||||||
return -1;
|
return -1;
|
||||||
|
|||||||
@@ -170,8 +170,21 @@ static void _i2c_init(void)
|
|||||||
|
|
||||||
static void _i2c_reInit(void)
|
static void _i2c_reInit(void)
|
||||||
{
|
{
|
||||||
// stm32_i2c_deinit(TOUCH_I2C_BUS);
|
TRACE("I2C reinit: bus reset triggered");
|
||||||
// _i2c_init();
|
|
||||||
|
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)
|
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()
|
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;
|
if (!touchEventOccured) return internalTouchState;
|
||||||
|
|
||||||
touchEventOccured = false;
|
touchEventOccured = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user