From 36ee9dddd8f955f087f6bc14ef50291cc05f9d9f Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Thu, 18 Dec 2025 18:06:27 +0800 Subject: [PATCH] improve periphery --- 3rd/periphery/include/periphery.h | 6 +- 3rd/periphery/src/periphery.c | 1187 +++++++++++++++++++++++++++++ ffigen/ffigen/meta/parser.py | 1 + ffigen/libc_include/stdint.h | 2 +- ffigen/libc_include/sys/types.h | 2 + include/typings/periphery.pyi | 266 ++++++- include/typings/stdc.pyi | 4 + src/modules/stdc.c | 9 + 8 files changed, 1472 insertions(+), 5 deletions(-) create mode 100644 ffigen/libc_include/sys/types.h diff --git a/3rd/periphery/include/periphery.h b/3rd/periphery/include/periphery.h index 32c10b42..508057a0 100644 --- a/3rd/periphery/include/periphery.h +++ b/3rd/periphery/include/periphery.h @@ -1,8 +1,8 @@ #include "../c-periphery/src/gpio.h" // #include "../c-periphery/src/i2c.h" // #include "../c-periphery/src/led.h" -// #include "../c-periphery/src/mmio.h" +#include "../c-periphery/src/mmio.h" #include "../c-periphery/src/pwm.h" -// #include "../c-periphery/src/serial.h" -// #include "../c-periphery/src/spi.h" +#include "../c-periphery/src/serial.h" +#include "../c-periphery/src/spi.h" #include "../c-periphery/src/version.h" diff --git a/3rd/periphery/src/periphery.c b/3rd/periphery/src/periphery.c index c79ed2d7..ebe9b662 100644 --- a/3rd/periphery/src/periphery.c +++ b/3rd/periphery/src/periphery.c @@ -157,6 +157,123 @@ static py_Type register__gpio_config(py_GlobalRef mod) { return type; } static py_Type tp_user_gpio_config; +static bool spi_msg__new__(int argc, py_Ref argv) { + py_Type cls = py_totype(argv); + py_newobject(py_retval(), cls, 0, sizeof(spi_msg_t)); + return true; +} +static bool spi_msg__init__(int argc, py_Ref argv) { + spi_msg_t* self = py_touserdata(argv); + if(argc == 1) { + memset(self, 0, sizeof(spi_msg_t)); + } else if(argc == 1 + 6) { + // _0 txbuf is read-only + if(!py_checkint(py_arg(2))) return false; + self->rxbuf = (uint8_t*)py_toint(py_arg(2)); + if(!py_checkint(py_arg(3))) return false; + self->len = py_toint(py_arg(3)); + if(!py_checkbool(py_arg(4))) return false; + self->deselect = py_tobool(py_arg(4)); + if(!py_checkint(py_arg(5))) return false; + self->deselect_delay_us = py_toint(py_arg(5)); + if(!py_checkint(py_arg(6))) return false; + self->word_delay_us = py_toint(py_arg(6)); + } else { + return TypeError("expected 1 or 7 arguments"); + } + py_newnone(py_retval()); + return true; +} +static bool spi_msg__get_txbuf(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + spi_msg_t* self = py_touserdata(argv); + py_newint(py_retval(), (py_i64)self->txbuf); + return true; +} +static bool spi_msg__get_rxbuf(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + spi_msg_t* self = py_touserdata(argv); + py_newint(py_retval(), (py_i64)self->rxbuf); + return true; +} +static bool spi_msg__set_rxbuf(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + spi_msg_t* self = py_touserdata(argv); + if(!py_checkint(py_arg(1))) return false; + self->rxbuf = (uint8_t*)py_toint(py_arg(1)); + py_newnone(py_retval()); + return true; +} +static bool spi_msg__get_len(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + spi_msg_t* self = py_touserdata(argv); + py_newint(py_retval(), self->len); + return true; +} +static bool spi_msg__set_len(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + spi_msg_t* self = py_touserdata(argv); + if(!py_checkint(py_arg(1))) return false; + self->len = py_toint(py_arg(1)); + py_newnone(py_retval()); + return true; +} +static bool spi_msg__get_deselect(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + spi_msg_t* self = py_touserdata(argv); + py_newbool(py_retval(), self->deselect); + return true; +} +static bool spi_msg__set_deselect(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + spi_msg_t* self = py_touserdata(argv); + if(!py_checkbool(py_arg(1))) return false; + self->deselect = py_tobool(py_arg(1)); + py_newnone(py_retval()); + return true; +} +static bool spi_msg__get_deselect_delay_us(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + spi_msg_t* self = py_touserdata(argv); + py_newint(py_retval(), self->deselect_delay_us); + return true; +} +static bool spi_msg__set_deselect_delay_us(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + spi_msg_t* self = py_touserdata(argv); + if(!py_checkint(py_arg(1))) return false; + self->deselect_delay_us = py_toint(py_arg(1)); + py_newnone(py_retval()); + return true; +} +static bool spi_msg__get_word_delay_us(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + spi_msg_t* self = py_touserdata(argv); + py_newint(py_retval(), self->word_delay_us); + return true; +} +static bool spi_msg__set_word_delay_us(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + spi_msg_t* self = py_touserdata(argv); + if(!py_checkint(py_arg(1))) return false; + self->word_delay_us = py_toint(py_arg(1)); + py_newnone(py_retval()); + return true; +} +static py_Type register__spi_msg(py_GlobalRef mod) { + py_Type type = py_newtype("spi_msg", tp_stdc_Memory, mod, NULL); + py_newint(py_emplacedict(py_tpobject(type), py_name("size")), sizeof(spi_msg_t)); + py_bindmethod(type, "__new__", spi_msg__new__); + py_bindmethod(type, "__init__", spi_msg__init__); + py_bindproperty(type, "txbuf", spi_msg__get_txbuf, NULL); + py_bindproperty(type, "rxbuf", spi_msg__get_rxbuf, spi_msg__set_rxbuf); + py_bindproperty(type, "len", spi_msg__get_len, spi_msg__set_len); + py_bindproperty(type, "deselect", spi_msg__get_deselect, spi_msg__set_deselect); + py_bindproperty(type, "deselect_delay_us", spi_msg__get_deselect_delay_us, spi_msg__set_deselect_delay_us); + py_bindproperty(type, "word_delay_us", spi_msg__get_word_delay_us, spi_msg__set_word_delay_us); + return type; +} +static py_Type tp_user_spi_msg; static bool periphery_version__new__(int argc, py_Ref argv) { py_Type cls = py_totype(argv); py_newobject(py_retval(), cls, 0, sizeof(periphery_version_t)); @@ -709,6 +826,279 @@ static bool cfunc__gpio_errmsg(int argc, py_Ref argv) { py_newstr(py_retval(), res); return true; } +static bool cfunc__mmio_new(int argc, py_Ref argv) { + PY_CHECK_ARGC(0); + mmio_t* res = mmio_new(); + py_newint(py_retval(), (py_i64)res); + return true; +} +static bool cfunc__mmio_open(int argc, py_Ref argv) { + PY_CHECK_ARGC(3); + mmio_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (mmio_t*)py_toint(py_arg(0)); + uintptr_t _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + size_t _2; + if(!py_checkint(py_arg(2))) return false; + _2 = py_toint(py_arg(2)); + int res = mmio_open(_0, _1, _2); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__mmio_open_advanced(int argc, py_Ref argv) { + PY_CHECK_ARGC(4); + mmio_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (mmio_t*)py_toint(py_arg(0)); + uintptr_t _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + size_t _2; + if(!py_checkint(py_arg(2))) return false; + _2 = py_toint(py_arg(2)); + const char* _3; + if(!py_checkstr(py_arg(3))) return false; + _3 = py_tostr(py_arg(3)); + int res = mmio_open_advanced(_0, _1, _2, _3); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__mmio_ptr(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + mmio_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (mmio_t*)py_toint(py_arg(0)); + void* res = mmio_ptr(_0); + py_newint(py_retval(), (py_i64)res); + return true; +} +static bool cfunc__mmio_read64(int argc, py_Ref argv) { + PY_CHECK_ARGC(3); + mmio_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (mmio_t*)py_toint(py_arg(0)); + uintptr_t _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + uint64_t* _2; + if(!py_checkint(py_arg(2))) return false; + _2 = (uint64_t*)py_toint(py_arg(2)); + int res = mmio_read64(_0, _1, _2); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__mmio_read32(int argc, py_Ref argv) { + PY_CHECK_ARGC(3); + mmio_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (mmio_t*)py_toint(py_arg(0)); + uintptr_t _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + uint32_t* _2; + if(!py_checkint(py_arg(2))) return false; + _2 = (uint32_t*)py_toint(py_arg(2)); + int res = mmio_read32(_0, _1, _2); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__mmio_read16(int argc, py_Ref argv) { + PY_CHECK_ARGC(3); + mmio_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (mmio_t*)py_toint(py_arg(0)); + uintptr_t _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + uint16_t* _2; + if(!py_checkint(py_arg(2))) return false; + _2 = (uint16_t*)py_toint(py_arg(2)); + int res = mmio_read16(_0, _1, _2); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__mmio_read8(int argc, py_Ref argv) { + PY_CHECK_ARGC(3); + mmio_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (mmio_t*)py_toint(py_arg(0)); + uintptr_t _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + uint8_t* _2; + if(!py_checkint(py_arg(2))) return false; + _2 = (uint8_t*)py_toint(py_arg(2)); + int res = mmio_read8(_0, _1, _2); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__mmio_read(int argc, py_Ref argv) { + PY_CHECK_ARGC(4); + mmio_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (mmio_t*)py_toint(py_arg(0)); + uintptr_t _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + uint8_t* _2; + if(!py_checkint(py_arg(2))) return false; + _2 = (uint8_t*)py_toint(py_arg(2)); + size_t _3; + if(!py_checkint(py_arg(3))) return false; + _3 = py_toint(py_arg(3)); + int res = mmio_read(_0, _1, _2, _3); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__mmio_write64(int argc, py_Ref argv) { + PY_CHECK_ARGC(3); + mmio_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (mmio_t*)py_toint(py_arg(0)); + uintptr_t _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + uint64_t _2; + if(!py_checkint(py_arg(2))) return false; + _2 = py_toint(py_arg(2)); + int res = mmio_write64(_0, _1, _2); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__mmio_write32(int argc, py_Ref argv) { + PY_CHECK_ARGC(3); + mmio_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (mmio_t*)py_toint(py_arg(0)); + uintptr_t _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + uint32_t _2; + if(!py_checkint(py_arg(2))) return false; + _2 = py_toint(py_arg(2)); + int res = mmio_write32(_0, _1, _2); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__mmio_write16(int argc, py_Ref argv) { + PY_CHECK_ARGC(3); + mmio_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (mmio_t*)py_toint(py_arg(0)); + uintptr_t _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + uint16_t _2; + if(!py_checkint(py_arg(2))) return false; + _2 = py_toint(py_arg(2)); + int res = mmio_write16(_0, _1, _2); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__mmio_write8(int argc, py_Ref argv) { + PY_CHECK_ARGC(3); + mmio_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (mmio_t*)py_toint(py_arg(0)); + uintptr_t _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + uint8_t _2; + if(!py_checkint(py_arg(2))) return false; + _2 = py_toint(py_arg(2)); + int res = mmio_write8(_0, _1, _2); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__mmio_write(int argc, py_Ref argv) { + PY_CHECK_ARGC(4); + mmio_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (mmio_t*)py_toint(py_arg(0)); + uintptr_t _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + const uint8_t* _2; + if(!py_checkint(py_arg(2))) return false; + _2 = (const uint8_t*)py_toint(py_arg(2)); + size_t _3; + if(!py_checkint(py_arg(3))) return false; + _3 = py_toint(py_arg(3)); + int res = mmio_write(_0, _1, _2, _3); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__mmio_close(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + mmio_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (mmio_t*)py_toint(py_arg(0)); + int res = mmio_close(_0); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__mmio_free(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + mmio_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (mmio_t*)py_toint(py_arg(0)); + mmio_free(_0); + py_newnone(py_retval()); + return true; +} +static bool cfunc__mmio_base(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + mmio_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (mmio_t*)py_toint(py_arg(0)); + uintptr_t res = mmio_base(_0); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__mmio_size(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + mmio_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (mmio_t*)py_toint(py_arg(0)); + size_t res = mmio_size(_0); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__mmio_tostring(int argc, py_Ref argv) { + PY_CHECK_ARGC(3); + mmio_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (mmio_t*)py_toint(py_arg(0)); + char* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (char*)py_toint(py_arg(1)); + size_t _2; + if(!py_checkint(py_arg(2))) return false; + _2 = py_toint(py_arg(2)); + int res = mmio_tostring(_0, _1, _2); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__mmio_errno(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + mmio_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (mmio_t*)py_toint(py_arg(0)); + int res = mmio_errno(_0); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__mmio_errmsg(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + mmio_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (mmio_t*)py_toint(py_arg(0)); + const char* res = mmio_errmsg(_0); + py_newstr(py_retval(), res); + return true; +} static bool cfunc__pwm_new(int argc, py_Ref argv) { PY_CHECK_ARGC(0); pwm_t* res = pwm_new(); @@ -982,6 +1372,703 @@ static bool cfunc__pwm_errmsg(int argc, py_Ref argv) { py_newstr(py_retval(), res); return true; } +static bool cfunc__serial_new(int argc, py_Ref argv) { + PY_CHECK_ARGC(0); + serial_t* res = serial_new(); + py_newint(py_retval(), (py_i64)res); + return true; +} +static bool cfunc__serial_open(int argc, py_Ref argv) { + PY_CHECK_ARGC(3); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + const char* _1; + if(!py_checkstr(py_arg(1))) return false; + _1 = py_tostr(py_arg(1)); + uint32_t _2; + if(!py_checkint(py_arg(2))) return false; + _2 = py_toint(py_arg(2)); + int res = serial_open(_0, _1, _2); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_open_advanced(int argc, py_Ref argv) { + PY_CHECK_ARGC(8); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + const char* _1; + if(!py_checkstr(py_arg(1))) return false; + _1 = py_tostr(py_arg(1)); + uint32_t _2; + if(!py_checkint(py_arg(2))) return false; + _2 = py_toint(py_arg(2)); + unsigned _3; + if(!py_checkint(py_arg(3))) return false; + _3 = py_toint(py_arg(3)); + serial_parity_t _4; + if(!py_checkint(py_arg(4))) return false; + _4 = (serial_parity_t)py_toint(py_arg(4)); + unsigned _5; + if(!py_checkint(py_arg(5))) return false; + _5 = py_toint(py_arg(5)); + bool _6; + if(!py_checkbool(py_arg(6))) return false; + _6 = py_tobool(py_arg(6)); + bool _7; + if(!py_checkbool(py_arg(7))) return false; + _7 = py_tobool(py_arg(7)); + int res = serial_open_advanced(_0, _1, _2, _3, _4, _5, _6, _7); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_read(int argc, py_Ref argv) { + PY_CHECK_ARGC(4); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + uint8_t* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (uint8_t*)py_toint(py_arg(1)); + size_t _2; + if(!py_checkint(py_arg(2))) return false; + _2 = py_toint(py_arg(2)); + int _3; + if(!py_checkint(py_arg(3))) return false; + _3 = py_toint(py_arg(3)); + int res = serial_read(_0, _1, _2, _3); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_write(int argc, py_Ref argv) { + PY_CHECK_ARGC(3); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + const uint8_t* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (const uint8_t*)py_toint(py_arg(1)); + size_t _2; + if(!py_checkint(py_arg(2))) return false; + _2 = py_toint(py_arg(2)); + int res = serial_write(_0, _1, _2); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_flush(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + int res = serial_flush(_0); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_input_waiting(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + unsigned* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (unsigned*)py_toint(py_arg(1)); + int res = serial_input_waiting(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_output_waiting(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + unsigned* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (unsigned*)py_toint(py_arg(1)); + int res = serial_output_waiting(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_poll(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + int _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + int res = serial_poll(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_close(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + int res = serial_close(_0); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_free(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + serial_free(_0); + py_newnone(py_retval()); + return true; +} +static bool cfunc__serial_get_baudrate(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + uint32_t* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (uint32_t*)py_toint(py_arg(1)); + int res = serial_get_baudrate(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_get_databits(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + unsigned* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (unsigned*)py_toint(py_arg(1)); + int res = serial_get_databits(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_get_parity(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(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_get_parity(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_get_stopbits(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + unsigned* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (unsigned*)py_toint(py_arg(1)); + int res = serial_get_stopbits(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_get_xonxoff(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + bool* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (bool*)py_toint(py_arg(1)); + int res = serial_get_xonxoff(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_get_rtscts(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + bool* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (bool*)py_toint(py_arg(1)); + int res = serial_get_rtscts(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_get_vmin(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + unsigned* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (unsigned*)py_toint(py_arg(1)); + int res = serial_get_vmin(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_get_vtime(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + float* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (float*)py_toint(py_arg(1)); + int res = serial_get_vtime(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_set_baudrate(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + uint32_t _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + int res = serial_set_baudrate(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_set_databits(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + unsigned _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + int res = serial_set_databits(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_set_parity(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + 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); + int res = serial_set_parity(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_set_stopbits(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + unsigned _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + int res = serial_set_stopbits(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_set_xonxoff(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + bool _1; + if(!py_checkbool(py_arg(1))) return false; + _1 = py_tobool(py_arg(1)); + int res = serial_set_xonxoff(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_set_rtscts(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + bool _1; + if(!py_checkbool(py_arg(1))) return false; + _1 = py_tobool(py_arg(1)); + int res = serial_set_rtscts(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_set_vmin(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + unsigned _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + int res = serial_set_vmin(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_set_vtime(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + float _1; + if(!py_castfloat32(py_arg(1), &_1)) return false; + int res = serial_set_vtime(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_fd(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + int res = serial_fd(_0); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_tostring(int argc, py_Ref argv) { + PY_CHECK_ARGC(3); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + char* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (char*)py_toint(py_arg(1)); + size_t _2; + if(!py_checkint(py_arg(2))) return false; + _2 = py_toint(py_arg(2)); + int res = serial_tostring(_0, _1, _2); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_errno(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + int res = serial_errno(_0); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__serial_errmsg(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + serial_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (serial_t*)py_toint(py_arg(0)); + const char* res = serial_errmsg(_0); + py_newstr(py_retval(), res); + return true; +} +static bool cfunc__spi_new(int argc, py_Ref argv) { + PY_CHECK_ARGC(0); + spi_t* res = spi_new(); + py_newint(py_retval(), (py_i64)res); + return true; +} +static bool cfunc__spi_open(int argc, py_Ref argv) { + PY_CHECK_ARGC(4); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + const char* _1; + if(!py_checkstr(py_arg(1))) return false; + _1 = py_tostr(py_arg(1)); + unsigned _2; + if(!py_checkint(py_arg(2))) return false; + _2 = py_toint(py_arg(2)); + uint32_t _3; + if(!py_checkint(py_arg(3))) return false; + _3 = py_toint(py_arg(3)); + int res = spi_open(_0, _1, _2, _3); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__spi_open_advanced(int argc, py_Ref argv) { + PY_CHECK_ARGC(7); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + const char* _1; + if(!py_checkstr(py_arg(1))) return false; + _1 = py_tostr(py_arg(1)); + unsigned _2; + if(!py_checkint(py_arg(2))) return false; + _2 = py_toint(py_arg(2)); + uint32_t _3; + if(!py_checkint(py_arg(3))) return false; + _3 = py_toint(py_arg(3)); + spi_bit_order_t _4; + if(!py_checkint(py_arg(4))) return false; + _4 = (spi_bit_order_t)py_toint(py_arg(4)); + uint8_t _5; + if(!py_checkint(py_arg(5))) return false; + _5 = py_toint(py_arg(5)); + uint8_t _6; + if(!py_checkint(py_arg(6))) return false; + _6 = py_toint(py_arg(6)); + int res = spi_open_advanced(_0, _1, _2, _3, _4, _5, _6); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__spi_open_advanced2(int argc, py_Ref argv) { + PY_CHECK_ARGC(7); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + const char* _1; + if(!py_checkstr(py_arg(1))) return false; + _1 = py_tostr(py_arg(1)); + unsigned _2; + if(!py_checkint(py_arg(2))) return false; + _2 = py_toint(py_arg(2)); + uint32_t _3; + if(!py_checkint(py_arg(3))) return false; + _3 = py_toint(py_arg(3)); + spi_bit_order_t _4; + if(!py_checkint(py_arg(4))) return false; + _4 = (spi_bit_order_t)py_toint(py_arg(4)); + uint8_t _5; + if(!py_checkint(py_arg(5))) return false; + _5 = py_toint(py_arg(5)); + uint32_t _6; + if(!py_checkint(py_arg(6))) return false; + _6 = py_toint(py_arg(6)); + int res = spi_open_advanced2(_0, _1, _2, _3, _4, _5, _6); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__spi_transfer(int argc, py_Ref argv) { + PY_CHECK_ARGC(4); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + const uint8_t* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (const uint8_t*)py_toint(py_arg(1)); + uint8_t* _2; + if(!py_checkint(py_arg(2))) return false; + _2 = (uint8_t*)py_toint(py_arg(2)); + size_t _3; + if(!py_checkint(py_arg(3))) return false; + _3 = py_toint(py_arg(3)); + int res = spi_transfer(_0, _1, _2, _3); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__spi_transfer_advanced(int argc, py_Ref argv) { + PY_CHECK_ARGC(3); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + const spi_msg_t* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (const spi_msg_t*)py_toint(py_arg(1)); + size_t _2; + if(!py_checkint(py_arg(2))) return false; + _2 = py_toint(py_arg(2)); + int res = spi_transfer_advanced(_0, _1, _2); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__spi_close(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + int res = spi_close(_0); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__spi_free(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + spi_free(_0); + py_newnone(py_retval()); + return true; +} +static bool cfunc__spi_get_mode(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + unsigned* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (unsigned*)py_toint(py_arg(1)); + int res = spi_get_mode(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__spi_get_max_speed(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + uint32_t* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (uint32_t*)py_toint(py_arg(1)); + int res = spi_get_max_speed(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__spi_get_bit_order(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + spi_bit_order_t* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (spi_bit_order_t*)py_toint(py_arg(1)); + int res = spi_get_bit_order(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__spi_get_bits_per_word(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + uint8_t* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (uint8_t*)py_toint(py_arg(1)); + int res = spi_get_bits_per_word(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__spi_get_extra_flags(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + uint8_t* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (uint8_t*)py_toint(py_arg(1)); + int res = spi_get_extra_flags(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__spi_get_extra_flags32(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + uint32_t* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (uint32_t*)py_toint(py_arg(1)); + int res = spi_get_extra_flags32(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__spi_set_mode(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + unsigned _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + int res = spi_set_mode(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__spi_set_max_speed(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + uint32_t _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + int res = spi_set_max_speed(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__spi_set_bit_order(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + spi_bit_order_t _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (spi_bit_order_t)py_toint(py_arg(1)); + int res = spi_set_bit_order(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__spi_set_bits_per_word(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + uint8_t _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + int res = spi_set_bits_per_word(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__spi_set_extra_flags(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + uint8_t _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + int res = spi_set_extra_flags(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__spi_set_extra_flags32(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + uint32_t _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + int res = spi_set_extra_flags32(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__spi_fd(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + int res = spi_fd(_0); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__spi_tostring(int argc, py_Ref argv) { + PY_CHECK_ARGC(3); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + char* _1; + if(!py_checkint(py_arg(1))) return false; + _1 = (char*)py_toint(py_arg(1)); + size_t _2; + if(!py_checkint(py_arg(2))) return false; + _2 = py_toint(py_arg(2)); + int res = spi_tostring(_0, _1, _2); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__spi_errno(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + int res = spi_errno(_0); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__spi_errmsg(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + spi_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (spi_t*)py_toint(py_arg(0)); + const char* res = spi_errmsg(_0); + py_newstr(py_retval(), res); + return true; +} static bool cfunc__periphery_version(int argc, py_Ref argv) { PY_CHECK_ARGC(0); const char* res = periphery_version(); @@ -998,6 +2085,7 @@ void py__add_module_periphery() { py_GlobalRef mod = py_newmodule("periphery"); /* structs */ tp_user_gpio_config = register__gpio_config(mod); + tp_user_spi_msg = register__spi_msg(mod); tp_user_periphery_version = register__periphery_version(mod); /* aliases */ py_setdict(mod, py_name("gpio_direction_t"), py_tpobject(tp_int)); @@ -1006,6 +2094,8 @@ void py__add_module_periphery() { py_setdict(mod, py_name("gpio_bias_t"), py_tpobject(tp_int)); py_setdict(mod, py_name("gpio_drive_t"), py_tpobject(tp_int)); py_setdict(mod, py_name("pwm_polarity_t"), py_tpobject(tp_int)); + py_setdict(mod, py_name("serial_parity_t"), py_tpobject(tp_int)); + py_setdict(mod, py_name("spi_bit_order_t"), py_tpobject(tp_int)); /* functions */ py_bindfunc(mod, "gpio_new", &cfunc__gpio_new); py_bindfunc(mod, "gpio_open", &cfunc__gpio_open); @@ -1044,6 +2134,27 @@ void py__add_module_periphery() { py_bindfunc(mod, "gpio_tostring", &cfunc__gpio_tostring); py_bindfunc(mod, "gpio_errno", &cfunc__gpio_errno); py_bindfunc(mod, "gpio_errmsg", &cfunc__gpio_errmsg); + py_bindfunc(mod, "mmio_new", &cfunc__mmio_new); + py_bindfunc(mod, "mmio_open", &cfunc__mmio_open); + py_bindfunc(mod, "mmio_open_advanced", &cfunc__mmio_open_advanced); + py_bindfunc(mod, "mmio_ptr", &cfunc__mmio_ptr); + py_bindfunc(mod, "mmio_read64", &cfunc__mmio_read64); + py_bindfunc(mod, "mmio_read32", &cfunc__mmio_read32); + py_bindfunc(mod, "mmio_read16", &cfunc__mmio_read16); + py_bindfunc(mod, "mmio_read8", &cfunc__mmio_read8); + py_bindfunc(mod, "mmio_read", &cfunc__mmio_read); + py_bindfunc(mod, "mmio_write64", &cfunc__mmio_write64); + py_bindfunc(mod, "mmio_write32", &cfunc__mmio_write32); + py_bindfunc(mod, "mmio_write16", &cfunc__mmio_write16); + py_bindfunc(mod, "mmio_write8", &cfunc__mmio_write8); + py_bindfunc(mod, "mmio_write", &cfunc__mmio_write); + py_bindfunc(mod, "mmio_close", &cfunc__mmio_close); + py_bindfunc(mod, "mmio_free", &cfunc__mmio_free); + py_bindfunc(mod, "mmio_base", &cfunc__mmio_base); + py_bindfunc(mod, "mmio_size", &cfunc__mmio_size); + py_bindfunc(mod, "mmio_tostring", &cfunc__mmio_tostring); + py_bindfunc(mod, "mmio_errno", &cfunc__mmio_errno); + py_bindfunc(mod, "mmio_errmsg", &cfunc__mmio_errmsg); py_bindfunc(mod, "pwm_new", &cfunc__pwm_new); py_bindfunc(mod, "pwm_open", &cfunc__pwm_open); py_bindfunc(mod, "pwm_enable", &cfunc__pwm_enable); @@ -1069,6 +2180,61 @@ void py__add_module_periphery() { py_bindfunc(mod, "pwm_tostring", &cfunc__pwm_tostring); py_bindfunc(mod, "pwm_errno", &cfunc__pwm_errno); py_bindfunc(mod, "pwm_errmsg", &cfunc__pwm_errmsg); + py_bindfunc(mod, "serial_new", &cfunc__serial_new); + py_bindfunc(mod, "serial_open", &cfunc__serial_open); + py_bindfunc(mod, "serial_open_advanced", &cfunc__serial_open_advanced); + py_bindfunc(mod, "serial_read", &cfunc__serial_read); + py_bindfunc(mod, "serial_write", &cfunc__serial_write); + py_bindfunc(mod, "serial_flush", &cfunc__serial_flush); + py_bindfunc(mod, "serial_input_waiting", &cfunc__serial_input_waiting); + py_bindfunc(mod, "serial_output_waiting", &cfunc__serial_output_waiting); + py_bindfunc(mod, "serial_poll", &cfunc__serial_poll); + py_bindfunc(mod, "serial_close", &cfunc__serial_close); + py_bindfunc(mod, "serial_free", &cfunc__serial_free); + py_bindfunc(mod, "serial_get_baudrate", &cfunc__serial_get_baudrate); + py_bindfunc(mod, "serial_get_databits", &cfunc__serial_get_databits); + py_bindfunc(mod, "serial_get_parity", &cfunc__serial_get_parity); + py_bindfunc(mod, "serial_get_stopbits", &cfunc__serial_get_stopbits); + py_bindfunc(mod, "serial_get_xonxoff", &cfunc__serial_get_xonxoff); + py_bindfunc(mod, "serial_get_rtscts", &cfunc__serial_get_rtscts); + py_bindfunc(mod, "serial_get_vmin", &cfunc__serial_get_vmin); + py_bindfunc(mod, "serial_get_vtime", &cfunc__serial_get_vtime); + py_bindfunc(mod, "serial_set_baudrate", &cfunc__serial_set_baudrate); + py_bindfunc(mod, "serial_set_databits", &cfunc__serial_set_databits); + py_bindfunc(mod, "serial_set_parity", &cfunc__serial_set_parity); + py_bindfunc(mod, "serial_set_stopbits", &cfunc__serial_set_stopbits); + py_bindfunc(mod, "serial_set_xonxoff", &cfunc__serial_set_xonxoff); + py_bindfunc(mod, "serial_set_rtscts", &cfunc__serial_set_rtscts); + py_bindfunc(mod, "serial_set_vmin", &cfunc__serial_set_vmin); + py_bindfunc(mod, "serial_set_vtime", &cfunc__serial_set_vtime); + py_bindfunc(mod, "serial_fd", &cfunc__serial_fd); + py_bindfunc(mod, "serial_tostring", &cfunc__serial_tostring); + py_bindfunc(mod, "serial_errno", &cfunc__serial_errno); + py_bindfunc(mod, "serial_errmsg", &cfunc__serial_errmsg); + py_bindfunc(mod, "spi_new", &cfunc__spi_new); + py_bindfunc(mod, "spi_open", &cfunc__spi_open); + py_bindfunc(mod, "spi_open_advanced", &cfunc__spi_open_advanced); + py_bindfunc(mod, "spi_open_advanced2", &cfunc__spi_open_advanced2); + py_bindfunc(mod, "spi_transfer", &cfunc__spi_transfer); + py_bindfunc(mod, "spi_transfer_advanced", &cfunc__spi_transfer_advanced); + py_bindfunc(mod, "spi_close", &cfunc__spi_close); + py_bindfunc(mod, "spi_free", &cfunc__spi_free); + py_bindfunc(mod, "spi_get_mode", &cfunc__spi_get_mode); + py_bindfunc(mod, "spi_get_max_speed", &cfunc__spi_get_max_speed); + py_bindfunc(mod, "spi_get_bit_order", &cfunc__spi_get_bit_order); + py_bindfunc(mod, "spi_get_bits_per_word", &cfunc__spi_get_bits_per_word); + py_bindfunc(mod, "spi_get_extra_flags", &cfunc__spi_get_extra_flags); + py_bindfunc(mod, "spi_get_extra_flags32", &cfunc__spi_get_extra_flags32); + py_bindfunc(mod, "spi_set_mode", &cfunc__spi_set_mode); + py_bindfunc(mod, "spi_set_max_speed", &cfunc__spi_set_max_speed); + py_bindfunc(mod, "spi_set_bit_order", &cfunc__spi_set_bit_order); + py_bindfunc(mod, "spi_set_bits_per_word", &cfunc__spi_set_bits_per_word); + py_bindfunc(mod, "spi_set_extra_flags", &cfunc__spi_set_extra_flags); + py_bindfunc(mod, "spi_set_extra_flags32", &cfunc__spi_set_extra_flags32); + py_bindfunc(mod, "spi_fd", &cfunc__spi_fd); + py_bindfunc(mod, "spi_tostring", &cfunc__spi_tostring); + py_bindfunc(mod, "spi_errno", &cfunc__spi_errno); + py_bindfunc(mod, "spi_errmsg", &cfunc__spi_errmsg); py_bindfunc(mod, "periphery_version", &cfunc__periphery_version); py_bindfunc(mod, "periphery_version_info", &cfunc__periphery_version_info); /* enums */ @@ -1099,6 +2265,9 @@ void py__add_module_periphery() { ADD_ENUM(GPIO_DRIVE_DEFAULT); ADD_ENUM(GPIO_DRIVE_OPEN_DRAIN); ADD_ENUM(GPIO_DRIVE_OPEN_SOURCE); + ADD_ENUM(MMIO_ERROR_ARG); + ADD_ENUM(MMIO_ERROR_OPEN); + ADD_ENUM(MMIO_ERROR_CLOSE); ADD_ENUM(PWM_ERROR_ARG); ADD_ENUM(PWM_ERROR_OPEN); ADD_ENUM(PWM_ERROR_QUERY); @@ -1106,4 +2275,22 @@ void py__add_module_periphery() { ADD_ENUM(PWM_ERROR_CLOSE); ADD_ENUM(PWM_POLARITY_NORMAL); ADD_ENUM(PWM_POLARITY_INVERSED); + ADD_ENUM(SERIAL_ERROR_ARG); + ADD_ENUM(SERIAL_ERROR_OPEN); + ADD_ENUM(SERIAL_ERROR_QUERY); + ADD_ENUM(SERIAL_ERROR_CONFIGURE); + ADD_ENUM(SERIAL_ERROR_IO); + ADD_ENUM(SERIAL_ERROR_CLOSE); + ADD_ENUM(PARITY_NONE); + ADD_ENUM(PARITY_ODD); + ADD_ENUM(PARITY_EVEN); + ADD_ENUM(SPI_ERROR_ARG); + ADD_ENUM(SPI_ERROR_OPEN); + ADD_ENUM(SPI_ERROR_QUERY); + ADD_ENUM(SPI_ERROR_CONFIGURE); + ADD_ENUM(SPI_ERROR_TRANSFER); + ADD_ENUM(SPI_ERROR_CLOSE); + ADD_ENUM(SPI_ERROR_UNSUPPORTED); + ADD_ENUM(MSB_FIRST); + ADD_ENUM(LSB_FIRST); } \ No newline at end of file diff --git a/ffigen/ffigen/meta/parser.py b/ffigen/ffigen/meta/parser.py index 6456f5e8..cd69c3fc 100644 --- a/ffigen/ffigen/meta/parser.py +++ b/ffigen/ffigen/meta/parser.py @@ -17,6 +17,7 @@ class Header: 'size_t', 'bool', 'int8_t', 'int16_t', 'int32_t', 'int64_t', 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', + 'intptr_t', 'uintptr_t', } self.functions = [] # type: list[Function] diff --git a/ffigen/libc_include/stdint.h b/ffigen/libc_include/stdint.h index 1fe3c9b4..846a10e1 100644 --- a/ffigen/libc_include/stdint.h +++ b/ffigen/libc_include/stdint.h @@ -6,4 +6,4 @@ typedef int int64_t; typedef unsigned uint8_t; typedef unsigned uint16_t; typedef unsigned uint32_t; -typedef unsigned uint64_t; \ No newline at end of file +typedef unsigned uint64_t; diff --git a/ffigen/libc_include/sys/types.h b/ffigen/libc_include/sys/types.h new file mode 100644 index 00000000..d64e705c --- /dev/null +++ b/ffigen/libc_include/sys/types.h @@ -0,0 +1,2 @@ +typedef int intptr_t; +typedef unsigned uintptr_t; \ No newline at end of file diff --git a/include/typings/periphery.pyi b/include/typings/periphery.pyi index acb6c1c2..d967056c 100644 --- a/include/typings/periphery.pyi +++ b/include/typings/periphery.pyi @@ -16,6 +16,19 @@ class gpio_config: @overload def __init__(self, direction: int, edge: int, event_clock: int, debounce_us: int, bias: int, drive: int, inverted: bool, label: str): ... +class spi_msg: + txbuf: intptr # (const uint8_t*) + rxbuf: intptr # (uint8_t*) + len: int # (size_t) + deselect: bool # (bool) + deselect_delay_us: int # (uint16_t) + word_delay_us: int # (uint8_t) + + @overload + def __init__(self): ... + @overload + def __init__(self, txbuf: intptr, rxbuf: intptr, len: int, deselect: bool, deselect_delay_us: int, word_delay_us: int): ... + class periphery_version: major: int # (unsigned) minor: int # (unsigned) @@ -138,6 +151,69 @@ def gpio_errno(gpio: intptr, /) -> int: def gpio_errmsg(gpio: intptr, /) -> str: """Wraps `const char* gpio_errmsg(gpio_t* gpio)`""" +def mmio_new() -> intptr: + """Wraps `mmio_t* mmio_new()`""" + +def mmio_open(mmio: intptr, base: int, size: int, /) -> int: + """Wraps `int mmio_open(mmio_t* mmio, uintptr_t base, size_t size)`""" + +def mmio_open_advanced(mmio: intptr, base: int, size: int, path: str, /) -> int: + """Wraps `int mmio_open_advanced(mmio_t* mmio, uintptr_t base, size_t size, const char* path)`""" + +def mmio_ptr(mmio: intptr, /) -> intptr: + """Wraps `void* mmio_ptr(mmio_t* mmio)`""" + +def mmio_read64(mmio: intptr, offset: int, value: intptr, /) -> int: + """Wraps `int mmio_read64(mmio_t* mmio, uintptr_t offset, uint64_t* value)`""" + +def mmio_read32(mmio: intptr, offset: int, value: intptr, /) -> int: + """Wraps `int mmio_read32(mmio_t* mmio, uintptr_t offset, uint32_t* value)`""" + +def mmio_read16(mmio: intptr, offset: int, value: intptr, /) -> int: + """Wraps `int mmio_read16(mmio_t* mmio, uintptr_t offset, uint16_t* value)`""" + +def mmio_read8(mmio: intptr, offset: int, value: intptr, /) -> int: + """Wraps `int mmio_read8(mmio_t* mmio, uintptr_t offset, uint8_t* value)`""" + +def mmio_read(mmio: intptr, offset: int, buf: intptr, len: int, /) -> int: + """Wraps `int mmio_read(mmio_t* mmio, uintptr_t offset, uint8_t* buf, size_t len)`""" + +def mmio_write64(mmio: intptr, offset: int, value: int, /) -> int: + """Wraps `int mmio_write64(mmio_t* mmio, uintptr_t offset, uint64_t value)`""" + +def mmio_write32(mmio: intptr, offset: int, value: int, /) -> int: + """Wraps `int mmio_write32(mmio_t* mmio, uintptr_t offset, uint32_t value)`""" + +def mmio_write16(mmio: intptr, offset: int, value: int, /) -> int: + """Wraps `int mmio_write16(mmio_t* mmio, uintptr_t offset, uint16_t value)`""" + +def mmio_write8(mmio: intptr, offset: int, value: int, /) -> int: + """Wraps `int mmio_write8(mmio_t* mmio, uintptr_t offset, uint8_t value)`""" + +def mmio_write(mmio: intptr, offset: int, buf: intptr, len: int, /) -> int: + """Wraps `int mmio_write(mmio_t* mmio, uintptr_t offset, const uint8_t* buf, size_t len)`""" + +def mmio_close(mmio: intptr, /) -> int: + """Wraps `int mmio_close(mmio_t* mmio)`""" + +def mmio_free(mmio: intptr, /) -> None: + """Wraps `void mmio_free(mmio_t* mmio)`""" + +def mmio_base(mmio: intptr, /) -> int: + """Wraps `uintptr_t mmio_base(mmio_t* mmio)`""" + +def mmio_size(mmio: intptr, /) -> int: + """Wraps `size_t mmio_size(mmio_t* mmio)`""" + +def mmio_tostring(mmio: intptr, str: intptr, len: int, /) -> int: + """Wraps `int mmio_tostring(mmio_t* mmio, char* str, size_t len)`""" + +def mmio_errno(mmio: intptr, /) -> int: + """Wraps `int mmio_errno(mmio_t* mmio)`""" + +def mmio_errmsg(mmio: intptr, /) -> str: + """Wraps `const char* mmio_errmsg(mmio_t* mmio)`""" + def pwm_new() -> intptr: """Wraps `pwm_t* pwm_new()`""" @@ -213,6 +289,171 @@ def pwm_errno(pwm: intptr, /) -> int: def pwm_errmsg(pwm: intptr, /) -> str: """Wraps `const char* pwm_errmsg(pwm_t* pwm)`""" +def serial_new() -> intptr: + """Wraps `serial_t* serial_new()`""" + +def serial_open(serial: intptr, path: str, baudrate: int, /) -> int: + """Wraps `int serial_open(serial_t* serial, const char* path, uint32_t baudrate)`""" + +def serial_open_advanced(serial: intptr, path: str, baudrate: int, databits: int, parity: int, stopbits: int, xonxoff: bool, rtscts: bool, /) -> int: + """Wraps `int serial_open_advanced(serial_t* serial, const char* path, uint32_t baudrate, unsigned databits, serial_parity_t parity, unsigned stopbits, bool xonxoff, bool rtscts)`""" + +def serial_read(serial: intptr, buf: intptr, len: int, timeout_ms: int, /) -> int: + """Wraps `int serial_read(serial_t* serial, uint8_t* buf, size_t len, int timeout_ms)`""" + +def serial_write(serial: intptr, buf: intptr, len: int, /) -> int: + """Wraps `int serial_write(serial_t* serial, const uint8_t* buf, size_t len)`""" + +def serial_flush(serial: intptr, /) -> int: + """Wraps `int serial_flush(serial_t* serial)`""" + +def serial_input_waiting(serial: intptr, count: intptr, /) -> int: + """Wraps `int serial_input_waiting(serial_t* serial, unsigned* count)`""" + +def serial_output_waiting(serial: intptr, count: intptr, /) -> int: + """Wraps `int serial_output_waiting(serial_t* serial, unsigned* count)`""" + +def serial_poll(serial: intptr, timeout_ms: int, /) -> int: + """Wraps `int serial_poll(serial_t* serial, int timeout_ms)`""" + +def serial_close(serial: intptr, /) -> int: + """Wraps `int serial_close(serial_t* serial)`""" + +def serial_free(serial: intptr, /) -> None: + """Wraps `void serial_free(serial_t* serial)`""" + +def serial_get_baudrate(serial: intptr, baudrate: intptr, /) -> int: + """Wraps `int serial_get_baudrate(serial_t* serial, uint32_t* baudrate)`""" + +def serial_get_databits(serial: intptr, databits: intptr, /) -> int: + """Wraps `int serial_get_databits(serial_t* serial, unsigned* databits)`""" + +def serial_get_parity(serial: intptr, parity: intptr, /) -> int: + """Wraps `int serial_get_parity(serial_t* serial, serial_parity_t* parity)`""" + +def serial_get_stopbits(serial: intptr, stopbits: intptr, /) -> int: + """Wraps `int serial_get_stopbits(serial_t* serial, unsigned* stopbits)`""" + +def serial_get_xonxoff(serial: intptr, xonxoff: intptr, /) -> int: + """Wraps `int serial_get_xonxoff(serial_t* serial, bool* xonxoff)`""" + +def serial_get_rtscts(serial: intptr, rtscts: intptr, /) -> int: + """Wraps `int serial_get_rtscts(serial_t* serial, bool* rtscts)`""" + +def serial_get_vmin(serial: intptr, vmin: intptr, /) -> int: + """Wraps `int serial_get_vmin(serial_t* serial, unsigned* vmin)`""" + +def serial_get_vtime(serial: intptr, vtime: intptr, /) -> int: + """Wraps `int serial_get_vtime(serial_t* serial, float* vtime)`""" + +def serial_set_baudrate(serial: intptr, baudrate: int, /) -> int: + """Wraps `int serial_set_baudrate(serial_t* serial, uint32_t baudrate)`""" + +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_stopbits(serial: intptr, stopbits: int, /) -> int: + """Wraps `int serial_set_stopbits(serial_t* serial, unsigned stopbits)`""" + +def serial_set_xonxoff(serial: intptr, enabled: bool, /) -> int: + """Wraps `int serial_set_xonxoff(serial_t* serial, bool enabled)`""" + +def serial_set_rtscts(serial: intptr, enabled: bool, /) -> int: + """Wraps `int serial_set_rtscts(serial_t* serial, bool enabled)`""" + +def serial_set_vmin(serial: intptr, vmin: int, /) -> int: + """Wraps `int serial_set_vmin(serial_t* serial, unsigned vmin)`""" + +def serial_set_vtime(serial: intptr, vtime: float, /) -> int: + """Wraps `int serial_set_vtime(serial_t* serial, float vtime)`""" + +def serial_fd(serial: intptr, /) -> int: + """Wraps `int serial_fd(serial_t* serial)`""" + +def serial_tostring(serial: intptr, str: intptr, len: int, /) -> int: + """Wraps `int serial_tostring(serial_t* serial, char* str, size_t len)`""" + +def serial_errno(serial: intptr, /) -> int: + """Wraps `int serial_errno(serial_t* serial)`""" + +def serial_errmsg(serial: intptr, /) -> str: + """Wraps `const char* serial_errmsg(serial_t* serial)`""" + +def spi_new() -> intptr: + """Wraps `spi_t* spi_new()`""" + +def spi_open(spi: intptr, path: str, mode: int, max_speed: int, /) -> int: + """Wraps `int spi_open(spi_t* spi, const char* path, unsigned mode, uint32_t max_speed)`""" + +def spi_open_advanced(spi: intptr, path: str, mode: int, max_speed: int, bit_order: int, bits_per_word: int, extra_flags: int, /) -> int: + """Wraps `int spi_open_advanced(spi_t* spi, const char* path, unsigned mode, uint32_t max_speed, spi_bit_order_t bit_order, uint8_t bits_per_word, uint8_t extra_flags)`""" + +def spi_open_advanced2(spi: intptr, path: str, mode: int, max_speed: int, bit_order: int, bits_per_word: int, extra_flags: int, /) -> int: + """Wraps `int spi_open_advanced2(spi_t* spi, const char* path, unsigned mode, uint32_t max_speed, spi_bit_order_t bit_order, uint8_t bits_per_word, uint32_t extra_flags)`""" + +def spi_transfer(spi: intptr, txbuf: intptr, rxbuf: intptr, len: int, /) -> int: + """Wraps `int spi_transfer(spi_t* spi, const uint8_t* txbuf, uint8_t* rxbuf, size_t len)`""" + +def spi_transfer_advanced(spi: intptr, msgs: intptr, count: int, /) -> int: + """Wraps `int spi_transfer_advanced(spi_t* spi, const spi_msg_t* msgs, size_t count)`""" + +def spi_close(spi: intptr, /) -> int: + """Wraps `int spi_close(spi_t* spi)`""" + +def spi_free(spi: intptr, /) -> None: + """Wraps `void spi_free(spi_t* spi)`""" + +def spi_get_mode(spi: intptr, mode: intptr, /) -> int: + """Wraps `int spi_get_mode(spi_t* spi, unsigned* mode)`""" + +def spi_get_max_speed(spi: intptr, max_speed: intptr, /) -> int: + """Wraps `int spi_get_max_speed(spi_t* spi, uint32_t* max_speed)`""" + +def spi_get_bit_order(spi: intptr, bit_order: intptr, /) -> int: + """Wraps `int spi_get_bit_order(spi_t* spi, spi_bit_order_t* bit_order)`""" + +def spi_get_bits_per_word(spi: intptr, bits_per_word: intptr, /) -> int: + """Wraps `int spi_get_bits_per_word(spi_t* spi, uint8_t* bits_per_word)`""" + +def spi_get_extra_flags(spi: intptr, extra_flags: intptr, /) -> int: + """Wraps `int spi_get_extra_flags(spi_t* spi, uint8_t* extra_flags)`""" + +def spi_get_extra_flags32(spi: intptr, extra_flags: intptr, /) -> int: + """Wraps `int spi_get_extra_flags32(spi_t* spi, uint32_t* extra_flags)`""" + +def spi_set_mode(spi: intptr, mode: int, /) -> int: + """Wraps `int spi_set_mode(spi_t* spi, unsigned mode)`""" + +def spi_set_max_speed(spi: intptr, max_speed: int, /) -> int: + """Wraps `int spi_set_max_speed(spi_t* spi, uint32_t max_speed)`""" + +def spi_set_bit_order(spi: intptr, bit_order: int, /) -> int: + """Wraps `int spi_set_bit_order(spi_t* spi, spi_bit_order_t bit_order)`""" + +def spi_set_bits_per_word(spi: intptr, bits_per_word: int, /) -> int: + """Wraps `int spi_set_bits_per_word(spi_t* spi, uint8_t bits_per_word)`""" + +def spi_set_extra_flags(spi: intptr, extra_flags: int, /) -> int: + """Wraps `int spi_set_extra_flags(spi_t* spi, uint8_t extra_flags)`""" + +def spi_set_extra_flags32(spi: intptr, extra_flags: int, /) -> int: + """Wraps `int spi_set_extra_flags32(spi_t* spi, uint32_t extra_flags)`""" + +def spi_fd(spi: intptr, /) -> int: + """Wraps `int spi_fd(spi_t* spi)`""" + +def spi_tostring(spi: intptr, str: intptr, len: int, /) -> int: + """Wraps `int spi_tostring(spi_t* spi, char* str, size_t len)`""" + +def spi_errno(spi: intptr, /) -> int: + """Wraps `int spi_errno(spi_t* spi)`""" + +def spi_errmsg(spi: intptr, /) -> str: + """Wraps `const char* spi_errmsg(spi_t* spi)`""" + def periphery_version() -> str: """Wraps `const char* periphery_version()`""" @@ -226,6 +467,8 @@ gpio_event_clock_t = int gpio_bias_t = int gpio_drive_t = int pwm_polarity_t = int +serial_parity_t = int +spi_bit_order_t = int # enums GPIO_ERROR_ARG: int GPIO_ERROR_OPEN: int @@ -254,10 +497,31 @@ GPIO_BIAS_DISABLE: int GPIO_DRIVE_DEFAULT: int GPIO_DRIVE_OPEN_DRAIN: int GPIO_DRIVE_OPEN_SOURCE: int +MMIO_ERROR_ARG: int +MMIO_ERROR_OPEN: int +MMIO_ERROR_CLOSE: int PWM_ERROR_ARG: int PWM_ERROR_OPEN: int PWM_ERROR_QUERY: int PWM_ERROR_CONFIGURE: int PWM_ERROR_CLOSE: int PWM_POLARITY_NORMAL: int -PWM_POLARITY_INVERSED: int \ No newline at end of file +PWM_POLARITY_INVERSED: int +SERIAL_ERROR_ARG: int +SERIAL_ERROR_OPEN: int +SERIAL_ERROR_QUERY: int +SERIAL_ERROR_CONFIGURE: int +SERIAL_ERROR_IO: int +SERIAL_ERROR_CLOSE: int +PARITY_NONE: int +PARITY_ODD: int +PARITY_EVEN: int +SPI_ERROR_ARG: int +SPI_ERROR_OPEN: int +SPI_ERROR_QUERY: int +SPI_ERROR_CONFIGURE: int +SPI_ERROR_TRANSFER: int +SPI_ERROR_CLOSE: int +SPI_ERROR_UNSUPPORTED: int +MSB_FIRST: int +LSB_FIRST: int \ No newline at end of file diff --git a/include/typings/stdc.pyi b/include/typings/stdc.pyi index f3515aaf..277df4a0 100644 --- a/include/typings/stdc.pyi +++ b/include/typings/stdc.pyi @@ -40,6 +40,7 @@ class UInt(_BuiltinMemory[int]): ... class Long(_BuiltinMemory[int]): ... class ULong(_BuiltinMemory[int]): ... class LongLong(_BuiltinMemory[int]): ... +class ULongLong(_BuiltinMemory[int]): ... class Float(_BuiltinMemory[float]): ... class Double(_BuiltinMemory[float]): ... @@ -56,6 +57,9 @@ Int64: _BuiltinMemory[int] UInt64: _BuiltinMemory[int] SizeT: _BuiltinMemory[int] +IntptrT: _BuiltinMemory[int] +UintptrT: _BuiltinMemory[int] + def addressof(obj: Memory) -> intptr: ... def sizeof(obj: type[Memory]) -> int: ... diff --git a/src/modules/stdc.c b/src/modules/stdc.c index 8d7bb3bd..e12b7f4d 100644 --- a/src/modules/stdc.c +++ b/src/modules/stdc.c @@ -274,6 +274,15 @@ void pk__add_module_stdc() { break; } } + if(sizeof(void*) == 4) { + py_setdict(mod, py_name("IntPtrT"), py_getdict(mod, py_name("Int32"))); + py_setdict(mod, py_name("UIntPtrT"), py_getdict(mod, py_name("UInt32"))); + } else if(sizeof(void*) == 8) { + py_setdict(mod, py_name("IntPtrT"), py_getdict(mod, py_name("Int64"))); + py_setdict(mod, py_name("UIntPtrT"), py_getdict(mod, py_name("UInt64"))); + } else { + c11__abort("unsupported pointer size"); + } pk__bind_stdc_Float(mod); pk__bind_stdc_Double(mod);