Changes in uspace/lib/usbhid/src/hidiface.c [266fcd8:160b75e] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhid/src/hidiface.c
r266fcd8 r160b75e 46 46 * @return Number of usages returned or negative error code. 47 47 */ 48 int usbhid_dev_get_event_length(int dev_phone , size_t *size)48 int usbhid_dev_get_event_length(int dev_phone) 49 49 { 50 50 if (dev_phone < 0) { … … 56 56 IPC_M_USBHID_GET_EVENT_LENGTH, &len); 57 57 if (rc == EOK) { 58 if (size != NULL) {59 *size = (size_t) len;60 }58 return (int) len; 59 } else { 60 return rc; 61 61 } 62 63 return rc;64 62 } 65 63 … … 76 74 * @return Error code. 77 75 */ 78 int usbhid_dev_get_event(int dev_phone, uint 8_t *buf,79 size_t size, size_t *actual_size, int *event_nr, unsigned int flags)76 int usbhid_dev_get_event(int dev_phone, uint16_t *usage_pages, uint16_t *usages, 77 size_t usage_count, size_t *actual_usage_count, unsigned int flags) 80 78 { 81 79 if (dev_phone < 0) { 82 80 return EINVAL; 83 81 } 84 if (( buf== NULL)) {82 if ((usage_pages == NULL) || (usages == NULL)) { 85 83 return ENOMEM; 86 84 } 87 if ( size== 0) {85 if (usage_count == 0) { 88 86 return EINVAL; 89 87 } 90 91 // if (size == 0) {92 // return EOK;93 // }94 88 95 size_t buffer_size = size;96 uint 8_t *buffer = malloc(buffer_size);89 size_t buffer_size = sizeof(uint16_t) * usage_count * 2; 90 uint16_t *buffer = malloc(buffer_size); 97 91 if (buffer == NULL) { 98 92 return ENOMEM; 99 93 } 100 94 101 ipc_call_t opening_request_call;102 95 aid_t opening_request = async_send_2(dev_phone, 103 96 DEV_IFACE_ID(USBHID_DEV_IFACE), IPC_M_USBHID_GET_EVENT, 104 flags, &opening_request_call);97 flags, NULL); 105 98 if (opening_request == 0) { 106 99 free(buffer); … … 135 128 } 136 129 137 size_t act_size = IPC_GET_ARG2(data_request_call); 130 size_t actual_size = IPC_GET_ARG2(data_request_call); 131 size_t items = actual_size / 2; 138 132 139 133 /* Copy the individual items. */ 140 memcpy( buf, buffer, act_size);141 // memcpy(usages, buffer + items, items * sizeof(int32_t));134 memcpy(usage_pages, buffer, items * sizeof(uint16_t)); 135 memcpy(usages, buffer + items, items * sizeof(uint16_t)); 142 136 143 if (actual_size != NULL) { 144 *actual_size = act_size; 145 } 146 147 if (event_nr != NULL) { 148 *event_nr = IPC_GET_ARG1(opening_request_call); 149 } 150 151 return EOK; 152 } 153 154 155 int usbhid_dev_get_report_descriptor_length(int dev_phone, size_t *size) 156 { 157 if (dev_phone < 0) { 158 return EINVAL; 159 } 160 161 sysarg_t arg_size; 162 int rc = async_req_1_1(dev_phone, DEV_IFACE_ID(USBHID_DEV_IFACE), 163 IPC_M_USBHID_GET_REPORT_DESCRIPTOR_LENGTH, &arg_size); 164 if (rc == EOK) { 165 if (size != NULL) { 166 *size = (size_t) arg_size; 167 } 168 } 169 return rc; 170 } 171 172 int usbhid_dev_get_report_descriptor(int dev_phone, uint8_t *buf, size_t size, 173 size_t *actual_size) 174 { 175 if (dev_phone < 0) { 176 return EINVAL; 177 } 178 if ((buf == NULL)) { 179 return ENOMEM; 180 } 181 if (size == 0) { 182 return EINVAL; 183 } 184 185 aid_t opening_request = async_send_1(dev_phone, 186 DEV_IFACE_ID(USBHID_DEV_IFACE), IPC_M_USBHID_GET_REPORT_DESCRIPTOR, 187 NULL); 188 if (opening_request == 0) { 189 return ENOMEM; 190 } 191 192 ipc_call_t data_request_call; 193 aid_t data_request = async_data_read(dev_phone, buf, size, 194 &data_request_call); 195 if (data_request == 0) { 196 async_wait_for(opening_request, NULL); 197 return ENOMEM; 198 } 199 200 sysarg_t data_request_rc; 201 sysarg_t opening_request_rc; 202 async_wait_for(data_request, &data_request_rc); 203 async_wait_for(opening_request, &opening_request_rc); 204 205 if (data_request_rc != EOK) { 206 /* Prefer return code of the opening request. */ 207 if (opening_request_rc != EOK) { 208 return (int) opening_request_rc; 209 } else { 210 return (int) data_request_rc; 211 } 212 } 213 214 if (opening_request_rc != EOK) { 215 return (int) opening_request_rc; 216 } 217 218 size_t act_size = IPC_GET_ARG2(data_request_call); 219 220 if (actual_size != NULL) { 221 *actual_size = act_size; 137 if (actual_usage_count != NULL) { 138 *actual_usage_count = items; 222 139 } 223 140
Note:
See TracChangeset
for help on using the changeset viewer.