int lc823450_wm8776initialize(int minor) { FAR struct audio_lowerhalf_s *wm8776; FAR struct audio_lowerhalf_s *pcm; FAR struct i2c_master_s *i2c; FAR struct i2s_dev_s *i2s; char devname[12]; int ret; ainfo("Initializing WM8776 \n"); /* Initialize I2C */ i2c = lc823450_i2cbus_initialize(WM8776_I2C_PORTNO); if (!i2c) { return -ENODEV; } i2s = lc823450_i2sdev_initialize(); #ifdef CONFIG_AUDIO_I2SCHAR i2schar_register(i2s, 0); #endif wm8776 = wm8776_initialize(i2c, i2s, &g_wm8776info); if (!wm8776) { auderr("ERROR: Failed to initialize the WM8904\n"); return -ENODEV; } pcm = pcm_decode_initialize(wm8776); if (!pcm) { auderr("ERROR: Failed create the PCM decoder\n"); return -ENODEV; } snprintf(devname, 12, "pcm%d", minor); ret = audio_register(devname, pcm); if (ret < 0) { auderr("ERROR: Failed to register /dev/%s device: %d\n", devname, ret); } return 0; }
int sam_audio_null_initialize(int minor) { FAR struct audio_lowerhalf_s *nullaudio; FAR struct audio_lowerhalf_s *pcm; static bool initialized = false; char devname[12]; int ret; auddbg("minor %d\n", minor); DEBUGASSERT(minor >= 0 && minor <= 25); /* Have we already initialized? Since we never uninitialize we must prevent * multiple initializations. This is necessary, for example, when the * touchscreen example is used as a built-in application in NSH and can be * called numerous time. It will attempt to initialize each time. */ if (!initialized) { /* Get a null audio interface */ nullaudio = audio_null_initialize(); if (!nullaudio) { auddbg("Failed to get the NULL audio interface\n"); ret = -ENODEV; goto errout; } /* No we can embed the null audio interface into a PCM decoder * instance so that we will have a PCM front end for the NULL * audio driver. */ pcm = pcm_decode_initialize(nullaudio); if (!pcm) { auddbg("ERROR: Failed create the PCM decoder\n"); ret = -ENODEV; goto errout_with_nullaudio; } /* Create a device name */ snprintf(devname, 12, "pcm%d", minor); /* Finally, we can register the PCM/NULL audio device. */ ret = audio_register(devname, pcm); if (ret < 0) { auddbg("ERROR: Failed to register /dev/%s device: %d\n", devname, ret); goto errout_with_pcm; } /* Now we are initialized */ initialized = true; } return OK; /* Error exits. Unfortunately there is no mechanism in place now to * recover resources from most errors on initialization failures. */ errout_with_nullaudio: errout_with_pcm: errout: return ret; }