{"id":320394,"date":"2021-03-27T21:01:48","date_gmt":"2021-03-27T21:01:48","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=320394"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=320394","title":{"rendered":"Stm32 + USB \u043d\u0430 \u0448\u0430\u0431\u043b\u043e\u043d\u0430\u0445 C++. \u041f\u0440\u043e\u0434\u043e\u043b\u0436\u0435\u043d\u0438\u0435. \u0414\u0435\u043b\u0430\u0435\u043c HID"},"content":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0412 <a href=\"https:\/\/habr.com\/ru\/post\/547732\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u0448\u043b\u044b\u0439<\/a> \u0440\u0430\u0437 \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c\u0438 \u0442\u043e\u0447\u043a\u0430\u043c\u0438, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u0432 EPnR, \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0434 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b \u0431\u0443\u0444\u0435\u0440\u043e\u0432 \u0438 \u043f\u043e\u0434 \u0441\u0430\u043c\u0438 \u0431\u0443\u0444\u0435\u0440\u044b. \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u043d\u0430\u0447\u0430\u0442\u043e\u0435 \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e HID-\u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0435\u0433\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434\u043e\u043c.<\/p>\n<h2>\u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f<\/h2>\n<p>\u041a\u0440\u043e\u043c\u0435 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0445 \u0440\u0430\u043d\u0435\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438 \u0442\u0430\u043a\u0436\u0435 \u0434\u0435\u043b\u044f\u0442 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u0435. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043e\u0431\u0449\u0438\u0439 (\u0433\u043b\u0430\u0432\u043d\u044b\u0439) \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u043e\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438. \u041d\u043e\u043c\u0435\u0440 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0445\u043e\u0441\u0442, \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0431\u0438\u0442\u0430\u0445 EP_ID \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430 ISTR. \u041f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044f\u0441\u044c \u043b\u0438\u043d\u0438\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441:<\/p>\n<pre><code class=\"cpp\">using EpRequestHandler = std::add_pointer_t&lt;void()&gt;; template&lt;typename...&gt; class EndpointHandlersBase; template&lt;typename... Endpoints, int8_t... Indexes&gt; class EndpointHandlersBase&lt;TypeList&lt;Endpoints...&gt;, Int8_tArray&lt;Indexes...&gt;&gt; { public:   \/\/ \u041c\u0430\u0441\u0441\u0438\u0432 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u043d\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438   static constexpr EpRequestHandler _handlers[] = {Endpoints::Handler...};   \/\/ \u0418\u043d\u0434\u0435\u043a\u0441\u044b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432   static constexpr int8_t _handlersIndexes[] = {Indexes...}; public:   inline static void Handle(uint8_t number, EndpointDirection direction)   {     _handlers[_handlersIndexes[2 * number + (direction == EndpointDirection::Out ? 1 : 0)]]();   } };<\/code><\/pre>\n<p>\u041a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432 <em>_handlersIndexes<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 \u043d\u043e\u043c\u0435\u0440 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0438 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441:<\/p>\n<pre><code class=\"cpp\">template&lt;int8_t Index, typename Endpoints&gt; class EndpointHandlersIndexes {   \/\/ \u041f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438.   using Predicate = Select&lt;Index % 2 == 0, IsTxOrBidirectionalEndpointWithNumber&lt;Index \/ 2&gt;, IsRxOrBidirectionalEndpointWithNumber&lt;Index \/ 2&gt;&gt;::value;   static const int8_t EndpointIndex = Search&lt;Predicate::template type, Endpoints&gt;::value; public:   \/\/ \u0412 \u043a\u043e\u043d\u0435\u0446 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u043e\u043c\u0435\u0440 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0438\u043b\u0438 -1 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430.   using type = typename Int8_tArray_InsertBack&lt;typename EndpointHandlersIndexes&lt;Index - 1, Endpoints&gt;::type, EndpointIndex&gt;::type; }; template&lt;typename Endpoints&gt; class EndpointHandlersIndexes&lt;-1, Endpoints&gt; { public:   using type = Int8_tArray&lt;&gt;; };<\/code><\/pre>\n<p>\u0418\u0437 \u0442\u0430\u043a\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u0441\u0442\u0430\u0442\u0438, \u0432\u044b\u0442\u0435\u043a\u0430\u0435\u0442 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438 \u0441 \u043d\u043e\u043c\u0435\u0440\u0430\u043c\u0438 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0440\u0430\u0437\u043c\u0435\u0440 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0440\u0430\u0432\u0435\u043d \u0443\u0434\u0432\u043e\u0435\u043d\u043d\u043e\u043c\u0443 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043d\u043e\u043c\u0435\u0440\u0443 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438.<\/p>\n<h2>\u041a\u043b\u0430\u0441\u0441 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438<\/h2>\n<p>\u0418\u0437-\u0437\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c\u0438 \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043e\u0434 \u043d\u0430 \u0434\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0430: \u0431\u0430\u0437\u043e\u0432\u044b\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u043d\u0443\u0436\u043d\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"cpp\">template &lt;uint8_t _Number, EndpointDirection _Direction, EndpointType _Type, uint16_t _MaxPacketSize, uint8_t _Interval&gt; class EndpointBase ...<\/code><\/pre>\n<p>\u0410 \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u044b\u0439, \u0441 \u0430\u0434\u0440\u0435\u0441\u0430\u043c\u0438 \u0431\u0443\u0444\u0435\u0440\u043e\u0432 \u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430 (\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u044e\u0442\u0441\u044f \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u043e\u043c, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u043c \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435). \u0418\u0437-\u0437\u0430 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c\u0438 \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432\/\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0439 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443 \u043e\u0434\u043d\u043e\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0442\u0438\u043f\u0430 Interrupt \u0431\u0443\u0434\u0435\u0442 \u043e\u0434\u0438\u043d \u0431\u0443\u0444\u0435\u0440, \u0430 \u0443 \u0434\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0438\u043b\u0438 Bulk \u0441 \u0434\u0432\u043e\u0439\u043d\u043e\u0439 \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439 &#8212; \u0434\u0432\u0430) \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d \u0441\u0432\u043e\u0439 \u043a\u043b\u0430\u0441\u0441:<\/p>\n<pre><code class=\"cpp\">template &lt;typename _Base, typename _Reg&gt; class Endpoint : public _Base ... template&lt;typename _Base, typename _Reg, uint32_t _TxBufferAddress, uint32_t _TxCountRegAddress, uint32_t _RxBufferAddress, uint32_t _RxCountRegAddress&gt; class BidirectionalEndpoint : public Endpoint&lt;_Base, _Reg&gt; ... template&lt;typename _Base, typename _Reg, uint32_t _Buffer0Address, uint32_t _Count0RegAddress, uint32_t _Buffer1Address, uint32_t _Count1RegAddress&gt; class BulkDoubleBufferedEndpoint : public Endpoint&lt;_Base, _Reg&gt;<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0439: \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 (\u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440 EPnR), \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430, \u043c\u0435\u0442\u043e\u0434\u044b \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0431\u0438\u0442\u0430\u043c\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430 (\u041e\u0447\u0438\u0441\u0442\u043a\u0430 \u0431\u0438\u0442\u043e\u0432 <em>CTR_TX\/RX<\/em>, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0431\u0438\u0442\u043e\u0432 <em>TX\/RX_STATUS<\/em>), \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<h2>\u041a\u043b\u0430\u0441\u0441 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430<\/h2>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u044e \u0432 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u043f\u043e \u0441\u0443\u0442\u0438 (\u043a\u0430\u043a \u044f \u043f\u043e\u043d\u0438\u043c\u0430\u044e) \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445 \u0442\u043e\u0447\u0435\u043a, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 (\u043f\u0440\u0438\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e \u043a\u043e\u0434 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043c\u043e\u0449\u044c variadic-\u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043b\u0438\u0448\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438):<\/p>\n<pre><code class=\"cpp\">template &lt;uint8_t _Number, uint8_t _AlternateSetting = 0, uint8_t _Class = 0, uint8_t _SubClass = 0, uint8_t _Protocol = 0, typename... _Endpoints&gt; class Interface { public:   using Endpoints = Zhele::TemplateUtils::TypeList&lt;_Endpoints...&gt;;   static const uint8_t EndpointsCount = ((_Endpoints::Direction == EndpointDirection::Bidirectional ? 2 : 1) + ...);    static void Reset()   {     (_Endpoints::Reset(), ...);   }    static uint16_t FillDescriptor(InterfaceDescriptor* descriptor)   {     uint16_t totalLength = sizeof(InterfaceDescriptor);      *descriptor = InterfaceDescriptor {       .Number = _Number,       .AlternateSetting = _AlternateSetting,       .EndpointsCount = EndpointsCount,       .Class = _Class,       .SubClass = _SubClass,       .Protocol = _Protocol     };          EndpointDescriptor* endpointsDescriptors = reinterpret_cast&lt;EndpointDescriptor*&gt;(++descriptor);     totalLength += (_Endpoints::FillDescriptor(endpointsDescriptors++) + ...);      return totalLength;   } };<\/code><\/pre>\n<h2>\u041a\u043b\u0430\u0441\u0441 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438<\/h2>\n<p>\u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0435\u0441\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432. \u0427\u0438\u0442\u0430\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 USB \u044f \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e \u0432\u0441\u0435 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u0438 \u0445\u043e\u0441\u0442 \u0432\u043f\u0440\u0430\u0432\u0435 \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438\/\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b, \u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0435 \u043e\u0441\u043e\u0437\u043d\u0430\u043b \u0441\u0443\u0442\u0438 \u0438 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b. \u0412 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u044e, \u0447\u0442\u043e \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0445\u043e\u0441\u0442\u0430 \u0441 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f\u043c\u0438 \u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e &#8212; \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0439 \u043a \u043d\u0438\u043c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0439 \u043a \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c \u0442\u043e\u0447\u043a\u0430\u043c.<\/p>\n<pre><code class=\"cpp\">template &lt;uint8_t _Number, uint8_t _MaxPower, bool _RemoteWakeup = false, bool _SelfPowered = false, typename... _Interfaces&gt; class Configuration { public:   using Endpoints = Zhele::TemplateUtils::Append_t&lt;typename _Interfaces::Endpoints...&gt;;   static void Reset()   {     (_Interfaces::Reset(), ...);   } ...<\/code><\/pre>\n<h2>\u041a\u043b\u0430\u0441\u0441 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430<\/h2>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0432 \u0432\u0435\u0440\u0448\u0438\u043d\u0435 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e. \u0412 \u043c\u043e\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u043c \u043e\u0442 \u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d\u0430 \u043e\u0441\u043e\u0431\u0430\u044f \u0438 \u043e\u0431\u043c\u0435\u043d \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0441 \u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 &#8212; \u044d\u0442\u043e \u043e\u0431\u043c\u0435\u043d \u0434\u0430\u043d\u043d\u044b\u043c\u0438 (\u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u043c\u0438) \u0441 \u0441\u0430\u043c\u0438\u043c \u0434\u0435\u0432\u0430\u0439\u0441\u043e\u043c.<\/p>\n<pre><code class=\"cpp\">template&lt;   typename _Regs,   IRQn_Type _IRQNumber,   typename _ClockCtrl,    uint16_t _UsbVersion,   DeviceClass _Class,   uint8_t _SubClass,   uint8_t _Protocol,   uint16_t _VendorId,   uint16_t _ProductId,   uint16_t _DeviceReleaseNumber,   typename _Ep0,   typename... _Configurations&gt; class DeviceBase : public _Ep0 {   using This = DeviceBase&lt;_Regs, _IRQNumber, _ClockCtrl, _UsbVersion, _Class, _SubClass, _Protocol, _VendorId, _ProductId, _DeviceReleaseNumber, _Ep0, _Configurations...&gt;;   using Endpoints = Append_t&lt;typename _Configurations::Endpoints...&gt;;   using Configurations = TypeList&lt;_Configurations...&gt;;    \/\/ Replace Ep0 with this for correct handler register.   using EpBufferManager = EndpointsManager&lt;Append_t&lt;_Ep0, Endpoints&gt;&gt;;   using EpHandlers = EndpointHandlers&lt;Append_t&lt;This, Endpoints&gt;&gt;; ...<\/code><\/pre>\n<p>\u041a\u043b\u0430\u0441\u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f, \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0443\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c \u0442\u043e\u0447\u043a\u0430\u043c:<\/p>\n<pre><code class=\"cpp\">static void CommonHandler() {   if(_Regs()-&gt;ISTR &amp; USB_ISTR_RESET)   {     Reset();   }   if (_Regs()-&gt;ISTR &amp; USB_ISTR_CTR)   {     uint8_t endpoint = _Regs()-&gt;ISTR &amp; USB_ISTR_EP_ID;     EpHandlers::Handle(endpoint, ((_Regs()-&gt;ISTR &amp; USB_ISTR_DIR) != 0 ? EndpointDirection::Out : EndpointDirection::In));   }   NVIC_ClearPendingIRQ(_IRQNumber); }<\/code><\/pre>\n<p>\u042f\u0432\u043b\u044f\u044f\u0441\u044c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0438 \u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439, \u043a\u043b\u0430\u0441\u0441 <em>Device <\/em>\u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0439 \u043a \u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u0442\u043e\u0447\u043a\u0435, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044f, \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0443\u043c\u0435\u0440\u0430\u0446\u0438\u0438:<\/p>\n<details class=\"spoiler\">\n<summary>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f \u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">static void Handler() {   if(_Ep0::Reg::Get() &amp; USB_EP_CTR_RX)   {     _Ep0::ClearCtrRx();     if(_Ep0::Reg::Get() &amp; USB_EP_SETUP)     {       SetupPacket* setup = reinterpret_cast&lt;SetupPacket*&gt;(_Ep0::RxBuffer);       switch (setup-&gt;Request) {       case StandartRequestCode::GetStatus: {         uint16_t status = 0;         _Ep0::Writer::SendData(&amp;status, sizeof(status));         break;       }       case StandartRequestCode::SetAddress: {         TempAddressStorage = setup-&gt;Value;         _Ep0::Writer::SendData(0);         break;       }       case StandartRequestCode::GetDescriptor: {         switch (static_cast&lt;GetDescriptorParameter&gt;(setup-&gt;Value)) {         case GetDescriptorParameter::DeviceDescriptor: {           DeviceDescriptor tempDeviceDescriptor;           FillDescriptor(reinterpret_cast&lt;DeviceDescriptor*&gt;(&amp;tempDeviceDescriptor));           _Ep0::Writer::SendData(&amp;tempDeviceDescriptor, setup-&gt;Length &lt; sizeof(DeviceDescriptor) ? setup-&gt;Length : sizeof(DeviceDescriptor));           break;         }         case GetDescriptorParameter::ConfigurationDescriptor: {           uint8_t temp[64];           uint16_t size = GetType&lt;0, Configurations&gt;::type::FillDescriptor(reinterpret_cast&lt;ConfigurationDescriptor*&gt;(&amp;temp[0]));           _Ep0::Writer::SendData(reinterpret_cast&lt;ConfigurationDescriptor*&gt;(&amp;temp[0]), setup-&gt;Length &lt; size ? setup-&gt;Length : size);           break;         }         case GetDescriptorParameter::HidReportDescriptor: {           uint16_t size = sizeof(GetType_t&lt;0, Configurations&gt;::HidReport::Data);           _Ep0::Writer::SendData(GetType_t&lt;0, Configurations&gt;::HidReport::Data, setup-&gt;Length &lt; size ? setup-&gt;Length : size);           break;         }         default:           _Ep0::SetTxStatus(EndpointStatus::Stall);           break;         }         break;       }       case StandartRequestCode::GetConfiguration: {         uint16_t configuration = 0;         _Ep0::Writer::SendData(&amp;configuration, 1);         break;       }       case StandartRequestCode::SetConfiguration: {         _Ep0::Writer::SendData(0);         break;       }       default:         _Ep0::SetTxStatus(EndpointStatus::Stall);         break;       }     }     _Ep0::SetRxStatus(EndpointStatus::Valid);   }   if(_Ep0::Reg::Get() &amp; USB_EP_CTR_TX)   {     _Ep0::ClearCtrTx();     if(TempAddressStorage != 0)     {       _Regs()-&gt;DADDR = USB_DADDR_EF | (TempAddressStorage &amp; USB_DADDR_ADD);       TempAddressStorage = 0;     }     _Ep0::SetRxStatus(EndpointStatus::Valid);   } }<\/code><\/pre>\n<\/div>\n<\/details>\n<h2>\u0418\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 HID<\/h2>\n<p>HID-\u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e &#8212; \u044d\u0442\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e \u043a\u0430\u043a \u043c\u0438\u043d\u0438\u043c\u0443\u043c \u0441 \u043e\u0434\u043d\u0438\u043c \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c \u0442\u0438\u043f\u0430 HID, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0432 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0435 \u043a\u043b\u0430\u0441\u0441 HID &#8212; \u044d\u0442\u043e \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u0439 \u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430:<\/p>\n<details class=\"spoiler\">\n<summary>\u041a\u043b\u0430\u0441\u0441 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 hid<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">template &lt;uint8_t _Number, uint8_t _AlternateSetting, uint8_t _SubClass, uint8_t _Protocol, typename _Hid, typename... _Endpoints&gt; class HidInterface : public Interface&lt;_Number, _AlternateSetting, 0x03, _SubClass, _Protocol, _Endpoints...&gt; {   using Base = Interface&lt;_Number, _AlternateSetting, 0x03, _SubClass, _Protocol, _Endpoints...&gt;; public:   using Endpoints = Base::Endpoints;    static uint16_t FillDescriptor(InterfaceDescriptor* descriptor)   {     uint16_t totalLength = sizeof(InterfaceDescriptor);      *descriptor = InterfaceDescriptor {       .Number = _Number,       .AlternateSetting = _AlternateSetting,       .EndpointsCount = Base::EndpointsCount,       .Class = 0x03,       .SubClass = _SubClass,       .Protocol = _Protocol     };     _Hid* hidDescriptor = reinterpret_cast&lt;_Hid*&gt;(++descriptor);     *hidDescriptor = _Hid {     };     uint8_t* reportsPart = reinterpret_cast&lt;uint8_t*&gt;(++hidDescriptor);     uint16_t bytesWritten = _Hid::FillReports(reportsPart);      totalLength += sizeof(_Hid) + bytesWritten;      EndpointDescriptor* endpointsDescriptors = reinterpret_cast&lt;EndpointDescriptor*&gt;(&amp;reportsPart[bytesWritten]);     totalLength += (_Endpoints::FillDescriptor(endpointsDescriptors++) + ...);      return totalLength;   } private: };<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0421\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0447\u043d\u0430\u044f \u0447\u0430\u0441\u0442\u044c \u043d\u0430 \u044d\u0442\u043e\u043c \u043e\u043a\u043e\u043d\u0447\u0435\u043d\u0430, \u0432 \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c, \u043a\u043e\u043d\u0435\u0447\u043d\u043e, \u043a \u043a\u043b\u0430\u0441\u0441\u0443 <em>HidInterface <\/em>\u0431\u0443\u0434\u0443\u0442 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u044b \u0434\u0440\u0443\u0433\u0438\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u043a\u043b\u0430\u0441\u0441\u044b, \u0447\u0442\u043e \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0443 \u0447\u0438\u0441\u0442\u043e \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0443\u044e, \u043d\u0438\u0447\u0435\u0433\u043e \u0438\u0437\u043e\u0431\u0440\u0435\u0442\u0430\u0442\u044c \u0443\u0436\u0435 \u043d\u0435 \u043d\u0443\u0436\u043d\u043e (\u043d\u0430\u0434\u0435\u044e\u0441\u044c).<\/p>\n<h2>HID-\u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e<\/h2>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u0438\u0437 \u0432\u0441\u0435\u0433\u043e \u044d\u0442\u043e\u0433\u043e \u0441\u0434\u0435\u043b\u0430\u0435\u043c \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u043e\u0434\u0438\u043d \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434 (\u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0442\u0430\u043a \u0443\u0434\u043e\u0431\u043d\u043e, \u043e\u043d \u0435\u0441\u0442\u044c \u043d\u0430 \u043f\u043b\u0430\u0442\u0435 BluePill) \u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u044d\u0442\u0438\u043c \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434\u043e\u043c \u0441 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0430 (\u0447\u0435\u0440\u0435\u0437 USB HID Demonstrator).<\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043b\u044e\u0431\u043e\u0433\u043e HID-\u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f <em>Report<\/em>, \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u044e\u0449\u0438\u0439 \u043f\u043e\u0440\u044f\u0434\u043e\u043a \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043e\u043d \u0431\u0443\u0434\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u044b\u043c:<\/p>\n<pre><code class=\"cpp\">using Report = HidReport&lt;   0x06, 0x00, 0xff,    \/\/ USAGE_PAGE (Generic Desktop)   0x09, 0x01,          \/\/ USAGE (Vendor Usage 1)   0xa1, 0x01,          \/\/ COLLECTION (Application)   0x85, 0x01,          \/\/   REPORT_ID (1)   0x09, 0x01,          \/\/   USAGE (Vendor Usage 1)   0x15, 0x00,          \/\/   LOGICAL_MINIMUM (0)   0x25, 0x01,          \/\/   LOGICAL_MAXIMUM (1)   0x75, 0x08,          \/\/   REPORT_SIZE (8)   0x95, 0x01,          \/\/   REPORT_COUNT (1)   0xb1, 0x82,          \/\/   FEATURE (Data,Var,Abs,Vol)   0x85, 0x01,          \/\/   REPORT_ID (1)   0x09, 0x01,          \/\/   USAGE (Vendor Usage 1)   0x91, 0x82,          \/\/   OUTPUT (Data,Var,Abs,Vol)   0xc0                 \/\/ END_COLLECTION &gt;;<\/code><\/pre>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043d\u0443\u0436\u043d\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0432\u0441\u044e \u0438\u0440\u0435\u0440\u0430\u0445\u0438\u044e: \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438, \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044e \u0438 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e:<\/p>\n<pre><code class=\"cpp\">using HidDesc = HidDescriptor&lt;0x1001, Report&gt;;  using LedsControlEpBase = OutEndpointBase&lt;1, EndpointType::Interrupt, 4, 32&gt;; using EpInitializer = EndpointsInitializer&lt;DefaultEp0, LedsControlEpBase&gt;;  using Ep0 = EpInitializer::ExtendEndpoint&lt;DefaultEp0&gt;; using LedsControlEp = EpInitializer::ExtendEndpoint&lt;LedsControlEpBase&gt;;  using Hid = HidInterface&lt;0, 0, 0, 0, HidDesc, LedsControlEp&gt;; using Config = HidConfiguration&lt;0, 250, false, false, Report, Hid&gt;; using MyDevice = Device&lt;0x0200, DeviceClass::InterfaceSpecified, 0, 0, 0x0483, 0x5711, 0, Ep0, Config&gt;;<\/code><\/pre>\n<p>\u0412 \u043e\u0431\u0449\u0435\u043c-\u0442\u043e \u0432\u0441\u0451, \u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0434\u043b\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434\u043e\u043c:<\/p>\n<pre><code class=\"cpp\">using Led = IO::Pc13Inv; \/\/ Inv - \u0438\u043d\u0432\u0435\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439.  template&lt;&gt; void LedsControlEp::Handler() {   LedsControlEp::ClearCtrRx();   uint8_t* buffer = reinterpret_cast&lt;uint8_t*&gt;(LedsControlEp::Buffer);   bool needSet = buffer[1] != 0;   \/\/ \u041a\u043e\u0434 \u043f\u043e\u0447\u0442\u0438 \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u043f\u043e\u0437\u0430\u0438\u043c\u0441\u0442\u0432\u043e\u0432\u0430\u043d \u0438\u0437 \u043f\u043e\u0441\u0442\u0430 \"STM32 \u0438 USB-HID \u2014 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e\".   \/\/ \u041d\u0435 \u0441\u0442\u0430\u043b \u0438\u0437\u043c\u0435\u043d\u044f\u0442\u044c \u0435\u0433\u043e \u0434\u043b\u044f \u0443\u0434\u043e\u0431\u043d\u043e\u0439 \u043d\u0430\u0432\u0438\u0433\u0430\u0446\u0438\u0438.   switch(buffer[0])   {   case 1:     needSet ? Led::Set() : Led::Clear();     break;   }   LedsControlEp::SetRxStatus(EndpointStatus::Valid); }<\/code><\/pre>\n<p>\u0426\u0435\u043b\u0438\u043a\u043e\u043c \u0444\u0430\u0439\u043b main.c \u0434\u043b\u044f Stm32f103 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a (\u043f\u043e-\u043c\u043e\u0435\u043c\u0443, \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u043e):<\/p>\n<details class=\"spoiler\">\n<summary>\u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">#include &lt;clock.h&gt; #include &lt;iopins.h&gt; #include &lt;usb.h&gt;  using namespace Zhele; using namespace Zhele::Clock; using namespace Zhele::IO; using namespace Zhele::Usb;  using Report = HidReport&lt;   0x06, 0x00, 0xff,        \/\/ USAGE_PAGE (Generic Desktop)   0x09, 0x01,          \/\/ USAGE (Vendor Usage 1)   0xa1, 0x01,          \/\/ COLLECTION (Application)   0x85, 0x01,          \/\/   REPORT_ID (1)   0x09, 0x01,          \/\/   USAGE (Vendor Usage 1)   0x15, 0x00,          \/\/   LOGICAL_MINIMUM (0)   0x25, 0x01,          \/\/   LOGICAL_MAXIMUM (1)   0x75, 0x08,          \/\/   REPORT_SIZE (8)   0x95, 0x01,          \/\/   REPORT_COUNT (1)   0xb1, 0x82,          \/\/   FEATURE (Data,Var,Abs,Vol)   0x85, 0x01,          \/\/   REPORT_ID (1)   0x09, 0x01,          \/\/   USAGE (Vendor Usage 1)   0x91, 0x82,          \/\/   OUTPUT (Data,Var,Abs,Vol)   0xc0               \/\/ END_COLLECTION &gt;;  using HidDesc = HidDescriptor&lt;0x1001, Report&gt;;  using LedsControlEpBase = OutEndpointBase&lt;1, EndpointType::Interrupt, 4, 32&gt;; using EpInitializer = EndpointsInitializer&lt;DefaultEp0, LedsControlEpBase&gt;;  using Ep0 = EpInitializer::ExtendEndpoint&lt;DefaultEp0&gt;; using LedsControlEp = EpInitializer::ExtendEndpoint&lt;LedsControlEpBase&gt;;  using Hid = HidInterface&lt;0, 0, 0, 0, HidDesc, LedsControlEp&gt;; using Config = HidConfiguration&lt;0, 250, false, false, Report, Hid&gt;; using MyDevice = Device&lt;0x0200, DeviceClass::InterfaceSpecified, 0, 0, 0x0483, 0x5711, 0, Ep0, Config&gt;;  using Led = IO::Pc13Inv;  void ConfigureClock(); void ConfigureLeds();  int main() {   ConfigureClock();   ConfigureLeds();    Zhele::IO::Porta::Enable();   MyDevice::Enable();    for(;;)   {   } }  void ConfigureClock() {   PllClock::SelectClockSource(PllClock::ClockSource::External);   PllClock::SetMultiplier(9);   Apb1Clock::SetPrescaler(Apb1Clock::Div2);   SysClock::SelectClockSource(SysClock::Pll);   MyDevice::SelectClockSource(Zhele::Usb::ClockSource::PllDividedOneAndHalf); }  void ConfigureLeds() {   Led::Port::Enable();   Led::SetConfiguration&lt;Led::Configuration::Out&gt;();   Led::SetDriverType&lt;Led::DriverType::PushPull&gt;();   Led::Set(); }  template&lt;&gt; void LedsControlEp::Handler() {   LedsControlEp::ClearCtrRx();   uint8_t* buffer = reinterpret_cast&lt;uint8_t*&gt;(LedsControlEp::Buffer);   bool needSet = buffer[1] != 0;    switch(buffer[0])   {   case 1:     needSet ? Led::Set() : Led::Clear();     break;   }    LedsControlEp::SetRxStatus(EndpointStatus::Valid); }  extern \"C\" void USB_LP_IRQHandler() {   MyDevice::CommonHandler(); }<\/code><\/pre>\n<\/div>\n<\/details>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u041d\u0435 \u0441\u043e\u0432\u0441\u0435\u043c \u043e\u0447\u0435\u0432\u0438\u0434\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u0447\u043d\u043e\u0433\u043e \u043a\u043e\u0434\u0430 (\u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u0437\u0430\u0441\u043b\u0443\u0436\u0435\u043d\u043d\u044b\u0435 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0438 \u0432 \u0441\u0442\u0438\u043b\u0435 &#171;\u041d\u0435 \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0442\u0430\u043a\u043e\u0439 \u043a\u043e\u0434 \u0432 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u043d\u0435&#187;, &#171;\u041a\u0430\u043a \u044d\u0442\u043e \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0442\u044c&#187; \u0438 \u0442.\u043f.) \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b\u0430 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e \u0443\u043f\u0440\u043e\u0441\u0442\u0438\u0442\u044c \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430, \u043d\u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u0430\u0436\u0435 \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b: \u0432\u0441\u0435 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438\u0437 \u043f\u043e\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u044b\u0445 \u0432 \u0448\u0430\u0431\u043b\u043e\u043d\u044b \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 variadic-\u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432 \u043f\u043e\u043c\u043e\u0433\u043b\u043e \u0438\u0437\u0431\u0430\u0432\u0438\u0442\u044c\u0441\u044f \u043e\u0442 \u043b\u0438\u0448\u043d\u0438\u0445 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0435\u0439. \u041f\u0440\u043e\u0448\u0438\u0432\u043a\u0430 \u0442\u043e\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u043c\u043f\u0430\u043a\u0442\u043d\u043e\u0439, \u043a\u043e\u0434 \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u0432\u044b\u0448\u0435 \u0441 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0435\u0439 <em>Og <\/em>\u0432\u044b\u0448\u0435\u043b \u0432 2360 \u0431\u0430\u0439\u0442\u043e\u0432 Flash \u0438 36 \u0431\u0430\u0439\u0442\u043e\u0432 RAM (\u0441 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0435\u0439 <em>Os <\/em>\u043f\u0440\u043e\u0448\u0438\u0432\u043a\u0430 \u0432\u0435\u0441\u0438\u0442 1712 \u0431\u0430\u0439\u0442\u043e\u0432, \u043d\u043e \u043d\u0435 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442. \u041f\u043e\u043a\u0430 \u043d\u0435 \u0440\u0430\u0437\u043e\u0431\u0440\u0430\u043b\u0441\u044f, \u043f\u043e\u0447\u0435\u043c\u0443 \u0438\u043c\u0435\u043d\u043d\u043e), \u0447\u0442\u043e \u044f \u0441\u0447\u0438\u0442\u0430\u044e \u043d\u0435\u043f\u043b\u043e\u0445\u0438\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c.<\/p>\n<h2>\u0411\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u043d\u043e\u0441\u0442\u0438<\/h2>\n<p>\u0417\u0430 \u0437\u0430\u043c\u0435\u0447\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 <a href=\"https:\/\/habr.com\/ru\/post\/208026\/\" rel=\"noopener noreferrer nofollow\">\u043f\u043e\u0441\u0442 <\/a>\u043f\u0440\u043e HID \u0431\u043b\u0430\u0433\u043e\u0434\u0430\u0440\u0435\u043d <a class=\"mention\" href=\"\/users\/raja\">@RaJa<\/a>. \u0422\u0430\u043a\u0436\u0435 \u043c\u0435\u043d\u0435\u0435, \u0447\u0435\u043c \u0437\u0430 \u043d\u0435\u0434\u0435\u043b\u044e \u0434\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f \u044d\u0442\u043e\u0433\u043e \u043f\u043e\u0441\u0442\u0430 \u0432\u044b\u0448\u0435\u043b \u0435\u0449\u0435 \u043a\u0440\u0443\u0442\u043e\u0439 <a href=\"https:\/\/habr.com\/ru\/post\/548150\/\" rel=\"noopener noreferrer nofollow\">\u043c\u0430\u0442\u0435\u0440\u0438\u0430\u043b <\/a>\u043f\u043e HID \u043e\u0442 <a class=\"mention\" href=\"\/users\/cokpoweheu\">@COKPOWEHEU<\/a>. \u0411\u0435\u0437 \u044d\u0442\u0438\u0445 \u043f\u043e\u0441\u0442\u043e\u0432 \u044f \u0431\u044b \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u043e\u0441\u0438\u043b\u0438\u043b. \u0415\u0449\u0435 \u0431\u043e\u043b\u044c\u0448\u0443\u044e \u043f\u043e\u043c\u043e\u0449\u044c \u043e\u043a\u0430\u0437\u0430\u043b\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438 \u0441 \u0444\u043e\u0440\u0443\u043c\u0430 radiokot (COKPOWEHEU \u0438 VladislavS), \u0431\u044b\u043b \u043f\u0440\u0438\u044f\u0442\u043d\u043e \u0443\u0434\u0438\u0432\u043b\u0435\u043d \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u044c\u044e \u043e\u0442\u0432\u0435\u0442\u043e\u0432 \u0438 \u0436\u0435\u043b\u0430\u043d\u0438\u0435\u043c \u043f\u043e\u043c\u043e\u0447\u044c.<\/p>\n<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/549296\/\"> https:\/\/habr.com\/ru\/post\/549296\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text_v2\" id=\"post-content-body\">\n<p>\u0412 <a href=\"https:\/\/habr.com\/ru\/post\/547732\/\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u0448\u043b\u044b\u0439<\/a> \u0440\u0430\u0437 \u043f\u043e\u043a\u0430\u0437\u0430\u043b \u043e\u0434\u0438\u043d \u0438\u0437 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u0432 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c\u0438 \u0442\u043e\u0447\u043a\u0430\u043c\u0438, \u0430 \u0438\u043c\u0435\u043d\u043d\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u043e\u0432 EPnR, \u043f\u0430\u043c\u044f\u0442\u0438 \u043f\u043e\u0434 \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u044b \u0431\u0443\u0444\u0435\u0440\u043e\u0432 \u0438 \u043f\u043e\u0434 \u0441\u0430\u043c\u0438 \u0431\u0443\u0444\u0435\u0440\u044b. \u041f\u0440\u0435\u0434\u043b\u0430\u0433\u0430\u044e \u043f\u0440\u043e\u0434\u043e\u043b\u0436\u0438\u0442\u044c \u043d\u0430\u0447\u0430\u0442\u043e\u0435 \u0438 \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u0443\u044e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e HID-\u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0449\u0435\u0433\u043e \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u0432\u0435\u0442\u043e\u0434\u0438\u043e\u0434\u043e\u043c.<\/p>\n<h2>\u0420\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0435 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f<\/h2>\n<p>\u041a\u0440\u043e\u043c\u0435 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u043d\u044b\u0445 \u0440\u0430\u043d\u0435\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438 \u0442\u0430\u043a\u0436\u0435 \u0434\u0435\u043b\u044f\u0442 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u0435. \u0421\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043e\u0431\u0449\u0438\u0439 (\u0433\u043b\u0430\u0432\u043d\u044b\u0439) \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u0434\u043e\u043b\u0436\u0435\u043d \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0443 \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u043e\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438. \u041d\u043e\u043c\u0435\u0440 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438, \u043a \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u043e\u0431\u0440\u0430\u0449\u0430\u0435\u0442\u0441\u044f \u0445\u043e\u0441\u0442, \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0431\u0438\u0442\u0430\u0445 EP_ID \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430 ISTR. \u041f\u0440\u0438\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044f\u0441\u044c \u043b\u0438\u043d\u0438\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0448\u0430\u0431\u043b\u043e\u043d\u043d\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438, \u043f\u043e\u043b\u0443\u0447\u0438\u043b \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441:<\/p>\n<pre><code class=\"cpp\">using EpRequestHandler = std::add_pointer_t&lt;void()&gt;; template&lt;typename...&gt; class EndpointHandlersBase; template&lt;typename... Endpoints, int8_t... Indexes&gt; class EndpointHandlersBase&lt;TypeList&lt;Endpoints...&gt;, Int8_tArray&lt;Indexes...&gt;&gt; { public:   \/\/ \u041c\u0430\u0441\u0441\u0438\u0432 \u0443\u043a\u0430\u0437\u0430\u0442\u0435\u043b\u0435\u0439 \u043d\u0430 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u0438   static constexpr EpRequestHandler _handlers[] = {Endpoints::Handler...};   \/\/ \u0418\u043d\u0434\u0435\u043a\u0441\u044b \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432   static constexpr int8_t _handlersIndexes[] = {Indexes...}; public:   inline static void Handle(uint8_t number, EndpointDirection direction)   {     _handlers[_handlersIndexes[2 * number + (direction == EndpointDirection::Out ? 1 : 0)]]();   } };<\/code><\/pre>\n<p>\u041a\u043b\u044e\u0447\u0435\u0432\u044b\u043c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u043c \u043a\u043b\u0430\u0441\u0441\u0430 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043c\u0430\u0441\u0441\u0438\u0432 <em>_handlersIndexes<\/em>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0442\u043e\u0431\u0440\u0430\u0436\u0430\u0435\u0442 \u043d\u043e\u043c\u0435\u0440 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0438 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0432 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a. \u0414\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441:<\/p>\n<pre><code class=\"cpp\">template&lt;int8_t Index, typename Endpoints&gt; class EndpointHandlersIndexes {   \/\/ \u041f\u0440\u0435\u0434\u0438\u043a\u0430\u0442 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u043e\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438.   using Predicate = Select&lt;Index % 2 == 0, IsTxOrBidirectionalEndpointWithNumber&lt;Index \/ 2&gt;, IsRxOrBidirectionalEndpointWithNumber&lt;Index \/ 2&gt;&gt;::value;   static const int8_t EndpointIndex = Search&lt;Predicate::template type, Endpoints&gt;::value; public:   \/\/ \u0412 \u043a\u043e\u043d\u0435\u0446 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0432\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u043e\u043c\u0435\u0440 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0435\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0438\u043b\u0438 -1 \u0432 \u0441\u043b\u0443\u0447\u0430\u0435 \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430.   using type = typename Int8_tArray_InsertBack&lt;typename EndpointHandlersIndexes&lt;Index - 1, Endpoints&gt;::type, EndpointIndex&gt;::type; }; template&lt;typename Endpoints&gt; class EndpointHandlersIndexes&lt;-1, Endpoints&gt; { public:   using type = Int8_tArray&lt;&gt;; };<\/code><\/pre>\n<p>\u0418\u0437 \u0442\u0430\u043a\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043a\u0441\u0442\u0430\u0442\u0438, \u0432\u044b\u0442\u0435\u043a\u0430\u0435\u0442 \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0430\u0446\u0438\u044f \u043e\u0431\u044a\u044f\u0432\u043b\u044f\u0442\u044c \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0435 \u0442\u043e\u0447\u043a\u0438 \u0441 \u043d\u043e\u043c\u0435\u0440\u0430\u043c\u0438 \u043f\u043e \u043f\u043e\u0440\u044f\u0434\u043a\u0443, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0440\u0430\u0437\u043c\u0435\u0440 \u043c\u0430\u0441\u0441\u0438\u0432\u0430 \u0438\u043d\u0434\u0435\u043a\u0441\u043e\u0432 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u0432 \u0440\u0430\u0432\u0435\u043d \u0443\u0434\u0432\u043e\u0435\u043d\u043d\u043e\u043c\u0443 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043d\u043e\u043c\u0435\u0440\u0443 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438.<\/p>\n<h2>\u041a\u043b\u0430\u0441\u0441 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438<\/h2>\n<p>\u0418\u0437-\u0437\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c\u0438 \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u0440\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u043a\u043e\u0434 \u043d\u0430 \u0434\u0432\u0430 \u043a\u043b\u0430\u0441\u0441\u0430: \u0431\u0430\u0437\u043e\u0432\u044b\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438 \u043d\u0443\u0436\u043d\u043e \u0438\u043d\u0441\u0442\u0430\u043d\u0446\u0438\u0440\u043e\u0432\u0430\u0442\u044c:<\/p>\n<pre><code class=\"cpp\">template &lt;uint8_t _Number, EndpointDirection _Direction, EndpointType _Type, uint16_t _MaxPacketSize, uint8_t _Interval&gt; class EndpointBase ...<\/code><\/pre>\n<p>\u0410 \u0442\u0430\u043a\u0436\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043d\u043d\u044b\u0439, \u0441 \u0430\u0434\u0440\u0435\u0441\u0430\u043c\u0438 \u0431\u0443\u0444\u0435\u0440\u043e\u0432 \u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430 (\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043d\u0430\u0437\u043d\u0430\u0447\u0430\u044e\u0442\u0441\u044f \u043c\u0435\u043d\u0435\u0434\u0436\u0435\u0440\u043e\u043c, \u043e\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u043c \u0432 \u043f\u0440\u043e\u0448\u043b\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435). \u0418\u0437-\u0437\u0430 \u0440\u0430\u0437\u043b\u0438\u0447\u0438\u0439 \u043c\u0435\u0436\u0434\u0443 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c\u0438 \u0442\u043e\u0447\u043a\u0430\u043c\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0438\u043f\u043e\u0432\/\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0439 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0443 \u043e\u0434\u043d\u043e\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438 \u0442\u0438\u043f\u0430 Interrupt \u0431\u0443\u0434\u0435\u0442 \u043e\u0434\u0438\u043d \u0431\u0443\u0444\u0435\u0440, \u0430 \u0443 \u0434\u0432\u0443\u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043d\u043e\u0439 \u0438\u043b\u0438 Bulk \u0441 \u0434\u0432\u043e\u0439\u043d\u043e\u0439 \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0435\u0439 &#8212; \u0434\u0432\u0430) \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0442\u0438\u043f\u0430 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d \u0441\u0432\u043e\u0439 \u043a\u043b\u0430\u0441\u0441:<\/p>\n<pre><code class=\"cpp\">template &lt;typename _Base, typename _Reg&gt; class Endpoint : public _Base ... template&lt;typename _Base, typename _Reg, uint32_t _TxBufferAddress, uint32_t _TxCountRegAddress, uint32_t _RxBufferAddress, uint32_t _RxCountRegAddress&gt; class BidirectionalEndpoint : public Endpoint&lt;_Base, _Reg&gt; ... template&lt;typename _Base, typename _Reg, uint32_t _Buffer0Address, uint32_t _Count0RegAddress, uint32_t _Buffer1Address, uint32_t _Count1RegAddress&gt; class BulkDoubleBufferedEndpoint : public Endpoint&lt;_Base, _Reg&gt;<\/code><\/pre>\n<p>\u041a\u043e\u043d\u0435\u0447\u043d\u0430\u044f \u0442\u043e\u0447\u043a\u0430 \u043d\u0430 \u0442\u0435\u043a\u0443\u0449\u0438\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u043e\u0439: \u044d\u043a\u0441\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u0442 \u043c\u0435\u0442\u043e\u0434 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 (\u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f \u0440\u0435\u0433\u0438\u0441\u0442\u0440 EPnR), \u043c\u0435\u0442\u043e\u0434 \u0437\u0430\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f \u0434\u0435\u0441\u043a\u0440\u0438\u043f\u0442\u043e\u0440\u0430, \u043c\u0435\u0442\u043e\u0434\u044b \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0431\u0438\u0442\u0430\u043c\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430 (\u041e\u0447\u0438\u0441\u0442\u043a\u0430 \u0431\u0438\u0442\u043e\u0432 <em>CTR_TX\/RX<\/em>, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0431\u0438\u0442\u043e\u0432 <em>TX\/RX_STATUS<\/em>), \u0430 \u0442\u0430\u043a\u0436\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0443 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<h2>\u041a\u043b\u0430\u0441\u0441 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430<\/h2>\n<p>\u0421\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c\u044e \u0432 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u043a\u043e\u0442\u043e\u0440\u044b\u0439, \u043f\u043e \u0441\u0443\u0442\u0438 (\u043a\u0430\u043a \u044f \u043f\u043e\u043d\u0438\u043c\u0430\u044e) \u0435\u0441\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u0445 \u0442\u043e\u0447\u0435\u043a, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044e\u0449\u0438\u0439 \u0435\u0433\u043e \u043a\u043b\u0430\u0441\u0441 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439 (\u043f\u0440\u0438\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u044e \u043a\u043e\u0434 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e, \u043f\u043e\u0442\u043e\u043c\u0443 \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043c\u043e\u0449\u044c variadic-\u0448\u0430\u0431\u043b\u043e\u043d\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u043b \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u043b\u0438\u0448\u043d\u0438\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438):<\/p>\n<pre><code class=\"cpp\">template &lt;uint8_t _Number, uint8_t _AlternateSetting = 0, uint8_t _Class = 0, uint8_t _SubClass = 0, uint8_t _Protocol = 0, typename... _Endpoints&gt; class Interface { public:   using Endpoints = Zhele::TemplateUtils::TypeList&lt;_Endpoints...&gt;;   static const uint8_t EndpointsCount = ((_Endpoints::Direction == EndpointDirection::Bidirectional ? 2 : 1) + ...);    static void Reset()   {     (_Endpoints::Reset(), ...);   }    static uint16_t FillDescriptor(InterfaceDescriptor* descriptor)   {     uint16_t totalLength = sizeof(InterfaceDescriptor);      *descriptor = InterfaceDescriptor {       .Number = _Number,       .AlternateSetting = _AlternateSetting,       .EndpointsCount = EndpointsCount,       .Class = _Class,       .SubClass = _SubClass,       .Protocol = _Protocol     };          EndpointDescriptor* endpointsDescriptors = reinterpret_cast&lt;EndpointDescriptor*&gt;(++descriptor);     totalLength += (_Endpoints::FillDescriptor(endpointsDescriptors++) + ...);      return totalLength;   } };<\/code><\/pre>\n<h2>\u041a\u043b\u0430\u0441\u0441 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438<\/h2>\n<p>\u0422\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043e \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0435\u0441\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440 \u0434\u043b\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u0432. \u0427\u0438\u0442\u0430\u044f \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 USB \u044f \u043f\u043e\u043d\u044f\u043b, \u0447\u0442\u043e \u0432\u0441\u0435 \u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0441\u043b\u043e\u0436\u043d\u0435\u0435 \u0438 \u0445\u043e\u0441\u0442 \u0432\u043f\u0440\u0430\u0432\u0435 \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u0438\/\u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u044b, \u043e\u0434\u043d\u0430\u043a\u043e \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442 \u043d\u0435 \u043e\u0441\u043e\u0437\u043d\u0430\u043b \u0441\u0443\u0442\u0438 \u0438 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e \u043f\u043e\u0434\u043e\u0431\u043d\u044b\u0435 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u044b. \u0412 \u0442\u043e \u0436\u0435 \u0432\u0440\u0435\u043c\u044f \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u044e, \u0447\u0442\u043e \u0434\u043b\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0445\u043e\u0441\u0442\u0430 \u0441 \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f\u043c\u0438 \u0438 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430\u043c\u0438 \u043d\u0443\u0436\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e &#8212; \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0439 \u043a \u043d\u0438\u043c \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0439 \u043a \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c \u0442\u043e\u0447\u043a\u0430\u043c.<\/p>\n<pre><code class=\"cpp\">template &lt;uint8_t _Number, uint8_t _MaxPower, bool _RemoteWakeup = false, bool _SelfPowered = false, typename... _Interfaces&gt; class Configuration { public:   using Endpoints = Zhele::TemplateUtils::Append_t&lt;typename _Interfaces::Endpoints...&gt;;   static void Reset()   {     (_Interfaces::Reset(), ...);   } ...<\/code><\/pre>\n<h2>\u041a\u043b\u0430\u0441\u0441 \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u0430<\/h2>\n<p>\u041d\u0430\u043a\u043e\u043d\u0435\u0446, \u0432 \u0432\u0435\u0440\u0448\u0438\u043d\u0435 \u0438\u0435\u0440\u0430\u0440\u0445\u0438\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0441\u0430\u043c\u043e \u0443\u0441\u0442\u0440\u043e\u0439\u0441\u0442\u0432\u043e. \u0412 \u043c\u043e\u0435\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043a\u043b\u0430\u0441\u0441 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u043d\u044b\u043c \u043e\u0442 \u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043e\u043d\u0430 \u043e\u0441\u043e\u0431\u0430\u044f \u0438 \u043e\u0431\u043c\u0435\u043d \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0441 \u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439 &#8212; \u044d\u0442\u043e \u043e\u0431\u043c\u0435\u043d \u0434\u0430\u043d\u043d\u044b\u043c\u0438 (\u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0443\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0449\u0438\u043c\u0438) \u0441 \u0441\u0430\u043c\u0438\u043c \u0434\u0435\u0432\u0430\u0439\u0441\u043e\u043c.<\/p>\n<pre><code class=\"cpp\">template&lt;   typename _Regs,   IRQn_Type _IRQNumber,   typename _ClockCtrl,    uint16_t _UsbVersion,   DeviceClass _Class,   uint8_t _SubClass,   uint8_t _Protocol,   uint16_t _VendorId,   uint16_t _ProductId,   uint16_t _DeviceReleaseNumber,   typename _Ep0,   typename... _Configurations&gt; class DeviceBase : public _Ep0 {   using This = DeviceBase&lt;_Regs, _IRQNumber, _ClockCtrl, _UsbVersion, _Class, _SubClass, _Protocol, _VendorId, _ProductId, _DeviceReleaseNumber, _Ep0, _Configurations...&gt;;   using Endpoints = Append_t&lt;typename _Configurations::Endpoints...&gt;;   using Configurations = TypeList&lt;_Configurations...&gt;;    \/\/ Replace Ep0 with this for correct handler register.   using EpBufferManager = EndpointsManager&lt;Append_t&lt;_Ep0, Endpoints&gt;&gt;;   using EpHandlers = EndpointHandlers&lt;Append_t&lt;This, Endpoints&gt;&gt;; ...<\/code><\/pre>\n<p>\u041a\u043b\u0430\u0441\u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0433\u043b\u0430\u0432\u043d\u044b\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f, \u0434\u0438\u0441\u043f\u0435\u0442\u0447\u0435\u0440\u0438\u0437\u0443\u044f \u0437\u0430\u043f\u0440\u043e\u0441\u044b \u043f\u043e \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043a\u043e\u043d\u0435\u0447\u043d\u044b\u043c \u0442\u043e\u0447\u043a\u0430\u043c:<\/p>\n<pre><code class=\"cpp\">static void CommonHandler() {   if(_Regs()-&gt;ISTR &amp; USB_ISTR_RESET)   {     Reset();   }   if (_Regs()-&gt;ISTR &amp; USB_ISTR_CTR)   {     uint8_t endpoint = _Regs()-&gt;ISTR &amp; USB_ISTR_EP_ID;     EpHandlers::Handle(endpoint, ((_Regs()-&gt;ISTR &amp; USB_ISTR_DIR) != 0 ? EndpointDirection::Out : EndpointDirection::In));   }   NVIC_ClearPendingIRQ(_IRQNumber); }<\/code><\/pre>\n<p>\u042f\u0432\u043b\u044f\u044f\u0441\u044c \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0438 \u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u043e\u0439, \u043a\u043b\u0430\u0441\u0441 <em>Device <\/em>\u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0439 \u043a \u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u0442\u043e\u0447\u043a\u0435, \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u044f, \u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442, \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u043d\u0443\u043c\u0435\u0440\u0430\u0446\u0438\u0438:<\/p>\n<details class=\"spoiler\">\n<summary>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a \u043f\u0440\u0435\u0440\u044b\u0432\u0430\u043d\u0438\u044f \u043d\u0443\u043b\u0435\u0432\u043e\u0439 \u043a\u043e\u043d\u0435\u0447\u043d\u043e\u0439 \u0442\u043e\u0447\u043a\u0438<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"cpp\">static void Handler() {   if(_Ep0::Reg::Get() &amp; USB_EP_CTR_RX)   {     _Ep0::ClearCtrRx();     if(_Ep0::Reg::Get() &amp; USB_EP_SETUP)     {       SetupPacket* setup = reinterpret_cast&lt;SetupPacket*&gt;(_Ep0::RxBuffer);       switch (setup-&gt;Request) {       case StandartRequestCode::GetStatus: {         uint16_t status = 0;         _Ep0::Writer::SendData(&amp;status, sizeof(status));         break;       }       case StandartRequestCode::SetAddress: {         TempAddressStorage = setup-&gt;Value;         _Ep0::Writer::SendData(0);         break;       }       case StandartRequestCode::GetDescriptor: {         switch (static_cast&lt;GetDescriptorParameter&gt;(setup-&gt;Value)) {         case GetDescriptorParameter::DeviceDescriptor: {           DeviceDescriptor tempDeviceDescriptor;           FillDescriptor(reinterpret_cast&lt;DeviceDescriptor*&gt;(&amp;tempDeviceDescriptor));           _Ep0::Writer::SendData(&amp;tempDeviceDescriptor, setup-&gt;Length &lt; sizeof(DeviceDescriptor) ? setup-&gt;Length : sizeof(DeviceDescriptor));           break;         }         case GetDescriptorParameter::ConfigurationDescriptor: {           uint8_t temp[64];           uint16_t size = GetType&lt;0, Configurations&gt;::type::FillDescriptor(reinterpret_cast&lt;ConfigurationDescriptor*&gt;(&amp;temp[0]));           _Ep0::Writer::SendData(reinterpret_cast&lt;ConfigurationDescriptor*&gt;(&amp;temp[0]), setup-&gt;Length &lt; size ? setup-&gt;Length : size);           break;         }         case GetDescriptorParameter::HidReportDescriptor: {           uint16_t size = sizeof(GetType_t&lt;0, Configurations&gt;::HidReport::Data);           _Ep0::Writer::SendData(GetType_t&lt;0, Configurations&gt;::HidReport::Data, setup-&gt;Length &lt; size ? setup-&gt;Length : size);           break;         }         default:           _Ep0::SetTxStatus(EndpointStatus::Stall);           break;         }         break;       }       case StandartRequestCode::GetConfiguration: {         uint16_t configuration = 0;         _Ep0::Writer::SendData(&amp;configuration, 1);         break;       }       case StandartRequestCode::SetConfiguration: {         _Ep0::Writer::SendData(0);         break;       }       default:         _Ep0::SetTxStatus(EndpointStatus::Stall);         break;       }     }<\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-320394","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/320394","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=320394"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/320394\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=320394"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=320394"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=320394"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}