Coverage for linuxpy/codegen/usbfs.py: 0%
11 statements
« prev ^ index » next coverage.py v7.6.8, created at 2025-05-27 13:54 +0200
« prev ^ index » next coverage.py v7.6.8, created at 2025-05-27 13:54 +0200
1#
2# This file is part of the linuxpy project
3#
4# Copyright (c) 2023 Tiago Coutinho
5# Distributed under the GPLv3 license. See LICENSE for more info.
7import pathlib
9from .base import CEnum, run
11HEADERS = [
12 "/usr/include/linux/usbdevice_fs.h",
13 "/usr/include/linux/usbip.h",
14 "/usr/include/linux/usb/ch9.h",
15 "/usr/include/linux/usb/ch11.h",
16 "/usr/include/linux/usb/video.h",
17]
20TEMPLATE = """\
21#
22# This file is part of the linuxpy project
23#
24# Copyright (c) 2023 Tiago Coutinho
25# Distributed under the GPLv3 license. See LICENSE for more info.
27# This file has been generated by {name}
28# Date: {date}
29# System: {system}
30# Release: {release}
31# Version: {version}
33import enum
35from linuxpy.ctypes import (
36 POINTER,
37 Struct,
38 Union,
39 cchar,
40 cint,
41 cuint,
42 cvoidp,
43 u8,
44 u16,
45 u32,
46)
47from linuxpy.ioctl import IO as _IO, IOR as _IOR, IOW as _IOW, IOWR as _IOWR
49{enums_body}
52{structs_body}
55# Extra structs not found on header files
57class usb_hid_descriptor(Struct):
58 _fields_ = [
59 ("bLength", u8),
60 ("bDescriptorType", u8),
61 ("bcdHID", u16),
62 ("bCountryCode", u8),
63 ("bNumDescriptors", u8),
64 ("bClassDescriptorType", u8),
65 ("wClassDescriptorLength", u16),
66 ]
69{iocs_body}"""
71this_dir = pathlib.Path(__file__).parent
73# macros from #define statements
74MACRO_ENUMS = [
75 CEnum("URBType", "USBDEVFS_URB_TYPE_"),
76 CEnum(
77 "URB",
78 "USBDEVFS_URB_",
79 "IntFlag",
80 filter=lambda name, _: not name.startswith("USBDEVFS_USB_TYPE_"),
81 ),
82 CEnum("Capability", "USBDEVFS_CAP_", "IntFlag"),
83 CEnum("DisconnectClaim", "USBDEVFS_DISCONNECT_CLAIM_", "IntFlag"),
84 CEnum(
85 "IOC",
86 "USBDEVFS_",
87 filter=lambda name, value: "_IO" in value and not name.endswith("32"),
88 ),
89 CEnum("Direction", "USB_DIR_"),
90 CEnum("RequestType", "USB_TYPE_"),
91 CEnum("Recipient", "USB_RECIP_"),
92 CEnum("Request", "USB_REQ_"),
93 CEnum("Device", "USB_DEVICE_"),
94 CEnum("Class", "USB_CLASS_"),
95 CEnum("Test", "USB_TEST_"),
96 CEnum("StatusType", "USB_STATUS_TYPE_"),
97 CEnum("EndpointTransferType", "USB_ENDPOINT_XFER_"),
98 CEnum("VideoSubClass", "UVC_SC_"),
99 CEnum("VideoProtocol", "UVC_PC_PROTOCOL_"),
100 CEnum("VideoControl", "UVC_VC_"),
101 CEnum("VideoStreaming", "UVC_VS_"),
102 CEnum("VideoEndPoint", "UVC_EP_"),
103]
106this_dir = pathlib.Path(__file__).parent
109def main(output=this_dir.parent / "usb" / "raw.py"):
110 run(__name__, HEADERS, TEMPLATE, MACRO_ENUMS, output=output)
113if __name__ == "__main__":
114 main()