blob: 0f8106af4b7a9b799e05535acf32de93bb3a8ecb (
plain)
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
|
/*
* Copyright (c) 2022, Jesse Buhagiar <jesse.buhagiar@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Vector.h>
#include <Kernel/Bus/USB/USBDescriptors.h>
#include <Kernel/Bus/USB/USBDevice.h>
#include <Kernel/Bus/USB/USBInterface.h>
namespace Kernel::USB {
class Device;
class USBConfiguration {
public:
USBConfiguration() = delete;
USBConfiguration(Device& device, USBConfigurationDescriptor const descriptor)
: m_device(device)
, m_descriptor(descriptor)
{
m_interfaces.ensure_capacity(descriptor.number_of_interfaces);
}
Device const& device() const { return m_device; }
USBConfigurationDescriptor const& descriptor() const { return m_descriptor; }
u8 interface_count() const { return m_descriptor.number_of_interfaces; }
u8 configuration_id() const { return m_descriptor.configuration_value; }
u8 attributes() const { return m_descriptor.attributes_bitmap; }
u16 max_power_ma() const { return m_descriptor.max_power_in_ma * 2u; } // Note: "Power" is used incorrectly here, however it's what it's called in the descriptor/documentation
Vector<USBInterface> const& interfaces() const { return m_interfaces; }
ErrorOr<void> enumerate_interfaces();
private:
Device& m_device; // Reference to the device linked to this configuration
USBConfigurationDescriptor const m_descriptor; // Descriptor that backs this configuration
Vector<USBInterface> m_interfaces; // Interfaces for this device
};
}
|