Skip to content

Commit 88b7ab2

Browse files
committed
Update analogRead to map the return values
Instead of changing the number of bits for the analogRead to use from the count of bits zephyr,resolution Updated the GIGA overlay to change the resolution from 12 to 16.
1 parent 26e0823 commit 88b7ab2

File tree

22 files changed

+76
-58
lines changed

22 files changed

+76
-58
lines changed

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
extra/post_build_tool/distrib/
22
build/
33
venv/
4+
cores/arduino/api/
5+
cores/arduino/api

Diff for: cores/arduino/zephyrCommon.cpp

+15-7
Original file line numberDiff line numberDiff line change
@@ -374,10 +374,13 @@ static int read_resolution = 10;
374374
void analogReadResolution(int bits)
375375
{
376376
read_resolution = bits;
377-
//for(size_t i=0; i<ARRAY_SIZE(arduino_analog_pins); i++) {
378-
// arduino_adc[i].resolution = bits;
379-
// }
380-
}
377+
}
378+
379+
int analogReadResolution()
380+
{
381+
return read_resolution;
382+
}
383+
381384

382385
int analogRead(pin_size_t pinNumber)
383386
{
@@ -404,16 +407,21 @@ int analogRead(pin_size_t pinNumber)
404407
}
405408

406409
seq.channels = BIT(arduino_adc[idx].channel_id);
407-
//seq.resolution = arduino_adc[idx].resolution;
408-
seq.resolution = read_resolution;
410+
seq.resolution = arduino_adc[idx].resolution;
409411
seq.oversampling = arduino_adc[idx].oversampling;
410412

411413
err = adc_read(arduino_adc[idx].dev, &seq);
412414
if (err < 0) {
413415
return err;
414416
}
415417

416-
return buf;
418+
/*
419+
* If necessary map the return value to the
420+
* number of bits the user has asked for
421+
*/
422+
if (read_resolution == seq.resolution) return buf;
423+
if (read_resolution < seq.resolution) return buf >> (seq.resolution - read_resolution);
424+
return buf << (read_resolution - seq.resolution) ;
417425
}
418426

419427
#endif

Diff for: firmwares/zephyr-arduino_giga_r1_m7.bin

4.42 KB
Binary file not shown.

Diff for: firmwares/zephyr-arduino_giga_r1_m7.elf

63 KB
Binary file not shown.

Diff for: loader/boards/arduino_giga_r1_m7.overlay

+14-14
Original file line numberDiff line numberDiff line change
@@ -206,85 +206,85 @@
206206
zephyr,gain = "ADC_GAIN_1";
207207
zephyr,reference = "ADC_REF_INTERNAL";
208208
zephyr,acquisition-time = <ADC_ACQ_TIME_MAX>;
209-
zephyr,resolution = <12>;
209+
zephyr,resolution = <16>;
210210
};
211211
channel@8 {
212212
reg = <8>;
213213
zephyr,gain = "ADC_GAIN_1";
214214
zephyr,reference = "ADC_REF_INTERNAL";
215215
zephyr,acquisition-time = <ADC_ACQ_TIME_MAX>;
216-
zephyr,resolution = <12>;
216+
zephyr,resolution = <16>;
217217
};
218218
channel@9 {
219219
reg = <9>;
220220
zephyr,gain = "ADC_GAIN_1";
221221
zephyr,reference = "ADC_REF_INTERNAL";
222222
zephyr,acquisition-time = <ADC_ACQ_TIME_MAX>;
223-
zephyr,resolution = <12>;
223+
zephyr,resolution = <16>;
224224
};
225225
channel@5 {
226226
reg = <5>;
227227
zephyr,gain = "ADC_GAIN_1";
228228
zephyr,reference = "ADC_REF_INTERNAL";
229229
zephyr,acquisition-time = <ADC_ACQ_TIME_MAX>;
230-
zephyr,resolution = <12>;
230+
zephyr,resolution = <16>;
231231
};
232232
channel@d {
233233
reg = <13>;
234234
zephyr,gain = "ADC_GAIN_1";
235235
zephyr,reference = "ADC_REF_INTERNAL";
236236
zephyr,acquisition-time = <ADC_ACQ_TIME_MAX>;
237-
zephyr,resolution = <12>;
237+
zephyr,resolution = <16>;
238238
};
239239
channel@c {
240240
reg = <12>;
241241
zephyr,gain = "ADC_GAIN_1";
242242
zephyr,reference = "ADC_REF_INTERNAL";
243243
zephyr,acquisition-time = <ADC_ACQ_TIME_MAX>;
244-
zephyr,resolution = <12>;
244+
zephyr,resolution = <16>;
245245
};
246246
channel@a {
247247
reg = <10>;
248248
zephyr,gain = "ADC_GAIN_1";
249249
zephyr,reference = "ADC_REF_INTERNAL";
250250
zephyr,acquisition-time = <ADC_ACQ_TIME_MAX>;
251-
zephyr,resolution = <12>;
251+
zephyr,resolution = <16>;
252252
};
253253
channel@10 {
254254
reg = <16>;
255255
zephyr,gain = "ADC_GAIN_1";
256256
zephyr,reference = "ADC_REF_INTERNAL";
257257
zephyr,acquisition-time = <ADC_ACQ_TIME_MAX>;
258-
zephyr,resolution = <12>;
258+
zephyr,resolution = <16>;
259259
};
260260
channel@12 {
261261
reg = <18>;
262262
zephyr,gain = "ADC_GAIN_1";
263263
zephyr,reference = "ADC_REF_INTERNAL";
264264
zephyr,acquisition-time = <ADC_ACQ_TIME_MAX>;
265-
zephyr,resolution = <12>;
265+
zephyr,resolution = <16>;
266266
};
267267
channel@13 {
268268
reg = <19>;
269269
zephyr,gain = "ADC_GAIN_1";
270270
zephyr,reference = "ADC_REF_INTERNAL";
271271
zephyr,acquisition-time = <ADC_ACQ_TIME_MAX>;
272-
zephyr,resolution = <12>;
272+
zephyr,resolution = <16>;
273273
};
274274
/* PA0_C and PA1_C */
275275
channel@0 {
276276
reg = <0>;
277277
zephyr,gain = "ADC_GAIN_1";
278278
zephyr,reference = "ADC_REF_INTERNAL";
279279
zephyr,acquisition-time = <ADC_ACQ_TIME_MAX>;
280-
zephyr,resolution = <12>;
280+
zephyr,resolution = <16>;
281281
};
282282
channel@1 {
283283
reg = <1>;
284284
zephyr,gain = "ADC_GAIN_1";
285285
zephyr,reference = "ADC_REF_INTERNAL";
286286
zephyr,acquisition-time = <ADC_ACQ_TIME_MAX>;
287-
zephyr,resolution = <12>;
287+
zephyr,resolution = <16>;
288288
};
289289
};
290290

@@ -304,14 +304,14 @@
304304
zephyr,gain = "ADC_GAIN_1";
305305
zephyr,reference = "ADC_REF_INTERNAL";
306306
zephyr,acquisition-time = <ADC_ACQ_TIME_MAX>;
307-
zephyr,resolution = <12>;
307+
zephyr,resolution = <16>;
308308
};
309309
channel@1 {
310310
reg = <1>;
311311
zephyr,gain = "ADC_GAIN_1";
312312
zephyr,reference = "ADC_REF_INTERNAL";
313313
zephyr,acquisition-time = <ADC_ACQ_TIME_MAX>;
314-
zephyr,resolution = <12>;
314+
zephyr,resolution = <16>;
315315
};
316316
};
317317

Diff for: variants/arduino_portenta_h7/llext-edk/Makefile.cflags

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
LLEXT_CFLAGS = -DKERNEL -D__ZEPHYR__=1 -D__LINUX_ERRNO_EXTENSIONS__ -DPICOLIBC_DOUBLE_PRINTF_SCANF -D__PROGRAM_START -DSTM32H747xx -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -DCORE_CM7 -DHSE_VALUE=25000000 -DK_HEAP_MEM_POOL_SIZE=32768 -DLL_EXTENSION_BUILD -fno-strict-aliasing -fno-common -fdiagnostics-color=always -mcpu=cortex-m7 -mthumb -mabi=aapcs -mfpu=fpv5-d16 -mfloat-abi=hard -mfp16-format=ieee -mtp=soft -Wall -Wformat -Wformat-security -Wformat -Wno-format-zero-length -Wdouble-promotion -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -ftls-model=local-exec -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -specs=picolibc.specs -D_POSIX_THREADS -std=c99 -mlong-calls -mthumb -nodefaultlibs -imacros$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include/zephyr/toolchain/zephyr_stdint.h -imacros$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include/generated/zephyr/autoconf.h -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include/generated/zephyr -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include/generated -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/soc/st/stm32 -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/lib/libc/common/include -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include/zephyr/posix -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/lib/posix/options/getopt/ -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/soc/st/stm32/common/. -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/drivers -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/soc/st/stm32/stm32h7x/. -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/usb/device -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/net/l2 -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/net/lib/dns/. -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/shell/modules/kernel_service/thread/../ -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/cmsis/CMSIS/Core/Include -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/modules/cmsis/. -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/stm32/stm32cube/stm32h7xx/soc -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/stm32/stm32cube/stm32h7xx/drivers/include -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/stm32/stm32cube/common_ll/include -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/crypto/tinycrypt/lib/include
1+
LLEXT_CFLAGS = -DKERNEL -D__ZEPHYR__=1 -D__LINUX_ERRNO_EXTENSIONS__ -DPICOLIBC_DOUBLE_PRINTF_SCANF -D__PROGRAM_START -DSTM32H747xx -DUSE_HAL_DRIVER -DUSE_FULL_LL_DRIVER -DCORE_CM7 -DHSE_VALUE=25000000 -DK_HEAP_MEM_POOL_SIZE=32768 -DLL_EXTENSION_BUILD -fno-strict-aliasing -fno-common -fdiagnostics-color=always -mcpu=cortex-m7 -mthumb -mabi=aapcs -mfpu=fpv5-d16 -mfloat-abi=hard -mfp16-format=ieee -mtp=soft -Wall -Wformat -Wformat-security -Wformat -Wno-format-zero-length -Wdouble-promotion -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-asynchronous-unwind-tables -ftls-model=local-exec -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -specs=picolibc.specs -D_POSIX_THREADS -std=c99 -mlong-calls -mthumb -nodefaultlibs -imacros$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include/zephyr/toolchain/zephyr_stdint.h -imacros$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include/generated/zephyr/autoconf.h -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include/generated/zephyr -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include/generated -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/soc/st/stm32 -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/lib/libc/common/include -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include/zephyr/posix -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/lib/posix/options/getopt/ -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/lib/cpp/minimal/include -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/soc/st/stm32/common/. -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/drivers -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/soc/st/stm32/stm32h7x/. -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/usb/device -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/net/l2 -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/net/lib/dns/. -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/shell/modules/kernel_service/thread/../ -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/cmsis/CMSIS/Core/Include -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/modules/cmsis/. -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/stm32/stm32cube/stm32h7xx/soc -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/stm32/stm32cube/stm32h7xx/drivers/include -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/stm32/stm32cube/common_ll/include -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/crypto/tinycrypt/lib/include
22

3-
LLEXT_ALL_INCLUDE_CFLAGS = -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include/generated/zephyr -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include/generated -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/soc/st/stm32 -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/lib/libc/common/include -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include/zephyr/posix -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/lib/posix/options/getopt/ -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/soc/st/stm32/common/. -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/drivers -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/soc/st/stm32/stm32h7x/. -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/usb/device -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/net/l2 -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/net/lib/dns/. -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/shell/modules/kernel_service/thread/../ -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/cmsis/CMSIS/Core/Include -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/modules/cmsis/. -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/stm32/stm32cube/stm32h7xx/soc -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/stm32/stm32cube/stm32h7xx/drivers/include -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/stm32/stm32cube/common_ll/include -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/crypto/tinycrypt/lib/include
3+
LLEXT_ALL_INCLUDE_CFLAGS = -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include/generated/zephyr -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include/generated -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/soc/st/stm32 -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/lib/libc/common/include -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include/zephyr/posix -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/lib/posix/options/getopt/ -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/lib/cpp/minimal/include -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/soc/st/stm32/common/. -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/drivers -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/soc/st/stm32/stm32h7x/. -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/usb/device -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/net/l2 -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/net/lib/dns/. -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/shell/modules/kernel_service/thread/../ -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/cmsis/CMSIS/Core/Include -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/modules/cmsis/. -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/stm32/stm32cube/stm32h7xx/soc -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/stm32/stm32cube/stm32h7xx/drivers/include -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/stm32/stm32cube/common_ll/include -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/crypto/tinycrypt/lib/include
44

5-
LLEXT_INCLUDE_CFLAGS = -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/soc/st/stm32 -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/lib/libc/common/include -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include/zephyr/posix -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/lib/posix/options/getopt/ -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/soc/st/stm32/common/. -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/drivers -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/soc/st/stm32/stm32h7x/. -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/usb/device -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/net/l2 -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/net/lib/dns/. -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/shell/modules/kernel_service/thread/../ -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/cmsis/CMSIS/Core/Include -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/modules/cmsis/. -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/stm32/stm32cube/stm32h7xx/soc -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/stm32/stm32cube/stm32h7xx/drivers/include -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/stm32/stm32cube/common_ll/include -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/crypto/tinycrypt/lib/include
5+
LLEXT_INCLUDE_CFLAGS = -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/soc/st/stm32 -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/lib/libc/common/include -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include/zephyr/posix -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/lib/posix/options/getopt/ -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/lib/cpp/minimal/include -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/soc/st/stm32/common/. -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/drivers -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/soc/st/stm32/stm32h7x/. -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/usb/device -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/net/l2 -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/net/lib/dns/. -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/subsys/shell/modules/kernel_service/thread/../ -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/cmsis/CMSIS/Core/Include -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/modules/cmsis/. -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/stm32/stm32cube/stm32h7xx/soc -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/stm32/stm32cube/stm32h7xx/drivers/include -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/hal/stm32/stm32cube/common_ll/include -I$(LLEXT_EDK_INSTALL_DIR)/include/modules/crypto/tinycrypt/lib/include
66

77
LLEXT_GENERATED_INCLUDE_CFLAGS = -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include/generated/zephyr -I$(LLEXT_EDK_INSTALL_DIR)/include/zephyr/include/generated
88

0 commit comments

Comments
 (0)