From da3181f50f0cc21f50c6a95bac0d09bc5e755208 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sat, 1 Jul 2017 18:56:23 +0200 Subject: Added keypad support. --- laks | 2 +- main.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/laks b/laks index 4796432..d81982e 160000 --- a/laks +++ b/laks @@ -1 +1 @@ -Subproject commit 4796432e8d165b5358af9675f2ca15a61bafee68 +Subproject commit d81982edb1c4abf9a38da742f81bb648ce6882c5 diff --git a/main.cpp b/main.cpp index 1ec89a6..fbc3e23 100644 --- a/main.cpp +++ b/main.cpp @@ -9,9 +9,12 @@ #include 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(); } } -- cgit v1.2.3