// SPDX-License-Identifier: GPL-2.0-or-later /* * ION iCade input driver * * Copyright (c) 2012 Bastien Nocera <[email protected]> * Copyright (c) 2012 Benjamin Tissoires <[email protected]> */ /* */ #include <linux/device.h> #include <linux/hid.h> #include <linux/module.h> #include "hid-ids.h" /* * ↑ A C Y L * ← → * ↓ B X Z R * * * UP ON,OFF = w,e * RT ON,OFF = d,c * DN ON,OFF = x,z * LT ON,OFF = a,q * A ON,OFF = y,t * B ON,OFF = h,r * C ON,OFF = u,f * X ON,OFF = j,n * Y ON,OFF = i,m * Z ON,OFF = k,p * L ON,OFF = o,g * R ON,OFF = l,v */ /* The translation code uses HID usage instead of input layer * keys. This code generates a lookup table that makes * translation quick. * * #include <linux/input.h> * #include <stdio.h> * #include <assert.h> * * #define unk KEY_UNKNOWN * * < copy of hid_keyboard[] from hid-input.c > * * struct icade_key_translation { * int from; * const char *to; * int press; * }; * * static const struct icade_key_translation icade_keys[] = { * { KEY_W, "KEY_UP", 1 }, * { KEY_E, "KEY_UP", 0 }, * { KEY_D, "KEY_RIGHT", 1 }, * { KEY_C, "KEY_RIGHT", 0 }, * { KEY_X, "KEY_DOWN", 1 }, * { KEY_Z, "KEY_DOWN", 0 }, * { KEY_A, "KEY_LEFT", 1 }, * { KEY_Q, "KEY_LEFT", 0 }, * { KEY_Y, "BTN_A", 1 }, * { KEY_T, "BTN_A", 0 }, * { KEY_H, "BTN_B", 1 }, * { KEY_R, "BTN_B", 0 }, * { KEY_U, "BTN_C", 1 }, * { KEY_F, "BTN_C", 0 }, * { KEY_J, "BTN_X", 1 }, * { KEY_N, "BTN_X", 0 }, * { KEY_I, "BTN_Y", 1 }, * { KEY_M, "BTN_Y", 0 }, * { KEY_K, "BTN_Z", 1 }, * { KEY_P, "BTN_Z", 0 }, * { KEY_O, "BTN_THUMBL", 1 }, * { KEY_G, "BTN_THUMBL", 0 }, * { KEY_L, "BTN_THUMBR", 1 }, * { KEY_V, "BTN_THUMBR", 0 }, * * { } * }; * * static int * usage_for_key (int key) * { * int i; * for (i = 0; i < 256; i++) { * if (hid_keyboard[i] == key) * return i; * } * assert(0); * } * * int main (int argc, char **argv) * { * const struct icade_key_translation *trans; * int max_usage = 0; * * for (trans = icade_keys; trans->from; trans++) { * int usage = usage_for_key (trans->from); * max_usage = usage > max_usage ? usage : max_usage; * } * * printf ("#define ICADE_MAX_USAGE %d\n\n", max_usage); * printf ("struct icade_key {\n"); * printf ("\tu16 to;\n"); * printf ("\tu8 press:1;\n"); * printf ("};\n\n"); * printf ("static const struct icade_key " * "icade_usage_table[%d] = {\n", max_usage + 1); * for (trans = icade_keys; trans->from; trans++) { * printf ("\t[%d] = { %s, %d },\n", * usage_for_key (trans->from), trans->to, trans->press); * } * printf ("};\n"); * * return 0; * } */ #define ICADE_MAX_USAGE … struct icade_key { … }; static const struct icade_key icade_usage_table[30] = …; static const struct icade_key *icade_find_translation(u16 from) { … } static int icade_event(struct hid_device *hdev, struct hid_field *field, struct hid_usage *usage, __s32 value) { … } static int icade_input_mapping(struct hid_device *hdev, struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, unsigned long **bit, int *max) { … } static int icade_input_mapped(struct hid_device *hdev, struct hid_input *hi, struct hid_field *field, struct hid_usage *usage, unsigned long **bit, int *max) { … } static const struct hid_device_id icade_devices[] = …; MODULE_DEVICE_TABLE(hid, icade_devices); static struct hid_driver icade_driver = …; module_hid_driver(…) …; MODULE_LICENSE(…) …; MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …;