Ignore:
Timestamp:
2011-05-12T08:33:24Z (14 years ago)
Author:
Lubos Slovak <lubos.slovak@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
373bc2d
Parents:
cecb1a97
Message:

Renamed lgtch-ultrax subdriver to multimedia

File:
1 moved

Legend:

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

    rcecb1a97 rd3b6d5e  
    3232/**
    3333 * @file
    34  * USB Logitech UltraX Keyboard sample driver.
    35  */
    36 
    37 
    38 #include "lgtch-ultrax.h"
     34 * USB Keyboard multimedia keys subdriver.
     35 */
     36
     37
     38#include "multimedia.h"
    3939#include "../usbhid.h"
    4040#include "keymap.h"
     
    5050#include <io/console.h>
    5151
    52 #define NAME "lgtch-ultrax"
    53 
    54 typedef enum usb_lgtch_flags {
    55         USB_LGTCH_STATUS_UNINITIALIZED = 0,
    56         USB_LGTCH_STATUS_INITIALIZED = 1,
    57         USB_LGTCH_STATUS_TO_DESTROY = -1
    58 } usb_lgtch_flags;
     52#define NAME "multimedia-keys"
    5953
    6054/*----------------------------------------------------------------------------*/
     
    6256 * Logitech UltraX device type.
    6357 */
    64 typedef struct usb_lgtch_ultrax_t {
     58typedef struct usb_multimedia_t {
    6559        /** Previously pressed keys (not translated to key codes). */
    6660        int32_t *keys_old;
     
    6862        int32_t *keys;
    6963        /** Count of stored keys (i.e. number of keys in the report). */
    70         size_t key_count;
    71        
     64        size_t key_count;       
    7265        /** IPC phone to the console device (for sending key events). */
    7366        int console_phone;
    74 
    75         /** Information for auto-repeat of keys. */
    76 //      usb_kbd_repeat_t repeat;
    77        
    78         /** Mutex for accessing the information about auto-repeat. */
    79 //      fibril_mutex_t *repeat_mtx;
    80 
    81         /** State of the structure (for checking before use).
    82          *
    83          * 0 - not initialized
    84          * 1 - initialized
    85          * -1 - ready for destroying
    86          */
    87         int initialized;
    88 } usb_lgtch_ultrax_t;
     67} usb_multimedia_t;
    8968
    9069
     
    11796        assert(hid_dev != NULL);
    11897        assert(hid_dev->data != NULL);
    119         usb_lgtch_ultrax_t *lgtch_dev = (usb_lgtch_ultrax_t *)hid_dev->data;
     98        usb_multimedia_t *multim_dev = (usb_multimedia_t *)hid_dev->data;
    12099
    121100        if (method == IPC_M_CONNECT_TO_ME) {
    122101                int callback = IPC_GET_ARG5(*icall);
    123102
    124                 if (lgtch_dev->console_phone != -1) {
     103                if (multim_dev->console_phone != -1) {
    125104                        async_answer_0(icallid, ELIMIT);
    126105                        return;
    127106                }
    128107
    129                 lgtch_dev->console_phone = callback;
     108                multim_dev->console_phone = callback;
    130109                usb_log_debug(NAME " Saved phone to console: %d\n", callback);
    131110                async_answer_0(icallid, EOK);
     
    138117/*----------------------------------------------------------------------------*/
    139118
    140 static ddf_dev_ops_t lgtch_ultrax_ops = {
     119static ddf_dev_ops_t multimedia_ops = {
    141120        .default_handler = default_connection_handler
    142121};
    143 
    144 /*----------------------------------------------------------------------------*/
    145 
    146 //static void usb_lgtch_process_keycodes(const uint8_t *key_codes, size_t count,
    147 //    uint8_t report_id, void *arg);
    148 
    149 //static const usb_hid_report_in_callbacks_t usb_lgtch_parser_callbacks = {
    150 //      .keyboard = usb_lgtch_process_keycodes
    151 //};
    152 
    153 ///*----------------------------------------------------------------------------*/
    154 
    155 //static void usb_lgtch_process_keycodes(const uint8_t *key_codes, size_t count,
    156 //    uint8_t report_id, void *arg)
    157 //{
    158 //      // TODO: checks
    159        
    160 //      usb_log_debug(NAME " Got keys from parser (report id: %u): %s\n",
    161 //          report_id, usb_debug_str_buffer(key_codes, count, 0));
    162 //}
    163122
    164123/*----------------------------------------------------------------------------*/
     
    180139 * @param key Key code of the key according to HID Usage Tables.
    181140 */
    182 static void usb_lgtch_push_ev(usb_hid_dev_t *hid_dev, int type,
     141static void usb_multimedia_push_ev(usb_hid_dev_t *hid_dev, int type,
    183142    unsigned int key)
    184143{
     
    186145        assert(hid_dev->data != NULL);
    187146       
    188         usb_lgtch_ultrax_t *lgtch_dev = (usb_lgtch_ultrax_t *)hid_dev->data;
     147        usb_multimedia_t *multim_dev = (usb_multimedia_t *)hid_dev->data;
    189148       
    190149        console_event_t ev;
     
    193152        ev.key = key;
    194153        ev.mods = 0;
    195 
    196154        ev.c = 0;
    197155
    198156        usb_log_debug2(NAME " Sending key %d to the console\n", ev.key);
    199         if (lgtch_dev->console_phone < 0) {
     157        if (multim_dev->console_phone < 0) {
    200158                usb_log_warning(
    201159                    "Connection to console not ready, key discarded.\n");
     
    203161        }
    204162       
    205         async_msg_4(lgtch_dev->console_phone, KBD_EVENT, ev.type, ev.key,
     163        async_msg_4(multim_dev->console_phone, KBD_EVENT, ev.type, ev.key,
    206164            ev.mods, ev.c);
    207165}
     
    209167/*----------------------------------------------------------------------------*/
    210168
    211 static void usb_lgtch_free(usb_lgtch_ultrax_t **lgtch_dev)
    212 {
    213         if (lgtch_dev == NULL || *lgtch_dev == NULL) {
     169static void usb_multimedia_free(usb_multimedia_t **multim_dev)
     170{
     171        if (multim_dev == NULL || *multim_dev == NULL) {
    214172                return;
    215173        }
    216174       
    217175        // hangup phone to the console
    218         async_hangup((*lgtch_dev)->console_phone);
    219        
    220 //      if ((*lgtch_dev)->repeat_mtx != NULL) {
    221 //              /* TODO: replace by some check and wait */
    222 //              assert(!fibril_mutex_is_locked((*lgtch_dev)->repeat_mtx));
    223 //              free((*lgtch_dev)->repeat_mtx);
    224 //      }
     176        async_hangup((*multim_dev)->console_phone);
    225177       
    226178        // free all buffers
    227         if ((*lgtch_dev)->keys != NULL) {
    228                 free((*lgtch_dev)->keys);
    229         }
    230         if ((*lgtch_dev)->keys_old != NULL) {
    231                 free((*lgtch_dev)->keys_old);
    232         }
    233 
    234         free(*lgtch_dev);
    235         *lgtch_dev = NULL;
    236 }
    237 
    238 /*----------------------------------------------------------------------------*/
    239 
    240 static int usb_lgtch_create_function(usb_hid_dev_t *hid_dev)
     179        if ((*multim_dev)->keys != NULL) {
     180                free((*multim_dev)->keys);
     181        }
     182        if ((*multim_dev)->keys_old != NULL) {
     183                free((*multim_dev)->keys_old);
     184        }
     185
     186        free(*multim_dev);
     187        *multim_dev = NULL;
     188}
     189
     190/*----------------------------------------------------------------------------*/
     191
     192static int usb_multimedia_create_function(usb_hid_dev_t *hid_dev)
    241193{
    242194        /* Create the function exposed under /dev/devices. */
     
    252204         * to the DDF function.
    253205         */
    254         fun->ops = &lgtch_ultrax_ops;
     206        fun->ops = &multimedia_ops;
    255207        fun->driver_data = hid_dev;   // TODO: maybe change to hid_dev->data
    256208       
     
    279231/*----------------------------------------------------------------------------*/
    280232
    281 int usb_lgtch_init(struct usb_hid_dev *hid_dev)
     233int usb_multimedia_init(struct usb_hid_dev *hid_dev)
    282234{
    283235        if (hid_dev == NULL || hid_dev->usb_dev == NULL) {
     
    285237        }
    286238       
    287         usb_log_debug(NAME " Initializing HID/lgtch_ultrax structure...\n");
    288        
    289         usb_lgtch_ultrax_t *lgtch_dev = (usb_lgtch_ultrax_t *)malloc(
    290             sizeof(usb_lgtch_ultrax_t));
    291         if (lgtch_dev == NULL) {
     239        usb_log_debug(NAME " Initializing HID/multimedia structure...\n");
     240       
     241        usb_multimedia_t *multim_dev = (usb_multimedia_t *)malloc(
     242            sizeof(usb_multimedia_t));
     243        if (multim_dev == NULL) {
    292244                return ENOMEM;
    293245        }
    294246       
    295         lgtch_dev->console_phone = -1;
     247        multim_dev->console_phone = -1;
    296248       
    297249        usb_hid_report_path_t *path = usb_hid_report_path();
     
    300252        usb_hid_report_path_set_report_id(path, 1);
    301253       
    302         lgtch_dev->key_count = usb_hid_report_input_length(
     254        multim_dev->key_count = usb_hid_report_input_length(
    303255            hid_dev->report, path,
    304256            USB_HID_PATH_COMPARE_END | USB_HID_PATH_COMPARE_USAGE_PAGE_ONLY);
     
    306258       
    307259        usb_log_debug(NAME " Size of the input report: %zu\n",
    308             lgtch_dev->key_count);
    309        
    310         lgtch_dev->keys = (int32_t *)calloc(lgtch_dev->key_count,
     260            multim_dev->key_count);
     261       
     262        multim_dev->keys = (int32_t *)calloc(multim_dev->key_count,
    311263            sizeof(int32_t));
    312264       
    313         if (lgtch_dev->keys == NULL) {
     265        if (multim_dev->keys == NULL) {
    314266                usb_log_fatal("No memory!\n");
    315                 free(lgtch_dev);
     267                free(multim_dev);
    316268                return ENOMEM;
    317269        }
    318270       
    319         lgtch_dev->keys_old =
    320                 (int32_t *)calloc(lgtch_dev->key_count, sizeof(int32_t));
    321        
    322         if (lgtch_dev->keys_old == NULL) {
     271        multim_dev->keys_old =
     272                (int32_t *)calloc(multim_dev->key_count, sizeof(int32_t));
     273       
     274        if (multim_dev->keys_old == NULL) {
    323275                usb_log_fatal("No memory!\n");
    324                 free(lgtch_dev->keys);
    325                 free(lgtch_dev);
     276                free(multim_dev->keys);
     277                free(multim_dev);
    326278                return ENOMEM;
    327279        }
     
    330282       
    331283        // save the KBD device structure into the HID device structure
    332         hid_dev->data = lgtch_dev;
    333        
    334         lgtch_dev->initialized = USB_LGTCH_STATUS_INITIALIZED;
    335         usb_log_debug(NAME " HID/lgtch_ultrax device structure initialized.\n");
    336        
    337         int rc = usb_lgtch_create_function(hid_dev);
     284        hid_dev->data = multim_dev;
     285       
     286        usb_log_debug(NAME " HID/multimedia device structure initialized.\n");
     287       
     288        int rc = usb_multimedia_create_function(hid_dev);
    338289        if (rc != EOK) {
    339                 usb_lgtch_free(&lgtch_dev);
     290                usb_multimedia_free(&multim_dev);
    340291                return rc;
    341292        }
    342293       
    343         usb_log_debug(NAME " HID/lgtch_ultrax structure initialized.\n");
     294        usb_log_debug(NAME " HID/multimedia structure initialized.\n");
    344295       
    345296        return EOK;
     
    348299/*----------------------------------------------------------------------------*/
    349300
    350 void usb_lgtch_deinit(struct usb_hid_dev *hid_dev)
     301void usb_multimedia_deinit(struct usb_hid_dev *hid_dev)
    351302{
    352303        if (hid_dev == NULL) {
     
    355306       
    356307        if (hid_dev->data != NULL) {
    357                 usb_lgtch_ultrax_t *lgtch_dev =
    358                     (usb_lgtch_ultrax_t *)hid_dev->data;
    359 //              if (usb_kbd_is_initialized(kbd_dev)) {
    360 //                      usb_kbd_mark_unusable(kbd_dev);
    361 //              } else {
    362                         usb_lgtch_free(&lgtch_dev);
    363                         hid_dev->data = NULL;
    364 //              }
    365         }
    366 }
    367 
    368 /*----------------------------------------------------------------------------*/
    369 
    370 bool usb_lgtch_polling_callback(struct usb_hid_dev *hid_dev,
     308                usb_multimedia_t *multim_dev =
     309                    (usb_multimedia_t *)hid_dev->data;
     310                usb_multimedia_free(&multim_dev);
     311                hid_dev->data = NULL;
     312        }
     313}
     314
     315/*----------------------------------------------------------------------------*/
     316
     317bool usb_multimedia_polling_callback(struct usb_hid_dev *hid_dev,
    371318    uint8_t *buffer, size_t buffer_size)
    372319{
     
    380327       
    381328        usb_hid_report_path_t *path = usb_hid_report_path();
    382         usb_hid_report_path_append_item(path, 0xc, 0);
     329        usb_hid_report_path_append_item(path, USB_HIDUT_PAGE_CONSUMER, 0);
    383330
    384331        uint8_t report_id;
     
    409356                    field->usage);
    410357               
    411                 key = usb_lgtch_map_usage(field->usage);
    412                 usb_lgtch_push_ev(hid_dev, KEY_PRESS, key);
     358                key = usb_multimedia_map_usage(field->usage);
     359                const char *key_str = usb_multimedia_usage_to_str(field->usage);
     360                usb_log_info("Pressed key: %s\n", key_str);
     361                usb_multimedia_push_ev(hid_dev, KEY_PRESS, key);
    413362               
    414363                field = usb_hid_report_get_sibling(
Note: See TracChangeset for help on using the changeset viewer.