diff --git a/app/modules/pwm.c b/app/modules/pwm.c index da9d5f8d..088223d2 100644 --- a/app/modules/pwm.c +++ b/app/modules/pwm.c @@ -122,6 +122,11 @@ static int lpwm_getduty( lua_State* L ) return 1; } +int lpwm_open( lua_State *L ) { + platform_pwm_init(); + return 0; +} + // Module function map static const LUA_REG_TYPE pwm_map[] = { { LSTRKEY( "setup" ), LFUNCVAL( lpwm_setup ) }, @@ -135,4 +140,4 @@ static const LUA_REG_TYPE pwm_map[] = { { LNILKEY, LNILVAL } }; -NODEMCU_MODULE(PWM, "pwm", pwm_map, NULL); +NODEMCU_MODULE(PWM, "pwm", pwm_map, lpwm_open); diff --git a/app/platform/platform.c b/app/platform/platform.c index 351d1b4e..e7bb32ad 100755 --- a/app/platform/platform.c +++ b/app/platform/platform.c @@ -32,16 +32,11 @@ static struct gpio_hook platform_gpio_hook; #endif #endif -static void pwms_init(); - int platform_init() { // Setup the various forward and reverse mappings for the pins get_pin_map(); - // Setup PWMs - pwms_init(); - cmn_platform_init(); // All done return PLATFORM_OK; @@ -113,7 +108,9 @@ int platform_gpio_mode( unsigned pin, unsigned mode, unsigned pull ) return 1; } +#ifdef LUA_USE_MODULES_PWM platform_pwm_close(pin); // closed from pwm module, if it is used in pwm +#endif if (pull == PLATFORM_GPIO_PULLUP) { PIN_PULLUP_EN(pin_mux[pin]); @@ -421,7 +418,7 @@ void platform_uart_send( unsigned id, u8 data ) static uint16_t pwms_duty[NUM_PWM] = {0}; -static void pwms_init() +void platform_pwm_init() { int i; for(i=0;i 0)); } uint32_t platform_pwm_setup( unsigned id, uint32_t frequency, unsigned duty ); void platform_pwm_close( unsigned id );