36
36
#include "supervisor/shared/translate.h"
37
37
38
38
//|class I2SOut:
39
- //| """.. currentmodule:: audiobusio
39
+ //|""".. currentmodule:: audiobusio
40
40
//|
41
- //| :class:`I2SOut` -- Output an I2S audio signal
42
- //| ========================================================
41
+ //|:class:`I2SOut` -- Output an I2S audio signal
42
+ //|========================================================
43
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.
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
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.
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
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>`_::
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
56
//|
57
- //| import audiobusio
58
- //| import audiocore
59
- //| import board
60
- //| import array
61
- //| import time
62
- //| import math
57
+ //|import audiobusio
58
+ //|import audiocore
59
+ //|import board
60
+ //|import array
61
+ //|import time
62
+ //|import math
63
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)
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
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()
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
75
//|
76
- //| Playing a wave file from flash::
76
+ //|Playing a wave file from flash::
77
77
//|
78
- //| import board
79
- //| import audioio
80
- //| import audiocore
81
- //| import audiobusio
82
- //| import digitalio
78
+ //|import board
79
+ //|import audioio
80
+ //|import audiocore
81
+ //|import audiobusio
82
+ //|import digitalio
83
83
//|
84
84
//|
85
- //| f = open("cplay-5.1-16bit-16khz.wav", "rb")
86
- //| wav = audiocore.WaveFile(f)
85
+ //|f = open("cplay-5.1-16bit-16khz.wav", "rb")
86
+ //|wav = audiocore.WaveFile(f)
87
87
//|
88
- //| a = audiobusio.I2SOut(board.D1, board.D0, board.D9)
88
+ //|a = audiobusio.I2SOut(board.D1, board.D0, board.D9)
89
89
//|
90
- //| print("playing")
91
- //| a.play(wav)
92
- //| while a.playing:
93
- //| pass
94
- //| print("stopped")"""
95
- //| ...
90
+ //|print("playing")
91
+ //|a.play(wav)
92
+ //|while a.playing:
93
+ //|pass
94
+ //|print("stopped")"""
95
+ //|...
96
96
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 ) {
97
97
enum { ARG_bit_clock , ARG_word_select , ARG_data , ARG_left_justified };
98
98
static const mp_arg_t allowed_args [] = {
@@ -115,9 +115,9 @@ STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_a
115
115
return MP_OBJ_FROM_PTR (self );
116
116
}
117
117
118
- //| def deinit(self, ) -> Any:
119
- //| """Deinitialises the I2SOut and releases any hardware resources for reuse."""
120
- //| ...
118
+ //|def deinit(self, ) -> Any:
119
+ //|"""Deinitialises the I2SOut and releases any hardware resources for reuse."""
120
+ //|...
121
121
STATIC mp_obj_t audiobusio_i2sout_deinit (mp_obj_t self_in ) {
122
122
audiobusio_i2sout_obj_t * self = MP_OBJ_TO_PTR (self_in );
123
123
common_hal_audiobusio_i2sout_deinit (self );
@@ -130,15 +130,15 @@ STATIC void check_for_deinit(audiobusio_i2sout_obj_t *self) {
130
130
raise_deinited_error ();
131
131
}
132
132
}
133
- //| def __enter__(self, ) -> Any:
134
- //| """No-op used by Context Managers."""
135
- //| ...
133
+ //|def __enter__(self, ) -> Any:
134
+ //|"""No-op used by Context Managers."""
135
+ //|...
136
136
// Provided by context manager helper.
137
137
138
- //| def __exit__(self, ) -> Any:
139
- //| """Automatically deinitializes the hardware when exiting a context. See
140
- //| :ref:`lifetime-and-contextmanagers` for more info."""
141
- //| ...
138
+ //|def __exit__(self, ) -> Any:
139
+ //|"""Automatically deinitializes the hardware when exiting a context. See
140
+ //|:ref:`lifetime-and-contextmanagers` for more info."""
141
+ //|...
142
142
STATIC mp_obj_t audiobusio_i2sout_obj___exit__ (size_t n_args , const mp_obj_t * args ) {
143
143
(void )n_args ;
144
144
common_hal_audiobusio_i2sout_deinit (args [0 ]);
@@ -147,14 +147,14 @@ STATIC mp_obj_t audiobusio_i2sout_obj___exit__(size_t n_args, const mp_obj_t *ar
147
147
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN (audiobusio_i2sout___exit___obj , 4 , 4 , audiobusio_i2sout_obj___exit__ );
148
148
149
149
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.
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.
153
153
//|
154
- //| Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, or `audiomixer.Mixer`.
154
+ //|Sample must be an `audiocore.WaveFile`, `audiocore.RawSample`, or `audiomixer.Mixer`.
155
155
//|
156
- //| The sample itself should consist of 8 bit or 16 bit samples."""
157
- //| ...
156
+ //|The sample itself should consist of 8 bit or 16 bit samples."""
157
+ //|...
158
158
STATIC mp_obj_t audiobusio_i2sout_obj_play (size_t n_args , const mp_obj_t * pos_args , mp_map_t * kw_args ) {
159
159
enum { ARG_sample , ARG_loop };
160
160
static const mp_arg_t allowed_args [] = {
@@ -173,9 +173,9 @@ STATIC mp_obj_t audiobusio_i2sout_obj_play(size_t n_args, const mp_obj_t *pos_ar
173
173
}
174
174
MP_DEFINE_CONST_FUN_OBJ_KW (audiobusio_i2sout_play_obj , 1 , audiobusio_i2sout_obj_play );
175
175
176
- //| def stop(self, ) -> Any:
177
- //| """Stops playback."""
178
- //| ...
176
+ //|def stop(self, ) -> Any:
177
+ //|"""Stops playback."""
178
+ //|...
179
179
STATIC mp_obj_t audiobusio_i2sout_obj_stop (mp_obj_t self_in ) {
180
180
audiobusio_i2sout_obj_t * self = MP_OBJ_TO_PTR (self_in );
181
181
check_for_deinit (self );
@@ -184,9 +184,9 @@ STATIC mp_obj_t audiobusio_i2sout_obj_stop(mp_obj_t self_in) {
184
184
}
185
185
MP_DEFINE_CONST_FUN_OBJ_1 (audiobusio_i2sout_stop_obj , audiobusio_i2sout_obj_stop );
186
186
187
- //| playing: Any =
188
- //| """True when the audio sample is being output. (read-only)"""
189
- //| ...
187
+ //|playing: Any =
188
+ //|"""True when the audio sample is being output. (read-only)"""
189
+ //|...
190
190
STATIC mp_obj_t audiobusio_i2sout_obj_get_playing (mp_obj_t self_in ) {
191
191
audiobusio_i2sout_obj_t * self = MP_OBJ_TO_PTR (self_in );
192
192
check_for_deinit (self );
@@ -201,9 +201,9 @@ const mp_obj_property_t audiobusio_i2sout_playing_obj = {
201
201
(mp_obj_t )& mp_const_none_obj },
202
202
};
203
203
204
- //| def pause(self, ) -> Any:
205
- //| """Stops playback temporarily while remembering the position. Use `resume` to resume playback."""
206
- //| ...
204
+ //|def pause(self, ) -> Any:
205
+ //|"""Stops playback temporarily while remembering the position. Use `resume` to resume playback."""
206
+ //|...
207
207
STATIC mp_obj_t audiobusio_i2sout_obj_pause (mp_obj_t self_in ) {
208
208
audiobusio_i2sout_obj_t * self = MP_OBJ_TO_PTR (self_in );
209
209
check_for_deinit (self );
@@ -216,9 +216,9 @@ STATIC mp_obj_t audiobusio_i2sout_obj_pause(mp_obj_t self_in) {
216
216
}
217
217
MP_DEFINE_CONST_FUN_OBJ_1 (audiobusio_i2sout_pause_obj , audiobusio_i2sout_obj_pause );
218
218
219
- //| def resume(self, ) -> Any:
220
- //| """Resumes sample playback after :py:func:`pause`."""
221
- //| ...
219
+ //|def resume(self, ) -> Any:
220
+ //|"""Resumes sample playback after :py:func:`pause`."""
221
+ //|...
222
222
STATIC mp_obj_t audiobusio_i2sout_obj_resume (mp_obj_t self_in ) {
223
223
audiobusio_i2sout_obj_t * self = MP_OBJ_TO_PTR (self_in );
224
224
check_for_deinit (self );
@@ -231,9 +231,9 @@ STATIC mp_obj_t audiobusio_i2sout_obj_resume(mp_obj_t self_in) {
231
231
}
232
232
MP_DEFINE_CONST_FUN_OBJ_1 (audiobusio_i2sout_resume_obj , audiobusio_i2sout_obj_resume );
233
233
234
- //| paused: Any =
235
- //| """True when playback is paused. (read-only)"""
236
- //| ...
234
+ //|paused: Any =
235
+ //|"""True when playback is paused. (read-only)"""
236
+ //|...
237
237
STATIC mp_obj_t audiobusio_i2sout_obj_get_paused (mp_obj_t self_in ) {
238
238
audiobusio_i2sout_obj_t * self = MP_OBJ_TO_PTR (self_in );
239
239
check_for_deinit (self );
0 commit comments