gen_periphery.py 657 B

1234567891011121314151617181920212223242526
  1. import pcpp
  2. import pycparser
  3. from c_bind import Library, set_vmath_converter, set_enum_converters
  4. from c_bind.meta import Header
  5. import os
  6. file_dir = os.path.dirname(os.path.abspath(__file__))
  7. path = '3rd/periphery/c-periphery/src/gpio.h'
  8. code = pcpp.CmdPreprocessor([None, path, '-o', 'tmp.h', '-I', os.path.join(file_dir, 'libc_include')])
  9. ast = pycparser.parse_file('tmp.h')
  10. os.remove('tmp.h')
  11. header = Header()
  12. header.build(ast)
  13. lib = Library.from_header('periphery', header)
  14. set_enum_converters([enum.name for enum in lib.enums])
  15. lib.build(
  16. includes=['c-periphery/gpio.h'],
  17. glue_dir='3rd/periphery/src',
  18. stub_dir='include/typings'
  19. )