-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstm_.py
152 lines (137 loc) · 5.17 KB
/
stm_.py
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
"""
Generate `pyi` from corresponding `rst` docs.
"""
from typing import Final
import rst
from class_ import strip_leading_and_trailing_blank_lines
from rst2pyi import RST2PyI
__author__ = rst.__author__
__copyright__ = rst.__copyright__
__license__ = rst.__license__
__version__ = "7.5.3" # Version set by https://github.com/hlovatt/tag2ver
def stm(shed: RST2PyI) -> None:
shed.module(
name="stm",
old="functionality specific to STM32 MCUs",
post_doc='''
from typing import Final
# noinspection PyPep8Naming
class mem:
"""
Memory objects that can be used in combination with the peripheral register
constants to read and write registers of the MCU hardware peripherals, as well
as all other areas of address space.
Cannot make an instance of this class,
but pre-made instances: `mem8`, `mem16`, and `mem32` are available for 8, 16, and 32 bit access respectively.
"""
def __getitem__(self, loc: int, /) -> int:
"""
Get the contents of the given memory location using subscript notation e.g., `mem8[0]`.
Returns 8 bits for mem8`, 16 bits for `mem16`, and 32 bits for `mem32`, in all cases as a single `int`.
Location doesn't overflow, it is truncated.
Can be used in combination with the peripheral register
constants to read registers of the MCU hardware peripherals, as well
as all other areas of address space.
"""
def __setitem__(self, loc: int, value: int, /) -> None:
"""
Set the contents of the given memory location to the given value using subscript notation e.g., `mem8[0] = 195`.
Sets 8 bits for `mem8`, 16 bits for `mem16`, and 32 bits for `mem32`, from the given `int` value.
Location doesn't overflow, it is truncated.
Can be used in combination with the peripheral register
constants to write registers of the MCU hardware peripherals, as well
as all other areas of address space.
"""
''',
end="Memory access",
)
shed.consume_containing_line(
"The module exposes three objects used for raw memory access.",
and_preceding_lines=True,
)
shed.vars(
old=r".. data:: mem8", class_var=None, type_="mem",
)
shed.vars(
old=r".. data:: mem16", class_var=None, type_="mem",
)
use_sub: Final = "Use subscript notation ``[...]`` to index these objects with the address of"
shed.vars(
old=r".. data:: mem32", class_var=None, type_="mem", end=use_sub,
)
shed.consume_containing_line(
use_sub, and_preceding_lines=True,
)
shed.consume_containing_line(
"interest.", and_preceding_lines=True,
)
shed.consume_containing_line(
"These memory objects can be used in combination with the peripheral register",
and_preceding_lines=True,
)
shed.consume_containing_line(
"constants to read and write registers of the MCU hardware peripherals, as well",
and_preceding_lines=True,
)
shed.consume_containing_line(
"as all other areas of address space.", and_preceding_lines=True,
)
shed.consume_minuses_underline_line(and_preceding_lines=True)
gpioa_reg = r".. data:: GPIOA"
extra_reg_doc: Final = strip_leading_and_trailing_blank_lines(
shed.extra_docs(indent=0, end=gpioa_reg,)
)
temp_reg_def: Final = shed.rst.pop_lines(num_lines=21)
fun_spec: Final = "Functions specific to STM32WBxx MCUs"
extra_reg_doc.extend(
strip_leading_and_trailing_blank_lines(shed.extra_docs(indent=0, end=fun_spec))
)
shed.rst.push_lines(lines=temp_reg_def)
shed.vars(
old=gpioa_reg, class_var=None, extra_docs=extra_reg_doc,
)
shed.vars(
old=r".. data:: GPIOB", class_var=None, extra_docs=extra_reg_doc,
)
shed.vars(
old=r".. data:: GPIO_BSRR", class_var=None, extra_docs=extra_reg_doc,
)
shed.vars(
old=r".. data:: GPIO_IDR", class_var=None, extra_docs=extra_reg_doc,
)
shed.vars(
old=r".. data:: GPIO_ODR",
class_var=None,
extra_docs=extra_reg_doc,
end=fun_spec,
)
shed.consume_minuses_underline_line(and_preceding_lines=True)
rf_stat = r".. function:: rfcore_status()"
fun_spec_extra_doc: Final = strip_leading_and_trailing_blank_lines(
shed.extra_docs(end=rf_stat)
)
shed.def_(
old=rf_stat,
new="def rfcore_status() -> int",
indent=0,
extra_docs=fun_spec_extra_doc,
)
shed.def_(
old=r".. function:: rfcore_fw_version(id)",
new="def rfcore_fw_version(id: int, /) -> tuple[int, int, int, int, int]",
indent=0,
extra_docs=fun_spec_extra_doc,
)
make_room: Final = shed.rst.pop_lines(num_lines=5)
dummy_end = "DUMMY END LINE"
shed.rst.push_line(dummy_end)
shed.rst.push_lines(lines=make_room)
shed.def_(
old=r".. function:: rfcore_sys_hci(ogf, ocf, data, timeout_ms=0)",
new="def rfcore_sys_hci(ogf: int, ocf: int, data: int, timeout_ms: int = 0, /) -> bytes",
indent=0,
extra_docs=fun_spec_extra_doc,
end=dummy_end,
)
shed.consume_containing_line(dummy_end)
shed.write()