mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 07:17:35 +00:00
Kernel/USB: Fetch configuration descriptors on enumeration
This also introduces a new class, `USBConfiguration` that stores a configuration. The device, when instructed, sets this configuration and holds a pointer to it so we have a record of what configuration is currently active.
This commit is contained in:
parent
1409a48da6
commit
dac26f89cb
3 changed files with 62 additions and 0 deletions
38
Kernel/Bus/USB/USBConfiguration.h
Normal file
38
Kernel/Bus/USB/USBConfiguration.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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>
|
||||
|
||||
namespace Kernel::USB {
|
||||
|
||||
class Device;
|
||||
|
||||
class USBConfiguration {
|
||||
public:
|
||||
USBConfiguration() = delete;
|
||||
USBConfiguration(Device& device, USBConfigurationDescriptor const configuration_descriptor)
|
||||
: m_device(device)
|
||||
, m_descriptor(configuration_descriptor)
|
||||
{
|
||||
}
|
||||
|
||||
Device const& device() const { return m_device; }
|
||||
|
||||
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
|
||||
|
||||
private:
|
||||
Device& m_device; // Reference to the device linked to this configuration
|
||||
USBConfigurationDescriptor m_descriptor; // Descriptor that backs this configuration
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue