Skip to content

Commit 32475ce

Browse files
committed
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.
1 parent f1ada8e commit 32475ce

File tree

4 files changed

+4
-6
lines changed

4 files changed

+4
-6
lines changed

supervisor/flash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
#include "py/mpconfig.h"
3333

34-
#ifdef EXTERNAL_FLASH_DEVICE_COUNT
34+
#ifdef EXTERNAL_FLASH_DEVICES
3535
#include "supervisor/shared/external_flash/external_flash.h"
3636
#else
3737
#include "supervisor/shared/internal_flash.h"

supervisor/flash_root_pointers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#ifndef MICROPY_INCLUDED_SUPERVISOR_FLASH_ROOT_POINTERS_H
2727
#define MICROPY_INCLUDED_SUPERVISOR_FLASH_ROOT_POINTERS_H
2828

29-
#ifdef EXTERNAL_FLASH_DEVICE_COUNT
29+
#ifdef EXTERNAL_FLASH_DEVICES
3030
#include "supervisor/shared/external_flash/external_flash_root_pointers.h"
3131
#else
3232
#include "supervisor/internal_flash_root_pointers.h"

supervisor/shared/external_flash/external_flash.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
// The currently cached sector in the cache, ram or flash based.
4646
static uint32_t current_sector;
4747

48-
const external_flash_device possible_devices[EXTERNAL_FLASH_DEVICE_COUNT] = {EXTERNAL_FLASH_DEVICES};
48+
STATIC const external_flash_device possible_devices[] = {EXTERNAL_FLASH_DEVICES};
49+
#define EXTERNAL_FLASH_DEVICE_COUNT MP_ARRAY_SIZE(possible_devices)
4950

5051
static const external_flash_device* flash_device = NULL;
5152

supervisor/supervisor.mk

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ endif
3333
# (Right now INTERNAL_FLASH_FILESYSTEM and (Q)SPI_FLASH_FILESYSTEM are mutually exclusive.
3434
# But that might not be true in the future.)
3535
ifdef EXTERNAL_FLASH_DEVICES
36-
COMMA := ,
37-
EXTERNAL_FLASH_DEVICE_COUNT := $(words $(subst $(COMMA), ,$(EXTERNAL_FLASH_DEVICES)))
3836
CFLAGS += -DEXTERNAL_FLASH_DEVICES=$(EXTERNAL_FLASH_DEVICES) \
39-
-DEXTERNAL_FLASH_DEVICE_COUNT=$(EXTERNAL_FLASH_DEVICE_COUNT)
4037

4138
SRC_SUPERVISOR += supervisor/shared/external_flash/external_flash.c
4239
ifeq ($(SPI_FLASH_FILESYSTEM),1)

0 commit comments

Comments
 (0)