Changes in uspace/lib/usbhid/src/hidiface.c [160b75e:266fcd8] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/usbhid/src/hidiface.c
r160b75e r266fcd8 46 46 * @return Number of usages returned or negative error code. 47 47 */ 48 int usbhid_dev_get_event_length(int dev_phone )48 int usbhid_dev_get_event_length(int dev_phone, size_t *size) 49 49 { 50 50 if (dev_phone < 0) { … … 56 56 IPC_M_USBHID_GET_EVENT_LENGTH, &len); 57 57 if (rc == EOK) { 58 return (int) len; 59 } else { 60 return rc; 61 } 58 if (size != NULL) { 59 *size = (size_t) len; 60 } 61 } 62 63 return rc; 62 64 } 63 65 … … 74 76 * @return Error code. 75 77 */ 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) 78 { 79 if (dev_phone < 0) { 80 return EINVAL; 81 } 82 if ((usage_pages == NULL) || (usages == NULL)) { 83 return ENOMEM; 84 } 85 if (usage_count == 0) { 86 return EINVAL; 87 } 88 89 size_t buffer_size = sizeof(uint16_t) * usage_count * 2; 90 uint16_t *buffer = malloc(buffer_size); 78 int usbhid_dev_get_event(int dev_phone, uint8_t *buf, 79 size_t size, size_t *actual_size, int *event_nr, unsigned int flags) 80 { 81 if (dev_phone < 0) { 82 return EINVAL; 83 } 84 if ((buf == NULL)) { 85 return ENOMEM; 86 } 87 if (size == 0) { 88 return EINVAL; 89 } 90 91 // if (size == 0) { 92 // return EOK; 93 // } 94 95 size_t buffer_size = size; 96 uint8_t *buffer = malloc(buffer_size); 91 97 if (buffer == NULL) { 92 98 return ENOMEM; 93 99 } 94 100 101 ipc_call_t opening_request_call; 95 102 aid_t opening_request = async_send_2(dev_phone, 96 103 DEV_IFACE_ID(USBHID_DEV_IFACE), IPC_M_USBHID_GET_EVENT, 97 flags, NULL);104 flags, &opening_request_call); 98 105 if (opening_request == 0) { 99 106 free(buffer); … … 128 135 } 129 136 130 size_t actual_size = IPC_GET_ARG2(data_request_call); 131 size_t items = actual_size / 2; 137 size_t act_size = IPC_GET_ARG2(data_request_call); 132 138 133 139 /* Copy the individual items. */ 134 memcpy(usage_pages, buffer, items * sizeof(uint16_t)); 135 memcpy(usages, buffer + items, items * sizeof(uint16_t)); 136 137 if (actual_usage_count != NULL) { 138 *actual_usage_count = items; 140 memcpy(buf, buffer, act_size); 141 // memcpy(usages, buffer + items, items * sizeof(int32_t)); 142 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; 139 222 } 140 223
Note:
See TracChangeset
for help on using the changeset viewer.