diff options
author | David Chiu <dchiu@synaptics.com> | 2022-01-10 15:43:09 +0800 |
---|---|---|
committer | Vincent Huang <vincenthsw@gmail.com> | 2022-01-25 10:48:45 +0800 |
commit | 84a72ab59d271e790029b67312163c16c3c073dc (patch) | |
tree | 0d0923cba7eecf27e0ff748540a0f9717c0e1235 | |
parent | 37259214c592bd9e73eaa0cb2945b9f6173bd7ed (diff) | |
download | rmi4utils-84a72ab59d271e790029b67312163c16c3c073dc.tar.gz |
Support toggle interrupts mask by setting feature report
-rwxr-xr-x | rmi4update/main.cpp | 6 | ||||
-rwxr-xr-x | rmi4update/rmi4update.cpp | 15 | ||||
-rwxr-xr-x | rmidevice/hiddevice.cpp | 28 | ||||
-rwxr-xr-x | rmidevice/hiddevice.h | 1 | ||||
-rw-r--r-- | rmidevice/rmidevice.h | 1 |
5 files changed, 48 insertions, 3 deletions
diff --git a/rmi4update/main.cpp b/rmi4update/main.cpp index 89c3e4c..761954e 100755 --- a/rmi4update/main.cpp +++ b/rmi4update/main.cpp @@ -67,9 +67,15 @@ int GetFirmwareProps(const char * deviceFile, std::string &props, bool configid) if (rc) return rc; + // Clear all interrupts before parsing to avoid unexpected interrupts. + rmidevice.ToggleInterruptMask(false); + rmidevice.ScanPDT(0x1); rmidevice.QueryBasicProperties(); + // Restore the interrupts + rmidevice.ToggleInterruptMask(true); + if (configid) { ss << std::hex << rmidevice.GetConfigID(); } else { diff --git a/rmi4update/rmi4update.cpp b/rmi4update/rmi4update.cpp index 282fb90..cc27e22 100755 --- a/rmi4update/rmi4update.cpp +++ b/rmi4update/rmi4update.cpp @@ -97,13 +97,22 @@ int RMI4Update::UpdateFirmware(bool force, bool performLockdown) long long int duration_us = 0; int rc; const unsigned char eraseAll = RMI_F34_ERASE_ALL; + + // Clear all interrupts before parsing to avoid unexpected interrupts. + m_device.ToggleInterruptMask(false); rc = FindUpdateFunctions(); - if (rc != UPDATE_SUCCESS) + if (rc != UPDATE_SUCCESS) { + m_device.ToggleInterruptMask(true); return rc; + } rc = m_device.QueryBasicProperties(); - if (rc < 0) - return UPDATE_FAIL_QUERY_BASIC_PROPERTIES; + if (rc < 0) { + m_device.ToggleInterruptMask(true); + return UPDATE_FAIL_QUERY_BASIC_PROPERTIES; + } + // Restore the interrupts + m_device.ToggleInterruptMask(true); if (!force && m_firmwareImage.HasIO()) { if (m_firmwareImage.GetFirmwareID() <= m_device.GetFirmwareID()) { diff --git a/rmidevice/hiddevice.cpp b/rmidevice/hiddevice.cpp index a41e680..9adc952 100755 --- a/rmidevice/hiddevice.cpp +++ b/rmidevice/hiddevice.cpp @@ -422,6 +422,34 @@ int HIDDevice::SetMode(int mode) return 0; } +int HIDDevice::ToggleInterruptMask(bool enable) +{ + int rc; + char buf[2]; + + if (GetDeviceType() != RMI_DEVICE_TYPE_TOUCHPAD) { + fprintf(stdout, "Not TP, skip toggle interrupts mask\n"); + return 0; + } + + if (!m_deviceOpen) + return -1; + + buf[0] = 0xE; + if (enable) { + buf[1] = 0; + } else { + buf[1] = 8; + } + rc = ioctl(m_fd, HIDIOCSFEATURE(2), buf); + if (rc < 0) { + perror("HIDIOCSFEATURE"); + return rc; + } + Sleep(10); + return 0; +} + void HIDDevice::Close() { RMIDevice::Close(); diff --git a/rmidevice/hiddevice.h b/rmidevice/hiddevice.h index b947f62..5a01edb 100755 --- a/rmidevice/hiddevice.h +++ b/rmidevice/hiddevice.h @@ -49,6 +49,7 @@ public: virtual int Write(unsigned short addr, const unsigned char *buf, unsigned short len); virtual int SetMode(int mode); + virtual int ToggleInterruptMask(bool enable); virtual int WaitForAttention(struct timeval * timeout = NULL, unsigned int source_mask = RMI_INTERUPT_SOURCES_ALL_MASK); virtual int GetAttentionReport(struct timeval * timeout, unsigned int source_mask, diff --git a/rmidevice/rmidevice.h b/rmidevice/rmidevice.h index 9bfe849..a0249bc 100644 --- a/rmidevice/rmidevice.h +++ b/rmidevice/rmidevice.h @@ -46,6 +46,7 @@ public: virtual int Write(unsigned short addr, const unsigned char *data, unsigned short len) = 0; virtual int SetMode(int mode) { return -1; /* Unsupported */ } + virtual int ToggleInterruptMask(bool enable) = 0; virtual int WaitForAttention(struct timeval * timeout = NULL, unsigned int source_mask = RMI_INTERUPT_SOURCES_ALL_MASK) = 0; virtual int GetAttentionReport(struct timeval * timeout, unsigned int source_mask, |