Skip to content

Commit 3be3a53

Browse files
committed
x
1 parent a6a1406 commit 3be3a53

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

cores/arduino/zephyrCommon.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,19 @@ constexpr inline pin_size_t port_idx(pin_size_t gpin)
5151
return port_index_recursive(local_gpio_port(gpin), gpios, 0, ARRAY_SIZE(gpios));
5252
}
5353

54+
constexpr inline pin_size_t end_accum_recursive(const uint32_t accum, const uint32_t *end, size_t n)
55+
{
56+
return (n == 0) ? accum : end_accum_recursive(accum + end[0], end + 1, n - 1);
57+
}
58+
59+
constexpr inline pin_size_t end_accum(size_t n)
60+
{
61+
return end_accum_recursive(0, pins, n);
62+
}
63+
5464
constexpr inline pin_size_t local_gpio_pin(pin_size_t gpin)
5565
{
56-
return port_idx(gpin) == pin_size_t(-1) ? pin_size_t(-1) : gpin - pins[port_idx(gpin)];
66+
return port_idx(gpin) == pin_size_t(-1) ? pin_size_t(-1) : gpin - end_accum(port_idx(gpin));
5767
}
5868

5969
constexpr inline pin_size_t global_gpio_pin_(size_t port_idx, pin_size_t lpin)
@@ -252,7 +262,7 @@ static bool interrupts_disabled = false;
252262

253263
#define Dx(x) D ## x
254264
#define DXx(x) DX ## x
255-
#define PRINT_PIN(p, _) printf(STRINGIFY(DXX(p)) "%p:%d - %p:%d\n", arduino_pins[Dx(p)].port, arduino_pins[Dx(p)].pin, local_gpio_port(DXx(p)), local_gpio_pin(DXx(p)));
265+
#define PRINT_PIN(p, _) printf(STRINGIFY(Dx(p)) ":%d:%p:%d - " STRINGIFY(DXx(p)) ":%d:%p:%d\n", Dx(p), arduino_pins[Dx(p)].port, arduino_pins[Dx(p)].pin, DXx(p), local_gpio_port(DXx(p)), local_gpio_pin(DXx(p)));
256266

257267
void yield(void) {
258268

0 commit comments

Comments
 (0)