From dd9004501a24f21545cc287022ab34624f194deb Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Thu, 18 Dec 2025 18:27:40 +0800 Subject: [PATCH] add periphery led --- 3rd/periphery/include/periphery.h | 2 +- 3rd/periphery/src/periphery.c | 223 ++++++++++++++++++++++++++++++ include/typings/periphery.pyi | 56 ++++++++ 3 files changed, 280 insertions(+), 1 deletion(-) diff --git a/3rd/periphery/include/periphery.h b/3rd/periphery/include/periphery.h index 508057a0..c8355462 100644 --- a/3rd/periphery/include/periphery.h +++ b/3rd/periphery/include/periphery.h @@ -1,6 +1,6 @@ #include "../c-periphery/src/gpio.h" // #include "../c-periphery/src/i2c.h" -// #include "../c-periphery/src/led.h" +#include "../c-periphery/src/led.h" #include "../c-periphery/src/mmio.h" #include "../c-periphery/src/pwm.h" #include "../c-periphery/src/serial.h" diff --git a/3rd/periphery/src/periphery.c b/3rd/periphery/src/periphery.c index 32f4a5d1..0bef9926 100644 --- a/3rd/periphery/src/periphery.c +++ b/3rd/periphery/src/periphery.c @@ -826,6 +826,207 @@ static bool cfunc__gpio_errmsg(int argc, py_Ref argv) { py_newstr(py_retval(), res); return true; } +static bool cfunc__led_new(int argc, py_Ref argv) { + PY_CHECK_ARGC(0); + led_t* res = led_new(); + py_newint(py_retval(), (py_i64)res); + return true; +} +static bool cfunc__led_open(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + led_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (led_t*)py_toint(py_arg(0)); + const char* _1; + if(!py_checkstr(py_arg(1))) return false; + _1 = py_tostr(py_arg(1)); + int res = led_open(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__led_read(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + led_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (led_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 = led_read(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__led_write(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + led_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (led_t*)py_toint(py_arg(0)); + bool _1; + if(!py_checkbool(py_arg(1))) return false; + _1 = py_tobool(py_arg(1)); + int res = led_write(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__led_close(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + led_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (led_t*)py_toint(py_arg(0)); + int res = led_close(_0); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__led_free(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + led_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (led_t*)py_toint(py_arg(0)); + led_free(_0); + py_newnone(py_retval()); + return true; +} +static bool cfunc__led_get_brightness(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + led_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (led_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 = led_get_brightness(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__led_get_max_brightness(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + led_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (led_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 = led_get_max_brightness(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__led_get_trigger(int argc, py_Ref argv) { + PY_CHECK_ARGC(3); + led_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (led_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 = led_get_trigger(_0, _1, _2); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__led_get_triggers_entry(int argc, py_Ref argv) { + PY_CHECK_ARGC(4); + led_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (led_t*)py_toint(py_arg(0)); + unsigned _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + char* _2; + if(!py_checkint(py_arg(2))) return false; + _2 = (char*)py_toint(py_arg(2)); + size_t _3; + if(!py_checkint(py_arg(3))) return false; + _3 = py_toint(py_arg(3)); + int res = led_get_triggers_entry(_0, _1, _2, _3); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__led_get_triggers_count(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + led_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (led_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 = led_get_triggers_count(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__led_set_brightness(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + led_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (led_t*)py_toint(py_arg(0)); + unsigned _1; + if(!py_checkint(py_arg(1))) return false; + _1 = py_toint(py_arg(1)); + int res = led_set_brightness(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__led_set_trigger(int argc, py_Ref argv) { + PY_CHECK_ARGC(2); + led_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (led_t*)py_toint(py_arg(0)); + const char* _1; + if(!py_checkstr(py_arg(1))) return false; + _1 = py_tostr(py_arg(1)); + int res = led_set_trigger(_0, _1); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__led_name(int argc, py_Ref argv) { + PY_CHECK_ARGC(3); + led_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (led_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 = led_name(_0, _1, _2); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__led_tostring(int argc, py_Ref argv) { + PY_CHECK_ARGC(3); + led_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (led_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 = led_tostring(_0, _1, _2); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__led_errno(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + led_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (led_t*)py_toint(py_arg(0)); + int res = led_errno(_0); + py_newint(py_retval(), res); + return true; +} +static bool cfunc__led_errmsg(int argc, py_Ref argv) { + PY_CHECK_ARGC(1); + led_t* _0; + if(!py_checkint(py_arg(0))) return false; + _0 = (led_t*)py_toint(py_arg(0)); + const char* res = led_errmsg(_0); + 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(); @@ -2132,6 +2333,23 @@ 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, "led_new", &cfunc__led_new); + py_bindfunc(mod, "led_open", &cfunc__led_open); + py_bindfunc(mod, "led_read", &cfunc__led_read); + py_bindfunc(mod, "led_write", &cfunc__led_write); + py_bindfunc(mod, "led_close", &cfunc__led_close); + py_bindfunc(mod, "led_free", &cfunc__led_free); + py_bindfunc(mod, "led_get_brightness", &cfunc__led_get_brightness); + py_bindfunc(mod, "led_get_max_brightness", &cfunc__led_get_max_brightness); + py_bindfunc(mod, "led_get_trigger", &cfunc__led_get_trigger); + py_bindfunc(mod, "led_get_triggers_entry", &cfunc__led_get_triggers_entry); + py_bindfunc(mod, "led_get_triggers_count", &cfunc__led_get_triggers_count); + py_bindfunc(mod, "led_set_brightness", &cfunc__led_set_brightness); + py_bindfunc(mod, "led_set_trigger", &cfunc__led_set_trigger); + py_bindfunc(mod, "led_name", &cfunc__led_name); + py_bindfunc(mod, "led_tostring", &cfunc__led_tostring); + py_bindfunc(mod, "led_errno", &cfunc__led_errno); + py_bindfunc(mod, "led_errmsg", &cfunc__led_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); @@ -2263,6 +2481,11 @@ void py__add_module_periphery() { ADD_ENUM(GPIO_DRIVE_DEFAULT); ADD_ENUM(GPIO_DRIVE_OPEN_DRAIN); ADD_ENUM(GPIO_DRIVE_OPEN_SOURCE); + ADD_ENUM(LED_ERROR_ARG); + ADD_ENUM(LED_ERROR_OPEN); + ADD_ENUM(LED_ERROR_QUERY); + ADD_ENUM(LED_ERROR_IO); + ADD_ENUM(LED_ERROR_CLOSE); ADD_ENUM(MMIO_ERROR_ARG); ADD_ENUM(MMIO_ERROR_OPEN); ADD_ENUM(MMIO_ERROR_CLOSE); diff --git a/include/typings/periphery.pyi b/include/typings/periphery.pyi index 0ae1548e..b7845f27 100644 --- a/include/typings/periphery.pyi +++ b/include/typings/periphery.pyi @@ -151,6 +151,57 @@ def gpio_errno(gpio: intptr, /) -> int: def gpio_errmsg(gpio: intptr, /) -> str: """Wraps `const char* gpio_errmsg(gpio_t* gpio)`""" +def led_new() -> intptr: + """Wraps `led_t* led_new()`""" + +def led_open(led: intptr, name: str, /) -> int: + """Wraps `int led_open(led_t* led, const char* name)`""" + +def led_read(led: intptr, value: intptr, /) -> int: + """Wraps `int led_read(led_t* led, bool* value)`""" + +def led_write(led: intptr, value: bool, /) -> int: + """Wraps `int led_write(led_t* led, bool value)`""" + +def led_close(led: intptr, /) -> int: + """Wraps `int led_close(led_t* led)`""" + +def led_free(led: intptr, /) -> None: + """Wraps `void led_free(led_t* led)`""" + +def led_get_brightness(led: intptr, brightness: intptr, /) -> int: + """Wraps `int led_get_brightness(led_t* led, unsigned* brightness)`""" + +def led_get_max_brightness(led: intptr, max_brightness: intptr, /) -> int: + """Wraps `int led_get_max_brightness(led_t* led, unsigned* max_brightness)`""" + +def led_get_trigger(led: intptr, str: intptr, len: int, /) -> int: + """Wraps `int led_get_trigger(led_t* led, char* str, size_t len)`""" + +def led_get_triggers_entry(led: intptr, index: int, str: intptr, len: int, /) -> int: + """Wraps `int led_get_triggers_entry(led_t* led, unsigned index, char* str, size_t len)`""" + +def led_get_triggers_count(led: intptr, count: intptr, /) -> int: + """Wraps `int led_get_triggers_count(led_t* led, unsigned* count)`""" + +def led_set_brightness(led: intptr, brightness: int, /) -> int: + """Wraps `int led_set_brightness(led_t* led, unsigned brightness)`""" + +def led_set_trigger(led: intptr, trigger: str, /) -> int: + """Wraps `int led_set_trigger(led_t* led, const char* trigger)`""" + +def led_name(led: intptr, str: intptr, len: int, /) -> int: + """Wraps `int led_name(led_t* led, char* str, size_t len)`""" + +def led_tostring(led: intptr, str: intptr, len: int, /) -> int: + """Wraps `int led_tostring(led_t* led, char* str, size_t len)`""" + +def led_errno(led: intptr, /) -> int: + """Wraps `int led_errno(led_t* led)`""" + +def led_errmsg(led: intptr, /) -> str: + """Wraps `const char* led_errmsg(led_t* led)`""" + def mmio_new() -> intptr: """Wraps `mmio_t* mmio_new()`""" @@ -497,6 +548,11 @@ GPIO_BIAS_DISABLE: int GPIO_DRIVE_DEFAULT: int GPIO_DRIVE_OPEN_DRAIN: int GPIO_DRIVE_OPEN_SOURCE: int +LED_ERROR_ARG: int +LED_ERROR_OPEN: int +LED_ERROR_QUERY: int +LED_ERROR_IO: int +LED_ERROR_CLOSE: int MMIO_ERROR_ARG: int MMIO_ERROR_OPEN: int MMIO_ERROR_CLOSE: int