USBDevice.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. * Copyright (c) 2021, Jesse Buhagiar <jooster669@gmail.com>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/OwnPtr.h>
  8. #include <AK/Types.h>
  9. #include <Kernel/Bus/USB/USBPipe.h>
  10. namespace Kernel::USB {
  11. class USBController;
  12. //
  13. // Some nice info from FTDI on device enumeration and how some of this
  14. // glues together:
  15. //
  16. // https://www.ftdichip.com/Support/Documents/TechnicalNotes/TN_113_Simplified%20Description%20of%20USB%20Device%20Enumeration.pdf
  17. class Device : public RefCounted<Device> {
  18. public:
  19. enum class DeviceSpeed : u8 {
  20. FullSpeed = 0,
  21. LowSpeed
  22. };
  23. public:
  24. static KResultOr<NonnullRefPtr<Device>> try_create(USBController const&, u8, DeviceSpeed);
  25. Device(USBController const&, u8, DeviceSpeed, NonnullOwnPtr<Pipe> default_pipe);
  26. Device(Device const& device, NonnullOwnPtr<Pipe> default_pipe);
  27. virtual ~Device();
  28. KResult enumerate_device();
  29. u8 port() const { return m_device_port; }
  30. DeviceSpeed speed() const { return m_device_speed; }
  31. u8 address() const { return m_address; }
  32. const USBDeviceDescriptor& device_descriptor() const { return m_device_descriptor; }
  33. USBController& controller() { return *m_controller; }
  34. USBController const& controller() const { return *m_controller; }
  35. protected:
  36. Device(NonnullRefPtr<USBController> controller, u8 address, u8 port, DeviceSpeed speed, NonnullOwnPtr<Pipe> default_pipe);
  37. u8 m_device_port { 0 }; // What port is this device attached to. NOTE: This is 1-based.
  38. DeviceSpeed m_device_speed; // What speed is this device running at
  39. u8 m_address { 0 }; // USB address assigned to this device
  40. // Device description
  41. u16 m_vendor_id { 0 }; // This device's vendor ID assigned by the USB group
  42. u16 m_product_id { 0 }; // This device's product ID assigned by the USB group
  43. USBDeviceDescriptor m_device_descriptor; // Device Descriptor obtained from USB Device
  44. NonnullRefPtr<USBController> m_controller;
  45. NonnullOwnPtr<Pipe> m_default_pipe; // Default communication pipe (endpoint0) used during enumeration
  46. private:
  47. IntrusiveListNode<Device, NonnullRefPtr<Device>> m_hub_child_node;
  48. public:
  49. using List = IntrusiveList<Device, NonnullRefPtr<Device>, &Device::m_hub_child_node>;
  50. };
  51. }