You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

lufa.c 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. /*
  2. * Copyright 2012 Jun Wako <[email protected]>
  3. * This file is based on:
  4. * LUFA-120219/Demos/Device/Lowlevel/KeyboardMouse
  5. * LUFA-120219/Demos/Device/Lowlevel/GenericHID
  6. */
  7. /*
  8. LUFA Library
  9. Copyright (C) Dean Camera, 2012.
  10. dean [at] fourwalledcubicle [dot] com
  11. www.lufa-lib.org
  12. */
  13. /*
  14. Copyright 2012 Dean Camera (dean [at] fourwalledcubicle [dot] com)
  15. Copyright 2010 Denver Gingerich (denver [at] ossguy [dot] com)
  16. Permission to use, copy, modify, distribute, and sell this
  17. software and its documentation for any purpose is hereby granted
  18. without fee, provided that the above copyright notice appear in
  19. all copies and that both that the copyright notice and this
  20. permission notice and warranty disclaimer appear in supporting
  21. documentation, and that the name of the author not be used in
  22. advertising or publicity pertaining to distribution of the
  23. software without specific, written prior permission.
  24. The author disclaim all warranties with regard to this
  25. software, including all implied warranties of merchantability
  26. and fitness. In no event shall the author be liable for any
  27. special, indirect or consequential damages or any damages
  28. whatsoever resulting from loss of use, data or profits, whether
  29. in an action of contract, negligence or other tortious action,
  30. arising out of or in connection with the use or performance of
  31. this software.
  32. */
  33. #include "report.h"
  34. #include "host.h"
  35. #include "host_driver.h"
  36. #include "keyboard.h"
  37. #include "action.h"
  38. #include "led.h"
  39. #include "sendchar.h"
  40. #include "debug.h"
  41. #ifdef SLEEP_LED_ENABLE
  42. #include "sleep_led.h"
  43. #endif
  44. #include "suspend.h"
  45. #include "hook.h"
  46. #include "descriptor.h"
  47. #include "lufa.h"
  48. uint8_t keyboard_idle = 0;
  49. /* 0: Boot Protocol, 1: Report Protocol(default) */
  50. uint8_t keyboard_protocol = 1;
  51. static uint8_t keyboard_led_stats = 0;
  52. static report_keyboard_t keyboard_report_sent;
  53. /* Host driver */
  54. static uint8_t keyboard_leds(void);
  55. static void send_keyboard(report_keyboard_t *report);
  56. static void send_mouse(report_mouse_t *report);
  57. static void send_system(uint16_t data);
  58. static void send_consumer(uint16_t data);
  59. host_driver_t lufa_driver = {
  60. keyboard_leds,
  61. send_keyboard,
  62. send_mouse,
  63. send_system,
  64. send_consumer
  65. };
  66. /*******************************************************************************
  67. * Console
  68. ******************************************************************************/
  69. #ifdef CONSOLE_ENABLE
  70. static void Console_Task(void)
  71. {
  72. /* Device must be connected and configured for the task to run */
  73. if (USB_DeviceState != DEVICE_STATE_Configured)
  74. return;
  75. uint8_t ep = Endpoint_GetCurrentEndpoint();
  76. #if 0
  77. // TODO: impl receivechar()/recvchar()
  78. Endpoint_SelectEndpoint(CONSOLE_OUT_EPNUM);
  79. /* Check to see if a packet has been sent from the host */
  80. if (Endpoint_IsOUTReceived())
  81. {
  82. /* Check to see if the packet contains data */
  83. if (Endpoint_IsReadWriteAllowed())
  84. {
  85. /* Create a temporary buffer to hold the read in report from the host */
  86. uint8_t ConsoleData[CONSOLE_EPSIZE];
  87. /* Read Console Report Data */
  88. Endpoint_Read_Stream_LE(&ConsoleData, sizeof(ConsoleData), NULL);
  89. /* Process Console Report Data */
  90. //ProcessConsoleHIDReport(ConsoleData);
  91. }
  92. /* Finalize the stream transfer to send the last packet */
  93. Endpoint_ClearOUT();
  94. }
  95. #endif
  96. /* IN packet */
  97. Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM);
  98. if (!Endpoint_IsEnabled() || !Endpoint_IsConfigured()) {
  99. Endpoint_SelectEndpoint(ep);
  100. return;
  101. }
  102. // fill empty bank
  103. while (Endpoint_IsReadWriteAllowed())
  104. Endpoint_Write_8(0);
  105. // flash senchar packet
  106. if (Endpoint_IsINReady()) {
  107. Endpoint_ClearIN();
  108. }
  109. Endpoint_SelectEndpoint(ep);
  110. }
  111. #else
  112. static void Console_Task(void)
  113. {
  114. }
  115. #endif
  116. /*******************************************************************************
  117. * USB Events
  118. ******************************************************************************/
  119. /*
  120. * Event Order of Plug in:
  121. * 0) EVENT_USB_Device_Connect
  122. * 1) EVENT_USB_Device_Suspend
  123. * 2) EVENT_USB_Device_Reset
  124. * 3) EVENT_USB_Device_Wake
  125. */
  126. void EVENT_USB_Device_Connect(void)
  127. {
  128. print("[C]");
  129. /* For battery powered device */
  130. if (!USB_IsInitialized) {
  131. USB_Disable();
  132. USB_Init();
  133. USB_Device_EnableSOFEvents();
  134. }
  135. }
  136. void EVENT_USB_Device_Disconnect(void)
  137. {
  138. print("[D]");
  139. /* For battery powered device */
  140. USB_IsInitialized = false;
  141. /* TODO: This doesn't work. After several plug in/outs can not be enumerated.
  142. if (USB_IsInitialized) {
  143. USB_Disable(); // Disable all interrupts
  144. USB_Controller_Enable();
  145. USB_INT_Enable(USB_INT_VBUSTI);
  146. }
  147. */
  148. }
  149. void EVENT_USB_Device_Reset(void)
  150. {
  151. print("[R]");
  152. }
  153. void EVENT_USB_Device_Suspend()
  154. {
  155. print("[S]");
  156. hook_usb_suspend_entry();
  157. }
  158. void EVENT_USB_Device_WakeUp()
  159. {
  160. print("[W]");
  161. hook_usb_wakeup();
  162. }
  163. #ifdef CONSOLE_ENABLE
  164. static bool console_flush = false;
  165. #define CONSOLE_FLUSH_SET(b) do { \
  166. uint8_t sreg = SREG; cli(); console_flush = b; SREG = sreg; \
  167. } while (0)
  168. // called every 1ms
  169. void EVENT_USB_Device_StartOfFrame(void)
  170. {
  171. static uint8_t count;
  172. if (++count % 50) return;
  173. count = 0;
  174. if (!console_flush) return;
  175. Console_Task();
  176. console_flush = false;
  177. }
  178. #endif
  179. /** Event handler for the USB_ConfigurationChanged event.
  180. * This is fired when the host sets the current configuration of the USB device after enumeration.
  181. *
  182. * ATMega32u2 supports dual bank(ping-pong mode) only on endpoint 3 and 4,
  183. * it is safe to use singl bank for all endpoints.
  184. */
  185. void EVENT_USB_Device_ConfigurationChanged(void)
  186. {
  187. bool ConfigSuccess = true;
  188. /* Setup Keyboard HID Report Endpoints */
  189. ConfigSuccess &= ENDPOINT_CONFIG(KEYBOARD_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
  190. KEYBOARD_EPSIZE, ENDPOINT_BANK_SINGLE);
  191. #ifdef MOUSE_ENABLE
  192. /* Setup Mouse HID Report Endpoint */
  193. ConfigSuccess &= ENDPOINT_CONFIG(MOUSE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
  194. MOUSE_EPSIZE, ENDPOINT_BANK_SINGLE);
  195. #endif
  196. #ifdef EXTRAKEY_ENABLE
  197. /* Setup Extra HID Report Endpoint */
  198. ConfigSuccess &= ENDPOINT_CONFIG(EXTRAKEY_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
  199. EXTRAKEY_EPSIZE, ENDPOINT_BANK_SINGLE);
  200. #endif
  201. #ifdef CONSOLE_ENABLE
  202. /* Setup Console HID Report Endpoints */
  203. ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
  204. CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE);
  205. #if 0
  206. ConfigSuccess &= ENDPOINT_CONFIG(CONSOLE_OUT_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_OUT,
  207. CONSOLE_EPSIZE, ENDPOINT_BANK_SINGLE);
  208. #endif
  209. #endif
  210. #ifdef NKRO_ENABLE
  211. /* Setup NKRO HID Report Endpoints */
  212. ConfigSuccess &= ENDPOINT_CONFIG(NKRO_IN_EPNUM, EP_TYPE_INTERRUPT, ENDPOINT_DIR_IN,
  213. NKRO_EPSIZE, ENDPOINT_BANK_SINGLE);
  214. #endif
  215. }
  216. /*
  217. Appendix G: HID Request Support Requirements
  218. The following table enumerates the requests that need to be supported by various types of HID class devices.
  219. Device type GetReport SetReport GetIdle SetIdle GetProtocol SetProtocol
  220. ------------------------------------------------------------------------------------------
  221. Boot Mouse Required Optional Optional Optional Required Required
  222. Non-Boot Mouse Required Optional Optional Optional Optional Optional
  223. Boot Keyboard Required Optional Required Required Required Required
  224. Non-Boot Keybrd Required Optional Required Required Optional Optional
  225. Other Device Required Optional Optional Optional Optional Optional
  226. */
  227. /** Event handler for the USB_ControlRequest event.
  228. * This is fired before passing along unhandled control requests to the library for processing internally.
  229. */
  230. void EVENT_USB_Device_ControlRequest(void)
  231. {
  232. uint8_t* ReportData = NULL;
  233. uint8_t ReportSize = 0;
  234. /* Handle HID Class specific requests */
  235. switch (USB_ControlRequest.bRequest)
  236. {
  237. case HID_REQ_GetReport:
  238. if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
  239. {
  240. Endpoint_ClearSETUP();
  241. // Interface
  242. switch (USB_ControlRequest.wIndex) {
  243. case KEYBOARD_INTERFACE:
  244. // TODO: test/check
  245. ReportData = (uint8_t*)&keyboard_report_sent;
  246. ReportSize = sizeof(keyboard_report_sent);
  247. break;
  248. }
  249. /* Write the report data to the control endpoint */
  250. Endpoint_Write_Control_Stream_LE(ReportData, ReportSize);
  251. Endpoint_ClearOUT();
  252. }
  253. break;
  254. case HID_REQ_SetReport:
  255. if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
  256. {
  257. // Interface
  258. switch (USB_ControlRequest.wIndex) {
  259. case KEYBOARD_INTERFACE:
  260. #ifdef NKRO_ENABLE
  261. case NKRO_INTERFACE:
  262. #endif
  263. Endpoint_ClearSETUP();
  264. while (!(Endpoint_IsOUTReceived())) {
  265. if (USB_DeviceState == DEVICE_STATE_Unattached)
  266. return;
  267. }
  268. keyboard_led_stats = Endpoint_Read_8();
  269. Endpoint_ClearOUT();
  270. Endpoint_ClearStatusStage();
  271. break;
  272. }
  273. }
  274. break;
  275. case HID_REQ_GetProtocol:
  276. if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
  277. {
  278. if (USB_ControlRequest.wIndex == KEYBOARD_INTERFACE) {
  279. Endpoint_ClearSETUP();
  280. while (!(Endpoint_IsINReady()));
  281. Endpoint_Write_8(keyboard_protocol);
  282. Endpoint_ClearIN();
  283. Endpoint_ClearStatusStage();
  284. }
  285. }
  286. break;
  287. case HID_REQ_SetProtocol:
  288. if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
  289. {
  290. if (USB_ControlRequest.wIndex == KEYBOARD_INTERFACE) {
  291. Endpoint_ClearSETUP();
  292. Endpoint_ClearStatusStage();
  293. keyboard_protocol = (USB_ControlRequest.wValue & 0xFF);
  294. clear_keyboard();
  295. }
  296. }
  297. break;
  298. case HID_REQ_SetIdle:
  299. if (USB_ControlRequest.bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE))
  300. {
  301. Endpoint_ClearSETUP();
  302. Endpoint_ClearStatusStage();
  303. keyboard_idle = ((USB_ControlRequest.wValue & 0xFF00) >> 8);
  304. }
  305. break;
  306. case HID_REQ_GetIdle:
  307. if (USB_ControlRequest.bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE))
  308. {
  309. Endpoint_ClearSETUP();
  310. while (!(Endpoint_IsINReady()));
  311. Endpoint_Write_8(keyboard_idle);
  312. Endpoint_ClearIN();
  313. Endpoint_ClearStatusStage();
  314. }
  315. break;
  316. }
  317. }
  318. /*******************************************************************************
  319. * Host driver
  320. ******************************************************************************/
  321. static uint8_t keyboard_leds(void)
  322. {
  323. return keyboard_led_stats;
  324. }
  325. static void send_keyboard(report_keyboard_t *report)
  326. {
  327. uint8_t timeout = 255;
  328. if (USB_DeviceState != DEVICE_STATE_Configured)
  329. return;
  330. /* Select the Keyboard Report Endpoint */
  331. #ifdef NKRO_ENABLE
  332. if (keyboard_protocol && keyboard_nkro) {
  333. /* Report protocol - NKRO */
  334. Endpoint_SelectEndpoint(NKRO_IN_EPNUM);
  335. /* Check if write ready for a polling interval around 1ms */
  336. while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(4);
  337. if (!Endpoint_IsReadWriteAllowed()) return;
  338. /* Write Keyboard Report Data */
  339. Endpoint_Write_Stream_LE(report, NKRO_EPSIZE, NULL);
  340. }
  341. else
  342. #endif
  343. {
  344. /* Boot protocol */
  345. Endpoint_SelectEndpoint(KEYBOARD_IN_EPNUM);
  346. /* Check if write ready for a polling interval around 10ms */
  347. while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40);
  348. if (!Endpoint_IsReadWriteAllowed()) return;
  349. /* Write Keyboard Report Data */
  350. Endpoint_Write_Stream_LE(report, KEYBOARD_EPSIZE, NULL);
  351. }
  352. /* Finalize the stream transfer to send the last packet */
  353. Endpoint_ClearIN();
  354. keyboard_report_sent = *report;
  355. }
  356. static void send_mouse(report_mouse_t *report)
  357. {
  358. #ifdef MOUSE_ENABLE
  359. uint8_t timeout = 255;
  360. if (USB_DeviceState != DEVICE_STATE_Configured)
  361. return;
  362. /* Select the Mouse Report Endpoint */
  363. Endpoint_SelectEndpoint(MOUSE_IN_EPNUM);
  364. /* Check if write ready for a polling interval around 10ms */
  365. while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40);
  366. if (!Endpoint_IsReadWriteAllowed()) return;
  367. /* Write Mouse Report Data */
  368. Endpoint_Write_Stream_LE(report, sizeof(report_mouse_t), NULL);
  369. /* Finalize the stream transfer to send the last packet */
  370. Endpoint_ClearIN();
  371. #endif
  372. }
  373. static void send_system(uint16_t data)
  374. {
  375. uint8_t timeout = 255;
  376. if (USB_DeviceState != DEVICE_STATE_Configured)
  377. return;
  378. report_extra_t r = {
  379. .report_id = REPORT_ID_SYSTEM,
  380. .usage = data
  381. };
  382. Endpoint_SelectEndpoint(EXTRAKEY_IN_EPNUM);
  383. /* Check if write ready for a polling interval around 10ms */
  384. while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40);
  385. if (!Endpoint_IsReadWriteAllowed()) return;
  386. Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL);
  387. Endpoint_ClearIN();
  388. }
  389. static void send_consumer(uint16_t data)
  390. {
  391. uint8_t timeout = 255;
  392. if (USB_DeviceState != DEVICE_STATE_Configured)
  393. return;
  394. report_extra_t r = {
  395. .report_id = REPORT_ID_CONSUMER,
  396. .usage = data
  397. };
  398. Endpoint_SelectEndpoint(EXTRAKEY_IN_EPNUM);
  399. /* Check if write ready for a polling interval around 10ms */
  400. while (timeout-- && !Endpoint_IsReadWriteAllowed()) _delay_us(40);
  401. if (!Endpoint_IsReadWriteAllowed()) return;
  402. Endpoint_Write_Stream_LE(&r, sizeof(report_extra_t), NULL);
  403. Endpoint_ClearIN();
  404. }
  405. /*******************************************************************************
  406. * sendchar
  407. ******************************************************************************/
  408. #ifdef CONSOLE_ENABLE
  409. #define SEND_TIMEOUT 5
  410. int8_t sendchar(uint8_t c)
  411. {
  412. // Not wait once timeouted.
  413. // Because sendchar() is called so many times, waiting each call causes big lag.
  414. static bool timeouted = false;
  415. // prevents Console_Task() from running during sendchar() runs.
  416. // or char will be lost. These two function is mutually exclusive.
  417. CONSOLE_FLUSH_SET(false);
  418. if (USB_DeviceState != DEVICE_STATE_Configured)
  419. return -1;
  420. uint8_t ep = Endpoint_GetCurrentEndpoint();
  421. Endpoint_SelectEndpoint(CONSOLE_IN_EPNUM);
  422. if (!Endpoint_IsEnabled() || !Endpoint_IsConfigured()) {
  423. goto ERROR_EXIT;
  424. }
  425. if (timeouted && !Endpoint_IsReadWriteAllowed()) {
  426. goto ERROR_EXIT;
  427. }
  428. timeouted = false;
  429. uint8_t timeout = SEND_TIMEOUT;
  430. while (!Endpoint_IsReadWriteAllowed()) {
  431. if (USB_DeviceState != DEVICE_STATE_Configured) {
  432. goto ERROR_EXIT;
  433. }
  434. if (Endpoint_IsStalled()) {
  435. goto ERROR_EXIT;
  436. }
  437. if (!(timeout--)) {
  438. timeouted = true;
  439. goto ERROR_EXIT;
  440. }
  441. _delay_ms(1);
  442. }
  443. Endpoint_Write_8(c);
  444. // send when bank is full
  445. if (!Endpoint_IsReadWriteAllowed()) {
  446. while (!(Endpoint_IsINReady()));
  447. Endpoint_ClearIN();
  448. } else {
  449. CONSOLE_FLUSH_SET(true);
  450. }
  451. Endpoint_SelectEndpoint(ep);
  452. return 0;
  453. ERROR_EXIT:
  454. Endpoint_SelectEndpoint(ep);
  455. return -1;
  456. }
  457. #else
  458. int8_t sendchar(uint8_t c)
  459. {
  460. return 0;
  461. }
  462. #endif
  463. /*******************************************************************************
  464. * main
  465. ******************************************************************************/
  466. static void setup_mcu(void)
  467. {
  468. /* Disable watchdog if enabled by bootloader/fuses */
  469. MCUSR &= ~(1 << WDRF);
  470. wdt_disable();
  471. /* Disable clock division */
  472. clock_prescale_set(clock_div_1);
  473. }
  474. static void setup_usb(void)
  475. {
  476. // Leonardo needs. Without this USB device is not recognized.
  477. USB_Disable();
  478. USB_Init();
  479. // for Console_Task
  480. USB_Device_EnableSOFEvents();
  481. print_set_sendchar(sendchar);
  482. }
  483. int main(void) __attribute__ ((weak));
  484. int main(void)
  485. {
  486. setup_mcu();
  487. hook_early_init();
  488. keyboard_setup();
  489. setup_usb();
  490. sei();
  491. /* wait for USB startup & debug output */
  492. while (USB_DeviceState != DEVICE_STATE_Configured) {
  493. #if defined(INTERRUPT_CONTROL_ENDPOINT)
  494. ;
  495. #else
  496. USB_USBTask();
  497. #endif
  498. }
  499. print("USB configured.\n");
  500. /* init modules */
  501. keyboard_init();
  502. host_set_driver(&lufa_driver);
  503. #ifdef SLEEP_LED_ENABLE
  504. sleep_led_init();
  505. #endif
  506. print("Keyboard start.\n");
  507. hook_late_init();
  508. while (1) {
  509. while (USB_DeviceState == DEVICE_STATE_Suspended) {
  510. print("[s]");
  511. hook_usb_suspend_loop();
  512. }
  513. keyboard_task();
  514. #if !defined(INTERRUPT_CONTROL_ENDPOINT)
  515. USB_USBTask();
  516. #endif
  517. }
  518. }
  519. /* hooks */
  520. __attribute__((weak))
  521. void hook_early_init(void) {}
  522. __attribute__((weak))
  523. void hook_late_init(void) {}
  524. __attribute__((weak))
  525. void hook_usb_suspend_entry(void)
  526. {
  527. #ifdef SLEEP_LED_ENABLE
  528. sleep_led_enable();
  529. #endif
  530. }
  531. __attribute__((weak))
  532. void hook_usb_suspend_loop(void)
  533. {
  534. suspend_power_down();
  535. if (USB_Device_RemoteWakeupEnabled && suspend_wakeup_condition()) {
  536. USB_Device_SendRemoteWakeup();
  537. }
  538. }
  539. __attribute__((weak))
  540. void hook_usb_wakeup(void)
  541. {
  542. suspend_wakeup_init();
  543. #ifdef SLEEP_LED_ENABLE
  544. sleep_led_disable();
  545. // NOTE: converters may not accept this
  546. led_set(host_keyboard_leds());
  547. #endif
  548. }