summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Epler <jepler@gmail.com>2021-03-07 12:51:47 -0600
committerJeff Epler <jepler@gmail.com>2021-03-07 12:51:47 -0600
commit32475ce98c2eaa13240fa24e713ce3d5df60afd9 (patch)
treef0404e025c4cfeb8689057eea9a5d26c1a6a1d0e
parentf1ada8e8800a6ac64ebf611ba292b0eb93345c8e (diff)
Automatically count EXTERNAL_FLASH_DEVICES (mk2)
Instead of counting words in make, which is slightly awful, notice that possible_devices is local to external_flash.c, so we can declare the array with an automatic bound, and then get the count as the element-count (MP_ARRAY_SIZE) of the array. Since EXTERNAL_FLASH_DEVICE_COUNT is no longer a global macro, switch a few sites to using EXTERNAL_FLASH_DEVICES in `#if` checks instead.
-rw-r--r--supervisor/flash.h2
-rw-r--r--supervisor/flash_root_pointers.h2
-rw-r--r--supervisor/shared/external_flash/external_flash.c3
-rw-r--r--supervisor/supervisor.mk3
4 files changed, 4 insertions, 6 deletions
diff --git a/supervisor/flash.h b/supervisor/flash.h
index cd69cbfa9..289c76c2d 100644
--- a/supervisor/flash.h
+++ b/supervisor/flash.h
@@ -31,7 +31,7 @@
#include "py/mpconfig.h"
-#ifdef EXTERNAL_FLASH_DEVICE_COUNT
+#ifdef EXTERNAL_FLASH_DEVICES
#include "supervisor/shared/external_flash/external_flash.h"
#else
#include "supervisor/shared/internal_flash.h"
diff --git a/supervisor/flash_root_pointers.h b/supervisor/flash_root_pointers.h
index 634ae58d3..a426b9c4e 100644
--- a/supervisor/flash_root_pointers.h
+++ b/supervisor/flash_root_pointers.h
@@ -26,7 +26,7 @@
#ifndef MICROPY_INCLUDED_SUPERVISOR_FLASH_ROOT_POINTERS_H
#define MICROPY_INCLUDED_SUPERVISOR_FLASH_ROOT_POINTERS_H
-#ifdef EXTERNAL_FLASH_DEVICE_COUNT
+#ifdef EXTERNAL_FLASH_DEVICES
#include "supervisor/shared/external_flash/external_flash_root_pointers.h"
#else
#include "supervisor/internal_flash_root_pointers.h"
diff --git a/supervisor/shared/external_flash/external_flash.c b/supervisor/shared/external_flash/external_flash.c
index e2d767235..23727e7e7 100644
--- a/supervisor/shared/external_flash/external_flash.c
+++ b/supervisor/shared/external_flash/external_flash.c
@@ -45,7 +45,8 @@
// The currently cached sector in the cache, ram or flash based.
static uint32_t current_sector;
-const external_flash_device possible_devices[EXTERNAL_FLASH_DEVICE_COUNT] = {EXTERNAL_FLASH_DEVICES};
+STATIC const external_flash_device possible_devices[] = {EXTERNAL_FLASH_DEVICES};
+#define EXTERNAL_FLASH_DEVICE_COUNT MP_ARRAY_SIZE(possible_devices)
static const external_flash_device* flash_device = NULL;
diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk
index f94bccd9a..083e7fb35 100644
--- a/supervisor/supervisor.mk
+++ b/supervisor/supervisor.mk
@@ -33,10 +33,7 @@ endif
# (Right now INTERNAL_FLASH_FILESYSTEM and (Q)SPI_FLASH_FILESYSTEM are mutually exclusive.
# But that might not be true in the future.)
ifdef EXTERNAL_FLASH_DEVICES
- COMMA := ,
- EXTERNAL_FLASH_DEVICE_COUNT := $(words $(subst $(COMMA), ,$(EXTERNAL_FLASH_DEVICES)))
CFLAGS += -DEXTERNAL_FLASH_DEVICES=$(EXTERNAL_FLASH_DEVICES) \
- -DEXTERNAL_FLASH_DEVICE_COUNT=$(EXTERNAL_FLASH_DEVICE_COUNT)
SRC_SUPERVISOR += supervisor/shared/external_flash/external_flash.c
ifeq ($(SPI_FLASH_FILESYSTEM),1)