Skip to content

Commit 0c27bd8

Browse files
committed
Add compile flag to remove code from smaller boards
1 parent 4c11d11 commit 0c27bd8

File tree

9 files changed

+44
-26
lines changed

9 files changed

+44
-26
lines changed

main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@ int __attribute__((used)) main(void) {
10511051
alarm_reset();
10521052
#endif
10531053

1054-
#if CIRCUITPY_DISPLAYIO && CIRCUITPY_OS_GETENV
1054+
#if CIRCUITPY_DISPLAYIO && CIRCUITPY_OS_GETENV && CIRCUITPY_SET_DISPLAY_LIMIT
10551055
// If number of displays has been overridden in settings.toml allocate memory and
10561056
// move existing displays
10571057
malloc_display_memory();

ports/atmel-samd/mpconfigport.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CIRCUITPY_OPTIMIZE_PROPERTY_FLASH_SIZE ?= 1
1212
CIRCUITPY_LTO = 1
1313

1414
CIRCUITPY_KEYPAD_DEMUX ?= 0
15+
CIRCUITPY_SET_DISPLAY_LIMIT ?= 0
1516

1617
######################################################################
1718
# Put samd21-only choices here.

ports/stm/boards/stm32f411ve_discovery/mpconfigboard.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ CIRCUITPY_BLEIO_HCI = 0
2222
CIRCUITPY_CODEOP = 0
2323
CIRCUITPY_MSGPACK = 0
2424
CIRCUITPY_VECTORIO = 0
25+
CIRCUITPY_SET_DISPLAY_LIMIT = 0

py/circuitpy_mpconfig.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ CFLAGS += -DCIRCUITPY_COUNTIO=$(CIRCUITPY_COUNTIO)
227227
CIRCUITPY_DISPLAYIO ?= $(CIRCUITPY_FULL_BUILD)
228228
CFLAGS += -DCIRCUITPY_DISPLAYIO=$(CIRCUITPY_DISPLAYIO)
229229

230+
CIRCUITPY_SET_DISPLAY_LIMIT ?= $(CIRCUITPY_DISPLAYIO)
231+
CFLAGS += -DCIRCUITPY_SET_DISPLAY_LIMIT=$(CIRCUITPY_SET_DISPLAY_LIMIT)
232+
230233
CIRCUITPY_BUSDISPLAY ?= $(CIRCUITPY_DISPLAYIO)
231234
CFLAGS += -DCIRCUITPY_BUSDISPLAY=$(CIRCUITPY_BUSDISPLAY)
232235

shared-module/board/__init__.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include "mpconfigboard.h"
1111
#include "py/runtime.h"
1212

13-
#if CIRCUITPY_OS_GETENV
13+
#if CIRCUITPY_OS_GETENV && CIRCUITPY_SET_DISPLAY_LIMIT
1414
#include "shared-module/os/__init__.h"
1515
#endif
1616

@@ -178,15 +178,12 @@ mp_obj_t common_hal_board_create_uart(const mp_int_t instance) {
178178
void reset_board_buses(void) {
179179
#if (CIRCUITPY_BOARD_I2C && CIRCUITPY_I2CDISPLAYBUS) || (CIRCUITPY_BOARD_SPI && (CIRCUITPY_FOURWIRE || CIRCUITPY_SHARPDISPLAY || CIRCUITPY_AURORA_EPAPER))
180180
mp_int_t max_num_displays = CIRCUITPY_DISPLAY_LIMIT;
181-
#if CIRCUITPY_OS_GETENV
181+
#if CIRCUITPY_OS_GETENV && CIRCUITPY_SET_DISPLAY_LIMIT
182182
#define DYN_DISPLAY_BUSES(indx) (indx < CIRCUITPY_DISPLAY_LIMIT ? display_buses[indx] : display_buses_dyn[indx - CIRCUITPY_DISPLAY_LIMIT])
183+
(void)common_hal_os_getenv_int("CIRCUITPY_DISPLAY_LIMIT", &max_num_displays);
183184
#else
184185
#define DYN_DISPLAY_BUSES(indx) (display_buses[indx])
185186
#endif
186-
187-
#if CIRCUITPY_OS_GETENV
188-
(void)common_hal_os_getenv_int("CIRCUITPY_DISPLAY_LIMIT", &max_num_displays);
189-
#endif
190187
#endif
191188

192189
#if CIRCUITPY_BOARD_I2C

shared-module/displayio/__init__.c

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#include "py/mpconfig.h"
2424

25-
#if CIRCUITPY_OS_GETENV
25+
#if CIRCUITPY_OS_GETENV && CIRCUITPY_SET_DISPLAY_LIMIT
2626
#include "shared-module/os/__init__.h"
2727
#endif
2828

@@ -54,7 +54,7 @@ static mp_int_t max_num_displays = CIRCUITPY_DISPLAY_LIMIT;
5454

5555
primary_display_bus_t display_buses[CIRCUITPY_DISPLAY_LIMIT];
5656
primary_display_t displays[CIRCUITPY_DISPLAY_LIMIT];
57-
#if CIRCUITPY_OS_GETENV
57+
#if CIRCUITPY_OS_GETENV && CIRCUITPY_SET_DISPLAY_LIMIT
5858
primary_display_bus_t *display_buses_dyn = &display_buses[0];
5959
primary_display_t *displays_dyn = &displays[0];
6060
#define DYN_DISPLAY_BUSES(indx) (indx < CIRCUITPY_DISPLAY_LIMIT ? display_buses[indx] : display_buses_dyn[indx - CIRCUITPY_DISPLAY_LIMIT])
@@ -159,13 +159,15 @@ static void common_hal_displayio_release_displays_impl(bool keep_primary) {
159159
release_framebufferdisplay(DYN_DISPLAYS_ADR(i, framebuffer_display));
160160
#endif
161161
}
162+
#if CIRCUITPY_OS_GETENV && CIRCUITPY_SET_DISPLAY_LIMIT
162163
if (i < CIRCUITPY_DISPLAY_LIMIT) {
163164
displays[i].display_base.type = &mp_type_NoneType;
164-
#if CIRCUITPY_OS_GETENV
165165
} else {
166166
displays_dyn[i - CIRCUITPY_DISPLAY_LIMIT].display_base.type = &mp_type_NoneType;
167-
#endif
168167
}
168+
#else
169+
displays[i].display_base.type = &mp_type_NoneType;
170+
#endif
169171
}
170172
for (uint8_t i = 0; i < max_num_displays; i++) {
171173
mp_const_obj_t bus_type = DYN_DISPLAY_BUSES(i).bus_base.type;
@@ -208,13 +210,15 @@ static void common_hal_displayio_release_displays_impl(bool keep_primary) {
208210
common_hal_picodvi_framebuffer_deinit(DYN_DISPLAY_BUSES_ADR(i, picodvi));
209211
#endif
210212
}
213+
#if CIRCUITPY_OS_GETENV && CIRCUITPY_SET_DISPLAY_LIMIT
211214
if (i < CIRCUITPY_DISPLAY_LIMIT) {
212215
display_buses[i].bus_base.type = &mp_type_NoneType;
213-
#if CIRCUITPY_OS_GETENV
214216
} else {
215217
display_buses_dyn[i - CIRCUITPY_DISPLAY_LIMIT].bus_base.type = &mp_type_NoneType;
216-
#endif
217218
}
219+
#else
220+
display_buses[i].bus_base.type = &mp_type_NoneType;
221+
#endif
218222
}
219223

220224
supervisor_stop_terminal();
@@ -225,7 +229,7 @@ void common_hal_displayio_release_displays(void) {
225229
}
226230

227231
void malloc_display_memory(void) {
228-
#if CIRCUITPY_OS_GETENV
232+
#if CIRCUITPY_OS_GETENV && CIRCUITPY_SET_DISPLAY_LIMIT
229233
(void)common_hal_os_getenv_int("CIRCUITPY_DISPLAY_LIMIT", &max_num_displays);
230234
if (max_num_displays > CIRCUITPY_DISPLAY_LIMIT) {
231235
display_buses_dyn = (primary_display_bus_t *)port_malloc(sizeof(primary_display_bus_t) * (max_num_displays - CIRCUITPY_DISPLAY_LIMIT), false);
@@ -470,13 +474,15 @@ primary_display_t *allocate_display(void) {
470474
// memset(DYN_DISPLAYS_ADR0(i), 0, sizeof(DYN_DISPLAYS(i)));
471475
memset(DYN_DISPLAYS_ADR0(i), 0, sizeof(displays[0]));
472476
// Default to None so that it works as board.DISPLAY.
477+
#if CIRCUITPY_OS_GETENV && CIRCUITPY_SET_DISPLAY_LIMIT
473478
if (i < CIRCUITPY_DISPLAY_LIMIT) {
474479
displays[i].display_base.type = &mp_type_NoneType;
475-
#if CIRCUITPY_OS_GETENV
476480
} else {
477481
displays_dyn[i - CIRCUITPY_DISPLAY_LIMIT].display_base.type = &mp_type_NoneType;
478-
#endif
479482
}
483+
#else
484+
displays[i].display_base.type = &mp_type_NoneType;
485+
#endif
480486
return DYN_DISPLAYS_ADR0(i);
481487
}
482488
}
@@ -498,13 +504,15 @@ primary_display_bus_t *allocate_display_bus(void) {
498504
// Clear this memory so it is in a known state before init.
499505
// memset(DYN_DISPLAY_BUSES_ADR0(i), 0, sizeof(DYN_DISPLAY_BUSES(i)));
500506
memset(DYN_DISPLAY_BUSES_ADR0(i), 0, sizeof(display_buses[0]));
507+
#if CIRCUITPY_OS_GETENV && CIRCUITPY_SET_DISPLAY_LIMIT
501508
if (i < CIRCUITPY_DISPLAY_LIMIT) {
502509
display_buses[i].bus_base.type = &mp_type_NoneType;
503-
#if CIRCUITPY_OS_GETENV
504510
} else {
505511
display_buses_dyn[i - CIRCUITPY_DISPLAY_LIMIT].bus_base.type = &mp_type_NoneType;
506-
#endif
507512
}
513+
#else
514+
display_buses[i].bus_base.type = &mp_type_NoneType;
515+
#endif
508516
return DYN_DISPLAY_BUSES_ADR0(i);
509517
}
510518
}

shared-module/displayio/__init__.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ typedef struct {
101101

102102
extern primary_display_bus_t display_buses[CIRCUITPY_DISPLAY_LIMIT];
103103
extern primary_display_t displays[CIRCUITPY_DISPLAY_LIMIT];
104-
#if CIRCUITPY_OS_GETENV
104+
#if CIRCUITPY_OS_GETENV && CIRCUITPY_SET_DISPLAY_LIMIT
105105
extern primary_display_bus_t *display_buses_dyn;
106106
extern primary_display_t *displays_dyn;
107107
#endif

shared-module/epaperdisplay/EPaperDisplay.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "supervisor/usb.h"
2121
#endif
2222

23-
#if CIRCUITPY_OS_GETENV
23+
#if CIRCUITPY_OS_GETENV && CIRCUITPY_SET_DISPLAY_LIMIT
2424
#include "shared-module/os/__init__.h"
2525
#endif
2626

@@ -507,35 +507,43 @@ void epaperdisplay_epaperdisplay_collect_ptrs(epaperdisplay_epaperdisplay_obj_t
507507
size_t maybe_refresh_epaperdisplay(void) {
508508
mp_int_t max_num_displays = CIRCUITPY_DISPLAY_LIMIT;
509509

510-
#if CIRCUITPY_OS_GETENV
510+
#if CIRCUITPY_OS_GETENV && CIRCUITPY_SET_DISPLAY_LIMIT
511511
(void)common_hal_os_getenv_int("CIRCUITPY_DISPLAY_LIMIT", &max_num_displays);
512512
#endif
513513

514514
for (uint8_t i = 0; i < max_num_displays; i++) {
515+
#if CIRCUITPY_OS_GETENV && CIRCUITPY_SET_DISPLAY_LIMIT
515516
if (i < CIRCUITPY_DISPLAY_LIMIT) {
516517
if (displays[i].epaper_display.base.type != &epaperdisplay_epaperdisplay_type ||
517518
displays[i].epaper_display.core.current_group != &circuitpython_splash) {
518519
// Skip regular displays and those not showing the splash.
519520
continue;
520521
}
521-
#if CIRCUITPY_OS_GETENV
522522
} else {
523523
if (displays_dyn[i - CIRCUITPY_DISPLAY_LIMIT].epaper_display.base.type != &epaperdisplay_epaperdisplay_type ||
524524
displays_dyn[i - CIRCUITPY_DISPLAY_LIMIT].epaper_display.core.current_group != &circuitpython_splash) {
525525
// Skip regular displays and those not showing the splash.
526526
continue;
527527
}
528-
#endif
529528
}
529+
#else
530+
if (displays[i].epaper_display.base.type != &epaperdisplay_epaperdisplay_type ||
531+
displays[i].epaper_display.core.current_group != &circuitpython_splash) {
532+
// Skip regular displays and those not showing the splash.
533+
continue;
534+
}
535+
#endif
530536

531537
epaperdisplay_epaperdisplay_obj_t *display;
538+
#if CIRCUITPY_OS_GETENV && CIRCUITPY_SET_DISPLAY_LIMIT
532539
if (i < CIRCUITPY_DISPLAY_LIMIT) {
533540
display = &displays[i].epaper_display;
534-
#if CIRCUITPY_OS_GETENV
535541
} else {
536542
display = &displays_dyn[i - CIRCUITPY_DISPLAY_LIMIT].epaper_display;
537-
#endif
538543
}
544+
#else
545+
display = &displays[i].epaper_display;
546+
#endif
539547
size_t time_to_refresh = common_hal_epaperdisplay_epaperdisplay_get_time_to_refresh(display);
540548
if (time_to_refresh > 0) {
541549
return time_to_refresh;

supervisor/shared/web_workflow/web_workflow.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1563,7 +1563,7 @@ static bool supervisor_filesystem_access_could_block(void) {
15631563
}
15641564

15651565
mp_int_t max_num_displays = CIRCUITPY_DISPLAY_LIMIT;
1566-
#if CIRCUITPY_OS_GETENV
1566+
#if CIRCUITPY_OS_GETENV && CIRCUITPY_SET_DISPLAY_LIMIT
15671567
(void)common_hal_os_getenv_int("CIRCUITPY_DISPLAY_LIMIT", &max_num_displays);
15681568
#define DYN_DISPLAY_BUSES(indx) (indx < CIRCUITPY_DISPLAY_LIMIT ? display_buses[indx] : display_buses_dyn[indx - CIRCUITPY_DISPLAY_LIMIT])
15691569
#define DYN_DISPLAY_BUSES_ADR(indx, membr) (indx < CIRCUITPY_DISPLAY_LIMIT ? &display_buses[indx].membr : &display_buses_dyn[indx - CIRCUITPY_DISPLAY_LIMIT].membr)

0 commit comments

Comments
 (0)