Skip to content

Commit 9114af1

Browse files
committed
snippets: Add ArduinoCore snippet
This snippet configure boards to support ArduinoCore API. Signed-off-by: TOKITA Hiroshi <[email protected]>
1 parent 3aa64aa commit 9114af1

12 files changed

+1472
-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: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
/ {
2+
zephyr,user {
3+
digital-pin-gpios = <&arduino_nano_header 0 0>,
4+
<&arduino_nano_header 1 0>,
5+
<&arduino_nano_header 2 0>,
6+
<&arduino_nano_header 3 0>,
7+
<&arduino_nano_header 4 0>,
8+
<&arduino_nano_header 5 0>,
9+
<&arduino_nano_header 6 0>,
10+
<&arduino_nano_header 7 0>,
11+
<&arduino_nano_header 8 0>,
12+
<&arduino_nano_header 9 0>,
13+
<&arduino_nano_header 10 0>,
14+
<&arduino_nano_header 11 0>,
15+
<&arduino_nano_header 12 0>,
16+
<&arduino_nano_header 13 0>,
17+
<&arduino_nano_header 14 0>, /* D14 / A0 */
18+
<&arduino_nano_header 15 0>,
19+
<&arduino_nano_header 16 0>,
20+
<&arduino_nano_header 17 0>,
21+
<&arduino_nano_header 18 0>, /* D18 / A4 / I2C-SDA */
22+
<&arduino_nano_header 19 0>, /* D19 / A5 / I2C-SCL */
23+
<&arduino_nano_header 20 0>,
24+
<&arduino_nano_header 21 0>;
25+
26+
pwm-pin-gpios = <&arduino_nano_header 3 0>,
27+
<&arduino_nano_header 5 0>,
28+
<&arduino_nano_header 6 0>,
29+
<&arduino_nano_header 13 0>,
30+
<&arduino_nano_header 9 0>,
31+
<&arduino_nano_header 10 0>,
32+
<&arduino_nano_header 11 0>;
33+
34+
adc-pin-gpios = <&arduino_nano_header 14 0>,
35+
<&arduino_nano_header 15 0>,
36+
<&arduino_nano_header 16 0>,
37+
<&arduino_nano_header 17 0>,
38+
<&arduino_nano_header 18 0>,
39+
<&arduino_nano_header 19 0>,
40+
<&arduino_nano_header 20 0>,
41+
<&arduino_nano_header 21 0>;
42+
43+
pwms = <&pwm1 1 255 PWM_POLARITY_NORMAL>,
44+
<&pwm1 2 255 PWM_POLARITY_NORMAL>,
45+
<&pwm1 3 255 PWM_POLARITY_NORMAL>,
46+
<&pwm2 0 255 PWM_POLARITY_NORMAL>,
47+
<&pwm2 1 255 PWM_POLARITY_NORMAL>,
48+
<&pwm2 2 255 PWM_POLARITY_NORMAL>,
49+
<&pwm2 3 255 PWM_POLARITY_NORMAL>;
50+
51+
io-channels = <&adc 2>,
52+
<&adc 3>,
53+
<&adc 6>,
54+
<&adc 5>,
55+
<&adc 7>,
56+
<&adc 0>,
57+
<&adc 4>,
58+
<&adc 1>;
59+
60+
gpio-ports = <&gpio0>, <&gpio1>;
61+
serials = <&uart0>;
62+
i2cs = <&arduino_nano_i2c>;
63+
};
64+
};
65+
66+
&adc {
67+
#address-cells = <1>;
68+
#size-cells = <0>;
69+
70+
channel@0 {
71+
reg = <0>;
72+
zephyr,gain = "ADC_GAIN_1_6";
73+
zephyr,reference = "ADC_REF_INTERNAL";
74+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
75+
zephyr,input-positive = <NRF_SAADC_AIN0>; /* P0.02 */
76+
zephyr,resolution = <10>;
77+
};
78+
79+
channel@1 {
80+
reg = <1>;
81+
zephyr,gain = "ADC_GAIN_1_6";
82+
zephyr,reference = "ADC_REF_INTERNAL";
83+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
84+
zephyr,input-positive = <NRF_SAADC_AIN1>; /* P0.03 */
85+
zephyr,resolution = <10>;
86+
};
87+
88+
channel@2 {
89+
reg = <2>;
90+
zephyr,gain = "ADC_GAIN_1_6";
91+
zephyr,reference = "ADC_REF_INTERNAL";
92+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
93+
zephyr,input-positive = <NRF_SAADC_AIN2>; /* P0.04 */
94+
zephyr,resolution = <10>;
95+
};
96+
97+
channel@3 {
98+
reg = <3>;
99+
zephyr,gain = "ADC_GAIN_1_6";
100+
zephyr,reference = "ADC_REF_INTERNAL";
101+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
102+
zephyr,input-positive = <NRF_SAADC_AIN3>; /* P0.05 */
103+
zephyr,resolution = <10>;
104+
};
105+
106+
channel@4 {
107+
reg = <4>;
108+
zephyr,gain = "ADC_GAIN_1_6";
109+
zephyr,reference = "ADC_REF_INTERNAL";
110+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
111+
zephyr,input-positive = <NRF_SAADC_AIN4>; /* P0.28 */
112+
zephyr,resolution = <10>;
113+
};
114+
115+
channel@5 {
116+
reg = <5>;
117+
zephyr,gain = "ADC_GAIN_1_6";
118+
zephyr,reference = "ADC_REF_INTERNAL";
119+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
120+
zephyr,input-positive = <NRF_SAADC_AIN5>; /* P0.29 */
121+
zephyr,resolution = <10>;
122+
};
123+
124+
channel@6 {
125+
reg = <6>;
126+
zephyr,gain = "ADC_GAIN_1_6";
127+
zephyr,reference = "ADC_REF_INTERNAL";
128+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
129+
zephyr,input-positive = <NRF_SAADC_AIN6>; /* P0.30 */
130+
zephyr,resolution = <10>;
131+
};
132+
133+
channel@7 {
134+
reg = <7>;
135+
zephyr,gain = "ADC_GAIN_1_6";
136+
zephyr,reference = "ADC_REF_INTERNAL";
137+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
138+
zephyr,input-positive = <NRF_SAADC_AIN7>; /* P0.31 */
139+
zephyr,resolution = <10>;
140+
};
141+
};
142+
143+
&pinctrl {
144+
pwm1_default: pwm1_default {
145+
group1 {
146+
psels = <NRF_PSEL(PWM_OUT0, 1, 9)>, /* keep original config */
147+
<NRF_PSEL(PWM_OUT1, 1, 12)>,
148+
<NRF_PSEL(PWM_OUT2, 1, 13)>,
149+
<NRF_PSEL(PWM_OUT3, 1, 14)>;
150+
nordic,invert;
151+
};
152+
};
153+
154+
pwm1_sleep: pwm1_sleep {
155+
group1 {
156+
psels = <NRF_PSEL(PWM_OUT0, 1, 9)>, /* keep original config */
157+
<NRF_PSEL(PWM_OUT1, 1, 12)>,
158+
<NRF_PSEL(PWM_OUT2, 1, 13)>,
159+
<NRF_PSEL(PWM_OUT3, 1, 14)>;
160+
low-power-enable;
161+
};
162+
};
163+
164+
pwm2_default: pwm2_default {
165+
group1 {
166+
psels = <NRF_PSEL(PWM_OUT0, 0, 13)>, /* keep original config */
167+
<NRF_PSEL(PWM_OUT1, 0, 27)>,
168+
<NRF_PSEL(PWM_OUT2, 1, 2)>,
169+
<NRF_PSEL(PWM_OUT3, 1, 1)>;
170+
nordic,invert;
171+
};
172+
};
173+
174+
pwm2_sleep: pwm2_sleep {
175+
group1 {
176+
psels = <NRF_PSEL(PWM_OUT0, 0, 13)>, /* keep original config */
177+
<NRF_PSEL(PWM_OUT1, 0, 27)>,
178+
<NRF_PSEL(PWM_OUT2, 1, 2)>,
179+
<NRF_PSEL(PWM_OUT3, 1, 1)>;
180+
low-power-enable;
181+
};
182+
};
183+
};
184+
185+
&pwm1 {
186+
status = "okay";
187+
pinctrl-0 = <&pwm1_default>;
188+
pinctrl-1 = <&pwm1_sleep>;
189+
pinctrl-names = "default", "sleep";
190+
};
191+
192+
&pwm2 {
193+
status = "okay";
194+
pinctrl-0 = <&pwm2_default>;
195+
pinctrl-1 = <&pwm2_sleep>;
196+
pinctrl-names = "default", "sleep";
197+
};

0 commit comments

Comments
 (0)