Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,7 @@ Makefile

# Editor
*.orig
*.rej
*.rej

# build dirs
build-*
68 changes: 62 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,25 @@ project(libnfcnci
DESCRIPTION "NFC NCI library adapted for use with EVerest"
LANGUAGES C CXX)

include(GNUInstallDirs)

find_package(everest-cmake 0.1 REQUIRED
PATHS ../everest-cmake
)
find_package(Threads REQUIRED)
find_library(LIBRT rt)


option(LIBNFCNCI_BUILD_EXAMPLES "enable building of examples" OFF)
option(LIBNFCNCI_INSTALL "Install the library (shared data might be installed anyway)" ${EVC_MAIN_PROJECT})
option(LIBNFCNCI_LIBGPIOD "Build with libgpiod support" OFF)

if (LIBNFCNCI_LIBGPIOD)
# search for package PkgConfig
find_package(PkgConfig REQUIRED)

# search for libgpiod
pkg_search_module(LIBGPIOD REQUIRED libgpiodcxx)
endif()

if (NOT LIBNFCNCI_CONFIG_INSTALL_PATH)
set (LIBNFCNCI_CONFIG_INSTALL_PATH "${CMAKE_INSTALL_SYSCONFDIR}/everest/libnfc_config/")
Expand All @@ -23,6 +34,14 @@ set (LIBNFCNCI_CONFIG_FILES
conf/libnfc-nxp.conf
)

set(LIBNFCNCI_PUBLIC_HEADERS
src/include/linux_nfc_api.h
src/include/linux_nfc_api_compatibility.h
src/include/linux_nfc_factory_api.h
)

set(LIBNFCNCI_SOVERSION 1)

set (LIBNFCNCI_SOURCES
src/android/utility/base/file.cpp
src/libnfc-utils/src/ConfigPathProvider.cc
Expand Down Expand Up @@ -227,10 +246,11 @@ set (COMPILE_DEFINITIONS
-DSNEP_ENABLED
)


#
# library target
#
add_library(libnfc_nci)
add_library(libnfc_nci SHARED)
add_library(libnfc_nci::libnfc_nci ALIAS libnfc_nci)

target_sources(libnfc_nci
Expand All @@ -242,7 +262,9 @@ target_sources(libnfc_nci

target_compile_definitions(libnfc_nci
PRIVATE
${COMPILE_DEFINITIONS})
${COMPILE_DEFINITIONS}
$<$<BOOL:${LIBNFCNCI_LIBGPIOD}>:USE_LIBGPIOD>
)

# NOTE (aw): this is dangerous
target_compile_options(libnfc_nci
Expand All @@ -261,9 +283,27 @@ target_include_directories(libnfc_nci
target_link_libraries(libnfc_nci
PRIVATE
Threads::Threads
${LIBRT}
)

set_target_properties(libnfc_nci
PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${LIBNFCNCI_SOVERSION}
OUTPUT_NAME nfc_nci
)

if(LIBNFCNCI_LIBGPIOD)
target_include_directories(libnfc_nci
PRIVATE
${LIBGPIOD_INCLUDE_DIRS}
)

target_link_libraries(libnfc_nci
PRIVATE
${LIBGPIOD_LIBRARIES}
)
endif()

#
# examples
#
Expand All @@ -277,6 +317,10 @@ if(LIBNFCNCI_BUILD_EXAMPLES)
PRIVATE
libnfc_nci
)
install(
TARGETS nfc_cb_example
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)

add_executable(nfc_demo)
target_sources(nfc_demo
Expand All @@ -288,6 +332,10 @@ if(LIBNFCNCI_BUILD_EXAMPLES)
PRIVATE
libnfc_nci
)
install(
TARGETS nfc_demo
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
endif()

#
Expand All @@ -297,10 +345,14 @@ if (LIBNFCNCI_INSTALL)
install(
TARGETS libnfc_nci
EXPORT libnfc_nci-targets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)

install(
DIRECTORY src/include/
FILES ${LIBNFCNCI_PUBLIC_HEADERS}
TYPE INCLUDE
)

Expand All @@ -314,6 +366,10 @@ if (LIBNFCNCI_INSTALL)
NAMESPACE libnfc_nci
ADDITIONAL_CONTENT
"find_dependency(Threads)"
"set(LIBNFCNCI_LIBGPIOD @LIBNFCNCI_LIBGPIOD@)"
"if(LIBNFCNCI_LIBGPIOD)"
" find_dependency(PkgConfig)"
" pkg_search_module(LIBGPIOD REQUIRED libgpiodcxx)"
"endif()"
)
endif()

23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The [original upstream source code](https://github.com/NXPNFCLinux/linux_libnfc-
- Added CMakeLists.txt
- Allow for runtime configuration of interface properties for alternative I²C/SPI interface
- Allow configuration files to be in a custom path
- Added support for using GPIO line names via libgpiod

## Building

Expand Down Expand Up @@ -51,6 +52,13 @@ cmake --install .
```
This will also install the configuration files into the expected folder.

### libgpiod

Building against `libgpiod` can be enabled by passing the property `LIBNFCNCI_LIBGPIOD` set to `ON` to cmake.
By default, this is disabled.
Using libgpiod and GPIO line names should be the preferred way to access GPIO lines from user-space since
the older Linux' sysfs interface is deprecated since ages.

## Runtime Configuration

Runtime configuration (debug output levels, detailled NFC behaviour, interface specification) happens via the above-mentioned files.
Expand All @@ -65,7 +73,6 @@ Relevant settings are:

```
NXP_TRANSPORT=0x02
NXP_NFC_DEV_NODE="/dev/nxpnfc"
PIN_INT=535
PIN_ENABLE=536
PIN_FWDNLD=537
Expand All @@ -74,6 +81,20 @@ I2C_BUS="/dev/i2c-1"
SPI_BUS="/dev/spidev0.0"
```

When compiled with libgpiod support, then instead of using integers for Linux' legacy sysfs interface,
it is possible to use GPIO line names. These are usually defined via Device Tree for your board.
Such line names must be enclosed in quotation marks to indicate that the configuration value is a string.
And it cannot be mixed: all pin configuration values needs to be GPIO line names.

```
NXP_TRANSPORT=0x02
PIN_INT="RFID_IRQ"
PIN_ENABLE="nRESET_RFID"
PIN_FWDNLD="RFID_DWL_REQ"
I2C_ADDRESS=0x28
I2C_BUS="/dev/i2c-1"
```


---

Expand Down
23 changes: 19 additions & 4 deletions conf/libnfc-nxp.conf
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,34 @@ NXPLOG_FWDNLD_LOGLEVEL=0x00
NXPLOG_TML_LOGLEVEL=0x00
###############################################################################
# TRANSPORT Type
# 0x00 - I2C /SPI for noraml nxpnfc driver
# 0x00 - I2C / SPI for normal nxpnfc driver
# 0x01 - Not Used, kept to align with Android code
# 0x02 - ALT_I2C
# 0x03 - ALT_SPI
# 0x02 - ALT_I2C: standard I2C Linux interface
# 0x03 - ALT_SPI: standard SPIDEV Linux interface
NXP_TRANSPORT=0x02

###############################################################################
# Nfc Device Node name
# Nfc Device Node name (only used for NXP_TRANSPORT=0x00)
NXP_NFC_DEV_NODE="/dev/nxpnfc"

###############################################################################
# ALT_I2C/SPI Interface Configuration
# [PINs defined as GPIO23/24/25 on RPi4 (choose 594, 595, 596 for RPi5)]
#
# Integer numbers are used for Linux' deprecated sysfs GPIO interface. When
# the library is built against libgpiod, then use GPIO line names. Prefixing
# a line name with '!' signals to libgpiod that the line should be handled with
# ACTIVE_LOW semantic. In the following example, however, the 'reset pin'
# has inverted logic and gives thus 'enable' functionality without the need
# to mark it as active-low.
Comment thread
mhei marked this conversation as resolved.
# Note: Mixing plain integers and GPIO line names is not supported and results
# in undefined behavior.
#
# Example for GPIO line names usage:
# PIN_INT="RFID_IRQ"
# PIN_ENABLE="nRESET_RFID"
# PIN_FWDNLD="RFID_DWL_REQ"
#
PIN_INT=535
PIN_ENABLE=536
PIN_FWDNLD=537
Expand Down
2 changes: 1 addition & 1 deletion demoapp/nfc_cb_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ NfcHandler::NfcHandler() {
throw std::runtime_error("Only one global nfc handler instance allowed");
}

setConfigPath("../../build/dist/etc/everest/libnfc_config")
setConfigPath("../../build/dist/etc/everest/libnfc_config");

InitializeLogLevel();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,26 +275,3 @@ int NfccAltI2cTransport::Write(void* pDevHandle, uint8_t* pBuffer,
NXPLOG_TML_D("%s exit", __func__);
return numWrote;
}

/*******************************************************************************
**
** Function Close
**
** Description Closes NFCC device
**
** Parameters pDevHandle - device handle
**
** Returns None
**
*******************************************************************************/
void NfccAltI2cTransport::Close(void* pDevHandle) {
NXPLOG_TML_D("%s Enter", __func__);
if (NULL != pDevHandle) {
close((intptr_t)pDevHandle);
}
if (iEnableFd) close(iEnableFd);
if (iInterruptFd) close(iInterruptFd);
if (iFwDnldFd) close(iFwDnldFd);
NXPLOG_TML_D("%s exit", __func__);
return;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <NfccTransport.h>

class NfccAltI2cTransport : public NfccAltTransport {
public:
public:
/*****************************************************************************
**
** Function OpenAndConfigure
Expand All @@ -36,7 +36,7 @@ class NfccAltI2cTransport : public NfccAltTransport {
** NFCSTATUS_INVALID_DEVICE - device open operation failure
**
****************************************************************************/
NFCSTATUS OpenAndConfigure(pphTmlNfc_Config_t pConfig, void** pLinkHandle);
virtual NFCSTATUS OpenAndConfigure(pphTmlNfc_Config_t pConfig, void** pLinkHandle) override;

/*****************************************************************************
**
Expand All @@ -54,7 +54,7 @@ class NfccAltI2cTransport : public NfccAltTransport {
** -1 - read operation failure
**
****************************************************************************/
int Read(void* pDevHandle, uint8_t* pBuffer, int nNbBytesToRead);
virtual int Read(void* pDevHandle, uint8_t* pBuffer, int nNbBytesToRead) override;

/*****************************************************************************
**
Expand All @@ -71,6 +71,5 @@ class NfccAltI2cTransport : public NfccAltTransport {
** -1 - write operation failure
**
*****************************************************************************/
int Write(void* pDevHandle, uint8_t* pBuffer, int nNbBytesToWrite);
void Close(void* pDevHandle);
virtual int Write(void* pDevHandle, uint8_t* pBuffer, int nNbBytesToWrite) override;
};
Original file line number Diff line number Diff line change
Expand Up @@ -390,26 +390,3 @@ int NfccAltSpiTransport::Write(void* pDevHandle, uint8_t* pBuffer,
NXPLOG_TML_D("%s exit", __func__);
return numWrote - PREFIX_LENGTH;
}

/*******************************************************************************
**
** Function Close
**
** Description Closes NFCC device
**
** Parameters pDevHandle - device handle
**
** Returns None
**
*******************************************************************************/
void NfccAltSpiTransport::Close(void* pDevHandle) {
NXPLOG_TML_D("%s Enter", __func__);
if (NULL != pDevHandle) {
close((intptr_t)pDevHandle);
}
if (iEnableFd) close(iEnableFd);
if (iInterruptFd) close(iInterruptFd);
if (iFwDnldFd) close(iFwDnldFd);
NXPLOG_TML_D("%s exit", __func__);
return;
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#include <NfccTransport.h>

class NfccAltSpiTransport : public NfccAltTransport {
public:
public:
/*****************************************************************************
**
** Function OpenAndConfigure
Expand All @@ -36,7 +36,7 @@ class NfccAltSpiTransport : public NfccAltTransport {
** NFCSTATUS_INVALID_DEVICE - device open operation failure
**
****************************************************************************/
NFCSTATUS OpenAndConfigure(pphTmlNfc_Config_t pConfig, void** pLinkHandle);
virtual NFCSTATUS OpenAndConfigure(pphTmlNfc_Config_t pConfig, void** pLinkHandle) override;

/*****************************************************************************
**
Expand All @@ -54,7 +54,7 @@ class NfccAltSpiTransport : public NfccAltTransport {
** -1 - read operation failure
**
****************************************************************************/
int Read(void* pDevHandle, uint8_t* pBuffer, int nNbBytesToRead);
virtual int Read(void* pDevHandle, uint8_t* pBuffer, int nNbBytesToRead) override;

/*****************************************************************************
**
Expand All @@ -71,6 +71,5 @@ class NfccAltSpiTransport : public NfccAltTransport {
** -1 - write operation failure
**
*****************************************************************************/
int Write(void* pDevHandle, uint8_t* pBuffer, int nNbBytesToWrite);
void Close(void* pDevHandle);
virtual int Write(void* pDevHandle, uint8_t* pBuffer, int nNbBytesToWrite) override;
};
Loading