Merge branch 'main' of https://github.com/adafruit/circuitpython into arduino-nano-esp32s3

This commit is contained in:
Melissa LeBlanc-Williams 2023-07-24 08:47:15 -07:00
commit a134eebefb
30 changed files with 276 additions and 111 deletions

@ -1 +1 @@
Subproject commit f1e006d09bd32088ab421d0b519eb89c531eda4e
Subproject commit 6c7c9f2ef5a80d5a6879e9c3558162188c6cf889

View File

@ -6,7 +6,7 @@ msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-01-04 12:55-0600\n"
"PO-Revision-Date: 2023-07-10 14:50+0000\n"
"PO-Revision-Date: 2023-07-19 21:06+0000\n"
"Last-Translator: Luc <some_physics@live.com>\n"
"Language: de_DE\n"
"MIME-Version: 1.0\n"
@ -487,7 +487,7 @@ msgstr "Alle Kanäle werden verwendet"
#: ports/raspberrypi/common-hal/usb_host/Port.c
msgid "All dma channels in use"
msgstr ""
msgstr "All DMA-Kanäle in Verwendung"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
msgid "All event channels in use"

View File

@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2023-05-23 22:55+0000\n"
"PO-Revision-Date: 2023-07-19 21:06+0000\n"
"Last-Translator: Andi Chandler <andi@gowling.com>\n"
"Language-Team: none\n"
"Language: en_GB\n"
@ -15,7 +15,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 4.18-dev\n"
"X-Generator: Weblate 5.0-dev\n"
#: main.c
msgid ""
@ -486,7 +486,7 @@ msgstr "All channels in use"
#: ports/raspberrypi/common-hal/usb_host/Port.c
msgid "All dma channels in use"
msgstr ""
msgstr "All DMA channels in use"
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
msgid "All event channels in use"
@ -1378,7 +1378,7 @@ msgstr "Mismatched swap flag"
#: ports/mimxrt10xx/common-hal/busio/SPI.c
msgid "Missing MISO or MOSI Pin"
msgstr "Missing MISO or MOSI pin"
msgstr "Missing MISO or MOSI Pin"
#: ports/stm/common-hal/busio/SPI.c
msgid "Missing MISO or MOSI pin"
@ -1493,7 +1493,7 @@ msgstr "No IP"
#: ports/espressif/common-hal/busio/SPI.c
#: ports/mimxrt10xx/common-hal/busio/SPI.c
msgid "No MISO Pin"
msgstr "No MISO pin"
msgstr "No MISO Pin"
#: ports/stm/common-hal/busio/SPI.c shared-module/bitbangio/SPI.c
msgid "No MISO pin"
@ -1502,7 +1502,7 @@ msgstr "No MISO pin"
#: ports/espressif/common-hal/busio/SPI.c
#: ports/mimxrt10xx/common-hal/busio/SPI.c
msgid "No MOSI Pin"
msgstr "No MOSI pin"
msgstr "No MOSI Pin"
#: ports/stm/common-hal/busio/SPI.c shared-module/bitbangio/SPI.c
msgid "No MOSI pin"

View File

@ -7,7 +7,7 @@ msgstr ""
"Project-Id-Version: circuitpython-cn\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-01-04 12:55-0600\n"
"PO-Revision-Date: 2023-07-16 04:32+0000\n"
"PO-Revision-Date: 2023-07-21 00:10+0000\n"
"Last-Translator: hexthat <hexthat@gmail.com>\n"
"Language-Team: Chinese Hanyu Pinyin\n"
"Language: zh_Latn_pinyin\n"
@ -1641,7 +1641,7 @@ msgstr "Bù zhīchí jīshù"
#: supervisor/shared/bluetooth/bluetooth.c
msgid "Off"
msgstr "guānbì"
msgstr "Guānbì"
#: supervisor/shared/bluetooth/bluetooth.c
msgid "Ok"
@ -3286,7 +3286,7 @@ msgstr "bù zhèngquè de tiánchōng"
#: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/transform.c
msgid "index is out of bounds"
msgstr "suǒyǐn chāochū fànwéi"
msgstr "suǒyǐn yuèjiè"
#: shared-bindings/_pixelmap/PixelMap.c
msgid "index must be tuple or int"

View File

@ -12,6 +12,7 @@ LONGINT_IMPL = MPZ
# No I2S on SAMD51G
CIRCUITPY_AUDIOBUSIO = 0
CIRCUITPY_SYNTHIO = 0
CIRCUITPY_BITBANG_APA102 = 1

View File

@ -34,8 +34,9 @@
#define MICROPY_HW_LED_STATUS (&pin_GPIO13)
#define DEFAULT_I2C_BUS_SCL (&pin_GPIO9)
#define DEFAULT_I2C_BUS_SDA (&pin_GPIO8)
#define CIRCUITPY_BOARD_I2C (2)
#define CIRCUITPY_BOARD_I2C_PIN {{.scl = &pin_GPIO9, .sda = &pin_GPIO8}, \
{.scl = &pin_GPIO15, .sda = &pin_GPIO16}}
#define DEFAULT_SPI_BUS_SCK (&pin_GPIO36)
#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO35)

View File

@ -1,5 +1,7 @@
#include "shared-bindings/board/__init__.h"
CIRCUITPY_BOARD_BUS_SINGLETON(stemma_i2c, i2c, 1)
STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
@ -89,11 +91,16 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO11) },
{ MP_ROM_QSTR(MP_QSTR_A10), MP_ROM_PTR(&pin_GPIO11) },
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO13) }, // Blue LED
// Blue LED
{ MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO13) },
// STEMMA QT Vertical Connector I2C IO
{ MP_ROM_QSTR(MP_QSTR_IO15), MP_ROM_PTR(&pin_GPIO15) },
{ MP_ROM_QSTR(MP_QSTR_SCL2), MP_ROM_PTR(&pin_GPIO15) },
{ MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) },
{ MP_ROM_QSTR(MP_QSTR_SDA2), MP_ROM_PTR(&pin_GPIO16) },
// Battery voltage sense pin
// I really don't know what name to use here. Adafruit use BATTERY & VOLTAGE_MONITOR
// I prefer VBAT or VBAT_SENSE
{ MP_ROM_QSTR(MP_QSTR_BATTERY), MP_ROM_PTR(&pin_GPIO2) },
{ MP_ROM_QSTR(MP_QSTR_VBAT), MP_ROM_PTR(&pin_GPIO2) },
{ MP_ROM_QSTR(MP_QSTR_VBAT_SENSE), MP_ROM_PTR(&pin_GPIO2) },
@ -103,18 +110,29 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_VBUS), MP_ROM_PTR(&pin_GPIO34) },
{ MP_ROM_QSTR(MP_QSTR_VBUS_SENSE), MP_ROM_PTR(&pin_GPIO34) },
// Neopixel pins
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL_POWER), MP_ROM_PTR(&pin_GPIO39) },
{ MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO40) },
{ MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) }, // Ambient Light Sensor
{ MP_ROM_QSTR(MP_QSTR_AMB), MP_ROM_PTR(&pin_GPIO4) }, // Ambient Light Sensor
// Ambient Light Sensor
{ MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) },
{ MP_ROM_QSTR(MP_QSTR_AMB), MP_ROM_PTR(&pin_GPIO4) },
{ MP_ROM_QSTR(MP_QSTR_LDO2), MP_ROM_PTR(&pin_GPIO39) }, // Second LDO Enable control
{ MP_ROM_QSTR(MP_QSTR_IO39), MP_ROM_PTR(&pin_GPIO39) }, // Second LDO Enable control
// Second LDO Enable control
{ MP_ROM_QSTR(MP_QSTR_LDO2), MP_ROM_PTR(&pin_GPIO39) },
{ MP_ROM_QSTR(MP_QSTR_IO39), MP_ROM_PTR(&pin_GPIO39) },
// I2C
{ MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_STEMMA_I2C), MP_ROM_PTR(&board_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_STEMMA_VERTICAL_I2C), MP_ROM_PTR(&board_stemma_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_STEMMA_I2C2), MP_ROM_PTR(&board_stemma_i2c_obj) },
{ MP_ROM_QSTR(MP_QSTR_I2C2), MP_ROM_PTR(&board_stemma_i2c_obj) },
// SPI
{ MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&board_spi_obj) },
// UART
{ MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&board_uart_obj) },
};
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

View File

@ -28,6 +28,8 @@
#include "supervisor/board.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/usb_host/Port.h"
// These pins should never ever be reset; doing so could interfere with basic operation.
// Used in common-hal/microcontroller/Pin.c
const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = {
@ -55,4 +57,8 @@ const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = {
NULL, // Must end in NULL.
};
void board_init(void) {
common_hal_usb_host_port_construct(&pin_USB_OTG2_DP, &pin_USB_OTG2_DN);
}
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

View File

@ -28,6 +28,8 @@
#include "supervisor/board.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/usb_host/Port.h"
// These pins should never ever be reset; doing so could interfere with basic operation.
// Used in common-hal/microcontroller/Pin.c
const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = {
@ -52,7 +54,11 @@ const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = {
// USB Pins
&pin_GPIO_AD_B0_01, // ID Pin
&pin_GPIO_AD_B0_03, // OC/Fault Pin
NULL, // Must end in NULL.
NULL, // Must end in NULL.
};
void board_init(void) {
common_hal_usb_host_port_construct(&pin_USB_OTG2_DP, &pin_USB_OTG2_DN);
}
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

View File

@ -28,6 +28,8 @@
#include "supervisor/board.h"
#include "shared-bindings/microcontroller/Pin.h"
#include "shared-bindings/usb_host/Port.h"
// These pins should never ever be reset; doing so could interfere with basic operation.
// Used in common-hal/microcontroller/Pin.c
const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = {
@ -54,4 +56,8 @@ const mcu_pin_obj_t *mimxrt10xx_reset_forbidden_pins[] = {
NULL, // Must end in NULL.
};
void board_init(void) {
common_hal_usb_host_port_construct(&pin_USB_OTG2_DP, &pin_USB_OTG2_DN);
}
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

View File

@ -29,9 +29,13 @@
#include "py/runtime.h"
bool usb_host_init;
#include "tusb.h"
void common_hal_usb_host_port_construct(usb_host_port_obj_t *self, const mcu_pin_obj_t *dp, const mcu_pin_obj_t *dm) {
#include "imx_usb.h"
usb_host_port_obj_t usb_host_instance;
usb_host_port_obj_t *common_hal_usb_host_port_construct(const mcu_pin_obj_t *dp, const mcu_pin_obj_t *dm) {
const mcu_pin_obj_t *supported_dp;
const mcu_pin_obj_t *supported_dm;
if (CIRCUITPY_USB_HOST_INSTANCE == 0) {
@ -41,18 +45,27 @@ void common_hal_usb_host_port_construct(usb_host_port_obj_t *self, const mcu_pin
supported_dp = &pin_USB_OTG2_DP;
supported_dm = &pin_USB_OTG2_DN;
}
// Return the singleton if given the same pins.
usb_host_port_obj_t *self = &usb_host_instance;
if (self->dp != NULL) {
if (self->dp != dp || self->dm != dm) {
mp_raise_msg_varg(&mp_type_RuntimeError, translate("%q in use"), MP_QSTR_usb_host);
}
return self;
}
if (dp != supported_dp || dm != supported_dm) {
raise_ValueError_invalid_pins();
}
self->init = true;
usb_host_init = true;
}
void common_hal_usb_host_port_deinit(usb_host_port_obj_t *self) {
self->init = false;
usb_host_init = false;
}
assert_pin_free(dp);
assert_pin_free(dm);
bool common_hal_usb_host_port_deinited(usb_host_port_obj_t *self) {
return !self->init;
init_usb_instance(CIRCUITPY_USB_HOST_INSTANCE);
tuh_init(TUH_OPT_RHPORT);
self->base.type = &usb_host_port_type;
self->dp = dp;
self->dm = dm;
return self;
}

View File

@ -31,11 +31,8 @@
typedef struct {
mp_obj_base_t base;
bool init;
const mcu_pin_obj_t *dp;
const mcu_pin_obj_t *dm;
} usb_host_port_obj_t;
// Cheater state so that the usb module knows if it should return the TinyUSB
// state.
extern bool usb_host_init;
#endif // MICROPY_INCLUDED_MIMXRT10XX_COMMON_HAL_USB_HOST_PORT_H

View File

@ -0,0 +1,31 @@
/*
* This file is part of the Micro Python project, http://micropython.org/
*
* The MIT License (MIT)
*
* Copyright (c) 2022 Scott Shawcroft for Adafruit Industries
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#pragma once
// Provided by supervisor/usb.c that has a shared, non-port-specific header. So,
// just define it here.
void init_usb_instance(mp_int_t instance);

View File

@ -71,7 +71,7 @@ SECTIONS
. = ALIGN(4);
*(EXCLUDE_FILE(
*fsl_flexspi.o
*dcd_ci_hs.o
*cd_ci_hs.o
*ehci.o
*tusb_fifo.o
*usbd.o
@ -88,6 +88,9 @@ SECTIONS
/* Keep USB processing functions out of RAM because we don't know which will be used.
We try to only keep USB interrupt related functions. */
*dcd_ci_hs.o(.text.process_*_request .text.dcd_edpt* .text.dcd_init .text.dcd_set_address)
/* Move hcd_dcache* routines to RAM so that we don't cross execution from
the cache during cache maintenance. Weird things happen when we do. */
*hcd_ci_hs.o(.text.hcd_i*)
*usbd.o(.text.process_*_request .text.process_[gs]et* .text.tud_* .text.usbd_* .text.configuration_reset .text.invoke_*)
*ehci.o(.text.hcd_edpt* .text.hcd_setup* .text.ehci_init* .text.hcd_port* .text.hcd_device* .text.qtd_init* .text.list_remove*)

View File

@ -31,7 +31,9 @@
#include "supervisor/linker.h"
#include "supervisor/usb.h"
STATIC void init_usb_instance(mp_int_t instance) {
#include "imx_usb.h"
void init_usb_instance(mp_int_t instance) {
if (instance < 0) {
return;
}
@ -72,9 +74,6 @@ STATIC void init_usb_instance(mp_int_t instance) {
void init_usb_hardware(void) {
init_usb_instance(CIRCUITPY_USB_DEVICE_INSTANCE);
// We can't dynamically start the USB Host port at the moment, so do it
// up front.
init_usb_instance(CIRCUITPY_USB_HOST_INSTANCE);
}
// Provide the prototypes for the interrupt handlers. The iMX RT SDK doesn't.

View File

@ -31,7 +31,6 @@
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.
usb_host_port_obj_t _host_port;
digitalio_digitalinout_obj_t _host_power;
void board_init(void) {
@ -39,5 +38,5 @@ void board_init(void) {
common_hal_digitalio_digitalinout_never_reset(&_host_power);
common_hal_digitalio_digitalinout_switch_to_output(&_host_power, true, DRIVE_MODE_PUSH_PULL);
common_hal_usb_host_port_construct(&_host_port, &pin_GPIO16, &pin_GPIO17);
common_hal_usb_host_port_construct(&pin_GPIO16, &pin_GPIO17);
}

View File

@ -45,7 +45,7 @@
#include "supervisor/serial.h"
bool usb_host_init;
usb_host_port_obj_t usb_host_instance;
STATIC PIO pio_instances[2] = {pio0, pio1};
volatile bool _core1_ready = false;
@ -102,10 +102,23 @@ STATIC bool _has_program_room(uint8_t pio_index, uint8_t program_size) {
return pio_can_add_program(pio, &program_struct);
}
void common_hal_usb_host_port_construct(usb_host_port_obj_t *self, const mcu_pin_obj_t *dp, const mcu_pin_obj_t *dm) {
usb_host_port_obj_t *common_hal_usb_host_port_construct(const mcu_pin_obj_t *dp, const mcu_pin_obj_t *dm) {
if (dp->number + 1 != dm->number) {
raise_ValueError_invalid_pins();
}
usb_host_port_obj_t *self = &usb_host_instance;
// Return the singleton if given the same pins.
if (self->dp != NULL) {
if (self->dp != dp || self->dm != dm) {
mp_raise_msg_varg(&mp_type_RuntimeError, translate("%q in use"), MP_QSTR_usb_host);
}
return self;
}
assert_pin_free(dp);
assert_pin_free(dm);
pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG;
pio_cfg.skip_alarm_pool = true;
pio_cfg.pin_dp = dp->number;
@ -122,6 +135,10 @@ void common_hal_usb_host_port_construct(usb_host_port_obj_t *self, const mcu_pin
mp_raise_RuntimeError(translate("All dma channels in use"));
}
self->base.type = &usb_host_port_type;
self->dp = dp;
self->dm = dm;
PIO tx_pio = pio_instances[pio_cfg.pio_tx_num];
pio_cfg.sm_tx = pio_claim_unused_sm(tx_pio, false);
PIO rx_pio = pio_instances[pio_cfg.pio_rx_num];
@ -151,15 +168,5 @@ void common_hal_usb_host_port_construct(usb_host_port_obj_t *self, const mcu_pin
tuh_configure(TUH_OPT_RHPORT, TUH_CFGID_RPI_PIO_USB_CONFIGURATION, &pio_cfg);
tuh_init(TUH_OPT_RHPORT);
self->init = true;
usb_host_init = true;
}
void common_hal_usb_host_port_deinit(usb_host_port_obj_t *self) {
self->init = false;
usb_host_init = false;
}
bool common_hal_usb_host_port_deinited(usb_host_port_obj_t *self) {
return !self->init;
return self;
}

View File

@ -30,9 +30,6 @@
typedef struct {
mp_obj_base_t base;
bool init;
const mcu_pin_obj_t *dp;
const mcu_pin_obj_t *dm;
} usb_host_port_obj_t;
// Cheater state so that the usb module knows if it should return the TinyUSB
// state.
extern bool usb_host_init;

View File

@ -31,6 +31,7 @@
#include "py/binary.h"
#include "py/objproperty.h"
#include "py/runtime.h"
#include "py/enum.h"
#include "shared-bindings/util.h"
#include "shared-bindings/synthio/Biquad.h"
#include "shared-bindings/synthio/Synthesizer.h"
@ -256,7 +257,9 @@ MP_PROPERTY_GETTER(synthio_synthesizer_sample_rate_obj,
(mp_obj_t)&synthio_synthesizer_get_sample_rate_obj);
//| pressed: NoteSequence
//| """A sequence of the currently pressed notes (read-only property)"""
//| """A sequence of the currently pressed notes (read-only property).
//|
//| This does not include notes in the release phase of the envelope."""
//|
STATIC mp_obj_t synthio_synthesizer_obj_get_pressed(mp_obj_t self_in) {
synthio_synthesizer_obj_t *self = MP_OBJ_TO_PTR(self_in);
@ -268,6 +271,23 @@ MP_DEFINE_CONST_FUN_OBJ_1(synthio_synthesizer_get_pressed_obj, synthio_synthesiz
MP_PROPERTY_GETTER(synthio_synthesizer_pressed_obj,
(mp_obj_t)&synthio_synthesizer_get_pressed_obj);
//| def note_info(self, note: Note) -> Tuple[Optional[EnvelopeState], float]:
//| """Get info about a note's current envelope state
//|
//| If the note is currently playing (including in the release phase), the returned value gives the current envelope state and the current envelope value.
//|
//| If the note is not playing on this synthesizer, returns the tuple ``(None, 0.0)``."""
STATIC mp_obj_t synthio_synthesizer_obj_note_info(mp_obj_t self_in, mp_obj_t note) {
synthio_synthesizer_obj_t *self = MP_OBJ_TO_PTR(self_in);
check_for_deinit(self);
mp_float_t vol = MICROPY_FLOAT_CONST(0.0);
envelope_state_e state = common_hal_synthio_synthesizer_note_info(self, note, &vol);
return MP_OBJ_NEW_TUPLE(
cp_enum_find(&synthio_note_state_type, state),
mp_obj_new_float(vol));
}
MP_DEFINE_CONST_FUN_OBJ_2(synthio_synthesizer_note_info_obj, synthio_synthesizer_obj_note_info);
//| blocks: List[BlockInput]
//| """A list of blocks to advance whether or not they are associated with a playing note.
//|
@ -417,6 +437,7 @@ STATIC const mp_rom_map_elem_t synthio_synthesizer_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_sample_rate), MP_ROM_PTR(&synthio_synthesizer_sample_rate_obj) },
{ MP_ROM_QSTR(MP_QSTR_max_polyphony), MP_ROM_INT(CIRCUITPY_SYNTHIO_MAX_CHANNELS) },
{ MP_ROM_QSTR(MP_QSTR_pressed), MP_ROM_PTR(&synthio_synthesizer_pressed_obj) },
{ MP_ROM_QSTR(MP_QSTR_note_info), MP_ROM_PTR(&synthio_synthesizer_note_info_obj) },
{ MP_ROM_QSTR(MP_QSTR_blocks), MP_ROM_PTR(&synthio_synthesizer_blocks_obj) },
};
STATIC MP_DEFINE_CONST_DICT(synthio_synthesizer_locals_dict, synthio_synthesizer_locals_dict_table);

View File

@ -45,3 +45,4 @@ void common_hal_synthio_synthesizer_retrigger(synthio_synthesizer_obj_t *self, m
void common_hal_synthio_synthesizer_release_all(synthio_synthesizer_obj_t *self);
mp_obj_t common_hal_synthio_synthesizer_get_pressed_notes(synthio_synthesizer_obj_t *self);
mp_obj_t common_hal_synthio_synthesizer_get_blocks(synthio_synthesizer_obj_t *self);
envelope_state_e common_hal_synthio_synthesizer_note_info(synthio_synthesizer_obj_t *self, mp_obj_t note, mp_float_t *vol_out);

View File

@ -45,6 +45,32 @@
#include "shared-module/synthio/LFO.h"
//| class EnvelopeState:
//| ATTACK: EnvelopeState
//| """The note is in its attack phase"""
//| DECAY: EnvelopeState
//| """The note is in its decay phase"""
//| SUSTAIN: EnvelopeState
//| """The note is in its sustain phase"""
//| RELEASE: EnvelopeState
//| """The note is in its release phase"""
//|
MAKE_ENUM_VALUE(synthio_note_state_type, note_state, ATTACK, SYNTHIO_ENVELOPE_STATE_ATTACK);
MAKE_ENUM_VALUE(synthio_note_state_type, note_state, DECAY, SYNTHIO_ENVELOPE_STATE_DECAY);
MAKE_ENUM_VALUE(synthio_note_state_type, note_state, SUSTAIN, SYNTHIO_ENVELOPE_STATE_SUSTAIN);
MAKE_ENUM_VALUE(synthio_note_state_type, note_state, RELEASE, SYNTHIO_ENVELOPE_STATE_RELEASE);
MAKE_ENUM_MAP(synthio_note_state) {
MAKE_ENUM_MAP_ENTRY(note_state, ATTACK),
MAKE_ENUM_MAP_ENTRY(note_state, DECAY),
MAKE_ENUM_MAP_ENTRY(note_state, SUSTAIN),
MAKE_ENUM_MAP_ENTRY(note_state, RELEASE),
};
STATIC MP_DEFINE_CONST_DICT(synthio_note_state_locals_dict, synthio_note_state_locals_table);
MAKE_PRINTER(synthio, synthio_note_state);
MAKE_ENUM_TYPE(synthio, EnvelopeState, synthio_note_state);
#define default_attack_time (MICROPY_FLOAT_CONST(0.1))
#define default_decay_time (MICROPY_FLOAT_CONST(0.05))
#define default_release_time (MICROPY_FLOAT_CONST(0.2))
@ -316,6 +342,7 @@ STATIC const mp_rom_map_elem_t synthio_module_globals_table[] = {
{ MP_ROM_QSTR(MP_QSTR_MathOperation), MP_ROM_PTR(&synthio_math_operation_type) },
{ MP_ROM_QSTR(MP_QSTR_MidiTrack), MP_ROM_PTR(&synthio_miditrack_type) },
{ MP_ROM_QSTR(MP_QSTR_Note), MP_ROM_PTR(&synthio_note_type) },
{ MP_ROM_QSTR(MP_QSTR_EnvelopeState), MP_ROM_PTR(&synthio_note_state_type) },
{ MP_ROM_QSTR(MP_QSTR_LFO), MP_ROM_PTR(&synthio_lfo_type) },
{ MP_ROM_QSTR(MP_QSTR_Synthesizer), MP_ROM_PTR(&synthio_synthesizer_type) },
{ MP_ROM_QSTR(MP_QSTR_from_file), MP_ROM_PTR(&synthio_from_file_obj) },

View File

@ -29,10 +29,16 @@
#include "py/objnamedtuple.h"
#include "py/enum.h"
typedef enum {
SYNTHIO_ENVELOPE_STATE_ATTACK, SYNTHIO_ENVELOPE_STATE_DECAY,
SYNTHIO_ENVELOPE_STATE_SUSTAIN, SYNTHIO_ENVELOPE_STATE_RELEASE
} envelope_state_e;
typedef enum synthio_bend_mode_e {
SYNTHIO_BEND_MODE_STATIC, SYNTHIO_BEND_MODE_VIBRATO, SYNTHIO_BEND_MODE_SWEEP, SYNTHIO_BEND_MODE_SWEEP_IN
} synthio_bend_mode_t;
extern const mp_obj_type_t synthio_note_state_type;
extern const cp_enum_obj_t bend_mode_VIBRATO_obj;
extern const mp_obj_type_t synthio_bend_mode_type;
typedef struct synthio_synth synthio_synth_t;

View File

@ -35,59 +35,36 @@
//|
//| def __init__(self, dp: microcontroller.Pin, dm: microcontroller.Pin) -> None:
//| """Create a USB host port on the given pins. Access attached devices
//| through the `usb` module. Keep this object referenced while
//| interacting with devices, otherwise they will be disconnected.
//| through the `usb` module.
//|
//| The resulting object lives longer than the CircuitPython VM so that
//| USB devices such as keyboards can continue to be used. Subsequent
//| calls to this constructor will return the same object and *not*
//| reinitialize the USB host port. It will raise an exception when
//| given different arguments from the first successful call.
//|
//| :param ~microcontroller.Pin dp: The data plus pin
//| :param ~microcontroller.Pin dm: The data minus pin
//| """
//| ...
//|
STATIC mp_obj_t usb_host_port_make_new(const mp_obj_type_t *type,
size_t n_args, size_t n_kw, const mp_obj_t *args) {
// check number of arguments
mp_arg_check_num(n_args, n_kw, 2, 2, false);
const mcu_pin_obj_t *dp = validate_obj_is_free_pin(args[0], MP_QSTR_dp);
const mcu_pin_obj_t *dm = validate_obj_is_free_pin(args[1], MP_QSTR_dm);
const mcu_pin_obj_t *dp = validate_obj_is_pin(args[0], MP_QSTR_dp);
const mcu_pin_obj_t *dm = validate_obj_is_pin(args[1], MP_QSTR_dm);
usb_host_port_obj_t *self = m_new_obj(usb_host_port_obj_t);
self->base.type = &usb_host_port_type;
common_hal_usb_host_port_construct(self, dp, dm);
// Pin in use checks happen in the implementation so they can be ignored
// when returning the singleton.
usb_host_port_obj_t *self = common_hal_usb_host_port_construct(dp, dm);
return (mp_obj_t)self;
}
//| def deinit(self) -> None:
//| """Turn off the USB host port and release the pins for other use."""
//| ...
STATIC mp_obj_t usb_host_port_obj_deinit(mp_obj_t self_in) {
usb_host_port_obj_t *self = MP_OBJ_TO_PTR(self_in);
common_hal_usb_host_port_deinit(self);
return mp_const_none;
}
MP_DEFINE_CONST_FUN_OBJ_1(usb_host_port_deinit_obj, usb_host_port_obj_deinit);
//| def __enter__(self) -> Port:
//| """No-op used by Context Managers."""
//| ...
// Provided by context manager helper.
//| def __exit__(self) -> None:
//| """Automatically deinitializes the hardware when exiting a context. See
//| :ref:`lifetime-and-contextmanagers` for more info."""
//| ...
//|
STATIC mp_obj_t usb_host_port_obj___exit__(size_t n_args, const mp_obj_t *args) {
(void)n_args;
common_hal_usb_host_port_deinit(MP_OBJ_TO_PTR(args[0]));
return mp_const_none;
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(usb_host_port_obj___exit___obj, 4, 4, usb_host_port_obj___exit__);
STATIC const mp_rom_map_elem_t usb_host_port_locals_dict_table[] = {
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&usb_host_port_deinit_obj) },
{ MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) },
{ MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&usb_host_port_obj___exit___obj) },
};
STATIC MP_DEFINE_CONST_DICT(usb_host_port_locals_dict, usb_host_port_locals_dict_table);

View File

@ -35,8 +35,10 @@
extern const mp_obj_type_t usb_host_port_type;
void common_hal_usb_host_port_construct(usb_host_port_obj_t *self, const mcu_pin_obj_t *dp, const mcu_pin_obj_t *dm);
void common_hal_usb_host_port_deinit(usb_host_port_obj_t *self);
bool common_hal_usb_host_port_deinited(usb_host_port_obj_t *self);
// This is unique to common_hal constructs because it returns a globally stored
// object instead of taking on in that may be on the heap. This allows the
// method to check the internals of the global object against the given arguments
// to determine whether to return the singleton or raise an exception.
usb_host_port_obj_t *common_hal_usb_host_port_construct(const mcu_pin_obj_t *dp, const mcu_pin_obj_t *dm);
#endif // MICROPY_INCLUDED_SHARED_BINDINGS_USB_HOST_PORT_H

View File

@ -185,6 +185,17 @@ mp_obj_t common_hal_synthio_synthesizer_get_pressed_notes(synthio_synthesizer_ob
return MP_OBJ_FROM_PTR(result);
}
envelope_state_e common_hal_synthio_synthesizer_note_info(synthio_synthesizer_obj_t *self, mp_obj_t note, mp_float_t *vol_out) {
for (int chan = 0; chan < CIRCUITPY_SYNTHIO_MAX_CHANNELS; chan++) {
if (self->synth.span.note_obj[chan] == note) {
*vol_out = self->synth.envelope_state[chan].level / 32767.;
return self->synth.envelope_state[chan].state;
}
}
return (envelope_state_e) - 1;
}
mp_obj_t common_hal_synthio_synthesizer_get_blocks(synthio_synthesizer_obj_t *self) {
return self->blocks;
}

View File

@ -35,6 +35,7 @@
#define SYNTHIO_FREQUENCY_SHIFT (16)
#include "shared-module/audiocore/__init__.h"
#include "shared-bindings/synthio/__init__.h"
typedef struct {
uint16_t dur;
@ -49,11 +50,6 @@ typedef struct {
uint16_t attack_level, sustain_level;
} synthio_envelope_definition_t;
typedef enum {
SYNTHIO_ENVELOPE_STATE_ATTACK, SYNTHIO_ENVELOPE_STATE_DECAY,
SYNTHIO_ENVELOPE_STATE_SUSTAIN, SYNTHIO_ENVELOPE_STATE_RELEASE
} envelope_state_e;
typedef struct {
int16_t level;
uint16_t substep;

View File

@ -152,7 +152,8 @@ extern "C" {
#endif
#define CFG_TUH_HID 2
#define CFG_TUH_HUB 1
// 2 hubs so we can support "7 port" hubs which have two internal hubs.
#define CFG_TUH_HUB 2
#define CFG_TUH_CDC 0
#define CFG_TUH_MSC 0
#define CFG_TUH_VENDOR 0

View File

@ -0,0 +1,17 @@
from synthio import Synthesizer, Note, Envelope
from audiocore import get_buffer
s = Synthesizer()
n = Note(440, envelope=Envelope())
print("{} {:.2f}".format(*s.note_info(n)))
s.press(n)
print("press")
for _ in range(9):
print("{} {:.2f}".format(*s.note_info(n)))
get_buffer(s)
s.release(n)
print("release")
for _ in range(11):
print("{} {:.2f}".format(*s.note_info(n)))
get_buffer(s)

View File

@ -0,0 +1,23 @@
None 0.00
press
synthio.EnvelopeState.ATTACK 0.23
synthio.EnvelopeState.ATTACK 0.46
synthio.EnvelopeState.ATTACK 0.70
synthio.EnvelopeState.ATTACK 0.93
synthio.EnvelopeState.DECAY 1.00
synthio.EnvelopeState.DECAY 0.91
synthio.EnvelopeState.DECAY 0.81
synthio.EnvelopeState.SUSTAIN 0.80
synthio.EnvelopeState.SUSTAIN 0.80
release
synthio.EnvelopeState.RELEASE 0.80
synthio.EnvelopeState.RELEASE 0.71
synthio.EnvelopeState.RELEASE 0.61
synthio.EnvelopeState.RELEASE 0.52
synthio.EnvelopeState.RELEASE 0.43
synthio.EnvelopeState.RELEASE 0.34
synthio.EnvelopeState.RELEASE 0.24
synthio.EnvelopeState.RELEASE 0.15
synthio.EnvelopeState.RELEASE 0.06
synthio.EnvelopeState.RELEASE 0.00
None 0.00

View File

@ -1,7 +1,6 @@
File cmdline/cmd_showbc.py, code block '<module>' (descriptor: \.\+, bytecode @\.\+ bytes)
Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+):
########
\.\+63
arg names:
(N_STATE 3)
(N_EXC_STACK 0)