Added inline pyi to audiobusio
This commit is contained in:
parent
8344fce994
commit
e96235d0cf
@ -35,16 +35,15 @@
|
||||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: audiobusio
|
||||
//|class I2SOut:
|
||||
//| """.. currentmodule:: audiobusio
|
||||
//|
|
||||
//| :class:`I2SOut` -- Output an I2S audio signal
|
||||
//| ========================================================
|
||||
//|
|
||||
//| I2S is used to output an audio signal on an I2S bus.
|
||||
//|
|
||||
//| .. class:: I2SOut(bit_clock, word_select, data, *, left_justified)
|
||||
//|
|
||||
//| Create a I2SOut object associated with the given pins.
|
||||
//| I2S is used to output an audio signal on an I2S bus."""
|
||||
//| def __init__(self, bit_clock: microcontroller.Pin, word_select: microcontroller.Pin, data: microcontroller.Pin, *, left_justified: bool):
|
||||
//| """Create a I2SOut object associated with the given pins.
|
||||
//|
|
||||
//| :param ~microcontroller.Pin bit_clock: The bit clock (or serial clock) pin
|
||||
//| :param ~microcontroller.Pin word_select: The word select (or left/right clock) pin
|
||||
@ -92,8 +91,8 @@
|
||||
//| a.play(wav)
|
||||
//| while a.playing:
|
||||
//| pass
|
||||
//| print("stopped")
|
||||
//|
|
||||
//| print("stopped")"""
|
||||
//| ...
|
||||
STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_bit_clock, ARG_word_select, ARG_data, ARG_left_justified };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
@ -116,10 +115,9 @@ STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_a
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Deinitialises the I2SOut and releases any hardware resources for reuse.
|
||||
//|
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """Deinitialises the I2SOut and releases any hardware resources for reuse."""
|
||||
//| ...
|
||||
STATIC mp_obj_t audiobusio_i2sout_deinit(mp_obj_t self_in) {
|
||||
audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
common_hal_audiobusio_i2sout_deinit(self);
|
||||
@ -132,17 +130,15 @@ STATIC void check_for_deinit(audiobusio_i2sout_obj_t *self) {
|
||||
raise_deinited_error();
|
||||
}
|
||||
}
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used by Context Managers.
|
||||
//|
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info.
|
||||
//|
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """Automatically deinitializes the hardware when exiting a context. See
|
||||
//| :ref:`lifetime-and-contextmanagers` for more info."""
|
||||
//| ...
|
||||
STATIC mp_obj_t audiobusio_i2sout_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
common_hal_audiobusio_i2sout_deinit(args[0]);
|
||||
@ -151,15 +147,14 @@ STATIC mp_obj_t audiobusio_i2sout_obj___exit__(size_t n_args, const mp_obj_t *ar
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiobusio_i2sout___exit___obj, 4, 4, audiobusio_i2sout_obj___exit__);
|
||||
|
||||
|
||||
//| .. method:: play(sample, *, loop=False)
|
||||
//|
|
||||
//| Plays the sample once when loop=False and continuously when loop=True.
|
||||
//| def play(self, sample: Any, *, loop: Any = False) -> Any:
|
||||
//| """Plays the sample once when loop=False and continuously when loop=True.
|
||||
//| Does not block. Use `playing` to block.
|
||||
//|
|
||||
//| Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, or `audiomixer.Mixer`.
|
||||
//|
|
||||
//| The sample itself should consist of 8 bit or 16 bit samples.
|
||||
//|
|
||||
//| The sample itself should consist of 8 bit or 16 bit samples."""
|
||||
//| ...
|
||||
STATIC mp_obj_t audiobusio_i2sout_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
|
||||
enum { ARG_sample, ARG_loop };
|
||||
static const mp_arg_t allowed_args[] = {
|
||||
@ -178,10 +173,9 @@ STATIC mp_obj_t audiobusio_i2sout_obj_play(size_t n_args, const mp_obj_t *pos_ar
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_KW(audiobusio_i2sout_play_obj, 1, audiobusio_i2sout_obj_play);
|
||||
|
||||
//| .. method:: stop()
|
||||
//|
|
||||
//| Stops playback.
|
||||
//|
|
||||
//| def stop(self, ) -> Any:
|
||||
//| """Stops playback."""
|
||||
//| ...
|
||||
STATIC mp_obj_t audiobusio_i2sout_obj_stop(mp_obj_t self_in) {
|
||||
audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
@ -190,10 +184,9 @@ STATIC mp_obj_t audiobusio_i2sout_obj_stop(mp_obj_t self_in) {
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(audiobusio_i2sout_stop_obj, audiobusio_i2sout_obj_stop);
|
||||
|
||||
//| .. attribute:: playing
|
||||
//|
|
||||
//| True when the audio sample is being output. (read-only)
|
||||
//|
|
||||
//| playing: Any =
|
||||
//| """True when the audio sample is being output. (read-only)"""
|
||||
//| ...
|
||||
STATIC mp_obj_t audiobusio_i2sout_obj_get_playing(mp_obj_t self_in) {
|
||||
audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
@ -208,10 +201,9 @@ const mp_obj_property_t audiobusio_i2sout_playing_obj = {
|
||||
(mp_obj_t)&mp_const_none_obj},
|
||||
};
|
||||
|
||||
//| .. method:: pause()
|
||||
//|
|
||||
//| Stops playback temporarily while remembering the position. Use `resume` to resume playback.
|
||||
//|
|
||||
//| def pause(self, ) -> Any:
|
||||
//| """Stops playback temporarily while remembering the position. Use `resume` to resume playback."""
|
||||
//| ...
|
||||
STATIC mp_obj_t audiobusio_i2sout_obj_pause(mp_obj_t self_in) {
|
||||
audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
@ -224,10 +216,9 @@ STATIC mp_obj_t audiobusio_i2sout_obj_pause(mp_obj_t self_in) {
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(audiobusio_i2sout_pause_obj, audiobusio_i2sout_obj_pause);
|
||||
|
||||
//| .. method:: resume()
|
||||
//|
|
||||
//| Resumes sample playback after :py:func:`pause`.
|
||||
//|
|
||||
//| def resume(self, ) -> Any:
|
||||
//| """Resumes sample playback after :py:func:`pause`."""
|
||||
//| ...
|
||||
STATIC mp_obj_t audiobusio_i2sout_obj_resume(mp_obj_t self_in) {
|
||||
audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
@ -240,10 +231,9 @@ STATIC mp_obj_t audiobusio_i2sout_obj_resume(mp_obj_t self_in) {
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_1(audiobusio_i2sout_resume_obj, audiobusio_i2sout_obj_resume);
|
||||
|
||||
//| .. attribute:: paused
|
||||
//|
|
||||
//| True when playback is paused. (read-only)
|
||||
//|
|
||||
//| paused: Any =
|
||||
//| """True when playback is paused. (read-only)"""
|
||||
//| ...
|
||||
STATIC mp_obj_t audiobusio_i2sout_obj_get_paused(mp_obj_t self_in) {
|
||||
audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
|
@ -36,16 +36,23 @@
|
||||
#include "shared-bindings/util.h"
|
||||
#include "supervisor/shared/translate.h"
|
||||
|
||||
//| .. currentmodule:: audiobusio
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//|class PDMIn:
|
||||
//| """.. currentmodule:: audiobusio
|
||||
//|
|
||||
//| :class:`PDMIn` -- Record an input PDM audio stream
|
||||
//| ========================================================
|
||||
//|
|
||||
//| PDMIn can be used to record an input audio signal on a given set of pins.
|
||||
//| PDMIn can be used to record an input audio signal on a given set of pins."""
|
||||
//|
|
||||
//| .. class:: PDMIn(clock_pin, data_pin, *, sample_rate=16000, bit_depth=8, mono=True, oversample=64, startup_delay=0.11)
|
||||
//|
|
||||
//| Create a PDMIn object associated with the given pins. This allows you to
|
||||
//| def __init__(self, clock_pin: microcontroller.Pin, data_pin: microcontroller.Pin, *, sample_rate: int = 16000, bit_depth: int = 8, mono: bool = True, oversample: int = 64, startup_delay: float = 0.11):
|
||||
//| """Create a PDMIn object associated with the given pins. This allows you to
|
||||
//| record audio signals from the given pins. Individual ports may put further
|
||||
//| restrictions on the recording parameters. The overall sample rate is
|
||||
//| determined by `sample_rate` x ``oversample``, and the total must be 1MHz or
|
||||
@ -60,8 +67,8 @@
|
||||
//| :param int oversample: Number of single bit samples to decimate into a final sample. Must be divisible by 8
|
||||
//| :param float startup_delay: seconds to wait after starting microphone clock
|
||||
//| to allow microphone to turn on. Most require only 0.01s; some require 0.1s. Longer is safer.
|
||||
//| Must be in range 0.0-1.0 seconds.
|
||||
//|
|
||||
//| Must be in range 0.0-1.0 seconds."""
|
||||
//| ...
|
||||
|
||||
//| Record 8-bit unsigned samples to buffer::
|
||||
//|
|
||||
@ -138,10 +145,9 @@ STATIC mp_obj_t audiobusio_pdmin_make_new(const mp_obj_type_t *type, size_t n_ar
|
||||
return MP_OBJ_FROM_PTR(self);
|
||||
}
|
||||
|
||||
//| .. method:: deinit()
|
||||
//|
|
||||
//| Deinitialises the PDMIn and releases any hardware resources for reuse.
|
||||
//|
|
||||
//| def deinit(self, ) -> Any:
|
||||
//| """Deinitialises the PDMIn and releases any hardware resources for reuse."""
|
||||
//| ...
|
||||
STATIC mp_obj_t audiobusio_pdmin_deinit(mp_obj_t self_in) {
|
||||
audiobusio_pdmin_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
common_hal_audiobusio_pdmin_deinit(self);
|
||||
@ -154,16 +160,14 @@ STATIC void check_for_deinit(audiobusio_pdmin_obj_t *self) {
|
||||
raise_deinited_error();
|
||||
}
|
||||
}
|
||||
//| .. method:: __enter__()
|
||||
//|
|
||||
//| No-op used by Context Managers.
|
||||
//|
|
||||
//| def __enter__(self, ) -> Any:
|
||||
//| """No-op used by Context Managers."""
|
||||
//| ...
|
||||
// Provided by context manager helper.
|
||||
|
||||
//| .. method:: __exit__()
|
||||
//|
|
||||
//| Automatically deinitializes the hardware when exiting a context.
|
||||
//|
|
||||
//| def __exit__(self, ) -> Any:
|
||||
//| """Automatically deinitializes the hardware when exiting a context."""
|
||||
//| ...
|
||||
STATIC mp_obj_t audiobusio_pdmin_obj___exit__(size_t n_args, const mp_obj_t *args) {
|
||||
(void)n_args;
|
||||
common_hal_audiobusio_pdmin_deinit(args[0]);
|
||||
@ -172,9 +176,8 @@ STATIC mp_obj_t audiobusio_pdmin_obj___exit__(size_t n_args, const mp_obj_t *arg
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiobusio_pdmin___exit___obj, 4, 4, audiobusio_pdmin_obj___exit__);
|
||||
|
||||
|
||||
//| .. method:: record(destination, destination_length)
|
||||
//|
|
||||
//| Records destination_length bytes of samples to destination. This is
|
||||
//| def record(self, destination: Any, destination_length: Any) -> Any:
|
||||
//| """Records destination_length bytes of samples to destination. This is
|
||||
//| blocking.
|
||||
//|
|
||||
//| An IOError may be raised when the destination is too slow to record the
|
||||
@ -182,8 +185,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiobusio_pdmin___exit___obj, 4, 4,
|
||||
//| before recording is recommended to speed up writes.
|
||||
//|
|
||||
//| :return: The number of samples recorded. If this is less than ``destination_length``,
|
||||
//| some samples were missed due to processing time.
|
||||
//|
|
||||
//| some samples were missed due to processing time."""
|
||||
//| ...
|
||||
STATIC mp_obj_t audiobusio_pdmin_obj_record(mp_obj_t self_obj, mp_obj_t destination, mp_obj_t destination_length) {
|
||||
audiobusio_pdmin_obj_t *self = MP_OBJ_TO_PTR(self_obj);
|
||||
check_for_deinit(self);
|
||||
@ -214,11 +217,10 @@ STATIC mp_obj_t audiobusio_pdmin_obj_record(mp_obj_t self_obj, mp_obj_t destinat
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_3(audiobusio_pdmin_record_obj, audiobusio_pdmin_obj_record);
|
||||
|
||||
//| .. attribute:: sample_rate
|
||||
//|
|
||||
//| The actual sample_rate of the recording. This may not match the constructed
|
||||
//| sample rate due to internal clock limitations.
|
||||
//|
|
||||
//| sample_rate: Any =
|
||||
//| """The actual sample_rate of the recording. This may not match the constructed
|
||||
//| sample rate due to internal clock limitations."""
|
||||
//| ...
|
||||
STATIC mp_obj_t audiobusio_pdmin_obj_get_sample_rate(mp_obj_t self_in) {
|
||||
audiobusio_pdmin_obj_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
check_for_deinit(self);
|
||||
|
Loading…
Reference in New Issue
Block a user