-
Notifications
You must be signed in to change notification settings - Fork 0
Altapi #24
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
Altapi #24
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| # 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 | ||
| ${RUST_CRATE_DIR}/src/string.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) | ||
|
|
||
| if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/idl/CMakeLists.txt) | ||
| add_subdirectory(idl) | ||
| elseif (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/../idl/CMakeLists.txt) | ||
| add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../idl ${CMAKE_CURRENT_BINARY_DIR}/legacy_idl) | ||
| endif() | ||
|
|
||
| if(TARGET arduinocore_idl_generate_interfaces) | ||
| add_dependencies(app arduinocore_idl_generate_interfaces) | ||
| endif() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| #pragma once | ||
|
|
||
| #ifdef __cplusplus | ||
| #include <cstdint> | ||
| #include <cstddef> | ||
| #include <stdlib.h> | ||
| #else | ||
| #include <stdint.h> | ||
| #include <stddef.h> | ||
| #include <stdlib.h> | ||
| #endif | ||
| #include <zephyr/drivers/gpio.h> | ||
|
|
||
| #include "api/HardwareSerial.h" | ||
| #include "common_types.h" | ||
|
|
||
| #define lowByte(w) ((uint8_t) ((w) & 0xff)) | ||
| #define highByte(w) ((uint8_t) ((w) >> 8)) | ||
|
|
||
| #define bit(b) BIT(b) | ||
| #define bitRead(value, bit) FIELD_GET(BIT(bit), value) | ||
| #define bitSet(value, bit) ((value) |= BIT(bit)) | ||
| #define bitClear(value, bit) ((value) &= ~BIT(bit)) | ||
| #define bitToggle(value, bit) ((value) ^= BIT(bit)) | ||
| #define bitWrite(value, bit, bitvalue) WRITE_BIT(value, bit, bitvalue) | ||
|
|
||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| typedef gpio_port_pins_t pin_size_t; | ||
|
|
||
| typedef void (*voidFuncPtr)(void); | ||
| typedef void (*voidFuncPtrParam)(void*); | ||
|
|
||
| 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 |
| 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 */ |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,13 @@ | ||||||
| #pragma once | ||||||
|
|
||||||
| #include "Stream.h" | ||||||
| #include <client_interface.hpp> | ||||||
|
|
||||||
| namespace arduino { | ||||||
|
|
||||||
| class Client : virtual public Stream, virtual public ClientInterface { | ||||||
| protected: | ||||||
| uint8_t* rawIPAddress(IPAddress& addr); //TODO | ||||||
| }; | ||||||
|
||||||
|
|
||||||
| }; | ||||||
|
||||||
| }; | |
| }; // namespace arduino |
Copilot
AI
Feb 22, 2026
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.
Missing newline at end of file. This violates POSIX standards and can cause issues with some tools.
| 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 */ |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,17 @@ | ||||||
| /* | ||||||
| * Copyright (c) 2026 TOKITA Hiroshi | ||||||
| * | ||||||
| * SPDX-License-Identifier: Apache-2.0 | ||||||
| */ | ||||||
|
|
||||||
| #pragma once | ||||||
|
|
||||||
| #include "Stream.h" | ||||||
| #include <hardware_i2c_interface.hpp> | ||||||
|
|
||||||
| namespace arduino { | ||||||
|
|
||||||
| class HardwareI2C : virtual public Stream, virtual public HardwareI2CInterface { | ||||||
| }; | ||||||
|
|
||||||
| }; | ||||||
|
||||||
| }; | |
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,18 @@ | ||||||||||||||
| /* | ||||||||||||||
| * Copyright (c) 2026 TOKITA Hiroshi | ||||||||||||||
| * | ||||||||||||||
| * SPDX-License-Identifier: Apache-2.0 | ||||||||||||||
| */ | ||||||||||||||
|
|
||||||||||||||
| #pragma once | ||||||||||||||
|
|
||||||||||||||
| #include "Stream.h" | ||||||||||||||
| #include <hardware_spi_interface.hpp> | ||||||||||||||
|
|
||||||||||||||
| namespace arduino { | ||||||||||||||
|
|
||||||||||||||
| class HardwareSPI : virtual public HardwareSPIInterface { | ||||||||||||||
| }; | ||||||||||||||
|
|
||||||||||||||
| typedef HardwareSPI SPIClass; | ||||||||||||||
| }; | ||||||||||||||
|
||||||||||||||
| }; | |
| } // namespace arduino |
Copilot
AI
Feb 22, 2026
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.
Missing newline at end of file. This violates POSIX standards and can cause issues with some tools.
| }; | |
| }; |
Copilot
AI
Feb 22, 2026
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.
Missing semicolon after the closing brace of the class declaration. This will cause a compilation error.
| }; | |
| } |
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.
Missing copyright and SPDX license header. All other new files in this PR have proper copyright headers with "Copyright (c) 2026 TOKITA Hiroshi" and "SPDX-License-Identifier: Apache-2.0".