Skip to content

Commit 6dac4cc

Browse files
committed
snippets: Add ArduinoCore snippet
This snippet configure boards to support ArduinoCore API. Signed-off-by: TOKITA Hiroshi <[email protected]>
1 parent 45c02d4 commit 6dac4cc

12 files changed

+1503
-0
lines changed

snippets/arduino-core/README.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.. _arduino_core:
2+
3+
ArduinoCore: universal snippet for ArduinoCore
4+
##############################################
5+
6+
Overview
7+
********
8+
9+
This snippet will enable the necessary settings for ArduinoCore.
10+
11+
Programming
12+
***********
13+
14+
Correct snippet designation for ArduinoCore must
15+
be entered when you invoke ``west build``.
16+
For example:
17+
18+
.. code-block:: console
19+
20+
west build -b arduino_nano_33_ble -S arduino_core <sample directory>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_ARDUINO_API=y
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
/*
2+
* Copyright (c) 2022 Dhruva Gole <[email protected]>
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/dt-bindings/adc/adc.h>
8+
9+
/ {
10+
zephyr,user {
11+
digital-pin-gpios = <&arduino_mkr_header 0 0>,
12+
<&arduino_mkr_header 1 0>,
13+
<&arduino_mkr_header 2 0>,
14+
<&arduino_mkr_header 3 0>,
15+
<&arduino_mkr_header 4 0>,
16+
<&arduino_mkr_header 5 0>,
17+
<&arduino_mkr_header 6 0>,
18+
<&arduino_mkr_header 7 0>,
19+
<&arduino_mkr_header 8 0>,
20+
<&arduino_mkr_header 9 0>,
21+
<&arduino_mkr_header 10 0>,
22+
<&arduino_mkr_header 11 0>,
23+
<&arduino_mkr_header 12 0>,
24+
<&arduino_mkr_header 13 0>,
25+
<&arduino_mkr_header 14 0>, /* D14 / A0 */
26+
<&arduino_mkr_header 15 0>,
27+
<&arduino_mkr_header 16 0>,
28+
<&arduino_mkr_header 17 0>,
29+
<&arduino_mkr_header 18 0>, /* D18 / A4 / I2C-SDA */
30+
<&arduino_mkr_header 19 0>, /* D19 / A5 / I2C-SCL */
31+
<&arduino_mkr_header 20 0>,
32+
<&arduino_mkr_header 21 0>,
33+
<&portb 8 0>;
34+
35+
pwm-pin-gpios = <&arduino_mkr_header 2 0>,
36+
<&arduino_mkr_header 3 0>;
37+
38+
adc-pin-gpios = <&arduino_mkr_header 15 0>,
39+
<&arduino_mkr_header 16 0>,
40+
<&arduino_mkr_header 17 0>,
41+
<&arduino_mkr_header 18 0>,
42+
<&arduino_mkr_header 19 0>,
43+
<&arduino_mkr_header 20 0>,
44+
<&arduino_mkr_header 21 0>;
45+
46+
pwms = <&tcc0 2 255>,
47+
<&tcc0 3 255>;
48+
49+
io-channels = <&adc 0>,
50+
<&adc 10>,
51+
<&adc 11>,
52+
<&adc 4>,
53+
<&adc 5>,
54+
<&adc 6>,
55+
<&adc 7>;
56+
57+
gpio-ports = <&porta>, <&portb>;
58+
serials = <&sercom5>;
59+
i2cs = <&sercom0>;
60+
};
61+
};
62+
63+
&pinctrl {
64+
pwm_default: pwm_default {
65+
group1 {
66+
pinmux = <PA10F_TCC0_WO2>,
67+
<PA11F_TCC0_WO3>;
68+
};
69+
};
70+
71+
adc_default: adc_default {
72+
group1 {
73+
pinmux = <PA2B_ADC_AIN0>,
74+
<PB2B_ADC_AIN10>,
75+
<PB3B_ADC_AIN11>,
76+
<PA4B_ADC_AIN4>,
77+
<PA5B_ADC_AIN5>,
78+
<PA6B_ADC_AIN6>,
79+
<PA7B_ADC_AIN7>;
80+
};
81+
};
82+
};
83+
84+
&tcc0 {
85+
status = "okay";
86+
compatible = "atmel,sam0-tcc-pwm";
87+
prescaler = <2>;
88+
#pwm-cells = <2>;
89+
90+
pinctrl-0 = <&pwm_default>;
91+
pinctrl-names = "default";
92+
};
93+
94+
&adc {
95+
status = "okay";
96+
pinctrl-0 = <&adc_default>;
97+
pinctrl-names = "default";
98+
99+
#address-cells = <1>;
100+
#size-cells = <0>;
101+
102+
channel@0 {
103+
reg = <0x0>;
104+
zephyr,gain = "ADC_GAIN_1";
105+
zephyr,reference = "ADC_REF_INTERNAL";
106+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
107+
zephyr,resolution = <10>;
108+
zephyr,input-positive = <0>;
109+
};
110+
111+
channel@4 {
112+
reg = <0x4>;
113+
zephyr,gain = "ADC_GAIN_1";
114+
zephyr,reference = "ADC_REF_INTERNAL";
115+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
116+
zephyr,resolution = <10>;
117+
zephyr,input-positive = <4>;
118+
};
119+
120+
channel@5 {
121+
reg = <0x5>;
122+
zephyr,gain = "ADC_GAIN_1";
123+
zephyr,reference = "ADC_REF_INTERNAL";
124+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
125+
zephyr,resolution = <10>;
126+
zephyr,input-positive = <5>;
127+
};
128+
129+
channel@6 {
130+
reg = <0x6>;
131+
zephyr,gain = "ADC_GAIN_1";
132+
zephyr,reference = "ADC_REF_INTERNAL";
133+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
134+
zephyr,resolution = <10>;
135+
zephyr,input-positive = <6>;
136+
};
137+
138+
channel@7 {
139+
reg = <0x7>;
140+
zephyr,gain = "ADC_GAIN_1";
141+
zephyr,reference = "ADC_REF_INTERNAL";
142+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
143+
zephyr,resolution = <10>;
144+
zephyr,input-positive = <7>;
145+
};
146+
147+
channel@a {
148+
reg = <0xa>;
149+
zephyr,gain = "ADC_GAIN_1";
150+
zephyr,reference = "ADC_REF_INTERNAL";
151+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
152+
zephyr,resolution = <10>;
153+
zephyr,input-positive = <10>;
154+
};
155+
156+
channel@b {
157+
reg = <0xb>;
158+
zephyr,gain = "ADC_GAIN_1";
159+
zephyr,reference = "ADC_REF_INTERNAL";
160+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
161+
zephyr,resolution = <10>;
162+
zephyr,input-positive = <11>;
163+
};
164+
};
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
/*
2+
* Copyright (c) 2023 John Doe
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
zephyr,user {
9+
digital-pin-gpios = <&arduino_nano_header 0 0>,
10+
<&arduino_nano_header 1 0>,
11+
<&arduino_nano_header 2 0>,
12+
<&arduino_nano_header 3 0>,
13+
<&arduino_nano_header 4 0>,
14+
<&arduino_nano_header 5 0>,
15+
<&arduino_nano_header 6 0>,
16+
<&arduino_nano_header 7 0>,
17+
<&arduino_nano_header 8 0>,
18+
<&arduino_nano_header 9 0>,
19+
<&arduino_nano_header 10 0>,
20+
<&arduino_nano_header 11 0>,
21+
<&arduino_nano_header 12 0>,
22+
<&arduino_nano_header 13 0>,
23+
<&arduino_nano_header 14 0>, /* D14 / A0 */
24+
<&arduino_nano_header 15 0>,
25+
<&arduino_nano_header 16 0>,
26+
<&arduino_nano_header 17 0>,
27+
<&arduino_nano_header 18 0>, /* D18 / A4 / I2C-SDA */
28+
<&arduino_nano_header 19 0>, /* D19 / A5 / I2C-SCL */
29+
<&arduino_nano_header 20 0>,
30+
<&arduino_nano_header 21 0>;
31+
32+
pwm-pin-gpios = <&arduino_nano_header 3 0>,
33+
<&arduino_nano_header 5 0>,
34+
<&arduino_nano_header 6 0>,
35+
<&arduino_nano_header 13 0>,
36+
<&arduino_nano_header 9 0>,
37+
<&arduino_nano_header 10 0>,
38+
<&arduino_nano_header 11 0>;
39+
40+
adc-pin-gpios = <&arduino_nano_header 14 0>,
41+
<&arduino_nano_header 15 0>,
42+
<&arduino_nano_header 16 0>,
43+
<&arduino_nano_header 17 0>,
44+
<&arduino_nano_header 18 0>,
45+
<&arduino_nano_header 19 0>,
46+
<&arduino_nano_header 20 0>,
47+
<&arduino_nano_header 21 0>;
48+
49+
pwms = <&pwm1 1 255 PWM_POLARITY_NORMAL>,
50+
<&pwm1 2 255 PWM_POLARITY_NORMAL>,
51+
<&pwm1 3 255 PWM_POLARITY_NORMAL>,
52+
<&pwm2 0 255 PWM_POLARITY_NORMAL>,
53+
<&pwm2 1 255 PWM_POLARITY_NORMAL>,
54+
<&pwm2 2 255 PWM_POLARITY_NORMAL>,
55+
<&pwm2 3 255 PWM_POLARITY_NORMAL>;
56+
57+
io-channels = <&adc 2>,
58+
<&adc 3>,
59+
<&adc 6>,
60+
<&adc 5>,
61+
<&adc 7>,
62+
<&adc 0>,
63+
<&adc 4>,
64+
<&adc 1>;
65+
66+
gpio-ports = <&gpio0>, <&gpio1>;
67+
serials = <&uart0>;
68+
i2cs = <&arduino_nano_i2c>;
69+
};
70+
};
71+
72+
&adc {
73+
#address-cells = <1>;
74+
#size-cells = <0>;
75+
76+
channel@0 {
77+
reg = <0>;
78+
zephyr,gain = "ADC_GAIN_1_6";
79+
zephyr,reference = "ADC_REF_INTERNAL";
80+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
81+
zephyr,input-positive = <NRF_SAADC_AIN0>; /* P0.02 */
82+
zephyr,resolution = <10>;
83+
};
84+
85+
channel@1 {
86+
reg = <1>;
87+
zephyr,gain = "ADC_GAIN_1_6";
88+
zephyr,reference = "ADC_REF_INTERNAL";
89+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
90+
zephyr,input-positive = <NRF_SAADC_AIN1>; /* P0.03 */
91+
zephyr,resolution = <10>;
92+
};
93+
94+
channel@2 {
95+
reg = <2>;
96+
zephyr,gain = "ADC_GAIN_1_6";
97+
zephyr,reference = "ADC_REF_INTERNAL";
98+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
99+
zephyr,input-positive = <NRF_SAADC_AIN2>; /* P0.04 */
100+
zephyr,resolution = <10>;
101+
};
102+
103+
channel@3 {
104+
reg = <3>;
105+
zephyr,gain = "ADC_GAIN_1_6";
106+
zephyr,reference = "ADC_REF_INTERNAL";
107+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
108+
zephyr,input-positive = <NRF_SAADC_AIN3>; /* P0.05 */
109+
zephyr,resolution = <10>;
110+
};
111+
112+
channel@4 {
113+
reg = <4>;
114+
zephyr,gain = "ADC_GAIN_1_6";
115+
zephyr,reference = "ADC_REF_INTERNAL";
116+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
117+
zephyr,input-positive = <NRF_SAADC_AIN4>; /* P0.28 */
118+
zephyr,resolution = <10>;
119+
};
120+
121+
channel@5 {
122+
reg = <5>;
123+
zephyr,gain = "ADC_GAIN_1_6";
124+
zephyr,reference = "ADC_REF_INTERNAL";
125+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
126+
zephyr,input-positive = <NRF_SAADC_AIN5>; /* P0.29 */
127+
zephyr,resolution = <10>;
128+
};
129+
130+
channel@6 {
131+
reg = <6>;
132+
zephyr,gain = "ADC_GAIN_1_6";
133+
zephyr,reference = "ADC_REF_INTERNAL";
134+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
135+
zephyr,input-positive = <NRF_SAADC_AIN6>; /* P0.30 */
136+
zephyr,resolution = <10>;
137+
};
138+
139+
channel@7 {
140+
reg = <7>;
141+
zephyr,gain = "ADC_GAIN_1_6";
142+
zephyr,reference = "ADC_REF_INTERNAL";
143+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
144+
zephyr,input-positive = <NRF_SAADC_AIN7>; /* P0.31 */
145+
zephyr,resolution = <10>;
146+
};
147+
};
148+
149+
&pinctrl {
150+
pwm1_default: pwm1_default {
151+
group1 {
152+
psels = <NRF_PSEL(PWM_OUT0, 1, 9)>, /* keep original config */
153+
<NRF_PSEL(PWM_OUT1, 1, 12)>,
154+
<NRF_PSEL(PWM_OUT2, 1, 13)>,
155+
<NRF_PSEL(PWM_OUT3, 1, 14)>;
156+
nordic,invert;
157+
};
158+
};
159+
160+
pwm1_sleep: pwm1_sleep {
161+
group1 {
162+
psels = <NRF_PSEL(PWM_OUT0, 1, 9)>, /* keep original config */
163+
<NRF_PSEL(PWM_OUT1, 1, 12)>,
164+
<NRF_PSEL(PWM_OUT2, 1, 13)>,
165+
<NRF_PSEL(PWM_OUT3, 1, 14)>;
166+
low-power-enable;
167+
};
168+
};
169+
170+
pwm2_default: pwm2_default {
171+
group1 {
172+
psels = <NRF_PSEL(PWM_OUT0, 0, 13)>, /* keep original config */
173+
<NRF_PSEL(PWM_OUT1, 0, 27)>,
174+
<NRF_PSEL(PWM_OUT2, 1, 2)>,
175+
<NRF_PSEL(PWM_OUT3, 1, 1)>;
176+
nordic,invert;
177+
};
178+
};
179+
180+
pwm2_sleep: pwm2_sleep {
181+
group1 {
182+
psels = <NRF_PSEL(PWM_OUT0, 0, 13)>, /* keep original config */
183+
<NRF_PSEL(PWM_OUT1, 0, 27)>,
184+
<NRF_PSEL(PWM_OUT2, 1, 2)>,
185+
<NRF_PSEL(PWM_OUT3, 1, 1)>;
186+
low-power-enable;
187+
};
188+
};
189+
};
190+
191+
&pwm1 {
192+
status = "okay";
193+
pinctrl-0 = <&pwm1_default>;
194+
pinctrl-1 = <&pwm1_sleep>;
195+
pinctrl-names = "default", "sleep";
196+
};
197+
198+
&pwm2 {
199+
status = "okay";
200+
pinctrl-0 = <&pwm2_default>;
201+
pinctrl-1 = <&pwm2_sleep>;
202+
pinctrl-names = "default", "sleep";
203+
};

0 commit comments

Comments
 (0)