Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
a0888d0
samples: hello_arduino: Correct printk format specifier (again)
soburi Feb 26, 2026
8f7c7db
cores: arduino: Format with clang-format
soburi Feb 27, 2026
e440ec6
cores: arduino: zephyrPrint: Fix typo
soburi Mar 1, 2026
366a634
cores: arduino: digitalPins: take into account boards without gpios
facchinm Oct 1, 2024
8696226
Arduino.h: fix DIGITAL_PIN_EXISTS macro to avoid comment expansion is…
pillo79 Mar 12, 2025
8c85e36
cores: arduino: add macro to find pins by node
sebromero Sep 17, 2025
3693469
cores: arduino: zephyrCommon: warning squash
pillo79 Apr 10, 2025
9d9665b
cores: arduino: Arduino.h: Fix typo
soburi Mar 1, 2026
7acef85
Wire: reset ring buffer during requestFrom() call
JZimnol Mar 11, 2026
fe7c9b5
Wire: fix the behavior of the arduino::ZephyrI2C::read()
JZimnol Mar 11, 2026
9e134ee
Wire: don't use rxRingBuffer.buffer directly for i2c_read() calls
JZimnol Mar 11, 2026
03f35e6
Wire: fix the behavior of the arduino::ZephyrI2C::peek()
JZimnol Mar 11, 2026
ea100a9
Wire: avoid buffer overflow in arduino::ZephyrI2C::write(uint8_t)
JZimnol Mar 11, 2026
a2822be
Wire: add logging module, add basic error logs
JZimnol Mar 11, 2026
ce662c6
variants: Add initial native_sim support
DhruvaG2000 Mar 29, 2026
78bcf6a
libraries: Format with clang-format
soburi Apr 17, 2026
fad6df7
Fix micros() for nano without breaking giga
KurtE Jan 30, 2025
0b9b69d
zephyrCommon: improve delay* accurancy
facchinm Feb 16, 2026
f503bac
core: add time related macros
facchinm Dec 13, 2024
05001be
Arduino.h: properly inline delay and delayMicroseconds
pillo79 Mar 4, 2026
8e23269
treewide: fix SPDX tags on existing files
soburi Apr 17, 2026
6885448
libraries: Wire: Compile only CONFIG_I2C enabled
soburi Apr 25, 2026
6af32d0
cores: arduino: analogWrite: Fix max value calculation
soburi Apr 27, 2026
081c7b0
analogWrite: implement DAC pins
facchinm Jan 23, 2025
d78c44c
Implement analogReadResolution
KurtE Jan 27, 2025
ee33055
cores: arduino: zephyrCommon: make analogReference as weak func
facchinm Aug 26, 2025
4069733
CI: Specify revision on BeagleConnect Freedom
soburi May 3, 2026
5146532
zephyrSerial: Keeping up with UART API changes
soburi May 27, 2026
1316b52
cores: arduino: zephyrCommon: rework tone slot handling and timer lif…
soburi Apr 16, 2026
4ac5092
analogWrite: add digitalWrite fallback for analogWrite without PWM
vs11official Mar 23, 2026
9521617
zephyrCommon: fix issues with invalid pin numbers
pillo79 Mar 13, 2026
5cd4785
core: Introduce digitalPinTo(PortDevice|PinIndex)
facchinm Apr 7, 2026
eb95065
core: Define F_CPU for ARM targets
soburi Jun 1, 2026
19f3aa3
variants: Added legacy pin coverager for nano 33 boards
mjs513 Jan 30, 2025
6806d96
core: add dynamic peripheral init for pinmux switching
facchinm Nov 17, 2025
cab36f7
cores: Define `invalid_pin_number`
soburi May 4, 2026
0abcb2e
cores: Specify port/pin instead of gpio_dt_spec.
soburi May 4, 2026
b5c0676
cores: Generate ADC/PWM config from connector definition
soburi May 4, 2026
61b31f3
documentation: Add configuration guide and reference
soburi Feb 15, 2026
d7b3c5b
variant: Adds support for Arduino Uno R4.
soburi Feb 9, 2026
e4ba9af
cores: arduino: zephyrCommon.cpp: fix struct initialization warnings
soburi Apr 18, 2026
1454458
cores: arduino: Extract definitions used for compile-time calculations
soburi Apr 17, 2026
649366a
cores: arduino: Split zephyrCommon.cpp
soburi Apr 17, 2026
c1af5a4
core: PWM/ADC constants make into `constexpr`
soburi May 7, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:

- name: Build adc
run: |
west build -p -b beagleconnect_freedom/cc1352p7 $MODULE_PATH/samples/analog_input
west build -p -b beagleconnect_freedom@C7/cc1352p7 $MODULE_PATH/samples/analog_input

- name: Archive firmware
uses: actions/upload-artifact@v4
Expand Down
9 changes: 7 additions & 2 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ config ARDUINO_MAX_TONES
default -1
help
Specify the maximum number of tones that can be played simultaneously with tone().
If set to a negative value, the maximum number will be determined from the
system's digital pin configuration.
If set to -1 (or any other negative value), the maximum number will be
determined from the system's digital pin configuration.

module = ARDUINO_API
module-str = arduino_api
source "subsys/logging/Kconfig.template.log_config"

endif
135 changes: 112 additions & 23 deletions cores/arduino/Arduino.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2022 Dhruva Gole
* Copyright (c) 2026 TOKITA Hiroshi
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -12,43 +13,53 @@
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/pwm.h>
#include <zephyr/drivers/adc.h>
#include <zephyr/drivers/dac.h>
#include <zephyr/drivers/i2c.h>

#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), digital_pin_gpios)

#if DT_PROP_LEN(DT_PATH(zephyr_user), digital_pin_gpios) > 0
/* Note: DT_REG_ADDR needs an expanded argument or it will not work properly */
#define DIGITAL_PIN_MATCHES(dev_pha, pin, dev, num) \
(((dev == DT_REG_ADDR(dev_pha)) && (num == pin)) ? 1 : 0)
#define DIGITAL_PIN_EXISTS(n, p, i, dev, num) \
(((dev == DT_REG_ADDR(DT_PHANDLE_BY_IDX(n, p, i))) && \
(num == DT_PHA_BY_IDX(n, p, i, pin))) \
? 1 \
: 0)
DIGITAL_PIN_MATCHES(DT_PHANDLE_BY_IDX(n, p, i), DT_PHA_BY_IDX(n, p, i, pin), dev, num)

/* Check all pins are defined only once */
#define DIGITAL_PIN_CHECK_UNIQUE(i, _) \
((DT_FOREACH_PROP_ELEM_SEP_VARGS( \
DT_PATH(zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, (+), \
DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), digital_pin_gpios, i)), \
((DT_FOREACH_PROP_ELEM_SEP_VARGS( \
DT_PATH(zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, (+), \
DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), digital_pin_gpios, i)), \
DT_PHA_BY_IDX(DT_PATH(zephyr_user), digital_pin_gpios, i, pin))) == 1)

#if !LISTIFY(DT_PROP_LEN(DT_PATH(zephyr_user), digital_pin_gpios), DIGITAL_PIN_CHECK_UNIQUE, (&&))
#error "digital_pin_gpios has duplicate definition"
#endif

#undef DIGITAL_PIN_CHECK_UNIQUE
#endif

// Helper macro to get Arduino pin number from device tree alias
#define DIGITAL_PIN_GPIOS_FIND_NODE(node) \
DIGITAL_PIN_GPIOS_FIND_PIN(DT_REG_ADDR(DT_PHANDLE_BY_IDX(node, gpios, 0)), \
DT_PHA_BY_IDX(node, gpios, 0, pin))

/* Return the index of it if matched, oterwise return 0 */
/* Return the index of it if matched, otherwise return 0 */
#define LED_BUILTIN_INDEX_BY_REG_AND_PINNUM(n, p, i, dev, num) \
(DIGITAL_PIN_EXISTS(n, p, i, dev, num) ? i : 0)

/* Only matched pin returns non-zero value, so the sum is matched pin's index */
#define DIGITAL_PIN_GPIOS_FIND_PIN(dev, pin) \
DT_FOREACH_PROP_ELEM_SEP_VARGS(DT_PATH(zephyr_user), digital_pin_gpios, \
LED_BUILTIN_INDEX_BY_REG_AND_PINNUM, (+), dev, pin)
#define DIGITAL_PIN_GPIOS_FIND_PIN(dev, pin) \
DT_FOREACH_PROP_ELEM_SEP_VARGS(DT_PATH(zephyr_user), digital_pin_gpios, \
LED_BUILTIN_INDEX_BY_REG_AND_PINNUM, (+), dev, pin)

#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), builtin_led_gpios) && \
(DT_PROP_LEN(DT_PATH(zephyr_user), builtin_led_gpios) > 0)

#if !(DT_FOREACH_PROP_ELEM_SEP_VARGS( \
DT_PATH(zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, (+), \
DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0)), \
DT_PHA_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0, pin)) > 0)
#if !(DT_FOREACH_PROP_ELEM_SEP_VARGS( \
DT_PATH(zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, (+), \
DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0)), \
DT_PHA_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0, pin)) > 0)
#warning "pin not found in digital_pin_gpios"
#else
#define ZARD_LED_BUILTIN \
Expand All @@ -60,9 +71,10 @@
/* If digital-pin-gpios is not defined, tries to use the led0 alias */
#elif DT_NODE_EXISTS(DT_ALIAS(led0))

#if !(DT_FOREACH_PROP_ELEM_SEP_VARGS(DT_PATH(zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, \
(+), DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_ALIAS(led0), gpios, 0)), \
DT_PHA_BY_IDX(DT_ALIAS(led0), gpios, 0, pin)) > 0)
#if !(DT_FOREACH_PROP_ELEM_SEP_VARGS(DT_PATH(zephyr_user), digital_pin_gpios, DIGITAL_PIN_EXISTS, \
(+), \
DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_ALIAS(led0), gpios, 0)), \
DT_PHA_BY_IDX(DT_ALIAS(led0), gpios, 0, pin)) > 0)
#warning "pin not found in digital_pin_gpios"
#else
#define ZARD_LED_BUILTIN \
Expand All @@ -74,22 +86,72 @@

#define DN_ENUMS(n, p, i) D##i = i

#else

#include "connectors/connector.h"

#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), builtin_led_gpios) && \
(DT_PROP_LEN(DT_PATH(zephyr_user), builtin_led_gpios) > 0)
#define ZARD_LED_BUILTIN \
ZARD_GLOBAL_GPIO_OFFSET(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0)) + \
DT_PHA_BY_IDX(DT_PATH(zephyr_user), builtin_led_gpios, 0, pin)
#elif DT_NODE_EXISTS(DT_ALIAS(led0))
#define ZARD_LED_BUILTIN \
ZARD_GLOBAL_GPIO_OFFSET(DT_PHANDLE_BY_IDX(DT_ALIAS(led0), gpios, 0)) + \
DT_PHA_BY_IDX(DT_ALIAS(led0), gpios, 0, pin)
#endif
#endif // digital_pin_gpios

/*
* expand as
* enum digitalPins { D0, D1, ... LED... NUM_OF_DIGITAL_PINS };
*/
enum digitalPins {
#if DT_PROP_LEN_OR(DT_PATH(zephyr_user), digital_pin_gpios, 0) > 0
DT_FOREACH_PROP_ELEM_SEP(DT_PATH(zephyr_user), digital_pin_gpios, DN_ENUMS, (, )),
NUM_OF_DIGITAL_PINS
#elif defined(ZARD_CONNECTOR)
DT_FOREACH_MAP_ENTRY(DT_NODELABEL(ZARD_CONNECTOR), gpio_map, ZARD_CONN_DN_ENUMS)
#endif
};

#ifdef CONFIG_ADC

#define AN_ENUMS(n, p, i) A ## i = DIGITAL_PIN_GPIOS_FIND_PIN( \
DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), p, i)), \
DT_PHA_BY_IDX(DT_PATH(zephyr_user), p, i, pin)),
enum analogPins { DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user),
adc_pin_gpios, AN_ENUMS) };
#define AN_ENUMS(n, p, i) \
A##i = DIGITAL_PIN_GPIOS_FIND_PIN(DT_REG_ADDR(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), p, i)), \
DT_PHA_BY_IDX(DT_PATH(zephyr_user), p, i, pin)),

enum analogPins {
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), adc_pin_gpios)
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), digital_pin_gpios)
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), adc_pin_gpios, AN_ENUMS)
#else
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), adc_pin_gpios, ZARD_AN_ENUM_GLOBAL)
#endif
#elif defined(ZARD_CONNECTOR)
DT_FOREACH_MAP_ENTRY(DT_NODELABEL(ZARD_CONNECTOR), gpio_map, ZARD_CONN_AN_ENUMS)
#endif
};

// We provide analogReadResolution APIs
void analogReadResolution(int bits);

#endif

#ifdef CONFIG_DAC

#undef DAC0
#undef DAC1
#undef DAC2
#undef DAC3
#define DAC_ENUMS(n, p, i) DAC##i = i,

enum dacPins {
#if DT_PROP_LEN_OR(DT_PATH(zephyr_user), dac_channels, 0) > 0
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), dac_channels, DAC_ENUMS)
#endif
NUM_OF_DACS
};

#endif

Expand All @@ -98,12 +160,39 @@ void noInterrupts(void);

int digitalPinToInterrupt(pin_size_t pin);

// These defines can be overridden by variant.h if implemented
#define digitalPinToPort(x) (x)
#define digitalPinToBitMask(x) (x)
#define portOutputRegister(x) (x)
#define portInputRegister(x) (x)

const struct device *digitalPinToPortDevice(pin_size_t pinNumber);
int digitalPinToPinIndex(pin_size_t pinNumber);

#if defined(CONFIG_PWM) || defined(CONFIG_DAC)
void analogWriteResolution(int bits);
#endif

#if defined(__arm__)
#define F_CPU (SystemCoreClock)
#endif

#include <variant.h>

#if !defined(LED_BUILTIN) && defined(ZARD_LED_BUILTIN)
#define LED_BUILTIN ZARD_LED_BUILTIN
#endif // LED_BUILTIN

#include <inlines.h>

#ifdef __cplusplus
#include <zephyrSerial.h>
#include <strings.h>
#include <api/itoa.h>
#include <time_macros.h>
#include <overloads.h>

// Allow namespace-less operations if Arduino.h is included
using namespace arduino;

#endif // __cplusplus
7 changes: 7 additions & 0 deletions cores/arduino/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ if(CONFIG_USE_ARDUINO_API_RUST_IMPLEMENTATION)
zephyr_sources(apiCommon.cpp)
endif()

zephyr_sources(wiring_analog.cpp)
zephyr_sources(wiring_digital.cpp)
zephyr_sources(wiring_pulse.cpp)
zephyr_sources(Tone.cpp)
zephyr_sources(WMath.cpp)
zephyr_sources(WInterrupts.cpp)

if(DEFINED CONFIG_ARDUINO_ENTRY)
zephyr_sources(main.cpp)
endif()
Expand Down
Loading
Loading