1010#include "mpconfigboard.h"
1111#include "py/runtime.h"
1212
13+ #if CIRCUITPY_OS_GETENV && CIRCUITPY_SET_DISPLAY_LIMIT
14+ #include "shared-module/os/__init__.h"
15+ #endif
16+
1317#if CIRCUITPY_BUSIO
1418#include "shared-bindings/busio/I2C.h"
1519#include "shared-bindings/busio/SPI.h"
@@ -172,12 +176,22 @@ mp_obj_t common_hal_board_create_uart(const mp_int_t instance) {
172176#endif
173177
174178void reset_board_buses (void ) {
179+ #if (CIRCUITPY_BOARD_I2C && CIRCUITPY_I2CDISPLAYBUS ) || (CIRCUITPY_BOARD_SPI && (CIRCUITPY_FOURWIRE || CIRCUITPY_SHARPDISPLAY || CIRCUITPY_AURORA_EPAPER ))
180+ mp_int_t max_num_displays = CIRCUITPY_DISPLAY_LIMIT ;
181+ #if CIRCUITPY_OS_GETENV && CIRCUITPY_SET_DISPLAY_LIMIT
182+ #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 );
184+ #else
185+ #define DYN_DISPLAY_BUSES (indx ) (display_buses[indx])
186+ #endif
187+ #endif
188+
175189 #if CIRCUITPY_BOARD_I2C
176190 for (uint8_t instance = 0 ; instance < CIRCUITPY_BOARD_I2C ; instance ++ ) {
177191 bool display_using_i2c = false;
178192 #if CIRCUITPY_I2CDISPLAYBUS
179- for (uint8_t i = 0 ; i < CIRCUITPY_DISPLAY_LIMIT ; i ++ ) {
180- if (display_buses [ i ] .bus_base .type == & i2cdisplaybus_i2cdisplaybus_type && display_buses [ i ] .i2cdisplay_bus .bus == & i2c_obj [instance ]) {
193+ for (uint8_t i = 0 ; i < max_num_displays ; i ++ ) {
194+ if (DYN_DISPLAY_BUSES ( i ) .bus_base .type == & i2cdisplaybus_i2cdisplaybus_type && DYN_DISPLAY_BUSES ( i ) .i2cdisplay_bus .bus == & i2c_obj [instance ]) {
181195 display_using_i2c = true;
182196 break ;
183197 }
@@ -197,22 +211,22 @@ void reset_board_buses(void) {
197211 for (uint8_t instance = 0 ; instance < CIRCUITPY_BOARD_SPI ; instance ++ ) {
198212 bool display_using_spi = false;
199213 #if CIRCUITPY_FOURWIRE || CIRCUITPY_SHARPDISPLAY || CIRCUITPY_AURORA_EPAPER
200- for (uint8_t i = 0 ; i < CIRCUITPY_DISPLAY_LIMIT ; i ++ ) {
201- mp_const_obj_t bus_type = display_buses [ i ] .bus_base .type ;
214+ for (uint8_t i = 0 ; i < max_num_displays ; i ++ ) {
215+ mp_const_obj_t bus_type = DYN_DISPLAY_BUSES ( i ) .bus_base .type ;
202216 #if CIRCUITPY_FOURWIRE
203- if (bus_type == & fourwire_fourwire_type && display_buses [ i ] .fourwire_bus .bus == & spi_obj [instance ]) {
217+ if (bus_type == & fourwire_fourwire_type && DYN_DISPLAY_BUSES ( i ) .fourwire_bus .bus == & spi_obj [instance ]) {
204218 display_using_spi = true;
205219 break ;
206220 }
207221 #endif
208222 #if CIRCUITPY_SHARPDISPLAY
209- if (bus_type == & sharpdisplay_framebuffer_type && display_buses [ i ] .sharpdisplay .bus == & spi_obj [instance ]) {
223+ if (bus_type == & sharpdisplay_framebuffer_type && DYN_DISPLAY_BUSES ( i ) .sharpdisplay .bus == & spi_obj [instance ]) {
210224 display_using_spi = true;
211225 break ;
212226 }
213227 #endif
214228 #if CIRCUITPY_AURORA_EPAPER
215- if (bus_type == & aurora_epaper_framebuffer_type && display_buses [ i ] .aurora_epaper .bus == & spi_obj [instance ]) {
229+ if (bus_type == & aurora_epaper_framebuffer_type && DYN_DISPLAY_BUSES ( i ) .aurora_epaper .bus == & spi_obj [instance ]) {
216230 display_using_spi = true;
217231 break ;
218232 }
0 commit comments