diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 53 |
1 files changed, 52 insertions, 1 deletions
@@ -9,9 +9,12 @@ #include <usb/descriptor.h> auto dev_desc = device_desc(0x200, 0, 0, 0, 64, 0x1d50, 0x60f8, 0, 0, 0, 0, 1); -auto conf_desc = configuration_desc(1, 1, 0, 0xc0, 0, +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(2, 0, 1, 0xff, 0x00, 0x00, 0, + endpoint_desc(0x82, 0x03, 64, 0) ) ); @@ -30,6 +33,9 @@ Pin nfc_irq_in = GPIOC[13]; Pin button = GPIOA[3]; Pin led = GPIOA[4]; +PinArray kp_rows = GPIOB.array(12, 15); +PinArray kp_cols = GPIOA.array(8, 10); + class CR95HF { private: SPI_t& spi; @@ -99,6 +105,25 @@ class USB_NFC : public USB_class_driver { USB_NFC usb_nfc(usb); +class USB_keypad : public USB_class_driver { + private: + USB_generic& usb; + + public: + USB_keypad(USB_generic& usbd) : usb(usbd) { + usb.register_driver(this); + } + + protected: + virtual void handle_set_configuration(uint8_t configuration) { + if(configuration) { + usb.hw_conf_ep(0x82, EPType::Interrupt, 64); + } + } +}; + +USB_keypad usb_keypad(usb); + int main() { rcc_init(); @@ -156,6 +181,14 @@ int main() { cr95hf.send_cmd(0x02, 2, (uint8_t*)"\x01\x05"); // Select ISO 15693 cr95hf.get_response(64, buf); + kp_cols.set_mode(Pin::Input); + kp_cols.set_pull(Pin::PullUp); + + kp_rows.set_type(Pin::OpenDrain); + kp_rows.set_mode(Pin::Output); + + uint32_t kp_last = 0; + while(1) { if(Time::time() < nfc_delay_until) { // Just do nothing. @@ -187,6 +220,24 @@ int main() { } } + uint32_t kp_state = 0; + + for(int i = 0; i < 4; i++) { + kp_rows.set(~(1 << i)); + asm volatile("dmb"); + asm volatile("nop"); + asm volatile("nop"); + asm volatile("nop"); + asm volatile("nop"); + kp_state |= ((~kp_cols.get()) & 0x7) << (i * 3); + } + + if(kp_state != kp_last && usb.ep_ready(2)) { + usb.write(2, &kp_state, 2); + kp_last = kp_state; + } + + usb.process(); } } |