Changes in / [8a02ff3:f4cf2813] in mainline


Ignore:
Location:
uspace/drv/usbhid
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/drv/usbhid/conv.c

    r8a02ff3 rf4cf2813  
    4040#include "conv.h"
    4141
     42/**
     43 * Mapping between USB HID key codes (from HID Usage Tables) and corresponding
     44 * HelenOS key codes.
     45 */
    4246static int scanmap_simple[255] = {
    4347
     
    163167};
    164168
     169/**
     170 * Translate USB HID key codes (from HID Usage Tables) to generic key codes
     171 * recognized by HelenOS.
     172 *
     173 * @param scancode USB HID key code (from HID Usage Tables).
     174 *
     175 * @retval HelenOS key code corresponding to the given USB HID key code.
     176 */
    165177unsigned int usbhid_parse_scancode(int scancode)
    166178{
  • uspace/drv/usbhid/descdump.c

    r8a02ff3 rf4cf2813  
    4444#define BYTES_PER_LINE 12
    4545
     46/**
     47 * Dumps the given buffer in hexadecimal format to standard output.
     48 *
     49 * @param msg Message to print before the buffer.
     50 * @param buffer Buffer to print.
     51 * @param length Size of the buffer in bytes.
     52 */
    4653static void dump_buffer(const char *msg, const uint8_t *buffer, size_t length)
    4754{
     
    6269#define INDENT "  "
    6370
     71/**
     72 * Print standard configuration descriptor to standard output.
     73 *
     74 * @param index Index of the descriptor.
     75 * @param d Standard configuration descriptor to print.
     76 */
    6477void dump_standard_configuration_descriptor(
    6578    int index, const usb_standard_configuration_descriptor_t *d)
     
    8497}
    8598
     99/**
     100 * Print standard interface descriptor to standard output.
     101 *
     102 * @param d Standard interface descriptor to print.
     103 */
    86104void dump_standard_interface_descriptor(
    87105    const usb_standard_interface_descriptor_t *d)
     
    99117}
    100118
     119/**
     120 * Print standard endpoint descriptor to standard output.
     121 *
     122 * @param d Standard endpoint descriptor to print.
     123 */
    101124void dump_standard_endpoint_descriptor(
    102125    const usb_standard_endpoint_descriptor_t *d)
     
    126149}
    127150
     151/**
     152 * Print standard HID descriptor to standard output.
     153 *
     154 * @param d Standard HID descriptor to print.
     155 */
    128156void dump_standard_hid_descriptor_header(
    129157    const usb_standard_hid_descriptor_t *d)
     
    139167}
    140168
     169/**
     170 * Print HID class-specific descriptor header (type and length) to standard
     171 * output.
     172 *
     173 * @param d HID class-specific descriptor header to print.
     174 */
    141175void dump_standard_hid_class_descriptor_info(
    142176    const usb_standard_hid_class_descriptor_info_t *d)
     
    146180}
    147181
     182/**
     183 * Print HID class-specific descriptor (without the header) to standard output.
     184 *
     185 * @param index Index of the descriptor.
     186 * @param type Type of the HID class-specific descriptor (Report or Physical).
     187 * @param d HID class descriptor to print.
     188 * @param size Size of the descriptor in bytes.
     189 */
    148190void dump_hid_class_descriptor(int index, uint8_t type,
    149191    const uint8_t *d, size_t size )
  • uspace/drv/usbhid/hiddev.c

    r8a02ff3 rf4cf2813  
    5353/* Non-API functions                                                          */
    5454/*----------------------------------------------------------------------------*/
    55 
     55/**
     56 * Retreives HID Report descriptor from the device.
     57 *
     58 * This function first parses the HID descriptor from the Interface descriptor
     59 * to get the size of the Report descriptor and then requests the Report
     60 * descriptor from the device.
     61 *
     62 * @param hid_dev HID device structure.
     63 * @param config_desc Full configuration descriptor (including all nested
     64 *                    descriptors).
     65 * @param config_desc_size Size of the full configuration descriptor (in bytes).
     66 * @param iface_desc Pointer to the interface descriptor inside the full
     67 *                   configuration descriptor (@a config_desc) for the interface
     68 *                   assigned with this device (@a hid_dev).
     69 *
     70 * @retval EOK if successful.
     71 * @retval ENOENT if no HID descriptor could be found.
     72 * @retval EINVAL if the HID descriptor  or HID report descriptor have different
     73 *                size than expected.
     74 * @retval ENOMEM if some allocation failed.
     75 * @return Other value inherited from function usb_request_get_descriptor().
     76 *
     77 * @sa usb_request_get_descriptor()
     78 */
    5679static int usbhid_dev_get_report_descriptor(usbhid_dev_t *hid_dev,
    5780    uint8_t *config_desc, size_t config_desc_size, uint8_t *iface_desc)
     
    141164
    142165/*----------------------------------------------------------------------------*/
    143 
     166/**
     167 * Retreives descriptors from the device, initializes pipes and stores
     168 * important information from descriptors.
     169 *
     170 * Initializes the polling pipe described by the given endpoint description
     171 * (@a poll_ep_desc).
     172 *
     173 * Information retreived from descriptors and stored in the HID device structure:
     174 *    - Assigned interface number (the interface controlled by this instance of
     175 *                                 the driver)
     176 *    - Polling interval (from the interface descriptor)
     177 *    - Report descriptor
     178 *
     179 * @param hid_dev HID device structure to be initialized.
     180 * @param poll_ep_desc Description of the polling (Interrupt In) endpoint
     181 *                     that has to be present in the device in order to
     182 *                     successfuly initialize the structure.
     183 *
     184 * @sa usb_endpoint_pipe_initialize_from_configuration(),
     185 *     usbhid_dev_get_report_descriptor()
     186 */
    144187static int usbhid_dev_process_descriptors(usbhid_dev_t *hid_dev,
    145188    usb_endpoint_description_t *poll_ep_desc)
     
    230273/* API functions                                                              */
    231274/*----------------------------------------------------------------------------*/
    232 
     275/**
     276 * Creates new uninitialized HID device structure.
     277 *
     278 * @return Pointer to the new HID device structure, or NULL if an error occured.
     279 */
    233280usbhid_dev_t *usbhid_dev_new(void)
    234281{
     
    249296
    250297/*----------------------------------------------------------------------------*/
    251 
     298/**
     299 * Properly destroys the HID device structure.
     300 *
     301 * @note Currently does not clean-up the used pipes, as there are no functions
     302 *       offering such functionality.
     303 *
     304 * @param hid_dev Pointer to the structure to be destroyed.
     305 */
    252306void usbhid_dev_free(usbhid_dev_t **hid_dev)
    253307{
     
    272326
    273327/*----------------------------------------------------------------------------*/
    274 
     328/**
     329 * Initializes HID device structure.
     330 *
     331 * @param hid_dev HID device structure to be initialized.
     332 * @param dev DDF device representing the HID device.
     333 * @param poll_ep_desc Description of the polling (Interrupt In) endpoint
     334 *                     that has to be present in the device in order to
     335 *                     successfuly initialize the structure.
     336 *
     337 * @retval EOK if successful.
     338 * @retval EINVAL if some argument is missing.
     339 * @return Other value inherited from one of functions
     340 *         usb_device_connection_initialize_from_device(),
     341 *         usb_endpoint_pipe_initialize_default_control(),
     342 *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
     343 *         usbhid_dev_process_descriptors().
     344 *
     345 * @sa usbhid_dev_process_descriptors()
     346 */
    275347int usbhid_dev_init(usbhid_dev_t *hid_dev, ddf_dev_t *dev,
    276348    usb_endpoint_description_t *poll_ep_desc)
     
    323395         * Get descriptors, parse descriptors and save endpoints.
    324396         */
    325         usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe);
     397        rc = usb_endpoint_pipe_start_session(&hid_dev->ctrl_pipe);
     398        if (rc != EOK) {
     399                usb_log_error("Failed to start session on the control pipe: %s"
     400                    ".\n", str_error(rc));
     401                return rc;
     402        }
    326403       
    327404        rc = usbhid_dev_process_descriptors(hid_dev, poll_ep_desc);
    328        
    329         usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
    330         if (rc != EOK) {
     405        if (rc != EOK) {
     406                /* TODO: end session?? */
    331407                usb_log_error("Failed to process descriptors: %s.\n",
    332408                    str_error(rc));
     
    334410        }
    335411       
     412        rc = usb_endpoint_pipe_end_session(&hid_dev->ctrl_pipe);
     413        if (rc != EOK) {
     414                usb_log_warning("Failed to start session on the control pipe: "
     415                    "%s.\n", str_error(rc));
     416                return rc;
     417        }
     418       
    336419        hid_dev->initialized = 1;
    337420        usb_log_info("HID device structure initialized.\n");
  • uspace/drv/usbhid/hiddev.h

    r8a02ff3 rf4cf2813  
    4848
    4949/**
    50  * @brief USB/HID device type.
     50 * USB/HID device type.
     51 *
     52 * Holds a reference to DDF device structure, and HID-specific data, such
     53 * as information about used pipes (one Control pipe and one Interrupt In pipe),
     54 * polling interval, assigned interface number, Report descriptor and a
     55 * reference to the Report parser used to parse incoming reports and composing
     56 * outgoing reports.
    5157 */
    5258typedef struct {
     59        /** DDF device representing the controlled HID device. */
    5360        ddf_dev_t *device;
    5461
     62        /** Physical connection to the device. */
    5563        usb_device_connection_t wire;
     64        /** USB pipe corresponding to the default Control endpoint. */
    5665        usb_endpoint_pipe_t ctrl_pipe;
     66        /** USB pipe corresponding to the Interrupt In (polling) pipe. */
    5767        usb_endpoint_pipe_t poll_pipe;
    5868       
     69        /** Polling interval retreived from the Interface descriptor. */
    5970        short poll_interval;
    6071       
     72        /** Interface number assigned to this device. */
    6173        uint16_t iface;
    6274       
     75        /** Report descriptor. */
    6376        uint8_t *report_desc;
     77        /** HID Report parser. */
    6478        usb_hid_report_parser_t *parser;
    6579       
     80        /** State of the structure (for checking before use). */
    6681        int initialized;
    6782} usbhid_dev_t;
  • uspace/drv/usbhid/hidreq.c

    r8a02ff3 rf4cf2813  
    4646
    4747/*----------------------------------------------------------------------------*/
    48 
     48/**
     49 * Send Set Report request to the HID device.
     50 *
     51 * @param hid_dev HID device to send the request to.
     52 * @param type Type of the report.
     53 * @param buffer Report data.
     54 * @param buf_size Report data size (in bytes).
     55 *
     56 * @retval EOK if successful.
     57 * @retval EINVAL if no HID device is given.
     58 * @return Other value inherited from one of functions
     59 *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
     60 *         usb_control_request_set().
     61 */
    4962int usbhid_req_set_report(usbhid_dev_t *hid_dev,
    5063    usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size)
     
    97110
    98111/*----------------------------------------------------------------------------*/
    99 
     112/**
     113 * Send Set Protocol request to the HID device.
     114 *
     115 * @param hid_dev HID device to send the request to.
     116 * @param protocol Protocol to set.
     117 *
     118 * @retval EOK if successful.
     119 * @retval EINVAL if no HID device is given.
     120 * @return Other value inherited from one of functions
     121 *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
     122 *         usb_control_request_set().
     123 */
    100124int usbhid_req_set_protocol(usbhid_dev_t *hid_dev, usb_hid_protocol_t protocol)
    101125{
     
    145169
    146170/*----------------------------------------------------------------------------*/
    147 
     171/**
     172 * Send Set Idle request to the HID device.
     173 *
     174 * @param hid_dev HID device to send the request to.
     175 * @param duration Duration value (is multiplicated by 4 by the device to
     176 *                 get real duration in miliseconds).
     177 *
     178 * @retval EOK if successful.
     179 * @retval EINVAL if no HID device is given.
     180 * @return Other value inherited from one of functions
     181 *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
     182 *         usb_control_request_set().
     183 */
    148184int usbhid_req_set_idle(usbhid_dev_t *hid_dev, uint8_t duration)
    149185{
     
    195231
    196232/*----------------------------------------------------------------------------*/
    197 
     233/**
     234 * Send Get Report request to the HID device.
     235 *
     236 * @param[in] hid_dev HID device to send the request to.
     237 * @param[in] type Type of the report.
     238 * @param[in][out] buffer Buffer for the report data.
     239 * @param[in] buf_size Size of the buffer (in bytes).
     240 * @param[out] actual_size Actual size of report received from the device
     241 *                         (in bytes).
     242 *
     243 * @retval EOK if successful.
     244 * @retval EINVAL if no HID device is given.
     245 * @return Other value inherited from one of functions
     246 *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
     247 *         usb_control_request_set().
     248 */
    198249int usbhid_req_get_report(usbhid_dev_t *hid_dev, usb_hid_report_type_t type,
    199250    uint8_t *buffer, size_t buf_size, size_t *actual_size)
     
    246297}
    247298
     299/*----------------------------------------------------------------------------*/
     300/**
     301 * Send Get Protocol request to the HID device.
     302 *
     303 * @param[in] hid_dev HID device to send the request to.
     304 * @param[out] protocol Current protocol of the device.
     305 *
     306 * @retval EOK if successful.
     307 * @retval EINVAL if no HID device is given.
     308 * @return Other value inherited from one of functions
     309 *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
     310 *         usb_control_request_set().
     311 */
    248312int usbhid_req_get_protocol(usbhid_dev_t *hid_dev, usb_hid_protocol_t *protocol)
    249313{
     
    303367}
    304368
     369/*----------------------------------------------------------------------------*/
     370/**
     371 * Send Get Idle request to the HID device.
     372 *
     373 * @param[in] hid_dev HID device to send the request to.
     374 * @param[out] duration Duration value (multiplicate by 4 to get real duration
     375 *                      in miliseconds).
     376 *
     377 * @retval EOK if successful.
     378 * @retval EINVAL if no HID device is given.
     379 * @return Other value inherited from one of functions
     380 *         usb_endpoint_pipe_start_session(), usb_endpoint_pipe_end_session(),
     381 *         usb_control_request_set().
     382 */
    305383int usbhid_req_get_idle(usbhid_dev_t *hid_dev, uint8_t *duration)
    306384{
  • uspace/drv/usbhid/kbddev.c

    r8a02ff3 rf4cf2813  
    6060
    6161/*----------------------------------------------------------------------------*/
    62 
     62/** Default modifiers when the keyboard is initialized. */
    6363static const unsigned DEFAULT_ACTIVE_MODS = KM_NUM_LOCK;
     64
     65/** Boot protocol report size (key part). */
    6466static const size_t BOOTP_REPORT_SIZE = 6;
     67
     68/** Boot protocol total report size. */
    6569static const size_t BOOTP_BUFFER_SIZE = 8;
     70
     71/** Boot protocol output report size. */
    6672static const size_t BOOTP_BUFFER_OUT_SIZE = 1;
     73
     74/** Boot protocol error key code. */
    6775static const uint8_t BOOTP_ERROR_ROLLOVER = 1;
     76
     77/** Default idle rate for keyboards. */
    6878static const uint8_t IDLE_RATE = 0;
     79
     80/** Delay before a pressed key starts auto-repeating. */
    6981static const unsigned int DEFAULT_DELAY_BEFORE_FIRST_REPEAT = 500 * 1000;
     82
     83/** Delay between two repeats of a pressed key when auto-repeating. */
    7084static const unsigned int DEFAULT_REPEAT_DELAY = 50 * 1000;
    7185
     
    86100#define NUM_LAYOUTS 3
    87101
     102/** Keyboard layout map. */
    88103static layout_op_t *layout[NUM_LAYOUTS] = {
    89104        &us_qwerty_op,
     
    97112/* Modifier constants                                                         */
    98113/*----------------------------------------------------------------------------*/
    99 
     114/** Mapping of USB modifier key codes to generic modifier key codes. */
    100115static const keycode_t usbhid_modifiers_keycodes[USB_HID_MOD_COUNT] = {
    101116        KC_LCTRL,         /* USB_HID_MOD_LCTRL */
     
    118133};
    119134
    120 /** Default handler for IPC methods not handled by DDF.
    121  *
    122  * @param dev Device handling the call.
     135/**
     136 * Default handler for IPC methods not handled by DDF.
     137 *
     138 * Currently recognizes only one method (IPC_M_CONNECT_TO_ME), in which case it
     139 * assumes the caller is the console and thus it stores IPC phone to it for
     140 * later use by the driver to notify about key events.
     141 *
     142 * @param fun Device function handling the call.
    123143 * @param icallid Call id.
    124144 * @param icall Call data.
     
    151171/* Key processing functions                                                   */
    152172/*----------------------------------------------------------------------------*/
    153 
     173/**
     174 * Handles turning of LED lights on and off.
     175 *
     176 * In case of USB keyboards, the LEDs are handled in the driver, not in the
     177 * device. When there should be a change (lock key was pressed), the driver
     178 * uses a Set_Report request sent to the device to set the state of the LEDs.
     179 *
     180 * This functions sets the LED lights according to current settings of modifiers
     181 * kept in the keyboard device structure.
     182 *
     183 * @param kbd_dev Keyboard device structure.
     184 */
    154185static void usbhid_kbd_set_led(usbhid_kbd_t *kbd_dev)
    155186{
     
    193224
    194225/*----------------------------------------------------------------------------*/
    195 
     226/**
     227 * Processes key events.
     228 *
     229 * @note This function was copied from AT keyboard driver and modified to suit
     230 *       USB keyboard.
     231 *
     232 * @note Lock keys are not sent to the console, as they are completely handled
     233 *       in the driver. It may, however, be required later that the driver
     234 *       sends also these keys to application (otherwise it cannot use those
     235 *       keys at all).
     236 *
     237 * @param kbd_dev Keyboard device structure.
     238 * @param type Type of the event (press / release). Recognized values:
     239 *             KEY_PRESS, KEY_RELEASE
     240 * @param key Key code of the key according to HID Usage Tables.
     241 */
    196242void usbhid_kbd_push_ev(usbhid_kbd_t *kbd_dev, int type, unsigned int key)
    197243{
     
    292338
    293339/*----------------------------------------------------------------------------*/
    294 
     340/**
     341 * Checks if modifiers were pressed or released and generates key events.
     342 *
     343 * @param kbd_dev Keyboard device structure.
     344 * @param modifiers Bitmap of modifiers.
     345 *
     346 * @sa usbhid_kbd_push_ev()
     347 */
    295348static void usbhid_kbd_check_modifier_changes(usbhid_kbd_t *kbd_dev,
    296349    uint8_t modifiers)
     
    328381
    329382/*----------------------------------------------------------------------------*/
    330 
     383/**
     384 * Checks if some keys were pressed or released and generates key events.
     385 *
     386 * An event is created only when key is pressed or released. Besides handling
     387 * the events (usbhid_kbd_push_ev()), the auto-repeat fibril is notified about
     388 * key presses and releases (see usbhid_kbd_repeat_start() and
     389 * usbhid_kbd_repeat_stop()).
     390 *
     391 * @param kbd_dev Keyboard device structure.
     392 * @param key_codes Parsed keyboard report - codes of currently pressed keys
     393 *                  according to HID Usage Tables.
     394 * @param count Number of key codes in report (size of the report).
     395 *
     396 * @sa usbhid_kbd_push_ev(), usbhid_kbd_repeat_start(), usbhid_kbd_repeat_stop()
     397 */
    331398static void usbhid_kbd_check_key_changes(usbhid_kbd_t *kbd_dev,
    332     const uint8_t *key_codes)
     399    const uint8_t *key_codes, size_t count)
    333400{
    334401        unsigned int key;
     
    340407        i = 0;
    341408        // all fields should report Error Rollover
    342         while (i < kbd_dev->key_count &&
     409        while (i < count &&
    343410            key_codes[i] == BOOTP_ERROR_ROLLOVER) {
    344411                ++i;
    345412        }
    346         if (i == kbd_dev->key_count) {
     413        if (i == count) {
    347414                usb_log_debug("Phantom state occured.\n");
    348415                // phantom state, do nothing
     
    350417        }
    351418       
    352         // TODO: quite dummy right now, think of better implementation
     419        /* TODO: quite dummy right now, think of better implementation */
     420        assert(count == kbd_dev->key_count);
    353421       
    354422        /*
    355423         * 1) Key releases
    356424         */
    357         for (j = 0; j < kbd_dev->key_count; ++j) {
     425        for (j = 0; j < count; ++j) {
    358426                // try to find the old key in the new key list
    359427                i = 0;
     
    363431                }
    364432               
    365                 if (i == kbd_dev->key_count) {
     433                if (i == count) {
    366434                        // not found, i.e. the key was released
    367435                        key = usbhid_parse_scancode(kbd_dev->keys[j]);
     
    380448                // try to find the new key in the old key list
    381449                j = 0;
    382                 while (j < kbd_dev->key_count
    383                     && kbd_dev->keys[j] != key_codes[i]) {
     450                while (j < count && kbd_dev->keys[j] != key_codes[i]) {
    384451                        ++j;
    385452                }
    386453               
    387                 if (j == kbd_dev->key_count) {
     454                if (j == count) {
    388455                        // not found, i.e. new key pressed
    389456                        key = usbhid_parse_scancode(key_codes[i]);
     
    392459                        usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, key);
    393460                        usbhid_kbd_repeat_start(kbd_dev, key);
    394                 } else {
     461                } else {size_t
    395462                        // found, nothing happens
    396463                }
    397464        }
    398 //      // report all currently pressed keys
    399 //      for (i = 0; i < kbd_dev->keycode_count; ++i) {
    400 //              if (key_codes[i] != 0) {
    401 //                      key = usbhid_parse_scancode(key_codes[i]);
    402 //                      usb_log_debug2("Key pressed: %d (keycode: %d)\n", key,
    403 //                          key_codes[i]);
    404 //                      usbhid_kbd_push_ev(kbd_dev, KEY_PRESS, key);
    405 //              }
    406 //      }
    407        
    408         memcpy(kbd_dev->keys, key_codes, kbd_dev->key_count);
     465       
     466        memcpy(kbd_dev->keys, key_codes, count);
    409467
    410468        usb_log_debug("New stored keycodes: %s\n",
     
    415473/* Callbacks for parser                                                       */
    416474/*----------------------------------------------------------------------------*/
    417 
     475/**
     476 * Callback function for the HID report parser.
     477 *
     478 * This function is called by the HID report parser with the parsed report.
     479 * The parsed report is used to check if any events occured (key was pressed or
     480 * released, modifier was pressed or released).
     481 *
     482 * @param key_codes Parsed keyboard report - codes of currently pressed keys
     483 *                  according to HID Usage Tables.
     484 * @param count Number of key codes in report (size of the report).
     485 * @param modifiers Bitmap of modifiers (Ctrl, Alt, Shift, GUI).
     486 * @param arg User-specified argument. Expects pointer to the keyboard device
     487 *            structure representing the keyboard.
     488 *
     489 * @sa usbhid_kbd_check_key_changes(), usbhid_kbd_check_modifier_changes()
     490 */
    418491static void usbhid_kbd_process_keycodes(const uint8_t *key_codes, size_t count,
    419492    uint8_t modifiers, void *arg)
     
    438511       
    439512        usbhid_kbd_check_modifier_changes(kbd_dev, modifiers);
    440         usbhid_kbd_check_key_changes(kbd_dev, key_codes);
     513        usbhid_kbd_check_key_changes(kbd_dev, key_codes, count);
    441514}
    442515
     
    686759                        usb_log_warning("Failed to start a session: %s.\n",
    687760                            str_error(sess_rc));
    688                         continue;
     761                        break;
    689762                }
    690763
     
    698771                        usb_log_warning("Error polling the keyboard: %s.\n",
    699772                            str_error(rc));
    700                         continue;
     773                        break;
    701774                }
    702775
     
    704777                        usb_log_warning("Error closing session: %s.\n",
    705778                            str_error(sess_rc));
    706                         continue;
     779                        break;
    707780                }
    708781
     
    725798                //async_usleep(kbd_dev->hid_dev->poll_interval);
    726799        }
    727 
    728         // not reached
    729         assert(0);
    730800}
    731801
     
    773843 *
    774844 * This functions initializes required structures from the device's descriptors
    775  * and starts a new fibril for polling the keyboard for events.
     845 * and starts new fibril for polling the keyboard for events and another one for
     846 * handling auto-repeat of keys.
    776847 *
    777848 * During initialization, the keyboard is switched into boot protocol, the idle
     
    791862 *         ddf_fun_bind() and ddf_fun_add_to_class().
    792863 *
    793  * @sa usbhid_kbd_fibril()
     864 * @sa usbhid_kbd_fibril(), usbhid_kbd_repeat_fibril()
    794865 */
    795866int usbhid_kbd_try_add_device(ddf_dev_t *dev)
  • uspace/drv/usbhid/kbdrepeat.c

    r8a02ff3 rf4cf2813  
    4545#include "kbddev.h"
    4646
    47 static unsigned int CHECK_DELAY = 1000;
     47
     48/** Delay between auto-repeat state checks when no key is being repeated. */
     49static unsigned int CHECK_DELAY = 10000;
    4850
    4951/*----------------------------------------------------------------------------*/
    50 
     52/**
     53 * Main loop handling the auto-repeat of keys.
     54 *
     55 * This functions periodically checks if there is some key to be auto-repeated.
     56 *
     57 * If a new key is to be repeated, it uses the delay before first repeat stored
     58 * in the keyboard structure to wait until the key has to start repeating.
     59 *
     60 * If the same key is still pressed, it uses the delay between repeats stored
     61 * in the keyboard structure to wait until the key should be repeated.
     62 *
     63 * If the currently repeated key is not pressed any more (
     64 * usbhid_kbd_repeat_stop() was called), it stops repeating it and starts
     65 * checking again.
     66 *
     67 * @note For accessing the keyboard device auto-repeat information a fibril
     68 *       mutex (repeat_mtx) from the @a kbd structure is used.
     69 *
     70 * @param kbd Keyboard device structure.
     71 */
    5172static void usbhid_kbd_repeat_loop(usbhid_kbd_t *kbd)
    5273{
     
    86107
    87108/*----------------------------------------------------------------------------*/
    88 
     109/**
     110 * Main routine to be executed by a fibril for handling auto-repeat.
     111 *
     112 * Starts the loop for checking changes in auto-repeat.
     113 *
     114 * @param arg User-specified argument. Expects pointer to the keyboard device
     115 *            structure representing the keyboard.
     116 *
     117 * @retval EOK if the routine has finished.
     118 * @retval EINVAL if no argument is supplied.
     119 */
    89120int usbhid_kbd_repeat_fibril(void *arg)
    90121{
     
    104135
    105136/*----------------------------------------------------------------------------*/
    106 
     137/**
     138 * Start repeating particular key.
     139 *
     140 * @note Only one key is repeated at any time, so calling this function
     141 *       effectively cancels auto-repeat of the current repeated key (if any)
     142 *       and 'schedules' another key for auto-repeat.
     143 *
     144 * @param kbd Keyboard device structure.
     145 * @param key Key to start repeating.
     146 */
    107147void usbhid_kbd_repeat_start(usbhid_kbd_t *kbd, unsigned int key)
    108148{
     
    113153
    114154/*----------------------------------------------------------------------------*/
    115 
     155/**
     156 * Stop repeating particular key.
     157 *
     158 * @note Only one key is repeated at any time, but this function may be called
     159 *       even with key that is not currently repeated (in that case nothing
     160 *       happens).
     161 *
     162 * @param kbd Keyboard device structure.
     163 * @param key Key to stop repeating.
     164 */
    116165void usbhid_kbd_repeat_stop(usbhid_kbd_t *kbd, unsigned int key)
    117166{
Note: See TracChangeset for help on using the changeset viewer.