Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f5b6505
Fix micros() for nano without breaking giga
KurtE Jan 30, 2025
e4d88f8
cores: arduino: zephyrCommon: rework tone slot handling and timer lif…
soburi Apr 16, 2026
85c5413
zephyrCommon: improve delay* accurancy
facchinm Feb 16, 2026
ae9ff38
core: add time related macros
facchinm Dec 13, 2024
f0a297e
Arduino.h: properly inline delay and delayMicroseconds
pillo79 Mar 4, 2026
b9d124f
treewide: fix SPDX tags on existing files
soburi Apr 17, 2026
654efb0
analogWrite: implement DAC pins
facchinm Jan 23, 2025
5f22a53
Implement analogReadResolution
KurtE Jan 27, 2025
565a002
unoq: implement analogReference
facchinm Aug 26, 2025
8abd725
make internal arduino_adc array static
facchinm Jan 23, 2025
0aa016c
ZephyrCommon: allow boards without any ADC channel configured
facchinm Dec 9, 2024
b3fe8a9
cores: arduino: Format ADC/DAC part with clang-format
soburi Mar 3, 2026
467daa4
cores: arduino: Improve analog(Read|Write)Rsolution declaration
soburi Mar 1, 2026
00c2cdf
cores: arduino: analogWrite: Fix max value calculation
soburi Mar 1, 2026
ebd47d1
cores: arduino: analogWrite: Fix DAC output calculation
soburi Mar 1, 2026
8739cc0
zephyrCommon: fixs analogWrite overflow
gbr1 Apr 15, 2026
7a95671
treewide: fix SPDX tags on existing files
soburi Apr 17, 2026
6627a2c
core: pinmux: implement rough solution
facchinm Nov 17, 2025
51e3597
zephyrCommon: fix issues with invalid pin numbers
pillo79 Mar 13, 2026
8420b2e
fix: analogWrite() silently fails when PWM pin lookup fails on Uno Q
vs11official Mar 23, 2026
9b74e7e
boards: unoq/giga: add implementation of low-level gpio APIs
facchinm Apr 7, 2026
3aa4e62
core: pinmux: wrap peripheral init and deinit operations with CONFIG …
pennam Mar 3, 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
4 changes: 2 additions & 2 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ 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
Expand Down
48 changes: 48 additions & 0 deletions cores/arduino/Arduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#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_PROP_LEN(DT_PATH(zephyr_user), digital_pin_gpios) > 0
Expand Down Expand Up @@ -103,19 +104,66 @@ enum analogPins {
DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), adc_pin_gpios, AN_ENUMS)
};

// 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

void interrupts(void);
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
27 changes: 27 additions & 0 deletions cores/arduino/inlines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) Arduino s.r.l. and/or its affiliated companies
*
* SPDX-License-Identifier: Apache-2.0
*/

/*
* Provide implementations for inline functions.
*/

#ifndef __INLINES_H__
#define __INLINES_H__

#include <zephyr/kernel.h>

inline __attribute__((always_inline)) void delay(unsigned long ms) {
k_sleep(K_MSEC(ms));
}

inline __attribute__((always_inline)) void delayMicroseconds(unsigned int us) {
if (us == 0) {
return;
}
k_busy_wait(us - 1);
}

#endif /* __INLINES_H__ */
15 changes: 15 additions & 0 deletions cores/arduino/overloads.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Copyright (c) Arduino s.r.l. and/or its affiliated companies
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifdef CONFIG_DAC

void analogWrite(enum dacPins pinNumber, int value);

#endif

// In c++ mode, we also provide analogReadResolution and analogWriteResolution getters
int analogReadResolution();
int analogWriteResolution();
13 changes: 13 additions & 0 deletions cores/arduino/time_macros.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright (c) Arduino s.r.l. and/or its affiliated companies
*
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <zephyr/sys/time_units.h>

#define clockCyclesPerMicrosecond() (1000000 / k_cyc_to_ns_near64(1000))
#define clockCyclesToMicroseconds(a) (a / clockCyclesPerMicrosecond())
#define microsecondsToClockCycles(a) (a * clockCyclesPerMicrosecond())
Loading
Loading