Coverage for linuxpy/codegen/gpio.py: 0%

20 statements  

« 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) 2024 Tiago Coutinho 

5# Distributed under the GPLv3 license. See LICENSE for more info. 

6 

7import pathlib 

8 

9from linuxpy.codegen.base import CEnum, run 

10 

11HEADERS = [ 

12 "/usr/include/linux/gpio.h", 

13] 

14 

15 

16TEMPLATE = """\ 

17# 

18# This file is part of the linuxpy project 

19# 

20# Copyright (c) 2024 Tiago Coutinho 

21# Distributed under the GPLv3 license. See LICENSE for more info. 

22 

23# This file has been generated by {name} 

24# Date: {date} 

25# System: {system} 

26# Release: {release} 

27# Version: {version} 

28 

29import enum 

30 

31from linuxpy.ioctl import IOR as _IOR, IOW as _IOW, IOWR as _IOWR 

32from linuxpy.ctypes import u8, u16, u32, cuint, cint, cchar, culonglong 

33from linuxpy.ctypes import Struct, Union, POINTER, cvoidp 

34 

35 

36MAX_LINES = 64 

37MAX_ATTRS = 10 

38 

39 

40{enums_body} 

41 

42 

43{structs_body} 

44 

45 

46{iocs_body}""" 

47 

48 

49class IOC(CEnum): 

50 def __init__(self): 

51 def filter(name, value): 

52 return name.endswith("_IOCTL") 

53 

54 super().__init__("IOC", ["GPIO_GET_", "GPIO_V2_"], filter=filter) 

55 

56 def add_item(self, name, value): 

57 name = name.removesuffix("_IOCTL") 

58 return super().add_item(name, value) 

59 

60 

61# macros from #define statements 

62MACRO_ENUMS = [ 

63 IOC(), 

64] 

65 

66 

67this_dir = pathlib.Path(__file__).parent 

68 

69 

70def decode_name(name: str) -> str: 

71 return name.removeprefix("gpio_v2_").removeprefix("gpio_") 

72 

73 

74def main(output=this_dir.parent / "gpio" / "raw.py"): 

75 run(__name__, HEADERS, TEMPLATE, MACRO_ENUMS, output=output, decode_enum_name=decode_name) 

76 

77 

78if __name__ == "__main__": 

79 main()