re-arrange some logic for better passive operation
This commit is contained in:
parent
f470e9a9cd
commit
3005a63938
@ -73,6 +73,9 @@ void hw_init(int lf);
|
|||||||
#define SOLO_AMS_CS_PORT GPIOB
|
#define SOLO_AMS_CS_PORT GPIOB
|
||||||
#define SOLO_AMS_CS_PIN LL_GPIO_PIN_0
|
#define SOLO_AMS_CS_PIN LL_GPIO_PIN_0
|
||||||
|
|
||||||
|
#define SOLO_AMS_IRQ_PORT GPIOC
|
||||||
|
#define SOLO_AMS_IRQ_PIN LL_GPIO_PIN_15
|
||||||
|
|
||||||
#define SKIP_BUTTON_CHECK_WITH_DELAY 0
|
#define SKIP_BUTTON_CHECK_WITH_DELAY 0
|
||||||
#define SKIP_BUTTON_CHECK_FAST 0
|
#define SKIP_BUTTON_CHECK_FAST 0
|
||||||
|
|
||||||
|
@ -111,11 +111,16 @@ void device_reboot()
|
|||||||
{
|
{
|
||||||
NVIC_SystemReset();
|
NVIC_SystemReset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void device_init()
|
void device_init()
|
||||||
{
|
{
|
||||||
hw_init(HIGH_FREQUENCY);
|
|
||||||
|
// hw_init(LOW_FREQUENCY);
|
||||||
// isLowFreq = 1;
|
// isLowFreq = 1;
|
||||||
|
|
||||||
|
hw_init(HIGH_FREQUENCY);
|
||||||
|
isLowFreq = 0;
|
||||||
|
|
||||||
#ifndef IS_BOOTLOADER
|
#ifndef IS_BOOTLOADER
|
||||||
#if BOOT_TO_DFU
|
#if BOOT_TO_DFU
|
||||||
flash_option_bytes_init(1);
|
flash_option_bytes_init(1);
|
||||||
@ -153,6 +158,12 @@ void usbhid_init()
|
|||||||
#if DEBUG_LEVEL>1
|
#if DEBUG_LEVEL>1
|
||||||
wait_for_usb_tether();
|
wait_for_usb_tether();
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,10 +11,9 @@
|
|||||||
|
|
||||||
#include "ctap_errors.h"
|
#include "ctap_errors.h"
|
||||||
|
|
||||||
|
#define IS_IRQ_ACTIVE() (1 == (LL_GPIO_ReadInputPort(SOLO_AMS_IRQ_PORT) & SOLO_AMS_IRQ_PIN))
|
||||||
|
|
||||||
// Capability container
|
// Capability container
|
||||||
|
|
||||||
|
|
||||||
const CAPABILITY_CONTAINER NFC_CC = {
|
const CAPABILITY_CONTAINER NFC_CC = {
|
||||||
.cclen_hi = 0x00, .cclen_lo = 0x0f,
|
.cclen_hi = 0x00, .cclen_lo = 0x0f,
|
||||||
.version = 0x20,
|
.version = 0x20,
|
||||||
@ -26,8 +25,19 @@ const CAPABILITY_CONTAINER NFC_CC = {
|
|||||||
0x00,0x00 }
|
0x00,0x00 }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 13 chars
|
||||||
uint8_t NDEF_SAMPLE[] = "\x00\x14\xd1\x01\x0eU\x04solokeys.com/";
|
uint8_t NDEF_SAMPLE[] = "\x00\x14\xd1\x01\x0eU\x04solokeys.com/";
|
||||||
|
|
||||||
|
#include <stdarg.h>
|
||||||
|
void nprintf(const char *format, ...)
|
||||||
|
{
|
||||||
|
memmove((char*)NDEF_SAMPLE + sizeof(NDEF_SAMPLE) - 1 - 13," ", 13);
|
||||||
|
va_list args;
|
||||||
|
va_start (args, format);
|
||||||
|
vsnprintf ((char*)NDEF_SAMPLE + sizeof(NDEF_SAMPLE) - 1 - 13, 13, format, args);
|
||||||
|
va_end (args);
|
||||||
|
}
|
||||||
|
|
||||||
static struct
|
static struct
|
||||||
{
|
{
|
||||||
uint8_t max_frame_size;
|
uint8_t max_frame_size;
|
||||||
@ -315,8 +325,11 @@ int answer_rats(uint8_t parameter)
|
|||||||
// historical bytes
|
// historical bytes
|
||||||
memcpy(&res[3], (uint8_t *)"SoloKey tap", 11);
|
memcpy(&res[3], (uint8_t *)"SoloKey tap", 11);
|
||||||
|
|
||||||
|
|
||||||
nfc_write_frame(res, sizeof(res));
|
nfc_write_frame(res, sizeof(res));
|
||||||
ams_wait_for_tx(10);
|
ams_wait_for_tx(10);
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -657,49 +670,51 @@ void nfc_process_block(uint8_t * buf, int len)
|
|||||||
void nfc_loop()
|
void nfc_loop()
|
||||||
{
|
{
|
||||||
static uint32_t t1 = 0;
|
static uint32_t t1 = 0;
|
||||||
|
static uint32_t t2 = 0;
|
||||||
uint8_t buf[32];
|
uint8_t buf[32];
|
||||||
AMS_DEVICE ams;
|
AMS_DEVICE ams;
|
||||||
int len = 0;
|
int len = 0;
|
||||||
// uint8_t def[] = "\x00\x00\x05\x40\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14\x02\x01\x00";
|
|
||||||
|
|
||||||
|
|
||||||
// if (millis() - t1 > interval)
|
|
||||||
if (1)
|
if (1)
|
||||||
{
|
{
|
||||||
t1 = millis();
|
|
||||||
read_reg_block(&ams);
|
read_reg_block(&ams);
|
||||||
|
uint8_t state = AMS_STATE_MASK & ams.regs.rfid_status;
|
||||||
|
|
||||||
process_int0(ams.regs.int0);
|
if (state != AMS_STATE_SELECTED && state != AMS_STATE_SELECTEDX)
|
||||||
|
{
|
||||||
|
// delay(1); // sleep ?
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// if (memcmp(def,ams.buf,sizeof(AMS_DEVICE)) != 0)
|
|
||||||
// {
|
|
||||||
// printf1(TAG_NFC,"regs: "); dump_hex1(TAG_NFC,ams.buf,sizeof(AMS_DEVICE));
|
|
||||||
// }
|
|
||||||
if (ams.regs.rfid_status)
|
if (ams.regs.rfid_status)
|
||||||
{
|
{
|
||||||
// uint8_t state = AMS_STATE_MASK & ams.regs.rfid_status;
|
|
||||||
// if (state != AMS_STATE_SENSE)
|
// if (state != AMS_STATE_SENSE)
|
||||||
// printf1(TAG_NFC," %s %d\r\n", ams_get_state_string(ams.regs.rfid_status), millis());
|
// printf1(TAG_NFC," %s x%02x\r\n", ams_get_state_string(ams.regs.rfid_status), state);
|
||||||
}
|
}
|
||||||
if (ams.regs.int0 & AMS_INT_INIT)
|
if (ams.regs.int0 & AMS_INT_INIT)
|
||||||
{
|
{
|
||||||
// Initialize chip!
|
|
||||||
nfc_state_init();
|
nfc_state_init();
|
||||||
|
t1 = millis();
|
||||||
}
|
}
|
||||||
if (ams.regs.int1)
|
if (ams.regs.int1)
|
||||||
{
|
{
|
||||||
// ams_print_int1(ams.regs.int1);
|
// ams_print_int1(ams.regs.int1);
|
||||||
}
|
}
|
||||||
if (ams.regs.buffer_status2 && (ams.regs.int0 & AMS_INT_RXE))
|
|
||||||
|
if ((ams.regs.int0 & AMS_INT_RXE))
|
||||||
{
|
{
|
||||||
if (ams.regs.buffer_status2 & AMS_BUF_INVALID)
|
if (ams.regs.buffer_status2)
|
||||||
{
|
{
|
||||||
printf1(TAG_NFC,"Buffer being updated!\r\n");
|
if (ams.regs.buffer_status2 & AMS_BUF_INVALID)
|
||||||
}
|
{
|
||||||
else
|
printf1(TAG_NFC,"Buffer being updated!\r\n");
|
||||||
{
|
}
|
||||||
len = ams.regs.buffer_status2 & AMS_BUF_LEN_MASK;
|
else
|
||||||
ams_read_buffer(buf, len);
|
{
|
||||||
|
len = ams.regs.buffer_status2 & AMS_BUF_LEN_MASK;
|
||||||
|
ams_read_buffer(buf, len);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -719,12 +734,17 @@ void nfc_loop()
|
|||||||
printf1(TAG_NFC, "HLTA/Halt\r\n");
|
printf1(TAG_NFC, "HLTA/Halt\r\n");
|
||||||
break;
|
break;
|
||||||
case NFC_CMD_RATS:
|
case NFC_CMD_RATS:
|
||||||
printf1(TAG_NFC,"RATS\r\n");
|
t2 = millis();
|
||||||
t1 = millis();
|
|
||||||
answer_rats(buf[1]);
|
answer_rats(buf[1]);
|
||||||
|
nprintf("R:%x-%x:%d:%d",firstbuf[0],firstbuf[1],t2-t1,inits);
|
||||||
|
///
|
||||||
|
LL_GPIO_SetOutputPin(GPIOA,LL_GPIO_PIN_12);
|
||||||
|
///
|
||||||
|
|
||||||
NFC_STATE.block_num = 1;
|
NFC_STATE.block_num = 1;
|
||||||
clear_ibuf();
|
clear_ibuf();
|
||||||
WTX_clear();
|
WTX_clear();
|
||||||
printf1(TAG_NFC,"RATS answered %d (took %d)\r\n",millis(), millis() - t1);
|
printf1(TAG_NFC,"RATS answered %d (took %d)\r\n",millis(), millis() - t1);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -736,10 +756,8 @@ void nfc_loop()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -37,18 +37,16 @@ void _putchar(char c)
|
|||||||
LL_USART_TransmitData8(DEBUG_UART,c);
|
LL_USART_TransmitData8(DEBUG_UART,c);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
static int NFC = 0;
|
|
||||||
|
|
||||||
|
|
||||||
int _write (int fd, const void *buf, long int len)
|
int _write (int fd, const void *buf, long int len)
|
||||||
{
|
{
|
||||||
uint8_t * data = (uint8_t *) buf;
|
uint8_t * data = (uint8_t *) buf;
|
||||||
|
|
||||||
if (!NFC)
|
|
||||||
{
|
// Send out USB serial
|
||||||
// Send out USB serial
|
CDC_Transmit_FS(data, len);
|
||||||
CDC_Transmit_FS(data, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send out UART serial
|
// Send out UART serial
|
||||||
while(len--)
|
while(len--)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user