mirror of
https://github.com/pocketpy/pocketpy
synced 2026-02-04 06:30:17 +00:00
fix periphery
This commit is contained in:
parent
36ee9dddd8
commit
b4d035a912
@ -1644,11 +1644,9 @@ static bool cfunc__serial_set_parity(int argc, py_Ref argv) {
|
||||
serial_t* _0;
|
||||
if(!py_checkint(py_arg(0))) return false;
|
||||
_0 = (serial_t*)py_toint(py_arg(0));
|
||||
enum serial_parity _1;
|
||||
do {
|
||||
if(!py_checktype(py_arg(1), tp_user_enum serial_parity)) return false;
|
||||
_1 = *(enum serial_parity*)py_touserdata(py_arg(1));
|
||||
} while(0);
|
||||
serial_parity_t _1;
|
||||
if(!py_checkint(py_arg(1))) return false;
|
||||
_1 = (serial_parity_t)py_toint(py_arg(1));
|
||||
int res = serial_set_parity(_0, _1);
|
||||
py_newint(py_retval(), res);
|
||||
return true;
|
||||
|
||||
@ -33,7 +33,7 @@ class Header:
|
||||
self.type_aliases[k] = v
|
||||
|
||||
def build_enum(self, node: c_ast.Enum, alias_name: str | None = None):
|
||||
enum = Enum(node.name)
|
||||
enum = Enum(node.name, alias_name)
|
||||
for item in node.values.enumerators:
|
||||
enum.values.append(item.name)
|
||||
self.types.append(enum)
|
||||
|
||||
@ -23,8 +23,9 @@ class Struct(NamedFields): pass
|
||||
class Union(NamedFields): pass
|
||||
|
||||
class Enum:
|
||||
def __init__(self, name: str):
|
||||
def __init__(self, name: str, typedef_name: str | None = None):
|
||||
self.name = name
|
||||
self.typedef_name = typedef_name
|
||||
self.values = [] # type: list[str]
|
||||
|
||||
def __repr__(self):
|
||||
|
||||
@ -10,6 +10,17 @@ file_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
path = '3rd/periphery/include/periphery.h'
|
||||
code = pcpp.CmdPreprocessor([None, path, '-o', 'tmp.h', '-I', os.path.join(file_dir, 'libc_include')])
|
||||
|
||||
mapping = {
|
||||
'enum serial_parity parity': 'serial_parity_t parity',
|
||||
}
|
||||
# remap tmp.h
|
||||
with open('tmp.h', 'r') as f:
|
||||
content = f.read()
|
||||
for k, v in mapping.items():
|
||||
content = content.replace(k, v)
|
||||
with open('tmp.h', 'w') as f:
|
||||
f.write(content)
|
||||
|
||||
ast = pycparser.parse_file('tmp.h')
|
||||
os.remove('tmp.h')
|
||||
|
||||
|
||||
@ -352,8 +352,8 @@ def serial_set_baudrate(serial: intptr, baudrate: int, /) -> int:
|
||||
def serial_set_databits(serial: intptr, databits: int, /) -> int:
|
||||
"""Wraps `int serial_set_databits(serial_t* serial, unsigned databits)`"""
|
||||
|
||||
def serial_set_parity(serial: intptr, parity: enum serial_parity, /) -> int:
|
||||
"""Wraps `int serial_set_parity(serial_t* serial, enum serial_parity parity)`"""
|
||||
def serial_set_parity(serial: intptr, parity: int, /) -> int:
|
||||
"""Wraps `int serial_set_parity(serial_t* serial, serial_parity_t parity)`"""
|
||||
|
||||
def serial_set_stopbits(serial: intptr, stopbits: int, /) -> int:
|
||||
"""Wraps `int serial_set_stopbits(serial_t* serial, unsigned stopbits)`"""
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user