Skip to content

Commit cdd6fbc

Browse files
committed
Giga Pin Names
Add PinNames for Giga as well, as I see some of the libraries like touch library uses them with MBED to map Pin names to their actual pin
1 parent c47ea7b commit cdd6fbc

File tree

37 files changed

+181129
-180399
lines changed

37 files changed

+181129
-180399
lines changed
560 Bytes
Binary file not shown.
Binary file not shown.

firmwares/zephyr-arduino_giga_r1_stm32h747xx_m7.hex

+10,970-10,935
Large diffs are not rendered by default.
Binary file not shown.
Binary file not shown.

firmwares/zephyr-arduino_nano_33_ble_nrf52840_sense.hex

+15,600-15,567
Large diffs are not rendered by default.
Binary file not shown.
Binary file not shown.

firmwares/zephyr-arduino_nicla_sense_me_nrf52832.hex

+14,041-14,009
Large diffs are not rendered by default.
Binary file not shown.
Binary file not shown.

firmwares/zephyr-arduino_portenta_c33_r7fa6m5bh3cfc.hex

+18,879-18,854
Large diffs are not rendered by default.
Binary file not shown.
Binary file not shown.

firmwares/zephyr-arduino_portenta_h7_stm32h747xx_m7.hex

+19,593-19,559
Large diffs are not rendered by default.
752 Bytes
Binary file not shown.

firmwares/zephyr-ek_ra8d1_r7fa8d1bhecbd.hex

+6,339-6,308
Large diffs are not rendered by default.
528 Bytes
Binary file not shown.
812 Bytes
Binary file not shown.

firmwares/zephyr-frdm_mcxn947_mcxn947_cpu0.hex

+12,931-12,897
Large diffs are not rendered by default.

firmwares/zephyr-frdm_rw612_rw612.bin

512 Bytes
Binary file not shown.

firmwares/zephyr-frdm_rw612_rw612.elf

784 Bytes
Binary file not shown.

firmwares/zephyr-frdm_rw612_rw612.hex

+66,567-66,535
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright (c) 2024 Arduino SA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <Arduino.h>
8+
#include "zephyrInternal.h"
9+
#include "PinNames.h"
10+
11+
// duplicate of one in zephyr common
12+
static const struct gpio_dt_spec arduino_pins[] = { DT_FOREACH_PROP_ELEM_SEP(
13+
DT_PATH(zephyr_user), digital_pin_gpios, GPIO_DT_SPEC_GET_BY_IDX, (, )) };
14+
15+
static const struct gpio_dt_spec arduino_ports[] = { DT_FOREACH_PROP_ELEM_SEP(
16+
DT_PATH(zephyr_user), port_pin_gpios, GPIO_DT_SPEC_GET_BY_IDX, (, )) };
17+
18+
19+
void pinMode(PinName pinNumber, PinMode mode) {
20+
// See if the pinName maps to a real pin number if so use the pin number version
21+
int pin_index = PinNameToIndex(pinNumber);
22+
if (pin_index != -1) {
23+
// this will grab any settings out of the device tree.
24+
pinMode((pin_size_t)pin_index, mode);
25+
return;
26+
}
27+
28+
if (pinNumber & DUAL_PAD) return;
29+
30+
if (mode == INPUT) { // input mode
31+
gpio_pin_configure(arduino_ports[pinNumber >> 4].port, pinNumber & 0xf,
32+
GPIO_INPUT | GPIO_ACTIVE_HIGH);
33+
} else if (mode == INPUT_PULLUP) { // input with internal pull-up
34+
gpio_pin_configure(arduino_ports[pinNumber >> 4].port, pinNumber & 0xf,
35+
GPIO_INPUT | GPIO_PULL_UP | GPIO_ACTIVE_HIGH);
36+
} else if (mode == INPUT_PULLDOWN) { // input with internal pull-down
37+
gpio_pin_configure(arduino_ports[pinNumber >> 4].port, pinNumber & 0xf,
38+
GPIO_INPUT | GPIO_PULL_DOWN | GPIO_ACTIVE_HIGH);
39+
} else if (mode == OUTPUT) { // output mode
40+
gpio_pin_configure(arduino_ports[pinNumber >> 4].port, pinNumber & 0xf,
41+
GPIO_OUTPUT_LOW | GPIO_ACTIVE_HIGH);
42+
}
43+
}
44+
45+
void digitalWrite(PinName pinNumber, PinStatus status) {
46+
if (pinNumber & DUAL_PAD) return;
47+
gpio_pin_set(arduino_ports[pinNumber >> 4].port, pinNumber & 0xf, status);
48+
}
49+
50+
51+
PinStatus digitalRead(PinName pinNumber) {
52+
if (pinNumber & DUAL_PAD) return LOW;
53+
return (gpio_pin_get(arduino_ports[pinNumber >> 4].port, pinNumber & 0xf) == 1) ? HIGH : LOW;
54+
}
55+
56+
int analogRead(PinName pinNumber) {
57+
// Not sure what to do here, does anyone do something like:
58+
// analogRead(PA_0c); or analogRead(PC2_ALT0)?
59+
// first pass only support ones on pins.
60+
if (pinNumber & DUAL_PAD) {
61+
switch (pinNumber & 0xf) {
62+
case 0: return analogRead(A0);
63+
case 1: return analogRead(A1);
64+
case 2: return analogRead(A2);
65+
case 3: return analogRead(A3);
66+
default: return -1;
67+
}
68+
69+
}
70+
int pin_index = PinNameToIndex(pinNumber);
71+
if (pin_index != -1) {
72+
return analogRead(pin_index);
73+
}
74+
return -1;
75+
}
76+
77+
78+
void analogWrite(PinName pinNumber, int value) {
79+
// first pass only support ones on pins.
80+
if (pinNumber & DUAL_PAD) return;
81+
int pin_index = PinNameToIndex(pinNumber);
82+
if (pin_index != -1) {
83+
analogWrite(pin_index, value);
84+
}
85+
}
86+
87+
88+
89+
int PinNameToIndex(PinName P) {
90+
if (P & DUAL_PAD) return -1;
91+
for (size_t i = 0; i < ARRAY_SIZE(arduino_pins); i++) {
92+
if ((arduino_ports[P >> 4].port == arduino_pins[i].port) && ((P & 0xf) == arduino_pins[i].pin)) {
93+
return i;
94+
}
95+
}
96+
return -1;
97+
}
98+
99+
PinName digitalPinToPinName(pin_size_t P) {
100+
if (P < ARRAY_SIZE(arduino_pins)) {
101+
// Convert the pins port into an index into our port's list
102+
for (uint8_t port_index = 0; port_index < ARRAY_SIZE(arduino_ports); port_index++) {
103+
if (arduino_pins[P].port == arduino_ports[port_index].port) {
104+
return (PinName)((port_index << 4) | arduino_pins[P].pin);
105+
}
106+
}
107+
}
108+
return PinName::NC;
109+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
/*
2+
* Copyright (c) 2024 Arduino SA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_PINNAMES_H
8+
#define ZEPHYR_PINNAMES_H
9+
10+
#ifdef __cplusplus
11+
extern "C" {
12+
#endif
13+
14+
#define DUAL_PAD 0x800
15+
16+
typedef enum {
17+
PA_0 = 0x00,
18+
PA_1 = 0x01,
19+
PA_2 = 0x02,
20+
PA_3 = 0x03,
21+
PA_4 = 0x04,
22+
PA_5 = 0x05,
23+
PA_6 = 0x06,
24+
PA_7 = 0x07,
25+
PA_8 = 0x08,
26+
PA_9 = 0x09,
27+
PA_10 = 0x0A,
28+
PA_11 = 0x0B,
29+
PA_12 = 0x0C,
30+
PA_13 = 0x0D,
31+
PA_14 = 0x0E,
32+
PA_15 = 0x0F,
33+
PB_0 = 0x10,
34+
PB_1 = 0x11,
35+
PB_2 = 0x12,
36+
PB_3 = 0x13,
37+
PB_4 = 0x14,
38+
PB_5 = 0x15,
39+
PB_6 = 0x16,
40+
PB_7 = 0x17,
41+
PB_8 = 0x18,
42+
PB_9 = 0x19,
43+
PB_10 = 0x1A,
44+
PB_11 = 0x1B,
45+
PB_12 = 0x1C,
46+
PB_13 = 0x1D,
47+
PB_14 = 0x1E,
48+
PB_15 = 0x1F,
49+
PC_0 = 0x20,
50+
PC_1 = 0x21,
51+
PC_2 = 0x22,
52+
PC_3 = 0x23,
53+
PC_4 = 0x24,
54+
PC_5 = 0x25,
55+
PC_6 = 0x26,
56+
PC_7 = 0x27,
57+
PC_8 = 0x28,
58+
PC_9 = 0x29,
59+
PC_10 = 0x2A,
60+
PC_11 = 0x2B,
61+
PC_12 = 0x2C,
62+
PC_13 = 0x2D,
63+
PC_14 = 0x2E,
64+
PC_15 = 0x2F,
65+
PD_0 = 0x30,
66+
PD_1 = 0x31,
67+
PD_2 = 0x32,
68+
PD_3 = 0x33,
69+
PD_4 = 0x34,
70+
PD_5 = 0x35,
71+
PD_6 = 0x36,
72+
PD_7 = 0x37,
73+
PD_8 = 0x38,
74+
PD_9 = 0x39,
75+
PD_10 = 0x3A,
76+
PD_11 = 0x3B,
77+
PD_12 = 0x3C,
78+
PD_13 = 0x3D,
79+
PD_14 = 0x3E,
80+
PD_15 = 0x3F,
81+
PE_0 = 0x40,
82+
PE_1 = 0x41,
83+
PE_2 = 0x42,
84+
PE_3 = 0x43,
85+
PE_4 = 0x44,
86+
PE_5 = 0x45,
87+
PE_6 = 0x46,
88+
PE_7 = 0x47,
89+
PE_8 = 0x48,
90+
PE_9 = 0x49,
91+
PE_10 = 0x4A,
92+
PE_11 = 0x4B,
93+
PE_12 = 0x4C,
94+
PE_13 = 0x4D,
95+
PE_14 = 0x4E,
96+
PE_15 = 0x4F,
97+
PF_0 = 0x50,
98+
PF_1 = 0x51,
99+
PF_2 = 0x52,
100+
PF_3 = 0x53,
101+
PF_4 = 0x54,
102+
PF_5 = 0x55,
103+
PF_6 = 0x56,
104+
PF_7 = 0x57,
105+
PF_8 = 0x58,
106+
PF_9 = 0x59,
107+
PF_10 = 0x5A,
108+
PF_11 = 0x5B,
109+
PF_12 = 0x5C,
110+
PF_13 = 0x5D,
111+
PF_14 = 0x5E,
112+
PF_15 = 0x5F,
113+
PG_0 = 0x60,
114+
PG_1 = 0x61,
115+
PG_2 = 0x62,
116+
PG_3 = 0x63,
117+
PG_4 = 0x64,
118+
PG_5 = 0x65,
119+
PG_6 = 0x66,
120+
PG_7 = 0x67,
121+
PG_8 = 0x68,
122+
PG_9 = 0x69,
123+
PG_10 = 0x6A,
124+
PG_11 = 0x6B,
125+
PG_12 = 0x6C,
126+
PG_13 = 0x6D,
127+
PG_14 = 0x6E,
128+
PG_15 = 0x6F,
129+
PH_0 = 0x70,
130+
PH_1 = 0x71,
131+
PH_2 = 0x72,
132+
PH_3 = 0x73,
133+
PH_4 = 0x74,
134+
PH_5 = 0x75,
135+
PH_6 = 0x76,
136+
PH_7 = 0x77,
137+
PH_8 = 0x78,
138+
PH_9 = 0x79,
139+
PH_10 = 0x7A,
140+
PH_11 = 0x7B,
141+
PH_12 = 0x7C,
142+
PH_13 = 0x7D,
143+
PH_14 = 0x7E,
144+
PH_15 = 0x7F,
145+
PI_0 = 0x80,
146+
PI_1 = 0x81,
147+
PI_2 = 0x82,
148+
PI_3 = 0x83,
149+
PI_4 = 0x84,
150+
PI_5 = 0x85,
151+
PI_6 = 0x86,
152+
PI_7 = 0x87,
153+
PI_8 = 0x88,
154+
PI_9 = 0x89,
155+
PI_10 = 0x8A,
156+
PI_11 = 0x8B,
157+
PI_12 = 0x8C,
158+
PI_13 = 0x8D,
159+
PI_14 = 0x8E,
160+
PI_15 = 0x8F,
161+
PJ_0 = 0x90,
162+
PJ_1 = 0x91,
163+
PJ_2 = 0x92,
164+
PJ_3 = 0x93,
165+
PJ_4 = 0x94,
166+
PJ_5 = 0x95,
167+
PJ_6 = 0x96,
168+
PJ_7 = 0x97,
169+
PJ_8 = 0x98,
170+
PJ_9 = 0x99,
171+
PJ_10 = 0x9A,
172+
PJ_11 = 0x9B,
173+
PJ_12 = 0x9C,
174+
PJ_13 = 0x9D,
175+
PJ_14 = 0x9E,
176+
PJ_15 = 0x9F,
177+
PK_0 = 0xA0,
178+
PK_1 = 0xA1,
179+
PK_2 = 0xA2,
180+
PK_3 = 0xA3,
181+
PK_4 = 0xA4,
182+
PK_5 = 0xA5,
183+
PK_6 = 0xA6,
184+
PK_7 = 0xA7,
185+
186+
187+
//Led mappings
188+
LED_RED = PI_12, //Red
189+
LED_GREEN = PJ_13, //Green
190+
LED_BLUE = PE_3, //Blue
191+
192+
// Not connected
193+
NC = (int)0xFFFFFFFF
194+
} PinName;
195+
196+
// Standardized LED and button names
197+
#define LED1 LED_RED
198+
#define LED2 LED_GREEN
199+
#define LED3 LED_BLUE
200+
201+
202+
203+
#ifdef __cplusplus
204+
205+
}
206+
207+
// overloads - only cpp as c does not allow overloads of functions
208+
void pinMode(PinName pinNumber, PinMode mode);
209+
void digitalWrite(PinName pinNumber, PinStatus status);
210+
int PinNameToIndex(PinName P);
211+
PinName digitalPinToPinName(pin_size_t P);
212+
PinStatus digitalRead(PinName pinNumber);
213+
int analogRead(PinName pinNumber);
214+
void analogWrite(PinName pinNumber, int value);
215+
216+
#endif
217+
218+
#endif

variants/arduino_giga_r1_stm32h747xx_m7/arduino_giga_r1_stm32h747xx_m7.overlay

+12
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,18 @@
476476
<&arduino_header 18 0>,
477477
<&arduino_header 19 0>;
478478

479+
port-pin-gpios = <&gpioa 0 0>,
480+
<&gpiob 0 0>,
481+
<&gpioc 0 0>,
482+
<&gpiod 0 0>,
483+
<&gpioe 0 0>,
484+
<&gpiof 0 0>,
485+
<&gpiog 0 0>,
486+
<&gpioh 0 0>,
487+
<&gpioi 0 0>,
488+
<&gpioj 0 0>,
489+
<&gpiok 0 0>;
490+
479491
adc-pin-gpios = <&gpioc 4 0>,
480492
<&gpioc 5 0>,
481493
<&gpiob 0 0>,

0 commit comments

Comments
 (0)