diff options
Diffstat (limited to 'main.cpp')
-rw-r--r-- | main.cpp | 44 |
1 files changed, 42 insertions, 2 deletions
@@ -40,8 +40,9 @@ static Pin pwm_outputs[] = {PC6, PC7, PC8, PC9}; auto dev_desc = device_desc(0x200, 0, 0, 0, 64, 0x1234, 0x5678, 0, 0, 0, 0, 1); auto conf_desc = configuration_desc(3, 1, 0, 0xc0, 0, - interface_desc(0, 0, 1, 0xff, 0x00, 0x00, 0, - endpoint_desc(0x81, 0x02, 64, 0) + interface_desc(0, 0, 2, 0xff, 0x00, 0x00, 0, + endpoint_desc(0x01, 0x02, 64, 0), // OUT + endpoint_desc(0x81, 0x02, 64, 0) // IN ) ); @@ -133,6 +134,45 @@ class USB_JTAG : public USB_class_driver { USB_JTAG usb_jtag(usb); +class USB_TM : public USB_class_driver { + private: + USB_generic& usb; + + uint32_t buf[16]; + + public: + USB_TM(USB_generic& usbd) : usb(usbd) { + usb.register_driver(this); + } + + protected: + virtual void handle_set_configuration(uint8_t configuration) { + if(configuration) { + usb.hw_conf_ep(0x81, EPType::Bulk, 64); + usb.hw_conf_ep(0x01, EPType::Bulk, 64); + usb.register_out_handler(this, 1); + } + } + + virtual void handle_out(uint8_t ep, uint32_t len) { + if(ep == 1 && len) { + usb.read(ep, buf, len); + + if(len == 2) { + uint8_t* bufp = (uint8_t*)buf; + + switch(bufp[0]) { + case 2: + TIM8.CCR1 = TIM8.CCR2 = TIM8.CCR3 = TIM8.CCR4 = 1000 + bufp[1] * 2; + break; + } + } + } + } +}; + +USB_TM usb_tm(usb); + template<> void interrupt<(Interrupt::IRQ)77>() { usb.process(); |