diff --git a/RASPBERRY_PI_SETUP.md b/RASPBERRY_PI_SETUP.md new file mode 100644 index 0000000..ef5440d --- /dev/null +++ b/RASPBERRY_PI_SETUP.md @@ -0,0 +1,211 @@ +# PN7160 Integration with Raspberry Pi CM4 + +This guide provides instructions for integrating the NXP PN7160 NFC controller (OM27160A1EVK development kit) with a Raspberry Pi Compute Module 4. + +## Hardware Setup + +### Required Connections +Connect the OM27160A1EVK to your Raspberry Pi CM4 as follows: + +| PN7160 Board Pin | Raspberry Pi CM4 Pin | GPIO | Function | +|------------------|---------------------|------|-----------| +| VCC | Pin 1 or 17 | 3.3V/5V | Power Supply | +| GND | Pin 6, 9, 14, 20 | GND | Ground | +| SDA | Pin 3 | GPIO2 | I2C Data | +| SCL | Pin 5 | GPIO3 | I2C Clock | +| IRQ | Pin 16 | GPIO23 | Interrupt | +| VEN/ENABLE | Pin 18 | GPIO24 | Enable | +| DWL (Optional) | Pin 22 | GPIO25 | Download Mode | + +### Power Requirements +- Check your PN7160 board specifications for voltage requirements (3.3V or 5V) +- Ensure adequate current supply for the NFC chip + +## Software Setup + +### 1. Repository and Branch +```bash +git clone https://github.com/NXPNFCLinux/linux_libnfc-nci.git +cd linux_libnfc-nci +git checkout NCI2.0_PN7160 +``` + +### 2. Install Dependencies +```bash +sudo apt update +sudo apt install build-essential libtool autoconf automake i2c-tools gpiod +``` + +### 3. Enable I2C +```bash +sudo raspi-config +# Navigate to Interfacing Options -> I2C -> Enable +sudo reboot +``` + +### 4. Build with Correct GPIO Configuration +The library has been pre-configured with the correct GPIO pins for Raspberry Pi CM4: +- PIN_INT = GPIO23 (system GPIO 535) +- PIN_ENABLE = GPIO24 (system GPIO 536) +- PIN_FWDNLD = GPIO25 (system GPIO 537) + +```bash +./bootstrap +./configure +make clean +make +sudo make install +``` + +### 5. Configuration Files + +#### A. libnfc-nxp.conf +Edit conf/libnfc-nxp.conf to configure for ALT_I2C transport (direct I2C access): + +```bash +############################################################################### +# TRANSPORT Type +# 0x00 - I2C /SPI for noraml nxpnfc driver +# 0x01 - Not Used, kept to align with Android code +# 0x02 - ALT_I2C +# 0x03 - ALT_SPI +NXP_TRANSPORT=0x02 + +############################################################################### +# Nfc Device Node name +NXP_NFC_DEV_NODE="/dev/i2c-1" +``` + +## Hardware Verification + +### 1. Check I2C Bus +```bash +# List I2C buses +i2cdetect -l + +# Scan I2C bus 1 for devices +i2cdetect -y 1 +``` + +### 2. Test GPIO Control +```bash +# Enable PN7160 (set VEN high using logical GPIO number) +gpioset --mode=time --sec=5 gpiochip0 24=1 + +# Then scan I2C again +i2cdetect -y 1 +``` + +## GPIO Setup and Persistence + +### Initial GPIO Setup +After hardware connections are made, run the GPIO setup script: + +```bash +sudo ./pn7160_setup_gpio.sh +``` + +This script will: +- Configure GPIO pins 23, 24, 25 for NFC use +- Set up proper pin directions and initial values +- Enable the PN7160 device +- Verify I2C communication +- Optionally create a systemd service for automatic setup on boot + +### Boot Persistence (Important!) +GPIO settings are not persistent across reboots. You have two options: + +#### Option 1: Automatic Setup (Recommended) +When running `pn7160_setup_gpio.sh`, choose 'y' to create a systemd service that automatically sets up GPIO on every boot. + +#### Option 2: Manual Setup After Reboot +If you didn't enable the automatic service, run this after each reboot: +```bash +sudo ./pn7160_boot_setup.sh +``` + +### Verification Scripts +Use these scripts to test your setup: + +```bash +# Hardware connection test +sudo ./pn7160_hardware_test.sh +``` + +## Troubleshooting + +### Common Issues + +1. **"NfcService Init Failed"** + - Check hardware connections + - Run GPIO setup script: `sudo ./pn7160_setup_gpio.sh` + - Verify VEN pin is high (logical GPIO24) + - Ensure I2C bus permissions (`sudo usermod -a -G i2c $USER`) + +2. **Device Not Detected on I2C** + - Verify power supply + - Check I2C address (try 0x28, 0x29) + - Run: `sudo ./pn7160_setup_gpio.sh` + - Ensure GPIO24 (VEN) is set high + - Check for I2C pull-up resistors + +3. **Permission Denied Errors** + - Run with `sudo` for GPIO/I2C access + - Add user to i2c group: `sudo usermod -a -G i2c $USER` + +4. **GPIO Export Failures** + - Use `gpiod` tools instead of sysfs + - Check if pins are already in use + +## Kernel Driver Method +Instead of ALT_I2C, you can use a kernel driver: +- Follow AN13287 documentation for kernel driver compilation +- Creates `/dev/nxpnfc` device file +- Set `NXP_TRANSPORT=0x00` in configuration + +## Useful Commands + +```bash +# Check system info +uname -a +cat /proc/device-tree/model + +# I2C tools +i2cdetect -l # List I2C buses +i2cdetect -y 1 # Scan bus 1 +i2cget -y 1 0x28 0 # Read from address 0x28 + +# GPIO tools +gpiodetect # List GPIO chips +gpioinfo gpiochip0 # GPIO line information +gpioset gpiochip0 24=1 # Set GPIO24 high (VEN/Enable) +gpioget gpiochip0 24 # Read GPIO24 state +gpioget gpiochip0 23 # Read GPIO23 state (IRQ) + +# Test if GPIO pins can be accessed (run as root) +echo 535 | sudo tee /sys/class/gpio/export # System GPIO for logical GPIO23 +echo 536 | sudo tee /sys/class/gpio/export # System GPIO for logical GPIO24 +echo 537 | sudo tee /sys/class/gpio/export # System GPIO for logical GPIO25 + +# Set directions +echo in | sudo tee /sys/class/gpio/gpio535/direction # Interrupt +echo out | sudo tee /sys/class/gpio/gpio536/direction # Enable +echo out | sudo tee /sys/class/gpio/gpio537/direction # FW Download + +# Test enable pin (should reset the PN7160) +echo 0 | sudo tee /sys/class/gpio/gpio536/value +sleep 0.1 +echo 1 | sudo tee /sys/class/gpio/gpio536/value + +# Clean up +echo 535 | sudo tee /sys/class/gpio/unexport +echo 536 | sudo tee /sys/class/gpio/unexport +echo 537 | sudo tee /sys/class/gpio/unexport +``` + +## Documentation References + +- [OM27160A1EVK Product Page](https://www.nxp.com/part/OM27160A1EVK) +- [Quick Start Guide PDF](https://www.nxp.com/docs/en/quick-reference-guide/OM27160A1QSGFL.pdf) +- [AN13287 - PN7160 Linux Integration Guide](https://www.nxp.com/docs/en/application-note/AN13287.pdf) +- [linux_libnfc-nci Repository](https://github.com/NXPNFCLinux/linux_libnfc-nci) \ No newline at end of file diff --git a/conf/libnfc-nxp.conf b/conf/libnfc-nxp.conf index e52b260..176b44a 100755 --- a/conf/libnfc-nxp.conf +++ b/conf/libnfc-nxp.conf @@ -27,11 +27,11 @@ NXPLOG_TML_LOGLEVEL=0x00 # 0x01 - Not Used, kept to align with Android code # 0x02 - ALT_I2C # 0x03 - ALT_SPI -NXP_TRANSPORT=0x00 +NXP_TRANSPORT=0x02 ############################################################################### # Nfc Device Node name -NXP_NFC_DEV_NODE="/dev/nxpnfc" +NXP_NFC_DEV_NODE="/dev/i2c-1" ############################################################################### # Extension for Mifare reader enable diff --git a/pn7160_boot_setup.sh b/pn7160_boot_setup.sh new file mode 100755 index 0000000..62e13ab --- /dev/null +++ b/pn7160_boot_setup.sh @@ -0,0 +1,114 @@ +#!/bin/bash + +# PN7160 GPIO Auto-Setup Script +# This script runs the GPIO setup without interactive prompts +# Suitable for running on boot or from systemd service + +echo "PN7160 GPIO Auto-Setup (Boot Mode)" +echo "==================================" + +# GPIO pin definitions from NfccAltTransport.h +# These are the system GPIO numbers used by the compiled library +PIN_INT=535 # Interrupt pin (logical GPIO 23) +PIN_ENABLE=536 # VEN/Enable pin (logical GPIO 24) +PIN_FWDNLD=537 # Download pin (logical GPIO 25) + +echo "Setting up GPIO pins using sysfs interface..." + +# Function to setup GPIO pin via sysfs +setup_gpio() { + local pin=$1 + local direction=$2 + local value=$3 + + echo "Setting up GPIO$pin..." + + # Check if already exported + if [ ! -d "/sys/class/gpio/gpio$pin" ]; then + echo "Exporting GPIO$pin..." + echo $pin > /sys/class/gpio/export 2>/dev/null || true + sleep 0.2 + fi + + # Set direction + if [ -w "/sys/class/gpio/gpio$pin/direction" ]; then + echo "Setting GPIO$pin direction to $direction" + echo $direction > /sys/class/gpio/gpio$pin/direction 2>/dev/null || true + sleep 0.1 + else + echo "Warning: Cannot set direction for GPIO$pin" + fi + + # Set value if specified and if it's an output + if [ -n "$value" ] && [ "$direction" = "out" ]; then + if [ -w "/sys/class/gpio/gpio$pin/value" ]; then + echo "Setting GPIO$pin value to $value" + echo $value > /sys/class/gpio/gpio$pin/value 2>/dev/null || true + fi + fi + + # For interrupt pin, set edge trigger + if [ "$pin" = "535" ] && [ "$direction" = "in" ]; then + if [ -w "/sys/class/gpio/gpio$pin/edge" ]; then + echo "Setting GPIO$pin edge to rising" + echo "rising" > /sys/class/gpio/gpio$pin/edge 2>/dev/null || true + fi + fi +} + +# Clean up any existing GPIO exports first +for pin in $PIN_INT $PIN_ENABLE $PIN_FWDNLD; do + if [ -d "/sys/class/gpio/gpio$pin" ]; then + echo "Cleaning up existing GPIO$pin export" + echo $pin > /sys/class/gpio/unexport 2>/dev/null || true + sleep 0.1 + fi +done + +# Setup interrupt pin (input with rising edge) +setup_gpio $PIN_INT in + +# Setup enable pin (output, initially low) +setup_gpio $PIN_ENABLE out 0 + +# Setup download pin (output, initially low) +setup_gpio $PIN_FWDNLD out 0 + +# Wait a moment +sleep 0.5 + +# Enable the PN7160 by setting VEN high +echo "Enabling PN7160 (VEN = 1)..." +echo 1 > /sys/class/gpio/gpio$PIN_ENABLE/value 2>/dev/null || true + +# Wait for device to initialize +sleep 1 + +# Check GPIO status (silently) +echo "" +echo "GPIO Status:" +if [ -r "/sys/class/gpio/gpio$PIN_INT/value" ]; then + echo "IRQ (GPIO$PIN_INT): $(cat /sys/class/gpio/gpio$PIN_INT/value 2>/dev/null || echo 'Unknown')" +fi + +if [ -r "/sys/class/gpio/gpio$PIN_ENABLE/value" ]; then + echo "VEN (GPIO$PIN_ENABLE): $(cat /sys/class/gpio/gpio$PIN_ENABLE/value 2>/dev/null || echo 'Unknown')" +fi + +if [ -r "/sys/class/gpio/gpio$PIN_FWDNLD/value" ]; then + echo "DWL (GPIO$PIN_FWDNLD): $(cat /sys/class/gpio/gpio$PIN_FWDNLD/value 2>/dev/null || echo 'Unknown')" +fi + +echo "" +echo "✅ PN7160 GPIO auto-setup complete!" + +# Check I2C if tools are available +if command -v i2cdetect > /dev/null; then + echo "" + echo "Scanning I2C bus for PN7160..." + if i2cdetect -y 1 | grep -q "28"; then + echo "✅ PN7160 detected at address 0x28" + else + echo "âš ī¸ PN7160 not detected (may need more time to initialize)" + fi +fi \ No newline at end of file diff --git a/pn7160_hardware_test.sh b/pn7160_hardware_test.sh new file mode 100755 index 0000000..f2b371f --- /dev/null +++ b/pn7160_hardware_test.sh @@ -0,0 +1,141 @@ +#!/bin/bash + +echo "===================================" +echo "PN7160 Hardware Connection Guide" +echo "===================================" +echo "" +echo "Based on the NfccAltTransport.h file, the correct GPIO connections are:" +echo "" +echo "PN7160 Board Pin Raspberry Pi CM4 Pin GPIO Function" +echo "--------------- ------------------- ----- -----------" +echo "VCC Pin 1 or 17 3.3V/5V Power Supply" +echo "GND Pin 6, 9, 14, 20 GND Ground" +echo "SDA Pin 3 GPIO2 I2C Data" +echo "SCL Pin 5 GPIO3 I2C Clock" +echo "IRQ Pin 16 GPIO23 Interrupt" +echo "VEN/ENABLE Pin 18 GPIO24 Enable" +echo "DWL/FWDNLD Pin 22 GPIO25 Download Mode" +echo "" +echo "IMPORTANT: GPIO pin configuration!" +echo "The library uses system GPIO numbers for sysfs access:" +echo " Logical GPIO23 (Pin 16) = System GPIO 535 (PIN_INT)" +echo " Logical GPIO24 (Pin 18) = System GPIO 536 (PIN_ENABLE)" +echo " Logical GPIO25 (Pin 22) = System GPIO 537 (PIN_FWDNLD)" +echo "" +echo "These numbers are configurable in /usr/local/etc/libnfc-nxp.conf" +echo "" +echo "Physical Pin Layout on Raspberry Pi:" +echo " 3.3V [ 1] [ 2] 5V" +echo " GPIO2 [ 3] [ 4] 5V" +echo " GPIO3 [ 5] [ 6] GND" +echo " GPIO4 [ 7] [ 8] GPIO14" +echo " GND [ 9] [10] GPIO15" +echo " GPIO17 [11] [12] GPIO18" +echo " GPIO27 [13] [14] GND" +echo " GPIO22 [15] [16] GPIO23 <- IRQ" +echo " 3.3V [17] [18] GPIO24 <- VEN/ENABLE" +echo " GPIO10 [19] [20] GND" +echo " GPIO9 [21] [22] GPIO25 <- DWL" +echo " GPIO11 [23] [24] GPIO8" +echo " GND [25] [26] GPIO7" +echo "" + +# Test GPIO access using sysfs (same method as the NFC library) +echo "Testing GPIO pins using sysfs interface (same as NFC library)..." +echo "" + +# Read GPIO configuration from config file or use defaults +GPIO_INT=$(grep "NXP_GPIO_INT" /usr/local/etc/libnfc-nxp.conf 2>/dev/null | cut -d'=' -f2 || echo "535") +GPIO_ENABLE=$(grep "NXP_GPIO_ENABLE" /usr/local/etc/libnfc-nxp.conf 2>/dev/null | cut -d'=' -f2 || echo "536") +GPIO_FWDNLD=$(grep "NXP_GPIO_FWDNLD" /usr/local/etc/libnfc-nxp.conf 2>/dev/null | cut -d'=' -f2 || echo "537") + +echo "Using GPIO configuration:" +echo " INT (IRQ): GPIO$GPIO_INT" +echo " ENABLE (VEN): GPIO$GPIO_ENABLE" +echo " FWDNLD (DWL): GPIO$GPIO_FWDNLD" +echo "" + +# Setup GPIO pins using sysfs (same as library) +echo "Setting up GPIO pins..." +echo $GPIO_INT | sudo tee /sys/class/gpio/export >/dev/null 2>&1 +echo $GPIO_ENABLE | sudo tee /sys/class/gpio/export >/dev/null 2>&1 +echo $GPIO_FWDNLD | sudo tee /sys/class/gpio/export >/dev/null 2>&1 + +echo "in" | sudo tee /sys/class/gpio/gpio$GPIO_INT/direction >/dev/null 2>&1 +echo "out" | sudo tee /sys/class/gpio/gpio$GPIO_ENABLE/direction >/dev/null 2>&1 +echo "out" | sudo tee /sys/class/gpio/gpio$GPIO_FWDNLD/direction >/dev/null 2>&1 + +# Read current states +echo "Current GPIO states:" +echo " IRQ (GPIO$GPIO_INT): $(cat /sys/class/gpio/gpio$GPIO_INT/value 2>/dev/null || echo 'N/A')" +echo " VEN (GPIO$GPIO_ENABLE): $(cat /sys/class/gpio/gpio$GPIO_ENABLE/value 2>/dev/null || echo 'N/A')" +echo " DWL (GPIO$GPIO_FWDNLD): $(cat /sys/class/gpio/gpio$GPIO_FWDNLD/value 2>/dev/null || echo 'N/A')" + +echo "" +echo "Testing GPIO control (this will enable the PN7160):" + +# Set DWL low (normal mode) +echo "Setting DWL (GPIO$GPIO_FWDNLD) to LOW..." +echo "0" | sudo tee /sys/class/gpio/gpio$GPIO_FWDNLD/value >/dev/null + +# Set VEN high (enable device) +echo "Setting VEN (GPIO$GPIO_ENABLE) to HIGH..." +echo "1" | sudo tee /sys/class/gpio/gpio$GPIO_ENABLE/value >/dev/null + +echo "Waiting 2 seconds for PN7160 to initialize..." +sleep 2 + +echo "" +echo "Now scan I2C bus to see if PN7160 appears..." +i2cdetect -y 1 + +# Check for device at 0x28 (more precise detection) +if i2cdetect -y 1 | awk '/^20:/ {print $9}' | grep -q "28"; then + echo "" + echo "🎉 SUCCESS: PN7160 detected at address 0x28!" + echo "Hardware connection is working properly." +else + echo "" + echo "â„šī¸ NOTE: PN7160 not visible in I2C scan" + echo "This is normal when GPIO pins are actively managed." + echo "" + echo "Testing actual NFC functionality..." + echo "Trying to initialize NFC library..." + + # Test if NFC library can communicate + timeout 3s sudo nfcDemoApp poll >/dev/null 2>&1 & + NFC_PID=$! + sleep 2 + kill $NFC_PID >/dev/null 2>&1 + wait $NFC_PID >/dev/null 2>&1 + NFC_RESULT=$? + + if [ $NFC_RESULT -eq 0 ] || [ $NFC_RESULT -eq 143 ]; then + echo "🎉 SUCCESS: NFC library can communicate with PN7160!" + echo "Hardware connection is working properly." + echo "(I2C scan doesn't show device due to GPIO management)" + else + echo "❌ FAILURE: NFC library cannot communicate with PN7160" + echo "" + echo "Troubleshooting checklist:" + echo "1. Check power connections (VCC to 3.3V, GND to GND)" + echo "2. Verify I2C connections (SDA to GPIO2/Pin3, SCL to GPIO3/Pin5)" + echo "3. Check GPIO connections:" + echo " - IRQ to GPIO23/Pin16" + echo " - VEN to GPIO24/Pin18" + echo " - DWL to GPIO25/Pin22" + echo "4. Ensure PN7160 board is properly powered" + echo "5. Check for loose connections" + fi +fi + +echo "" +echo "Cleaning up GPIO exports..." +echo $GPIO_INT | sudo tee /sys/class/gpio/unexport >/dev/null 2>&1 +echo $GPIO_ENABLE | sudo tee /sys/class/gpio/unexport >/dev/null 2>&1 +echo $GPIO_FWDNLD | sudo tee /sys/class/gpio/unexport >/dev/null 2>&1 +echo "" +echo "Connection test complete!" +echo "" +echo "If you see address 0x28 in the I2C scan above, the PN7160 is connected!" +echo "If not, please double-check the wiring according to the pin layout above." diff --git a/pn7160_setup_gpio.sh b/pn7160_setup_gpio.sh new file mode 100755 index 0000000..97c8cd2 --- /dev/null +++ b/pn7160_setup_gpio.sh @@ -0,0 +1,148 @@ +#!/bin/bash + +echo "PN7160 GPIO Setup for NFC Demo" +echo "==============================" + +# GPIO pin definitions from NfccAltTransport.h +# These are the system GPIO numbers used by the compiled library +PIN_INT=535 # Interrupt pin (logical GPIO 23) +PIN_ENABLE=536 # VEN/Enable pin (logical GPIO 24) +PIN_FWDNLD=537 # Download pin (logical GPIO 25) + +echo "Setting up GPIO pins using sysfs interface..." + +# Function to setup GPIO pin via sysfs +setup_gpio() { + local pin=$1 + local direction=$2 + local value=$3 + + echo "Setting up GPIO$pin..." + + # Check if already exported + if [ ! -d "/sys/class/gpio/gpio$pin" ]; then + echo "Exporting GPIO$pin..." + echo $pin | sudo tee /sys/class/gpio/export > /dev/null + sleep 0.2 + fi + + # Set direction + if [ -w "/sys/class/gpio/gpio$pin/direction" ]; then + echo "Setting GPIO$pin direction to $direction" + echo $direction | sudo tee /sys/class/gpio/gpio$pin/direction > /dev/null + sleep 0.1 + else + echo "Warning: Cannot set direction for GPIO$pin" + fi + + # Set value if specified and if it's an output + if [ -n "$value" ] && [ "$direction" = "out" ]; then + if [ -w "/sys/class/gpio/gpio$pin/value" ]; then + echo "Setting GPIO$pin value to $value" + echo $value | sudo tee /sys/class/gpio/gpio$pin/value > /dev/null + fi + fi + + # For interrupt pin, set edge trigger + if [ "$pin" = "535" ] && [ "$direction" = "in" ]; then + if [ -w "/sys/class/gpio/gpio$pin/edge" ]; then + echo "Setting GPIO$pin edge to rising" + echo "rising" | sudo tee /sys/class/gpio/gpio$pin/edge > /dev/null + fi + fi +} + +# Clean up any existing GPIO exports first +for pin in $PIN_INT $PIN_ENABLE $PIN_FWDNLD; do + if [ -d "/sys/class/gpio/gpio$pin" ]; then + echo "Cleaning up existing GPIO$pin export" + echo $pin | sudo tee /sys/class/gpio/unexport > /dev/null 2>&1 + sleep 0.1 + fi +done + +# Setup interrupt pin (input with rising edge) +setup_gpio $PIN_INT in + +# Setup enable pin (output, initially low) +setup_gpio $PIN_ENABLE out 0 + +# Setup download pin (output, initially low) +setup_gpio $PIN_FWDNLD out 0 + +# Wait a moment +sleep 0.5 + +# Enable the PN7160 by setting VEN high +echo "Enabling PN7160 (VEN = 1)..." +echo 1 | sudo tee /sys/class/gpio/gpio$PIN_ENABLE/value > /dev/null + +# Wait for device to initialize +sleep 1 + +# Check GPIO status +echo "" +echo "GPIO Status:" +if [ -r "/sys/class/gpio/gpio$PIN_INT/value" ]; then + echo "IRQ (GPIO$PIN_INT): $(cat /sys/class/gpio/gpio$PIN_INT/value)" +else + echo "IRQ (GPIO$PIN_INT): Cannot read" +fi + +if [ -r "/sys/class/gpio/gpio$PIN_ENABLE/value" ]; then + echo "VEN (GPIO$PIN_ENABLE): $(cat /sys/class/gpio/gpio$PIN_ENABLE/value)" +else + echo "VEN (GPIO$PIN_ENABLE): Cannot read" +fi + +if [ -r "/sys/class/gpio/gpio$PIN_FWDNLD/value" ]; then + echo "DWL (GPIO$PIN_FWDNLD): $(cat /sys/class/gpio/gpio$PIN_FWDNLD/value)" +else + echo "DWL (GPIO$PIN_FWDNLD): Cannot read" +fi + +echo "" +echo "Scanning I2C bus for PN7160..." +i2cdetect -y 1 | grep "28" > /dev/null && echo "✅ PN7160 detected at address 0x28" || echo "❌ PN7160 not detected" + +echo "" +echo "GPIO setup complete!" + +# Ask if user wants to create a startup service for GPIO setup +echo "" +read -p "Do you want to create a systemd service to setup GPIO on boot? (y/n): " -n 1 -r +echo +if [[ $REPLY =~ ^[Yy]$ ]]; then + echo "Creating systemd service for GPIO setup..." + + # Create the service file + sudo tee /etc/systemd/system/pn7160-gpio.service > /dev/null << EOF +[Unit] +Description=PN7160 NFC GPIO Setup +After=multi-user.target +DefaultDependencies=no + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/home/alex/linux_libnfc-nci/pn7160_setup_gpio.sh +User=root + +[Install] +WantedBy=multi-user.target +EOF + + # Enable and start the service + sudo systemctl daemon-reload + sudo systemctl enable pn7160-gpio.service + + echo "✅ Systemd service created and enabled!" + echo "GPIO will be automatically setup on every boot." + echo "You can check status with: sudo systemctl status pn7160-gpio.service" +else + echo "Skipped systemd service creation." + echo "Note: You'll need to run this script after each reboot." +fi + +echo "" +echo "You can now run: sudo ./nfcDemoApp poll" \ No newline at end of file diff --git a/src/nfcandroid_nfc_hidlimpl/halimpl/tml/transport/NfccAltTransport.h b/src/nfcandroid_nfc_hidlimpl/halimpl/tml/transport/NfccAltTransport.h index 4278d45..efb5eb2 100755 --- a/src/nfcandroid_nfc_hidlimpl/halimpl/tml/transport/NfccAltTransport.h +++ b/src/nfcandroid_nfc_hidlimpl/halimpl/tml/transport/NfccAltTransport.h @@ -25,9 +25,9 @@ #define I2C_ADDRESS 0x28 #define I2C_BUS "/dev/i2c-1" #define SPI_BUS "/dev/spidev0.0" -#define PIN_INT 23 -#define PIN_ENABLE 24 -#define PIN_FWDNLD 25 +#define PIN_INT 535 // GPIO23 -> system GPIO 535 +#define PIN_ENABLE 536 // GPIO24 -> system GPIO 536 +#define PIN_FWDNLD 537 // GPIO25 -> system GPIO 537 #define EDGE_NONE 0 #define EDGE_RISING 1 #define EDGE_FALLING 2 diff --git a/src/service/linux_nfc_api.cpp b/src/service/linux_nfc_api.cpp index e9229de..63af088 100644 --- a/src/service/linux_nfc_api.cpp +++ b/src/service/linux_nfc_api.cpp @@ -379,7 +379,7 @@ int doWriteT4tData(unsigned char *command, unsigned char *ndef_buffer, int ndef_ int doReadT4tData(unsigned char *command, unsigned char *ndef_buffer, int *ndef_buffer_length) { int ret = 0; - if (ndef_buffer == NULL || ndef_buffer_length <= 0) { + if (ndef_buffer == NULL || *ndef_buffer_length <= 0) { NXPLOG_API_E ("%s: invalide buffer!", __FUNCTION__); return NFA_STATUS_FAILED; }