summaryrefslogtreecommitdiff
path: root/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'main.cpp')
-rw-r--r--main.cpp46
1 files changed, 43 insertions, 3 deletions
diff --git a/main.cpp b/main.cpp
index 9aae4ee..ced6660 100644
--- a/main.cpp
+++ b/main.cpp
@@ -8,6 +8,7 @@
#include <spi/spi.h>
#include <usb/usb.h>
#include <usb/descriptor.h>
+#include <usb/hid.h>
const uint8_t fw_version = 1;
@@ -25,10 +26,37 @@ enum tag_type_t {
ISO18092,
};
+auto report_desc = pack(
+ usage_page(0xffca),
+ usage(0x01),
+ collection(Collection::Application,
+ // ISO 15693
+ report_id(1),
+ usage_page(0xffca),
+ usage(0x41),
+ logical_minimum(0),
+ logical_maximum(255),
+ report_size(8),
+ report_count(8),
+ input(0x02),
+
+ // ISO 18092
+ report_id(2),
+ usage_page(0xffca),
+ usage(0x42),
+ logical_minimum(0),
+ logical_maximum(255),
+ report_size(8),
+ report_count(8),
+ input(0x02)
+ )
+);
+
auto dev_desc = device_desc(0x200, 0, 0, 0, 64, 0x1d50, 0x60f8, 0, 0, 0, 0, 1);
auto conf_desc = configuration_desc(2, 1, 0, 0xc0, 0,
- interface_desc(1, 0, 1, 0xff, 0x00, 0x00, 0,
- endpoint_desc(0x81, 0x02, 64, 0)
+ interface_desc(1, 0, 1, 0x03, 0x00, 0x00, 0,
+ hid_desc(0x111, 0, 1, 0x22, sizeof(report_desc)),
+ endpoint_desc(0x81, 0x03, 64, 0)
),
interface_desc(2, 0, 1, 0xff, 0x00, 0x00, 0,
endpoint_desc(0x82, 0x03, 64, 0)
@@ -37,6 +65,7 @@ auto conf_desc = configuration_desc(2, 1, 0, 0xc0, 0,
desc_t dev_desc_p = {sizeof(dev_desc), (void*)&dev_desc};
desc_t conf_desc_p = {sizeof(conf_desc), (void*)&conf_desc};
+desc_t report_desc_p = {sizeof(report_desc), (void*)&report_desc};
USB_l0 usb(USB, dev_desc_p, conf_desc_p);
@@ -103,6 +132,14 @@ class CR95HF {
CR95HF cr95hf(SPI1, nfc_ss);
+class HID_NFC : public USB_HID {
+ public:
+ HID_NFC(USB_generic& usbd, desc_t rdesc) : USB_HID(usbd, rdesc, 1, 1, 64) {}
+};
+
+HID_NFC hid_nfc(usb, report_desc_p);
+
+/*
class USB_NFC : public USB_class_driver {
private:
USB_generic& usb;
@@ -121,6 +158,7 @@ class USB_NFC : public USB_class_driver {
};
USB_NFC usb_nfc(usb);
+*/
class USB_keypad : public USB_class_driver {
private:
@@ -237,7 +275,7 @@ int main() {
uint8_t buf[64];
bool cmd_sent = false;
uint32_t nfc_delay_until = 0;
- uint8_t bulk_buf[8];
+ uint8_t bulk_buf[9];
tag_type_t active_type = ISO15693;
Time::sleep(1000);
@@ -282,12 +320,14 @@ int main() {
uint8_t* id_buf = bulk_buf;
if(active_type == ISO15693) {
+ *id_buf++ = 1;
uint8_t* id_raw = &buf[11];
for(uint32_t i = 0; i < 8; i++) {
*id_buf++ = *id_raw--;
}
} else if(active_type == ISO18092) {
+ *id_buf++ = 2;
uint8_t* id_raw = &buf[3];
for(uint32_t i = 0; i < 8; i++) {
*id_buf++ = *id_raw++;