Skip to content

Commit b6d45a6

Browse files
committed
refactor(wasm): Remove Metro branding from generic board implementation
- Refactored generic_board.h to remove Metro-specific references and use "Generic Board" naming - Updated generic_board.c to use generic naming conventions (GENERIC_BOARD_PIN_COUNT, generic_board_pins) - Enhanced js_provider.c with comprehensive pin name and number support for better HAL integration - Changed board identification from "Generic Metro (WASM Simulator)" to "Generic Board (WASM)" - Updated MCU type from "Virtual SAMD21G18" to "Virtual MCU" for true hardware abstraction - Removed redundant generic_provider.c and consolidated functionality into js_provider - Improved HAL provider architecture with cleaner separation of concerns - Added board initialization notification system for JavaScript integration - Maintained Arduino-compatible pin layout while removing brand-specific assumptions This creates a truly generic board configuration that can represent any CircuitPython-compatible board without hardware vendor bias, improving the flexibility of the WASM HAL system.
1 parent ab92f92 commit b6d45a6

5 files changed

Lines changed: 211 additions & 347 deletions

File tree

ports/wasm/Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ LDFLAGS += -s SUPPORT_LONGJMP=emscripten
9393
SRC_HAL = \
9494
hal_provider.c \
9595
generic_board.c \
96-
providers/generic_provider.c \
9796
providers/stub_provider.c \
9897
providers/js_provider.c \
9998

ports/wasm/generic_board.c

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Generic Metro-style board implementation for WASM HAL
1+
// Generic board implementation for CircuitPython WASM HAL
22

33
#include <stdio.h>
44
#include <string.h>
@@ -31,28 +31,28 @@ void generic_board_init(void) {
3131
}
3232

3333
// Allocate virtual pins
34-
virtual_pin_count = GENERIC_METRO_PIN_COUNT;
34+
virtual_pin_count = GENERIC_BOARD_PIN_COUNT;
3535
virtual_pins = calloc(virtual_pin_count, sizeof(virtual_pin_state_t));
3636

3737
// Initialize each pin
38-
for (int i = 0; i < GENERIC_METRO_PIN_COUNT; i++) {
39-
virtual_pins[i].name = generic_metro_pins[i].name;
40-
virtual_pins[i].capabilities = generic_metro_pins[i].capabilities;
38+
for (int i = 0; i < GENERIC_BOARD_PIN_COUNT; i++) {
39+
virtual_pins[i].name = generic_board_pins[i].name;
40+
virtual_pins[i].capabilities = generic_board_pins[i].capabilities;
4141
virtual_pins[i].value = 0;
4242
virtual_pins[i].direction = 0; // Input by default
4343
virtual_pins[i].pull = 0;
4444
virtual_pins[i].analog_value = 0.0;
4545

4646
// Special initializations
47-
if (strcmp(generic_metro_pins[i].name, "BUTTON") == 0) {
47+
if (strcmp(generic_board_pins[i].name, "BUTTON") == 0) {
4848
virtual_pins[i].value = 1; // Button not pressed (pull-up)
4949
virtual_pins[i].pull = 1; // Internal pull-up
5050
}
5151
}
5252

5353
board_initialized = 1;
5454

55-
printf("Generic Metro board initialized with %d pins\n", virtual_pin_count);
55+
printf("Generic board initialized with %d pins\n", virtual_pin_count);
5656
}
5757

5858
// Generate JSON representation of the board
@@ -71,45 +71,45 @@ const char* generic_board_to_json(void) {
7171

7272
// Board info
7373
sprintf(json_buffer + strlen(json_buffer),
74-
"\"board_name\":\"%s\",", generic_metro_info.board_name);
74+
"\"board_name\":\"%s\",", generic_board_info.board_name);
7575
sprintf(json_buffer + strlen(json_buffer),
76-
"\"mcu_type\":\"%s\",", generic_metro_info.mcu_type);
76+
"\"mcu_type\":\"%s\",", generic_board_info.mcu_type);
7777
sprintf(json_buffer + strlen(json_buffer),
78-
"\"flash_size\":%u,", generic_metro_info.flash_size);
78+
"\"flash_size\":%u,", generic_board_info.flash_size);
7979
sprintf(json_buffer + strlen(json_buffer),
80-
"\"ram_size\":%u,", generic_metro_info.ram_size);
80+
"\"ram_size\":%u,", generic_board_info.ram_size);
8181
sprintf(json_buffer + strlen(json_buffer),
82-
"\"cpu_frequency_mhz\":%.1f,", generic_metro_info.cpu_frequency_mhz);
82+
"\"cpu_frequency_mhz\":%.1f,", generic_board_info.cpu_frequency_mhz);
8383
sprintf(json_buffer + strlen(json_buffer),
84-
"\"logic_level_v\":%.1f,", generic_metro_info.logic_level_v);
84+
"\"logic_level_v\":%.1f,", generic_board_info.logic_level_v);
8585

8686
// Pins array
8787
strcat(json_buffer, "\"pins\":[");
88-
for (int i = 0; i < GENERIC_METRO_PIN_COUNT; i++) {
88+
for (int i = 0; i < GENERIC_BOARD_PIN_COUNT; i++) {
8989
if (i > 0) strcat(json_buffer, ",");
9090
sprintf(json_buffer + strlen(json_buffer),
9191
"{\"name\":\"%s\",\"mcu_pin\":\"%s\",\"capabilities\":%u}",
92-
generic_metro_pins[i].name,
93-
generic_metro_pins[i].mcu_pin,
94-
generic_metro_pins[i].capabilities
92+
generic_board_pins[i].name,
93+
generic_board_pins[i].mcu_pin,
94+
generic_board_pins[i].capabilities
9595
);
9696
}
9797
strcat(json_buffer, "],");
9898

9999
// Peripherals array
100100
strcat(json_buffer, "\"peripherals\":[");
101-
for (int i = 0; i < GENERIC_METRO_PERIPHERAL_COUNT; i++) {
101+
for (int i = 0; i < GENERIC_BOARD_PERIPHERAL_COUNT; i++) {
102102
if (i > 0) strcat(json_buffer, ",");
103103
sprintf(json_buffer + strlen(json_buffer),
104104
"{\"name\":\"%s\",\"pins\":[",
105-
generic_metro_peripherals[i].name
105+
generic_board_peripherals[i].name
106106
);
107107

108108
// Add peripheral pins
109-
for (int j = 0; j < 4 && generic_metro_peripherals[i].default_pins[j]; j++) {
109+
for (int j = 0; j < 4 && generic_board_peripherals[i].default_pins[j]; j++) {
110110
if (j > 0) strcat(json_buffer, ",");
111111
sprintf(json_buffer + strlen(json_buffer),
112-
"\"%s\"", generic_metro_peripherals[i].default_pins[j]
112+
"\"%s\"", generic_board_peripherals[i].default_pins[j]
113113
);
114114
}
115115
strcat(json_buffer, "]}");
@@ -219,21 +219,21 @@ const char* mp_js_generate_board_module(void) {
219219
}
220220

221221
module_source = malloc(4096);
222-
strcpy(module_source, "# Auto-generated board module for Generic Metro\n");
222+
strcpy(module_source, "# Auto-generated board module for Generic Board\n");
223223
strcat(module_source, "# This module provides pin definitions for the simulated board\n\n");
224224

225225
// Add pin constants
226-
for (int i = 0; i < GENERIC_METRO_PIN_COUNT; i++) {
226+
for (int i = 0; i < GENERIC_BOARD_PIN_COUNT; i++) {
227227
sprintf(module_source + strlen(module_source),
228228
"%s = '%s'\n",
229-
generic_metro_pins[i].name,
230-
generic_metro_pins[i].name);
229+
generic_board_pins[i].name,
230+
generic_board_pins[i].name);
231231
}
232232

233233
// Add helper information
234234
strcat(module_source, "\n# Board information\n");
235235
sprintf(module_source + strlen(module_source),
236-
"board_id = '%s'\n", generic_metro_info.board_name);
236+
"board_id = '%s'\n", generic_board_info.board_name);
237237

238238
// Add peripheral groupings
239239
strcat(module_source, "\n# Peripheral pin groups\n");

ports/wasm/generic_board.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
// Generic Metro-style board configuration for WASM HAL
1+
// Generic board configuration for CircuitPython WASM HAL
22
// Provides a comprehensive fallback board with common peripherals
33

44
#ifndef GENERIC_BOARD_H
55
#define GENERIC_BOARD_H
66

77
#include <stdint.h>
88

9-
// Generic Metro board pin definitions
10-
// Based on common Arduino Uno/Metro layout
9+
// Generic board pin definitions
10+
// Based on common Arduino-compatible layout for familiarity
1111

1212
typedef struct {
1313
const char* name;
@@ -24,8 +24,8 @@ typedef struct {
2424
#define PIN_CAP_UART (1 << 5)
2525
#define PIN_CAP_TOUCH (1 << 6)
2626

27-
// Standard Metro/Arduino pin layout
28-
static const generic_pin_def_t generic_metro_pins[] = {
27+
// Standard Arduino-compatible pin layout
28+
static const generic_pin_def_t generic_board_pins[] = {
2929
// Digital pins (0-13)
3030
{"D0", "PA00", PIN_CAP_DIGITAL | PIN_CAP_UART}, // RX
3131
{"D1", "PA01", PIN_CAP_DIGITAL | PIN_CAP_UART}, // TX
@@ -73,7 +73,7 @@ static const generic_pin_def_t generic_metro_pins[] = {
7373
{"RX", "PA00", PIN_CAP_DIGITAL | PIN_CAP_UART},
7474
};
7575

76-
#define GENERIC_METRO_PIN_COUNT (sizeof(generic_metro_pins) / sizeof(generic_metro_pins[0]))
76+
#define GENERIC_BOARD_PIN_COUNT (sizeof(generic_board_pins) / sizeof(generic_board_pins[0]))
7777

7878
// Board metadata
7979
typedef struct {
@@ -85,9 +85,9 @@ typedef struct {
8585
float logic_level_v;
8686
} generic_board_info_t;
8787

88-
static const generic_board_info_t generic_metro_info = {
89-
.board_name = "Generic Metro (WASM Simulator)",
90-
.mcu_type = "Virtual SAMD21G18", // Pretend to be SAMD21 for compatibility
88+
static const generic_board_info_t generic_board_info = {
89+
.board_name = "Generic Board (WASM)",
90+
.mcu_type = "Virtual MCU", // Generic virtual microcontroller
9191
.flash_size = 256 * 1024, // 256KB flash
9292
.ram_size = 32 * 1024, // 32KB RAM
9393
.cpu_frequency_mhz = 48.0,
@@ -100,14 +100,14 @@ typedef struct {
100100
const char* default_pins[4]; // Up to 4 pins per peripheral
101101
} generic_peripheral_t;
102102

103-
static const generic_peripheral_t generic_metro_peripherals[] = {
103+
static const generic_peripheral_t generic_board_peripherals[] = {
104104
{"I2C", {"SDA", "SCL", NULL, NULL}},
105105
{"SPI", {"MOSI", "MISO", "SCK", "D10"}}, // D10 as CS
106106
{"UART", {"TX", "RX", NULL, NULL}},
107107
{"NEOPIXEL", {"NEOPIXEL", NULL, NULL, NULL}},
108108
};
109109

110-
#define GENERIC_METRO_PERIPHERAL_COUNT (sizeof(generic_metro_peripherals) / sizeof(generic_metro_peripherals[0]))
110+
#define GENERIC_BOARD_PERIPHERAL_COUNT (sizeof(generic_board_peripherals) / sizeof(generic_board_peripherals[0]))
111111

112112
// Function declarations
113113
void generic_board_init(void);

0 commit comments

Comments
 (0)