Skip to content

Commit 02675cb

Browse files
committed
rework mcp4822 module from mtm_hardware.DACOut
1 parent a5f9f3b commit 02675cb

15 files changed

Lines changed: 417 additions & 4946 deletions

File tree

locale/circuitpython.pot

Lines changed: 0 additions & 4579 deletions
This file was deleted.

ports/raspberrypi/boards/mtm_computer/board.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,24 @@
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"
12+
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+
static mp_obj_t board_dac_factory(void) {
16+
mcp4822_mcp4822_obj_t *dac = mp_obj_malloc_with_finaliser(
17+
mcp4822_mcp4822_obj_t, &mcp4822_mcp4822_type);
18+
common_hal_mcp4822_mcp4822_construct(
19+
dac,
20+
&pin_GPIO18, // clock (SCK)
21+
&pin_GPIO19, // mosi (SDI)
22+
&pin_GPIO21, // cs
23+
1); // gain 1x
24+
return MP_OBJ_FROM_PTR(dac);
25+
}
26+
MP_DEFINE_CONST_FUN_OBJ_0(board_dac_obj, board_dac_factory);
827

928
// Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here.

ports/raspberrypi/boards/mtm_computer/module/DACOut.h

Lines changed: 0 additions & 38 deletions
This file was deleted.

ports/raspberrypi/boards/mtm_computer/module/mtm_hardware.c

Lines changed: 0 additions & 276 deletions
This file was deleted.

ports/raspberrypi/boards/mtm_computer/mpconfigboard.mk

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,4 @@ EXTERNAL_FLASH_DEVICES = "W25Q16JVxQ"
1111
CIRCUITPY_AUDIOEFFECTS = 1
1212
CIRCUITPY_IMAGECAPTURE = 0
1313
CIRCUITPY_PICODVI = 0
14-
15-
SRC_C += \
16-
boards/$(BOARD)/module/mtm_hardware.c \
17-
boards/$(BOARD)/module/DACOut.c
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)