Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better synthio #7825

Merged
merged 22 commits into from
Apr 5, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions locale/circuitpython.pot
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ msgid "%q in %q must be of type %q, not %q"
msgstr ""

#: ports/espressif/common-hal/espulp/ULP.c
#: ports/mimxrt10xx/common-hal/audiobusio/__init__.c
#: ports/raspberrypi/common-hal/rp2pio/StateMachine.c
#: shared-bindings/digitalio/DigitalInOut.c
#: shared-bindings/microcontroller/Pin.c
Expand Down Expand Up @@ -192,6 +193,10 @@ msgstr ""
msgid "%q must be array of type 'H'"
msgstr ""

#: shared-bindings/synthio/MidiTrack.c shared-bindings/synthio/__init__.c
msgid "%q must be array of type 'h'"
msgstr ""

#: ports/raspberrypi/bindings/cyw43/__init__.c py/argcheck.c py/objexcept.c
#: shared-bindings/canio/CAN.c shared-bindings/digitalio/Pull.c
msgid "%q must be of type %q or %q, not %q"
Expand Down Expand Up @@ -1217,13 +1222,15 @@ msgstr ""
msgid "Interrupt error."
msgstr ""

#: ports/mimxrt10xx/common-hal/audiobusio/__init__.c
#: ports/mimxrt10xx/common-hal/pwmio/PWMOut.c py/argcheck.c
#: shared-bindings/digitalio/DigitalInOut.c
#: shared-bindings/displayio/EPaperDisplay.c
msgid "Invalid %q"
msgstr ""

#: ports/atmel-samd/common-hal/microcontroller/Pin.c
#: ports/mimxrt10xx/common-hal/microcontroller/Pin.c
#: shared-bindings/microcontroller/Pin.c
msgid "Invalid %q pin"
msgstr ""
Expand Down Expand Up @@ -3827,11 +3834,7 @@ msgstr ""
msgid "out must be a float dense array"
msgstr ""

#: shared-bindings/displayio/Bitmap.c
msgid "out of range of source"
msgstr ""

#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
#: shared-bindings/bitmaptools/__init__.c
msgid "out of range of target"
msgstr ""

Expand All @@ -3856,14 +3859,10 @@ msgstr ""
msgid "parameters must be registers in sequence r0 to r3"
msgstr ""

#: shared-bindings/bitmaptools/__init__.c shared-bindings/displayio/Bitmap.c
#: shared-bindings/bitmaptools/__init__.c
msgid "pixel coordinates out of bounds"
msgstr ""

#: shared-bindings/displayio/Bitmap.c
msgid "pixel value requires too many bits"
msgstr ""

#: shared-bindings/displayio/TileGrid.c shared-bindings/vectorio/VectorShape.c
msgid "pixel_shader must be displayio.Palette or displayio.ColorConverter"
msgstr ""
Expand Down Expand Up @@ -4276,10 +4275,6 @@ msgstr ""
msgid "value out of range of target"
msgstr ""

#: shared-bindings/displayio/Bitmap.c
msgid "value_count must be > 0"
msgstr ""

#: ports/espressif/common-hal/watchdog/WatchDogTimer.c
msgid "watchdog not initialized"
msgstr ""
Expand Down
2 changes: 2 additions & 0 deletions ports/atmel-samd/boards/pewpew_m4/mpconfigboard.mk
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ CIRCUITPY_AUDIOIO = 1
CIRCUITPY_AUDIOMIXER = 1
CIRCUITPY_DISPLAYIO = 1
CIRCUITPY_KEYPAD = 1
CIRCUITPY_KEYPAD_SHIFTREGISTERKEYS = 0
CIRCUITPY_KEYPAD_KEYMATRIX = 0
CIRCUITPY_MATH = 1
CIRCUITPY_STAGE = 1
CIRCUITPY_SYNTHIO = 1
Expand Down
1 change: 1 addition & 0 deletions ports/mimxrt10xx/mpconfigport.mk
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ CIRCUITPY_AUDIOIO = 0
CIRCUITPY_AUDIOMIXER = 1
CIRCUITPY_AUDIOMP3 = 1
CIRCUITPY_AUDIOPWMIO = 1
CIRCUITPY_SYNTHIO_MAX_CHANNELS = 12
CIRCUITPY_BUSDEVICE = 1
CIRCUITPY_COUNTIO = 0
CIRCUITPY_FREQUENCYIO = 0
Expand Down
18 changes: 17 additions & 1 deletion ports/unix/variants/coverage/mpconfigvariant.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,24 @@ SRC_BITMAP := \
displayio_min.c \
shared-bindings/aesio/aes.c \
shared-bindings/aesio/__init__.c \
shared-bindings/audiocore/__init__.c \
shared-bindings/audiocore/RawSample.c \
shared-bindings/audiocore/WaveFile.c \
shared-bindings/bitmaptools/__init__.c \
shared-bindings/displayio/Bitmap.c \
shared-bindings/rainbowio/__init__.c \
shared-bindings/struct/__init__.c \
shared-bindings/synthio/__init__.c \
shared-bindings/synthio/MidiTrack.c \
shared-bindings/synthio/Synthesizer.c \
shared-bindings/traceback/__init__.c \
shared-bindings/util.c \
shared-bindings/zlib/__init__.c \
shared-module/aesio/aes.c \
shared-module/aesio/__init__.c \
shared-module/audiocore/__init__.c \
shared-module/audiocore/RawSample.c \
shared-module/audiocore/WaveFile.c \
shared-module/bitmaptools/__init__.c \
shared-module/displayio/area.c \
shared-module/displayio/Bitmap.c \
Expand All @@ -47,19 +56,26 @@ SRC_BITMAP := \
shared-module/os/getenv.c \
shared-module/rainbowio/__init__.c \
shared-module/struct/__init__.c \
shared-module/synthio/__init__.c \
shared-module/synthio/MidiTrack.c \
shared-module/synthio/Synthesizer.c \
shared-module/traceback/__init__.c \
shared-module/zlib/__init__.c \

SRC_C += $(SRC_BITMAP)

CFLAGS += \
-DCIRCUITPY_AESIO=1 \
-DCIRCUITPY_AUDIOCORE=1 \
-DCIRCUITPY_AUDIOCORE_DEBUG=1 \
-DCIRCUITPY_BITMAPTOOLS=1 \
-DCIRCUITPY_DISPLAYIO_UNIX=1 \
-DCIRCUITPY_OS_GETENV=1 \
-DCIRCUITPY_GIFIO=1 \
-DCIRCUITPY_OS_GETENV=1 \
-DCIRCUITPY_RAINBOWIO=1 \
-DCIRCUITPY_STRUCT=1 \
-DCIRCUITPY_SYNTHIO=1 \
-DCIRCUITPY_SYNTHIO_MAX_CHANNELS=14 \
-DCIRCUITPY_TRACEBACK=1 \
-DCIRCUITPY_ZLIB=1

Expand Down
1 change: 1 addition & 0 deletions py/circuitpy_defns.mk
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,7 @@ SRC_SHARED_MODULE_ALL = \
supervisor/__init__.c \
supervisor/StatusBar.c \
synthio/MidiTrack.c \
synthio/Synthesizer.c \
synthio/__init__.c \
terminalio/Terminal.c \
terminalio/__init__.c \
Expand Down
18 changes: 18 additions & 0 deletions py/circuitpy_mpconfig.mk
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ CFLAGS += -DCIRCUITPY_AUDIOCORE=$(CIRCUITPY_AUDIOCORE)
CIRCUITPY_AUDIOMIXER ?= $(CIRCUITPY_AUDIOIO)
CFLAGS += -DCIRCUITPY_AUDIOMIXER=$(CIRCUITPY_AUDIOMIXER)

ifndef CIRCUITPY_AUDIOCORE_DEBUG
CIRCUITPY_AUDIOCORE_DEBUG ?= 0
endif
CFLAGS += -DCIRCUITPY_AUDIOCORE_DEBUG=$(CIRCUITPY_AUDIOCORE_DEBUG)

ifndef CIRCUITPY_AUDIOMP3
ifeq ($(CIRCUITPY_FULL_BUILD),1)
CIRCUITPY_AUDIOMP3 = $(CIRCUITPY_AUDIOCORE)
Expand Down Expand Up @@ -286,6 +291,15 @@ CFLAGS += -DCIRCUITPY_JSON=$(CIRCUITPY_JSON)
CIRCUITPY_KEYPAD ?= $(CIRCUITPY_FULL_BUILD)
CFLAGS += -DCIRCUITPY_KEYPAD=$(CIRCUITPY_KEYPAD)

CIRCUITPY_KEYPAD_KEYS ?= $(CIRCUITPY_KEYPAD)
CFLAGS += -DCIRCUITPY_KEYPAD_KEYS=$(CIRCUITPY_KEYPAD_KEYS)

CIRCUITPY_KEYPAD_KEYMATRIX ?= $(CIRCUITPY_KEYPAD)
CFLAGS += -DCIRCUITPY_KEYPAD_KEYMATRIX=$(CIRCUITPY_KEYPAD_KEYMATRIX)

CIRCUITPY_KEYPAD_SHIFTREGISTERKEYS ?= $(CIRCUITPY_KEYPAD)
CFLAGS += -DCIRCUITPY_KEYPAD_SHIFTREGISTERKEYS=$(CIRCUITPY_KEYPAD_SHIFTREGISTERKEYS)

CIRCUITPY_MATH ?= 1
CFLAGS += -DCIRCUITPY_MATH=$(CIRCUITPY_MATH)

Expand Down Expand Up @@ -437,6 +451,10 @@ CFLAGS += -DCIRCUITPY_SUPERVISOR=$(CIRCUITPY_SUPERVISOR)
CIRCUITPY_SYNTHIO ?= $(CIRCUITPY_AUDIOCORE)
CFLAGS += -DCIRCUITPY_SYNTHIO=$(CIRCUITPY_SYNTHIO)

CIRCUITPY_SYNTHIO_MAX_CHANNELS ?= 2
CFLAGS += -DCIRCUITPY_SYNTHIO_MAX_CHANNELS=$(CIRCUITPY_SYNTHIO_MAX_CHANNELS)


CIRCUITPY_SYS ?= 1
CFLAGS += -DCIRCUITPY_SYS=$(CIRCUITPY_SYS)

Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/audiobusio/I2SOut.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
//| ...
STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
#if !CIRCUITPY_AUDIOBUSIO_I2SOUT
mp_raise_NotImplementedError(translate("I2SOut not available"));
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_I2SOut);
return NULL; // Not reachable.
#else
enum { ARG_bit_clock, ARG_word_select, ARG_data, ARG_left_justified };
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/audiobusio/PDMIn.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
//| ...
STATIC mp_obj_t audiobusio_pdmin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
#if !CIRCUITPY_AUDIOBUSIO_PDMIN
mp_raise_NotImplementedError(translate("PDMIn not available"));
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_PDMIn);
#else
enum { ARG_clock_pin, ARG_data_pin, ARG_sample_rate, ARG_bit_depth, ARG_mono, ARG_oversample, ARG_startup_delay };
static const mp_arg_t allowed_args[] = {
Expand Down
2 changes: 1 addition & 1 deletion shared-bindings/audiocore/RawSample.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
//| def __init__(
//| self, buffer: ReadableBuffer, *, channel_count: int = 1, sample_rate: int = 8000
//| ) -> None:
//| """Create a RawSample based on the given buffer of signed values. If channel_count is more than
//| """Create a RawSample based on the given buffer of values. If channel_count is more than
//| 1 then each channel's samples should alternate. In other words, for a two channel buffer, the
//| first sample will be for channel 1, the second sample will be for channel two, the third for
//| channel 1 and so on.
Expand Down
1 change: 1 addition & 0 deletions shared-bindings/audiocore/WaveFile.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "shared-bindings/audiocore/WaveFile.h"
#include "shared-bindings/util.h"
#include "supervisor/shared/translate/translate.h"
#include "extmod/vfs_posix.h"

//| class WaveFile:
//| """Load a wave file for audio playback
Expand Down
48 changes: 47 additions & 1 deletion shared-bindings/audiocore/__init__.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,64 @@
#include "py/obj.h"
#include "py/runtime.h"

#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/audiocore/__init__.h"
#include "shared-bindings/audiocore/RawSample.h"
#include "shared-bindings/audiocore/WaveFile.h"
// #include "shared-bindings/audiomixer/Mixer.h"

//| """Support for audio samples"""

#if CIRCUITPY_AUDIOCORE_DEBUG
// (no docstrings so that the debug functions are not shown on docs.circuitpython.org)
STATIC mp_obj_t audiocore_get_buffer(mp_obj_t sample_in) {
uint8_t *buffer = NULL;
uint32_t buffer_length = 0;
audioio_get_buffer_result_t gbr = audiosample_get_buffer(sample_in, false, 0, &buffer, &buffer_length);

mp_obj_t result[2] = {mp_obj_new_int_from_uint(gbr), mp_const_none};

if (gbr != GET_BUFFER_ERROR) {
// copies the data because the gc semantics of get_buffer are unclear
result[1] = mp_obj_new_bytes(buffer, buffer_length);
}

return mp_obj_new_tuple(2, result);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(audiocore_get_buffer_obj, audiocore_get_buffer);

STATIC mp_obj_t audiocore_get_structure(mp_obj_t sample_in) {
bool single_buffer, samples_signed;
uint32_t max_buffer_length;
uint8_t spacing;

audiosample_get_buffer_structure(sample_in, false, &single_buffer, &samples_signed, &max_buffer_length, &spacing);
mp_obj_t result[4] = {
mp_obj_new_int_from_uint(single_buffer),
mp_obj_new_int_from_uint(samples_signed),
mp_obj_new_int_from_uint(max_buffer_length),
mp_obj_new_int_from_uint(spacing),
};
return mp_obj_new_tuple(4, result);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(audiocore_get_structure_obj, audiocore_get_structure);

STATIC mp_obj_t audiocore_reset_buffer(mp_obj_t sample_in) {
audiosample_reset_buffer(sample_in, false, 0);
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(audiocore_reset_buffer_obj, audiocore_reset_buffer);

#endif

STATIC const mp_rom_map_elem_t audiocore_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_audiocore) },
{ MP_ROM_QSTR(MP_QSTR_RawSample), MP_ROM_PTR(&audioio_rawsample_type) },
{ MP_ROM_QSTR(MP_QSTR_WaveFile), MP_ROM_PTR(&audioio_wavefile_type) },
#if CIRCUITPY_AUDIOCORE_DEBUG
{ MP_ROM_QSTR(MP_QSTR_get_buffer), MP_ROM_PTR(&audiocore_get_buffer_obj) },
{ MP_ROM_QSTR(MP_QSTR_reset_buffer), MP_ROM_PTR(&audiocore_reset_buffer_obj) },
{ MP_ROM_QSTR(MP_QSTR_get_structure), MP_ROM_PTR(&audiocore_get_structure_obj) },
#endif
};

STATIC MP_DEFINE_CONST_DICT(audiocore_module_globals, audiocore_module_globals_table);
Expand Down
1 change: 0 additions & 1 deletion shared-bindings/audiomixer/Mixer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#ifndef MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOMIXER_MIXER_H
#define MICROPY_INCLUDED_SHARED_BINDINGS_AUDIOMIXER_MIXER_H

#include "common-hal/microcontroller/Pin.h"
#include "shared-module/audiomixer/Mixer.h"
#include "shared-bindings/audiocore/RawSample.h"

Expand Down
4 changes: 2 additions & 2 deletions shared-bindings/keypad/Event.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ STATIC mp_obj_t keypad_event_unary_op(mp_unary_op_t op, mp_obj_t self_in) {

STATIC void keypad_event_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
keypad_event_obj_t *self = MP_OBJ_TO_PTR(self_in);
mp_printf(print, "<Event: key_number %d %s>",
mp_printf(print, "<Event: key_number %d %q>",
common_hal_keypad_event_get_key_number(self),
common_hal_keypad_event_get_pressed(self) ? "pressed" : "released");
common_hal_keypad_event_get_pressed(self) ? MP_QSTR_pressed : MP_QSTR_released);
}

STATIC const mp_rom_map_elem_t keypad_event_locals_dict_table[] = {
Expand Down
10 changes: 10 additions & 0 deletions shared-bindings/keypad/KeyMatrix.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
//| ...

STATIC mp_obj_t keypad_keymatrix_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
#if CIRCUITPY_KEYPAD_KEYMATRIX
keypad_keymatrix_obj_t *self = m_new_obj(keypad_keymatrix_obj_t);
self->base.type = &keypad_keymatrix_type;
enum { ARG_row_pins, ARG_column_pins, ARG_columns_to_anodes, ARG_interval, ARG_max_events };
Expand Down Expand Up @@ -114,8 +115,13 @@ STATIC mp_obj_t keypad_keymatrix_make_new(const mp_obj_type_t *type, size_t n_ar

common_hal_keypad_keymatrix_construct(self, num_row_pins, row_pins_array, num_column_pins, column_pins_array, args[ARG_columns_to_anodes].u_bool, interval, max_events);
return MP_OBJ_FROM_PTR(self);
#else
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_KeyMatrix);

#endif
}

#if CIRCUITPY_KEYPAD_KEYMATRIX
//| def deinit(self) -> None:
//| """Stop scanning and release the pins."""
//| ...
Expand Down Expand Up @@ -228,9 +234,13 @@ STATIC const mp_rom_map_elem_t keypad_keymatrix_locals_dict_table[] = {

STATIC MP_DEFINE_CONST_DICT(keypad_keymatrix_locals_dict, keypad_keymatrix_locals_dict_table);

#endif

const mp_obj_type_t keypad_keymatrix_type = {
{ &mp_type_type },
.name = MP_QSTR_KeyMatrix,
.make_new = keypad_keymatrix_make_new,
#if CIRCUITPY_KEYPAD_KEYMATRIX
.locals_dict = (mp_obj_t)&keypad_keymatrix_locals_dict,
#endif
};
9 changes: 9 additions & 0 deletions shared-bindings/keypad/Keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
//| ...

STATIC mp_obj_t keypad_keys_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) {
#if CIRCUITPY_KEYPAD_KEYS
keypad_keys_obj_t *self = m_new_obj(keypad_keys_obj_t);
self->base.type = &keypad_keys_type;
enum { ARG_pins, ARG_value_when_pressed, ARG_pull, ARG_interval, ARG_max_events };
Expand Down Expand Up @@ -106,8 +107,13 @@ STATIC mp_obj_t keypad_keys_make_new(const mp_obj_type_t *type, size_t n_args, s
common_hal_keypad_keys_construct(self, num_pins, pins_array, value_when_pressed, args[ARG_pull].u_bool, interval, max_events);

return MP_OBJ_FROM_PTR(self);
#else
mp_raise_NotImplementedError_varg(translate("%q"), MP_QSTR_Keys);

#endif
}

#if CIRCUITPY_KEYPAD_KEYS
//| def deinit(self) -> None:
//| """Stop scanning and release the pins."""
//| ...
Expand Down Expand Up @@ -162,10 +168,13 @@ STATIC const mp_rom_map_elem_t keypad_keys_locals_dict_table[] = {
};

STATIC MP_DEFINE_CONST_DICT(keypad_keys_locals_dict, keypad_keys_locals_dict_table);
#endif

const mp_obj_type_t keypad_keys_type = {
{ &mp_type_type },
.name = MP_QSTR_Keys,
.make_new = keypad_keys_make_new,
#if CIRCUITPY_KEYPAD_KEYS
.locals_dict = (mp_obj_t)&keypad_keys_locals_dict,
#endif
};
Loading