remove wrong V2 Firmware

This commit is contained in:
André Fiedler 2025-02-12 08:27:31 +01:00
parent 615dd58d85
commit 0f51245914
93 changed files with 0 additions and 103919 deletions

View File

@ -1,102 +0,0 @@
.config
*.o
*.pyc
# gtags
GTAGS
GRTAGS
GPATH
# emacs
.dir-locals.el
# emacs temp file suffixes
*~
.#*
\#*#
# eclipse setting
.settings
# MacOS directory files
.DS_Store
# cache dir
.cache/
# Components Unit Test Apps files
components/**/build/
components/**/build_*_*/
components/**/sdkconfig
components/**/sdkconfig.old
# Example project files
examples/**/build/
examples/**/build_esp*_*/
examples/**/sdkconfig
examples/**/sdkconfig.old
# Doc build artifacts
docs/_build/
docs/doxygen_sqlite3.db
# Downloaded font files
docs/_static/DejaVuSans.ttf
docs/_static/NotoSansSC-Regular.otf
# Unit test app files
tools/unit-test-app/sdkconfig
tools/unit-test-app/sdkconfig.old
tools/unit-test-app/build
tools/unit-test-app/build_*_*/
tools/unit-test-app/output
tools/unit-test-app/test_configs
# Unit Test CMake compile log folder
log_ut_cmake
# test application build files
tools/test_apps/**/build/
tools/test_apps/**/build_*_*/
tools/test_apps/**/sdkconfig
tools/test_apps/**/sdkconfig.old
# IDF monitor test
tools/test_idf_monitor/outputs
TEST_LOGS
# gcov coverage reports
*.gcda
*.gcno
coverage.info
coverage_report/
test_multi_heap_host
# VS Code Settings
.vscode/
# VIM files
*.swp
*.swo
# Clion IDE CMake build & config
.idea/
cmake-build-*/
# Results for the checking of the Python coding style and static analysis
.mypy_cache
flake8_output.txt
# ESP-IDF default build directory name
build
# lock files for examples and components
dependencies.lock
# managed_components for examples
managed_components
# pytest log
pytest_embedded_log/

View File

@ -1,9 +0,0 @@
# For more information about build system see
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
# The following five lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.5)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(fab-reader2-c)

View File

@ -1,2 +0,0 @@
idf_component_register(SRCS "EPD_2in66.c" "Config/DEV_Config.c"
INCLUDE_DIRS "include" "include/Config")

View File

@ -1,70 +0,0 @@
/*****************************************************************************
* | File : DEV_Config.c
* | Author : Waveshare team
* | Function : Hardware underlying interface
* | Info :
* Used to shield the underlying layers of each master
* and enhance portability
*----------------
* | This version: V2.0
* | Date : 2018-10-30
* | Info :
# ******************************************************************************
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
******************************************************************************/
#include "DEV_Config.h"
#include <esp_err.h>
#include <driver/spi_master.h>
#include <memory.h>
spi_device_handle_t pSpi;
void DEV_SPI_Init(spi_device_handle_t spi) {
pSpi = spi;
}
void DEV_SPI_WriteByte(UBYTE value)
{
spi_transaction_t t;
memset(&t, 0, sizeof(t));
t.length = 8;
t.tx_buffer = &value;
ESP_ERROR_CHECK(spi_device_polling_transmit(pSpi, &t));
}
int DEV_Module_Init(void)
{
DEV_Digital_Write(EPD_DC_PIN, 0);
DEV_Digital_Write(EPD_CS_PIN, 0);
DEV_Digital_Write(EPD_RST_PIN, 1);
return 0;
}
void DEV_Module_Exit(void)
{
DEV_Digital_Write(EPD_DC_PIN, 0);
DEV_Digital_Write(EPD_CS_PIN, 0);
//close 5V
DEV_Digital_Write(EPD_RST_PIN, 0);
}

View File

@ -1,259 +0,0 @@
/*****************************************************************************
* | File : EPD_2in66.c
* | Author : Waveshare team
* | Function : 2.66inch e-paper
* | Info :
*----------------
* | This version: V1.0
* | Date : 2020-07-29
* | Info :
* -----------------------------------------------------------------------------
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
******************************************************************************/
#include "EPD_2in66.h"
#include "Debug.h"
const unsigned char WF_PARTIAL[159] ={
0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x40,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x0A,0x00,0x00,0x00,0x00,0x00,0x02,0x01,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x22,0x22,0x22,0x22,0x22,0x22,
0x00,0x00,0x00,0x22,0x17,0x41,0xB0,0x32,0x36,
};
/******************************************************************************
function : Software reset
parameter:
******************************************************************************/
static void EPD_2IN66_Reset(void)
{
DEV_Digital_Write(EPD_RST_PIN, 1);
DEV_Delay_ms(200);
DEV_Digital_Write(EPD_RST_PIN, 0);
DEV_Delay_ms(2);
DEV_Digital_Write(EPD_RST_PIN, 1);
DEV_Delay_ms(200);
}
/******************************************************************************
function : send command
parameter:
Reg : Command register
******************************************************************************/
static void EPD_2IN66_SendCommand(UBYTE Reg)
{
DEV_Digital_Write(EPD_DC_PIN, 0);
DEV_Digital_Write(EPD_CS_PIN, 0);
DEV_SPI_WriteByte(Reg);
DEV_Digital_Write(EPD_CS_PIN, 1);
}
/******************************************************************************
function : send data
parameter:
Data : Write data
******************************************************************************/
static void EPD_2IN66_SendData(UBYTE Data)
{
DEV_Digital_Write(EPD_DC_PIN, 1);
DEV_Digital_Write(EPD_CS_PIN, 0);
DEV_SPI_WriteByte(Data);
DEV_Digital_Write(EPD_CS_PIN, 1);
}
/******************************************************************************
function : Wait until the busy_pin goes LOW
parameter:
******************************************************************************/
void EPD_2IN66_ReadBusy(void)
{
Debug("e-Paper busy\r\n");
DEV_Delay_ms(100);
while(DEV_Digital_Read(EPD_BUSY_PIN) == 1) { //LOW: idle, HIGH: busy
DEV_Delay_ms(100);
}
DEV_Delay_ms(100);
Debug("e-Paper busy release\r\n");
}
/******************************************************************************
function : Turn On Display
parameter:
******************************************************************************/
static void EPD_2IN66_TurnOnDisplay(void)
{
EPD_2IN66_SendCommand(0x20);
EPD_2IN66_ReadBusy();
}
/******************************************************************************
function : Send LUT
parameter:
******************************************************************************/
static void EPD_2IN66_SetLUA(void)
{
UWORD count;
EPD_2IN66_SendCommand(0x32);
for(count=0;count<153;count++){
EPD_2IN66_SendData(WF_PARTIAL[count]);
}
EPD_2IN66_ReadBusy();
}
/******************************************************************************
function : Initialize the e-Paper register
parameter:
******************************************************************************/
void EPD_2IN66_Init(void)
{
EPD_2IN66_Reset();
EPD_2IN66_ReadBusy();
EPD_2IN66_SendCommand(0x12);//soft reset
EPD_2IN66_ReadBusy();
/* Y increment, X increment */
EPD_2IN66_SendCommand(0x11);
EPD_2IN66_SendData(0x03);
/* Set RamX-address Start/End position */
EPD_2IN66_SendCommand(0x44);
EPD_2IN66_SendData(0x01);
EPD_2IN66_SendData((EPD_2IN66_WIDTH % 8 == 0)? (EPD_2IN66_WIDTH / 8 ): (EPD_2IN66_WIDTH / 8 + 1) );
/* Set RamY-address Start/End position */
EPD_2IN66_SendCommand(0x45);
EPD_2IN66_SendData(0);
EPD_2IN66_SendData(0);
EPD_2IN66_SendData((EPD_2IN66_HEIGHT&0xff));
EPD_2IN66_SendData((EPD_2IN66_HEIGHT&0x100)>>8);
EPD_2IN66_ReadBusy();
}
/******************************************************************************
function : Initialize the e-Paper register(Partial display)
parameter:
******************************************************************************/
void EPD_2IN66_Init_Partial(void)
{
EPD_2IN66_Reset();
EPD_2IN66_ReadBusy();
EPD_2IN66_SendCommand(0x12);//soft reset
EPD_2IN66_ReadBusy();
EPD_2IN66_SetLUA();
EPD_2IN66_SendCommand(0x37);
EPD_2IN66_SendData(0x00);
EPD_2IN66_SendData(0x00);
EPD_2IN66_SendData(0x00);
EPD_2IN66_SendData(0x00);
EPD_2IN66_SendData(0x00);
EPD_2IN66_SendData(0x40);
EPD_2IN66_SendData(0x00);
EPD_2IN66_SendData(0x00);
EPD_2IN66_SendData(0x00);
EPD_2IN66_SendData(0x00);
/* Y increment, X increment */
EPD_2IN66_SendCommand(0x11);
EPD_2IN66_SendData(0x03);
/* Set RamX-address Start/End position */
EPD_2IN66_SendCommand(0x44);
EPD_2IN66_SendData(0x01);
EPD_2IN66_SendData((EPD_2IN66_WIDTH % 8 == 0)? (EPD_2IN66_WIDTH / 8 ): (EPD_2IN66_WIDTH / 8 + 1) );
/* Set RamY-address Start/End position */
EPD_2IN66_SendCommand(0x45);
EPD_2IN66_SendData(0);
EPD_2IN66_SendData(0);
EPD_2IN66_SendData((EPD_2IN66_HEIGHT&0xff));
EPD_2IN66_SendData((EPD_2IN66_HEIGHT&0x100)>>8);
EPD_2IN66_SendCommand(0x3C);
EPD_2IN66_SendData(0x80);
EPD_2IN66_SendCommand(0x22);
EPD_2IN66_SendData(0xcf);
EPD_2IN66_SendCommand(0x20);
EPD_2IN66_ReadBusy();
}
/******************************************************************************
function : Clear screen
parameter:
******************************************************************************/
void EPD_2IN66_Clear(void)
{
UWORD Width, Height;
Width = (EPD_2IN66_WIDTH % 8 == 0)? (EPD_2IN66_WIDTH / 8 ): (EPD_2IN66_WIDTH / 8 + 1);
Height = EPD_2IN66_HEIGHT;
EPD_2IN66_SendCommand(0x24);
for (UWORD j = 0; j <=Height; j++) {
for (UWORD i = 0; i < Width; i++) {
EPD_2IN66_SendData(0xff);
}
}
EPD_2IN66_TurnOnDisplay();
}
/******************************************************************************
function : Sends the image buffer in RAM to e-Paper and displays
parameter:
******************************************************************************/
void EPD_2IN66_Display(UBYTE *Image)
{
UWORD Width, Height;
Width = (EPD_2IN66_WIDTH % 8 == 0)? (EPD_2IN66_WIDTH / 8 ): (EPD_2IN66_WIDTH / 8 + 1);
Height = EPD_2IN66_HEIGHT;
UDOUBLE Addr = 0;
// UDOUBLE Offset = ImageName;
EPD_2IN66_SendCommand(0x24);
for (UWORD j = 0; j <Height; j++) {
for (UWORD i = 0; i <Width; i++) {
Addr = i + j * Width;
EPD_2IN66_SendData(Image[Addr]);
}
}
EPD_2IN66_TurnOnDisplay();
}
/******************************************************************************
function : Enter sleep mode
parameter:
******************************************************************************/
void EPD_2IN66_Sleep(void)
{
EPD_2IN66_SendCommand(0x10);
EPD_2IN66_SendData(0x01);
//EPD_2IN66_ReadBusy();
}

View File

@ -1,94 +0,0 @@
/*****************************************************************************
* | File : DEV_Config.h
* | Author : Waveshare team
* | Function : Hardware underlying interface
* | Info :
* Used to shield the underlying layers of each master
* and enhance portability
*----------------
* | This version: V2.0
* | Date : 2018-10-30
* | Info :
* 1.add:
* UBYTE\UWORD\UDOUBLE
* 2.Change:
* EPD_RST -> EPD_RST_PIN
* EPD_DC -> EPD_DC_PIN
* EPD_CS -> EPD_CS_PIN
* EPD_BUSY -> EPD_BUSY_PIN
* 3.Remote:
* EPD_RST_1\EPD_RST_0
* EPD_DC_1\EPD_DC_0
* EPD_CS_1\EPD_CS_0
* EPD_BUSY_1\EPD_BUSY_0
* 3.add:
* #define DEV_Digital_Write(_pin, _value) bcm2835_gpio_write(_pin, _value)
* #define DEV_Digital_Read(_pin) bcm2835_gpio_lev(_pin)
* #define DEV_SPI_WriteByte(__value) bcm2835_spi_transfer(__value)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
******************************************************************************/
#ifndef _DEV_CONFIG_H_
#define _DEV_CONFIG_H_
#include "esp_err.h"
#include "driver/gpio.h"
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <stdint.h>
#include <stdio.h>
#include <driver/spi_master.h>
/**
* data
**/
#define UBYTE uint8_t
#define UWORD uint16_t
#define UDOUBLE uint32_t
/**
* e-Paper GPIO
**/
#define EPD_RST_PIN 40
#define EPD_DC_PIN 39
#define EPD_CS_PIN 38
#define EPD_BUSY_PIN 41
/**
* GPIO read and write
**/
#define DEV_Digital_Write(_pin, _value) ESP_ERROR_CHECK(gpio_set_level(_pin, _value))
#define DEV_Digital_Read(_pin) gpio_get_level(_pin)
/**
* delay x ms
**/
#define DEV_Delay_ms(__xms) vTaskDelay(pdMS_TO_TICKS(__xms))
/**
* SPI
**/
void DEV_SPI_Init(spi_device_handle_t spi);
void DEV_SPI_WriteByte(UBYTE value);
int DEV_Module_Init(void);
void DEV_Module_Exit(void);
#endif

View File

@ -1,26 +0,0 @@
/*****************************************************************************
* | File : Debug.h
* | Author : Waveshare team
* | Function : debug with printf
* | Info :
* Image scanning
* Please use progressive scanning to generate images or fonts
*----------------
* | This version: V1.0
* | Date : 2018-01-11
* | Info : Basic version
*
******************************************************************************/
#ifndef __DEBUG_H
#define __DEBUG_H
#include <esp_log.h>
#define DEBUG 1
#if DEBUG
#define Debug(...) ESP_LOGD("EPD", __VA_ARGS__)
#else
#define Debug(__info,...)
#endif
#endif

View File

@ -1,46 +0,0 @@
/*****************************************************************************
* | File : EPD_2in66.h
* | Author : Waveshare team
* | Function : 2.66inch e-paper
* | Info :
*----------------
* | This version: V1.0
* | Date : 2020-07-29
* | Info :
* -----------------------------------------------------------------------------
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
******************************************************************************/
#ifndef __EPD_2IN66_H_
#define __EPD_2IN66_H_
#include "DEV_Config.h"
// Display resolution
#define EPD_2IN66_WIDTH 152
#define EPD_2IN66_HEIGHT 296
void EPD_2IN66_Init(void);
void EPD_2IN66_Init_Partial(void);
void EPD_2IN66_Clear(void);
void EPD_2IN66_Display(UBYTE *Image);
void EPD_2IN66_Sleep(void);
#endif

View File

@ -1,3 +0,0 @@
idf_component_register(SRCS "GUI/GUI_Paint.c" "Fonts/font8.c" "Fonts/font12.c" "Fonts/font16.c" "Fonts/font20.c" "Fonts/font24.c"
INCLUDE_DIRS "include/GUI" "include/Fonts"
REQUIRES "epd_266")

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,890 +0,0 @@
/******************************************************************************
* | File : GUI_Paint.c
* | Author : Waveshare electronics
* | Function : Achieve drawing: draw points, lines, boxes, circles and
* their size, solid dotted line, solid rectangle hollow
* rectangle, solid circle hollow circle.
* | Info :
* Achieve display characters: Display a single character, string, number
* Achieve time display: adaptive size display time minutes and seconds
*----------------
* | This version: V3.1
* | Date : 2020-07-08
* | Info :
* -----------------------------------------------------------------------------
* V3.1(2020-07-08):
* 1.Change: Paint_SetScale(UBYTE scale)
* Add scale 7 for 5.65f e-Parper
* 2.Change: Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color)
* Add the branch for scale 7
* 3.Change: Paint_Clear(UWORD Color)
* Add the branch for scale 7
*
* -----------------------------------------------------------------------------
* V3.0(2019-04-18):
* 1.Change:
* Paint_DrawPoint(..., DOT_STYLE DOT_STYLE)
* => Paint_DrawPoint(..., DOT_STYLE Dot_Style)
* Paint_DrawLine(..., LINE_STYLE Line_Style, DOT_PIXEL Dot_Pixel)
* => Paint_DrawLine(..., DOT_PIXEL Line_width, LINE_STYLE Line_Style)
* Paint_DrawRectangle(..., DRAW_FILL Filled, DOT_PIXEL Dot_Pixel)
* => Paint_DrawRectangle(..., DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
* Paint_DrawCircle(..., DRAW_FILL Draw_Fill, DOT_PIXEL Dot_Pixel)
* => Paint_DrawCircle(..., DOT_PIXEL Line_width, DRAW_FILL Draw_Filll)
*
* -----------------------------------------------------------------------------
* V2.0(2018-11-15):
* 1.add: Paint_NewImage()
* Create an image's properties
* 2.add: Paint_SelectImage()
* Select the picture to be drawn
* 3.add: Paint_SetRotate()
* Set the direction of the cache
* 4.add: Paint_RotateImage()
* Can flip the picture, Support 0-360 degrees,
* but only 90.180.270 rotation is better
* 4.add: Paint_SetMirroring()
* Can Mirroring the picture, horizontal, vertical, origin
* 5.add: Paint_DrawString_CN()
* Can display Chinese(GB1312)
*
* -----------------------------------------------------------------------------
* V1.0(2018-07-17):
* Create library
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documnetation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
******************************************************************************/
#include "GUI_Paint.h"
#include "DEV_Config.h"
#include "Debug.h"
#include <stdint.h>
#include <stdlib.h>
#include <string.h> //memset()
#include <math.h>
PAINT Paint;
/******************************************************************************
function: Create Image
parameter:
image : Pointer to the image cache
width : The width of the picture
Height : The height of the picture
Color : Whether the picture is inverted
******************************************************************************/
void Paint_NewImage(UBYTE *image, UWORD Width, UWORD Height, UWORD Rotate, UWORD Color)
{
Paint.Image = NULL;
Paint.Image = image;
Paint.WidthMemory = Width;
Paint.HeightMemory = Height;
Paint.Color = Color;
Paint.Scale = 2;
Paint.WidthByte = (Width % 8 == 0)? (Width / 8 ): (Width / 8 + 1);
Paint.HeightByte = Height;
// printf("WidthByte = %d, HeightByte = %d\r\n", Paint.WidthByte, Paint.HeightByte);
// printf(" EPD_WIDTH / 8 = %d\r\n", 122 / 8);
Paint.Rotate = Rotate;
Paint.Mirror = MIRROR_NONE;
if(Rotate == ROTATE_0 || Rotate == ROTATE_180) {
Paint.Width = Width;
Paint.Height = Height;
} else {
Paint.Width = Height;
Paint.Height = Width;
}
}
/******************************************************************************
function: Select Image
parameter:
image : Pointer to the image cache
******************************************************************************/
void Paint_SelectImage(UBYTE *image)
{
Paint.Image = image;
}
/******************************************************************************
function: Select Image Rotate
parameter:
Rotate : 0,90,180,270
******************************************************************************/
void Paint_SetRotate(UWORD Rotate)
{
if(Rotate == ROTATE_0 || Rotate == ROTATE_90 || Rotate == ROTATE_180 || Rotate == ROTATE_270) {
Debug("Set image Rotate %d\r\n", Rotate);
Paint.Rotate = Rotate;
} else {
Debug("rotate = 0, 90, 180, 270\r\n");
}
}
void Paint_SetScale(UBYTE scale)
{
if(scale == 2){
Paint.Scale = scale;
Paint.WidthByte = (Paint.WidthMemory % 8 == 0)? (Paint.WidthMemory / 8 ): (Paint.WidthMemory / 8 + 1);
}else if(scale == 4){
Paint.Scale = scale;
Paint.WidthByte = (Paint.WidthMemory % 4 == 0)? (Paint.WidthMemory / 4 ): (Paint.WidthMemory / 4 + 1);
}else if(scale == 7){//Only applicable with 5in65 e-Paper
Paint.Scale = scale;
Paint.WidthByte = (Paint.WidthMemory % 2 == 0)? (Paint.WidthMemory / 2 ): (Paint.WidthMemory / 2 + 1);;
}else{
Debug("Set Scale Input parameter error\r\n");
Debug("Scale Only support: 2 4 7\r\n");
}
}
/******************************************************************************
function: Select Image mirror
parameter:
mirror :Not mirror,Horizontal mirror,Vertical mirror,Origin mirror
******************************************************************************/
void Paint_SetMirroring(UBYTE mirror)
{
if(mirror == MIRROR_NONE || mirror == MIRROR_HORIZONTAL ||
mirror == MIRROR_VERTICAL || mirror == MIRROR_ORIGIN) {
Debug("mirror image x:%s, y:%s\r\n",(mirror & 0x01)? "mirror":"none", ((mirror >> 1) & 0x01)? "mirror":"none");
Paint.Mirror = mirror;
} else {
Debug("mirror should be MIRROR_NONE, MIRROR_HORIZONTAL, \
MIRROR_VERTICAL or MIRROR_ORIGIN\r\n");
}
}
/******************************************************************************
function: Draw Pixels
parameter:
Xpoint : At point X
Ypoint : At point Y
Color : Painted colors
******************************************************************************/
void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color)
{
if(Xpoint > Paint.Width || Ypoint > Paint.Height){
Debug("Exceeding display boundaries\r\n");
return;
}
UWORD X, Y;
switch(Paint.Rotate) {
case 0:
X = Xpoint;
Y = Ypoint;
break;
case 90:
X = Paint.WidthMemory - Ypoint - 1;
Y = Xpoint;
break;
case 180:
X = Paint.WidthMemory - Xpoint - 1;
Y = Paint.HeightMemory - Ypoint - 1;
break;
case 270:
X = Ypoint;
Y = Paint.HeightMemory - Xpoint - 1;
break;
default:
return;
}
switch(Paint.Mirror) {
case MIRROR_NONE:
break;
case MIRROR_HORIZONTAL:
X = Paint.WidthMemory - X - 1;
break;
case MIRROR_VERTICAL:
Y = Paint.HeightMemory - Y - 1;
break;
case MIRROR_ORIGIN:
X = Paint.WidthMemory - X - 1;
Y = Paint.HeightMemory - Y - 1;
break;
default:
return;
}
if(X > Paint.WidthMemory || Y > Paint.HeightMemory){
Debug("Exceeding display boundaries\r\n");
return;
}
if(Paint.Scale == 2){
UDOUBLE Addr = X / 8 + Y * Paint.WidthByte;
UBYTE Rdata = Paint.Image[Addr];
if(Color == BLACK)
Paint.Image[Addr] = Rdata & ~(0x80 >> (X % 8));
else
Paint.Image[Addr] = Rdata | (0x80 >> (X % 8));
}else if(Paint.Scale == 4){
UDOUBLE Addr = X / 4 + Y * Paint.WidthByte;
Color = Color % 4;//Guaranteed color scale is 4 --- 0~3
UBYTE Rdata = Paint.Image[Addr];
Rdata = Rdata & (~(0xC0 >> ((X % 4)*2)));
Paint.Image[Addr] = Rdata | ((Color << 6) >> ((X % 4)*2));
}else if(Paint.Scale == 7){
UDOUBLE Addr = X / 2 + Y * Paint.WidthByte;
UBYTE Rdata = Paint.Image[Addr];
Rdata = Rdata & (~(0xF0 >> ((X % 2)*4)));//Clear first, then set value
Paint.Image[Addr] = Rdata | ((Color << 4) >> ((X % 2)*4));
//printf("Add = %d ,data = %d\r\n",Addr,Rdata);
}
}
/******************************************************************************
function: Clear the color of the picture
parameter:
Color : Painted colors
******************************************************************************/
void Paint_Clear(UWORD Color)
{
if(Paint.Scale == 2) {
for (UWORD Y = 0; Y < Paint.HeightByte; Y++) {
for (UWORD X = 0; X < Paint.WidthByte; X++ ) {//8 pixel = 1 byte
UDOUBLE Addr = X + Y*Paint.WidthByte;
Paint.Image[Addr] = Color;
}
}
}else if(Paint.Scale == 4) {
for (UWORD Y = 0; Y < Paint.HeightByte; Y++) {
for (UWORD X = 0; X < Paint.WidthByte; X++ ) {
UDOUBLE Addr = X + Y*Paint.WidthByte;
Paint.Image[Addr] = (Color<<6)|(Color<<4)|(Color<<2)|Color;
}
}
}else if(Paint.Scale == 7) {
for (UWORD Y = 0; Y < Paint.HeightByte; Y++) {
for (UWORD X = 0; X < Paint.WidthByte; X++ ) {
UDOUBLE Addr = X + Y*Paint.WidthByte;
Paint.Image[Addr] = (Color<<4)|Color;
}
}
}
}
/******************************************************************************
function: Clear the color of a window
parameter:
Xstart : x starting point
Ystart : Y starting point
Xend : x end point
Yend : y end point
Color : Painted colors
******************************************************************************/
void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color)
{
UWORD X, Y;
for (Y = Ystart; Y < Yend; Y++) {
for (X = Xstart; X < Xend; X++) {//8 pixel = 1 byte
Paint_SetPixel(X, Y, Color);
}
}
}
/******************************************************************************
function: Draw Point(Xpoint, Ypoint) Fill the color
parameter:
Xpoint : The Xpoint coordinate of the point
Ypoint : The Ypoint coordinate of the point
Color : Painted color
Dot_Pixel : point size
Dot_Style : point Style
******************************************************************************/
void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color,
DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_Style)
{
if (Xpoint > Paint.Width || Ypoint > Paint.Height) {
Debug("Paint_DrawPoint Input exceeds the normal display range\r\n");
printf("Xpoint = %d , Paint.Width = %d \r\n ",Xpoint,Paint.Width);
printf("Ypoint = %d , Paint.Height = %d \r\n ",Ypoint,Paint.Height);
return;
}
int16_t XDir_Num , YDir_Num;
if (Dot_Style == DOT_FILL_AROUND) {
for (XDir_Num = 0; XDir_Num < 2 * Dot_Pixel - 1; XDir_Num++) {
for (YDir_Num = 0; YDir_Num < 2 * Dot_Pixel - 1; YDir_Num++) {
if(Xpoint + XDir_Num - Dot_Pixel < 0 || Ypoint + YDir_Num - Dot_Pixel < 0)
break;
// printf("x = %d, y = %d\r\n", Xpoint + XDir_Num - Dot_Pixel, Ypoint + YDir_Num - Dot_Pixel);
Paint_SetPixel(Xpoint + XDir_Num - Dot_Pixel, Ypoint + YDir_Num - Dot_Pixel, Color);
}
}
} else {
for (XDir_Num = 0; XDir_Num < Dot_Pixel; XDir_Num++) {
for (YDir_Num = 0; YDir_Num < Dot_Pixel; YDir_Num++) {
Paint_SetPixel(Xpoint + XDir_Num - 1, Ypoint + YDir_Num - 1, Color);
}
}
}
}
/******************************************************************************
function: Draw a line of arbitrary slope
parameter:
Xstart Starting Xpoint point coordinates
Ystart Starting Xpoint point coordinates
Xend End point Xpoint coordinate
Yend End point Ypoint coordinate
Color The color of the line segment
Line_width : Line width
Line_Style: Solid and dotted lines
******************************************************************************/
void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend,
UWORD Color, DOT_PIXEL Line_width, LINE_STYLE Line_Style)
{
if (Xstart > Paint.Width || Ystart > Paint.Height ||
Xend > Paint.Width || Yend > Paint.Height) {
Debug("Paint_DrawLine Input exceeds the normal display range\r\n");
return;
}
UWORD Xpoint = Xstart;
UWORD Ypoint = Ystart;
int dx = (int)Xend - (int)Xstart >= 0 ? Xend - Xstart : Xstart - Xend;
int dy = (int)Yend - (int)Ystart <= 0 ? Yend - Ystart : Ystart - Yend;
// Increment direction, 1 is positive, -1 is counter;
int XAddway = Xstart < Xend ? 1 : -1;
int YAddway = Ystart < Yend ? 1 : -1;
//Cumulative error
int Esp = dx + dy;
char Dotted_Len = 0;
for (;;) {
Dotted_Len++;
//Painted dotted line, 2 point is really virtual
if (Line_Style == LINE_STYLE_DOTTED && Dotted_Len % 3 == 0) {
//Debug("LINE_DOTTED\r\n");
Paint_DrawPoint(Xpoint, Ypoint, IMAGE_BACKGROUND, Line_width, DOT_STYLE_DFT);
Dotted_Len = 0;
} else {
Paint_DrawPoint(Xpoint, Ypoint, Color, Line_width, DOT_STYLE_DFT);
}
if (2 * Esp >= dy) {
if (Xpoint == Xend)
break;
Esp += dy;
Xpoint += XAddway;
}
if (2 * Esp <= dx) {
if (Ypoint == Yend)
break;
Esp += dx;
Ypoint += YAddway;
}
}
}
/******************************************************************************
function: Draw a rectangle
parameter:
Xstart Rectangular Starting Xpoint point coordinates
Ystart Rectangular Starting Xpoint point coordinates
Xend Rectangular End point Xpoint coordinate
Yend Rectangular End point Ypoint coordinate
Color The color of the Rectangular segment
Line_width: Line width
Draw_Fill : Whether to fill the inside of the rectangle
******************************************************************************/
void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend,
UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
{
if (Xstart > Paint.Width || Ystart > Paint.Height ||
Xend > Paint.Width || Yend > Paint.Height) {
Debug("Input exceeds the normal display range\r\n");
return;
}
if (Draw_Fill) {
UWORD Ypoint;
for(Ypoint = Ystart; Ypoint < Yend; Ypoint++) {
Paint_DrawLine(Xstart, Ypoint, Xend, Ypoint, Color , Line_width, LINE_STYLE_SOLID);
}
} else {
Paint_DrawLine(Xstart, Ystart, Xend, Ystart, Color, Line_width, LINE_STYLE_SOLID);
Paint_DrawLine(Xstart, Ystart, Xstart, Yend, Color, Line_width, LINE_STYLE_SOLID);
Paint_DrawLine(Xend, Yend, Xend, Ystart, Color, Line_width, LINE_STYLE_SOLID);
Paint_DrawLine(Xend, Yend, Xstart, Yend, Color, Line_width, LINE_STYLE_SOLID);
}
}
/******************************************************************************
function: Use the 8-point method to draw a circle of the
specified size at the specified position->
parameter:
X_Center Center X coordinate
Y_Center Center Y coordinate
Radius circle Radius
Color The color of the circle segment
Line_width: Line width
Draw_Fill : Whether to fill the inside of the Circle
******************************************************************************/
void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius,
UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
{
if (X_Center > Paint.Width || Y_Center >= Paint.Height) {
Debug("Paint_DrawCircle Input exceeds the normal display range\r\n");
return;
}
//Draw a circle from(0, R) as a starting point
int16_t XCurrent, YCurrent;
XCurrent = 0;
YCurrent = Radius;
//Cumulative error,judge the next point of the logo
int16_t Esp = 3 - (Radius << 1 );
int16_t sCountY;
if (Draw_Fill == DRAW_FILL_FULL) {
while (XCurrent <= YCurrent ) { //Realistic circles
for (sCountY = XCurrent; sCountY <= YCurrent; sCountY ++ ) {
Paint_DrawPoint(X_Center + XCurrent, Y_Center + sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//1
Paint_DrawPoint(X_Center - XCurrent, Y_Center + sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//2
Paint_DrawPoint(X_Center - sCountY, Y_Center + XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//3
Paint_DrawPoint(X_Center - sCountY, Y_Center - XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//4
Paint_DrawPoint(X_Center - XCurrent, Y_Center - sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//5
Paint_DrawPoint(X_Center + XCurrent, Y_Center - sCountY, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//6
Paint_DrawPoint(X_Center + sCountY, Y_Center - XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);//7
Paint_DrawPoint(X_Center + sCountY, Y_Center + XCurrent, Color, DOT_PIXEL_DFT, DOT_STYLE_DFT);
}
if (Esp < 0 )
Esp += 4 * XCurrent + 6;
else {
Esp += 10 + 4 * (XCurrent - YCurrent );
YCurrent --;
}
XCurrent ++;
}
} else { //Draw a hollow circle
while (XCurrent <= YCurrent ) {
Paint_DrawPoint(X_Center + XCurrent, Y_Center + YCurrent, Color, Line_width, DOT_STYLE_DFT);//1
Paint_DrawPoint(X_Center - XCurrent, Y_Center + YCurrent, Color, Line_width, DOT_STYLE_DFT);//2
Paint_DrawPoint(X_Center - YCurrent, Y_Center + XCurrent, Color, Line_width, DOT_STYLE_DFT);//3
Paint_DrawPoint(X_Center - YCurrent, Y_Center - XCurrent, Color, Line_width, DOT_STYLE_DFT);//4
Paint_DrawPoint(X_Center - XCurrent, Y_Center - YCurrent, Color, Line_width, DOT_STYLE_DFT);//5
Paint_DrawPoint(X_Center + XCurrent, Y_Center - YCurrent, Color, Line_width, DOT_STYLE_DFT);//6
Paint_DrawPoint(X_Center + YCurrent, Y_Center - XCurrent, Color, Line_width, DOT_STYLE_DFT);//7
Paint_DrawPoint(X_Center + YCurrent, Y_Center + XCurrent, Color, Line_width, DOT_STYLE_DFT);//0
if (Esp < 0 )
Esp += 4 * XCurrent + 6;
else {
Esp += 10 + 4 * (XCurrent - YCurrent );
YCurrent --;
}
XCurrent ++;
}
}
}
/******************************************************************************
function: Show English characters
parameter:
Xpoint X coordinate
Ypoint Y coordinate
Acsii_Char To display the English characters
Font A structure pointer that displays a character size
Color_Foreground : Select the foreground color
Color_Background : Select the background color
******************************************************************************/
void Paint_DrawChar(UWORD Xpoint, UWORD Ypoint, const char Acsii_Char,
sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)
{
UWORD Page, Column;
if (Xpoint > Paint.Width || Ypoint > Paint.Height) {
Debug("Paint_DrawChar Input exceeds the normal display range\r\n");
return;
}
uint32_t Char_Offset = (Acsii_Char - ' ') * Font->Height * (Font->Width / 8 + (Font->Width % 8 ? 1 : 0));
const unsigned char *ptr = &Font->table[Char_Offset];
for (Page = 0; Page < Font->Height; Page ++ ) {
for (Column = 0; Column < Font->Width; Column ++ ) {
//To determine whether the font background color and screen background color is consistent
if (FONT_BACKGROUND == Color_Background) { //this process is to speed up the scan
if (*ptr & (0x80 >> (Column % 8)))
Paint_SetPixel(Xpoint + Column, Ypoint + Page, Color_Foreground);
// Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
} else {
if (*ptr & (0x80 >> (Column % 8))) {
Paint_SetPixel(Xpoint + Column, Ypoint + Page, Color_Foreground);
// Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
} else {
Paint_SetPixel(Xpoint + Column, Ypoint + Page, Color_Background);
// Paint_DrawPoint(Xpoint + Column, Ypoint + Page, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT);
}
}
//One pixel is 8 bits
if (Column % 8 == 7)
ptr++;
}// Write a line
if (Font->Width % 8 != 0)
ptr++;
}// Write all
}
/******************************************************************************
function: Display the string
parameter:
Xstart X coordinate
Ystart Y coordinate
pString The first address of the English string to be displayed
Font A structure pointer that displays a character size
Color_Foreground : Select the foreground color
Color_Background : Select the background color
******************************************************************************/
void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString,
sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)
{
UWORD Xpoint = Xstart;
UWORD Ypoint = Ystart;
if (Xstart > Paint.Width || Ystart > Paint.Height) {
Debug("Paint_DrawString_EN Input exceeds the normal display range\r\n");
return;
}
while (* pString != '\0') {
//if X direction filled , reposition to(Xstart,Ypoint),Ypoint is Y direction plus the Height of the character
if ((Xpoint + Font->Width ) > Paint.Width ) {
Xpoint = Xstart;
Ypoint += Font->Height;
}
// If the Y direction is full, reposition to(Xstart, Ystart)
if ((Ypoint + Font->Height ) > Paint.Height ) {
Xpoint = Xstart;
Ypoint = Ystart;
}
Paint_DrawChar(Xpoint, Ypoint, * pString, Font, Color_Background, Color_Foreground);
//The next character of the address
pString ++;
//The next word of the abscissa increases the font of the broadband
Xpoint += Font->Width;
}
}
/******************************************************************************
function: Display the string
parameter:
Xstart X coordinate
Ystart Y coordinate
pString The first address of the Chinese string and English
string to be displayed
Font A structure pointer that displays a character size
Color_Foreground : Select the foreground color
Color_Background : Select the background color
******************************************************************************/
void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font,
UWORD Color_Foreground, UWORD Color_Background)
{
const char* p_text = pString;
int x = Xstart, y = Ystart;
int i, j,Num;
/* Send the string character by character on EPD */
while (*p_text != 0) {
if(*p_text <= 0x7F) { //ASCII < 126
for(Num = 0; Num < font->size; Num++) {
if(*p_text== font->table[Num].index[0]) {
const char* ptr = &font->table[Num].matrix[0];
for (j = 0; j < font->Height; j++) {
for (i = 0; i < font->Width; i++) {
if (FONT_BACKGROUND == Color_Background) { //this process is to speed up the scan
if (*ptr & (0x80 >> (i % 8))) {
Paint_SetPixel(x + i, y + j, Color_Foreground);
// Paint_DrawPoint(x + i, y + j, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
}
} else {
if (*ptr & (0x80 >> (i % 8))) {
Paint_SetPixel(x + i, y + j, Color_Foreground);
// Paint_DrawPoint(x + i, y + j, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
} else {
Paint_SetPixel(x + i, y + j, Color_Background);
// Paint_DrawPoint(x + i, y + j, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT);
}
}
if (i % 8 == 7) {
ptr++;
}
}
if (font->Width % 8 != 0) {
ptr++;
}
}
break;
}
}
/* Point on the next character */
p_text += 1;
/* Decrement the column position by 16 */
x += font->ASCII_Width;
} else { //Chinese
for(Num = 0; Num < font->size; Num++) {
if((*p_text== font->table[Num].index[0]) && (*(p_text+1) == font->table[Num].index[1])) {
const char* ptr = &font->table[Num].matrix[0];
for (j = 0; j < font->Height; j++) {
for (i = 0; i < font->Width; i++) {
if (FONT_BACKGROUND == Color_Background) { //this process is to speed up the scan
if (*ptr & (0x80 >> (i % 8))) {
Paint_SetPixel(x + i, y + j, Color_Foreground);
// Paint_DrawPoint(x + i, y + j, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
}
} else {
if (*ptr & (0x80 >> (i % 8))) {
Paint_SetPixel(x + i, y + j, Color_Foreground);
// Paint_DrawPoint(x + i, y + j, Color_Foreground, DOT_PIXEL_DFT, DOT_STYLE_DFT);
} else {
Paint_SetPixel(x + i, y + j, Color_Background);
// Paint_DrawPoint(x + i, y + j, Color_Background, DOT_PIXEL_DFT, DOT_STYLE_DFT);
}
}
if (i % 8 == 7) {
ptr++;
}
}
if (font->Width % 8 != 0) {
ptr++;
}
}
break;
}
}
/* Point on the next character */
p_text += 2;
/* Decrement the column position by 16 */
x += font->Width;
}
}
}
/******************************************************************************
function: Display nummber
parameter:
Xstart X coordinate
Ystart : Y coordinate
Nummber : The number displayed
Font A structure pointer that displays a character size
Color_Foreground : Select the foreground color
Color_Background : Select the background color
******************************************************************************/
#define ARRAY_LEN 255
void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, int32_t Nummber,
sFONT* Font, UWORD Color_Foreground, UWORD Color_Background)
{
int16_t Num_Bit = 0, Str_Bit = 0;
uint8_t Str_Array[ARRAY_LEN] = {0}, Num_Array[ARRAY_LEN] = {0};
uint8_t *pStr = Str_Array;
if (Xpoint > Paint.Width || Ypoint > Paint.Height) {
Debug("Paint_DisNum Input exceeds the normal display range\r\n");
return;
}
//Converts a number to a string
do {
Num_Array[Num_Bit] = Nummber % 10 + '0';
Num_Bit++;
Nummber /= 10;
} while(Nummber);
//The string is inverted
while (Num_Bit > 0) {
Str_Array[Str_Bit] = Num_Array[Num_Bit - 1];
Str_Bit ++;
Num_Bit --;
}
//show
Paint_DrawString_EN(Xpoint, Ypoint, (const char*)pStr, Font, Color_Background, Color_Foreground);
}
/******************************************************************************
function: Display nummber (Able to display decimals)
parameter:
Xstart X coordinate
Ystart : Y coordinate
Nummber : The number displayed
Font A structure pointer that displays a character size
Digit : Fractional width
Color_Foreground : Select the foreground color
Color_Background : Select the background color
******************************************************************************/
void Paint_DrawNumDecimals(UWORD Xpoint, UWORD Ypoint, double Nummber,
sFONT* Font, UWORD Digit, UWORD Color_Foreground, UWORD Color_Background)
{
int16_t Num_Bit = 0, Str_Bit = 0;
uint8_t Str_Array[ARRAY_LEN] = {0}, Num_Array[ARRAY_LEN] = {0};
uint8_t *pStr = Str_Array;
int temp = Nummber;
float decimals;
uint8_t i;
if (Xpoint > Paint.Width || Ypoint > Paint.Height) {
Debug("Paint_DisNum Input exceeds the normal display range\r\n");
return;
}
if(Digit > 0) {
decimals = Nummber - temp;
for(i=Digit; i > 0; i--) {
decimals*=10;
}
temp = decimals;
//Converts a number to a string
for(i=Digit; i>0; i--) {
Num_Array[Num_Bit] = temp % 10 + '0';
Num_Bit++;
temp /= 10;
}
Num_Array[Num_Bit] = '.';
Num_Bit++;
}
temp = Nummber;
//Converts a number to a string
do {
Num_Array[Num_Bit] = temp % 10 + '0';
Num_Bit++;
temp /= 10;
} while(temp);
//The string is inverted
while (Num_Bit > 0) {
Str_Array[Str_Bit] = Num_Array[Num_Bit - 1];
Str_Bit ++;
Num_Bit --;
}
//show
Paint_DrawString_EN(Xpoint, Ypoint, (const char*)pStr, Font, Color_Background, Color_Foreground);
}
/******************************************************************************
function: Display time
parameter:
Xstart X coordinate
Ystart : Y coordinate
pTime : Time-related structures
Font A structure pointer that displays a character size
Color_Foreground : Select the foreground color
Color_Background : Select the background color
******************************************************************************/
void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font,
UWORD Color_Foreground, UWORD Color_Background)
{
uint8_t value[10] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
UWORD Dx = Font->Width;
//Write data into the cache
Paint_DrawChar(Xstart , Ystart, value[pTime->Hour / 10], Font, Color_Background, Color_Foreground);
Paint_DrawChar(Xstart + Dx , Ystart, value[pTime->Hour % 10], Font, Color_Background, Color_Foreground);
Paint_DrawChar(Xstart + Dx + Dx / 4 + Dx / 2 , Ystart, ':' , Font, Color_Background, Color_Foreground);
Paint_DrawChar(Xstart + Dx * 2 + Dx / 2 , Ystart, value[pTime->Min / 10] , Font, Color_Background, Color_Foreground);
Paint_DrawChar(Xstart + Dx * 3 + Dx / 2 , Ystart, value[pTime->Min % 10] , Font, Color_Background, Color_Foreground);
Paint_DrawChar(Xstart + Dx * 4 + Dx / 2 - Dx / 4, Ystart, ':' , Font, Color_Background, Color_Foreground);
Paint_DrawChar(Xstart + Dx * 5 , Ystart, value[pTime->Sec / 10] , Font, Color_Background, Color_Foreground);
Paint_DrawChar(Xstart + Dx * 6 , Ystart, value[pTime->Sec % 10] , Font, Color_Background, Color_Foreground);
}
/******************************************************************************
function: Display monochrome bitmap
parameter:
image_buffer A picture data converted to a bitmap
info:
Use a computer to convert the image into a corresponding array,
and then embed the array directly into Imagedata.cpp as a .c file.
******************************************************************************/
void Paint_DrawBitMap(const unsigned char* image_buffer)
{
UWORD x, y;
UDOUBLE Addr = 0;
for (y = 0; y < Paint.HeightByte; y++) {
for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
Addr = x + y * Paint.WidthByte;
Paint.Image[Addr] = (unsigned char)image_buffer[Addr];
}
}
}
/******************************************************************************
function: paste monochrome bitmap to a frame buff
parameter:
image_buffer A picture data converted to a bitmap
xStart: The starting x coordinate
yStart: The starting y coordinate
imageWidth: Original image width
imageHeight: Original image height
flipColor: Whether the color is reversed
info:
Use this function to paste image data into a buffer
******************************************************************************/
void Paint_DrawBitMap_Paste(const unsigned char* image_buffer, UWORD xStart, UWORD yStart, UWORD imageWidth, UWORD imageHeight, UBYTE flipColor)
{
UBYTE color, srcImage;
UWORD x, y;
UWORD width = (imageWidth%8==0 ? imageWidth/8 : imageWidth/8+1);
for (y = 0; y < imageHeight; y++) {
for (x = 0; x < imageWidth; x++) {
srcImage = image_buffer[y*width + x/8];
if(flipColor)
color = (((srcImage<<(x%8) & 0x80) == 0) ? 1 : 0);
else
color = (((srcImage<<(x%8) & 0x80) == 0) ? 0 : 1);
Paint_SetPixel(x+xStart, y+yStart, color);
}
}
}
void Paint_DrawBitMap_Block(const unsigned char* image_buffer, UBYTE Region)
{
UWORD x, y;
UDOUBLE Addr = 0;
for (y = 0; y < Paint.HeightByte; y++) {
for (x = 0; x < Paint.WidthByte; x++) {//8 pixel = 1 byte
Addr = x + y * Paint.WidthByte ;
Paint.Image[Addr] = \
(unsigned char)image_buffer[Addr+ (Paint.HeightByte)*Paint.WidthByte*(Region - 1)];
}
}
}

View File

@ -1,95 +0,0 @@
/**
******************************************************************************
* @file fonts.h
* @author MCD Application Team
* @version V1.0.0
* @date 18-February-2014
* @brief Header for fonts.c file
******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of STMicroelectronics nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __FONTS_H
#define __FONTS_H
/*<2A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>΢<EFBFBD><CEA2><EFBFBD>ź<EFBFBD>24 (32x41) */
#define MAX_HEIGHT_FONT 41
#define MAX_WIDTH_FONT 32
#define OFFSET_BITMAP
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include <stdint.h>
//ASCII
typedef struct _tFont
{
const uint8_t *table;
uint16_t Width;
uint16_t Height;
} sFONT;
//GB2312
typedef struct // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD><C4A3><EFBFBD>ݽṹ
{
unsigned char index[2]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
const char matrix[MAX_HEIGHT_FONT*MAX_WIDTH_FONT/8]; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
}CH_CN;
typedef struct
{
const CH_CN *table;
uint16_t size;
uint16_t ASCII_Width;
uint16_t Width;
uint16_t Height;
}cFONT;
extern sFONT Font24;
extern sFONT Font20;
extern sFONT Font16;
extern sFONT Font12;
extern sFONT Font8;
#ifdef __cplusplus
}
#endif
#endif /* __FONTS_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -1,218 +0,0 @@
/******************************************************************************
* | File : GUI_Paint.h
* | Author : Waveshare electronics
* | Function : Achieve drawing: draw points, lines, boxes, circles and
* their size, solid dotted line, solid rectangle hollow
* rectangle, solid circle hollow circle.
* | Info :
* Achieve display characters: Display a single character, string, number
* Achieve time display: adaptive size display time minutes and seconds
*----------------
* | This version: V3.0
* | Date : 2019-04-18
* | Info :
* -----------------------------------------------------------------------------
* V3.0(2019-04-18):
* 1.Change:
* Paint_DrawPoint(..., DOT_STYLE DOT_STYLE)
* => Paint_DrawPoint(..., DOT_STYLE Dot_Style)
* Paint_DrawLine(..., LINE_STYLE Line_Style, DOT_PIXEL Dot_Pixel)
* => Paint_DrawLine(..., DOT_PIXEL Line_width, LINE_STYLE Line_Style)
* Paint_DrawRectangle(..., DRAW_FILL Filled, DOT_PIXEL Dot_Pixel)
* => Paint_DrawRectangle(..., DOT_PIXEL Line_width, DRAW_FILL Draw_Fill)
* Paint_DrawCircle(..., DRAW_FILL Draw_Fill, DOT_PIXEL Dot_Pixel)
* => Paint_DrawCircle(..., DOT_PIXEL Line_width, DRAW_FILL Draw_Filll)
*
* -----------------------------------------------------------------------------
* V2.0(2018-11-15):
* 1.add: Paint_NewImage()
* Create an image's properties
* 2.add: Paint_SelectImage()
* Select the picture to be drawn
* 3.add: Paint_SetRotate()
* Set the direction of the cache
* 4.add: Paint_RotateImage()
* Can flip the picture, Support 0-360 degrees,
* but only 90.180.270 rotation is better
* 4.add: Paint_SetMirroring()
* Can Mirroring the picture, horizontal, vertical, origin
* 5.add: Paint_DrawString_CN()
* Can display Chinese(GB1312)
*
* -----------------------------------------------------------------------------
* V1.0(2018-07-17):
* Create library
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documnetation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
******************************************************************************/
#ifndef __GUI_PAINT_H
#define __GUI_PAINT_H
#include "DEV_Config.h"
#include "../Fonts/fonts.h"
/**
* Image attributes
**/
typedef struct {
UBYTE *Image;
UWORD Width;
UWORD Height;
UWORD WidthMemory;
UWORD HeightMemory;
UWORD Color;
UWORD Rotate;
UWORD Mirror;
UWORD WidthByte;
UWORD HeightByte;
UWORD Scale;
} PAINT;
extern PAINT Paint;
/**
* Display rotate
**/
#define ROTATE_0 0
#define ROTATE_90 90
#define ROTATE_180 180
#define ROTATE_270 270
/**
* Display Flip
**/
typedef enum {
MIRROR_NONE = 0x00,
MIRROR_HORIZONTAL = 0x01,
MIRROR_VERTICAL = 0x02,
MIRROR_ORIGIN = 0x03,
} MIRROR_IMAGE;
#define MIRROR_IMAGE_DFT MIRROR_NONE
/**
* image color
**/
#define WHITE 0xFF
#define BLACK 0x00
#define RED BLACK
#define IMAGE_BACKGROUND WHITE
#define FONT_FOREGROUND BLACK
#define FONT_BACKGROUND WHITE
#define TRUE 1
#define FALSE 0
//4 Gray level
#define GRAY1 0x03 //Blackest
#define GRAY2 0x02
#define GRAY3 0x01 //gray
#define GRAY4 0x00 //white
/**
* The size of the point
**/
typedef enum {
DOT_PIXEL_1X1 = 1, // 1 x 1
DOT_PIXEL_2X2 , // 2 X 2
DOT_PIXEL_3X3 , // 3 X 3
DOT_PIXEL_4X4 , // 4 X 4
DOT_PIXEL_5X5 , // 5 X 5
DOT_PIXEL_6X6 , // 6 X 6
DOT_PIXEL_7X7 , // 7 X 7
DOT_PIXEL_8X8 , // 8 X 8
} DOT_PIXEL;
#define DOT_PIXEL_DFT DOT_PIXEL_1X1 //Default dot pilex
/**
* Point size fill style
**/
typedef enum {
DOT_FILL_AROUND = 1, // dot pixel 1 x 1
DOT_FILL_RIGHTUP , // dot pixel 2 X 2
} DOT_STYLE;
#define DOT_STYLE_DFT DOT_FILL_AROUND //Default dot pilex
/**
* Line style, solid or dashed
**/
typedef enum {
LINE_STYLE_SOLID = 0,
LINE_STYLE_DOTTED,
} LINE_STYLE;
/**
* Whether the graphic is filled
**/
typedef enum {
DRAW_FILL_EMPTY = 0,
DRAW_FILL_FULL,
} DRAW_FILL;
/**
* Custom structure of a time attribute
**/
typedef struct {
UWORD Year; //0000
UBYTE Month; //1 - 12
UBYTE Day; //1 - 30
UBYTE Hour; //0 - 23
UBYTE Min; //0 - 59
UBYTE Sec; //0 - 59
} PAINT_TIME;
extern PAINT_TIME sPaint_time;
//init and Clear
void Paint_NewImage(UBYTE *image, UWORD Width, UWORD Height, UWORD Rotate, UWORD Color);
void Paint_SelectImage(UBYTE *image);
void Paint_SetRotate(UWORD Rotate);
void Paint_SetMirroring(UBYTE mirror);
void Paint_SetPixel(UWORD Xpoint, UWORD Ypoint, UWORD Color);
void Paint_SetScale(UBYTE scale);
void Paint_Clear(UWORD Color);
void Paint_ClearWindows(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color);
//Drawing
void Paint_DrawPoint(UWORD Xpoint, UWORD Ypoint, UWORD Color, DOT_PIXEL Dot_Pixel, DOT_STYLE Dot_FillWay);
void Paint_DrawLine(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, DOT_PIXEL Line_width, LINE_STYLE Line_Style);
void Paint_DrawRectangle(UWORD Xstart, UWORD Ystart, UWORD Xend, UWORD Yend, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill);
void Paint_DrawCircle(UWORD X_Center, UWORD Y_Center, UWORD Radius, UWORD Color, DOT_PIXEL Line_width, DRAW_FILL Draw_Fill);
//Display string
void Paint_DrawChar(UWORD Xstart, UWORD Ystart, const char Acsii_Char, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background);
void Paint_DrawString_EN(UWORD Xstart, UWORD Ystart, const char * pString, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background);
void Paint_DrawString_CN(UWORD Xstart, UWORD Ystart, const char * pString, cFONT* font, UWORD Color_Foreground, UWORD Color_Background);
void Paint_DrawNum(UWORD Xpoint, UWORD Ypoint, int32_t Nummber, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background);
void Paint_DrawNumDecimals(UWORD Xpoint, UWORD Ypoint, double Nummber, sFONT* Font, UWORD Digit, UWORD Color_Foreground, UWORD Color_Background); // Able to display decimals
void Paint_DrawTime(UWORD Xstart, UWORD Ystart, PAINT_TIME *pTime, sFONT* Font, UWORD Color_Foreground, UWORD Color_Background);
//pic
void Paint_DrawBitMap(const unsigned char* image_buffer);
void Paint_DrawBitMap_Paste(const unsigned char* image_buffer, UWORD Xstart, UWORD Ystart, UWORD imageWidth, UWORD imageHeight, UBYTE flipColor);
//void Paint_DrawBitMap_Half(const unsigned char* image_buffer, UBYTE Region);
//void Paint_DrawBitMap_OneQuarter(const unsigned char* image_buffer, UBYTE Region);
//void Paint_DrawBitMap_OneEighth(const unsigned char* image_buffer, UBYTE Region);
void Paint_DrawBitMap_Block(const unsigned char* image_buffer, UBYTE Region);
#endif

View File

@ -1,14 +0,0 @@
idf_component_register(SRCS "Src/rfal_nfc.c"
"Src/rfal_analogConfig.c"
"Src/rfal_crc.c"
"Src/rfal_dpo.c"
"Src/rfal_iso15693_2.c"
"Src/rfal_isoDep.c"
"Src/rfal_nfca.c"
"Src/rfal_nfcb.c"
"Src/rfal_rfst25r3911.c"
"Src/rfal_t1t.c"
"Src/rfal_t2t.c"
"Src/rfal_t4t.c"
INCLUDE_DIRS "Inc"
REQUIRES "st25r3911")

View File

@ -1,334 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_AnalogConfig.h
*
* \author bkam
*
* \brief RF Chip Analog Configuration Settings
*
*
* \addtogroup RFAL
* @{
*
* \addtogroup RFAL-HAL
* \brief RFAL Hardware Abstraction Layer
* @{
*
* \addtogroup AnalogConfig
* \brief RFAL Analog Config Module
* @{
*
*/
#ifndef RFAL_ANALOG_CONFIG_H
#define RFAL_ANALOG_CONFIG_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
#include "st_errno.h"
/*
******************************************************************************
* DEFINES
******************************************************************************
*/
#define RFAL_ANALOG_CONFIG_LUT_SIZE (87U) /*!< Maximum number of Configuration IDs in the Loop Up Table */
#define RFAL_ANALOG_CONFIG_LUT_NOT_FOUND (0xFFU) /*!< Index value indicating no Configuration IDs found */
#define RFAL_ANALOG_CONFIG_TBL_SIZE (1024U) /*!< Maximum number of Register-Mask-Value in the Setting List */
#define RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_MASK (0x8000U) /*!< Mask bit of Poll Mode in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_TECH_MASK (0x7F00U) /*!< Mask bits for Technology in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_BITRATE_MASK (0x00F0U) /*!< Mask bits for Bit rate in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_DIRECTION_MASK (0x0003U) /*!< Mask bits for Direction in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_CHIP_SPECIFIC_MASK (0x00FFU) /*!< Mask bits for Chip Specific Technology */
#define RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_SHIFT (15U) /*!< Shift value of Poll Mode in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_TECH_SHIFT (8U) /*!< Shift value for Technology in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_BITRATE_SHIFT (4U) /*!< Shift value for Technology in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_DIRECTION_SHIFT (0U) /*!< Shift value for Direction in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_POLL (0x0000U) /*!< Poll Mode bit setting in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_LISTEN (0x8000U) /*!< Listen Mode bit setting in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_TECH_CHIP (0x0000U) /*!< Chip-Specific bit setting in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_TECH_NFCA (0x0100U) /*!< NFC-A Technology bits setting in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_TECH_NFCB (0x0200U) /*!< NFC-B Technology bits setting in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_TECH_NFCF (0x0400U) /*!< NFC-F Technology bits setting in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_TECH_AP2P (0x0800U) /*!< AP2P Technology bits setting in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_TECH_NFCV (0x1000U) /*!< NFC-V Technology bits setting in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_TECH_RFU (0x2000U) /*!< RFU for Technology bits */
#define RFAL_ANALOG_CONFIG_BITRATE_COMMON (0x0000U) /*!< Common settings for all bit rates in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_BITRATE_106 (0x0010U) /*!< 106kbits/s settings in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_BITRATE_212 (0x0020U) /*!< 212kbits/s settings in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_BITRATE_424 (0x0030U) /*!< 424kbits/s settings in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_BITRATE_848 (0x0040U) /*!< 848kbits/s settings in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_BITRATE_1695 (0x0050U) /*!< 1695kbits/s settings in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_BITRATE_3390 (0x0060U) /*!< 3390kbits/s settings in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_BITRATE_6780 (0x0070U) /*!< 6780kbits/s settings in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_BITRATE_1OF4 (0x00C0U) /*!< 1 out of 4 for NFC-V setting in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_BITRATE_1OF256 (0x00D0U) /*!< 1 out of 256 for NFC-V setting in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_NO_DIRECTION (0x0000U) /*!< No direction setting in Analog Conf ID (Chip Specific only) */
#define RFAL_ANALOG_CONFIG_TX (0x0001U) /*!< Transmission bit setting in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_RX (0x0002U) /*!< Reception bit setting in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_ANTICOL (0x0003U) /*!< Anticollision setting in Analog Configuration ID */
#define RFAL_ANALOG_CONFIG_CHIP_INIT (0x0000U) /*!< Chip-Specific event: Startup;Reset;Initialize */
#define RFAL_ANALOG_CONFIG_CHIP_DEINIT (0x0001U) /*!< Chip-Specific event: Deinitialize */
#define RFAL_ANALOG_CONFIG_CHIP_FIELD_ON (0x0002U) /*!< Chip-Specific event: Field On */
#define RFAL_ANALOG_CONFIG_CHIP_FIELD_OFF (0x0003U) /*!< Chip-Specific event: Field Off */
#define RFAL_ANALOG_CONFIG_CHIP_WAKEUP_ON (0x0004U) /*!< Chip-Specific event: Wake-up On */
#define RFAL_ANALOG_CONFIG_CHIP_WAKEUP_OFF (0x0005U) /*!< Chip-Specific event: Wake-up Off */
#define RFAL_ANALOG_CONFIG_CHIP_LISTEN_ON (0x0006U) /*!< Chip-Specific event: Listen On */
#define RFAL_ANALOG_CONFIG_CHIP_LISTEN_OFF (0x0007U) /*!< Chip-Specific event: Listen Off */
#define RFAL_ANALOG_CONFIG_CHIP_POLL_COMMON (0x0008U) /*!< Chip-Specific event: Poll common */
#define RFAL_ANALOG_CONFIG_CHIP_LISTEN_COMMON (0x0009U) /*!< Chip-Specific event: Listen common */
#define RFAL_ANALOG_CONFIG_UPDATE_LAST (0x00U) /*!< Value indicating Last configuration set during update */
#define RFAL_ANALOG_CONFIG_UPDATE_MORE (0x01U) /*!< Value indicating More configuration set coming during update */
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
#define RFAL_ANALOG_CONFIG_ID_GET_POLL_LISTEN(id) (RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_MASK & (id)) /*!< Check if id indicates Listen mode */
#define RFAL_ANALOG_CONFIG_ID_GET_TECH(id) (RFAL_ANALOG_CONFIG_TECH_MASK & (id)) /*!< Get the technology of Configuration ID */
#define RFAL_ANALOG_CONFIG_ID_IS_CHIP(id) (RFAL_ANALOG_CONFIG_TECH_MASK & (id)) /*!< Check if ID indicates Chip-specific */
#define RFAL_ANALOG_CONFIG_ID_IS_NFCA(id) (RFAL_ANALOG_CONFIG_TECH_NFCA & (id)) /*!< Check if ID indicates NFC-A */
#define RFAL_ANALOG_CONFIG_ID_IS_NFCB(id) (RFAL_ANALOG_CONFIG_TECH_NFCB & (id)) /*!< Check if ID indicates NFC-B */
#define RFAL_ANALOG_CONFIG_ID_IS_NFCF(id) (RFAL_ANALOG_CONFIG_TECH_NFCF & (id)) /*!< Check if ID indicates NFC-F */
#define RFAL_ANALOG_CONFIG_ID_IS_AP2P(id) (RFAL_ANALOG_CONFIG_TECH_AP2P & (id)) /*!< Check if ID indicates AP2P */
#define RFAL_ANALOG_CONFIG_ID_IS_NFCV(id) (RFAL_ANALOG_CONFIG_TECH_NFCV & (id)) /*!< Check if ID indicates NFC-V */
#define RFAL_ANALOG_CONFIG_ID_GET_BITRATE(id) (RFAL_ANALOG_CONFIG_BITRATE_MASK & (id)) /*!< Get Bitrate of Configuration ID */
#define RFAL_ANALOG_CONFIG_ID_IS_COMMON(id) (RFAL_ANALOG_CONFIG_BITRATE_MASK & (id)) /*!< Check if ID indicates common bitrate */
#define RFAL_ANALOG_CONFIG_ID_IS_106(id) (RFAL_ANALOG_CONFIG_BITRATE_106 & (id)) /*!< Check if ID indicates 106kbits/s */
#define RFAL_ANALOG_CONFIG_ID_IS_212(id) (RFAL_ANALOG_CONFIG_BITRATE_212 & (id)) /*!< Check if ID indicates 212kbits/s */
#define RFAL_ANALOG_CONFIG_ID_IS_424(id) (RFAL_ANALOG_CONFIG_BITRATE_424 & (id)) /*!< Check if ID indicates 424kbits/s */
#define RFAL_ANALOG_CONFIG_ID_IS_848(id) (RFAL_ANALOG_CONFIG_BITRATE_848 & (id)) /*!< Check if ID indicates 848kbits/s */
#define RFAL_ANALOG_CONFIG_ID_IS_1695(id) (RFAL_ANALOG_CONFIG_BITRATE_1695 & (id)) /*!< Check if ID indicates 1695kbits/s */
#define RFAL_ANALOG_CONFIG_ID_IS_3390(id) (RFAL_ANALOG_CONFIG_BITRATE_3390 & (id)) /*!< Check if ID indicates 3390kbits/s */
#define RFAL_ANALOG_CONFIG_ID_IS_6780(id) (RFAL_ANALOG_CONFIG_BITRATE_6780 & (id)) /*!< Check if ID indicates 6780kbits/s */
#define RFAL_ANALOG_CONFIG_ID_IS_1OF4(id) (RFAL_ANALOG_CONFIG_BITRATE_1OF4 & (id)) /*!< Check if ID indicates 1 out of 4 bitrate */
#define RFAL_ANALOG_CONFIG_ID_IS_1OF256(id) (RFAL_ANALOG_CONFIG_BITRATE_1OF256 & (id)) /*!< Check if ID indicates 1 out of 256 bitrate */
#define RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(id) (RFAL_ANALOG_CONFIG_DIRECTION_MASK & (id)) /*!< Get Direction of Configuration ID */
#define RFAL_ANALOG_CONFIG_ID_IS_TX(id) (RFAL_ANALOG_CONFIG_TX & (id)) /*!< Check if id indicates TX */
#define RFAL_ANALOG_CONFIG_ID_IS_RX(id) (RFAL_ANALOG_CONFIG_RX & (id)) /*!< Check if id indicates RX */
#define RFAL_ANALOG_CONFIG_CONFIG_NUM(x) (sizeof(x)/sizeof((x)[0])) /*!< Get Analog Config number */
/*! Set Analog Config ID value by: Mode, Technology, Bitrate and Direction */
#define RFAL_ANALOG_CONFIG_ID_SET(mode, tech, br, direction) \
( RFAL_ANALOG_CONFIG_ID_GET_POLL_LISTEN(mode) \
| RFAL_ANALOG_CONFIG_ID_GET_TECH(tech) \
| RFAL_ANALOG_CONFIG_ID_GET_BITRATE(br) \
| RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(direction) \
)
/*
******************************************************************************
* GLOBAL DATA TYPES
******************************************************************************
*/
typedef uint8_t rfalAnalogConfigMode; /*!< Polling or Listening Mode of Configuration */
typedef uint8_t rfalAnalogConfigTech; /*!< Technology of Configuration */
typedef uint8_t rfalAnalogConfigBitrate; /*!< Bitrate of Configuration */
typedef uint8_t rfalAnalogConfigDirection; /*!< Transmit/Receive direction of Configuration */
typedef uint8_t rfalAnalogConfigRegAddr[2]; /*!< Register Address to ST Chip */
typedef uint8_t rfalAnalogConfigRegMask; /*!< Register Mask Value */
typedef uint8_t rfalAnalogConfigRegVal; /*!< Register Value */
typedef uint16_t rfalAnalogConfigId; /*!< Analog Configuration ID */
typedef uint16_t rfalAnalogConfigOffset; /*!< Analog Configuration offset address in the table */
typedef uint8_t rfalAnalogConfigNum; /*!< Number of Analog settings for the respective Configuration ID */
/*! Struct that contain the Register-Mask-Value set. Make sure that the whole structure size is even and unaligned! */
typedef struct {
rfalAnalogConfigRegAddr addr; /*!< Register Address */
rfalAnalogConfigRegMask mask; /*!< Register Mask Value */
rfalAnalogConfigRegVal val; /*!< Register Value */
} rfalAnalogConfigRegAddrMaskVal;
/*! Struct that represents the Analog Configs */
typedef struct {
uint8_t id[sizeof(rfalAnalogConfigId)]; /*!< Configuration ID */
rfalAnalogConfigNum num; /*!< Number of Config Sets to follow */
rfalAnalogConfigRegAddrMaskVal regSet[]; /*!< Register-Mask-Value sets */ /* PRQA S 1060 # MISRA 18.7 - Flexible Array Members are the only meaningful way of denoting a variable length input buffer which follows a fixed header structure. */
} rfalAnalogConfig;
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief Initialize the Analog Configuration
*
* Reset the Analog Configuration LUT pointer to reference to default settings.
*
*****************************************************************************
*/
void rfalAnalogConfigInitialize( void );
/*!
*****************************************************************************
* \brief Indicate if the current Analog Configuration Table is complete and ready to be used.
*
* \return true if current Analog Configuration Table is complete and ready to be used.
* \return false if current Analog Configuration Table is incomplete
*
*****************************************************************************
*/
bool rfalAnalogConfigIsReady( void );
/*!
*****************************************************************************
* \brief Write the whole Analog Configuration table in raw format
*
* Writes the Analog Configuration and Look Up Table with the given raw table
*
* NOTE: Function does not check the validity of the given Table contents
*
* \param[in] configTbl: location of config Table to be loaded
* \param[in] configTblSize: size of the config Table to be loaded
*
* \return ERR_NONE : if setting is updated
* \return ERR_PARAM : if configTbl is invalid
* \return ERR_NOMEM : if the given Table is bigger exceeds the max size
* \return ERR_REQUEST : if the update Configuration Id is disabled
*
*****************************************************************************
*/
ReturnCode rfalAnalogConfigListWriteRaw( const uint8_t *configTbl, uint16_t configTblSize );
/*!
*****************************************************************************
* \brief Write the Analog Configuration table with new analog settings.
*
* Writes the Analog Configuration and Look Up Table with the new list of register-mask-value
* and Configuration ID respectively.
*
* NOTE: Function does not check for the validity of the Register Address.
*
* \param[in] more: 0x00 indicates it is last Configuration ID settings;
* 0x01 indicates more Configuration ID setting(s) are coming.
* \param[in] *config: reference to the configuration list of current Configuraiton ID.
*
* \return ERR_PARAM : if Configuration ID or parameter is invalid
* \return ERR_NOMEM : if LUT is full
* \return ERR_REQUEST : if the update Configuration Id is disabled
* \return ERR_NONE : if setting is updated
*
*****************************************************************************
*/
ReturnCode rfalAnalogConfigListWrite( uint8_t more, const rfalAnalogConfig *config );
/*!
*****************************************************************************
* \brief Read the whole Analog Configuration table in raw format
*
* Reads the whole Analog Configuration Table in raw format
*
* \param[out] tblBuf: location to the buffer to place the Config Table
* \param[in] tblBufLen: length of the buffer to place the Config Table
* \param[out] configTblSize: Config Table size
*
* \return ERR_PARAM : if configTbl or configTblSize is invalid
* \return ERR_NOMEM : if configTblSize is not enough for the whole table
* \return ERR_NONE : if read is successful
*
*****************************************************************************
*/
ReturnCode rfalAnalogConfigListReadRaw( uint8_t *tblBuf, uint16_t tblBufLen, uint16_t *configTblSize );
/*!
*****************************************************************************
* \brief Read the Analog Configuration table.
*
* Read the Analog Configuration Table
*
* \param[in] configOffset: offset to the next Configuration ID in the List Table to be read.
* \param[out] more: 0x00 indicates it is last Configuration ID settings;
* 0x01 indicates more Configuration ID setting(s) are coming.
* \param[out] config: configuration id, number of configuration sets and register-mask-value sets
* \param[in] numConfig: the remaining configuration settings space available;
*
* \return ERR_NOMEM : if number of Configuration for respective Configuration ID is greater the the remaining configuration setting space available
* \return ERR_NONE : if read is successful
*
*****************************************************************************
*/
ReturnCode rfalAnalogConfigListRead( rfalAnalogConfigOffset *configOffset, uint8_t *more, rfalAnalogConfig *config, rfalAnalogConfigNum numConfig );
/*!
*****************************************************************************
* \brief Set the Analog settings of indicated Configuration ID.
*
* Update the chip with indicated analog settings of indicated Configuration ID.
*
* \param[in] configId: configuration ID
*
* \return ERR_PARAM if Configuration ID is invalid
* \return ERR_INTERNAL if error updating setting to chip
* \return ERR_NONE if new settings is applied to chip
*
*****************************************************************************
*/
ReturnCode rfalSetAnalogConfig( rfalAnalogConfigId configId );
#endif /* RFAL_ANALOG_CONFIG_H */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,426 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_analogConfig.h
*
* \author bkam
*
* \brief ST25R3911 Analog Configuration Settings
*
*/
#ifndef ST25R3911_ANALOGCONFIG_H
#define ST25R3911_ANALOGCONFIG_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "rfal_analogConfig.h"
#include "st25r3911_com.h"
/*
******************************************************************************
* DEFINES
******************************************************************************
*/
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
/*! Macro for Configuration Setting with only one register-mask-value set:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1] */
#define MODE_ENTRY_1_REG(MODE, R0, M0, V0) \
(uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU), 1, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0)
/*! Macro for Configuration Setting with only two register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1] */
#define MODE_ENTRY_2_REG(MODE, R0, M0, V0, R1, M1, V1) \
(uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU), 2, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1)
/*! Macro for Configuration Setting with only three register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_3_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2) \
(uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU), 3, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
/*! Macro for Configuration Setting with only four register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_4_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3) \
(uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU), 4, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
/*! Macro for Configuration Setting with only five register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_5_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4) \
(uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU), 5, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \
/*! Macro for Configuration Setting with only six register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_6_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5) \
(uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU), 6, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \
, (uint8_t)((R5) >> 8), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \
/*! Macro for Configuration Setting with only seven register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_7_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6) \
(uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU), 7, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \
, (uint8_t)((R5) >> 8), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \
, (uint8_t)((R6) >> 8), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \
/*! Macro for Configuration Setting with only eight register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_8_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7) \
(uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU), 8, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \
, (uint8_t)((R5) >> 8), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \
, (uint8_t)((R6) >> 8), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \
, (uint8_t)((R7) >> 8), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7) \
/*! Macro for Configuration Setting with only nine register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_9_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7, R8, M8, V8) \
(uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU), 9, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \
, (uint8_t)((R5) >> 8), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \
, (uint8_t)((R6) >> 8), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \
, (uint8_t)((R7) >> 8), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7) \
, (uint8_t)((R8) >> 8), (uint8_t)((R8) & 0xFFU), (uint8_t)(M8), (uint8_t)(V8) \
/*! Macro for Configuration Setting with only ten register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_10_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7, R8, M8, V8, R9, M9, V9) \
(uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU),10, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \
, (uint8_t)((R5) >> 8), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \
, (uint8_t)((R6) >> 8), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \
, (uint8_t)((R7) >> 8), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7) \
, (uint8_t)((R8) >> 8), (uint8_t)((R8) & 0xFFU), (uint8_t)(M8), (uint8_t)(V8) \
, (uint8_t)((R9) >> 8), (uint8_t)((R9) & 0xFFU), (uint8_t)(M9), (uint8_t)(V9) \
/*! Macro for Configuration Setting with eleven register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_11_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7, R8, M8, V8, R9, M9, V9, R10, M10, V10) \
(uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU),11, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \
, (uint8_t)((R5) >> 8), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \
, (uint8_t)((R6) >> 8), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \
, (uint8_t)((R7) >> 8), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7) \
, (uint8_t)((R8) >> 8), (uint8_t)((R8) & 0xFFU), (uint8_t)(M8), (uint8_t)(V8) \
, (uint8_t)((R9) >> 8), (uint8_t)((R9) & 0xFFU), (uint8_t)(M9), (uint8_t)(V9) \
, (uint8_t)((R10) >> 8), (uint8_t)((R10) & 0xFFU), (uint8_t)(M10), (uint8_t)(V10) \
/*! Macro for Configuration Setting with twelve register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_12_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7, R8, M8, V8, R9, M9, V9, R10, M10, V10, R11, M11, V11) \
(uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU),12, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \
, (uint8_t)((R5) >> 8), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \
, (uint8_t)((R6) >> 8), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \
, (uint8_t)((R7) >> 8), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7) \
, (uint8_t)((R8) >> 8), (uint8_t)((R8) & 0xFFU), (uint8_t)(M8), (uint8_t)(V8) \
, (uint8_t)((R9) >> 8), (uint8_t)((R9) & 0xFFU), (uint8_t)(M9), (uint8_t)(V9) \
, (uint8_t)((R10) >> 8), (uint8_t)((R10) & 0xFFU), (uint8_t)(M10), (uint8_t)(V10) \
, (uint8_t)((R11) >> 8), (uint8_t)((R11) & 0xFFU), (uint8_t)(M11), (uint8_t)(V11) \
/*! Macro for Configuration Setting with thirteen register-mask-value sets:
* - Configuration ID[2], Number of Register sets to follow[1], Register[2], Mask[1], Value[1], Register[2], Mask[1], Value[1], Register[2]... */
#define MODE_ENTRY_13_REG(MODE, R0, M0, V0, R1, M1, V1, R2, M2, V2, R3, M3, V3, R4, M4, V4, R5, M5, V5, R6, M6, V6, R7, M7, V7, R8, M8, V8, R9, M9, V9, R10, M10, V10, R11, M11, V11, R12, M12, V12) \
(uint8_t)((MODE) >> 8), (uint8_t)((MODE) & 0xFFU),13, (uint8_t)((R0) >> 8), (uint8_t)((R0) & 0xFFU), (uint8_t)(M0), (uint8_t)(V0) \
, (uint8_t)((R1) >> 8), (uint8_t)((R1) & 0xFFU), (uint8_t)(M1), (uint8_t)(V1) \
, (uint8_t)((R2) >> 8), (uint8_t)((R2) & 0xFFU), (uint8_t)(M2), (uint8_t)(V2) \
, (uint8_t)((R3) >> 8), (uint8_t)((R3) & 0xFFU), (uint8_t)(M3), (uint8_t)(V3) \
, (uint8_t)((R4) >> 8), (uint8_t)((R4) & 0xFFU), (uint8_t)(M4), (uint8_t)(V4) \
, (uint8_t)((R5) >> 8), (uint8_t)((R5) & 0xFFU), (uint8_t)(M5), (uint8_t)(V5) \
, (uint8_t)((R6) >> 8), (uint8_t)((R6) & 0xFFU), (uint8_t)(M6), (uint8_t)(V6) \
, (uint8_t)((R7) >> 8), (uint8_t)((R7) & 0xFFU), (uint8_t)(M7), (uint8_t)(V7) \
, (uint8_t)((R8) >> 8), (uint8_t)((R8) & 0xFFU), (uint8_t)(M8), (uint8_t)(V8) \
, (uint8_t)((R9) >> 8), (uint8_t)((R9) & 0xFFU), (uint8_t)(M9), (uint8_t)(V9) \
, (uint8_t)((R10) >> 8), (uint8_t)((R10) & 0xFFU), (uint8_t)(M10), (uint8_t)(V10) \
, (uint8_t)((R11) >> 8), (uint8_t)((R11) & 0xFFU), (uint8_t)(M11), (uint8_t)(V11) \
, (uint8_t)((R12) >> 8), (uint8_t)((R12) & 0xFFU), (uint8_t)(M12), (uint8_t)(V12) \
/* Setting for approximately 14%: */
#define AM_MOD_DRIVER_LEVEL_DEFAULT 0xb9
/*
******************************************************************************
* GLOBAL DATA TYPES
******************************************************************************
*/
/* PRQA S 3406 1 # MISRA 8.6 - Externally generated table included by the library */ /* PRQA S 1514 1 # MISRA 8.9 - Externally generated table included by the library */
const uint8_t rfalAnalogConfigDefaultSettings[] = {
//****** Default Analog Configuration for Chip-Specific Reset. ******/
MODE_ENTRY_10_REG( (RFAL_ANALOG_CONFIG_TECH_CHIP | RFAL_ANALOG_CONFIG_CHIP_INIT)
, ST25R3911_REG_OP_CONTROL, 0x30, 0x10 /* default to AM */
, ST25R3911_REG_IO_CONF1, 0x06, 0x06 /* MCUCLK: HF clk off */
, ST25R3911_REG_IO_CONF1, (ST25R3911_REG_IO_CONF1_mask_out_cl | ST25R3911_REG_IO_CONF1_lf_clk_off), 0x07 /* MCUCLK: LF clk off */
, ST25R3911_REG_IO_CONF2, 0x18, 0x18 /* pull downs */
, ST25R3911_REG_RX_CONF4, ST25R3911_REG_RX_CONF4_mask_rg2_pm, 0x1U<<ST25R3911_REG_RX_CONF4_shift_rg2_pm /* increase digitizer window for PM */
, ST25R3911_REG_ANT_CAL_TARGET, 0xFF, 0x80 /* 90degrees */
, ST25R3911_REG_ANT_CAL_CONTROL, 0xF8, 0x00 /* trim value from calibrate antenna */
, ST25R3911_REG_AM_MOD_DEPTH_CONTROL, ST25R3911_REG_AM_MOD_DEPTH_CONTROL_am_s, ST25R3911_REG_AM_MOD_DEPTH_CONTROL_am_s /* AM modulated level is defined by RFO AM Modulated Level Def Reg, fixed setting, no automatic adjustment */
, ST25R3911_REG_FIELD_THRESHOLD, ST25R3911_REG_FIELD_THRESHOLD_mask_trg, ST25R3911_REG_FIELD_THRESHOLD_trg_75mV
, ST25R3911_REG_FIELD_THRESHOLD, ST25R3911_REG_FIELD_THRESHOLD_mask_rfe, ST25R3911_REG_FIELD_THRESHOLD_rfe_75mV
)
//****** Default Analog Configuration for Poll NFC-A Tx. ******/
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_RFO_AM_ON_LEVEL, 0xff, 0xf0 /* Used for 848 TX: very high AM to keep wave shapes */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_106 | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, 0x00 /* OOK */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_212 | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, 0x00 /* OOK */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_424 | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, 0x00 /* OOK */
)
, MODE_ENTRY_2_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_848 | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, ST25R3911_REG_AUX_tr_am /* AM! */
, ST25R3911_REG_RFO_AM_ON_LEVEL, 0xff, 0xf0 /* Used for 848 TX: very high AM to keep wave shapes */
)
//****** Default Analog Configuration for Poll NFC-A Rx. ******/
, MODE_ENTRY_3_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF3, 0xff, 0x18
, ST25R3911_REG_RX_CONF4, ST25R3911_REG_RX_CONF4_mask_rg2_am, 0x2U<<ST25R3911_REG_RX_CONF4_shift_rg2_am /* increase digitizer window for AM */
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_rx_tol, 0x00 /* rx_tol Off */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_106 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x00
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_212 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x04
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_424 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x22
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCA | RFAL_ANALOG_CONFIG_BITRATE_848 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x22
)
//****** Default Analog Configuration for Poll NFC-B Tx. ******/
, MODE_ENTRY_2_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, ST25R3911_REG_AUX_tr_am /* AM */
, ST25R3911_REG_RFO_AM_ON_LEVEL, 0xff, AM_MOD_DRIVER_LEVEL_DEFAULT /* Fixed driver for AM level: ~14% */
)
//****** Default Analog Configuration for Poll NFC-B Rx. ******/
, MODE_ENTRY_3_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF3, 0xff, 0x18
, ST25R3911_REG_RX_CONF4, ST25R3911_REG_RX_CONF4_mask_rg2_am, 0x1U<<ST25R3911_REG_RX_CONF4_shift_rg2_am /* increase digitizer window for AM */
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_rx_tol, ST25R3911_REG_AUX_rx_tol /* rx_tol On as default */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_106 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x04
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_212 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x04
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_424 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x22
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_848 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x22
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_1695 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x6c
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCB | RFAL_ANALOG_CONFIG_BITRATE_3390 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x6c
)
//****** Default Analog Configuration for Poll NFC-F Tx. ******/
, MODE_ENTRY_2_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCF | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, ST25R3911_REG_AUX_tr_am /* AM */
, ST25R3911_REG_RFO_AM_ON_LEVEL, 0xff, AM_MOD_DRIVER_LEVEL_DEFAULT /* Fixed driver for AM level: ~14% */
)
//****** Default Analog Configuration for Poll NFC-F Common bitrate Rx. ******/
, MODE_ENTRY_3_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCF | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF3, 0xff, 0x18
, ST25R3911_REG_RX_CONF4, ST25R3911_REG_RX_CONF4_mask_rg2_am, 0x1U<<ST25R3911_REG_RX_CONF4_shift_rg2_am /* increase digitizer window for AM */
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_rx_tol, ST25R3911_REG_AUX_rx_tol /* rx_tol On as default */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCF | RFAL_ANALOG_CONFIG_BITRATE_212 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x13 /* dev. from data sheet: lp 300kKz */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCF | RFAL_ANALOG_CONFIG_BITRATE_424 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x0b /* dev. from data sheet: lp 600kHz */
)
//****** Default Analog Configuration for Poll NFC-V Common bitrate Tx ******/
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCV | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, 0x00
)
//****** Default Analog Configuration for Poll NFC-V Common bitrate Rx ******/
, MODE_ENTRY_4_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_NFCV | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x0c /* use filter settings from table 9: "Recommended for 424/484 kHz sub-carrier" */
, ST25R3911_REG_RX_CONF3, 0xff, 0x18
, ST25R3911_REG_RX_CONF4, ST25R3911_REG_RX_CONF4_mask_rg2_am, 0x1U<<ST25R3911_REG_RX_CONF4_shift_rg2_am /* increase digitizer window for AM */
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_rx_tol, ST25R3911_REG_AUX_rx_tol /* rx_tol On as default */
)
//****** Default Analog Configuration for Poll AP2P Common bitrate Tx. ******/
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_RFO_AM_ON_LEVEL, 0xff, AM_MOD_DRIVER_LEVEL_DEFAULT /* Fixed driver for AM level: ~14% */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_106 | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, 0x00 /* OOK */
)
, MODE_ENTRY_2_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_212 | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, ST25R3911_REG_AUX_tr_am /* AM */
, ST25R3911_REG_RFO_AM_ON_LEVEL, 0xff, AM_MOD_DRIVER_LEVEL_DEFAULT /* Fixed driver for AM level: ~14% */
)
, MODE_ENTRY_2_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_424 | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, ST25R3911_REG_AUX_tr_am /* AM */
, ST25R3911_REG_RFO_AM_ON_LEVEL, 0xff, AM_MOD_DRIVER_LEVEL_DEFAULT /* Fixed driver for AM level: ~14% */
)
//****** Default Analog Configuration for Poll AP2P Common bitrate Rx. ******/
, MODE_ENTRY_4_REG( (RFAL_ANALOG_CONFIG_TECH_CHIP | RFAL_ANALOG_CONFIG_CHIP_LISTEN_ON)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x45
, ST25R3911_REG_RX_CONF3, (ST25R3911_REG_RX_CONF3_lim | ST25R3911_REG_RX_CONF3_rg_nfc), (ST25R3911_REG_RX_CONF3_lim | ST25R3911_REG_RX_CONF3_rg_nfc)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_rx_tol, ST25R3911_REG_AUX_rx_tol /* rx_tol On as default */
, ST25R3911_REG_RX_CONF4, ST25R3911_REG_RX_CONF4_mask_rg2_am, 0x1U<<ST25R3911_REG_RX_CONF4_shift_rg2_am /* increase digitizer window for AM */
)
, MODE_ENTRY_4_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x45
, ST25R3911_REG_RX_CONF3, (ST25R3911_REG_RX_CONF3_lim | ST25R3911_REG_RX_CONF3_rg_nfc), (ST25R3911_REG_RX_CONF3_lim | ST25R3911_REG_RX_CONF3_rg_nfc)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_rx_tol, ST25R3911_REG_AUX_rx_tol /* rx_tol On as default */
, ST25R3911_REG_RX_CONF4, ST25R3911_REG_RX_CONF4_mask_rg2_am, 0x1U<<ST25R3911_REG_RX_CONF4_shift_rg2_am /* increase digitizer window for AM */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_106 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF3, ST25R3911_REG_RX_CONF3_mask_rg1_am, 0xc0
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_212 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF3, ST25R3911_REG_RX_CONF3_mask_rg1_am, 0x00
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_POLL | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_424 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF3, ST25R3911_REG_RX_CONF3_mask_rg1_am, 0x00
)
//****** Default Analog Configuration for Listen AP2P Common bitrate Tx. ******/
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_RFO_AM_ON_LEVEL, 0xff, AM_MOD_DRIVER_LEVEL_DEFAULT /* Fixed driver for AM level: ~14% */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_106 | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, 0x00 /* OOK */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_212 | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, ST25R3911_REG_AUX_tr_am /* AM */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_424 | RFAL_ANALOG_CONFIG_TX)
, ST25R3911_REG_AUX, ST25R3911_REG_AUX_tr_am, ST25R3911_REG_AUX_tr_am /* AM */
)
//****** Default Analog Configuration for Listen AP2P Common bitrate Rx. ******/
, MODE_ENTRY_3_REG( (RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_COMMON | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF1, 0x7f, 0x45
, ST25R3911_REG_RX_CONF3, (ST25R3911_REG_RX_CONF3_lim | ST25R3911_REG_RX_CONF3_rg_nfc), (ST25R3911_REG_RX_CONF3_lim | ST25R3911_REG_RX_CONF3_rg_nfc)
, ST25R3911_REG_RX_CONF4, ST25R3911_REG_RX_CONF4_mask_rg2_am, 0x1U<<ST25R3911_REG_RX_CONF4_shift_rg2_am /* increase digitizer window for AM */
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_106 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF3, ST25R3911_REG_RX_CONF3_mask_rg1_am, 0xc0
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_212 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF3, ST25R3911_REG_RX_CONF3_mask_rg1_am, 0x00
)
, MODE_ENTRY_1_REG( (RFAL_ANALOG_CONFIG_LISTEN | RFAL_ANALOG_CONFIG_TECH_AP2P | RFAL_ANALOG_CONFIG_BITRATE_424 | RFAL_ANALOG_CONFIG_RX)
, ST25R3911_REG_RX_CONF3, ST25R3911_REG_RX_CONF3_mask_rg1_am, 0x00
)
};
#endif /* ST25R3911_ANALOGCONFIG_H */

View File

@ -1,296 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_chip.h
*
* \author Gustavo Patricio
*
* \brief RF Chip specific Layer
*
* \warning This layer, which provides direct access to RF chip, should
* only be used for debug purposes and/or advanced features
*
*
* \addtogroup RFAL
* @{
*
* \addtogroup RFAL-HAL
* \brief RFAL Hardware Abstraction Layer
* @{
*
* \addtogroup Chip
* \brief RFAL RF Chip Module
* @{
*
*/
#ifndef RFAL_CHIP_H
#define RFAL_CHIP_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
#include "st_errno.h"
#include "rfal_rf.h"
/*****************************************************************************
* RF Chip *
*****************************************************************************/
/*!
*****************************************************************************
* \brief Writes a register on the RF Chip
*
* Checks if the given register is valid and if so, writes the value(s)
* on the RF Chip register
*
* \param[in] reg: register address to be written, or the first if len > 1
* \param[in] values: pointer with content to be written on the register(s)
* \param[in] len: number of consecutive registers to be written
*
*
* \return ERR_PARAM : Invalid register or bad request
* \return ERR_NOTSUPP : Feature not supported
* \return ERR_NONE : Write done with no error
*****************************************************************************
*/
ReturnCode rfalChipWriteReg( uint16_t reg, const uint8_t* values, uint8_t len );
/*!
*****************************************************************************
* \brief Reads a register on the RF Chip
*
* Checks if the given register is valid and if so, reads the value(s)
* of the RF Chip register(s)
*
* \param[in] reg: register address to be read, or the first if len > 1
* \param[out] values: pointer where the register(s) read content will be placed
* \param[in] len: number of consecutive registers to be read
*
* \return ERR_PARAM : Invalid register or bad request
* \return ERR_NOTSUPP : Feature not supported
* \return ERR_NONE : Read done with no error
*****************************************************************************
*/
ReturnCode rfalChipReadReg( uint16_t reg, uint8_t* values, uint8_t len );
/*!
*****************************************************************************
* \brief Change a register on the RF Chip
*
* Change the value of the register bits on the RF Chip Test set in the valueMask.
*
* \param[in] reg: register address to be modified
* \param[in] valueMask: mask value of the register bits to be changed
* \param[in] value: register value to be set
*
* \return ERR_PARAM : Invalid register or bad request
* \return ERR_NOTSUPP : Feature not supported
* \return ERR_OK : Change done with no error
*****************************************************************************
*/
ReturnCode rfalChipChangeRegBits( uint16_t reg, uint8_t valueMask, uint8_t value );
/*!
*****************************************************************************
* \brief Writes a Test register on the RF Chip
*
* Writes the value on the RF Chip Test register
*
* \param[in] reg: register address to be written
* \param[in] value: value to be written on the register
*
*
* \return ERR_PARAM : Invalid register or bad request
* \return ERR_NOTSUPP : Feature not supported
* \return ERR_NONE : Write done with no error
*****************************************************************************
*/
ReturnCode rfalChipWriteTestReg( uint16_t reg, uint8_t value );
/*!
*****************************************************************************
* \brief Reads a Test register on the RF Chip
*
* Reads the value of the RF Chip Test register
*
* \param[in] reg: register address to be read
* \param[out] value: pointer where the register content will be placed
*
* \return ERR_PARAM :Invalid register or bad request
* \return ERR_NOTSUPP : Feature not supported
* \return ERR_NONE : Read done with no error
*****************************************************************************
*/
ReturnCode rfalChipReadTestReg( uint16_t reg, uint8_t* value );
/*!
*****************************************************************************
* \brief Change a Test register on the RF Chip
*
* Change the value of the register bits on the RF Chip Test set in the valueMask.
*
* \param[in] reg: test register address to be modified
* \param[in] valueMask: mask value of the register bits to be changed
* \param[in] value: register value to be set
*
* \return ERR_PARAM : Invalid register or bad request
* \return ERR_NOTSUPP : Feature not supported
* \return ERR_OK : Change done with no error
*****************************************************************************
*/
ReturnCode rfalChipChangeTestRegBits( uint16_t reg, uint8_t valueMask, uint8_t value );
/*!
*****************************************************************************
* \brief Execute command on the RF Chip
*
* Checks if the given command is valid and if so, executes it on
* the RF Chip
*
* \param[in] cmd: direct command to be executed
*
* \return ERR_PARAM : Invalid command or bad request
* \return ERR_NOTSUPP : Feature not supported
* \return ERR_NONE : Direct command executed with no error
*****************************************************************************
*/
ReturnCode rfalChipExecCmd( uint16_t cmd );
/*!
*****************************************************************************
* \brief Set RFO
*
* Sets the RFO value to be used when the field is on (unmodulated/active)
*
* \param[in] rfo : the RFO value to be used
*
* \return ERR_IO : Internal error
* \return ERR_NOTSUPP : Feature not supported
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalChipSetRFO( uint8_t rfo );
/*!
*****************************************************************************
* \brief Get RFO
*
* Gets the RFO value used used when the field is on (unmodulated/active)
*
* \param[out] result : the current RFO value
*
* \return ERR_IO : Internal error
* \return ERR_NOTSUPP : Feature not supported
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalChipGetRFO( uint8_t* result );
/*!
*****************************************************************************
* \brief Measure Amplitude
*
* Measures the RF Amplitude
*
* \param[out] result : result of RF measurement
*
* \return ERR_IO : Internal error
* \return ERR_NOTSUPP : Feature not supported
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalChipMeasureAmplitude( uint8_t* result );
/*!
*****************************************************************************
* \brief Measure Phase
*
* Measures the Phase
*
* \param[out] result : result of Phase measurement
*
* \return ERR_IO : Internal error
* \return ERR_NOTSUPP : Feature not supported
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalChipMeasurePhase( uint8_t* result );
/*!
*****************************************************************************
* \brief Measure Capacitance
*
* Measures the Capacitance
*
* \param[out] result : result of Capacitance measurement
*
* \return ERR_IO : Internal error
* \return ERR_NOTSUPP : Feature not supported
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalChipMeasureCapacitance( uint8_t* result );
/*!
*****************************************************************************
* \brief Measure Power Supply
*
* Measures the Power Supply
*
* \param[in] param : measurement parameter (chip specific)
* \param[out] result : result of the measurement
*
* \return ERR_IO : Internal error
* \return ERR_NOTSUPP : Feature not supported
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalChipMeasurePowerSupply( uint8_t param, uint8_t* result );
#endif /* RFAL_CHIP_H */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,75 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_crc.h
*
* \author Ulrich Herrmann
*
* \brief CRC calculation module
*
*/
/*!
*
*/
#ifndef RFAL_CRC_H_
#define RFAL_CRC_H_
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief Calculate CRC according to CCITT standard.
*
* This function takes \a length bytes from \a buf and calculates the CRC
* for this data. The result is returned.
* \note This implementation calculates the CRC with LSB first, i.e. all
* bytes are "read" from right to left.
*
* \param[in] preloadValue : Initial value of CRC calculation.
* \param[in] buf : buffer to calculate the CRC for.
* \param[in] length : size of the buffer.
*
* \return 16 bit long crc value.
*
*****************************************************************************
*/
extern uint16_t rfalCrcCalculateCcitt(uint16_t preloadValue, const uint8_t* buf, uint16_t length);
#endif /* RFAL_CRC_H_ */

View File

@ -1,209 +0,0 @@
/******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (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.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* $Revision: $
* LANGUAGE: ISO C99
*/
/*! \file rfal_dpo.h
*
* \author Martin Zechleitner
*
* \brief Dynamic Power adjustment
*
* This module provides an interface to perform the power adjustment dynamically
*
*
* \addtogroup RFAL
* @{
*
* \addtogroup RFAL-HAL
* \brief RFAL Hardware Abstraction Layer
* @{
*
* \addtogroup DynamicPower
* \brief RFAL Dynamic Power Module
* @{
*
*/
#ifndef RFAL_DPO_H
#define RFAL_DPO_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
#include "st_errno.h"
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_DPO_TABLE_SIZE_MAX 15U /*!< Max DPO table size */
#define RFAL_DPO_TABLE_PARAMETER 3U /*!< DPO table Parameter length */
/*
******************************************************************************
* GLOBAL TYPES
******************************************************************************
*/
/*! DPO table entry struct */
typedef struct {
uint8_t rfoRes; /*!< Setting for the resistance level of the RFO */
uint8_t inc; /*!< Threshold for incrementing the output power */
uint8_t dec; /*!< Threshold for decrementing the output power */
}rfalDpoEntry;
/*! Function pointer to methode doing the reference measurement */
typedef ReturnCode (*rfalDpoMeasureFunc)(uint8_t*);
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief Initialize dynamic power table
*
* This function sets the internal dynamic power table to the default
* values stored in rfal_DpoTbl.h
*
*****************************************************************************
*/
void rfalDpoInitialize( void );
/*!
*****************************************************************************
* \brief Set the measurement methode
*
* This function sets the measurement method used for reference measurement.
* Based on the measurement the power will then be adjusted
*
* \param[in] dpoMeasureFunc: callback of measurement function
*
*****************************************************************************
*/
void rfalDpoSetMeasureCallback( rfalDpoMeasureFunc dpoMeasureFunc );
/*!
*****************************************************************************
* \brief Write dynamic power table
*
* Load the dynamic power table
*
* \param[in] powerTbl: location of power Table to be loaded
* \param[in] powerTblEntries: number of entries of the power Table to be loaded
*
* \return ERR_NONE : No error
* \return ERR_PARAM : if configTbl is invalid
* \return ERR_NOMEM : if the given Table is bigger exceeds the max size
*****************************************************************************
*/
ReturnCode rfalDpoTableWrite( rfalDpoEntry* powerTbl, uint8_t powerTblEntries );
/*!
*****************************************************************************
* \brief Dynamic power table Read
*
* Read the dynamic power table
*
* \param[out] tblBuf: location to the rfalDpoEntry[] to place the Table
* \param[in] tblBufEntries: number of entries available in tblBuf to place the power Table
* \param[out] tableEntries: returned number of entries actually written into tblBuf
*
* \return ERR_NONE : No error
* \return ERR_PARAM : if configTbl is invalid or parameters are invalid
*****************************************************************************
*/
ReturnCode rfalDpoTableRead( rfalDpoEntry* tblBuf, uint8_t tblBufEntries, uint8_t* tableEntries );
/*!
*****************************************************************************
* \brief Dynamic power adjust
*
* It measures the current output and adjusts the power accordingly to
* the dynamic power table
*
* \return ERR_NONE : No error
* \return ERR_PARAM : if configTbl is invalid or parameters are invalid
* \return ERR_WRONG_STATE : if the current state is valid for DPO Adjustment
*****************************************************************************
*/
ReturnCode rfalDpoAdjust( void );
/*!
*****************************************************************************
* \brief Get Current Dynamic power table entry
*
* Return current used DPO power table entry settings
*
* \return ERR_NONE : Current DpoEntry. This includes d_res, inc and dec
*
*****************************************************************************
*/
rfalDpoEntry* rfalDpoGetCurrentTableEntry(void);
/*!
*****************************************************************************
* \brief Dynamic power set enabled state
*
* \param[in] enable: new active state
*
* Set state to enable or disable the Dynamic power adjustment
*
*****************************************************************************
*/
void rfalDpoSetEnabled( bool enable );
/*!
*****************************************************************************
* \brief Get the Dynamic power enabled state
*
* Get state of the Dynamic power adjustment
*
* \return true : enabled
* \return false : disabled
*****************************************************************************
*/
bool rfalDpoIsEnabled(void);
#endif /* RFAL_DPO_H */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,56 +0,0 @@
/******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (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.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* $Revision: $
* LANGUAGE: ISO C99
*/
#ifndef ST25R3911_DYNAMICPOWER_H
#define ST25R3911_DYNAMICPOWER_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "rfal_dpo.h"
/*
******************************************************************************
* GLOBAL VARIABLES
******************************************************************************
*/
/*! Default DPO table */
const uint8_t rfalDpoDefaultSettings [] = {
0x00, 255, 200,
0x01, 210, 150,
0x02, 160, 100,
0x03, 110, 50,
0x0E, 60, 0
};
#endif /* ST25R3911_DYNAMICPOWER_H */

View File

@ -1,115 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file
*
* \author Gustavo Patricio
*
* \brief RFAL Features/Capabilities Definition for ST25R3911
*/
#ifndef RFAL_FEATURES_H
#define RFAL_FEATURES_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_SUPPORT_MODE_POLL_NFCA true /*!< RFAL Poll NFCA mode support switch */
#define RFAL_SUPPORT_MODE_POLL_NFCB true /*!< RFAL Poll NFCB mode support switch */
#define RFAL_SUPPORT_MODE_POLL_NFCF true /*!< RFAL Poll NFCF mode support switch */
#define RFAL_SUPPORT_MODE_POLL_NFCV true /*!< RFAL Poll NFCV mode support switch */
#define RFAL_SUPPORT_MODE_POLL_ACTIVE_P2P true /*!< RFAL Poll AP2P mode support switch */
#define RFAL_SUPPORT_MODE_LISTEN_NFCA false /*!< RFAL Listen NFCA mode support switch */
#define RFAL_SUPPORT_MODE_LISTEN_NFCB false /*!< RFAL Listen NFCB mode support switch */
#define RFAL_SUPPORT_MODE_LISTEN_NFCF false /*!< RFAL Listen NFCF mode support switch */
#define RFAL_SUPPORT_MODE_LISTEN_ACTIVE_P2P true /*!< RFAL Listen AP2P mode support switch */
/*******************************************************************************/
/*! RFAL supported Card Emulation (CE) */
#define RFAL_SUPPORT_CE ( RFAL_SUPPORT_MODE_LISTEN_NFCA || RFAL_SUPPORT_MODE_LISTEN_NFCB || RFAL_SUPPORT_MODE_LISTEN_NFCF )
/*! RFAL supported Reader/Writer (RW) */
#define RFAL_SUPPORT_RW ( RFAL_SUPPORT_MODE_POLL_NFCA || RFAL_SUPPORT_MODE_POLL_NFCB || RFAL_SUPPORT_MODE_POLL_NFCF || RFAL_SUPPORT_MODE_POLL_NFCV )
/*! RFAL support for Active P2P (AP2P) */
#define RFAL_SUPPORT_AP2P ( RFAL_SUPPORT_MODE_POLL_ACTIVE_P2P || RFAL_SUPPORT_MODE_POLL_ACTIVE_P2P )
/*******************************************************************************/
#define RFAL_SUPPORT_BR_RW_106 true /*!< RFAL RW 106 Bit Rate support switch */
#define RFAL_SUPPORT_BR_RW_212 true /*!< RFAL RW 212 Bit Rate support switch */
#define RFAL_SUPPORT_BR_RW_424 true /*!< RFAL RW 424 Bit Rate support switch */
#define RFAL_SUPPORT_BR_RW_848 true /*!< RFAL RW 848 Bit Rate support switch */
#define RFAL_SUPPORT_BR_RW_1695 true /*!< RFAL RW 1695 Bit Rate support switch */
#define RFAL_SUPPORT_BR_RW_3390 true /*!< RFAL RW 3390 Bit Rate support switch */
#define RFAL_SUPPORT_BR_RW_6780 false /*!< RFAL RW 6780 Bit Rate support switch */
#define RFAL_SUPPORT_BR_RW_13560 false /*!< RFAL RW 6780 Bit Rate support switch */
/*******************************************************************************/
#define RFAL_SUPPORT_BR_AP2P_106 true /*!< RFAL AP2P 106 Bit Rate support switch */
#define RFAL_SUPPORT_BR_AP2P_212 true /*!< RFAL AP2P 212 Bit Rate support switch */
#define RFAL_SUPPORT_BR_AP2P_424 true /*!< RFAL AP2P 424 Bit Rate support switch */
#define RFAL_SUPPORT_BR_AP2P_848 false /*!< RFAL AP2P 848 Bit Rate support switch */
#define RFAL_SUPPORT_BR_AP2P_1695 false /*!< RFAL AP2P 1695 Bit Rate support switch */
#define RFAL_SUPPORT_BR_AP2P_3390 false /*!< RFAL AP2P 3390 Bit Rate support switch */
#define RFAL_SUPPORT_BR_AP2P_6780 false /*!< RFAL AP2P 6780 Bit Rate support switch */
/*******************************************************************************/
#define RFAL_SUPPORT_BR_CE_A_106 false /*!< RFAL CE A 106 Bit Rate support switch */
#define RFAL_SUPPORT_BR_CE_A_212 false /*!< RFAL CE A 212 Bit Rate support switch */
#define RFAL_SUPPORT_BR_CE_A_424 false /*!< RFAL CE A 424 Bit Rate support switch */
#define RFAL_SUPPORT_BR_CE_A_848 false /*!< RFAL CE A 848 Bit Rate support switch */
/*******************************************************************************/
#define RFAL_SUPPORT_BR_CE_B_106 false /*!< RFAL CE B 106 Bit Rate support switch */
#define RFAL_SUPPORT_BR_CE_B_212 false /*!< RFAL CE B 212 Bit Rate support switch */
#define RFAL_SUPPORT_BR_CE_B_424 false /*!< RFAL CE B 424 Bit Rate support switch */
#define RFAL_SUPPORT_BR_CE_B_848 false /*!< RFAL CE B 848 Bit Rate support switch */
/*******************************************************************************/
#define RFAL_SUPPORT_BR_CE_F_212 false /*!< RFAL CE F 212 Bit Rate support switch */
#define RFAL_SUPPORT_BR_CE_F_424 false /*!< RFAL CE F 424 Bit Rate support switch */
#endif /* RFAL_FEATURES_H */

View File

@ -1,202 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_iso15693_2.h
*
* \author Ulrich Herrmann
*
* \brief Implementation of ISO-15693-2
*
*/
/*!
*
*/
#ifndef RFAL_ISO_15693_2_H
#define RFAL_ISO_15693_2_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
#include "st_errno.h"
/*
******************************************************************************
* GLOBAL DATATYPES
******************************************************************************
*/
/*! Enum holding possible VCD codings */
typedef enum
{
ISO15693_VCD_CODING_1_4,
ISO15693_VCD_CODING_1_256
}iso15693VcdCoding_t;
/*! Enum holding possible VICC datarates */
/*! Configuration parameter used by #iso15693PhyConfigure */
typedef struct
{
iso15693VcdCoding_t coding; /*!< desired VCD coding */
uint32_t speedMode; /*!< 0: normal mode, 1: 2^1 = x2 Fast mode, 2 : 2^2 = x4 mode, 3 : 2^3 = x8 mode - all rx pulse numbers and times are divided by 1,2,4,8 */
}iso15693PhyConfig_t;
/*! Parameters how the stream mode should work */
struct iso15693StreamConfig {
uint8_t useBPSK; /*!< 0: subcarrier, 1:BPSK */
uint8_t din; /*!< the divider for the in subcarrier frequency: fc/2^din */
uint8_t dout; /*!< the divider for the in subcarrier frequency fc/2^dout */
uint8_t report_period_length; /*!< the length of the reporting period 2^report_period_length*/
};
/*
******************************************************************************
* GLOBAL CONSTANTS
******************************************************************************
*/
#define ISO15693_REQ_FLAG_TWO_SUBCARRIERS 0x01U /*!< Flag indication that communication uses two subcarriers */
#define ISO15693_REQ_FLAG_HIGH_DATARATE 0x02U /*!< Flag indication that communication uses high bitrate */
#define ISO15693_MASK_FDT_LISTEN (65) /*!< t1min = 308,2us = 4192/fc = 65.5 * 64/fc */
/*! t1max = 323,3us = 4384/fc = 68.5 * 64/fc
* 12 = 768/fc unmodulated time of single subcarrior SoF */
#define ISO15693_FWT (69 + 12)
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief Initialize the ISO15693 phy
*
* \param[in] config : ISO15693 phy related configuration (See #iso15693PhyConfig_t)
* \param[out] needed_stream_config : return a pointer to the stream config
* needed for this iso15693 config. To be used for configure RF chip.
*
* \return ERR_IO : Error during communication.
* \return ERR_NONE : No error.
*
*****************************************************************************
*/
extern ReturnCode iso15693PhyConfigure(const iso15693PhyConfig_t* config,
const struct iso15693StreamConfig ** needed_stream_config );
/*!
*****************************************************************************
* \brief Return current phy configuration
*
* This function returns current Phy configuration previously
* set by #iso15693PhyConfigure
*
* \param[out] config : ISO15693 phy configuration.
*
* \return ERR_NONE : No error.
*
*****************************************************************************
*/
extern ReturnCode iso15693PhyGetConfiguration(iso15693PhyConfig_t* config);
/*!
*****************************************************************************
* \brief Code an ISO15693 compatible frame
*
* This function takes \a length bytes from \a buffer, perform proper
* encoding and sends out the frame to the ST25R391x.
*
* \param[in] buffer : data to send, modified to adapt flags.
* \param[in] length : number of bytes to send.
* \param[in] sendCrc : If set to true, CRC is appended to the frame
* \param[in] sendFlags: If set to true, flag field is sent according to
* ISO15693.
* \param[in] picopassMode : If set to true, the coding will be according to Picopass
* \param[out] subbit_total_length : Return the complete bytes which need to
* be send for the current coding
* \param[in,out] offset : Set to 0 for first transfer, function will update it to
point to next byte to be coded
* \param[out] outbuf : buffer where the function will store the coded subbit stream
* \param[out] outBufSize : the size of the output buffer
* \param[out] actOutBufSize : the amount of data stored into the buffer at this call
*
* \return ERR_IO : Error during communication.
* \return ERR_AGAIN : Data was not coded all the way. Call function again with a new/emptied buffer
* \return ERR_NO_MEM : In case outBuf is not big enough. Needs to have at
least 5 bytes for 1of4 coding and 65 bytes for 1of256 coding
* \return ERR_NONE : No error.
*
*****************************************************************************
*/
extern ReturnCode iso15693VCDCode(uint8_t* buffer, uint16_t length, bool sendCrc, bool sendFlags, bool picopassMode,
uint16_t *subbit_total_length, uint16_t *offset,
uint8_t* outbuf, uint16_t outBufSize, uint16_t* actOutBufSize);
/*!
*****************************************************************************
* \brief Receive an ISO15693 compatible frame
*
* This function receives an ISO15693 frame from the ST25R391x, decodes the frame
* and writes the raw data to \a buffer.
* \note Buffer needs to be big enough to hold CRC also (+2 bytes)
*
* \param[in] inBuf : buffer with the hamming coded stream to be decoded
* \param[in] inBufLen : number of bytes to decode (=length of buffer).
* \param[out] outBuf : buffer where received data shall be written to.
* \param[in] outBufLen : Length of output buffer, should be approx twice the size of inBuf
* \param[out] outBufPos : The number of decoded bytes. Could be used in
* extended implementation to allow multiple calls
* \param[out] bitsBeforeCol : in case of ERR_COLLISION this value holds the
* number of bits in the current byte where the collision happened.
* \param[in] ignoreBits : number of bits in the beginning where collisions will be ignored
* \param[in] picopassMode : if set to true, the decoding will be according to Picopass
*
* \return ERR_COLLISION : collision occured, data uncorrect
* \return ERR_CRC : CRC error, data uncorrect
* \return ERR_TIMEOUT : timeout waiting for data.
* \return ERR_NONE : No error.
*
*****************************************************************************
*/
extern ReturnCode iso15693VICCDecode(const uint8_t *inBuf,
uint16_t inBufLen,
uint8_t* outBuf,
uint16_t outBufLen,
uint16_t* outBufPos,
uint16_t* bitsBeforeCol,
uint16_t ignoreBits,
bool picopassMode );
#endif /* RFAL_ISO_15693_2_H */

View File

@ -1,866 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_isoDep.h
*
* \author Gustavo Patricio
*
* \brief Implementation of ISO-DEP protocol
*
* This implementation was based on the following specs:
* - ISO/IEC 14443-4 2nd Edition 2008-07-15
* - NFC Forum Digital Protocol 1.1 2014-01-14
*
*
* \addtogroup RFAL
* @{
*
* \addtogroup RFAL-AL
* \brief RFAL Abstraction Layer
* @{
*
* \addtogroup ISO-DEP
* \brief RFAL ISO-DEP Module
* @{
*
*/
#ifndef RFAL_ISODEP_H_
#define RFAL_ISODEP_H_
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
#include "rfal_nfcb.h"
/*
******************************************************************************
* DEFINES
******************************************************************************
*/
#define RFAL_ISODEP_PROLOGUE_SIZE (3U) /*!< Length of Prologue Field for I-Block Format */
#define RFAL_ISODEP_PCB_LEN (1U) /*!< PCB length */
#define RFAL_ISODEP_DID_LEN (1U) /*!< DID length */
#define RFAL_ISODEP_NAD_LEN (1U) /*!< NAD length */
#define RFAL_ISODEP_NO_DID (0x00U) /*!< DID value indicating the ISO-DEP layer not to use DID */
#define RFAL_ISODEP_NO_NAD (0xFFU) /*!< NAD value indicating the ISO-DEP layer not to use NAD */
#define RFAL_ISODEP_FWI_MASK (0xF0U) /*!< Mask bits of FWI */
#define RFAL_ISODEP_FWI_SHIFT (4U) /*!< Shift val of FWI */
#define RFAL_ISODEP_FWI_DEFAULT (4U) /*!< Default value for FWI Digital 1.0 11.6.2.17 */
#define RFAL_ISODEP_ADV_FEATURE (0x0FU) /*!< Indicate 256 Bytes FSD and Advanc Proto Feature support:NAD & DID */
#define RFAL_ISODEP_DID_MAX (14U) /*!< Maximum DID value */
#define RFAL_ISODEP_BRI_MASK (0x07U) /*!< Mask bits for Poll to Listen Send bitrate */
#define RFAL_ISODEP_BSI_MASK (0x70U) /*!< Mask bits for Listen to Poll Send bitrate */
#define RFAL_ISODEP_SAME_BITRATE_MASK (0x80U) /*!< Mask bit indicate only same bit rate D for both direction support */
#define RFAL_ISODEP_BITRATE_RFU_MASK (0x08U) /*!< Mask bit for RFU */
/*! Maximum Frame Waiting Time = ((256 * 16/fc) * 2^FWImax) = ((256*16/fc)*2^14) = (67108864)/fc = 2^26 (1/fc) */
#define RFAL_ISODEP_MAX_FWT ((uint32_t)1U<<26)
#define RFAL_ISODEP_FSDI_DEFAULT RFAL_ISODEP_FSXI_256 /*!< Default Frame Size Integer in Poll mode */
#define RFAL_ISODEP_FSX_KEEP (0xFFU) /*!< Flag to keep FSX from activation */
#define RFAL_ISODEP_DEFAULT_FSCI RFAL_ISODEP_FSXI_256 /*!< FSCI default value to be used in Listen Mode */
#define RFAL_ISODEP_DEFAULT_FSC RFAL_ISODEP_FSX_256 /*!< FSC default value (aligned RFAL_ISODEP_DEFAULT_FSCI) */
#define RFAL_ISODEP_DEFAULT_SFGI (0U) /*!< SFGI Default value to be used in Listen Mode */
#define RFAL_ISODEP_DEFAULT_FWI (8U) /*!< Default Listener FWI (Max) Digital 2.0 B7 & B3 */
#define RFAL_ISODEP_APDU_MAX_LEN RFAL_ISODEP_FSX_1024 /*!< Max APDU length */
#define RFAL_ISODEP_ATTRIB_RES_MBLI_NO_INFO (0x00U) /*!< MBLI indicating no information on its internal input buffer size */
#define RFAL_ISODEP_ATTRIB_REQ_PARAM1_DEFAULT (0x00U) /*!< Default values of Param 1 of ATTRIB_REQ Digital 1.0 12.6.1.3-5 */
#define RFAL_ISODEP_ATTRIB_HLINFO_LEN (32U) /*!< Maximum Size of Higher Layer Information */
#define RFAL_ISODEP_ATS_HB_MAX_LEN (15U) /*!< Maximum length of Historical Bytes Digital 1.1 13.6.2.23 */
#define RFAL_ISODEP_ATTRIB_REQ_MIN_LEN (9U) /*!< Minimum Length of ATTRIB_REQ command */
#define RFAL_ISODEP_ATTRIB_RES_MIN_LEN (1U) /*!< Minimum Length of ATTRIB_RES response */
#define RFAL_ISODEP_SPARAM_VALUES_MAX_LEN (16U) /*!< Maximum Length of the value field on S(PARAMETERS) */
#define RFAL_ISODEP_SPARAM_TAG_BLOCKINFO (0xA0U) /*!< S(PARAMETERS) tag Block information */
#define RFAL_ISODEP_SPARAM_TAG_BRREQ (0xA1U) /*!< S(PARAMETERS) tag Bit rates Request */
#define RFAL_ISODEP_SPARAM_TAG_BRIND (0xA2U) /*!< S(PARAMETERS) tag Bit rates Indication */
#define RFAL_ISODEP_SPARAM_TAG_BRACT (0xA3U) /*!< S(PARAMETERS) tag Bit rates Activation */
#define RFAL_ISODEP_SPARAM_TAG_BRACK (0xA4U) /*!< S(PARAMETERS) tag Bit rates Acknowledgement */
#define RFAL_ISODEP_SPARAM_TAG_SUP_PCD2PICC (0x80U) /*!< S(PARAMETERS) tag Supported bit rates from PCD to PICC */
#define RFAL_ISODEP_SPARAM_TAG_SUP_PICC2PCD (0x81U) /*!< S(PARAMETERS) tag Supported bit rates from PICC to PCD */
#define RFAL_ISODEP_SPARAM_TAG_SUP_FRAME (0x82U) /*!< S(PARAMETERS) tag Supported framing options PICC to PCD */
#define RFAL_ISODEP_SPARAM_TAG_SEL_PCD2PICC (0x83U) /*!< S(PARAMETERS) tag Selected bit rate from PCD to PICC */
#define RFAL_ISODEP_SPARAM_TAG_SEL_PICC2PCD (0x84U) /*!< S(PARAMETERS) tag Selected bit rate from PICC to PCD */
#define RFAL_ISODEP_SPARAM_TAG_SEL_FRAME (0x85U) /*!< S(PARAMETERS) tag Selected framing options PICC to PCD */
#define RFAL_ISODEP_SPARAM_TAG_LEN (1) /*!< S(PARAMETERS) Tag Length */
#define RFAL_ISODEP_SPARAM_TAG_BRREQ_LEN (0U) /*!< S(PARAMETERS) tag Bit rates Request Length */
#define RFAL_ISODEP_SPARAM_TAG_PICC2PCD_LEN (2U) /*!< S(PARAMETERS) bit rates from PCD to PICC Length */
#define RFAL_ISODEP_SPARAM_TAG_PCD2PICC_LEN (2U) /*!< S(PARAMETERS) bit rates from PICC to PCD Length */
#define RFAL_ISODEP_SPARAM_TAG_BRACK_LEN (0U) /*!< S(PARAMETERS) tag Bit rates Acknowledgement Length */
#define RFAL_ISODEP_ATS_TA_DPL_212 (0x01U) /*!< ATS TA DSI 212 kbps support bit mask */
#define RFAL_ISODEP_ATS_TA_DPL_424 (0x02U) /*!< ATS TA DSI 424 kbps support bit mask */
#define RFAL_ISODEP_ATS_TA_DPL_848 (0x04U) /*!< ATS TA DSI 848 kbps support bit mask */
#define RFAL_ISODEP_ATS_TA_DLP_212 (0x10U) /*!< ATS TA DSI 212 kbps support bit mask */
#define RFAL_ISODEP_ATS_TA_DLP_424 (0x20U) /*!< ATS TA DRI 424 kbps support bit mask */
#define RFAL_ISODEP_ATS_TA_DLP_848 (0x40U) /*!< ATS TA DRI 848 kbps support bit mask */
#define RFAL_ISODEP_ATS_TA_SAME_D (0x80U) /*!< ATS TA same bit both directions bit mask */
#define RFAL_ISODEP_ATS_TB_FWI_MASK (0xF0U) /*!< Mask bits for FWI (Frame Waiting Integer) in TB byte */
#define RFAL_ISODEP_ATS_TB_SFGI_MASK (0x0FU) /*!< Mask bits for SFGI (Start-Up Frame Guard Integer) in TB byte */
#define RFAL_ISODEP_ATS_T0_TA_PRESENCE_MASK (0x10U) /*!< Mask bit for TA presence */
#define RFAL_ISODEP_ATS_T0_TB_PRESENCE_MASK (0x20U) /*!< Mask bit for TB presence */
#define RFAL_ISODEP_ATS_T0_TC_PRESENCE_MASK (0x40U) /*!< Mask bit for TC presence */
#define RFAL_ISODEP_ATS_T0_FSCI_MASK (0x0FU) /*!< Mask bit for FSCI presence */
#define RFAL_ISODEP_ATS_T0_OFFSET (0x01U) /*!< Offset of T0 in ATS Response */
#define RFAL_ISODEP_MAX_I_RETRYS (2U) /*!< Number of retries for a I-Block Digital 1.1 15.2.5.4 */
#define RFAL_ISODEP_MAX_R_RETRYS (3U) /*!< Number of retries for a R-Block Digital 1.1 A8 - nRETRY ACK/NAK: [2,5] */
#define RFAL_ISODEP_MAX_S_RETRYS (3U) /*!< Number of retries for a S-Block Digital 1.1 A8 - nRETRY DESELECT: [0,5] WTX[2,5] */
#define RFAL_ISODEP_RATS_RETRIES (1U) /*!< RATS retries upon fail Digital 1.1 A.6 - [0,1] */
/*! Frame Size for Proximity Card Integer definitions */
typedef enum
{
RFAL_ISODEP_FSXI_16 = 0, /*!< Frame Size for Proximity Card Integer with 16 bytes */
RFAL_ISODEP_FSXI_24 = 1, /*!< Frame Size for Proximity Card Integer with 24 bytes */
RFAL_ISODEP_FSXI_32 = 2, /*!< Frame Size for Proximity Card Integer with 32 bytes */
RFAL_ISODEP_FSXI_40 = 3, /*!< Frame Size for Proximity Card Integer with 40 bytes */
RFAL_ISODEP_FSXI_48 = 4, /*!< Frame Size for Proximity Card Integer with 48 bytes */
RFAL_ISODEP_FSXI_64 = 5, /*!< Frame Size for Proximity Card Integer with 64 bytes */
RFAL_ISODEP_FSXI_96 = 6, /*!< Frame Size for Proximity Card Integer with 96 bytes */
RFAL_ISODEP_FSXI_128 = 7, /*!< Frame Size for Proximity Card Integer with 128 bytes */
RFAL_ISODEP_FSXI_256 = 8, /*!< Frame Size for Proximity Card Integer with 256 bytes */
RFAL_ISODEP_FSXI_512 = 9, /*!< Frame Size for Proximity Card Integer with 512 bytes ISO14443-3 Amd2 2012 */
RFAL_ISODEP_FSXI_1024 = 10, /*!< Frame Size for Proximity Card Integer with 1024 bytes ISO14443-3 Amd2 2012 */
RFAL_ISODEP_FSXI_2048 = 11, /*!< Frame Size for Proximity Card Integer with 2048 bytes ISO14443-3 Amd2 2012 */
RFAL_ISODEP_FSXI_4096 = 12 /*!< Frame Size for Proximity Card Integer with 4096 bytes ISO14443-3 Amd2 2012 */
} rfalIsoDepFSxI;
/*! Frame Size for Proximity Card definitions */
typedef enum
{
RFAL_ISODEP_FSX_16 = 16, /*!< Frame Size for Proximity Card with 16 bytes */
RFAL_ISODEP_FSX_24 = 24, /*!< Frame Size for Proximity Card with 24 bytes */
RFAL_ISODEP_FSX_32 = 32, /*!< Frame Size for Proximity Card with 32 bytes */
RFAL_ISODEP_FSX_40 = 40, /*!< Frame Size for Proximity Card with 40 bytes */
RFAL_ISODEP_FSX_48 = 48, /*!< Frame Size for Proximity Card with 48 bytes */
RFAL_ISODEP_FSX_64 = 64, /*!< Frame Size for Proximity Card with 64 bytes */
RFAL_ISODEP_FSX_96 = 96, /*!< Frame Size for Proximity Card with 96 bytes */
RFAL_ISODEP_FSX_128 = 128, /*!< Frame Size for Proximity Card with 128 bytes */
RFAL_ISODEP_FSX_256 = 256, /*!< Frame Size for Proximity Card with 256 bytes */
RFAL_ISODEP_FSX_512 = 512, /*!< Frame Size for Proximity Card with 512 bytes ISO14443-3 Amd2 2012 */
RFAL_ISODEP_FSX_1024 = 1024, /*!< Frame Size for Proximity Card with 1024 bytes ISO14443-3 Amd2 2012 */
RFAL_ISODEP_FSX_2048 = 2048, /*!< Frame Size for Proximity Card with 2048 bytes ISO14443-3 Amd2 2012 */
RFAL_ISODEP_FSX_4096 = 4096, /*!< Frame Size for Proximity Card with 4096 bytes ISO14443-3 Amd2 2012 */
} rfalIsoDepFSx;
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
/*
******************************************************************************
* GLOBAL DATA TYPES
******************************************************************************
*/
/*! RATS format Digital 1.1 13.6.1 */
typedef struct
{
uint8_t CMD; /*!< RATS command byte: 0xE0 */
uint8_t PARAM; /*!< Param indicating FSDI and DID */
} rfalIsoDepRats;
/*! ATS response format Digital 1.1 13.6.2 */
typedef struct
{
uint8_t TL; /*!< Length Byte, including TL byte itself */
uint8_t T0; /*!< Format Byte T0 indicating if TA, TB, TC */
uint8_t TA; /*!< Interface Byte TA(1) */
uint8_t TB; /*!< Interface Byte TB(1) */
uint8_t TC; /*!< Interface Byte TC(1) */
uint8_t HB[RFAL_ISODEP_ATS_HB_MAX_LEN]; /*!< Historical Bytes */
} rfalIsoDepAts;
/*! PPS Request format (Protocol and Parameter Selection) ISO14443-4 5.3 */
typedef struct
{
uint8_t PPSS; /*!< Start Byte: [ 1101b | CID[4b] ] */
uint8_t PPS0; /*!< Parameter 0:[ 000b | PPS1[1n] | 0001b ] */
uint8_t PPS1; /*!< Parameter 1:[ 0000b | DSI[2b] | DRI[2b] ]*/
} rfalIsoDepPpsReq;
/*! PPS Response format (Protocol and Parameter Selection) ISO14443-4 5.4 */
typedef struct
{
uint8_t PPSS; /*!< Start Byte: [ 1101b | CID[4b] ] */
} rfalIsoDepPpsRes;
/*! ATTRIB Command Format Digital 1.1 15.6.1 */
typedef struct
{
uint8_t cmd; /*!< ATTRIB_REQ command byte */
uint8_t nfcid0[RFAL_NFCB_NFCID0_LEN]; /*!< NFCID0 of the card to be selected */
struct{
uint8_t PARAM1; /*!< PARAM1 of ATTRIB command */
uint8_t PARAM2; /*!< PARAM2 of ATTRIB command */
uint8_t PARAM3; /*!< PARAM3 of ATTRIB command */
uint8_t PARAM4; /*!< PARAM4 of ATTRIB command */
}Param; /*!< Parameter of ATTRIB command */
uint8_t HLInfo[RFAL_ISODEP_ATTRIB_HLINFO_LEN]; /*!< Higher Layer Information */
} rfalIsoDepAttribCmd;
/*! ATTRIB Response Format Digital 1.1 15.6.2 */
typedef struct
{
uint8_t mbliDid; /*!< Contains MBLI and DID */
uint8_t HLInfo[RFAL_ISODEP_ATTRIB_HLINFO_LEN]; /*!< Higher Layer Information */
} rfalIsoDepAttribRes;
/*! S(Parameters) Command Format ISO14443-4 (2016) Table 4 */
typedef struct
{
uint8_t tag; /*!< S(PARAMETERS) Tag field */
uint8_t length; /*!< S(PARAMETERS) Length field */
uint8_t value[RFAL_ISODEP_SPARAM_VALUES_MAX_LEN]; /*!< S(PARAMETERS) Value field */
} rfalIsoDepSParameter;
/*! Activation info as Poller and Listener for NFC-A and NFC-B */
typedef union {/* PRQA S 0750 # MISRA 19.2 - Both members of the union will not be used concurrently, device is only of type A or B at a time. Thus no problem can occur. */
/*! NFC-A information */
union {/* PRQA S 0750 # MISRA 19.2 - Both members of the union will not be used concurrently, device is only PCD or PICC at a time. Thus no problem can occur. */
struct {
rfalIsoDepAts ATS; /*!< ATS response (Poller mode) */
uint8_t ATSLen; /*!< ATS response length (Poller mode) */
}Listener;
struct {
rfalIsoDepRats RATS; /*!< RATS request (Listener mode) */
}Poller;
}A;
/*! NFC-B information */
union {/* PRQA S 0750 # MISRA 19.2 - Both members of the union will not be used concurrently, device is only PCD or PICC at a time. Thus no problem can occur. */
struct{
rfalIsoDepAttribRes ATTRIB_RES; /*!< ATTRIB_RES (Poller mode) */
uint8_t ATTRIB_RESLen; /*!< ATTRIB_RES length (Poller mode) */
}Listener;
struct{
rfalIsoDepAttribCmd ATTRIB; /*!< ATTRIB request (Listener mode) */
uint8_t ATTRIBLen; /*!< ATTRIB request length (Listener mode) */
}Poller;
}B;
}rfalIsoDepActivation;
/*! ISO-DEP device Info */
typedef struct {
uint8_t FWI; /*!< Frame Waiting Integer */
uint32_t FWT; /*!< Frame Waiting Time (1/fc) */
uint32_t dFWT; /*!< Delta Frame Waiting Time (1/fc) */
uint32_t SFGI; /*!< Start-up Frame Guard time Integer */
uint32_t SFGT; /*!< Start-up Frame Guard Time (ms) */
uint8_t FSxI; /*!< Frame Size Device/Card Integer (FSDI or FSCI) */
uint16_t FSx; /*!< Frame Size Device/Card (FSD or FSC) */
uint32_t MBL; /*!< Maximum Buffer Length (optional for NFC-B) */
rfalBitRate DSI; /*!< Bit Rate coding from Listener (PICC) to Poller (PCD) */
rfalBitRate DRI; /*!< Bit Rate coding from Poller (PCD) to Listener (PICC) */
uint8_t DID; /*!< Device ID */
uint8_t NAD; /*!< Node ADdress */
bool supDID; /*!< DID supported flag */
bool supNAD; /*!< NAD supported flag */
bool supAdFt; /*!< Advanced Features supported flag */
} rfalIsoDepInfo;
/*! ISO-DEP Device structure */
typedef struct {
rfalIsoDepActivation activation; /*!< Activation Info */
rfalIsoDepInfo info; /*!< ISO-DEP (ISO14443-4) device Info */
} rfalIsoDepDevice;
/*! ATTRIB Response parameters */
typedef struct
{
uint8_t mbli; /*!< MBLI */
uint8_t HLInfo[RFAL_ISODEP_ATTRIB_HLINFO_LEN]; /*!< Hi Layer Information */
uint8_t HLInfoLen; /*!< Hi Layer Information Length */
} rfalIsoDepAttribResParam;
/*! ATS Response parameter */
typedef struct
{
uint8_t fsci; /*!< Frame Size of Proximity Card Integer */
uint8_t fwi; /*!< Frame Waiting Time Integer */
uint8_t sfgi; /*!< Start-Up Frame Guard Time Integer */
bool didSupport; /*!< DID Supported */
uint8_t ta; /*!< Max supported bitrate both direction */
uint8_t *hb; /*!< Historical Bytes data */
uint8_t hbLen; /*!< Historical Bytes Length */
} rfalIsoDepAtsParam;
/*! Structure of I-Block Buffer format from caller */
typedef struct
{
uint8_t prologue[RFAL_ISODEP_PROLOGUE_SIZE]; /*!< Prologue/SoD buffer */
uint8_t inf[RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN]; /*!< INF/Payload buffer */
} rfalIsoDepBufFormat;
/*! Structure of APDU Buffer format from caller */
typedef struct
{
uint8_t prologue[RFAL_ISODEP_PROLOGUE_SIZE]; /*!< Prologue/SoD buffer */
uint8_t apdu[RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN]; /*!< APDU/Payload buffer */
} rfalIsoDepApduBufFormat;
/*! Listen Activation Parameters Structure */
typedef struct
{
rfalIsoDepBufFormat *rxBuf; /*!< Receive Buffer struct reference */
uint16_t *rxLen; /*!< Received INF data length in Bytes */
bool *isRxChaining; /*!< Received data is not complete */
rfalIsoDepDevice *isoDepDev; /*!< ISO-DEP device info */
} rfalIsoDepListenActvParam;
/*! Structure of parameters used on ISO DEP Transceive */
typedef struct
{
rfalIsoDepBufFormat *txBuf; /*!< Transmit Buffer struct reference */
uint16_t txBufLen; /*!< Transmit Buffer INF field length in Bytes*/
bool isTxChaining; /*!< Transmit data is not complete */
rfalIsoDepBufFormat *rxBuf; /*!< Receive Buffer struct reference in Bytes */
uint16_t *rxLen; /*!< Received INF data length in Bytes */
bool *isRxChaining; /*!< Received data is not complete */
uint32_t FWT; /*!< FWT to be used (ignored in Listen Mode) */
uint32_t dFWT; /*!< Delta FWT to be used */
uint16_t ourFSx; /*!< Our device Frame Size (FSD or FSC) */
uint16_t FSx; /*!< Other device Frame Size (FSD or FSC) */
uint8_t DID; /*!< Device ID (RFAL_ISODEP_NO_DID if no DID) */
} rfalIsoDepTxRxParam;
/*! Structure of parameters used on ISO DEP APDU Transceive */
typedef struct
{
rfalIsoDepApduBufFormat *txBuf; /*!< Transmit Buffer struct reference */
uint16_t txBufLen; /*!< Transmit Buffer INF field length in Bytes*/
rfalIsoDepApduBufFormat *rxBuf; /*!< Receive Buffer struct reference in Bytes */
uint16_t *rxLen; /*!< Received INF data length in Bytes */
rfalIsoDepBufFormat *tmpBuf; /*!< Temp buffer for Rx I-Blocks (internal) */
uint32_t FWT; /*!< FWT to be used (ignored in Listen Mode) */
uint32_t dFWT; /*!< Delta FWT to be used */
uint16_t FSx; /*!< Other device Frame Size (FSD or FSC) */
uint16_t ourFSx; /*!< Our device Frame Size (FSD or FSC) */
uint8_t DID; /*!< Device ID (RFAL_ISODEP_NO_DID if no DID) */
} rfalIsoDepApduTxRxParam;
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
******************************************************************************
* \brief Initialize the ISO-DEP protocol
*
* Initialize the ISO-DEP protocol layer with default config
******************************************************************************
*/
void rfalIsoDepInitialize( void );
/*!
******************************************************************************
* \brief Initialize the ISO-DEP protocol
*
* Initialize the ISO-DEP protocol layer with additional parameters allowing
* to customise the protocol layer for specific behaviours
*
* \param[in] compMode : compliance mode to be performed
* \param[in] maxRetriesR : Number of retries for a R-Block
* \param[in] maxRetriesS : Number of retries for a S-Block
* \param[in] maxRetriesI : Number of retries for a I-Block
* \param[in] maxRetriesRATS : Number of retries for RATS
*
******************************************************************************
*/
void rfalIsoDepInitializeWithParams( rfalComplianceMode compMode, uint8_t maxRetriesR, uint8_t maxRetriesS, uint8_t maxRetriesI, uint8_t maxRetriesRATS );
/*!
*****************************************************************************
* \brief FSxI to FSx
*
* Convert Frame Size for proximity coupling Device Integer (FSxI) to
* Frame Size for proximity coupling Device (FSx)
*
* FSD - maximum frame size for NFC Forum Device in Poll Mode
* FSC - maximum frame size for NFC Forum Device in Listen Mode
*
* FSxI = FSDI or FSCI
* FSx = FSD or FSC
*
* The FSD/FSC value includes the header and CRC
*
* \param[in] FSxI : Frame Size for proximity coupling Device Integer
*
* \return fsx : Frame Size for proximity coupling Device (FSD or FSC)
*
*****************************************************************************
*/
uint16_t rfalIsoDepFSxI2FSx( uint8_t FSxI );
/*!
*****************************************************************************
* \brief FWI to FWT
*
* Convert Frame Waiting time Integer (FWI) to Frame Waiting Time (FWT) in
* 1/fc units
*
* \param[in] fwi : Frame Waiting time Integer
*
* \return fwt : Frame Waiting Time in 1/fc units
*
*****************************************************************************
*/
uint32_t rfalIsoDepFWI2FWT( uint8_t fwi );
/*!
*****************************************************************************
* \brief Check if the buffer data contains a valid RATS command
*
* Check if it is a well formed RATS command with 2 bytes
* This function does not check the validity of FSDI and DID
*
* \param[in] buf : reference to buffer containing the data to be checked
* \param[in] bufLen : length of data in the buffer in bytes
*
* \return true if the data indicates a RATS command; false otherwise
*****************************************************************************
*/
bool rfalIsoDepIsRats( const uint8_t *buf, uint8_t bufLen );
/*!
*****************************************************************************
* \brief Check if the buffer data contains a valid ATTRIB command
*
* Check if it is a well formed ATTRIB command, but does not check the
* validity of the information inside
*
* \param[in] buf : reference to buffer containing the data to be checked
* \param[in] bufLen : length of data in the buffer in bytes
*
* \return true if the data indicates a ATTRIB command; false otherwise
*****************************************************************************
*/
bool rfalIsoDepIsAttrib( const uint8_t *buf, uint8_t bufLen );
/*!
*****************************************************************************
* \brief Start Listen Activation Handling
*
* Start Listen Activation Handling and setup to receive first I-block which may
* contain complete or partial APDU after activation is completed
*
* Pass in RATS for T4AT, or ATTRIB for T4BT, to handle ATS or ATTRIB Response respectively
* The Activation Handling handles ATS and ATTRIB Response; and additionally PPS Response
* if a PPS is received for T4AT.
* The method uses the current RFAL state machine to determine if it is expecting RATS or ATTRIB
*
* Activation is completed if PPS Response is sent or if first PDU is received in T4T-A
* Activation is completed if ATTRIB Response is sent in T4T-B
*
* \ref rfalIsoDepListenGetActivationStatus provide status if activation is completed.
* \ref rfalIsoDepStartTransceive shall be called right after activation is completed
*
* \param[in] atsParam : reference to ATS parameters
* \param[in] attribResParam : reference to ATTRIB_RES parameters
* \param[in] buf : reference to buffer containing RATS or ATTRIB
* \param[in] bufLen : length in bytes of the given bufffer
* \param[in] actParam : reference to incoming reception information will be placed
*
*
* \warning Once the Activation has been completed the method
* rfalIsoDepGetTransceiveStatus() must be called.
* If activation has completed due to reception of a data block (not PPS) the
* buffer owned by the caller and passed on actParam must still contain this data.
* The first data will be processed (I-Block or S-DSL) by rfalIsoDepGetTransceiveStatus()
* inform the caller and then for the next transaction use rfalIsoDepStartTransceive()
*
* \return ERR_NONE : RATS/ATTRIB is valid and activation has started
* \return ERR_PARAM : Invalid parameters
* \return ERR_PROTO : Invalid request
* \return ERR_NOTSUPP : Feature not supported
*****************************************************************************
*/
ReturnCode rfalIsoDepListenStartActivation( rfalIsoDepAtsParam *atsParam, const rfalIsoDepAttribResParam *attribResParam, uint8_t *buf, uint16_t bufLen, rfalIsoDepListenActvParam actParam );
/*!
*****************************************************************************
* \brief Get the current Activation Status
*
* \return ERR_NONE if Activation is already completed
* \return ERR_BUSY if Activation is ongoing
* \return ERR_LINK_LOSS if Remote Field is turned off
*****************************************************************************
*/
ReturnCode rfalIsoDepListenGetActivationStatus( void );
/*!
*****************************************************************************
* \brief Get the ISO-DEP Communication Information
*
* Gets the maximum INF length in bytes based on current Frame Size
* for proximity coupling Device (FSD or FSC) excluding the header and CRC
*
* \return maximum INF length in bytes
*****************************************************************************
*/
uint16_t rfalIsoDepGetMaxInfLen( void );
/*!
*****************************************************************************
* \brief ISO-DEP Start Transceive
*
* This method triggers a ISO-DEP Transceive containing a complete or
* partial APDU
* It transmits the given message and handles all protocol retransmitions,
* error handling and control messages
*
* The txBuf contains a complete or partial APDU (INF) to be transmitted
* The Prologue field will be manipulated by the Transceive
*
* If the buffer contains a partial APDU and is not the last block,
* then isTxChaining must be set to true
*
* \param[in] param: reference parameters to be used for the Transceive
*
* \return ERR_PARAM : Bad request
* \return ERR_WRONG_STATE : The module is not in a proper state
* \return ERR_NONE : The Transceive request has been started
*****************************************************************************
*/
ReturnCode rfalIsoDepStartTransceive( rfalIsoDepTxRxParam param );
/*!
*****************************************************************************
* \brief Get the Transceive status
*
* Returns the status of the ISO-DEP Transceive
*
* \warning When the other device is performing chaining once a chained
* block is received the error ERR_AGAIN is sent. At this point
* caller must handle the received data immediately.
* When ERR_AGAIN is returned an ACK has already been sent to
* the other device and the next block might be incoming.
* If rfalWorker() is called frequently it will place the next
* block on the given buffer
*
*
* \return ERR_NONE : Transceive has been completed successfully
* \return ERR_BUSY : Transceive is ongoing
* \return ERR_PROTO : Protocol error occurred
* \return ERR_TIMEOUT : Timeout error occurred
* \return ERR_SLEEP_REQ : Deselect has been received and responded
* \return ERR_NOMEM : The received INF does not fit into the
* receive buffer
* \return ERR_LINK_LOSS : Communication is lost because Reader/Writer
* has turned off its field
* \return ERR_AGAIN : received one chaining block, continue to call
* this method to retrieve the remaining blocks
*****************************************************************************
*/
ReturnCode rfalIsoDepGetTransceiveStatus( void );
/*!
*****************************************************************************
* \brief ISO-DEP Start APDU Transceive
*
* This method triggers a ISO-DEP Transceive containing a complete APDU
* It transmits the given message and handles all protocol retransmitions,
* error handling and control messages
*
* The txBuf contains a complete APDU to be transmitted
* The Prologue field will be manipulated by the Transceive
*
* \warning the txBuf will be modified during the transmission
* \warning the maximum RF frame which can be received is limited by param.tmpBuf
*
* \param[in] param: reference parameters to be used for the Transceive
*
* \return ERR_PARAM : Bad request
* \return ERR_WRONG_STATE : The module is not in a proper state
* \return ERR_NONE : The Transceive request has been started
*****************************************************************************
*/
ReturnCode rfalIsoDepStartApduTransceive( rfalIsoDepApduTxRxParam param );
/*!
*****************************************************************************
* \brief Get the APDU Transceive status
*
* \return ERR_NONE : if Transceive has been completed successfully
* \return ERR_BUSY : if Transceive is ongoing
* \return ERR_PROTO : if a protocol error occurred
* \return ERR_TIMEOUT : if a timeout error occurred
* \return ERR_SLEEP_REQ : if Deselect is received and responded
* \return ERR_NOMEM : if the received INF does not fit into the
* receive buffer
* \return ERR_LINK_LOSS : if communication is lost because Reader/Writer
* has turned off its field
*****************************************************************************
*/
ReturnCode rfalIsoDepGetApduTransceiveStatus( void );
/*!
*****************************************************************************
* \brief ISO-DEP Send RATS
*
* This sends a RATS to make a NFC-A Listen Device to enter
* ISO-DEP layer (ISO14443-4) and checks if the received ATS is valid
*
* \param[in] FSDI : Frame Size Device Integer to be used
* \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID
* \param[out] ats : pointer to place the ATS Response
* \param[out] atsLen : pointer to place the ATS length
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error
* \return ERR_PAR : Parity error detected
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error, ATS received
*****************************************************************************
*/
ReturnCode rfalIsoDepRATS( rfalIsoDepFSxI FSDI, uint8_t DID, rfalIsoDepAts *ats , uint8_t *atsLen );
/*!
*****************************************************************************
* \brief ISO-DEP Send PPS
*
* This sends a PPS to make a NFC-A Listen Device change the communications
* bit rate from 106kbps to one of the supported bit rates
* Additionally checks if the received PPS response is valid
*
* \param[in] DID : Device ID
* \param[in] DSI : DSI code the divisor from Listener (PICC) to Poller (PCD)
* \param[in] DRI : DRI code the divisor from Poller (PCD) to Listener (PICC)
* \param[out] ppsRes : pointer to place the PPS Response
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error
* \return ERR_PAR : Parity error detected
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error, PPS Response received
*****************************************************************************
*/
ReturnCode rfalIsoDepPPS( uint8_t DID, rfalBitRate DSI, rfalBitRate DRI, rfalIsoDepPpsRes *ppsRes );
/*!
*****************************************************************************
* \brief ISO-DEP Send ATTRIB
*
* This sends a ATTRIB to make a NFC-B Listen Device to enter
* ISO-DEP layer (ISO14443-4) and checks if the received ATTRIB Response is valid
*
* \param[in] nfcid0 : NFCID0 to be used for the ATTRIB
* \param[in] PARAM1 : ATTRIB PARAM1 byte (communication parameters)
* \param[in] DSI : DSI code the divisor from Listener (PICC) to Poller (PCD)
* \param[in] DRI : DRI code the divisor from Poller (PCD) to Listener (PICC)
* \param[in] FSDI : PCD's Frame Size to be announced on the ATTRIB
* \param[in] PARAM3 : ATTRIB PARAM1 byte (protocol type)
* \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID
* \param[in] HLInfo : pointer to Higher layer INF (NULL if none)
* \param[in] HLInfoLen : Length HLInfo
* \param[in] fwt : Frame Waiting Time to be used (from SENSB_RES)
* \param[out] attribRes : pointer to place the ATTRIB Response
* \param[out] attribResLen : pointer to place the ATTRIB Response length
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error, ATTRIB Response received
*****************************************************************************
*/
ReturnCode rfalIsoDepATTRIB( const uint8_t* nfcid0, uint8_t PARAM1, rfalBitRate DSI, rfalBitRate DRI, rfalIsoDepFSxI FSDI, uint8_t PARAM3, uint8_t DID, const uint8_t* HLInfo, uint8_t HLInfoLen, uint32_t fwt, rfalIsoDepAttribRes *attribRes, uint8_t *attribResLen );
/*!
*****************************************************************************
* \brief Deselects PICC
*
* This function sends a deselect command to PICC and waits for it`s
* responce in a blocking way
*
* \return ERR_NONE : Deselect successfully sent and acknowledged by PICC
* \return ERR_TIMEOUT: No response rcvd from PICC
*
*****************************************************************************
*/
ReturnCode rfalIsoDepDeselect( void );
/*!
*****************************************************************************
* \brief ISO-DEP Poller Handle NFC-A Activation
*
* This performs a NFC-A Activation into ISO-DEP layer (ISO14443-4) with the given
* parameters. It sends RATS and if the higher bit rates are supported by
* both devices it additionally sends PPS
* Once Activated all details of the device are provided on isoDepDev
*
* \param[in] FSDI : Frame Size Device Integer to be used
* \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID
* \param[in] maxBR : Max bit rate supported by the Poller
* \param[out] isoDepDev : ISO-DEP information of the activated Listen device
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error
* \return ERR_PAR : Parity error detected
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error, activation successful
*****************************************************************************
*/
ReturnCode rfalIsoDepPollAHandleActivation( rfalIsoDepFSxI FSDI, uint8_t DID, rfalBitRate maxBR, rfalIsoDepDevice *isoDepDev );
/*!
*****************************************************************************
* \brief ISO-DEP Poller Handle NFC-B Activation
*
* This performs a NFC-B Activation into ISO-DEP layer (ISO14443-4) with the given
* parameters. It sends ATTRIB and calculates supported higher bit rates of both
* devices and performs activation.
* Once Activated all details of the device are provided on isoDepDev
*
* \param[in] FSDI : Frame Size Device Integer to be used
* \param[in] DID : Device ID to be used or RFAL_ISODEP_NO_DID for not use DID
* \param[in] maxBR : Max bit rate supported by the Poller
* \param[in] PARAM1 : ATTRIB PARAM1 byte (communication parameters)
* \param[in] nfcbDev : pointer to the NFC-B Device containing the SENSB_RES
* \param[in] HLInfo : pointer to Higher layer INF (NULL if none)
* \param[in] HLInfoLen : Length HLInfo
* \param[out] isoDepDev : ISO-DEP information of the activated Listen device
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error
* \return ERR_PAR : Parity error detected
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error, activation successful
*****************************************************************************
*/
ReturnCode rfalIsoDepPollBHandleActivation( rfalIsoDepFSxI FSDI, uint8_t DID, rfalBitRate maxBR, uint8_t PARAM1, const rfalNfcbListenDevice *nfcbDev, const uint8_t* HLInfo, uint8_t HLInfoLen, rfalIsoDepDevice *isoDepDev );
/*!
*****************************************************************************
* \brief ISO-DEP Poller Handle S(Parameters)
*
* This checks if PICC supports S(PARAMETERS), retieves PICC's
* capabilities and sets the Bit Rate at the highest supported by both
* devices
*
* \param[out] isoDepDev : ISO-DEP information of the activated Listen device
* \param[in] maxTxBR : Maximum Tx bit rate supported by PCD
* \param[in] maxRxBR : Maximum Rx bit rate supported by PCD
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error, S(PARAMETERS) selection successful
*****************************************************************************
*/
ReturnCode rfalIsoDepPollHandleSParameters( rfalIsoDepDevice *isoDepDev, rfalBitRate maxTxBR, rfalBitRate maxRxBR );
#endif /* RFAL_ISODEP_H_ */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,406 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_nfc.h
*
* \brief RFAL NFC device
*
* This module provides the required features to behave as an NFC Poller
* or Listener device. It grants an easy to use interface for the following
* activities: Technology Detection, Collision Resolution, Activation,
* Data Exchange, and Deactivation
*
* This layer is influenced by (but not fully aligned with) the NFC Forum
* specifications, in particular: Activity 2.0 and NCI 2.0
*
*
*
* \addtogroup RFAL
* @{
*
* \addtogroup RFAL-AL
* \brief RFAL Abstraction Layer
* @{
*
* \addtogroup RF
* \brief RFAL RF Abstraction Layer
* @{
*
*/
#ifndef RFAL_NFC_H
#define RFAL_NFC_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
#include "st_errno.h"
#include "rfal_rf.h"
#include "rfal_nfca.h"
#include "rfal_nfcb.h"
#include "rfal_nfcf.h"
#include "rfal_nfcv.h"
#include "rfal_st25tb.h"
#include "rfal_nfcDep.h"
#include "rfal_isoDep.h"
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_NFC_RF_BUF_LEN 255U /*!< No technology */
#define RFAL_NFC_TECH_NONE 0x0000U /*!< No technology */
#define RFAL_NFC_POLL_TECH_A 0x0001U /*!< NFC-A technology Flag */
#define RFAL_NFC_POLL_TECH_B 0x0002U /*!< NFC-B technology Flag */
#define RFAL_NFC_POLL_TECH_F 0x0004U /*!< NFC-F technology Flag */
#define RFAL_NFC_POLL_TECH_V 0x0008U /*!< NFC-V technology Flag */
#define RFAL_NFC_POLL_TECH_AP2P 0x0010U /*!< AP2P technology Flag */
#define RFAL_NFC_POLL_TECH_ST25TB 0x0020U /*!< ST25TB technology Flag */
#define RFAL_NFC_LISTEN_TECH_A 0x1000U /*!< NFC-V technology Flag */
#define RFAL_NFC_LISTEN_TECH_B 0x2000U /*!< NFC-V technology Flag */
#define RFAL_NFC_LISTEN_TECH_F 0x4000U /*!< NFC-V technology Flag */
#define RFAL_NFC_LISTEN_TECH_AP2P 0x8000U /*!< NFC-V technology Flag */
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
/*! Checks if a device is currently activated */
#define rfalNfcIsDevActivated( st ) ( ((st)>= RFAL_NFC_STATE_ACTIVATED) && ((st)<RFAL_NFC_STATE_DEACTIVATION) )
/*! Checks if a device is in discovery */
#define rfalNfcIsInDiscovery( st ) ( ((st)>= RFAL_NFC_STATE_START_DISCOVERY) && ((st)<RFAL_NFC_STATE_ACTIVATED) )
/*
******************************************************************************
* GLOBAL ENUMS
******************************************************************************
*/
/*
******************************************************************************
* GLOBAL TYPES
******************************************************************************
*/
/*! Main state */
typedef enum{
RFAL_NFC_STATE_NOTINIT = 0, /*!< Not Initialized state */
RFAL_NFC_STATE_IDLE = 1, /*!< Initialize state */
RFAL_NFC_STATE_START_DISCOVERY = 2, /*!< Start Discovery loop state */
RFAL_NFC_STATE_WAKEUP_MODE = 3, /*!< Wake-Up state */
RFAL_NFC_STATE_POLL_TECHDETECT = 10, /*!< Technology Detection state */
RFAL_NFC_STATE_POLL_COLAVOIDANCE = 11, /*!< Collision Avoidance state */
RFAL_NFC_STATE_POLL_SELECT = 12, /*!< Wait for Selection state */
RFAL_NFC_STATE_POLL_ACTIVATION = 13, /*!< Activation state */
RFAL_NFC_STATE_LISTEN_TECHDETECT = 20, /*!< Listen Tech Detect */
RFAL_NFC_STATE_LISTEN_COLAVOIDANCE = 21, /*!< Listen Collision Avoidance */
RFAL_NFC_STATE_LISTEN_ACTIVATION = 22, /*!< Listen Activation state */
RFAL_NFC_STATE_LISTEN_SLEEP = 23, /*!< Listen Sleep state */
RFAL_NFC_STATE_ACTIVATED = 30, /*!< Activated state */
RFAL_NFC_STATE_DATAEXCHANGE = 31, /*!< Data Exchange Start state */
RFAL_NFC_STATE_DATAEXCHANGE_DONE = 33, /*!< Data Exchange terminated */
RFAL_NFC_STATE_DEACTIVATION = 34 /*!< Deactivation state */
}rfalNfcState;
/*! Device type */
typedef enum{
RFAL_NFC_LISTEN_TYPE_NFCA = 0, /*!< NFC-A Listener device type */
RFAL_NFC_LISTEN_TYPE_NFCB = 1, /*!< NFC-B Listener device type */
RFAL_NFC_LISTEN_TYPE_NFCF = 2, /*!< NFC-F Listener device type */
RFAL_NFC_LISTEN_TYPE_NFCV = 3, /*!< NFC-V Listener device type */
RFAL_NFC_LISTEN_TYPE_ST25TB = 4, /*!< ST25TB Listener device type */
RFAL_NFC_LISTEN_TYPE_AP2P = 5, /*!< AP2P Listener device type */
RFAL_NFC_POLL_TYPE_NFCA = 10, /*!< NFC-A Poller device type */
RFAL_NFC_POLL_TYPE_NFCB = 11, /*!< NFC-B Poller device type */
RFAL_NFC_POLL_TYPE_NFCF = 12, /*!< NFC-F Poller device type */
RFAL_NFC_POLL_TYPE_NFCV = 13, /*!< NFC-V Poller device type */
RFAL_NFC_POLL_TYPE_AP2P = 15 /*!< AP2P Poller device type */
}rfalNfcDevType;
/*! Device interface */
typedef enum{
RFAL_NFC_INTERFACE_RF = 0, /*!< RF Frame interface */
RFAL_NFC_INTERFACE_ISODEP = 1, /*!< ISO-DEP interface */
RFAL_NFC_INTERFACE_NFCDEP = 2 /*!< NFC-DEP interface */
}rfalNfcRfInterface;
/*! Device struct containing all its details */
typedef struct{
rfalNfcDevType type; /*!< Device's type */
union{ /* PRQA S 0750 # MISRA 19.2 - Members of the union will not be used concurrently, only one technology at a time */
rfalNfcaListenDevice nfca; /*!< NFC-A Listen Device instance */
rfalNfcbListenDevice nfcb; /*!< NFC-B Listen Device instance */
rfalNfcfListenDevice nfcf; /*!< NFC-F Listen Device instance */
rfalNfcvListenDevice nfcv; /*!< NFC-V Listen Device instance */
rfalSt25tbListenDevice st25tb; /*!< ST25TB Listen Device instance*/
}dev; /*!< Device's instance */
uint8_t *nfcid; /*!< Device's NFCID */
uint8_t nfcidLen; /*!< Device's NFCID length */
rfalNfcRfInterface rfInterface; /*!< Device's interface */
union{ /* PRQA S 0750 # MISRA 19.2 - Members of the union will not be used concurrently, only one protocol at a time */
rfalIsoDepDevice isoDep; /*!< ISO-DEP instance */
rfalNfcDepDevice nfcDep; /*!< NFC-DEP instance */
}proto; /*!< Device's protocol */
}rfalNfcDevice;
/*! Discovery parameters */
typedef struct{
rfalComplianceMode compMode; /*!< Compliancy mode to be used */
uint16_t techs2Find; /*!< Technologies to search for */
uint16_t totalDuration; /*!< Duration of a whole Poll + Listen cycle */
uint8_t devLimit; /*!< Max number of devices */
rfalBitRate nfcfBR; /*!< Bit rate to poll for NFC-F */
uint8_t nfcid3[RFAL_NFCDEP_NFCID3_LEN]; /*!< NFCID3 to be used on the ATR_REQ/ATR_RES */
uint8_t GB[RFAL_NFCDEP_GB_MAX_LEN]; /*!< General bytes to be used on the ATR-REQ */
uint8_t GBLen; /*!< Length of the General Bytes */
rfalBitRate ap2pBR; /*!< Bit rate to poll for AP2P */
rfalLmConfPA lmConfigPA; /*!< Configuration for Passive Listen mode NFC-A */
rfalLmConfPF lmConfigPF; /*!< Configuration for Passive Listen mode NFC-A */
void (*notifyCb)( rfalNfcState st ); /*!< Callback to Notify upper layer */
bool wakeupEnabled; /*!< Enable Wake-Up mode before polling */
bool wakeupConfigDefault; /*!< Wake-Up mode default configuration */
rfalWakeUpConfig wakeupConfig; /*!< Wake-Up mode configuration */
}rfalNfcDiscoverParam;
/*! Buffer union, only one interface is used at a time */
typedef union{ /* PRQA S 0750 # MISRA 19.2 - Members of the union will not be used concurrently, only one interface at a time */
uint8_t rfBuf[RFAL_NFC_RF_BUF_LEN]; /*!< RF buffer */
rfalIsoDepBufFormat isoDepBuf; /*!< ISO-DEP Tx buffer format (with header/prologue) */
rfalNfcDepBufFormat nfcDepBuf; /*!< NFC-DEP Rx buffer format (with header/prologue) */
}rfalNfcBuffer;
/*******************************************************************************/
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief RFAL NFC Worker
*
* It runs the internal state machine and runs the RFAL RF worker.
*****************************************************************************
*/
void rfalNfcWorker( void );
/*!
*****************************************************************************
* \brief RFAL NFC Initialize
*
* It initializes this module and its dependencies
*
* \return ERR_WRONG_STATE : Incorrect state for this operation
* \return ERR_IO : Generic internal error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcInitialize( void );
/*!
*****************************************************************************
* \brief RFAL NFC Discovery
*
* It set the device in Discovery state.
* In discovery it will Poll and/or Listen for the technologies configured,
* and perform Wake-up mode if configured to do so.
*
* The device list passed on disParams must not be empty.
* The number of devices on the list is indicated by the devLimit and shall
* be at >= 1.
*
* \param[in] disParams : discovery configuration parameters
*
* \return ERR_WRONG_STATE : Incorrect state for this operation
* \return ERR_PARAM : Invalid parameters
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcDiscover( const rfalNfcDiscoverParam *disParams );
/*!
*****************************************************************************
* \brief RFAL NFC Get State
*
* It returns the current state
*
* \return rfalNfcState : the current state
*****************************************************************************
*/
rfalNfcState rfalNfcGetState( void );
/*!
*****************************************************************************
* \brief RFAL NFC Get Devices Found
*
* It returns the location of the device list and the number of
* devices found.
*
* \param[out] devList : device list location
* \param[out] devCnt : number of devices found
*
* \return ERR_WRONG_STATE : Incorrect state for this operation
* Discovery still ongoing
* \return ERR_PARAM : Invalid parameters
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcGetDevicesFound( rfalNfcDevice **devList, uint8_t *devCnt );
/*!
*****************************************************************************
* \brief RFAL NFC Get Active Device
*
* It returns the location of the device current Active device
*
* \param[out] dev : device info location
*
* \return ERR_WRONG_STATE : Incorrect state for this operation
* No device activated
* \return ERR_PARAM : Invalid parameters
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcGetActiveDevice( rfalNfcDevice **dev );
/*!
*****************************************************************************
* \brief RFAL NFC Select Device
*
* It selects the device to be activated.
* It shall be called when more than one device has been identified to
* indiacte which device shall be actived
*
* \param[in] devIdx : device index to be activated
*
* \return ERR_WRONG_STATE : Incorrect state for this operation
* Not in select state
* \return ERR_PARAM : Invalid parameters
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcSelect( uint8_t devIdx );
/*!
*****************************************************************************
* \brief RFAL NFC Start Data Exchange
*
* After a device has been activated, it starts a data exchange.
* It handles automatically which interface/protocol to be used and acts accordingly.
*
* In Listen mode the first frame/data shall be sent by the Reader/Initiator
* therefore this method must be called first with txDataLen set to zero
* to retrieve the rxData and rcvLen locations.
*
*
* \param[in] txData : data to be transmitted
* \param[in] txDataLen : size of the data to be transmitted
* \param[out] rxData : location of the received data after operation is completed
* \param[out] rvdLen : location of thelength of the received data
* \param[in] fwt : FWT to be used in case of RF interface.
* If ISO-DEP or NFC-DEP interface is used, this will be ignored
*
* \return ERR_WRONG_STATE : Incorrect state for this operation
* \return ERR_PARAM : Invalid parameters
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcDataExchangeStart( uint8_t *txData, uint16_t txDataLen, uint8_t **rxData, uint16_t **rvdLen, uint32_t fwt );
/*!
*****************************************************************************
* \brief RFAL NFC Get Data Exchange Status
*
* Gets current Data Exchange status
*
* \return ERR_NONE : Transceive done with no error
* \return ERR_BUSY : Transceive ongoing
* \return ERR_AGAIN : received one chaining block, copy received data
* and continue to call this method to retrieve the
* remaining blocks
* \return ERR_XXXX : Error occurred
* \return ERR_TIMEOUT : No response
* \return ERR_FRAMING : Framing error detected
* \return ERR_PAR : Parity error detected
* \return ERR_CRC : CRC error detected
* \return ERR_LINK_LOSS : Link Loss - External Field is Off
* \return ERR_RF_COLLISION : Collision detected
* \return ERR_IO : Internal error
*****************************************************************************
*/
ReturnCode rfalNfcDataExchangeGetStatus( void );
/*!
*****************************************************************************
* \brief RFAL NFC Deactivate
*
* It triggers the deactivation procedure to terminate communications with
* remote device. At the end the field will be turned off.
*
* \param[in] discovery : TRUE if after deactivation go back into discovery
* : FALSE if after deactivation remain in idle
*
* \return ERR_WRONG_STATE : Incorrect state for this operation
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcDeactivate( bool discovery );
#endif /* RFAL_NFC_H */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,700 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_nfcDep.h
*
* \author Gustavo Patricio
*
* \brief Implementation of NFC-DEP protocol
*
* NFC-DEP is also known as NFCIP - Near Field Communication
* Interface and Protocol
*
* This implementation was based on the following specs:
* - NFC Forum Digital 1.1
* - ECMA 340 3rd Edition 2013
*
*
* \addtogroup RFAL
* @{
*
* \addtogroup RFAL-AL
* \brief RFAL Abstraction Layer
* @{
*
* \addtogroup NFC-DEP
* \brief RFAL NFC-DEP Module
* @{
*/
#ifndef RFAL_NFCDEP_H_
#define RFAL_NFCDEP_H_
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
#include "st_errno.h"
#include "rfal_rf.h"
/*
******************************************************************************
* DEFINES
******************************************************************************
*/
#define RFAL_NFCDEP_FRAME_SIZE_MAX_LEN 254U /*!< NFCIP Maximum Frame Size Digital 1.0 Table 91 */
#define RFAL_NFCDEP_DEPREQ_HEADER_LEN 5U /*!< DEP_REQ header length: CMD_TYPE + CMD_CMD + PBF + DID + NAD */
/*! Length NFCIP DEP REQ or RES header (incl LEN) */
#define RFAL_NFCDEP_DEP_HEADER ( RFAL_NFCDEP_LEN_LEN + RFAL_NFCDEP_CMDTYPE_LEN + RFAL_NFCDEP_CMD_LEN + RFAL_NFCDEP_DEP_PFB_LEN )
#define RFAL_NFCDEP_HEADER ( RFAL_NFCDEP_CMDTYPE_LEN + RFAL_NFCDEP_CMD_LEN ) /*!< NFCIP header length */
#define RFAL_NFCDEP_SB_LEN 1U /*!< SB length on NFCIP fram for NFC-A */
#define RFAL_NFCDEP_LEN_LEN 1U /*!< LEN length on NFCIP frame */
#define RFAL_NFCDEP_CMDTYPE_LEN 1U /*!< Length of the cmd type (REQ | RES) on NFCIP frame */
#define RFAL_NFCDEP_CMD_LEN 1U /*!< Length of the cmd on NFCIP frame */
#define RFAL_NFCDEP_DID_LEN 1U /*!< Length of did on NFCIP frame */
#define RFAL_NFCDEP_DEP_PFB_LEN 1U /*!< Length of the PFB field on NFCIP frame */
#define RFAL_NFCDEP_DSL_RLS_LEN_NO_DID (RFAL_NFCDEP_LEN_LEN + RFAL_NFCDEP_CMDTYPE_LEN + RFAL_NFCDEP_CMD_LEN) /*!< Length of DSL_REQ and RLS_REQ with no DID */
#define RFAL_NFCDEP_DSL_RLS_LEN_DID (RFAL_NFCDEP_DSL_RLS_LEN_NO_DID + RFAL_NFCDEP_DID_LEN) /*!< Length of DSL_REQ and RLS_REQ with DID */
#define RFAL_NFCDEP_FS_VAL_MIN 64U /*!< Minimum LR value */
#define RFAL_NFCDEP_LR_VAL_MASK 0x03U /*!< Bit mask for a LR value */
#define RFAL_NFCDEP_PP_LR_MASK 0x30U /*!< Bit mask for LR value in PP byte on a ATR REQ/RES */
#define RFAL_NFCDEP_PP_LR_SHIFT 4U /*!< Position of LR value in PP byte on a ATR REQ/RES */
#define RFAL_NFCDEP_DID_MAX 14U /*!< Max DID value Digital 14.6.2.3 */
#define RFAL_NFCDEP_DID_KEEP 0xFFU /*!< Keep DID value already configured */
#define RFAL_NFCDEP_DID_NO 0x00U /*!< No DID shall be used */
#define RFAL_NFCDEP_NAD_NO 0x00U /*!< No NAD shall be used */
#define RFAL_NFCDEP_OPER_RTOX_REQ_DIS 0x01U /*!< Operation config: RTOX REQ disable */
#define RFAL_NFCDEP_OPER_RTOX_REQ_EN 0x00U /*!< Operation config: RTOX REQ enable */
#define RFAL_NFCDEP_OPER_ATN_DIS 0x00U /*!< Operation config: ATN disable */
#define RFAL_NFCDEP_OPER_ATN_EN 0x02U /*!< Operation config: ATN enable */
#define RFAL_NFCDEP_OPER_EMPTY_DEP_DIS 0x04U /*!< Operation config: empty DEPs disable */
#define RFAL_NFCDEP_OPER_EMPTY_DEP_EN 0x00U /*!< Operation config: empty DEPs enable */
#define RFAL_NFCDEP_OPER_FULL_MI_DIS 0x00U /*!< Operation config: full chaining DEPs disable */
#define RFAL_NFCDEP_OPER_FULL_MI_EN 0x08U /*!< Operation config: full chaining DEPs enable */
#define RFAL_NFCDEP_BRS_MAINTAIN 0xC0U /*!< Value signalling that BR is to be maintained (no PSL) */
#define RFAL_NFCDEP_BRS_Dx_MASK 0x07U /*!< Value signalling that BR is to be maintained (no PSL) */
#define RFAL_NFCDEP_BRS_DSI_POS 3U /*!< Value signalling that BR is to be maintained (no PSL) */
#define RFAL_NFCDEP_WT_DELTA (16U - RFAL_NFCDEP_WT_DELTA_ADJUST) /*!< NFC-DEP dWRT (adjusted) Digital 2.0 B.10 */
#define RFAL_NFCDEP_WT_DELTA_ADJUST 4U /*!< dWRT value adjustment */
#define RFAL_NFCDEP_ATR_REQ_NFCID3_POS 2U /*!< NFCID3 offset in ATR_REQ frame */
#define RFAL_NFCDEP_NFCID3_LEN 10U /*!< NFCID3 Length */
#define RFAL_NFCDEP_LEN_MIN 3U /*!< Minimum length byte LEN value */
#define RFAL_NFCDEP_LEN_MAX 255U /*!< Maximum length byte LEN value */
#define RFAL_NFCDEP_ATRRES_HEADER_LEN 2U /*!< ATR RES Header Len: CmdType: 0xD5 + Cod: 0x01 */
#define RFAL_NFCDEP_ATRRES_MIN_LEN 17U /*!< Minimum length for an ATR RES */
#define RFAL_NFCDEP_ATRRES_MAX_LEN 64U /*!< Maximum length for an ATR RES Digital 1.0 14.6.1 */
#define RFAL_NFCDEP_ATRREQ_MIN_LEN 16U /*!< Minimum length for an ATR REQ */
#define RFAL_NFCDEP_ATRREQ_MAX_LEN RFAL_NFCDEP_ATRRES_MAX_LEN /*!< Maximum length for an ATR REQ Digital 1.0 14.6.1 */
#define RFAL_NFCDEP_GB_MAX_LEN (RFAL_NFCDEP_ATRREQ_MAX_LEN - RFAL_NFCDEP_ATRREQ_MIN_LEN) /*!< Maximum length the General Bytes on ATR Digital 1.1 16.6.3 */
#define RFAL_NFCDEP_WT_INI_DEFAULT RFAL_NFCDEP_WT_INI_MAX /*!< WT Initiator default value Digital 1.0 14.6.3.8 */
#define RFAL_NFCDEP_WT_INI_MIN 0U /*!< WT Initiator minimum value Digital 1.0 14.6.3.8 */
#define RFAL_NFCDEP_WT_INI_MAX 14U /*!< WT Initiator maximum value Digital 1.0 14.6.3.8 A.10 */
#define RFAL_NFCDEP_RWT_INI_MAX rfalNfcDepWT2RWT( RFAL_NFCDEP_WT_INI_MAX ) /*!< RWT Initiator maximum value */
#define RFAL_NFCDEP_WT_TRG_MAX_D10 8U /*!< WT target max Digital 1.0 14.6.3.8 A.10 */
#define RFAL_NFCDEP_WT_TRG_MAX_D11 14U /*!< WT target max Digital 1.1 16.6.3.9 A.9 */
#define RFAL_NFCDEP_WT_TRG_MAX RFAL_NFCDEP_WT_TRG_MAX_D11 /*!< WT target max Digital x.x */
#define RFAL_NFCDEP_RWT_TRG_MAX rfalNfcDepWT2RWT( RFAL_NFCDEP_WT_TRG_MAX ) /*!< RWT Initiator maximum value */
/*! Maximum Frame Waiting Time = ((256 * 16/fc)*2^FWImax) = ((256*16/fc)*2^14) = (1048576 / 64)/fc = (100000h*64)/fc */
#define RFAL_NFCDEP_MAX_FWT ((uint32_t)1U<<20)
#define RFAL_NFCDEP_WT_MASK 0x0FU /*!< Bit mask for the Wait Time value */
#define RFAL_NFCDEP_BR_MASK_106 0x01U /*!< Enable mask bit rate 106 */
#define RFAL_NFCDEP_BR_MASK_212 0x02U /*!< Enable mask bit rate 242 */
#define RFAL_NFCDEP_BR_MASK_424 0x04U /*!< Enable mask bit rate 424 */
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
#define rfalNfcDepWT2RWT( wt ) ( (uint32_t)1U << (((uint32_t)(wt) & RFAL_NFCDEP_WT_MASK) + 12U) ) /*!< Converts WT value to RWT (1/fc) */
/*! Returns the BRS value from the given bit rate */
#define rfalNfcDepDx2BRS( br ) ( (((uint8_t)(br) & RFAL_NFCDEP_BRS_Dx_MASK) << RFAL_NFCDEP_BRS_DSI_POS) | ((uint8_t)(br) & RFAL_NFCDEP_BRS_Dx_MASK) )
#define rfalNfcDepBRS2DRI( brs ) (uint8_t)( (uint8_t)(brs) & RFAL_NFCDEP_BRS_Dx_MASK ) /*!< Returns the DRI value from the given BRS byte */
#define rfalNfcDepBRS2DSI( brs ) (uint8_t)( ((uint8_t)(brs) >> RFAL_NFCDEP_BRS_DSI_POS) & RFAL_NFCDEP_BRS_Dx_MASK ) /*!< Returns the DSI value from the given BRS byte */
#define rfalNfcDepPP2LR( PPx ) ( ((uint8_t)(PPx) & RFAL_NFCDEP_PP_LR_MASK ) >> RFAL_NFCDEP_PP_LR_SHIFT) /*!< Returns the LR value from the given PPx byte */
#define rfalNfcDepLR2PP( LRx ) ( ((uint8_t)(LRx) << RFAL_NFCDEP_PP_LR_SHIFT) & RFAL_NFCDEP_PP_LR_MASK) /*!< Returns the PP byte with the given LRx value */
/*! Returns the Frame size value from the given LRx value */
#define rfalNfcDepLR2FS( LRx ) (uint16_t)(MIN( (RFAL_NFCDEP_FS_VAL_MIN * ((uint16_t)(LRx) + 1U) ), RFAL_NFCDEP_FRAME_SIZE_MAX_LEN ))
/*!
* Despite DIGITAL 1.0 14.6.2.1 stating that the last two bytes may filled with
* any value, some devices (Samsung Google Nexus) only accept when these are 0 */
#define rfalNfcDepSetNFCID( dst, src, len ) ST_MEMSET( (dst), 0x00, RFAL_NFCDEP_NFCID3_LEN ); \
if( (len) > 0U ) {ST_MEMCPY( (dst), (src), (len) );}
/*
******************************************************************************
* GLOBAL ENUMERATIONS
******************************************************************************
*/
/*! Enumeration of NFC-DEP bit rate in ATR Digital 1.0 Table 93 and 94 */
enum{
RFAL_NFCDEP_Bx_NO_HIGH_BR = 0x00, /*!< Peer supports no high bit rates */
RFAL_NFCDEP_Bx_08_848 = 0x01, /*!< Peer also supports 848 */
RFAL_NFCDEP_Bx_16_1695 = 0x02, /*!< Peer also supports 1695 */
RFAL_NFCDEP_Bx_32_3390 = 0x04, /*!< Peer also supports 3390 */
RFAL_NFCDEP_Bx_64_6780 = 0x08 /*!< Peer also supports 6780 */
};
/*! Enumeration of NFC-DEP bit rate Dividor in PSL Digital 1.0 Table 100 */
enum{
RFAL_NFCDEP_Dx_01_106 = RFAL_BR_106, /*!< Divisor D = 1 : bit rate = 106 */
RFAL_NFCDEP_Dx_02_212 = RFAL_BR_212, /*!< Divisor D = 2 : bit rate = 212 */
RFAL_NFCDEP_Dx_04_424 = RFAL_BR_424, /*!< Divisor D = 4 : bit rate = 424 */
RFAL_NFCDEP_Dx_08_848 = RFAL_BR_848, /*!< Divisor D = 8 : bit rate = 848 */
RFAL_NFCDEP_Dx_16_1695 = RFAL_BR_1695, /*!< Divisor D = 16 : bit rate = 1695 */
RFAL_NFCDEP_Dx_32_3390 = RFAL_BR_3390, /*!< Divisor D = 32 : bit rate = 3390 */
RFAL_NFCDEP_Dx_64_6780 = RFAL_BR_6780 /*!< Divisor D = 64 : bit rate = 6780 */
};
/*! Enumeration of NFC-DEP Length Reduction (LR) Digital 1.0 Table 91 */
enum{
RFAL_NFCDEP_LR_64 = 0x00, /*!< Maximum payload size is 64 bytes */
RFAL_NFCDEP_LR_128 = 0x01, /*!< Maximum payload size is 128 bytes */
RFAL_NFCDEP_LR_192 = 0x02, /*!< Maximum payload size is 192 bytes */
RFAL_NFCDEP_LR_254 = 0x03 /*!< Maximum payload size is 254 bytes */
};
/*
******************************************************************************
* GLOBAL DATA TYPES
******************************************************************************
*/
/*! NFC-DEP callback to check if upper layer has deactivation pending */
typedef bool (* rfalNfcDepDeactCallback)(void);
/*! Enumeration of the nfcip communication modes */
typedef enum{
RFAL_NFCDEP_COMM_PASSIVE, /*!< Passive communication mode */
RFAL_NFCDEP_COMM_ACTIVE /*!< Active communication mode */
} rfalNfcDepCommMode;
/*! Enumeration of the nfcip roles */
typedef enum{
RFAL_NFCDEP_ROLE_INITIATOR, /*!< Perform as Initiator */
RFAL_NFCDEP_ROLE_TARGET /*!< Perform as Target */
} rfalNfcDepRole;
/*! Struct that holds all NFCIP configs */
typedef struct{
rfalNfcDepRole role; /*!< Current NFCIP role */
rfalNfcDepCommMode commMode; /*!< Current NFCIP communication mode */
uint8_t oper; /*!< Operation config similar to NCI 1.0 Table 81 */
uint8_t did; /*!< Current Device ID (DID) */
uint8_t nad; /*!< Current Node Addressing (NAD) */
uint8_t bs; /*!< Bit rate in Sending Direction */
uint8_t br; /*!< Bit rate in Receiving Direction */
uint8_t nfcid[RFAL_NFCDEP_NFCID3_LEN]; /*!< Pointer to the NFCID to be used */
uint8_t nfcidLen; /*!< Length of the given NFCID in nfcid */
uint8_t gb[RFAL_NFCDEP_GB_MAX_LEN]; /*!< Pointer General Bytes (GB) to be used */
uint8_t gbLen; /*!< Length of the given GB in gb */
uint8_t lr; /*!< Length Reduction (LR) to be used */
uint8_t to; /*!< Timeout (TO) to be used */
uint32_t fwt; /*!< Frame Waiting Time (FWT) to be used */
uint32_t dFwt; /*!< Delta Frame Waiting Time (dFWT) to be used */
} rfalNfcDepConfigs;
/*! ATR_REQ command Digital 1.1 16.6.2 */
typedef struct {
uint8_t CMD1; /*!< Command format 0xD4 */
uint8_t CMD2; /*!< Command Value */
uint8_t NFCID3[RFAL_NFCDEP_NFCID3_LEN]; /*!< NFCID3 value */
uint8_t DID; /*!< DID */
uint8_t BSi; /*!< Sending Bitrate for Initiator */
uint8_t BRi; /*!< Receiving Bitrate for Initiator */
uint8_t PPi; /*!< Optional Parameters presence indicator */
uint8_t GBi[RFAL_NFCDEP_GB_MAX_LEN]; /*!< General Bytes */
} rfalNfcDepAtrReq;
/*! ATR_RES response Digital 1.1 16.6.3 */
typedef struct {
uint8_t CMD1; /*!< Response Byte 0xD5 */
uint8_t CMD2; /*!< Command Value */
uint8_t NFCID3[RFAL_NFCDEP_NFCID3_LEN]; /*!< NFCID3 value */
uint8_t DID; /*!< DID */
uint8_t BSt; /*!< Sending Bitrate for Initiator */
uint8_t BRt; /*!< Receiving Bitrate for Initiator */
uint8_t TO; /*!< Timeout */
uint8_t PPt; /*!< Optional Parameters presence indicator */
uint8_t GBt[RFAL_NFCDEP_GB_MAX_LEN]; /*!< General Bytes */
} rfalNfcDepAtrRes;
/*! Structure of transmit I-PDU Buffer format from caller */
typedef struct
{
uint8_t prologue[RFAL_NFCDEP_DEPREQ_HEADER_LEN]; /*!< Prologue space for NFC-DEP header*/
uint8_t inf[RFAL_NFCDEP_FRAME_SIZE_MAX_LEN]; /*!< INF | Data area of the buffer */
} rfalNfcDepBufFormat;
/*! Activation info as Initiator and Target */
typedef union { /* PRQA S 0750 # MISRA 19.2 - Both members of the union will not be used concurrently , device is only initiatior or target a time. No problem can occur. */
struct {
rfalNfcDepAtrRes ATR_RES; /*!< ATR RES (Initiator mode) */
uint8_t ATR_RESLen; /*!< ATR RES length (Initiator mode) */
}Target; /*!< Target */
struct {
rfalNfcDepAtrReq ATR_REQ; /*!< ATR REQ (Target mode) */
uint8_t ATR_REQLen; /*!< ATR REQ length (Target mode) */
}Initiator; /*!< Initiator */
} rfalNfcDepActivation;
/*! NFC-DEP device Info */
typedef struct {
uint8_t GBLen; /*!< General Bytes length */
uint8_t WT; /*!< WT to be used (ignored in Listen Mode) */
uint32_t FWT; /*!< FWT to be used (1/fc)(ignored Listen Mode) */
uint32_t dFWT; /*!< Delta FWT to be used (1/fc) */
uint8_t LR; /*!< Length Reduction coding the max payload */
uint16_t FS; /*!< Frame Size */
rfalBitRate DSI; /*!< Bit Rate coding from Initiator to Target */
rfalBitRate DRI; /*!< Bit Rate coding from Target to Initiator */
uint8_t DID; /*!< Device ID (RFAL_NFCDEP_DID_NO if no DID) */
uint8_t NAD; /*!< Node ADdress (RFAL_NFCDEP_NAD_NO if no NAD)*/
} rfalNfcDepInfo;
/*! NFC-DEP Device structure */
typedef struct {
rfalNfcDepActivation activation; /*!< Activation Info */
rfalNfcDepInfo info; /*!< NFC-DEP device Info */
} rfalNfcDepDevice;
/*! NFCIP Protocol structure for P2P Target
*
* operParam : derives from NFC-Forum NCI NFC-DEP Operation Parameter
* NCI 1.1 Table 86: NFC-DEP Operation Parameter
* and it's a bit mask composed as:
* [ 0000b
* | Chain SHALL use max. Transport Data Byte[1b]
* | I-PDU with no Transport Data SHALL NOT be sent [1b]
* | NFC-DEP Target SHALL NOT send RTOX request [1b]
* ]
*
*/
typedef struct{
rfalNfcDepCommMode commMode; /*!< Initiator in Active P2P or Passive P2P*/
uint8_t operParam; /*!< NFC-DEP Operation Parameter */
uint8_t* nfcid; /*!< Initiator's NFCID2 or NFCID3 */
uint8_t nfcidLen; /*!< Initiator's NFCID length (NFCID2/3) */
uint8_t DID; /*!< Initiator's Device ID DID */
uint8_t NAD; /*!< Initiator's Node ID NAD */
uint8_t BS; /*!< Initiator's Bit Rates supported in Tx */
uint8_t BitRate; /*!< Initiator's Bit Rates supported in Rx */
uint8_t LR; /*!< Initiator's Length reduction */
uint8_t* GB; /*!< Initiator's General Bytes (Gi) */
uint8_t GBLen; /*!< Initiator's General Bytes length */
} rfalNfcDepAtrParam;
/*! Structure of parameters to be passed in for nfcDepListenStartActivation */
typedef struct
{
rfalNfcDepBufFormat *rxBuf; /*!< Receive Buffer struct reference */
uint16_t *rxLen; /*!< Receive INF data length in bytes */
bool *isRxChaining; /*!< Received data is not complete */
rfalNfcDepDevice *nfcDepDev; /*!< NFC-DEP device info */
} rfalNfcDepListenActvParam;
/*! NFCIP Protocol structure for P2P Target
*
* operParam : derives from NFC-Forum NCI NFC-DEP Operation Parameter
* NCI 1.1 Table 86: NFC-DEP Operation Parameter
* and it's a bit mask composed as:
* [ 0000b
* | Chain SHALL use max. Transport Data Byte[1b]
* | I-PDU with no Transport Data SHALL NOT be sent [1b]
* | NFC-DEP Target SHALL NOT send RTOX request [1b]
* ]
*
*/
typedef struct{
rfalNfcDepCommMode commMode; /*!< Target in Active P2P or Passive P2P */
uint8_t nfcid3[RFAL_NFCDEP_NFCID3_LEN]; /*!< Target's NFCID3 */
uint8_t bst; /*!< Target's Bit Rates supported in Tx */
uint8_t brt; /*!< Target's Bit Rates supported in Rx */
uint8_t to; /*!< Target's timeout (TO) value */
uint8_t ppt; /*!< Target's Presence optional Params(PPt)*/
uint8_t GBt[RFAL_NFCDEP_GB_MAX_LEN]; /*!< Target's General Bytes (Gt) */
uint8_t GBtLen; /*!< Target's General Bytes length */
uint8_t operParam; /*!< NFC-DEP Operation Parameter */
} rfalNfcDepTargetParam;
/*! Structure of parameters to be passed in for nfcDepStartIpduTransceive */
typedef struct
{
rfalNfcDepBufFormat *txBuf; /*!< Transmit Buffer struct reference */
uint16_t txBufLen; /*!< Transmit Buffer INF field length in bytes */
bool isTxChaining; /*!< Transmit data is not complete */
rfalNfcDepBufFormat *rxBuf; /*!< Receive Buffer struct reference */
uint16_t *rxLen; /*!< Receive INF data length */
bool *isRxChaining; /*!< Received data is not complete */
uint32_t FWT; /*!< FWT to be used (ignored in Listen Mode) */
uint32_t dFWT; /*!< Delta FWT to be used */
uint16_t FSx; /*!< Other device Frame Size (FSD or FSC) */
uint8_t DID; /*!< Device ID (RFAL_ISODEP_NO_DID if no DID) */
} rfalNfcDepTxRxParam;
/*
* *****************************************************************************
* GLOBAL VARIABLE DECLARATIONS
******************************************************************************
*/
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
******************************************************************************
* \brief NFCIP Initialize
*
* This method resets all NFC-DEP inner states, counters and context and sets
* default values
*
******************************************************************************
*/
void rfalNfcDepInitialize( void );
/*!
******************************************************************************
* \brief Set deactivating callback
*
* Sets the deactivating callback so that nfcip layer can check if upper layer
* has a deactivation pending, and not perform error recovery upon specific
* errors
*
* \param[in] pFunc : method pointer to deactivation flag check
******************************************************************************
*/
void rfalNfcDepSetDeactivatingCallback( rfalNfcDepDeactCallback pFunc );
/*!
******************************************************************************
* \brief Calculate Response Waiting Time
*
* Calculates the Response Waiting Time (RWT) from the given Waiting Time (WT)
*
* \param[in] wt : the WT value to calculate RWT
*
* \return RWT value in 1/fc
******************************************************************************
*/
uint32_t rfalNfcDepCalculateRWT( uint8_t wt );
/*!
******************************************************************************
* \brief NFC-DEP Initiator ATR (Attribute Request)
*
* This method configures the NFC-DEP layer with given parameters and then
* sends an ATR to the Target with and checks for a valid response response
*
* \param[in] param : parameters to initialize and compose the ATR
* \param[out] atrRes : location to store the ATR_RES
* \param[out] atrResLen : length of the ATR_RES received
*
* \return ERR_NONE : No error
* \return ERR_TIMEOUT : Timeout occurred
* \return ERR_PROTO : Protocol error occurred
******************************************************************************
*/
ReturnCode rfalNfcDepATR( const rfalNfcDepAtrParam* param, rfalNfcDepAtrRes *atrRes, uint8_t* atrResLen );
/*!
******************************************************************************
* \brief NFC-DEP Initiator PSL (Parameter Selection)
*
* This method sends a PSL to the Target with the given parameters and checks
* for a valid response response
*
* The parameters must be coded according to Digital 1.1 16.7.1
*
* \param[in] BRS : the selected Bit Rates for Initiator and Target
* \param[in] FSL : the maximum length of Commands and Responses
*
* \return ERR_NONE : No error
* \return ERR_TIMEOUT : Timeout occurred
* \return ERR_PROTO : Protocol error occurred
******************************************************************************
*/
ReturnCode rfalNfcDepPSL( uint8_t BRS, uint8_t FSL );
/*!
******************************************************************************
* \brief NFC-DEP Initiator DSL (Deselect)
*
* This method checks if the NFCIP module is configured as initiator and if
* so sends a DSL REQ, waits the target's response and checks it
*
* In case of performing as target no action is taken
*
* \return ERR_NONE : No error
* \return ERR_TIMEOUT : Timeout occurred
* \return ERR_MAX_RERUNS : Timeout occurred
* \return ERR_PROTO : Protocol error occurred
******************************************************************************
*/
ReturnCode rfalNfcDepDSL( void );
/*!
******************************************************************************
* \brief NFC-DEP Initiator RLS (Release)
*
* This method checks if the NFCIP module is configured as initiator and if
* so sends a RLS REQ, waits target's response and checks it
*
* In case of performing as target no action is taken
*
* \return ERR_NONE : No error
* \return ERR_TIMEOUT : Timeout occurred
* \return ERR_MAX_RERUNS : Timeout occurred
* \return ERR_PROTO : Protocol error occurred
******************************************************************************
*/
ReturnCode rfalNfcDepRLS( void );
/*!
*****************************************************************************
* \brief NFC-DEP Initiator Handle Activation
*
* This performs a Activation into NFC-DEP layer with the given
* parameters. It sends ATR_REQ and if the higher bit rates are supported by
* both devices it additionally sends PSL
* Once Activated all details of the device are provided on nfcDepDev
*
* \param[in] param : required parameters to initialize and send ATR_REQ
* \param[in] desiredBR : Desired bit rate supported by the Poller
* \param[out] nfcDepDev : NFC-DEP information of the activated Listen device
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error
* \return ERR_PAR : Parity error detected
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error, activation successful
*****************************************************************************
*/
ReturnCode rfalNfcDepInitiatorHandleActivation( rfalNfcDepAtrParam* param, rfalBitRate desiredBR, rfalNfcDepDevice* nfcDepDev );
/*!
******************************************************************************
* \brief Check if buffer contains valid ATR_REQ
*
* This method checks if the given ATR_REQ is valid
*
*
* \param[in] buf : buffer holding Initiator's received request
* \param[in] bufLen : size of the msg contained on the buf in Bytes
* \param[out] nfcid3 : pointer to where the NFCID3 may be outputed,
* nfcid3 has NFCF_SENSF_NFCID3_LEN as length
* Pass NULL if output parameter not desired
*
* \return true : Valid ATR_REQ received, the ATR_RES has been computed in txBuf
* \return false : Invalid protocol request
*
******************************************************************************
*/
bool rfalNfcDepIsAtrReq( const uint8_t* buf, uint16_t bufLen, uint8_t* nfcid3 );
/*!
******************************************************************************
* \brief Check is Target has received ATR
*
* This method checks if the NFCIP module is configured as target and if a
* ATR REQ has been received ( whether is in activation or in data exchange)
*
* \return true : a ATR has already been received
* \return false : no ATR has been received
******************************************************************************
*/
bool rfalNfcDepTargetRcvdATR( void );
/*!
*****************************************************************************
* \brief NFCDEP Start Listen Activation Handling
*
* Start Activation Handling and setup to receive first frame which may
* contain complete or partial DEP-REQ after activation is completed
*
* Pass in ATR_REQ for NFC-DEP to handle ATR_RES. The Activation Handling
* handles ATR_RES and PSL_RES if a PSL_REQ is received
*
* Activation is completed if PSL_RES is sent or if first I-PDU is received
*
* \ref rfalNfcDepListenGetActivationStatus() provide status of the
* ongoing activation
*
* \warning nfcDepGetTransceiveStatus() shall be called right after activation
* is completed (i.e. rfalNfcDepListenGetActivationStatus() return ERR_NONE)
* to check for first received frame.
*
* \param[in] param : Target parameters to be used
* \param[in] atrReq : reference to buffer containing ATR_REQ
* \param[in] atrReqLength: Length of ATR_REQ
* \param[out] rxParam : references to buffer, length and chaining indication
* for first complete LLCP to be received
*
* \return ERR_NONE : ATR_REQ is valid and activation ongoing
* \return ERR_PARAM : ATR_REQ or other params are invalid
* \return ERR_LINK_LOSS : Remote Field is turned off
*****************************************************************************
*/
ReturnCode rfalNfcDepListenStartActivation( const rfalNfcDepTargetParam *param, const uint8_t *atrReq, uint16_t atrReqLength, rfalNfcDepListenActvParam rxParam );
/*!
*****************************************************************************
* \brief Get the current NFC-DEP Activation Status
*
* \return ERR_NONE : Activation has completed successfully
* \return ERR_BUSY : Activation is ongoing
* \return ERR_LINK_LOSS : Remote Field was turned off
*****************************************************************************
*/
ReturnCode rfalNfcDepListenGetActivationStatus( void );
/*!
*****************************************************************************
* \brief Start Transceive
*
* Transceives a complete or partial DEP block
*
* The txBuf contains complete or partial of DEP to be transmitted.
* The Prologue field of the I-PDU is handled internally
*
* If the buffer contains partial LLCP and is not the last block, then
* isTxChaining must be set to true
*
* \param[in] param: reference parameters to be used for the Transceive
*
* \return ERR_PARAM : Bad request
* \return ERR_WRONG_STATE : The module is not in a proper state
* \return ERR_NONE : The Transceive request has been started
*****************************************************************************
*/
ReturnCode rfalNfcDepStartTransceive( rfalNfcDepTxRxParam *param );
/*!
*****************************************************************************
* \brief Return the Transceive status
*
* Returns the status of the NFC-DEP Transceive
*
* \warning When the other device is performing chaining once a chained
* block is received the error ERR_AGAIN is sent. At this point
* caller must handle the received data immediately.
* When ERR_AGAIN is returned an ACK has already been sent to
* the other device and the next block might be incoming.
* If rfalWorker() is called frequently it will place the next
* block on the given buffer
*
* \return ERR_NONE : Transceive has been completed successfully
* \return ERR_BUSY : Transceive is ongoing
* \return ERR_PROTO : Protocol error occurred
* \return ERR_TIMEOUT : Timeout error occurred
* \return ERR_SLEEP_REQ : Deselect has been received and responded
* \return ERR_NOMEM : The received I-PDU does not fit into the
* receive buffer
* \return ERR_LINK_LOSS : Communication is lost because Reader/Writer
* has turned off its field
* \return ERR_AGAIN : received one chaining block, continue to call
* this method to retrieve the remaining blocks
*****************************************************************************
*/
ReturnCode rfalNfcDepGetTransceiveStatus( void );
#endif /* RFAL_NFCDEP_H_ */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,391 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_nfca.h
*
* \author Gustavo Patricio
*
* \brief Provides several NFC-A convenience methods and definitions
*
* It provides a Poller (ISO14443A PCD) interface and as well as
* some NFC-A Listener (ISO14443A PICC) helpers.
*
* The definitions and helpers methods provided by this module are only
* up to ISO14443-3 layer
*
*
* An usage example is provided here: \ref exampleRfalNfca.c
* \example exampleRfalNfca.c
*
*
* \addtogroup RFAL
* @{
*
* \addtogroup RFAL-AL
* \brief RFAL Abstraction Layer
* @{
*
* \addtogroup NFC-A
* \brief RFAL NFC-A Module
* @{
*
*/
#ifndef RFAL_NFCA_H
#define RFAL_NFCA_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
#include "st_errno.h"
#include "rfal_rf.h"
#include "rfal_t1t.h"
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_NFCA_CASCADE_1_UID_LEN 4U /*!< UID length of cascade level 1 only tag */
#define RFAL_NFCA_CASCADE_2_UID_LEN 7U /*!< UID length of cascade level 2 only tag */
#define RFAL_NFCA_CASCADE_3_UID_LEN 10U /*!< UID length of cascade level 3 only tag */
#define RFAL_NFCA_SENS_RES_PLATFORM_MASK 0x0FU /*!< SENS_RES (ATQA) platform configuration mask Digital 1.1 Table 10 */
#define RFAL_NFCA_SENS_RES_PLATFORM_T1T 0x0CU /*!< SENS_RES (ATQA) T1T platform configuration Digital 1.1 Table 10 */
#define RFAL_NFCA_SEL_RES_CONF_MASK 0x60U /*!< SEL_RES (SAK) platform configuration mask Digital 1.1 Table 19 */
#define RFAL_NFCA_SEL_RES_CONF_T2T 0x00U /*!< SEL_RES (SAK) T2T configuration Digital 1.1 Table 19 */
#define RFAL_NFCA_SEL_RES_CONF_T4T 0x20U /*!< SEL_RES (SAK) T4T configuration Digital 1.1 Table 19 */
#define RFAL_NFCA_SEL_RES_CONF_NFCDEP 0x40U /*!< SEL_RES (SAK) NFC-DEP configuration Digital 1.1 Table 19 */
#define RFAL_NFCA_SEL_RES_CONF_T4T_NFCDEP 0x60U /*!< SEL_RES (SAK) T4T and NFC-DEP configuration Digital 1.1 Table 19 */
/*! NFC-A minimum FDT(listen) = ((n * 128 + (84)) / fc) with n_min = 9 Digital 1.1 6.10.1
* = (1236)/fc
* Relax with 3etu: (3*128)/fc as with multiple NFC-A cards, response may take longer (JCOP cards)
* = (1236 + 384)/fc = 1620 / fc */
#define RFAL_NFCA_FDTMIN 1620U
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
/*! Checks if device is a T1T given its SENS_RES */
#define rfalNfcaIsSensResT1T( sensRes ) ((((rfalNfcaSensRes*)(sensRes))->platformInfo & RFAL_NFCA_SENS_RES_PLATFORM_MASK) == RFAL_NFCA_SENS_RES_PLATFORM_T1T )
/*! Checks if device is a T2T given its SENS_RES */
#define rfalNfcaIsSelResT2T( selRes ) ((((rfalNfcaSelRes*)(selRes))->sak & RFAL_NFCA_SEL_RES_CONF_MASK) == RFAL_NFCA_SEL_RES_CONF_T2T )
/*! Checks if device is a T4T given its SENS_RES */
#define rfalNfcaIsSelResT4T( selRes ) ((((rfalNfcaSelRes*)(selRes))->sak & RFAL_NFCA_SEL_RES_CONF_MASK) == RFAL_NFCA_SEL_RES_CONF_T4T )
/*! Checks if device supports NFC-DEP protocol given its SENS_RES */
#define rfalNfcaIsSelResNFCDEP( selRes ) ((((rfalNfcaSelRes*)(selRes))->sak & RFAL_NFCA_SEL_RES_CONF_MASK) == RFAL_NFCA_SEL_RES_CONF_NFCDEP )
/*! Checks if device supports ISO-DEP and NFC-DEP protocol given its SENS_RES */
#define rfalNfcaIsSelResT4TNFCDEP( selRes ) ((((rfalNfcaSelRes*)(selRes))->sak & RFAL_NFCA_SEL_RES_CONF_MASK) == RFAL_NFCA_SEL_RES_CONF_T4T_NFCDEP )
/*! Checks if a NFC-A listener device supports multiple protocols (ISO-DEP and NFC-DEP) */
#define rfalNfcaLisDevIsMultiProto( lisDev ) (((rfalNfcaListenDevice*)(lisDev))->type == RFAL_NFCA_T4T_NFCDEP )
/*
******************************************************************************
* GLOBAL TYPES
******************************************************************************
*/
/*! NFC-A Listen device types */
typedef enum {
RFAL_NFCA_T1T = 0x01, /* Device configured for T1T Digital 1.1 Table 9 */
RFAL_NFCA_T2T = 0x00, /* Device configured for T2T Digital 1.1 Table 19 */
RFAL_NFCA_T4T = 0x20, /* Device configured for T4T Digital 1.1 Table 19 */
RFAL_NFCA_NFCDEP = 0x40, /* Device configured for NFC-DEP Digital 1.1 Table 19 */
RFAL_NFCA_T4T_NFCDEP = 0x60 /* Device configured for NFC-DEP and T4T Digital 1.1 Table 19 */
} rfalNfcaListenDeviceType;
/*! SENS_RES (ATQA) format Digital 1.1 6.6.3 & Table 7 */
typedef struct
{
uint8_t anticollisionInfo; /*!< SENS_RES Anticollision Information */
uint8_t platformInfo; /*!< SENS_RES Platform Information */
} rfalNfcaSensRes;
/*! SDD_REQ (Anticollision) format Digital 1.1 6.7.1 & Table 11 */
typedef struct
{
uint8_t selCmd; /*!< SDD_REQ SEL_CMD: cascade Level */
uint8_t selPar; /*!< SDD_REQ SEL_PAR: Byte Count[4b] | Bit Count[4b] (NVB: Number of Valid Bits)*/
} rfalNfcaSddReq;
/*! SDD_RES (UID CLn) format Digital 1.1 6.7.2 & Table 15 */
typedef struct
{
uint8_t nfcid1[RFAL_NFCA_CASCADE_1_UID_LEN]; /*!< NFCID1 cascade level NFCID */
uint8_t bcc; /*!< BCC Exclusive-OR over first 4 bytes of SDD_RES */
} rfalNfcaSddRes;
/*! SEL_REQ (Select) format Digital 1.1 6.8.1 & Table 17 */
typedef struct
{
uint8_t selCmd; /*!< SDD_REQ SEL_CMD: cascade Level */
uint8_t selPar; /*!< SDD_REQ SEL_PAR: Byte Count[4b] | Bit Count[4b] (NVB: Number of Valid Bits)*/
uint8_t nfcid1[RFAL_NFCA_CASCADE_1_UID_LEN]; /*!< NFCID1 data */
uint8_t bcc; /*!< Checksum calculated as exclusive-OR over the 4 bytes of NFCID1 CLn */
} rfalNfcaSelReq;
/*! SEL_RES (SAK) format Digital 1.1 6.8.2 & Table 19 */
typedef struct
{
uint8_t sak; /*!< Select Acknowledge */
} rfalNfcaSelRes;
/*! NFC-A listener device (PICC) struct */
typedef struct
{
rfalNfcaListenDeviceType type; /*!< NFC-A Listen device type */
rfalNfcaSensRes sensRes; /*!< SENS_RES (ATQA) */
rfalNfcaSelRes selRes; /*!< SEL_RES (SAK) */
uint8_t nfcId1Len; /*!< NFCID1 Length */
uint8_t nfcId1[RFAL_NFCA_CASCADE_3_UID_LEN]; /*!< NFCID1 (UID) */
#ifdef RFAL_FEATURE_T1T
rfalT1TRidRes ridRes; /*!< RID_RES */
#endif /* RFAL_FEATURE_T1T */
bool isSleep; /*!< Device sleeping flag */
} rfalNfcaListenDevice;
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief Initialize NFC-A Poller mode
*
* This methods configures RFAL RF layer to perform as a
* NFC-A Poller/RW (ISO14443A PCD) including all default timings and bit rate
* to 106 kbps
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcaPollerInitialize( void );
/*!
*****************************************************************************
* \brief NFC-A Poller Check Presence
*
* This method checks if a NFC-A Listen device (PICC) is present on the field
* by sending an ALL_REQ (WUPA) or SENS_REQ (REQA)
*
* \param[in] cmd : Indicate if to send an ALL_REQ or a SENS_REQ
* \param[out] sensRes : If received, the SENS_RES
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_RF_COLLISION : Collision detected one or more device in the field
* \return ERR_PAR : Parity error detected, one or more device in the field
* \return ERR_CRC : CRC error detected, one or more device in the field
* \return ERR_FRAMING : Framing error detected, one or more device in the field
* \return ERR_PROTO : Protocol error detected, one or more device in the field
* \return ERR_TIMEOUT : Timeout error, no listener device detected
* \return ERR_NONE : No error, one or more device in the field
*****************************************************************************
*/
ReturnCode rfalNfcaPollerCheckPresence( rfal14443AShortFrameCmd cmd, rfalNfcaSensRes *sensRes );
/*!
*****************************************************************************
* \brief NFC-A Poller Select
*
* This method selects a NFC-A Listener device (PICC)
*
* \param[in] nfcid1 : Listener device NFCID1 to be selected
* \param[in] nfcidLen : Length of the NFCID1 to be selected
* \param[out] selRes : pointer to place the SEL_RES
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error
* \return ERR_PAR : Parity error detected
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error, SEL_RES received
*****************************************************************************
*/
ReturnCode rfalNfcaPollerSelect( const uint8_t *nfcid1, uint8_t nfcidLen, rfalNfcaSelRes *selRes );
/*!
*****************************************************************************
* \brief NFC-A Poller Sleep
*
* This method sends a SLP_REQ (HLTA)
* No response is expected afterwards Digital 1.1 6.9.2.1
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcaPollerSleep( void );
/*!
*****************************************************************************
* \brief NFC-A Technology Detection
*
* This method performs NFC-A Technology Detection as defined in the spec
* given in the compliance mode
*
* \param[in] compMode : compliance mode to be performed
* \param[out] sensRes : location to store the SENS_RES, if received
*
* When compMode is set to ISO compliance a SLP_REQ (HLTA) is not sent
* after detection. When set to EMV a ALL_REQ (WUPA) is sent instead of
* a SENS_REQ (REQA)
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_NONE : No error, one or more device in the field
*****************************************************************************
*/
ReturnCode rfalNfcaPollerTechnologyDetection( rfalComplianceMode compMode, rfalNfcaSensRes *sensRes );
/*!
*****************************************************************************
* \brief NFC-A Poller Collision Resolution
*
* Collision resolution for one NFC-A Listener device/card (PICC) as
* defined in Activity 1.1 9.3.4
*
* This method executes anti collision loop and select the device with higher NFCID1
*
* When devLimit = 0 it is configured to perform collision detection only. Once a collision
* is detected the collision resolution is aborted immidiatly. If only one device is found
* with no collisions, it will properly resolved.
*
* \param[in] devLimit : device limit value (CON_DEVICES_LIMIT)
* \param[out] collPending : pointer to collision pending flag (INT_COLL_PEND)
* \param[out] selRes : location to store the last Select Response from listener device (PICC)
* \param[out] nfcId1 : location to store the NFCID1 (UID), ensure RFAL_NFCA_CASCADE_3_UID_LEN
* \param[out] nfcId1Len : pointer to length of NFCID1 (UID)
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_PROTO : Card length invalid
* \return ERR_IGNORE : conDevLimit is 0 and there is a collision
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcaPollerSingleCollisionResolution( uint8_t devLimit, bool *collPending, rfalNfcaSelRes *selRes, uint8_t *nfcId1, uint8_t *nfcId1Len );
/*!
*****************************************************************************
* \brief NFC-A Poller Full Collision Resolution
*
* Performs a full Collision resolution as defined in Activity 1.0 or 1.1 9.3.4
*
* \param[in] compMode : compliance mode to be performed
* \param[in] devLimit : device limit value, and size nfcaDevList
* \param[out] nfcaDevList : NFC-A listener device info
* \param[out] devCnt : Devices found counter
*
* When compMode is set to ISO compliance it assumes that the device is
* not sleeping and therefore no ALL_REQ (WUPA) is sent at the beginning.
*
* When compMode is set to NFC compliance an additional ALL_REQ (WUPA) is sent at
* the beginning and a proprietary behaviour also takes place. Once a device has been
* resolved an additional SLP_REQ (HLTA) is sent regardless if there was a collision
* (except if the number of devices found already equals the limit).
* This proprietary behaviour ensures proper activation of certain devices that suffer
* from influence of Type B commands as foreseen in ISO14443-3 5.2.3
*
*
* When devLimit = 0 it is configured to perform collision detection only. Once a collision
* is detected the collision resolution is aborted immidiatly. If only one device is found
* with no collisions, it will properly resolved.
*
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcaPollerFullCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcaListenDevice *nfcaDevList, uint8_t *devCnt );
/*!
*****************************************************************************
* \brief NFC-A Listener is SLP_REQ
*
* Checks if the given buffer contains valid NFC-A SLP_REQ (HALT)
*
* \param[in] buf: buffer containing data
* \param[in] bufLen: length of the data in buffer to be checked
*
* \return true if data in buf contains a SLP_REQ ; false otherwise
*****************************************************************************
*/
bool rfalNfcaListenerIsSleepReq( const uint8_t *buf, uint16_t bufLen );
#endif /* RFAL_NFCA_H */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,398 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_nfcb.h
*
* \author Gustavo Patricio
*
* \brief Implementation of NFC-B (ISO14443B) helpers
*
* It provides a NFC-B Poller (ISO14443B PCD) interface and
* also provides some NFC-B Listener (ISO14443B PICC) helpers
*
* The definitions and helpers methods provided by this module are only
* up to ISO14443-3 layer (excluding ATTRIB)
*
*
* \addtogroup RFAL
* @{
*
* \addtogroup RFAL-AL
* \brief RFAL Abstraction Layer
* @{
*
* \addtogroup NFC-B
* \brief RFAL NFC-B Module
* @{
*
*/
#ifndef RFAL_NFCB_H
#define RFAL_NFCB_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
#include "st_errno.h"
#include "rfal_rf.h"
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_NFCB_FWTSENSB 7680U /*!< NFC-B FWT(SENSB) Digital 2.0 B.3 */
#define RFAL_NFCB_DFWT 49152U /*!< NFC-B dFWT Delta 2.0 7.9.1.3 & B.3 */
#define RFAL_NFCB_DTPOLL_10 rfalConvMsTo1fc(20) /*!< NFC-B Delta Tb Poll Digital 1.0 A.2 */
#define RFAL_NFCB_DTPOLL_20 rfalConvMsTo1fc(17) /*!< NFC-B Delta Tb Poll Digital 2.1 B.3 */
#define RFAL_NFCB_AFI 0x00U /*!< NFC-B default Application Family Digital 1.1 7.6.1.1 */
#define RFAL_NFCB_PARAM 0x00U /*!< NFC-B default SENSB_REQ PARAM */
#define RFAL_NFCB_CRC_LEN 2U /*!< NFC-B CRC length and CRC_B(AID) Digital 1.1 Table 28 */
#define RFAL_NFCB_NFCID0_LEN 4U /*!< Length of NFC-B NFCID0 */
#define RFAL_NFCB_CMD_LEN 1U /*!< Length of NFC-B Command */
#define RFAL_NFCB_SENSB_RES_LEN 12U /*!< Standard length of SENSB_RES without SFGI byte */
#define RFAL_NFCB_SENSB_RES_EXT_LEN 13U /*!< Extended length of SENSB_RES with SFGI byte */
#define RFAL_NFCB_SENSB_REQ_ADV_FEATURE 0x20U /*!< Bit mask for Advance Feature in SENSB_REQ */
#define RFAL_NFCB_SENSB_RES_FSCI_MASK 0x0FU /*!< Bit mask for FSCI value in SENSB_RES */
#define RFAL_NFCB_SENSB_RES_FSCI_SHIFT 4U /*!< Shift for FSCI value in SENSB_RES */
#define RFAL_NFCB_SENSB_RES_PROTO_RFU_MASK 0x08U /*!< Bit mask for Protocol Type RFU in SENSB_RES */
#define RFAL_NFCB_SENSB_RES_PROTO_TR2_MASK 0x03U /*!< Bit mask for Protocol Type TR2 in SENSB_RES */
#define RFAL_NFCB_SENSB_RES_PROTO_TR2_SHIFT 1U /*!< Shift for Protocol Type TR2 in SENSB_RES */
#define RFAL_NFCB_SENSB_RES_PROTO_ISO_MASK 0x01U /*!< Bit mask Protocol Type ISO14443 Compliant in SENSB_RES */
#define RFAL_NFCB_SENSB_RES_FWI_MASK 0x0FU /*!< Bit mask for FWI value in SENSB_RES */
#define RFAL_NFCB_SENSB_RES_FWI_SHIFT 4U /*!< Bit mask for FWI value in SENSB_RES */
#define RFAL_NFCB_SENSB_RES_ADC_MASK 0x0CU /*!< Bit mask for ADC value in SENSB_RES */
#define RFAL_NFCB_SENSB_RES_ADC_ADV_FEATURE_MASK 0x08U /*!< Bit mask for ADC.Advanced Proto Features in SENSB_RES */
#define RFAL_NFCB_SENSB_RES_ADC_PROPRIETARY_MASK 0x04U /*!< Bit mask for ADC.Proprietary Application in SENSB_RES */
#define RFAL_NFCB_SENSB_RES_FO_DID_MASK 0x01U /*!< Bit mask for DID in SENSB_RES */
#define RFAL_NFCB_SENSB_RES_FO_NAD_MASK 0x02U /*!< Bit mask for DID in SENSB_RES */
#define RFAL_NFCB_SENSB_RES_FO_MASK 0x03U /*!< Bit mask for FO value in SENSB_RES (NAD and DID) */
#define RFAL_NFCB_SENSB_RES_SFGI_MASK 0x0FU /*!< Bit mask for SFGI in SENSB_RES */
#define RFAL_NFCB_SENSB_RES_SFGI_SHIFT 4U /*!< Shift for SFGI in SENSB_RES */
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
/*! Get device's FSCI given its SENSB_RES Digital 1.1 7.6.2 */
#define rfalNfcbGetFSCI( sensbRes ) ((((rfalNfcbSensbRes*)(sensbRes))->protInfo.FsciProType >> RFAL_NFCB_SENSB_RES_FSCI_SHIFT) & RFAL_NFCB_SENSB_RES_FSCI_MASK )
/*! Checks if the given NFC-B device indicates ISO-DEP support */
#define rfalNfcbIsIsoDepSupported( dev ) ( (((rfalNfcbListenDevice*)(dev))->sensbRes.protInfo.FsciProType & RFAL_NFCB_SENSB_RES_PROTO_ISO_MASK) != 0U )
/*
******************************************************************************
* GLOBAL TYPES
******************************************************************************
*/
/*! SENSB_REQ and ALLB_REQ param Digital 1.1 7.6.1 */
typedef enum
{
RFAL_NFCB_SENS_CMD_ALLB_REQ = 0x08, /*!< ALLB_REQ (WUPB) */
RFAL_NFCB_SENS_CMD_SENSB_REQ = 0x00 /*!< SENSB_REQ (REQB) */
} rfalNfcbSensCmd;
/*! Number of Slots (NI) codes used for NFC-B anti collision Digital 1.1 Table 26 */
typedef enum
{
RFAL_NFCB_SLOT_NUM_1 = 0, /*!< N=0 : 1 slot */
RFAL_NFCB_SLOT_NUM_2 = 1, /*!< N=1 : 2 slots */
RFAL_NFCB_SLOT_NUM_4 = 2, /*!< N=2 : 4 slots */
RFAL_NFCB_SLOT_NUM_8 = 3, /*!< N=3 : 8 slots */
RFAL_NFCB_SLOT_NUM_16 = 4 /*!< N=4 : 16 slots */
}rfalNfcbSlots;
/*! SENSB_RES (ATQB) Application Data Format Digital 1.1 Table 28 */
typedef struct
{
uint8_t AFI; /*!< Application Family Identifier */
uint8_t CRC_B[RFAL_NFCB_CRC_LEN]; /*!< CRC_B of AID */
uint8_t numApps; /*!< Number of Applications */
} rfalNfcbSensbResAppData;
/*! SENSB_RES Protocol Info format Digital 1.1 Table 29 */
typedef struct
{
uint8_t BRC; /*!< Bit Rate Capability */
uint8_t FsciProType; /*!< Frame Size Card Integer [4b] | Protocol Type[4 bits] */
uint8_t FwiAdcFo; /*!< Frame Waiting Integer [4b] | Application Data Coding [2b] | Frame Options [2b] */
uint8_t SFGI; /*!< Optional: Start-Up Frame Guard Time Integer[4b] | RFU [4b] */
} rfalNfcbSensbResProtocolInfo;
/*! SENSB_RES format Digital 1.1 7.6.2 */
typedef struct
{
uint8_t cmd; /*!< SENSB_RES: 50h */
uint8_t nfcid0[RFAL_NFCB_NFCID0_LEN]; /*!< NFC Identifier (PUPI)*/
rfalNfcbSensbResAppData appData; /*!< Application Data */
rfalNfcbSensbResProtocolInfo protInfo; /*!< Protocol Information */
} rfalNfcbSensbRes;
/*! NFC-B listener device (PICC) struct */
typedef struct
{
uint8_t sensbResLen; /*!< SENSB_RES length */
rfalNfcbSensbRes sensbRes; /*!< SENSB_RES */
bool isSleep; /*!< Device sleeping flag */
}rfalNfcbListenDevice;
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief Initialize NFC-B Poller mode
*
* This methods configures RFAL RF layer to perform as a
* NFC-B Poller/RW (ISO14443B PCD) including all default timings
*
* It sets NFC-B parameters (AFI, PARAM) to default values
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcbPollerInitialize( void );
/*!
*****************************************************************************
* \brief Set NFC-B Poller parameters
*
* This methods configures RFAL RF layer to perform as a
* NFCA Poller/RW (ISO14443A PCD) including all default timings
*
* Additionally configures NFC-B specific parameters to be used on the
* following communications
*
* \param[in] AFI : Application Family Identifier to be used
* \param[in] PARAM : PARAM to be used, it announces whether Advanced
* Features or Extended SENSB_RES is supported
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcbPollerInitializeWithParams( uint8_t AFI, uint8_t PARAM );
/*!
*****************************************************************************
* \brief NFC-B Poller Check Presence
*
* This method checks if a NFC-B Listen device (PICC) is present on the field
* by sending an ALLB_REQ (WUPB) or SENSB_REQ (REQB)
*
* \param[in] cmd : Indicate if to send an ALL_REQ or a SENS_REQ
* \param[in] slots : The number of slots to be announced
* \param[out] sensbRes : If received, the SENSB_RES
* \param[out] sensbResLen : If received, the SENSB_RES length
*
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error, no listener device detected
* \return ERR_RF_COLLISION : Collision detected one or more device in the field
* \return ERR_PAR : Parity error detected, one or more device in the field
* \return ERR_CRC : CRC error detected, one or more device in the field
* \return ERR_FRAMING : Framing error detected, one or more device in the field
* \return ERR_PROTO : Protocol error detected, invalid SENSB_RES received
* \return ERR_NONE : No error, SENSB_RES received
*****************************************************************************
*/
ReturnCode rfalNfcbPollerCheckPresence( rfalNfcbSensCmd cmd, rfalNfcbSlots slots, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen );
/*!
*****************************************************************************
* \brief NFC-B Poller Sleep
*
* This function is used to send the SLPB_REQ (HLTB) command to put the PICC with
* the given NFCID0 to state HALT so that they do not reply to further SENSB_REQ
* commands (only to ALLB_REQ)
*
* \param[in] nfcid0 : NFCID of the device to be put to Sleep
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcbPollerSleep( const uint8_t* nfcid0 );
/*!
*****************************************************************************
* \brief NFC-B Poller Slot Marker
*
* This method selects a NFC-B Slot marker frame
*
* \param[in] slotCode : Slot Code [1-15]
* \param[out] sensbRes : If received, the SENSB_RES
* \param[out] sensbResLen : If received, the SENSB_RES length
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error
* \return ERR_PAR : Parity error detected
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error, SEL_RES received
*****************************************************************************
*/
ReturnCode rfalNfcbPollerSlotMarker( uint8_t slotCode, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen );
/*!
*****************************************************************************
* \brief NFC-B Technology Detection
*
* This method performs NFC-B Technology Detection as defined in the spec
* given in the compliance mode
*
* \param[in] compMode : compliance mode to be performed
* \param[out] sensbRes : location to store the SENSB_RES, if received
* \param[out] sensbResLen : length of the SENSB_RES, if received
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_NONE : No error, one or more device in the field
*****************************************************************************
*/
ReturnCode rfalNfcbPollerTechnologyDetection( rfalComplianceMode compMode, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen );
/*!
*****************************************************************************
* \brief NFC-B Poller Collision Resolution
*
* NFC-B Collision resolution Listener device/card (PICC) as
* defined in Activity 1.1 9.3.5
*
* This function is used to perform collision resolution for detection in case
* of multiple NFC Forum Devices with Technology B detected.
* Target with valid SENSB_RES will be stored in devInfo and nfcbDevCount incremented.
*
* \param[in] compMode : compliance mode to be performed
* \param[in] devLimit : device limit value, and size nfcbDevList
* \param[out] nfcbDevList : NFC-B listener device info
* \param[out] devCnt : devices found counter
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcbPollerCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcbListenDevice *nfcbDevList, uint8_t *devCnt );
/*!
*****************************************************************************
* \brief NFC-B Poller Collision Resolution Slotted
*
* NFC-B Collision resolution Listener device/card (PICC). The sequence can
* be configured to be according to NFC Forum Activity 1.1 9.3.5, ISO10373
* or EMVCo
*
* This function is used to perform collision resolution for detection in case
* of multiple NFC Forum Devices with Technology B are detected.
* Target with valid SENSB_RES will be stored in devInfo and nfcbDevCount incremented.
*
* This method provides the means to perform a collision resolution loop with specific
* initial and end number of slots. This allows to user to start the loop already with
* greater number of slots, and or limit the end number of slots. At the end a flag
* indicating whether there were collisions pending is returned.
*
* If RFAL_COMPLIANCE_MODE_ISO is used \a initSlots must be set to RFAL_NFCB_SLOT_NUM_1
*
*
* \param[in] compMode : compliance mode to be performed
* \param[in] devLimit : device limit value, and size nfcbDevList
* \param[in] initSlots : number of slots to open initially
* \param[in] endSlots : number of slots when to stop collision resolution
* \param[out] nfcbDevList : NFC-B listener device info
* \param[out] devCnt : devices found counter
* \param[out] colPending : flag indicating whether collision are still pending
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcbPollerSlottedCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcbSlots initSlots, rfalNfcbSlots endSlots, rfalNfcbListenDevice *nfcbDevList, uint8_t *devCnt, bool *colPending );
/*!
*****************************************************************************
* \brief NFC-B TR2 code to FDT
*
* Converts the TR2 code as defined in Digital 1.1 Table 33 Minimum
* TR2 Coding to Frame Delay Time (FDT) in 1/Fc
*
* \param[in] tr2Code : TR2 code as defined in Digital 1.1 Table 33
*
* \return FDT in 1/Fc
*****************************************************************************
*/
uint32_t rfalNfcbTR2ToFDT( uint8_t tr2Code );
#endif /* RFAL_NFCB_H */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,370 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_nfcf.h
*
* \author Gustavo Patricio
*
* \brief Implementation of NFC-F Poller (FeliCa PCD) device
*
* The definitions and helpers methods provided by this module are
* aligned with NFC-F (FeliCa - JIS X6319-4)
*
*
* \addtogroup RFAL
* @{
*
* \addtogroup RFAL-AL
* \brief RFAL Abstraction Layer
* @{
*
* \addtogroup NFC-F
* \brief RFAL NFC-F Module
* @{
*
*/
#ifndef RFAL_NFCF_H
#define RFAL_NFCF_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
#include "st_errno.h"
#include "rfal_rf.h"
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_NFCF_NFCID2_LEN 8U /*!< NFCID2 (FeliCa IDm) length */
#define RFAL_NFCF_SENSF_RES_LEN_MIN 16U /*!< SENSF_RES minimum length */
#define RFAL_NFCF_SENSF_RES_LEN_MAX 18U /*!< SENSF_RES maximum length */
#define RFAL_NFCF_SENSF_RES_PAD0_LEN 2U /*!< SENSF_RES PAD0 length */
#define RFAL_NFCF_SENSF_RES_PAD1_LEN 2U /*!< SENSF_RES PAD1 length */
#define RFAL_NFCF_SENSF_RES_RD_LEN 2U /*!< SENSF_RES Request Data length */
#define RFAL_NFCF_SENSF_RES_BYTE1 1U /*!< SENSF_RES first byte value */
#define RFAL_NFCF_SENSF_SC_LEN 2U /*!< Felica SENSF_REQ System Code length */
#define RFAL_NFCF_SENSF_PARAMS_SC1_POS 0U /*!< System Code byte1 position in the SENSF_REQ */
#define RFAL_NFCF_SENSF_PARAMS_SC2_POS 1U /*!< System Code byte2 position in the SENSF_REQ */
#define RFAL_NFCF_SENSF_PARAMS_RC_POS 2U /*!< Request Code position in the SENSF_REQ */
#define RFAL_NFCF_SENSF_PARAMS_TSN_POS 3U /*!< Time Slot Number position in the SENSF_REQ */
#define RFAL_NFCF_POLL_MAXCARDS 16U /*!< Max number slots/cards 16 */
#define RFAL_NFCF_CMD_POS 0U /*!< Command/Responce code length */
#define RFAL_NFCF_CMD_LEN 1U /*!< Command/Responce code length */
#define RFAL_NFCF_LENGTH_LEN 1U /*!< LEN field length */
#define RFAL_NFCF_HEADER_LEN (RFAL_NFCF_LENGTH_LEN + RFAL_NFCF_CMD_LEN) /*!< Header length*/
#define RFAL_NFCF_SENSF_NFCID2_BYTE1_POS 0U /*!< NFCID2 byte1 position */
#define RFAL_NFCF_SENSF_NFCID2_BYTE2_POS 1U /*!< NFCID2 byte2 position */
#define RFAL_NFCF_SENSF_NFCID2_PROT_TYPE_LEN 2U /*!< NFCID2 length for byte 1 and byte 2 indicating NFC-DEP or T3T support */
#define RFAL_NFCF_SENSF_NFCID2_BYTE1_NFCDEP 0x01U /*!< NFCID2 byte1 NFC-DEP support Digital 1.0 Table 44 */
#define RFAL_NFCF_SENSF_NFCID2_BYTE2_NFCDEP 0xFEU /*!< NFCID2 byte2 NFC-DEP support Digital 1.0 Table 44 */
#define RFAL_NFCF_SYSTEMCODE 0xFFFFU /*!< SENSF_RES Default System Code Digital 1.0 6.6.1.1 */
#define RFAL_NFCF_BLOCK_LEN 16U /*!< NFCF T3T Block size T3T 1.0 4.1 */
#define RFAL_NFCF_CHECKUPDATE_RES_ST1_POS 9U /*!< Check|Update Res Status Flag 1 position T3T 1.0 Table 8 */
#define RFAL_NFCF_CHECKUPDATE_RES_ST2_POS 10U /*!< Check|Update Res Status Flag 2 position T3T 1.0 Table 8 */
#define RFAL_NFCF_CHECKUPDATE_RES_NOB_POS 11U /*!< Check|Update Res Number of Blocks position T3T 1.0 Table 8 */
#define RFAL_NFCF_STATUS_FLAG_SUCCESS 0x00U /*!< Check response Number of Blocks position T3T 1.0 Table 11 */
#define RFAL_NFCF_STATUS_FLAG_ERROR 0xFFU /*!< Check response Number of Blocks position T3T 1.0 Table 11 */
#define RFAL_NFCF_BLOCKLISTELEM_LEN 0x80U /*!< Block List Element Length bit (2|3 bytes) T3T 1.0 5.6.1 */
#define RFAL_NFCF_SERVICECODE_RDONLY 0x000BU /*!< NDEF Service Code as Read-Only T3T 1.0 7.2.1 */
#define RFAL_NFCF_SERVICECODE_RDWR 0x0009U /*!< NDEF Service Code as Read and Write T3T 1.0 7.2.1 */
/*! NFC-F Felica command set JIS X6319-4 9.1 */
enum
{
RFAL_NFCF_CMD_POLLING = 0x00, /*!< SENSF_REQ (Felica Poll/REQC command to identify a card ) */
RFAL_NFCF_CMD_POLLING_RES = 0x01, /*!< SENSF_RES (Felica Poll/REQC command response ) */
RFAL_NFCF_CMD_REQUEST_SERVICE = 0x02, /*!< verify the existence of Area and Service */
RFAL_NFCF_CMD_REQUEST_RESPONSE = 0x04, /*!< verify the existence of a card */
RFAL_NFCF_CMD_READ_WITHOUT_ENCRYPTION = 0x06, /*!< read Block Data from a Service that requires no authentication */
RFAL_NFCF_CMD_READ_WITHOUT_ENCRYPTION_RES = 0x07, /*!< read Block Data response from a Service with no authentication */
RFAL_NFCF_CMD_WRITE_WITHOUT_ENCRYPTION = 0x08, /*!< write Block Data to a Service that requires no authentication */
RFAL_NFCF_CMD_WRITE_WITHOUT_ENCRYPTION_RES = 0x09, /*!< write Block Data response to a Service with no authentication */
RFAL_NFCF_CMD_REQUEST_SYSTEM_CODE = 0x0c, /*!< acquire the System Code registered to a card */
RFAL_NFCF_CMD_AUTHENTICATION1 = 0x10, /*!< authenticate a card */
RFAL_NFCF_CMD_AUTHENTICATION2 = 0x12, /*!< allow a card to authenticate a Reader/Writer */
RFAL_NFCF_CMD_READ = 0x14, /*!< read Block Data from a Service that requires authentication */
RFAL_NFCF_CMD_WRITE = 0x16, /*!< write Block Data to a Service that requires authentication */
};
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
/*! Checks if the given NFC-F device indicates NFC-DEP support */
#define rfalNfcfIsNfcDepSupported( dev ) ( (((rfalNfcfListenDevice*)(dev))->sensfRes.NFCID2[RFAL_NFCF_SENSF_NFCID2_BYTE1_POS] == RFAL_NFCF_SENSF_NFCID2_BYTE1_NFCDEP) && \
(((rfalNfcfListenDevice*)(dev))->sensfRes.NFCID2[RFAL_NFCF_SENSF_NFCID2_BYTE2_POS] == RFAL_NFCF_SENSF_NFCID2_BYTE2_NFCDEP) )
/*
******************************************************************************
* GLOBAL TYPES
******************************************************************************
*/
/*! NFC-F SENSF_RES format Digital 1.1 8.6.2 */
typedef struct
{
uint8_t CMD; /*!< Command Code: 01h */
uint8_t NFCID2[RFAL_NFCF_NFCID2_LEN]; /*!< NFCID2 */
uint8_t PAD0[RFAL_NFCF_SENSF_RES_PAD0_LEN]; /*!< PAD0 */
uint8_t PAD1[RFAL_NFCF_SENSF_RES_PAD1_LEN]; /*!< PAD1 */
uint8_t MRTIcheck; /*!< MRTIcheck */
uint8_t MRTIupdate; /*!< MRTIupdate */
uint8_t PAD2; /*!< PAD2 */
uint8_t RD[RFAL_NFCF_SENSF_RES_RD_LEN]; /*!< Request Data */
} rfalNfcfSensfRes;
/*! NFC-F poller device (PCD) struct */
typedef struct
{
uint8_t NFCID2[RFAL_NFCF_NFCID2_LEN]; /*!< NFCID2 */
} rfalNfcfPollDevice;
/*! NFC-F listener device (PICC) struct */
typedef struct
{
uint8_t sensfResLen; /*!< SENF_RES length */
rfalNfcfSensfRes sensfRes; /*!< SENF_RES */
} rfalNfcfListenDevice;
typedef uint16_t rfalNfcfServ; /*!< NFC-F Service Code */
/*! NFC-F Block List Element (2 or 3 bytes element) T3T 1.0 5.6.1 */
typedef struct
{
uint8_t conf; /*!< Access Mode | Serv Code List Order */
uint16_t blockNum; /*!< Block Number */
}rfalNfcfBlockListElem;
/*! Check Update Service list and Block list parameter */
typedef struct
{
uint8_t numServ; /*!< Number of Services */
rfalNfcfServ *servList; /*!< Service Code List */
uint8_t numBlock; /*!< Number of Blocks */
rfalNfcfBlockListElem *blockList; /*!< Block Number List */
}rfalNfcfServBlockListParam;
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief Initialize NFC-F Poller mode
*
* This methods configures RFAL RF layer to perform as a
* NFC-F Poller/RW (FeliCa PCD) including all default timings
*
* \param[in] bitRate : NFC-F bitrate to be initialize (212 or 424)
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_PARAM : Incorrect bitrate
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcfPollerInitialize( rfalBitRate bitRate );
/*!
*****************************************************************************
* \brief NFC-F Poller Check Presence
*
* This function sends a Poll/SENSF command according to NFC Activity spec
* It detects if a NCF-F device is within range
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error, no listener device detected
* \return ERR_NONE : No error and some NFC-F device was detected
*
*****************************************************************************
*/
ReturnCode rfalNfcfPollerCheckPresence( void );
/*!
*****************************************************************************
* \brief NFC-F Poller Poll
*
* This function sends to all PICCs in field the POLL command with the given
* number of slots.
*
* \param[in] slots : the number of slots to be performed
* \param[in] sysCode : as given in FeliCa poll command
* \param[in] reqCode : FeliCa communication parameters
* \param[out] cardList : Parameter of type rfalFeliCaPollRes which will hold the cards found
* \param[out] devCnt : actual number of cards found
* \param[out] collisions : number of collisions encountered
*
* \warning the list cardList has to be as big as the number of slots for the Poll
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error, no listener device detected
* \return ERR_NONE : No error and some NFC-F device was detected
*
*****************************************************************************
*/
ReturnCode rfalNfcfPollerPoll( rfalFeliCaPollSlots slots, uint16_t sysCode, uint8_t reqCode, rfalFeliCaPollRes *cardList, uint8_t *devCnt, uint8_t *collisions );
/*!
*****************************************************************************
* \brief NFC-F Poller Full Collision Resolution
*
* Performs a full Collision resolution as defined in Activity 1.1 9.3.4
*
* \param[in] compMode : compliance mode to be performed
* \param[in] devLimit : device limit value, and size nfcaDevList
* \param[out] nfcfDevList : NFC-F listener devices list
* \param[out] devCnt : Devices found counter
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcfPollerCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcfListenDevice *nfcfDevList, uint8_t *devCnt );
/*!
*****************************************************************************
* \brief NFC-F Poller Check/Read
*
* It computes a Check / Read command accoring to T3T 1.0 and JIS X6319-4 and
* sends it to PICC. If sucessfully, the rxBuf will contain the the number of
* blocks in the first byte followed by the blocks data.
*
* \param[in] nfcid2 : nfcid2 of the device
* \param[in] servBlock : parameter containing the list of Services and
* Blocks to be addressed by this command
* \param[out] rxBuf : buffer to place check/read data
* \param[in] rxBufLen : size of the rxBuf
* \param[out] rcvdLen : length of data placed in rxBuf
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_REQUEST : The request was executed with error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcfPollerCheck( const uint8_t* nfcid2, const rfalNfcfServBlockListParam *servBlock, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *rcvdLen );
/*!
*****************************************************************************
* \brief NFC-F Poller Update/Write
*
* It computes a Update / Write command accoring to T3T 1.0 and JIS X6319-4 and
* sends it to PICC.
*
* \param[in] nfcid2 : nfcid2 of the device
* \param[in] servBlock : parameter containing the list of Services and
* Blocks to be addressed by this command
* \param[in] txBuf : buffer where the request will be composed
* \param[in] txBufLen : size of txBuf
* \param[in] blockData : data to written on the given block(s)
* \param[out] rxBuf : buffer to place check/read data
* \param[in] rxBufLen : size of the rxBuf
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_REQUEST : The request was executed with error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcfPollerUpdate( const uint8_t* nfcid2, const rfalNfcfServBlockListParam *servBlock, uint8_t *txBuf, uint16_t txBufLen, const uint8_t *blockData, uint8_t *rxBuf, uint16_t rxBufLen);
/*!
*****************************************************************************
* \brief NFC-F Listener is T3T Request
*
* This method checks if the given data is a valid T3T command (Read or Write)
* and in case a valid request has been received it may output the request's NFCID2
*
* \param[in] buf : buffer holding Initiator's received command
* \param[in] bufLen : length of received command in bytes
* \param[out] nfcid2 : pointer to where the NFCID2 may be outputed,
* nfcid2 has NFCF_SENSF_NFCID2_LEN as length
* Pass NULL if output parameter not desired
*
* \return true : Valid T3T command (Read or Write) received
* \return false : Invalid protocol request
*
*****************************************************************************
*/
bool rfalNfcfListenerIsT3TReq( const uint8_t* buf, uint16_t bufLen, uint8_t* nfcid2 );
#endif /* RFAL_NFCF_H */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,772 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_nfcv.h
*
* \author Gustavo Patricio
*
* \brief Implementation of NFC-V Poller (ISO15693) device
*
* The definitions and helpers methods provided by this module
* are aligned with NFC-V Digital 2.1
*
*
* \addtogroup RFAL
* @{
*
* \addtogroup RFAL-AL
* \brief RFAL Abstraction Layer
* @{
*
* \addtogroup NFC-V
* \brief RFAL NFC-V Module
* @{
*
*/
#ifndef RFAL_NFCV_H
#define RFAL_NFCV_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
#include "st_errno.h"
#include "rfal_rf.h"
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_NFCV_UID_LEN 8U /*!< NFC-V UID length */
#define RFAL_NFCV_MAX_BLOCK_LEN 32U /*!< Max Block size: can be of up to 256 bits ISO 15693 2000 5 */
#define RFAL_NFCV_BNO_LEN 1U /*!< NFC-V Block Number length */
#define RFAL_NFCV_CRC_LEN 2U /*!< NFC-V CRC length */
#define RFAL_NFCV_MAX_GEN_DATA_LEN (RFAL_NFCV_MAX_BLOCK_LEN + RFAL_NFCV_BNO_LEN + RFAL_NFCV_UID_LEN) /*!<Max data */
#define RFAL_NFCV_BLOCKNUM_LEN 1U /*!< Block Number length on normal commands: 8 bits */
#define RFAL_NFCV_BLOCKNUM_EXTENDED_LEN 2U /*!< Block Number length on extended commands: 16 bits */
#define RFAL_NFCV_PARAM_SKIP 0U /*!< Skip proprietary Param Request */
/*! NFC-V RequestFlags ISO15693 2000 7.3.1 */
enum{
RFAL_NFCV_REQ_FLAG_DEFAULT = 0x02U, /*!< Default Request Flags */
RFAL_NFCV_REQ_FLAG_SUB_CARRIER = 0x01U, /*!< Sub Carrier flag */
RFAL_NFCV_REQ_FLAG_DATA_RATE = 0x02U, /*!< Data Rate flag */
RFAL_NFCV_REQ_FLAG_INVENTORY = 0x04U, /*!< Inventory flag */
RFAL_NFCV_REQ_FLAG_PROTOCOL_EXT = 0x08U, /*!< Protocol Extension flag */
RFAL_NFCV_REQ_FLAG_SELECT = 0x10U, /*!< Select flag */
RFAL_NFCV_REQ_FLAG_ADDRESS = 0x20U, /*!< Address flag */
RFAL_NFCV_REQ_FLAG_OPTION = 0x40U, /*!< Option flag */
RFAL_NFCV_REQ_FLAG_RFU = 0x80U, /*!< RFU flag */
RFAL_NFCV_REQ_FLAG_AFI = 0x10U, /*!< AFI flag */
RFAL_NFCV_REQ_FLAG_NB_SLOTS = 0x20U, /*!< Number of Slots flag */
};
/*! NFC-V Response Flags ISO15693 2000 7.4.1 */
enum{
RFAL_NFCV_RES_FLAG_ERROR = 0x01U, /*!< Error flag */
RFAL_NFCV_RES_FLAG_RFU1 = 0x02U, /*!< RFU flag */
RFAL_NFCV_RES_FLAG_RFU2 = 0x04U, /*!< RFU flag */
RFAL_NFCV_RES_FLAG_EXTENSION = 0x08U, /*!< Extension flag */
RFAL_NFCV_RES_FLAG_RFU3 = 0x10U, /*!< RFU flag */
RFAL_NFCV_RES_FLAG_RFU4 = 0x20U, /*!< RFU flag */
RFAL_NFCV_RES_FLAG_RFU5 = 0x40U, /*!< RFU flag */
RFAL_NFCV_RES_FLAG_RFU6 = 0x80U /*!< RFU flag */
};
/*! NFC-V Error code ISO15693 2000 7.4.2 */
enum{
RFAL_NFCV_ERROR_CMD_NOT_SUPPORTED = 0x01U, /*!< The command is not supported, code is not recognised */
RFAL_NFCV_ERROR_CMD_NOT_RECOGNIZED = 0x02U, /*!< The command is not recognised, format error occurred */
RFAL_NFCV_ERROR_OPTION_NOT_SUPPORTED = 0x03U, /*!< The option is not supported */
RFAL_NFCV_ERROR_UNKNOWN = 0x0FU, /*!< Unknown error */
RFAL_NFCV_ERROR_BLOCK_NOT_AVALIABLE = 0x10U, /*!< The specified block is not available */
RFAL_NFCV_ERROR_BLOCK_ALREDY_LOCKED = 0x11U, /*!< The specified block is already locked */
RFAL_NFCV_ERROR_BLOCK_LOCKED = 0x12U, /*!< The specified block is locked */
RFAL_NFCV_ERROR_WRITE_FAILED = 0x13U, /*!< The specified block was not successfully programmed */
RFAL_NFCV_ERROR_BLOCK_FAILED = 0x14U /*!< The specified block was not successfully locked */
};
/*! NFC-V command set ISO15693 2000 9.1 */
enum
{
RFAL_NFCV_CMD_INVENTORY = 0x01U, /*!< INVENTORY_REQ (Inventory) command */
RFAL_NFCV_CMD_SLPV = 0x02U, /*!< SLPV_REQ (Stay quiet) command */
RFAL_NFCV_CMD_READ_SINGLE_BLOCK = 0x20U, /*!< Read single block command */
RFAL_NFCV_CMD_WRITE_SINGLE_BLOCK = 0x21U, /*!< Write single block command */
RFAL_NFCV_CMD_LOCK_BLOCK = 0x22U, /*!< Lock block command */
RFAL_NFCV_CMD_READ_MULTIPLE_BLOCKS = 0x23U, /*!< Read multiple blocks command */
RFAL_NFCV_CMD_WRITE_MULTIPLE_BLOCKS = 0x24U, /*!< Write multiple blocks command */
RFAL_NFCV_CMD_SELECT = 0x25U, /*!< Select command */
RFAL_NFCV_CMD_RESET_TO_READY = 0x26U, /*!< Reset To Ready command */
RFAL_NFCV_CMD_GET_SYS_INFO = 0x2BU, /*!< Get System Information command */
RFAL_NFCV_CMD_EXTENDED_READ_SINGLE_BLOCK = 0x30U, /*!< Extended read single block command */
RFAL_NFCV_CMD_EXTENDED_WRITE_SINGLE_BLOCK = 0x31U, /*!< Extended write single block command */
RFAL_NFCV_CMD_EXTENDED_LOCK_SINGLE_BLOCK = 0x32U, /*!< Extended lock single block command */
RFAL_NFCV_CMD_EXTENDED_READ_MULTIPLE_BLOCK = 0x33U, /*!< Extended read multiple block command */
RFAL_NFCV_CMD_EXTENDED_WRITE_MULTIPLE_BLOCK = 0x34U, /*!< Extended read multiple block command */
RFAL_NFCV_CMD_EXTENDED_GET_SYS_INFO = 0x3BU /*!< Extended Get System Information command */
};
/*! ST25TV/ST25DV command set */
enum
{
RFAL_NFCV_CMD_READ_CONFIGURATION = 0xA0U, /*!< Read configuration command */
RFAL_NFCV_CMD_WRITE_CONFIGURATION = 0xA1U, /*!< Write configuration command */
RFAL_NFCV_CMD_SET_EAS = 0xA2U, /*!< Set EAS command */
RFAL_NFCV_CMD_RESET_EAS = 0xA3U, /*!< Reset EAS command */
RFAL_NFCV_CMD_LOCK_EAS = 0xA4U, /*!< Lock EAS command */
RFAL_NFCV_CMD_ENABLE_EAS = 0xA5U, /*!< Enable EAS command */
RFAL_NFCV_CMD_KILL = 0xA6U, /*!< Kill command */
RFAL_NFCV_CMD_WRITE_EAS_ID = 0xA7U, /*!< Write EAS ID command */
RFAL_NFCV_CMD_WRITE_EAS_CONFIG = 0xA8U, /*!< Write EAS CONFIG command */
RFAL_NFCV_CMD_MANAGE_GPO = 0xA9U, /*!< Manage GPO command */
RFAL_NFCV_CMD_WRITE_MESSAGE = 0xAAU, /*!< Write Message command */
RFAL_NFCV_CMD_READ_MESSAGE_LENGTH = 0xABU, /*!< Read Message Length command */
RFAL_NFCV_CMD_READ_MESSAGE = 0xACU, /*!< Read Message command */
RFAL_NFCV_CMD_READ_DYN_CONFIGURATION = 0xADU, /*!< Read Dynamic Configuration command */
RFAL_NFCV_CMD_WRITE_DYN_CONFIGURATION = 0xAEU, /*!< Write Dynamic Configuration command */
RFAL_NFCV_CMD_WRITE_PASSWORD = 0xB1U, /*!< Write Kill Password / Write Password command */
RFAL_NFCV_CMD_LOCK_KILL = 0xB2U, /*!< Lock Kill command */
RFAL_NFCV_CMD_PRESENT_PASSWORD = 0xB3U, /*!< Present Password command */
RFAL_NFCV_CMD_GET_RANDOM_NUMBER = 0xB4U, /*!< Get Random Number command */
RFAL_NFCV_CMD_FAST_READ_SINGLE_BLOCK = 0xC0U, /*!< Fast Read single block command */
RFAL_NFCV_CMD_FAST_READ_MULTIPLE_BLOCKS = 0xC3U, /*!< Fast Read multiple blocks command */
RFAL_NFCV_CMD_FAST_EXTENDED_READ_SINGLE_BLOCK = 0xC4U, /*!< Fast Extended Read single block command */
RFAL_NFCV_CMD_FAST_EXTENDED_READ_MULTIPLE_BLOCKS = 0xC5U, /*!< Fast Extended Read multiple blocks command */
RFAL_NFCV_CMD_FAST_WRITE_MESSAGE = 0xCAU, /*!< Fast Write Message */
RFAL_NFCV_CMD_FAST_READ_MESSAGE_LENGTH = 0xCBU, /*!< Fast Read Message Length */
RFAL_NFCV_CMD_FAST_READ_MESSAGE = 0xCCU, /*!< Fast Read Message */
RFAL_NFCV_CMD_FAST_READ_DYN_CONFIGURATION = 0xCDU, /*!< Fast Read Dynamic configuration */
RFAL_NFCV_CMD_FAST_WRITE_DYN_CONFIGURATION = 0xCEU /*!< Fast Write Dynamic Configuration */
};
/*! ISO 15693 Get System info parameter request field ISO15693 2018 Table 94 */
enum
{
RFAL_NFCV_SYSINFO_DFSID = 0x01U, /*!< Get System info DFSID flag */
RFAL_NFCV_SYSINFO_AFI = 0x02U, /*!< Get System info AFI flag */
RFAL_NFCV_SYSINFO_MEMSIZE = 0x04U, /*!< Get System info MEMSIZE flag */
RFAL_NFCV_SYSINFO_ICREF = 0x08U, /*!< Get System info ICREF flag */
RFAL_NFCV_SYSINFO_MOI = 0x10U, /*!< Get System info MOI flag */
RFAL_NFCV_SYSINFO_CMDLIST = 0x20U, /*!< Get System info CMDLIST flag */
RFAL_NFCV_SYSINFO_CSI = 0x40U, /*!< Get System info CSI flag */
RFAL_NFCV_SYSINFO_REQ_ALL = 0x7FU /*!< Get System info request of all parameters */
};
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
/*
******************************************************************************
* GLOBAL TYPES
******************************************************************************
*/
/*! NFC-V Number of slots Digital 2.0 9.6.1 */
typedef enum
{
RFAL_NFCV_NUM_SLOTS_1 = 0x20, /*!< Number of slots: 1 */
RFAL_NFCV_NUM_SLOTS_16 = 0x00, /*!< Number of slots: 16 */
} rfalNfcvNumSlots;
/*! NFC-V INVENTORY_RES format Digital 2.0 9.6.2 */
typedef struct
{
uint8_t RES_FLAG; /*!< Response Flags */
uint8_t DSFID; /*!< Data Storage Format Identifier */
uint8_t UID[RFAL_NFCV_UID_LEN]; /*!< NFC-V device UID */
uint8_t crc[RFAL_CRC_LEN]; /*!< CRC */
} rfalNfcvInventoryRes;
/*! NFC-V Generic Req format */
typedef struct
{
uint8_t REQ_FLAG; /*!< Request Flags */
uint8_t CMD; /*!< Command code */
union { /* PRQA S 0750 # MISRA 19.2 - Both members are of the same type, just different names. Thus no problem can occur. */
uint8_t UID[RFAL_NFCV_UID_LEN]; /*!< Mask Value */
uint8_t data[RFAL_NFCV_MAX_GEN_DATA_LEN]; /*!< Data */
}payload; /*!< Payload */
} rfalNfcvGenericReq;
/*! NFC-V Generic Response format */
typedef struct
{
uint8_t RES_FLAG; /*!< Response Flags */
uint8_t data[RFAL_NFCV_MAX_GEN_DATA_LEN]; /*!< Data */
} rfalNfcvGenericRes;
/*! NFC-V listener device (VICC) struct */
typedef struct
{
rfalNfcvInventoryRes InvRes; /*!< INVENTORY_RES */
bool isSleep; /*!< Device sleeping flag */
} rfalNfcvListenDevice;
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief Initialize NFC-V Poller mode
*
* This methods configures RFAL RF layer to perform as a
* NFC-F Poller/RW (ISO15693) including all default timings
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_PARAM : Incorrect bitrate
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcvPollerInitialize( void );
/*!
*****************************************************************************
* \brief NFC-V Poller Check Presence
*
* This method checks if a NFC-V Listen device (VICC) is present on the field
* by sending an Inventory (INVENTORY_REQ)
*
* \param[out] invRes : If received, the INVENTORY_RES
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error, no listener device detectedd
* \return ERR_NONE : No error, one or more device in the field
*****************************************************************************
*/
ReturnCode rfalNfcvPollerCheckPresence( rfalNfcvInventoryRes *invRes );
/*!
*****************************************************************************
* \brief NFC-F Poller Poll
*
* This function sends to all VICCs in field the INVENTORY command with the
* given number of slots
*
* If more than one slot is used the following EOF need to be handled
* by the caller using rfalISO15693TransceiveEOFAnticollision()
*
* \param[in] nSlots : Number of Slots to be sent (1 or 16)
* \param[in] maskLen : Number bits on the Mask value
* \param[in] maskVal : location of the Mask value
* \param[out] invRes : location to place the INVENTORY_RES
* \param[out] rcvdLen : number of bits received (without collision)
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_RF_COLLISION : Collision detected
* \return ERR_CRC : CRC error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcvPollerInventory( rfalNfcvNumSlots nSlots, uint8_t maskLen, const uint8_t *maskVal, rfalNfcvInventoryRes *invRes, uint16_t* rcvdLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Full Collision Resolution
*
* Performs a full Collision resolution as defined in Activity 2.0 9.3.7
* Once done, the devCnt will indicate how many (if any) devices have
* been identified and their details are contained on nfcvDevList
*
* \param[in] compMode : compliance mode to be performed
* \param[in] devLimit : device limit value, and size nfcaDevList
* \param[out] nfcvDevList : NFC-v listener devices list
* \param[out] devCnt : Devices found counter
*
* When compMode is set to ISO the function immediately goes to 16 slots improving
* chances to detect more than only one strong card.
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcvPollerCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcvListenDevice *nfcvDevList, uint8_t *devCnt );
/*!
*****************************************************************************
* \brief NFC-V Poller Full Collision Resolution With Sleep
*
* Performs a full Collision resolution which is different from Activity 2.0 9.3.7.
* The implementation uses SLPV (StayQuiet) command to make sure all cards are found.
* Once done, the devCnt will indicate how many (if any) devices have
* been identified and their details are contained on nfcvDevList
*
* \param[in] devLimit : device limit value, and size nfcaDevList
* \param[out] nfcvDevList : NFC-v listener devices list
* \param[out] devCnt : Devices found counter
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcvPollerSleepCollisionResolution( uint8_t devLimit, rfalNfcvListenDevice *nfcvDevList, uint8_t *devCnt );
/*!
*****************************************************************************
* \brief NFC-V Poller Sleep
*
* This function is used to send the SLPV_REQ (Stay Quiet) command to put the VICC
* with the given UID to state QUIET so that they do not reply to more Inventory
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to Sleep
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcvPollerSleep( uint8_t flags, const uint8_t* uid );
/*!
*****************************************************************************
* \brief NFC-V Poller Select
*
* Selects a device (VICC) by its UID
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be Selected
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcvPollerSelect( uint8_t flags, const uint8_t* uid );
/*!
*****************************************************************************
* \brief NFC-V Poller Read Single Block
*
* Reads a Single Block from a device (VICC)
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] blockNum : Number of the block to read
* \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
* \param[in] rxBufLen : length of rxBuf
* \param[out] rcvLen : number of bytes received
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcvPollerReadSingleBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Write Single Block
*
* Writes a Single Block from a device (VICC)
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be written
* if not provided Select mode will be used
* \param[in] blockNum : Number of the block to write
* \param[in] wrData : data to be written on the given block
* \param[in] blockLen : number of bytes of a block
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcvPollerWriteSingleBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum, const uint8_t* wrData, uint8_t blockLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Read Multiple Blocks
*
* Reads Multiple Blocks from a device (VICC)
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] firstBlockNum : first block to be read
* \param[in] numOfBlocks : number of block to read
* \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
* \param[in] rxBufLen : length of rxBuf
* \param[out] rcvLen : number of bytes received
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcvPollerReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint8_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Write Multiple Blocks
*
* Reads Multiple Blocks from a device (VICC)
* In order to not limit the length of the Write multiple command, a buffer
* must be provided where the request will be composed and then sent.
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] firstBlockNum : first block to be write
* \param[in] numOfBlocks : number of consecutive blocks to write
* \param[in] txBuf : buffer where the request will be composed
* \param[in] txBufLen : length of txBuf
* \param[in] blockLen : number of bytes of a block
* \param[in] wrData : data to be written
* \param[in] wrDataLen : length of the data do be written. Must be
* aligned with number of blocks to write and
* the size of a block
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcvPollerWriteMultipleBlocks( uint8_t flags, const uint8_t* uid, uint8_t firstBlockNum, uint8_t numOfBlocks, uint8_t *txBuf, uint16_t txBufLen, uint8_t blockLen, const uint8_t* wrData, uint16_t wrDataLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Extended Lock Single Block
*
* Blocks a Single Block from a device (VICC) supporting extended commands
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device
* if not provided Select mode will be used
* \param[in] blockNum : Number of the block to be locked
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcvPollerLockBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum );
/*!
*****************************************************************************
* \brief NFC-V Poller Extended Lock Single Block
*
* Blocks a Single Block from a device (VICC) supporting extended commands
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device
* if not provided Select mode will be used
* \param[in] blockNum : Number of the block to be locked (16 bits)
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcvPollerExtendedLockSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum );
/*!
*****************************************************************************
* \brief NFC-V Poller Extended Read Single Block
*
* Reads a Single Block from a device (VICC) supporting extended commands
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] blockNum : Number of the block to read (16 bits)
* \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
* \param[in] rxBufLen : length of rxBuf
* \param[out] rcvLen : number of bytes received
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcvPollerExtendedReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Extended Write Single Block
*
* Writes a Single Block from a device (VICC) supporting extended commands
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device
* if not provided Select mode will be used
* \param[in] blockNum : Number of the block to write (16 bits)
* \param[in] wrData : data to be written on the given block
* \param[in] blockLen : number of bytes of a block
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcvPollerExtendedWriteSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, const uint8_t* wrData, uint8_t blockLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Extended Read Multiple Blocks
*
* Reads Multiple Blocks from a device (VICC) supporting extended commands
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] firstBlockNum : first block to be read (16 bits)
* \param[in] numOfBlocks : number of consecutive blocks to read (16 bits)
* \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
* \param[in] rxBufLen : length of rxBuf
* \param[out] rcvLen : number of bytes received
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcvPollerExtendedReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint16_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Extended Write Multiple Blocks
*
* Writes Multiple Blocks from a device (VICC) supporting extended commands
* In order to not limit the length of the Write multiple command, a buffer
* must be provided where the request will be composed and then sent.
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] firstBlockNum : first block to be write (16 bits)
* \param[in] numOfBlocks : number of consecutive blocks to write (16 bits)
* \param[in] txBuf : buffer where the request will be composed
* \param[in] txBufLen : length of txBuf
* \param[in] blockLen : number of bytes of a block
* \param[in] wrData : data to be written
* \param[in] wrDataLen : length of the data do be written. Must be
* aligned with number of blocks to write and
* the size of a block
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcvPollerExtendedWriteMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint16_t numOfBlocks, uint8_t *txBuf, uint16_t txBufLen, uint8_t blockLen, const uint8_t* wrData, uint16_t wrDataLen );
/*!
*****************************************************************************
* \brief NFC-V Get System Information
*
* Sends Get System Information command
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
* \param[in] rxBufLen : length of rxBuf
* \param[out] rcvLen : number of bytes received
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcvPollerGetSystemInformation( uint8_t flags, const uint8_t* uid, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-V Extended Get System Information
*
* Sends Extended Get System Information command
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] requestField : Get System info parameter request field
* \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
* \param[in] rxBufLen : length of rxBuf
* \param[out] rcvLen : number of bytes received
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcvPollerExtendedGetSystemInformation( uint8_t flags, const uint8_t* uid, uint8_t requestField, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-V Transceive Request
*
* Performs a generic transceive with an ISO15693 tag
*
* \param[in] cmd : NFC-V command
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] param : Prepend parameter on certain proprietary requests
* For default commands skip: RFAL_NFCV_PARAM_SKIP
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] data : command parameters append after UID
* \param[in] dataLen : command parameters Len
* \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
* \param[in] rxBufLen : length of rxBuf
* \param[out] rcvLen : number of bytes received
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalNfcvPollerTransceiveReq( uint8_t cmd, uint8_t flags, uint8_t param, const uint8_t* uid, const uint8_t *data, uint16_t dataLen, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
#endif /* RFAL_NFCV_H */
/**
* @}
*
* @}
*
* @}
*/

File diff suppressed because it is too large Load Diff

View File

@ -1,355 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_st25tb.h
*
* \author Gustavo Patricio
*
* \brief Implementation of ST25TB interface
*
*
* \addtogroup RFAL
* @{
*
* \addtogroup RFAL-AL
* \brief RFAL Abstraction Layer
* @{
*
* \addtogroup ST25TB
* \brief RFAL ST25TB Module
* @{
*
*/
#ifndef RFAL_ST25TB_H
#define RFAL_ST25TB_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
#include "st_errno.h"
#include "rfal_rf.h"
#include "rfal_nfcb.h"
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_ST25TB_CHIP_ID_LEN 1U /*!< ST25TB chip ID length */
#define RFAL_ST25TB_CRC_LEN 2U /*!< ST25TB CRC length */
#define RFAL_ST25TB_UID_LEN 8U /*!< ST25TB Unique ID length */
#define RFAL_ST25TB_BLOCK_LEN 4U /*!< ST25TB Data Block length */
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
/*
******************************************************************************
* GLOBAL TYPES
******************************************************************************
*/
typedef uint8_t rfalSt25tbUID[RFAL_ST25TB_UID_LEN]; /*!< ST25TB UID type */
typedef uint8_t rfalSt25tbBlock[RFAL_ST25TB_BLOCK_LEN]; /*!< ST25TB Block type */
/*! ST25TB listener device (PICC) struct */
typedef struct
{
uint8_t chipID; /*!< Device's session Chip ID */
rfalSt25tbUID UID; /*!< Device's UID */
bool isDeselected; /*!< Device deselect flag */
}rfalSt25tbListenDevice;
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief Initialize ST25TB Poller mode
*
* This methods configures RFAL RF layer to perform as a
* ST25TB Poller/RW including all default timings
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalSt25tbPollerInitialize( void );
/*!
*****************************************************************************
* \brief ST25TB Poller Check Presence
*
* This method checks if a ST25TB Listen device (PICC) is present on the field
* by sending an Initiate command
*
* \param[out] chipId : if successfully retrieved, the device's chip ID
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error, no listener device detected
* \return ERR_RF_COLLISION : Collision detected one or more device in the field
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalSt25tbPollerCheckPresence( uint8_t *chipId );
/*!
*****************************************************************************
* \brief ST25TB Poller Collision Resolution
*
* This method performs ST25TB Collision resolution, selects the each device,
* retrieves its UID and then deselects.
* In case only one device is identified the ST25TB device is left in select
* state.
*
* \param[in] devLimit : device limit value, and size st25tbDevList
* \param[out] st25tbDevList : ST35TB listener device info
* \param[out] devCnt : Devices found counter
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error, no listener device detected
* \return ERR_RF_COLLISION : Collision detected one or more device in the field
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalSt25tbPollerCollisionResolution( uint8_t devLimit, rfalSt25tbListenDevice *st25tbDevList, uint8_t *devCnt );
/*!
*****************************************************************************
* \brief ST25TB Poller Initiate
*
* This method sends an Initiate command
*
* If a single device responds the chip ID will be retrieved
*
* \param[out] chipId : chip ID of the device
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error, no listener device detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalSt25tbPollerInitiate( uint8_t *chipId );
/*!
*****************************************************************************
* \brief ST25TB Poller Pcall
*
* This method sends a Pcall command
* If successful the device's chip ID will be retrieved
*
* \param[out] chipId : Chip ID of the device
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error, no listener device detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalSt25tbPollerPcall( uint8_t *chipId );
/*!
*****************************************************************************
* \brief ST25TB Poller Slot Marker
*
* This method sends a Slot Marker
*
* If a single device responds the chip ID will be retrieved
*
* \param[in] slotNum : Slot Number
* \param[out] chipIdRes : Chip ID of the device
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error, no listener device detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalSt25tbPollerSlotMarker( uint8_t slotNum, uint8_t *chipIdRes );
/*!
*****************************************************************************
* \brief ST25TB Poller Select
*
* This method sends a ST25TB Select command with the given chip ID.
*
* If the device is already in Selected state and receives an incorrect chip
* ID, it goes into Deselected state
*
* \param[in] chipId : chip ID of the device to be selected
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error, no listener device detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalSt25tbPollerSelect( uint8_t chipId );
/*!
*****************************************************************************
* \brief ST25TB Get UID
*
* This method sends a Get_UID command
*
* If a single device responds the chip UID will be retrieved
*
* \param[out] UID : UID of the found device
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error, no listener device detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalSt25tbPollerGetUID( rfalSt25tbUID *UID );
/*!
*****************************************************************************
* \brief ST25TB Poller Read Block
*
* This method reads a block of the ST25TB
*
* \param[in] blockAddress : address of the block to be read
* \param[out] blockData : location to place the data read from block
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error, no listener device detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalSt25tbPollerReadBlock( uint8_t blockAddress, rfalSt25tbBlock *blockData );
/*!
*****************************************************************************
* \brief ST25TB Poller Write Block
*
* This method writes a block of the ST25TB
*
* \param[in] blockAddress : address of the block to be written
* \param[in] blockData : data to be written on the block
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error, no listener device detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalSt25tbPollerWriteBlock( uint8_t blockAddress, const rfalSt25tbBlock *blockData );
/*!
*****************************************************************************
* \brief ST25TB Poller Completion
*
* This method sends a completion command to the ST25TB. After the
* completion the card no longer will reply to any command.
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error, no listener device detected
* \return ERR_PROTO : Protocol error detected, invalid SENSB_RES received
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalSt25tbPollerCompletion( void );
/*!
*****************************************************************************
* \brief ST25TB Poller Reset to Inventory
*
* This method sends a Reset to Inventory command to the ST25TB.
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_TIMEOUT : Timeout error, no listener device detected
* \return ERR_PROTO : Protocol error detected, invalid SENSB_RES received
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalSt25tbPollerResetToInventory( void );
#endif /* RFAL_ST25TB_H */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,729 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_st25xv.h
*
* \author Gustavo Patricio
*
* \brief NFC-V ST25 NFC-V Tag specific features
*
* This module provides support for ST's specific features available on
* NFC-V (ISO15693) tag families: ST25D, ST25TV, M24LR
*
*
* \addtogroup RFAL
* @{
*
* \addtogroup RFAL-AL
* \brief RFAL Abstraction Layer
* @{
*
* \addtogroup ST25xV
* \brief RFAL ST25xV Module
* @{
*
*/
#ifndef RFAL_ST25xV_H
#define RFAL_ST25xV_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
#include "st_errno.h"
#include "rfal_nfc.h"
#include "rfal_rf.h"
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_NFCV_BLOCKNUM_M24LR_LEN 2U /*!< Block Number length of MR24LR tags: 16 bits */
#define RFAL_NFCV_ST_IC_MFG_CODE 0x02 /*!< ST IC Mfg code (used for custom commands) */
/*!
*****************************************************************************
* \brief NFC-V Poller Read Single Block (M24LR)
*
* Reads a Single Block from a M24LR tag which has the number of blocks
* bigger than 256 (M24LR16 ; M24LR64)
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* default: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] blockNum : Number of the block to read (16 bits)
* \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
* \param[in] rxBufLen : length of rxBuf
* \param[out] rcvLen : number of bytes received
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerM24LRReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Fast Read Single Block (M24LR)
*
* Reads a Single Block from a M24LR tag which has the number of blocks
* bigger than 256 (M24LR16 ; M24LR64) using ST Fast mode
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* default: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] blockNum : Number of the block to read (16 bits)
* \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
* \param[in] rxBufLen : length of rxBuf
* \param[out] rcvLen : number of bytes received
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerM24LRFastReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Write Single Block (M24LR)
*
* Writes a Single Block from a M24LR tag which has the number of blocks
* bigger than 256 (M24LR16 ; M24LR64)
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be written
* if not provided Select mode will be used
* \param[in] blockNum : Number of the block to write (16 bits)
* \param[in] wrData : data to be written on the given block
* \param[in] blockLen : number of bytes of a block
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerM24LRWriteSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, const uint8_t* wrData, uint8_t blockLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Read Multiple Blocks (M24LR)
*
* Reads Multiple Blocks from a device from a M24LR tag which has the number of blocks
* bigger than 256 (M24LR16 ; M24LR64)
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] firstBlockNum : first block to be read (16 bits)
* \param[in] numOfBlocks : number of block to read
* \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
* \param[in] rxBufLen : length of rxBuf
* \param[out] rcvLen : number of bytes received
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerM24LRReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Fast Read Multiple Blocks (M24LR)
*
* Reads Multiple Blocks from a device from a M24LR tag which has the number of blocks
* bigger than 256 (M24LR16 ; M24LR64) using ST Fast mode
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] firstBlockNum : first block to be read (16 bits)
* \param[in] numOfBlocks : number of block to read
* \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
* \param[in] rxBufLen : length of rxBuf
* \param[out] rcvLen : number of bytes received
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerM24LRFastReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Fast Read Single Block
*
* Reads a Single Block from a device (VICC) using ST Fast mode
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] blockNum : Number of the block to read
* \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
* \param[in] rxBufLen : length of rxBuf
* \param[out] rcvLen : number of bytes received
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerFastReadSingleBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Fast Read Multiple Blocks
*
* Reads Multiple Blocks from a device (VICC) using ST Fast mode
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] firstBlockNum : first block to be read
* \param[in] numOfBlocks : number of block to read
* \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
* \param[in] rxBufLen : length of rxBuf
* \param[out] rcvLen : number of bytes received
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerFastReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint8_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Fast Extended Read Single Block
*
* Reads a Single Block from a device (VICC) supporting extended commands using ST Fast mode
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] blockNum : Number of the block to read (16 bits)
* \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
* \param[in] rxBufLen : length of rxBuf
* \param[out] rcvLen : number of bytes received
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerFastExtendedReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Fast Extended Read Multiple Blocks
*
* Reads Multiple Blocks from a device (VICC) supporting extended commands using ST Fast mode
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] firstBlockNum : first block to be read (16 bits)
* \param[in] numOfBlocks : number of consecutive blocks to read (16 bits)
* \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
* \param[in] rxBufLen : length of rxBuf
* \param[out] rcvLen : number of bytes received
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerFastExtReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint16_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Read Configuration
*
* Reads static configuration registers at the Pointer address
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] pointer : Pointer address
* \param[out] regValue : Register value
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerReadConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue );
/*!
*****************************************************************************
* \brief NFC-V Poller Write Configuration
*
* Writes static configuration registers at the Pointer address
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] pointer : Pointer address
* \param[in] regValue : Register value
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerWriteConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue );
/*!
*****************************************************************************
* \brief NFC-V Poller Read Dynamic Configuration
*
* Reads dynamic registers at the Pointer address
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] pointer : Pointer address
* \param[out] regValue : Register value
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerReadDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue );
/*!
*****************************************************************************
* \brief NFC-V Poller Write Dynamic Configuration
*
* Writes dynamic registers at the Pointer address
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] pointer : Pointer address
* \param[in] regValue : Register value
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerWriteDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue );
/*!
*****************************************************************************
* \brief NFC-V Poller Fast Read Dynamic Configuration
*
* Reads dynamic registers at the Pointer address using ST Fast mode
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] pointer : Pointer address
* \param[out] regValue : Register value
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerFastReadDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue );
/*!
*****************************************************************************
* \brief NFC-V Poller Fast Write Dynamic Configuration
*
* Writes dynamic registers at the Pointer address using ST Fast mode
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] pointer : Pointer address
* \param[in] regValue : Register value
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerFastWriteDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue );
/*!
*****************************************************************************
* \brief NFC-V Poller Present Password
*
* Sends the Present Password command
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] pwdNum : Password number
* \param[in] pwd : Password
* \param[in] pwdLen : Password length
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerPresentPassword( uint8_t flags, const uint8_t* uid, uint8_t pwdNum, const uint8_t* pwd, uint8_t pwdLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Get Random Number
*
* Returns a 16 bit random number
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
* \param[in] rxBufLen : length of rxBuf
* \param[out] rcvLen : number of bytes received
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerGetRandomNumber( uint8_t flags, const uint8_t* uid, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Read Message length
*
* Sends a Read Message Length message to retrieve the value of MB_LEN_Dyn
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[out] msgLen : Message Length
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerReadMessageLength( uint8_t flags, const uint8_t* uid, uint8_t* msgLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Fast Read Message length
*
* Sends a Fast Read Message Length message to retrieve the value of MB_LEN_Dyn using ST Fast mode.
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[out] msgLen : Message Length
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerFastReadMsgLength( uint8_t flags, const uint8_t* uid, uint8_t* msgLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Read Message
*
* Reads up to 256 bytes in the Mailbox from the location
* specified by MBpointer and sends back their value in the rxBuf response.
* First MailBox location is '00'. When Number of bytes is set to 00h
* and MBPointer is equals to 00h, the MB_LEN bytes of the full message
* are returned. Otherwise, Read Message command returns (Number of Bytes + 1) bytes
* (i.e. 01h returns 2 bytes, FFh returns 256 bytes).
* An error is reported if (Pointer + Nb of bytes + 1) is greater than the message length.
* RF Reading of the last byte of the mailbox message automatically clears b1
* of MB_CTRL_Dyn HOST_PUT_MSG, and allows RF to put a new message.
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] mbPointer : MPpointer
* \param[in] numBytes : number of bytes
* \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
* \param[in] rxBufLen : length of rxBuf
* \param[out] rcvLen : number of bytes received
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerReadMessage( uint8_t flags, const uint8_t* uid, uint8_t mbPointer, uint8_t numBytes, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Fast Read Message
*
* Reads up to 256 bytes in the Mailbox from the location
* specified by MBpointer and sends back their value in the rxBuf response using ST Fast mode.
* First MailBox location is '00'. When Number of bytes is set to 00h
* and MBPointer is equals to 00h, the MB_LEN bytes of the full message
* are returned. Otherwise, Read Message command returns (Number of Bytes + 1) bytes
* (i.e. 01h returns 2 bytes, FFh returns 256 bytes).
* An error is reported if (Pointer + Nb of bytes + 1) is greater than the message length.
* RF Reading of the last byte of the mailbox message automatically clears b1
* of MB_CTRL_Dyn HOST_PUT_MSG, and allows RF to put a new message.
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] mbPointer : MPpointer
* \param[in] numBytes : number of bytes
* \param[out] rxBuf : buffer to store response (also with RES_FLAGS)
* \param[in] rxBufLen : length of rxBuf
* \param[out] rcvLen : number of bytes received
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerFastReadMessage( uint8_t flags, const uint8_t* uid, uint8_t mbPointer, uint8_t numBytes, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Write Message
*
* Sends Write message Command
*
* On receiving the Write Message command, the ST25DVxxx puts the data contained
* in the request into the Mailbox buffer, update the MB_LEN_Dyn register, and
* set bit RF_PUT_MSG in MB_CTRL_Dyn register. It then reports if the write operation was successful
* in the response. The ST25DVxxx Mailbox contains up to 256 data bytes which are filled from the
* first location '00'. MSGlength parameter of the command is the number of
* Data bytes minus 1 (00 for 1 byte of data, FFh for 256 bytes of data).
* Write Message could be executed only when Mailbox is accessible by RF.
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] msgLen : MSGLen number of Data bytes minus 1
* \param[in] msgData : Message Data
* \param[out] txBuf : buffer to used to build the Write Message command
* \param[in] txBufLen : length of txBuf
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerWriteMessage( uint8_t flags, const uint8_t* uid, uint8_t msgLen, const uint8_t* msgData, uint8_t* txBuf, uint16_t txBufLen );
/*!
*****************************************************************************
* \brief NFC-V Poller Fast Write Message
*
* Sends Fast Write message Command using ST Fast mode
*
* On receiving the Write Message command, the ST25DVxxx puts the data contained
* in the request into the Mailbox buffer, update the MB_LEN_Dyn register, and
* set bit RF_PUT_MSG in MB_CTRL_Dyn register. It then reports if the write operation was successful
* in the response. The ST25DVxxx Mailbox contains up to 256 data bytes which are filled from the
* first location '00'. MSGlength parameter of the command is the number of
* Data bytes minus 1 (00 for 1 byte of data, FFh for 256 bytes of data).
* Write Message could be executed only when Mailbox is accessible by RF.
*
* \param[in] flags : Flags to be used: Sub-carrier; Data_rate; Option
* for NFC-Forum use: RFAL_NFCV_REQ_FLAG_DEFAULT
* \param[in] uid : UID of the device to be put to be read
* if not provided Select mode will be used
* \param[in] msgLen : MSGLen number of Data bytes minus 1
* \param[in] msgData : Message Data
* \param[out] txBuf : buffer to used to build the Write Message command
* \param[in] txBufLen : length of txBuf
*
* \return ERR_WRONG_STATE : RFAL not initialized or incorrect mode
* \return ERR_PARAM : Invalid parameters
* \return ERR_IO : Generic internal error
* \return ERR_CRC : CRC error detected
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_TIMEOUT : Timeout error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalST25xVPollerFastWriteMessage( uint8_t flags, const uint8_t* uid, uint8_t msgLen, const uint8_t* msgData, uint8_t* txBuf, uint16_t txBufLen );
#endif /* RFAL_ST25xV_H */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,187 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_t1t.h
*
* \author Gustavo Patricio
*
* \brief Provides NFC-A T1T convenience methods and definitions
*
* This module provides an interface to perform as a NFC-A Reader/Writer
* to handle a Type 1 Tag T1T (Topaz)
*
*
* \addtogroup RFAL
* @{
*
* \addtogroup RFAL-AL
* \brief RFAL Abstraction Layer
* @{
*
* \addtogroup T1T
* \brief RFAL T1T Module
* @{
*
*/
#ifndef RFAL_T1T_H
#define RFAL_T1T_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
#include "st_errno.h"
#include "rfal_rf.h"
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_T1T_UID_LEN 4 /*!< T1T UID length of cascade level 1 only tag */
#define RFAL_T1T_HR_LENGTH 2 /*!< T1T HR(Header ROM) length */
#define RFAL_T1T_HR0_NDEF_MASK 0xF0 /*!< T1T HR0 NDEF capability mask T1T 1.2 2.2.2 */
#define RFAL_T1T_HR0_NDEF_SUPPORT 0x10 /*!< T1T HR0 NDEF capable value T1T 1.2 2.2.2 */
/*! NFC-A T1T (Topaz) command set */
typedef enum
{
RFAL_T1T_CMD_RID = 0x78, /*!< T1T Read UID */
RFAL_T1T_CMD_RALL = 0x00, /*!< T1T Read All */
RFAL_T1T_CMD_READ = 0x01, /*!< T1T Read */
RFAL_T1T_CMD_WRITE_E = 0x53, /*!< T1T Write with erase (single byte) */
RFAL_T1T_CMD_WRITE_NE = 0x1A /*!< T1T Write with no erase (single byte) */
} rfalT1Tcmds;
/*
******************************************************************************
* GLOBAL TYPES
******************************************************************************
*/
/*! NFC-A T1T (Topaz) RID_RES Digital 1.1 10.6.2 & Table 50 */
typedef struct
{
uint8_t hr0; /*!< T1T Header ROM: HR0 */
uint8_t hr1; /*!< T1T Header ROM: HR1 */
uint8_t uid[RFAL_T1T_UID_LEN]; /*!< T1T UID */
} rfalT1TRidRes;
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief Initialize NFC-A T1T Poller mode
*
* This methods configures RFAL RF layer to perform as a
* NFC-A T1T Poller/RW (Topaz) including all default timings
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalT1TPollerInitialize( void );
/*!
*****************************************************************************
* \brief NFC-A T1T Poller RID
*
* This method reads the UID of a NFC-A T1T Listener device
*
*
* \param[out] ridRes : pointer to place the RID_RES
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_PARAM : Invalid parameter
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalT1TPollerRid( rfalT1TRidRes *ridRes );
/*!
*****************************************************************************
* \brief NFC-A T1T Poller RALL
*
* This method send a Read All command to a NFC-A T1T Listener device
*
*
* \param[in] uid : the UID of the device to read data
* \param[out] rxBuf : pointer to place the read data
* \param[in] rxBufLen : size of rxBuf
* \param[out] rxRcvdLen : actual received data
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_PARAM : Invalid parameter
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalT1TPollerRall( const uint8_t* uid, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rxRcvdLen );
/*!
*****************************************************************************
* \brief NFC-A T1T Poller Write
*
* This method writes the given data on the address of a NFC-A T1T Listener device
*
*
* \param[in] uid : the UID of the device to read data
* \param[in] address : address to write the data
* \param[in] data : the data to be written
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_PARAM : Invalid parameter
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalT1TPollerWrite( const uint8_t* uid, uint8_t address, uint8_t data );
#endif /* RFAL_T1T_H */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,153 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_t2t.h
*
* \author Gustavo Patricio
*
* \brief Provides NFC-A T2T convenience methods and definitions
*
* This module provides an interface to perform as a NFC-A Reader/Writer
* to handle a Type 2 Tag T2T
*
*
* \addtogroup RFAL
* @{
*
* \addtogroup RFAL-AL
* \brief RFAL Abstraction Layer
* @{
*
* \addtogroup T2T
* \brief RFAL T2T Module
* @{
*
*/
#ifndef RFAL_T2T_H
#define RFAL_T2T_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
#include "st_errno.h"
#include "rfal_rf.h"
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_T2T_BLOCK_LEN 4U /*!< T2T block length */
#define RFAL_T2T_READ_DATA_LEN (4U * RFAL_T2T_BLOCK_LEN) /*!< T2T READ data length */
#define RFAL_T2T_WRITE_DATA_LEN RFAL_T2T_BLOCK_LEN /*!< T2T WRITE data length */
/*
******************************************************************************
* GLOBAL TYPES
******************************************************************************
*/
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief NFC-A T2T Poller Read
*
* This method sends a Read command to a NFC-A T2T Listener device
*
*
* \param[in] blockNum : Number of the block to read
* \param[out] rxBuf : pointer to place the read data
* \param[in] rxBufLen : size of rxBuf (RFAL_T2T_READ_DATA_LEN)
* \param[out] rcvLen : actual received data
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_PARAM : Invalid parameter
* \return ERR_PROTO : Protocol error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalT2TPollerRead( uint8_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
/*!
*****************************************************************************
* \brief NFC-A T2T Poller Write
*
* This method sends a Write command to a NFC-A T2T Listener device
*
*
* \param[in] blockNum : Number of the block to write
* \param[in] wrData : data to be written on the given block
* size must be of RFAL_T2T_WRITE_DATA_LEN
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_PARAM : Invalid parameter
* \return ERR_PROTO : Protocol error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalT2TPollerWrite( uint8_t blockNum, const uint8_t* wrData );
/*!
*****************************************************************************
* \brief NFC-A T2T Poller Sector Select
*
* This method sends a Sector Select commands to a NFC-A T2T Listener device
*
* \param[in] sectorNum : Sector Number
*
* \return ERR_WRONG_STATE : RFAL not initialized or mode not set
* \return ERR_PARAM : Invalid parameter
* \return ERR_PROTO : Protocol error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalT2TPollerSectorSelect( uint8_t sectorNum );
#endif /* RFAL_T2T_H */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,365 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_t4t.h
*
* \author Gustavo Patricio
*
* \brief Provides convenience methods and definitions for T4T (ISO7816-4)
*
* This module provides an interface to exchange T4T APDUs according to
* NFC Forum T4T and ISO7816-4
*
* This implementation was based on the following specs:
* - ISO/IEC 7816-4 3rd Edition 2013-04-15
* - NFC Forum T4T Technical Specification 1.0 2017-08-28
*
* \addtogroup RFAL
* @{
*
* \addtogroup RFAL-AL
* \brief RFAL Abstraction Layer
* @{
*
* \addtogroup T4T
* \brief RFAL T4T Module
* @{
*
*/
#ifndef RFAL_T4T_H
#define RFAL_T4T_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
#include "st_errno.h"
#include "rfal_rf.h"
#include "rfal_isoDep.h"
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_T4T_MAX_CAPDU_PROLOGUE_LEN 4U /*!< Command-APDU prologue length (CLA INS P1 P2) */
#define RFAL_T4T_LE_LEN 1U /*!< Le Expected Response Length (short field coding) */
#define RFAL_T4T_LC_LEN 1U /*!< Lc Data field length (short field coding) */
#define RFAL_T4T_MAX_RAPDU_SW1SW2_LEN 2U /*!< SW1 SW2 length */
#define RFAL_T4T_CLA 0x00U /*!< Class byte (contains 00h because secure message are not used) */
#define RFAL_T4T_ISO7816_P1_SELECT_BY_DF_NAME 0x04U /*!< P1 value for Select by name */
#define RFAL_T4T_ISO7816_P1_SELECT_BY_FILEID 0x00U /*!< P1 value for Select by file identifier */
#define RFAL_T4T_ISO7816_P2_SELECT_FIRST_OR_ONLY_OCCURENCE 0x00U /*!< b2b1 P2 value for First or only occurence */
#define RFAL_T4T_ISO7816_P2_SELECT_RETURN_FCI_TEMPLATE 0x00U /*!< b4b3 P2 value for Return FCI template */
#define RFAL_T4T_ISO7816_P2_SELECT_NO_RESPONSE_DATA 0x0CU /*!< b4b3 P2 value for No responce data */
#define RFAL_T4T_ISO7816_STATUS_COMPLETE 0x9000U /*!< Command completed \ Normal processing - No further qualification*/
/*
******************************************************************************
* GLOBAL VARIABLES
******************************************************************************
*/
/*
******************************************************************************
* GLOBAL TYPES
******************************************************************************
*/
/*! NFC-A T4T Command-APDU structure */
typedef struct
{
uint8_t CLA; /*!< Class byte */
uint8_t INS; /*!< Instruction byte */
uint8_t P1; /*!< Parameter byte 1 */
uint8_t P2; /*!< Parameter byte 2 */
uint8_t Lc; /*!< Data field length */
bool LcFlag; /*!< Lc flag (append Lc when true) */
uint8_t Le; /*!< Expected Response Length */
bool LeFlag; /*!< Le flag (append Le when true) */
rfalIsoDepApduBufFormat *cApduBuf; /*!< Command-APDU buffer (Tx) */
uint16_t *cApduLen; /*!< Command-APDU Length */
}rfalT4tCApduParam;
/*! NFC-A T4T Response-APDU structure */
typedef struct
{
rfalIsoDepApduBufFormat *rApduBuf; /*!< Response-APDU buffer (Rx) */
uint16_t rcvdLen; /*!< Full response length */
uint16_t rApduBodyLen; /*!< Response body length */
uint16_t statusWord; /*!< R-APDU Status Word SW1|SW2 */
}rfalT4tRApduParam;
/*! NFC-A T4T command set T4T 1.0 & ISO7816-4 2013 Table 4 */
typedef enum
{
RFAL_T4T_INS_SELECT = 0xA4U, /*!< T4T Select */
RFAL_T4T_INS_READBINARY = 0xB0U, /*!< T4T ReadBinary */
RFAL_T4T_INS_UPDATEBINARY = 0xD6U, /*!< T4T UpdateBinay */
RFAL_T4T_INS_READBINARY_ODO = 0xB1U, /*!< T4T ReadBinary using ODO */
RFAL_T4T_INS_UPDATEBINARY_ODO = 0xD7U /*!< T4T UpdateBinay using ODO */
} rfalT4tCmds;
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief T4T Compose APDU
*
* This method computes a C-APDU according to NFC Forum T4T and ISO7816-4.
*
* If C-APDU contains data to be sent, it must be placed inside the buffer
* rfalT4tTxRxApduParam.txRx.cApduBuf.apdu and signaled by Lc
*
* To transceive the formed APDU the ISO-DEP layer shall be used
*
* \see rfalIsoDepStartApduTransceive()
* \see rfalIsoDepGetApduTransceiveStatus()
* \see rfalT4TPollerParseRAPDU()
*
* \warning The ISO-DEP module is used to perform the tranceive. Usually
* activation has been done via ISO-DEP activatiavtion. If not
* please call rfalIsoDepInitialize() before.
*
* \param[in,out] apduParam : APDU parameters
* apduParam.cApduLen will contain the APDU length
*
* \return ERR_PARAM : Invalid parameter
* \return ERR_PROTO : Protocol error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalT4TPollerComposeCAPDU( rfalT4tCApduParam *apduParam );
/*!
*****************************************************************************
* \brief T4T Parse R-APDU
*
* This method parses a R-APDU according to NFC Forum T4T and ISO7816-4.
* It will extract the data length and check if the Satus word is expected.
*
* \param[in,out] apduParam : APDU parameters
* apduParam.rApduBodyLen will contain the data length
* apduParam.statusWord will contain the SW1 and SW2
*
* \return ERR_REQUEST : Status word (SW1 SW2) different from 9000
* \return ERR_PARAM : Invalid parameter
* \return ERR_PROTO : Protocol error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalT4TPollerParseRAPDU( rfalT4tRApduParam *apduParam );
/*!
*****************************************************************************
* \brief T4T Compose Select Application APDU
*
* This method computes a Select Application APDU according to NFC Forum T4T
*
* To transceive the formed APDU the ISO-DEP layer shall be used
*
* \see rfalIsoDepStartApduTransceive()
* \see rfalIsoDepGetApduTransceiveStatus()
*
* \param[out] cApduBuf : buffer where the C-APDU will be placed
* \param[in] aid : Application ID to be used
* \param[in] aidLen : Application ID length
* \param[out] cApduLen : Composed C-APDU length
*
* \return ERR_PARAM : Invalid parameter
* \return ERR_PROTO : Protocol error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalT4TPollerComposeSelectAppl( rfalIsoDepApduBufFormat *cApduBuf, const uint8_t* aid, uint8_t aidLen, uint16_t *cApduLen );
/*!
*****************************************************************************
* \brief T4T Compose Select File APDU
*
* This method computes a Select File APDU according to NFC Forum T4T
*
* To transceive the formed APDU the ISO-DEP layer shall be used
*
* \see rfalIsoDepStartApduTransceive()
* \see rfalIsoDepGetApduTransceiveStatus()
*
* \param[out] cApduBuf : buffer where the C-APDU will be placed
* \param[in] fid : File ID to be used
* \param[in] fidLen : File ID length
* \param[out] cApduLen : Composed C-APDU length
*
* \return ERR_PARAM : Invalid parameter
* \return ERR_PROTO : Protocol error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalT4TPollerComposeSelectFile( rfalIsoDepApduBufFormat *cApduBuf, const uint8_t* fid, uint8_t fidLen, uint16_t *cApduLen );
/*!
*****************************************************************************
* \brief T4T Compose Select File APDU for Mapping Version 1
*
* This method computes a Select File APDU according to NFC Forum T4TOP_v1.0
*
* To transceive the formed APDU the ISO-DEP layer shall be used
*
* \see rfalIsoDepStartApduTransceive()
* \see rfalIsoDepGetApduTransceiveStatus()
*
* \param[out] cApduBuf : buffer where the C-APDU will be placed
* \param[in] fid : File ID to be used
* \param[in] fidLen : File ID length
* \param[out] cApduLen : Composed C-APDU length
*
* \return ERR_PARAM : Invalid parameter
* \return ERR_PROTO : Protocol error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalT4TPollerComposeSelectFileV1Mapping( rfalIsoDepApduBufFormat *cApduBuf, const uint8_t* fid, uint8_t fidLen, uint16_t *cApduLen );
/*!
*****************************************************************************
* \brief T4T Compose Read Data APDU
*
* This method computes a Read Data APDU according to NFC Forum T4T
*
* To transceive the formed APDU the ISO-DEP layer shall be used
*
* \see rfalIsoDepStartApduTransceive()
* \see rfalIsoDepGetApduTransceiveStatus()
*
* \param[out] cApduBuf : buffer where the C-APDU will be placed
* \param[in] offset : File offset
* \param[in] expLen : Expected length (Le)
* \param[out] cApduLen : Composed C-APDU length
*
* \return ERR_PARAM : Invalid parameter
* \return ERR_PROTO : Protocol error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalT4TPollerComposeReadData( rfalIsoDepApduBufFormat *cApduBuf, uint16_t offset, uint8_t expLen, uint16_t *cApduLen );
/*!
*****************************************************************************
* \brief T4T Compose Read Data ODO APDU
*
* This method computes a Read Data ODO APDU according to NFC Forum T4T
*
* To transceive the formed APDU the ISO-DEP layer shall be used
*
* \see rfalIsoDepStartApduTransceive()
* \see rfalIsoDepGetApduTransceiveStatus()
*
* \param[out] cApduBuf : buffer where the C-APDU will be placed
* \param[in] offset : File offset
* \param[in] expLen : Expected length (Le)
* \param[out] cApduLen : Composed C-APDU length
*
* \return ERR_PARAM : Invalid parameter
* \return ERR_PROTO : Protocol error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalT4TPollerComposeReadDataODO( rfalIsoDepApduBufFormat *cApduBuf, uint32_t offset, uint8_t expLen, uint16_t *cApduLen );
/*!
*****************************************************************************
* \brief T4T Compose Write Data APDU
*
* This method computes a Write Data APDU according to NFC Forum T4T
*
* To transceive the formed APDU the ISO-DEP layer shall be used
*
* \see rfalIsoDepStartApduTransceive()
* \see rfalIsoDepGetApduTransceiveStatus()
*
* \param[out] cApduBuf : buffer where the C-APDU will be placed
* \param[in] offset : File offset
* \param[in] data : Data to be written
* \param[in] dataLen : Data length to be written (Lc)
* \param[out] cApduLen : Composed C-APDU length
*
* \return ERR_PARAM : Invalid parameter
* \return ERR_PROTO : Protocol error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalT4TPollerComposeWriteData( rfalIsoDepApduBufFormat *cApduBuf, uint16_t offset, const uint8_t* data, uint8_t dataLen, uint16_t *cApduLen );
/*!
*****************************************************************************
* \brief T4T Compose Write Data ODO APDU
*
* This method computes a Write Data ODO sAPDU according to NFC Forum T4T
*
* To transceive the formed APDU the ISO-DEP layer shall be used
*
* \see rfalIsoDepStartApduTransceive()
* \see rfalIsoDepGetApduTransceiveStatus()
*
* \param[out] cApduBuf : buffer where the C-APDU will be placed
* \param[in] offset : File offset
* \param[in] data : Data to be written
* \param[in] dataLen : Data length to be written (Lc)
* \param[out] cApduLen : Composed C-APDU length
*
* \return ERR_PARAM : Invalid parameter
* \return ERR_PROTO : Protocol error
* \return ERR_NONE : No error
*****************************************************************************
*/
ReturnCode rfalT4TPollerComposeWriteDataODO( rfalIsoDepApduBufFormat *cApduBuf, uint32_t offset, const uint8_t* data, uint8_t dataLen, uint16_t *cApduLen );
#endif /* RFAL_T4T_H */
/**
* @}
*
* @}
*
* @}
*/

View File

@ -1,417 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_analogConfig.c
*
* \author bkam
*
* \brief Funcitons to manage and set analog settings.
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "rfal_analogConfig.h"
#include "rfal_chip.h"
#include "st_errno.h"
#include "platform.h"
#include "utils.h"
/* Check whether the Default Analog settings are to be used or custom ones */
#ifdef RFAL_ANALOG_CONFIG_CUSTOM
extern const uint8_t* rfalAnalogConfigCustomSettings;
extern const uint16_t rfalAnalogConfigCustomSettingsLength;
#else
#include "rfal_analogConfigTbl.h"
#endif
/*
******************************************************************************
* DEFINES
******************************************************************************
*/
#define RFAL_TEST_REG 0x0080U /*!< Test Register indicator */
/*
******************************************************************************
* MACROS
******************************************************************************
*/
/*
******************************************************************************
* LOCAL DATA TYPES
******************************************************************************
*/
#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
static uint8_t gRfalAnalogConfig[RFAL_ANALOG_CONFIG_TBL_SIZE]; /*!< Analog Configuration Settings List */
#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
/*! Struct for Analog Config Look Up Table Update */
typedef struct {
const uint8_t *currentAnalogConfigTbl; /*!< Reference to start of current Analog Configuration */
uint16_t configTblSize; /*!< Total size of Analog Configuration */
bool ready; /*!< Indicate if Look Up Table is complete and ready for use */
} rfalAnalogConfigMgmt;
static rfalAnalogConfigMgmt gRfalAnalogConfigMgmt; /*!< Analog Configuration LUT management */
/*
******************************************************************************
* LOCAL TABLES
******************************************************************************
*/
/*
******************************************************************************
* LOCAL FUNCTION PROTOTYPES
******************************************************************************
*/
static rfalAnalogConfigNum rfalAnalogConfigSearch( rfalAnalogConfigId configId, uint16_t *configOffset );
#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
static void rfalAnalogConfigPtrUpdate( const uint8_t* analogConfigTbl );
#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
/*
******************************************************************************
* GLOBAL VARIABLE DEFINITIONS
******************************************************************************
*/
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
void rfalAnalogConfigInitialize( void )
{
/* Use default Analog configuration settings in Flash by default. */
/* Check whether the Default Analog settings are to be used or custom ones */
#ifdef RFAL_ANALOG_CONFIG_CUSTOM
gRfalAnalogConfigMgmt.currentAnalogConfigTbl = (const uint8_t *)&rfalAnalogConfigCustomSettings;
gRfalAnalogConfigMgmt.configTblSize = rfalAnalogConfigCustomSettingsLength;
#else
gRfalAnalogConfigMgmt.currentAnalogConfigTbl = (const uint8_t *)&rfalAnalogConfigDefaultSettings;
gRfalAnalogConfigMgmt.configTblSize = sizeof(rfalAnalogConfigDefaultSettings);
#endif
gRfalAnalogConfigMgmt.ready = true;
} /* rfalAnalogConfigInitialize() */
bool rfalAnalogConfigIsReady( void )
{
return gRfalAnalogConfigMgmt.ready;
}
ReturnCode rfalAnalogConfigListWriteRaw( const uint8_t *configTbl, uint16_t configTblSize )
{
#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
/* Check if the Configuration Table exceed the Table size */
if ( configTblSize >= RFAL_ANALOG_CONFIG_TBL_SIZE )
{
rfalAnalogConfigInitialize(); /* Revert to default Analog Configuration */
return ERR_NOMEM;
}
/* Check for invalid parameters */
if( (configTbl == NULL) || (configTblSize == 0U) )
{
return ERR_PARAM;
}
/* NOTE: Function does not check for the validity of the Table contents (conf IDs, conf sets, register address) */
ST_MEMCPY( gRfalAnalogConfig, configTbl, configTblSize );
/* Update the total size of configuration settings */
gRfalAnalogConfigMgmt.configTblSize = configTblSize;
rfalAnalogConfigPtrUpdate(gRfalAnalogConfig);
return ERR_NONE;
#else
// If Analog Configuration Update is to be disabled
NO_WARNING(configTbl);
NO_WARNING(configTblSize);
return ERR_REQUEST;
#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
}
ReturnCode rfalAnalogConfigListWrite( uint8_t more, const rfalAnalogConfig *config )
{
#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
rfalAnalogConfigId configId;
rfalAnalogConfigNum numConfig;
uint8_t configSize;
if (true == gRfalAnalogConfigMgmt.ready)
{ /* First Update to the Configuration list. */
gRfalAnalogConfigMgmt.ready = false; // invalidate the config List
gRfalAnalogConfigMgmt.configTblSize = 0; // Clear the config List
}
configId = GETU16(config->id);
/* Check validity of the Configuration ID. */
if ( (RFAL_ANALOG_CONFIG_TECH_RFU <= RFAL_ANALOG_CONFIG_ID_GET_TECH(configId))
||((RFAL_ANALOG_CONFIG_BITRATE_6780 < RFAL_ANALOG_CONFIG_ID_GET_BITRATE(configId)) && (RFAL_ANALOG_CONFIG_BITRATE_1OF4 > RFAL_ANALOG_CONFIG_ID_GET_BITRATE(configId)))
||(RFAL_ANALOG_CONFIG_BITRATE_1OF256 < RFAL_ANALOG_CONFIG_ID_GET_BITRATE(configId))
)
{
rfalAnalogConfigInitialize(); /* Revert to default Analog Configuration */
return ERR_PARAM;
}
numConfig = config->num;
configSize = (uint8_t)(sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum) + (numConfig * sizeof(rfalAnalogConfigRegAddrMaskVal)));
/* Check if the Configuration Set exceed the Table size. */
if ( RFAL_ANALOG_CONFIG_TBL_SIZE <= (gRfalAnalogConfigMgmt.configTblSize + configSize) )
{
rfalAnalogConfigInitialize(); /* Revert to default Analog Configuration */
return ERR_NOMEM;
}
/* NOTE: Function does not check for the validity of the Register Address. */
ST_MEMCPY(&gRfalAnalogConfig[gRfalAnalogConfigMgmt.configTblSize], (const uint8_t*)config, configSize);
/* Increment the total size of configuration settings. */
gRfalAnalogConfigMgmt.configTblSize += configSize;
/* Check if it is the last Analog Configuration to load. */
if (RFAL_ANALOG_CONFIG_UPDATE_LAST == more)
{ /* Update the Analog Configuration to the new settings. */
rfalAnalogConfigPtrUpdate(gRfalAnalogConfig);
}
return ERR_NONE;
#else
// If Analog Configuration Update is to be disabled
NO_WARNING(config);
NO_WARNING(more);
return ERR_DISABLED;
#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
} /* rfalAnalogConfigListUpdate() */
ReturnCode rfalAnalogConfigListReadRaw( uint8_t *tblBuf, uint16_t tblBufLen, uint16_t *configTblSize )
{
/* Check if the the current table will fit into the given buffer */
if( tblBufLen < gRfalAnalogConfigMgmt.configTblSize )
{
return ERR_NOMEM;
}
/* Check for invalid parameters */
if( configTblSize == NULL )
{
return ERR_PARAM;
}
/* Copy the whole Table to the given buffer */
if( gRfalAnalogConfigMgmt.configTblSize > 0U ) /* MISRA 21.18 */
{
ST_MEMCPY( tblBuf, gRfalAnalogConfigMgmt.currentAnalogConfigTbl, gRfalAnalogConfigMgmt.configTblSize );
}
*configTblSize = gRfalAnalogConfigMgmt.configTblSize;
return ERR_NONE;
}
ReturnCode rfalAnalogConfigListRead( rfalAnalogConfigOffset *configOffset, uint8_t *more, rfalAnalogConfig *config, rfalAnalogConfigNum numConfig )
{
uint16_t configSize;
rfalAnalogConfigOffset offset = *configOffset;
rfalAnalogConfigNum numConfigSet;
/* Check if the number of register-mask-value settings for the respective Configuration ID will fit into the buffer passed in. */
if (gRfalAnalogConfigMgmt.currentAnalogConfigTbl[offset + sizeof(rfalAnalogConfigId)] > numConfig)
{
return ERR_NOMEM;
}
/* Get the number of Configuration set */
numConfigSet = gRfalAnalogConfigMgmt.currentAnalogConfigTbl[offset + sizeof(rfalAnalogConfigId)];
/* Pass Configuration Register-Mask-Value sets */
configSize = (sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum) + (uint16_t)(numConfigSet * sizeof(rfalAnalogConfigRegAddrMaskVal)));
ST_MEMCPY( (uint8_t*) config
, &gRfalAnalogConfigMgmt.currentAnalogConfigTbl[offset]
, configSize
);
*configOffset = offset + configSize;
/* Check if it is the last Analog Configuration in the Table.*/
*more = (uint8_t)((*configOffset >= gRfalAnalogConfigMgmt.configTblSize) ? RFAL_ANALOG_CONFIG_UPDATE_LAST
: RFAL_ANALOG_CONFIG_UPDATE_MORE);
return ERR_NONE;
} /* rfalAnalogConfigListRead() */
ReturnCode rfalSetAnalogConfig( rfalAnalogConfigId configId )
{
rfalAnalogConfigOffset configOffset = 0;
rfalAnalogConfigNum numConfigSet;
rfalAnalogConfigRegAddrMaskVal *configTbl;
ReturnCode retCode = ERR_NONE;
rfalAnalogConfigNum i;
if (true != gRfalAnalogConfigMgmt.ready)
{
return ERR_REQUEST;
}
/* Search LUT for the specific Configuration ID. */
while(true)
{
numConfigSet = rfalAnalogConfigSearch(configId, &configOffset);
if( RFAL_ANALOG_CONFIG_LUT_NOT_FOUND == numConfigSet )
{
break;
}
configTbl = (rfalAnalogConfigRegAddrMaskVal *)( (uint32_t)gRfalAnalogConfigMgmt.currentAnalogConfigTbl + (uint32_t)configOffset);
/* Increment the offset to the next index to search from. */
configOffset += (uint16_t)(numConfigSet * sizeof(rfalAnalogConfigRegAddrMaskVal));
if ((gRfalAnalogConfigMgmt.configTblSize + 1U) < configOffset)
{ /* Error check make sure that the we do not access outside the configuration Table Size */
return ERR_NOMEM;
}
for ( i = 0; i < numConfigSet; i++)
{
if( (GETU16(configTbl[i].addr) & RFAL_TEST_REG) != 0U )
{
EXIT_ON_ERR(retCode, rfalChipChangeTestRegBits( (GETU16(configTbl[i].addr) & ~RFAL_TEST_REG), configTbl[i].mask, configTbl[i].val) );
}
else
{
EXIT_ON_ERR(retCode, rfalChipChangeRegBits( GETU16(configTbl[i].addr), configTbl[i].mask, configTbl[i].val) );
}
}
} /* while(found Analog Config Id) */
return retCode;
} /* rfalSetAnalogConfig() */
/*
******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************
*/
/*!
*****************************************************************************
* \brief Update the link to Analog Configuration LUT
*
* Update the link to the Analog Configuration LUT for the subsequent search
* of Analog Settings.
*
* \param[in] analogConfigTbl: reference to the start of the new Analog Configuration Table
*
*****************************************************************************
*/
#if RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG
static void rfalAnalogConfigPtrUpdate( const uint8_t* analogConfigTbl )
{
gRfalAnalogConfigMgmt.currentAnalogConfigTbl = analogConfigTbl;
gRfalAnalogConfigMgmt.ready = true;
} /* rfalAnalogConfigPtrUpdate() */
#endif /* RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG */
/*!
*****************************************************************************
* \brief Search the Analog Configuration LUT for a specific Configuration ID.
*
* Search the Analog Configuration LUT for the Configuration ID.
*
* \param[in] configId: Configuration ID to search for.
* \param[in] configOffset: Configuration Offset in Table
*
* \return number of Configuration Sets
* \return #RFAL_ANALOG_CONFIG_LUT_NOT_FOUND in case Configuration ID is not found.
*****************************************************************************
*/
static rfalAnalogConfigNum rfalAnalogConfigSearch( rfalAnalogConfigId configId, uint16_t *configOffset )
{
rfalAnalogConfigId foundConfigId;
rfalAnalogConfigId configIdMaskVal;
const uint8_t *configTbl;
const uint8_t *currentConfigTbl;
uint16_t i;
currentConfigTbl = gRfalAnalogConfigMgmt.currentAnalogConfigTbl;
configIdMaskVal = ((RFAL_ANALOG_CONFIG_POLL_LISTEN_MODE_MASK | RFAL_ANALOG_CONFIG_BITRATE_MASK)
|((RFAL_ANALOG_CONFIG_TECH_CHIP == RFAL_ANALOG_CONFIG_ID_GET_TECH(configId)) ? (RFAL_ANALOG_CONFIG_TECH_MASK | RFAL_ANALOG_CONFIG_CHIP_SPECIFIC_MASK) : configId)
|((RFAL_ANALOG_CONFIG_NO_DIRECTION == RFAL_ANALOG_CONFIG_ID_GET_DIRECTION(configId)) ? RFAL_ANALOG_CONFIG_DIRECTION_MASK : configId)
);
i = *configOffset;
while (i < gRfalAnalogConfigMgmt.configTblSize)
{
configTbl = &currentConfigTbl[i];
foundConfigId = GETU16(configTbl);
if (configId == (foundConfigId & configIdMaskVal))
{
*configOffset = (uint16_t)(i + sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum));
return configTbl[sizeof(rfalAnalogConfigId)];
}
/* If Config Id does not match, increment to next Configuration Id */
i += (uint16_t)( sizeof(rfalAnalogConfigId) + sizeof(rfalAnalogConfigNum)
+ (configTbl[sizeof(rfalAnalogConfigId)] * sizeof(rfalAnalogConfigRegAddrMaskVal) )
);
} /* for */
return RFAL_ANALOG_CONFIG_LUT_NOT_FOUND;
} /* rfalAnalogConfigSearch() */

View File

@ -1,86 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_crc.c
*
* \author Oliver Regenfelder
*
* \brief CRC calculation implementation
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "rfal_crc.h"
/*
******************************************************************************
* LOCAL FUNCTION PROTOTYPES
******************************************************************************
*/
static uint16_t rfalCrcUpdateCcitt(uint16_t crcSeed, uint8_t dataByte);
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
uint16_t rfalCrcCalculateCcitt(uint16_t preloadValue, const uint8_t* buf, uint16_t length)
{
uint16_t crc = preloadValue;
uint16_t index;
for (index = 0; index < length; index++)
{
crc = rfalCrcUpdateCcitt(crc, buf[index]);
}
return crc;
}
/*
******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************
*/
static uint16_t rfalCrcUpdateCcitt(uint16_t crcSeed, uint8_t dataByte)
{
uint16_t crc = crcSeed;
uint8_t dat = dataByte;
dat ^= (uint8_t)(crc & 0xFFU);
dat ^= (dat << 4);
crc = (crc >> 8)^(((uint16_t) dat) << 8)^(((uint16_t) dat) << 3)^(((uint16_t) dat) >> 4);
return crc;
}

View File

@ -1,240 +0,0 @@
/******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (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.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* $Revision: $
* LANGUAGE: ISO C99
*/
/*! \file rfal_dpo.c
*
* \author Martin Zechleitner
*
* \brief Functions to manage and set dynamic power settings.
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "rfal_dpoTbl.h"
#include "rfal_dpo.h"
#include "platform.h"
#include "rfal_rf.h"
#include "rfal_chip.h"
#include "utils.h"
/*
******************************************************************************
* ENABLE SWITCH
******************************************************************************
*/
#ifndef RFAL_FEATURE_DPO
#define RFAL_FEATURE_DPO false /* Dynamic Power Module configuration missing. Disabled by default */
#endif
#if RFAL_FEATURE_DPO
/*
******************************************************************************
* LOCAL DATA TYPES
******************************************************************************
*/
static bool gRfalDpoIsEnabled = false;
static uint8_t* gRfalCurrentDpo;
static uint8_t gRfalDpoTableEntries;
static uint8_t gRfalDpo[RFAL_DPO_TABLE_SIZE_MAX];
static uint8_t gRfalDpoTableEntry;
static rfalDpoMeasureFunc gRfalDpoMeasureCallback = NULL;
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
void rfalDpoInitialize( void )
{
/* Use the default Dynamic Power values */
gRfalCurrentDpo = (uint8_t*) rfalDpoDefaultSettings;
gRfalDpoTableEntries = (sizeof(rfalDpoDefaultSettings) / RFAL_DPO_TABLE_PARAMETER);
ST_MEMCPY( gRfalDpo, gRfalCurrentDpo, sizeof(rfalDpoDefaultSettings) );
/* by default use amplitude measurement */
gRfalDpoMeasureCallback = rfalChipMeasureAmplitude;
/* by default DPO is disabled */
gRfalDpoIsEnabled = false;
gRfalDpoTableEntry = 0;
}
void rfalDpoSetMeasureCallback( rfalDpoMeasureFunc pMeasureFunc )
{
gRfalDpoMeasureCallback = pMeasureFunc;
}
/*******************************************************************************/
ReturnCode rfalDpoTableWrite( rfalDpoEntry* powerTbl, uint8_t powerTblEntries )
{
uint8_t entry = 0;
/* check if the table size parameter is too big */
if( (powerTblEntries * RFAL_DPO_TABLE_PARAMETER) > RFAL_DPO_TABLE_SIZE_MAX)
{
return ERR_NOMEM;
}
/* check if the first increase entry is 0xFF */
if( (powerTblEntries == 0) || (powerTbl == NULL) )
{
return ERR_PARAM;
}
/* check if the entries of the dynamic power table are valid */
for (entry = 0; entry < powerTblEntries; entry++)
{
if(powerTbl[entry].inc < powerTbl[entry].dec)
{
return ERR_PARAM;
}
}
/* copy the data set */
ST_MEMCPY( gRfalDpo, powerTbl, (powerTblEntries * RFAL_DPO_TABLE_PARAMETER) );
gRfalCurrentDpo = gRfalDpo;
gRfalDpoTableEntries = powerTblEntries;
if(gRfalDpoTableEntry > powerTblEntries)
{
/* is always greater then zero, otherwise we already returned ERR_PARAM */
gRfalDpoTableEntry = (powerTblEntries - 1);
}
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode rfalDpoTableRead( rfalDpoEntry* tblBuf, uint8_t tblBufEntries, uint8_t* tableEntries )
{
/* wrong request */
if( (tblBuf == NULL) || (tblBufEntries < gRfalDpoTableEntries) || (tableEntries == NULL) )
{
return ERR_PARAM;
}
/* Copy the whole Table to the given buffer */
ST_MEMCPY( tblBuf, gRfalCurrentDpo, (tblBufEntries * RFAL_DPO_TABLE_PARAMETER) );
*tableEntries = gRfalDpoTableEntries;
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode rfalDpoAdjust( void )
{
uint8_t refValue = 0;
rfalDpoEntry* dpoTable = (rfalDpoEntry*) gRfalCurrentDpo;
/* Check if the Power Adjustment is disabled and *
* if the callback to the measurement method is properly set */
if( (gRfalCurrentDpo == NULL) || (!gRfalDpoIsEnabled) || (gRfalDpoMeasureCallback == NULL) )
{
return ERR_PARAM;
}
/* Ensure that the current mode is Passive Poller */
if( !rfalIsModePassivePoll( rfalGetMode() ) )
{
return ERR_WRONG_STATE;
}
/* Ensure a proper measure reference value */
if( ERR_NONE != gRfalDpoMeasureCallback( &refValue ) )
{
return ERR_IO;
}
/* Increase the output power */
if( refValue >= dpoTable[gRfalDpoTableEntry].inc )
{
/* the top of the table represents the highest amplitude value*/
if( gRfalDpoTableEntry == 0 )
{
/* check if the maximum driver value has been reached */
return ERR_NONE;
}
/* go up in the table to decrease the driver resistance */
gRfalDpoTableEntry--;
}
else
{
/* decrease the output power */
if(refValue <= dpoTable[gRfalDpoTableEntry].dec)
{
/* The bottom is the highest possible value */
if( (gRfalDpoTableEntry + 1) >= gRfalDpoTableEntries)
{
/* check if the minimum driver value has been reached */
return ERR_NONE;
}
/* go down in the table to increase the driver resistance */
gRfalDpoTableEntry++;
}
else
{
/* do not write the driver again with the same value */
}
}
/* get the new value for RFO resistance form the table and apply the new RFO resistance setting */
rfalChipSetRFO( dpoTable[gRfalDpoTableEntry].rfoRes );
return ERR_NONE;
}
/*******************************************************************************/
rfalDpoEntry* rfalDpoGetCurrentTableEntry( void )
{
rfalDpoEntry* dpoTable = (rfalDpoEntry*) gRfalCurrentDpo;
return &dpoTable[gRfalDpoTableEntry];
}
/*******************************************************************************/
void rfalDpoSetEnabled( bool enable )
{
gRfalDpoIsEnabled = enable;
}
/*******************************************************************************/
bool rfalDpoIsEnabled( void )
{
return gRfalDpoIsEnabled;
}
#endif /* RFAL_FEATURE_DPO */

View File

@ -1,534 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_iso15693_2.c
*
* \author Ulrich Herrmann
*
* \brief Implementation of ISO-15693-2
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "rfal_iso15693_2.h"
#include "rfal_crc.h"
#include "utils.h"
/*
******************************************************************************
* ENABLE SWITCH
******************************************************************************
*/
#ifndef RFAL_FEATURE_NFCV
#define RFAL_FEATURE_NFCV false /* NFC-V module configuration missing. Disabled by default */
#endif
#if RFAL_FEATURE_NFCV
/*
******************************************************************************
* LOCAL MACROS
******************************************************************************
*/
//#define ISO_15693_DEBUG dbgLog
#define ISO_15693_DEBUG(...) /*!< Macro for the log method */
/*
******************************************************************************
* LOCAL DEFINES
******************************************************************************
*/
#define ISO15693_DAT_SOF_1_4 0x21 /* LSB constants */
#define ISO15693_DAT_EOF_1_4 0x04
#define ISO15693_DAT_00_1_4 0x02
#define ISO15693_DAT_01_1_4 0x08
#define ISO15693_DAT_10_1_4 0x20
#define ISO15693_DAT_11_1_4 0x80
#define ISO15693_DAT_SOF_1_256 0x81
#define ISO15693_DAT_EOF_1_256 0x04
#define ISO15693_DAT_SLOT0_1_256 0x02
#define ISO15693_DAT_SLOT1_1_256 0x08
#define ISO15693_DAT_SLOT2_1_256 0x20
#define ISO15693_DAT_SLOT3_1_256 0x80
#define ISO15693_PHY_DAT_MANCHESTER_1 0xaaaa
#define ISO15693_PHY_BIT_BUFFER_SIZE 1000 /*!< size of the receiving buffer. Might be adjusted if longer datastreams are expected. */
/*
******************************************************************************
* LOCAL VARIABLES
******************************************************************************
*/
static iso15693PhyConfig_t iso15693PhyConfig; /*!< current phy configuration */
/*
******************************************************************************
* LOCAL FUNCTION PROTOTYPES
******************************************************************************
*/
static ReturnCode iso15693PhyVCDCode1Of4(const uint8_t data, uint8_t* outbuffer, uint16_t maxOutBufLen, uint16_t* outBufLen);
static ReturnCode iso15693PhyVCDCode1Of256(const uint8_t data, uint8_t* outbuffer, uint16_t maxOutBufLen, uint16_t* outBufLen);
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
ReturnCode iso15693PhyConfigure(const iso15693PhyConfig_t* config, const struct iso15693StreamConfig ** needed_stream_config )
{
static struct iso15693StreamConfig stream_config = { /* MISRA 8.9 */
.useBPSK = 0, /* 0: subcarrier, 1:BPSK */
.din = 5, /* 2^5*fc = 423750 Hz: divider for the in subcarrier frequency */
.dout = 7, /*!< 2^7*fc = 105937 : divider for the in subcarrier frequency */
.report_period_length = 3, /*!< 8=2^3 the length of the reporting period */
};
/* make a copy of the configuration */
ST_MEMCPY( (uint8_t*)&iso15693PhyConfig, (const uint8_t*)config, sizeof(iso15693PhyConfig_t));
if ( config->speedMode <= 3U)
{ /* If valid speed mode adjust report period accordingly */
stream_config.report_period_length = (3U - (uint8_t)config->speedMode);
}
else
{ /* If invalid default to normal (high) speed */
stream_config.report_period_length = 3;
}
*needed_stream_config = &stream_config;
return ERR_NONE;
}
ReturnCode iso15693PhyGetConfiguration(iso15693PhyConfig_t* config)
{
ST_MEMCPY(config, &iso15693PhyConfig, sizeof(iso15693PhyConfig_t));
return ERR_NONE;
}
ReturnCode iso15693VCDCode(uint8_t* buffer, uint16_t length, bool sendCrc, bool sendFlags, bool picopassMode,
uint16_t *subbit_total_length, uint16_t *offset,
uint8_t* outbuf, uint16_t outBufSize, uint16_t* actOutBufSize)
{
ReturnCode err = ERR_NONE;
uint8_t eof, sof;
uint8_t transbuf[2];
uint16_t crc = 0;
ReturnCode (*txFunc)(const uint8_t data, uint8_t* outbuffer, uint16_t maxOutBufLen, uint16_t* outBufLen);
uint8_t crc_len;
uint8_t* outputBuf;
uint16_t outputBufSize;
crc_len = (uint8_t)((sendCrc)?2:0);
*actOutBufSize = 0;
if (ISO15693_VCD_CODING_1_4 == iso15693PhyConfig.coding)
{
sof = ISO15693_DAT_SOF_1_4;
eof = ISO15693_DAT_EOF_1_4;
txFunc = iso15693PhyVCDCode1Of4;
*subbit_total_length = (
( 1U /* SOF */
+ ((length + (uint16_t)crc_len) * 4U)
+ 1U) /* EOF */
);
if (outBufSize < 5U) { /* 5 should be safe: enough for sof + 1byte data in 1of4 */
return ERR_NOMEM;
}
}
else
{
sof = ISO15693_DAT_SOF_1_256;
eof = ISO15693_DAT_EOF_1_256;
txFunc = iso15693PhyVCDCode1Of256;
*subbit_total_length = (
( 1U /* SOF */
+ ((length + (uint16_t)crc_len) * 64U)
+ 1U) /* EOF */
);
if (*offset != 0U)
{
if (outBufSize < 64U) { /* 64 should be safe: enough a single byte data in 1of256 */
return ERR_NOMEM;
}
}
else
{
if (outBufSize < 65U) { /* At beginning of a frame we need at least 65 bytes to start: enough for sof + 1byte data in 1of256 */
return ERR_NOMEM;
}
}
}
if (length == 0U)
{
*subbit_total_length = 1;
}
if ((length != 0U) && (0U == *offset) && sendFlags && !picopassMode)
{
/* set high datarate flag */
buffer[0] |= (uint8_t)ISO15693_REQ_FLAG_HIGH_DATARATE;
/* clear sub-carrier flag - we only support single sub-carrier */
buffer[0] = (uint8_t)(buffer[0] & ~ISO15693_REQ_FLAG_TWO_SUBCARRIERS); /* MISRA 10.3 */
}
outputBuf = outbuf; /* MISRA 17.8: Use intermediate variable */
outputBufSize = outBufSize; /* MISRA 17.8: Use intermediate variable */
/* Send SOF if at 0 offset */
if ((length != 0U) && (0U == *offset))
{
*outputBuf = sof;
(*actOutBufSize)++;
outputBufSize--;
outputBuf++;
}
while ((*offset < length) && (err == ERR_NONE))
{
uint16_t filled_size;
/* send data */
err = txFunc(buffer[*offset], outputBuf, outputBufSize, &filled_size);
(*actOutBufSize) += filled_size;
outputBuf = &outputBuf[filled_size]; /* MISRA 18.4: Avoid pointer arithmetic */
outputBufSize -= filled_size;
if (err == ERR_NONE) {
(*offset)++;
}
}
if (err != ERR_NONE) {
return ERR_AGAIN;
}
while ((err == ERR_NONE) && sendCrc && (*offset < (length + 2U)))
{
uint16_t filled_size;
if (0U==crc)
{
crc = rfalCrcCalculateCcitt( (uint16_t) ((picopassMode) ? 0xE012U : 0xFFFFU), /* In PicoPass Mode a different Preset Value is used */
((picopassMode) ? (buffer + 1U) : buffer), /* CMD byte is not taken into account in PicoPass mode */
((picopassMode) ? (length - 1U) : length)); /* CMD byte is not taken into account in PicoPass mode */
crc = (uint16_t)((picopassMode) ? crc : ~crc);
}
/* send crc */
transbuf[0] = (uint8_t)(crc & 0xffU);
transbuf[1] = (uint8_t)((crc >> 8) & 0xffU);
err = txFunc(transbuf[*offset - length], outputBuf, outputBufSize, &filled_size);
(*actOutBufSize) += filled_size;
outputBuf = &outputBuf[filled_size]; /* MISRA 18.4: Avoid pointer arithmetic */
outputBufSize -= filled_size;
if (err == ERR_NONE) {
(*offset)++;
}
}
if (err != ERR_NONE) {
return ERR_AGAIN;
}
if ((!sendCrc && (*offset == length))
|| (sendCrc && (*offset == (length + 2U))))
{
*outputBuf = eof;
(*actOutBufSize)++;
outputBufSize--;
outputBuf++;
}
else
{
return ERR_AGAIN;
}
return err;
}
ReturnCode iso15693VICCDecode(const uint8_t *inBuf,
uint16_t inBufLen,
uint8_t* outBuf,
uint16_t outBufLen,
uint16_t* outBufPos,
uint16_t* bitsBeforeCol,
uint16_t ignoreBits,
bool picopassMode )
{
ReturnCode err = ERR_NONE;
uint16_t crc;
uint16_t mp; /* Current bit position in manchester bit inBuf*/
uint16_t bp; /* Current bit position in outBuf */
*bitsBeforeCol = 0;
*outBufPos = 0;
/* first check for valid SOF. Since it starts with 3 unmodulated pulses it is 0x17. */
if ((inBuf[0] & 0x1fU) != 0x17U)
{
ISO_15693_DEBUG("0x%x\n", iso15693PhyBitBuffer[0]);
return ERR_FRAMING;
}
ISO_15693_DEBUG("SOF\n");
if (outBufLen == 0U)
{
return ERR_NONE;
}
mp = 5; /* 5 bits were SOF, now manchester starts: 2 bits per payload bit */
bp = 0;
ST_MEMSET(outBuf,0,outBufLen);
if (inBufLen == 0U)
{
return ERR_CRC;
}
for ( ; mp < ((inBufLen * 8U) - 2U); mp+=2U )
{
bool isEOF = false;
uint8_t man;
man = (inBuf[mp/8U] >> (mp%8U)) & 0x1U;
man |= ((inBuf[(mp+1U)/8U] >> ((mp+1U)%8U)) & 0x1U) << 1;
if (1U == man)
{
bp++;
}
if (2U == man)
{
outBuf[bp/8U] = (uint8_t)(outBuf[bp/8U] | (1U <<(bp%8U))); /* MISRA 10.3 */
bp++;
}
if ((bp%8U) == 0U)
{ /* Check for EOF */
ISO_15693_DEBUG("ceof %hhx %hhx\n", inBuf[mp/8U], inBuf[mp/8+1]);
if ( ((inBuf[mp/8U] & 0xe0U) == 0xa0U)
&&(inBuf[(mp/8U)+1U] == 0x03U))
{ /* Now we know that it was 10111000 = EOF */
ISO_15693_DEBUG("EOF\n");
isEOF = true;
}
}
if ( ((0U == man) || (3U == man)) && !isEOF )
{
if (bp >= ignoreBits)
{
err = ERR_RF_COLLISION;
}
else
{
/* ignored collision: leave as 0 */
bp++;
}
}
if ( (bp >= (outBufLen * 8U)) || (err == ERR_RF_COLLISION) || isEOF )
{ /* Don't write beyond the end */
break;
}
}
*outBufPos = (bp / 8U);
*bitsBeforeCol = bp;
if (err != ERR_NONE)
{
return err;
}
if ((bp%8U) != 0U)
{
return ERR_CRC;
}
if (*outBufPos > 2U)
{
/* finally, check crc */
ISO_15693_DEBUG("Calculate CRC, val: 0x%x, outBufLen: ", *outBuf);
ISO_15693_DEBUG("0x%x ", *outBufPos - 2);
crc = rfalCrcCalculateCcitt(((picopassMode) ? 0xE012U : 0xFFFFU), outBuf, *outBufPos - 2U);
crc = (uint16_t)((picopassMode) ? crc : ~crc);
if (((crc & 0xffU) == outBuf[*outBufPos-2U]) &&
(((crc >> 8U) & 0xffU) == outBuf[*outBufPos-1U]))
{
err = ERR_NONE;
ISO_15693_DEBUG("OK\n");
}
else
{
ISO_15693_DEBUG("error! Expected: 0x%x, got ", crc);
ISO_15693_DEBUG("0x%hhx 0x%hhx\n", outBuf[*outBufPos-2], outBuf[*outBufPos-1]);
err = ERR_CRC;
}
}
else
{
err = ERR_CRC;
}
return err;
}
/*
******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************
*/
/*!
*****************************************************************************
* \brief Perform 1 of 4 coding and send coded data
*
* This function takes \a length bytes from \a buffer, perform 1 of 4 coding
* (see ISO15693-2 specification) and sends the data using stream mode.
*
* \param[in] sendSof : send SOF prior to data.
* \param[in] buffer : data to send.
* \param[in] length : number of bytes to send.
*
* \return ERR_IO : Error during communication.
* \return ERR_NONE : No error.
*
*****************************************************************************
*/
static ReturnCode iso15693PhyVCDCode1Of4(const uint8_t data, uint8_t* outbuffer, uint16_t maxOutBufLen, uint16_t* outBufLen)
{
uint8_t tmp;
ReturnCode err = ERR_NONE;
uint16_t a;
uint8_t* outbuf = outbuffer;
*outBufLen = 0;
if (maxOutBufLen < 4U) {
return ERR_NOMEM;
}
tmp = data;
for (a = 0; a < 4U; a++)
{
switch (tmp & 0x3U)
{
case 0:
*outbuf = ISO15693_DAT_00_1_4;
break;
case 1:
*outbuf = ISO15693_DAT_01_1_4;
break;
case 2:
*outbuf = ISO15693_DAT_10_1_4;
break;
case 3:
*outbuf = ISO15693_DAT_11_1_4;
break;
default:
/* MISRA 16.4: mandatory default statement */
break;
}
outbuf++;
(*outBufLen)++;
tmp >>= 2;
}
return err;
}
/*!
*****************************************************************************
* \brief Perform 1 of 256 coding and send coded data
*
* This function takes \a length bytes from \a buffer, perform 1 of 256 coding
* (see ISO15693-2 specification) and sends the data using stream mode.
* \note This function sends SOF prior to the data.
*
* \param[in] sendSof : send SOF prior to data.
* \param[in] buffer : data to send.
* \param[in] length : number of bytes to send.
*
* \return ERR_IO : Error during communication.
* \return ERR_NONE : No error.
*
*****************************************************************************
*/
static ReturnCode iso15693PhyVCDCode1Of256(const uint8_t data, uint8_t* outbuffer, uint16_t maxOutBufLen, uint16_t* outBufLen)
{
uint8_t tmp;
ReturnCode err = ERR_NONE;
uint16_t a;
uint8_t* outbuf = outbuffer;
*outBufLen = 0;
if (maxOutBufLen < 64U) {
return ERR_NOMEM;
}
tmp = data;
for (a = 0; a < 64U; a++)
{
switch (tmp)
{
case 0:
*outbuf = ISO15693_DAT_SLOT0_1_256;
break;
case 1:
*outbuf = ISO15693_DAT_SLOT1_1_256;
break;
case 2:
*outbuf = ISO15693_DAT_SLOT2_1_256;
break;
case 3:
*outbuf = ISO15693_DAT_SLOT3_1_256;
break;
default:
*outbuf = 0;
break;
}
outbuf++;
(*outBufLen)++;
tmp -= 4U;
}
return err;
}
#endif /* RFAL_FEATURE_NFCV */

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,630 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_nfca.c
*
* \author Gustavo Patricio
*
* \brief Provides several NFC-A convenience methods and definitions
*
* It provides a Poller (ISO14443A PCD) interface and as well as
* some NFC-A Listener (ISO14443A PICC) helpers.
*
* The definitions and helpers methods provided by this module are only
* up to ISO14443-3 layer
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "rfal_nfca.h"
#include "utils.h"
/*
******************************************************************************
* ENABLE SWITCH
******************************************************************************
*/
#ifndef RFAL_FEATURE_NFCA
#define RFAL_FEATURE_NFCA false /* NFC-A module configuration missing. Disabled by default */
#endif
#if RFAL_FEATURE_NFCA
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_NFCA_SLP_FWT rfalConvMsTo1fc(1) /*!< Check 1ms for any modulation ISO14443-3 6.4.3 */
#define RFAL_NFCA_SLP_CMD 0x50U /*!< SLP cmd (byte1) Digital 1.1 6.9.1 & Table 20 */
#define RFAL_NFCA_SLP_BYTE2 0x00U /*!< SLP byte2 Digital 1.1 6.9.1 & Table 20 */
#define RFAL_NFCA_SLP_CMD_POS 0U /*!< SLP cmd position Digital 1.1 6.9.1 & Table 20 */
#define RFAL_NFCA_SLP_BYTE2_POS 1U /*!< SLP byte2 position Digital 1.1 6.9.1 & Table 20 */
#define RFAL_NFCA_SDD_CT 0x88U /*!< Cascade Tag value Digital 1.1 6.7.2 */
#define RFAL_NFCA_SDD_CT_LEN 1U /*!< Cascade Tag length */
#define RFAL_NFCA_SLP_REQ_LEN 2U /*!< SLP_REQ length */
#define RFAL_NFCA_SEL_CMD_LEN 1U /*!< SEL_CMD length */
#define RFAL_NFCA_SEL_PAR_LEN 1U /*!< SEL_PAR length */
#define RFAL_NFCA_SEL_SELPAR rfalNfcaSelPar(7U, 0U)/*!< SEL_PAR on Select is always with 4 data/nfcid */
#define RFAL_NFCA_BCC_LEN 1U /*!< BCC length */
#define RFAL_NFCA_SDD_REQ_LEN (RFAL_NFCA_SEL_CMD_LEN + RFAL_NFCA_SEL_PAR_LEN) /*!< SDD_REQ length */
#define RFAL_NFCA_SDD_RES_LEN (RFAL_NFCA_CASCADE_1_UID_LEN + RFAL_NFCA_BCC_LEN) /*!< SDD_RES length */
#define RFAL_NFCA_T_RETRANS 5U /*!< t RETRANSMISSION [3, 33]ms EMVCo 2.6 A.5 */
#define RFAL_NFCA_N_RETRANS 2U /*!< Number of retries EMVCo 2.6 9.6.1.3 */
/*! SDD_REQ (Select) Cascade Levels */
enum
{
RFAL_NFCA_SEL_CASCADE_L1 = 0, /*!< SDD_REQ Cascade Level 1 */
RFAL_NFCA_SEL_CASCADE_L2 = 1, /*!< SDD_REQ Cascade Level 2 */
RFAL_NFCA_SEL_CASCADE_L3 = 2 /*!< SDD_REQ Cascade Level 3 */
};
/*! SDD_REQ (Select) request Cascade Level command Digital 1.1 Table 15 */
enum
{
RFAL_NFCA_CMD_SEL_CL1 = 0x93, /*!< SDD_REQ command Cascade Level 1 */
RFAL_NFCA_CMD_SEL_CL2 = 0x95, /*!< SDD_REQ command Cascade Level 2 */
RFAL_NFCA_CMD_SEL_CL3 = 0x97, /*!< SDD_REQ command Cascade Level 3 */
};
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
#define rfalNfcaSelPar( nBy, nbi ) (uint8_t)((((nBy)<<4U) & 0xF0U) | ((nbi)&0x0FU) ) /*!< Calculates SEL_PAR with the bytes/bits to be sent */
#define rfalNfcaCLn2SELCMD( cl ) (uint8_t)((uint8_t)(RFAL_NFCA_CMD_SEL_CL1) + (2U*(cl))) /*!< Calculates SEL_CMD with the given cascade level */
#define rfalNfcaNfcidLen2CL( len ) ((len) / 5U) /*!< Calculates cascade level by the NFCID length */
/*! Executes the given Tx method (f) and if a Timeout error is detected it retries (rt) times performing a delay of (dl) in between */
#define rfalNfcaTxRetry( r, f, rt, dl ) \
{ \
uint8_t rts = (uint8_t)(rt); \
do { \
(r)=(f); \
if (((rt)!=0U) && ((dl)!=0U)) { \
platformDelay(dl); \
} \
} while( ((rts--) != 0U) && ((r)==ERR_TIMEOUT) ); \
}
/*
******************************************************************************
* GLOBAL TYPES
******************************************************************************
*/
/*! SLP_REQ (HLTA) format Digital 1.1 6.9.1 & Table 20 */
typedef struct
{
uint8_t frame[RFAL_NFCA_SLP_REQ_LEN]; /*!< SLP: 0x50 0x00 */
} rfalNfcaSlpReq;
/*
******************************************************************************
* LOCAL FUNCTION PROTOTYPES
******************************************************************************
*/
static uint8_t rfalNfcaCalculateBcc( const uint8_t* buf, uint8_t bufLen );
/*
******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************
*/
static uint8_t rfalNfcaCalculateBcc( const uint8_t* buf, uint8_t bufLen )
{
uint8_t i;
uint8_t BCC;
BCC = 0;
/* BCC is XOR over first 4 bytes of the SDD_RES Digital 1.1 6.7.2 */
for(i = 0; i < bufLen; i++)
{
BCC ^= buf[i];
}
return BCC;
}
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
/*******************************************************************************/
ReturnCode rfalNfcaPollerInitialize( void )
{
ReturnCode ret;
EXIT_ON_ERR( ret, rfalSetMode( RFAL_MODE_POLL_NFCA, RFAL_BR_106, RFAL_BR_106 ) );
rfalSetErrorHandling( RFAL_ERRORHANDLING_NFC );
rfalSetGT( RFAL_GT_NFCA );
rfalSetFDTListen( RFAL_FDT_LISTEN_NFCA_POLLER );
rfalSetFDTPoll( RFAL_FDT_POLL_NFCA_POLLER );
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode rfalNfcaPollerCheckPresence( rfal14443AShortFrameCmd cmd, rfalNfcaSensRes *sensRes )
{
ReturnCode ret;
uint16_t rcvLen;
/* Digital 1.1 6.10.1.3 For Commands ALL_REQ, SENS_REQ, SDD_REQ, and SEL_REQ, the NFC Forum Device *
* MUST treat receipt of a Listen Frame at a time after FDT(Listen, min) as a Timeour Error */
ret = rfalISO14443ATransceiveShortFrame( cmd, (uint8_t*)sensRes, (uint8_t)rfalConvBytesToBits(sizeof(rfalNfcaSensRes)), &rcvLen, RFAL_NFCA_FDTMIN );
if( (ret == ERR_RF_COLLISION) || (ret == ERR_CRC) || (ret == ERR_NOMEM) || (ret == ERR_FRAMING) || (ret == ERR_PAR) )
{
ret = ERR_NONE;
}
return ret;
}
/*******************************************************************************/
ReturnCode rfalNfcaPollerTechnologyDetection( rfalComplianceMode compMode, rfalNfcaSensRes *sensRes )
{
ReturnCode ret;
EXIT_ON_ERR( ret, rfalNfcaPollerCheckPresence( ((compMode == RFAL_COMPLIANCE_MODE_EMV) ? RFAL_14443A_SHORTFRAME_CMD_WUPA : RFAL_14443A_SHORTFRAME_CMD_REQA), sensRes ) );
/* Send SLP_REQ as Activity 1.1 9.2.3.6 and EMVCo 2.6 9.2.1.3 */
if( compMode != RFAL_COMPLIANCE_MODE_ISO)
{
rfalNfcaPollerSleep();
}
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode rfalNfcaPollerSingleCollisionResolution( uint8_t devLimit, bool *collPending, rfalNfcaSelRes *selRes, uint8_t *nfcId1, uint8_t *nfcId1Len )
{
uint8_t i;
ReturnCode ret;
rfalNfcaSelReq selReq;
uint16_t bytesRx;
uint8_t bytesTxRx;
uint8_t bitsTxRx;
bool doBacktrack = false;
uint8_t backtrackCnt = 3;
/* Check parameters */
if( (collPending == NULL) || (selRes == NULL) || (nfcId1 == NULL) || (nfcId1Len == NULL) )
{
return ERR_PARAM;
}
/* Initialize output parameters */
*collPending = false; /* Activity 1.1 9.3.4.6 */
*nfcId1Len = 0;
ST_MEMSET( nfcId1, 0x00, RFAL_NFCA_CASCADE_3_UID_LEN );
/*******************************************************************************/
/* Go through all Cascade Levels Activity 1.1 9.3.4 */
for( i = (uint8_t)RFAL_NFCA_SEL_CASCADE_L1; i <= (uint8_t)RFAL_NFCA_SEL_CASCADE_L3; i++)
{
/* Initialize the SDD_REQ to send for the new cascade level */
ST_MEMSET( (uint8_t*)&selReq, 0x00, sizeof(rfalNfcaSelReq) );
selReq.selCmd = rfalNfcaCLn2SELCMD(i);
bytesTxRx = RFAL_NFCA_SDD_REQ_LEN;
bitsTxRx = 0;
/*******************************************************************************/
/* Go through Collision loop */
do
{
uint8_t collBit = 1; /* standards mandate or recommend collision bit to be set to One. */
/* Calculate SEL_PAR with the bytes/bits to be sent */
selReq.selPar = rfalNfcaSelPar(bytesTxRx, bitsTxRx);
/* Send SDD_REQ (Anticollision frame) - Retry upon timeout EMVCo 2.6 9.6.1.3 */
rfalNfcaTxRetry( ret, rfalISO14443ATransceiveAnticollisionFrame( (uint8_t*)&selReq, &bytesTxRx, &bitsTxRx, &bytesRx, RFAL_NFCA_FDTMIN ), ((devLimit==0U)?RFAL_NFCA_N_RETRANS:0U), RFAL_NFCA_T_RETRANS );
bytesRx = rfalConvBitsToBytes(bytesRx);
if ((ret == ERR_TIMEOUT)
&& (backtrackCnt != 0U) && !doBacktrack
&& !((RFAL_NFCA_SDD_REQ_LEN==bytesTxRx) && (0U==bitsTxRx)))
{
/* In multiple card scenarios it may always happen that some
* collisions of a weaker tag go unnoticed. If then a later
* collision is recognized and the strong tag has a 0 at the
* collision position then no tag will respond. Catch this
* corner case and then try with the bit being sent as zero. */
rfalNfcaSensRes sensRes;
ret = ERR_RF_COLLISION;
rfalNfcaPollerCheckPresence( RFAL_14443A_SHORTFRAME_CMD_REQA, &sensRes );
/* Algorithm below does a post-increment, decrement to go back to current position */
if (0U == bitsTxRx)
{
bitsTxRx = 7;
bytesTxRx--;
}
else
{
bitsTxRx--;
}
collBit = (uint8_t)( ((uint8_t*)&selReq)[bytesTxRx] & (1U << bitsTxRx) );
collBit = (uint8_t)((0U==collBit)?1U:0U); // invert the collision bit
doBacktrack = true;
backtrackCnt--;
}
else
{
doBacktrack = false;
}
if( ret == ERR_RF_COLLISION )
{
/* Check received length */
if( (bytesTxRx + ((bitsTxRx != 0U) ? 1U : 0U)) > (RFAL_NFCA_SDD_RES_LEN + RFAL_NFCA_SDD_REQ_LEN) )
{
return ERR_PROTO;
}
if( ((bytesTxRx + ((bitsTxRx != 0U) ? 1U : 0U)) > (RFAL_NFCA_CASCADE_1_UID_LEN + RFAL_NFCA_SDD_REQ_LEN)) && (backtrackCnt != 0U) )
{ /* Collision in BCC: Anticollide only UID part */
backtrackCnt--;
bytesTxRx = RFAL_NFCA_CASCADE_1_UID_LEN + RFAL_NFCA_SDD_REQ_LEN - 1U;
bitsTxRx = 7;
collBit = (uint8_t)( ((uint8_t*)&selReq)[bytesTxRx] & (1U << bitsTxRx) ); /* Not a real collision, extract the actual bit for the subsequent code */
}
if( (devLimit == 0U) && !(*collPending) )
{
/* Activity 1.0 & 1.1 9.3.4.12: If CON_DEVICES_LIMIT has a value of 0, then
* NFC Forum Device is configured to perform collision detection only */
*collPending = true;
return ERR_IGNORE;
}
*collPending = true;
/* Set and select the collision bit, with the number of bytes/bits successfully TxRx */
if (collBit != 0U)
{
((uint8_t*)&selReq)[bytesTxRx] = (uint8_t)(((uint8_t*)&selReq)[bytesTxRx] | (1U << bitsTxRx)); /* MISRA 10.3 */
}
else
{
((uint8_t*)&selReq)[bytesTxRx] = (uint8_t)(((uint8_t*)&selReq)[bytesTxRx] & ~(1U << bitsTxRx)); /* MISRA 10.3 */
}
bitsTxRx++;
/* Check if number of bits form a byte */
if( bitsTxRx == RFAL_BITS_IN_BYTE )
{
bitsTxRx = 0;
bytesTxRx++;
}
}
}while (ret == ERR_RF_COLLISION);
/*******************************************************************************/
/* Check if Collision loop has failed */
if( ret != ERR_NONE )
{
return ret;
}
/* If collisions are to be reported check whether the response is complete */
if( (devLimit == 0U) && (bytesRx != sizeof(rfalNfcaSddRes)) )
{
return ERR_PROTO;
}
/* Check if the received BCC match */
if( selReq.bcc != rfalNfcaCalculateBcc( selReq.nfcid1, RFAL_NFCA_CASCADE_1_UID_LEN ) )
{
return ERR_PROTO;
}
/*******************************************************************************/
/* Anticollision OK, Select this Cascade Level */
selReq.selPar = RFAL_NFCA_SEL_SELPAR;
/* Send SEL_REQ (Select command) - Retry upon timeout EMVCo 2.6 9.6.1.3 */
rfalNfcaTxRetry( ret, rfalTransceiveBlockingTxRx( (uint8_t*)&selReq, sizeof(rfalNfcaSelReq), (uint8_t*)selRes, sizeof(rfalNfcaSelRes), &bytesRx, RFAL_TXRX_FLAGS_DEFAULT, RFAL_NFCA_FDTMIN ), ((devLimit==0U)?RFAL_NFCA_N_RETRANS:0U), RFAL_NFCA_T_RETRANS );
if( ret != ERR_NONE )
{
return ret;
}
/* Ensure proper response length */
if( bytesRx != sizeof(rfalNfcaSelRes) )
{
return ERR_PROTO;
}
/*******************************************************************************/
/* Check cascade byte, if cascade tag then go next cascade level */
if( (ret == ERR_NONE) && (*selReq.nfcid1 == RFAL_NFCA_SDD_CT) )
{
/* Cascade Tag present, store nfcid1 bytes (excluding cascade tag) and continue for next CL */
ST_MEMCPY( &nfcId1[*nfcId1Len], &((uint8_t*)&selReq.nfcid1)[RFAL_NFCA_SDD_CT_LEN], (RFAL_NFCA_CASCADE_1_UID_LEN - RFAL_NFCA_SDD_CT_LEN) );
*nfcId1Len += (RFAL_NFCA_CASCADE_1_UID_LEN - RFAL_NFCA_SDD_CT_LEN);
}
else
{
/* UID Selection complete, Stop Cascade Level loop */
ST_MEMCPY( &nfcId1[*nfcId1Len], (uint8_t*)&selReq.nfcid1, RFAL_NFCA_CASCADE_1_UID_LEN );
*nfcId1Len += RFAL_NFCA_CASCADE_1_UID_LEN;
return ERR_NONE;
}
}
return ERR_INTERNAL;
}
/*******************************************************************************/
ReturnCode rfalNfcaPollerFullCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcaListenDevice *nfcaDevList, uint8_t *devCnt )
{
ReturnCode ret;
bool collPending;
rfalNfcaSensRes sensRes;
uint16_t rcvLen;
if( (nfcaDevList == NULL) || (devCnt == NULL) )
{
return ERR_PARAM;
}
*devCnt = 0;
ret = ERR_NONE;
/*******************************************************************************/
/* Send ALL_REQ before Anticollision if a Sleep was sent before Activity 1.1 9.3.4.1 and EMVco 2.6 9.3.2.1 */
if( compMode != RFAL_COMPLIANCE_MODE_ISO )
{
ret = rfalISO14443ATransceiveShortFrame( RFAL_14443A_SHORTFRAME_CMD_WUPA, (uint8_t*)&nfcaDevList->sensRes, (uint8_t)rfalConvBytesToBits(sizeof(rfalNfcaSensRes)), &rcvLen, RFAL_NFCA_FDTMIN );
if(ret != ERR_NONE)
{
if( (compMode == RFAL_COMPLIANCE_MODE_EMV) || ((ret != ERR_RF_COLLISION) && (ret != ERR_CRC) && (ret != ERR_FRAMING) && (ret != ERR_PAR)) )
{
return ret;
}
}
/* Check proper SENS_RES/ATQA size */
if( (ret == ERR_NONE) && (rfalConvBytesToBits(sizeof(rfalNfcaSensRes)) != rcvLen) )
{
return ERR_PROTO;
}
}
#if RFAL_FEATURE_T1T
/*******************************************************************************/
/* Only check for T1T if previous SENS_RES was received without a transmission *
* error. When collisions occur bits in the SENS_RES may look like a T1T */
/* If T1T Anticollision is not supported Activity 1.1 9.3.4.3 */
if( rfalNfcaIsSensResT1T( &nfcaDevList->sensRes ) && (devLimit != 0U) && (ret == ERR_NONE) && (compMode != RFAL_COMPLIANCE_MODE_EMV) )
{
/* RID_REQ shall be performed with rfalT1TPollerRid() Activity 1.1 9.3.4.24 */
rfalT1TPollerInitialize();
EXIT_ON_ERR( ret, rfalT1TPollerRid( &nfcaDevList->ridRes ) );
/* T1T doesn't support Anticollision */
*devCnt = 1;
nfcaDevList->isSleep = false;
nfcaDevList->type = RFAL_NFCA_T1T;
nfcaDevList->nfcId1Len = RFAL_NFCA_CASCADE_1_UID_LEN;
ST_MEMCPY( &nfcaDevList->nfcId1, &nfcaDevList->ridRes.uid, RFAL_NFCA_CASCADE_1_UID_LEN );
return ERR_NONE;
}
#endif /* RFAL_FEATURE_T1T */
/*******************************************************************************/
/* Store the SENS_RES from Technology Detection or from WUPA */
sensRes = nfcaDevList->sensRes;
if( devLimit > 0U ) /* MISRA 21.18 */
{
ST_MEMSET( nfcaDevList, 0x00, (sizeof(rfalNfcaListenDevice) * devLimit) );
}
/* Restore the prev SENS_RES, assuming that the SENS_RES received is from first device
* When only one device is detected it's not woken up then we'll have no SENS_RES (ATQA) */
nfcaDevList->sensRes = sensRes;
/*******************************************************************************/
do
{
uint8_t newDeviceType;
EXIT_ON_ERR( ret, rfalNfcaPollerSingleCollisionResolution( devLimit, &collPending, &nfcaDevList[*devCnt].selRes, (uint8_t*)&nfcaDevList[*devCnt].nfcId1, (uint8_t*)&nfcaDevList[*devCnt].nfcId1Len ) );
/* Assign Listen Device */
newDeviceType = ((uint8_t)nfcaDevList[*devCnt].selRes.sak) & RFAL_NFCA_SEL_RES_CONF_MASK; /* MISRA 10.8 */
/* PRQA S 4342 1 # MISRA 10.5 - Guaranteed that no invalid enum values are created: see guard_eq_RFAL_NFCA_T2T, .... */
nfcaDevList[*devCnt].type = (rfalNfcaListenDeviceType) (newDeviceType);
nfcaDevList[*devCnt].isSleep = false;
(*devCnt)++;
/* If a collision was detected and device counter is lower than limit Activity 1.1 9.3.4.21 */
if( (*devCnt < devLimit) && ((collPending) || (compMode != RFAL_COMPLIANCE_MODE_ISO) ) )
{
/* Put this device to Sleep Activity 1.1 9.3.4.22 */
rfalNfcaPollerSleep();
nfcaDevList[(*devCnt - 1U)].isSleep = true;
/* Send a new SENS_REQ to check for other cards Activity 1.1 9.3.4.23 */
ret = rfalNfcaPollerCheckPresence( RFAL_14443A_SHORTFRAME_CMD_REQA, &nfcaDevList[*devCnt].sensRes );
if( ret == ERR_TIMEOUT )
{
/* No more devices found, exit */
collPending = false;
}
else
{
/* Another device found, continue loop */
collPending = true;
}
}
else
{
/* Exit loop */
collPending = false;
}
}while( (*devCnt < devLimit) && (collPending) );
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode rfalNfcaPollerSelect( const uint8_t *nfcid1, uint8_t nfcidLen, rfalNfcaSelRes *selRes )
{
uint8_t i;
uint8_t cl;
uint8_t nfcidOffset;
uint16_t rxLen;
ReturnCode ret;
rfalNfcaSelReq selReq;
if( (nfcid1 == NULL) || (nfcidLen > RFAL_NFCA_CASCADE_3_UID_LEN) || (selRes == NULL) )
{
return ERR_PARAM;
}
/* Calculate Cascate Level */
cl = rfalNfcaNfcidLen2CL( nfcidLen );
nfcidOffset = 0;
/*******************************************************************************/
/* Go through all Cascade Levels Activity 1.1 9.4.4 */
for( i = RFAL_NFCA_SEL_CASCADE_L1; i <= cl; i++ )
{
/* Assign SEL_CMD according to the CLn and SEL_PAR*/
selReq.selCmd = rfalNfcaCLn2SELCMD(i);
selReq.selPar = RFAL_NFCA_SEL_SELPAR;
/* Compute NFCID/Data on the SEL_REQ command Digital 1.1 Table 18 */
if( cl != i )
{
*selReq.nfcid1 = RFAL_NFCA_SDD_CT;
ST_MEMCPY( &selReq.nfcid1[RFAL_NFCA_SDD_CT_LEN], &nfcid1[nfcidOffset], (RFAL_NFCA_CASCADE_1_UID_LEN - RFAL_NFCA_SDD_CT_LEN) );
nfcidOffset += (RFAL_NFCA_CASCADE_1_UID_LEN - RFAL_NFCA_SDD_CT_LEN);
}
else
{
ST_MEMCPY( selReq.nfcid1, &nfcid1[nfcidOffset], RFAL_NFCA_CASCADE_1_UID_LEN );
}
/* Calculate nfcid's BCC */
selReq.bcc = rfalNfcaCalculateBcc( (uint8_t*)&selReq.nfcid1, sizeof(selReq.nfcid1) );
/*******************************************************************************/
/* Send SEL_REQ */
EXIT_ON_ERR( ret, rfalTransceiveBlockingTxRx( (uint8_t*)&selReq, sizeof(rfalNfcaSelReq), (uint8_t*)selRes, sizeof(rfalNfcaSelRes), &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_NFCA_FDTMIN ) );
/* Ensure proper response length */
if( rxLen != sizeof(rfalNfcaSelRes) )
{
return ERR_PROTO;
}
}
/* REMARK: Could check if NFCID1 is complete */
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode rfalNfcaPollerSleep( void )
{
rfalNfcaSlpReq slpReq;
uint8_t rxBuf; /* dummy buffer, just to perform Rx */
slpReq.frame[RFAL_NFCA_SLP_CMD_POS] = RFAL_NFCA_SLP_CMD;
slpReq.frame[RFAL_NFCA_SLP_BYTE2_POS] = RFAL_NFCA_SLP_BYTE2;
rfalTransceiveBlockingTxRx( (uint8_t*)&slpReq, sizeof(rfalNfcaSlpReq), &rxBuf, sizeof(rxBuf), NULL, RFAL_TXRX_FLAGS_DEFAULT, RFAL_NFCA_SLP_FWT );
/* ISO14443-3 6.4.3 HLTA - If PICC responds with any modulation during 1 ms this response shall be interpreted as not acknowledge
Digital 2.0 6.9.2.1 & EMVCo 3.0 5.6.2.1 - consider the HLTA command always acknowledged
No check to be compliant with NFC and EMVCo, and to improve interoprability (Kovio RFID Tag)
*/
return ERR_NONE;
}
/*******************************************************************************/
bool rfalNfcaListenerIsSleepReq( const uint8_t *buf, uint16_t bufLen )
{
/* Check if length and payload match */
if( (bufLen != sizeof(rfalNfcaSlpReq)) || (buf[RFAL_NFCA_SLP_CMD_POS] != RFAL_NFCA_SLP_CMD) || (buf[RFAL_NFCA_SLP_BYTE2_POS] != RFAL_NFCA_SLP_BYTE2) )
{
return false;
}
return true;
}
/* If the guards here don't compile then the code above cannot work anymore. */
extern uint8_t guard_eq_RFAL_NFCA_T2T[((RFAL_NFCA_SEL_RES_CONF_MASK&(uint8_t)RFAL_NFCA_T2T) == (uint8_t)RFAL_NFCA_T2T)?1:(-1)];
extern uint8_t guard_eq_RFAL_NFCA_T4T[((RFAL_NFCA_SEL_RES_CONF_MASK&(uint8_t)RFAL_NFCA_T4T) == (uint8_t)RFAL_NFCA_T4T)?1:(-1)];
extern uint8_t guard_eq_RFAL_NFCA_NFCDEP[((RFAL_NFCA_SEL_RES_CONF_MASK&(uint8_t)RFAL_NFCA_NFCDEP) == (uint8_t)RFAL_NFCA_NFCDEP)?1:(-1)];
extern uint8_t guard_eq_RFAL_NFCA_T4T_NFCDEP[((RFAL_NFCA_SEL_RES_CONF_MASK&(uint8_t)RFAL_NFCA_T4T_NFCDEP) == (uint8_t)RFAL_NFCA_T4T_NFCDEP)?1:(-1)];
#endif /* RFAL_FEATURE_NFCA */

View File

@ -1,504 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_nfcb.c
*
* \author Gustavo Patricio
*
* \brief Implementation of NFC-B (ISO14443B) helpers
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "rfal_nfcb.h"
#include "utils.h"
/*
******************************************************************************
* ENABLE SWITCH
******************************************************************************
*/
#ifndef RFAL_FEATURE_NFCB
#define RFAL_FEATURE_NFCB false /* NFC-B module configuration missing. Disabled by default */
#endif
#if RFAL_FEATURE_NFCB
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_NFCB_SENSB_REQ_EXT_SENSB_RES_SUPPORTED 0x10U /*!< Bit mask for Extended SensB Response support in SENSB_REQ */
#define RFAL_NFCB_SENSB_RES_PROT_TYPE_RFU 0x08U /*!< Bit mask for Protocol Type RFU in SENSB_RES */
#define RFAL_NFCB_SLOT_MARKER_SC_SHIFT 4U /*!< Slot Code position on SLOT_MARKER APn */
#define RFAL_NFCB_SLOTMARKER_SLOTCODE_MIN 1U /*!< SLOT_MARKER Slot Code minimum Digital 1.1 Table 37 */
#define RFAL_NFCB_SLOTMARKER_SLOTCODE_MAX 16U /*!< SLOT_MARKER Slot Code maximum Digital 1.1 Table 37 */
#define RFAL_NFCB_ACTIVATION_FWT (RFAL_NFCB_FWTSENSB + RFAL_NFCB_DTPOLL_20) /*!< FWT(SENSB) + dTbPoll Digital 2.0 7.9.1.3 */
/*! Advanced and Extended bit mask in Parameter of SENSB_REQ */
#define RFAL_NFCB_SENSB_REQ_PARAM (RFAL_NFCB_SENSB_REQ_ADV_FEATURE | RFAL_NFCB_SENSB_REQ_EXT_SENSB_RES_SUPPORTED)
/*! NFC-B commands definition */
enum
{
RFAL_NFCB_CMD_SENSB_REQ = 0x05, /*!< SENSB_REQ (REQB) & SLOT_MARKER Digital 1.1 Table 24 */
RFAL_NFCB_CMD_SENSB_RES = 0x50, /*!< SENSB_RES (ATQB) & SLOT_MARKER Digital 1.1 Table 27 */
RFAL_NFCB_CMD_SLPB_REQ = 0x50, /*!< SLPB_REQ (HLTB command) Digital 1.1 Table 38 */
RFAL_NFCB_CMD_SLPB_RES = 0x00 /*!< SLPB_RES (HLTB Answer) Digital 1.1 Table 39 */
};
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
#define rfalNfcbNI2NumberOfSlots( ni ) (uint8_t)(1U << (ni)) /*!< Converts the Number of slots Identifier to slot number */
/*
******************************************************************************
* GLOBAL TYPES
******************************************************************************
*/
/*! ALLB_REQ (WUPB) and SENSB_REQ (REQB) Command Format Digital 1.1 7.6.1 */
typedef struct
{
uint8_t cmd; /*!< xxxxB_REQ: 05h */
uint8_t AFI; /*!< NFC Identifier */
uint8_t PARAM; /*!< Application Data */
} rfalNfcbSensbReq;
/*! SLOT_MARKER Command format Digital 1.1 7.7.1 */
typedef struct
{
uint8_t APn; /*!< Slot number 2..16 | 0101b */
} rfalNfcbSlotMarker;
/*! SLPB_REQ (HLTB) Command Format Digital 1.1 7.8.1 */
typedef struct
{
uint8_t cmd; /*!< SLPB_REQ: 50h */
uint8_t nfcid0[RFAL_NFCB_NFCID0_LEN]; /*!< NFC Identifier (PUPI)*/
} rfalNfcbSlpbReq;
/*! SLPB_RES (HLTB) Response Format Digital 1.1 7.8.2 */
typedef struct
{
uint8_t cmd; /*!< SLPB_RES: 00h */
} rfalNfcbSlpbRes;
/*! RFAL NFC-B instance */
typedef struct
{
uint8_t AFI; /*!< AFI to be used */
uint8_t PARAM; /*!< PARAM to be used */
} rfalNfcb;
/*
******************************************************************************
* LOCAL FUNCTION PROTOTYPES
******************************************************************************
*/
static ReturnCode rfalNfcbCheckSensbRes( const rfalNfcbSensbRes *sensbRes, uint8_t sensbResLen );
/*
******************************************************************************
* LOCAL VARIABLES
******************************************************************************
*/
static rfalNfcb gRfalNfcb; /*!< RFAL NFC-B Instance */
/*
******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************
*/
/*******************************************************************************/
static ReturnCode rfalNfcbCheckSensbRes( const rfalNfcbSensbRes *sensbRes, uint8_t sensbResLen )
{
/* Check response length */
if( ( (sensbResLen != RFAL_NFCB_SENSB_RES_LEN) && (sensbResLen != RFAL_NFCB_SENSB_RES_EXT_LEN) ) )
{
return ERR_PROTO;
}
/* Check SENSB_RES and Protocol Type Digital 1.1 7.6.2.19 */
if( ((sensbRes->protInfo.FsciProType & RFAL_NFCB_SENSB_RES_PROT_TYPE_RFU) != 0U) || (sensbRes->cmd != (uint8_t)RFAL_NFCB_CMD_SENSB_RES) )
{
return ERR_PROTO;
}
return ERR_NONE;
}
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
/*******************************************************************************/
ReturnCode rfalNfcbPollerInitialize( void )
{
ReturnCode ret;
EXIT_ON_ERR( ret, rfalSetMode( RFAL_MODE_POLL_NFCB, RFAL_BR_106, RFAL_BR_106 ) );
rfalSetErrorHandling( RFAL_ERRORHANDLING_NFC );
rfalSetGT( RFAL_GT_NFCB );
rfalSetFDTListen( RFAL_FDT_LISTEN_NFCB_POLLER );
rfalSetFDTPoll( RFAL_FDT_POLL_NFCB_POLLER );
gRfalNfcb.AFI = RFAL_NFCB_AFI;
gRfalNfcb.PARAM = RFAL_NFCB_PARAM;
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode rfalNfcbPollerInitializeWithParams( uint8_t AFI, uint8_t PARAM )
{
ReturnCode ret;
EXIT_ON_ERR( ret, rfalNfcbPollerInitialize() );
gRfalNfcb.AFI = AFI;
gRfalNfcb.PARAM = (PARAM & RFAL_NFCB_SENSB_REQ_PARAM);
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode rfalNfcbPollerCheckPresence( rfalNfcbSensCmd cmd, rfalNfcbSlots slots, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen )
{
uint16_t rxLen;
ReturnCode ret;
rfalNfcbSensbReq sensbReq;
/* Check if the command requested and given the slot number are valid */
if( ((RFAL_NFCB_SENS_CMD_SENSB_REQ != cmd) && (RFAL_NFCB_SENS_CMD_ALLB_REQ != cmd)) ||
(slots > RFAL_NFCB_SLOT_NUM_16) || (sensbRes == NULL) || (sensbResLen == NULL) )
{
return ERR_PARAM;
}
*sensbResLen = 0;
ST_MEMSET(sensbRes, 0x00, sizeof(rfalNfcbSensbRes) );
/* Compute SENSB_REQ */
sensbReq.cmd = RFAL_NFCB_CMD_SENSB_REQ;
sensbReq.AFI = gRfalNfcb.AFI;
sensbReq.PARAM = (((uint8_t)gRfalNfcb.PARAM & RFAL_NFCB_SENSB_REQ_PARAM) | (uint8_t)cmd | (uint8_t)slots);
/* Send SENSB_REQ and disable AGC to detect collisions */
ret = rfalTransceiveBlockingTxRx( (uint8_t*)&sensbReq, sizeof(rfalNfcbSensbReq), (uint8_t*)sensbRes, sizeof(rfalNfcbSensbRes), &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_NFCB_FWTSENSB );
*sensbResLen = (uint8_t)rxLen;
/* Check if a transmission error was detected */
if( (ret == ERR_CRC) || (ret == ERR_FRAMING) )
{
/* Invalidate received frame as an error was detected (CollisionResolution checks if valid) */
*sensbResLen = 0;
return ERR_NONE;
}
if( ret == ERR_NONE )
{
return rfalNfcbCheckSensbRes( sensbRes, *sensbResLen );
}
return ret;
}
/*******************************************************************************/
ReturnCode rfalNfcbPollerSleep( const uint8_t* nfcid0 )
{
uint16_t rxLen;
ReturnCode ret;
rfalNfcbSlpbReq slpbReq;
rfalNfcbSlpbRes slpbRes;
if( nfcid0 == NULL )
{
return ERR_PARAM;
}
/* Compute SLPB_REQ */
slpbReq.cmd = RFAL_NFCB_CMD_SLPB_REQ;
ST_MEMCPY( slpbReq.nfcid0, nfcid0, RFAL_NFCB_NFCID0_LEN );
EXIT_ON_ERR( ret, rfalTransceiveBlockingTxRx( (uint8_t*)&slpbReq, sizeof(rfalNfcbSlpbReq), (uint8_t*)&slpbRes, sizeof(rfalNfcbSlpbRes), &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_NFCB_ACTIVATION_FWT ));
/* Check SLPB_RES */
if( (rxLen != sizeof(rfalNfcbSlpbRes)) || (slpbRes.cmd != (uint8_t)RFAL_NFCB_CMD_SLPB_RES) )
{
return ERR_PROTO;
}
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode rfalNfcbPollerSlotMarker( uint8_t slotCode, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen )
{
ReturnCode ret;
rfalNfcbSlotMarker slotMarker;
uint16_t rxLen;
/* Check parameters */
if( (sensbRes == NULL) || (sensbResLen == NULL) ||
(slotCode < RFAL_NFCB_SLOTMARKER_SLOTCODE_MIN) ||
(slotCode > RFAL_NFCB_SLOTMARKER_SLOTCODE_MAX) )
{
return ERR_PARAM;
}
/* Compose and send SLOT_MARKER with disabled AGC to detect collisions */
slotMarker.APn = ((slotCode << RFAL_NFCB_SLOT_MARKER_SC_SHIFT) | (uint8_t)RFAL_NFCB_CMD_SENSB_REQ);
ret = rfalTransceiveBlockingTxRx( (uint8_t*)&slotMarker, sizeof(rfalNfcbSlotMarker), (uint8_t*)sensbRes, sizeof(rfalNfcbSensbRes), &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_NFCB_ACTIVATION_FWT );
*sensbResLen = (uint8_t)rxLen;
/* Check if a transmission error was detected */
if( (ret == ERR_CRC) || (ret == ERR_FRAMING) )
{
return ERR_RF_COLLISION;
}
if( ret == ERR_NONE )
{
return rfalNfcbCheckSensbRes( sensbRes, *sensbResLen );
}
return ret;
}
ReturnCode rfalNfcbPollerTechnologyDetection( rfalComplianceMode compMode, rfalNfcbSensbRes *sensbRes, uint8_t *sensbResLen )
{
NO_WARNING(compMode);
return rfalNfcbPollerCheckPresence( RFAL_NFCB_SENS_CMD_SENSB_REQ, RFAL_NFCB_SLOT_NUM_1, sensbRes, sensbResLen );
}
/*******************************************************************************/
ReturnCode rfalNfcbPollerCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcbListenDevice *nfcbDevList, uint8_t *devCnt )
{
bool colPending; /* dummy */
return rfalNfcbPollerSlottedCollisionResolution( compMode, devLimit, RFAL_NFCB_SLOT_NUM_1, RFAL_NFCB_SLOT_NUM_16, nfcbDevList, devCnt, &colPending );
}
/*******************************************************************************/
ReturnCode rfalNfcbPollerSlottedCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcbSlots initSlots, rfalNfcbSlots endSlots, rfalNfcbListenDevice *nfcbDevList, uint8_t *devCnt, bool *colPending )
{
ReturnCode ret;
uint8_t slotsNum;
uint8_t slotCode;
uint8_t curDevCnt;
/* Check parameters. In ISO | Activity 1.0 mode the initial slots must be 1 as continuation of Technology Detection */
if( (nfcbDevList == NULL) || (devCnt == NULL) || (colPending == NULL) || (initSlots > RFAL_NFCB_SLOT_NUM_16) ||
(endSlots > RFAL_NFCB_SLOT_NUM_16) || ((compMode == RFAL_COMPLIANCE_MODE_ISO) && (initSlots != RFAL_NFCB_SLOT_NUM_1)) )
{
return ERR_PARAM;
}
/* Initialise as no error in case Activity 1.0 where the previous SENSB_RES from technology detection should be used */
ret = ERR_NONE;
*devCnt = 0;
curDevCnt = 0;
*colPending = false;
/* Send ALLB_REQ Activity 1.1 9.3.5.2 and 9.3.5.3 (Symbol 1 and 2) */
if( compMode != RFAL_COMPLIANCE_MODE_ISO )
{
ret = rfalNfcbPollerCheckPresence( RFAL_NFCB_SENS_CMD_ALLB_REQ, initSlots, &nfcbDevList->sensbRes, &nfcbDevList->sensbResLen );
if( (ret != ERR_NONE) && (initSlots == RFAL_NFCB_SLOT_NUM_1) )
{
return ret;
}
}
/* Check if there was a transmission error on WUPB EMVCo 2.6 9.3.3.1 */
if( (compMode == RFAL_COMPLIANCE_MODE_EMV) && (nfcbDevList->sensbResLen == 0U) )
{
return ERR_FRAMING;
}
for( slotsNum = (uint8_t)initSlots; slotsNum <= (uint8_t)endSlots; slotsNum++ )
{
do {
/* Activity 1.1 9.3.5.23 - Symbol 22 */
if( (compMode == RFAL_COMPLIANCE_MODE_NFC) && (curDevCnt != 0U) )
{
rfalNfcbPollerSleep( nfcbDevList[(*devCnt-1U)].sensbRes.nfcid0 );
nfcbDevList[(*devCnt-1U)].isSleep = true;
}
/* Send SENSB_REQ with number of slots if not the first Activity 1.1 9.3.5.24 - Symbol 23 */
if( (slotsNum != (uint8_t)initSlots) || *colPending )
{
/* PRQA S 4342 1 # MISRA 10.5 - Layout of rfalNfcbSlots and above loop guarantee that no invalid enum values are created. */
ret = rfalNfcbPollerCheckPresence( RFAL_NFCB_SENS_CMD_SENSB_REQ, (rfalNfcbSlots)slotsNum, &nfcbDevList[*devCnt].sensbRes, &nfcbDevList[*devCnt].sensbResLen );
}
/* Activity 1.1 9.3.5.6 - Symbol 5 */
slotCode = 0;
curDevCnt = 0;
*colPending = false;
do{
/* Activity 1.1 9.3.5.26 - Symbol 25 */
if( slotCode != 0U )
{
ret = rfalNfcbPollerSlotMarker( slotCode, &nfcbDevList[*devCnt].sensbRes, &nfcbDevList[*devCnt].sensbResLen );
}
/* Activity 1.1 9.3.5.7 and 9.3.5.8 - Symbol 6 */
if( ret != ERR_TIMEOUT )
{
/* Activity 1.1 9.3.5.8 - Symbol 7 */
if( (rfalNfcbCheckSensbRes( &nfcbDevList[*devCnt].sensbRes, nfcbDevList[*devCnt].sensbResLen) == ERR_NONE) && (ret == ERR_NONE) )
{
nfcbDevList[*devCnt].isSleep = false;
if( compMode == RFAL_COMPLIANCE_MODE_EMV )
{
(*devCnt)++;
return ret;
}
else if( compMode == RFAL_COMPLIANCE_MODE_ISO )
{
/* Activity 1.0 9.3.5.8 - Symbol 7 */
(*devCnt)++;
curDevCnt++;
/* Activity 1.0 9.3.5.10 - Symbol 9 */
if( (*devCnt >= devLimit) || (slotsNum == (uint8_t)RFAL_NFCB_SLOT_NUM_1) )
{
return ret;
}
/* Activity 1.0 9.3.5.11 - Symbol 10 */
rfalNfcbPollerSleep( nfcbDevList[*devCnt-1U].sensbRes.nfcid0 );
nfcbDevList[*devCnt-1U].isSleep = true;
}
else if( compMode == RFAL_COMPLIANCE_MODE_NFC )
{
/* Activity 1.1 9.3.5.10 and 9.3.5.11 - Symbol 9 and Symbol 11*/
if(curDevCnt != 0U)
{
rfalNfcbPollerSleep( nfcbDevList[*devCnt-1U].sensbRes.nfcid0 );
nfcbDevList[*devCnt-1U].isSleep = true;
}
/* Activity 1.1 9.3.5.12 - Symbol 11 */
(*devCnt)++;
curDevCnt++;
/* Activity 1.1 9.3.5.6 - Symbol 13 */
if( (*devCnt >= devLimit) || (slotsNum == (uint8_t)RFAL_NFCB_SLOT_NUM_1) )
{
return ret;
}
}
else
{
/* MISRA 15.7 - Empty else */
}
}
else
{
/* If deviceLimit is set to 0 the NFC Forum Device is configured to perform collision detection only Activity 1.0 and 1.1 9.3.5.5 - Symbol 4 */
if( (devLimit == 0U) && (slotsNum == (uint8_t)RFAL_NFCB_SLOT_NUM_1) )
{
return ERR_RF_COLLISION;
}
/* Activity 1.1 9.3.5.9 - Symbol 8 */
*colPending = true;
}
}
/* Activity 1.1 9.3.5.15 - Symbol 14 */
slotCode++;
}
while( slotCode < rfalNfcbNI2NumberOfSlots(slotsNum) );
/* Activity 1.1 9.3.5.17 - Symbol 16 */
if( !(*colPending) )
{
return ERR_NONE;
}
/* Activity 1.1 9.3.5.18 - Symbol 17 */
} while (curDevCnt != 0U); /* If a collision is detected and card(s) were found on this loop keep the same number of available slots */
}
return ERR_NONE;
}
/*******************************************************************************/
uint32_t rfalNfcbTR2ToFDT( uint8_t tr2Code )
{
/*******************************************************************************/
/* MISRA 8.9 An object should be defined at block scope if its identifier only appears in a single function */
/*! TR2 Table according to Digital 1.1 Table 33 */
const uint16_t rfalNfcbTr2Table[] = { 1792, 3328, 5376, 9472 };
/*******************************************************************************/
return rfalNfcbTr2Table[ (tr2Code & RFAL_NFCB_SENSB_RES_PROTO_TR2_MASK) ];
}
#endif /* RFAL_FEATURE_NFCB */

View File

@ -1,546 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_nfcf.c
*
* \author Gustavo Patricio
*
* \brief Implementation of NFC-F Poller (FeliCa PCD) device
*
* The definitions and helpers methods provided by this module are
* aligned with NFC-F (FeliCa - JIS X6319-4)
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "rfal_nfcf.h"
#include "utils.h"
/*
******************************************************************************
* ENABLE SWITCH
******************************************************************************
*/
#ifndef RFAL_FEATURE_NFCF
#define RFAL_FEATURE_NFCF false /* NFC-F module configuration missing. Disabled by default */
#endif
#if RFAL_FEATURE_NFCF
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_NFCF_SENSF_REQ_LEN_MIN 5U /*!< SENSF_RES minimum length */
#define RFAL_NFCF_READ_WO_ENCRYPTION_MIN_LEN 15U /*!< Minimum length for a Check Command T3T 5.4.1 */
#define RFAL_NFCF_WRITE_WO_ENCRYPTION_MIN_LEN 31U /*!< Minimum length for an Update Command T3T 5.5.1 */
#define RFAL_NFCF_CHECK_RES_MIN_LEN 11U /*!< CHECK Response minimum length T3T 1.0 Table 8 */
#define RFAL_NFCF_UPDATE_RES_MIN_LEN 11U /*!< UPDATE Response minimum length T3T 1.0 Table 8 */
#define RFAL_NFCF_CHECK_REQ_MAX_LEN 86U /*!< Max length of a Check request T3T 1.0 Table 7 */
#define RFAL_NFCF_CHECK_REQ_MAX_SERV 15U /*!< Max Services number on Check request T3T 1.0 5.4.1.5 */
#define RFAL_NFCF_CHECK_REQ_MAX_BLOCK 15U /*!< Max Blocks number on Check request T3T 1.0 5.4.1.10 */
#define RFAL_NFCF_UPDATE_REQ_MAX_SERV 15U /*!< Max Services number Update request T3T 1.0 5.4.1.5 */
#define RFAL_NFCF_UPDATE_REQ_MAX_BLOCK 13U /*!< Max Blocks number on Update request T3T 1.0 5.4.1.10 */
/*! MRT Check | Uupdate = (Tt3t x ((A+1) + n (B+1)) x 4^E) + dRWTt3t T3T 5.8
Max values used: A = 7 ; B = 7 ; E = 3 ; n = 15 (NFC Forum n = 15, JIS n = 32)
*/
#define RFAL_NFCF_MRT_CHECK_UPDATE ((4096 * (8 + (15 * 8)) * 64 ) + 16)
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
#define rfalNfcfSlots2CardNum( s ) ((uint8_t)(s)+1U) /*!< Converts Time Slot Number (TSN) into num of slots */
/*
******************************************************************************
* GLOBAL TYPES
******************************************************************************
*/
/*! Structure/Buffer to hold the SENSF_RES with LEN byte prepended */
typedef struct{
uint8_t LEN; /*!< NFC-F LEN byte */
rfalNfcfSensfRes SENSF_RES; /*!< SENSF_RES */
} rfalNfcfSensfResBuf;
/*! Greedy collection for NFCF GRE_POLL_F Activity 1.0 Table 10 */
typedef struct{
uint8_t pollFound; /*!< Number of devices found by the Poll */
uint8_t pollCollision; /*!< Number of collisions detected */
rfalFeliCaPollRes POLL_F[RFAL_NFCF_POLL_MAXCARDS]; /*!< GRE_POLL_F Activity 1.0 Table 10 */
} rfalNfcfGreedyF;
/*! NFC-F SENSF_REQ format Digital 1.1 8.6.1 */
typedef struct
{
uint8_t CMD; /*!< Command code: 00h */
uint8_t SC[RFAL_NFCF_SENSF_SC_LEN]; /*!< System Code */
uint8_t RC; /*!< Request Code */
uint8_t TSN; /*!< Time Slot Number */
} rfalNfcfSensfReq;
/*
******************************************************************************
* LOCAL VARIABLES
******************************************************************************
*/
static rfalNfcfGreedyF gRfalNfcfGreedyF; /*!< Activity's NFCF Greedy collection */
/*
******************************************************************************
* LOCAL FUNCTION PROTOTYPES
******************************************************************************
*/
static void rfalNfcfComputeValidSENF( rfalNfcfListenDevice *outDevInfo, uint8_t *curDevIdx, uint8_t devLimit, bool overwrite, bool *nfcDepFound );
/*
******************************************************************************
* LOCAL VARIABLES
******************************************************************************
*/
/*******************************************************************************/
static void rfalNfcfComputeValidSENF( rfalNfcfListenDevice *outDevInfo, uint8_t *curDevIdx, uint8_t devLimit, bool overwrite, bool *nfcDepFound )
{
uint8_t tmpIdx;
bool duplicate;
rfalNfcfSensfResBuf *sensfBuf;
rfalNfcfSensfResBuf sensfCopy;
/*******************************************************************************/
/* Go through all responses check if valid and duplicates */
/*******************************************************************************/
while( (gRfalNfcfGreedyF.pollFound > 0U) && ((*curDevIdx) < devLimit) )
{
duplicate = false;
gRfalNfcfGreedyF.pollFound--;
/* MISRA 11.3 - Cannot point directly into different object type, use local copy */
ST_MEMCPY( (uint8_t*)&sensfCopy, (uint8_t*)&gRfalNfcfGreedyF.POLL_F[gRfalNfcfGreedyF.pollFound], sizeof(rfalNfcfSensfResBuf) );
/* Point to received SENSF_RES */
sensfBuf = &sensfCopy;
/* Check for devices that are already in device list */
for( tmpIdx = 0; tmpIdx < (*curDevIdx); tmpIdx++ )
{
if( ST_BYTECMP( sensfBuf->SENSF_RES.NFCID2, outDevInfo[tmpIdx].sensfRes.NFCID2, RFAL_NFCF_NFCID2_LEN ) == 0 )
{
duplicate = true;
break;
}
}
/* If is a duplicate skip this (and not to overwrite)*/
if(duplicate && !overwrite)
{
continue;
}
/* Check if response length is OK */
if( (( sensfBuf->LEN - RFAL_NFCF_HEADER_LEN) < RFAL_NFCF_SENSF_RES_LEN_MIN) || ((sensfBuf->LEN - RFAL_NFCF_HEADER_LEN) > RFAL_NFCF_SENSF_RES_LEN_MAX) )
{
continue;
}
/* Check if the response is a SENSF_RES / Polling response */
if( sensfBuf->SENSF_RES.CMD != (uint8_t)RFAL_NFCF_CMD_POLLING_RES )
{
continue;
}
/* Check if is an overwrite request or new device*/
if(duplicate && overwrite)
{
/* overwrite deviceInfo/GRE_SENSF_RES with SENSF_RES */
outDevInfo[tmpIdx].sensfResLen = (sensfBuf->LEN - RFAL_NFCF_LENGTH_LEN);
ST_MEMCPY( &outDevInfo[tmpIdx].sensfRes, &sensfBuf->SENSF_RES, outDevInfo[tmpIdx].sensfResLen );
continue;
}
else
{
/* fill deviceInfo/GRE_SENSF_RES with new SENSF_RES */
outDevInfo[(*curDevIdx)].sensfResLen = (sensfBuf->LEN - RFAL_NFCF_LENGTH_LEN);
ST_MEMCPY( &outDevInfo[(*curDevIdx)].sensfRes, &sensfBuf->SENSF_RES, outDevInfo[(*curDevIdx)].sensfResLen );
}
/* Check if this device supports NFC-DEP and signal it (ACTIVITY 1.1 9.3.6.63) */
*nfcDepFound = rfalNfcfIsNfcDepSupported( &outDevInfo[(*curDevIdx)] );
(*curDevIdx)++;
}
}
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
/*******************************************************************************/
ReturnCode rfalNfcfPollerInitialize( rfalBitRate bitRate )
{
ReturnCode ret;
if( (bitRate != RFAL_BR_212) && (bitRate != RFAL_BR_424) )
{
return ERR_PARAM;
}
EXIT_ON_ERR( ret, rfalSetMode( RFAL_MODE_POLL_NFCF, bitRate, bitRate ) );
rfalSetErrorHandling( RFAL_ERRORHANDLING_NFC );
rfalSetGT( RFAL_GT_NFCF );
rfalSetFDTListen( RFAL_FDT_LISTEN_NFCF_POLLER );
rfalSetFDTPoll( RFAL_FDT_POLL_NFCF_POLLER );
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode rfalNfcfPollerPoll( rfalFeliCaPollSlots slots, uint16_t sysCode, uint8_t reqCode, rfalFeliCaPollRes *cardList, uint8_t *devCnt, uint8_t *collisions )
{
return rfalFeliCaPoll( slots, sysCode, reqCode, cardList, rfalNfcfSlots2CardNum(slots), devCnt, collisions );
}
/*******************************************************************************/
ReturnCode rfalNfcfPollerCheckPresence( void )
{
gRfalNfcfGreedyF.pollFound = 0;
gRfalNfcfGreedyF.pollCollision = 0;
/* ACTIVITY 1.0 & 1.1 - 9.2.3.17 SENSF_REQ must be with number of slots equal to 4
* SC must be 0xFFFF
* RC must be 0x00 (No system code info required) */
return rfalFeliCaPoll( RFAL_FELICA_4_SLOTS, RFAL_NFCF_SYSTEMCODE, RFAL_FELICA_POLL_RC_NO_REQUEST, gRfalNfcfGreedyF.POLL_F, rfalNfcfSlots2CardNum(RFAL_FELICA_4_SLOTS), &gRfalNfcfGreedyF.pollFound, &gRfalNfcfGreedyF.pollCollision );
}
/*******************************************************************************/
ReturnCode rfalNfcfPollerCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcfListenDevice *nfcfDevList, uint8_t *devCnt )
{
ReturnCode ret;
bool nfcDepFound;
if( (nfcfDevList == NULL) || (devCnt == NULL) )
{
return ERR_PARAM;
}
*devCnt = 0;
nfcDepFound = false;
/*******************************************************************************************/
/* ACTIVITY 1.0 - 9.3.6.3 Copy valid SENSF_RES in GRE_POLL_F into GRE_SENSF_RES */
/* ACTIVITY 1.0 - 9.3.6.6 The NFC Forum Device MUST remove all entries from GRE_SENSF_RES[]*/
/* ACTIVITY 1.1 - 9.3.63.59 Populate GRE_SENSF_RES with data from GRE_POLL_F */
/* */
/* CON_DEVICES_LIMIT = 0 Just check if devices from Tech Detection exceeds -> always true */
/* Allow the number of slots open on Technology Detection */
/*******************************************************************************************/
rfalNfcfComputeValidSENF( nfcfDevList, devCnt, ((devLimit == 0U) ? rfalNfcfSlots2CardNum( RFAL_FELICA_4_SLOTS ) : devLimit), false, &nfcDepFound );
/*******************************************************************************/
/* ACTIVITY 1.0 - 9.3.6.4 */
/* ACTIVITY 1.1 - 9.3.63.60 Check if devices found are lower than the limit */
/* and send a SENSF_REQ if so */
/*******************************************************************************/
if( *devCnt < devLimit )
{
/* ACTIVITY 1.0 - 9.3.6.5 Copy valid SENSF_RES and then to remove it
* ACTIVITY 1.1 - 9.3.6.65 Copy and filter duplicates
* For now, due to some devices keep generating different nfcid2, we use 1.0
* Phones detected: Samsung Galaxy Nexus,Samsung Galaxy S3,Samsung Nexus S */
*devCnt = 0;
ret = rfalNfcfPollerPoll( RFAL_FELICA_16_SLOTS, RFAL_NFCF_SYSTEMCODE, RFAL_FELICA_POLL_RC_NO_REQUEST, gRfalNfcfGreedyF.POLL_F, &gRfalNfcfGreedyF.pollFound, &gRfalNfcfGreedyF.pollCollision );
if( ret == ERR_NONE )
{
rfalNfcfComputeValidSENF( nfcfDevList, devCnt, devLimit, false, &nfcDepFound );
}
/*******************************************************************************/
/* ACTIVITY 1.1 - 9.3.6.63 Check if any device supports NFC DEP */
/*******************************************************************************/
if( nfcDepFound && (compMode == RFAL_COMPLIANCE_MODE_NFC) )
{
ret = rfalNfcfPollerPoll( RFAL_FELICA_16_SLOTS, RFAL_NFCF_SYSTEMCODE, RFAL_FELICA_POLL_RC_SYSTEM_CODE, gRfalNfcfGreedyF.POLL_F, &gRfalNfcfGreedyF.pollFound, &gRfalNfcfGreedyF.pollCollision );
if( ret == ERR_NONE )
{
rfalNfcfComputeValidSENF( nfcfDevList, devCnt, devLimit, true, &nfcDepFound );
}
}
}
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode rfalNfcfPollerCheck( const uint8_t* nfcid2, const rfalNfcfServBlockListParam *servBlock, uint8_t *rxBuf, uint16_t rxBufLen, uint16_t *rcvdLen )
{
uint8_t txBuf[RFAL_NFCF_CHECK_REQ_MAX_LEN];
uint8_t msgIt;
uint8_t i;
ReturnCode ret;
uint8_t *checkRes;
/* Check parameters */
if( (nfcid2 == NULL) || (rxBuf == NULL) || (servBlock == NULL) ||
(servBlock->numBlock == 0U) || (servBlock->numBlock > RFAL_NFCF_CHECK_REQ_MAX_BLOCK) ||
(servBlock->numServ == 0U) || (servBlock->numServ > RFAL_NFCF_CHECK_REQ_MAX_SERV) ||
(rxBufLen < (RFAL_NFCF_LENGTH_LEN + RFAL_NFCF_CHECK_RES_MIN_LEN)) )
{
return ERR_PARAM;
}
msgIt = 0;
/*******************************************************************************/
/* Compose CHECK command/request */
txBuf[msgIt++] = RFAL_NFCF_CMD_READ_WITHOUT_ENCRYPTION; /* Command Code */
ST_MEMCPY( &txBuf[msgIt], nfcid2, RFAL_NFCF_NFCID2_LEN ); /* NFCID2 */
msgIt += RFAL_NFCF_NFCID2_LEN;
txBuf[msgIt++] = servBlock->numServ; /* NoS */
for( i = 0; i < servBlock->numServ; i++)
{
txBuf[msgIt++] = (uint8_t)((servBlock->servList[i] >> 0U) & 0xFFU); /* Service Code */
txBuf[msgIt++] = (uint8_t)((servBlock->servList[i] >> 8U) & 0xFFU);
}
txBuf[msgIt++] = servBlock->numBlock; /* NoB */
for( i = 0; i < servBlock->numBlock; i++)
{
txBuf[msgIt++] = servBlock->blockList[i].conf; /* Block list element conf (Flag|Access|Service) */
if( (servBlock->blockList[i].conf & 0x80U) != 0U ) /* Check if 2 or 3 byte block list element */
{
txBuf[msgIt++] = (uint8_t)(servBlock->blockList[i].blockNum & 0xFFU); /* 1byte Block Num */
}
else
{
txBuf[msgIt++] = (uint8_t)((servBlock->blockList[i].blockNum >> 0U) & 0xFFU); /* 2byte Block Num */
txBuf[msgIt++] = (uint8_t)((servBlock->blockList[i].blockNum >> 8U) & 0xFFU);
}
}
/*******************************************************************************/
/* Transceive CHECK command/request */
ret = rfalTransceiveBlockingTxRx( txBuf, msgIt, rxBuf, rxBufLen, rcvdLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_NFCF_MRT_CHECK_UPDATE );
if( ret == ERR_NONE )
{
/* Skip LEN byte */
checkRes = (rxBuf + RFAL_NFCF_LENGTH_LEN);
/* Check response length */
if( *rcvdLen < (RFAL_NFCF_LENGTH_LEN + RFAL_NFCF_CHECKUPDATE_RES_ST2_POS) )
{
ret = ERR_PROTO;
}
/* Check for a valid response */
else if( (checkRes[RFAL_NFCF_CMD_POS] != (uint8_t)RFAL_NFCF_CMD_READ_WITHOUT_ENCRYPTION_RES) ||
(checkRes[RFAL_NFCF_CHECKUPDATE_RES_ST1_POS] != RFAL_NFCF_STATUS_FLAG_SUCCESS) ||
(checkRes[RFAL_NFCF_CHECKUPDATE_RES_ST2_POS] != RFAL_NFCF_STATUS_FLAG_SUCCESS) )
{
ret = ERR_REQUEST;
}
/* CHECK succesfull, remove header */
else
{
(*rcvdLen) -= (RFAL_NFCF_LENGTH_LEN + RFAL_NFCF_CHECKUPDATE_RES_NOB_POS);
if( *rcvdLen > 0U )
{
ST_MEMMOVE( rxBuf, &checkRes[RFAL_NFCF_CHECKUPDATE_RES_NOB_POS], (*rcvdLen) );
}
}
}
return ret;
}
/*******************************************************************************/
ReturnCode rfalNfcfPollerUpdate( const uint8_t* nfcid2, const rfalNfcfServBlockListParam *servBlock, uint8_t *txBuf, uint16_t txBufLen, const uint8_t *blockData, uint8_t *rxBuf, uint16_t rxBufLen )
{
uint8_t i;
uint16_t msgIt;
uint16_t rcvdLen;
uint16_t auxLen;
uint8_t *updateRes;
ReturnCode ret;
/* Check parameters */
if( (nfcid2 == NULL) || (rxBuf == NULL) || (servBlock == NULL) || (txBuf == NULL) ||
(servBlock->numBlock == 0U) || (servBlock->numBlock > RFAL_NFCF_UPDATE_REQ_MAX_BLOCK) ||
(servBlock->numServ == 0U) || (servBlock->numServ > RFAL_NFCF_UPDATE_REQ_MAX_SERV) ||
(rxBufLen < (RFAL_NFCF_LENGTH_LEN + RFAL_NFCF_UPDATE_RES_MIN_LEN)) )
{
return ERR_PARAM;
}
/* Calculate required txBuffer lenth */
auxLen = (uint16_t)( RFAL_NFCF_CMD_LEN + RFAL_NFCF_NFCID2_LEN + ( servBlock->numServ * sizeof(rfalNfcfServ) ) +
(servBlock->numBlock * sizeof(rfalNfcfBlockListElem)) + (uint16_t)((uint16_t)servBlock->numBlock * RFAL_NFCF_BLOCK_LEN) );
/* Check whether the provided buffer is sufficient for this request */
if( txBufLen < auxLen )
{
return ERR_PARAM;
}
msgIt = 0;
/*******************************************************************************/
/* Compose UPDATE command/request */
txBuf[msgIt++] = RFAL_NFCF_CMD_WRITE_WITHOUT_ENCRYPTION; /* Command Code */
ST_MEMCPY( &txBuf[msgIt], nfcid2, RFAL_NFCF_NFCID2_LEN ); /* NFCID2 */
msgIt += RFAL_NFCF_NFCID2_LEN;
txBuf[msgIt++] = servBlock->numServ; /* NoS */
for( i = 0; i < servBlock->numServ; i++)
{
txBuf[msgIt++] = (uint8_t)((servBlock->servList[i] >> 0U) & 0xFFU); /* Service Code */
txBuf[msgIt++] = (uint8_t)((servBlock->servList[i] >> 8U) & 0xFFU);
}
txBuf[msgIt++] = servBlock->numBlock; /* NoB */
for( i = 0; i < servBlock->numBlock; i++)
{
txBuf[msgIt++] = servBlock->blockList[i].conf; /* Block list element conf (Flag|Access|Service) */
if( (servBlock->blockList[i].conf & 0x80U) != 0U ) /* Check if 2 or 3 byte block list element */
{
txBuf[msgIt++] = (uint8_t)(servBlock->blockList[i].blockNum & 0xFFU); /* 1byte Block Num */
}
else
{
txBuf[msgIt++] = (uint8_t)((servBlock->blockList[i].blockNum >> 0U) & 0xFFU); /* 2byte Block Num */
txBuf[msgIt++] = (uint8_t)((servBlock->blockList[i].blockNum >> 8U) & 0xFFU);
}
}
auxLen = ((uint16_t)servBlock->numBlock * RFAL_NFCF_BLOCK_LEN);
ST_MEMCPY( &txBuf[msgIt], blockData, auxLen ); /* Block Data */
msgIt += auxLen;
/*******************************************************************************/
/* Transceive UPDATE command/request */
ret = rfalTransceiveBlockingTxRx( txBuf, msgIt, rxBuf, rxBufLen, &rcvdLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_NFCF_MRT_CHECK_UPDATE );
if( ret == ERR_NONE )
{
/* Skip LEN byte */
updateRes = (rxBuf + RFAL_NFCF_LENGTH_LEN);
/* Check response length */
if( rcvdLen < (RFAL_NFCF_LENGTH_LEN + RFAL_NFCF_CHECKUPDATE_RES_ST2_POS) )
{
ret = ERR_PROTO;
}
/* Check for a valid response */
else if( (updateRes[RFAL_NFCF_CMD_POS] != (uint8_t)RFAL_NFCF_CMD_WRITE_WITHOUT_ENCRYPTION_RES) ||
(updateRes[RFAL_NFCF_CHECKUPDATE_RES_ST1_POS] != RFAL_NFCF_STATUS_FLAG_SUCCESS) ||
(updateRes[RFAL_NFCF_CHECKUPDATE_RES_ST2_POS] != RFAL_NFCF_STATUS_FLAG_SUCCESS) )
{
ret = ERR_REQUEST;
}
else
{
/* MISRA 15.7 - Empty else */
}
}
return ret;
}
/*******************************************************************************/
bool rfalNfcfListenerIsT3TReq( const uint8_t* buf, uint16_t bufLen, uint8_t* nfcid2 )
{
/* Check cmd byte */
switch( *buf )
{
case RFAL_NFCF_CMD_READ_WITHOUT_ENCRYPTION:
if( bufLen < RFAL_NFCF_READ_WO_ENCRYPTION_MIN_LEN )
{
return false;
}
break;
case RFAL_NFCF_CMD_WRITE_WITHOUT_ENCRYPTION:
if( bufLen < RFAL_NFCF_WRITE_WO_ENCRYPTION_MIN_LEN )
{
return false;
}
break;
default:
return false;
}
/* Output NFID2 if requested */
if( nfcid2 != NULL )
{
ST_MEMCPY( nfcid2, &buf[RFAL_NFCF_CMD_LEN], RFAL_NFCF_NFCID2_LEN );
}
return true;
}
#endif /* RFAL_FEATURE_NFCF */

View File

@ -1,874 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_nfcv.c
*
* \author Gustavo Patricio
*
* \brief Implementation of NFC-V Poller (ISO15693) device
*
* The definitions and helpers methods provided by this module are
* aligned with NFC-V (ISO15693)
*
* The definitions and helpers methods provided by this module
* are aligned with NFC-V Digital 2.1
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "rfal_nfcv.h"
#include "utils.h"
/*
******************************************************************************
* ENABLE SWITCH
******************************************************************************
*/
#ifndef RFAL_FEATURE_NFCV
#define RFAL_FEATURE_NFCV false /* NFC-V module configuration missing. Disabled by default */
#endif
#if RFAL_FEATURE_NFCV
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_NFCV_INV_REQ_FLAG 0x06U /*!< INVENTORY_REQ INV_FLAG Digital 2.1 9.6.1 */
#define RFAL_NFCV_MASKVAL_MAX_LEN 8U /*!< Mask value max length: 64 bits (UID length) */
#define RFAL_NFCV_MASKVAL_MAX_1SLOT_LEN 64U /*!< Mask value max length in 1 Slot mode in bits Digital 2.1 9.6.1.6 */
#define RFAL_NFCV_MASKVAL_MAX_16SLOT_LEN 60U /*!< Mask value max length in 16 Slot mode in bits Digital 2.1 9.6.1.6 */
#define RFAL_NFCV_MAX_SLOTS 16U /*!< NFC-V max number of Slots */
#define RFAL_NFCV_INV_REQ_HEADER_LEN 3U /*!< INVENTORY_REQ header length (INV_FLAG, CMD, MASK_LEN) */
#define RFAL_NFCV_INV_RES_LEN 10U /*!< INVENTORY_RES length */
#define RFAL_NFCV_WR_MUL_REQ_HEADER_LEN 4U /*!< Write Multiple header length (INV_FLAG, CMD, [UID], BNo, Bno) */
#define RFAL_CMD_LEN 1U /*!< Commandbyte length */
#define RFAL_NFCV_FLAG_POS 0U /*!< Flag byte position */
#define RFAL_NFCV_FLAG_LEN 1U /*!< Flag byte length */
#define RFAL_NFCV_DATASTART_POS 1U /*!< Position of start of data */
#define RFAL_NFCV_DSFI_LEN 1U /*!< DSFID length */
#define RFAL_NFCV_SLPREQ_REQ_FLAG 0x22U /*!< SLPV_REQ request flags Digital 2.0 (Candidate) 9.7.1.1 */
#define RFAL_NFCV_MAX_COLL_SUPPORTED 16U /*!< Maximum number of collisions supported by the Anticollision loop */
#define RFAL_FDT_POLL_MAX rfalConvMsTo1fc(20) /*!< Maximum Wait time FDTV,EOF 20 ms Digital 2.0 B.5 */
/*! Time from special frame to EOF
* ISO15693 2009 10.4.2 : 20ms
* NFC Forum defines Digital 2.0 9.7.4 : FDTV,EOF = [10 ; 20]ms
*/
#define RFAL_NFCV_FDT_EOF 20U
/*! Time between slots - ISO 15693 defines t3min depending on modulation depth and data rate.
* With only high-bitrate supported, AM modulation and a length of 12 bytes (96bits) for INV_RES we get:
* - ISO t3min = 96/26 ms + 300us = 4 ms
* - NFC Forum defines FDTV,INVENT_NORES = (4394 + 2048)/fc. Digital 2.0 B.5*/
#define RFAL_NFCV_FDT_V_INVENT_NORES 4U
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
/*
******************************************************************************
* GLOBAL TYPES
******************************************************************************
*/
/*! NFC-V INVENTORY_REQ format Digital 2.0 9.6.1 */
typedef struct
{
uint8_t INV_FLAG; /*!< Inventory Flags */
uint8_t CMD; /*!< Command code: 01h */
uint8_t MASK_LEN; /*!< Mask Value Length */
uint8_t MASK_VALUE[RFAL_NFCV_MASKVAL_MAX_LEN]; /*!< Mask Value */
} rfalNfcvInventoryReq;
/*! NFC-V SLP_REQ format Digital 2.0 (Candidate) 9.7.1 */
typedef struct
{
uint8_t REQ_FLAG; /*!< Request Flags */
uint8_t CMD; /*!< Command code: 02h */
uint8_t UID[RFAL_NFCV_UID_LEN]; /*!< Mask Value */
} rfalNfcvSlpvReq;
/*! Container for a collision found during Anticollision loop */
typedef struct
{
uint8_t maskLen;
uint8_t maskVal[RFAL_NFCV_MASKVAL_MAX_LEN];
}rfalNfcvCollision;
/*
******************************************************************************
* LOCAL FUNCTION PROTOTYPES
******************************************************************************
*/
static ReturnCode rfalNfcvParseError( uint8_t err );
/*
******************************************************************************
* LOCAL VARIABLES
******************************************************************************
*/
/*
******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************
*/
/*******************************************************************************/
static ReturnCode rfalNfcvParseError( uint8_t err )
{
switch(err)
{
case RFAL_NFCV_ERROR_CMD_NOT_SUPPORTED:
case RFAL_NFCV_ERROR_OPTION_NOT_SUPPORTED:
return ERR_NOTSUPP;
case RFAL_NFCV_ERROR_CMD_NOT_RECOGNIZED:
return ERR_PROTO;
case RFAL_NFCV_ERROR_WRITE_FAILED:
return ERR_WRITE;
default:
return ERR_REQUEST;
}
}
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
/*******************************************************************************/
ReturnCode rfalNfcvPollerInitialize( void )
{
ReturnCode ret;
EXIT_ON_ERR( ret, rfalSetMode( RFAL_MODE_POLL_NFCV, RFAL_BR_26p48, RFAL_BR_26p48 ) );
rfalSetErrorHandling( RFAL_ERRORHANDLING_NFC );
rfalSetGT( RFAL_GT_NFCV );
rfalSetFDTListen( RFAL_FDT_LISTEN_NFCV_POLLER );
rfalSetFDTPoll( RFAL_FDT_POLL_NFCV_POLLER );
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode rfalNfcvPollerCheckPresence( rfalNfcvInventoryRes *invRes )
{
ReturnCode ret;
/* INVENTORY_REQ with 1 slot and no Mask Activity 2.0 (Candidate) 9.2.3.32 */
ret = rfalNfcvPollerInventory( RFAL_NFCV_NUM_SLOTS_1, 0, NULL, invRes, NULL );
if( (ret == ERR_RF_COLLISION) || (ret == ERR_CRC) ||
(ret == ERR_FRAMING) || (ret == ERR_PROTO) )
{
ret = ERR_NONE;
}
return ret;
}
/*******************************************************************************/
ReturnCode rfalNfcvPollerInventory( rfalNfcvNumSlots nSlots, uint8_t maskLen, const uint8_t *maskVal, rfalNfcvInventoryRes *invRes, uint16_t* rcvdLen )
{
ReturnCode ret;
rfalNfcvInventoryReq invReq;
uint16_t rxLen;
if( ((maskVal == NULL) && (maskLen != 0U)) || (invRes == NULL) )
{
return ERR_PARAM;
}
invReq.INV_FLAG = (RFAL_NFCV_INV_REQ_FLAG | (uint8_t)nSlots);
invReq.CMD = RFAL_NFCV_CMD_INVENTORY;
invReq.MASK_LEN = (uint8_t)MIN( maskLen, ((nSlots == RFAL_NFCV_NUM_SLOTS_1) ? RFAL_NFCV_MASKVAL_MAX_1SLOT_LEN : RFAL_NFCV_MASKVAL_MAX_16SLOT_LEN) ); /* Digital 2.0 9.6.1.6 */
if( rfalConvBitsToBytes(invReq.MASK_LEN) > 0U ) /* MISRA 21.18 */
{
ST_MEMCPY( invReq.MASK_VALUE, maskVal, rfalConvBitsToBytes(invReq.MASK_LEN) );
}
ret = rfalISO15693TransceiveAnticollisionFrame( (uint8_t*)&invReq, (uint8_t)(RFAL_NFCV_INV_REQ_HEADER_LEN + rfalConvBitsToBytes(invReq.MASK_LEN)), (uint8_t*)invRes, sizeof(rfalNfcvInventoryRes), &rxLen );
/* Check for optional output parameter */
if( rcvdLen != NULL )
{
*rcvdLen = rxLen;
}
if( ret == ERR_NONE )
{
if( rxLen != rfalConvBytesToBits(RFAL_NFCV_INV_RES_LEN + RFAL_NFCV_CRC_LEN) )
{
return ERR_PROTO;
}
}
return ret;
}
/*******************************************************************************/
ReturnCode rfalNfcvPollerCollisionResolution( rfalComplianceMode compMode, uint8_t devLimit, rfalNfcvListenDevice *nfcvDevList, uint8_t *devCnt )
{
ReturnCode ret;
uint8_t slotNum;
uint16_t rcvdLen;
uint8_t colIt;
uint8_t colCnt;
uint8_t colPos;
bool colPending;
rfalNfcvCollision colFound[RFAL_NFCV_MAX_COLL_SUPPORTED];
if( (nfcvDevList == NULL) || (devCnt == NULL) )
{
return ERR_PARAM;
}
/* Initialize parameters */
*devCnt = 0;
colIt = 0;
colCnt = 0;
colPending = false;
ST_MEMSET(colFound, 0x00, (sizeof(rfalNfcvCollision)*RFAL_NFCV_MAX_COLL_SUPPORTED) );
if( devLimit > 0U ) /* MISRA 21.18 */
{
ST_MEMSET(nfcvDevList, 0x00, (sizeof(rfalNfcvListenDevice)*devLimit) );
}
NO_WARNING(colPending); /* colPending is not exposed externally, in future it might become exposed/ouput parameter */
if( compMode == RFAL_COMPLIANCE_MODE_NFC )
{
/* Send INVENTORY_REQ with one slot Activity 2.0 9.3.7.1 (Symbol 0) */
ret = rfalNfcvPollerInventory( RFAL_NFCV_NUM_SLOTS_1, 0, NULL, &nfcvDevList->InvRes, NULL );
if( ret == ERR_TIMEOUT ) /* Exit if no device found Activity 2.0 9.3.7.2 (Symbol 1) */
{
return ERR_NONE;
}
if( ret == ERR_NONE ) /* Device found without transmission error/collision Activity 2.0 9.3.7.3 (Symbol 2) */
{
(*devCnt)++;
return ERR_NONE;
}
/* A Collision has been identified Activity 2.0 9.3.7.2 (Symbol 3) */
colPending = true;
colCnt = 1;
/* Check if the Collision Resolution is set to perform only Collision detection Activity 2.0 9.3.7.5 (Symbol 4)*/
if( devLimit == 0U )
{
return ERR_RF_COLLISION;
}
platformDelay(RFAL_NFCV_FDT_V_INVENT_NORES);
/*******************************************************************************/
/* Collisions pending, Anticollision loop must be executed */
/*******************************************************************************/
}
else
{
/* Advance to 16 slots below without mask. Will give a good chance to identify multiple cards */
colPending = true;
colCnt = 1;
}
/* Execute until all collisions are resolved Activity 2.0 9.3.7.16 (Symbol 17) */
do
{
/* Activity 2.0 9.3.7.5 (Symbol 6) */
colPending = false;
slotNum = 0;
do
{
if( slotNum == 0U )
{
/* Send INVENTORY_REQ with 16 slots Activity 2.0 9.3.7.7 (Symbol 8) */
ret = rfalNfcvPollerInventory( RFAL_NFCV_NUM_SLOTS_16, colFound[colIt].maskLen, colFound[colIt].maskVal, &nfcvDevList[(*devCnt)].InvRes, &rcvdLen );
}
else
{
ret = rfalISO15693TransceiveEOFAnticollision( (uint8_t*)&nfcvDevList[(*devCnt)].InvRes, sizeof(rfalNfcvInventoryRes), &rcvdLen );
}
slotNum++;
/*******************************************************************************/
if( ret != ERR_TIMEOUT )
{
if( rcvdLen < rfalConvBytesToBits(RFAL_NFCV_INV_RES_LEN + RFAL_NFCV_CRC_LEN) )
{ /* If only a partial frame was received make sure the FDT_V_INVENT_NORES is fulfilled */
platformDelay(RFAL_NFCV_FDT_V_INVENT_NORES);
}
if( ret == ERR_NONE )
{
/* Check if the device found is already on the list and its response is a valid INVENTORY_RES */
if( rcvdLen == rfalConvBytesToBits(RFAL_NFCV_INV_RES_LEN + RFAL_NFCV_CRC_LEN) )
{
/* Activity 2.0 9.3.7.15 (Symbol 11) */
(*devCnt)++;
}
}
else /* Treat everything else as collision */
{
/* Activity 2.0 9.3.7.15 (Symbol 16) */
colPending = true;
/*******************************************************************************/
/* Ensure that this collision still fits on the container */
if( colCnt < RFAL_NFCV_MAX_COLL_SUPPORTED )
{
/* Store this collision on the container to be resolved later */
/* Activity 2.0 9.3.7.15 (Symbol 16): add the collision information
* (MASK_VAL + SN) to the list containing the collision information */
ST_MEMCPY(colFound[colCnt].maskVal, colFound[colIt].maskVal, RFAL_NFCV_UID_LEN);
colPos = colFound[colIt].maskLen;
colFound[colCnt].maskVal[(colPos/RFAL_BITS_IN_BYTE)] &= (uint8_t)((1U << (colPos % RFAL_BITS_IN_BYTE)) - 1U);
colFound[colCnt].maskVal[(colPos/RFAL_BITS_IN_BYTE)] |= (uint8_t)((slotNum-1U) << (colPos % RFAL_BITS_IN_BYTE));
colFound[colCnt].maskVal[((colPos/RFAL_BITS_IN_BYTE)+1U)] = (uint8_t)((slotNum-1U) >> (RFAL_BITS_IN_BYTE - (colPos % RFAL_BITS_IN_BYTE)));
colFound[colCnt].maskLen = (colFound[colIt].maskLen + 4U);
colCnt++;
}
}
}
else
{
/* Timeout */
platformDelay(RFAL_NFCV_FDT_V_INVENT_NORES);
}
/* Check if devices found have reached device limit Activity 2.0 9.3.7.15 (Symbol 16) */
if( *devCnt >= devLimit )
{
return ERR_NONE;
}
} while( slotNum < RFAL_NFCV_MAX_SLOTS ); /* Slot loop */
colIt++;
} while( colIt < colCnt ); /* Collisions found loop */
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode rfalNfcvPollerSleepCollisionResolution( uint8_t devLimit, rfalNfcvListenDevice *nfcvDevList, uint8_t *devCnt )
{
uint8_t locDevCnt;
ReturnCode ret;
uint8_t i;
if( (nfcvDevList == NULL) || (devCnt == NULL) )
{
return ERR_PARAM;
}
*devCnt = 0;
do
{
locDevCnt = 0;
ret = rfalNfcvPollerCollisionResolution( RFAL_COMPLIANCE_MODE_ISO, (devLimit - *devCnt), &nfcvDevList[*devCnt], &locDevCnt );
for( i = *devCnt; i < (*devCnt + locDevCnt); i++ )
{
rfalNfcvPollerSleep( 0x00, nfcvDevList[i].InvRes.UID );
nfcvDevList[i].isSleep = true;
}
*devCnt += locDevCnt;
}
while( (locDevCnt > 0U) && (*devCnt < devLimit) );
return ret;
}
/*******************************************************************************/
ReturnCode rfalNfcvPollerSleep( uint8_t flags, const uint8_t* uid )
{
ReturnCode ret;
rfalNfcvSlpvReq slpReq;
uint8_t rxBuf; /* dummy buffer, just to perform Rx */
if( uid == NULL )
{
return ERR_PARAM;
}
/* Compute SLPV_REQ */
slpReq.REQ_FLAG = (flags | (uint8_t)RFAL_NFCV_REQ_FLAG_ADDRESS); /* Should be with UID according Digital 2.0 (Candidate) 9.7.1.1 */
slpReq.CMD = RFAL_NFCV_CMD_SLPV;
ST_MEMCPY( slpReq.UID, uid, RFAL_NFCV_UID_LEN );
/* NFC Forum device SHALL wait at least FDTVpp to consider the SLPV acknowledged (FDTVpp = FDTVpoll) Digital 2.0 (Candidate) 9.7 9.8.2 */
ret = rfalTransceiveBlockingTxRx( (uint8_t*)&slpReq, sizeof(rfalNfcvSlpvReq), &rxBuf, sizeof(rxBuf), NULL, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_NFCV_POLLER );
if( ret != ERR_TIMEOUT )
{
return ret;
}
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode rfalNfcvPollerSelect( uint8_t flags, const uint8_t* uid )
{
uint16_t rcvLen;
rfalNfcvGenericRes res;
if( uid == NULL )
{
return ERR_PARAM;
}
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_SELECT, flags, RFAL_NFCV_PARAM_SKIP, uid, NULL, 0U, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen );
}
/*******************************************************************************/
ReturnCode rfalNfcvPollerReadSingleBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen )
{
uint8_t bn;
bn = blockNum;
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_READ_SINGLE_BLOCK, flags, RFAL_NFCV_PARAM_SKIP, uid, &bn, sizeof(uint8_t), rxBuf, rxBufLen, rcvLen );
}
/*******************************************************************************/
ReturnCode rfalNfcvPollerWriteSingleBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum, const uint8_t* wrData, uint8_t blockLen )
{
uint8_t data[(RFAL_NFCV_BLOCKNUM_LEN + RFAL_NFCV_MAX_BLOCK_LEN)];
uint8_t dataLen;
uint16_t rcvLen;
rfalNfcvGenericRes res;
/* Check for valid parameters */
if( (blockLen == 0U) || (blockLen > (uint8_t)RFAL_NFCV_MAX_BLOCK_LEN) || (wrData == NULL) )
{
return ERR_PARAM;
}
dataLen = 0U;
/* Compute Request Data */
data[dataLen++] = blockNum; /* Set Block Number (8 bits) */
ST_MEMCPY( &data[dataLen], wrData, blockLen ); /* Append Block data to write */
dataLen += blockLen;
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_WRITE_SINGLE_BLOCK, flags, RFAL_NFCV_PARAM_SKIP, uid, data, dataLen, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen );
}
/*******************************************************************************/
ReturnCode rfalNfcvPollerLockBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum )
{
uint16_t rcvLen;
rfalNfcvGenericRes res;
uint8_t bn;
bn = blockNum;
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_LOCK_BLOCK, flags, RFAL_NFCV_PARAM_SKIP, uid, &bn, sizeof(uint8_t), (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen );
}
/*******************************************************************************/
ReturnCode rfalNfcvPollerReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint8_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen )
{
uint8_t data[(RFAL_NFCV_BLOCKNUM_LEN + RFAL_NFCV_BLOCKNUM_LEN)];
uint8_t dataLen;
dataLen = 0U;
/* Compute Request Data */
data[dataLen++] = firstBlockNum; /* Set first Block Number */
data[dataLen++] = numOfBlocks; /* Set number of blocks to read */
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_READ_MULTIPLE_BLOCKS, flags, RFAL_NFCV_PARAM_SKIP, uid, data, dataLen, rxBuf, rxBufLen, rcvLen );
}
/*******************************************************************************/
ReturnCode rfalNfcvPollerWriteMultipleBlocks( uint8_t flags, const uint8_t* uid, uint8_t firstBlockNum, uint8_t numOfBlocks, uint8_t *txBuf, uint16_t txBufLen, uint8_t blockLen, const uint8_t* wrData, uint16_t wrDataLen )
{
ReturnCode ret;
uint16_t rcvLen;
uint16_t reqLen;
rfalNfcvGenericRes res;
uint16_t msgIt;
/* Calculate required buffer length */
reqLen = (uint16_t)((uid != NULL) ? (RFAL_NFCV_WR_MUL_REQ_HEADER_LEN + RFAL_NFCV_UID_LEN + wrDataLen) : (RFAL_NFCV_WR_MUL_REQ_HEADER_LEN + wrDataLen));
if( (reqLen > txBufLen) || (blockLen > (uint8_t)RFAL_NFCV_MAX_BLOCK_LEN) || ((((uint16_t)numOfBlocks) * (uint16_t)blockLen) != wrDataLen) || (numOfBlocks == 0U) || (wrData == NULL) )
{
return ERR_PARAM;
}
msgIt = 0;
/* Compute Request Command */
txBuf[msgIt++] = (uint8_t)(flags & (~((uint32_t)RFAL_NFCV_REQ_FLAG_ADDRESS) & ~((uint32_t)RFAL_NFCV_REQ_FLAG_SELECT)));
txBuf[msgIt++] = RFAL_NFCV_CMD_WRITE_MULTIPLE_BLOCKS;
/* Check if Request is to be sent in Addressed or Selected mode */
if( uid != NULL )
{
txBuf[RFAL_NFCV_FLAG_POS] |= (uint8_t)RFAL_NFCV_REQ_FLAG_ADDRESS;
ST_MEMCPY( &txBuf[msgIt], uid, RFAL_NFCV_UID_LEN );
msgIt += (uint8_t)RFAL_NFCV_UID_LEN;
}
else
{
txBuf[RFAL_NFCV_FLAG_POS] |= (uint8_t)RFAL_NFCV_REQ_FLAG_SELECT;
}
txBuf[msgIt++] = firstBlockNum;
txBuf[msgIt++] = (numOfBlocks - 1U);
if( wrDataLen > 0U ) /* MISRA 21.18 */
{
ST_MEMCPY( &txBuf[msgIt], wrData, wrDataLen );
msgIt += wrDataLen;
}
/* Transceive Command */
ret = rfalTransceiveBlockingTxRx( txBuf, msgIt, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_MAX );
if( ret != ERR_NONE )
{
return ret;
}
/* Check if the response minimum length has been received */
if( rcvLen < (uint8_t)RFAL_NFCV_FLAG_LEN )
{
return ERR_PROTO;
}
/* Check if an error has been signalled */
if( (res.RES_FLAG & (uint8_t)RFAL_NFCV_RES_FLAG_ERROR) != 0U )
{
return rfalNfcvParseError( *res.data );
}
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode rfalNfcvPollerExtendedReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen )
{
uint8_t data[RFAL_NFCV_BLOCKNUM_EXTENDED_LEN];
uint8_t dataLen;
dataLen = 0U;
/* Compute Request Data */
data[dataLen++] = (uint8_t)blockNum; /* TS T5T 1.0 BNo is considered as a multi-byte field. TS T5T 1.0 5.1.1.13 multi-byte field follows [DIGITAL]. [DIGITAL] 9.3.1 A multiple byte field is transmitted LSB first. */
data[dataLen++] = (uint8_t)((blockNum >> 8U) & 0xFFU);
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_EXTENDED_READ_SINGLE_BLOCK, flags, RFAL_NFCV_PARAM_SKIP, uid, data, dataLen, rxBuf, rxBufLen, rcvLen );
}
/*******************************************************************************/
ReturnCode rfalNfcvPollerExtendedWriteSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, const uint8_t* wrData, uint8_t blockLen )
{
uint8_t data[(RFAL_NFCV_BLOCKNUM_EXTENDED_LEN + RFAL_NFCV_MAX_BLOCK_LEN)];
uint8_t dataLen;
uint16_t rcvLen;
rfalNfcvGenericRes res;
/* Check for valid parameters */
if( (blockLen == 0U) || (blockLen > (uint8_t)RFAL_NFCV_MAX_BLOCK_LEN) )
{
return ERR_PARAM;
}
dataLen = 0U;
/* Compute Request Data */
data[dataLen++] = (uint8_t)blockNum; /* TS T5T 1.0 BNo is considered as a multi-byte field. TS T5T 1.0 5.1.1.13 multi-byte field follows [DIGITAL]. [DIGITAL] 9.3.1 A multiple byte field is transmitted LSB first. */
data[dataLen++] = (uint8_t)((blockNum >> 8U) & 0xFFU);
ST_MEMCPY( &data[dataLen], wrData, blockLen ); /* Append Block data to write */
dataLen += blockLen;
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_EXTENDED_WRITE_SINGLE_BLOCK, flags, RFAL_NFCV_PARAM_SKIP, uid, data, dataLen, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen );
}
/*******************************************************************************/
ReturnCode rfalNfcvPollerExtendedLockSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum )
{
uint8_t data[RFAL_NFCV_BLOCKNUM_EXTENDED_LEN];
uint8_t dataLen;
uint16_t rcvLen;
rfalNfcvGenericRes res;
dataLen = 0U;
/* Compute Request Data */
data[dataLen++] = (uint8_t)blockNum; /* TS T5T 1.0 BNo is considered as a multi-byte field. TS T5T 1.0 5.1.1.13 multi-byte field follows [DIGITAL]. [DIGITAL] 9.3.1 A multiple byte field is transmitted LSB first. */
data[dataLen++] = (uint8_t)((blockNum >> 8U) & 0xFFU);
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_EXTENDED_LOCK_SINGLE_BLOCK, flags, RFAL_NFCV_PARAM_SKIP, uid, data, dataLen, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen );
}
/*******************************************************************************/
ReturnCode rfalNfcvPollerExtendedReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint16_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen )
{
uint8_t data[(RFAL_NFCV_BLOCKNUM_EXTENDED_LEN + RFAL_NFCV_BLOCKNUM_EXTENDED_LEN)];
uint8_t dataLen;
dataLen = 0U;
/* Compute Request Data */
data[dataLen++] = (uint8_t)((firstBlockNum >> 0U) & 0xFFU);
data[dataLen++] = (uint8_t)((firstBlockNum >> 8U) & 0xFFU);
data[dataLen++] = (uint8_t)((numOfBlocks >> 0U) & 0xFFU);
data[dataLen++] = (uint8_t)((numOfBlocks >> 8U) & 0xFFU);
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_EXTENDED_READ_MULTIPLE_BLOCK, flags, RFAL_NFCV_PARAM_SKIP, uid, data, dataLen, rxBuf, rxBufLen, rcvLen );
}
/*******************************************************************************/
ReturnCode rfalNfcvPollerExtendedWriteMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint16_t numOfBlocks, uint8_t *txBuf, uint16_t txBufLen, uint8_t blockLen, const uint8_t* wrData, uint16_t wrDataLen )
{
ReturnCode ret;
uint16_t rcvLen;
uint16_t reqLen;
rfalNfcvGenericRes res;
uint16_t msgIt;
uint16_t nBlocks;
/* Calculate required buffer length */
reqLen = ((uid != NULL) ? (RFAL_NFCV_WR_MUL_REQ_HEADER_LEN + RFAL_NFCV_UID_LEN + wrDataLen) : (RFAL_NFCV_WR_MUL_REQ_HEADER_LEN + wrDataLen) );
if( (reqLen > txBufLen) || (blockLen > (uint8_t)RFAL_NFCV_MAX_BLOCK_LEN) || (( (uint16_t)numOfBlocks * (uint16_t)blockLen) != wrDataLen) || (numOfBlocks == 0U) )
{
return ERR_PARAM;
}
msgIt = 0;
nBlocks = (numOfBlocks - 1U);
/* Compute Request Command */
txBuf[msgIt++] = (uint8_t)(flags & (~((uint32_t)RFAL_NFCV_REQ_FLAG_ADDRESS) & ~((uint32_t)RFAL_NFCV_REQ_FLAG_SELECT)));
txBuf[msgIt++] = RFAL_NFCV_CMD_EXTENDED_WRITE_MULTIPLE_BLOCK;
/* Check if Request is to be sent in Addressed or Selected mode */
if( uid != NULL )
{
txBuf[RFAL_NFCV_FLAG_POS] |= (uint8_t)RFAL_NFCV_REQ_FLAG_ADDRESS;
ST_MEMCPY( &txBuf[msgIt], uid, RFAL_NFCV_UID_LEN );
msgIt += (uint8_t)RFAL_NFCV_UID_LEN;
}
else
{
txBuf[RFAL_NFCV_FLAG_POS] |= (uint8_t)RFAL_NFCV_REQ_FLAG_SELECT;
}
txBuf[msgIt++] = (uint8_t)((firstBlockNum >> 0) & 0xFFU);
txBuf[msgIt++] = (uint8_t)((firstBlockNum >> 8) & 0xFFU);
txBuf[msgIt++] = (uint8_t)((nBlocks >> 0) & 0xFFU);
txBuf[msgIt++] = (uint8_t)((nBlocks >> 8) & 0xFFU);
if( wrDataLen > 0U ) /* MISRA 21.18 */
{
ST_MEMCPY( &txBuf[msgIt], wrData, wrDataLen );
msgIt += wrDataLen;
}
/* Transceive Command */
ret = rfalTransceiveBlockingTxRx( txBuf, msgIt, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_MAX );
if( ret != ERR_NONE )
{
return ret;
}
/* Check if the response minimum length has been received */
if( rcvLen < (uint8_t)RFAL_NFCV_FLAG_LEN )
{
return ERR_PROTO;
}
/* Check if an error has been signalled */
if( (res.RES_FLAG & (uint8_t)RFAL_NFCV_RES_FLAG_ERROR) != 0U )
{
return rfalNfcvParseError( *res.data );
}
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode rfalNfcvPollerGetSystemInformation( uint8_t flags, const uint8_t* uid, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen )
{
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_GET_SYS_INFO, flags, RFAL_NFCV_PARAM_SKIP, uid, NULL, 0U, rxBuf, rxBufLen, rcvLen );
}
/*******************************************************************************/
ReturnCode rfalNfcvPollerExtendedGetSystemInformation( uint8_t flags, const uint8_t* uid, uint8_t requestField, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen )
{
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_EXTENDED_GET_SYS_INFO, flags, requestField, uid, NULL, 0U, rxBuf, rxBufLen, rcvLen );
}
/*******************************************************************************/
ReturnCode rfalNfcvPollerTransceiveReq( uint8_t cmd, uint8_t flags, uint8_t param, const uint8_t* uid, const uint8_t *data, uint16_t dataLen, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen )
{
ReturnCode ret;
rfalNfcvGenericReq req;
uint8_t msgIt;
rfalBitRate rxBR;
bool fastMode;
msgIt = 0;
fastMode = false;
/* Check for valid parameters */
if( (rxBuf == NULL) || (rcvLen == NULL) || ((dataLen > 0U) && (data == NULL)) ||
(dataLen > ((uid != NULL) ? RFAL_NFCV_MAX_GEN_DATA_LEN : (RFAL_NFCV_MAX_GEN_DATA_LEN - RFAL_NFCV_UID_LEN))) )
{
return ERR_PARAM;
}
/* Check if the command is an ST's Fast command */
if( (cmd == (uint8_t)RFAL_NFCV_CMD_FAST_READ_SINGLE_BLOCK) || (cmd == (uint8_t)RFAL_NFCV_CMD_FAST_EXTENDED_READ_SINGLE_BLOCK) ||
(cmd == (uint8_t)RFAL_NFCV_CMD_FAST_READ_MULTIPLE_BLOCKS) || (cmd == (uint8_t)RFAL_NFCV_CMD_FAST_EXTENDED_READ_MULTIPLE_BLOCKS) ||
(cmd == (uint8_t)RFAL_NFCV_CMD_FAST_WRITE_MESSAGE) || (cmd == (uint8_t)RFAL_NFCV_CMD_FAST_READ_MESSAGE_LENGTH) ||
(cmd == (uint8_t)RFAL_NFCV_CMD_FAST_READ_MESSAGE) || (cmd == (uint8_t)RFAL_NFCV_CMD_FAST_READ_DYN_CONFIGURATION) ||
(cmd == (uint8_t)RFAL_NFCV_CMD_FAST_WRITE_DYN_CONFIGURATION) )
{
/* Store current Rx bit rate and move to fast mode */
rfalGetBitRate( NULL, &rxBR );
rfalSetBitRate( RFAL_BR_KEEP, RFAL_BR_52p97 );
fastMode = true;
}
/* Compute Request Command */
req.REQ_FLAG = (uint8_t)(flags & (~((uint32_t)RFAL_NFCV_REQ_FLAG_ADDRESS) & ~((uint32_t)RFAL_NFCV_REQ_FLAG_SELECT)));
req.CMD = cmd;
/* Prepend parameter on ceratin proprietary requests: IC Manuf, Parameters */
if( param != RFAL_NFCV_PARAM_SKIP )
{
req.payload.data[msgIt++] = param;
}
/* Check if request is to be sent in Addressed or Selected mode */
if( uid != NULL )
{
req.REQ_FLAG |= (uint8_t)RFAL_NFCV_REQ_FLAG_ADDRESS;
ST_MEMCPY( &req.payload.data[msgIt], uid, RFAL_NFCV_UID_LEN );
msgIt += RFAL_NFCV_UID_LEN;
}
else
{
req.REQ_FLAG |= (uint8_t)RFAL_NFCV_REQ_FLAG_SELECT;
}
if( dataLen > 0U )
{
ST_MEMCPY( &req.payload.data[msgIt], data, dataLen);
msgIt += (uint8_t)dataLen;
}
/* Transceive Command */
ret = rfalTransceiveBlockingTxRx( (uint8_t*)&req, (RFAL_CMD_LEN + RFAL_NFCV_FLAG_LEN +(uint16_t)msgIt), rxBuf, rxBufLen, rcvLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_MAX );
/* If the Option Flag is set in certain commands an EOF needs to be sent after 20ms to retrieve the VICC response ISO15693-3 2009 10.4.2 & 10.4.3 & 10.4.5 */
if( ((flags & (uint8_t)RFAL_NFCV_REQ_FLAG_OPTION) != 0U) && ((cmd == (uint8_t)RFAL_NFCV_CMD_WRITE_SINGLE_BLOCK) || (cmd == (uint8_t)RFAL_NFCV_CMD_WRITE_MULTIPLE_BLOCKS) ||
(cmd == (uint8_t)RFAL_NFCV_CMD_LOCK_BLOCK) || (cmd == (uint8_t)RFAL_NFCV_CMD_EXTENDED_WRITE_SINGLE_BLOCK) ||
(cmd == (uint8_t)RFAL_NFCV_CMD_EXTENDED_LOCK_SINGLE_BLOCK) || (cmd == (uint8_t)RFAL_NFCV_CMD_EXTENDED_WRITE_MULTIPLE_BLOCK)) )
{
ret = rfalISO15693TransceiveEOF( rxBuf, (uint8_t)rxBufLen, rcvLen );
}
/* Restore Rx BitRate */
if( fastMode )
{
rfalSetBitRate( RFAL_BR_KEEP, rxBR );
}
if( ret != ERR_NONE )
{
return ret;
}
/* Check if the response minimum length has been received */
if( (*rcvLen) < (uint8_t)RFAL_NFCV_FLAG_LEN )
{
return ERR_PROTO;
}
/* Check if an error has been signalled */
if( (rxBuf[RFAL_NFCV_FLAG_POS] & (uint8_t)RFAL_NFCV_RES_FLAG_ERROR) != 0U )
{
return rfalNfcvParseError( rxBuf[RFAL_NFCV_DATASTART_POS] );
}
return ERR_NONE;
}
#endif /* RFAL_FEATURE_NFCV */

File diff suppressed because it is too large Load Diff

View File

@ -1,551 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_st25tb.c
*
* \author Gustavo Patricio
*
* \brief Implementation of ST25TB interface
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "rfal_st25tb.h"
#include "utils.h"
/*
******************************************************************************
* ENABLE SWITCH
******************************************************************************
*/
#ifndef RFAL_FEATURE_ST25TB
#define RFAL_FEATURE_ST25TB false /* ST25TB module configuration missing. Disabled by default */
#endif
#if RFAL_FEATURE_ST25TB
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_ST25TB_CMD_LEN 1U /*!< ST25TB length of a command */
#define RFAL_ST25TB_SLOTS 16U /*!< ST25TB number of slots */
#define RFAL_ST25TB_SLOTNUM_MASK 0x0FU /*!< ST25TB Slot Number bit mask on SlotMarker */
#define RFAL_ST25TB_SLOTNUM_SHIFT 4U /*!< ST25TB Slot Number shift on SlotMarker */
#define RFAL_ST25TB_INITIATE_CMD1 0x06U /*!< ST25TB Initiate command byte1 */
#define RFAL_ST25TB_INITIATE_CMD2 0x00U /*!< ST25TB Initiate command byte2 */
#define RFAL_ST25TB_PCALL_CMD1 0x06U /*!< ST25TB Pcall16 command byte1 */
#define RFAL_ST25TB_PCALL_CMD2 0x04U /*!< ST25TB Pcall16 command byte2 */
#define RFAL_ST25TB_SELECT_CMD 0x0EU /*!< ST25TB Select command */
#define RFAL_ST25TB_GET_UID_CMD 0x0BU /*!< ST25TB Get UID command */
#define RFAL_ST25TB_COMPLETION_CMD 0x0FU /*!< ST25TB Completion command */
#define RFAL_ST25TB_RESET_INV_CMD 0x0CU /*!< ST25TB Reset to Inventory command */
#define RFAL_ST25TB_READ_BLOCK_CMD 0x08U /*!< ST25TB Read Block command */
#define RFAL_ST25TB_WRITE_BLOCK_CMD 0x09U /*!< ST25TB Write Block command */
#define RFAL_ST25TB_T0 2157U /*!< ST25TB t0 159 us ST25TB RF characteristics */
#define RFAL_ST25TB_T1 2048U /*!< ST25TB t1 151 us ST25TB RF characteristics */
#define RFAL_ST25TB_FWT (RFAL_ST25TB_T0 + RFAL_ST25TB_T1) /*!< ST25TB FWT = T0 + T1 */
#define RFAL_ST25TB_TW rfalConvMsTo1fc(7U) /*!< ST25TB TW : Programming time for write max 7ms */
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
/*
******************************************************************************
* GLOBAL TYPES
******************************************************************************
*/
/*! Initiate Request */
typedef struct
{
uint8_t cmd1; /*!< Initiate Request cmd1: 0x06 */
uint8_t cmd2; /*!< Initiate Request cmd2: 0x00 */
} rfalSt25tbInitiateReq;
/*! Pcall16 Request */
typedef struct
{
uint8_t cmd1; /*!< Pcal16 Request cmd1: 0x06 */
uint8_t cmd2; /*!< Pcal16 Request cmd2: 0x04 */
} rfalSt25tbPcallReq;
/*! Select Request */
typedef struct
{
uint8_t cmd; /*!< Select Request cmd: 0x0E */
uint8_t chipId; /*!< Chip ID */
} rfalSt25tbSelectReq;
/*! Read Block Request */
typedef struct
{
uint8_t cmd; /*!< Select Request cmd: 0x08 */
uint8_t address; /*!< Block address */
} rfalSt25tbReadBlockReq;
/*! Write Block Request */
typedef struct
{
uint8_t cmd; /*!< Select Request cmd: 0x09 */
uint8_t address; /*!< Block address */
rfalSt25tbBlock data; /*!< Block Data */
} rfalSt25tbWriteBlockReq;
/*
******************************************************************************
* LOCAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief ST25TB Poller Do Collision Resolution
*
* This method performs ST25TB Collision resolution loop for each slot
*
* \param[in] devLimit : device limit value, and size st25tbDevList
* \param[out] st25tbDevList : ST35TB listener device info
* \param[out] devCnt : Devices found counter
*
* \return colPending : true if a collision was detected
*****************************************************************************
*/
static bool rfalSt25tbPollerDoCollisionResolution( uint8_t devLimit, rfalSt25tbListenDevice *st25tbDevList, uint8_t *devCnt );
/*
******************************************************************************
* LOCAL FUNCTION PROTOTYPES
******************************************************************************
*/
static bool rfalSt25tbPollerDoCollisionResolution( uint8_t devLimit, rfalSt25tbListenDevice *st25tbDevList, uint8_t *devCnt )
{
uint8_t i;
uint8_t chipId;
ReturnCode ret;
bool col;
col = false;
for(i = 0; i < RFAL_ST25TB_SLOTS; i++)
{
platformDelay(1); /* Wait t2: Answer to new request delay */
if( i==0U )
{
/* Step 2: Send Pcall16 */
ret = rfalSt25tbPollerPcall( &chipId );
}
else
{
/* Step 3-17: Send Pcall16 */
ret = rfalSt25tbPollerSlotMarker( i, &chipId );
}
if( ret == ERR_NONE )
{
/* Found another device */
st25tbDevList[*devCnt].chipID = chipId;
st25tbDevList[*devCnt].isDeselected = false;
/* Select Device, retrieve its UID */
ret = rfalSt25tbPollerSelect( chipId );
/* By Selecting this device, the previous gets Deselected */
if( (*devCnt) > 0U )
{
st25tbDevList[(*devCnt)-1U].isDeselected = true;
}
if( ERR_NONE == ret )
{
rfalSt25tbPollerGetUID( &st25tbDevList[*devCnt].UID );
}
if( ERR_NONE == ret )
{
(*devCnt)++;
}
}
else if( (ret == ERR_CRC) || (ret == ERR_FRAMING) )
{
col = true;
}
else
{
/* MISRA 15.7 - Empty else */
}
if( *devCnt >= devLimit )
{
break;
}
}
return col;
}
/*
******************************************************************************
* LOCAL VARIABLES
******************************************************************************
*/
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
/*******************************************************************************/
ReturnCode rfalSt25tbPollerInitialize( void )
{
return rfalNfcbPollerInitialize();
}
/*******************************************************************************/
ReturnCode rfalSt25tbPollerCheckPresence( uint8_t *chipId )
{
ReturnCode ret;
uint8_t chipIdRes;
chipIdRes = 0x00;
/* Send Initiate Request */
ret = rfalSt25tbPollerInitiate( &chipIdRes );
/* Check if a transmission error was detected */
if( (ret == ERR_CRC) || (ret == ERR_FRAMING) )
{
return ERR_NONE;
}
/* Copy chip ID if requested */
if( chipId != NULL )
{
*chipId = chipIdRes;
}
return ret;
}
/*******************************************************************************/
ReturnCode rfalSt25tbPollerInitiate( uint8_t *chipId )
{
ReturnCode ret;
uint16_t rxLen;
rfalSt25tbInitiateReq initiateReq;
uint8_t rxBuf[RFAL_ST25TB_CHIP_ID_LEN + RFAL_ST25TB_CRC_LEN]; /* In case we receive less data that CRC, RF layer will not remove the CRC from buffer */
/* Compute Initiate Request */
initiateReq.cmd1 = RFAL_ST25TB_INITIATE_CMD1;
initiateReq.cmd2 = RFAL_ST25TB_INITIATE_CMD2;
/* Send Initiate Request */
ret = rfalTransceiveBlockingTxRx( (uint8_t*)&initiateReq, sizeof(rfalSt25tbInitiateReq), (uint8_t*)rxBuf, sizeof(rxBuf), &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_ST25TB_FWT );
/* Check for valid Select Response */
if( (ret == ERR_NONE) && (rxLen != RFAL_ST25TB_CHIP_ID_LEN) )
{
return ERR_PROTO;
}
/* Copy chip ID if requested */
if( chipId != NULL )
{
*chipId = *rxBuf;
}
return ret;
}
/*******************************************************************************/
ReturnCode rfalSt25tbPollerPcall( uint8_t *chipId )
{
ReturnCode ret;
uint16_t rxLen;
rfalSt25tbPcallReq pcallReq;
/* Compute Pcal16 Request */
pcallReq.cmd1 = RFAL_ST25TB_PCALL_CMD1;
pcallReq.cmd2 = RFAL_ST25TB_PCALL_CMD2;
/* Send Pcal16 Request */
ret = rfalTransceiveBlockingTxRx( (uint8_t*)&pcallReq, sizeof(rfalSt25tbPcallReq), (uint8_t*)chipId, RFAL_ST25TB_CHIP_ID_LEN, &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_ST25TB_FWT );
/* Check for valid Select Response */
if( (ret == ERR_NONE) && (rxLen != RFAL_ST25TB_CHIP_ID_LEN) )
{
return ERR_PROTO;
}
return ret;
}
/*******************************************************************************/
ReturnCode rfalSt25tbPollerSlotMarker( uint8_t slotNum, uint8_t *chipIdRes )
{
ReturnCode ret;
uint16_t rxLen;
uint8_t slotMarker;
if( (slotNum == 0U) || (slotNum > 15U) )
{
return ERR_PARAM;
}
/* Compute SlotMarker */
slotMarker = ( ((slotNum & RFAL_ST25TB_SLOTNUM_MASK) << RFAL_ST25TB_SLOTNUM_SHIFT) | RFAL_ST25TB_PCALL_CMD1 );
/* Send SlotMarker */
ret = rfalTransceiveBlockingTxRx( (uint8_t*)&slotMarker, RFAL_ST25TB_CMD_LEN, (uint8_t*)chipIdRes, RFAL_ST25TB_CHIP_ID_LEN, &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_ST25TB_FWT );
/* Check for valid ChipID Response */
if( (ret == ERR_NONE) && (rxLen != RFAL_ST25TB_CHIP_ID_LEN) )
{
return ERR_PROTO;
}
return ret;
}
/*******************************************************************************/
ReturnCode rfalSt25tbPollerSelect( uint8_t chipId )
{
ReturnCode ret;
uint16_t rxLen;
rfalSt25tbSelectReq selectReq;
uint8_t chipIdRes;
/* Compute Select Request */
selectReq.cmd = RFAL_ST25TB_SELECT_CMD;
selectReq.chipId = chipId;
/* Send Select Request */
ret = rfalTransceiveBlockingTxRx( (uint8_t*)&selectReq, sizeof(rfalSt25tbSelectReq), (uint8_t*)&chipIdRes, RFAL_ST25TB_CHIP_ID_LEN, &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_ST25TB_FWT );
/* Check for valid Select Response */
if( (ret == ERR_NONE) && ((rxLen != RFAL_ST25TB_CHIP_ID_LEN) || (chipIdRes != chipId)) )
{
return ERR_PROTO;
}
return ret;
}
/*******************************************************************************/
ReturnCode rfalSt25tbPollerGetUID( rfalSt25tbUID *UID )
{
ReturnCode ret;
uint16_t rxLen;
uint8_t getUidReq;
/* Compute Get UID Request */
getUidReq = RFAL_ST25TB_GET_UID_CMD;
/* Send Select Request */
ret = rfalTransceiveBlockingTxRx( (uint8_t*)&getUidReq, RFAL_ST25TB_CMD_LEN, (uint8_t*)UID, sizeof(rfalSt25tbUID), &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_ST25TB_FWT );
/* Check for valid UID Response */
if( (ret == ERR_NONE) && (rxLen != RFAL_ST25TB_UID_LEN) )
{
return ERR_PROTO;
}
return ret;
}
/*******************************************************************************/
ReturnCode rfalSt25tbPollerCollisionResolution( uint8_t devLimit, rfalSt25tbListenDevice *st25tbDevList, uint8_t *devCnt )
{
uint8_t chipId;
ReturnCode ret;
bool detected; /* collision or device was detected */
if( (st25tbDevList == NULL) || (devCnt == NULL) || (devLimit == 0U) )
{
return ERR_PARAM;
}
*devCnt = 0;
/* Step 1: Send Initiate */
ret = rfalSt25tbPollerInitiate( &chipId );
if( ret == ERR_NONE )
{
/* If only 1 answer is detected */
st25tbDevList[*devCnt].chipID = chipId;
st25tbDevList[*devCnt].isDeselected = false;
/* Retrieve its UID and keep it Selected*/
ret = rfalSt25tbPollerSelect( chipId );
if( ERR_NONE == ret )
{
ret = rfalSt25tbPollerGetUID( &st25tbDevList[*devCnt].UID );
}
if( ERR_NONE == ret )
{
(*devCnt)++;
}
}
/* Always proceed to Pcall16 anticollision as phase differences of tags can lead to no tag recognized, even if there is one */
if( *devCnt < devLimit )
{
/* Multiple device responses */
do
{
detected = rfalSt25tbPollerDoCollisionResolution( devLimit, st25tbDevList, devCnt );
}
while( (detected == true) && (*devCnt < devLimit) );
}
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode rfalSt25tbPollerReadBlock( uint8_t blockAddress, rfalSt25tbBlock *blockData )
{
ReturnCode ret;
uint16_t rxLen;
rfalSt25tbReadBlockReq readBlockReq;
/* Compute Read Block Request */
readBlockReq.cmd = RFAL_ST25TB_READ_BLOCK_CMD;
readBlockReq.address = blockAddress;
/* Send Read Block Request */
ret = rfalTransceiveBlockingTxRx( (uint8_t*)&readBlockReq, sizeof(rfalSt25tbReadBlockReq), (uint8_t*)blockData, sizeof(rfalSt25tbBlock), &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_ST25TB_FWT );
/* Check for valid UID Response */
if( (ret == ERR_NONE) && (rxLen != RFAL_ST25TB_BLOCK_LEN) )
{
return ERR_PROTO;
}
return ret;
}
/*******************************************************************************/
ReturnCode rfalSt25tbPollerWriteBlock( uint8_t blockAddress, const rfalSt25tbBlock *blockData )
{
ReturnCode ret;
uint16_t rxLen;
rfalSt25tbWriteBlockReq writeBlockReq;
rfalSt25tbBlock tmpBlockData;
/* Compute Write Block Request */
writeBlockReq.cmd = RFAL_ST25TB_WRITE_BLOCK_CMD;
writeBlockReq.address = blockAddress;
ST_MEMCPY( &writeBlockReq.data, blockData, RFAL_ST25TB_BLOCK_LEN );
/* Send Write Block Request */
ret = rfalTransceiveBlockingTxRx( (uint8_t*)&writeBlockReq, sizeof(rfalSt25tbWriteBlockReq), tmpBlockData, RFAL_ST25TB_BLOCK_LEN, &rxLen, RFAL_TXRX_FLAGS_DEFAULT, (RFAL_ST25TB_FWT + RFAL_ST25TB_TW) );
/* Check if an unexpected answer was received */
if( ret == ERR_NONE )
{
return ERR_PROTO;
}
/* Check there was any error besides Timeout*/
if( ret != ERR_TIMEOUT )
{
return ret;
}
ret = rfalSt25tbPollerReadBlock(blockAddress, &tmpBlockData);
if( ret == ERR_NONE )
{
if( ST_BYTECMP( &tmpBlockData, blockData, RFAL_ST25TB_BLOCK_LEN ) == 0 )
{
return ERR_NONE;
}
return ERR_PROTO;
}
return ret;
}
/*******************************************************************************/
ReturnCode rfalSt25tbPollerCompletion( void )
{
uint8_t completionReq;
/* Compute Completion Request */
completionReq = RFAL_ST25TB_COMPLETION_CMD;
/* Send Completion Request, no response is expected */
return rfalTransceiveBlockingTxRx( (uint8_t*)&completionReq, RFAL_ST25TB_CMD_LEN, NULL, 0, NULL, RFAL_TXRX_FLAGS_DEFAULT, RFAL_ST25TB_FWT );
}
/*******************************************************************************/
ReturnCode rfalSt25tbPollerResetToInventory( void )
{
uint8_t resetInvReq;
/* Compute Completion Request */
resetInvReq = RFAL_ST25TB_RESET_INV_CMD;
/* Send Completion Request, no response is expected */
return rfalTransceiveBlockingTxRx( (uint8_t*)&resetInvReq, RFAL_ST25TB_CMD_LEN, NULL, 0, NULL, RFAL_TXRX_FLAGS_DEFAULT, RFAL_ST25TB_FWT );
}
#endif /* RFAL_FEATURE_ST25TB */

View File

@ -1,528 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_st25xv.c
*
* \author Gustavo Patricio
*
* \brief NFC-V ST25 NFC-V Tag specific features
*
* This module provides support for ST's specific features available on
* NFC-V (ISO15693) tag families: ST25D, ST25TV, M24LR
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "rfal_st25xv.h"
#include "rfal_nfcv.h"
#include "utils.h"
/*
******************************************************************************
* ENABLE SWITCH
******************************************************************************
*/
#ifndef RFAL_FEATURE_ST25xV
#define RFAL_FEATURE_ST25xV false /* ST25xV module configuration missing. Disabled by default */
#endif
#if RFAL_FEATURE_ST25xV
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_ST25xV_READ_CONFIG_LEN 2U /*!< READ CONFIGURATION length */
#define RFAL_ST25xV_READ_MSG_LEN_LEN 2U /*!< READ MESSAGE LENGTH length */
#define RFAL_ST25xV_CONF_POINTER_LEN 1U /*!< READ/WRITE CONFIGURATION Pointer length */
#define RFAL_ST25xV_CONF_REGISTER_LEN 1U /*!< READ/WRITE CONFIGURATION Register length */
#define RFAL_ST25xV_PWDNUM_LEN 1U /*!< Password Number length */
#define RFAL_ST25xV_PWD_LEN 8U /*!< Password length */
#define RFAL_ST25xV_MBPOINTER_LEN 1U /*!< Read Message MBPointer length */
#define RFAL_ST25xV_NUMBYTES_LEN 1U /*!< Read Message Number of Bytes length */
#define RFAL_ST25TV02K_TBOOT_RF 1U /*!< RF Boot time (Minimum time from carrier generation to first data) */
#define RFAL_ST25TV02K_TRF_OFF 2U /*!< RF OFF time */
#define RFAL_FDT_POLL_MAX rfalConvMsTo1fc(20) /*!< Maximum Wait time FDTV,EOF 20 ms Digital 2.0 B.5 */
#define RFAL_NFCV_FLAG_POS 0U /*!< Flag byte position */
#define RFAL_NFCV_FLAG_LEN 1U /*!< Flag byte length */
/*
******************************************************************************
* LOCAL FUNCTION PROTOTYPES
******************************************************************************
*/
static ReturnCode rfalST25xVPollerGenericReadConfiguration(uint8_t cmd, uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue );
static ReturnCode rfalST25xVPollerGenericWriteConfiguration( uint8_t cmd, uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue );
static ReturnCode rfalST25xVPollerGenericReadMessageLength( uint8_t cmd, uint8_t flags, const uint8_t* uid, uint8_t* msgLen );
static ReturnCode rfalST25xVPollerGenericReadMessage( uint8_t cmd, uint8_t flags, const uint8_t* uid, uint8_t mbPointer, uint8_t numBytes, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen );
static ReturnCode rfalST25xVPollerGenericWriteMessage( uint8_t cmd, uint8_t flags, const uint8_t* uid, uint8_t msgLen, const uint8_t* msgData, uint8_t* txBuf, uint16_t txBufLen );
/*
******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************
*/
/*******************************************************************************/
static ReturnCode rfalST25xVPollerGenericReadConfiguration(uint8_t cmd, uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue )
{
ReturnCode ret;
uint8_t p;
uint16_t rcvLen;
rfalNfcvGenericRes res;
if( regValue == NULL )
{
return ERR_PARAM;
}
p = pointer;
ret = rfalNfcvPollerTransceiveReq( cmd, flags, RFAL_NFCV_ST_IC_MFG_CODE, uid, &p, sizeof(uint8_t), (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen );
if( ret == ERR_NONE )
{
if( rcvLen < RFAL_ST25xV_READ_CONFIG_LEN )
{
ret = ERR_PROTO;
}
else
{
*regValue = res.data[0];
}
}
return ret;
}
/*******************************************************************************/
static ReturnCode rfalST25xVPollerGenericWriteConfiguration( uint8_t cmd, uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue )
{
uint8_t data[RFAL_ST25xV_CONF_POINTER_LEN + RFAL_ST25xV_CONF_REGISTER_LEN];
uint8_t dataLen;
uint16_t rcvLen;
rfalNfcvGenericRes res;
dataLen = 0U;
data[dataLen++] = pointer;
data[dataLen++] = regValue;
return rfalNfcvPollerTransceiveReq( cmd, flags, RFAL_NFCV_ST_IC_MFG_CODE, uid, data, dataLen, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen );
}
/*******************************************************************************/
static ReturnCode rfalST25xVPollerGenericReadMessageLength( uint8_t cmd, uint8_t flags, const uint8_t* uid, uint8_t* msgLen )
{
ReturnCode ret;
uint16_t rcvLen;
rfalNfcvGenericRes res;
if( msgLen == NULL )
{
return ERR_PARAM;
}
ret = rfalNfcvPollerTransceiveReq( cmd, flags, RFAL_NFCV_ST_IC_MFG_CODE, uid, NULL, 0, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen );
if( ret == ERR_NONE )
{
if( rcvLen < RFAL_ST25xV_READ_MSG_LEN_LEN )
{
ret = ERR_PROTO;
}
else
{
*msgLen = res.data[0];
}
}
return ret;
}
/*******************************************************************************/
static ReturnCode rfalST25xVPollerGenericReadMessage( uint8_t cmd, uint8_t flags, const uint8_t* uid, uint8_t mbPointer, uint8_t numBytes, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen )
{
uint8_t data[RFAL_ST25xV_MBPOINTER_LEN + RFAL_ST25xV_NUMBYTES_LEN];
uint8_t dataLen;
dataLen = 0;
/* Compute Request Data */
data[dataLen++] = mbPointer;
data[dataLen++] = numBytes;
return rfalNfcvPollerTransceiveReq( cmd, flags, RFAL_NFCV_ST_IC_MFG_CODE, uid, data, dataLen, rxBuf, rxBufLen, rcvLen );
}
/*******************************************************************************/
static ReturnCode rfalST25xVPollerGenericWriteMessage( uint8_t cmd, uint8_t flags, const uint8_t* uid, uint8_t msgLen, const uint8_t* msgData, uint8_t* txBuf, uint16_t txBufLen )
{
ReturnCode ret;
uint8_t reqFlag;
uint16_t msgIt;
rfalBitRate rxBR;
bool fastMode;
rfalNfcvGenericRes res;
uint16_t rcvLen;
/* Calculate required Tx buf length: Mfg Code UID MSGLen MSGLen+1 */
msgIt = (uint16_t)( msgLen + sizeof(flags) + sizeof(cmd) + 1U + ((uid != NULL) ? RFAL_NFCV_UID_LEN : 0U) + 1U + 1U );
/* Check for valid parameters */
if( (txBuf == NULL) || (msgData == NULL) || (msgLen == 0U) || (msgLen == 0xFFU) || (txBufLen < msgIt) )
{
return ERR_PARAM;
}
msgIt = 0;
fastMode = false;
/* Check if the command is an ST's Fast command */
if( cmd == (uint8_t)RFAL_NFCV_CMD_FAST_WRITE_MESSAGE )
{
/* Store current Rx bit rate and move to fast mode */
rfalGetBitRate( NULL, &rxBR );
rfalSetBitRate( RFAL_BR_KEEP, RFAL_BR_52p97 );
fastMode = true;
}
/* Compute Request Command */
reqFlag = (uint8_t)(flags & (~((uint32_t)RFAL_NFCV_REQ_FLAG_ADDRESS) & ~((uint32_t)RFAL_NFCV_REQ_FLAG_SELECT)));
reqFlag |= (( uid != NULL ) ? (uint8_t)RFAL_NFCV_REQ_FLAG_ADDRESS : (uint8_t)RFAL_NFCV_REQ_FLAG_SELECT);
txBuf[msgIt++] = reqFlag;
txBuf[msgIt++] = cmd;
txBuf[msgIt++] = RFAL_NFCV_ST_IC_MFG_CODE;
if( uid != NULL )
{
ST_MEMCPY( &txBuf[msgIt], uid, RFAL_NFCV_UID_LEN );
msgIt += RFAL_NFCV_UID_LEN;
}
txBuf[msgIt++] = msgLen;
ST_MEMCPY( &txBuf[msgIt], msgData, (uint8_t)(msgLen + 1U) ); /* Message Data contains (MSGLength + 1) bytes */
msgIt += (uint8_t)(msgLen + 1U);
/* Transceive Command */
ret = rfalTransceiveBlockingTxRx( txBuf, msgIt, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_MAX );
/* Restore Rx BitRate */
if( fastMode )
{
rfalSetBitRate( RFAL_BR_KEEP, rxBR );
}
if( ret != ERR_NONE )
{
return ret;
}
/* Check if the response minimum length has been received */
if( rcvLen < (uint8_t)RFAL_NFCV_FLAG_LEN )
{
return ERR_PROTO;
}
/* Check if an error has been signalled */
if( (res.RES_FLAG & (uint8_t)RFAL_NFCV_RES_FLAG_ERROR) != 0U )
{
return ERR_PROTO;
}
return ERR_NONE;
}
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
/*******************************************************************************/
ReturnCode rfalST25xVPollerM24LRReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen )
{
uint8_t data[RFAL_NFCV_BLOCKNUM_M24LR_LEN];
uint8_t dataLen;
dataLen = 0;
/* Compute Request Data */
data[dataLen++] = (uint8_t)blockNum; /* Set M24LR Block Number (16 bits) LSB */
data[dataLen++] = (uint8_t)(blockNum >> 8U); /* Set M24LR Block Number (16 bits) MSB */
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_READ_SINGLE_BLOCK, (flags | (uint8_t)RFAL_NFCV_REQ_FLAG_PROTOCOL_EXT), RFAL_NFCV_PARAM_SKIP, uid, data, dataLen, rxBuf, rxBufLen, rcvLen );
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerM24LRWriteSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, const uint8_t* wrData, uint8_t blockLen )
{
uint8_t data[(RFAL_NFCV_BLOCKNUM_M24LR_LEN + RFAL_NFCV_MAX_BLOCK_LEN)];
uint8_t dataLen;
uint16_t rcvLen;
rfalNfcvGenericRes res;
/* Check for valid parameters */
if( (blockLen == 0U) || (blockLen > (uint8_t)RFAL_NFCV_MAX_BLOCK_LEN) || (wrData == NULL) )
{
return ERR_PARAM;
}
dataLen = 0U;
/* Compute Request Data */
data[dataLen++] = (uint8_t)blockNum; /* Set M24LR Block Number (16 bits) LSB */
data[dataLen++] = (uint8_t)(blockNum >> 8U); /* Set M24LR Block Number (16 bits) MSB */
ST_MEMCPY( &data[dataLen], wrData, blockLen ); /* Append Block data to write */
dataLen += blockLen;
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_WRITE_SINGLE_BLOCK, (flags | (uint8_t)RFAL_NFCV_REQ_FLAG_PROTOCOL_EXT), RFAL_NFCV_PARAM_SKIP, uid, data, dataLen, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen );
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerM24LRReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen )
{
uint8_t data[(RFAL_NFCV_BLOCKNUM_M24LR_LEN + RFAL_NFCV_BLOCKNUM_M24LR_LEN)];
uint8_t dataLen;
dataLen = 0U;
/* Compute Request Data */
data[dataLen++] = (uint8_t)firstBlockNum; /* Set M24LR Block Number (16 bits) LSB */
data[dataLen++] = (uint8_t)(firstBlockNum >> 8U); /* Set M24LR Block Number (16 bits) MSB */
data[dataLen++] = numOfBlocks; /* Set number of blocks to read */
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_READ_MULTIPLE_BLOCKS, (flags | (uint8_t)RFAL_NFCV_REQ_FLAG_PROTOCOL_EXT), RFAL_NFCV_PARAM_SKIP, uid, data, dataLen, rxBuf, rxBufLen, rcvLen );
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerFastReadSingleBlock( uint8_t flags, const uint8_t* uid, uint8_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen )
{
uint8_t bn;
bn = blockNum;
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_FAST_READ_SINGLE_BLOCK, flags, RFAL_NFCV_ST_IC_MFG_CODE, uid, &bn, sizeof(uint8_t), rxBuf, rxBufLen, rcvLen );
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerM24LRFastReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen )
{
uint8_t data[RFAL_NFCV_BLOCKNUM_M24LR_LEN];
uint8_t dataLen;
dataLen = 0;
/* Compute Request Data */
data[dataLen++] = (uint8_t)blockNum; /* Set M24LR Block Number (16 bits) LSB */
data[dataLen++] = (uint8_t)(blockNum >> 8U); /* Set M24LR Block Number (16 bits) MSB */
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_FAST_READ_SINGLE_BLOCK, (flags | (uint8_t)RFAL_NFCV_REQ_FLAG_PROTOCOL_EXT), RFAL_NFCV_ST_IC_MFG_CODE, uid, data, dataLen, rxBuf, rxBufLen, rcvLen );
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerM24LRFastReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen )
{
uint8_t data[(RFAL_NFCV_BLOCKNUM_M24LR_LEN + RFAL_NFCV_BLOCKNUM_M24LR_LEN)];
uint8_t dataLen;
dataLen = 0U;
/* Compute Request Data */
data[dataLen++] = (uint8_t)firstBlockNum; /* Set M24LR Block Number (16 bits) LSB */
data[dataLen++] = (uint8_t)(firstBlockNum >> 8U); /* Set M24LR Block Number (16 bits) MSB */
data[dataLen++] = numOfBlocks; /* Set number of blocks to read */
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_FAST_READ_MULTIPLE_BLOCKS, (flags | (uint8_t)RFAL_NFCV_REQ_FLAG_PROTOCOL_EXT), RFAL_NFCV_ST_IC_MFG_CODE, uid, data, dataLen, rxBuf, rxBufLen, rcvLen );
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerFastReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint8_t firstBlockNum, uint8_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen )
{
uint8_t data[(RFAL_NFCV_BLOCKNUM_LEN + RFAL_NFCV_BLOCKNUM_LEN)];
uint8_t dataLen;
dataLen = 0U;
/* Compute Request Data */
data[dataLen++] = firstBlockNum; /* Set first Block Number */
data[dataLen++] = numOfBlocks; /* Set number of blocks to read */
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_FAST_READ_MULTIPLE_BLOCKS, flags, RFAL_NFCV_ST_IC_MFG_CODE, uid, data, dataLen, rxBuf, rxBufLen, rcvLen );
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerFastExtendedReadSingleBlock( uint8_t flags, const uint8_t* uid, uint16_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen )
{
uint8_t data[RFAL_NFCV_BLOCKNUM_EXTENDED_LEN];
uint8_t dataLen;
dataLen = 0U;
/* Compute Request Data */
data[dataLen++] = (uint8_t)blockNum; /* TS T5T 1.0 BNo is considered as a multi-byte field. TS T5T 1.0 5.1.1.13 multi-byte field follows [DIGITAL]. [DIGITAL] 9.3.1 A multiple byte field is transmitted LSB first. */
data[dataLen++] = (uint8_t)((blockNum >> 8U) & 0xFFU);
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_FAST_EXTENDED_READ_SINGLE_BLOCK, flags, RFAL_NFCV_ST_IC_MFG_CODE, uid, data, dataLen, rxBuf, rxBufLen, rcvLen );
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerFastExtReadMultipleBlocks( uint8_t flags, const uint8_t* uid, uint16_t firstBlockNum, uint16_t numOfBlocks, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen )
{
uint8_t data[(RFAL_NFCV_BLOCKNUM_EXTENDED_LEN + RFAL_NFCV_BLOCKNUM_EXTENDED_LEN)];
uint8_t dataLen;
dataLen = 0U;
/* Compute Request Data */
data[dataLen++] = (uint8_t)((firstBlockNum >> 0U) & 0xFFU);
data[dataLen++] = (uint8_t)((firstBlockNum >> 8U) & 0xFFU);
data[dataLen++] = (uint8_t)((numOfBlocks >> 0U) & 0xFFU);
data[dataLen++] = (uint8_t)((numOfBlocks >> 8U) & 0xFFU);
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_FAST_EXTENDED_READ_MULTIPLE_BLOCKS, flags, RFAL_NFCV_ST_IC_MFG_CODE, uid, data, dataLen, rxBuf, rxBufLen, rcvLen );
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerReadConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue )
{
return rfalST25xVPollerGenericReadConfiguration(RFAL_NFCV_CMD_READ_CONFIGURATION, flags, uid, pointer, regValue );
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerWriteConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue )
{
return rfalST25xVPollerGenericWriteConfiguration( RFAL_NFCV_CMD_WRITE_CONFIGURATION, flags, uid, pointer, regValue);
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerReadDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue )
{
return rfalST25xVPollerGenericReadConfiguration(RFAL_NFCV_CMD_READ_DYN_CONFIGURATION, flags, uid, pointer, regValue );
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerWriteDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue )
{
return rfalST25xVPollerGenericWriteConfiguration( RFAL_NFCV_CMD_WRITE_DYN_CONFIGURATION, flags, uid, pointer, regValue);
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerFastReadDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t* regValue )
{
return rfalST25xVPollerGenericReadConfiguration(RFAL_NFCV_CMD_FAST_READ_DYN_CONFIGURATION, flags, uid, pointer, regValue );
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerFastWriteDynamicConfiguration( uint8_t flags, const uint8_t* uid, uint8_t pointer, uint8_t regValue )
{
return rfalST25xVPollerGenericWriteConfiguration( RFAL_NFCV_CMD_FAST_WRITE_DYN_CONFIGURATION, flags, uid, pointer, regValue);
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerPresentPassword( uint8_t flags, const uint8_t* uid, uint8_t pwdNum, const uint8_t *pwd, uint8_t pwdLen)
{
uint8_t data[RFAL_ST25xV_PWDNUM_LEN + RFAL_ST25xV_PWD_LEN];
uint8_t dataLen;
uint16_t rcvLen;
rfalNfcvGenericRes res;
if( (pwdLen > RFAL_ST25xV_PWD_LEN) || (pwd == NULL) )
{
return ERR_PARAM;
}
dataLen = 0U;
data[dataLen++] = pwdNum;;
if( pwdLen > 0U )
{
ST_MEMCPY(&data[dataLen], pwd, pwdLen);
}
dataLen += pwdLen;
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_PRESENT_PASSWORD, flags, RFAL_NFCV_ST_IC_MFG_CODE, uid, data, dataLen, (uint8_t*)&res, sizeof(rfalNfcvGenericRes), &rcvLen );
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerGetRandomNumber( uint8_t flags, const uint8_t* uid, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen )
{
rfalFieldOff();
platformDelay(RFAL_ST25TV02K_TRF_OFF);
rfalNfcvPollerInitialize();
rfalFieldOnAndStartGT();
platformDelay(RFAL_ST25TV02K_TBOOT_RF);
return rfalNfcvPollerTransceiveReq( RFAL_NFCV_CMD_GET_RANDOM_NUMBER, flags, RFAL_NFCV_ST_IC_MFG_CODE, uid, NULL, 0U, rxBuf, rxBufLen, rcvLen );
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerWriteMessage( uint8_t flags, const uint8_t* uid, uint8_t msgLen, const uint8_t* msgData, uint8_t* txBuf, uint16_t txBufLen )
{
return rfalST25xVPollerGenericWriteMessage( RFAL_NFCV_CMD_WRITE_MESSAGE, flags, uid, msgLen, msgData, txBuf, txBufLen);
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerFastWriteMessage( uint8_t flags, const uint8_t* uid, uint8_t msgLen, const uint8_t* msgData, uint8_t* txBuf, uint16_t txBufLen )
{
return rfalST25xVPollerGenericWriteMessage( RFAL_NFCV_CMD_FAST_WRITE_MESSAGE, flags, uid, msgLen, msgData, txBuf, txBufLen);
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerReadMessageLength( uint8_t flags, const uint8_t* uid, uint8_t* msgLen )
{
return rfalST25xVPollerGenericReadMessageLength(RFAL_NFCV_CMD_READ_MESSAGE_LENGTH, flags, uid, msgLen);
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerFastReadMsgLength( uint8_t flags, const uint8_t* uid, uint8_t* msgLen )
{
return rfalST25xVPollerGenericReadMessageLength(RFAL_NFCV_CMD_FAST_READ_MESSAGE_LENGTH, flags, uid, msgLen);
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerReadMessage( uint8_t flags, const uint8_t* uid, uint8_t mbPointer, uint8_t numBytes, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen )
{
return rfalST25xVPollerGenericReadMessage(RFAL_NFCV_CMD_READ_MESSAGE, flags, uid, mbPointer, numBytes, rxBuf, rxBufLen, rcvLen );
}
/*******************************************************************************/
ReturnCode rfalST25xVPollerFastReadMessage( uint8_t flags, const uint8_t* uid, uint8_t mbPointer, uint8_t numBytes, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen )
{
return rfalST25xVPollerGenericReadMessage(RFAL_NFCV_CMD_FAST_READ_MESSAGE, flags, uid, mbPointer, numBytes, rxBuf, rxBufLen, rcvLen );
}
#endif /* RFAL_FEATURE_ST25xV */

View File

@ -1,220 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_t1t.c
*
* \author Gustavo Patricio
*
* \brief Provides NFC-A T1T convenience methods and definitions
*
* This module provides an interface to perform as a NFC-A Reader/Writer
* to handle a Type 1 Tag T1T (Topaz)
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "rfal_t1t.h"
#include "utils.h"
/*
******************************************************************************
* ENABLE SWITCH
******************************************************************************
*/
#ifndef RFAL_FEATURE_T1T
#define RFAL_FEATURE_T1T false /* T1T module configuration missing. Disabled by default */
#endif
#if RFAL_FEATURE_T1T
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_T1T_DRD_READ (1236U*2U) /*!< DRD for Reads with n=9 => 1236/fc ~= 91 us T1T 1.2 4.4.2 */
#define RFAL_T1T_DRD_WRITE 36052U /*!< DRD for Write with n=281 => 36052/fc ~= 2659 us T1T 1.2 4.4.2 */
#define RFAL_T1T_DRD_WRITE_E 70996U /*!< DRD for Write/Erase with n=554 => 70996/fc ~= 5236 us T1T 1.2 4.4.2 */
#define RFAL_T1T_RID_RES_HR0_VAL 0x10U /*!< HR0 indicating NDEF support Digital 2.0 (Candidate) 11.6.2.1 */
#define RFAL_T1T_RID_RES_HR0_MASK 0xF0U /*!< HR0 most significant nibble mask */
/*
******************************************************************************
* GLOBAL TYPES
******************************************************************************
*/
/*! NFC-A T1T (Topaz) RID_REQ Digital 1.1 10.6.1 & Table 49 */
typedef struct
{
uint8_t cmd; /*!< T1T cmd: RID */
uint8_t add; /*!< ADD: undefined value */
uint8_t data; /*!< DATA: undefined value */
uint8_t uid[RFAL_T1T_UID_LEN]; /*!< UID-echo: undefined value */
} rfalT1TRidReq;
/*! NFC-A T1T (Topaz) RALL_REQ T1T 1.2 Table 4 */
typedef struct
{
uint8_t cmd; /*!< T1T cmd: RALL */
uint8_t add1; /*!< ADD: 0x00 */
uint8_t add0; /*!< ADD: 0x00 */
uint8_t uid[RFAL_T1T_UID_LEN]; /*!< UID */
} rfalT1TRallReq;
/*! NFC-A T1T (Topaz) WRITE_REQ T1T 1.2 Table 4 */
typedef struct
{
uint8_t cmd; /*!< T1T cmd: RALL */
uint8_t add; /*!< ADD */
uint8_t data; /*!< DAT */
uint8_t uid[RFAL_T1T_UID_LEN]; /*!< UID */
} rfalT1TWriteReq;
/*! NFC-A T1T (Topaz) WRITE_RES T1T 1.2 Table 4 */
typedef struct
{
uint8_t add; /*!< ADD */
uint8_t data; /*!< DAT */
} rfalT1TWriteRes;
/*
******************************************************************************
* LOCAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
ReturnCode rfalT1TPollerInitialize( void )
{
ReturnCode ret;
EXIT_ON_ERR(ret, rfalSetMode( RFAL_MODE_POLL_NFCA_T1T, RFAL_BR_106, RFAL_BR_106 ) );
rfalSetErrorHandling( RFAL_ERRORHANDLING_NFC );
rfalSetGT( RFAL_GT_NONE ); /* T1T should only be initialized after NFC-A mode, therefore the GT has been fulfilled */
rfalSetFDTListen( RFAL_FDT_LISTEN_NFCA_POLLER ); /* T1T uses NFC-A FDT Listen with n=9 Digital 1.1 10.7.2 */
rfalSetFDTPoll( RFAL_FDT_POLL_NFCA_T1T_POLLER );
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode rfalT1TPollerRid( rfalT1TRidRes *ridRes )
{
ReturnCode ret;
rfalT1TRidReq ridReq;
uint16_t rcvdLen;
if( ridRes == NULL )
{
return ERR_PARAM;
}
/* Compute RID command and set Undefined Values to 0x00 Digital 1.1 10.6.1 */
ST_MEMSET( &ridReq, 0x00, sizeof(rfalT1TRidReq) );
ridReq.cmd = (uint8_t)RFAL_T1T_CMD_RID;
EXIT_ON_ERR( ret, rfalTransceiveBlockingTxRx( (uint8_t*)&ridReq, sizeof(rfalT1TRidReq), (uint8_t*)ridRes, sizeof(rfalT1TRidRes), &rcvdLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_T1T_DRD_READ ) );
/* Check expected RID response length and the HR0 Digital 2.0 (Candidate) 11.6.2.1 */
if( (rcvdLen != sizeof(rfalT1TRidRes)) || ((ridRes->hr0 & RFAL_T1T_RID_RES_HR0_MASK) != RFAL_T1T_RID_RES_HR0_VAL) )
{
return ERR_PROTO;
}
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode rfalT1TPollerRall( const uint8_t* uid, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rxRcvdLen )
{
rfalT1TRallReq rallReq;
if( (rxBuf == NULL) || (uid == NULL) || (rxRcvdLen == NULL) )
{
return ERR_PARAM;
}
/* Compute RALL command and set Add to 0x00 */
ST_MEMSET( &rallReq, 0x00, sizeof(rfalT1TRallReq) );
rallReq.cmd = (uint8_t)RFAL_T1T_CMD_RALL;
ST_MEMCPY(rallReq.uid, uid, RFAL_T1T_UID_LEN);
return rfalTransceiveBlockingTxRx( (uint8_t*)&rallReq, sizeof(rfalT1TRallReq), (uint8_t*)rxBuf, rxBufLen, rxRcvdLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_T1T_DRD_READ );
}
/*******************************************************************************/
ReturnCode rfalT1TPollerWrite( const uint8_t* uid, uint8_t address, uint8_t data )
{
rfalT1TWriteReq writeReq;
rfalT1TWriteRes writeRes;
uint16_t rxRcvdLen;
ReturnCode err;
if( uid == NULL )
{
return ERR_PARAM;
}
writeReq.cmd = (uint8_t)RFAL_T1T_CMD_WRITE_E;
writeReq.add = address;
writeReq.data = data;
ST_MEMCPY(writeReq.uid, uid, RFAL_T1T_UID_LEN);
err = rfalTransceiveBlockingTxRx( (uint8_t*)&writeReq, sizeof(rfalT1TWriteReq), (uint8_t*)&writeRes, sizeof(rfalT1TWriteRes), &rxRcvdLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_T1T_DRD_WRITE_E );
if( err == ERR_NONE )
{
if( (writeReq.add != writeRes.add) || (writeReq.data != writeRes.data) || (rxRcvdLen != sizeof(rfalT1TWriteRes)) )
{
return ERR_PROTO;
}
}
return err;
}
#endif /* RFAL_FEATURE_T1T */

View File

@ -1,242 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2018 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_t2t.c
*
* \author
*
* \brief Provides NFC-A T2T convenience methods and definitions
*
* This module provides an interface to perform as a NFC-A Reader/Writer
* to handle a Type 2 Tag T2T
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "rfal_t2t.h"
#include "utils.h"
/*
******************************************************************************
* ENABLE SWITCH
******************************************************************************
*/
#ifndef RFAL_FEATURE_T2T
#define RFAL_FEATURE_T2T false /* T2T module configuration missing. Disabled by default */
#endif
#if RFAL_FEATURE_T2T
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_FDT_POLL_READ_MAX rfalConvMsTo1fc(5U) /*!< Maximum Wait time for Read command as defined in TS T2T 1.0 table 18 */
#define RFAL_FDT_POLL_WRITE_MAX rfalConvMsTo1fc(10U) /*!< Maximum Wait time for Write command as defined in TS T2T 1.0 table 18 */
#define RFAL_FDT_POLL_SL_MAX rfalConvMsTo1fc(1U) /*!< Maximum Wait time for Sector Select as defined in TS T2T 1.0 table 18 */
#define RFAL_T2T_ACK_NACK_LEN 1U /*!< Len of NACK in bytes (4 bits) */
#define RFAL_T2T_ACK 0x0AU /*!< ACK value */
#define RFAL_T2T_ACK_MASK 0x0FU /*!< ACK value */
#define RFAL_T2T_SECTOR_SELECT_P1_BYTE2 0xFFU /*!< Sector Select Packet 1 byte 2 */
#define RFAL_T2T_SECTOR_SELECT_P2_RFU_LEN 3U /*!< Sector Select RFU length */
/*
******************************************************************************
* GLOBAL TYPES
******************************************************************************
*/
/*! NFC-A T2T command set T2T 1.0 5.1 */
typedef enum
{
RFAL_T2T_CMD_READ = 0x30, /*!< T2T Read */
RFAL_T2T_CMD_WRITE = 0xA2, /*!< T2T Write */
RFAL_T2T_CMD_SECTOR_SELECT = 0xC2 /*!< T2T Sector Select */
} rfalT2Tcmds;
/*! NFC-A T2T READ T2T 1.0 5.2 and table 11 */
typedef struct
{
uint8_t code; /*!< Command code */
uint8_t blNo; /*!< Block number */
} rfalT2TReadReq;
/*! NFC-A T2T WRITE T2T 1.0 5.3 and table 12 */
typedef struct
{
uint8_t code; /*!< Command code */
uint8_t blNo; /*!< Block number */
uint8_t data[RFAL_T2T_WRITE_DATA_LEN]; /*!< Data */
} rfalT2TWriteReq;
/*! NFC-A T2T SECTOR SELECT Packet 1 T2T 1.0 5.4 and table 13 */
typedef struct
{
uint8_t code; /*!< Command code */
uint8_t byte2; /*!< Sector Select Packet 1 byte 2 */
} rfalT2TSectorSelectP1Req;
/*! NFC-A T2T SECTOR SELECT Packet 2 T2T 1.0 5.4 and table 13 */
typedef struct
{
uint8_t secNo; /*!< Block number */
uint8_t rfu[RFAL_T2T_SECTOR_SELECT_P2_RFU_LEN]; /*!< Sector Select Packet RFU */
} rfalT2TSectorSelectP2Req;
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
ReturnCode rfalT2TPollerRead( uint8_t blockNum, uint8_t* rxBuf, uint16_t rxBufLen, uint16_t *rcvLen )
{
ReturnCode ret;
rfalT2TReadReq req;
if( (rxBuf == NULL) || (rcvLen == NULL) )
{
return ERR_PARAM;
}
req.code = (uint8_t)RFAL_T2T_CMD_READ;
req.blNo = blockNum;
/* Transceive Command */
ret = rfalTransceiveBlockingTxRx( (uint8_t*)&req, sizeof(rfalT2TReadReq), rxBuf, rxBufLen, rcvLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_READ_MAX );
/* T2T 1.0 5.2.1.7 The Reader/Writer SHALL treat a NACK in response to a READ Command as a Protocol Error */
if( (ret == ERR_INCOMPLETE_BYTE) && (*rcvLen == RFAL_T2T_ACK_NACK_LEN) && ((*rxBuf & RFAL_T2T_ACK_MASK) != RFAL_T2T_ACK) )
{
return ERR_PROTO;
}
return ret;
}
/*******************************************************************************/
ReturnCode rfalT2TPollerWrite( uint8_t blockNum, const uint8_t* wrData )
{
ReturnCode ret;
rfalT2TWriteReq req;
uint8_t res;
uint16_t rxLen;
req.code = (uint8_t)RFAL_T2T_CMD_WRITE;
req.blNo = blockNum;
ST_MEMCPY(req.data, wrData, RFAL_T2T_WRITE_DATA_LEN);
/* Transceive WRITE Command */
ret = rfalTransceiveBlockingTxRx( (uint8_t*)&req, sizeof(rfalT2TWriteReq), &res, sizeof(uint8_t), &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_READ_MAX );
/* Check for a valid ACK */
if( (ret == ERR_INCOMPLETE_BYTE) || (ret == ERR_NONE) )
{
ret = ERR_PROTO;
if( (rxLen == RFAL_T2T_ACK_NACK_LEN) && ((res & RFAL_T2T_ACK_MASK) == RFAL_T2T_ACK) )
{
ret = ERR_NONE;
}
}
return ret;
}
/*******************************************************************************/
ReturnCode rfalT2TPollerSectorSelect( uint8_t sectorNum )
{
rfalT2TSectorSelectP1Req p1Req;
rfalT2TSectorSelectP2Req p2Req;
ReturnCode ret;
uint8_t res;
uint16_t rxLen;
/* Compute SECTOR SELECT Packet 1 */
p1Req.code = (uint8_t)RFAL_T2T_CMD_SECTOR_SELECT;
p1Req.byte2 = RFAL_T2T_SECTOR_SELECT_P1_BYTE2;
/* Transceive SECTOR SELECT Packet 1 */
ret = rfalTransceiveBlockingTxRx( (uint8_t*)&p1Req, sizeof(rfalT2TSectorSelectP1Req), &res, sizeof(uint8_t), &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_SL_MAX );
/* Check and report any transmission error */
if( (ret != ERR_INCOMPLETE_BYTE) && (ret != ERR_NONE) )
{
return ret;
}
/* Ensure that an ACK was received */
if( (ret != ERR_INCOMPLETE_BYTE) || (rxLen != RFAL_T2T_ACK_NACK_LEN) || ((res & RFAL_T2T_ACK_MASK) != RFAL_T2T_ACK) )
{
return ERR_PROTO;
}
/* Compute SECTOR SELECT Packet 2 */
p2Req.secNo = sectorNum;
ST_MEMSET( &p2Req.rfu, 0x00, RFAL_T2T_SECTOR_SELECT_P2_RFU_LEN );
/* Transceive SECTOR SELECT Packet 2 */
ret = rfalTransceiveBlockingTxRx( (uint8_t*)&p2Req, sizeof(rfalT2TSectorSelectP2Req), &res, sizeof(uint8_t), &rxLen, RFAL_TXRX_FLAGS_DEFAULT, RFAL_FDT_POLL_SL_MAX );
/* T2T 1.0 5.4.1.14 The Reader/Writer SHALL treat any response received before the end of PATT2T,SL,MAX as a Protocol Error */
if( (ret == ERR_NONE) || (ret == ERR_INCOMPLETE_BYTE) )
{
return ERR_PROTO;
}
/* T2T 1.0 5.4.1.13 The Reader/Writer SHALL treat the transmission of the SECTOR SELECT Command Packet 2 as being successful when it receives no response until PATT2T,SL,MAX. */
if( ret == ERR_TIMEOUT )
{
return ERR_NONE;
}
return ret;
}
#endif /* RFAL_FEATURE_T2T */

View File

@ -1,398 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2018 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file rfal_t4t.h
*
* \author Gustavo Patricio
*
* \brief Provides convenience methods and definitions for T4T (ISO7816-4)
*
* This module provides an interface to exchange T4T APDUs according to
* NFC Forum T4T and ISO7816-4
*
* This implementation was based on the following specs:
* - ISO/IEC 7816-4 3rd Edition 2013-04-15
* - NFC Forum T4T Technical Specification 1.0 2017-08-28
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "rfal_t4t.h"
#include "utils.h"
/*
******************************************************************************
* ENABLE SWITCH
******************************************************************************
*/
#ifndef RFAL_FEATURE_T4T
#define RFAL_FEATURE_T4T false /* T4T module configuration missing. Disabled by default */
#endif
#if RFAL_FEATURE_T4T
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define RFAL_T4T_OFFSET_DO 0x54U /*!< Tag value for offset BER-TLV data object */
#define RFAL_T4T_LENGTH_DO 0x03U /*!< Len value for offset BER-TLV data object */
#define RFAL_T4T_DATA_DO 0x53U /*!< Tag value for data BER-TLV data object */
#define RFAL_T4T_MAX_LC 255U /*!< Maximum Lc value for short Lc coding */
/*
******************************************************************************
* GLOBAL TYPES
******************************************************************************
*/
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
/*
******************************************************************************
* LOCAL VARIABLES
******************************************************************************
*/
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
/*******************************************************************************/
ReturnCode rfalT4TPollerComposeCAPDU( rfalT4tCApduParam *apduParam )
{
uint8_t hdrLen;
uint16_t msgIt;
if( (apduParam == NULL) || (apduParam->cApduBuf == NULL) || (apduParam->cApduLen == NULL) )
{
return ERR_PARAM;
}
msgIt = 0;
*(apduParam->cApduLen) = 0;
/*******************************************************************************/
/* Compute Command-APDU according to the format T4T 1.0 5.1.2 & ISO7816-4 2013 Table 1 */
/* Check if Data is present */
if( apduParam->LcFlag )
{
if( apduParam->Lc == 0U )
{
/* Extented field coding not supported */
return ERR_PARAM;
}
/* Check whether requested Lc fits */
if( (uint16_t)apduParam->Lc > (uint16_t)(RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN - RFAL_T4T_LE_LEN) )
{
return ERR_PARAM; /* PRQA S 2880 # MISRA 2.1 - Unreachable code due to configuration option being set/unset */
}
/* Calculate the header length a place the data/body where it should be */
hdrLen = RFAL_T4T_MAX_CAPDU_PROLOGUE_LEN + RFAL_T4T_LC_LEN;
/* make sure not to exceed buffer size */
if( ((uint16_t)hdrLen + (uint16_t)apduParam->Lc + (apduParam->LeFlag ? RFAL_T4T_LC_LEN : 0U)) > RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN )
{
return ERR_NOMEM; /* PRQA S 2880 # MISRA 2.1 - Unreachable code due to configuration option being set/unset */
}
ST_MEMMOVE( &apduParam->cApduBuf->apdu[hdrLen], apduParam->cApduBuf->apdu, apduParam->Lc );
}
/* Prepend the ADPDU's header */
apduParam->cApduBuf->apdu[msgIt++] = apduParam->CLA;
apduParam->cApduBuf->apdu[msgIt++] = apduParam->INS;
apduParam->cApduBuf->apdu[msgIt++] = apduParam->P1;
apduParam->cApduBuf->apdu[msgIt++] = apduParam->P2;
/* Check if Data field length is to be added */
if( apduParam->LcFlag )
{
apduParam->cApduBuf->apdu[msgIt++] = apduParam->Lc;
msgIt += apduParam->Lc;
}
/* Check if Expected Response Length is to be added */
if( apduParam->LeFlag )
{
apduParam->cApduBuf->apdu[msgIt++] = apduParam->Le;
}
*(apduParam->cApduLen) = msgIt;
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode rfalT4TPollerParseRAPDU( rfalT4tRApduParam *apduParam )
{
if( (apduParam == NULL) || (apduParam->rApduBuf == NULL) )
{
return ERR_PARAM;
}
if( apduParam->rcvdLen < RFAL_T4T_MAX_RAPDU_SW1SW2_LEN )
{
return ERR_PROTO;
}
apduParam->rApduBodyLen = (apduParam->rcvdLen - (uint16_t)RFAL_T4T_MAX_RAPDU_SW1SW2_LEN);
apduParam->statusWord = GETU16( &apduParam->rApduBuf->apdu[ apduParam->rApduBodyLen ] );
/* Check SW1 SW2 T4T 1.0 5.1.3 NOTE */
if( apduParam->statusWord == RFAL_T4T_ISO7816_STATUS_COMPLETE )
{
return ERR_NONE;
}
return ERR_REQUEST;
}
/*******************************************************************************/
ReturnCode rfalT4TPollerComposeSelectAppl( rfalIsoDepApduBufFormat *cApduBuf, const uint8_t* aid, uint8_t aidLen, uint16_t *cApduLen )
{
rfalT4tCApduParam cAPDU;
/* CLA INS P1 P2 Lc Data Le */
/* 00h A4h 00h 00h 07h AID 00h */
cAPDU.CLA = RFAL_T4T_CLA;
cAPDU.INS = (uint8_t)RFAL_T4T_INS_SELECT;
cAPDU.P1 = RFAL_T4T_ISO7816_P1_SELECT_BY_DF_NAME;
cAPDU.P2 = RFAL_T4T_ISO7816_P2_SELECT_FIRST_OR_ONLY_OCCURENCE | RFAL_T4T_ISO7816_P2_SELECT_RETURN_FCI_TEMPLATE;
cAPDU.Lc = aidLen;
cAPDU.Le = 0x00;
cAPDU.LcFlag = true;
cAPDU.LeFlag = true;
cAPDU.cApduBuf = cApduBuf;
cAPDU.cApduLen = cApduLen;
if( aidLen > 0U )
{
ST_MEMCPY( cAPDU.cApduBuf->apdu, aid, aidLen );
}
return rfalT4TPollerComposeCAPDU( &cAPDU );
}
/*******************************************************************************/
ReturnCode rfalT4TPollerComposeSelectFile( rfalIsoDepApduBufFormat *cApduBuf, const uint8_t* fid, uint8_t fidLen, uint16_t *cApduLen )
{
rfalT4tCApduParam cAPDU;
/* CLA INS P1 P2 Lc Data Le */
/* 00h A4h 00h 0Ch 02h FID - */
cAPDU.CLA = RFAL_T4T_CLA;
cAPDU.INS = (uint8_t)RFAL_T4T_INS_SELECT;
cAPDU.P1 = RFAL_T4T_ISO7816_P1_SELECT_BY_FILEID;
cAPDU.P2 = RFAL_T4T_ISO7816_P2_SELECT_FIRST_OR_ONLY_OCCURENCE | RFAL_T4T_ISO7816_P2_SELECT_NO_RESPONSE_DATA;
cAPDU.Lc = fidLen;
cAPDU.Le = 0x00;
cAPDU.LcFlag = true;
cAPDU.LeFlag = false;
cAPDU.cApduBuf = cApduBuf;
cAPDU.cApduLen = cApduLen;
if( fidLen > 0U )
{
ST_MEMCPY( cAPDU.cApduBuf->apdu, fid, fidLen );
}
return rfalT4TPollerComposeCAPDU( &cAPDU );
}
/*******************************************************************************/
ReturnCode rfalT4TPollerComposeSelectFileV1Mapping( rfalIsoDepApduBufFormat *cApduBuf, const uint8_t* fid, uint8_t fidLen, uint16_t *cApduLen )
{
rfalT4tCApduParam cAPDU;
/* CLA INS P1 P2 Lc Data Le */
/* 00h A4h 00h 00h 02h FID - */
cAPDU.CLA = RFAL_T4T_CLA;
cAPDU.INS = (uint8_t)RFAL_T4T_INS_SELECT;
cAPDU.P1 = RFAL_T4T_ISO7816_P1_SELECT_BY_FILEID;
cAPDU.P2 = RFAL_T4T_ISO7816_P2_SELECT_FIRST_OR_ONLY_OCCURENCE | RFAL_T4T_ISO7816_P2_SELECT_RETURN_FCI_TEMPLATE;
cAPDU.Lc = fidLen;
cAPDU.Le = 0x00;
cAPDU.LcFlag = true;
cAPDU.LeFlag = false;
cAPDU.cApduBuf = cApduBuf;
cAPDU.cApduLen = cApduLen;
if( fidLen > 0U )
{
ST_MEMCPY( cAPDU.cApduBuf->apdu, fid, fidLen );
}
return rfalT4TPollerComposeCAPDU( &cAPDU );
}
/*******************************************************************************/
ReturnCode rfalT4TPollerComposeReadData( rfalIsoDepApduBufFormat *cApduBuf, uint16_t offset, uint8_t expLen, uint16_t *cApduLen )
{
rfalT4tCApduParam cAPDU;
/* CLA INS P1 P2 Lc Data Le */
/* 00h B0h [Offset] - - len */
cAPDU.CLA = RFAL_T4T_CLA;
cAPDU.INS = (uint8_t)RFAL_T4T_INS_READBINARY;
cAPDU.P1 = (uint8_t)((offset >> 8U) & 0xFFU);
cAPDU.P2 = (uint8_t)((offset >> 0U) & 0xFFU);
cAPDU.Le = expLen;
cAPDU.LcFlag = false;
cAPDU.LeFlag = true;
cAPDU.cApduBuf = cApduBuf;
cAPDU.cApduLen = cApduLen;
return rfalT4TPollerComposeCAPDU( &cAPDU );
}
/*******************************************************************************/
ReturnCode rfalT4TPollerComposeReadDataODO( rfalIsoDepApduBufFormat *cApduBuf, uint32_t offset, uint8_t expLen, uint16_t *cApduLen )
{
rfalT4tCApduParam cAPDU;
uint8_t dataIt;
/* CLA INS P1 P2 Lc Data Le */
/* 00h B1h 00h 00h Lc 54 03 xxyyzz len */
/* [Offset] */
cAPDU.CLA = RFAL_T4T_CLA;
cAPDU.INS = (uint8_t)RFAL_T4T_INS_READBINARY_ODO;
cAPDU.P1 = 0x00U;
cAPDU.P2 = 0x00U;
cAPDU.Le = expLen;
cAPDU.LcFlag = true;
cAPDU.LeFlag = true;
cAPDU.cApduBuf = cApduBuf;
cAPDU.cApduLen = cApduLen;
dataIt = 0U;
cApduBuf->apdu[dataIt++] = RFAL_T4T_OFFSET_DO;
cApduBuf->apdu[dataIt++] = RFAL_T4T_LENGTH_DO;
cApduBuf->apdu[dataIt++] = (uint8_t)(offset >> 16U);
cApduBuf->apdu[dataIt++] = (uint8_t)(offset >> 8U);
cApduBuf->apdu[dataIt++] = (uint8_t)(offset);
cAPDU.Lc = dataIt;
return rfalT4TPollerComposeCAPDU( &cAPDU );
}
/*******************************************************************************/
ReturnCode rfalT4TPollerComposeWriteData( rfalIsoDepApduBufFormat *cApduBuf, uint16_t offset, const uint8_t* data, uint8_t dataLen, uint16_t *cApduLen )
{
rfalT4tCApduParam cAPDU;
/* CLA INS P1 P2 Lc Data Le */
/* 00h D6h [Offset] len Data - */
cAPDU.CLA = RFAL_T4T_CLA;
cAPDU.INS = (uint8_t)RFAL_T4T_INS_UPDATEBINARY;
cAPDU.P1 = (uint8_t)((offset >> 8U) & 0xFFU);
cAPDU.P2 = (uint8_t)((offset >> 0U) & 0xFFU);
cAPDU.Lc = dataLen;
cAPDU.LcFlag = true;
cAPDU.LeFlag = false;
cAPDU.cApduBuf = cApduBuf;
cAPDU.cApduLen = cApduLen;
if( dataLen > 0U )
{
ST_MEMCPY( cAPDU.cApduBuf->apdu, data, dataLen );
}
return rfalT4TPollerComposeCAPDU( &cAPDU );
}
/*******************************************************************************/
ReturnCode rfalT4TPollerComposeWriteDataODO( rfalIsoDepApduBufFormat *cApduBuf, uint32_t offset, const uint8_t* data, uint8_t dataLen, uint16_t *cApduLen )
{
rfalT4tCApduParam cAPDU;
uint8_t dataIt;
/* CLA INS P1 P2 Lc Data Le */
/* 00h D7h 00h 00h len 54 03 xxyyzz 53 Ld data - */
/* [offset] [data] */
cAPDU.CLA = RFAL_T4T_CLA;
cAPDU.INS = (uint8_t)RFAL_T4T_INS_UPDATEBINARY_ODO;
cAPDU.P1 = 0x00U;
cAPDU.P2 = 0x00U;
cAPDU.LcFlag = true;
cAPDU.LeFlag = false;
cAPDU.cApduBuf = cApduBuf;
cAPDU.cApduLen = cApduLen;
dataIt = 0U;
cApduBuf->apdu[dataIt++] = RFAL_T4T_OFFSET_DO;
cApduBuf->apdu[dataIt++] = RFAL_T4T_LENGTH_DO;
cApduBuf->apdu[dataIt++] = (uint8_t)(offset >> 16U);
cApduBuf->apdu[dataIt++] = (uint8_t)(offset >> 8U);
cApduBuf->apdu[dataIt++] = (uint8_t)(offset);
cApduBuf->apdu[dataIt++] = RFAL_T4T_DATA_DO;
cApduBuf->apdu[dataIt++] = dataLen;
if( (((uint32_t)dataLen + (uint32_t)dataIt) >= RFAL_T4T_MAX_LC) || (((uint32_t)dataLen + (uint32_t)dataIt) >= RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN) )
{
return (ERR_NOMEM);
}
if( dataLen > 0U )
{
ST_MEMCPY( &cAPDU.cApduBuf->apdu[dataIt], data, dataLen );
}
dataIt += dataLen;
cAPDU.Lc = dataIt;
return rfalT4TPollerComposeCAPDU( &cAPDU );
}
#endif /* RFAL_FEATURE_T4T */

View File

@ -1,3 +0,0 @@
idf_component_register(SRCS "st25r3911.c" "st25r3911_com.c" "st25r3911_interrupt.c" "timer.c" "st25r3911_spi.c" "utils.c"
INCLUDE_DIRS "."
REQUIRES "driver")

View File

@ -1,177 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40"><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link rel="File-List" href="Library_files/filelist.xml">
<link rel="Edit-Time-Data" href="Library_files/editdata.mso">
<!--[if !mso]> <style> v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} </style> <![endif]-->
<title>Release Notes for ST25R3911 Driver</title>
<!--[if gte mso 9]><xml> <o:DocumentProperties> <o:Author>STMicroelectronics</o:Author> <o:LastAuthor>STMicroelectronics</o:LastAuthor> <o:Revision>37</o:Revision> <o:TotalTime>136</o:TotalTime> <o:Created>2009-02-27T19:26:00Z</o:Created> <o:LastSaved>2009-03-01T17:56:00Z</o:LastSaved> <o:Pages>1</o:Pages> <o:Words>522</o:Words> <o:Characters>2977</o:Characters> <o:Company>STMicroelectronics</o:Company> <o:Lines>24</o:Lines> <o:Paragraphs>6</o:Paragraphs> <o:CharactersWithSpaces>3493</o:CharactersWithSpaces> <o:Version>11.6568</o:Version> </o:DocumentProperties> </xml><![endif]--><!--[if gte mso 9]><xml> <w:WordDocument> <w:Zoom>110</w:Zoom> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]-->
<style>
<!--
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{mso-style-parent:"";
margin:0in;
margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
h2
{mso-style-next:Normal;
margin-top:12.0pt;
margin-right:0in;
margin-bottom:3.0pt;
margin-left:0in;
mso-pagination:widow-orphan;
page-break-after:avoid;
mso-outline-level:2;
font-size:14.0pt;
font-family:Arial;
font-weight:bold;
font-style:italic;}
a:link, span.MsoHyperlink
{color:blue;
text-decoration:underline;
text-underline:single;}
a:visited, span.MsoHyperlinkFollowed
{color:blue;
text-decoration:underline;
text-underline:single;}
p
{mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
mso-pagination:widow-orphan;
font-size:12.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";}
@page Section1
{size:8.5in 11.0in;
margin:1.0in 1.25in 1.0in 1.25in;
mso-header-margin:.5in;
mso-footer-margin:.5in;
mso-paper-source:0;}
div.Section1
{page:Section1;}
-->
</style><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin:0in; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} </style> <![endif]--><!--[if gte mso 9]><xml> <o:shapedefaults v:ext="edit" spidmax="5122"/> </xml><![endif]--><!--[if gte mso 9]><xml> <o:shapelayout v:ext="edit"> <o:idmap v:ext="edit" data="1"/> </o:shapelayout></xml><![endif]-->
<meta content="MCD Application Team" name="author">
</head><body link="blue" vlink="blue">
<div class="Section1">
<p class="MsoNormal"><span style="font-family: Arial;"><o:p><br>
</o:p></span></p>
<div align="center">
<table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" cellspacing="0" width="900">
<tbody>
<tr>
<td style="padding: 0cm;" valign="top">
<table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" cellspacing="0" width="900">
<tbody>
<tr>
<td style="vertical-align: top;">
<p class="MsoNormal"><span style="font-size: 8pt; font-family: Arial; color: blue;"><a href="../../../../Release_Notes.html">Back to Release page</a><o:p></o:p></span></p>
</td>
</tr>
<tr style="">
<td style="padding: 1.5pt;">
<h1 style="margin-bottom: 18pt; text-align: center;" align="center"><span style="font-size: 20pt; font-family: Verdana; color: rgb(51, 102, 255);">Release
Notes for ST25R3911 driver </span><span style="font-size: 20pt; font-family: Verdana;"><o:p></o:p></span></h1>
<p class="MsoNormal" style="text-align: center;" align="center"><span style="font-size: 10pt; font-family: Arial; color: black;">Copyright
2017 STMicroelectronics</span><span style="color: black;"><u1:p></u1:p><o:p></o:p></span></p>
<p class="MsoNormal" style="text-align: center;" align="center"><span style="font-size: 10pt; font-family: Arial; color: black;"><img alt="" id="_x0000_i1025" src="../../../../_htmresc/st_logo.png" style="border: 0px solid ; width: 86px; height: 65px;"></span><span style="font-size: 10pt;"><o:p></o:p></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span style="font-family: Arial; display: none;"><o:p>&nbsp;</o:p></span></p>
<table class="MsoNormalTable" style="width: 675pt;" border="0" cellpadding="0" width="900">
<tbody>
<tr style="">
<td style="padding: 0cm;" valign="top"> <span style="font-family: &quot;Times New Roman&quot;;"></span>
<h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><a name="History"></a><span style="font-size: 12pt; color: white;">Update
History</span></h2>
<span style="font-size: 10pt; font-family: Verdana;"></span>
<span style="font-size: 10pt; font-family: Verdana;"></span>
<h3 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; margin-right: 500pt; width: 200px;"><span style="font-size: 10pt; font-family: Arial; color: white;">V1.0.0
/ 15-March-2017</span></h3>
<p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt;"><b style=""><u><span style="font-size: 10pt; font-family: Verdana; color: black;">Main
Changes<o:p></o:p></span></u></b></p>
<span style="font-size: 10pt; font-family: Verdana;"></span>
<span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;"></span> <span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;"></span> <span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;"></span> <span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;"></span>
<ul style="list-style-type: square;">
<li><span style="font-size: 10pt; font-family: Verdana;">First
official release.</span><span style="color: rgb(0, 0, 0); font-family: Verdana; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; display: inline ! important; float: none;"></span><span style="font-size: 10pt; font-family: Verdana;"></span><span style="font-size: 10pt; font-family: Verdana;"></span></li>
</ul>
<span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"><span style="font-style: italic; font-weight: bold;"></span></span><span style="font-size: 10pt; font-family: Verdana;"></span>
<h2 style="background: rgb(51, 102, 255) none repeat scroll 0% 50%; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"><a name="License"></a><span style="font-size: 12pt; color: white;">License<o:p></o:p></span><br>
</h2>
<div style="text-align: justify;"><font size="-1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">Redistribution
and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:</span><br>
</font>
<ol>
<li><font size="-1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">Redistributions
of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></font></li>
<li><font size="-1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">Redistributions
in binary form must reproduce the above copyright notice, this list of
conditions and the following disclaimer in </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">the
documentation and/or other materials provided with the distribution.</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span></font></li>
<li><font size="-1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">Neither the
name of STMicroelectronics nor the names of its contributors may be
used to endorse or promote products derived </span><br>
</font> </li>
</ol>
<font size="-1"><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
from this software without specific prior written permission.</span><br>
<span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"></span><br>
<span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">THIS
SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">PARTICULAR
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
CONTRIBUTORS BE LIABLE FOR ANY </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER</span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;"> CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR </span><span style="font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;;">OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.</span></font> </div>
<p class="MsoNormal"><span style="font-size: 10pt; font-family: &quot;Verdana&quot;,&quot;sans-serif&quot;; color: black;"><o:p></o:p></span></p>
<b><span style="font-size: 10pt; font-family: Verdana; color: black;"></span></b>
<div class="MsoNormal" style="text-align: center;" align="center"><span style="color: black;">
<hr align="center" size="2" width="100%"></span></div>
<p class="MsoNormal" style="margin: 4.5pt 0cm 4.5pt 18pt; text-align: center;" align="center"><span style="font-size: 10pt; font-family: Verdana; color: black;">For
complete documentation on </span><span style="font-size: 10pt; font-family: Verdana;">STM32<span style="color: black;">&nbsp;Microcontrollers
visit </span><u><span style="color: blue;"><a href="http://www.st.com/internet/mcu/class/1734.jsp" target="_blank">www.st.com/STM32</a></span></u></span><span style="font-size: 10pt; font-family: Verdana;"><a target="_blank" href="http://www.st.com/internet/mcu/family/141.jsp"><u><span style="color: blue;"></span></u></a></span><span style="font-size: 10pt; font-family: Verdana;"><u><span style="color: blue;"></span></u></span><span style="color: black;"><o:p></o:p></span></p>
</td>
</tr>
</tbody>
</table>
<p class="MsoNormal"><span style="font-size: 10pt;"><o:p></o:p></span></p>
</td>
</tr>
</tbody>
</table>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
</div>
</body></html>

View File

@ -1,197 +0,0 @@
/******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (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.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*! \file
*
* \author
*
* \brief Platform header file. Defining platform independent functionality.
*
*/
/*
* PROJECT:
* $Revision: $
* LANGUAGE: ISO C99
*/
/*! \file platform.h
*
* \author Gustavo Patricio
*
* \brief Platform specific definition layer
*
* This should contain all platform and hardware specifics such as
* GPIO assignment, system resources, locks, IRQs, etc
*
* Each distinct platform/system/board must provide this definitions
* for all SW layers to use
*
*/
#ifndef PLATFORM_H
#define PLATFORM_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <driver/gpio.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <esp_log.h>
#include "st25r3911_spi.h"
#include "timer.h"
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define ST25R391X_SS_PIN 4 /*!< GPIO pin used for ST25R3911 SPI SS */
#define ST25R391X_SS_PORT /*!< GPIO port used for ST25R3911 SPI SS port */
#define ST25R391X_INT_PIN 15 /*!< GPIO pin used for ST25R3911 External Interrupt */
#define ST25R391X_INT_PORT /*!< GPIO port used for ST25R3911 External Interrupt */
#ifdef LED_FIELD_Pin
#define PLATFORM_LED_FIELD_PIN LED_FIELD_Pin /*!< GPIO pin used as field LED */
#endif
#ifdef LED_FIELD_GPIO_Port
#define PLATFORM_LED_FIELD_PORT LED_FIELD_GPIO_Port /*!< GPIO port used as field LED */
#endif
#define PLATFORM_LED_A_PIN LED_A_Pin /*!< GPIO pin used for LED A */
#define PLATFORM_LED_A_PORT LED_A_GPIO_Port /*!< GPIO port used for LED A */
#define PLATFORM_LED_B_PIN LED_B_Pin /*!< GPIO pin used for LED B */
#define PLATFORM_LED_B_PORT LED_B_GPIO_Port /*!< GPIO port used for LED B */
#define PLATFORM_LED_F_PIN LED_F_Pin /*!< GPIO pin used for LED F */
#define PLATFORM_LED_F_PORT LED_F_GPIO_Port /*!< GPIO port used for LED F */
#define PLATFORM_LED_V_PIN LED_V_Pin /*!< GPIO pin used for LED V */
#define PLATFORM_LED_V_PORT LED_V_GPIO_Port /*!< GPIO port used for LED V */
#define PLATFORM_LED_AP2P_PIN LED_AP2P_Pin /*!< GPIO pin used for LED AP2P */
#define PLATFORM_LED_AP2P_PORT LED_AP2P_GPIO_Port /*!< GPIO port used for LED AP2P*/
#define PLATFORM_USER_BUTTON_PIN 12 /*!< GPIO pin user button */
#define PLATFORM_USER_BUTTON_PORT B1_GPIO_Port /*!< GPIO port user button */
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
#define platformProtectST25R391xComm() taskENTER_CRITICAL(&CommProtectLock) /*!< Protect unique access to ST25R391x communication channel - IRQ disable on single thread environment (MCU) ; Mutex lock on a multi thread environment */
#define platformUnprotectST25R391xComm() taskEXIT_CRITICAL(&CommProtectLock) /*!< Unprotect unique access to ST25R391x communication channel - IRQ enable on a single thread environment (MCU) ; Mutex unlock on a multi thread environment */
#define platformProtectST25R391xIrqStatus() platformProtectST25R391xComm() /*!< Protect unique access to IRQ status var - IRQ disable on single thread environment (MCU) ; Mutex lock on a multi thread environment */
#define platformUnprotectST25R391xIrqStatus() platformUnprotectST25R391xComm() /*!< Unprotect the IRQ status var - IRQ enable on a single thread environment (MCU) ; Mutex unlock on a multi thread environment */
#define platformProtectWorker() /* Protect RFAL Worker/Task/Process from concurrent execution on multi thread platforms */
#define platformUnprotectWorker() /* Unprotect RFAL Worker/Task/Process from concurrent execution on multi thread platforms */
#define platformIrqST25R3911SetCallback( cb )
#define platformIrqST25R3911PinInitialize()
#define platformIrqST25R3916SetCallback( cb )
#define platformIrqST25R3916PinInitialize()
#define platformLedsInitialize() /*!< Initializes the pins used as LEDs to outputs*/
#define platformLedOff( port, pin ) platformGpioClear((port), (pin)) /*!< Turns the given LED Off */
#define platformLedOn( port, pin ) platformGpioSet((port), (pin)) /*!< Turns the given LED On */
#define platformLedToogle( port, pin ) platformGpioToogle((port), (pin)) /*!< Toogle the given LED */
#define platformGpioSet( port, pin ) ESP_ERROR_CHECK(gpio_set_level(pin, 1)) /*!< Turns the given GPIO High */
#define platformGpioClear( port, pin ) ESP_ERROR_CHECK(gpio_set_level(pin, 0)) /*!< Turns the given GPIO Low */
#define platformGpioToogle( port, pin ) ESP_ERROR_CHECK(gpio_set_level(pin, !gpio_get_level(pin))) /*!< Toogles the given GPIO */
#define platformGpioIsHigh( port, pin ) (gpio_get_level(pin)) /*!< Checks if the given LED is High */
#define platformGpioIsLow( port, pin ) (!platformGpioIsHigh(port, pin)) /*!< Checks if the given LED is Low */
#define platformTimerCreate( t ) timerCalculateTimer(t) /*!< Create a timer with the given time (ms) */
#define platformTimerIsExpired( timer ) timerIsExpired(timer) /*!< Checks if the given timer is expired */
#define platformDelay( t ) vTaskDelay(pdMS_TO_TICKS(t)) /*!< Performs a delay for the given time (ms) */
#define platformGetSysTick() pdTICKS_TO_MS(xTaskGetTickCount()) /*!< Get System Tick ( 1 tick = 1 ms) */
#define platformSpiSelect() platformGpioClear( ST25R391X_SS_PORT, ST25R391X_SS_PIN ) /*!< SPI SS\CS: Chip|Slave Select */
#define platformSpiDeselect() platformGpioSet( ST25R391X_SS_PORT, ST25R391X_SS_PIN ) /*!< SPI SS\CS: Chip|Slave Deselect */
#define platformSpiTxRx( txBuf, rxBuf, len ) st25r3911_spiTxRx( (txBuf), (rxBuf), (len) ) /*!< SPI transceive */
#define platformI2CTx( txBuf, len ) /*!< I2C Transmit */
#define platformI2CRx( txBuf, len ) /*!< I2C Receive */
#define platformI2CStart() /*!< I2C Start condition */
#define platformI2CStop() /*!< I2C Stop condition */
#define platformI2CRepeatStart() /*!< I2C Repeat Start */
#define platformI2CSlaveAddrWR(add) /*!< I2C Slave address for Write operation */
#define platformI2CSlaveAddrRD(add) /*!< I2C Slave address for Read operation */
#define platformLog(...) ESP_LOGI("RFAL",__VA_ARGS__) /*!< Log method */
/*
******************************************************************************
* GLOBAL VARIABLES
******************************************************************************
*/
extern portMUX_TYPE CommProtectLock; /* Global Protection Counter provided per platform - instantiated in main.c */
/*
******************************************************************************
* RFAL FEATURES CONFIGURATION
******************************************************************************
*/
#define RFAL_FEATURE_LISTEN_MODE false /*!< Enable/Disable RFAL support for Listen Mode */
#define RFAL_FEATURE_WAKEUP_MODE true /*!< Enable/Disable RFAL support for the Wake-Up mode */
#define RFAL_FEATURE_NFCA true /*!< Enable/Disable RFAL support for NFC-A (ISO14443A) */
#define RFAL_FEATURE_NFCB true /*!< Enable/Disable RFAL support for NFC-B (ISO14443B) */
#define RFAL_FEATURE_NFCF false /*!< Enable/Disable RFAL support for NFC-F (FeliCa) */
#define RFAL_FEATURE_NFCV false /*!< Enable/Disable RFAL support for NFC-V (ISO15693) */
#define RFAL_FEATURE_T1T false /*!< Enable/Disable RFAL support for T1T (Topaz) */
#define RFAL_FEATURE_T2T true /*!< Enable/Disable RFAL support for T2T */
#define RFAL_FEATURE_T4T true /*!< Enable/Disable RFAL support for T4T */
#define RFAL_FEATURE_ST25TB false /*!< Enable/Disable RFAL support for ST25TB */
#define RFAL_FEATURE_ST25xV false /*!< Enable/Disable RFAL support for ST25TV/ST25DV */
#define RFAL_FEATURE_DYNAMIC_ANALOG_CONFIG false /*!< Enable/Disable Analog Configs to be dynamically updated (RAM) */
#define RFAL_FEATURE_DYNAMIC_POWER false /*!< Enable/Disable RFAL dynamic power support */
#define RFAL_FEATURE_ISO_DEP true /*!< Enable/Disable RFAL support for ISO-DEP (ISO14443-4) */
#define RFAL_FEATURE_ISO_DEP_POLL true /*!< Enable/Disable RFAL support for Poller mode (PCD) ISO-DEP (ISO14443-4) */
#define RFAL_FEATURE_ISO_DEP_LISTEN false /*!< Enable/Disable RFAL support for Listen mode (PICC) ISO-DEP (ISO14443-4) */
#define RFAL_FEATURE_NFC_DEP false /*!< Enable/Disable RFAL support for NFC-DEP (NFCIP1/P2P) */
#define RFAL_FEATURE_ISO_DEP_IBLOCK_MAX_LEN 256U /*!< ISO-DEP I-Block max length. Please use values as defined by rfalIsoDepFSx */
#define RFAL_FEATURE_ISO_DEP_APDU_MAX_LEN 1024U /*!< ISO-DEP APDU max length. Please use multiples of I-Block max length */
#endif /* PLATFORM_H */

View File

@ -1,656 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R3911 firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file
*
* \author Ulrich Herrmann
*
* \brief ST25R3911 high level interface
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "st25r3911.h"
#include "st25r3911_com.h"
#include "st25r3911_interrupt.h"
#include "utils.h"
/*
******************************************************************************
* LOCAL DEFINES
******************************************************************************
*/
#define ST25R3911_OSC_STABLE_TIMEOUT 10U /*!< Timeout for Oscillator to get stable, datasheet: 700us, take 5 ms */
#define ST25R3911_CA_TIMEOUT 10U /*!< Timeout for Collision Avoidance command */
#define ST25R3911_TOUT_CALIBRATE_CAP_SENSOR 4U /*!< Max duration Calibrate Capacitive Sensor command Datasheet: 3ms */
/*
******************************************************************************
* LOCAL CONSTANTS
******************************************************************************
*/
/*
******************************************************************************
* LOCAL VARIABLES
******************************************************************************
*/
static uint32_t st25r3911NoResponseTime_64fcs;
/*
******************************************************************************
* LOCAL FUNCTION PROTOTYPES
******************************************************************************
*/
static ReturnCode st25r3911ExecuteCommandAndGetResult(uint8_t cmd, uint8_t resreg, uint8_t sleeptime, uint8_t* result);
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
void st25r3911TxRxOn( void )
{
st25r3911SetRegisterBits(ST25R3911_REG_OP_CONTROL, (ST25R3911_REG_OP_CONTROL_rx_en | ST25R3911_REG_OP_CONTROL_tx_en) );
}
void st25r3911TxRxOff( void )
{
st25r3911ClrRegisterBits(ST25R3911_REG_OP_CONTROL, (ST25R3911_REG_OP_CONTROL_rx_en | ST25R3911_REG_OP_CONTROL_tx_en) );
}
void st25r3911OscOn( void )
{
/* Check if oscillator is already turned on and stable */
/* Use ST25R3911_REG_OP_CONTROL_en instead of ST25R3911_REG_AUX_DISPLAY_osc_ok to be on the safe side */
if( !st25r3911CheckReg( ST25R3911_REG_OP_CONTROL, ST25R3911_REG_OP_CONTROL_en, ST25R3911_REG_OP_CONTROL_en ) )
{
/* Clear any eventual previous oscillator IRQ */
st25r3911GetInterrupt( ST25R3911_IRQ_MASK_OSC );
/* enable oscillator frequency stable interrupt */
st25r3911EnableInterrupts(ST25R3911_IRQ_MASK_OSC);
/* enable oscillator and regulator output */
st25r3911ModifyRegister(ST25R3911_REG_OP_CONTROL, 0x00, ST25R3911_REG_OP_CONTROL_en);
/* wait for the oscillator interrupt */
st25r3911WaitForInterruptsTimed(ST25R3911_IRQ_MASK_OSC, ST25R3911_OSC_STABLE_TIMEOUT);
st25r3911DisableInterrupts(ST25R3911_IRQ_MASK_OSC);
}
}
void st25r3911Initialize(void)
{
uint16_t vdd_mV;
/* first, reset the st25r3911 */
st25r3911ExecuteCommand(ST25R3911_CMD_SET_DEFAULT);
/* Set Operation Control Register to default value */
st25r3911WriteRegister(ST25R3911_REG_OP_CONTROL, 0x00);
/* enable pull downs on miso line */
st25r3911ModifyRegister(ST25R3911_REG_IO_CONF2, 0,
ST25R3911_REG_IO_CONF2_miso_pd1 |
ST25R3911_REG_IO_CONF2_miso_pd2);
/* after reset all interrupts are enabled. so disable them at first */
st25r3911DisableInterrupts(ST25R3911_IRQ_MASK_ALL);
/* and clear them, just to be sure... */
st25r3911ClearInterrupts();
st25r3911OscOn();
/* Measure vdd and set sup3V bit accordingly */
vdd_mV = st25r3911MeasureVoltage(ST25R3911_REG_REGULATOR_CONTROL_mpsv_vdd);
st25r3911ModifyRegister(ST25R3911_REG_IO_CONF2,
ST25R3911_REG_IO_CONF2_sup3V,
(uint8_t)((vdd_mV < 3600U)?ST25R3911_REG_IO_CONF2_sup3V:0U));
/* Make sure Transmitter and Receiver are disabled */
st25r3911TxRxOff();
return;
}
void st25r3911Deinitialize(void)
{
st25r3911DisableInterrupts(ST25R3911_IRQ_MASK_ALL);
/* Disabe Tx and Rx, Keep OSC */
st25r3911TxRxOff();
return;
}
ReturnCode st25r3911AdjustRegulators(uint16_t* result_mV)
{
uint8_t result;
uint8_t io_conf2;
ReturnCode err = ERR_NONE;
/* Reset logic and set regulated voltages to be defined by result of Adjust Regulators command */
st25r3911SetRegisterBits( ST25R3911_REG_REGULATOR_CONTROL, ST25R3911_REG_REGULATOR_CONTROL_reg_s );
st25r3911ClrRegisterBits( ST25R3911_REG_REGULATOR_CONTROL, ST25R3911_REG_REGULATOR_CONTROL_reg_s );
st25r3911ExecuteCommandAndGetResult(ST25R3911_CMD_ADJUST_REGULATORS,
ST25R3911_REG_REGULATOR_RESULT,
5,
&result);
st25r3911ReadRegister(ST25R3911_REG_IO_CONF2, &io_conf2);
result >>= ST25R3911_REG_REGULATOR_RESULT_shift_reg;
result -= 5U;
if (result_mV != NULL)
{
if((io_conf2 & ST25R3911_REG_IO_CONF2_sup3V) != 0U)
{
*result_mV = 2400;
*result_mV += (uint16_t)result * 100U;
}
else
{
*result_mV = 3900;
*result_mV += (uint16_t)result * 120U;
}
}
return err;
}
void st25r3911MeasureAmplitude(uint8_t* result)
{
st25r3911ExecuteCommandAndGetResult(ST25R3911_CMD_MEASURE_AMPLITUDE,
ST25R3911_REG_AD_RESULT,
10,
result);
}
void st25r3911MeasurePhase(uint8_t* result)
{
st25r3911ExecuteCommandAndGetResult(ST25R3911_CMD_MEASURE_PHASE,
ST25R3911_REG_AD_RESULT,
10,
result);
}
void st25r3911MeasureCapacitance(uint8_t* result)
{
st25r3911ExecuteCommandAndGetResult(ST25R3911_CMD_MEASURE_CAPACITANCE,
ST25R3911_REG_AD_RESULT,
10,
result);
}
void st25r3911CalibrateAntenna(uint8_t* result)
{
st25r3911ExecuteCommandAndGetResult(ST25R3911_CMD_CALIBRATE_ANTENNA,
ST25R3911_REG_ANT_CAL_RESULT,
10,
result);
}
void st25r3911CalibrateModulationDepth(uint8_t* result)
{
st25r3911ExecuteCommandAndGetResult(ST25R3911_CMD_CALIBRATE_MODULATION,
ST25R3911_REG_AM_MOD_DEPTH_RESULT,
10,
result);
}
ReturnCode st25r3911CalibrateCapacitiveSensor(uint8_t* result)
{
ReturnCode ret;
uint8_t res;
/* Clear Manual calibration values to enable automatic calibration mode */
st25r3911ClrRegisterBits( ST25R3911_REG_CAP_SENSOR_CONTROL, ST25R3916_REG_CAP_SENSOR_CONTROL_mask_cs_mcal );
/* Execute automatic calibration */
ret = st25r3911ExecuteCommandAndGetResult( ST25R3911_CMD_CALIBRATE_C_SENSOR, ST25R3911_REG_CAP_SENSOR_RESULT, ST25R3911_TOUT_CALIBRATE_CAP_SENSOR, &res );
/* Check wether the calibration was successull */
if( ((res & ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal_end) != ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal_end) ||
((res & ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal_err) == ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal_err) || (ret != ERR_NONE) )
{
return ERR_IO;
}
if( result != NULL )
{
(*result) = (uint8_t)(res >> ST25R3911_REG_CAP_SENSOR_CONTROL_shift_cs_mcal);
}
return ERR_NONE;
}
ReturnCode st25r3911SetBitrate(uint8_t txRate, uint8_t rxRate)
{
uint8_t reg;
st25r3911ReadRegister(ST25R3911_REG_BIT_RATE, &reg);
if (rxRate != ST25R3911_BR_DO_NOT_SET)
{
if(rxRate > ST25R3911_BR_3390)
{
return ERR_PARAM;
}
else
{
reg = (uint8_t)(reg & ~ST25R3911_REG_BIT_RATE_mask_rxrate); /* MISRA 10.3 */
reg |= rxRate << ST25R3911_REG_BIT_RATE_shift_rxrate;
}
}
if (txRate != ST25R3911_BR_DO_NOT_SET)
{
if(txRate > ST25R3911_BR_6780)
{
return ERR_PARAM;
}
else
{
reg = (uint8_t)(reg & ~ST25R3911_REG_BIT_RATE_mask_txrate); /* MISRA 10.3 */
reg |= txRate<<ST25R3911_REG_BIT_RATE_shift_txrate;
}
}
st25r3911WriteRegister(ST25R3911_REG_BIT_RATE, reg);
return ERR_NONE;
}
uint8_t st25r3911MeasurePowerSupply( uint8_t mpsv )
{
uint8_t result;
/* Set the source of direct command: Measure Power Supply Voltage */
st25r3911ChangeRegisterBits( ST25R3911_REG_REGULATOR_CONTROL, ST25R3911_REG_REGULATOR_CONTROL_mask_mpsv, mpsv );
/* Execute command: Measure Power Supply Voltage */
st25r3911ExecuteCommandAndGetResult( ST25R3911_CMD_MEASURE_VDD, ST25R3911_REG_AD_RESULT, 10, &result);
return result;
}
uint16_t st25r3911MeasureVoltage(uint8_t mpsv)
{
uint8_t result;
uint16_t mV;
result = st25r3911MeasurePowerSupply( mpsv );
mV = ((uint16_t)result) * 23U;
mV += ((((uint16_t)result) * 438U) + 500U) / 1000U;
return mV;
}
uint8_t st25r3911GetNumFIFOLastBits(void)
{
uint8_t reg;
st25r3911ReadRegister( ST25R3911_REG_FIFO_RX_STATUS2, &reg );
return ((reg & ST25R3911_REG_FIFO_RX_STATUS2_mask_fifo_lb) >> ST25R3911_REG_FIFO_RX_STATUS2_shift_fifo_lb);
}
uint32_t st25r3911GetNoResponseTime_64fcs(void)
{
return st25r3911NoResponseTime_64fcs;
}
void st25r3911StartGPTimer_8fcs(uint16_t gpt_8fcs, uint8_t trigger_source)
{
st25r3911SetGPTime_8fcs(gpt_8fcs);
st25r3911ModifyRegister(ST25R3911_REG_GPT_CONTROL,
ST25R3911_REG_GPT_CONTROL_gptc_mask,
trigger_source);
if (trigger_source == 0U)
{
st25r3911ExecuteCommand(ST25R3911_CMD_START_GP_TIMER);
}
return;
}
void st25r3911SetGPTime_8fcs(uint16_t gpt_8fcs)
{
st25r3911WriteRegister(ST25R3911_REG_GPT1, (uint8_t)(gpt_8fcs >> 8));
st25r3911WriteRegister(ST25R3911_REG_GPT2, (uint8_t)(gpt_8fcs & 0xffU));
return;
}
bool st25r3911CheckReg( uint8_t reg, uint8_t mask, uint8_t value )
{
uint8_t regVal;
regVal = 0;
st25r3911ReadRegister( reg, &regVal );
return ((regVal & mask) == value );
}
bool st25r3911CheckChipID( uint8_t *rev )
{
uint8_t ID;
ID = 0;
st25r3911ReadRegister( ST25R3911_REG_IC_IDENTITY, &ID );
platformLog("Chip ID: 0x%02x", ID);
/* Check if IC Identity Register contains ST25R3911's IC type code */
if( (ID & ST25R3911_REG_IC_IDENTITY_mask_ic_type) != ST25R3911_REG_IC_IDENTITY_ic_type )
{
return false;
}
if(rev != NULL)
{
*rev = (ID & ST25R3911_REG_IC_IDENTITY_mask_ic_rev);
}
return true;
}
ReturnCode st25r3911SetNoResponseTime_64fcs(uint32_t nrt_64fcs)
{
ReturnCode err = ERR_NONE;
uint8_t nrt_step = 0;
uint32_t noResponseTime_64fcs = nrt_64fcs; /* MISRA 17.8: Use intermediate variable */
st25r3911NoResponseTime_64fcs = noResponseTime_64fcs;
if (noResponseTime_64fcs > (uint32_t)0xFFFFU)
{
nrt_step = ST25R3911_REG_GPT_CONTROL_nrt_step;
noResponseTime_64fcs = (noResponseTime_64fcs + 63U) / 64U;
if (noResponseTime_64fcs > (uint32_t)0xFFFFU)
{
noResponseTime_64fcs = 0xFFFFU;
err = ERR_PARAM;
}
st25r3911NoResponseTime_64fcs = 64U * noResponseTime_64fcs;
}
st25r3911ModifyRegister(ST25R3911_REG_GPT_CONTROL, ST25R3911_REG_GPT_CONTROL_nrt_step, nrt_step);
st25r3911WriteRegister(ST25R3911_REG_NO_RESPONSE_TIMER1, (uint8_t)(noResponseTime_64fcs >> 8));
st25r3911WriteRegister(ST25R3911_REG_NO_RESPONSE_TIMER2, (uint8_t)(noResponseTime_64fcs & 0xffU));
return err;
}
ReturnCode st25r3911SetStartNoResponseTime_64fcs(uint32_t nrt_64fcs)
{
ReturnCode err;
err = st25r3911SetNoResponseTime_64fcs( nrt_64fcs );
if(err == ERR_NONE)
{
st25r3911ExecuteCommand(ST25R3911_CMD_START_NO_RESPONSE_TIMER);
}
return err;
}
ReturnCode st25r3911PerformCollisionAvoidance( uint8_t FieldONCmd, uint8_t pdThreshold, uint8_t caThreshold, uint8_t nTRFW )
{
uint8_t treMask;
uint32_t irqs;
if( (FieldONCmd != ST25R3911_CMD_INITIAL_RF_COLLISION) &&
(FieldONCmd != ST25R3911_CMD_RESPONSE_RF_COLLISION_0) &&
(FieldONCmd != ST25R3911_CMD_RESPONSE_RF_COLLISION_N) )
{
return ERR_PARAM;
}
/* Check if new thresholds are to be applied */
if( (pdThreshold != ST25R3911_THRESHOLD_DO_NOT_SET) || (caThreshold != ST25R3911_THRESHOLD_DO_NOT_SET) )
{
treMask = 0;
if(pdThreshold != ST25R3911_THRESHOLD_DO_NOT_SET)
{
treMask |= ST25R3911_REG_FIELD_THRESHOLD_mask_trg;
}
if(caThreshold != ST25R3911_THRESHOLD_DO_NOT_SET)
{
treMask |= ST25R3911_REG_FIELD_THRESHOLD_mask_rfe;
}
/* Set Detection Threshold and|or Collision Avoidance Threshold */
st25r3911ChangeRegisterBits( ST25R3911_REG_FIELD_THRESHOLD, treMask, (pdThreshold & ST25R3911_REG_FIELD_THRESHOLD_mask_trg) | (caThreshold & ST25R3911_REG_FIELD_THRESHOLD_mask_rfe ) );
}
/* Set n x TRFW */
st25r3911ModifyRegister(ST25R3911_REG_AUX, ST25R3911_REG_AUX_mask_nfc_n, (nTRFW & ST25R3911_REG_AUX_mask_nfc_n) );
/* Enable and clear CA specific interrupts and execute command */
st25r3911EnableInterrupts( (ST25R3911_IRQ_MASK_CAC | ST25R3911_IRQ_MASK_CAT) );
st25r3911GetInterrupt( (ST25R3911_IRQ_MASK_CAC | ST25R3911_IRQ_MASK_CAT) );
st25r3911ExecuteCommand(FieldONCmd);
irqs = st25r3911WaitForInterruptsTimed(ST25R3911_IRQ_MASK_CAC | ST25R3911_IRQ_MASK_CAT, ST25R3911_CA_TIMEOUT );
/* Clear any previous External Field events and disable CA specific interrupts */
st25r3911GetInterrupt( (ST25R3911_IRQ_MASK_EOF | ST25R3911_IRQ_MASK_EON) );
st25r3911DisableInterrupts(ST25R3911_IRQ_MASK_CAC | ST25R3911_IRQ_MASK_CAT);
if((ST25R3911_IRQ_MASK_CAC & irqs) != 0U) /* Collision occurred */
{
return ERR_RF_COLLISION;
}
if((ST25R3911_IRQ_MASK_CAT & irqs) != 0U) /* No Collision detected, Field On */
{
return ERR_NONE;
}
/* No interrupt detected */
return ERR_INTERNAL;
}
ReturnCode st25r3911GetRegsDump(uint8_t* resRegDump, uint8_t* sizeRegDump)
{
uint8_t regIt;
uint8_t regDump[ST25R3911_REG_IC_IDENTITY+1U];
if(!sizeRegDump || !resRegDump)
{
return ERR_PARAM;
}
for( regIt = ST25R3911_REG_IO_CONF1; regIt < SIZEOF_ARRAY(regDump); regIt++ )
{
st25r3911ReadRegister(regIt, &regDump[regIt] );
}
*sizeRegDump = MIN(*sizeRegDump, regIt);
if( *sizeRegDump > 0U ) /* MISRA 21.18 */
{
ST_MEMCPY(resRegDump, regDump, *sizeRegDump );
}
return ERR_NONE;
}
void st25r3911SetNumTxBits( uint32_t nBits )
{
st25r3911WriteRegister(ST25R3911_REG_NUM_TX_BYTES2, (uint8_t)((nBits >> 0) & 0xffU));
st25r3911WriteRegister(ST25R3911_REG_NUM_TX_BYTES1, (uint8_t)((nBits >> 8) & 0xffU));
}
bool st25r3911IsCmdValid( uint8_t cmd )
{
if( !((cmd >= ST25R3911_CMD_SET_DEFAULT) && (cmd <= ST25R3911_CMD_ANALOG_PRESET)) &&
!((cmd >= ST25R3911_CMD_MASK_RECEIVE_DATA) && (cmd <= ST25R3911_CMD_CLEAR_RSSI)) &&
!((cmd >= ST25R3911_CMD_TRANSPARENT_MODE) && (cmd <= ST25R3911_CMD_START_NO_RESPONSE_TIMER)) &&
!((cmd >= ST25R3911_CMD_TEST_CLEARA) && (cmd <= ST25R3911_CMD_FUSE_PPROM)) )
{
return false;
}
return true;
}
ReturnCode st25r3911StreamConfigure(const struct st25r3911StreamConfig *config)
{
uint8_t smd = 0;
uint8_t mode;
if (config->useBPSK != 0U)
{
mode = ST25R3911_REG_MODE_om_bpsk_stream;
if ((config->din<2U) || (config->din>4U)) /* not in fc/4 .. fc/16 */
{
return ERR_PARAM;
}
smd |= (4U - config->din) << ST25R3911_REG_STREAM_MODE_shift_scf;
}
else
{
mode = ST25R3911_REG_MODE_om_subcarrier_stream;
if ((config->din<3U) || (config->din>6U)) /* not in fc/8 .. fc/64 */
{
return ERR_PARAM;
}
smd |= (6U - config->din) << ST25R3911_REG_STREAM_MODE_shift_scf;
if (config->report_period_length == 0U)
{
return ERR_PARAM;
}
}
if ((config->dout<1U) || (config->dout>7U)) /* not in fc/2 .. fc/128 */
{
return ERR_PARAM;
}
smd |= (7U - config->dout) << ST25R3911_REG_STREAM_MODE_shift_stx;
if (config->report_period_length > 3U)
{
return ERR_PARAM;
}
smd |= config->report_period_length << ST25R3911_REG_STREAM_MODE_shift_scp;
st25r3911WriteRegister(ST25R3911_REG_STREAM_MODE, smd);
st25r3911ChangeRegisterBits(ST25R3911_REG_MODE, ST25R3911_REG_MODE_mask_om, mode);
return ERR_NONE;
}
/*******************************************************************************/
ReturnCode st25r3911GetRSSI( uint16_t *amRssi, uint16_t *pmRssi )
{
/*******************************************************************************/
/* MISRA 8.9 An object should be defined at block scope if its identifier only appears in a single function */
/*< ST25R3911 RSSI Display Reg values:0 1 2 3 4 5 6 7 8 9 a b c d e f */
const uint16_t st25r3911Rssi2mV[] = { 0 ,20 ,27 ,37 ,52 ,72 ,99 ,136 ,190 ,262 ,357 ,500 ,686 ,950, 0, 0 };
/* ST25R3911 2/3 stage gain reduction [dB] 0 0 0 0 0 3 6 9 12 15 18 na na na na na */
const uint16_t st25r3911Gain2Percent[] = { 100, 100, 100, 100, 100, 141, 200, 281, 398, 562, 794, 1, 1, 1, 1, 1 };
/*******************************************************************************/
uint8_t rssi;
uint8_t gainRed;
st25r3911ReadRegister( ST25R3911_REG_RSSI_RESULT, &rssi );
st25r3911ReadRegister( ST25R3911_REG_GAIN_RED_STATE, &gainRed );
if( amRssi != NULL )
{
*amRssi = (uint16_t) ( ( (uint32_t)st25r3911Rssi2mV[ (rssi >> ST25R3911_REG_RSSI_RESULT_shift_rssi_am) ] * (uint32_t)st25r3911Gain2Percent[ (gainRed >> ST25R3911_REG_GAIN_RED_STATE_shift_gs_am) ] ) / 100U );
}
if( pmRssi != NULL )
{
*pmRssi = (uint16_t) ( ( (uint32_t)st25r3911Rssi2mV[ (rssi & ST25R3911_REG_RSSI_RESULT_mask_rssi_pm) ] * (uint32_t)st25r3911Gain2Percent[ (gainRed & ST25R3911_REG_GAIN_RED_STATE_mask_gs_pm) ] ) / 100U );
}
return ERR_NONE;
}
/*
******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************
*/
/*!
*****************************************************************************
* \brief Executes a direct command and returns the result
*
* This function executes the direct command given by \a cmd waits for
* \a sleeptime for I_dct and returns the result read from register \a resreg.
* No checking of the validity of the cmd is performed.
*
* \param[in] cmd: direct command to execute.
* \param[in] resreg: Address of the register containing the result.
* \param[in] sleeptime: time in milliseconds to wait before reading the result.
* \param[out] result: 8 bit long result
*
*****************************************************************************
*/
static ReturnCode st25r3911ExecuteCommandAndGetResult(uint8_t cmd, uint8_t resreg, uint8_t sleeptime, uint8_t* result)
{
st25r3911EnableInterrupts(ST25R3911_IRQ_MASK_DCT);
st25r3911GetInterrupt(ST25R3911_IRQ_MASK_DCT);
st25r3911ExecuteCommand(cmd);
st25r3911WaitForInterruptsTimed(ST25R3911_IRQ_MASK_DCT, sleeptime);
st25r3911DisableInterrupts(ST25R3911_IRQ_MASK_DCT);
/* read out the result if the pointer is not NULL */
if (result != NULL)
{
st25r3911ReadRegister(resreg, result);
}
return ERR_NONE;
}

View File

@ -1,601 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R3911 firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file
*
* \author Ulrich Herrmann
*
* \brief ST25R3911 declaration file
*
* API:
* - Initialize ST25R3911 driver: #st25r3911Initialize
* - Deinitialize ST25R3911 driver: #st25r3911Deinitialize
*
*
* \addtogroup RFAL
* @{
*
* \addtogroup RFAL-HAL
* \brief RFAL Hardware Abstraction Layer
* @{
*
* \addtogroup ST25R3911
* \brief RFAL ST25R3911 Driver
* @{
*
* \addtogroup ST25R3911_Driver
* \brief RFAL ST25R3911 Driver
* @{
*
*/
#ifndef ST25R3911_H
#define ST25R3911_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
#include "st_errno.h"
/*
******************************************************************************
* GLOBAL DATATYPES
******************************************************************************
*/
/*! Parameters how the stream mode should work */
struct st25r3911StreamConfig {
uint8_t useBPSK; /*!< 0: subcarrier, 1:BPSK */
uint8_t din; /*!< the divider for the in subcarrier frequency: fc/2^din */
uint8_t dout; /*!< the divider for the in subcarrier frequency fc/2^dout */
uint8_t report_period_length; /*!< the length of the reporting period 2^report_period_length */
};
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define ST25R3911_FDT_NONE 0x00U /*!< Value indicating not to perform FDT */
#define MS_TO_64FCS(A) ((A) * 212U) /*!< Converts from ms to 64/fc steps */
#define MS_FROM_64FCS(A) ((A) / 212U) /*!< Converts from 64/fc steps to ms */
/* ST25R3911 direct commands */
#define ST25R3911_CMD_SET_DEFAULT 0xC1U /*!< Puts the chip in default state (same as after power-up) */
#define ST25R3911_CMD_CLEAR_FIFO 0xC2U /*!< Stops all activities and clears FIFO */
#define ST25R3911_CMD_TRANSMIT_WITH_CRC 0xC4U /*!< Transmit with CRC */
#define ST25R3911_CMD_TRANSMIT_WITHOUT_CRC 0xC5U /*!< Transmit without CRC */
#define ST25R3911_CMD_TRANSMIT_REQA 0xC6U /*!< Transmit REQA */
#define ST25R3911_CMD_TRANSMIT_WUPA 0xC7U /*!< Transmit WUPA */
#define ST25R3911_CMD_INITIAL_RF_COLLISION 0xC8U /*!< NFC transmit with Initial RF Collision Avoidance */
#define ST25R3911_CMD_RESPONSE_RF_COLLISION_N 0xC9U /*!< NFC transmit with Response RF Collision Avoidance */
#define ST25R3911_CMD_RESPONSE_RF_COLLISION_0 0xCAU /*!< NFC transmit with Response RF Collision Avoidance with n=0 */
#define ST25R3911_CMD_NORMAL_NFC_MODE 0xCBU /*!< NFC switch to normal NFC mode */
#define ST25R3911_CMD_ANALOG_PRESET 0xCCU /*!< Analog Preset */
#define ST25R3911_CMD_MASK_RECEIVE_DATA 0xD0U /*!< Mask recive data */
#define ST25R3911_CMD_UNMASK_RECEIVE_DATA 0xD1U /*!< Unmask recive data */
#define ST25R3911_CMD_MEASURE_AMPLITUDE 0xD3U /*!< Measure singal amplitude on RFI inputs */
#define ST25R3911_CMD_SQUELCH 0xD4U /*!< Squelch */
#define ST25R3911_CMD_CLEAR_SQUELCH 0xD5U /*!< Clear Squelch */
#define ST25R3911_CMD_ADJUST_REGULATORS 0xD6U /*!< Adjust regulators */
#define ST25R3911_CMD_CALIBRATE_MODULATION 0xD7U /*!< Calibrate modulation depth */
#define ST25R3911_CMD_CALIBRATE_ANTENNA 0xD8U /*!< Calibrate antenna */
#define ST25R3911_CMD_MEASURE_PHASE 0xD9U /*!< Measure phase between RFO and RFI signal */
#define ST25R3911_CMD_CLEAR_RSSI 0xDAU /*!< clear RSSI bits and restart the measurement */
#define ST25R3911_CMD_TRANSPARENT_MODE 0xDCU /*!< Transparent mode */
#define ST25R3911_CMD_CALIBRATE_C_SENSOR 0xDDU /*!< Calibrate the capacitive sensor */
#define ST25R3911_CMD_MEASURE_CAPACITANCE 0xDEU /*!< Measure capacitance */
#define ST25R3911_CMD_MEASURE_VDD 0xDFU /*!< Measure power supply voltage */
#define ST25R3911_CMD_START_GP_TIMER 0xE0U /*!< Start the general purpose timer */
#define ST25R3911_CMD_START_WUP_TIMER 0xE1U /*!< Start the wake-up timer */
#define ST25R3911_CMD_START_MASK_RECEIVE_TIMER 0xE2U /*!< Start the mask-receive timer */
#define ST25R3911_CMD_START_NO_RESPONSE_TIMER 0xE3U /*!< Start the no-repsonse timer */
#define ST25R3911_CMD_TEST_CLEARA 0xFAU /*!< Clear Test register */
#define ST25R3911_CMD_TEST_CLEARB 0xFBU /*!< Clear Test register */
#define ST25R3911_CMD_TEST_ACCESS 0xFCU /*!< Enable R/W access to the test registers */
#define ST25R3911_CMD_LOAD_PPROM 0xFDU /*!< Load data from the poly fuses to RAM */
#define ST25R3911_CMD_FUSE_PPROM 0xFEU /*!< Fuse poly fuses with data from the RAM */
#define ST25R3911_FIFO_DEPTH 96U /*!< Depth of FIFO */
#define ST25R3911_THRESHOLD_DO_NOT_SET 0xFFU /*!< Indicates not to change this Threshold */
#define ST25R3911_BR_DO_NOT_SET 0xFFU /*!< Indicates not to change this Bit Rate */
#define ST25R3911_BR_106 0x00U /*!< ST25R3911 Bit Rate 106 kbit/s (fc/128) */
#define ST25R3911_BR_212 0x01U /*!< ST25R3911 Bit Rate 212 kbit/s (fc/64) */
#define ST25R3911_BR_424 0x02U /*!< ST25R3911 Bit Rate 424 kbit/s (fc/32) */
#define ST25R3911_BR_848 0x03U /*!< ST25R3911 Bit Rate 848 kbit/s (fc/16) */
#define ST25R3911_BR_1695 0x04U /*!< ST25R3911 Bit Rate 1696 kbit/s (fc/8) */
#define ST25R3911_BR_3390 0x05U /*!< ST25R3911 Bit Rate 3390 kbit/s (fc/4) */
#define ST25R3911_BR_6780 0x06U /*!< ST25R3911 Bit Rate 6780 kbit/s (fc/2) */
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
/*! Checks if General Purpose Timer is still running by reading gpt_on flag */
#define st25r3911IsGPTRunning( ) ( st25r3911CheckReg(ST25R3911_REG_REGULATOR_RESULT, ST25R3911_REG_REGULATOR_RESULT_gpt_on, ST25R3911_REG_REGULATOR_RESULT_gpt_on) )
/*! Checks if CRC is configured to be in FIFO */
#define st25r3911IsCRCinFIFO( ) ( st25r3911CheckReg(ST25R3911_REG_AUX, ST25R3911_REG_AUX_crc_2_fifo, ST25R3911_REG_AUX_crc_2_fifo) )
/*! Checks if External Filed is detected by reading ST25R3911 External Field
* Detector output */
#define st25r3911IsExtFieldOn() ( st25r3911CheckReg(ST25R3911_REG_AUX_DISPLAY, ST25R3911_REG_AUX_DISPLAY_efd_o, ST25R3911_REG_AUX_DISPLAY_efd_o ) )
/*! Checks if Transmitter is enabled (Field On) */
#define st25r3911IsTxEnabled() ( st25r3911CheckReg(ST25R3911_REG_OP_CONTROL, ST25R3911_REG_OP_CONTROL_tx_en, ST25R3911_REG_OP_CONTROL_tx_en ) )
/*! Turn Off Tx (Field Off) */
#define st25r3911TxOff() st25r3911ClrRegisterBits(ST25R3911_REG_OP_CONTROL, ST25R3911_REG_OP_CONTROL_tx_en );
/*! Checks if last FIFO byte is complete */
#define st25r3911IsLastFIFOComplete() st25r3911CheckReg( ST25R3911_REG_FIFO_RX_STATUS2, ST25R3911_REG_FIFO_RX_STATUS2_mask_fifo_lb, 0 )
/*! Checks if the Oscillator is enabled */
#define st25r3911IsOscOn() st25r3911CheckReg( ST25R3911_REG_OP_CONTROL, ST25R3911_REG_OP_CONTROL_en, ST25R3911_REG_OP_CONTROL_en )
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief Turn on Oscillator and Regulator
*
* This function turn on oscillator and regulator and wait for the oscillator to
* become stable.
*
*****************************************************************************
*/
extern void st25r3911OscOn( void );
/*!
*****************************************************************************
* \brief Turn On Tx and Rx
*
* This function turns On Tx and Rx (Field On)
*
*****************************************************************************
*/
extern void st25r3911TxRxOn( void );
/*!
*****************************************************************************
* \brief Turn Off Tx and Rx
*
* This function turns Off Tx and Rx (Field Off)
*
*****************************************************************************
*/
extern void st25r3911TxRxOff( void );
/*!
*****************************************************************************
* \brief Initialise ST25R3911 driver
*
* This function initialises the ST25R3911 driver.
*
*****************************************************************************
*/
extern void st25r3911Initialize( void );
/*!
*****************************************************************************
* \brief Deinitialize ST25R3911 driver
*
* Calling this function deinitializes the ST25R3911 driver.
*
*****************************************************************************
*/
extern void st25r3911Deinitialize( void );
/*!
*****************************************************************************
* \brief Sets the bitrate registers
*
* This function sets the bitrate register for rx and tx
*
* \param txRate : speed is 2^txrate * 106 kb/s
* 0xff : don't set txrate
* \param rxRate : speed is 2^rxrate * 106 kb/s
* 0xff : don't set rxrate
*
* \return ERR_NONE : No error, both bit rates were set
* \return ERR_PARAM: At least one bit rate was invalid
*
*****************************************************************************
*/
extern ReturnCode st25r3911SetBitrate( uint8_t txRate, uint8_t rxRate );
/*!
*****************************************************************************
* \brief Adjusts supply regulators according to the current supply voltage
*
* On this function the power level is measured in maximum load conditions and
* the regulated voltage reference is set to 250mV below this level.
* Execution of this function lasts arround 5ms.
*
* The regulated voltages will be set to the result of Adjust Regulators
*
* \param [out] result_mV : Result of calibration in milliVolts.
*
* \return ERR_IO : Error during communication with ST25R3911.
* \return ERR_NONE : No error.
*
*****************************************************************************
*/
extern ReturnCode st25r3911AdjustRegulators( uint16_t* result_mV );
/*!
*****************************************************************************
* \brief Measure Amplitude
*
* This function measured the amplitude on the RFI inputs and stores the
* result in parameter \a result.
*
* \param[out] result: 8 bit long result of RF measurement.
*
*****************************************************************************
*/
extern void st25r3911MeasureAmplitude( uint8_t* result );
/*!
*****************************************************************************
* \brief Measure Capacitance
*
* This function performs the capacitance measurement and stores the
* result in parameter \a result.
*
* \param[out] result: 8 bit long result of RF measurement.
*
*****************************************************************************
*/
extern void st25r3911MeasureCapacitance( uint8_t* result );
/*!
*****************************************************************************
* \brief Measure Voltage
*
* This function measures the voltage on one of VDD and VSP_*
* result in parameter \a result.
*
* \param[in] mpsv : one of ST25R3911_REG_REGULATOR_CONTROL_mpsv_vdd
* ST25R3911_REG_REGULATOR_CONTROL_mpsv_vsp_rf
* ST25R3911_REG_REGULATOR_CONTROL_mpsv_vsp_a
* or ST25R3911_REG_REGULATOR_CONTROL_mpsv_vsp_d
*
* \return the measured voltage raw values
*
*****************************************************************************
*/
extern uint8_t st25r3911MeasurePowerSupply( uint8_t mpsv );
/*!
*****************************************************************************
* \brief Measure Voltage
*
* This function measures the voltage on one of VDD and VSP_*
* result in parameter \a result.
*
* \param[in] mpsv : one of ST25R3911_REG_REGULATOR_CONTROL_mpsv_vdd
* ST25R3911_REG_REGULATOR_CONTROL_mpsv_vsp_rf
* ST25R3911_REG_REGULATOR_CONTROL_mpsv_vsp_a
* or ST25R3911_REG_REGULATOR_CONTROL_mpsv_vsp_d
*
* \return the measured voltage in mV
*
*****************************************************************************
*/
extern uint16_t st25r3911MeasureVoltage( uint8_t mpsv );
/*!
*****************************************************************************
* \brief Calibrate antenna
*
* This function is used to calibrate the antenna using a special sequence.
* The result is stored in the \a result parameter.
*
* \param[out] result: 8 bit long result of antenna calibration algorithm.
*
*****************************************************************************
*/
extern void st25r3911CalibrateAntenna( uint8_t* result );
/*!
*****************************************************************************
* \brief Measure Phase
*
* This function performs a Phase measurement.
* The result is stored in the \a result parameter.
*
* \param[out] result: 8 bit long result of the measurement.
*
*****************************************************************************
*/
extern void st25r3911MeasurePhase( uint8_t* result );
/*!
*****************************************************************************
* \brief Calibrate modulation depth
*
* This function is used to calibrate the modulation depth using a special sequence.
* The result is stored in the \a result parameter.
*
* \param[out] result: 8 bit long result of antenna calibration algorithm.
*
*****************************************************************************
*/
extern void st25r3911CalibrateModulationDepth( uint8_t* result );
/*!
*****************************************************************************
* \brief Calibrate Capacitive Sensor
*
* This function performs automatic calibration of the capacitive sensor
* and stores the result in parameter \a result.
*
* \warning To avoid interference with Xtal oscillator and reader magnetic
* field, it is strongly recommended to perform calibration
* in Power-down mode only.
* This method does not modify the Oscillator nor transmitter state,
* these should be configured before by user.
*
* \param[out] result: 5 bit long result of the calibration.
* Binary weighted, step 0.1 pF, max 3.1 pF
*
*
* \return ERR_PARAM : Invalid parameter
* \return ERR_IO : The calibration was not successful
* \return ERR_NONE : No error
*
*****************************************************************************
*/
extern ReturnCode st25r3911CalibrateCapacitiveSensor( uint8_t* result );
/*!
*****************************************************************************
* \brief set no response time
*
* This function executes sets the no response time to the defines value
*
* \param nrt_64fcs : no response time in 64/fc = 4.72us
* completion interrupt
*
* \return ERR_PARAM : if time is too large
*/
extern ReturnCode st25r3911SetNoResponseTime_64fcs( uint32_t nrt_64fcs );
/*!
*****************************************************************************
* \brief set no response time
*
* This function executes sets and immediately start the no response timer
* to the defines value
* This is used when needs to add more time before timeout whitout Tx
*
* \param nrt_64fcs : no response time in 64/fc = 4.72us
* completion interrupt
*
* \return ERR_PARAM : if time is too large
*/
extern ReturnCode st25r3911SetStartNoResponseTime_64fcs( uint32_t nrt_64fcs );
/*!
*****************************************************************************
* \brief Perform Collision Avoidance
*
* Performs Collision Avoidance with the given threshold and with the
* n number of TRFW
*
* \param[in] FieldONCmd : Field ON command to be executed ST25R3911_CMD_INITIAL_RF_COLLISION
* or ST25R3911_CMD_RESPONSE_RF_COLLISION_0/N
* \param[in] pdThreshold : Peer Detection Threshold (ST25R3916_REG_FIELD_THRESHOLD_trg_xx)
* 0xff : don't set Threshold (ST25R3916_THRESHOLD_DO_NOT_SET)
* \param[in] caThreshold : Collision Avoidance Threshold (ST25R3916_REG_FIELD_THRESHOLD_rfe_xx)
* 0xff : don't set Threshold (ST25R3916_THRESHOLD_DO_NOT_SET)
* \param[in] nTRFW : Number of TRFW
*
* \return ERR_NONE : no collision detected
* \return ERR_RF_COLLISION : collision detected
*/
extern ReturnCode st25r3911PerformCollisionAvoidance( uint8_t FieldONCmd, uint8_t pdThreshold, uint8_t caThreshold, uint8_t nTRFW );
/*!
*****************************************************************************
* \brief Get amount of bits of the last FIFO byte if incomplete
*
* Gets the number of bits of the last FIFO byte if incomplete
*
* \return the number of bits of the last FIFO byte if incomplete, 0 if
* the last byte is complete
*
*****************************************************************************
*/
extern uint8_t st25r3911GetNumFIFOLastBits( void );
/*!
*****************************************************************************
* \brief Get NRT time
*
* This returns the last value set on the NRT
*
* \warning it does not reads chip register, just the sw var that contains the
* last value set before
*
* \return the value of the NRT
*/
extern uint32_t st25r3911GetNoResponseTime_64fcs( void );
/*!
*****************************************************************************
* \brief set general purpose timer timeout
*
* This function sets the proper registers but does not start the timer actually
*
* \param gpt_8fcs : general purpose timer timeout in 8/fc = 590ns
*
*/
extern void st25r3911SetGPTime_8fcs( uint16_t gpt_8fcs );
/*!
*****************************************************************************
* \brief Starts GPT with given timeout
*
* This function starts the general purpose timer with the given timeout
*
* \param gpt_8fcs : general purpose timer timeout in 8/fc = 590ns
* \param trigger_source : no trigger, start of Rx, end of Rx, end of Tx in NFC mode
*/
extern void st25r3911StartGPTimer_8fcs( uint16_t gpt_8fcs, uint8_t trigger_source );
/*!
*****************************************************************************
* \brief Checks if register contains a expected value
*
* This function checks if the given reg contains a value that once masked
* equals the expected value
*
* \param reg : the register to check the value
* \param mask : the mask apply on register value
* \param value : expected value to be compared to
*
* \return true when reg contains the expected value | false otherwise
*/
bool st25r3911CheckReg( uint8_t reg, uint8_t mask, uint8_t value );
/*!
*****************************************************************************
* \brief Sets the number Tx Bits
*
* Sets ST25R3911 internal registers with correct number of complete bytes and
* bits to be sent
*
* \param nBits : the number bits to be transmitted
*****************************************************************************
*/
void st25r3911SetNumTxBits( uint32_t nBits );
/*!
*****************************************************************************
* \brief Check Identity
*
* Checks if the chip ID is as expected.
*
* 5 bit IC type code for ST25R3911: 00001
* The 3 lsb contain the IC revision code
*
*
* \param[out] rev : the IC revision code
*
* \return true when IC type is as expected
*
*****************************************************************************
*/
bool st25r3911CheckChipID( uint8_t *rev );
/*!
*****************************************************************************
* \brief Check if command is valid
*
* Checks if the given command is a valid ST25R3911 command
*
* \param[in] cmd: Command to check
*
* \return true if is a valid command
* \return false otherwise
*
*****************************************************************************
*/
bool st25r3911IsCmdValid( uint8_t cmd );
/*!
*****************************************************************************
* \brief Configure the stream mode of ST25R3911
*
* This function initializes the stream with the given parameters
*
* \param[in] config : all settings for bitrates, type, etc.
* \return ERR_NONE : No error, stream mode driver initialized.
*
*****************************************************************************
*/
extern ReturnCode st25r3911StreamConfigure( const struct st25r3911StreamConfig *config );
/*!
*****************************************************************************
* \brief Retrieves all internal registers from st25r3911
*/
extern ReturnCode st25r3911GetRegsDump( uint8_t* resRegDump, uint8_t* sizeRegDump );
/*!
*****************************************************************************
* \brief Gets the RSSI values
*
* This function gets the RSSI value of the previous reception taking into
* account the gain reductions that were used.
* RSSI value for both AM and PM channel can be retrieved.
*
* \param[out] amRssi: the RSSI on the AM channel expressed in mV
* \param[out] pmRssi: the RSSI on the PM channel expressed in mV
*
* \return ERR_PARAM : Invalid parameter
* \return ERR_NONE : No error
*
*****************************************************************************
*/
ReturnCode st25r3911GetRSSI( uint16_t *amRssi, uint16_t *pmRssi );
#endif /* ST25R3911_H */
/**
* @}
*
* @}
*
* @}
*
* @}
*/

View File

@ -1,457 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R3911 firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file
*
* \author Ulrich Herrmann
*
* \brief Implementation of ST25R3911 communication.
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "st25r3911_com.h"
#include "st25r3911.h"
#include "utils.h"
/*
******************************************************************************
* LOCAL DEFINES
******************************************************************************
*/
#define ST25R3911_WRITE_MODE (0U) /*!< ST25R3911 SPI Operation Mode: Write */
#define ST25R3911_READ_MODE (1U << 6) /*!< ST25R3911 SPI Operation Mode: Read */
#define ST25R3911_FIFO_LOAD (2U << 6) /*!< ST25R3911 SPI Operation Mode: FIFO Load */
#define ST25R3911_FIFO_READ (0xBFU) /*!< ST25R3911 SPI Operation Mode: FIFO Read */
#define ST25R3911_CMD_MODE (3U << 6) /*!< ST25R3911 SPI Operation Mode: Direct Command */
#define ST25R3911_CMD_LEN (1U) /*!< ST25R3911 CMD length */
#define ST25R3911_BUF_LEN (ST25R3911_CMD_LEN+ST25R3911_FIFO_DEPTH) /*!< ST25R3911 communication buffer: CMD + FIFO length */
/*
******************************************************************************
* LOCAL VARIABLES
******************************************************************************
*/
#ifdef ST25R391X_COM_SINGLETXRX
static uint8_t comBuf[ST25R3911_BUF_LEN]; /*!< ST25R3911 communication buffer */
#endif /* ST25R391X_COM_SINGLETXRX */
/*
******************************************************************************
* LOCAL FUNCTION PROTOTYPES
******************************************************************************
*/
static inline void st25r3911CheckFieldSetLED(uint8_t value)
{
if ((ST25R3911_REG_OP_CONTROL_tx_en & value) != 0U)
{
#ifdef PLATFORM_LED_FIELD_PIN
platformLedOn( PLATFORM_LED_FIELD_PORT, PLATFORM_LED_FIELD_PIN );
}
else
{
platformLedOff( PLATFORM_LED_FIELD_PORT, PLATFORM_LED_FIELD_PIN );
#endif /* PLATFORM_LED_FIELD_PIN */
}
}
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
void st25r3911ReadRegister(uint8_t reg, uint8_t* value)
{
#ifdef ST25R391X_COM_SINGLETXRX
uint8_t* buf = comBuf;
#else /* ST25R391X_COM_SINGLETXRX */
uint8_t buf[2];
#endif /* ST25R391X_COM_SINGLETXRX */
platformProtectST25R391xComm();
platformSpiSelect();
buf[0] = (reg | ST25R3911_READ_MODE);
buf[1] = 0;
platformSpiTxRx(buf, buf, 2);
if(value != NULL)
{
*value = buf[1];
}
platformSpiDeselect();
platformUnprotectST25R391xComm();
return;
}
void st25r3911ReadMultipleRegisters(uint8_t reg, uint8_t* values, uint8_t length)
{
#if !defined(ST25R391X_COM_SINGLETXRX)
uint8_t cmd = (reg | ST25R3911_READ_MODE);
#endif /* !ST25R391X_COM_SINGLETXRX */
if (length > 0U)
{
platformProtectST25R391xComm();
platformSpiSelect();
#ifdef ST25R391X_COM_SINGLETXRX
ST_MEMSET( comBuf, 0x00, MIN( (ST25R3911_CMD_LEN + (uint32_t)length), ST25R3911_BUF_LEN ) );
comBuf[0] = (reg | ST25R3911_READ_MODE);
platformSpiTxRx(comBuf, comBuf, MIN( (ST25R3911_CMD_LEN + length), ST25R3911_BUF_LEN ) ); /* Transceive as a single SPI call */
ST_MEMCPY( values, &comBuf[ST25R3911_CMD_LEN], MIN( length, ST25R3911_BUF_LEN - ST25R3911_CMD_LEN ) ); /* Copy from local buf to output buffer and skip cmd byte */
#else /* ST25R391X_COM_SINGLETXRX */
/* Since the result comes one byte later, let's first transmit the adddress with discarding the result */
platformSpiTxRx(&cmd, NULL, ST25R3911_CMD_LEN);
platformSpiTxRx(NULL, values, length);
#endif /* ST25R391X_COM_SINGLETXRX */
platformSpiDeselect();
platformUnprotectST25R391xComm();
}
return;
}
void st25r3911ReadTestRegister(uint8_t reg, uint8_t* value)
{
#ifdef ST25R391X_COM_SINGLETXRX
uint8_t* buf = comBuf;
#else /* ST25R391X_COM_SINGLETXRX */
uint8_t buf[3];
#endif /* ST25R391X_COM_SINGLETXRX */
platformProtectST25R391xComm();
platformSpiSelect();
buf[0] = ST25R3911_CMD_TEST_ACCESS;
buf[1] = (reg | ST25R3911_READ_MODE);
buf[2] = 0x00;
platformSpiTxRx(buf, buf, 3);
if(value != NULL)
{
*value = buf[2];
}
platformSpiDeselect();
platformUnprotectST25R391xComm();
return;
}
void st25r3911WriteTestRegister(uint8_t reg, uint8_t value)
{
#ifdef ST25R391X_COM_SINGLETXRX
uint8_t* buf = comBuf;
#else /* ST25R391X_COM_SINGLETXRX */
uint8_t buf[3];
#endif /* ST25R391X_COM_SINGLETXRX */
platformProtectST25R391xComm();
platformSpiSelect();
buf[0] = ST25R3911_CMD_TEST_ACCESS;
buf[1] = (reg | ST25R3911_WRITE_MODE);
buf[2] = value;
platformSpiTxRx(buf, NULL, 3);
platformSpiDeselect();
platformUnprotectST25R391xComm();
return;
}
void st25r3911WriteRegister(uint8_t reg, uint8_t value)
{
#ifdef ST25R391X_COM_SINGLETXRX
uint8_t* buf = comBuf;
#else /* ST25R391X_COM_SINGLETXRX */
uint8_t buf[2];
#endif /* ST25R391X_COM_SINGLETXRX */
if (ST25R3911_REG_OP_CONTROL == reg)
{
st25r3911CheckFieldSetLED(value);
}
platformProtectST25R391xComm();
platformSpiSelect();
buf[0] = reg | ST25R3911_WRITE_MODE;
buf[1] = value;
platformSpiTxRx(buf, NULL, 2);
platformSpiDeselect();
platformUnprotectST25R391xComm();
return;
}
void st25r3911ClrRegisterBits( uint8_t reg, uint8_t clr_mask )
{
uint8_t tmp;
st25r3911ReadRegister(reg, &tmp);
tmp &= ~clr_mask;
st25r3911WriteRegister(reg, tmp);
return;
}
void st25r3911SetRegisterBits( uint8_t reg, uint8_t set_mask )
{
uint8_t tmp;
st25r3911ReadRegister(reg, &tmp);
tmp |= set_mask;
st25r3911WriteRegister(reg, tmp);
return;
}
void st25r3911ChangeRegisterBits(uint8_t reg, uint8_t valueMask, uint8_t value)
{
st25r3911ModifyRegister(reg, valueMask, (valueMask & value) );
}
void st25r3911ModifyRegister(uint8_t reg, uint8_t clr_mask, uint8_t set_mask)
{
uint8_t tmp;
st25r3911ReadRegister(reg, &tmp);
/* mask out the bits we don't want to change */
tmp &= ~clr_mask;
/* set the new value */
tmp |= set_mask;
st25r3911WriteRegister(reg, tmp);
return;
}
void st25r3911ChangeTestRegisterBits( uint8_t reg, uint8_t valueMask, uint8_t value )
{
uint8_t rdVal;
uint8_t wrVal;
/* Read current reg value */
st25r3911ReadTestRegister(reg, &rdVal);
/* Compute new value */
wrVal = (rdVal & ~valueMask);
wrVal |= (value & valueMask);
/* Write new reg value */
st25r3911WriteTestRegister(reg, wrVal );
return;
}
void st25r3911WriteMultipleRegisters(uint8_t reg, const uint8_t* values, uint8_t length)
{
#if !defined(ST25R391X_COM_SINGLETXRX)
uint8_t cmd = (reg | ST25R3911_WRITE_MODE);
#endif /* !ST25R391X_COM_SINGLETXRX */
if ((reg <= ST25R3911_REG_OP_CONTROL) && ((reg+length) >= ST25R3911_REG_OP_CONTROL))
{
st25r3911CheckFieldSetLED(values[ST25R3911_REG_OP_CONTROL-reg]);
}
if (length > 0U)
{
/* make this operation atomic */
platformProtectST25R391xComm();
platformSpiSelect();
#ifdef ST25R391X_COM_SINGLETXRX
comBuf[0] = (reg | ST25R3911_WRITE_MODE);
ST_MEMCPY( &comBuf[ST25R3911_CMD_LEN], values, MIN( length, ST25R3911_BUF_LEN - ST25R3911_CMD_LEN ) );
platformSpiTxRx( comBuf, NULL, MIN( (ST25R3911_CMD_LEN + length), ST25R3911_BUF_LEN ) );
#else /*ST25R391X_COM_SINGLETXRX*/
platformSpiTxRx( &cmd, NULL, ST25R3911_CMD_LEN );
platformSpiTxRx( values, NULL, length );
#endif /*ST25R391X_COM_SINGLETXRX*/
platformSpiDeselect();
platformUnprotectST25R391xComm();
}
return;
}
void st25r3911WriteFifo(const uint8_t* values, uint8_t length)
{
#if !defined(ST25R391X_COM_SINGLETXRX)
uint8_t cmd = ST25R3911_FIFO_LOAD;
#endif /* !ST25R391X_COM_SINGLETXRX */
if (length > 0U)
{
platformProtectST25R391xComm();
platformSpiSelect();
#ifdef ST25R391X_COM_SINGLETXRX
comBuf[0] = ST25R3911_FIFO_LOAD;
ST_MEMCPY( &comBuf[ST25R3911_CMD_LEN], values, MIN( length, ST25R3911_BUF_LEN - ST25R3911_CMD_LEN ) );
platformSpiTxRx( comBuf, NULL, MIN( (ST25R3911_CMD_LEN + length), ST25R3911_BUF_LEN ) );
#else /*ST25R391X_COM_SINGLETXRX*/
platformSpiTxRx( &cmd, NULL, ST25R3911_CMD_LEN );
platformSpiTxRx( values, NULL, length );
#endif /*ST25R391X_COM_SINGLETXRX*/
platformSpiDeselect();
platformUnprotectST25R391xComm();
}
return;
}
void st25r3911ReadFifo(uint8_t* buf, uint8_t length)
{
#if !defined(ST25R391X_COM_SINGLETXRX)
uint8_t cmd = ST25R3911_FIFO_READ;
#endif /* !ST25R391X_COM_SINGLETXRX */
if(length > 0U)
{
platformProtectST25R391xComm();
platformSpiSelect();
#ifdef ST25R391X_COM_SINGLETXRX
ST_MEMSET( comBuf, 0x00, MIN( (ST25R3911_CMD_LEN + (uint32_t)length), ST25R3911_BUF_LEN ) );
comBuf[0] = ST25R3911_FIFO_READ;
platformSpiTxRx( comBuf, comBuf, MIN( (ST25R3911_CMD_LEN + length), ST25R3911_BUF_LEN ) ); /* Transceive as a single SPI call */
ST_MEMCPY( buf, &comBuf[ST25R3911_CMD_LEN], MIN( length, ST25R3911_BUF_LEN - ST25R3911_CMD_LEN ) ); /* Copy from local buf to output buffer and skip cmd byte */
#else /*ST25R391X_COM_SINGLETXRX*/
platformSpiTxRx( &cmd, NULL, ST25R3911_CMD_LEN );
platformSpiTxRx( NULL, buf, length );
#endif /*ST25R391X_COM_SINGLETXRX*/
platformSpiDeselect();
platformUnprotectST25R391xComm();
}
return;
}
void st25r3911ExecuteCommand( uint8_t cmd )
{
uint8_t tmpCmd; /* MISRA 17.8 */
#ifdef PLATFORM_LED_FIELD_PIN
if ( (cmd >= ST25R3911_CMD_TRANSMIT_WITH_CRC) && (cmd <= ST25R3911_CMD_RESPONSE_RF_COLLISION_0))
{
platformLedOff(PLATFORM_LED_FIELD_PORT, PLATFORM_LED_FIELD_PIN);
}
#endif /* PLATFORM_LED_FIELD_PIN */
tmpCmd = (cmd | ST25R3911_CMD_MODE);
platformProtectST25R391xComm();
platformSpiSelect();
platformSpiTxRx( &tmpCmd, NULL, ST25R3911_CMD_LEN );
platformSpiDeselect();
platformUnprotectST25R391xComm();
return;
}
void st25r3911ExecuteCommands(const uint8_t *cmds, uint8_t length)
{
platformProtectST25R391xComm();
platformSpiSelect();
platformSpiTxRx(cmds, NULL, length);
platformSpiDeselect();
platformUnprotectST25R391xComm();
return;
}
bool st25r3911IsRegValid( uint8_t reg )
{
if( !(( (int16_t)reg >= (int16_t)ST25R3911_REG_IO_CONF1) && (reg <= ST25R3911_REG_CAPACITANCE_MEASURE_RESULT)) && (reg != ST25R3911_REG_IC_IDENTITY) )
{
return false;
}
return true;
}
/*
******************************************************************************
* LOCAL FUNCTIONS
******************************************************************************
*/

View File

@ -1,816 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R3911 firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file
*
* \author Ulrich Herrmann
*
* \brief ST25R3911 communication declaration file
*
*/
/*!
* This driver provides basic abstraction for communication with the ST25R3911.
* It uses the SPI driver for interfacing with the ST25R3911.
*
* API:
* - Read Register: #st25r3911ReadRegister
* - Modify Register: #st25r3911ModifyRegister
* - Write Register: #st25r3911WriteRegister
* - Write Multiple Registers: #st25r3911WriteMultipleRegisters
* - Load ST25R3911 FIFO with data: #st25r3911WriteFifo
* - Read from ST25R3911 FIFO: #st25r3911ReadFifo
* - Execute direct command: #st25r3911ExecuteCommand
*
*
* \addtogroup RFAL
* @{
*
* \addtogroup RFAL-HAL
* \brief RFAL Hardware Abstraction Layer
* @{
*
* \addtogroup ST25R3911
* \brief RFAL ST25R3911 Driver
* @{
*
* \addtogroup ST25R3911_Com
* \brief RFAL ST25R3911 Communication
* @{
*
*/
#ifndef ST25R3911_COM_H
#define ST25R3911_COM_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
#include "st_errno.h"
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
#define ST25R3911_FIFO_STATUS_LEN 2 /*!< Number of FIFO Status Register */
#define ST25R3911_REG_IO_CONF1 0x00U /*!< RW IO Configuration Register 1 */
#define ST25R3911_REG_IO_CONF2 0x01U /*!< RW IO Configuration Register 2 */
#define ST25R3911_REG_OP_CONTROL 0x02U /*!< RW Operation Control Register */
#define ST25R3911_REG_MODE 0x03U /*!< RW Mode Definition Register */
#define ST25R3911_REG_BIT_RATE 0x04U /*!< RW Bit Rate Definition Register */
#define ST25R3911_REG_ISO14443A_NFC 0x05U /*!< RW ISO14443A and NFC 106 kBit/s Settings Register */
#define ST25R3911_REG_ISO14443B_1 0x06U /*!< RW ISO14443B Settings Register 1 */
#define ST25R3911_REG_ISO14443B_2 0x07U /*!< RW ISO14443B Settings Register 2 */
#define ST25R3911_REG_STREAM_MODE 0x08U /*!< RW Stream Mode Definition Register */
#define ST25R3911_REG_AUX 0x09U /*!< RW Auxiliary Definition Register */
#define ST25R3911_REG_RX_CONF1 0x0AU /*!< RW Receiver Configuration Register 1 */
#define ST25R3911_REG_RX_CONF2 0x0BU /*!< RW Receiver Configuration Register 2 */
#define ST25R3911_REG_RX_CONF3 0x0CU /*!< RW Receiver Configuration Register 3 */
#define ST25R3911_REG_RX_CONF4 0x0DU /*!< RW Receiver Configuration Register 4 */
#define ST25R3911_REG_MASK_RX_TIMER 0x0EU /*!< RW Mask Receive Timer Register */
#define ST25R3911_REG_NO_RESPONSE_TIMER1 0x0FU /*!< RW No-response Timer Register 1 */
#define ST25R3911_REG_NO_RESPONSE_TIMER2 0x10U /*!< RW No-response Timer Register 2 */
#define ST25R3911_REG_GPT_CONTROL 0x11U /*!< RW General Purpose Timer Control Register */
#define ST25R3911_REG_GPT1 0x12U /*!< RW General Purpose Timer Register 1 */
#define ST25R3911_REG_GPT2 0x13U /*!< RW General Purpose Timer Register 2 */
#define ST25R3911_REG_IRQ_MASK_MAIN 0x14U /*!< RW Mask Main Interrupt Register */
#define ST25R3911_REG_IRQ_MASK_TIMER_NFC 0x15U /*!< RW Mask Timer and NFC Interrupt Register */
#define ST25R3911_REG_IRQ_MASK_ERROR_WUP 0x16U /*!< RW Mask Error and Wake-up Interrupt Register */
#define ST25R3911_REG_IRQ_MAIN 0x17U /*!< R Main Interrupt Register */
#define ST25R3911_REG_IRQ_TIMER_NFC 0x18U /*!< R Timer and NFC Interrupt Register */
#define ST25R3911_REG_IRQ_ERROR_WUP 0x19U /*!< R Error and Wake-up Interrupt Register */
#define ST25R3911_REG_FIFO_RX_STATUS1 0x1AU /*!< R FIFO RX Status Register 1 */
#define ST25R3911_REG_FIFO_RX_STATUS2 0x1BU /*!< R FIFO RX Status Register 2 */
#define ST25R3911_REG_COLLISION_STATUS 0x1CU /*!< R Collision Display Register */
#define ST25R3911_REG_NUM_TX_BYTES1 0x1DU /*!< RW Number of Transmitted Bytes Register 1 */
#define ST25R3911_REG_NUM_TX_BYTES2 0x1EU /*!< RW Number of Transmitted Bytes Register 2 */
#define ST25R3911_REG_NFCIP1_BIT_RATE 0x1FU /*!< R NFCIP Bit Rate Detection Display Register */
#define ST25R3911_REG_AD_RESULT 0x20U /*!< R A/D Converter Output Register */
#define ST25R3911_REG_ANT_CAL_CONTROL 0x21U /*!< RW Antenna Calibration Control Register */
#define ST25R3911_REG_ANT_CAL_TARGET 0x22U /*!< RW Antenna Calibration Target Register */
#define ST25R3911_REG_ANT_CAL_RESULT 0x23U /*!< R Antenna Calibration Display Register */
#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL 0x24U /*!< RW AM Modulation Depth Control Register */
#define ST25R3911_REG_AM_MOD_DEPTH_RESULT 0x25U /*!< R AM Modulation Depth Display Register */
#define ST25R3911_REG_RFO_AM_ON_LEVEL 0x26U /*!< RW RFO AM Modulation (On) Level Definition Register */
#define ST25R3911_REG_RFO_AM_OFF_LEVEL 0x27U /*!< RW RFO Normal (AM Off) Level Definition Register */
#define ST25R3911_REG_FIELD_THRESHOLD 0x29U /*!< RW External Field Detector Threshold Register */
#define ST25R3911_REG_REGULATOR_CONTROL 0x2AU /*!< RW Regulated Voltage Control Register */
#define ST25R3911_REG_REGULATOR_RESULT 0x2BU /*!< R Regulator Display Register */
#define ST25R3911_REG_RSSI_RESULT 0x2CU /*!< R RSSI Display Register*/
#define ST25R3911_REG_GAIN_RED_STATE 0x2DU /*!< R Gain Reduction State Register*/
#define ST25R3911_REG_CAP_SENSOR_CONTROL 0x2EU /*!< RW Capacitive Sensor Control Register */
#define ST25R3911_REG_CAP_SENSOR_RESULT 0x2FU /*!< R Capacitive Sensor Display Register */
#define ST25R3911_REG_AUX_DISPLAY 0x30U /*!< R Auxiliary Display Register */
#define ST25R3911_REG_WUP_TIMER_CONTROL 0x31U /*!< RW Wake-up Timer Control Register */
#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF 0x32U /*!< RW Amplitude Measurement Configuration Register */
#define ST25R3911_REG_AMPLITUDE_MEASURE_REF 0x33U /*!< RW Amplitude Measurement Reference Register */
#define ST25R3911_REG_AMPLITUDE_MEASURE_AA_RESULT 0x34U /*!< R Amplitude Measurement Auto Averaging Display Register */
#define ST25R3911_REG_AMPLITUDE_MEASURE_RESULT 0x35U /*!< R Amplitude Measurement Display Register */
#define ST25R3911_REG_PHASE_MEASURE_CONF 0x36U /*!< RW Phase Measurement Configuration Register */
#define ST25R3911_REG_PHASE_MEASURE_REF 0x37U /*!< RW Phase Measurement Reference Register */
#define ST25R3911_REG_PHASE_MEASURE_AA_RESULT 0x38U /*!< R Phase Measurement Auto Averaging Display Register */
#define ST25R3911_REG_PHASE_MEASURE_RESULT 0x39U /*!< R Phase Measurement Display Register */
#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF 0x3AU /*!< RW Capacitance Measurement Configuration Register */
#define ST25R3911_REG_CAPACITANCE_MEASURE_REF 0x3BU /*!< RW Capacitance Measurement Reference Register */
#define ST25R3911_REG_CAPACITANCE_MEASURE_AA_RESULT 0x3CU /*!< R Capacitance Measurement Auto Averaging Display Register */
#define ST25R3911_REG_CAPACITANCE_MEASURE_RESULT 0x3DU /*!< R Capacitance Measurement Display Register */
#define ST25R3911_REG_IC_IDENTITY 0x3FU /*!< R Chip Id: 0 for old silicon, v2 silicon: 0x09 */
/*! Register bit definitions \cond DOXYGEN_SUPRESS */
#define ST25R3911_REG_IO_CONF1_lf_clk_off (1U<<0)
#define ST25R3911_REG_IO_CONF1_out_cl0 (1U<<1)
#define ST25R3911_REG_IO_CONF1_out_cl1 (1U<<2)
#define ST25R3911_REG_IO_CONF1_mask_out_cl (3U<<1)
#define ST25R3911_REG_IO_CONF1_osc (1U<<3)
#define ST25R3911_REG_IO_CONF1_fifo_lt (1U<<4)
#define ST25R3911_REG_IO_CONF1_fifo_lt_32bytes (0U<<4)
#define ST25R3911_REG_IO_CONF1_fifo_lt_16bytes (1U<<4)
#define ST25R3911_REG_IO_CONF1_fifo_lr (1U<<5)
#define ST25R3911_REG_IO_CONF1_fifo_lr_64bytes (0U<<5)
#define ST25R3911_REG_IO_CONF1_fifo_lr_80bytes (1U<<5)
#define ST25R3911_REG_IO_CONF1_rfo2 (1U<<6)
#define ST25R3911_REG_IO_CONF1_single (1U<<7)
#define ST25R3911_REG_IO_CONF2_slow_up (1U<<0)
#define ST25R3911_REG_IO_CONF2_io_18 (1U<<2)
#define ST25R3911_REG_IO_CONF2_miso_pd1 (1U<<3)
#define ST25R3911_REG_IO_CONF2_miso_pd2 (1U<<4)
#define ST25R3911_REG_IO_CONF2_vspd_off (1U<<6)
#define ST25R3911_REG_IO_CONF2_sup3V (1U<<7)
#define ST25R3911_REG_OP_CONTROL_wu (1U<<2)
#define ST25R3911_REG_OP_CONTROL_tx_en (1U<<3)
#define ST25R3911_REG_OP_CONTROL_rx_man (1U<<4)
#define ST25R3911_REG_OP_CONTROL_rx_chn (1U<<5)
#define ST25R3911_REG_OP_CONTROL_rx_en (1U<<6)
#define ST25R3911_REG_OP_CONTROL_en (1U<<7)
#define ST25R3911_REG_MODE_nfc_ar (1U<<0)
#define ST25R3911_REG_MODE_nfc_ar_on (1U<<0)
#define ST25R3911_REG_MODE_nfc_ar_off (0U<<0)
#define ST25R3911_REG_MODE_mask_om (0xfU<<3)
#define ST25R3911_REG_MODE_om_nfc (0x0U<<3)
#define ST25R3911_REG_MODE_om_iso14443a (0x1U<<3)
#define ST25R3911_REG_MODE_om_iso14443b (0x2U<<3)
#define ST25R3911_REG_MODE_om_felica (0x3U<<3)
#define ST25R3911_REG_MODE_om_topaz (0x4U<<3)
#define ST25R3911_REG_MODE_om_subcarrier_stream (0xeU<<3)
#define ST25R3911_REG_MODE_om_bpsk_stream (0xfU<<3)
#define ST25R3911_REG_MODE_om_bit_rate_detection (0x0U<<3)
#define ST25R3911_REG_MODE_om_nfcip1_normal_mode (0x1U<<3)
#define ST25R3911_REG_MODE_targ (1U<<7)
#define ST25R3911_REG_MODE_targ_targ (1U<<7)
#define ST25R3911_REG_MODE_targ_init (0U<<7)
#define ST25R3911_REG_BIT_RATE_mask_txrate (0xfU<<4)
#define ST25R3911_REG_BIT_RATE_shift_txrate (4U)
#define ST25R3911_REG_BIT_RATE_txrate_106 (0x0U<<4)
#define ST25R3911_REG_BIT_RATE_txrate_212 (0x1U<<4)
#define ST25R3911_REG_BIT_RATE_txrate_424 (0x2U<<4)
#define ST25R3911_REG_BIT_RATE_txrate_848 (0x3U<<4)
#define ST25R3911_REG_BIT_RATE_txrate_1695 (0x4U<<4)
#define ST25R3911_REG_BIT_RATE_txrate_3390 (0x5U<<4)
#define ST25R3911_REG_BIT_RATE_txrate_6780 (0x6U<<4)
#define ST25R3911_REG_BIT_RATE_mask_rxrate (0xfU<<0)
#define ST25R3911_REG_BIT_RATE_shift_rxrate (0U)
#define ST25R3911_REG_BIT_RATE_rxrate_106 (0x0U<<0)
#define ST25R3911_REG_BIT_RATE_rxrate_212 (0x1U<<0)
#define ST25R3911_REG_BIT_RATE_rxrate_424 (0x2U<<0)
#define ST25R3911_REG_BIT_RATE_rxrate_848 (0x3U<<0)
#define ST25R3911_REG_BIT_RATE_rxrate_1695 (0x4U<<0)
#define ST25R3911_REG_BIT_RATE_rxrate_3390 (0x5U<<0)
#define ST25R3911_REG_BIT_RATE_rxrate_6780 (0x6U<<0)
#define ST25R3911_REG_ISO14443A_NFC_antcl (1U<<0)
#define ST25R3911_REG_ISO14443A_NFC_mask_p_len (0xfU<<1)
#define ST25R3911_REG_ISO14443A_NFC_shift_p_len (1U)
#define ST25R3911_REG_ISO14443A_NFC_nfc_f0 (1U<<5)
#define ST25R3911_REG_ISO14443A_NFC_nfc_f0_off (0U<<5)
#define ST25R3911_REG_ISO14443A_NFC_no_rx_par (1U<<6)
#define ST25R3911_REG_ISO14443A_NFC_no_rx_par_off (0U<<6)
#define ST25R3911_REG_ISO14443A_NFC_no_tx_par (1U<<7)
#define ST25R3911_REG_ISO14443A_NFC_no_tx_par_off (0U<<7)
#define ST25R3911_REG_ISO14443B_1_mask_eof (1U<<2)
#define ST25R3911_REG_ISO14443B_1_eof_10etu (0U<<2)
#define ST25R3911_REG_ISO14443B_1_eof_11etu (1U<<2)
#define ST25R3911_REG_ISO14443B_1_mask_sof (3U<<3)
#define ST25R3911_REG_ISO14443B_1_mask_sof_0 (1U<<4)
#define ST25R3911_REG_ISO14443B_1_sof_0_10etu (0U<<4)
#define ST25R3911_REG_ISO14443B_1_sof_0_11etu (1U<<4)
#define ST25R3911_REG_ISO14443B_1_mask_sof_1 (1U<<3)
#define ST25R3911_REG_ISO14443B_1_sof_1_2etu (0U<<3)
#define ST25R3911_REG_ISO14443B_1_sof_2_3etu (1U<<3)
#define ST25R3911_REG_ISO14443B_1_mask_egt (7U<<5)
#define ST25R3911_REG_ISO14443B_1_shift_egt (5U)
#define ST25R3911_REG_ISO14443B_2_eof_12 (1U<<3)
#define ST25R3911_REG_ISO14443B_2_eof_12_10to11etu (0U<<3)
#define ST25R3911_REG_ISO14443B_2_eof_12_10to12etu (1U<<3)
#define ST25R3911_REG_ISO14443B_2_no_eof (1U<<4)
#define ST25R3911_REG_ISO14443B_2_no_sof (1U<<5)
#define ST25R3911_REG_ISO14443B_2_mask_tr1 (3U<<6)
#define ST25R3911_REG_ISO14443B_2_shift_tr1 (6U)
#define ST25R3911_REG_ISO14443B_2_tr1_0 (1U<<6)
#define ST25R3911_REG_ISO14443B_2_tr1_1 (1U<<7)
#define ST25R3911_REG_ISO14443B_2_tr1_80fs80fs (0U<<6)
#define ST25R3911_REG_ISO14443B_2_tr1_64fs32fs (1U<<6)
#define ST25R3911_REG_STREAM_MODE_mask_stx (7U<<0)
#define ST25R3911_REG_STREAM_MODE_shift_stx (0U)
#define ST25R3911_REG_STREAM_MODE_stx_106 (0U<<0)
#define ST25R3911_REG_STREAM_MODE_stx_212 (1U<<0)
#define ST25R3911_REG_STREAM_MODE_stx_424 (2U<<0)
#define ST25R3911_REG_STREAM_MODE_stx_848 (3U<<0)
#define ST25R3911_REG_STREAM_MODE_stx_1695 (4U<<0)
#define ST25R3911_REG_STREAM_MODE_stx_3390 (5U<<0)
#define ST25R3911_REG_STREAM_MODE_stx_6780 (6U<<0)
#define ST25R3911_REG_STREAM_MODE_mask_scp (3U<<3)
#define ST25R3911_REG_STREAM_MODE_shift_scp (3U)
#define ST25R3911_REG_STREAM_MODE_scp_1pulse (0U<<3)
#define ST25R3911_REG_STREAM_MODE_scp_2pulses (1U<<3)
#define ST25R3911_REG_STREAM_MODE_scp_4pulses (2U<<3)
#define ST25R3911_REG_STREAM_MODE_scp_8pulses (3U<<3)
#define ST25R3911_REG_STREAM_MODE_mask_scf (3U<<5)
#define ST25R3911_REG_STREAM_MODE_shift_scf (5U)
#define ST25R3911_REG_STREAM_MODE_scf_bpsk848 (0U<<5)
#define ST25R3911_REG_STREAM_MODE_scf_bpsk1695 (1U<<5)
#define ST25R3911_REG_STREAM_MODE_scf_bpsk3390 (2U<<5)
#define ST25R3911_REG_STREAM_MODE_scf_bpsk106 (3U<<5)
#define ST25R3911_REG_STREAM_MODE_scf_sc212 (0U<<5)
#define ST25R3911_REG_STREAM_MODE_scf_sc424 (1U<<5)
#define ST25R3911_REG_STREAM_MODE_scf_sc848 (2U<<5)
#define ST25R3911_REG_STREAM_MODE_scf_sc1695 (3U<<5)
#define ST25R3911_REG_AUX_mask_nfc_n (3U<<0)
#define ST25R3911_REG_AUX_nfc_n0 (1U<<0)
#define ST25R3911_REG_AUX_nfc_n1 (1U<<1)
#define ST25R3911_REG_AUX_rx_tol (1U<<2)
#define ST25R3911_REG_AUX_ook_hr (1U<<3)
#define ST25R3911_REG_AUX_en_fd (1U<<4)
#define ST25R3911_REG_AUX_tr_am (1U<<5)
#define ST25R3911_REG_AUX_crc_2_fifo (1U<<6)
#define ST25R3911_REG_AUX_no_crc_rx (1U<<7)
#define ST25R3911_REG_RX_CONF1_z12k (1U<<0)
#define ST25R3911_REG_RX_CONF1_h80 (1U<<1)
#define ST25R3911_REG_RX_CONF1_h200 (1U<<2)
#define ST25R3911_REG_RX_CONF1_mask_lp (7U<<3)
#define ST25R3911_REG_RX_CONF1_lp_1200khz (0U<<3)
#define ST25R3911_REG_RX_CONF1_lp_600khz (1U<<3)
#define ST25R3911_REG_RX_CONF1_lp_300khz (2U<<3)
#define ST25R3911_REG_RX_CONF1_lp_2000khz (4U<<3)
#define ST25R3911_REG_RX_CONF1_lp_7000khz (5U<<3)
#define ST25R3911_REG_RX_CONF1_amd_sel (1U<<6)
#define ST25R3911_REG_RX_CONF1_ch_sel (1U<<7)
#define ST25R3911_REG_RX_CONF2_sqm_dyn (1U<<1)
#define ST25R3911_REG_RX_CONF2_agc_alg (1U<<2)
#define ST25R3911_REG_RX_CONF2_agc_m (1U<<3)
#define ST25R3911_REG_RX_CONF2_agc_en (1U<<4)
#define ST25R3911_REG_RX_CONF2_lf_en (1U<<5)
#define ST25R3911_REG_RX_CONF2_lf_op (1U<<6)
#define ST25R3911_REG_RX_CONF2_rx_lp (1U<<7)
#define ST25R3911_REG_RX_CONF3_rg_nfc (1U<<0)
#define ST25R3911_REG_RX_CONF3_lim (1U<<1)
#define ST25R3911_REG_RX_CONF3_shift_rg1_pm (2U)
#define ST25R3911_REG_RX_CONF3_mask_rg1_pm (0x7U<<2)
#define ST25R3911_REG_RX_CONF3_rg1_pm0 (1U<<2)
#define ST25R3911_REG_RX_CONF3_rg1_pm1 (1U<<3)
#define ST25R3911_REG_RX_CONF3_rg1_pm2 (1U<<4)
#define ST25R3911_REG_RX_CONF3_shift_rg1_am (5U)
#define ST25R3911_REG_RX_CONF3_mask_rg1_am (0x7U<<5)
#define ST25R3911_REG_RX_CONF3_rg1_am0 (1U<<5)
#define ST25R3911_REG_RX_CONF3_rg1_am1 (1U<<6)
#define ST25R3911_REG_RX_CONF3_rg1_am2 (1U<<7)
#define ST25R3911_REG_RX_CONF4_shift_rg2_pm (0U)
#define ST25R3911_REG_RX_CONF4_mask_rg2_pm (0xfU<<0)
#define ST25R3911_REG_RX_CONF4_rg2_pm0 (1U<<0)
#define ST25R3911_REG_RX_CONF4_rg2_pm1 (1U<<1)
#define ST25R3911_REG_RX_CONF4_rg2_pm2 (1U<<2)
#define ST25R3911_REG_RX_CONF4_rg2_pm3 (1U<<3)
#define ST25R3911_REG_RX_CONF4_shift_rg2_am (4U)
#define ST25R3911_REG_RX_CONF4_mask_rg2_am (0xfU<<4)
#define ST25R3911_REG_RX_CONF4_rg2_am0 (1U<<4)
#define ST25R3911_REG_RX_CONF4_rg2_am1 (1U<<5)
#define ST25R3911_REG_RX_CONF4_rg2_am2 (1U<<6)
#define ST25R3911_REG_RX_CONF4_rg2_am3 (1U<<7)
#define ST25R3911_REG_GPT_CONTROL_nrt_step (1U<<0)
#define ST25R3911_REG_GPT_CONTROL_nrt_emv (1U<<1)
#define ST25R3911_REG_GPT_CONTROL_gptc0 (1U<<5)
#define ST25R3911_REG_GPT_CONTROL_gptc1 (1U<<6)
#define ST25R3911_REG_GPT_CONTROL_gptc2 (1U<<7)
#define ST25R3911_REG_GPT_CONTROL_gptc_mask (0x7U<<5)
#define ST25R3911_REG_GPT_CONTROL_gptc_no_trigger (0x0U<<5)
#define ST25R3911_REG_GPT_CONTROL_gptc_erx (0x1U<<5)
#define ST25R3911_REG_GPT_CONTROL_gptc_srx (0x2U<<5)
#define ST25R3911_REG_GPT_CONTROL_gptc_etx_nfc (0x3U<<5)
#define ST25R3911_REG_FIFO_RX_STATUS2_np_lb (1U<<0)
#define ST25R3911_REG_FIFO_RX_STATUS2_mask_fifo_lb (7U<<1)
#define ST25R3911_REG_FIFO_RX_STATUS2_shift_fifo_lb (1U)
#define ST25R3911_REG_FIFO_RX_STATUS2_fifo_lb0 (1U<<1)
#define ST25R3911_REG_FIFO_RX_STATUS2_fifo_lb1 (1U<<2)
#define ST25R3911_REG_FIFO_RX_STATUS2_fifo_lb2 (1U<<3)
#define ST25R3911_REG_FIFO_RX_STATUS2_fifo_ncp (1U<<4)
#define ST25R3911_REG_FIFO_RX_STATUS2_fifo_ovr (1U<<5)
#define ST25R3911_REG_FIFO_RX_STATUS2_fifo_unf (1U<<6)
#define ST25R3911_REG_COLLISION_STATUS_c_pb (1U<<0)
#define ST25R3911_REG_COLLISION_STATUS_mask_c_bit (3U<<1)
#define ST25R3911_REG_COLLISION_STATUS_shift_c_bit (1U)
#define ST25R3911_REG_COLLISION_STATUS_mask_c_byte (0xfU<<4)
#define ST25R3911_REG_COLLISION_STATUS_shift_c_byte (4U)
#define ST25R3911_ST25R3911_REG_NFCIP1_BIT_RATE_nfc_rate0 (1U<<4)
#define ST25R3911_ST25R3911_REG_NFCIP1_BIT_RATE_nfc_rate1 (1U<<5)
#define ST25R3911_ST25R3911_REG_NFCIP1_BIT_RATE_nfc_rate2 (1U<<6)
#define ST25R3911_ST25R3911_REG_NFCIP1_BIT_RATE_nfc_rate3 (1U<<7)
#define ST25R3911_REG_NFCIP1_BIT_RATE_nfc_rate_mask (0xfU<<4)
#define ST25R3911_REG_NFCIP1_BIT_RATE_nfc_rate_shift (4U)
#define ST25R3911_REG_ANT_CAL_CONTROL_mask_tre (0xfU<<3)
#define ST25R3911_REG_ANT_CAL_CONTROL_shift_tre (3U)
#define ST25R3911_REG_ANT_CAL_CONTROL_tre_0 (1U<<3)
#define ST25R3911_REG_ANT_CAL_CONTROL_tre_1 (1U<<4)
#define ST25R3911_REG_ANT_CAL_CONTROL_tre_2 (1U<<5)
#define ST25R3911_REG_ANT_CAL_CONTROL_tre_3 (1U<<6)
#define ST25R3911_REG_ANT_CAL_CONTROL_trim_s (1U<<7)
#define ST25R3911_REG_ANT_CAL_RESULT_tri_err (1U<<3)
#define ST25R3911_REG_ANT_CAL_RESULT_tri_0 (1U<<4)
#define ST25R3911_REG_ANT_CAL_RESULT_tri_1 (1U<<5)
#define ST25R3911_REG_ANT_CAL_RESULT_tri_2 (1U<<6)
#define ST25R3911_REG_ANT_CAL_RESULT_tri_3 (1U<<7)
#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL_mask_mod (0x3fU<<1)
#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL_shift_mod (1U)
#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL_mod_8percent (0xbU<<1)
#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL_mod_10percent (0xeU<<1)
#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL_mod_14percent (0x14U<<1)
#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL_mod_20percent (0x20U<<1)
#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL_mod_25percent (0x2aU<<1)
#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL_mod_30percent (0x37U<<1)
#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL_mod_33percent (0x3fU<<1)
#define ST25R3911_REG_AM_MOD_DEPTH_CONTROL_am_s (1U<<7)
#define ST25R3911_REG_RFO_AM_MOD_LEVEL_dram0 (1U<<0)
#define ST25R3911_REG_RFO_AM_MOD_LEVEL_dram1 (1U<<1)
#define ST25R3911_REG_RFO_AM_MOD_LEVEL_dram2 (1U<<2)
#define ST25R3911_REG_RFO_AM_MOD_LEVEL_dram3 (1U<<3)
#define ST25R3911_REG_RFO_AM_MOD_LEVEL_dram4 (1U<<4)
#define ST25R3911_REG_RFO_AM_MOD_LEVEL_dram5 (1U<<5)
#define ST25R3911_REG_RFO_AM_MOD_LEVEL_dram6 (1U<<6)
#define ST25R3911_REG_RFO_AM_MOD_LEVEL_dram7 (1U<<7)
#define ST25R3911_REG_FIELD_THRESHOLD_rfe_t0 (1U<<0)
#define ST25R3911_REG_FIELD_THRESHOLD_rfe_t1 (1U<<1)
#define ST25R3911_REG_FIELD_THRESHOLD_rfe_t2 (1U<<2)
#define ST25R3911_REG_FIELD_THRESHOLD_rfe_t3 (1U<<3)
#define ST25R3911_REG_FIELD_THRESHOLD_trg_l0 (1U<<4)
#define ST25R3911_REG_FIELD_THRESHOLD_trg_l1 (1U<<5)
#define ST25R3911_REG_FIELD_THRESHOLD_trg_l2 (1U<<6)
#define ST25R3911_REG_FIELD_THRESHOLD_mask_trg (0x07U<<4)
#define ST25R3911_REG_FIELD_THRESHOLD_trg_75mV (0x00U<<4)
#define ST25R3911_REG_FIELD_THRESHOLD_trg_105mV (0x01U<<4)
#define ST25R3911_REG_FIELD_THRESHOLD_trg_150mV (0x02U<<4)
#define ST25R3911_REG_FIELD_THRESHOLD_trg_205mV (0x03U<<4)
#define ST25R3911_REG_FIELD_THRESHOLD_trg_290mV (0x04U<<4)
#define ST25R3911_REG_FIELD_THRESHOLD_trg_400mV (0x05U<<4)
#define ST25R3911_REG_FIELD_THRESHOLD_trg_560mV (0x06U<<4)
#define ST25R3911_REG_FIELD_THRESHOLD_trg_800mV (0x07U<<4)
#define ST25R3911_REG_FIELD_THRESHOLD_mask_rfe (0x0FU<<0)
#define ST25R3911_REG_FIELD_THRESHOLD_rfe_75mV (0x00U<<0)
#define ST25R3911_REG_FIELD_THRESHOLD_rfe_105mV (0x01U<<0)
#define ST25R3911_REG_FIELD_THRESHOLD_rfe_150mV (0x02U<<0)
#define ST25R3911_REG_FIELD_THRESHOLD_rfe_205mV (0x03U<<0)
#define ST25R3911_REG_FIELD_THRESHOLD_rfe_290mV (0x04U<<0)
#define ST25R3911_REG_FIELD_THRESHOLD_rfe_400mV (0x05U<<0)
#define ST25R3911_REG_FIELD_THRESHOLD_rfe_560mV (0x06U<<0)
#define ST25R3911_REG_FIELD_THRESHOLD_rfe_800mV (0x07U<<0)
#define ST25R3911_REG_FIELD_THRESHOLD_rfe_25mV (0x08U<<0)
#define ST25R3911_REG_FIELD_THRESHOLD_rfe_33mV (0x09U<<0)
#define ST25R3911_REG_FIELD_THRESHOLD_rfe_47mV (0x0AU<<0)
#define ST25R3911_REG_FIELD_THRESHOLD_rfe_64mV (0x0BU<<0)
#define ST25R3911_REG_FIELD_THRESHOLD_rfe_90mV (0x0CU<<0)
#define ST25R3911_REG_FIELD_THRESHOLD_rfe_125mV (0x0DU<<0)
#define ST25R3911_REG_FIELD_THRESHOLD_rfe_175mV (0x0EU<<0)
#define ST25R3911_REG_FIELD_THRESHOLD_rfe_250mV (0x0FU<<0)
#define ST25R3911_REG_REGULATOR_CONTROL_shift_mpsv (1U)
#define ST25R3911_REG_REGULATOR_CONTROL_mask_mpsv (3U<<1)
#define ST25R3911_REG_REGULATOR_CONTROL_mpsv_vdd (0U<<1)
#define ST25R3911_REG_REGULATOR_CONTROL_mpsv_vsp_a (1U<<1)
#define ST25R3911_REG_REGULATOR_CONTROL_mpsv_vsp_d (2U<<1)
#define ST25R3911_REG_REGULATOR_CONTROL_mpsv_vsp_rf (3U<<1)
#define ST25R3911_REG_REGULATOR_CONTROL_mask_rege (0xfU<<3)
#define ST25R3911_REG_REGULATOR_CONTROL_shift_rege (3U)
#define ST25R3911_REG_REGULATOR_CONTROL_reg_s (1U<<7)
#define ST25R3911_REG_REGULATOR_RESULT_mrt_on (1U<<0)
#define ST25R3911_REG_REGULATOR_RESULT_nrt_on (1U<<1)
#define ST25R3911_REG_REGULATOR_RESULT_gpt_on (1U<<2)
#define ST25R3911_REG_REGULATOR_RESULT_mask_reg (0xfU<<4)
#define ST25R3911_REG_REGULATOR_RESULT_shift_reg (4U)
#define ST25R3911_REG_REGULATOR_RESULT_reg_0 (1U<<4)
#define ST25R3911_REG_REGULATOR_RESULT_reg_1 (1U<<5)
#define ST25R3911_REG_REGULATOR_RESULT_reg_2 (1U<<6)
#define ST25R3911_REG_REGULATOR_RESULT_reg_3 (1U<<7)
#define ST25R3911_REG_RSSI_RESULT_mask_rssi_pm (0xfU)
#define ST25R3911_REG_RSSI_RESULT_shift_rssi_pm (0U)
#define ST25R3911_REG_RSSI_RESULT_rssi_pm0 (1U<<0)
#define ST25R3911_REG_RSSI_RESULT_rssi_pm1 (1U<<1)
#define ST25R3911_REG_RSSI_RESULT_rssi_pm2 (1U<<2)
#define ST25R3911_REG_RSSI_RESULT_rssi_pm3 (1U<<3)
#define ST25R3911_REG_RSSI_RESULT_mask_rssi_am (0xfU<<4)
#define ST25R3911_REG_RSSI_RESULT_shift_rssi_am (4U)
#define ST25R3911_REG_RSSI_RESULT_rssi_am_0 (1U<<4)
#define ST25R3911_REG_RSSI_RESULT_rssi_am_1 (1U<<5)
#define ST25R3911_REG_RSSI_RESULT_rssi_am_2 (1U<<6)
#define ST25R3911_REG_RSSI_RESULT_rssi_am_3 (1U<<7)
#define ST25R3911_REG_GAIN_RED_STATE_mask_gs_pm (0xfU)
#define ST25R3911_REG_GAIN_RED_STATE_shift_gs_pm (0U)
#define ST25R3911_REG_GAIN_RED_STATE_gs_pm_0 (1U<<0)
#define ST25R3911_REG_GAIN_RED_STATE_gs_pm_1 (1U<<1)
#define ST25R3911_REG_GAIN_RED_STATE_gs_pm_2 (1U<<2)
#define ST25R3911_REG_GAIN_RED_STATE_gs_pm_3 (1U<<3)
#define ST25R3911_REG_GAIN_RED_STATE_mask_gs_am (0xfU<<4)
#define ST25R3911_REG_GAIN_RED_STATE_shift_gs_am (4U)
#define ST25R3911_REG_GAIN_RED_STATE_gs_am_0 (1U<<4)
#define ST25R3911_REG_GAIN_RED_STATE_gs_am_1 (1U<<5)
#define ST25R3911_REG_GAIN_RED_STATE_gs_am_2 (1U<<6)
#define ST25R3911_REG_GAIN_RED_STATE_gs_am_3 (1U<<7)
#define ST25R3911_REG_CAP_SENSOR_CONTROL_cs_g0 (1U<<0)
#define ST25R3911_REG_CAP_SENSOR_CONTROL_cs_g1 (1U<<1)
#define ST25R3911_REG_CAP_SENSOR_CONTROL_cs_g2 (1U<<2)
#define ST25R3911_REG_CAP_SENSOR_CONTROL_mask_cs_g (7U<<0)
#define ST25R3911_REG_CAP_SENSOR_CONTROL_cs_mcal0 (1U<<3)
#define ST25R3911_REG_CAP_SENSOR_CONTROL_cs_mcal1 (1U<<4)
#define ST25R3911_REG_CAP_SENSOR_CONTROL_cs_mcal2 (1U<<5)
#define ST25R3911_REG_CAP_SENSOR_CONTROL_cs_mcal3 (1U<<6)
#define ST25R3911_REG_CAP_SENSOR_CONTROL_cs_mcal4 (1U<<7)
#define ST25R3916_REG_CAP_SENSOR_CONTROL_mask_cs_mcal (0x1fU<<3)
#define ST25R3911_REG_CAP_SENSOR_CONTROL_shift_cs_mcal (3U)
#define ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal_err (1U<<1)
#define ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal_end (1U<<2)
#define ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal0 (1U<<3)
#define ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal1 (1U<<4)
#define ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal2 (1U<<5)
#define ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal3 (1U<<6)
#define ST25R3911_REG_CAP_SENSOR_RESULT_cs_cal4 (1U<<7)
#define ST25R3911_REG_AUX_DISPLAY_mrt_on (1U<<0)
#define ST25R3911_REG_AUX_DISPLAY_nrt_on (1U<<1)
#define ST25R3911_REG_AUX_DISPLAY_gpt_on (1U<<2)
#define ST25R3911_REG_AUX_DISPLAY_rx_on (1U<<3)
#define ST25R3911_REG_AUX_DISPLAY_osc_ok (1U<<4)
#define ST25R3911_REG_AUX_DISPLAY_tx_on (1U<<5)
#define ST25R3911_REG_AUX_DISPLAY_efd_o (1U<<6)
#define ST25R3911_REG_AUX_DISPLAY_a_cha (1U<<7)
#define ST25R3911_REG_WUP_TIMER_CONTROL_wcap (1U<<0)
#define ST25R3911_REG_WUP_TIMER_CONTROL_wph (1U<<1)
#define ST25R3911_REG_WUP_TIMER_CONTROL_wam (1U<<2)
#define ST25R3911_REG_WUP_TIMER_CONTROL_wto (1U<<3)
#define ST25R3911_REG_WUP_TIMER_CONTROL_wut0 (1U<<4)
#define ST25R3911_REG_WUP_TIMER_CONTROL_wut1 (1U<<5)
#define ST25R3911_REG_WUP_TIMER_CONTROL_wut2 (1U<<6)
#define ST25R3911_REG_WUP_TIMER_CONTROL_shift_wut (4U)
#define ST25R3911_REG_WUP_TIMER_CONTROL_wur (1U<<7)
#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_am_ae (1U<<0)
#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_am_aew0 (1U<<1)
#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_am_aew1 (1U<<2)
#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_shift_am_aew (1U)
#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_mask_am_aew (3U<<1)
#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_am_aam (1U<<3)
#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_am_d0 (1U<<4)
#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_am_d1 (1U<<5)
#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_am_d2 (1U<<6)
#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_am_d3 (1U<<7)
#define ST25R3911_REG_AMPLITUDE_MEASURE_CONF_shift_am_d (4U)
#define ST25R3911_REG_PHASE_MEASURE_CONF_pm_ae (1U<<0)
#define ST25R3911_REG_PHASE_MEASURE_CONF_pm_aew0 (1U<<1)
#define ST25R3911_REG_PHASE_MEASURE_CONF_pm_aew1 (1U<<2)
#define ST25R3911_REG_PHASE_MEASURE_CONF_shift_pm_aew (1U)
#define ST25R3911_REG_PHASE_MEASURE_CONF_mask_pm_aew (3U<<1)
#define ST25R3911_REG_PHASE_MEASURE_CONF_pm_aam (1U<<3)
#define ST25R3911_REG_PHASE_MEASURE_CONF_pm_d0 (1U<<4)
#define ST25R3911_REG_PHASE_MEASURE_CONF_pm_d1 (1U<<5)
#define ST25R3911_REG_PHASE_MEASURE_CONF_pm_d2 (1U<<6)
#define ST25R3911_REG_PHASE_MEASURE_CONF_pm_d3 (1U<<7)
#define ST25R3911_REG_PHASE_MEASURE_CONF_shift_pm_d (4U)
#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_cm_ae (1U<<0)
#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_cm_aew0 (1U<<1)
#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_cm_aew1 (1U<<2)
#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_shift_cm_aew (1U)
#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_mask_cm_aew (3U<<1)
#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_cm_aam (1U<<3)
#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_cm_d0 (1U<<4)
#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_cm_d1 (1U<<5)
#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_cm_d2 (1U<<6)
#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_cm_d3 (1U<<7)
#define ST25R3911_REG_CAPACITANCE_MEASURE_CONF_shift_cm_d (4U)
#define ST25R3911_REG_IC_IDENTITY_v2 (0x09U)
#define ST25R3911_REG_IC_IDENTITY_ic_type (1U<<3)
#define ST25R3911_REG_IC_IDENTITY_mask_ic_type (0x1FU<<3)
#define ST25R3911_REG_IC_IDENTITY_shift_ic_type (3U)
#define ST25R3911_REG_IC_IDENTITY_mask_ic_rev (7U)
/*! \endcond DOXYGEN_SUPRESS */
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief Returns the content of a register within the ST25R3911
*
* This function is used to read out the content of ST25R3911 registers.
*
* \param[in] reg: Address of register to read.
* \param[out] value: Returned value.
*
*****************************************************************************
*/
extern void st25r3911ReadRegister(uint8_t reg, uint8_t* value);
/*!
*****************************************************************************
* \brief Writes a given value to a register within the ST25R3911
*
* This function is used to write \a value to address \a reg within the ST25R3911.
*
* \param[in] reg: Address of the register to write.
* \param[in] value: Value to be written.
*
*****************************************************************************
*/
extern void st25r3911WriteRegister(uint8_t reg, uint8_t value);
/*!
*****************************************************************************
* \brief Cleart bits on Register
*
* This function clears the given bitmask on the register
*
* \warning This method does not guarantee consistency of register content
* when called from multiple contexts (task, ISR, thread)
*
* \param[in] reg: Address of the register clear
* \param[in] clr_mask: Bitmask of bit to be cleared
*
*****************************************************************************
*/
extern void st25r3911ClrRegisterBits( uint8_t reg, uint8_t clr_mask );
/*!
*****************************************************************************
* \brief Set bits on Register
*
* This function sets the given bitmask on the register
*
* \warning This method does not guarantee consistency of register content
* when called from multiple contexts (task, ISR, thread)
*
* \param[in] reg: Address of the register clear
* \param[in] set_mask: Bitmask of bit to be cleared
*
*****************************************************************************
*/
extern void st25r3911SetRegisterBits( uint8_t reg, uint8_t set_mask );
/*!
*****************************************************************************
* \brief Changes the given bits on a ST25R3911 register
*
* This function is used if only a particular bits should be changed within
* an ST25R3911 register.
*
* \warning This method does not guarantee consistency of register content
* when called from multiple contexts (task, ISR, thread)
*
* \param[in] reg: Address of the register to write.
* \param[in] valueMask: bitmask of bits to be changed
* \param[in] value: the bits to be written on the enabled valueMask bits
*
*****************************************************************************
*/
extern void st25r3911ChangeRegisterBits(uint8_t reg, uint8_t valueMask, uint8_t value);
/*!
*****************************************************************************
* \brief Read a test register within the ST25R3911
*
* This function is used to read the content of test address \a reg within the ST25R3911.
*
* \param[in] reg: Address of the register to read.
* \param[out] value: Returned read.
*
*****************************************************************************
*/
extern void st25r3911ReadTestRegister(uint8_t reg, uint8_t* value);
/*!
*****************************************************************************
* \brief Writes a given value to a test register within the ST25R3911
*
* This function is used to write \a value to test address \a reg within the ST25R3911.
*
* \param[in] reg: Address of the register to write.
* \param[in] value: Value to be written.
*
*****************************************************************************
*/
extern void st25r3911WriteTestRegister(uint8_t reg, uint8_t value);
/*!
*****************************************************************************
* \brief Modifies a value within a ST25R3911 register
*
* This function is used if only a particular bits should be changed within
* an ST25R3911 register.
*
* \warning This method does not guarantee consistency of register content
* when called from multiple contexts (task, ISR, thread)
*
* \param[in] reg: Address of the register to write.
* \param[in] clr_mask: bitmask of bits to be cleared to 0.
* \param[in] set_mask: bitmask of bits to be set to 1.
*
*****************************************************************************
*/
extern void st25r3911ModifyRegister(uint8_t reg, uint8_t clr_mask, uint8_t set_mask);
/*!
*****************************************************************************
* \brief Changes the given bits on a ST25R3911 Test register
*
* This function is used if only a particular bits should be changed within
* an ST25R3916 register.
*
* \param[in] reg: Address of the Test register to change.
* \param[in] valueMask: bitmask of bits to be changed
* \param[in] value: the bits to be written on the enabled valueMask bits
*
* \warning This method does not guarantee consistency of register content
* when called from multiple contexts (task, ISR, thread)
* \return ERR_NONE : Operation successful
* \return ERR_PARAM : Invalid parameter
* \return ERR_SEND : Transmission error or acknowledge not received
*****************************************************************************
*/
extern void st25r3911ChangeTestRegisterBits( uint8_t reg, uint8_t valueMask, uint8_t value );
/*!
*****************************************************************************
* \brief Writes multiple values to ST25R3911 registers
*
* This function is used to write multiple values to the ST25R3911 using the
* auto-increment feature. That is, after each write the address pointer
* inside the ST25R3911 gets incremented automatically.
*
* \param[in] reg: Address of the frist register to write.
* \param[in] values: pointer to a buffer containing the values to be written.
* \param[in] length: Number of values to be written.
*
*****************************************************************************
*/
extern void st25r3911WriteMultipleRegisters(uint8_t reg, const uint8_t* values, uint8_t length);
/*!
*****************************************************************************
* \brief Reads from multiple ST25R3911 registers
*
* This function is used to read from multiple registers using the
* auto-increment feature. That is, after each read the address pointer
* inside the ST25R3911 gets incremented automatically.
*
* \param[in] reg: Address of the frist register to read from.
* \param[in] values: pointer to a buffer where the result shall be written to.
* \param[in] length: Number of registers to be read out.
*
*****************************************************************************
*/
extern void st25r3911ReadMultipleRegisters(uint8_t reg, uint8_t* values, uint8_t length);
/*!
*****************************************************************************
* \brief Writes values to ST25R3911 FIFO
*
* This function needs to be called in order to write to the ST25R3911 FIFO.
*
* \param[in] values: pointer to a buffer containing the values to be written
* to the FIFO.
* \param[in] length: Number of values to be written.
*
*****************************************************************************
*/
extern void st25r3911WriteFifo(const uint8_t* values, uint8_t length);
/*!
*****************************************************************************
* \brief Read values from ST25R3911 FIFO
*
* This function needs to be called in order to read from ST25R3911 FIFO.
*
* \param[out] buf: pointer to a buffer where the FIFO content shall be
* written to.
* \param[in] length: Number of bytes to read. (= size of \a buf)
* \note: This function doesn't check whether \a length is really the
* number of available bytes in FIFO
*
*****************************************************************************
*/
extern void st25r3911ReadFifo(uint8_t* buf, uint8_t length);
/*!
*****************************************************************************
* \brief Execute a direct command
*
* This function is used to start so-called direct command. These commands
* are implemented inside the chip and each command has unique code (see
* datasheet).
*
* \param[in] cmd : code of the direct command to be executed.
*
*****************************************************************************
*/
extern void st25r3911ExecuteCommand(uint8_t cmd);
/*!
*****************************************************************************
* \brief Execute several direct commands
*
* This function is used to start so-called direct command. These commands
* are implemented inside the chip and each command has unique code (see
* datasheet).
*
* \param[in] cmds : codes of the direct command to be executed.
* \param[in] length : number of commands to be executed
*
*****************************************************************************
*/
extern void st25r3911ExecuteCommands(const uint8_t *cmds, uint8_t length);
/*!
*****************************************************************************
* \brief Check if register ID is valid
*
* Checks if the given register ID a valid ST25R3911 register
*
* \param[in] reg: Address of register to check
*
* \return true if is a valid register ID
* \return false otherwise
*
*****************************************************************************
*/
extern bool st25r3911IsRegValid( uint8_t reg );
#endif /* ST25R3911_COM_H */
/**
* @}
*
* @}
*
* @}
*
* @}
*/

View File

@ -1,249 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R3911 firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file
*
* \author Ulrich Herrmann
*
* \brief ST25R3911 Interrupt handling
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "st25r3911_interrupt.h"
#include "st25r3911_com.h"
#include "st25r3911.h"
#include "st_errno.h"
#include "utils.h"
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
/*! Length of the interrupt registers */
#define ST25R3911_INT_REGS_LEN ( (ST25R3911_REG_IRQ_ERROR_WUP - ST25R3911_REG_IRQ_MAIN) + 1U )
/*
******************************************************************************
* LOCAL DATA TYPES
******************************************************************************
*/
/*! Holds current and previous interrupt callback pointer as well as current Interrupt status and mask */
typedef struct
{
void (*prevCallback)(void); /*!< call back function for 3911 interrupt */
void (*callback)(void); /*!< call back function for 3911 interrupt */
uint32_t status; /*!< latest interrupt status */
uint32_t mask; /*!< Interrupt mask. Negative mask = ST25R3911 mask regs */
}t_st25r3911Interrupt;
/*
******************************************************************************
* GLOBAL VARIABLES
******************************************************************************
*/
static volatile t_st25r3911Interrupt st25r3911interrupt; /*!< Instance of ST25R3911 interrupt */
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
void st25r3911InitInterrupts( void )
{
platformIrqST25R3911PinInitialize();
platformIrqST25R3911SetCallback( st25r3911Isr );
st25r3911interrupt.callback = NULL;
st25r3911interrupt.prevCallback = NULL;
st25r3911interrupt.status = ST25R3911_IRQ_MASK_NONE;
st25r3911interrupt.mask = ST25R3911_IRQ_MASK_NONE;
/* Initialize LEDs if existing and defined */
platformLedsInitialize();
#ifdef PLATFORM_LED_RX_PIN
platformLedOff( PLATFORM_LED_RX_PORT, PLATFORM_LED_RX_PIN );
#endif /* PLATFORM_LED_RX_PIN */
#ifdef PLATFORM_LED_FIELD_PIN
platformLedOff( PLATFORM_LED_FIELD_PORT, PLATFORM_LED_FIELD_PIN );
#endif /* PLATFORM_LED_FIELD_PIN */
}
void st25r3911Isr( void )
{
st25r3911CheckForReceivedInterrupts();
if (NULL != st25r3911interrupt.callback)
{
st25r3911interrupt.callback();
}
}
void st25r3911CheckForReceivedInterrupts( void )
{
uint8_t iregs[ST25R3911_INT_REGS_LEN];
uint32_t irqStatus;
irqStatus = ST25R3911_IRQ_MASK_NONE;
ST_MEMSET( iregs, (int32_t)(ST25R3911_IRQ_MASK_ALL & 0xFFU), ST25R3911_INT_REGS_LEN ); /* MISRA 10.3 */
/* In case the IRQ is Edge (not Level) triggered read IRQs until done */
while( platformGpioIsHigh( ST25R391X_INT_PORT, ST25R391X_INT_PIN ) )
{
st25r3911ReadMultipleRegisters(ST25R3911_REG_IRQ_MAIN, iregs, sizeof(iregs));
#ifdef PLATFORM_LED_FIELD_PIN
if ((iregs[0] & ST25R3911_IRQ_MASK_TXE) != 0U)
{
platformLedOn( PLATFORM_LED_FIELD_PORT, PLATFORM_LED_FIELD_PIN );
}
#endif /* PLATFORM_LED_FIELD_PIN */
#ifdef PLATFORM_LED_RX_PIN
if ((iregs[0] & ST25R3911_IRQ_MASK_RXS) != 0)
{
platformLedOn( PLATFORM_LED_RX_PORT, PLATFORM_LED_RX_PIN );
}
if (((iregs[0] & ST25R3911_IRQ_MASK_RXE) != 0) || ((iregs[1] & (ST25R3911_IRQ_MASK_NRE >> 8)) != 0)) /* In rare cases there is rxs but not rxe, then we have nre */
{
platformLedOff( PLATFORM_LED_RX_PORT, PLATFORM_LED_RX_PIN );
}
#endif /* PLATFORM_LED_RX_PIN */
irqStatus |= (uint32_t)iregs[0];
irqStatus |= (uint32_t)iregs[1]<<8;
irqStatus |= (uint32_t)iregs[2]<<16;
}
/* Forward all interrupts, even masked ones to application. */
platformProtectST25R391xIrqStatus();
st25r3911interrupt.status |= irqStatus;
platformUnprotectST25R391xIrqStatus();
}
void st25r3911ModifyInterrupts(uint32_t clr_mask, uint32_t set_mask)
{
uint8_t i;
uint32_t old_mask;
uint32_t new_mask;
old_mask = st25r3911interrupt.mask;
new_mask = (~old_mask & set_mask) | (old_mask & clr_mask);
st25r3911interrupt.mask &= ~clr_mask;
st25r3911interrupt.mask |= set_mask;
for (i=0; i<3U ; i++)
{
if (((new_mask >> (i*8U)) & 0xffU) == 0U) {
continue;
}
st25r3911WriteRegister((ST25R3911_REG_IRQ_MASK_MAIN + i), (uint8_t)((st25r3911interrupt.mask>>(i*8U))&0xffU));
}
return;
}
uint32_t st25r3911WaitForInterruptsTimed(uint32_t mask, uint16_t tmo)
{
uint32_t tmr;
uint32_t status;
tmr = platformTimerCreate(tmo);
do
{
status = (st25r3911interrupt.status & mask);
} while( ( !platformTimerIsExpired( tmr ) || (tmo == 0U)) && (status == 0U) );
status = st25r3911interrupt.status & mask;
platformProtectST25R391xIrqStatus();
st25r3911interrupt.status &= ~status;
platformUnprotectST25R391xIrqStatus();
return status;
}
uint32_t st25r3911GetInterrupt(uint32_t mask)
{
uint32_t irqs;
irqs = (st25r3911interrupt.status & mask);
if (irqs != ST25R3911_IRQ_MASK_NONE)
{
platformProtectST25R391xIrqStatus();
st25r3911interrupt.status &= ~irqs;
platformUnprotectST25R391xIrqStatus();
}
return irqs;
}
void st25r3911EnableInterrupts(uint32_t mask)
{
st25r3911ModifyInterrupts(mask,0);
}
void st25r3911DisableInterrupts(uint32_t mask)
{
st25r3911ModifyInterrupts(0,mask);
}
void st25r3911ClearInterrupts( void )
{
uint8_t iregs[3];
st25r3911ReadMultipleRegisters(ST25R3911_REG_IRQ_MAIN, iregs, 3);
platformProtectST25R391xIrqStatus();
st25r3911interrupt.status = 0;
platformUnprotectST25R391xIrqStatus();
return;
}
void st25r3911IRQCallbackSet( void (*cb)(void) )
{
st25r3911interrupt.prevCallback = st25r3911interrupt.callback;
st25r3911interrupt.callback = cb;
}
void st25r3911IRQCallbackRestore( void )
{
st25r3911interrupt.callback = st25r3911interrupt.prevCallback;
st25r3911interrupt.prevCallback = NULL;
}

View File

@ -1,250 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R3911 firmware
* Revision:
* LANGUAGE: ISO C99
*/
/*! \file
*
* \author Ulrich Herrmann
*
* \brief ST25R3911 Interrupt header file
*
*
* \addtogroup RFAL
* @{
*
* \addtogroup RFAL-HAL
* \brief RFAL Hardware Abstraction Layer
* @{
*
* \addtogroup ST25R3911
* \brief RFAL ST25R3911 Driver
* @{
*
* \addtogroup ST25R3911_Interrupt
* \brief RFAL ST25R3911 Interrupt
* @{
*
*/
#ifndef ST25R3911_INTERRUPT_H
#define ST25R3911_INTERRUPT_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
/* Main interrupt register. */
#define ST25R3911_IRQ_MASK_ALL (uint32_t)(0xFFFFFFU) /*!< All ST25R3911 interrupt sources */
#define ST25R3911_IRQ_MASK_NONE (uint32_t)(0U) /*!< No ST25R3911 interrupt source */
#define ST25R3911_IRQ_MASK_OSC (uint32_t)(0x80U) /*!< ST25R3911 oscillator stable interrupt */
#define ST25R3911_IRQ_MASK_FWL (uint32_t)(0x40U) /*!< ST25R3911 FIFO water level interrupt */
#define ST25R3911_IRQ_MASK_RXS (uint32_t)(0x20U) /*!< ST25R3911 start of receive interrupt */
#define ST25R3911_IRQ_MASK_RXE (uint32_t)(0x10U) /*!< ST25R3911 end of receive interrupt */
#define ST25R3911_IRQ_MASK_TXE (uint32_t)(0x08U) /*!< ST25R3911 end of transmission interrupt */
#define ST25R3911_IRQ_MASK_COL (uint32_t)(0x04U) /*!< ST25R3911 bit collision interrupt */
/* Timer and NFC interrupt register. */
#define ST25R3911_IRQ_MASK_DCT (uint32_t)(0x8000U) /*!< ST25R3911 termination of direct command interrupt */
#define ST25R3911_IRQ_MASK_NRE (uint32_t)(0x4000U) /*!< ST25R3911 no-response timer expired interrupt */
#define ST25R3911_IRQ_MASK_GPE (uint32_t)(0x2000U) /*!< ST25R3911 general purpose timer expired interrupt */
#define ST25R3911_IRQ_MASK_EON (uint32_t)(0x1000U) /*!< ST25R3911 external field on interrupt */
#define ST25R3911_IRQ_MASK_EOF (uint32_t)(0x0800U) /*!< ST25R3911 external field off interrupt */
#define ST25R3911_IRQ_MASK_CAC (uint32_t)(0x0400U) /*!< ST25R3911 collision during RF collision avoidance interrupt */
#define ST25R3911_IRQ_MASK_CAT (uint32_t)(0x0200U) /*!< ST25R3911 minimum guard time expired interrupt */
#define ST25R3911_IRQ_MASK_NFCT (uint32_t)(0x0100U) /*!< ST25R3911 initiator bit rate recognized interrupt */
/* Error and wake-up interrupt register. */
#define ST25R3911_IRQ_MASK_CRC (uint32_t)(0x800000U) /*!< ST25R3911 CRC error interrupt */
#define ST25R3911_IRQ_MASK_PAR (uint32_t)(0x400000U) /*!< ST25R3911 parity error interrupt */
#define ST25R3911_IRQ_MASK_ERR2 (uint32_t)(0x200000U) /*!< ST25R3911 soft framing error interrupt */
#define ST25R3911_IRQ_MASK_ERR1 (uint32_t)(0x100000U) /*!< ST25R3911 hard framing error interrupt */
#define ST25R3911_IRQ_MASK_WT (uint32_t)(0x080000U) /*!< ST25R3911 wake-up interrupt */
#define ST25R3911_IRQ_MASK_WAM (uint32_t)(0x040000U) /*!< ST25R3911 wake-up due to amplitude interrupt */
#define ST25R3911_IRQ_MASK_WPH (uint32_t)(0x020000U) /*!< ST25R3911 wake-up due to phase interrupt */
#define ST25R3911_IRQ_MASK_WCAP (uint32_t)(0x010000U) /*!< ST25R3911 wake-up due to capacitance measurement */
#define ST25R3911_IRQ_MASK_TIM (0x02U) /*!< additional interrupts in ST25R3911_REG_IRQ_TIMER_NFC */
#define ST25R3911_IRQ_MASK_ERR (0x01U) /*!< additional interrupts in ST25R3911_REG_IRQ_ERROR_WUP */
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief Wait until an ST25R3911 interrupt occurs
*
* This function is used to access the ST25R3911 interrupt flags. Use this
* to wait for max. \a tmo milliseconds for the \b first interrupt indicated
* with mask \a mask to occur.
*
* \param[in] mask : mask indicating the interrupts to wait for.
* \param[in] tmo : time in milliseconds until timeout occurs. If set to 0
* the functions waits forever.
*
* \return : 0 if timeout occurred otherwise a mask indicating the cleared
* interrupts.
*
*****************************************************************************
*/
extern uint32_t st25r3911WaitForInterruptsTimed(uint32_t mask, uint16_t tmo);
/*!
*****************************************************************************
* \brief Get status for the given interrupt
*
* This function is used to check whether the interrupt given by \a mask
* has occurred. If yes the interrupt gets cleared. This function returns
* only status bits which are inside \a mask.
*
* \param[in] mask : mask indicating the interrupt to check for.
*
* \return the mask of the interrupts occurred
*
*****************************************************************************
*/
extern uint32_t st25r3911GetInterrupt(uint32_t mask);
/*!
*****************************************************************************
* \brief Init the 3911 interrupt
*
* This function initiates the 3911 interrupts.
*
*****************************************************************************
*/
extern void st25r3911InitInterrupts( void );
/*!
*****************************************************************************
* \brief Modifies the Interrupt
*
* This function modifies the interrupt
*
* \param[in] clr_mask : bit mask to be cleared on the interrupt mask
* \param[in] set_mask : bit mask to be set on the interrupt mask
*****************************************************************************
*/
extern void st25r3911ModifyInterrupts(uint32_t clr_mask, uint32_t set_mask);
/*!
*****************************************************************************
* \brief Checks received interrupts
*
* Checks received interrupts and saves the result into global params
*****************************************************************************
*/
extern void st25r3911CheckForReceivedInterrupts( void );
/*!
*****************************************************************************
* \brief ISR Service routine
*
* This function modifies the interrupt
*****************************************************************************
*/
extern void st25r3911Isr( void );
/*!
*****************************************************************************
* \brief Enable a given ST25R3911 Interrupt source
*
* This function enables all interrupts given by \a mask,
* ST25R3911_IRQ_MASK_ALL enables all interrupts.
*
* \param[in] mask: mask indicating the interrupts to be enabled
*
*****************************************************************************
*/
extern void st25r3911EnableInterrupts(uint32_t mask);
/*!
*****************************************************************************
* \brief Disable one or more a given ST25R3911 Interrupt sources
*
* This function disables all interrupts given by \a mask. 0xff disables all.
*
* \param[in] mask: mask indicating the interrupts to be disabled.
*
*****************************************************************************
*/
extern void st25r3911DisableInterrupts(uint32_t mask);
/*!
*****************************************************************************
* \brief Clear all st25r3911 irq flags
*
*****************************************************************************
*/
extern void st25r3911ClearInterrupts(void);
/*!
*****************************************************************************
* \brief Sets IRQ callback for the ST25R3911 interrupt
*
*****************************************************************************
*/
extern void st25r3911IRQCallbackSet(void (*cb)(void));
/*!
*****************************************************************************
* \brief Sets IRQ callback for the ST25R3911 interrupt
*
*****************************************************************************
*/
extern void st25r3911IRQCallbackRestore(void);
#endif /* ST25R3911_ISR_H */
/**
* @}
*
* @}
*
* @}
*
* @}
*/

View File

@ -1,34 +0,0 @@
//
// Created by Kai Jan Kriegel on 12.10.22.
//
#include <memory.h>
#include <esp_err.h>
#include "st25r3911_spi.h"
#include "platform.h"
spi_device_handle_t pSpi;
#define SPI_BUF_LEN 32
void st25r3911_spi_init(spi_device_handle_t spi) {
pSpi = spi;
}
esp_err_t st25r3911_spiTxRx(const uint8_t *txData, uint8_t *rxData, uint16_t length) {
if (length > SPI_BUF_LEN) {
return ESP_FAIL;
}
spi_transaction_t t;
memset(&t, 0, sizeof(t));
t.length = length * 8;
t.rx_buffer = rxData;
t.tx_buffer = txData;
esp_err_t ret = spi_device_polling_transmit(pSpi, &t);
ESP_ERROR_CHECK(ret);
return ret;
}

View File

@ -1,15 +0,0 @@
//
// Created by Kai Jan Kriegel on 12.10.22.
//
#ifndef FAB_READER2_C_ST25R3911_SPI_H
#define FAB_READER2_C_ST25R3911_SPI_H
#include <esp_err.h>
#include <driver/spi_master.h>
void st25r3911_spi_init(spi_device_handle_t spi);
esp_err_t st25r3911_spiTxRx(const uint8_t *txData, uint8_t *rxData, uint16_t length);
#endif //FAB_READER2_C_ST25R3911_SPI_H

View File

@ -1,164 +0,0 @@
/******************************************************************************
* \attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: STxxxx firmware
* LANGUAGE: ISO C99
*/
/*! \file st_errno.h
*
* \author
*
* \brief Main error codes
*
*/
#ifndef ST_ERRNO_H
#define ST_ERRNO_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
/*
******************************************************************************
* GLOBAL DATA TYPES
******************************************************************************
*/
typedef uint16_t ReturnCode; /*!< Standard Return Code type from function. */
/*
******************************************************************************
* DEFINES
******************************************************************************
*/
/*
* Error codes to be used within the application.
* They are represented by an uint8_t
*/
#define ERR_NONE ((ReturnCode)0U) /*!< no error occurred */
#define ERR_NOMEM ((ReturnCode)1U) /*!< not enough memory to perform the requested operation */
#define ERR_BUSY ((ReturnCode)2U) /*!< device or resource busy */
#define ERR_IO ((ReturnCode)3U) /*!< generic IO error */
#define ERR_TIMEOUT ((ReturnCode)4U) /*!< error due to timeout */
#define ERR_REQUEST ((ReturnCode)5U) /*!< invalid request or requested function can't be executed at the moment */
#define ERR_NOMSG ((ReturnCode)6U) /*!< No message of desired type */
#define ERR_PARAM ((ReturnCode)7U) /*!< Parameter error */
#define ERR_SYSTEM ((ReturnCode)8U) /*!< System error */
#define ERR_FRAMING ((ReturnCode)9U) /*!< Framing error */
#define ERR_OVERRUN ((ReturnCode)10U) /*!< lost one or more received bytes */
#define ERR_PROTO ((ReturnCode)11U) /*!< protocol error */
#define ERR_INTERNAL ((ReturnCode)12U) /*!< Internal Error */
#define ERR_AGAIN ((ReturnCode)13U) /*!< Call again */
#define ERR_MEM_CORRUPT ((ReturnCode)14U) /*!< memory corruption */
#define ERR_NOT_IMPLEMENTED ((ReturnCode)15U) /*!< not implemented */
#define ERR_PC_CORRUPT ((ReturnCode)16U) /*!< Program Counter has been manipulated or spike/noise trigger illegal operation */
#define ERR_SEND ((ReturnCode)17U) /*!< error sending*/
#define ERR_IGNORE ((ReturnCode)18U) /*!< indicates error detected but to be ignored */
#define ERR_SEMANTIC ((ReturnCode)19U) /*!< indicates error in state machine (unexpected cmd) */
#define ERR_SYNTAX ((ReturnCode)20U) /*!< indicates error in state machine (unknown cmd) */
#define ERR_CRC ((ReturnCode)21U) /*!< crc error */
#define ERR_NOTFOUND ((ReturnCode)22U) /*!< transponder not found */
#define ERR_NOTUNIQUE ((ReturnCode)23U) /*!< transponder not unique - more than one transponder in field */
#define ERR_NOTSUPP ((ReturnCode)24U) /*!< requested operation not supported */
#define ERR_WRITE ((ReturnCode)25U) /*!< write error */
#define ERR_FIFO ((ReturnCode)26U) /*!< fifo over or underflow error */
#define ERR_PAR ((ReturnCode)27U) /*!< parity error */
#define ERR_DONE ((ReturnCode)28U) /*!< transfer has already finished */
#define ERR_RF_COLLISION ((ReturnCode)29U) /*!< collision error (Bit Collision or during RF Collision avoidance ) */
#define ERR_HW_OVERRUN ((ReturnCode)30U) /*!< lost one or more received bytes */
#define ERR_RELEASE_REQ ((ReturnCode)31U) /*!< device requested release */
#define ERR_SLEEP_REQ ((ReturnCode)32U) /*!< device requested sleep */
#define ERR_WRONG_STATE ((ReturnCode)33U) /*!< incorrent state for requested operation */
#define ERR_MAX_RERUNS ((ReturnCode)34U) /*!< blocking procedure reached maximum runs */
#define ERR_DISABLED ((ReturnCode)35U) /*!< operation aborted due to disabled configuration */
#define ERR_HW_MISMATCH ((ReturnCode)36U) /*!< expected hw do not match */
#define ERR_LINK_LOSS ((ReturnCode)37U) /*!< Other device's field didn't behave as expected: turned off by Initiator in Passive mode, or AP2P did not turn on field */
#define ERR_INVALID_HANDLE ((ReturnCode)38U) /*!< invalid or not initalized device handle */
#define ERR_INCOMPLETE_BYTE ((ReturnCode)40U) /*!< Incomplete byte rcvd */
#define ERR_INCOMPLETE_BYTE_01 ((ReturnCode)41U) /*!< Incomplete byte rcvd - 1 bit */
#define ERR_INCOMPLETE_BYTE_02 ((ReturnCode)42U) /*!< Incomplete byte rcvd - 2 bit */
#define ERR_INCOMPLETE_BYTE_03 ((ReturnCode)43U) /*!< Incomplete byte rcvd - 3 bit */
#define ERR_INCOMPLETE_BYTE_04 ((ReturnCode)44U) /*!< Incomplete byte rcvd - 4 bit */
#define ERR_INCOMPLETE_BYTE_05 ((ReturnCode)45U) /*!< Incomplete byte rcvd - 5 bit */
#define ERR_INCOMPLETE_BYTE_06 ((ReturnCode)46U) /*!< Incomplete byte rcvd - 6 bit */
#define ERR_INCOMPLETE_BYTE_07 ((ReturnCode)47U) /*!< Incomplete byte rcvd - 7 bit */
/* General Sub-category number */
#define ERR_GENERIC_GRP (0x0000) /*!< Reserved value for generic error no */
#define ERR_WARN_GRP (0x0100) /*!< Errors which are not expected in normal operation */
#define ERR_PROCESS_GRP (0x0200) /*!< Processes management errors */
#define ERR_SIO_GRP (0x0800) /*!< SIO errors due to logging */
#define ERR_RINGBUF_GRP (0x0900) /*!< Ring Buffer errors */
#define ERR_MQ_GRP (0x0A00) /*!< MQ errors */
#define ERR_TIMER_GRP (0x0B00) /*!< Timer errors */
#define ERR_RFAL_GRP (0x0C00) /*!< RFAL errors */
#define ERR_UART_GRP (0x0D00) /*!< UART errors */
#define ERR_SPI_GRP (0x0E00) /*!< SPI errors */
#define ERR_I2C_GRP (0x0F00) /*!< I2c errors */
#define ERR_INSERT_SIO_GRP(x) (ERR_SIO_GRP | (x)) /*!< Insert the SIO grp */
#define ERR_INSERT_RINGBUF_GRP(x) (ERR_RINGBUF_GRP | (x)) /*!< Insert the Ring Buffer grp */
#define ERR_INSERT_RFAL_GRP(x) (ERR_RFAL_GRP | (x)) /*!< Insert the RFAL grp */
#define ERR_INSERT_SPI_GRP(x) (ERR_SPI_GRP | (x)) /*!< Insert the spi grp */
#define ERR_INSERT_I2C_GRP(x) (ERR_I2C_GRP | (x)) /*!< Insert the i2c grp */
#define ERR_INSERT_UART_GRP(x) (ERR_UART_GRP | (x)) /*!< Insert the uart grp */
#define ERR_INSERT_TIMER_GRP(x) (ERR_TIMER_GRP | (x)) /*!< Insert the timer grp */
#define ERR_INSERT_MQ_GRP(x) (ERR_MQ_GRP | (x)) /*!< Insert the mq grp */
#define ERR_INSERT_PROCESS_GRP(x) (ERR_PROCESS_GRP | (x)) /*!< Insert the process grp */
#define ERR_INSERT_WARN_GRP(x) (ERR_WARN_GRP | (x)) /*!< Insert the i2c grp */
#define ERR_INSERT_GENERIC_GRP(x) (ERR_GENERIC_GRP | (x)) /*!< Insert the generic grp */
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
#define ERR_NO_MASK(x) ((uint16_t)(x) & 0x00FFU) /*!< Mask the error number */
/*! Common code to exit a function with the error if function f return error */
#define EXIT_ON_ERR(r, f) \
(r) = (f); \
if (ERR_NONE != (r)) \
{ \
return (r); \
}
#endif /* ST_ERRNO_H */

View File

@ -1,121 +0,0 @@
/******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* $Revision: $
* LANGUAGE: ANSI C
*/
/*! \file timer.c
*
* \brief SW Timer implementation
*
* \author Gustavo Patricio
*
* This module makes use of a System Tick in millisconds and provides
* an abstraction for SW timers
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "timer.h"
/*
******************************************************************************
* LOCAL DEFINES
******************************************************************************
*/
/*
******************************************************************************
* LOCAL VARIABLES
******************************************************************************
*/
static uint32_t timerStopwatchTick;
/*
******************************************************************************
* GLOBAL FUNCTIONS
******************************************************************************
*/
/*******************************************************************************/
uint32_t timerCalculateTimer( uint16_t time )
{
return (platformGetSysTick() + time);
}
/*******************************************************************************/
bool timerIsExpired( uint32_t timer )
{
uint32_t uDiff;
int32_t sDiff;
uDiff = (timer - platformGetSysTick()); /* Calculate the diff between the timers */
sDiff = uDiff; /* Convert the diff to a signed var */
/* Having done this has two side effects:
* 1) all differences smaller than -(2^31) ms (~25d) will become positive
* Signaling not expired: acceptable!
* 2) Time roll-over case will be handled correctly: super!
*/
/* Check if the given timer has expired already */
if( sDiff < 0 )
{
return true;
}
return false;
}
/*******************************************************************************/
void timerDelay( uint16_t tOut )
{
uint32_t t;
/* Calculate the timer and wait blocking until is running */
t = timerCalculateTimer( tOut );
while( timerIsRunning(t) );
}
/*******************************************************************************/
void timerStopwatchStart( void )
{
timerStopwatchTick = platformGetSysTick();
}
/*******************************************************************************/
uint32_t timerStopwatchMeasure( void )
{
return (uint32_t)(platformGetSysTick() - timerStopwatchTick);
}

View File

@ -1,128 +0,0 @@
/******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: ST25R391x firmware
* $Revision: $
* LANGUAGE: ANSI C
*/
/*! \file timer.h
*
* \brief SW Timer implementation header file
*
* This module makes use of a System Tick in millisconds and provides
* an abstraction for SW timers
*
*/
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include "platform.h"
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
#define timerIsRunning(t) (!timerIsExpired(t))
/*
******************************************************************************
* GLOBAL DEFINES
******************************************************************************
*/
/*!
*****************************************************************************
* \brief Calculate Timer
*
* This method calculates when the timer will be expired given the amount
* time in milliseconds /a tOut.
* Once the timer has been calculated it will then be used to check when
* it expires.
*
* \see timersIsExpired
*
* \param[in] time : time/duration in Milliseconds for the timer
*
* \return u32 : The new timer calculated based on the given time
*****************************************************************************
*/
uint32_t timerCalculateTimer( uint16_t time );
/*!
*****************************************************************************
* \brief Checks if a Timer is Expired
*
* This method checks if a timer has already expired.
* Based on the given timer previously calculated it checks if this timer
* has already elapsed
*
* \see timersCalculateTimer
*
* \param[in] timer : the timer to check
*
* \return true : timer has already expired
* \return false : timer is still running
*****************************************************************************
*/
bool timerIsExpired( uint32_t timer );
/*!
*****************************************************************************
* \brief Performs a Delay
*
* This method performs a delay for the given amount of time in Milliseconds
*
* \param[in] time : time/duration in Milliseconds of the delay
*
*****************************************************************************
*/
void timerDelay( uint16_t time );
/*!
*****************************************************************************
* \brief Stopwatch start
*
* This method initiates the stopwatch to later measure the time in ms
*
*****************************************************************************
*/
void timerStopwatchStart( void );
/*!
*****************************************************************************
* \brief Stopwatch Measure
*
* This method returns the elapsed time in ms since the stopwatch was initiated
*
* \return The time in ms since the stopwatch was started
*****************************************************************************
*/
uint32_t timerStopwatchMeasure( void );

View File

@ -1,41 +0,0 @@
//
// Created by Kai Jan Kriegel on 17.10.22.
//
#include "utils.h"
#define MAX_HEX_STR 4
#define MAX_HEX_STR_LENGTH 128
char hexStr[MAX_HEX_STR][MAX_HEX_STR_LENGTH];
uint8_t hexStrIdx = 0;
char *hex2Str(unsigned char *data, size_t dataLen) {
{
unsigned char *pin = data;
const char *hex = "0123456789ABCDEF";
char *pout = hexStr[hexStrIdx];
uint8_t i = 0;
uint8_t idx = hexStrIdx;
size_t len;
if (dataLen == 0) {
pout[0] = 0;
} else {
/* Trim data that doesn't fit in buffer */
len = MIN(dataLen, (MAX_HEX_STR_LENGTH / 2));
for (; i < (len - 1); ++i) {
*pout++ = hex[(*pin >> 4) & 0xF];
*pout++ = hex[(*pin++) & 0xF];
}
*pout++ = hex[(*pin >> 4) & 0xF];
*pout++ = hex[(*pin) & 0xF];
*pout = 0;
}
hexStrIdx++;
hexStrIdx %= MAX_HEX_STR;
return hexStr[idx];
}
}

View File

@ -1,113 +0,0 @@
/******************************************************************************
* @attention
*
* <h2><center>&copy; COPYRIGHT 2016 STMicroelectronics</center></h2>
*
* Licensed under ST MYLIBERTY SOFTWARE LICENSE AGREEMENT (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* www.st.com/myliberty
*
* 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,
* AND SPECIFICALLY DISCLAIMING THE IMPLIED WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
/*
* PROJECT: NFCC firmware
* $Revision: $
* LANGUAGE: ISO C99
*/
/*! \file
*
* \author Ulrich Herrmann
*
* \brief Common and helpful macros
*
*/
#ifndef UTILS_H
#define UTILS_H
/*
******************************************************************************
* INCLUDES
******************************************************************************
*/
#include <string.h>
/*
******************************************************************************
* GLOBAL MACROS
******************************************************************************
*/
/*!
* this macro evaluates an error variable \a ERR against an error code \a EC.
* in case it is not equal it jumps to the given label \a LABEL.
*/
#define EVAL_ERR_NE_GOTO(EC, ERR, LABEL) \
if ((EC) != (ERR)) goto LABEL;
/*!
* this macro evaluates an error variable \a ERR against an error code \a EC.
* in case it is equal it jumps to the given label \a LABEL.
*/
#define EVAL_ERR_EQ_GOTO(EC, ERR, LABEL) \
if ((EC) == (ERR)) goto LABEL;
#define SIZEOF_ARRAY(a) (sizeof(a) / sizeof((a)[0])) /*!< Compute the size of an array */
#define MAX(a, b) (((a) > (b)) ? (a) : (b)) /*!< Return the maximum of the 2 values */
#define MIN(a, b) (((a) < (b)) ? (a) : (b)) /*!< Return the minimum of the 2 values */
#define BITMASK_1 (0x01) /*!< Bit mask for lsb bit */
#define BITMASK_2 (0x03) /*!< Bit mask for two lsb bits */
#define BITMASK_3 (0x07) /*!< Bit mask for three lsb bits */
#define BITMASK_4 (0x0F) /*!< Bit mask for four lsb bits */
#define U16TOU8(a) ((a) & 0x00FF) /*!< Cast 16-bit unsigned to 8-bit unsigned */
#define GETU16(a) (((uint16_t)(a)[0] << 8) | (uint16_t)(a)[1])/*!< Cast two Big Endian 8-bits byte array to 16-bits unsigned */
#define GETU32(a) (((uint32_t)(a)[0] << 24) | ((uint32_t)(a)[1] << 16) | ((uint32_t)(a)[2] << 8) | ((uint32_t)(a)[3])) /*!< Cast four Big Endian 8-bit byte array to 32-bit unsigned */
#define REVERSE_BYTES(pData, nDataSize) \
{unsigned char swap, *lo = ((unsigned char *)(pData)), *hi = ((unsigned char *)(pData)) + (nDataSize) - 1; \
while (lo < hi) { swap = *lo; *lo++ = *hi; *hi-- = swap; }}
#ifdef __CSMC__
/* STM8 COSMIC */
#define ST_MEMMOVE(s1,s2,n) memmove(s1,s2,n) /*!< map memmove to string library code */
static inline void * ST_MEMCPY(void *s1, const void *s2, uint32_t n) { return memcpy(s1,s2,(uint16_t)n); } /* PRQA S 0431 # MISRA 1.1 - string.h from Cosmic only provides functions with low qualified parameters */
#define ST_MEMSET(s1,c,n) memset(s1,(char)(c),n) /*!< map memset to string library code */
static inline int32_t ST_BYTECMP(void *s1, const void *s2, uint32_t n) { return (int32_t)memcmp(s1,s2,(uint16_t)n); } /* PRQA S 0431 # MISRA 1.1 - string.h from Cosmic only provides functions with low qualified parameters */
#else /* __CSMC__ */
#define ST_MEMMOVE memmove /*!< map memmove to string library code */
#define ST_MEMCPY memcpy /*!< map memcpy to string library code */
#define ST_MEMSET memset /*!< map memset to string library code */
#define ST_BYTECMP memcmp /*!< map bytecmp to string library code */
#endif /* __CSMC__ */
#define NO_WARNING(v) ((void) (v)) /*!< Macro to suppress compiler warning */
#ifndef NULL
#define NULL (void*)0 /*!< represents a NULL pointer */
#endif /* !NULL */
/*
******************************************************************************
* GLOBAL FUNCTION PROTOTYPES
******************************************************************************
*/
char *hex2Str(unsigned char *data, size_t dataLen);
#endif /* UTILS_H */

File diff suppressed because it is too large Load Diff

View File

@ -1,6 +0,0 @@
target remote :3333
set remote hardware-watchpoint-limit 2
mon reset halt
flushregs
thb app_main
c

View File

@ -1,4 +0,0 @@
idf_component_register(SRCS "fab-reader2.c" "nfc/pollingtagdetect.c" "epd/qrurn.c" "epd/FabAccess_Icon_NoHeader.c" "epd/EPD_2in66_test.c" "epd/epd.c" "epd/EPD_2in66_test.c" "ota/ota.c"
INCLUDE_DIRS "." "nfc" "epd" "ota"
REQUIRES "rfal" "epd_266" "epd_gfx"
PRIV_REQUIRES "driver nvs_flash mqtt")

View File

@ -1,50 +0,0 @@
menu "FabReader Configuration"
config WIFI_SSID
string "WiFi SSID"
default "myssid"
help
SSID (network name) for the example to connect to.
config WIFI_PASSWORD
string "WiFi Password"
default "mypassword"
help
WiFi password (WPA or WPA2) for the example to use.
choice WIFI_SCAN_METHOD
prompt "scan method"
default WIFI_FAST_SCAN
help
scan method for the esp32 to use
config WIFI_FAST_SCAN
bool "fast"
config WIFI_ALL_CHANNEL_SCAN
bool "all"
endchoice
config BROKER_URI
string "Broker URL"
default "mqtts://mqtt.eclipseprojects.io:8883"
help
URL of an mqtt broker which this example connects to.
config BROKER_CERTIFICATE_OVERRIDE
string "Broker certificate override"
default ""
help
Please leave empty if broker certificate included from a textfile; otherwise fill in a base64 part of PEM
format certificate
config BROKER_CERTIFICATE_OVERRIDDEN
bool
default y if BROKER_CERTIFICATE_OVERRIDE != ""
config FABREADER2_ID
int "FabReader2 ID"
default 1
help
Numerical ID of the FabReader2 device
endmenu

View File

@ -1,160 +0,0 @@
/*****************************************************************************
* | File : EPD_2IN66_test.c
* | Author : Waveshare team
* | Function : 2.66inch e-paper test demo
* | Info :
*----------------
* | This version: V1.0
* | Date : 2020-07-29
* | Info :
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
******************************************************************************/
#include "epd.h"
#include "EPD_2in66.h"
int EPD_test(void)
{
printf("EPD_2IN66_test Demo\r\n");
if(DEV_Module_Init()!=0){
return -1;
}
printf("e-Paper Init and Clear...\r\n");
EPD_2IN66_Init();
// EPD_2IN66_Clear();
// DEV_Delay_ms(500);
//Create a new image cache
UBYTE *BlackImage;
/* you have to edit the startup_stm32fxxx.s file and set a big enough heap size */
UWORD Imagesize = ((EPD_2IN66_WIDTH % 8 == 0)? (EPD_2IN66_WIDTH / 8 ): (EPD_2IN66_WIDTH / 8 + 1)) * EPD_2IN66_HEIGHT;
if((BlackImage = (UBYTE *)malloc(Imagesize)) == NULL) {
printf("Failed to apply for black memory...\r\n");
return -1;
}
printf("Paint_NewImage\r\n");
Paint_NewImage(BlackImage, EPD_2IN66_WIDTH, EPD_2IN66_HEIGHT, 270, WHITE);
Paint_SelectImage(BlackImage);
Paint_Clear(WHITE);
Paint_DrawString_EN(10, 10, "Welcome to FabAccess", &Font16, WHITE, BLACK);
Paint_DrawBitMap_Paste(gImage_FabAccess_Icon_NoHeader, 20, 40, 100, 98, TRUE);
Paint_DrawBitMap_Paste(gImage_qrurn, 130, 40, 100, 100, TRUE);
EPD_2IN66_Display(BlackImage);
#if 0 //show image for array
printf("show image for array\r\n");
Paint_SelectImage(BlackImage);
Paint_Clear(WHITE);
Paint_DrawBitMap(gImage_2in66);
Paint_DrawBitMap_Paste(gImage_100X50, 10, 10, 100, 50, TRUE);
EPD_2IN66_Display(BlackImage);
DEV_Delay_ms(10000);
#endif
#if 0 // Drawing on the image
//1.Select Image
Paint_SelectImage(BlackImage);
Paint_Clear(WHITE);
// 2.Drawing on the image
printf("Drawing:BlackImage\r\n");
Paint_DrawPoint(10, 80, BLACK, DOT_PIXEL_1X1, DOT_STYLE_DFT);
Paint_DrawPoint(10, 90, BLACK, DOT_PIXEL_2X2, DOT_STYLE_DFT);
Paint_DrawPoint(10, 100, BLACK, DOT_PIXEL_3X3, DOT_STYLE_DFT);
Paint_DrawLine(20, 70, 70, 120, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
Paint_DrawLine(70, 70, 20, 120, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
Paint_DrawRectangle(20, 70, 70, 120, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
Paint_DrawRectangle(80, 70, 130, 120, BLACK, DOT_PIXEL_1X1, DRAW_FILL_FULL);
Paint_DrawCircle(45, 95, 20, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
Paint_DrawCircle(105, 95, 20, WHITE, DOT_PIXEL_1X1, DRAW_FILL_FULL);
Paint_DrawLine(85, 95, 125, 95, BLACK, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
Paint_DrawLine(105, 75, 105, 115, BLACK, DOT_PIXEL_1X1, LINE_STYLE_DOTTED);
Paint_DrawString_EN(10, 0, "waveshare", &Font16, BLACK, WHITE);
Paint_DrawString_EN(10, 20, "hello world", &Font12, WHITE, BLACK);
Paint_DrawNum(10, 33, 123456789, &Font12, BLACK, WHITE);
Paint_DrawNum(10, 50, 987654321, &Font16, WHITE, BLACK);
EPD_2IN66_Display(BlackImage);
DEV_Delay_ms(10000);
#endif
#if 0 //partial refresh, show time
printf("EPD_2IN66_DisplayPart\r\n");
EPD_2IN66_Init_Partial();
Paint_SelectImage(BlackImage);
PAINT_TIME sPaint_time; //time struct
sPaint_time.Hour = 12;
sPaint_time.Min = 34;
sPaint_time.Sec = 56;
for (uint8_t i = 100; i > 0; i--) {
sPaint_time.Sec = sPaint_time.Sec + 1;
if (sPaint_time.Sec == 60) {
sPaint_time.Min = sPaint_time.Min + 1;
sPaint_time.Sec = 0;
if (sPaint_time.Min == 60) {
sPaint_time.Hour = sPaint_time.Hour + 1;
sPaint_time.Min = 0;
if (sPaint_time.Hour == 24) {
sPaint_time.Hour = 0;
sPaint_time.Min = 0;
sPaint_time.Sec = 0;
}
}
}
Paint_ClearWindows(180, 100, 296, 152, WHITE);
Paint_DrawTime(180, 110, &sPaint_time, &Font20, WHITE, BLACK);
printf("Part refresh...\r\n");
EPD_2IN66_Display(BlackImage);
DEV_Delay_ms(500);
}
EPD_2IN66_Clear();
#endif
// printf("Clear...\r\n");
// EPD_2IN66_Init();
// EPD_2IN66_Clear();
printf("Goto Sleep...\r\n");
EPD_2IN66_Sleep();
free(BlackImage);
BlackImage = NULL;
// close 5V
printf("close 5V, Module enters 0 power consumption ...\r\n");
DEV_Module_Exit();
return 0;
}

View File

@ -1,81 +0,0 @@
const unsigned char gImage_FabAccess_Icon_NoHeader[1274] = { /* 0X00,0X01,0X64,0X00,0X62,0X00, */
0X00,0X00,0X7F,0XC0,0X00,0X00,0X00,0X00,0X00,0X3F,0XE0,0X00,0X00,0X00,0X03,0XFF,
0XF8,0X00,0X00,0X00,0X00,0X01,0XFF,0XFC,0X00,0X00,0X00,0X1F,0XFF,0XFF,0X00,0X00,
0X00,0X00,0X0F,0XFF,0XFF,0X80,0X00,0X00,0X3F,0XFF,0XFF,0X80,0X00,0X00,0X00,0X1F,
0XFF,0XFF,0XC0,0X00,0X00,0XFF,0XFF,0XFF,0XE0,0X00,0X00,0X00,0X7F,0XFF,0XFF,0XF0,
0X00,0X01,0XFF,0XFF,0XFF,0XF0,0X00,0X00,0X00,0XFF,0XFF,0XFF,0XF8,0X00,0X03,0XFF,
0XFF,0XFF,0XF8,0X00,0X00,0X01,0XFF,0XFF,0XFF,0XFC,0X00,0X07,0XFF,0XE0,0XFF,0XFC,
0XFF,0XFF,0XF3,0XFF,0XF0,0X7F,0XFE,0X00,0X0F,0XFF,0X80,0X3F,0XFE,0X7F,0XFF,0XE7,
0XFF,0XC0,0X1F,0XFF,0X00,0X0F,0XFF,0X00,0X1F,0XFE,0X7F,0XFF,0XE7,0XFF,0X80,0X0F,
0XFF,0X00,0X1F,0XFE,0X01,0X8F,0XFF,0X3F,0XFF,0XCF,0XFF,0X18,0X07,0XFF,0X80,0X3F,
0XFE,0X07,0XCF,0XFF,0X00,0X00,0X1F,0XFF,0X3E,0X07,0XFF,0XC0,0X3F,0XFE,0X0F,0XEF,
0XFF,0X80,0X00,0X1F,0XFF,0X7F,0X07,0XFF,0XC0,0X7F,0XFC,0X0F,0X87,0XFF,0X80,0X00,
0X1F,0XFE,0X1F,0X03,0XFF,0XC0,0X7F,0XFC,0X0F,0X07,0XFF,0XC0,0X00,0X3F,0XFE,0X0F,
0X03,0XFF,0XE0,0X7F,0XFC,0X0F,0XEF,0XFF,0XC0,0X00,0X3F,0XFF,0X7F,0X03,0XFF,0XE0,
0X7F,0XFE,0X07,0XC0,0XFF,0XC0,0X00,0X3F,0XF8,0X3E,0X07,0XFF,0XE0,0XFF,0XFE,0X03,
0XC0,0X00,0X60,0X00,0X60,0X00,0X3C,0X07,0XFF,0XF0,0XFF,0XFF,0X00,0X00,0X00,0X0F,
0XFF,0X00,0X00,0X00,0X0F,0XFF,0XF0,0XFF,0XFF,0X80,0X38,0X00,0X07,0XFE,0X00,0X01,
0XC0,0X1F,0XFF,0XF0,0XFF,0XFF,0XC0,0X7F,0XF0,0X07,0XFE,0X00,0XFF,0XE0,0X3F,0XFF,
0XF0,0XFF,0XFF,0XFF,0XFF,0XFF,0XE0,0X00,0X7F,0XFF,0XFF,0XFF,0XFF,0XF0,0XFF,0XFF,
0XFF,0XFF,0XFF,0XE0,0X00,0X7F,0XFF,0XFF,0XFF,0XFF,0XF0,0XFF,0XFF,0XFF,0XFF,0XFF,
0XE0,0X00,0X7F,0XFF,0XFF,0XFF,0XFF,0XF0,0XFF,0XFF,0XFF,0XFF,0XFF,0XE0,0X00,0X7F,
0XFF,0XFF,0XFF,0XFF,0XF0,0XFF,0XFF,0XFF,0XFF,0XFF,0XC0,0X00,0X78,0X00,0X00,0X00,
0X00,0XF0,0X7F,0XFF,0XFF,0XFF,0XFF,0XC0,0X00,0X78,0X00,0X00,0X00,0X00,0XF0,0X7F,
0XFF,0XFF,0XFF,0XFF,0XC0,0X00,0X78,0X00,0X00,0X00,0X00,0XF0,0X7F,0XFF,0XFF,0XFF,
0XFF,0XC0,0X00,0X78,0X00,0X00,0X00,0X00,0XF0,0X3F,0XFF,0XFF,0XFF,0XFF,0X80,0X00,
0X78,0X00,0X00,0X00,0X00,0XF0,0X3F,0XFF,0XFF,0XFF,0XFF,0X80,0X00,0X78,0X00,0X00,
0X00,0X00,0XF0,0X1F,0XFF,0XFF,0XFF,0XFF,0X00,0X00,0X78,0X00,0X00,0X00,0X00,0XF0,
0X1F,0XFF,0XFF,0XFF,0XFF,0X00,0X00,0X78,0X00,0X00,0X00,0X00,0XF0,0X0F,0XFF,0XFF,
0XFF,0XFE,0X00,0X00,0X78,0X00,0X00,0X00,0X00,0XF0,0X07,0XFF,0XFF,0XFF,0XFC,0X00,
0X00,0X78,0X00,0X7F,0XF0,0X00,0XF0,0X03,0XFF,0XFF,0XFF,0XF8,0X00,0X00,0X78,0X01,
0XFF,0XFC,0X00,0XF0,0X01,0XFF,0XFF,0XFF,0XF0,0X00,0X00,0X78,0X07,0XFF,0XFF,0X00,
0XF0,0X00,0XFF,0XFF,0XFF,0XE0,0X00,0X00,0X78,0X1F,0XF0,0X7F,0XC0,0XF0,0X00,0X7F,
0XFF,0XFF,0XC0,0X00,0X00,0X78,0X3F,0X80,0X07,0XE0,0XF0,0X00,0X1F,0XFF,0XFF,0X00,
0X00,0X00,0X78,0X3E,0X1F,0XC3,0XF0,0XF0,0X00,0X0F,0XFF,0XFC,0X00,0X00,0X00,0X78,
0X78,0XFF,0XF8,0XF0,0XF0,0X00,0X03,0XFF,0XF8,0X00,0X00,0X00,0X78,0X31,0XFF,0XFC,
0X60,0XF0,0X00,0X03,0XFF,0XF8,0X00,0X00,0X00,0X78,0X03,0XFF,0XFE,0X00,0XF0,0X00,
0X03,0XFF,0XF8,0X00,0X00,0X00,0X78,0X07,0XE0,0X1F,0X00,0XF0,0X00,0X03,0XFF,0XF8,
0X00,0X00,0X00,0X78,0X07,0X87,0X0F,0X00,0XF0,0X00,0X03,0XFF,0XF8,0X00,0X00,0X00,
0X78,0X03,0X3F,0XE6,0X00,0XF0,0X00,0X03,0XC7,0XF8,0X00,0X00,0X00,0X78,0X00,0X7F,
0XF0,0X00,0XF0,0X00,0X03,0XC7,0XF8,0X00,0X00,0X00,0X78,0X00,0X7F,0XF0,0X00,0XF0,
0X00,0X03,0XC7,0XF8,0X00,0X00,0X00,0X78,0X00,0X70,0X70,0X00,0XF0,0X00,0X03,0XC7,
0XF8,0X00,0X00,0X00,0X78,0X00,0X00,0X00,0X00,0XF0,0X00,0X03,0XC7,0XF8,0X00,0X00,
0X00,0X78,0X00,0X07,0X00,0X00,0XF0,0X00,0X03,0XC7,0XF0,0X00,0X00,0X00,0X78,0X00,
0X07,0X00,0X00,0XF0,0X00,0X03,0XC7,0XE0,0X00,0X00,0X00,0X78,0X00,0X07,0X00,0X00,
0XF0,0X00,0X03,0XC7,0XE0,0X00,0X00,0X00,0X78,0X00,0X00,0X00,0X00,0XF0,0X00,0X03,
0XC7,0XE0,0X00,0X00,0X00,0X78,0X00,0X00,0X00,0X00,0XF0,0X00,0X03,0XC7,0XE0,0X00,
0X00,0X00,0X78,0X00,0X00,0X00,0X00,0XF0,0X00,0X03,0XC7,0XF0,0X00,0X00,0X00,0X78,
0X00,0X00,0X00,0X00,0XF0,0X00,0X03,0XC7,0XF0,0X00,0X00,0X00,0X78,0X00,0X00,0X00,
0X00,0XF0,0X00,0X03,0XC7,0XF8,0X00,0X00,0X00,0X78,0X00,0X00,0X00,0X00,0XF0,0X00,
0X03,0XC7,0XF8,0X00,0X00,0X00,0X78,0X00,0X00,0X00,0X00,0XF0,0X00,0X03,0XC7,0XF8,
0X00,0X00,0X00,0X7F,0XFF,0XFF,0XFF,0XFF,0XF0,0X00,0X03,0XC7,0XF0,0X00,0X00,0X00,
0X7F,0XFF,0XFF,0XFF,0XFF,0XF0,0X00,0X03,0XC7,0XE0,0X00,0X00,0X00,0X7F,0XFF,0XFF,
0XFF,0XFF,0XF0,0X00,0X03,0XC7,0XC0,0X00,0X00,0X00,0X7F,0XFF,0XFF,0XFF,0XFF,0XF0,
0X00,0X03,0XC7,0X80,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XC7,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XC7,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XC7,0X80,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X03,0XC7,0X80,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X03,0XC7,0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,
0XC7,0XE0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XC7,0XF0,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XC7,0XF0,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XC7,0XF8,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X03,0XC7,0XF8,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X03,0XC7,0XF8,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XC7,0XF8,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XC7,0XF8,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XC7,0XF8,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X03,0XC7,0XF0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X03,0XC7,0XE0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XC7,
0XC0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XC7,0XE0,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XC7,0XE0,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X03,0XC7,0XF0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X03,0XC7,0XF0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,
0XC7,0XF0,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XC7,0XF8,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XD7,0XF8,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X03,0XFF,0XF8,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X03,0XFF,0XF8,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X03,0XFF,0XF8,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X01,0XFF,0XF0,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0XFF,0XE0,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X7F,0X80,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X3F,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X1C,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X08,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,};

View File

@ -1,43 +0,0 @@
/*****************************************************************************
* | File : ImageData.h
* | Author : Waveshare team
* | Function :
*----------------
* | This version: V1.0
* | Date : 2018-10-23
* | Info :
*
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
******************************************************************************/
#ifndef _IMAGEDATA_H_
#define _IMAGEDATA_H_
// FabAccess_Icon.c
extern const unsigned char gImage_FabAccess_Icon_NoHeader[];
extern const unsigned char gImage_qrurn[];
#endif
/* FILE END */

View File

@ -1,215 +0,0 @@
//
// Created by Kai Jan Kriegel on 03.02.23.
//
#include "epd.h"
#include "EPD_2in66.h"
#include "platform.h"
#include <esp_err.h>
#include <string.h>
display_t epd_display;
esp_err_t epd_init(display_t display) {
if (DEV_Module_Init() != 0) {
return ESP_FAIL;
}
EPD_2IN66_Init();
epd_display = display;
UWORD Imagesize =
((EPD_2IN66_WIDTH % 8 == 0) ? (EPD_2IN66_WIDTH / 8) : (EPD_2IN66_WIDTH / 8 + 1)) * EPD_2IN66_HEIGHT;
if ((epd_display.canvas = (UBYTE *) malloc(Imagesize)) == NULL) {
ESP_LOGE("EPD", "Failed to allocate epd canvas memory");
return ESP_FAIL;
}
Paint_NewImage(epd_display.canvas, EPD_2IN66_WIDTH, EPD_2IN66_HEIGHT, 270, WHITE);
// Initialise the display
Paint_SelectImage(epd_display.canvas);
Paint_Clear(WHITE);
char readerid[DISPLAY_BUFFER_SIZE];
snprintf(readerid, DISPLAY_BUFFER_SIZE, "Reader ID: %05d", epd_display.reader_info.reader_id);
char batterlevel[DISPLAY_BUFFER_SIZE];
snprintf(batterlevel, DISPLAY_BUFFER_SIZE, "Battery: %d%%", epd_display.reader_info.battery_level);
//Draw border
Paint_DrawRectangle(1, 1, EPD_2IN66_HEIGHT - 1, EPD_2IN66_WIDTH, BLACK, DOT_PIXEL_1X1, DRAW_FILL_EMPTY);
// Draw reader id
Paint_DrawString_EN(17, 2, readerid, &Font12, WHITE, BLACK);
// draw divider
Paint_DrawLine(EPD_2IN66_HEIGHT / 2, 1, EPD_2IN66_HEIGHT / 2, 15, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
// Draw battery level
Paint_DrawString_EN(175, 2, batterlevel, &Font12, WHITE, BLACK);
// Draw header horizontal divider
Paint_DrawLine(1, 15, EPD_2IN66_HEIGHT, 15, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
// draw vertical button divider
ESP_LOGD("EPD", "Drawing vertical button divider");
Paint_DrawLine(40, 15, 40, EPD_2IN66_WIDTH, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
Paint_DrawLine(EPD_2IN66_HEIGHT - 40, 15, EPD_2IN66_HEIGHT - 40, EPD_2IN66_WIDTH, BLACK, DOT_PIXEL_1X1,
LINE_STYLE_SOLID);
// Draw horizontal button divider
ESP_LOGD("EPD", "Drawing horizontal button divider");
Paint_DrawLine(1, ((EPD_2IN66_WIDTH - 15) / 2) + 15, 40, ((EPD_2IN66_WIDTH - 15) / 2) + 15, BLACK, DOT_PIXEL_1X1,
LINE_STYLE_SOLID);
Paint_DrawLine(EPD_2IN66_HEIGHT - 40, ((EPD_2IN66_WIDTH - 15) / 2) + 15, EPD_2IN66_HEIGHT,
((EPD_2IN66_WIDTH - 15) / 2) + 15, BLACK, DOT_PIXEL_1X1, LINE_STYLE_SOLID);
// Draw buttons
ESP_LOGD("EPD", "Drawing buttons");
Paint_DrawString_EN(12, ((EPD_2IN66_WIDTH - 15) / 2) - 20 - (Font24.Height / 2), epd_display.buttons.btn0, &Font24, WHITE, BLACK);
Paint_DrawString_EN(12, ((EPD_2IN66_WIDTH - 15) / 2) + 40, epd_display.buttons.btn1, &Font24, WHITE, BLACK);
Paint_DrawString_EN(EPD_2IN66_HEIGHT - 12 - Font24.Width, ((EPD_2IN66_WIDTH - 15) / 2) - 20 - (Font24.Height / 2), epd_display.buttons.btn2, &Font24, WHITE, BLACK);
Paint_DrawString_EN(EPD_2IN66_HEIGHT - 12 - Font24.Width, ((EPD_2IN66_WIDTH - 15) / 2) + 40, epd_display.buttons.btn3, &Font24, WHITE, BLACK);
// Draw machine name
ESP_LOGD("EPD", "Drawing machine name");
Paint_DrawString_EN(42, 20, epd_display.machine_name, &Font16, WHITE, BLACK);
// Draw machine state
ESP_LOGD("EPD", "Drawing machine state");
Paint_DrawString_EN(60, ((EPD_2IN66_WIDTH - 15) / 2) + 15 - (Font24.Height / 2), epd_display.state, &Font24, WHITE,
BLACK);
// Draw QR code
ESP_LOGD("EPD", "Drawing QR code");
Paint_DrawBitMap_Paste(gImage_qrurn, EPD_2IN66_HEIGHT - 142,
((EPD_2IN66_WIDTH - 15) / 2) - 35, 100, 100, TRUE);
ESP_LOGI("EPD", "Displaying initial layout");
EPD_2IN66_Display(epd_display.canvas);
ESP_LOGD("EPD", "Sleeping");
EPD_2IN66_Sleep();
DEV_Module_Exit();
return ESP_OK;
}
void epd_clear() {
EPD_2IN66_Init();
EPD_2IN66_Clear();
EPD_2IN66_Sleep();
}
void epd_update_reader_info(reader_info_t reader_info) {
if (memcmp(&epd_display.reader_info, &reader_info, sizeof(reader_info_t)) != 0) {
memcpy(&epd_display.reader_info, &reader_info, sizeof(reader_info_t));
DEV_Module_Init();
EPD_2IN66_Init();
EPD_2IN66_Init_Partial();
Paint_SelectImage(epd_display.canvas);
char readerid[DISPLAY_BUFFER_SIZE];
snprintf(readerid, DISPLAY_BUFFER_SIZE, "%05d", epd_display.reader_info.reader_id);
char batterlevel[DISPLAY_BUFFER_SIZE];
snprintf(batterlevel, DISPLAY_BUFFER_SIZE, "%d%%", epd_display.reader_info.battery_level);
Paint_ClearWindows(94, 2, 129, 14, WHITE);
Paint_DrawString_EN(94, 2, readerid, &Font12, WHITE, BLACK);
// blank out battery level
Paint_ClearWindows(238, 2, 266, 14, WHITE);
// Draw battery level
Paint_DrawString_EN(238, 2, batterlevel, &Font12, WHITE, BLACK);
EPD_2IN66_Display(epd_display.canvas);
EPD_2IN66_Sleep();
DEV_Module_Exit();
}
}
void epd_update_state(char* state) {
if (strcmp(epd_display.state, state) != 0) {
ESP_LOGI("EPD", "Updating state to %s", state);
strncpy(epd_display.state, state, DISPLAY_BUFFER_SIZE);
DEV_Module_Init();
EPD_2IN66_Init();
EPD_2IN66_Init_Partial();
Paint_SelectImage(epd_display.canvas);
Paint_ClearWindows(60, ((EPD_2IN66_WIDTH - 15) / 2) + 15 - (Font24.Height / 2), EPD_2IN66_HEIGHT - 142,
((EPD_2IN66_WIDTH - 15) / 2) + 15 - (Font24.Height / 2) + Font24.Height, WHITE);
Paint_DrawString_EN(60, ((EPD_2IN66_WIDTH - 15) / 2) + 15 - (Font24.Height / 2), epd_display.state, &Font24,
WHITE,
BLACK);
EPD_2IN66_Display(epd_display.canvas);
EPD_2IN66_Sleep();
DEV_Module_Exit();
}
}
void epd_update_buttons(buttons_t* buttons) {
DEV_Module_Init();
EPD_2IN66_Init();
EPD_2IN66_Init_Partial();
if (strcmp(epd_display.buttons.btn0, buttons->btn0) != 0) {
strncpy(epd_display.buttons.btn0, buttons->btn0, DISPLAY_BUFFER_SIZE);
Paint_SelectImage(epd_display.canvas);
Paint_ClearWindows(12, ((EPD_2IN66_WIDTH - 15) / 2) - 20 - (Font24.Height / 2), 12 + Font24.Width,
((EPD_2IN66_WIDTH - 15) / 2) - 20 - (Font24.Height / 2) + Font24.Height, WHITE);
Paint_DrawString_EN(12, ((EPD_2IN66_WIDTH - 15) / 2) - 20 - (Font24.Height / 2), epd_display.buttons.btn0, &Font24,
WHITE, BLACK);
EPD_2IN66_Display(epd_display.canvas);
}
if (strcmp(epd_display.buttons.btn1, buttons->btn1) != 0) {
strncpy(epd_display.buttons.btn1, buttons->btn1, DISPLAY_BUFFER_SIZE);
Paint_SelectImage(epd_display.canvas);
Paint_ClearWindows(12, ((EPD_2IN66_WIDTH - 15) / 2) + 40, 12 + Font24.Width,
((EPD_2IN66_WIDTH - 15) / 2) + 40 + Font24.Height, WHITE);
Paint_DrawString_EN(12, ((EPD_2IN66_WIDTH - 15) / 2) + 40, epd_display.buttons.btn1, &Font24, WHITE, BLACK);
EPD_2IN66_Display(epd_display.canvas);
}
if (strcmp(epd_display.buttons.btn2, buttons->btn2) != 0) {
strncpy(epd_display.buttons.btn2, buttons->btn2, DISPLAY_BUFFER_SIZE);
Paint_SelectImage(epd_display.canvas);
Paint_ClearWindows(EPD_2IN66_HEIGHT - 12 - Font24.Width,
((EPD_2IN66_WIDTH - 15) / 2) - 20 - (Font24.Height / 2), EPD_2IN66_HEIGHT - 12,
((EPD_2IN66_WIDTH - 15) / 2) - 20 - (Font24.Height / 2) + Font24.Height, WHITE);
Paint_DrawString_EN(EPD_2IN66_HEIGHT - 12 - Font24.Width,
((EPD_2IN66_WIDTH - 15) / 2) - 20 - (Font24.Height / 2), epd_display.buttons.btn2, &Font24,
WHITE, BLACK);
EPD_2IN66_Display(epd_display.canvas);
}
if (strcmp(epd_display.buttons.btn3, buttons->btn3) != 0) {
strncpy(epd_display.buttons.btn3, buttons->btn3, DISPLAY_BUFFER_SIZE);
Paint_SelectImage(epd_display.canvas);
Paint_ClearWindows(EPD_2IN66_HEIGHT - 12 - Font24.Width,
((EPD_2IN66_WIDTH - 15) / 2) + 40, EPD_2IN66_HEIGHT - 12,
((EPD_2IN66_WIDTH - 15) / 2) + 40 + Font24.Height, WHITE);
Paint_DrawString_EN(EPD_2IN66_HEIGHT - 12 - Font24.Width,
((EPD_2IN66_WIDTH - 15) / 2) + 40, epd_display.buttons.btn3, &Font24, WHITE, BLACK);
EPD_2IN66_Display(epd_display.canvas);
}
EPD_2IN66_Sleep();
DEV_Module_Exit();
}
void epd_update_machine_name(char* machine_name) {
if (strcmp(epd_display.machine_name, machine_name) != 0) {
strncpy(epd_display.machine_name, machine_name, DISPLAY_BUFFER_SIZE);
DEV_Module_Init();
EPD_2IN66_Init();
EPD_2IN66_Init_Partial();
Paint_SelectImage(epd_display.canvas);
Paint_ClearWindows(42, 20, 251,
20 + Font16.Height, WHITE);
Paint_DrawString_EN(42, 20, epd_display.machine_name, &Font16, WHITE, BLACK);
EPD_2IN66_Display(epd_display.canvas);
EPD_2IN66_Sleep();
DEV_Module_Exit();
}
}
void epd_update_image(UBYTE* image) {
if (memcmp(epd_display.image, image, DISPLAY_BUFFER_SIZE) != 0) {
memcpy(epd_display.image, image, DISPLAY_BUFFER_SIZE);
DEV_Module_Init();
EPD_2IN66_Init();
EPD_2IN66_Init_Partial();
Paint_SelectImage(epd_display.canvas);
Paint_ClearWindows(EPD_2IN66_HEIGHT - 142,
((EPD_2IN66_WIDTH - 15) / 2) - 35,
EPD_2IN66_HEIGHT - 142 + 100,
((EPD_2IN66_WIDTH - 15) / 2) - 35 + 100, WHITE);
Paint_DrawBitMap_Paste(epd_display.image, EPD_2IN66_HEIGHT - 142,
((EPD_2IN66_WIDTH - 15) / 2) - 35, 100, 100, TRUE);
EPD_2IN66_Display(epd_display.canvas);
EPD_2IN66_Sleep();
DEV_Module_Exit();
}
}

View File

@ -1,73 +0,0 @@
/*****************************************************************************
* | File : EPD_Test.h
* | Author : Waveshare team
* | Function : e-Paper test Demo
* | Info :
*----------------
* | This version: V1.0
* | Date : 2019-06-11
* | Info :
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documnetation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#
******************************************************************************/
#ifndef _EPD_TEST_H_
#define _EPD_TEST_H_
#include "DEV_Config.h"
#include "GUI_Paint.h"
#include "imagedata.h"
#include "Debug.h"
#include <stdlib.h> // malloc() free()
#define DISPLAY_BUFFER_SIZE 30
typedef struct {
int reader_id;
int battery_level;
} reader_info_t;
typedef struct {
char btn0[DISPLAY_BUFFER_SIZE];
char btn1[DISPLAY_BUFFER_SIZE];
char btn2[DISPLAY_BUFFER_SIZE];
char btn3[DISPLAY_BUFFER_SIZE];
} buttons_t;
typedef struct {
UBYTE* canvas;
reader_info_t reader_info;
char state[DISPLAY_BUFFER_SIZE];
buttons_t buttons;
char machine_name[DISPLAY_BUFFER_SIZE];
UBYTE *image;
} display_t;
esp_err_t epd_init(display_t display);
esp_err_t epd_deinit();
void epd_clear();
void epd_update_reader_info(reader_info_t reader_info);
void epd_update_state(char* state);
void epd_update_buttons(buttons_t* buttons);
void epd_update_machine_name(char* machine_name);
void epd_update_image(UBYTE* image);
int EPD_test();
#endif

View File

@ -1,83 +0,0 @@
const unsigned char gImage_qrurn[1300] = { /* 0X00,0X01,0X64,0X00,0X64,0X00, */
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X1F,0XFF,0XFC,0X63,0X9F,0XFC,0X03,0X83,0XFF,0XFF,0X80,0X00,0X00,0X1F,0XFF,0XFC,
0X63,0X9F,0XFC,0X03,0X83,0XFF,0XFF,0X80,0X00,0X00,0X1F,0XFF,0XFC,0X63,0X9F,0XFC,
0X03,0X83,0XFF,0XFF,0X80,0X00,0X00,0X1C,0X00,0X1C,0X1F,0XFF,0X83,0X9C,0X63,0X80,
0X03,0X80,0X00,0X00,0X1C,0X00,0X1C,0X1F,0XFF,0X83,0X9C,0X63,0X80,0X03,0X80,0X00,
0X00,0X1C,0X00,0X1C,0X1F,0XFF,0X83,0X9C,0X63,0X80,0X03,0X80,0X00,0X00,0X1C,0X7F,
0X9C,0X7F,0X80,0X03,0X80,0X63,0X9F,0XE3,0X80,0X00,0X00,0X1C,0X7F,0X9C,0X7F,0X80,
0X03,0X80,0X63,0X9F,0XE3,0X80,0X00,0X00,0X1C,0X7F,0X9C,0X7F,0X9C,0X7C,0X00,0X03,
0X9F,0XE3,0X80,0X00,0X00,0X1C,0X7F,0X9C,0X7F,0X9C,0X7C,0X00,0X03,0X9F,0XE3,0X80,
0X00,0X00,0X1C,0X7F,0X9C,0X7F,0X9C,0X7C,0X00,0X03,0X9F,0XE3,0X80,0X00,0X00,0X1C,
0X7F,0X9C,0X60,0X7C,0X63,0XFF,0XE3,0X9F,0XE3,0X80,0X00,0X00,0X1C,0X7F,0X9C,0X60,
0X7C,0X63,0XFF,0XE3,0X9F,0XE3,0X80,0X00,0X00,0X1C,0X7F,0X9C,0X60,0X7C,0X63,0XFF,
0XE3,0X9F,0XE3,0X80,0X00,0X00,0X1C,0X00,0X1C,0X03,0XE3,0X9F,0XE3,0XE3,0X80,0X03,
0X80,0X00,0X00,0X1C,0X00,0X1C,0X03,0XE3,0X9F,0XE3,0XE3,0X80,0X03,0X80,0X00,0X00,
0X1F,0XFF,0XFC,0X63,0X9C,0X63,0X9C,0X63,0XFF,0XFF,0X80,0X00,0X00,0X1F,0XFF,0XFC,
0X63,0X9C,0X63,0X9C,0X63,0XFF,0XFF,0X80,0X00,0X00,0X1F,0XFF,0XFC,0X63,0X9C,0X63,
0X9C,0X63,0XFF,0XFF,0X80,0X00,0X00,0X00,0X00,0X00,0X03,0X9C,0X1F,0X9F,0X80,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X03,0X9C,0X1F,0X9F,0X80,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X03,0X9C,0X1F,0X9F,0X80,0X00,0X00,0X00,0X00,0X00,0X1F,0XFC,
0X1C,0X63,0XFF,0X9F,0XE3,0XFC,0X1F,0XE3,0X80,0X00,0X00,0X1F,0XFC,0X1C,0X63,0XFF,
0X9F,0XE3,0XFC,0X1F,0XE3,0X80,0X00,0X00,0X1C,0X7C,0X60,0X63,0X9F,0XFC,0X1C,0X60,
0X7F,0X9F,0X80,0X00,0X00,0X1C,0X7C,0X60,0X63,0X9F,0XFC,0X1C,0X60,0X7F,0X9F,0X80,
0X00,0X00,0X1C,0X7C,0X60,0X63,0X9F,0XFC,0X1C,0X60,0X7F,0X9F,0X80,0X00,0X00,0X1F,
0X9F,0XFF,0X9F,0XFF,0X80,0X7C,0X1C,0X7C,0X00,0X00,0X00,0X00,0X1F,0X9F,0XFF,0X9F,
0XFF,0X80,0X7C,0X1C,0X7C,0X00,0X00,0X00,0X00,0X1F,0X9F,0XFF,0X9F,0XFF,0X80,0X7C,
0X1C,0X7C,0X00,0X00,0X00,0X00,0X1F,0X83,0XE0,0X7F,0X80,0X03,0XE0,0X7C,0X60,0X7C,
0X00,0X00,0X00,0X1F,0X83,0XE0,0X7F,0X80,0X03,0XE0,0X7C,0X60,0X7C,0X00,0X00,0X00,
0X1C,0X63,0XFF,0XFF,0X9C,0X7F,0X80,0X7C,0X60,0X60,0X00,0X00,0X00,0X1C,0X63,0XFF,
0XFF,0X9C,0X7F,0X80,0X7C,0X60,0X60,0X00,0X00,0X00,0X1C,0X63,0XFF,0XFF,0X9C,0X7F,
0X80,0X7C,0X60,0X60,0X00,0X00,0X00,0X1F,0XFC,0X60,0X1C,0X7C,0X60,0X7F,0X9F,0XE0,
0X7C,0X00,0X00,0X00,0X1F,0XFC,0X60,0X1C,0X7C,0X60,0X7F,0X9F,0XE0,0X7C,0X00,0X00,
0X00,0X1F,0XFC,0X60,0X1C,0X7C,0X60,0X7F,0X9F,0XE0,0X7C,0X00,0X00,0X00,0X1C,0X00,
0X1C,0X00,0X63,0X80,0X7C,0X1F,0X9C,0X7F,0X80,0X00,0X00,0X1C,0X00,0X1C,0X00,0X63,
0X80,0X7C,0X1F,0X9C,0X7F,0X80,0X00,0X00,0X03,0X80,0X63,0X83,0XE0,0X60,0X1F,0XE3,
0XFC,0X63,0X80,0X00,0X00,0X03,0X80,0X63,0X83,0XE0,0X60,0X1F,0XE3,0XFC,0X63,0X80,
0X00,0X00,0X03,0X80,0X63,0X83,0XE0,0X60,0X1F,0XE3,0XFC,0X63,0X80,0X00,0X00,0X1F,
0XFC,0X1C,0X00,0X1C,0X63,0XE0,0X00,0X1C,0X1C,0X00,0X00,0X00,0X1F,0XFC,0X1C,0X00,
0X1C,0X63,0XE0,0X00,0X1C,0X1C,0X00,0X00,0X00,0X1F,0XFC,0X1C,0X00,0X1C,0X63,0XE0,
0X00,0X1C,0X1C,0X00,0X00,0X00,0X03,0XE3,0XE0,0X1F,0X80,0X63,0X9C,0X1C,0X00,0X03,
0X80,0X00,0X00,0X03,0XE3,0XE0,0X1F,0X80,0X63,0X9C,0X1C,0X00,0X03,0X80,0X00,0X00,
0X1C,0X00,0X1C,0X1C,0X03,0XFC,0X60,0X7C,0X00,0X7C,0X00,0X00,0X00,0X1C,0X00,0X1C,
0X1C,0X03,0XFC,0X60,0X7C,0X00,0X7C,0X00,0X00,0X00,0X1C,0X00,0X1C,0X1C,0X03,0XFC,
0X60,0X7C,0X00,0X7C,0X00,0X00,0X00,0X00,0X1C,0X63,0X80,0X63,0XE3,0XE3,0X9F,0X83,
0XE3,0X80,0X00,0X00,0X00,0X1C,0X63,0X80,0X63,0XE3,0XE3,0X9F,0X83,0XE3,0X80,0X00,
0X00,0X00,0X1C,0X63,0X80,0X63,0XE3,0XE3,0X9F,0X83,0XE3,0X80,0X00,0X00,0X03,0XE3,
0X9F,0X9F,0X83,0XE0,0X63,0XFF,0XFF,0XE3,0X80,0X00,0X00,0X03,0XE3,0X9F,0X9F,0X83,
0XE0,0X63,0XFF,0XFF,0XE3,0X80,0X00,0X00,0X00,0X00,0X00,0X63,0X80,0X1F,0X83,0XE0,
0X1F,0X9C,0X00,0X00,0X00,0X00,0X00,0X00,0X63,0X80,0X1F,0X83,0XE0,0X1F,0X9C,0X00,
0X00,0X00,0X00,0X00,0X00,0X63,0X80,0X1F,0X83,0XE0,0X1F,0X9C,0X00,0X00,0X00,0X1F,
0XFF,0XFC,0X03,0X80,0X60,0X1C,0X63,0X9C,0X1C,0X00,0X00,0X00,0X1F,0XFF,0XFC,0X03,
0X80,0X60,0X1C,0X63,0X9C,0X1C,0X00,0X00,0X00,0X1F,0XFF,0XFC,0X03,0X80,0X60,0X1C,
0X63,0X9C,0X1C,0X00,0X00,0X00,0X1C,0X00,0X1C,0X00,0X7F,0XFC,0X60,0X60,0X1F,0X80,
0X00,0X00,0X00,0X1C,0X00,0X1C,0X00,0X7F,0XFC,0X60,0X60,0X1F,0X80,0X00,0X00,0X00,
0X1C,0X7F,0X9C,0X1C,0X60,0X1C,0X1C,0X7F,0XFF,0X9F,0X80,0X00,0X00,0X1C,0X7F,0X9C,
0X1C,0X60,0X1C,0X1C,0X7F,0XFF,0X9F,0X80,0X00,0X00,0X1C,0X7F,0X9C,0X1C,0X60,0X1C,
0X1C,0X7F,0XFF,0X9F,0X80,0X00,0X00,0X1C,0X7F,0X9C,0X63,0XE3,0X9F,0XE0,0X03,0X83,
0XFC,0X00,0X00,0X00,0X1C,0X7F,0X9C,0X63,0XE3,0X9F,0XE0,0X03,0X83,0XFC,0X00,0X00,
0X00,0X1C,0X7F,0X9C,0X63,0XE3,0X9F,0XE0,0X03,0X83,0XFC,0X00,0X00,0X00,0X1C,0X7F,
0X9C,0X7C,0X1C,0X7F,0XFC,0X00,0X03,0XE3,0X80,0X00,0X00,0X1C,0X7F,0X9C,0X7C,0X1C,
0X7F,0XFC,0X00,0X03,0XE3,0X80,0X00,0X00,0X1C,0X00,0X1C,0X60,0X1F,0X83,0XFC,0X60,
0X00,0X03,0X80,0X00,0X00,0X1C,0X00,0X1C,0X60,0X1F,0X83,0XFC,0X60,0X00,0X03,0X80,
0X00,0X00,0X1C,0X00,0X1C,0X60,0X1F,0X83,0XFC,0X60,0X00,0X03,0X80,0X00,0X00,0X1F,
0XFF,0XFC,0X60,0X60,0X03,0XE0,0X7F,0X80,0X1C,0X00,0X00,0X00,0X1F,0XFF,0XFC,0X60,
0X60,0X03,0XE0,0X7F,0X80,0X1C,0X00,0X00,0X00,0X1F,0XFF,0XFC,0X60,0X60,0X03,0XE0,
0X7F,0X80,0X1C,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,
0X00,0X00,0X00,0X00,};

View File

@ -1,363 +0,0 @@
#include <sys/cdefs.h>
#include <stdio.h>
#include <esp_err.h>
#include <esp_wifi.h>
#include <esp_event.h>
#include <esp_log.h>
#include <nvs_flash.h>
#include <mqtt_client.h>
#include <esp_crt_bundle.h>
#include "fab-reader2.h"
#include "platform.h"
#include "st25R3911_interrupt.h"
#include "DEV_Config.h"
#include "pollingtagdetect.h"
#include "epd.h"
#include "ota.h"
#define SPI_CLK 5
#define SPI_MOSI 6
#define SPI_MISO 7
#define ESP_INTR_FLAG_DEFAULT 0
portMUX_TYPE CommProtectLock = portMUX_INITIALIZER_UNLOCKED;
esp_err_t init_mqtt(void);
static void IRAM_ATTR gpio_isr_handler(void *arg) {
st25r3911Isr();
ets_printf("Interrupt\n");
}
static void network_event_handler(void* arg, esp_event_base_t event_base, int32_t event_id, void* event_data)
{
if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_START) {
esp_wifi_connect();
} else if (event_base == WIFI_EVENT && event_id == WIFI_EVENT_STA_DISCONNECTED) {
esp_wifi_connect();
} else if (event_base == IP_EVENT && event_id == IP_EVENT_STA_GOT_IP) {
ip_event_got_ip_t* event = (ip_event_got_ip_t*) event_data;
ESP_LOGI("network", "got ip:" IPSTR, IP2STR(&event->ip_info.ip));
ESP_ERROR_CHECK(init_mqtt());
ESP_LOGI("main", "init_mqtt done");
}
}
/*
* @brief Event handler registered to receive MQTT events
*
* This function is called by the MQTT client event loop.
*
* @param handler_args user data registered to the event.
* @param base Event base for the handler(always MQTT Base in this example).
* @param event_id The id for the received event.
* @param event_data The data for the event, esp_mqtt_event_handle_t.
*/
static void mqtt_event_handler(void *handler_args, esp_event_base_t base, int32_t event_id, void *event_data)
{
ESP_LOGD("mqtt", "Event dispatched from event loop base=%s, event_id=%d", base, event_id);
esp_mqtt_event_handle_t event = event_data;
esp_mqtt_client_handle_t client = event->client;
int msg_id;
switch ((esp_mqtt_event_id_t)event_id) {
case MQTT_EVENT_CONNECTED:
ESP_LOGI("mqtt", "MQTT_EVENT_CONNECTED");
char id[6] = "00000";
sprintf(id, "%05d", CONFIG_FABREADER2_ID);
// Register Reader
msg_id = esp_mqtt_client_publish(client, "fabreader", id, 0, 0, 0);
ESP_LOGI("mqtt", "sent publish successful, msg_id=%d", msg_id);
char topic_requestOTA[] = "fabreader/00000/requestOTA";
sprintf(topic_requestOTA, "fabreader/%05d/requestOTA", CONFIG_FABREADER2_ID);
msg_id = esp_mqtt_client_subscribe(client, topic_requestOTA, 0);
ESP_LOGI("mqtt", "sent subscribe successful, msg_id=%d", msg_id);
char topic_stopOTA[] = "fabreader/00000/stopOTA";
sprintf(topic_stopOTA, "fabreader/%05d/stopOTA", CONFIG_FABREADER2_ID);
msg_id = esp_mqtt_client_subscribe(client, topic_stopOTA, 0);
ESP_LOGI("mqtt", "sent subscribe successful, msg_id=%d", msg_id);
char topic_display[] = "fabreader/00000/display/#";
sprintf(topic_display, "fabreader/%05d/display/#", CONFIG_FABREADER2_ID);
msg_id = esp_mqtt_client_subscribe(client, topic_display, 0);
ESP_LOGI("mqtt", "sent subscribe successful, msg_id=%d", msg_id);
break;
case MQTT_EVENT_DISCONNECTED:
ESP_LOGI("mqtt", "MQTT_EVENT_DISCONNECTED");
break;
case MQTT_EVENT_SUBSCRIBED:
ESP_LOGI("mqtt", "MQTT_EVENT_SUBSCRIBED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_UNSUBSCRIBED:
ESP_LOGI("mqtt", "MQTT_EVENT_UNSUBSCRIBED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_PUBLISHED:
ESP_LOGI("mqtt", "MQTT_EVENT_PUBLISHED, msg_id=%d", event->msg_id);
break;
case MQTT_EVENT_DATA:
ESP_LOGI("mqtt", "MQTT_EVENT_DATA");
printf("TOPIC=%.*s\r\n", event->topic_len, event->topic);
printf("DATA=%.*s\r\n", event->data_len, event->data);
if (hasActiveOTA()) {
continueOTA(client, event->topic, event->data, event->data_len);
}
break;
case MQTT_EVENT_ERROR:
ESP_LOGE("mqtt", "MQTT_EVENT_ERROR");
if (event->error_handle->error_type == MQTT_ERROR_TYPE_TCP_TRANSPORT) {
ESP_LOGE("mqtt", "Last error code reported from esp-tls: 0x%x", event->error_handle->esp_tls_last_esp_err);
ESP_LOGE("mqtt", "Last tls stack error number: 0x%x", event->error_handle->esp_tls_stack_err);
ESP_LOGE("mqtt", "Last captured errno : %d (%s)", event->error_handle->esp_transport_sock_errno,
strerror(event->error_handle->esp_transport_sock_errno));
} else if (event->error_handle->error_type == MQTT_ERROR_TYPE_CONNECTION_REFUSED) {
ESP_LOGE("mqtt", "Connection refused error: 0x%x", event->error_handle->connect_return_code);
} else {
ESP_LOGW("mqtt", "Unknown error type: 0x%x", event->error_handle->error_type);
}
break;
default:
ESP_LOGI("mqtt", "Other event id:%d", event->event_id);
break;
}
}
esp_err_t init_gpio(void) {
gpio_config_t io_conf = {};
//disable interrupt
io_conf.intr_type = GPIO_INTR_DISABLE;
//set as output mode
io_conf.mode = GPIO_MODE_INPUT_OUTPUT;
//bit mask of the pins that you want to set,e.g.GPIO18/19
io_conf.pin_bit_mask = (1ULL << ST25R391X_SS_PIN) | (1ULL << EPD_CS_PIN) | (1ULL << EPD_DC_PIN) | (1ULL << EPD_RST_PIN);
//disable pull-down mode
io_conf.pull_down_en = 0;
//disable pull-up mode
io_conf.pull_up_en = 0;
//configure GPIO with the given settings
esp_err_t ret = gpio_config(&io_conf);
ESP_ERROR_CHECK(ret);
io_conf.mode = GPIO_MODE_INPUT;
io_conf.pin_bit_mask = (1ULL << EPD_BUSY_PIN);
ret = gpio_config(&io_conf);
ESP_ERROR_CHECK(ret);
//interrupt of rising edge
io_conf.intr_type = GPIO_INTR_POSEDGE;
//bit mask of the pins, use GPIO4/5 here
io_conf.pin_bit_mask = (1ULL << ST25R391X_INT_PIN);
//set as input mode
io_conf.mode = GPIO_MODE_INPUT;
//disable pull-down mode
io_conf.pull_down_en = 0;
//enable pull-up mode
io_conf.pull_up_en = 0;
ESP_ERROR_CHECK(gpio_config(&io_conf));
ESP_ERROR_CHECK(gpio_install_isr_service(ESP_INTR_FLAG_DEFAULT));
//hook isr handler for specific gpio pin
ESP_ERROR_CHECK(gpio_isr_handler_add(ST25R391X_INT_PIN, gpio_isr_handler, NULL));
return ret;
}
esp_err_t init_spi(void) {
spi_bus_config_t buscfg = {
.miso_io_num=SPI_MISO,
.mosi_io_num=SPI_MOSI,
.sclk_io_num=SPI_CLK,
.quadwp_io_num=-1,
.quadhd_io_num=-1,
};
esp_err_t ret = spi_bus_initialize(SPI3_HOST, &buscfg, SPI_DMA_CH_AUTO);
ESP_ERROR_CHECK(ret);
spi_device_interface_config_t nfc_devcfg = {
.clock_speed_hz=SPI_MASTER_FREQ_8M, //Clock out at 26 MHz
.mode=1, //SPI mode 1
.spics_io_num=-1, //CS pin
.queue_size=1, //We want to be able to queue 7 transactions at a time
};
spi_device_handle_t nfc_spi;
ret = spi_bus_add_device(SPI3_HOST, &nfc_devcfg, &nfc_spi);
ESP_ERROR_CHECK(ret);
st25r3911_spi_init(nfc_spi);
spi_device_interface_config_t epd_devcfg = {
.clock_speed_hz=SPI_MASTER_FREQ_8M, //Clock out at 26 MHz
.mode=0, //SPI mode 1
.spics_io_num=-1, //CS pin
.queue_size=1, //We want to be able to queue 7 transactions at a time
};
spi_device_handle_t epd_spi;
ret = spi_bus_add_device(SPI3_HOST, &epd_devcfg, &epd_spi);
ESP_ERROR_CHECK(ret);
DEV_SPI_Init(epd_spi);
return ret;
}
esp_err_t init_eventloop() {
esp_err_t ret = esp_event_loop_create_default();
ESP_ERROR_CHECK(ret);
return ret;
}
esp_err_t init_wifi() {
esp_err_t ret;
ret = esp_netif_init();
ESP_ERROR_CHECK(ret);
wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT();
ret = esp_wifi_init(&cfg);
ESP_ERROR_CHECK(ret);
ret = esp_event_handler_instance_register(WIFI_EVENT, ESP_EVENT_ANY_ID, &network_event_handler, NULL, NULL);
ESP_ERROR_CHECK(ret);
ret = esp_event_handler_instance_register(IP_EVENT, IP_EVENT_STA_GOT_IP, &network_event_handler, NULL, NULL);
ESP_ERROR_CHECK(ret);
// Initialize default station as network interface instance (esp-netif)
esp_netif_t *sta_netif = esp_netif_create_default_wifi_sta();
assert(sta_netif);
// Initialize and start WiFi
wifi_config_t wifi_config = {
.sta = {
.ssid = DEFAULT_SSID,
.password = DEFAULT_PWD,
.scan_method = DEFAULT_SCAN_METHOD,
.sort_method = DEFAULT_SORT_METHOD,
.threshold.rssi = DEFAULT_RSSI,
.threshold.authmode = DEFAULT_AUTHMODE,
},
};
ret = esp_wifi_set_mode(WIFI_MODE_STA);
ESP_ERROR_CHECK(ret);
ret = esp_wifi_set_config(WIFI_IF_STA, &wifi_config);
ESP_ERROR_CHECK(ret);
ret = esp_wifi_start();
ESP_ERROR_CHECK(ret);
return ret;
}
esp_err_t init_nvs() {
// Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK( ret );
return ret;
}
esp_err_t init_mqtt() {
esp_err_t ret;
const esp_mqtt_client_config_t mqtt_cfg = {
.uri = CONFIG_BROKER_URI,
.crt_bundle_attach = esp_crt_bundle_attach
};
esp_mqtt_client_handle_t client = esp_mqtt_client_init(&mqtt_cfg);
/* The last argument may be used to pass data to the event handler, in this example mqtt_event_handler */
ret = esp_mqtt_client_register_event(client, MQTT_EVENT_ANY, mqtt_event_handler, NULL);
ESP_ERROR_CHECK(ret);
ret = esp_mqtt_client_start(client);
ESP_ERROR_CHECK(ret);
mqtt_client = client;
return ret;
}
esp_err_t init_epd() {
esp_err_t ret;
reader_info_t reader_info = {
.reader_id = CONFIG_FABREADER2_ID,
.battery_level = 100
};
buttons_t buttons = {
.btn0 = "X",
.btn1 = "<",
.btn2 = "O",
.btn3 = ">"
};
display_t display = {
.canvas = NULL,
.image = NULL,
.machine_name = "",
.state = "IDLE",
.buttons = buttons,
.reader_info = reader_info
};
ret = epd_init(display);
ESP_ERROR_CHECK(ret);
return ret;
}
_Noreturn static void cycle_task(void *arg) {
while (1) {
TagDetectCycle();
// ESP_LOGI("cycle_task", "running tag detect cycle_task");
}
}
void app_main(void) {
// Log basic information about the system
ESP_LOGI("startup", "Startup..");
ESP_LOGI("startup", "Built with IDF version: %s", esp_get_idf_version());
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);
ESP_LOGI("startup", "This is %s chip with %d CPU cores, WiFi%s%s, ",
chip_info.model == CHIP_ESP32S3 ? "ESP32S3" : CHIP_ESP32S2 ? "ESP32S2" : "unknown",
chip_info.cores,
(chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");
// Initialize peripherals
ESP_ERROR_CHECK(init_gpio());
ESP_LOGI("main", "init_gpio done");
ESP_ERROR_CHECK(init_spi());
ESP_LOGI("main", "init_spi done");
// ESP_ERROR_CHECK(init_epd());
ESP_LOGI("main", "init_epd done");
ESP_ERROR_CHECK(init_nvs());
ESP_LOGI("main", "init_nvs done");
ESP_ERROR_CHECK(init_eventloop());
ESP_LOGI("main", "init_eventloop done");
ESP_ERROR_CHECK(init_wifi());
ESP_LOGI("main", "init_wifi done");
// epd_update_state("OTA...");
// Start main application
ESP_ERROR_CHECK(TagDetectInit());
ESP_LOGI("main", "TagDetectInit done");
xTaskCreate(cycle_task, "cycle_task", 4096, NULL, tskIDLE_PRIORITY, NULL);
ESP_LOGI("main", "cycle_task sheduled");
ESP_LOGI("app", "Free memory: %d bytes", esp_get_free_heap_size());
}

View File

@ -1,29 +0,0 @@
#pragma once
#include <mqtt_client.h>
/* Set the SSID and Password via project configuration, or can set directly here */
#define DEFAULT_SSID CONFIG_WIFI_SSID
#define DEFAULT_PWD CONFIG_WIFI_PASSWORD
#if CONFIG_WIFI_ALL_CHANNEL_SCAN
#define DEFAULT_SCAN_METHOD WIFI_ALL_CHANNEL_SCAN
#elif CONFIG_WIFI_FAST_SCAN
#define DEFAULT_SCAN_METHOD WIFI_FAST_SCAN
#else
#define DEFAULT_SCAN_METHOD WIFI_FAST_SCAN
#endif /*CONFIG_FABREADER2_SCAN_METHOD*/
#if CONFIG_WIFI_CONNECT_AP_BY_SIGNAL
#define DEFAULT_SORT_METHOD WIFI_CONNECT_AP_BY_SIGNAL
#elif CONFIG_WIFI_CONNECT_AP_BY_SECURITY
#define DEFAULT_SORT_METHOD WIFI_CONNECT_AP_BY_SECURITY
#else
#define DEFAULT_SORT_METHOD WIFI_CONNECT_AP_BY_SIGNAL
#endif /*CONFIG_FABREADER2_SORT_METHOD*/
#define DEFAULT_RSSI -127
#define DEFAULT_AUTHMODE WIFI_AUTH_WPA2_PSK
esp_mqtt_client_handle_t mqtt_client;

View File

@ -1,17 +0,0 @@
## IDF Component Manager Manifest File
dependencies:
espressif/qrcode: "^0.1.0"
## Required IDF version
idf:
version: ">=4.1.0"
# # Put list of dependencies here
# # For components maintained by Espressif:
# component: "~1.0.0"
# # For 3rd party components:
# username/component: ">=1.0.0,<2.0.0"
# username2/component2:
# version: "~1.0.0"
# # For transient dependencies `public` flag can be set.
# # `public` flag doesn't have an effect dependencies of the `main` component.
# # All dependencies of `main` are public by default.
# public: true

View File

@ -1,264 +0,0 @@
//
// Created by Kai Jan Kriegel on 17.10.22.
//
#include "pollingtagdetect.h"
#include "rfal_nfc.h"
#include "utils.h"
#include "fab-reader2.h"
#include "ota.h"
#include "epd.h"
#include "st25r3911_com.h"
/* P2P communication data */
static uint8_t NFCID3[] = {0x01, 0xFE, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A};
static uint8_t GB[] = {0x46, 0x66, 0x6d, 0x01, 0x01, 0x11, 0x02, 0x02, 0x07, 0x80, 0x03, 0x02, 0x00, 0x03, 0x04, 0x01,
0x32, 0x07, 0x01, 0x03};
/* APDUs communication data */
static uint8_t ndefSelectApp[] = {0x00, 0xA4, 0x04, 0x00, 0x07, 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01, 0x00};
static uint8_t ccSelectFile[] = {0x00, 0xA4, 0x00, 0x0C, 0x02, 0xE1, 0x03};
static uint8_t readBinary[] = {0x00, 0xB0, 0x00, 0x00, 0x0F};
static rfalNfcDiscoverParam discParam;
static TagDetectState nfc_state = NOT_INIT;
void TagDetectAPDU(void);
static void TagDetectNotify(rfalNfcState st) {
uint8_t devCnt;
rfalNfcDevice *dev;
if (st == RFAL_NFC_STATE_WAKEUP_MODE) {
platformLog("Wake Up mode started \r\n");
} else if (st == RFAL_NFC_STATE_POLL_TECHDETECT) {
platformLog("Wake Up mode terminated. Polling for devices \r\n");
} else if (st == RFAL_NFC_STATE_POLL_SELECT) {
/* Multiple devices were found, activate first of them */
rfalNfcGetDevicesFound(&dev, &devCnt);
rfalNfcSelect(0);
platformLog("Multiple Tags detected: %d \r\n", devCnt);
}
}
esp_err_t TagDetectInit(void) {
ReturnCode err = rfalNfcInitialize();
if (err == ERR_NONE) {
discParam.compMode = RFAL_COMPLIANCE_MODE_NFC;
discParam.devLimit = 1U;
ST_MEMCPY(&discParam.nfcid3, NFCID3, sizeof(NFCID3));
ST_MEMCPY(&discParam.GB, GB, sizeof(GB));
discParam.GBLen = sizeof(GB);
discParam.notifyCb = TagDetectNotify;
discParam.totalDuration = 1000U;
discParam.wakeupEnabled = false;
discParam.wakeupConfigDefault = true;
discParam.techs2Find = (RFAL_NFC_POLL_TECH_A | RFAL_NFC_POLL_TECH_B);
#if defined(ST25R3911) || defined(ST25R3916)
discParam.techs2Find |= RFAL_NFC_POLL_TECH_AP2P;
#endif /* ST25R95 */
nfc_state = START_DISCOVERY;
uint8_t irq_mask = 0;
st25r3911ReadRegister(ST25R3911_REG_IRQ_MASK_TIMER_NFC, &irq_mask);
ESP_LOGI("nfc", "irq_mask: %02x", irq_mask);
return ESP_OK;
}
return err;
}
/*!
*****************************************************************************
* \brief Demo Cycle
*
* This function executes the demo state machine.
* It must be called periodically
*****************************************************************************
*/
void TagDetectCycle(void) {
static rfalNfcDevice *nfcDevice;
rfalNfcWorker(); /* Run RFAL worker periodically */
/*******************************************************************************/
/* Check if USER button is pressed */
if (platformGpioIsLow(PLATFORM_USER_BUTTON_PORT, PLATFORM_USER_BUTTON_PIN)) {
discParam.wakeupEnabled = !discParam.wakeupEnabled; /* enable/disable wakeup */
nfc_state = START_DISCOVERY; /* restart loop */
platformLog("Toggling Wake Up mode %s\r\n", discParam.wakeupEnabled ? "ON" : "OFF");
/* Debounce button */
while (platformGpioIsLow(PLATFORM_USER_BUTTON_PORT, PLATFORM_USER_BUTTON_PIN));
}
switch (nfc_state) {
/*******************************************************************************/
case START_DISCOVERY:
// platformLedOff(PLATFORM_LED_A_PORT, PLATFORM_LED_A_PIN);
// platformLedOff(PLATFORM_LED_B_PORT, PLATFORM_LED_B_PIN);
// platformLedOff(PLATFORM_LED_F_PORT, PLATFORM_LED_F_PIN);
// platformLedOff(PLATFORM_LED_V_PORT, PLATFORM_LED_V_PIN);
// platformLedOff(PLATFORM_LED_AP2P_PORT, PLATFORM_LED_AP2P_PIN);
// platformLedOff(PLATFORM_LED_FIELD_PORT, PLATFORM_LED_FIELD_PIN);
rfalNfcDeactivate(false);
rfalNfcDiscover(&discParam);
nfc_state = DISCOVERY;
break;
/*******************************************************************************/
case DISCOVERY:
if (rfalNfcIsDevActivated(rfalNfcGetState())) {
rfalNfcGetActiveDevice(&nfcDevice);
switch (nfcDevice->type) {
/*******************************************************************************/
case RFAL_NFC_LISTEN_TYPE_NFCA:
// platformLedOn(PLATFORM_LED_A_PORT, PLATFORM_LED_A_PIN);
switch (nfcDevice->dev.nfca.type) {
case RFAL_NFCA_T1T:
platformLog("ISO14443A/Topaz (NFC-A T1T) TAG found. UID: %s\r\n",
hex2Str(nfcDevice->nfcid, nfcDevice->nfcidLen));
break;
case RFAL_NFCA_T4T:
platformLog("NFCA Passive ISO-DEP device found. UID: %s\r\n",
hex2Str(nfcDevice->nfcid, nfcDevice->nfcidLen));
// TagDetectAPDU();
if (!hasActiveOTA()) {
startOTA(mqtt_client, nfcDevice->nfcid, nfcDevice->nfcidLen);
epd_update_state("OTA\nrunning");
}
break;
case RFAL_NFCA_T4T_NFCDEP:
case RFAL_NFCA_NFCDEP:
platformLog("NFCA Passive P2P device found. NFCID: %s\r\n",
hex2Str(nfcDevice->nfcid, nfcDevice->nfcidLen));
// demoP2P();
break;
default:
platformLog("ISO14443A/NFC-A card found. UID: %s\r\n",
hex2Str(nfcDevice->nfcid, nfcDevice->nfcidLen));
break;
}
break;
/*******************************************************************************/
case RFAL_NFC_LISTEN_TYPE_NFCB:
platformLog("ISO14443B/NFC-B card found. UID: %s\r\n",
hex2Str(nfcDevice->nfcid, nfcDevice->nfcidLen));
// platformLedOn(PLATFORM_LED_B_PORT, PLATFORM_LED_B_PIN);
if (rfalNfcbIsIsoDepSupported(&nfcDevice->dev.nfcb)) {
TagDetectAPDU();
}
break;
/*******************************************************************************/
default:
break;
}
// rfalNfcDeactivate(false);
// platformDelay(500);
// state = START_DISCOVERY;
}
break;
/*******************************************************************************/
case NOT_INIT:
default:
break;
}
}
/*!
*****************************************************************************
* \brief Demo APDUs Exchange
*
* Example how to exchange a set of predefined APDUs with PICC. The NDEF
* application will be selected and then CC will be selected and read.
*
*****************************************************************************
*/
void TagDetectAPDU(void) {
ReturnCode err;
uint16_t *rxLen;
uint8_t *rxData;
/* Exchange APDU: NDEF Tag Application Select command */
err = TagDetectTransceiveBlocking(ndefSelectApp, sizeof(ndefSelectApp), &rxData, &rxLen, RFAL_FWT_NONE);
platformLog(" Select NDEF Application: %s Data: %s\r\n", (err != ERR_NONE) ? "FAIL" : "OK",
hex2Str(rxData, *rxLen));
if ((err == ERR_NONE) && rxData[0] == 0x90 && rxData[1] == 0x00) {
/* Exchange APDU: Select Capability Container File */
err = TagDetectTransceiveBlocking(ccSelectFile, sizeof(ccSelectFile), &rxData, &rxLen, RFAL_FWT_NONE);
platformLog(" Select CC: %s Data: %s\r\n", (err != ERR_NONE) ? "FAIL" : "OK", hex2Str(rxData, *rxLen));
/* Exchange APDU: Read Capability Container File */
err = TagDetectTransceiveBlocking(readBinary, sizeof(readBinary), &rxData, &rxLen, RFAL_FWT_NONE);
platformLog(" Read CC: %s Data: %s\r\n", (err != ERR_NONE) ? "FAIL" : "OK", hex2Str(rxData, *rxLen));
}
}
/*!
*****************************************************************************
* \brief Demo Blocking Transceive
*
* Helper function to send data in a blocking manner via the rfalNfc module
*
* \warning A protocol transceive handles long timeouts (several seconds),
* transmission errors and retransmissions which may lead to a long period of
* time where the MCU/CPU is blocked in this method.
* This is a demo implementation, for a non-blocking usage example please
* refer to the Examples available with RFAL
*
* \param[in] txBuf : data to be transmitted
* \param[in] txBufSize : size of the data to be transmited
* \param[out] rxData : location where the received data has been placed
* \param[out] rcvLen : number of data bytes received
* \param[in] fwt : FWT to be used (only for RF frame interface,
* otherwise use RFAL_FWT_NONE)
*
*
* \return ERR_PARAM : Invalid parameters
* \return ERR_TIMEOUT : Timeout error
* \return ERR_FRAMING : Framing error detected
* \return ERR_PROTO : Protocol error detected
* \return ERR_NONE : No error, activation successful
*
*****************************************************************************
*/
ReturnCode
TagDetectTransceiveBlocking(uint8_t *txBuf, uint16_t txBufSize, uint8_t **rxData, uint16_t **rcvLen, uint32_t fwt) {
ReturnCode err;
err = rfalNfcDataExchangeStart(txBuf, txBufSize, rxData, rcvLen, fwt);
if (err == ERR_NONE) {
do {
rfalNfcWorker();
err = rfalNfcDataExchangeGetStatus();
} while (err == ERR_BUSY);
}
return err;
}

View File

@ -1,23 +0,0 @@
//
// Created by Kai Jan Kriegel on 17.10.22.
//
#ifndef FAB_READER2_C_POLLINGTAGDETECT_H
#define FAB_READER2_C_POLLINGTAGDETECT_H
#include "esp_err.h"
#include "st_errno.h"
typedef enum {
NOT_INIT = 0, /*!< Demo State: Not initialized */
START_DISCOVERY = 1, /*!< Demo State: Start Discovery */
DISCOVERY = 2 /*!< Demo State: Discovery */
} TagDetectState;
static TagDetectState nfc_state;
esp_err_t TagDetectInit(void);
void TagDetectCycle(void);
ReturnCode TagDetectTransceiveBlocking(uint8_t *txBuf, uint16_t txBufSize, uint8_t **rxData, uint16_t **rcvLen, uint32_t fwt);
#endif //FAB_READER2_C_POLLINGTAGDETECT_H

View File

@ -1,7 +0,0 @@
//
// Created by Kai Jan Kriegel on 23.01.23.
//
#include "rfalpoller.h"

View File

@ -1,8 +0,0 @@
//
// Created by Kai Jan Kriegel on 23.01.23.
//
#ifndef FAB_READER2_C_RFALPOLLER_H
#define FAB_READER2_C_RFALPOLLER_H
#endif //FAB_READER2_C_RFALPOLLER_H

View File

@ -1,92 +0,0 @@
//
// Created by Kai Jan Kriegel on 06.02.23.
//
#include "ota.h"
#include <stdbool.h>
#include <mqtt_client.h>
#include <esp_log.h>
#include "pollingtagdetect.h"
#include "st_errno.h"
#include "rfal_nfc.h"
extern TagDetectState nfc_state;
bool activeOTA = false;
uint8_t* current_nfcId;
uint8_t current_nfcIdLen;
bool hasActiveOTA() {
return activeOTA;
}
void startOTA(esp_mqtt_client_handle_t client, uint8_t *nfcId, uint8_t nfcIdLen) {
activeOTA = true;
char topic_stopOTA[] = "fabreader/00000/startOTA";
sprintf(topic_stopOTA, "fabreader/%05d/stopOTA", CONFIG_FABREADER2_ID);
esp_mqtt_client_publish(client, topic_stopOTA, (const char*)nfcId, nfcIdLen, 0, 0);
current_nfcId = (uint8_t*)malloc(nfcIdLen);
memcpy(current_nfcId, nfcId, nfcIdLen);
current_nfcIdLen = nfcIdLen;
ESP_LOGI("OTA", "Started OTA communication");
}
void continueOTA(esp_mqtt_client_handle_t client, char* topic, char *payload, unsigned int length) {
char topic_requestOTA[] = "fabreader/00000/requestOTA";
sprintf(topic_requestOTA, "fabreader/%05d/requestOTA", CONFIG_FABREADER2_ID);
char topic_responseOTA[] = "fabreader/00000/responseOTA";
sprintf(topic_responseOTA, "fabreader/%05d/responseOTA", CONFIG_FABREADER2_ID);
char topic_stopOTA[] = "fabreader/00000/stopOTA";
sprintf(topic_stopOTA, "fabreader/%05d/stopOTA", CONFIG_FABREADER2_ID);
char topic_restartOTA[] = "fabreader/00000/restartOTA";
sprintf(topic_restartOTA, "fabreader/%05d/restartOTA", CONFIG_FABREADER2_ID);
if (strcmp(topic, topic_requestOTA) == 0) {
uint16_t *rxLen;
uint8_t *rxData;
ESP_LOGD("OTA", "Received OTA request, transmiting to card");
ReturnCode err = TagDetectTransceiveBlocking((uint8_t*)payload, length, &rxData, &rxLen, RFAL_FWT_NONE);
if (err == ERR_NONE) {
ESP_LOGD("OTA", "Transmit to card successful, sending response");
esp_mqtt_client_publish(client, topic_responseOTA, (const char*)rxData, *rxLen, 0, 0);
} else {
ESP_LOGD("OTA", "Transmit to card failed!");
cancelOTA(client);
}
esp_mqtt_client_publish(client, topic_responseOTA, payload, length, 0, 0);
} else if (strcmp(topic, topic_stopOTA) == 0) {
ESP_LOGD("OTA", "Received OTA stop");
free(current_nfcId);
rfalNfcDeactivate(false);
platformDelay(500);
activeOTA = false;
nfc_state = START_DISCOVERY;
}
}
void cancelOTA(esp_mqtt_client_handle_t client) {
activeOTA = false;
char topic_cancelOTA[] = "fabreader/00000/cancelOTA";
sprintf(topic_cancelOTA, "fabreader/%05d/cancelOTA", CONFIG_FABREADER2_ID);
esp_mqtt_client_publish(client, topic_cancelOTA, (const char*)current_nfcId, current_nfcIdLen, 0, 0);
free(current_nfcId);
rfalNfcDeactivate(false);
platformDelay(500);
activeOTA = false;
nfc_state = START_DISCOVERY;
ESP_LOGI("OTA", "Canceled OTA communication");
}

View File

@ -1,19 +0,0 @@
//
// Created by Kai Jan Kriegel on 06.02.23.
//
#ifndef FAB_READER2_C_OTA_H
#define FAB_READER2_C_OTA_H
#include <stdbool.h>
#include <stdint.h>
#include <mqtt_client.h>
bool hasActiveOTA();
void startOTA(esp_mqtt_client_handle_t client, uint8_t *nfcId, uint8_t nfcIdLen);
void continueOTA(esp_mqtt_client_handle_t client, char* topic, char *payload, unsigned int length);
void cancelOTA(esp_mqtt_client_handle_t client);
#endif //FAB_READER2_C_OTA_H

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff