Adding initial API

pull/7822/head
Donatien Garnier 2018-08-03 17:28:31 +01:00
parent 9e012c3de6
commit 8d03c557e2
15 changed files with 724 additions and 0 deletions

View File

@ -0,0 +1,38 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_PN512_DRIVER_H
#define MBED_PN512_DRIVER_H
#include <stdint.h>
#include "nfc/NFCControllerDriver.h"
namespace mbed {
struct PN512TransportDriver;
class PN512Driver : NFCControllerDriver {
public:
PN512Driver(PN512TransportDriver* transport_driver);
private:
virtual void initialize(scheduler_timer_t* pTimer) = 0;
virtual transceiver_t* get_transceiver() const;
pn512_t _pn512;
};
} // namespace mbed
#endif

View File

@ -0,0 +1,52 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_PN512_TRANSPORT_DRIVER_H
#define MBED_PN512_TRANSPORT_DRIVER_H
#include <stdint.h>
#include "platform/platform.h"
#include "PN512TransportDriver.h"
namespace mbed {
namespace nfc {
class PN512SPITransportDriver {
public:
PN512SPITransportDriver(PinName mosi, PinName miso, PinName sclk, PinName ssel, PinName irq);
private:
virtual void initialize();
virtual nfc_transport_t* get_transport() const;
void transport_write( uint8_t address, const uint8_t* outBuf, size_t outLen );
void transport_read( uint8_t address, uint8_t* inBuf, size_t inLen );
// Callbacks from munfc
static void s_transport_write( uint8_t address, const uint8_t* outBuf, size_t outLen, void* pUser );
static void s_transport_read( uint8_t address, uint8_t* inBuf, size_t inLen, void* pUser );
nfc_transport_t _nfc_transport;
SPI _spi;
InterruptIn _irq;
};
} // namespace nfc
} // namespace mbed
#endif

View File

@ -0,0 +1,35 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_PN512_TRANSPORT_DRIVER_H
#define MBED_PN512_TRANSPORT_DRIVER_H
#include <stdint.h>
#include "stack/platform/nfc_transport.h"
namespace mbed {
namespace nfc {
struct PN512TransportDriver {
virtual void initialize() = 0;
virtual nfc_transport_t* get_transport() const = 0;
};
} // namespace nfc
} // namespace mbed
#endif

View File

@ -0,0 +1,72 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_ISO7816_APP_H
#define MBED_ISO7816_APP_H
#include <stdint.h>
#include <stddef.h>
#include "NFCDefinitions.h"
namespace mbed {
namespace nfc {
class ISO7816App {
class Exchange {
public:
struct CAPDU
{
uint8_t cla;
uint8_t ins;
uint8_t p1;
uint8_t p2;
ac_buffer_t dataIn;
size_t maxRespLength;
};
struct RAPDU
{
ac_buffer_t dataOut;
uint16_t sw;
};
const CAPDU& command() const;
RAPDU& response();
nfc_err_t respond();
private:
Command _command;
Response _response;
ISO7816Application* _app;
};
struct Delegate {
virtual void on_selected() {}
virtual void on_deselected() {}
virtual void on_exchange(Exchange* exchange) {}
};
void set_delegate(Delegate* delegate);
};
} // namespace nfc
} // namespace mbed
#endif

31
features/nfc/nfc/NFC.h Normal file
View File

@ -0,0 +1,31 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_NFC_H
#define MBED_NFC_H
// Convenience header
// NFC Controller
#include "NFCController.h"
// NFC EEPROM
#include "NFCEEPROM.h"
// ISO7816 App
#include "ISO7816App.h"
#endif

View File

@ -0,0 +1,68 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_NFC_CONTROLLER_H
#define MBED_NFC_CONTROLLER_H
#include <stdint.h>
#include "events/EventQueue.h"
#include "NFCDefinitions.h"
namespace mbed {
namespace nfc {
class NFCRemoteInitiator;
class NFCRemoteTarget;
class NFCControllerDriver;
class NFCController {
public:
struct Delegate {
enum nfc_discovery_terminated_reason_t {
nfc_discovery_terminated_completed = 0,
nfc_discovery_terminated_canceled,
nfc_discovery_terminated_rf_error
};
virtual void on_discovery_terminated(nfc_discovery_terminated_reason_t reason) {}
virtual void on_nfc_initiator_discovered(const NFCRemoteInitiator& nfc_initiator) {}
virtual void on_nfc_target_discovered(const NFCRemoteTarget& nfc_target) {}
};
NFCController(NFCControllerDriver* driver, events::EventQueue* queue);
void set_delegate(Delegate* delegate);
nfc_rf_protocols_bitmask_t get_supported_rf_protocols() const;
nfc_err_t configure_rf_protocols(nfc_rf_protocols_bitmask_t rf_protocols);
nfc_err_t start_discovery();
nfc_err_t cancel_discovery();
private:
NFCControllerDriver* _driver;
Delegate* _delegate;
};
} // namespace nfc
} // namespace mbed
#endif

View File

@ -0,0 +1,38 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_NFC_CONTROLLER_DRIVER_H
#define MBED_NFC_CONTROLLER_DRIVER_H
#include <stdint.h>
#include "events/EventQueue.h"
#include "stack/nfc_errors.h"
#include "stack/transceiver/transceiver.h"
#include "stack/platform/scheduler.h"
namespace mbed {
namespace nfc {
struct NFCControllerDriver {
virtual void initialize(scheduler_timer_t* pTimer) = 0;
virtual transceiver_t* get_transceiver() const = 0;
};
} // namespace nfc
} // namespace mbed
#endif

View File

@ -0,0 +1,47 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_NFC_DEFINITIONS_H
#define MBED_NFC_DEFINITIONS_H
#include <stdint.h>
#include "stack/nfc_errors.h"
#include "acore/buffer.h"
namespace mbed {
namespace nfc {
struct nfc_rf_protocols_bitmask_t
{
uint8_t initiator_t1t : 1;
uint8_t initiator_t2t : 1;
uint8_t initiator_t3t : 1;
uint8_t initiator_iso_dep : 1;
uint8_t initiator_nfc_dep : 1;
uint8_t initiator_t5t : 1;
uint8_t target_t1t : 1;
uint8_t target_t2t : 1;
uint8_t target_t3t : 1;
uint8_t target_iso_dep : 1;
uint8_t target_nfc_dep : 1;
uint8_t target_t5t : 1;
};
} // namespace nfc
} // namespace mbed
#endif

View File

@ -0,0 +1,43 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_NFC_EEPROM_H
#define MBED_NFC_EEPROM_H
#include <stdint.h>
#include "NFCDefinitions.h"
#include "NFCTarget.h"
#include "NFCEEPROMDriver.h"
namespace mbed {
namespace nfc {
class NFCEEPROM : public NFCTarget {
public:
NFCEEPROM();
virtual ~NFCTarget();
struct Delegate : NFCTarget::Delegate {
};
void set_delegate(Delegate* delegate);
};
} // namespace nfc
} // namespace mbed
#endif

View File

@ -0,0 +1,63 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_NFC_EEPROM_DRIVER_H
#define MBED_NFC_EEPROM_DRIVER_H
#include <stdint.h>
#include "NFCDefinitions.h"
#include "NFCTarget.h"
#include "NFCEEPROMDriver.h"
namespace mbed {
namespace nfc {
class NFCEEPROMDriver {
public:
NFCEEPROMDriver();
struct Delegate {
virtual void has_read_bytes(bool success, const uint8_t* bytes) = 0;
virtual void has_written_bytes(bool success) = 0;
virtual void has_set_size(bool success) = 0;
virtual void has_gotten_size(bool success, size_t size) = 0;
virtual void has_erased_bytes(bool success) = 0;
};
void set_delegate(Delegate* delegate);
virtual void reset() = 0;
virtual size_t get_max_size() = 0;
virtual void start_session() = 0; // This could lock the chip i
virtual void end_session() = 0;
virtual void read_bytes(uint32_t address, size_t count) = 0;
virtual void write_bytes(uint32_t address, const uint8_t* bytes, size_t count) = 0;
virtual void set_size(size_t count) = 0;
virtual void get_size() = 0;
virtual void erase_bytes(uint32_t address, size_t size) = 0;
protected:
Delegate* delegate();
private:
Delegate* _delegate;
};
} // namespace nfc
} // namespace mbed
#endif

View File

@ -0,0 +1,39 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_NFC_ENDPOINT_H
#define MBED_NFC_ENDPOINT_H
#include <stdint.h>
#include "NFCDefinitions.h"
namespace mbed {
namespace nfc {
class NFCEndpoint {
public:
struct Delegate {
virtual void on_lost() {};
};
bool is_lost() const;
nfc_rf_protocols_bitmask_t rf_protocols() const;
};
} // namespace nfc
} // namespace mbed
#endif

View File

@ -0,0 +1,52 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_NFC_NDEF_CAPABLE_H
#define MBED_NFC_NDEF_CAPABLE_H
#include <stdint.h>
#include "NFCDefinitions.h"
namespace mbed {
namespace nfc {
class NFCNDEFCapable {
public:
bool is_ndef_supported() const;
void set_enable_remote_ndef_reads(bool enable);
void set_enable_remote_ndef_writes(bool enable);
void set_ndef_message_parser(ndef::MessageParser* parser) const;
void set_ndef_message_builder(ndef::MessageBuilder* builder) const;
protected:
void set_ndef_support(bool supported);
bool are_remote_ndef_reads_enabled();
bool are_remote_ndef_writes_enabled();
ndef::MessageParser* ndef_message_parser() const;
ndef::MessageBuilder* ndef_message_builder() const;
private:
ndef::MessageParser* _message_parser;
ndef::MessageBuilder* _message_builder;
};
} // namespace nfc
} // namespace mbed
#endif

View File

@ -0,0 +1,50 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_NFC_REMOTE_INITIATOR_H
#define MBED_NFC_REMOTE_INITIATOR_H
#include <stdint.h>
#include "NFCDefinitions.h"
#include "NFCEndpoint.h"
#include "NFCNDEFCapable.h"
namespace mbed {
namespace nfc {
class NFCRemoteInitiator : public NFCEndpoint, public NFCNDEFCapable {
public:
NFCRemoteInitiator();
virtual ~NFCRemoteInitiator();
struct Delegate : NFCEndpoint::Delegate {
virtual void on_selected() {}
virtual void on_deselected() {}
virtual void on_before_ndef_message_read() {}
virtual void on_after_ndef_message_write() {}
};
void set_delegate(Delegate* delegate);
bool is_iso7816_supported();
void add_iso7816_application(ISO7816App* application);
};
} // namespace nfc
} // namespace mbed
#endif

View File

@ -0,0 +1,50 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_NFC_TARGET_H
#define MBED_NFC_TARGET_H
#include <stdint.h>
#include "NFCDefinitions.h"
#include "NFCEndpoint.h"
#include "NFCNDEFCapable.h"
namespace mbed {
namespace nfc {
class NFCTarget : public NFCEndpoint, public NFCNDEFCapable {
public:
NFCTarget();
virtual ~NFCTarget();
struct Delegate {
virtual void on_ndef_message_erased(nfc_err_t result) {}
virtual void on_ndef_message_written(nfc_err_t result) {}
virtual void on_ndef_message_read(nfc_err_t result) {}
};
void set_delegate(Delegate* delegate);
void write_ndef_message();
void read_ndef_message();
void erase_ndef_message();
};
} // namespace nfc
} // namespace mbed
#endif

View File

@ -0,0 +1,46 @@
/* mbed Microcontroller Library
* Copyright (c) 2018 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_TYPE4_TAG_APP_H
#define MBED_TYPE4_TAG_APP_H
#include <stdint.h>
#include <stddef.h>
#include "IOS7816App.h"
#include "NFCNDEFCapable.h"
#include "acore/buffer.h"
namespace mbed {
namespace nfc {
class Type4TagApp : public ISO7816App, private ISO7816App::Delegate, public NFCNDEFCapable {
public:
struct Delegate {
virtual void on_selected() {}
virtual void on_deselected() {}
virtual void on_exchange(uint8_t cla, uint8_t ins, uint8_t p1, uint8_t p2,
ac_buffer_t* command, size_t max_response_sz) {}
};
};
} // namespace nfc
} // namespace mbed
#endif