luat_lib_hwtimer.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "luat_base.h"
  2. #include "luat_hwtimer.h"
  3. static int l_hwtimer_create(lua_State* L) {
  4. luat_hwtimer_conf_t conf = {0};
  5. conf.unit = luaL_checkinteger(L, 1);
  6. conf.timeout = luaL_checkinteger(L, 2);
  7. if (!lua_isnoneornil(L, 3))
  8. conf.is_repeat = lua_toboolean(L, 3);
  9. int id = luat_hwtimer_create(&conf);
  10. lua_pushinteger(L, id);
  11. return 1;
  12. }
  13. static int l_hwtimer_start(lua_State* L) {
  14. int id = luaL_checkinteger(L, 1);
  15. int ret = luat_hwtimer_start(id);
  16. lua_pushboolean(L, ret == 0 ? 1 : 0);
  17. return 1;
  18. }
  19. static int l_hwtimer_stop(lua_State* L) {
  20. int id = luaL_checkinteger(L, 1);
  21. int ret = luat_hwtimer_stop(id);
  22. lua_pushboolean(L, ret == 0 ? 1 : 0);
  23. return 1;
  24. }
  25. static int l_hwtimer_read(lua_State* L) {
  26. int id = luaL_checkinteger(L, 1);
  27. uint32_t ret = luat_hwtimer_read(id);
  28. lua_pushinteger(L, ret);
  29. return 1;
  30. }
  31. static int l_hwtimer_change(lua_State* L) {
  32. int id = luaL_checkinteger(L, 1);
  33. uint32_t newtimeout = luaL_checkinteger(L, 2);
  34. int ret = luat_hwtimer_change(id, newtimeout);
  35. lua_pushboolean(L, ret == 0 ? 1 : 0);
  36. return 1;
  37. }
  38. static int l_hwtimer_destroy(lua_State* L) {
  39. int id = luaL_checkinteger(L, 1);
  40. uint32_t ret = luat_hwtimer_destroy(id);
  41. lua_pushinteger(L, ret);
  42. return 1;
  43. }
  44. #include "rotable.h"
  45. static const rotable_Reg reg_hwtimer[] =
  46. {
  47. { "create" , l_hwtimer_create, 0},
  48. { "start", l_hwtimer_start, 0},
  49. { "stop", l_hwtimer_stop, 0},
  50. { "read", l_hwtimer_read, 0},
  51. { "change", l_hwtimer_change, 0},
  52. { "destroy", l_hwtimer_destroy,0},
  53. { NULL, NULL , 0}
  54. };
  55. LUAMOD_API int luaopen_hwtimer( lua_State *L ) {
  56. luat_newlib(L, reg_hwtimer);
  57. return 1;
  58. }