Enable device discovery using evdev on VxWorks

Provide VxWorks-specific implementation of keyboard and mouse device
discovery, and enable usage of evdev on this platform.

Task-number: QTBUG-115777
Change-Id: I9370ac085aa58c72e2d39731b78ebd854f5aad9a
Reviewed-by: Laszlo Agocs <laszlo.agocs@qt.io>
This commit is contained in:
Michał Łoś 2024-04-10 16:50:32 +02:00
parent 61b9195fc2
commit c4dfb8030c
3 changed files with 85 additions and 2 deletions

View File

@ -363,15 +363,25 @@ qt_config_compile_test(evdev
CODE
"#if defined(__FreeBSD__)
# include <dev/evdev/input.h>
#elif defined(__VXWORKS__)
#include <evdevLib.h>
typedef EV_DEV_EVENT input_event;
#else
# include <linux/input.h>
# include <linux/kd.h>
#endif
enum {
#if defined(__VXWORKS__)
e1 = EV_DEV_ABS,
e2 = EV_DEV_PTR_ABS_X,
e3 = EV_DEV_PTR_ABS_Y,
e4 = EV_DEV_PTR_BTN_TOUCH,
#else
e1 = ABS_PRESSURE,
e2 = ABS_X,
e3 = REL_X,
e4 = SYN_REPORT,
#endif
};
int main(void)

View File

@ -13,6 +13,9 @@
#ifdef Q_OS_FREEBSD
#include <dev/evdev/input.h>
#elif defined(Q_OS_VXWORKS)
#include <evdevLib.h>
#define ABS_X EV_DEV_PTR_ABS_X
#else
#include <linux/input.h>
#endif
@ -40,10 +43,12 @@
#define LONG_BITS (sizeof(long) * 8 )
#define LONG_FIELD_SIZE(bits) ((bits / LONG_BITS) + 1)
#if !defined(Q_OS_VXWORKS)
static bool testBit(long bit, const long *field)
{
return (field[bit / LONG_BITS] >> bit % LONG_BITS) & 1;
}
#endif
QT_BEGIN_NAMESPACE
@ -65,6 +70,37 @@ QDeviceDiscoveryStatic::QDeviceDiscoveryStatic(QDeviceTypes types, QObject *pare
QStringList QDeviceDiscoveryStatic::scanConnectedDevices()
{
QStringList devices;
#if defined(Q_OS_VXWORKS)
QStringList inputDevices;
UINT32 devCount = 0;
static const char* device = "/input/event";
int fd = QT_OPEN(device, O_RDONLY | O_NDELAY, 0);
if (fd >= 0) {
if (ERROR == ioctl(fd, EV_DEV_IO_GET_DEV_COUNT, (char *)&devCount)) {
qWarning() << "DeviceDiscovery cannot open device" << device;
return devices;
}
for (UINT32 i=0; i<devCount; i++)
inputDevices << QString::fromLatin1("/input/event%1").arg(i);
} else {
for (int i=0; i<=EV_DEV_DEVICE_MAX; i++)
inputDevices << QString::fromLatin1("/input/event%1").arg(i);
}
QT_CLOSE(fd);
// check for input devices
if (m_types & Device_InputMask) {
for (const auto& deviceFile : inputDevices) {
if (checkDeviceType(deviceFile))
devices << deviceFile;
}
}
#else
QDir dir;
dir.setFilter(QDir::System);
@ -92,6 +128,7 @@ QStringList QDeviceDiscoveryStatic::scanConnectedDevices()
qCDebug(lcDD) << "Found matching devices" << devices;
#endif // Q_OS_VXWORKS
return devices;
}
@ -99,7 +136,15 @@ bool QDeviceDiscoveryStatic::checkDeviceType(const QString &device)
{
int fd = QT_OPEN(device.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0);
if (Q_UNLIKELY(fd == -1)) {
qWarning() << "Device discovery cannot open device" << device;
#if defined(Q_OS_VXWORKS)
// This is changed to debug type message due the nature of scanning
// and adding new device for VxWorks by getting dev count from
// dev /input/event0 which might be already in use
qCDebug(lcDD)
#else
qWarning()
#endif
<< "Device discovery cannot open device" << device;
return false;
}
@ -110,6 +155,27 @@ bool QDeviceDiscoveryStatic::checkDeviceType(const QString &device)
return true;
}
#if defined(Q_OS_VXWORKS)
UINT32 devCap = 0;
if (ERROR != ioctl(fd, EV_DEV_IO_GET_CAP, (char *)&devCap)) {
if ((m_types & Device_Keyboard) && (devCap & EV_DEV_KEY)) {
if (!(devCap & EV_DEV_REL) && !(devCap & EV_DEV_ABS)) {
qCDebug(lcDD) << "DeviceDiscovery found keyboard at" << device;
QT_CLOSE(fd);
return true;
}
}
if (m_types & Device_Mouse) {
if ((devCap & EV_DEV_REL) && (devCap & EV_DEV_KEY)) {
qCDebug(lcDD) << "DeviceDiscovery found mouse at" << device;
QT_CLOSE(fd);
return true;
}
}
}
QT_CLOSE(fd);
#else
long bitsAbs[LONG_FIELD_SIZE(ABS_CNT)];
long bitsKey[LONG_FIELD_SIZE(KEY_CNT)];
long bitsRel[LONG_FIELD_SIZE(REL_CNT)];
@ -162,6 +228,7 @@ bool QDeviceDiscoveryStatic::checkDeviceType(const QString &device)
return true;
}
}
#endif
return false;
}

View File

@ -19,7 +19,13 @@ ParsedSpecification parseSpecification(const QString &specification)
if (arg.startsWith("/dev/"_L1)) {
// if device is specified try to use it
result.devices.append(arg.toString());
} else {
}
#ifdef Q_OS_VXWORKS
else if (arg.startsWith("/input/"_L1)) {
result.devices.append(arg.toString());
}
#endif
else {
// build new specification without /dev/ elements
result.spec += arg + u':';
}