#ifndef __USB_CDC_H__ #define __USB_CDC_H__ #include #include "usb.h" #include "util/minimal_io.h" class USB_CDC : public MinimalIO { public: /** * Header Functional Descriptor */ struct HeaderFunctionDescriptor { Uint8 bLength; Uint8 bDescriptorType; Uint8 bDescriptorSubtype; Uint8 bcdCDC_L; Uint8 bcdCDC_H; }; /** * Call Management Functional Descriptor */ struct CallManagementFunctionalDescriptor { Uint8 bLength; Uint8 bDescriptorType; Uint8 bDescriptorSubtype; Uint8 bmCapabilities; Uint8 bDataInterface; }; /** * Abstract Control Management Functional Descriptor */ struct AbstractControlManagementFunctionalDescriptor { Uint8 bLength; Uint8 bDescriptorType; Uint8 bDescriptorSubtype; Uint8 bmCapabilities; }; /** * Union Functional Descriptor */ struct UnionFunctionalDescriptor { Uint8 bLength; Uint8 bDescriptorType; Uint8 bDescriptorSubtype; Uint8 bMasterInterface; Uint8 bSlaveInterface0; }; struct LineCoding { Uint8 baudrate[sizeof(Uint32)]; ///< baudrate Uint8 stopbit; ///< stop bit: 0-1, 1-1.5, 2-2 Uint8 parity; ///< parity: 0-none, 1-odd, 2-even, 3-mark, 4-space Uint8 databit; ///< data bits: 5,6,7,8,16 } line_coding; // Descriptor type (Class specific) static const Uint8 DSC_TYPE_CS_INTERFACE = 0x24; static const Uint8 DSC_SUBTYPE_CS_HEADER_FUNC = 0x00; static const Uint8 DSC_SUBTYPE_CS_CALL_MAN = 0x01; static const Uint8 DSC_SUBTYPE_CS_ABST_CNTRL = 0x02; static const Uint8 DSC_SUBTYPE_CS_UNION_FUNC = 0x06; class ClassRequest { public: struct SetLineCodingComplete : public USB::CallbackFunctor { LineCoding &old_value; LineCoding new_value; void operator()(); SetLineCodingComplete(LineCoding &old); ~SetLineCodingComplete(); }; protected: USB_CDC &parent; SetLineCodingComplete set_line_coding_complete; bool send_encapsulated_command(const USB::SetupBuffer &buf); bool get_encapsulated_command(const USB::SetupBuffer &buf); bool set_line_coding(const USB::SetupBuffer &buf); bool get_line_coding(const USB::SetupBuffer &buf); bool set_control_line_state(const USB::SetupBuffer &buf); bool send_break(const USB::SetupBuffer &buf); public: // CDC ACM class specifc requests static const Uint8 SEND_ENCAPSULATED_COMMAND = 0x00; static const Uint8 GET_ENCAPSULATED_RESPONSE = 0x01; static const Uint8 SET_LINE_CODING = 0x20; static const Uint8 GET_LINE_CODING = 0x21; static const Uint8 SET_CONTROL_LINE_STATE = 0x22; static const Uint8 SEND_BREAK = 0x23; ClassRequest(USB_CDC &usb_cdc); ~ClassRequest(); bool handle(const USB::SetupBuffer &buf); } class_request_handler; void send_break(int i){} protected: USB &usb; const Uint8 ep_in_ctl, ep_in_data, ep_out_data; public: void handle_ctl(); unsigned int transmit(const char *buf, const unsigned int &buf_size); unsigned int receive(char *buf, const unsigned int &buf_size); USB_CDC(USB &target, const Uint8 &ep_in_ctl_index, const Uint8 &ep_in_data_index, const Uint8 &ep_out_data_index); ~USB_CDC(); }; #endif /* __USB_CDC_H__ */