printer_proto.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #ifndef PRINTER_PROTO_H
  2. #define PRINTER_PROTO_H
  3. #include <gblink/include/gblink.h>
  4. #pragma once
  5. enum cb_reason {
  6. reason_data,
  7. reason_print,
  8. reason_complete,
  9. };
  10. /* Dual purpose struct used for both receiving image data from game boy, and
  11. * sending it to printer.
  12. */
  13. struct gb_image {
  14. /* NOTE: Do not change the order of these 4 bytes!
  15. * TODO: Maybe make this a struct, or a union, or something to help
  16. * enforce their ordering to allow for a memcpy to and from printer.
  17. */
  18. /* TODO: Need to understand this more */
  19. uint8_t num_sheets;
  20. uint8_t margins;
  21. /* TODO: Does this actually matter? */
  22. uint8_t palette;
  23. /* TODO: Need to play with this more */
  24. uint8_t exposure;
  25. /* Always expected to be 160 px wide */
  26. size_t data_sz;
  27. uint8_t data[];
  28. };
  29. void *printer_alloc(void);
  30. void printer_free(void *printer_handle);
  31. void printer_callback_context_set(void *printer_handle, void *context);
  32. void printer_callback_set(void *printer_handle, void (*callback)(void *context, struct gb_image *image, enum cb_reason reason));
  33. /* Can only be run after alloc, before start */
  34. int printer_pin_set_default(void *printer_handle, gblink_pinouts pinout);
  35. int printer_pin_set(void *printer_handle, gblink_bus_pins pin, const GpioPin *gpio);
  36. const GpioPin *printer_pin_get(void *printer_handle, gblink_bus_pins pin);
  37. void printer_stop(void *printer_handle);
  38. /* Allocates a buffer of the maximum size that the printer can handle, must be
  39. * freed manually. Provided as a convenience function so the application doesn't
  40. * need to know how big of a buffer to create.
  41. */
  42. struct gb_image *printer_image_buffer_alloc(void);
  43. void printer_image_buffer_free(struct gb_image *image);
  44. #endif // PRINTER_PROTO_H