Skip to content

Commit e96235d

Browse files
committed
Added inline pyi to audiobusio
1 parent 8344fce commit e96235d

File tree

2 files changed

+140
-148
lines changed

2 files changed

+140
-148
lines changed

shared-bindings/audiobusio/I2SOut.c

Lines changed: 89 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -35,65 +35,64 @@
3535
#include "shared-bindings/util.h"
3636
#include "supervisor/shared/translate.h"
3737

38-
//| .. currentmodule:: audiobusio
39-
//|
40-
//| :class:`I2SOut` -- Output an I2S audio signal
41-
//| ========================================================
42-
//|
43-
//| I2S is used to output an audio signal on an I2S bus.
44-
//|
45-
//| .. class:: I2SOut(bit_clock, word_select, data, *, left_justified)
46-
//|
47-
//| Create a I2SOut object associated with the given pins.
48-
//|
49-
//| :param ~microcontroller.Pin bit_clock: The bit clock (or serial clock) pin
50-
//| :param ~microcontroller.Pin word_select: The word select (or left/right clock) pin
51-
//| :param ~microcontroller.Pin data: The data pin
52-
//| :param bool left_justified: True when data bits are aligned with the word select clock. False
53-
//| when they are shifted by one to match classic I2S protocol.
54-
//|
55-
//| Simple 8ksps 440 Hz sine wave on `Metro M0 Express <https://www.adafruit.com/product/3505>`_
56-
//| using `UDA1334 Breakout <https://www.adafruit.com/product/3678>`_::
57-
//|
58-
//| import audiobusio
59-
//| import audiocore
60-
//| import board
61-
//| import array
62-
//| import time
63-
//| import math
64-
//|
65-
//| # Generate one period of sine wave.
66-
//| length = 8000 // 440
67-
//| sine_wave = array.array("H", [0] * length)
68-
//| for i in range(length):
69-
//| sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15) + 2 ** 15)
70-
//|
71-
//| sine_wave = audiocore.RawSample(sine_wave, sample_rate=8000)
72-
//| i2s = audiobusio.I2SOut(board.D1, board.D0, board.D9)
73-
//| i2s.play(sine_wave, loop=True)
74-
//| time.sleep(1)
75-
//| i2s.stop()
76-
//|
77-
//| Playing a wave file from flash::
78-
//|
79-
//| import board
80-
//| import audioio
81-
//| import audiocore
82-
//| import audiobusio
83-
//| import digitalio
84-
//|
85-
//|
86-
//| f = open("cplay-5.1-16bit-16khz.wav", "rb")
87-
//| wav = audiocore.WaveFile(f)
88-
//|
89-
//| a = audiobusio.I2SOut(board.D1, board.D0, board.D9)
90-
//|
91-
//| print("playing")
92-
//| a.play(wav)
93-
//| while a.playing:
94-
//| pass
95-
//| print("stopped")
96-
//|
38+
//|class I2SOut:
39+
//| """.. currentmodule:: audiobusio
40+
//|
41+
//| :class:`I2SOut` -- Output an I2S audio signal
42+
//| ========================================================
43+
//|
44+
//| I2S is used to output an audio signal on an I2S bus."""
45+
//| def __init__(self, bit_clock: microcontroller.Pin, word_select: microcontroller.Pin, data: microcontroller.Pin, *, left_justified: bool):
46+
//| """Create a I2SOut object associated with the given pins.
47+
//|
48+
//| :param ~microcontroller.Pin bit_clock: The bit clock (or serial clock) pin
49+
//| :param ~microcontroller.Pin word_select: The word select (or left/right clock) pin
50+
//| :param ~microcontroller.Pin data: The data pin
51+
//| :param bool left_justified: True when data bits are aligned with the word select clock. False
52+
//| when they are shifted by one to match classic I2S protocol.
53+
//|
54+
//| Simple 8ksps 440 Hz sine wave on `Metro M0 Express <https://www.adafruit.com/product/3505>`_
55+
//| using `UDA1334 Breakout <https://www.adafruit.com/product/3678>`_::
56+
//|
57+
//| import audiobusio
58+
//| import audiocore
59+
//| import board
60+
//| import array
61+
//| import time
62+
//| import math
63+
//|
64+
//| # Generate one period of sine wave.
65+
//| length = 8000 // 440
66+
//| sine_wave = array.array("H", [0] * length)
67+
//| for i in range(length):
68+
//| sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2 ** 15) + 2 ** 15)
69+
//|
70+
//| sine_wave = audiocore.RawSample(sine_wave, sample_rate=8000)
71+
//| i2s = audiobusio.I2SOut(board.D1, board.D0, board.D9)
72+
//| i2s.play(sine_wave, loop=True)
73+
//| time.sleep(1)
74+
//| i2s.stop()
75+
//|
76+
//| Playing a wave file from flash::
77+
//|
78+
//| import board
79+
//| import audioio
80+
//| import audiocore
81+
//| import audiobusio
82+
//| import digitalio
83+
//|
84+
//|
85+
//| f = open("cplay-5.1-16bit-16khz.wav", "rb")
86+
//| wav = audiocore.WaveFile(f)
87+
//|
88+
//| a = audiobusio.I2SOut(board.D1, board.D0, board.D9)
89+
//|
90+
//| print("playing")
91+
//| a.play(wav)
92+
//| while a.playing:
93+
//| pass
94+
//| print("stopped")"""
95+
//| ...
9796
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) {
9897
enum { ARG_bit_clock, ARG_word_select, ARG_data, ARG_left_justified };
9998
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
116115
return MP_OBJ_FROM_PTR(self);
117116
}
118117

119-
//| .. method:: deinit()
120-
//|
121-
//| Deinitialises the I2SOut and releases any hardware resources for reuse.
122-
//|
118+
//| def deinit(self, ) -> Any:
119+
//| """Deinitialises the I2SOut and releases any hardware resources for reuse."""
120+
//| ...
123121
STATIC mp_obj_t audiobusio_i2sout_deinit(mp_obj_t self_in) {
124122
audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in);
125123
common_hal_audiobusio_i2sout_deinit(self);
@@ -132,17 +130,15 @@ STATIC void check_for_deinit(audiobusio_i2sout_obj_t *self) {
132130
raise_deinited_error();
133131
}
134132
}
135-
//| .. method:: __enter__()
136-
//|
137-
//| No-op used by Context Managers.
138-
//|
133+
//| def __enter__(self, ) -> Any:
134+
//| """No-op used by Context Managers."""
135+
//| ...
139136
// Provided by context manager helper.
140137

141-
//| .. method:: __exit__()
142-
//|
143-
//| Automatically deinitializes the hardware when exiting a context. See
144-
//| :ref:`lifetime-and-contextmanagers` for more info.
145-
//|
138+
//| def __exit__(self, ) -> Any:
139+
//| """Automatically deinitializes the hardware when exiting a context. See
140+
//| :ref:`lifetime-and-contextmanagers` for more info."""
141+
//| ...
146142
STATIC mp_obj_t audiobusio_i2sout_obj___exit__(size_t n_args, const mp_obj_t *args) {
147143
(void)n_args;
148144
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
151147
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(audiobusio_i2sout___exit___obj, 4, 4, audiobusio_i2sout_obj___exit__);
152148

153149

154-
//| .. method:: play(sample, *, loop=False)
150+
//| def play(self, sample: Any, *, loop: Any = False) -> Any:
151+
//| """Plays the sample once when loop=False and continuously when loop=True.
152+
//| Does not block. Use `playing` to block.
155153
//|
156-
//| Plays the sample once when loop=False and continuously when loop=True.
157-
//| Does not block. Use `playing` to block.
158-
//|
159-
//| Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, or `audiomixer.Mixer`.
160-
//|
161-
//| The sample itself should consist of 8 bit or 16 bit samples.
154+
//| Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, or `audiomixer.Mixer`.
162155
//|
156+
//| The sample itself should consist of 8 bit or 16 bit samples."""
157+
//| ...
163158
STATIC mp_obj_t audiobusio_i2sout_obj_play(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
164159
enum { ARG_sample, ARG_loop };
165160
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
178173
}
179174
MP_DEFINE_CONST_FUN_OBJ_KW(audiobusio_i2sout_play_obj, 1, audiobusio_i2sout_obj_play);
180175

181-
//| .. method:: stop()
182-
//|
183-
//| Stops playback.
184-
//|
176+
//| def stop(self, ) -> Any:
177+
//| """Stops playback."""
178+
//| ...
185179
STATIC mp_obj_t audiobusio_i2sout_obj_stop(mp_obj_t self_in) {
186180
audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in);
187181
check_for_deinit(self);
@@ -190,10 +184,9 @@ STATIC mp_obj_t audiobusio_i2sout_obj_stop(mp_obj_t self_in) {
190184
}
191185
MP_DEFINE_CONST_FUN_OBJ_1(audiobusio_i2sout_stop_obj, audiobusio_i2sout_obj_stop);
192186

193-
//| .. attribute:: playing
194-
//|
195-
//| True when the audio sample is being output. (read-only)
196-
//|
187+
//| playing: Any =
188+
//| """True when the audio sample is being output. (read-only)"""
189+
//| ...
197190
STATIC mp_obj_t audiobusio_i2sout_obj_get_playing(mp_obj_t self_in) {
198191
audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in);
199192
check_for_deinit(self);
@@ -208,10 +201,9 @@ const mp_obj_property_t audiobusio_i2sout_playing_obj = {
208201
(mp_obj_t)&mp_const_none_obj},
209202
};
210203

211-
//| .. method:: pause()
212-
//|
213-
//| Stops playback temporarily while remembering the position. Use `resume` to resume playback.
214-
//|
204+
//| def pause(self, ) -> Any:
205+
//| """Stops playback temporarily while remembering the position. Use `resume` to resume playback."""
206+
//| ...
215207
STATIC mp_obj_t audiobusio_i2sout_obj_pause(mp_obj_t self_in) {
216208
audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in);
217209
check_for_deinit(self);
@@ -224,10 +216,9 @@ STATIC mp_obj_t audiobusio_i2sout_obj_pause(mp_obj_t self_in) {
224216
}
225217
MP_DEFINE_CONST_FUN_OBJ_1(audiobusio_i2sout_pause_obj, audiobusio_i2sout_obj_pause);
226218

227-
//| .. method:: resume()
228-
//|
229-
//| Resumes sample playback after :py:func:`pause`.
230-
//|
219+
//| def resume(self, ) -> Any:
220+
//| """Resumes sample playback after :py:func:`pause`."""
221+
//| ...
231222
STATIC mp_obj_t audiobusio_i2sout_obj_resume(mp_obj_t self_in) {
232223
audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in);
233224
check_for_deinit(self);
@@ -240,10 +231,9 @@ STATIC mp_obj_t audiobusio_i2sout_obj_resume(mp_obj_t self_in) {
240231
}
241232
MP_DEFINE_CONST_FUN_OBJ_1(audiobusio_i2sout_resume_obj, audiobusio_i2sout_obj_resume);
242233

243-
//| .. attribute:: paused
244-
//|
245-
//| True when playback is paused. (read-only)
246-
//|
234+
//| paused: Any =
235+
//| """True when playback is paused. (read-only)"""
236+
//| ...
247237
STATIC mp_obj_t audiobusio_i2sout_obj_get_paused(mp_obj_t self_in) {
248238
audiobusio_i2sout_obj_t *self = MP_OBJ_TO_PTR(self_in);
249239
check_for_deinit(self);

0 commit comments

Comments
 (0)