Add portable NFC module
This commit is contained in:
85
nfc/include/nfc_platform.h
Normal file
85
nfc/include/nfc_platform.h
Normal file
@@ -0,0 +1,85 @@
|
||||
#ifndef PORTABLE_NFC_PLATFORM_H
|
||||
#define PORTABLE_NFC_PLATFORM_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define NFC_PLATFORM_WAIT_FOREVER 0xFFFFFFFFu
|
||||
|
||||
typedef void *nfc_platform_sem_t;
|
||||
typedef void *nfc_platform_task_t;
|
||||
typedef void (*nfc_platform_irq_handler_t)(void *arg);
|
||||
typedef void (*nfc_platform_task_entry_t)(void *arg);
|
||||
|
||||
typedef enum {
|
||||
NFC_PLATFORM_GPIO_IN = 0,
|
||||
NFC_PLATFORM_GPIO_OUT = 1,
|
||||
} nfc_platform_gpio_direction_t;
|
||||
|
||||
typedef enum {
|
||||
NFC_PLATFORM_GPIO_PULL_DISABLE = 0,
|
||||
NFC_PLATFORM_GPIO_PULL_UP = 1,
|
||||
NFC_PLATFORM_GPIO_PULL_DOWN = 2,
|
||||
} nfc_platform_gpio_pull_t;
|
||||
|
||||
typedef enum {
|
||||
NFC_PLATFORM_GPIO_LOW = 0,
|
||||
NFC_PLATFORM_GPIO_HIGH = 1,
|
||||
} nfc_platform_gpio_level_t;
|
||||
|
||||
typedef enum {
|
||||
NFC_PLATFORM_IRQ_NONE = 0,
|
||||
NFC_PLATFORM_IRQ_RISING_EDGE = 1,
|
||||
NFC_PLATFORM_IRQ_FALLING_EDGE = 2,
|
||||
NFC_PLATFORM_IRQ_BOTH_EDGE = 3,
|
||||
} nfc_platform_irq_edge_t;
|
||||
|
||||
void nfc_platform_log(const char *fmt, ...);
|
||||
void nfc_platform_sleep_ms(uint32_t ms);
|
||||
|
||||
int nfc_platform_i2c_init(uint8_t bus, uint32_t fast_mode);
|
||||
int nfc_platform_i2c_write(uint8_t bus,
|
||||
uint8_t slave_addr,
|
||||
uint16_t reg,
|
||||
const uint8_t *data,
|
||||
uint32_t len);
|
||||
int nfc_platform_i2c_read(uint8_t bus,
|
||||
uint8_t slave_addr,
|
||||
uint16_t reg,
|
||||
uint8_t *data,
|
||||
uint32_t len);
|
||||
|
||||
int nfc_platform_gpio_init(uint32_t pin,
|
||||
nfc_platform_gpio_direction_t direction,
|
||||
nfc_platform_gpio_pull_t pull,
|
||||
nfc_platform_gpio_level_t initial_level);
|
||||
int nfc_platform_gpio_set_level(uint32_t pin, nfc_platform_gpio_level_t level);
|
||||
int nfc_platform_gpio_get_level(uint32_t pin, uint8_t *level);
|
||||
|
||||
int nfc_platform_irq_register(uint32_t pin,
|
||||
nfc_platform_irq_edge_t edge,
|
||||
nfc_platform_gpio_pull_t pull,
|
||||
void *arg,
|
||||
nfc_platform_irq_handler_t handler);
|
||||
int nfc_platform_irq_enable_wakeup(uint32_t pin, nfc_platform_irq_edge_t edge);
|
||||
int nfc_platform_irq_disable_wakeup(uint32_t pin);
|
||||
|
||||
int nfc_platform_sem_create(nfc_platform_sem_t *sem, uint32_t initial_count);
|
||||
int nfc_platform_sem_wait(nfc_platform_sem_t sem, uint32_t timeout_ms);
|
||||
int nfc_platform_sem_release(nfc_platform_sem_t sem);
|
||||
|
||||
int nfc_platform_task_create(nfc_platform_task_t *task,
|
||||
uint32_t stack_size,
|
||||
uint32_t priority,
|
||||
const char *name,
|
||||
nfc_platform_task_entry_t entry,
|
||||
void *arg);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
63
nfc/include/nfc_service.h
Normal file
63
nfc/include/nfc_service.h
Normal file
@@ -0,0 +1,63 @@
|
||||
#ifndef PORTABLE_NFC_SERVICE_H
|
||||
#define PORTABLE_NFC_SERVICE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define NFC_UID_MAX_BYTES 10
|
||||
#define NFC_UID_STRING_MAX_LEN ((NFC_UID_MAX_BYTES * 2) + 1)
|
||||
|
||||
typedef enum {
|
||||
NFC_STATUS_OK = 0,
|
||||
NFC_STATUS_ERROR = -1,
|
||||
NFC_STATUS_BAD_PARAM = -2,
|
||||
NFC_STATUS_NOT_INITIALIZED = -3,
|
||||
NFC_STATUS_ALREADY_STARTED = -4,
|
||||
} nfc_status_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t bytes[NFC_UID_MAX_BYTES];
|
||||
uint8_t length;
|
||||
char value[NFC_UID_STRING_MAX_LEN];
|
||||
} nfc_uid_t;
|
||||
|
||||
typedef int (*nfc_can_poll_fn)(void *ctx);
|
||||
typedef void (*nfc_uid_fn)(const nfc_uid_t *uid, void *ctx);
|
||||
typedef void (*nfc_error_fn)(int status, void *ctx);
|
||||
|
||||
typedef struct {
|
||||
nfc_can_poll_fn can_poll;
|
||||
nfc_uid_fn on_uid;
|
||||
nfc_error_fn on_error;
|
||||
void *ctx;
|
||||
} nfc_service_callbacks_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t i2c_bus;
|
||||
uint8_t i2c_fast_mode;
|
||||
uint8_t i2c_slave_addr;
|
||||
uint32_t reset_pin;
|
||||
uint32_t irq_pin;
|
||||
uint32_t task_stack_size;
|
||||
uint32_t task_priority;
|
||||
uint32_t debounce_ms;
|
||||
uint32_t disallowed_poll_delay_ms;
|
||||
uint32_t retry_poll_delay_ms;
|
||||
uint8_t max_fail_count;
|
||||
} nfc_service_config_t;
|
||||
|
||||
void nfc_service_default_config(nfc_service_config_t *config);
|
||||
int nfc_service_init(const nfc_service_config_t *config,
|
||||
const nfc_service_callbacks_t *callbacks);
|
||||
int nfc_service_start(void);
|
||||
int nfc_service_stop(void);
|
||||
int nfc_service_is_started(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user