My Marlin configs for Fabrikator Mini and CTC i3 Pro B
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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. u8g_pb8h8.c
  3. 8 bits per pixel, horizontal
  4. Universal 8bit Graphics Library
  5. Copyright (c) 2012, olikraus@gmail.com
  6. All rights reserved.
  7. Redistribution and use in source and binary forms, with or without modification,
  8. are permitted provided that the following conditions are met:
  9. * Redistributions of source code must retain the above copyright notice, this list
  10. of conditions and the following disclaimer.
  11. * Redistributions in binary form must reproduce the above copyright notice, this
  12. list of conditions and the following disclaimer in the documentation and/or other
  13. materials provided with the distribution.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  15. CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  16. INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  17. MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  19. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  24. STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  26. ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. struct _u8g_pb_t
  28. {
  29. u8g_page_t p;
  30. u8g_uint_t width;
  31. void *buf;
  32. };
  33. typedef struct _u8g_pb_t u8g_pb_t;
  34. uint8_t u8g_index_color_8h8_buf[WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ;
  35. u8g_pb_t u8g_index_color_8h8_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_index_color_8h8_buff};
  36. u8g_dev_t name = { dev_fn, &u8g_index_color_8h8_pb, com_fn }
  37. */
  38. #include "u8g.h"
  39. #define WIDTH_BITS 7
  40. #define WIDTH (1<<WIDTH_BITS)
  41. #define PAGE_HEIGHT_BITS 3
  42. #define PAGE_HEIGHT (1<<PAGE_HEIGHT_BITS)
  43. void u8g_pb8h8_Clear(u8g_pb_t *b)
  44. {
  45. uint8_t *ptr = (uint8_t *)b->buf;
  46. uint8_t *end_ptr = ptr;
  47. uint8_t cnt = b->p.page_height;
  48. do
  49. {
  50. end_ptr += b->width;
  51. cnt--;
  52. } while( cnt > 0 );
  53. do
  54. {
  55. *ptr++ = 0;
  56. } while( ptr != end_ptr );
  57. }
  58. void u8g_pb8h8_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
  59. {
  60. b->buf = buf;
  61. b->width = width;
  62. u8g_pb8h8_Clear(b);
  63. }
  64. static void u8g_pb8h8_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index)
  65. {
  66. uint16_t tmp;
  67. uint8_t *ptr = b->buf;
  68. y -= b->p.page_y0;
  69. tmp = y;
  70. tmp *= b->width;
  71. tmp += x;
  72. ptr += tmp;
  73. *ptr = color_index;
  74. }
  75. void u8g_pb8h8_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel)
  76. {
  77. if ( arg_pixel->y < b->p.page_y0 )
  78. return;
  79. if ( arg_pixel->y > b->p.page_y1 )
  80. return;
  81. if ( arg_pixel->x >= b->width )
  82. return;
  83. u8g_pb8h8_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color);
  84. }
  85. void u8g_pb8h8_Set8Pixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
  86. {
  87. register uint8_t pixel = arg_pixel->pixel;
  88. u8g_uint_t dx = 0;
  89. u8g_uint_t dy = 0;
  90. switch( arg_pixel->dir )
  91. {
  92. case 0: dx++; break;
  93. case 1: dy++; break;
  94. case 2: dx--; break;
  95. case 3: dy--; break;
  96. }
  97. do
  98. {
  99. if ( pixel & 128 )
  100. u8g_pb8h8_SetPixel(b, arg_pixel);
  101. arg_pixel->x += dx;
  102. arg_pixel->y += dy;
  103. pixel <<= 1;
  104. } while( pixel != 0 );
  105. }
  106. uint8_t u8g_dev_pb8h8_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
  107. {
  108. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  109. switch(msg)
  110. {
  111. case U8G_DEV_MSG_SET_8PIXEL:
  112. if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
  113. u8g_pb8h8_Set8Pixel(pb, (u8g_dev_arg_pixel_t *)arg);
  114. break;
  115. case U8G_DEV_MSG_SET_PIXEL:
  116. u8g_pb8h8_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg);
  117. break;
  118. case U8G_DEV_MSG_INIT:
  119. break;
  120. case U8G_DEV_MSG_STOP:
  121. break;
  122. case U8G_DEV_MSG_PAGE_FIRST:
  123. u8g_pb8h8_Clear(pb);
  124. u8g_page_First(&(pb->p));
  125. break;
  126. case U8G_DEV_MSG_PAGE_NEXT:
  127. if ( u8g_page_Next(&(pb->p)) == 0 )
  128. return 0;
  129. u8g_pb8h8_Clear(pb);
  130. break;
  131. #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
  132. case U8G_DEV_MSG_IS_BBX_INTERSECTION:
  133. return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
  134. #endif
  135. case U8G_DEV_MSG_GET_PAGE_BOX:
  136. u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
  137. break;
  138. case U8G_DEV_MSG_GET_WIDTH:
  139. *((u8g_uint_t *)arg) = pb->width;
  140. break;
  141. case U8G_DEV_MSG_GET_HEIGHT:
  142. *((u8g_uint_t *)arg) = pb->p.total_height;
  143. break;
  144. case U8G_DEV_MSG_SET_COLOR_INDEX:
  145. break;
  146. case U8G_DEV_MSG_SET_XY_CB:
  147. break;
  148. case U8G_DEV_MSG_GET_MODE:
  149. return U8G_MODE_R3G3B2;
  150. }
  151. return 1;
  152. }