From 2dce64f82155190f84a1693ab38cf437ac74e6dc Mon Sep 17 00:00:00 2001 From: Scott Vitale Date: Tue, 3 Mar 2015 23:47:26 +0000 Subject: [PATCH] Remove NxpRdLib source and pull it directly from NXP during the build process. --- Mifare.c | 2 +- Mifare.h | 6 ++-- get_nxpRdLib.sh | 80 +++++++++++++++++++++++++++++++++++++++++++++++++ setup.py | 17 +++-------- 4 files changed, 88 insertions(+), 17 deletions(-) create mode 100755 get_nxpRdLib.sh diff --git a/Mifare.c b/Mifare.c index d29070d..280dfd1 100644 --- a/Mifare.c +++ b/Mifare.c @@ -5,7 +5,7 @@ int Mifare_init(Mifare *self, PyObject *args, PyObject *kwds) { phStatus_t status; /* Initialize the Reader BAL (Bus Abstraction Layer) component */ - status = phbalReg_R_Pi_spi_Init(&self->data.balReader, sizeof(phbalReg_R_Pi_spi_DataParams_t)); + status = phbalReg_RpiSpi_Init(&self->data.balReader, sizeof(phbalReg_RpiSpi_DataParams_t)); if (PH_ERR_SUCCESS != status) { PyErr_Format(InitError, "SPI Init failed: %04x", status); diff --git a/Mifare.h b/Mifare.h index 1fd92c8..7c35dfd 100644 --- a/Mifare.h +++ b/Mifare.h @@ -32,6 +32,8 @@ /* Status code definitions */ #include +#include + /* Reader Library Headers */ /* Generic ISO14443-3A Component of * Reader Library Framework */ @@ -55,8 +57,6 @@ * Ultralight-C cards. */ #include -#include -#include #include #include @@ -64,7 +64,7 @@ #define UID_ASCII_BUFFER_SIZE ((UID_BUFFER_SIZE * 2) + 1) typedef struct { - phbalReg_R_Pi_spi_DataParams_t balReader; + phbalReg_RpiSpi_DataParams_t balReader; phhalHw_Rc523_DataParams_t hal; phpalI14443p4_Sw_DataParams_t I14443p4; phpalMifare_Sw_DataParams_t palMifare; diff --git a/get_nxpRdLib.sh b/get_nxpRdLib.sh new file mode 100755 index 0000000..2eb52ff --- /dev/null +++ b/get_nxpRdLib.sh @@ -0,0 +1,80 @@ +#!/bin/bash + +blue='\033[0;34m' +NC='\033[0m' # No Color + +prereq() { + echo -e "[${blue}Installing prerequisites${NC}]" + sudo apt-get update + sudo apt-get -y install libglib2.0 glib-networking-services libreadline6-dev libglib2.0-dev glib-networking-services python2.7-dev build-essential autoconf libtool +} + +neardal() { + echo -e "[${blue}Downloading NeardAL${NC}]" + curl -L https://github.com/connectivity/neardal/archive/0.14.tar.gz | tar --overwrite -xz + cd neardal-0.14 + + echo -e "[${blue}Running autogen.sh${NC}]" + ./autogen.sh + + echo -e "[${blue}Configuring NeardAL${NC}]" + ./configure --prefix=/usr --sysconfdir=/etc --localstatedir=/var + + echo -e "[${blue}Building NeardAL${NC}]" + make + + echo -e "[${blue}Installing NeardAL${NC}]" + sudo make install + + cd .. +} + +wiringpi() { + echo -e "[${blue}Downloading wiringPi${NC}]" + git clone git://git.drogon.net/wiringPi + git reset --hard 72b2af231be337d45a557ce6ca3ed1eeb6675ffd + + echo -e "[${blue}Building and Installing wiringPi${NC}]" + cd wiringPi + ./build + + echo -e "[${blue}Running ldconfig${NC}]" + sudo ldconfig + + cd .. +} + +nxp() { + echo -e "[${blue}Downloading NXP Reader Library${NC}]" + wget http://www.nxp.com/redirect/explore-nfc-dev_latest -O nxp.zip + unzip -o nxp.zip + tar --overwrite -xzf neard-explorenfc_0.1.orig.tar.gz + cd neard-explorenfc-0.1 + + export WIRINGPI_CFLAGS=-I/usr/local/include + export WIRINGPI_LIBS=-L/usr/local/lib\ -lwiringPi + + echo -e "[${blue}Running bootstrap${NC}]" + ./bootstrap + + echo -e "[${blue}Configuring NXP Reader Library${NC}]" + ./configure --prefix=/usr --sysconfdir=/etc + + echo -e "[${blue}Building NXP Reader Library${NC}]" + cd nxprdlib + make +} + +all() { + prereq + neardal + wiringpi + nxp +} + +if [[ $# -eq 0 ]]; then + all +else + $@ +fi + diff --git a/setup.py b/setup.py index a7ab833..e2c7b9f 100644 --- a/setup.py +++ b/setup.py @@ -7,29 +7,20 @@ class build_nxppy(build): def run(self): - - startingDir = os.getcwd() - - os.chdir( os.path.join('NxpRdLib_PublicRelease', 'build') ) - def compile(): - call( r"sed -i 's/^blacklist spi-bcm2708/#&/' /etc/modprobe.d/raspi-blacklist.conf", shell=True ) - call( 'modprobe spi-bcm2708', shell=True ) - call( 'cmake .', shell=True ) - call( 'make', shell=True ) + call( './get_nxpRdLib.sh', shell=True ) self.execute(compile, [], 'compiling NxpRdLib') - os.chdir( startingDir ) - # Run the rest of the build build.run(self) nxppy = Extension('nxppy', sources = ['Mifare.c', 'nxppy.c'], - include_dirs = ['NxpRdLib_PublicRelease/types', 'NxpRdLib_PublicRelease/intfs', 'NxpRdLib_PublicRelease/comps/phpalSli15693/src/Sw'], + include_dirs = ['neard-explorenfc-0.1/nxprdlib/types', + 'neard-explorenfc-0.1/nxprdlib/intfs'], extra_compile_args=['-O1'], - extra_link_args=['NxpRdLib_PublicRelease/build/libnxprd.a'] + extra_link_args=['neard-explorenfc-0.1/nxprdlib/libnxprdlib.a', '-lwiringPi'] ) short_description = 'A python extension for interfacing with the NXP PN512 NFC Reader. Targeted specifically for Raspberry Pi and the EXPLORE-NFC module'