// Lua: drv:play(self, rate) static int pcm_drv_play( lua_State *L ) { GET_PUD(); cfg->rate = luaL_optinteger( L, 2, PCM_RATE_8K ); luaL_argcheck( L, (cfg->rate >= PCM_RATE_1K) && (cfg->rate <= PCM_RATE_16K), 2, "invalid bit rate" ); if (cfg->self_ref == LUA_NOREF) { lua_pushvalue( L, 1 ); // copy self userdata to the top of stack cfg->self_ref = luaL_ref( L, LUA_REGISTRYINDEX ); } // schedule actions for play in separate task since drv:play() might have been called // in the callback fn of pcm_data_play_task() which in turn gets called when starting play... task_post_low( cfg->start_play_task, (os_param_t)pud ); return 0; }
void nodemcu_init(void) { NODE_ERR("\n"); // Initialize platform first for lua modules. if( platform_init() != PLATFORM_OK ) { // This should never happen NODE_DBG("Can not init platform for modules.\n"); return; } #if defined(FLASH_SAFE_API) if( flash_safe_get_size_byte() != flash_rom_get_size_byte()) { NODE_ERR("Self adjust flash size.\n"); // Fit hardware real flash size. flash_rom_set_size_byte(flash_safe_get_size_byte()); if( !fs_format() ) { NODE_ERR( "\ni*** ERROR ***: unable to format. FS might be compromised.\n" ); NODE_ERR( "It is advised to re-flash the NodeMCU image.\n" ); } else { NODE_ERR( "format done.\n" ); } fs_unmount(); // mounted by format. // Reboot to get SDK to use (or write) init data at new location system_restart (); // Don't post the start_lua task, we're about to reboot... return; } #endif // defined(FLASH_SAFE_API) #if defined ( BUILD_SPIFFS ) fs_mount(); // test_spiffs(); #endif // endpoint_setup(); task_post_low(task_get_id(start_lua),'s'); }
bool user_process_input(bool force) { return task_post_low(input_sig, force); }
static void ICACHE_RAM_ATTR gpio_pulse_timeout(os_param_t p) { (void) p; uint32_t now = system_get_time(); int delay; if (active_pulser) { delay = active_pulser->pending_delay; if (delay > 0) { if (delay > 1200000) { delay = 1000000; } active_pulser->pending_delay -= delay; platform_hw_timer_arm_us(TIMER_OWNER, delay); return; } } do { active_pulser->active_pos = active_pulser->entry_pos; if (!active_pulser || active_pulser->entry_pos >= active_pulser->entry_count) { if (active_pulser) { active_pulser->steps++; } platform_hw_timer_close(TIMER_OWNER); task_post_low(tasknumber, (task_param_t)0); return; } active_pulser->steps++; pulse_entry_t *entry = active_pulser->entry + active_pulser->entry_pos; // Yes, this means that there is more skew on D0 than on other pins.... if (entry->gpio_set & 0x10000) { gpio16_output_set(1); } GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, entry->gpio_set); GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, entry->gpio_clr); if (entry->gpio_clr & 0x10000) { gpio16_output_set(0); } int16_t stop = active_pulser->stop_pos; if (stop == -2 || stop == active_pulser->entry_pos) { platform_hw_timer_close(TIMER_OWNER); task_post_low(tasknumber, (task_param_t)0); return; } if (entry->loop) { if (entry->count_left == 0) { entry->count_left = entry->count + 1; } if (--entry->count_left >= 1) { active_pulser->entry_pos = entry->loop - 1; // zero offset } else { active_pulser->entry_pos++; } } else { active_pulser->entry_pos++; } delay = entry->delay; int delay_offset = 0; if (entry->delay_min != -1) { int offset = active_pulser->next_adjust; active_pulser->next_adjust = 0; delay_offset = ((0x7fffffff & (now - active_pulser->desired_end_time)) << 1) >> 1; delay -= delay_offset; delay += offset; //dbg_printf("%d(et %d diff %d): Delay was %d us, offset = %d, delay_offset = %d, new delay = %d, range=%d..%d\n", // now, active_pulser->desired_end_time, now - active_pulser->desired_end_time, // entry->delay, offset, delay_offset, delay, entry->delay_min, entry->delay_max); if (delay < entry->delay_min) { // we can't delay as little as 'delay', so we need to adjust // the next period as well. active_pulser->next_adjust = (entry->delay - entry->delay_min) + offset; delay = entry->delay_min; } else if (delay > entry->delay_max) { // we can't delay as much as 'delay', so we need to adjust // the next period as well. active_pulser->next_adjust = (entry->delay - entry->delay_max) + offset; delay = entry->delay_max; } } active_pulser->desired_end_time += delay + delay_offset; active_pulser->expected_end_time = system_get_time() + delay; } while (delay < 3);