My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

u8g_pb16h2.c 4.6KB

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