Skip to content

Commit c07f3fc

Browse files
authored
Merge pull request #10895 from todbot/mtm_computer_dac_audio
Add mcp4822 DAC module for audio streaming and mtm_computer updates
2 parents 31a9435 + 0f690b7 commit c07f3fc

File tree

31 files changed

+693
-2
lines changed

31 files changed

+693
-2
lines changed

locale/circuitpython.pot

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,7 @@ msgstr ""
625625

626626
#: ports/raspberrypi/common-hal/audiobusio/I2SOut.c
627627
#: ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c
628+
#: ports/raspberrypi/common-hal/mcp4822/MCP4822.c
628629
msgid "Audio source error"
629630
msgstr ""
630631

@@ -1300,6 +1301,7 @@ msgstr ""
13001301
msgid "Invalid %q"
13011302
msgstr ""
13021303

1304+
#: ports/raspberrypi/common-hal/mcp4822/MCP4822.c
13031305
#: ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2350.c
13041306
#: shared-module/aurora_epaper/aurora_framebuffer.c
13051307
msgid "Invalid %q and %q"
@@ -1537,6 +1539,7 @@ msgstr ""
15371539
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
15381540
#: ports/raspberrypi/common-hal/audiobusio/I2SOut.c
15391541
#: ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c
1542+
#: ports/raspberrypi/common-hal/mcp4822/MCP4822.c
15401543
msgid "No DMA channel found"
15411544
msgstr ""
15421545

@@ -1651,7 +1654,7 @@ msgid "Not connected"
16511654
msgstr ""
16521655

16531656
#: shared-bindings/audiobusio/I2SOut.c shared-bindings/audioio/AudioOut.c
1654-
#: shared-bindings/audiopwmio/PWMAudioOut.c
1657+
#: shared-bindings/audiopwmio/PWMAudioOut.c shared-bindings/mcp4822/MCP4822.c
16551658
msgid "Not playing"
16561659
msgstr ""
16571660

@@ -2168,6 +2171,7 @@ msgid "Too many channels in sample"
21682171
msgstr ""
21692172

21702173
#: ports/raspberrypi/common-hal/audiobusio/I2SOut.c
2174+
#: ports/raspberrypi/common-hal/mcp4822/MCP4822.c
21712175
msgid "Too many channels in sample."
21722176
msgstr ""
21732177

@@ -2266,6 +2270,7 @@ msgstr ""
22662270
#: ports/atmel-samd/common-hal/audioio/AudioOut.c
22672271
#: ports/raspberrypi/common-hal/audiobusio/I2SOut.c
22682272
#: ports/raspberrypi/common-hal/audiopwmio/PWMAudioOut.c
2273+
#: ports/raspberrypi/common-hal/mcp4822/MCP4822.c
22692274
msgid "Unable to allocate buffers for signed conversion"
22702275
msgstr ""
22712276

ports/raspberrypi/boards/mtm_computer/board.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,36 @@
55
// SPDX-License-Identifier: MIT
66

77
#include "supervisor/board.h"
8+
#include "shared-bindings/mcp4822/MCP4822.h"
9+
#include "shared-bindings/microcontroller/Pin.h"
10+
#include "peripherals/pins.h"
11+
#include "py/runtime.h"
812

13+
// board.DAC() — factory function that constructs an mcp4822.MCP4822 with
14+
// the MTM Workshop Computer's DAC pins (GP18=SCK, GP19=SDI, GP21=CS).
15+
16+
static mp_obj_t board_dac_singleton = MP_OBJ_NULL;
17+
18+
static mp_obj_t board_dac_factory(void) {
19+
if (board_dac_singleton == MP_OBJ_NULL) {
20+
mcp4822_mcp4822_obj_t *dac = mp_obj_malloc_with_finaliser(
21+
mcp4822_mcp4822_obj_t, &mcp4822_mcp4822_type);
22+
common_hal_mcp4822_mcp4822_construct(
23+
dac,
24+
&pin_GPIO18, // clock (SCK)
25+
&pin_GPIO19, // mosi (SDI)
26+
&pin_GPIO21, // cs
27+
1); // gain 1x
28+
board_dac_singleton = MP_OBJ_FROM_PTR(dac);
29+
}
30+
return board_dac_singleton;
31+
}
32+
MP_DEFINE_CONST_FUN_OBJ_0(board_dac_obj, board_dac_factory);
33+
34+
void board_deinit(void) {
35+
if (board_dac_singleton != MP_OBJ_NULL) {
36+
common_hal_mcp4822_mcp4822_deinit(MP_OBJ_TO_PTR(board_dac_singleton));
37+
board_dac_singleton = MP_OBJ_NULL;
38+
}
39+
}
940
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

ports/raspberrypi/boards/mtm_computer/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ"
1111
CIRCUITPY_AUDIOEFFECTS = 1
1212
CIRCUITPY_IMAGECAPTURE = 0
1313
CIRCUITPY_PICODVI = 0
14+
CIRCUITPY_MCP4822 = 1

ports/raspberrypi/boards/mtm_computer/pins.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
#include "shared-bindings/board/__init__.h"
88

9+
extern const mp_obj_fun_builtin_fixed_t board_dac_obj;
10+
911
static const mp_rom_map_elem_t board_module_globals_table[] = {
1012
CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS
1113

@@ -21,7 +23,6 @@ static const mp_rom_map_elem_t board_module_globals_table[] = {
2123
{ MP_ROM_QSTR(MP_QSTR_PULSE_2_IN), MP_ROM_PTR(&pin_GPIO3) },
2224
{ MP_ROM_QSTR(MP_QSTR_GP3), MP_ROM_PTR(&pin_GPIO3) },
2325

24-
2526
{ MP_ROM_QSTR(MP_QSTR_NORM_PROBE), MP_ROM_PTR(&pin_GPIO4) },
2627
{ MP_ROM_QSTR(MP_QSTR_GP4), MP_ROM_PTR(&pin_GPIO4) },
2728

@@ -105,6 +106,9 @@ static const mp_rom_map_elem_t board_module_globals_table[] = {
105106
{ MP_ROM_QSTR(MP_QSTR_A3), MP_ROM_PTR(&pin_GPIO29) },
106107
{ MP_ROM_QSTR(MP_QSTR_GP29), MP_ROM_PTR(&pin_GPIO29) },
107108

109+
// Factory function: dac = board.DAC() returns a configured mcp4822.MCP4822
110+
{ MP_ROM_QSTR(MP_QSTR_DAC), MP_ROM_PTR(&board_dac_obj) },
111+
108112
// { MP_ROM_QSTR(MP_QSTR_EEPROM_I2C), MP_ROM_PTR(&board_i2c_obj) },
109113
};
110114
MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table);

0 commit comments

Comments
 (0)