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

u8g_pb16v1.c 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. u8g_pb16v1.c
  3. 16bit height monochrom (1 bit) page buffer
  4. byte has vertical 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_pb16v1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) U8G_NOINLINE;
  32. void u8g_pb16v1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE;
  33. void u8g_pb16v1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) U8G_NOINLINE ;
  34. void u8g_pb16v1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) U8G_NOINLINE;
  35. void u8g_pb16v1_Clear(u8g_pb_t *b)
  36. {
  37. uint8_t *ptr = (uint8_t *)b->buf;
  38. uint8_t *end_ptr = ptr;
  39. end_ptr += b->width*2;
  40. do
  41. {
  42. *ptr++ = 0;
  43. } while( ptr != end_ptr );
  44. }
  45. /* Obsolete, usually set by the init of the structure */
  46. void u8g_pb16v1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width)
  47. {
  48. b->buf = buf;
  49. b->width = width;
  50. u8g_pb16v1_Clear(b);
  51. }
  52. void u8g_pb16v1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index)
  53. {
  54. register uint8_t mask;
  55. uint8_t *ptr = b->buf;
  56. y -= b->p.page_y0;
  57. if ( y >= 8 )
  58. {
  59. ptr += b->width;
  60. y &= 0x07;
  61. }
  62. mask = 1;
  63. mask <<= y;
  64. ptr += x;
  65. if ( color_index )
  66. {
  67. *ptr |= mask;
  68. }
  69. else
  70. {
  71. mask ^=0xff;
  72. *ptr &= mask;
  73. }
  74. }
  75. void u8g_pb16v1_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_pb16v1_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color);
  84. }
  85. void u8g_pb16v1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
  86. {
  87. register uint8_t pixel = arg_pixel->pixel;
  88. do
  89. {
  90. if ( pixel & 128 )
  91. {
  92. u8g_pb16v1_SetPixel(b, arg_pixel);
  93. }
  94. switch( arg_pixel->dir )
  95. {
  96. case 0: arg_pixel->x++; break;
  97. case 1: arg_pixel->y++; break;
  98. case 2: arg_pixel->x--; break;
  99. case 3: arg_pixel->y--; break;
  100. }
  101. pixel <<= 1;
  102. } while( pixel != 0 );
  103. }
  104. void u8g_pb16v1_Set8PixelOpt2(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel)
  105. {
  106. register uint8_t pixel = arg_pixel->pixel;
  107. u8g_uint_t dx = 0;
  108. u8g_uint_t dy = 0;
  109. switch( arg_pixel->dir )
  110. {
  111. case 0: dx++; break;
  112. case 1: dy++; break;
  113. case 2: dx--; break;
  114. case 3: dy--; break;
  115. }
  116. do
  117. {
  118. if ( pixel & 128 )
  119. u8g_pb16v1_SetPixel(b, arg_pixel);
  120. arg_pixel->x += dx;
  121. arg_pixel->y += dy;
  122. pixel <<= 1;
  123. } while( pixel != 0 );
  124. }
  125. uint8_t u8g_dev_pb16v1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
  126. {
  127. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  128. switch(msg)
  129. {
  130. case U8G_DEV_MSG_SET_8PIXEL:
  131. if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) )
  132. u8g_pb16v1_Set8PixelOpt2(pb, (u8g_dev_arg_pixel_t *)arg);
  133. break;
  134. case U8G_DEV_MSG_SET_PIXEL:
  135. u8g_pb16v1_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg);
  136. break;
  137. case U8G_DEV_MSG_INIT:
  138. break;
  139. case U8G_DEV_MSG_STOP:
  140. break;
  141. case U8G_DEV_MSG_PAGE_FIRST:
  142. u8g_pb16v1_Clear(pb);
  143. u8g_page_First(&(pb->p));
  144. break;
  145. case U8G_DEV_MSG_PAGE_NEXT:
  146. if ( u8g_page_Next(&(pb->p)) == 0 )
  147. return 0;
  148. u8g_pb16v1_Clear(pb);
  149. break;
  150. #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION
  151. case U8G_DEV_MSG_IS_BBX_INTERSECTION:
  152. return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg);
  153. #endif
  154. case U8G_DEV_MSG_GET_PAGE_BOX:
  155. u8g_pb_GetPageBox(pb, (u8g_box_t *)arg);
  156. break;
  157. case U8G_DEV_MSG_GET_WIDTH:
  158. *((u8g_uint_t *)arg) = pb->width;
  159. break;
  160. case U8G_DEV_MSG_GET_HEIGHT:
  161. *((u8g_uint_t *)arg) = pb->p.total_height;
  162. break;
  163. case U8G_DEV_MSG_SET_COLOR_INDEX:
  164. break;
  165. case U8G_DEV_MSG_SET_XY_CB:
  166. break;
  167. case U8G_DEV_MSG_GET_MODE:
  168. return U8G_MODE_BW;
  169. }
  170. return 1;
  171. }