Skip to content

Commit 1e65d4c

Browse files
authored
Integrated latest corrections into FTDI (#14)
* Support for legacy Arduino libraries w/o src * bmp280 examples * rename to Arduino.cmake * Arduino.cmake * remove doxygen html * RPI: compile errors * Serial2 * HardwareSetup: issue warning * RPI linker errors * serial2 logging * RPI: cleanup cmake * rename Arduino.cmake
1 parent 66ffdc4 commit 1e65d4c

File tree

14 files changed

+139
-16
lines changed

14 files changed

+139
-16
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Doxygen GitHub Pages Deploy Action
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
deploy:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: DenverCoder1/[email protected]
13+
with:
14+
github_token: ${{ secrets.GITHUB_TOKEN }}
15+
folder: docs/html
16+
branch: doxygen

ArduinoLibrary.cmake renamed to Arduino.cmake

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# ArduinoLibrary.cmake
1+
# Arduino.cmake
22
# Defines a function to easily add Arduino-style libraries to your CMake project.
33
#
44
# Example usage for arduino-SAM library from GitHub
5-
# Place this in your CMakeLists.txt after including ArduinoLibrary.cmake
5+
# Place this in your CMakeLists.txt after including Arduino.cmake
66
#
7-
# include(${CMAKE_SOURCE_DIR}/ArduinoLibrary.cmake)
7+
# include(${CMAKE_SOURCE_DIR}/Arduino.cmake)
88
# arduino_library(arduino-SAM "https://github.com/pschatzmann/arduino-SAM")
99
# target_link_libraries(your_target PRIVATE arduino-SAM)
1010

@@ -31,31 +31,43 @@ function(arduino_library LIB_NAME LIB_PATH)
3131
endif()
3232
set(LIB_PATH "${CLONE_DIR}")
3333
endif()
34-
set(INC_DIR "${LIB_PATH}/src")
35-
file(GLOB SRC_FILES
36-
"${LIB_PATH}/src/*.c"
37-
"${LIB_PATH}/src/*.cpp"
38-
)
34+
if(EXISTS "${LIB_PATH}/src")
35+
set(INC_DIR "${LIB_PATH}/src")
36+
file(GLOB_RECURSE SRC_FILES
37+
"${LIB_PATH}/src/*.c"
38+
"${LIB_PATH}/src/*.cpp"
39+
)
40+
else()
41+
# Legacy libraries without src folder
42+
set(INC_DIR "${LIB_PATH}")
43+
file(GLOB_RECURSE SRC_FILES
44+
"${LIB_PATH}/*.c"
45+
"${LIB_PATH}/*.cpp"
46+
)
47+
endif()
3948
# Only create library if there are source files
4049
if(SRC_FILES)
4150
add_library(${LIB_NAME} STATIC ${SRC_FILES})
4251
target_compile_options(${LIB_NAME} PRIVATE -DPROGMEM=)
4352
# Ensure C files are compiled as C, not C++
4453
set_target_properties(${LIB_NAME} PROPERTIES LINKER_LANGUAGE C)
54+
target_include_directories(${LIB_NAME} PUBLIC ${INC_DIR})
4555
else()
4656
# Create a header-only interface library if no source files
4757
add_library(${LIB_NAME} INTERFACE)
58+
target_include_directories(${LIB_NAME} INTERFACE ${INC_DIR})
4859
endif()
49-
target_include_directories(${LIB_NAME} PUBLIC ${INC_DIR})
5060
# Link arduino_emulator to propagate its include directories
5161
if(TARGET arduino_emulator)
5262
if(SRC_FILES)
5363
target_link_libraries(${LIB_NAME} PUBLIC arduino_emulator)
5464
else()
5565
# For interface libraries, use INTERFACE linkage
5666
target_link_libraries(${LIB_NAME} INTERFACE arduino_emulator)
57-
endif()
67+
endif()
68+
5869
endif()
70+
5971
endfunction()
6072

6173
# arduino_sketch(<name> <ino_file> [LIBRARIES <lib1> <lib2> ...] [DEFINITIONS <def1> <def2> ...])
@@ -107,11 +119,7 @@ function(arduino_sketch name ino_file)
107119
target_compile_definitions(${name} PUBLIC ${ARG_DEFINITIONS})
108120
endif()
109121

110-
# Add platform-specific libraries
111-
if (USE_RPI)
112-
target_link_libraries(${name} gpiod)
113-
endif(USE_RPI)
114-
122+
# Handle FTDI support if specified
115123
if (USE_FTDI)
116124
# Find and link libftdi1
117125
find_package(PkgConfig REQUIRED)

ArduinoCore-Linux/cores/arduino/HardwareSetupRemote.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class HardwareSetupRemote : public I2CSource,
7676

7777
// setup global objects
7878
if (asDefault) {
79+
Logger.warning("GPIO, I2C, SPI set up for Remote");
7980
SPI.setSPI(&spi);
8081
Wire.setI2C(&i2c);
8182
GPIO.setGPIO(&gpio);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
WProgram.h - Legacy Main include file for the Arduino SDK
3+
Copyright (c) 2025 Phil Schatzmann. All right reserved.
4+
5+
This library is free software; you can redistribute it and/or
6+
modify it under the terms of the GNU Lesser General Public
7+
License as published by the Free Software Foundation; either
8+
version 2.1 of the License, or (at your option) any later version.
9+
10+
This library is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
Lesser General Public License for more details.
14+
15+
You should have received a copy of the GNU Lesser General Public
16+
License along with this library; if not, write to the Free Software
17+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
#pragma once
20+
// This is for compatibility with older Arduino libraries that still include WProgram.h
21+
// It is recommended to use Arduino.h instead of WProgram.h in new code
22+
#include "Arduino.h"

ArduinoCore-Linux/cores/rasperry_pi/HardwareGPIO_RPI.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020
#ifdef USE_RPI
2121
#include "HardwareGPIO.h"
22+
#include <map>
2223

2324

2425
namespace arduino {

ArduinoCore-Linux/cores/rasperry_pi/HardwareSetupRPI.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class HardwareSetupRPI : public I2CSource, public SPISource, public GPIOSource {
5151

5252
// define the global hardware interfaces
5353
if (asDefault) {
54+
Logger.warning("GPIO, I2C, SPI set up for Raspberry Pi");
5455
GPIO.setGPIO(&gpio);
5556
SPI.setSPI(&spi);
5657
Wire.setI2C(&i2c);

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/ArduinoCore-Linux/cores/arduino/"
6666
target_compile_features(arduino_emulator PUBLIC cxx_std_17)
6767

6868
# Include Arduino library functions
69-
include(${CMAKE_CURRENT_SOURCE_DIR}/ArduinoLibrary.cmake)
69+
include(${CMAKE_CURRENT_SOURCE_DIR}/Arduino.cmake)
7070

7171
if (USE_RPI)
7272
target_compile_options(arduino_emulator PUBLIC -DUSE_RPI)
73+
target_link_libraries(arduino_emulator gpiod)
7374
endif(USE_RPI)
7475

7576
if (USE_REMOTE)

examples/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ add_subdirectory("serial2")
77
add_subdirectory("using-arduino-library")
88
add_subdirectory("pwm")
99

10+
# BME280 Sensor Examples
11+
arduino_library(SparkFunBME280 "https://github.com/sparkfun/SparkFun_BME280_Arduino_Library" )
12+
add_subdirectory("bme280-i2c")
13+
add_subdirectory("bme280-spi")
14+
1015
if(USE_HTTPS)
1116
add_subdirectory("wifi-secure")
1217
endif(USE_HTTPS)

examples/bme280-i2c/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
arduino_sketch(bme280-i2c bme280-i2c.ino LIBRARIES SparkFunBME280)

examples/bme280-i2c/bme280-i2c.ino

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Example sketch for the BME280 combined humidity and pressure sensor
2+
// Using I2C communication with the SparkFun BME280 Arduino Library
3+
4+
#include <Arduino.h>
5+
#include <Wire.h>
6+
#include "SparkFunBME280.h"
7+
8+
BME280 mySensor;
9+
10+
void setup() {
11+
Serial.begin(115200);
12+
Serial.println("Reading basic values from BME280");
13+
// Begin communication over I2C
14+
Wire.begin();
15+
if (!mySensor.beginI2C(Wire)) {
16+
Serial.println("The sensor did not respond. Please check wiring.");
17+
while (1); // Freeze
18+
}
19+
}
20+
21+
void loop() {
22+
Serial.print("Humidity: ");
23+
Serial.print(mySensor.readFloatHumidity(), 0);
24+
Serial.print(" Pressure: ");
25+
Serial.print(mySensor.readFloatPressure(), 0);
26+
Serial.print(" Alt: ");
27+
Serial.print(mySensor.readFloatAltitudeMeters(), 1);
28+
Serial.print(" Temp: ");
29+
Serial.println(mySensor.readTempC(), 2);
30+
31+
delay(1000);
32+
}

0 commit comments

Comments
 (0)