forked from zephyrproject-rtos/ArduinoCore-zephyr
-
Notifications
You must be signed in to change notification settings - Fork 0
Altminimum #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Altminimum #25
Changes from all commits
Commits
Show all changes
61 commits
Select commit
Hold shift + click to select a range
466e235
wire
soburi 1db1fd3
Revert "x"
soburi 656adfb
Revert "x"
soburi 7a4e60e
x
soburi 68db9ed
x
soburi 04c1aec
x
soburi eaba0dc
x
soburi 767b98e
x
soburi d5d4dfe
x
soburi 97d242a
x
soburi 3ecbfb1
x
soburi d801c36
x
soburi a7d2c9a
x
soburi 9dae731
x
soburi 6d129d6
x
soburi a58608c
x
soburi 727b8a7
x
soburi 2526a17
x
soburi 1fa2641
x
soburi 3a87736
x
soburi d0b96e7
x
soburi 9f2a8bc
x
soburi 99fb903
x
soburi 94bbe02
x
soburi 80bc31c
x
soburi 85629e9
x
soburi cbe0ba1
x
soburi ee85991
x
soburi 67516a6
x
soburi 6769f7e
x
soburi eb4bf71
x
soburi 20b2c45
x
soburi c21537f
x
soburi 882b16e
x
soburi de2e36b
x
soburi 92452bf
x
soburi b32b779
x
soburi 67cf8de
x
soburi c9b9d11
x
soburi 084aa8a
x
soburi 3759945
x
soburi 4034f46
x
soburi 83c3ade
x
soburi 4c2345e
x
soburi 0e7b6ac
x
soburi 7bb4552
x
soburi c47e18a
x
soburi 55327a3
x
soburi 969e633
x
soburi db3ac80
x
soburi faa9d1d
x
soburi c3e9e77
x
soburi 00ca28f
x
soburi d908a9b
x
soburi a16d4dc
x
soburi e0953ae
x
soburi 6da82c1
x
soburi 3d2adab
x
soburi 2c47873
x
soburi 42b9c85
x
soburi 92a766d
x
soburi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| function(rust_target_arch RUST_TARGET) | ||
| # Map Zephyr targets to LLVM targets. | ||
| if(CONFIG_CPU_CORTEX_M) | ||
| if(CONFIG_CPU_CORTEX_M0 OR CONFIG_CPU_CORTEX_M0PLUS OR CONFIG_CPU_CORTEX_M1) | ||
| set(${RUST_TARGET} "thumbv6m-none-eabi" PARENT_SCOPE) | ||
| elseif(CONFIG_CPU_CORTEX_M3) | ||
| set(${RUST_TARGET} "thumbv7m-none-eabi" PARENT_SCOPE) | ||
| elseif(CONFIG_CPU_CORTEX_M4 OR CONFIG_CPU_CORTEX_M7) | ||
| if(CONFIG_FP_HARDABI OR FORCE_FP_HARDABI) | ||
| set(${RUST_TARGET} "thumbv7em-none-eabihf" PARENT_SCOPE) | ||
| else() | ||
| set(${RUST_TARGET} "thumbv7em-none-eabi" PARENT_SCOPE) | ||
| endif() | ||
| elseif(CONFIG_CPU_CORTEX_M23) | ||
| set(${RUST_TARGET} "thumbv8m.base-none-eabi" PARENT_SCOPE) | ||
| elseif(CONFIG_CPU_CORTEX_M33 OR CONFIG_CPU_CORTEX_M55) | ||
| if(CONFIG_FP_HARDABI OR FORCE_FP_HARDABI) | ||
| set(${RUST_TARGET} "thumbv8m.main-none-eabihf" PARENT_SCOPE) | ||
| else() | ||
| set(${RUST_TARGET} "thumbv8m.main-none-eabi" PARENT_SCOPE) | ||
| endif() | ||
| else() | ||
| message(FATAL_ERROR "Unknown Cortex-M target.") | ||
| endif() | ||
| elseif(CONFIG_RISCV) | ||
| if(CONFIG_RISCV_ISA_RV64I) | ||
| set(${RUST_TARGET} "riscv64imac-unknown-none-elf" PARENT_SCOPE) | ||
| elseif(CONFIG_RISCV_ISA_RV32I) | ||
| set(${RUST_TARGET} "riscv32i-unknown-none-elf" PARENT_SCOPE) | ||
| else() | ||
| message(FATAL_ERROR "Rust: Unsupported riscv ISA") | ||
| endif() | ||
| elseif(CONFIG_ARCH_POSIX AND CONFIG_64BIT AND (${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "x86_64")) | ||
| set(${RUST_TARGET} "x86_64-unknown-none" PARENT_SCOPE) | ||
| elseif(CONFIG_ARCH_POSIX AND CONFIG_64BIT AND (${CMAKE_HOST_SYSTEM_PROCESSOR} MATCHES "aarch64")) | ||
| set(${RUST_TARGET} "aarch64-unknown-none" PARENT_SCOPE) | ||
| else() | ||
| message(FATAL_ERROR "Rust: Add support for other target") | ||
| endif() | ||
| endfunction() | ||
|
|
||
| rust_target_arch(RUST_TARGET_TRIPLE) | ||
|
|
||
| if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/rust/Cargo.toml) | ||
| set(RUST_CRATE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/rust) | ||
| else() | ||
| set(RUST_CRATE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../rust) | ||
| endif() | ||
| set(RUST_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}/rust) | ||
| set(RUST_LIB ${RUST_OUT_DIR}/target/${RUST_TARGET_TRIPLE}/release/libarduinocore_api_rust.a) | ||
| set(RUST_SRCS | ||
| ${RUST_CRATE_DIR}/src/lib.rs | ||
| ${RUST_CRATE_DIR}/src/common.rs | ||
| ) | ||
|
|
||
| add_custom_command( | ||
| OUTPUT ${RUST_LIB} | ||
| COMMAND ${CMAKE_COMMAND} -E env CARGO_TARGET_DIR=${RUST_OUT_DIR}/target | ||
| cargo build --manifest-path ${RUST_CRATE_DIR}/Cargo.toml | ||
| --target ${RUST_TARGET_TRIPLE} --release | ||
| WORKING_DIRECTORY ${RUST_CRATE_DIR} | ||
| DEPENDS ${RUST_CRATE_DIR}/Cargo.toml ${RUST_SRCS} | ||
| COMMENT "Building Rust staticlib for ${RUST_TARGET_TRIPLE}" | ||
| VERBATIM | ||
| ) | ||
|
|
||
| add_custom_target(arduinocore_api_rust_build ALL DEPENDS ${RUST_LIB}) | ||
| add_library(arduinocore_api_rust STATIC IMPORTED GLOBAL) | ||
| set_target_properties(arduinocore_api_rust PROPERTIES IMPORTED_LOCATION ${RUST_LIB}) | ||
| zephyr_link_libraries(arduinocore_api_rust) | ||
|
|
||
| add_subdirectory(idl) | ||
| add_subdirectory(api) | ||
|
|
||
| if(TARGET arduinocore_idl_generate_interfaces) | ||
| add_dependencies(app arduinocore_idl_generate_interfaces) | ||
| endif() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| #pragma once | ||
|
|
||
| #ifdef __cplusplus | ||
| #include <cstdint> | ||
| #include <cstddef> | ||
| #else | ||
| #include <stdint.h> | ||
| #include <stddef.h> | ||
| #endif | ||
| #include <stdlib.h> | ||
|
|
||
| #include <zephyr/drivers/gpio.h> | ||
| #include <zephyr/sys/util.h> | ||
|
|
||
| #include "common_types.h" | ||
|
|
||
| //#ifdef __cplusplus | ||
| //extern "C" { | ||
| //#endif | ||
|
|
||
| typedef gpio_port_pins_t pin_size_t; | ||
|
|
||
| typedef void (*voidFuncPtr)(void); | ||
| typedef void (*voidFuncPtrParam)(void*); | ||
|
|
||
| void setup(void); | ||
| void loop(void); | ||
|
|
||
| void delay(unsigned long); | ||
|
|
||
| namespace arduino { | ||
| } | ||
|
|
||
| using namespace arduino; | ||
|
|
||
| template <class T> constexpr const T &max(const T &a, const T &b) { | ||
| return (a < b) ? b : a; | ||
| } | ||
|
|
||
| template <class T> constexpr const T &min(const T &a, const T &b) { | ||
| return (a < b) ? a : b; | ||
| } | ||
|
|
||
| #if 0 | ||
| void yield(void); | ||
|
|
||
| void init(void); | ||
| void initVariant(void); | ||
|
|
||
| int main() __attribute__((weak)); | ||
|
|
||
| void pinMode(pin_size_t pinNumber, PinMode pinMode); | ||
| void digitalWrite(pin_size_t pinNumber, PinStatus status); | ||
| PinStatus digitalRead(pin_size_t pinNumber); | ||
| int analogRead(pin_size_t pinNumber); | ||
| void analogReference(uint8_t mode); | ||
| void analogWrite(pin_size_t pinNumber, int value); | ||
|
|
||
| unsigned long millis(void); | ||
| unsigned long micros(void); | ||
| void delay(unsigned long); | ||
| void delayMicroseconds(unsigned int us); | ||
| unsigned long pulseIn(pin_size_t pin, uint8_t state, unsigned long timeout); | ||
| unsigned long pulseInLong(pin_size_t pin, uint8_t state, unsigned long timeout); | ||
|
|
||
| void shiftOut(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder, uint8_t val); | ||
| uint8_t shiftIn(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOrder); | ||
|
|
||
| void attachInterrupt(pin_size_t interruptNumber, voidFuncPtr callback, PinStatus mode); | ||
| void attachInterruptParam(pin_size_t interruptNumber, voidFuncPtrParam callback, PinStatus mode, void* param); | ||
| void detachInterrupt(pin_size_t interruptNumber); | ||
|
|
||
| void setup(void); | ||
| void loop(void); | ||
|
|
||
| #ifdef __cplusplus | ||
| } // extern "C" | ||
| #endif | ||
|
|
||
| unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); | ||
| unsigned long pulseInLong(uint8_t pin, uint8_t state, unsigned long timeout = 1000000L); | ||
|
|
||
| void tone(uint8_t _pin, unsigned int frequency, unsigned long duration = 0); | ||
| void noTone(uint8_t _pin); | ||
|
|
||
| // WMath prototypes | ||
| long random(long); | ||
| long random(long, long); | ||
| void randomSeed(unsigned long); | ||
|
|
||
|
|
||
| extern "C" { | ||
| int32_t map_i32(int32_t x, int32_t in_min, int32_t in_max, int32_t out_min, int32_t out_max); | ||
| uint16_t makeWord_w(uint16_t w); | ||
| uint16_t makeWord_hl(uint8_t h, uint8_t l); | ||
| } | ||
|
|
||
| inline long map(long x, long in_min, long in_max, long out_min, long out_max) | ||
| { | ||
| return map_i32(x, in_min, in_max, out_min, out_max); | ||
| } | ||
|
|
||
| inline uint16_t makeWord(uint16_t w) { | ||
| return makeWord_w(w); | ||
| } | ||
|
|
||
| inline uint16_t makeWord(uint8_t h, uint8_t l) { | ||
| return makeWord_hl(h, l); | ||
| } | ||
|
|
||
| #define word(...) makeWord(__VA_ARGS__) | ||
|
|
||
| #ifdef __cplusplus | ||
| template<class T, class L> | ||
| auto min(const T& a, const L& b) -> decltype((b < a) ? b : a) | ||
| { | ||
| return (b < a) ? b : a; | ||
| } | ||
|
|
||
| template<class T, class L> | ||
| auto max(const T& a, const L& b) -> decltype((b < a) ? b : a) | ||
| { | ||
| return (a < b) ? b : a; | ||
| } | ||
| #else | ||
| #ifndef min | ||
| #define min(a,b) \ | ||
| ({ __typeof__ (a) _a = (a); \ | ||
| __typeof__ (b) _b = (b); \ | ||
| _a < _b ? _a : _b; }) | ||
| #endif | ||
| #ifndef max | ||
| #define max(a,b) \ | ||
| ({ __typeof__ (a) _a = (a); \ | ||
| __typeof__ (b) _b = (b); \ | ||
| _a > _b ? _a : _b; }) | ||
| #endif | ||
| #endif | ||
| #endif | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| zephyr_sources(zephyrPrint.cpp) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| /* | ||
| * Copyright (c) 2026 TOKITA Hiroshi | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| /* stub file for compat */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /* | ||
| * Copyright (c) 2026 TOKITA Hiroshi | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "Stream.h" | ||
| #include <hardware_serial_interface.hpp> | ||
|
|
||
| namespace arduino { | ||
|
|
||
| enum SerialConfig { | ||
| SERIAL_5E1 = (SERIAL_DATA_5 | SERIAL_PARITY_EVEN | SERIAL_STOP_BIT_1), | ||
| SERIAL_5E2 = (SERIAL_DATA_5 | SERIAL_PARITY_EVEN | SERIAL_STOP_BIT_2), | ||
| SERIAL_5O1 = (SERIAL_DATA_5 | SERIAL_PARITY_ODD | SERIAL_STOP_BIT_1), | ||
| SERIAL_5O2 = (SERIAL_DATA_5 | SERIAL_PARITY_ODD | SERIAL_STOP_BIT_2), | ||
| SERIAL_5N1 = (SERIAL_DATA_5 | SERIAL_PARITY_NONE | SERIAL_STOP_BIT_1), | ||
| SERIAL_5N2 = (SERIAL_DATA_5 | SERIAL_PARITY_NONE | SERIAL_STOP_BIT_2), | ||
| SERIAL_5M1 = (SERIAL_DATA_5 | SERIAL_PARITY_MARK | SERIAL_STOP_BIT_1), | ||
| SERIAL_5M2 = (SERIAL_DATA_5 | SERIAL_PARITY_MARK | SERIAL_STOP_BIT_2), | ||
| SERIAL_5S1 = (SERIAL_DATA_5 | SERIAL_PARITY_SPACE | SERIAL_STOP_BIT_1), | ||
| SERIAL_5S2 = (SERIAL_DATA_5 | SERIAL_PARITY_SPACE | SERIAL_STOP_BIT_2), | ||
| SERIAL_6E1 = (SERIAL_DATA_6 | SERIAL_PARITY_EVEN | SERIAL_STOP_BIT_1), | ||
| SERIAL_6E2 = (SERIAL_DATA_6 | SERIAL_PARITY_EVEN | SERIAL_STOP_BIT_2), | ||
| SERIAL_6O1 = (SERIAL_DATA_6 | SERIAL_PARITY_ODD | SERIAL_STOP_BIT_1), | ||
| SERIAL_6O2 = (SERIAL_DATA_6 | SERIAL_PARITY_ODD | SERIAL_STOP_BIT_2), | ||
| SERIAL_6N1 = (SERIAL_DATA_6 | SERIAL_PARITY_NONE | SERIAL_STOP_BIT_1), | ||
| SERIAL_6N2 = (SERIAL_DATA_6 | SERIAL_PARITY_NONE | SERIAL_STOP_BIT_2), | ||
| SERIAL_6M1 = (SERIAL_DATA_6 | SERIAL_PARITY_MARK | SERIAL_STOP_BIT_1), | ||
| SERIAL_6M2 = (SERIAL_DATA_6 | SERIAL_PARITY_MARK | SERIAL_STOP_BIT_2), | ||
| SERIAL_6S1 = (SERIAL_DATA_6 | SERIAL_PARITY_SPACE | SERIAL_STOP_BIT_1), | ||
| SERIAL_6S2 = (SERIAL_DATA_6 | SERIAL_PARITY_SPACE | SERIAL_STOP_BIT_2), | ||
| SERIAL_7E1 = (SERIAL_DATA_7 | SERIAL_PARITY_EVEN | SERIAL_STOP_BIT_1), | ||
| SERIAL_7E2 = (SERIAL_DATA_7 | SERIAL_PARITY_EVEN | SERIAL_STOP_BIT_2), | ||
| SERIAL_7O1 = (SERIAL_DATA_7 | SERIAL_PARITY_ODD | SERIAL_STOP_BIT_1), | ||
| SERIAL_7O2 = (SERIAL_DATA_7 | SERIAL_PARITY_ODD | SERIAL_STOP_BIT_2), | ||
| SERIAL_7N1 = (SERIAL_DATA_7 | SERIAL_PARITY_NONE | SERIAL_STOP_BIT_1), | ||
| SERIAL_7N2 = (SERIAL_DATA_7 | SERIAL_PARITY_NONE | SERIAL_STOP_BIT_2), | ||
| SERIAL_7M1 = (SERIAL_DATA_7 | SERIAL_PARITY_MARK | SERIAL_STOP_BIT_1), | ||
| SERIAL_7M2 = (SERIAL_DATA_7 | SERIAL_PARITY_MARK | SERIAL_STOP_BIT_2), | ||
| SERIAL_7S1 = (SERIAL_DATA_7 | SERIAL_PARITY_SPACE | SERIAL_STOP_BIT_1), | ||
| SERIAL_7S2 = (SERIAL_DATA_7 | SERIAL_PARITY_SPACE | SERIAL_STOP_BIT_2), | ||
| SERIAL_8E1 = (SERIAL_DATA_8 | SERIAL_PARITY_EVEN | SERIAL_STOP_BIT_1), | ||
| SERIAL_8E2 = (SERIAL_DATA_8 | SERIAL_PARITY_EVEN | SERIAL_STOP_BIT_2), | ||
| SERIAL_8O1 = (SERIAL_DATA_8 | SERIAL_PARITY_ODD | SERIAL_STOP_BIT_1), | ||
| SERIAL_8O2 = (SERIAL_DATA_8 | SERIAL_PARITY_ODD | SERIAL_STOP_BIT_2), | ||
| SERIAL_8N1 = (SERIAL_DATA_8 | SERIAL_PARITY_NONE | SERIAL_STOP_BIT_1), | ||
| SERIAL_8N2 = (SERIAL_DATA_8 | SERIAL_PARITY_NONE | SERIAL_STOP_BIT_2), | ||
| SERIAL_8M1 = (SERIAL_DATA_8 | SERIAL_PARITY_MARK | SERIAL_STOP_BIT_1), | ||
| SERIAL_8M2 = (SERIAL_DATA_8 | SERIAL_PARITY_MARK | SERIAL_STOP_BIT_2), | ||
| SERIAL_8S1 = (SERIAL_DATA_8 | SERIAL_PARITY_SPACE | SERIAL_STOP_BIT_1), | ||
| SERIAL_8S2 = (SERIAL_DATA_8 | SERIAL_PARITY_SPACE | SERIAL_STOP_BIT_2), | ||
| }; | ||
|
|
||
| class HardwareSerial : virtual public Stream, virtual public HardwareSerialInterface { | ||
| public: | ||
| using Print::write; | ||
| }; | ||
|
|
||
| extern void __weak serialEventRun(void); | ||
|
|
||
| } // namespace arduino |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost the entire Arduino API surface is currently disabled by
#if 0(starting here), including core declarations likepinMode,digitalWrite, interrupt APIs, and themap/makeWordhelpers. With the Rust implementation enabled, sketches including<Arduino.h>will not see these declarations and will fail to compile (e.g., the blinky sample calls pinMode/digitalWrite). Replace#if 0with the intended feature guard or remove it so these APIs are declared.