Skip to content

Commit 7eb3eae

Browse files
committed
Update PR to reflect changes from this morning
1 parent f4b4f46 commit 7eb3eae

40 files changed

+13279
-6575
lines changed

Diff for: CMakeLists.txt

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# SPDX-License-Identifier: Apache-2.0
22

3+
string(REPLACE "__" "_" NORMALIZED_BOARD_TARGET "${NORMALIZED_BOARD_TARGET}")
4+
35
if (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/variants/${BOARD})
46
set(variant_dir variants/${BOARD})
5-
elseif (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS})
6-
set(variant_dir variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS})
7+
elseif (IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/variants/${NORMALIZED_BOARD_TARGET})
8+
set(variant_dir variants/${NORMALIZED_BOARD_TARGET})
79
else()
8-
message(INFO "Variant dir not found: variants/${BOARD}, variants/${BOARD}${NORMALIZED_BOARD_QUALIFIERS}")
10+
if (CONFIG_ARDUINO_API)
11+
message(FATAL_ERROR "Variant dir not found: variants/${BOARD}, variants/${NORMALIZED_BOARD_TARGET}")
12+
endif()
913
endif()
1014

1115
if (CONFIG_ARDUINO_API)

Diff for: cores/arduino/Arduino.h

+16
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <zephyr/drivers/gpio.h>
1313
#include <zephyr/drivers/pwm.h>
1414
#include <zephyr/drivers/adc.h>
15+
#include <zephyr/drivers/dac.h>
1516
#include <zephyr/drivers/i2c.h>
1617
#include <math.h>
1718

@@ -102,6 +103,17 @@ enum analogPins { DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user),
102103

103104
#endif
104105

106+
#ifdef CONFIG_DAC
107+
108+
#undef DAC0
109+
#undef DAC1
110+
#undef DAC2
111+
#undef DAC3
112+
#define DAC_ENUMS(n, p, i) DAC ## i = i,
113+
enum dacPins { DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), dac_channels, DAC_ENUMS) NUM_OF_DACS };
114+
115+
#endif
116+
105117
void interrupts(void);
106118
void noInterrupts(void);
107119

@@ -112,13 +124,17 @@ int digitalPinToInterrupt(pin_size_t pin);
112124
#define portOutputRegister(x) (x)
113125
#define portInputRegister(x) (x)
114126

127+
void analogReadResolution(int bits);
128+
void analogWriteResolution(int bits);
129+
115130
#include <variant.h>
116131
#ifdef __cplusplus
117132
#include <SerialUSB.h>
118133
#include <zephyrSerial.h>
119134
#include <strings.h>
120135
#include <api/itoa.h>
121136
#include <time_macros.h>
137+
#include <overloads.h>
122138

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

Diff for: cores/arduino/CMakeLists.txt

+10-1
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,19 @@ if(NOT DEFINED ARDUINO_BUILD_PATH)
66

77
zephyr_sources(zephyrSerial.cpp)
88
zephyr_sources(zephyrCommon.cpp)
9+
zephyr_sources(USB.cpp)
10+
zephyr_sources(itoa.cpp)
11+
12+
zephyr_sources(api/CanMsg.cpp)
13+
zephyr_sources(api/CanMsgRingbuffer.cpp)
14+
zephyr_sources(api/Common.cpp)
15+
zephyr_sources(api/IPAddress.cpp)
16+
zephyr_sources(api/Print.cpp)
17+
zephyr_sources(api/Stream.cpp)
18+
zephyr_sources(api/String.cpp)
919

1020
if(DEFINED CONFIG_ARDUINO_ENTRY)
1121
zephyr_sources(main.cpp)
1222
endif()
1323

1424
endif()
15-

Diff for: cores/arduino/SerialUSB.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ class SerialUSB_ : public ZephyrSerial {
3131
};
3232
} // namespace arduino
3333

34-
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm)
34+
#if (DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) && CONFIG_USB_CDC_ACM)
3535
extern arduino::SerialUSB_ Serial;
3636
#endif

Diff for: cores/arduino/USB.cpp

+1-11
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,13 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
// Make PluggableUSB link happy
8-
#include "api/PluggableUSB.h"
9-
10-
static uint8_t _epBuffer[1];
11-
void* epBuffer(unsigned int n) {
12-
return &_epBuffer[n];
13-
};
14-
15-
arduino::PluggableUSB_::PluggableUSB_() {}
16-
177
#include <zephyr/devicetree.h>
188
#include <zephyr/drivers/uart.h>
199
#include <zephyr/drivers/uart/cdc_acm.h>
2010
#include <zephyr/usb/usb_device.h>
2111
#include <SerialUSB.h>
2212

23-
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm)
13+
#if (DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) && CONFIG_USB_CDC_ACM)
2414
const struct device *const usb_dev = DEVICE_DT_GET(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), cdc_acm, 0));
2515

2616
void usb_status_cb(enum usb_dc_status_code cb_status, const uint8_t *param) {

Diff for: cores/arduino/overloads.h

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifdef CONFIG_DAC
2+
3+
void analogWrite(enum dacPins pinNumber, int value);
4+
5+
#endif
6+
7+
// In c++ mode, we also provide analogReadResolution and analogWriteResolution getters
8+
int analogReadResolution();
9+
int analogWriteResolution();

Diff for: cores/arduino/zephyrCommon.cpp

+50-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ size_t pwm_pin_index(pin_size_t pinNumber) {
163163
DT_PHA_BY_IDX(DT_PATH(zephyr_user), p, i, pin)),
164164
#define ADC_CH_CFG(n,p,i) arduino_adc[i].channel_cfg,
165165

166-
const struct adc_dt_spec arduino_adc[] =
166+
static const struct adc_dt_spec arduino_adc[] =
167167
{ DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), io_channels, ADC_DT_SPEC) };
168168

169169
/* io-channel-pins node provides a mapping digital pin numbers to adc channels */
@@ -184,6 +184,28 @@ size_t analog_pin_index(pin_size_t pinNumber) {
184184

185185
#endif //CONFIG_ADC
186186

187+
#ifdef CONFIG_DAC
188+
189+
#if (DT_NODE_HAS_PROP(DT_PATH(zephyr_user), dac))
190+
191+
#define DAC_NODE DT_PHANDLE(DT_PATH(zephyr_user), dac)
192+
#define DAC_RESOLUTION DT_PROP(DT_PATH(zephyr_user), dac_resolution)
193+
static const struct device *const dac_dev = DEVICE_DT_GET(DAC_NODE);
194+
195+
#define DAC_CHANNEL_DEFINE(n, p, i) \
196+
{ \
197+
.channel_id = DT_PROP_BY_IDX(n, p, i), \
198+
.resolution = DAC_RESOLUTION, \
199+
.buffered = true, \
200+
},
201+
202+
static const struct dac_channel_cfg dac_ch_cfg[] =
203+
{ DT_FOREACH_PROP_ELEM(DT_PATH(zephyr_user), dac_channels, DAC_CHANNEL_DEFINE) };
204+
205+
#endif
206+
207+
#endif //CONFIG_DAC
208+
187209
static unsigned int irq_key;
188210
static bool interrupts_disabled = false;
189211
}
@@ -276,6 +298,16 @@ unsigned long micros(void) {
276298

277299
unsigned long millis(void) { return k_uptime_get_32(); }
278300

301+
#if defined(CONFIG_DAC) || defined(CONFIG_PWM)
302+
static int _analog_write_resolution = 8;
303+
void analogWriteResolution(int bits) {
304+
_analog_write_resolution = bits;
305+
}
306+
int analogWriteResolution() {
307+
return _analog_write_resolution;
308+
}
309+
#endif
310+
279311
#ifdef CONFIG_PWM
280312

281313
void analogWrite(pin_size_t pinNumber, int value)
@@ -290,6 +322,8 @@ void analogWrite(pin_size_t pinNumber, int value)
290322
return;
291323
}
292324

325+
value = map(value, 0, 1 << _analog_write_resolution, 0, arduino_pwm[idx].period);
326+
293327
if (((uint32_t)value) > arduino_pwm[idx].period) {
294328
value = arduino_pwm[idx].period;
295329
} else if (value < 0) {
@@ -305,6 +339,21 @@ void analogWrite(pin_size_t pinNumber, int value)
305339

306340
#endif
307341

342+
#ifdef CONFIG_DAC
343+
void analogWrite(enum dacPins dacName, int value)
344+
{
345+
if (dacName >= NUM_OF_DACS) {
346+
return;
347+
}
348+
349+
dac_channel_setup(dac_dev, &dac_ch_cfg[dacName]);
350+
351+
const int max_dac_value = 1U << dac_ch_cfg[dacName].resolution;
352+
dac_write_value(dac_dev, dac_ch_cfg[dacName].channel_id, map(value, 0, 1 << _analog_write_resolution, 0, max_dac_value));
353+
}
354+
#endif
355+
356+
308357
#ifdef CONFIG_ADC
309358

310359
void analogReference(uint8_t mode)

Diff for: cores/arduino/zephyrSerial.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,16 @@ void arduino::ZephyrSerial::flush() {
198198
}
199199
}
200200

201+
#if (DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm))
202+
#define FIRST_UART_INDEX 1
203+
#else
204+
#define FIRST_UART_INDEX 0
205+
#endif
201206

202207
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), serials)
203-
#if !DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm)
208+
#if !(DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) && CONFIG_USB_CDC_ACM)
204209
// If CDC USB, use that object as Serial (and SerialUSB)
205-
arduino::ZephyrSerial Serial(DEVICE_DT_GET(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), serials, 0)));
210+
arduino::ZephyrSerial Serial(DEVICE_DT_GET(DT_PHANDLE_BY_IDX(DT_PATH(zephyr_user), serials, FIRST_UART_INDEX)));
206211
#endif
207212
#if (DT_PROP_LEN(DT_PATH(zephyr_user), serials) > 1)
208213
#define ARDUINO_SERIAL_DEFINED_0 1

Diff for: cores/arduino/zephyrSerial.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class ZephyrSerial : public HardwareSerial
8181
} // namespace arduino
8282

8383
#if DT_NODE_HAS_PROP(DT_PATH(zephyr_user), serials)
84-
#if !DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm)
84+
#if !(DT_NODE_HAS_PROP(DT_PATH(zephyr_user), cdc_acm) && CONFIG_USB_CDC_ACM)
8585
// If CDC USB, use that object as Serial (and SerialUSB)
8686
extern arduino::ZephyrSerial Serial;
8787
#endif

Diff for: extra/bootstrap.sh

+3
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ west init -l .
1212
west update
1313
pip install -r ../zephyr/scripts/requirements-base.txt
1414
# download slim toolchain from https://github.com/zephyrproject-rtos/sdk-ng/releases/tag/v0.16.8
15+
16+
# add here the required blobs based on supported platforms
17+
west blobs fetch hal_nxp

Diff for: firmwares/zephyr-arduino_giga_r1_m7.bin

1.62 KB
Binary file not shown.

Diff for: firmwares/zephyr-arduino_giga_r1_m7.elf

20.7 KB
Binary file not shown.

0 commit comments

Comments
 (0)