// Lua: stop( id ) static int ICACHE_FLASH_ATTR lpwm_stop( lua_State* L ) { unsigned id; id = luaL_checkinteger( L, 1 ); MOD_CHECK_ID( pwm, id ); platform_pwm_stop( id ); return 0; }
static int lpwm_stop(lua_State* L) { int id = luaL_checkinteger(L, 1); if (!platform_pwm_exists(L, id)) { return luaL_error(L, "pwm%d does not exist", id); } if (!pwm[id - 1].configured) { return luaL_error(L, "pwm%d is not setup", id); } platform_pwm_stop(L, id); pwm[id - 1].started = 0; return 0; }
OSStatus MicoPwmStop( mico_pwm_t pwm ) { if ( pwm >= MICO_PWM_NONE ) return kUnsupportedErr; return (OSStatus) platform_pwm_stop( &platform_pwm_peripherals[pwm] ); }
static int lpwm_setup(lua_State* L) { double duty; int res, val, khz; res = 0; khz = 0; duty = 0; val = 0; int id = luaL_checkinteger(L, 1); int mode = luaL_checkinteger(L, 2); if (!platform_pwm_exists(L, id)) { return luaL_error(L, "pwm%d does not exist", id); } switch (mode) { case 0: khz = luaL_checkinteger(L, 3); duty = luaL_checknumber(L, 4); break; case 1: res = luaL_checkinteger(L, 3); val = luaL_checknumber(L, 4); break; default: return luaL_error(L, "invalid setup mode"); } // Check for setup needed if (pwm[id - 1].configured && (pwm[id - 1].mode == mode) && (pwm[id - 1].res == res) && (pwm[id - 1].khz == khz)) { // No changes lua_pushinteger(L, platform_pwm_freq(L, id)); return 1; } // Setup is needed, if configured, stop first if (pwm[id - 1].configured) { platform_pwm_stop(L, id); } // Configure switch (mode) { case 0: lua_pushinteger(L, platform_pwm_setup_freq(L, id, khz, duty)); break; case 1: lua_pushinteger(L, platform_pwm_setup_res(L, id, res, val)); break; default: return luaL_error(L, "invalid setup mode"); } pwm[id - 1].mode = mode; pwm[id - 1].res = res; pwm[id - 1].khz = khz; pwm[id - 1].configured = 1; return 1; }