*/
int sandbox_get_setup_called(struct udevice *dev);
+/**
+ * sandbox_get_sound_active() - Returns whether sound play is in progress
+ *
+ * @return true if active, false if not
+ */
+int sandbox_get_sound_active(struct udevice *dev);
+
/**
* sandbox_get_sound_sum() - Read back the sum of the sound data so far
*
};
struct sandbox_sound_priv {
- int setup_called;
+ int setup_called; /* Incremented when setup() method is called */
+ bool active; /* TX data is being sent */
int sum; /* Use to sum the provided audio data */
bool allow_beep; /* true to allow the start_beep() interface */
int frequency_hz; /* Beep frequency if active, else 0 */
return priv->setup_called;
}
+int sandbox_get_sound_active(struct udevice *dev)
+{
+ struct sandbox_sound_priv *priv = dev_get_priv(dev);
+
+ return priv->active;
+}
+
int sandbox_get_sound_sum(struct udevice *dev)
{
struct sandbox_sound_priv *priv = dev_get_priv(dev);
return i2s_tx_data(uc_priv->i2s, data, data_size);
}
+static int sandbox_sound_stop_play(struct udevice *dev)
+{
+ struct sandbox_sound_priv *priv = dev_get_priv(dev);
+
+ sandbox_sdl_sound_stop();
+ priv->active = false;
+
+ return 0;
+}
+
int sandbox_sound_start_beep(struct udevice *dev, int frequency_hz)
{
struct sandbox_sound_priv *priv = dev_get_priv(dev);
static const struct sound_ops sandbox_sound_ops = {
.setup = sandbox_sound_setup,
.play = sandbox_sound_play,
+ .stop_play = sandbox_sound_stop_play,
.start_beep = sandbox_sound_start_beep,
.stop_beep = sandbox_sound_stop_beep,
};
return ops->play(dev, data, data_size);
}
+int sound_stop_play(struct udevice *dev)
+{
+ struct sound_ops *ops = sound_get_ops(dev);
+
+ if (!ops->play)
+ return -ENOSYS;
+
+ return ops->stop_play(dev);
+}
+
int sound_start_beep(struct udevice *dev, int frequency_hz)
{
struct sound_ops *ops = sound_get_ops(dev);
ret = sound_play(dev, data, size);
}
+ sound_stop_play(dev);
free(data);
*/
int (*play)(struct udevice *dev, void *data, uint data_size);
+ /**
+ * stop_play() - Indicate that there is no more data coming
+ *
+ * This is called once play() has finished sending all the data to the
+ * output device. This may be used to tell the hardware to turn off the
+ * codec, for example.
+ *
+ * @dev: Sound device
+ * @return 0 if OK, -ve on error
+ */
+ int (*stop_play)(struct udevice *dev);
+
/**
* start_beep() - Start beeping (optional)
*
ut_asserteq(4560, sandbox_get_sound_sum(dev));
ut_assertok(sound_beep(dev, 1, 100));
ut_asserteq(9120, sandbox_get_sound_sum(dev));
+ ut_asserteq(false, sandbox_get_sound_active(dev));
return 0;
}