flipper-gblink 455 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. commit ecce5b6363adb067cef424eab09fead2f038baf5
  2. Author: Kris Bahnsen <Kris@KBEmbedded.com>
  3. Date: Fri Nov 8 19:20:53 2024 -0800
  4. gblink_pinconf: add save/load configurations and helper funcs
  5. The pin get/set functions have _by_gpiopin and _by_pinnum variants
  6. with macros linking the original functions to _by_gpiopin
  7. Signed-off-by: Kris Bahnsen <Kris@KBEmbedded.com>
  8. diff --git a/gblink/gblink_pinconf.c b/gblink/gblink_pinconf.c
  9. index 83e7ef206..abb5766cd 100644
  10. --- a/gblink/gblink_pinconf.c
  11. +++ b/gblink/gblink_pinconf.c
  12. @@ -2,13 +2,26 @@
  13. // Copyright (c) 2023 KBEmbedded
  14. #include <furi.h>
  15. -#include <furi_hal.h>
  16. +#include <storage/storage.h>
  17. +#include <lib/toolbox/stream/stream.h>
  18. +#include <lib/flipper_format/flipper_format.h>
  19. #include <stdint.h>
  20. #include <gblink/include/gblink.h>
  21. #include "gblink_i.h"
  22. +#define PINCONF_FILE_TYPE "Flipper GB Link Pinconf"
  23. +#define PINCONF_FILE_VER 1
  24. +
  25. +#define PINCONF_ORIG "Original"
  26. +#define PINCONF_MLVK "MLVK2.5"
  27. +#define PINCONF_CUST "Custom"
  28. +
  29. +#define PINCONF_SI "SI"
  30. +#define PINCONF_SO "SO"
  31. +#define PINCONF_CLK "CLK"
  32. +
  33. struct gblink_pins {
  34. const GpioPin *serin;
  35. const GpioPin *serout;
  36. @@ -33,13 +46,14 @@ const struct gblink_pins common_pinouts[PINOUT_COUNT] = {
  37. },
  38. };
  39. -int gblink_pin_set(void *handle, gblink_bus_pins pin, const GpioPin *gpio)
  40. +
  41. +int gblink_pin_set_by_gpiopin(void *handle, gblink_bus_pins pin, const GpioPin *gpio)
  42. {
  43. furi_assert(handle);
  44. struct gblink *gblink = handle;
  45. if (furi_mutex_acquire(gblink->start_mutex, 0) != FuriStatusOk)
  46. - return 1;
  47. + return -1;
  48. switch (pin) {
  49. case PIN_SERIN:
  50. @@ -64,7 +78,7 @@ int gblink_pin_set(void *handle, gblink_bus_pins pin, const GpioPin *gpio)
  51. return 0;
  52. }
  53. -const GpioPin *gblink_pin_get(void *handle, gblink_bus_pins pin)
  54. +const GpioPin *gblink_pin_get_by_gpiopin(void *handle, gblink_bus_pins pin)
  55. {
  56. furi_assert(handle);
  57. struct gblink *gblink = handle;
  58. @@ -91,8 +105,11 @@ int gblink_pin_set_default(void *handle, gblink_pinouts pinout)
  59. furi_assert(handle);
  60. struct gblink *gblink = handle;
  61. + if (pinout == PINOUT_CUSTOM || pinout >= PINOUT_COUNT)
  62. + return -1;
  63. +
  64. if (furi_mutex_acquire(gblink->start_mutex, 0) != FuriStatusOk)
  65. - return 1;
  66. + return -1;
  67. gblink->serin = common_pinouts[pinout].serin;
  68. gblink->serout = common_pinouts[pinout].serout;
  69. @@ -127,3 +144,281 @@ int gblink_pin_get_default(void *handle)
  70. return i;
  71. }
  72. +
  73. +int gblink_pin_set(void *handle, gblink_bus_pins pin, unsigned int pinnum)
  74. +{
  75. + furi_assert(handle);
  76. + furi_assert(pinnum < gpio_pins_count);
  77. +
  78. + struct gblink *gblink = handle;
  79. +
  80. + if (furi_mutex_acquire(gblink->start_mutex, 0) != FuriStatusOk)
  81. + return -1;
  82. +
  83. + switch (pin) {
  84. + case PIN_SERIN:
  85. + gblink->serin = gpio_pins[pinnum].pin;
  86. + break;
  87. + case PIN_SEROUT:
  88. + gblink->serout = gpio_pins[pinnum].pin;
  89. + break;
  90. + case PIN_CLK:
  91. + gblink->clk = gpio_pins[pinnum].pin;
  92. + break;
  93. + case PIN_SD:
  94. + gblink->sd = gpio_pins[pinnum].pin;
  95. + break;
  96. + default:
  97. + furi_crash();
  98. + break;
  99. + }
  100. +
  101. + furi_mutex_release(gblink->start_mutex);
  102. +
  103. + return 0;
  104. +}
  105. +
  106. +int gblink_pin_get(void *handle, gblink_bus_pins pin)
  107. +{
  108. + furi_assert(handle);
  109. + struct gblink *gblink = handle;
  110. + unsigned int i;
  111. +
  112. + for (i = 0; i < gpio_pins_count; i++) {
  113. + switch (pin) {
  114. + case PIN_SERIN:
  115. + if (gpio_pins[i].pin == gblink->serin)
  116. + return i;
  117. + break;
  118. + case PIN_SEROUT:
  119. + if (gpio_pins[i].pin == gblink->serout)
  120. + return i;
  121. + break;
  122. + case PIN_CLK:
  123. + if (gpio_pins[i].pin == gblink->clk)
  124. + return i;
  125. + break;
  126. + case PIN_SD:
  127. + if (gpio_pins[i].pin == gblink->sd)
  128. + return i;
  129. + break;
  130. + default:
  131. + furi_crash();
  132. + break;
  133. + }
  134. + }
  135. +
  136. + return -1;
  137. +}
  138. +
  139. +int gblink_pin_count_max(void)
  140. +{
  141. + unsigned int i;
  142. + int count = 0;
  143. +
  144. + for (i = 0; i < gpio_pins_count; i++)
  145. + if (!gpio_pins[i].debug)
  146. + count = i;
  147. +
  148. + return count;
  149. +}
  150. +
  151. +int gblink_pin_get_next(unsigned int pinnum)
  152. +{
  153. + unsigned int i;
  154. +
  155. + /* The check could be eliminated and just rely on the return -1 at the
  156. + * end of the function, but this is a shortcut so we don't have to walk
  157. + * through the whole table just to find out its an out-of-bounds pin.
  158. + */
  159. + if (pinnum >= gpio_pins_count)
  160. + return -1;
  161. +
  162. + for (i = pinnum; i < gpio_pins_count; i++)
  163. + if (!gpio_pins[i].debug)
  164. + return i;
  165. +
  166. + return -1;
  167. +}
  168. +
  169. +int gblink_pin_get_prev(unsigned int pinnum)
  170. +{
  171. + int i;
  172. +
  173. + /* The check could be eliminated and just rely on the return -1 at the
  174. + * end of the function, but this is a shortcut so we don't have to walk
  175. + * through the whole table just to find out its an out-of-bounds pin.
  176. + */
  177. + if (pinnum >= gpio_pins_count)
  178. + return -1;
  179. +
  180. + for (i = pinnum; i >= 0; i--)
  181. + if (!gpio_pins[i].debug)
  182. + return i;
  183. +
  184. + return -1;
  185. +}
  186. +
  187. +bool gblink_pinconf_load(void *gblink)
  188. +{
  189. +
  190. + Storage *storage = NULL;;
  191. + FlipperFormat *data_file = NULL;
  192. + FuriString *string = NULL;
  193. + uint32_t val;
  194. + bool ret = false;
  195. +
  196. + storage = furi_record_open(RECORD_STORAGE);
  197. +
  198. + string = furi_string_alloc_set(APP_DATA_PATH(""));
  199. + storage_common_resolve_path_and_ensure_app_directory(storage, string);
  200. + furi_string_cat_str(string, ".gblink_pinconf");
  201. +
  202. + data_file = flipper_format_file_alloc(storage);
  203. +
  204. + if (!flipper_format_file_open_existing(data_file, furi_string_get_cstr(string))) {
  205. + FURI_LOG_E("pinconf", "Error opening file %s", furi_string_get_cstr(string));
  206. + goto out;
  207. + }
  208. +
  209. + if (!flipper_format_read_header(data_file, string, &val)) {
  210. + FURI_LOG_E("pinconf", "Missing or incorrect header");
  211. + goto out;
  212. + }
  213. +
  214. + if (strncmp(furi_string_get_cstr(string), PINCONF_FILE_TYPE, strlen(PINCONF_FILE_TYPE)) ||
  215. + val != PINCONF_FILE_VER) {
  216. + FURI_LOG_E("pinconf", "Type or version mismatch");
  217. + goto out;
  218. + }
  219. +
  220. + if (!flipper_format_read_string(data_file, "Mode", string)) {
  221. + FURI_LOG_E("pinconf", "Missing Mode");
  222. + goto out;
  223. + }
  224. +
  225. + if (!strncmp(furi_string_get_cstr(string), PINCONF_ORIG, strlen(PINCONF_ORIG))) {
  226. + FURI_LOG_I("pinconf", "Setting Original pinout");
  227. + gblink_pin_set_default(gblink, PINOUT_ORIGINAL);
  228. + goto out;
  229. + }
  230. +
  231. + if (!strncmp(furi_string_get_cstr(string), PINCONF_MLVK, strlen(PINCONF_MLVK))) {
  232. + FURI_LOG_I("pinconf", "Setting MALVEKE 2.5 pinout");
  233. + gblink_pin_set_default(gblink, PINOUT_MALVEKE_EXT1);
  234. + goto out;
  235. + }
  236. +
  237. + if (!strncmp(furi_string_get_cstr(string), PINCONF_CUST, strlen(PINCONF_CUST))) {
  238. + FURI_LOG_I("pinconf", "Setting Custom pinout");
  239. + }
  240. +
  241. + if (!flipper_format_read_uint32(data_file, PINCONF_SI, &val, 1)) {
  242. + FURI_LOG_E("pinconf", "Missing SI");
  243. + goto out;
  244. + } else {
  245. + gblink_pin_set(gblink, PIN_SERIN, val);
  246. + }
  247. +
  248. + if (!flipper_format_read_uint32(data_file, PINCONF_SO, &val, 1)) {
  249. + FURI_LOG_E("pinconf", "Missing SO");
  250. + goto out;
  251. + } else {
  252. + gblink_pin_set(gblink, PIN_SEROUT, val);
  253. + }
  254. +
  255. + if (!flipper_format_read_uint32(data_file, PINCONF_CLK, &val, 1)) {
  256. + FURI_LOG_E("pinconf", "Missing CLK");
  257. + goto out;
  258. + } else {
  259. + gblink_pin_set(gblink, PIN_CLK, val);
  260. + }
  261. +
  262. + ret = true;
  263. +
  264. +out:
  265. + flipper_format_file_close(data_file);
  266. + furi_string_free(string);
  267. + furi_record_close(RECORD_STORAGE);
  268. + return ret;
  269. +}
  270. +
  271. +/* XXX: TODO: I think there is a way to build this ahead of time and
  272. + * write it in one go to be a bit more time efficient.
  273. + */
  274. +bool gblink_pinconf_save(void *gblink)
  275. +{
  276. +
  277. + Storage *storage = NULL;;
  278. + FlipperFormat *data_file = NULL;
  279. + FuriString *string = NULL;
  280. + int rc;
  281. + uint32_t pin;
  282. + bool ret = false;
  283. +
  284. + storage = furi_record_open(RECORD_STORAGE);
  285. +
  286. + string = furi_string_alloc_set(APP_DATA_PATH(""));
  287. + storage_common_resolve_path_and_ensure_app_directory(storage, string);
  288. + furi_string_cat_str(string, ".gblink_pinconf");
  289. +
  290. + data_file = flipper_format_file_alloc(storage);
  291. +
  292. + if (!flipper_format_file_open_always(data_file, furi_string_get_cstr(string))) {
  293. + FURI_LOG_E("pinconf", "Error opening file %s", furi_string_get_cstr(string));
  294. + goto out;
  295. + }
  296. +
  297. + if (!flipper_format_write_header_cstr(data_file, PINCONF_FILE_TYPE, PINCONF_FILE_VER)) {
  298. + FURI_LOG_E("pinconf", "Error writing header to file");
  299. + goto out;
  300. + }
  301. +
  302. + rc = gblink_pin_get_default(gblink);
  303. + switch (rc) {
  304. + case 0:
  305. + if (!flipper_format_write_string_cstr(data_file, "Mode", PINCONF_ORIG))
  306. + FURI_LOG_E("pinconf", "Error writing mode to file");
  307. + goto out;
  308. + break;
  309. + case 1:
  310. + if (!flipper_format_write_string_cstr(data_file, "Mode", PINCONF_MLVK))
  311. + FURI_LOG_E("pinconf", "Error writing mode to file");
  312. + goto out;
  313. + break;
  314. + case -1:
  315. + if (!flipper_format_write_string_cstr(data_file, "Mode", PINCONF_CUST))
  316. + FURI_LOG_E("pinconf", "Error writing mode to file");
  317. + break;
  318. + default:
  319. + FURI_LOG_E("pinconf", "Unknown mode");
  320. + goto out;
  321. + break;
  322. + }
  323. +
  324. + pin = gblink_pin_get(gblink, PIN_SERIN);
  325. + if (!flipper_format_write_uint32(data_file, "SI", &pin, 1)) {
  326. + FURI_LOG_E("pinconf", "Error writing SI to file");
  327. + goto out;
  328. + }
  329. +
  330. + pin = gblink_pin_get(gblink, PIN_SEROUT);
  331. + if (!flipper_format_write_uint32(data_file, "SO", &pin, 1)) {
  332. + FURI_LOG_E("pinconf", "Error writing SO to file");
  333. + goto out;
  334. + }
  335. +
  336. + pin = gblink_pin_get(gblink, PIN_CLK);
  337. + if (!flipper_format_write_uint32(data_file, "CLK", &pin, 1)) {
  338. + FURI_LOG_E("pinconf", "Error writing CLK to file");
  339. + }
  340. +
  341. + ret = true;
  342. +
  343. +out:
  344. + flipper_format_file_close(data_file);
  345. + furi_string_free(string);
  346. + furi_record_close(RECORD_STORAGE);
  347. + return ret;
  348. +}
  349. +
  350. diff --git a/gblink/include/gblink.h b/gblink/include/gblink.h
  351. index d60fa49fb..eb714872c 100644
  352. --- a/gblink/include/gblink.h
  353. +++ b/gblink/include/gblink.h
  354. @@ -49,7 +49,8 @@ typedef enum {
  355. } gblink_speed;
  356. typedef enum {
  357. - PINOUT_ORIGINAL,
  358. + PINOUT_CUSTOM = -1,
  359. + PINOUT_ORIGINAL = 0,
  360. PINOUT_MALVEKE_EXT1,
  361. PINOUT_COUNT,
  362. } gblink_pinouts;
  363. diff --git a/gblink/include/gblink_pinconf.h b/gblink/include/gblink_pinconf.h
  364. index eb264abbf..3be45571d 100644
  365. --- a/gblink/include/gblink_pinconf.h
  366. +++ b/gblink/include/gblink_pinconf.h
  367. @@ -21,7 +21,7 @@ extern "C" {
  368. *
  369. * @note The gblink instance must not be gblink_start()'ed!
  370. *
  371. - * @returns 0 on success, 1 if gblink instance is not gblink_stop()'ed.
  372. + * @returns 0 on success, -1 if gblink instance is not gblink_stop()'ed.
  373. */
  374. int gblink_pin_set_default(void *handle, gblink_pinouts pinout);
  375. @@ -35,27 +35,115 @@ int gblink_pin_set_default(void *handle, gblink_pinouts pinout);
  376. int gblink_pin_get_default(void *handle);
  377. /**
  378. - * Set a gpio pin to a specific pin mode
  379. + * Set a GPIO pin to a specific pin mode for the EXT interface
  380. + *
  381. + * @param handle Pointer to gblink handle
  382. + * @param pin Pin mode to assign to the gpio pin
  383. + * @param pinnum GPIO pin number to assign pin mode to
  384. + *
  385. + * @note The gblink instance must not be gblink_start()'ed!
  386. + *
  387. + * @returns 0 on success, -1 if gblink instance is not gblink_stop()ed
  388. + */
  389. +int gblink_pin_set(void *handle, gblink_bus_pins pin, unsigned int pinum);
  390. +
  391. +/**
  392. + * Get the pin number associated with the requested pin mode
  393. + *
  394. + *
  395. + * @param handle Pointer to gblink handle
  396. + * @param pin Pin mode to inquire about
  397. + *
  398. + * @returns Pin number of the requested pin or -1 on error
  399. + */
  400. +int gblink_pin_get(void *handle, gblink_bus_pins pin);
  401. +
  402. +/**
  403. + * Set a gpio pin to a specific pin mode via GpioPin
  404. *
  405. * @param handle Pointer to gblink handle
  406. * @param pin Pin mode to assign to the gpio pin
  407. * @param gpio Which gpio pin to assign the pin mode
  408. *
  409. * @note The gblink instance must not be gblink_start()'ed!
  410. + * @note There is no sane way to do bounds checking with this function, so be
  411. + * careful when passing pointers to ensure they are actually Flipper GpioPin
  412. + * references.
  413. *
  414. - * @returns 0 on success, 1 if gblink instance is not gblink_stop()'ed.
  415. + * @returns 0 on success, -1 if gblink instance is not gblink_stop()'ed.
  416. */
  417. -int gblink_pin_set(void *handle, gblink_bus_pins pin, const GpioPin *gpio);
  418. +int gblink_pin_set_by_gpiopin(void *handle, gblink_bus_pins pin, const GpioPin *gpio);
  419. /**
  420. - * Get the gpio pin associated with the requested pin mode
  421. + * Get the GpioPin associated with the requested pin mode
  422. *
  423. * @param handle Pointer to gblink handle
  424. * @param pin Pin mode to inquire about
  425. *
  426. * @returns GpioPin pointer
  427. */
  428. -const GpioPin *gblink_pin_get(void *handle, gblink_bus_pins pin);
  429. +const GpioPin *gblink_pin_get_by_gpiopin(void *handle, gblink_bus_pins pin);
  430. +
  431. +/**
  432. + * Returns the pinnum of the highest usable, non-debug pin.
  433. + *
  434. + * @returns count of highest usable, non-debug pin or -1 on error
  435. + */
  436. +int gblink_pin_count_max(void);
  437. +
  438. +/**
  439. + * Get the next usable, non-debug GPIO pin by number.
  440. + *
  441. + * The return value is the next usable, non-debug pin starting from pinnum and
  442. + * will include pinnum if it is a valid pin.
  443. + *
  444. + * @param pinnum GPIO pin number to check if it is a valid pin.
  445. + *
  446. + * @returns -1 on error or no more valid pins. Any other value is the next usable
  447. + * pin which can include pinnum if it is usable. If pinnum is not usable, the next
  448. + * numbered pin which is will be returned or -1 if there are no further pins.
  449. + */
  450. +int gblink_pin_get_next(unsigned int pinnum);
  451. +
  452. +/**
  453. + * Get the previous usable, non-debug GPIO pin by number.
  454. + *
  455. + * The return value is the previous usable, non-debug pin starting from pinnum and
  456. + * will include pinnum if it is a valid pin.
  457. + *
  458. + * @param pinnum GPIO pin number to check if it is a valid pin.
  459. + *
  460. + * @returns -1 on error or no more valid pins. Any other value is the previous usable
  461. + * pin which can include pinnum if it is usable. If pinnum is not usable, the previous
  462. + * numbered pin which is will be returned or -1 if there are no further pins.
  463. + */
  464. +int gblink_pin_get_prev(unsigned int pinnum);
  465. +
  466. +/**
  467. + * Load pin configuration from file automatically
  468. + * Loads from .gblink_pinconf in app data folder
  469. + *
  470. + * @param gblink Pointer to gblink instance to set pins configurations
  471. + *
  472. + * @returns true on success, false on error
  473. + *
  474. + * @note This function should be called from the context of the application and
  475. + * not any other threads as it uses the app data folder to load data from
  476. + */
  477. +bool gblink_pinconf_load(void *gblink);
  478. +
  479. +/**
  480. + * Save current pin configuration to file automatically
  481. + * Saves to .gblink_pinconf in app data folder
  482. + *
  483. + * @param gblink Pointer to gblink instance to save pins configurations
  484. + *
  485. + * @returns true on success, false on error
  486. + *
  487. + * @note This function should be called from the context of the application and
  488. + * not any other threads as it uses the app data folder to save data to.
  489. + */
  490. +bool gblink_pinconf_save(void *gblink);
  491. #ifdef __cplusplus
  492. }
  493. diff --git a/protocols/printer/include/printer_proto.h b/protocols/printer/include/printer_proto.h
  494. index 9124b2fcb..094c7295f 100644
  495. --- a/protocols/printer/include/printer_proto.h
  496. +++ b/protocols/printer/include/printer_proto.h
  497. @@ -91,50 +91,27 @@ void printer_callback_context_set(void *printer_handle, void *context);
  498. */
  499. void printer_callback_set(void *printer_handle, void (*callback)(void *context, struct gb_image *image, enum cb_reason reason));
  500. -/* Can only be run after alloc, before start */
  501. /**
  502. - * Set one of the pre-configured pinouts
  503. - *
  504. - * @param printer_handle Printer instance handle
  505. - * @param pinout Which pinout to use
  506. - *
  507. - * @note The printer instance must not be actively sending or receiving
  508. - *
  509. - * @returns 0 on success, 1 if gblink instance is not gblink_stop()'ed.
  510. - */
  511. -int printer_pin_set_default(void *printer_handle, gblink_pinouts pinout);
  512. -
  513. -/**
  514. - * Set a gpio pin to a specific pin mode
  515. - *
  516. - * @param printer_handle Printer instance handle
  517. - * @param pin Pin mode to assign to the gpio pin
  518. - * @param gpio Which gpio pin to assign the pin mode
  519. - *
  520. - * @note The printer instance must not be actively sending or receiving
  521. + * Stop a printer instance
  522. *
  523. - * @returns 0 on success, 1 if gblink instance is not gblink_stop()'ed.
  524. - */
  525. -int printer_pin_set(void *printer_handle, gblink_bus_pins pin, const GpioPin *gpio);
  526. -
  527. -/**
  528. - * Get the gpio pin associated with the requested pin mode
  529. + * Disables interrupts, stops any pending timers, and enters back to an idle
  530. + * state. Once called, re-allows changes to be made.
  531. *
  532. * @param printer_handle Printer instance handle
  533. - * @param pin Pin mode to inquire about
  534. - *
  535. - * @returns GpioPin pointer
  536. */
  537. -const GpioPin *printer_pin_get(void *printer_handle, gblink_bus_pins pin);
  538. +void printer_stop(void *printer_handle);
  539. /**
  540. - * Stop a printer instance
  541. + * Get the gblink handle associated with the printer instance.
  542. *
  543. - * Disables interrupts, stops any pending timers, and enters back to an idle
  544. - * state. Once called, re-allows changes to be made.
  545. + * @warning It is not recommended to use this to change any gblink variables other
  546. + * than pin settings! Changing any other settings such as mode, speed, timeout,
  547. + * callback, etc., can break printer communication.
  548. *
  549. * @param printer_handle Printer instance handle
  550. + *
  551. + * @returns Pointer that can be used with gblink calls directly
  552. */
  553. -void printer_stop(void *printer_handle);
  554. +void *printer_gblink_handle_get(void *printer_handle);
  555. #endif // PRINTER_PROTO_H
  556. diff --git a/protocols/printer/printer_proto.c b/protocols/printer/printer_proto.c
  557. index 9430c6d3a..374ae601b 100644
  558. --- a/protocols/printer/printer_proto.c
  559. +++ b/protocols/printer/printer_proto.c
  560. @@ -4,6 +4,7 @@
  561. #include <furi.h>
  562. #include <gblink/include/gblink.h>
  563. +#include <gblink/include/gblink_pinconf.h>
  564. #include <protocols/printer/include/printer_proto.h>
  565. #include "printer_i.h"
  566. @@ -54,6 +55,7 @@ void *printer_alloc(void)
  567. printer->image = malloc(sizeof(struct gb_image));
  568. printer->gblink_handle = gblink_alloc();
  569. + gblink_pinconf_load(printer->gblink_handle);
  570. /* Set up some settings for the print protocol. The final send/receive() calls
  571. * may clobber some of these, but that is intentional and they don't need to
  572. @@ -96,25 +98,13 @@ void printer_callback_set(void *printer_handle, void (*callback)(void *context,
  573. printer->callback = callback;
  574. }
  575. -int printer_pin_set_default(void *printer_handle, gblink_pinouts pinout)
  576. +void *printer_gblink_handle_get(void *printer_handle)
  577. {
  578. struct printer_proto *printer = printer_handle;
  579. - return gblink_pin_set_default(printer->gblink_handle, pinout);
  580. -}
  581. -
  582. -int printer_pin_set(void *printer_handle, gblink_bus_pins pin, const GpioPin *gpio)
  583. -{
  584. - struct printer_proto *printer = printer_handle;
  585. - return gblink_pin_set(printer->gblink_handle, pin, gpio);
  586. -}
  587. -const GpioPin *printer_pin_get(void *printer_handle, gblink_bus_pins pin)
  588. -{
  589. - struct printer_proto *printer = printer_handle;
  590. - return gblink_pin_get(printer->gblink_handle, pin);
  591. + return printer->gblink_handle;
  592. }
  593. -
  594. void printer_stop(void *printer_handle)
  595. {
  596. struct printer_proto *printer = printer_handle;