static int lua_regsound(lua_State *L){ int argc = lua_gettop(L); #ifndef SKIP_ERROR_HANDLING if (argc != 2) return luaL_error(L, "wrong number of arguments"); #endif u32 time = luaL_checkinteger(L, 1); u32 samplerate = luaL_checkinteger(L, 2); u32 mem_base; if (samplerate <= 8200){ srate = MICU_SAMPLE_RATE_8180; mem_base = 0x4000; }else if (samplerate <= 12000){ srate = MICU_SAMPLE_RATE_10910; mem_base = 0x6000; }else if (samplerate <= 18000){ srate = MICU_SAMPLE_RATE_16360; mem_base = 0x8000; }else{ srate = MICU_SAMPLE_RATE_32730; mem_base = 0x10000; } u32 micbuf_pos = 0; u32 mem_size = mem_base * time; micbuf = (u32*)memalign(0x1000, mem_size); micInit((u8*)micbuf, mem_size); micsize = micGetSampleDataSize(); bool power; cur_offset = 0; svcSleepThread(1000000000); MICU_StartSampling(MICU_ENCODING_PCM16_SIGNED, srate, 0, micsize, false); return 0; }
int main(void) { /* Init microscope hardware */ micInit(); /* Create USB task */ xTaskCreate(usbTask, "USB", 256, NULL, 1, NULL); /* Start FreeRTOS task scheduler */ vTaskStartScheduler(); /* We never reached here */ while (1); }
/** * \brief Initializes all the subsystems for this Droplet. This function MUST be called * by the user before using any other functions in the API. */ static void initAllSystems(void){ cli(); Config32MHzClock(); calculateIdNumber(); schedulerInit(); INIT_DEBUG_PRINT("SCHEDULER INIT\r\n"); pcCommInit(); INIT_DEBUG_PRINT("PC COM INIT\r\n"); rgbLEDinit(); INIT_DEBUG_PRINT("LED INIT\r\n"); powerInit(); INIT_DEBUG_PRINT("POWER INIT\r\n"); i2cInit(); INIT_DEBUG_PRINT("I2C INIT\r\n"); enableInterrupts(); rangeAlgsInit(); INIT_DEBUG_PRINT("RANGE ALGORITHMS INIT\r\n"); rgbSensorInit(); INIT_DEBUG_PRINT("RGB SENSE INIT\r\n"); irLedInit(); INIT_DEBUG_PRINT("IR LED INIT\r\n"); irSensorInit(); INIT_DEBUG_PRINT("IR SENSE INIT\r\n"); #ifdef AUDIO_DROPLET speakerInit(); INIT_DEBUG_PRINT("SPEAKER INIT\r\n"); micInit(); INIT_DEBUG_PRINT("MIC INIT\r\n"); //Must occur after ir_sensor_init. #endif motorInit(); INIT_DEBUG_PRINT("MOTOR INIT\r\n"); randomInit(); INIT_DEBUG_PRINT("RAND INIT\r\n"); //This uses adc readings for a random seed, and so requires that the adcs have been initialized. localizationInit(); INIT_DEBUG_PRINT("LOCALIZATION INIT\r\n"); #ifdef SYNCHRONIZED fireflySyncInit(); #endif setAllirPowers(256); startupLightSequence(); irCommInit(); INIT_DEBUG_PRINT("IR COM INIT\r\n"); #ifdef AUDIO_DROPLET enableMicInterrupt(); #endif }