u8g_dev_flipdisc_2x7.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. u8g_dev_flipdisc.c
  3. 1-Bit (BW) Driver for flip disc matrix
  4. 2x 7 pixel height
  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. #define WIDTH 28
  31. #define HEIGHT 14
  32. #define PAGE_HEIGHT 14
  33. /*
  34. Write data to the flip disc matrix.
  35. This procedure must be implemented by the user.
  36. Arguments:
  37. id: Id for the matrix. Currently always 0.
  38. page: A page has a height of 14 pixel. For a matrix with HEIGHT == 14 this will be always 0
  39. width: The width of the flip disc matrix. Always equal to WIDTH
  40. row1: first data line (7 pixel per byte)
  41. row2: first data line (7 pixel per byte)
  42. */
  43. void writeFlipDiscMatrix(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2);
  44. void (*u8g_write_flip_disc_matrix)(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2);
  45. void u8g_SetFlipDiscCallback(u8g_t *u8g, void (*cb)(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2))
  46. {
  47. u8g_write_flip_disc_matrix = cb;
  48. }
  49. uint8_t u8g_dev_flipdisc_2x7_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg)
  50. {
  51. switch(msg)
  52. {
  53. case U8G_DEV_MSG_INIT:
  54. break;
  55. case U8G_DEV_MSG_STOP:
  56. break;
  57. case U8G_DEV_MSG_PAGE_NEXT:
  58. {
  59. u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem);
  60. /* current page: pb->p.page */
  61. /* ptr to the buffer: pb->buf */
  62. (*u8g_write_flip_disc_matrix)(0, pb->p.page, WIDTH, pb->buf, (uint8_t *)(pb->buf)+WIDTH);
  63. }
  64. break;
  65. case U8G_DEV_MSG_CONTRAST:
  66. return 1;
  67. }
  68. return u8g_dev_pb14v1_base_fn(u8g, dev, msg, arg);
  69. }
  70. uint8_t u8g_dev_flipdisc_2x7_bw_buf[WIDTH*2] U8G_NOCOMMON ;
  71. u8g_pb_t u8g_dev_flipdisc_2x7_bw_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_flipdisc_2x7_bw_buf};
  72. u8g_dev_t u8g_dev_flipdisc_2x7 = { u8g_dev_flipdisc_2x7_bw_fn, &u8g_dev_flipdisc_2x7_bw_pb, u8g_com_null_fn };