// Lua: realclock = setclock( id, clock ) static int ICACHE_FLASH_ATTR lpwm_setclock( lua_State* L ) { unsigned id; s32 clk; // signed to error-check for negative values id = luaL_checkinteger( L, 1 ); MOD_CHECK_ID( pwm, id ); clk = luaL_checkinteger( L, 2 ); if ( clk <= 0 ) return luaL_error( L, "wrong arg range" ); clk = platform_pwm_set_clock( id, (u32)clk ); lua_pushinteger( L, clk ); return 1; }
// Lua: realclock = setclock( id, clock ) static int pwm_setclock( lua_State *L ) { unsigned id; s32 clk; // signed to error-check for negative values id = luaL_checkinteger( L, 1 ); MOD_CHECK_ID( pwm, id ); clk = luaL_checkinteger( L, 2 ); if ( clk <= 0 ) return luaL_error( L, "frequency must be > 0" ); clk = platform_pwm_set_clock( id, (u32)clk ); lua_pushinteger( L, clk ); return 1; }
// Lua: realclock = setclock( clock ) static int lpwmled_setclock( lua_State* L ) { unsigned id; s32 clk; // signed to error-check for negative values clk = luaL_checkinteger( L, 1 ); if ( clk <= 0 ) return luaL_error( L, "wrong arg range" ); led.frequency=clk; led.frequency = platform_pwm_set_clock( led.pwmidr,led.frequency ); //due to ESP construction no need in next two //led.frequency = platform_pwm_set_clock( led.pwmidg,led.frequency ); //led.frequency = platform_pwm_set_clock( led.pwmidb,led.frequency ); lua_pushinteger( L, led.frequency ); return 1; }
// Setup all PWM channels static void platform_setup_pwm() { PWM_MATCHCFG_Type PWMMatchCfgDat; // Keep clock in reset, set PWM code PWM_ResetCounter( LPC_PWM1 ); // Set match mode (reset on MR0 match) PWMMatchCfgDat.IntOnMatch = DISABLE; PWMMatchCfgDat.MatchChannel = 0; PWMMatchCfgDat.ResetOnMatch = ENABLE; PWMMatchCfgDat.StopOnMatch = DISABLE; PWM_ConfigMatch( LPC_PWM1, &PWMMatchCfgDat ); // Set base frequency to 1MHz platform_pwm_set_clock( 0, 1000000 ); }