-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathUSBDevice.cpp
More file actions
46 lines (41 loc) · 1.43 KB
/
Copy pathUSBDevice.cpp
File metadata and controls
46 lines (41 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "USBDevice.hpp"
#include "USBKeyboard.hpp"
#include "USBMouse.hpp"
#include "usb_types.h"
USBDevice::USBDevice(uint32_t capacity, uint8_t address) : address(address) {
endpoints = IndexMap<USBEndpoint*>(capacity);
};
void USBDevice::request_data(uint8_t endpoint_id, USBDriver *driver){
if (endpoint_id >= endpoints.max_size()) return;
USBEndpoint *ep = endpoints[endpoint_id];
if (ep)
ep->request_data(driver);
}
void USBDevice::process_data(uint8_t endpoint_id, USBDriver *driver){
if (endpoint_id >= endpoints.max_size()) return;
USBEndpoint *ep = endpoints[endpoint_id];
if (ep)
ep->process_data(driver);
}
void USBDevice::register_endpoint(uint8_t endpoint, usb_device_types type, uint32_t interval, uint16_t packet_size){
if (endpoint >= endpoints.max_size()) return;
USBEndpoint *newendpoint;
switch (type){
case KEYBOARD:
newendpoint = new USBKeyboard(address, endpoint, interval, packet_size);
break;
case MOUSE:
newendpoint = new USBMouse(address, endpoint, interval, packet_size);
break;
default: return;
}
if (!newendpoint) return;
endpoints.add(endpoint,newendpoint);
}
void USBDevice::poll_inputs(USBDriver *driver){
for (uint8_t i = 0; i < endpoints.max_size(); i++){
USBEndpoint *ep = endpoints[i];
if (ep && ep->type != UNKNOWN)
ep->request_data(driver);
}
}