From 2e1d22fca34a98dea2d4ead93cf674a4da79e42d Mon Sep 17 00:00:00 2001 From: Gert-Jan Rozing Date: Mon, 26 Aug 2019 11:31:15 +0200 Subject: [PATCH 01/13] optimized cmake configuration --- CMakeLists.txt | 160 ++++++++++++++++++++++----------------- cmake/FindRT.cmake | 39 ++++++++++ cmake/pigpioConfig.cmake | 1 + 3 files changed, 129 insertions(+), 71 deletions(-) create mode 100644 cmake/FindRT.cmake create mode 100644 cmake/pigpioConfig.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index b36b0d6..012a3a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,18 @@ cmake_minimum_required(VERSION 3.0) -project(pigpio) +project(pigpio LANGUAGES C VERSION 0.71) -set(CMAKE_C_FLAGS "-O3 -Wall -pthread") -set(PIGPIO_FLAGS "-L. -lrt") -#set(DESTDIR ${CMAKE_CURRENT_SOURCE_DIR}/build/dest) +list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) + +find_package(Threads REQUIRED) +find_package(RT REQUIRED) if(NOT DEFINED BUILD_SHARED_LIBS) set(BUILD_SHARED_LIBS "ON") endif(NOT DEFINED BUILD_SHARED_LIBS) +add_compile_options(-Wall) + # libpigpio.(so|a) add_library(pigpio pigpio.c command.c custom.cext) @@ -22,59 +25,87 @@ add_library(pigpiod_if2 pigpiod_if2.c command.c) # x_pigpio add_executable(x_pigpio x_pigpio.c) -add_dependencies(x_pigpio pigpio) -target_link_libraries(x_pigpio - ${PIGPIO_FLAGS} - -lpigpio -) +target_link_libraries(x_pigpio pigpio RT::RT Threads::Threads) # x_pigpiod_if add_executable(x_pigpiod_if x_pigpiod_if.c) -add_dependencies(x_pigpiod_if pigpiod_if) -target_link_libraries(x_pigpiod_if - ${PIGPIO_FLAGS} - -lpigpiod_if -) +target_link_libraries(x_pigpiod_if pigpio_if RT::RT Threads::Threads) # x_pigpiod_if2 add_executable(x_pigpiod_if2 x_pigpiod_if2.c) -add_dependencies(x_pigpiod_if2 pigpiod_if2) -target_link_libraries(x_pigpiod_if2 - ${PIGPIO_FLAGS} - -lpigpiod_if2 -) +target_link_libraries(x_pigpiod_if2 pigpio_if2 RT::RT Threads::Threads) # pigpiod add_executable(pigpiod pigpiod.c) -add_dependencies(pigpiod pigpio) -target_link_libraries(pigpiod - ${PIGPIO_FLAGS} - -lpigpio -) +target_link_libraries(pigpiod pigpio RT::RT Threads::Threads) # pigs add_executable(pigs pigs.c command.c) +target_link_libraries(pigs Threads::Threads) # pig2vcd add_executable(pig2vcd pig2vcd.c command.c) +target_link_libraries(pig2vcd Threads::Threads) # install -install(DIRECTORY - DESTINATION ${DESTDIR}/opt/pigpio/cgi - PATTERN "" - PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ - GROUP_READ GROUP_EXECUTE - WORLD_READ WORLD_EXECUTE -) + +include (GenerateExportHeader) +include (CMakePackageConfigHelpers) + +generate_export_header(${PROJECT_NAME}) + +#install(DIRECTORY +# DESTINATION ${DESTDIR}/opt/pigpio/cgi +# PATTERN "" +# PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ +# GROUP_READ GROUP_EXECUTE +# WORLD_READ WORLD_EXECUTE +#) install(TARGETS pigpio pigpiod_if pigpiod_if2 pig2vcd pigpiod pigs - LIBRARY DESTINATION ${DESTDIR}/usr/local/lib - RUNTIME DESTINATION ${DESTDIR}/usr/local/bin - ARCHIVE DESTINATION ${DESTDIR}/usr/local/lib + EXPORT ${PROJECT_NAME}Targets + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + RUNTIME DESTINATION bin + INCLUDES DESTINATION include +) + +write_basic_package_version_file( + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + VERSION ${${PROJECT_NAME}_VERSION} + COMPATIBILITY AnyNewerVersion +) + +export(EXPORT ${PROJECT_NAME}Targets + FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake" + NAMESPACE pigpio:: +) + +#configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake +# "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" +# COPYONLY +#) + +set(ConfigPackageLocation lib/cmake/${PROJECT_NAME}) +install(EXPORT ${PROJECT_NAME}Targets + FILE + ${PROJECT_NAME}Targets.cmake + NAMESPACE + pigpio:: + DESTINATION + ${ConfigPackageLocation} +) + +install( + FILES + ${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake + "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake" + DESTINATION + ${ConfigPackageLocation} ) install(FILES pigpio.h pigpiod_if.h pigpiod_if2.h - DESTINATION ${DESTDIR}/usr/local/include + DESTINATION include PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ @@ -82,7 +113,7 @@ install(FILES pigpio.h pigpiod_if.h pigpiod_if2.h file(GLOB man_1_SRC "*.1") install(FILES ${man_1_SRC} - DESTINATION ${DESTDIR}/usr/local/man/man1 + DESTINATION man/man1 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ @@ -90,48 +121,35 @@ install(FILES ${man_1_SRC} file(GLOB man_3_SRC "*.3") install(FILES ${man_3_SRC} - DESTINATION ${DESTDIR}/usr/local/man/man3 + DESTINATION man/man3 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ ) -file(GLOB setup_SRC "setup.py") -find_program(PYTHON2_FOUND python2) -if(PYTHON2_FOUND) - install(CODE "execute_process(COMMAND cd ${CMAKE_SOURCE_DIR} && python2 ${setup_SRC} install)") -endif() -find_program(PYTHON3_FOUND python3) -if(PYTHON3_FOUND) - install(CODE "execute_process(COMMAND cd ${CMAKE_SOURCE_DIR} && python3 ${setup_SRC} install)") -endif() +find_package(Python COMPONENTS Interpreter QUIET) -install(CODE "execute_process(COMMAND ldconfig)") +#file(GLOB setup_SRC "setup.py") +#if(Python_FOUND) +# install(CODE "execute_process(COMMAND cd ${CMAKE_SOURCE_DIR} && ${Python_EXECUTABLE} ${setup_SRC} install)") +#endif() +# +#install(CODE "execute_process(COMMAND ldconfig)") +# One does not need a uninstall command if every file was installed via cmake +# install commands. That python script however seems to need some more +# script code. # uninstall -if(PYTHON2_FOUND) - set(PY2_CMD python2 ${setup_SRC} install --record /tmp/pigpio > /dev/null) - set(PY2_CMD ${PY2_CMD} && xargs rm -f < /tmp/pigpio > /dev/null) -endif() +#if(Python_FOUND) +# set(PY_CMD ${Python_EXECUTABLE} ${setup_SRC} install --record /tmp/pigpio > /dev/null) +# set(PY_CMD ${PY2_CMD} && xargs rm -f < /tmp/pigpio > /dev/null) +#endif() -if(PYTHON3_FOUND) - set(PY3_CMD python3 ${setup_SRC} install --record /tmp/pigpio > /dev/null) - set(PY3_CMD ${PY3_CMD} && xargs rm -f < /tmp/pigpio > /dev/null) -endif() +#add_custom_target(uninstall +# COMMAND cd ${CMAKE_SOURCE_DIR} && ${PY_CMD} +#) -add_custom_target(uninstall - COMMAND rm -f ${DESTDIR}/usr/local/include/pigpio.h - COMMAND rm -f ${DESTDIR}/usr/local/include/pigpiod_if.h - COMMAND rm -f ${DESTDIR}/usr/local/include/pigpiod_if2.h - COMMAND rm -f ${DESTDIR}/usr/local/lib/libpigpio.so - COMMAND rm -f ${DESTDIR}/usr/local/lib/libpigpiod_if.so - COMMAND rm -f ${DESTDIR}/usr/local/lib/libpigpiod_if2.so - COMMAND rm -f ${DESTDIR}/usr/local/bin/pig2vcd - COMMAND rm -f ${DESTDIR}/usr/local/bin/pigpiod - COMMAND rm -f ${DESTDIR}/usr/local/bin/pigs - COMMAND cd ${CMAKE_SOURCE_DIR} && ${PY2_CMD} - COMMAND cd ${CMAKE_SOURCE_DIR} && ${PY3_CMD} - COMMAND rm -f ${DESTDIR}/usr/local/man/man1/pig*.1 - COMMAND rm -f ${DESTDIR}/usr/local/man/man3/pig*.3 - COMMAND ldconfig -) + +# package project + +include (CPack) \ No newline at end of file diff --git a/cmake/FindRT.cmake b/cmake/FindRT.cmake new file mode 100644 index 0000000..db7c4de --- /dev/null +++ b/cmake/FindRT.cmake @@ -0,0 +1,39 @@ +# FindRT.cmake - Try to find the RT library +# Once done this will define +# +# RT_FOUND - System has rt +# RT_INCLUDE_DIR - The rt include directory +# RT_LIBRARIES - The libraries needed to use rt +# RT_DEFINITIONS - Compiler switches required for using rt +# +# Also creates an import target called RT::RT + +find_path (RT_INCLUDE_DIR NAMES time.h + PATHS + /usr + /usr/local + /opt + PATH_SUFFIXES +) + +find_library(RT_LIBRARIES NAMES rt + PATHS + /usr + /usr/local + /opt +) + +include(FindPackageHandleStandardArgs) + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(rt DEFAULT_MSG RT_LIBRARIES RT_INCLUDE_DIR) + +mark_as_advanced(RT_INCLUDE_DIR RT_LIBRARIES) + +if (NOT TARGET RT::RT) + add_library(RT::RT INTERFACE IMPORTED) + + set_target_properties(RT::RT PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES ${RT_INCLUDE_DIR} + INTERFACE_LINK_LIBRARIES ${RT_LIBRARIES} + ) +endif() \ No newline at end of file diff --git a/cmake/pigpioConfig.cmake b/cmake/pigpioConfig.cmake new file mode 100644 index 0000000..7912526 --- /dev/null +++ b/cmake/pigpioConfig.cmake @@ -0,0 +1 @@ +include (${CMAKE_CURRENT_LIST_DIR}/pigpioTargets.cmake) \ No newline at end of file From 062e981608df09299c9a78fce656c498a310abdf Mon Sep 17 00:00:00 2001 From: Gert-Jan Rozing Date: Mon, 26 Aug 2019 11:36:24 +0200 Subject: [PATCH 02/13] fixed usage of wrongly spelled target --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 012a3a2..dca39fb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,11 +29,11 @@ target_link_libraries(x_pigpio pigpio RT::RT Threads::Threads) # x_pigpiod_if add_executable(x_pigpiod_if x_pigpiod_if.c) -target_link_libraries(x_pigpiod_if pigpio_if RT::RT Threads::Threads) +target_link_libraries(x_pigpiod_if pigpiod_if RT::RT Threads::Threads) # x_pigpiod_if2 add_executable(x_pigpiod_if2 x_pigpiod_if2.c) -target_link_libraries(x_pigpiod_if2 pigpio_if2 RT::RT Threads::Threads) +target_link_libraries(x_pigpiod_if2 pigpiod_if2 RT::RT Threads::Threads) # pigpiod add_executable(pigpiod pigpiod.c) From b59425c9b89aad8d6b651afa6dde0585f6248305 Mon Sep 17 00:00:00 2001 From: Gert-Jan Rozing Date: Mon, 26 Aug 2019 11:43:07 +0200 Subject: [PATCH 03/13] Reenabled python isntall --- CMakeLists.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dca39fb..ea1bd55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,10 +129,10 @@ install(FILES ${man_3_SRC} find_package(Python COMPONENTS Interpreter QUIET) -#file(GLOB setup_SRC "setup.py") -#if(Python_FOUND) -# install(CODE "execute_process(COMMAND cd ${CMAKE_SOURCE_DIR} && ${Python_EXECUTABLE} ${setup_SRC} install)") -#endif() +file(GLOB setup_SRC "setup.py") +if(Python_FOUND) + install(CODE "execute_process(COMMAND cd ${CMAKE_SOURCE_DIR} && ${Python_EXECUTABLE} ${setup_SRC} install)") +endif() # #install(CODE "execute_process(COMMAND ldconfig)") From 61cf7041870d41eb61ee1daa0be5ecf83ef16117 Mon Sep 17 00:00:00 2001 From: Gert-Jan Rozing Date: Mon, 26 Aug 2019 11:45:08 +0200 Subject: [PATCH 04/13] Try to make things work --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ea1bd55..af8a3c1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -129,9 +129,9 @@ install(FILES ${man_3_SRC} find_package(Python COMPONENTS Interpreter QUIET) -file(GLOB setup_SRC "setup.py") if(Python_FOUND) - install(CODE "execute_process(COMMAND cd ${CMAKE_SOURCE_DIR} && ${Python_EXECUTABLE} ${setup_SRC} install)") + message(STATUS "Installing python modules.") + install(CODE "execute_process(COMMAND ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/setup.py install)") endif() # #install(CODE "execute_process(COMMAND ldconfig)") From b5f0e61ccf6d6bb115670aac016f634da7f69514 Mon Sep 17 00:00:00 2001 From: Gert-Jan Rozing Date: Mon, 26 Aug 2019 11:52:04 +0200 Subject: [PATCH 05/13] Python setup needs to be called from root --- CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index af8a3c1..393e38f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,8 +130,7 @@ install(FILES ${man_3_SRC} find_package(Python COMPONENTS Interpreter QUIET) if(Python_FOUND) - message(STATUS "Installing python modules.") - install(CODE "execute_process(COMMAND ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/setup.py install)") + install(CODE "execute_process(COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/setup.py install)") endif() # #install(CODE "execute_process(COMMAND ldconfig)") From 492d83d0d34a20f6e697cdaba1a12429fb12dcde Mon Sep 17 00:00:00 2001 From: Gert-Jan Rozing Date: Mon, 26 Aug 2019 12:00:09 +0200 Subject: [PATCH 06/13] optimized python setup --- CMakeLists.txt | 6 +++++- cmake/setup.py.in | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 cmake/setup.py.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 393e38f..face031 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,7 +130,11 @@ install(FILES ${man_3_SRC} find_package(Python COMPONENTS Interpreter QUIET) if(Python_FOUND) - install(CODE "execute_process(COMMAND cd ${CMAKE_CURRENT_SOURCE_DIR} && ${Python_EXECUTABLE} ${CMAKE_SOURCE_DIR}/setup.py install)") + configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/setup.py.in + ${CMAKE_CURRENT_BINARY_DIR}/setup.py + ) + + install(CODE "execute_process(${Python_EXECUTABLE} setup.py install)") endif() # #install(CODE "execute_process(COMMAND ldconfig)") diff --git a/cmake/setup.py.in b/cmake/setup.py.in new file mode 100644 index 0000000..a5913a2 --- /dev/null +++ b/cmake/setup.py.in @@ -0,0 +1,24 @@ +#!/usr/bin/env python + +from distutils.core import setup + +setup(name='pigpio', + version='1.44', + author='joan', + author_email='joan@abyz.me.uk', + maintainer='joan', + maintainer_email='joan@abyz.me.uk', + url='http://abyz.me.uk/rpi/pigpio/python.html', + description='Raspberry Pi GPIO module', + long_description='Raspberry Pi Python module to access the pigpio daemon', + download_url='http://abyz.me.uk/rpi/pigpio/pigpio.zip', + license='unlicense.org', + py_modules=['pigpio'], + keywords=['raspberrypi', 'gpio',], + classifiers=[ + "Programming Language :: Python :: 2", + "Programming Language :: Python :: 3", + ], + package_dir={ '': '${CMAKE_CURRENT_SOURCE_DIR}'} + ) + From 964bdb1e7924b672963322de5ad03cfd33c6a1fd Mon Sep 17 00:00:00 2001 From: Gert-Jan Rozing Date: Mon, 26 Aug 2019 12:02:02 +0200 Subject: [PATCH 07/13] Fixed path issue --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index face031..5ad5d37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,7 +134,7 @@ if(Python_FOUND) ${CMAKE_CURRENT_BINARY_DIR}/setup.py ) - install(CODE "execute_process(${Python_EXECUTABLE} setup.py install)") + install(CODE "execute_process(${Python_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py install)") endif() # #install(CODE "execute_process(COMMAND ldconfig)") From a8498a02955823b62cd6bdb5aa2410d920fe8dc1 Mon Sep 17 00:00:00 2001 From: Gert-Jan Rozing Date: Mon, 26 Aug 2019 12:03:31 +0200 Subject: [PATCH 08/13] Forgot the command option --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ad5d37..25d46be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -134,7 +134,7 @@ if(Python_FOUND) ${CMAKE_CURRENT_BINARY_DIR}/setup.py ) - install(CODE "execute_process(${Python_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py install)") + install(CODE "execute_process(COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py install)") endif() # #install(CODE "execute_process(COMMAND ldconfig)") From ee7a6be22706238aa4efe214206128d3ce0bebc4 Mon Sep 17 00:00:00 2001 From: Gert-Jan Rozing Date: Mon, 26 Aug 2019 12:08:08 +0200 Subject: [PATCH 09/13] Moved option like option to actual option --- CMakeLists.txt | 37 +++---------------------------------- 1 file changed, 3 insertions(+), 34 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 25d46be..383c445 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,9 +7,7 @@ list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/cmake) find_package(Threads REQUIRED) find_package(RT REQUIRED) -if(NOT DEFINED BUILD_SHARED_LIBS) -set(BUILD_SHARED_LIBS "ON") -endif(NOT DEFINED BUILD_SHARED_LIBS) +option(BUILD_SHARED_LIBS "Create shared libraries" ON) add_compile_options(-Wall) @@ -22,7 +20,6 @@ add_library(pigpiod_if pigpiod_if.c command.c) # libpigpiod_if2.(so|a) add_library(pigpiod_if2 pigpiod_if2.c command.c) - # x_pigpio add_executable(x_pigpio x_pigpio.c) target_link_libraries(x_pigpio pigpio RT::RT Threads::Threads) @@ -47,21 +44,13 @@ target_link_libraries(pigs Threads::Threads) add_executable(pig2vcd pig2vcd.c command.c) target_link_libraries(pig2vcd Threads::Threads) -# install +# Configure and install project include (GenerateExportHeader) include (CMakePackageConfigHelpers) generate_export_header(${PROJECT_NAME}) -#install(DIRECTORY -# DESTINATION ${DESTDIR}/opt/pigpio/cgi -# PATTERN "" -# PERMISSIONS OWNER_EXECUTE OWNER_WRITE OWNER_READ -# GROUP_READ GROUP_EXECUTE -# WORLD_READ WORLD_EXECUTE -#) - install(TARGETS pigpio pigpiod_if pigpiod_if2 pig2vcd pigpiod pigs EXPORT ${PROJECT_NAME}Targets LIBRARY DESTINATION lib @@ -81,11 +70,6 @@ export(EXPORT ${PROJECT_NAME}Targets NAMESPACE pigpio:: ) -#configure_file(${CMAKE_CURRENT_LIST_DIR}/cmake/${PROJECT_NAME}Config.cmake -# "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake" -# COPYONLY -#) - set(ConfigPackageLocation lib/cmake/${PROJECT_NAME}) install(EXPORT ${PROJECT_NAME}Targets FILE @@ -127,6 +111,7 @@ install(FILES ${man_3_SRC} WORLD_READ ) +# Install python modules. find_package(Python COMPONENTS Interpreter QUIET) if(Python_FOUND) @@ -136,22 +121,6 @@ if(Python_FOUND) install(CODE "execute_process(COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/setup.py install)") endif() -# -#install(CODE "execute_process(COMMAND ldconfig)") - -# One does not need a uninstall command if every file was installed via cmake -# install commands. That python script however seems to need some more -# script code. -# uninstall -#if(Python_FOUND) -# set(PY_CMD ${Python_EXECUTABLE} ${setup_SRC} install --record /tmp/pigpio > /dev/null) -# set(PY_CMD ${PY2_CMD} && xargs rm -f < /tmp/pigpio > /dev/null) -#endif() - -#add_custom_target(uninstall -# COMMAND cd ${CMAKE_SOURCE_DIR} && ${PY_CMD} -#) - # package project From 671adab8ad99629ac9b80dda4c9fabf47f0ecaf5 Mon Sep 17 00:00:00 2001 From: Marco Jassmann Date: Wed, 26 Feb 2020 12:29:55 +0100 Subject: [PATCH 10/13] Corrected constant name in spiClose from PI_I2C_CLOSED to PI_SPI_CLOSED --- pigpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigpio.c b/pigpio.c index 409b981..033213c 100644 --- a/pigpio.c +++ b/pigpio.c @@ -4768,7 +4768,7 @@ int spiClose(unsigned handle) if (spiInfo[handle].state != PI_SPI_OPENED) SOFT_ERROR(PI_BAD_HANDLE, "bad handle (%d)", handle); - spiInfo[handle].state = PI_I2C_CLOSED; + spiInfo[handle].state = PI_SPI_CLOSED; if (!spiAnyOpen(spiInfo[handle].flags)) spiTerm(spiInfo[handle].flags); /* terminate on last close */ From 4753b0d37ce16e48685aceafb8dd5df87d5b5acf Mon Sep 17 00:00:00 2001 From: joan2937 Date: Sun, 1 Mar 2020 13:35:16 +0000 Subject: [PATCH 11/13] Code for BSC I2C/SPI slave on the BCM2711 (PI4B) Added documentation for callback usage --- pigpio.3 | 46 ++++++++++++++++++----- pigpio.c | 57 +++++++++++++++++++++------- pigpio.h | 32 ++++++++++++---- pigpio.py | 60 +++++++++++++++++++++++------- pigpiod_if2.3 | 100 ++++++++++++++++++++++++++++++++++++++++++++------ pigpiod_if2.c | 2 +- pigpiod_if2.h | 55 ++++++++++++++++++++++----- pigs.1 | 34 ++++++++++++----- setup.py | 2 +- 9 files changed, 311 insertions(+), 77 deletions(-) diff --git a/pigpio.3 b/pigpio.3 index e218ed1..cd77e18 100644 --- a/pigpio.3 +++ b/pigpio.3 @@ -1682,6 +1682,15 @@ will be a latency. .br +.br +If you want to track the level of more than one GPIO do so by +maintaining the state in the callback. Do not use \fBgpioRead\fP. +Remember the event that triggered the callback may have +happened several milliseconds before and the GPIO may have +changed level many times since then. + +.br + .br The tick value is the time stamp of the sample in microseconds, see \fBgpioTick\fP for more details. @@ -4181,12 +4190,6 @@ queue and the master removes it. .br -.br -This function is not available on the BCM2711 (e.g. as -used in the Pi4B). - -.br - .br I can't get SPI to work properly. I tried with a control word of 0x303 and swapped MISO and MOSI. @@ -4249,14 +4252,37 @@ that mode until a different control word is sent. .br .br -The BSC peripheral uses GPIO 18 (SDA) and 19 (SCL) in I2C mode -and GPIO 18 (MOSI), 19 (SCLK), 20 (MISO), and 21 (CE) in SPI mode. You -need to swap MISO/MOSI between master and slave. +GPIO used for models other than those based on the BCM2711. .br .br -When a zero control word is received GPIO 18-21 will be reset + SDA SCL MOSI SCLK MISO CE +.br +I2C 18 19 - - - - +.br +SPI - - 18 19 20 21 +.br + +.br + +.br +GPIO used for models based on the BCM2711 (e.g. the Pi4B). + +.br + +.br + SDA SCL MOSI SCLK MISO CE +.br +I2C 10 11 - - - - +.br +SPI - - 10 11 9 8 +.br + +.br + +.br +When a zero control word is received the used GPIO will be reset to INPUT mode. .br diff --git a/pigpio.c b/pigpio.c index 409b981..fe5fc04 100644 --- a/pigpio.c +++ b/pigpio.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* pigpio version 74 */ +/* pigpio version 75 */ /* include ------------------------------------------------------- */ @@ -10730,35 +10730,69 @@ int bbI2CZip( void bscInit(int mode) { + int sda, scl, miso, ce; + bscsReg[BSC_CR]=0; /* clear device */ bscsReg[BSC_RSR]=0; /* clear underrun and overrun errors */ bscsReg[BSC_SLV]=0; /* clear I2C slave address */ bscsReg[BSC_IMSC]=0xf; /* mask off all interrupts */ bscsReg[BSC_ICR]=0x0f; /* clear all interrupts */ - gpioSetMode(BSC_SDA_MOSI, PI_ALT3); - gpioSetMode(BSC_SCL_SCLK, PI_ALT3); + if (pi_is_2711) + { + sda = BSC_SDA_MOSI_2711; + scl = BSC_SCL_SCLK_2711; + miso = BSC_MISO_2711; + ce = BSC_CE_N_2711; + } + else + { + sda = BSC_SDA_MOSI; + scl = BSC_SCL_SCLK; + miso = BSC_MISO; + ce = BSC_CE_N; + } + + gpioSetMode(sda, PI_ALT3); + gpioSetMode(scl, PI_ALT3); if (mode > 1) /* SPI uses all GPIO */ { - gpioSetMode(BSC_MISO, PI_ALT3); - gpioSetMode(BSC_CE_N, PI_ALT3); + gpioSetMode(miso, PI_ALT3); + gpioSetMode(ce, PI_ALT3); } } void bscTerm(int mode) { + int sda, scl, miso, ce; + bscsReg[BSC_CR] = 0; /* clear device */ bscsReg[BSC_RSR]=0; /* clear underrun and overrun errors */ bscsReg[BSC_SLV]=0; /* clear I2C slave address */ - gpioSetMode(BSC_SDA_MOSI, PI_INPUT); - gpioSetMode(BSC_SCL_SCLK, PI_INPUT); + if (pi_is_2711) + { + sda = BSC_SDA_MOSI_2711; + scl = BSC_SCL_SCLK_2711; + miso = BSC_MISO_2711; + ce = BSC_CE_N_2711; + } + else + { + sda = BSC_SDA_MOSI; + scl = BSC_SCL_SCLK; + miso = BSC_MISO; + ce = BSC_CE_N; + } + + gpioSetMode(sda, PI_INPUT); + gpioSetMode(scl, PI_INPUT); if (mode > 1) { - gpioSetMode(BSC_MISO, PI_INPUT); - gpioSetMode(BSC_CE_N, PI_INPUT); + gpioSetMode(miso, PI_INPUT); + gpioSetMode(ce, PI_INPUT); } } @@ -10778,9 +10812,6 @@ int bscXfer(bsc_xfer_t *xfer) CHECK_INITED; - if (pi_is_2711) - SOFT_ERROR(PI_NOT_ON_BCM2711, "SPI/BSC slave not available on BCM2711"); - eventAlert[PI_EVENT_BSC].ignore = 1; if (xfer->control) @@ -10794,7 +10825,7 @@ int bscXfer(bsc_xfer_t *xfer) if (mode > bscMode) { - bscInit(bscMode); + bscInit(mode); bscMode = mode; } } diff --git a/pigpio.h b/pigpio.h index 9f12497..e3eb97d 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 74 +#define PIGPIO_VERSION 7401 /*TEXT @@ -797,6 +797,11 @@ typedef void *(gpioThreadFunc_t) (void *); #define BSC_MISO 20 #define BSC_CE_N 21 +#define BSC_SDA_MOSI_2711 10 +#define BSC_SCL_SCLK_2711 11 +#define BSC_MISO_2711 9 +#define BSC_CE_N_2711 8 + /* Longest busy delay */ #define PI_MAX_BUSY_DELAY 100 @@ -1439,6 +1444,12 @@ once per level change since the last time the thread was activated. i.e. The active alert functions will get all level changes but there will be a latency. +If you want to track the level of more than one GPIO do so by +maintaining the state in the callback. Do not use [*gpioRead*]. +Remember the event that triggered the callback may have +happened several milliseconds before and the GPIO may have +changed level many times since then. + The tick value is the time stamp of the sample in microseconds, see [*gpioTick*] for more details. @@ -2913,9 +2924,6 @@ The output process is simple. You simply append data to the FIFO buffer on the chip. This works like a queue, you add data to the queue and the master removes it. -This function is not available on the BCM2711 (e.g. as -used in the Pi4B). - I can't get SPI to work properly. I tried with a control word of 0x303 and swapped MISO and MOSI. @@ -2947,11 +2955,19 @@ in rxBuf. Note that the control word sets the BSC mode. The BSC will stay in that mode until a different control word is sent. -The BSC peripheral uses GPIO 18 (SDA) and 19 (SCL) in I2C mode -and GPIO 18 (MOSI), 19 (SCLK), 20 (MISO), and 21 (CE) in SPI mode. You -need to swap MISO/MOSI between master and slave. +GPIO used for models other than those based on the BCM2711. -When a zero control word is received GPIO 18-21 will be reset + @ SDA @ SCL @ MOSI @ SCLK @ MISO @ CE +I2C @ 18 @ 19 @ - @ - @ - @ - +SPI @ - @ - @ 18 @ 19 @ 20 @ 21 + +GPIO used for models based on the BCM2711 (e.g. the Pi4B). + + @ SDA @ SCL @ MOSI @ SCLK @ MISO @ CE +I2C @ 10 @ 11 @ - @ - @ - @ - +SPI @ - @ - @ 10 @ 11 @ 9 @ 8 + +When a zero control word is received the used GPIO will be reset to INPUT mode. The returned function value is the status of the transfer (see below). diff --git a/pigpio.py b/pigpio.py index 0e2a0a1..cfaf845 100644 --- a/pigpio.py +++ b/pigpio.py @@ -330,7 +330,7 @@ import threading import os import atexit -VERSION = "1.45" +VERSION = "1.46" exceptions = True @@ -3557,13 +3557,9 @@ class pi(): buffer on the chip. This works like a queue, you add data to the queue and the master removes it. - This function is not available on the BCM2711 (e.g. as - used in the Pi4B). - I can't get SPI to work properly. I tried with a control word of 0x303 and swapped MISO and MOSI. - The function sets the BSC mode, writes any data in the transmit buffer to the BSC transmit FIFO, and copies any data in the BSC receive FIFO to the @@ -3580,12 +3576,19 @@ class pi(): Note that the control word sets the BSC mode. The BSC will stay in that mode until a different control word is sent. - The BSC peripheral uses GPIO 18 (SDA) and 19 (SCL) - in I2C mode and GPIO 18 (MOSI), 19 (SCLK), 20 (MISO), - and 21 (CE) in SPI mode. You need to swap MISO/MOSI - between master and slave. + GPIO used for models other than those based on the BCM2711. - When a zero control word is received GPIO 18-21 will be reset + @ SDA @ SCL @ MOSI @ SCLK @ MISO @ CE + I2C @ 18 @ 19 @ - @ - @ - @ - + SPI @ - @ - @ 18 @ 19 @ 20 @ 21 + + GPIO used for models based on the BCM2711 (e.g. the Pi4B). + + @ SDA @ SCL @ MOSI @ SCLK @ MISO @ CE + I2C @ 10 @ 11 @ - @ - @ - @ - + SPI @ - @ - @ 10 @ 11 @ 9 @ 8 + + When a zero control word is received the used GPIO will be reset to INPUT mode. bsc_control consists of the following bits: @@ -3684,10 +3687,10 @@ class pi(): (and will contain the error code). Note that an i2c_address of 0 may be used to close - the BSC device and reassign the used GPIO (18/19) - as inputs. + the BSC device and reassign the used GPIO as inputs. - This example assumes GPIO 2/3 are connected to GPIO 18/19. + This example assumes GPIO 2/3 are connected to GPIO 18/19 + (GPIO 10/11 on the BCM2711). ... #!/usr/bin/env python @@ -4939,6 +4942,37 @@ class pi(): A GPIO may have multiple callbacks (although I can't think of a reason to do so). + The GPIO are sampled at a rate set when the pigpio daemon + is started (default 5 us). + + The number of samples per second is given in the following table. + + . . + samples + per sec + + 1 1,000,000 + 2 500,000 + sample 4 250,000 + rate 5 200,000 + (us) 8 125,000 + 10 100,000 + . . + + GPIO level changes shorter than the sample rate may be missed. + + The daemon software which generates the callbacks is triggered + 1000 times per second. The callbacks will be called once per + level change since the last time they were called. + i.e. The callbacks will get all level changes but there will + be a latency. + + If you want to track the level of more than one GPIO do so by + maintaining the state in the callback. Do not use [*read*]. + Remember the event that triggered the callback may have + happened several milliseconds before and the GPIO may have + changed level many times since then. + ... def cbf(gpio, level, tick): print(gpio, level, tick) diff --git a/pigpiod_if2.3 b/pigpiod_if2.3 index 1c9291c..33c55e9 100644 --- a/pigpiod_if2.3 +++ b/pigpiod_if2.3 @@ -5920,6 +5920,66 @@ tick 32 bit The number of microseconds since boot .EE +.br + +.br +The GPIO are sampled at a rate set when the pigpio daemon +is started (default 5 us). + +.br + +.br +The number of samples per second is given in the following table. + +.br + +.br + +.EX + samples +.br + per sec +.br + +.br + 1 1,000,000 +.br + 2 500,000 +.br +sample 4 250,000 +.br +rate 5 200,000 +.br +(us) 8 125,000 +.br + 10 100,000 +.br + +.EE + +.br + +.br +GPIO level changes shorter than the sample rate may be missed. + +.br + +.br +The daemon software which generates the callbacks is triggered +1000 times per second. The callbacks will be called once per +level change since the last time they were called. +i.e. The callbacks will get all level changes but there will +be a latency. + +.br + +.br +If you want to track the level of more than one GPIO do so by +maintaining the state in the callback. Do not use \fBgpio_read\fP. +Remember the event that triggered the callback may have +happened several milliseconds before and the GPIO may have +changed level many times since then. + .IP "\fBint callback_ex(int pi, unsigned user_gpio, unsigned edge, CBFuncEx_t f, void *userdata)\fP" .IP "" 4 This function initialises a new callback. @@ -6072,12 +6132,6 @@ queue and the master removes it. .br -.br -This function is not available on the BCM2711 (e.g. as -used in the Pi4B). - -.br - .br I can't get SPI to work properly. I tried with a control word of 0x303 and swapped MISO and MOSI. @@ -6160,14 +6214,37 @@ that mode until a different control word is sent. .br .br -The BSC peripheral uses GPIO 18 (SDA) and 19 (SCL) in I2C mode -and GPIO 18 (MOSI), 19 (SCLK), 20 (MISO), and 21 (CE) in SPI mode. You -need to swap MISO/MOSI between master and slave. +GPIO used for models other than those based on the BCM2711. .br .br -When a zero control word is received GPIO 18-21 will be reset + SDA SCL MOSI SCLK MISO CE +.br +I2C 18 19 - - - - +.br +SPI - - 18 19 20 21 +.br + +.br + +.br +GPIO used for models based on the BCM2711 (e.g. the Pi4B). + +.br + +.br + SDA SCL MOSI SCLK MISO CE +.br +I2C 10 11 - - - - +.br +SPI - - 10 11 9 8 +.br + +.br + +.br +When a zero control word is received the used GPIO will be reset to INPUT mode. .br @@ -6390,8 +6467,7 @@ If there was an error the status will be less than zero .br Note that an i2c_address of 0 may be used to close -the BSC device and reassign the used GPIO (18/19) -as inputs. +the BSC device and reassign the used GPIO as inputs. .IP "\fBint event_callback(int pi, unsigned event, evtCBFunc_t f)\fP" .IP "" 4 diff --git a/pigpiod_if2.c b/pigpiod_if2.c index 36f01aa..90fb5fb 100644 --- a/pigpiod_if2.c +++ b/pigpiod_if2.c @@ -25,7 +25,7 @@ OTHER DEALINGS IN THE SOFTWARE. For more information, please refer to */ -/* PIGPIOD_IF2_VERSION 16 */ +/* PIGPIOD_IF2_VERSION 17 */ #include #include diff --git a/pigpiod_if2.h b/pigpiod_if2.h index fb214df..8d6f132 100644 --- a/pigpiod_if2.h +++ b/pigpiod_if2.h @@ -30,7 +30,7 @@ For more information, please refer to #include "pigpio.h" -#define PIGPIOD_IF2_VERSION 16 +#define PIGPIOD_IF2_VERSION 17 /*TEXT @@ -3352,6 +3352,37 @@ tick 32 bit The number of microseconds since boot WARNING: this wraps around from 4294967295 to 0 roughly every 72 minutes . . + +The GPIO are sampled at a rate set when the pigpio daemon +is started (default 5 us). + +The number of samples per second is given in the following table. + +. . + samples + per sec + + 1 1,000,000 + 2 500,000 +sample 4 250,000 +rate 5 200,000 +(us) 8 125,000 + 10 100,000 +. . + +GPIO level changes shorter than the sample rate may be missed. + +The daemon software which generates the callbacks is triggered +1000 times per second. The callbacks will be called once per +level change since the last time they were called. +i.e. The callbacks will get all level changes but there will +be a latency. + +If you want to track the level of more than one GPIO do so by +maintaining the state in the callback. Do not use [*gpio_read*]. +Remember the event that triggered the callback may have +happened several milliseconds before and the GPIO may have +changed level many times since then. D*/ /*F*/ @@ -3442,9 +3473,6 @@ The output process is simple. You simply append data to the FIFO buffer on the chip. This works like a queue, you add data to the queue and the master removes it. -This function is not available on the BCM2711 (e.g. as -used in the Pi4B). - I can't get SPI to work properly. I tried with a control word of 0x303 and swapped MISO and MOSI. @@ -3486,11 +3514,19 @@ less than requested if the FIFO already contained untransmitted data). Note that the control word sets the BSC mode. The BSC will stay in that mode until a different control word is sent. -The BSC peripheral uses GPIO 18 (SDA) and 19 (SCL) in I2C mode -and GPIO 18 (MOSI), 19 (SCLK), 20 (MISO), and 21 (CE) in SPI mode. You -need to swap MISO/MOSI between master and slave. +GPIO used for models other than those based on the BCM2711. -When a zero control word is received GPIO 18-21 will be reset + @ SDA @ SCL @ MOSI @ SCLK @ MISO @ CE +I2C @ 18 @ 19 @ - @ - @ - @ - +SPI @ - @ - @ 18 @ 19 @ 20 @ 21 + +GPIO used for models based on the BCM2711 (e.g. the Pi4B). + + @ SDA @ SCL @ MOSI @ SCLK @ MISO @ CE +I2C @ 10 @ 11 @ - @ - @ - @ - +SPI @ - @ - @ 10 @ 11 @ 9 @ 8 + +When a zero control word is received the used GPIO will be reset to INPUT mode. control consists of the following bits. @@ -3598,8 +3634,7 @@ If there was an error the status will be less than zero (and will contain the error code). Note that an i2c_address of 0 may be used to close -the BSC device and reassign the used GPIO (18/19) -as inputs. +the BSC device and reassign the used GPIO as inputs. D*/ /*F*/ diff --git a/pigs.1 b/pigs.1 index 3b5d30b..ca31392 100644 --- a/pigs.1 +++ b/pigs.1 @@ -925,10 +925,6 @@ The output process is simple. You simply append data to the FIFO buffer on the chip. This works like a queue, you add data to the queue and the master removes it. -.br -This function is not available on the BCM2711 (e.g. as -used in the Pi4B). - .br I can't get SPI to work properly. I tried with a control word of 0x303 and swapped MISO and MOSI. @@ -950,12 +946,31 @@ For I2C use a control word of (I2C address << 16) + 0x305. E.g. to talk as I2C slave with address 0x13 use 0x130305. .br -The BSC peripheral uses GPIO 18 (SDA) and 19 (SCL) in I2C mode -and GPIO 18 (MOSI), 19 (SCLK), 20 (MISO), and 21 (CE) in SPI mode. You -need to swap MISO/MOSI between master and slave. +GPIO used for models other than those based on the BCM2711. .br -When a zero control word is received GPIO 18-21 will be reset + +.EX + SDA SCL MOSI SCLK MISO CE +I2C 18 19 - - - - +SPI - - 18 19 20 21 + +.EE + +.br +GPIO used for models based on the BCM2711 (e.g. the Pi4B). + +.br + +.EX + SDA SCL MOSI SCLK MISO CE +I2C 10 11 - - - - +SPI - - 10 11 9 8 + +.EE + +.br +When a zero control word is received the used GPIO will be reset to INPUT mode. .br @@ -1031,7 +1046,8 @@ TB transmit busy .EE .br -This example assumes that GPIO 2/3 are connected to GPIO 18/19. +This example assumes that GPIO 2/3 are connected to GPIO 18/19 +(GPIO 10/11 on the BCM2711). .br diff --git a/setup.py b/setup.py index 00f70a0..023a2c4 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from distutils.core import setup setup(name='pigpio', - version='1.45', + version='1.46', author='joan', author_email='joan@abyz.me.uk', maintainer='joan', From 76cebc73b10279fbc279dffa041d9dc96676fe41 Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Sun, 22 Mar 2020 23:38:50 -0500 Subject: [PATCH 12/13] Change version to 7500 to sync with planned v75 release. --- .gitignore | 2 ++ pigpio.h | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index f67291c..98748da 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ __pycache__ build dist *.egg-info +wavepad_jitter.py + diff --git a/pigpio.h b/pigpio.h index e3eb97d..82a2394 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7401 +#define PIGPIO_VERSION 7500 /*TEXT From f2fdb2db454b242e1ce6342b907abaebedfb040c Mon Sep 17 00:00:00 2001 From: Guy McSwain Date: Mon, 23 Mar 2020 00:00:02 -0500 Subject: [PATCH 13/13] v75 --- pigpio.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pigpio.h b/pigpio.h index 82a2394..7701b45 100644 --- a/pigpio.h +++ b/pigpio.h @@ -30,7 +30,7 @@ For more information, please refer to #include #include -#define PIGPIO_VERSION 7500 +#define PIGPIO_VERSION 75 /*TEXT