File tree Expand file tree Collapse file tree 1 file changed +15
-9
lines changed
ports/raspberrypi/boards/mtm_computer Expand file tree Collapse file tree 1 file changed +15
-9
lines changed Original file line number Diff line number Diff line change 1212
1313// board.DAC() — factory function that constructs an mcp4822.MCP4822 with
1414// 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+
1518static 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 );
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 ;
2531}
2632MP_DEFINE_CONST_FUN_OBJ_0 (board_dac_obj , board_dac_factory );
2733
You can’t perform that action at this time.
0 commit comments