├── .gitignore
├── LICENSE
├── README.md
├── SConscript
├── docs
├── 8080.gif
├── README.md
├── full_buffer
│ ├── font_usage.jpg
│ ├── fps.jpg
│ ├── graphic_test.jpg
│ ├── hello_world.jpg
│ ├── icon_menu.gif
│ ├── print_utf8.jpg
│ ├── selection_list.jpg
│ ├── u8g2_logo.jpg
│ ├── update_area.jpg
│ └── weather.jpg
├── games
│ ├── space_trash.gif
│ └── trex.gif
├── page_buffer
│ ├── Chinese.jpg
│ ├── Devanagari.jpg
│ ├── Japanese.jpg
│ ├── Korean.jpg
│ ├── clip_window.gif
│ ├── clock.gif
│ ├── contrast_test.gif
│ ├── direct_access.gif
│ ├── draw_log.gif
│ ├── ext_utf8.jpg
│ ├── flip_mode.gif
│ ├── graphic_test.gif
│ ├── hello_world.jpg
│ ├── icon_menu.gif
│ ├── power_save_test.gif
│ ├── print_hello_world.jpg
│ ├── print_progmem.jpg
│ ├── print_utf8.jpg
│ ├── scrolling_text.gif
│ ├── selection_list.jpg
│ ├── serial.gif
│ ├── state_buffer_loop.gif
│ ├── u8g2_logo.jpg
│ ├── update_partly.gif
│ ├── weather.gif
│ ├── xbm.jpg
│ └── xor_test.gif
├── u8g2.jpg
├── u8g2_logo.png
└── u8x8
│ ├── 16x16_font.jpg
│ ├── flip_mode.gif
│ ├── graphic_test.gif
│ ├── hello_world.jpg
│ ├── message_box.jpg
│ └── terminal.gif
├── examples
├── full_buffer
│ ├── FPS.cpp
│ ├── FontUsage.cpp
│ ├── GraphicsTest.cpp
│ ├── HelloWorld.cpp
│ ├── IconMenu.cpp
│ ├── PrintUTF8.cpp
│ ├── SelectionList.cpp
│ ├── U8g2Logo.cpp
│ ├── UpdateArea.cpp
│ └── Weather.cpp
├── games
│ ├── SpaceTrash.cpp
│ └── TRex.cpp
├── page_buffer
│ ├── Chinese.cpp
│ ├── ClipWindow.cpp
│ ├── Clock.cpp
│ ├── ContrastTest.cpp
│ ├── Devanagari.cpp
│ ├── DirectAccess.cpp
│ ├── DrawLog.cpp
│ ├── ExtUTF8.cpp
│ ├── FPS_pb.cpp
│ ├── FlipMode_pb.cpp
│ ├── GraphicsTest_pb.cpp
│ ├── HelloWorld_pb.cpp
│ ├── IconMenu_pb.cpp
│ ├── Japanese.cpp
│ ├── Korean.cpp
│ ├── PowerSaveTest.cpp
│ ├── PrintHelloWorld.cpp
│ ├── ScrollingText.cpp
│ ├── SelectionList_pb.cpp
│ ├── Serial.cpp
│ ├── StateBufferLoop.cpp
│ ├── Terminal_pb.cpp
│ ├── U8g2Logo_pb.cpp
│ ├── UpdatePartly_pb.cpp
│ ├── Weather_pb.cpp
│ ├── XBM.cpp
│ └── XORTest.cpp
├── ssd1306_12864_4wire_hw_spi_example.c
├── ssd1306_12864_4wire_hw_spi_example.cpp
├── ssd1306_12864_4wire_sw_spi_example.c
├── ssd1306_12864_4wire_sw_spi_example.cpp
├── ssd1306_12864_hw_i2c_example.c
├── ssd1306_12864_hw_i2c_example.cpp
├── ssd1306_12864_sw_i2c_example.c
├── ssd1306_12864_sw_i2c_example.cpp
├── st7920_12864_8080_example.c
├── st7920_12864_8080_example.cpp
└── u8x8
│ ├── 16x16Font.cpp
│ ├── FlipMode.cpp
│ ├── GraphicsTest_8x8.cpp
│ ├── HelloWorld_8x8.cpp
│ ├── MessageBox_8x8.cpp
│ └── Terminal_8x8.cpp
├── port
├── Print.cpp
├── Print.h
├── Printable.h
├── U8g2lib.cpp
├── U8g2lib.h
├── U8x8lib.cpp
├── U8x8lib.h
├── u8g2_port.c
└── u8g2_port.h
├── src
├── u8g2.h
├── u8g2_bitmap.c
├── u8g2_box.c
├── u8g2_buffer.c
├── u8g2_circle.c
├── u8g2_cleardisplay.c
├── u8g2_d_memory.c
├── u8g2_d_setup.c
├── u8g2_font.c
├── u8g2_fonts.c
├── u8g2_hvline.c
├── u8g2_input_value.c
├── u8g2_intersection.c
├── u8g2_kerning.c
├── u8g2_line.c
├── u8g2_ll_hvline.c
├── u8g2_message.c
├── u8g2_polygon.c
├── u8g2_selection_list.c
├── u8g2_setup.c
├── u8log.c
├── u8log_u8g2.c
├── u8log_u8x8.c
├── u8x8.h
├── u8x8_8x8.c
├── u8x8_byte.c
├── u8x8_cad.c
├── u8x8_capture.c
├── u8x8_d_a2printer.c
├── u8x8_d_hd44102.c
├── u8x8_d_il3820_296x128.c
├── u8x8_d_ist3020.c
├── u8x8_d_ist7920.c
├── u8x8_d_ks0108.c
├── u8x8_d_lc7981.c
├── u8x8_d_ld7032_60x32.c
├── u8x8_d_ls013b7dh03.c
├── u8x8_d_max7219.c
├── u8x8_d_pcd8544_84x48.c
├── u8x8_d_pcf8812.c
├── u8x8_d_pcf8814_hx1230.c
├── u8x8_d_s1d15721.c
├── u8x8_d_s1d15e06.c
├── u8x8_d_sbn1661.c
├── u8x8_d_sed1330.c
├── u8x8_d_sh1106_64x32.c
├── u8x8_d_sh1106_72x40.c
├── u8x8_d_sh1107.c
├── u8x8_d_sh1108.c
├── u8x8_d_sh1122.c
├── u8x8_d_ssd1305.c
├── u8x8_d_ssd1306_128x32.c
├── u8x8_d_ssd1306_128x64_noname.c
├── u8x8_d_ssd1306_2040x16.c
├── u8x8_d_ssd1306_48x64.c
├── u8x8_d_ssd1306_64x32.c
├── u8x8_d_ssd1306_64x48.c
├── u8x8_d_ssd1306_72x40.c
├── u8x8_d_ssd1306_96x16.c
├── u8x8_d_ssd1309.c
├── u8x8_d_ssd1316.c
├── u8x8_d_ssd1317.c
├── u8x8_d_ssd1318.c
├── u8x8_d_ssd1320.c
├── u8x8_d_ssd1322.c
├── u8x8_d_ssd1325.c
├── u8x8_d_ssd1326.c
├── u8x8_d_ssd1327.c
├── u8x8_d_ssd1329.c
├── u8x8_d_ssd1606_172x72.c
├── u8x8_d_ssd1607_200x200.c
├── u8x8_d_st7511.c
├── u8x8_d_st75256.c
├── u8x8_d_st7528.c
├── u8x8_d_st75320.c
├── u8x8_d_st7565.c
├── u8x8_d_st7567.c
├── u8x8_d_st7571.c
├── u8x8_d_st7586s_erc240160.c
├── u8x8_d_st7586s_s028hn118a.c
├── u8x8_d_st7586s_ymc240160.c
├── u8x8_d_st7588.c
├── u8x8_d_st7920.c
├── u8x8_d_stdio.c
├── u8x8_d_t6963.c
├── u8x8_d_uc1601.c
├── u8x8_d_uc1604.c
├── u8x8_d_uc1608.c
├── u8x8_d_uc1610.c
├── u8x8_d_uc1611.c
├── u8x8_d_uc1617.c
├── u8x8_d_uc1638.c
├── u8x8_d_uc1701_dogs102.c
├── u8x8_d_uc1701_mini12864.c
├── u8x8_debounce.c
├── u8x8_display.c
├── u8x8_fonts.c
├── u8x8_gpio.c
├── u8x8_input_value.c
├── u8x8_message.c
├── u8x8_selection_list.c
├── u8x8_setup.c
├── u8x8_string.c
├── u8x8_u16toa.c
└── u8x8_u8toa.c
└── u8g2_logo.png
/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Object files
5 | *.o
6 | *.ko
7 | *.obj
8 | *.elf
9 |
10 | # Linker output
11 | *.ilk
12 | *.map
13 | *.exp
14 |
15 | # Precompiled Headers
16 | *.gch
17 | *.pch
18 |
19 | # Libraries
20 | *.lib
21 | *.a
22 | *.la
23 | *.lo
24 |
25 | # Shared objects (inc. Windows DLLs)
26 | *.dll
27 | *.so
28 | *.so.*
29 | *.dylib
30 |
31 | # Executables
32 | *.exe
33 | *.out
34 | *.app
35 | *.i*86
36 | *.x86_64
37 | *.hex
38 |
39 | # Debug files
40 | *.dSYM/
41 | *.su
42 | *.idb
43 | *.pdb
44 |
45 | # Kernel Module Compile Results
46 | *.mod*
47 | *.cmd
48 | .tmp_versions/
49 | modules.order
50 | Module.symvers
51 | Mkfile.old
52 | dkms.conf
53 | .vscode/
54 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The U8g2lib code (http://code.google.com/p/u8g2/) is licensed under the terms of
2 | the new-bsd license (two-clause bsd license).
3 | See also: http://www.opensource.org/licenses/bsd-license.php
4 |
5 | The repository and optionally the releases contain icons, which are
6 | derived from the WPZOOM Developer Icon Set:
7 | http://www.wpzoom.com/wpzoom/new-freebie-wpzoom-developer-icon-set-154-free-icons/
8 | WPZOOM Developer Icon Set by WPZOOM is licensed under a Creative Commons
9 | Attribution-ShareAlike 3.0 Unported License.
10 |
11 | Fonts are licensed under different conditions.
12 | See
13 | https://github.com/olikraus/u8g2/wiki/fntgrp
14 | for detailed information on the licensing conditions for each font.
15 |
16 | ============ X11 Fonts COUR, HELV, NCEN, TIM, SYMB ============
17 |
18 | For fonts derived from the following files, the license below applies.
19 | COURB08.BDF COURB10.BDF COURB12.BDF COURB14.BDF COURB18.BDF
20 | COURB24.BDF COURR08.BDF COURR10.BDF COURR12.BDF COURR14.BDF
21 | COURR18.BDF COURR24.BDF HELVB08.BDF HELVB10.BDF HELVB12.BDF HELVB14.BDF
22 | HELVB18.BDF HELVB24.BDF HELVR08.BDF HELVR10.BDF HELVR12.BDF HELVR14.BDF
23 | HELVR18.BDF HELVR24.BDF NCENB08.BDF NCENB10.BDF NCENB12.BDF
24 | NCENB14.BDF NCENB18.BDF NCENB24.BDF NCENR08.BDF NCENR10.BDF
25 | NCENR12.BDF NCENR14.BDF NCENR18.BDF NCENR24.BDF SYMB08.BDF SYMB10.BDF
26 | SYMB12.BDF SYMB14.BDF SYMB18.BDF SYMB24.BDF TIMB08.BDF TIMB10.BDF
27 | TIMB12.BDF TIMB14.BDF TIMB18.BDF TIMB24.BDF TIMR08.BDF TIMR10.BDF
28 | TIMR12.BDF TIMR14.BDF TIMR18.BDF TIMR24.BDF
29 |
30 | Copyright 1984-1989, 1994 Adobe Systems Incorporated.
31 | Copyright 1988, 1994 Digital Equipment Corporation.
32 |
33 | Adobe is a trademark of Adobe Systems Incorporated which may be
34 | registered in certain jurisdictions.
35 | Permission to use these trademarks is hereby granted only in
36 | association with the images described in this file.
37 |
38 | Permission to use, copy, modify, distribute and sell this software
39 | and its documentation for any purpose and without fee is hereby
40 | granted, provided that the above copyright notices appear in all
41 | copies and that both those copyright notices and this permission
42 | notice appear in supporting documentation, and that the names of
43 | Adobe Systems and Digital Equipment Corporation not be used in
44 | advertising or publicity pertaining to distribution of the software
45 | without specific, written prior permission. Adobe Systems and
46 | Digital Equipment Corporation make no representations about the
47 | suitability of this software for any purpose. It is provided "as
48 | is" without express or implied warranty.
49 |
50 |
51 | ============ BSD License for U8g2lib Code ============
52 |
53 | Universal 8bit Graphics Library (http://code.google.com/p/u8g2/)
54 |
55 | Copyright (c) 2016, olikraus@gmail.com
56 | All rights reserved.
57 |
58 | Redistribution and use in source and binary forms, with or without modification,
59 | are permitted provided that the following conditions are met:
60 |
61 | * Redistributions of source code must retain the above copyright notice, this list
62 | of conditions and the following disclaimer.
63 |
64 | * Redistributions in binary form must reproduce the above copyright notice, this
65 | list of conditions and the following disclaimer in the documentation and/or other
66 | materials provided with the distribution.
67 |
68 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
69 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
70 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
71 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
72 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
73 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
74 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
75 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
76 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
77 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
78 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
79 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
80 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
81 |
82 |
83 | ============ RT-Thread package maintainer ============
84 |
85 | Author: Wu Han
86 | Home : http://wuhanstudio.cc
87 | Email: wuhanstudio@hust.edu.cn
88 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | > 这个仓库是我以前移植 u8g2 到 RT-Thread 的版本,现在对应的移植已经 upstream 到 u8g2 的官方仓库了,所以可以直接用官方仓库了。 - 2021.09.30
4 |
5 | # rt-u8g2
6 |
7 | 
8 |
9 | ## 0、介绍
10 |
11 | u8g2 原先是 Arduino 平台上的一个单色屏驱动,现在移植到了 rt-thread,可以满足各种各种各样的需求。
12 |
13 | > 游戏开发 (examples/games/space_trash)
14 |
15 | 
16 |
17 | 
18 |
19 | > 用户界面 (examples/page_buffer/icon_menu)
20 |
21 | 
22 |
23 | > 绘图 (examples/page_buffer/graphic_test)
24 |
25 | 
26 |
27 | ## 1、U8G2 特点
28 |
29 | #### 1.1 支持屏幕多,移植方便
30 |
31 | 使用 u8g2 的好处在于它支持近 200 种单色屏,同样的代码可以直接运行在不同的屏幕上,比如前面的游戏可以在各种屏幕上运行:
32 |
33 | > 经典 128x64
34 |
35 | 
36 |
37 | > OLED SSD1306 I2C
38 |
39 | 
40 |
41 | 在这里可以看到所有支持的屏幕:
42 |
43 | [https://github.com/olikraus/u8g2/wiki/gallery](https://github.com/olikraus/u8g2/wiki/gallery)
44 |
45 | #### 1.2 支持字体多
46 |
47 | > 中文
48 |
49 | 
50 |
51 | > 韩文
52 |
53 | 
54 |
55 | > 日文
56 |
57 | 
58 |
59 | > 梵文
60 |
61 | 
62 |
63 | #### 1.3 绘图函数多
64 |
65 | 支持各种绘图函数,而且自带各种 icon
66 |
67 | 
68 |
69 | 
70 |
71 | 总结一下 u8g2 的特点:
72 |
73 | - 支持近 200 种单色屏,移植方便
74 | - 支持各种绘图函数、图像与非操作,自带用户按键检测
75 | - 支持 unicode 和 utf8,自带 100 多种字体和 100 多个 icon
76 |
77 |
78 | ## 2、项目说明
79 | ### 2.1 目录结构
80 |
81 | > 说明:目录结构
82 |
83 | | 名称 | 说明 |
84 | | ---- | ---- |
85 | | docs | 文档目录 |
86 | | examples | 例子目录|
87 | | src | 源代码目录 |
88 | | port | 针对特定平台的移植代码目录 |
89 |
90 | ### 2.2 许可证
91 |
92 | - The U8g2lib code (http://code.google.com/p/u8g2/) is licensed under the terms of
93 | the new-bsd license (two-clause bsd license). See also:
94 |
95 | http://www.opensource.org/licenses/bsd-license.php
96 |
97 | - The repository and optionally the releases contain icons, which are
98 | derived from the WPZOOM Developer Icon Set. WPZOOM Developer Icon Set by WPZOOM is licensed under a Creative Commons
99 | Attribution-ShareAlike 3.0 Unported License.
100 |
101 | http://www.wpzoom.com/wpzoom/new-freebie-wpzoom-developer-icon-set-154-free-icons/
102 |
103 | - Fonts are licensed under different conditions.for detailed information on the licensing conditions for each font.
104 |
105 | https://github.com/olikraus/u8g2/wiki/fntgrp
106 |
107 |
108 | Check full LICENCE **[here](LICENSE)**.
109 |
110 | ### 2.3 项目依赖
111 |
112 | 说明:如果使用 I2C 液晶屏需要开启 I2C,GPIO 模拟 I2C 。
113 |
114 | - Using I2C device drivers
115 | - Use GPIO to simulate I2C
116 |
117 | 说明:如果使用 SPI 液晶屏需要开启 SPI 。
118 |
119 | - Using SPI Bus/Device device drivers
120 |
121 | ## 3、如何使用 U8G2
122 |
123 | 使用 u8g2 package 需要在 RT-Thread 的包管理器中选择它,具体路径如下:
124 |
125 | RT-Thread online packages
126 | peripheral libraries and drivers --->
127 | [*] U8G2: a u8g2 package for rt-thread
128 | [*] Use hardware spi
129 | (spi1) spi bus name (NEW)
130 | (spi10) spi device name (NEW)
131 | [*] Use hardware i2c
132 | (i2c2) i2c device name
133 | U8G2 Examples --->
134 |
135 | 然后让 RT-Thread 的包管理器自动更新,或者使用 `pkgs --update` 命令更新包到 BSP 中。
136 |
137 | 一共有50个例程,可以在源码 docs 目录下看到预览图。默认的例程都是用的软件I2C,如果觉得速度比较慢可以使用硬件I2C。
138 |
139 | ## 4、注意事项
140 |
141 | - 默测试认使用 STM32F103,如果要使用到其他平台,请参照 [移植说明](port/README.md),不过只要用的 RT-Thread 应当不需要额外的移植。
142 | - 请使用 stm32 目录下的 bsp
143 | - 编译需要开启 -std=c99
144 | - 如果编译发现 flash 不够大,可以打开优化选项 -O3 或者参照 [这里](https://github.com/olikraus/u8g2/wiki/u8g2optimization) 去掉多余的字库
145 | - 完整的 API 手册可以访问这个 [链接](https://github.com/olikraus/u8g2/wiki/u8g2reference)
146 | - 其他 [常见问题 FAQ](https://github.com/wuhanstudio/rt-u8g2/issues)
147 |
148 | ## 5、感谢
149 |
150 | - u8g2: https://github.com/olikraus/u8g2
151 |
152 | ## 6、联系方式
153 |
154 | * 维护:Wu Han
155 | * 主页:http://wuhanstudio.cc
156 | * 联系:https://github.com/wuhanstudio/rt-u8g2/issues
157 |
--------------------------------------------------------------------------------
/SConscript:
--------------------------------------------------------------------------------
1 | from building import *
2 | import rtconfig
3 |
4 | # get current directory
5 | cwd = GetCurrentDir()
6 |
7 | # The set of source files associated with this SConscript file.
8 | src = Glob('src/*.c')
9 | src += Glob('port/*.c')
10 |
11 | if(GetDepend('U8G2_USE_CPP')):
12 | src += Glob('port/*.cpp')
13 |
14 | if(not GetDepend('U8G2_USE_CPP')):
15 |
16 | if GetDepend('U8G2_USING_SW_I2C_SSD1306'):
17 | src += Glob('examples/ssd1306_12864_sw_i2c_example.c')
18 |
19 | if GetDepend('U8G2_USING_HW_I2C_SSD1306'):
20 | src += Glob('examples/ssd1306_12864_hw_i2c_example.c')
21 |
22 | if GetDepend('U8G2_USING_SW_SPI_SSD1306'):
23 | src += Glob('examples/ssd1306_12864_4wire_sw_spi_example.c')
24 |
25 | if GetDepend('U8G2_USING_HW_SPI_SSD1306'):
26 | src += Glob('examples/ssd1306_12864_4wire_hw_spi_example.c')
27 |
28 | if GetDepend('U8G2_USING_8080_ST7920'):
29 | src += Glob('examples/st7920_12864_8080_example.c')
30 |
31 | if GetDepend('U8G2_USING_I2C_YL40'):
32 | src += Glob('examples/yl_40_example.c')
33 |
34 | else:
35 |
36 | # Basic Examples
37 | if GetDepend('U8G2_USING_SW_I2C_SSD1306'):
38 | src += Glob('examples/ssd1306_12864_sw_i2c_example.cpp')
39 |
40 | if GetDepend('U8G2_USING_HW_I2C_SSD1306'):
41 | src += Glob('examples/ssd1306_12864_hw_i2c_example.cpp')
42 |
43 | if GetDepend('U8G2_USING_SW_SPI_SSD1306'):
44 | src += Glob('examples/ssd1306_12864_4wire_sw_spi_example.cpp')
45 |
46 | if GetDepend('U8G2_USING_HW_SPI_SSD1306'):
47 | src += Glob('examples/ssd1306_12864_4wire_hw_spi_example.cpp')
48 |
49 | if GetDepend('U8G2_USING_8080_ST7920'):
50 | src += Glob('examples/st7920_12864_8080_example.cpp')
51 |
52 | if GetDepend('U8G2_USING_I2C_YL40'):
53 | src += Glob('examples/yl_40_example.c')
54 |
55 |
56 | # Frame Buffer Examples
57 | if GetDepend('U8G2_USING_FRAME_EXAMPLE_FONT_USAGE'):
58 | src += Glob('examples/full_buffer/FontUsage.cpp')
59 |
60 | if GetDepend('U8G2_USING_FRAME_EXAMPLE_FPS'):
61 | src += Glob('examples/full_buffer/FPS.cpp')
62 |
63 | if GetDepend('U8G2_USING_FRAME_EXAMPLE_GRAPHIC_TEST'):
64 | src += Glob('examples/full_buffer/GraphicsTest.cpp')
65 |
66 | if GetDepend('U8G2_USING_FRAME_EXAMPLE_HELLO_WORLD'):
67 | src += Glob('examples/full_buffer/HelloWorld.cpp')
68 |
69 | if GetDepend('U8G2_USING_FRAME_EXAMPLE_ICON_MENU'):
70 | src += Glob('examples/full_buffer/IconMenu.cpp')
71 |
72 | if GetDepend('U8G2_USING_FRAME_EXAMPLE_PRINT_UTF8'):
73 | src += Glob('examples/full_buffer/PrintUTF8.cpp')
74 |
75 | if GetDepend('U8G2_USING_FRAME_EXAMPLE_SELECTION_LIST'):
76 | src += Glob('examples/full_buffer/SelectionList.cpp')
77 |
78 | if GetDepend('U8G2_USING_FRAME_EXAMPLE_U8G2_LOGO'):
79 | src += Glob('examples/full_buffer/U8g2Logo.cpp')
80 |
81 | if GetDepend('U8G2_USING_FRAME_EXAMPLE_UPDATE_AREA'):
82 | src += Glob('examples/full_buffer/UpdateArea.cpp')
83 |
84 | if GetDepend('U8G2_USING_FRAME_EXAMPLE_WEATHER'):
85 | src += Glob('examples/full_buffer/Weather.cpp')
86 |
87 |
88 | # Page Buffer Examples
89 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_CHINESE'):
90 | src += Glob('examples/page_buffer/Chinese.cpp')
91 |
92 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_CLIP_WINDOW'):
93 | src += Glob('examples/page_buffer/ClipWindow.cpp')
94 |
95 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_CLOCK'):
96 | src += Glob('examples/page_buffer/Clock.cpp')
97 |
98 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_CONTRAST_TEST'):
99 | src += Glob('examples/page_buffer/ContrastTest.cpp')
100 |
101 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_DEVANAGARI'):
102 | src += Glob('examples/page_buffer/Devanagari.cpp')
103 |
104 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_DIRECT_ACCESS'):
105 | src += Glob('examples/page_buffer/DirectAccess.cpp')
106 |
107 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_DRAW_LOG'):
108 | src += Glob('examples/page_buffer/DrawLog.cpp')
109 |
110 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_EXT_UTF8'):
111 | src += Glob('examples/page_buffer/ExtUTF8.cpp')
112 |
113 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_FLIP_MODE'):
114 | src += Glob('examples/page_buffer/FlipMode_pb.cpp')
115 |
116 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_FPS'):
117 | src += Glob('examples/page_buffer/FPS_pb.cpp')
118 |
119 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_GRAPHIC_TEST'):
120 | src += Glob('examples/page_buffer/GraphicsTest_pb.cpp')
121 |
122 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_HELLO_WORLD'):
123 | src += Glob('examples/page_buffer/HelloWorld_pb.cpp')
124 |
125 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_ICON_MENU'):
126 | src += Glob('examples/page_buffer/IconMenu_pb.cpp')
127 |
128 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_JAPANESE'):
129 | src += Glob('examples/page_buffer/Japanese.cpp')
130 |
131 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_KOREAN'):
132 | src += Glob('examples/page_buffer/Korean.cpp')
133 |
134 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_POWER_SAVE_TEST'):
135 | src += Glob('examples/page_buffer/PowerSaveTest.cpp')
136 |
137 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_PRINT_HELLO_WORLD'):
138 | src += Glob('examples/page_buffer/PrintHelloWorld.cpp')
139 |
140 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_SCROLLING_TEXT'):
141 | src += Glob('examples/page_buffer/ScrollingText.cpp')
142 |
143 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_SELECTION_LIST'):
144 | src += Glob('examples/page_buffer/SelectionList_pb.cpp')
145 |
146 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_SERIAL'):
147 | src += Glob('examples/page_buffer/Serial.cpp')
148 |
149 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_STATE_BUFFER_LOOP'):
150 | src += Glob('examples/page_buffer/StateBufferLoop.cpp')
151 |
152 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_TERMINAL'):
153 | src += Glob('examples/page_buffer/Terminal_pb.cpp')
154 |
155 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_U8G2_LOGO'):
156 | src += Glob('examples/page_buffer/U8g2Logo_pb.cpp')
157 |
158 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_UPDATE_PARTLY'):
159 | src += Glob('examples/page_buffer/UpdatePartly_pb.cpp')
160 |
161 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_WEATHER'):
162 | src += Glob('examples/page_buffer/Weather_pb.cpp')
163 |
164 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_XBM'):
165 | src += Glob('examples/page_buffer/XBM.cpp')
166 |
167 | if GetDepend('U8G2_USING_PAGE_EXAMPLE_XOR_TEST'):
168 | src += Glob('examples/page_buffer/XORTest.cpp')
169 |
170 |
171 | # U8x8 Examples
172 | if GetDepend('U8G2_USING_U8x8_EXAMPLE_16x16_FONT'):
173 | src += Glob('examples/u8x8/16x16Font.cpp')
174 |
175 | if GetDepend('U8G2_USING_U8x8_EXAMPLE_FLIP_MODE'):
176 | src += Glob('examples/u8x8/FlipMode.cpp')
177 |
178 | if GetDepend('U8G2_USING_U8x8_EXAMPLE_GRAPHIC_TEST'):
179 | src += Glob('examples/u8x8/GraphicsTest_8x8.cpp')
180 |
181 | if GetDepend('U8G2_USING_U8x8_EXAMPLE_HELLO_WORLD'):
182 | src += Glob('examples/u8x8/HelloWorld_8x8.cpp')
183 |
184 | if GetDepend('U8G2_USING_U8x8_EXAMPLE_MESSAGE_BOX'):
185 | src += Glob('examples/u8x8/MessageBox_8x8.cpp')
186 |
187 | if GetDepend('U8G2_USING_U8x8_EXAMPLE_TERMINAL'):
188 | src += Glob('examples/u8x8/Terminal_8x8.cpp')
189 |
190 |
191 | # Game Examples
192 | if GetDepend('U8G2_USING_GAME_EXAMPLE_SPACE_TRASH'):
193 | src += Glob('examples/games/SpaceTrash.cpp')
194 | if GetDepend('U8G2_USING_GAME_EXAMPLE_TREX'):
195 | src += Glob('examples/games/TRex.cpp')
196 |
197 | path = [cwd + '/']
198 | path += [cwd + '/port']
199 | path += [cwd + '/src']
200 |
201 | LOCAL_CCFLAGS = ''
202 |
203 | group = DefineGroup('U8G2', src, depend = ['PKG_USING_U8G2'], CPPPATH = path, LOCAL_CCFLAGS = LOCAL_CCFLAGS, CPPDEFINES=['RTT_U8G2'])
204 |
205 | Return('group')
206 |
--------------------------------------------------------------------------------
/docs/8080.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/8080.gif
--------------------------------------------------------------------------------
/docs/README.md:
--------------------------------------------------------------------------------
1 | 
2 | # rt-u8g2
3 |
4 | ## 使用说明
5 |
6 | - 移植请参照 : [移植方法](../port/README.md)
7 | - 例程请参照 : [ssd1306 液晶 与 YL-40 模块](../examples/README.md)
8 | - API 请参照 : [U8g2 Reference](https://github.com/olikraus/u8g2/wiki/u8g2reference)
9 |
10 |
11 | ## Todo list
12 |
13 | [●] Hardware I2C
14 | [●] Hardware SPI
15 | [●] Software I2C
16 | [●] Software SPI
17 | [●] 8080 & 6800
18 |
--------------------------------------------------------------------------------
/docs/full_buffer/font_usage.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/full_buffer/font_usage.jpg
--------------------------------------------------------------------------------
/docs/full_buffer/fps.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/full_buffer/fps.jpg
--------------------------------------------------------------------------------
/docs/full_buffer/graphic_test.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/full_buffer/graphic_test.jpg
--------------------------------------------------------------------------------
/docs/full_buffer/hello_world.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/full_buffer/hello_world.jpg
--------------------------------------------------------------------------------
/docs/full_buffer/icon_menu.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/full_buffer/icon_menu.gif
--------------------------------------------------------------------------------
/docs/full_buffer/print_utf8.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/full_buffer/print_utf8.jpg
--------------------------------------------------------------------------------
/docs/full_buffer/selection_list.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/full_buffer/selection_list.jpg
--------------------------------------------------------------------------------
/docs/full_buffer/u8g2_logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/full_buffer/u8g2_logo.jpg
--------------------------------------------------------------------------------
/docs/full_buffer/update_area.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/full_buffer/update_area.jpg
--------------------------------------------------------------------------------
/docs/full_buffer/weather.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/full_buffer/weather.jpg
--------------------------------------------------------------------------------
/docs/games/space_trash.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/games/space_trash.gif
--------------------------------------------------------------------------------
/docs/games/trex.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/games/trex.gif
--------------------------------------------------------------------------------
/docs/page_buffer/Chinese.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/Chinese.jpg
--------------------------------------------------------------------------------
/docs/page_buffer/Devanagari.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/Devanagari.jpg
--------------------------------------------------------------------------------
/docs/page_buffer/Japanese.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/Japanese.jpg
--------------------------------------------------------------------------------
/docs/page_buffer/Korean.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/Korean.jpg
--------------------------------------------------------------------------------
/docs/page_buffer/clip_window.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/clip_window.gif
--------------------------------------------------------------------------------
/docs/page_buffer/clock.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/clock.gif
--------------------------------------------------------------------------------
/docs/page_buffer/contrast_test.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/contrast_test.gif
--------------------------------------------------------------------------------
/docs/page_buffer/direct_access.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/direct_access.gif
--------------------------------------------------------------------------------
/docs/page_buffer/draw_log.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/draw_log.gif
--------------------------------------------------------------------------------
/docs/page_buffer/ext_utf8.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/ext_utf8.jpg
--------------------------------------------------------------------------------
/docs/page_buffer/flip_mode.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/flip_mode.gif
--------------------------------------------------------------------------------
/docs/page_buffer/graphic_test.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/graphic_test.gif
--------------------------------------------------------------------------------
/docs/page_buffer/hello_world.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/hello_world.jpg
--------------------------------------------------------------------------------
/docs/page_buffer/icon_menu.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/icon_menu.gif
--------------------------------------------------------------------------------
/docs/page_buffer/power_save_test.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/power_save_test.gif
--------------------------------------------------------------------------------
/docs/page_buffer/print_hello_world.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/print_hello_world.jpg
--------------------------------------------------------------------------------
/docs/page_buffer/print_progmem.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/print_progmem.jpg
--------------------------------------------------------------------------------
/docs/page_buffer/print_utf8.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/print_utf8.jpg
--------------------------------------------------------------------------------
/docs/page_buffer/scrolling_text.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/scrolling_text.gif
--------------------------------------------------------------------------------
/docs/page_buffer/selection_list.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/selection_list.jpg
--------------------------------------------------------------------------------
/docs/page_buffer/serial.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/serial.gif
--------------------------------------------------------------------------------
/docs/page_buffer/state_buffer_loop.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/state_buffer_loop.gif
--------------------------------------------------------------------------------
/docs/page_buffer/u8g2_logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/u8g2_logo.jpg
--------------------------------------------------------------------------------
/docs/page_buffer/update_partly.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/update_partly.gif
--------------------------------------------------------------------------------
/docs/page_buffer/weather.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/weather.gif
--------------------------------------------------------------------------------
/docs/page_buffer/xbm.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/xbm.jpg
--------------------------------------------------------------------------------
/docs/page_buffer/xor_test.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/page_buffer/xor_test.gif
--------------------------------------------------------------------------------
/docs/u8g2.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/u8g2.jpg
--------------------------------------------------------------------------------
/docs/u8g2_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/u8g2_logo.png
--------------------------------------------------------------------------------
/docs/u8x8/16x16_font.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/u8x8/16x16_font.jpg
--------------------------------------------------------------------------------
/docs/u8x8/flip_mode.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/u8x8/flip_mode.gif
--------------------------------------------------------------------------------
/docs/u8x8/graphic_test.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/u8x8/graphic_test.gif
--------------------------------------------------------------------------------
/docs/u8x8/hello_world.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/u8x8/hello_world.jpg
--------------------------------------------------------------------------------
/docs/u8x8/message_box.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/u8x8/message_box.jpg
--------------------------------------------------------------------------------
/docs/u8x8/terminal.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/docs/u8x8/terminal.gif
--------------------------------------------------------------------------------
/examples/ssd1306_12864_4wire_hw_spi_example.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | // You may reference Drivers/drv_gpio.c for pinout
7 | // In u8x8.h #define U8X8_USE_PINS
8 |
9 | #define OLED_SPI_PIN_RES 2 // PA2
10 | #define OLED_SPI_PIN_DC 1 // PA1
11 | #define OLED_SPI_PIN_CS 0 // PA0
12 |
13 | static void u8g2_ssd1306_12864_4wire_hw_spi_example(int argc,char *argv[])
14 | {
15 | u8g2_t u8g2;
16 |
17 | // Initialization
18 | u8g2_Setup_ssd1306_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_rtthread_4wire_hw_spi, u8x8_gpio_and_delay_rtthread);
19 | u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_CS, OLED_SPI_PIN_CS);
20 | u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_DC, OLED_SPI_PIN_DC);
21 | u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_RESET, OLED_SPI_PIN_RES);
22 |
23 | u8g2_InitDisplay(&u8g2);
24 | u8g2_SetPowerSave(&u8g2, 0);
25 |
26 | // Draw Graphics
27 | /* full buffer example, setup procedure ends in _f */
28 | u8g2_ClearBuffer(&u8g2);
29 | u8g2_SetFont(&u8g2, u8g2_font_ncenB08_tr);
30 | u8g2_DrawStr(&u8g2, 1, 18, "U8g2 on RT-Thread");
31 | u8g2_SendBuffer(&u8g2);
32 |
33 | u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols);
34 | u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 );
35 | u8g2_SendBuffer(&u8g2);
36 | }
37 | MSH_CMD_EXPORT(u8g2_ssd1306_12864_4wire_hw_spi_example, hardware 4 wire spi ssd1306 sample);
38 |
--------------------------------------------------------------------------------
/examples/ssd1306_12864_4wire_hw_spi_example.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | // You may reference Drivers/drv_gpio.c for pinout
7 | // In u8x8.h #define U8X8_USE_PINS
8 |
9 | #define OLED_SPI_PIN_RES 2 // PA2
10 | #define OLED_SPI_PIN_DC 1 // PA1
11 | #define OLED_SPI_PIN_CS 0 // PA0
12 |
13 | // Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
14 | static U8G2_SSD1306_128X64_NONAME_F_4W_HW_SPI u8g2(U8G2_R0,
15 | /* cs=*/ OLED_SPI_PIN_CS,
16 | /* dc=*/ OLED_SPI_PIN_DC,
17 | /* reset=*/ OLED_SPI_PIN_RES);
18 | // same as the NONAME variant, but may solve the "every 2nd line skipped" problem
19 |
20 | static void u8g2_ssd1306_12864_4wire_hw_spi_example(int argc,char *argv[])
21 | {
22 | u8g2.begin();
23 | u8g2.clearBuffer(); // clear the internal memory
24 | u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
25 | u8g2.drawStr(1, 18, "U8g2 on RT-Thread"); // write something to the internal memory
26 | u8g2.setFont(u8g2_font_5x8_tr); // choose a suitable font
27 | u8g2.drawStr(1, 56, "2.29 Milestone"); // write something to the internal memory
28 | u8g2.sendBuffer(); // transfer internal memory to the display
29 | u8g2.setFont(u8g2_font_unifont_t_symbols);
30 | u8g2.drawGlyph(112, 56, 0x2603 );
31 | u8g2.sendBuffer();
32 | }
33 | MSH_CMD_EXPORT(u8g2_ssd1306_12864_4wire_hw_spi_example, hw 4wire spi ssd1306 sample);
34 |
--------------------------------------------------------------------------------
/examples/ssd1306_12864_4wire_sw_spi_example.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | // You may reference Drivers/drv_gpio.c for pinout
7 | // In u8x8.h #define U8X8_USE_PINS
8 |
9 | #define OLED_SPI_PIN_CLK 5 // PA5
10 | #define OLED_SPI_PIN_MOSI 7 // PA7
11 | #define OLED_SPI_PIN_RES 2 // PA2
12 | #define OLED_SPI_PIN_DC 1 // PA1
13 | #define OLED_SPI_PIN_CS 0 // PA0
14 |
15 | static void u8g2_ssd1306_12864_4wire_sw_spi_example(int argc,char *argv[])
16 | {
17 | u8g2_t u8g2;
18 |
19 | // Initialization
20 | u8g2_Setup_ssd1306_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_4wire_sw_spi, u8x8_gpio_and_delay_rtthread);
21 | u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_SPI_CLOCK, OLED_SPI_PIN_CLK);
22 | u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_SPI_DATA, OLED_SPI_PIN_MOSI);
23 | u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_CS, OLED_SPI_PIN_CS);
24 | u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_DC, OLED_SPI_PIN_DC);
25 | u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_RESET, OLED_SPI_PIN_RES);
26 |
27 | u8g2_InitDisplay(&u8g2);
28 | u8g2_SetPowerSave(&u8g2, 0);
29 |
30 | // Draw Graphics
31 | /* full buffer example, setup procedure ends in _f */
32 | u8g2_ClearBuffer(&u8g2);
33 | u8g2_SetFont(&u8g2, u8g2_font_ncenB08_tr);
34 | u8g2_DrawStr(&u8g2, 1, 18, "U8g2 on RT-Thread");
35 | u8g2_SendBuffer(&u8g2);
36 |
37 | u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols);
38 | u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 );
39 | u8g2_SendBuffer(&u8g2);
40 | }
41 | MSH_CMD_EXPORT(u8g2_ssd1306_12864_4wire_sw_spi_example, sw 4wire spi ssd1306 sample);
42 |
--------------------------------------------------------------------------------
/examples/ssd1306_12864_4wire_sw_spi_example.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | // You may reference Drivers/drv_gpio.c for pinout
7 | // In u8x8.h #define U8X8_USE_PINS
8 |
9 | #define OLED_SPI_PIN_CLK 5 // PA5
10 | #define OLED_SPI_PIN_MOSI 7 // PA7
11 | #define OLED_SPI_PIN_RES 2 // PA2
12 | #define OLED_SPI_PIN_DC 1 // PA1
13 | #define OLED_SPI_PIN_CS 0 // PA0
14 |
15 | // Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
16 | static U8G2_SSD1306_128X64_NONAME_F_4W_SW_SPI u8g2(U8G2_R0,\
17 | /* clock=*/ OLED_SPI_PIN_CLK,\
18 | /* data=*/ OLED_SPI_PIN_MOSI,\
19 | /* cs=*/ OLED_SPI_PIN_CS,\
20 | /* dc=*/ OLED_SPI_PIN_DC,\
21 | /* reset=*/ OLED_SPI_PIN_RES);
22 |
23 | static void u8g2_ssd1306_12864_4wire_sw_spi_example(int argc,char *argv[])
24 | {
25 | u8g2.begin();
26 | u8g2.clearBuffer(); // clear the internal memory
27 | u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
28 | u8g2.drawStr(1, 18, "U8g2 on RT-Thread"); // write something to the internal memory
29 | u8g2.sendBuffer(); // transfer internal memory to the display
30 | u8g2.setFont(u8g2_font_unifont_t_symbols);
31 | u8g2.drawGlyph(112, 56, 0x2603 );
32 | u8g2.sendBuffer();
33 | }
34 | MSH_CMD_EXPORT(u8g2_ssd1306_12864_4wire_sw_spi_example, sw 4wire spi ssd1306 sample);
35 |
--------------------------------------------------------------------------------
/examples/ssd1306_12864_hw_i2c_example.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | static void u8g2_ssd1306_12864_hw_i2c_example(int argc,char *argv[])
7 | {
8 | u8g2_t u8g2;
9 |
10 | // Initialization
11 | u8g2_Setup_ssd1306_i2c_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_rtthread_hw_i2c, u8x8_gpio_and_delay_rtthread);
12 | u8g2_InitDisplay(&u8g2);
13 | u8g2_SetPowerSave(&u8g2, 0);
14 |
15 | /* full buffer example, setup procedure ends in _f */
16 | u8g2_ClearBuffer(&u8g2);
17 | u8g2_SetFont(&u8g2, u8g2_font_ncenB08_tr);
18 | u8g2_DrawStr(&u8g2, 1, 18, "U8g2 on RT-Thread");
19 | u8g2_SendBuffer(&u8g2);
20 |
21 | // Draw Graphics
22 | u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols);
23 | u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 );
24 | u8g2_SendBuffer(&u8g2);
25 | }
26 | MSH_CMD_EXPORT(u8g2_ssd1306_12864_hw_i2c_example, i2c ssd1306 sample);
27 |
--------------------------------------------------------------------------------
/examples/ssd1306_12864_hw_i2c_example.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | // Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
7 | static U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
8 |
9 | static void u8g2_ssd1306_12864_hw_i2c_example(int argc,char *argv[])
10 | {
11 | u8g2.begin();
12 | u8g2.clearBuffer(); // clear the internal memory
13 | u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
14 | u8g2.drawStr(1, 18, "U8g2 on RT-Thread"); // write something to the internal memory
15 | u8g2.sendBuffer(); // transfer internal memory to the display
16 | u8g2.setFont(u8g2_font_unifont_t_symbols);
17 | u8g2.drawGlyph(112, 56, 0x2603 );
18 | u8g2.sendBuffer();
19 | }
20 | MSH_CMD_EXPORT(u8g2_ssd1306_12864_hw_i2c_example, i2c ssd1306 sample);
21 |
--------------------------------------------------------------------------------
/examples/ssd1306_12864_sw_i2c_example.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | #define OLED_I2C_PIN_SCL 22 // PB6
7 | #define OLED_I2C_PIN_SDA 23 // PB7
8 |
9 | static void u8g2_ssd1306_12864_sw_i2c_example(int argc,char *argv[])
10 | {
11 | u8g2_t u8g2;
12 |
13 | // Initialization
14 | u8g2_Setup_ssd1306_i2c_128x64_noname_f( &u8g2, U8G2_R0, u8x8_byte_sw_i2c, u8x8_gpio_and_delay_rtthread);
15 | u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_I2C_CLOCK, OLED_I2C_PIN_SCL);
16 | u8x8_SetPin(u8g2_GetU8x8(&u8g2), U8X8_PIN_I2C_DATA, OLED_I2C_PIN_SDA);
17 |
18 | u8g2_InitDisplay(&u8g2);
19 | u8g2_SetPowerSave(&u8g2, 0);
20 |
21 | // Draw Graphics
22 | /* full buffer example, setup procedure ends in _f */
23 | u8g2_ClearBuffer(&u8g2);
24 | u8g2_SetFont(&u8g2, u8g2_font_ncenB08_tr);
25 | u8g2_DrawStr(&u8g2, 1, 18, "U8g2 on RT-Thread");
26 | u8g2_SendBuffer(&u8g2);
27 |
28 | u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols);
29 | u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 );
30 | u8g2_SendBuffer(&u8g2);
31 | }
32 | MSH_CMD_EXPORT(u8g2_ssd1306_12864_sw_i2c_example, i2c ssd1306 software i2c sample);
33 |
--------------------------------------------------------------------------------
/examples/ssd1306_12864_sw_i2c_example.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | // You may reference Drivers/drv_gpio.c for pinout
7 | // In u8x8.h #define U8X8_USE_PINS
8 | #define OLED_I2C_PIN_SCL 22 // PB6
9 | #define OLED_I2C_PIN_SDA 23 // PB7
10 |
11 | // Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
12 | static U8G2_SSD1306_128X64_NONAME_F_SW_I2C u8g2(U8G2_R0,
13 | /* clock=*/ OLED_I2C_PIN_SCL,
14 | /* data=*/ OLED_I2C_PIN_SDA,
15 | /* reset=*/ U8X8_PIN_NONE);
16 | // All Boards without Reset of the Display
17 |
18 | static void u8g2_ssd1306_12864_sw_i2c_example(int argc,char *argv[])
19 | {
20 | u8g2.begin();
21 | u8g2.clearBuffer(); // clear the internal memory
22 | u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
23 | u8g2.drawStr(1, 18, "U8g2 on RT-Thread"); // write something to the internal memory
24 | u8g2.sendBuffer(); // transfer internal memory to the display
25 | u8g2.setFont(u8g2_font_unifont_t_symbols);
26 | u8g2.drawGlyph(112, 56, 0x2603 );
27 | u8g2.sendBuffer();
28 | }
29 | MSH_CMD_EXPORT(u8g2_ssd1306_12864_sw_i2c_example, i2c ssd1306 software i2c sample);
30 |
--------------------------------------------------------------------------------
/examples/st7920_12864_8080_example.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | // You may reference Drivers/drv_gpio.c for pinout
7 | // In u8x8.h #define U8X8_USE_PINS
8 |
9 | #define ST7920_8080_PIN_D0 31 // PB15
10 | #define ST7920_8080_PIN_D1 30 // PB14
11 | #define ST7920_8080_PIN_D2 29 // PB13
12 | #define ST7920_8080_PIN_D3 28 // PB12
13 | #define ST7920_8080_PIN_D4 38 // PC6
14 | #define ST7920_8080_PIN_D5 39 // PC7
15 | #define ST7920_8080_PIN_D6 40 // PC8
16 | #define ST7920_8080_PIN_D7 41 // PC9
17 | #define ST7920_8080_PIN_EN 15 // PA15
18 | #define ST7920_8080_PIN_CS U8X8_PIN_NONE
19 | #define ST7920_8080_PIN_DC 11 // PA11
20 | #define ST7920_8080_PIN_RST 12 // PA12
21 |
22 | void u8x8_SetPin_8Bit_8080(u8x8_t *u8x8, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7, uint8_t wr, uint8_t cs, uint8_t dc, uint8_t reset)
23 | {
24 | u8x8_SetPin(u8x8, U8X8_PIN_D0, d0);
25 | u8x8_SetPin(u8x8, U8X8_PIN_D1, d1);
26 | u8x8_SetPin(u8x8, U8X8_PIN_D2, d2);
27 | u8x8_SetPin(u8x8, U8X8_PIN_D3, d3);
28 | u8x8_SetPin(u8x8, U8X8_PIN_D4, d4);
29 | u8x8_SetPin(u8x8, U8X8_PIN_D5, d5);
30 | u8x8_SetPin(u8x8, U8X8_PIN_D6, d6);
31 | u8x8_SetPin(u8x8, U8X8_PIN_D7, d7);
32 | u8x8_SetPin(u8x8, U8X8_PIN_E, wr);
33 | u8x8_SetPin(u8x8, U8X8_PIN_CS, cs);
34 | u8x8_SetPin(u8x8, U8X8_PIN_DC, dc);
35 | u8x8_SetPin(u8x8, U8X8_PIN_RESET, reset);
36 | }
37 |
38 | static void u8g2_st7920_12864_8080_example(int argc,char *argv[])
39 | {
40 | u8g2_t u8g2;
41 |
42 | // Initialization
43 | u8g2_Setup_st7920_p_128x64_f(&u8g2, U8G2_R0, u8x8_byte_8bit_8080mode, u8x8_gpio_and_delay_rtthread);
44 | u8x8_SetPin_8Bit_8080(u8g2_GetU8x8(&u8g2),
45 | ST7920_8080_PIN_D0, ST7920_8080_PIN_D1,
46 | ST7920_8080_PIN_D2, ST7920_8080_PIN_D3,
47 | ST7920_8080_PIN_D4, ST7920_8080_PIN_D5,
48 | ST7920_8080_PIN_D6, ST7920_8080_PIN_D7,
49 | ST7920_8080_PIN_EN, ST7920_8080_PIN_CS,
50 | ST7920_8080_PIN_DC, ST7920_8080_PIN_RST);
51 |
52 | u8g2_InitDisplay(&u8g2);
53 | u8g2_SetPowerSave(&u8g2, 0);
54 |
55 | // Draw Graphics
56 | /* full buffer example, setup procedure ends in _f */
57 | u8g2_ClearBuffer(&u8g2);
58 | u8g2_SetFont(&u8g2, u8g2_font_baby_tf);
59 | u8g2_DrawStr(&u8g2, 1, 18, "U8g2 on RT-Thread");
60 | u8g2_SendBuffer(&u8g2);
61 |
62 | u8g2_SetFont(&u8g2, u8g2_font_unifont_t_symbols);
63 | u8g2_DrawGlyph(&u8g2, 112, 56, 0x2603 );
64 | u8g2_SendBuffer(&u8g2);
65 | }
66 | MSH_CMD_EXPORT(u8g2_st7920_12864_8080_example, st7920 12864 LCD sample);
67 |
--------------------------------------------------------------------------------
/examples/st7920_12864_8080_example.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | // You may reference Drivers/drv_gpio.c for pinout
7 | // In u8x8.h #define U8X8_USE_PINS
8 |
9 | #define ST7920_8080_PIN_D0 31 // PB15
10 | #define ST7920_8080_PIN_D1 30 // PB14
11 | #define ST7920_8080_PIN_D2 29 // PB13
12 | #define ST7920_8080_PIN_D3 28 // PB12
13 | #define ST7920_8080_PIN_D4 38 // PC6
14 | #define ST7920_8080_PIN_D5 39 // PC7
15 | #define ST7920_8080_PIN_D6 40 // PC8
16 | #define ST7920_8080_PIN_D7 41 // PC9
17 | #define ST7920_8080_PIN_EN 15 // PA15
18 | #define ST7920_8080_PIN_CS U8X8_PIN_NONE
19 | #define ST7920_8080_PIN_DC 11 // PA11
20 | #define ST7920_8080_PIN_RST 12 // PA12
21 |
22 | // Check https://github.com/olikraus/u8g2/wiki/u8g2setupcpp for all supported devices
23 | static U8G2_ST7920_128X64_F_8080 u8g2(U8G2_R0,
24 | ST7920_8080_PIN_D0,
25 | ST7920_8080_PIN_D1,
26 | ST7920_8080_PIN_D2,
27 | ST7920_8080_PIN_D3,
28 | ST7920_8080_PIN_D4,
29 | ST7920_8080_PIN_D5,
30 | ST7920_8080_PIN_D6,
31 | ST7920_8080_PIN_D7,
32 | /*enable=*/ ST7920_8080_PIN_EN,
33 | /*cs=*/ ST7920_8080_PIN_CS,
34 | /*dc=*/ ST7920_8080_PIN_DC,
35 | /*reset=*/ ST7920_8080_PIN_RST);
36 |
37 | static void u8g2_st7920_12864_8080_example(int argc,char *argv[])
38 | {
39 | u8g2.begin();
40 | u8g2.clearBuffer(); // clear the internal memory
41 | u8g2.setFont(u8g2_font_6x13_tr); // choose a suitable font
42 | u8g2.drawStr(1, 18, "U8g2 on RT-Thread"); // write something to the internal memory
43 | u8g2.sendBuffer(); // transfer internal memory to the display
44 | u8g2.setFont(u8g2_font_unifont_t_symbols);
45 | u8g2.drawGlyph(112, 56, 0x2603 );
46 | u8g2.sendBuffer();
47 | }
48 | MSH_CMD_EXPORT(u8g2_st7920_12864_8080_example, st7920 12864 LCD sample);
49 |
--------------------------------------------------------------------------------
/port/Print.cpp:
--------------------------------------------------------------------------------
1 | /*
2 | Print.cpp - Base class that provides print() and println()
3 | Copyright (c) 2008 David A. Mellis. All right reserved.
4 |
5 | This library is free software; you can redistribute it and/or
6 | modify it under the terms of the GNU Lesser General Public
7 | License as published by the Free Software Foundation; either
8 | version 2.1 of the License, or (at your option) any later version.
9 |
10 | This library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public
16 | License along with this library; if not, write to the Free Software
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 |
19 | Modified 23 November 2006 by David A. Mellis
20 | Modified 03 August 2015 by Chuck Todd
21 | */
22 |
23 | #include
24 | #include
25 | #include
26 | // Use Self-defined isnan isinf in Print.h
27 | //#include
28 |
29 | #include "Print.h"
30 |
31 | // Public Methods //////////////////////////////////////////////////////////////
32 |
33 | /* default implementation: may be overridden */
34 | size_t Print::write(const uint8_t *buffer, size_t size)
35 | {
36 | size_t n = 0;
37 | while (size--) {
38 | if (write(*buffer++)) n++;
39 | else break;
40 | }
41 | return n;
42 | }
43 |
44 | size_t Print::print(const char str[])
45 | {
46 | return write(str);
47 | }
48 |
49 | size_t Print::print(char c)
50 | {
51 | return write(c);
52 | }
53 |
54 | size_t Print::print(unsigned char b, int base)
55 | {
56 | return print((unsigned long) b, base);
57 | }
58 |
59 | size_t Print::print(int n, int base)
60 | {
61 | return print((long) n, base);
62 | }
63 |
64 | size_t Print::print(unsigned int n, int base)
65 | {
66 | return print((unsigned long) n, base);
67 | }
68 |
69 | size_t Print::print(long n, int base)
70 | {
71 | if (base == 0) {
72 | return write(n);
73 | } else if (base == 10) {
74 | if (n < 0) {
75 | int t = print('-');
76 | n = -n;
77 | return printNumber(n, 10) + t;
78 | }
79 | return printNumber(n, 10);
80 | } else {
81 | return printNumber(n, base);
82 | }
83 | }
84 |
85 | size_t Print::print(unsigned long n, int base)
86 | {
87 | if (base == 0) return write(n);
88 | else return printNumber(n, base);
89 | }
90 |
91 | size_t Print::print(double n, int digits)
92 | {
93 | return printFloat(n, digits);
94 | }
95 |
96 | size_t Print::print(const Printable& x)
97 | {
98 | return x.printTo(*this);
99 | }
100 |
101 | size_t Print::println(void)
102 | {
103 | return write("\r\n");
104 | }
105 |
106 | size_t Print::println(const char c[])
107 | {
108 | size_t n = print(c);
109 | n += println();
110 | return n;
111 | }
112 |
113 | size_t Print::println(char c)
114 | {
115 | size_t n = print(c);
116 | n += println();
117 | return n;
118 | }
119 |
120 | size_t Print::println(unsigned char b, int base)
121 | {
122 | size_t n = print(b, base);
123 | n += println();
124 | return n;
125 | }
126 |
127 | size_t Print::println(int num, int base)
128 | {
129 | size_t n = print(num, base);
130 | n += println();
131 | return n;
132 | }
133 |
134 | size_t Print::println(unsigned int num, int base)
135 | {
136 | size_t n = print(num, base);
137 | n += println();
138 | return n;
139 | }
140 |
141 | size_t Print::println(long num, int base)
142 | {
143 | size_t n = print(num, base);
144 | n += println();
145 | return n;
146 | }
147 |
148 | size_t Print::println(unsigned long num, int base)
149 | {
150 | size_t n = print(num, base);
151 | n += println();
152 | return n;
153 | }
154 |
155 | size_t Print::println(double num, int digits)
156 | {
157 | size_t n = print(num, digits);
158 | n += println();
159 | return n;
160 | }
161 |
162 | size_t Print::println(const Printable& x)
163 | {
164 | size_t n = print(x);
165 | n += println();
166 | return n;
167 | }
168 |
169 | // Private Methods /////////////////////////////////////////////////////////////
170 |
171 | size_t Print::printNumber(unsigned long n, uint8_t base)
172 | {
173 | char buf[8 * sizeof(long) + 1]; // Assumes 8-bit chars plus zero byte.
174 | char *str = &buf[sizeof(buf) - 1];
175 |
176 | *str = '\0';
177 |
178 | // prevent crash if called with base == 1
179 | if (base < 2) base = 10;
180 |
181 | do {
182 | char c = n % base;
183 | n /= base;
184 |
185 | *--str = c < 10 ? c + '0' : c + 'A' - 10;
186 | } while(n);
187 |
188 | return write(str);
189 | }
190 |
191 | size_t Print::printFloat(double number, uint8_t digits)
192 | {
193 | size_t n = 0;
194 |
195 | if (isnan(number)) return print("nan");
196 | if (isinf(number)) return print("inf");
197 | if (number > 4294967040.0) return print ("ovf"); // constant determined empirically
198 | if (number <-4294967040.0) return print ("ovf"); // constant determined empirically
199 |
200 | // Handle negative numbers
201 | if (number < 0.0)
202 | {
203 | n += print('-');
204 | number = -number;
205 | }
206 |
207 | // Round correctly so that print(1.999, 2) prints as "2.00"
208 | double rounding = 0.5;
209 | for (uint8_t i=0; i 0) {
221 | n += print('.');
222 | }
223 |
224 | // Extract digits from the remainder one at a time
225 | while (digits-- > 0)
226 | {
227 | remainder *= 10.0;
228 | unsigned int toPrint = (unsigned int)(remainder);
229 | n += print(toPrint);
230 | remainder -= toPrint;
231 | }
232 |
233 | return n;
234 | }
235 |
--------------------------------------------------------------------------------
/port/Print.h:
--------------------------------------------------------------------------------
1 | /*
2 | Print.h - Base class that provides print() and println()
3 | Copyright (c) 2008 David A. Mellis. All right reserved.
4 |
5 | This library is free software; you can redistribute it and/or
6 | modify it under the terms of the GNU Lesser General Public
7 | License as published by the Free Software Foundation; either
8 | version 2.1 of the License, or (at your option) any later version.
9 |
10 | This library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public
16 | License along with this library; if not, write to the Free Software
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 |
20 | #ifndef Print_h
21 | #define Print_h
22 |
23 | #include
24 | #include // for size_t
25 | #include
26 | #include "Printable.h"
27 |
28 | #define DEC 10
29 | #define HEX 16
30 | #define OCT 8
31 | #ifdef BIN // Prevent warnings if BIN is previously defined in "iotnx4.h" or similar
32 | #undef BIN
33 | #endif
34 | #define BIN 2
35 |
36 | class Print
37 | {
38 | private:
39 | int write_error;
40 | size_t printNumber(unsigned long, uint8_t);
41 | size_t printFloat(double, uint8_t);
42 | int isnan(double x) { return x != x; };
43 | int isinf(double x) { return !isnan(x) && isnan(x - x); };
44 | protected:
45 | void setWriteError(int err = 1) { write_error = err; }
46 | public:
47 | Print() : write_error(0) {}
48 |
49 | int getWriteError() { return write_error; }
50 | void clearWriteError() { setWriteError(0); }
51 |
52 | virtual size_t write(uint8_t) = 0;
53 | size_t write(const char *str) {
54 | if (str == NULL) return 0;
55 | return write((const uint8_t *)str, strlen(str));
56 | }
57 | virtual size_t write(const uint8_t *buffer, size_t size);
58 | size_t write(const char *buffer, size_t size) {
59 | return write((const uint8_t *)buffer, size);
60 | }
61 |
62 | // default to zero, meaning "a single write may block"
63 | // should be overriden by subclasses with buffering
64 | virtual int availableForWrite() { return 0; }
65 |
66 | // size_t print(const __FlashStringHelper *);
67 | // size_t print(const String &);
68 | size_t print(const char[]);
69 | size_t print(char);
70 | size_t print(unsigned char, int = DEC);
71 | size_t print(int, int = DEC);
72 | size_t print(unsigned int, int = DEC);
73 | size_t print(long, int = DEC);
74 | size_t print(unsigned long, int = DEC);
75 | size_t print(double, int = 2);
76 | size_t print(const Printable&);
77 |
78 | // size_t println(const __FlashStringHelper *);
79 | // size_t println(const String &s);
80 | size_t println(const char[]);
81 | size_t println(char);
82 | size_t println(unsigned char, int = DEC);
83 | size_t println(int, int = DEC);
84 | size_t println(unsigned int, int = DEC);
85 | size_t println(long, int = DEC);
86 | size_t println(unsigned long, int = DEC);
87 | size_t println(double, int = 2);
88 | size_t println(const Printable&);
89 | size_t println(void);
90 |
91 | virtual void flush() { /* Empty implementation for backward compatibility */ }
92 | };
93 |
94 | #endif
95 |
--------------------------------------------------------------------------------
/port/Printable.h:
--------------------------------------------------------------------------------
1 | /*
2 | Printable.h - Interface class that allows printing of complex types
3 | Copyright (c) 2011 Adrian McEwen. All right reserved.
4 |
5 | This library is free software; you can redistribute it and/or
6 | modify it under the terms of the GNU Lesser General Public
7 | License as published by the Free Software Foundation; either
8 | version 2.1 of the License, or (at your option) any later version.
9 |
10 | This library is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 | Lesser General Public License for more details.
14 |
15 | You should have received a copy of the GNU Lesser General Public
16 | License along with this library; if not, write to the Free Software
17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 | */
19 |
20 | #ifndef Printable_h
21 | #define Printable_h
22 |
23 | #include
24 |
25 | class Print;
26 |
27 | /** The Printable class provides a way for new classes to allow themselves to be printed.
28 | By deriving from Printable and implementing the printTo method, it will then be possible
29 | for users to print out instances of this class by passing them into the usual
30 | Print::print and Print::println methods.
31 | */
32 |
33 | class Printable
34 | {
35 | public:
36 | virtual size_t printTo(Print& p) const = 0;
37 | };
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/port/U8g2lib.cpp:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | U8g2lib.cpp
4 |
5 | Arduino specific functions
6 |
7 |
8 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
9 |
10 | Copyright (c) 2016, olikraus@gmail.com
11 | All rights reserved.
12 |
13 | Redistribution and use in source and binary forms, with or without modification,
14 | are permitted provided that the following conditions are met:
15 |
16 | * Redistributions of source code must retain the above copyright notice, this list
17 | of conditions and the following disclaimer.
18 |
19 | * Redistributions in binary form must reproduce the above copyright notice, this
20 | list of conditions and the following disclaimer in the documentation and/or other
21 | materials provided with the distribution.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 |
37 | */
38 |
39 |
40 | #include "U8g2lib.h"
41 |
42 | static Print *u8g2_print_for_screenshot;
43 |
44 |
45 | void u8g2_print_callback(const char *s)
46 | {
47 | // yield();
48 | u8g2_print_for_screenshot->print(s);
49 | }
50 |
51 | void U8G2::writeBufferPBM(Print &p)
52 | {
53 | u8g2_print_for_screenshot = &p;
54 | u8g2_WriteBufferPBM(getU8g2(), u8g2_print_callback);
55 | }
56 |
57 | void U8G2::writeBufferXBM(Print &p)
58 | {
59 | u8g2_print_for_screenshot = &p;
60 | u8g2_WriteBufferXBM(getU8g2(), u8g2_print_callback);
61 | }
62 |
63 | void U8G2::writeBufferPBM2(Print &p)
64 | {
65 | u8g2_print_for_screenshot = &p;
66 | u8g2_WriteBufferPBM2(getU8g2(), u8g2_print_callback);
67 | }
68 |
69 | void U8G2::writeBufferXBM2(Print &p)
70 | {
71 | u8g2_print_for_screenshot = &p;
72 | u8g2_WriteBufferXBM2(getU8g2(), u8g2_print_callback);
73 | }
74 |
75 |
76 |
77 |
--------------------------------------------------------------------------------
/port/u8g2_port.h:
--------------------------------------------------------------------------------
1 | #ifndef __U8G_PORT_H__
2 | #define __U8G_PORT_H__
3 |
4 | #ifdef __cplusplus
5 | extern "C" {
6 | #endif
7 |
8 | #include
9 | #include
10 | #if defined U8G2_USE_HW_SPI
11 | #include
12 | #endif
13 |
14 | #include
15 | #include
16 | #include
17 |
18 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
19 |
20 | #if defined U8G2_USE_HW_SPI
21 |
22 | #ifndef U8G2_SPI_BUS_NAME
23 | #define U8G2_SPI_BUS_NAME "spi1"
24 | #endif
25 |
26 | #ifndef U8G2_SPI_DEVICE_NAME
27 | #define U8G2_SPI_DEVICE_NAME "spi10"
28 | #endif
29 |
30 | uint8_t u8x8_byte_rtthread_4wire_hw_spi(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
31 |
32 | #endif
33 |
34 | #if defined U8G2_USE_HW_I2C
35 |
36 | #ifndef U8G2_I2C_DEVICE_NAME
37 | #define U8G2_I2C_DEVICE_NAME "i2c2"
38 | #endif
39 |
40 | uint8_t u8x8_byte_rtthread_hw_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
41 |
42 | #endif
43 |
44 | uint8_t u8x8_gpio_and_delay_rtthread(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr);
45 |
46 | #ifdef __cplusplus
47 | }
48 | #endif
49 |
50 | #endif /* __U8G_PORT_H__ */
51 |
--------------------------------------------------------------------------------
/src/u8g2_bitmap.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8g2_bitmap.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 | #include "u8g2.h"
37 |
38 |
39 | void u8g2_SetBitmapMode(u8g2_t *u8g2, uint8_t is_transparent) {
40 | u8g2->bitmap_transparency = is_transparent;
41 | }
42 |
43 | /*
44 | x,y Position on the display
45 | len Length of bitmap line in pixel. Note: This differs from u8glib which had a bytecount here.
46 | b Pointer to the bitmap line.
47 | Only draw pixels which are set.
48 | */
49 |
50 | void u8g2_DrawHorizontalBitmap(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, const uint8_t *b)
51 | {
52 | uint8_t mask;
53 | uint8_t color = u8g2->draw_color;
54 | uint8_t ncolor = (color == 0 ? 1 : 0);
55 |
56 | #ifdef U8G2_WITH_INTERSECTION
57 | if ( u8g2_IsIntersection(u8g2, x, y, x+len, y+1) == 0 )
58 | return;
59 | #endif /* U8G2_WITH_INTERSECTION */
60 |
61 | mask = 128;
62 | while(len > 0)
63 | {
64 | if ( *b & mask ) {
65 | u8g2->draw_color = color;
66 | u8g2_DrawHVLine(u8g2, x, y, 1, 0);
67 | } else if ( u8g2->bitmap_transparency == 0 ) {
68 | u8g2->draw_color = ncolor;
69 | u8g2_DrawHVLine(u8g2, x, y, 1, 0);
70 | }
71 |
72 | x++;
73 | mask >>= 1;
74 | if ( mask == 0 )
75 | {
76 | mask = 128;
77 | b++;
78 | }
79 | len--;
80 | }
81 | u8g2->draw_color = color;
82 | }
83 |
84 |
85 | /* u8glib compatible bitmap draw function */
86 | void u8g2_DrawBitmap(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t cnt, u8g2_uint_t h, const uint8_t *bitmap)
87 | {
88 | u8g2_uint_t w;
89 | w = cnt;
90 | w *= 8;
91 | #ifdef U8G2_WITH_INTERSECTION
92 | if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
93 | return;
94 | #endif /* U8G2_WITH_INTERSECTION */
95 |
96 | while( h > 0 )
97 | {
98 | u8g2_DrawHorizontalBitmap(u8g2, x, y, w, bitmap);
99 | bitmap += cnt;
100 | y++;
101 | h--;
102 | }
103 | }
104 |
105 |
106 |
107 | void u8g2_DrawHXBM(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, const uint8_t *b)
108 | {
109 | uint8_t mask;
110 | uint8_t color = u8g2->draw_color;
111 | uint8_t ncolor = (color == 0 ? 1 : 0);
112 | #ifdef U8G2_WITH_INTERSECTION
113 | if ( u8g2_IsIntersection(u8g2, x, y, x+len, y+1) == 0 )
114 | return;
115 | #endif /* U8G2_WITH_INTERSECTION */
116 |
117 | mask = 1;
118 | while(len > 0) {
119 | if ( *b & mask ) {
120 | u8g2->draw_color = color;
121 | u8g2_DrawHVLine(u8g2, x, y, 1, 0);
122 | } else if ( u8g2->bitmap_transparency == 0 ) {
123 | u8g2->draw_color = ncolor;
124 | u8g2_DrawHVLine(u8g2, x, y, 1, 0);
125 | }
126 | x++;
127 | mask <<= 1;
128 | if ( mask == 0 )
129 | {
130 | mask = 1;
131 | b++;
132 | }
133 | len--;
134 | }
135 | u8g2->draw_color = color;
136 | }
137 |
138 |
139 | void u8g2_DrawXBM(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, const uint8_t *bitmap)
140 | {
141 | u8g2_uint_t blen;
142 | blen = w;
143 | blen += 7;
144 | blen >>= 3;
145 | #ifdef U8G2_WITH_INTERSECTION
146 | if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
147 | return;
148 | #endif /* U8G2_WITH_INTERSECTION */
149 |
150 | while( h > 0 )
151 | {
152 | u8g2_DrawHXBM(u8g2, x, y, w, bitmap);
153 | bitmap += blen;
154 | y++;
155 | h--;
156 | }
157 | }
158 |
159 |
160 |
161 |
162 |
163 |
164 | void u8g2_DrawHXBMP(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t len, const uint8_t *b)
165 | {
166 | uint8_t mask;
167 | uint8_t color = u8g2->draw_color;
168 | uint8_t ncolor = (color == 0 ? 1 : 0);
169 | #ifdef U8G2_WITH_INTERSECTION
170 | if ( u8g2_IsIntersection(u8g2, x, y, x+len, y+1) == 0 )
171 | return;
172 | #endif /* U8G2_WITH_INTERSECTION */
173 |
174 | mask = 1;
175 | while(len > 0)
176 | {
177 | if( u8x8_pgm_read(b) & mask ) {
178 | u8g2->draw_color = color;
179 | u8g2_DrawHVLine(u8g2, x, y, 1, 0);
180 | } else if( u8g2->bitmap_transparency == 0 ) {
181 | u8g2->draw_color = ncolor;
182 | u8g2_DrawHVLine(u8g2, x, y, 1, 0);
183 | }
184 |
185 | x++;
186 | mask <<= 1;
187 | if ( mask == 0 )
188 | {
189 | mask = 1;
190 | b++;
191 | }
192 | len--;
193 | }
194 | u8g2->draw_color = color;
195 | }
196 |
197 |
198 | void u8g2_DrawXBMP(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, const uint8_t *bitmap)
199 | {
200 | u8g2_uint_t blen;
201 | blen = w;
202 | blen += 7;
203 | blen >>= 3;
204 | #ifdef U8G2_WITH_INTERSECTION
205 | if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
206 | return;
207 | #endif /* U8G2_WITH_INTERSECTION */
208 |
209 | while( h > 0 )
210 | {
211 | u8g2_DrawHXBMP(u8g2, x, y, w, bitmap);
212 | bitmap += blen;
213 | y++;
214 | h--;
215 | }
216 | }
217 |
218 |
219 |
--------------------------------------------------------------------------------
/src/u8g2_box.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8g2_box.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 | #include "u8g2.h"
37 |
38 | /*
39 | draw a filled box
40 | restriction: does not work for w = 0 or h = 0
41 | */
42 | void u8g2_DrawBox(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h)
43 | {
44 | #ifdef U8G2_WITH_INTERSECTION
45 | if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
46 | return;
47 | #endif /* U8G2_WITH_INTERSECTION */
48 | while( h != 0 )
49 | {
50 | u8g2_DrawHVLine(u8g2, x, y, w, 0);
51 | y++;
52 | h--;
53 | }
54 | }
55 |
56 |
57 | /*
58 | draw a frame (empty box)
59 | restriction: does not work for w = 0 or h = 0
60 | */
61 | void u8g2_DrawFrame(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h)
62 | {
63 | u8g2_uint_t xtmp = x;
64 |
65 | #ifdef U8G2_WITH_INTERSECTION
66 | if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
67 | return;
68 | #endif /* U8G2_WITH_INTERSECTION */
69 |
70 | u8g2_DrawHVLine(u8g2, x, y, w, 0);
71 | if (h >= 2) {
72 | h-=2;
73 | y++;
74 | if (h > 0) {
75 | u8g2_DrawHVLine(u8g2, x, y, h, 1);
76 | x+=w;
77 | x--;
78 | u8g2_DrawHVLine(u8g2, x, y, h, 1);
79 | y+=h;
80 | }
81 | u8g2_DrawHVLine(u8g2, xtmp, y, w, 0);
82 | }
83 | }
84 |
85 |
86 |
87 |
88 | void u8g2_DrawRBox(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, u8g2_uint_t r)
89 | {
90 | u8g2_uint_t xl, yu;
91 | u8g2_uint_t yl, xr;
92 |
93 | #ifdef U8G2_WITH_INTERSECTION
94 | if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
95 | return;
96 | #endif /* U8G2_WITH_INTERSECTION */
97 |
98 | xl = x;
99 | xl += r;
100 | yu = y;
101 | yu += r;
102 |
103 | xr = x;
104 | xr += w;
105 | xr -= r;
106 | xr -= 1;
107 |
108 | yl = y;
109 | yl += h;
110 | yl -= r;
111 | yl -= 1;
112 |
113 | u8g2_DrawDisc(u8g2, xl, yu, r, U8G2_DRAW_UPPER_LEFT);
114 | u8g2_DrawDisc(u8g2, xr, yu, r, U8G2_DRAW_UPPER_RIGHT);
115 | u8g2_DrawDisc(u8g2, xl, yl, r, U8G2_DRAW_LOWER_LEFT);
116 | u8g2_DrawDisc(u8g2, xr, yl, r, U8G2_DRAW_LOWER_RIGHT);
117 |
118 | {
119 | u8g2_uint_t ww, hh;
120 |
121 | ww = w;
122 | ww -= r;
123 | ww -= r;
124 | xl++;
125 | yu++;
126 |
127 | if ( ww >= 3 )
128 | {
129 | ww -= 2;
130 | u8g2_DrawBox(u8g2, xl, y, ww, r+1);
131 | u8g2_DrawBox(u8g2, xl, yl, ww, r+1);
132 | }
133 |
134 | hh = h;
135 | hh -= r;
136 | hh -= r;
137 | //h--;
138 | if ( hh >= 3 )
139 | {
140 | hh -= 2;
141 | u8g2_DrawBox(u8g2, x, yu, w, hh);
142 | }
143 | }
144 | }
145 |
146 |
147 | void u8g2_DrawRFrame(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8g2_uint_t w, u8g2_uint_t h, u8g2_uint_t r)
148 | {
149 | u8g2_uint_t xl, yu;
150 |
151 | #ifdef U8G2_WITH_INTERSECTION
152 | if ( u8g2_IsIntersection(u8g2, x, y, x+w, y+h) == 0 )
153 | return;
154 | #endif /* U8G2_WITH_INTERSECTION */
155 |
156 | xl = x;
157 | xl += r;
158 | yu = y;
159 | yu += r;
160 |
161 | {
162 | u8g2_uint_t yl, xr;
163 |
164 | xr = x;
165 | xr += w;
166 | xr -= r;
167 | xr -= 1;
168 |
169 | yl = y;
170 | yl += h;
171 | yl -= r;
172 | yl -= 1;
173 |
174 | u8g2_DrawCircle(u8g2, xl, yu, r, U8G2_DRAW_UPPER_LEFT);
175 | u8g2_DrawCircle(u8g2, xr, yu, r, U8G2_DRAW_UPPER_RIGHT);
176 | u8g2_DrawCircle(u8g2, xl, yl, r, U8G2_DRAW_LOWER_LEFT);
177 | u8g2_DrawCircle(u8g2, xr, yl, r, U8G2_DRAW_LOWER_RIGHT);
178 | }
179 |
180 | {
181 | u8g2_uint_t ww, hh;
182 |
183 | ww = w;
184 | ww -= r;
185 | ww -= r;
186 | hh = h;
187 | hh -= r;
188 | hh -= r;
189 |
190 | xl++;
191 | yu++;
192 |
193 | if ( ww >= 3 )
194 | {
195 | ww -= 2;
196 | h--;
197 | u8g2_DrawHLine(u8g2, xl, y, ww);
198 | u8g2_DrawHLine(u8g2, xl, y+h, ww);
199 | }
200 |
201 | if ( hh >= 3 )
202 | {
203 | hh -= 2;
204 | w--;
205 | u8g2_DrawVLine(u8g2, x, yu, hh);
206 | u8g2_DrawVLine(u8g2, x+w, yu, hh);
207 | }
208 | }
209 | }
210 |
211 |
--------------------------------------------------------------------------------
/src/u8g2_buffer.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8g2_buffer.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 | #include "u8g2.h"
37 | #include
38 |
39 | /*============================================*/
40 | void u8g2_ClearBuffer(u8g2_t *u8g2)
41 | {
42 | size_t cnt;
43 | cnt = u8g2_GetU8x8(u8g2)->display_info->tile_width;
44 | cnt *= u8g2->tile_buf_height;
45 | cnt *= 8;
46 | memset(u8g2->tile_buf_ptr, 0, cnt);
47 | }
48 |
49 | /*============================================*/
50 |
51 | static void u8g2_send_tile_row(u8g2_t *u8g2, uint8_t src_tile_row, uint8_t dest_tile_row)
52 | {
53 | uint8_t *ptr;
54 | uint16_t offset;
55 | uint8_t w;
56 |
57 | w = u8g2_GetU8x8(u8g2)->display_info->tile_width;
58 | offset = src_tile_row;
59 | ptr = u8g2->tile_buf_ptr;
60 | offset *= w;
61 | offset *= 8;
62 | ptr += offset;
63 | u8x8_DrawTile(u8g2_GetU8x8(u8g2), 0, dest_tile_row, w, ptr);
64 | }
65 |
66 | /*
67 | write the buffer to the display RAM.
68 | For most displays, this will make the content visible to the user.
69 | Some displays (like the SSD1606) require a u8x8_RefreshDisplay()
70 | */
71 | static void u8g2_send_buffer(u8g2_t *u8g2) U8X8_NOINLINE;
72 | static void u8g2_send_buffer(u8g2_t *u8g2)
73 | {
74 | uint8_t src_row;
75 | uint8_t src_max;
76 | uint8_t dest_row;
77 | uint8_t dest_max;
78 |
79 | src_row = 0;
80 | src_max = u8g2->tile_buf_height;
81 | dest_row = u8g2->tile_curr_row;
82 | dest_max = u8g2_GetU8x8(u8g2)->display_info->tile_height;
83 |
84 | do
85 | {
86 | u8g2_send_tile_row(u8g2, src_row, dest_row);
87 | src_row++;
88 | dest_row++;
89 | } while( src_row < src_max && dest_row < dest_max );
90 | }
91 |
92 | /* same as u8g2_send_buffer but also send the DISPLAY_REFRESH message (used by SSD1606) */
93 | void u8g2_SendBuffer(u8g2_t *u8g2)
94 | {
95 | u8g2_send_buffer(u8g2);
96 | u8x8_RefreshDisplay( u8g2_GetU8x8(u8g2) );
97 | }
98 |
99 | /*============================================*/
100 | void u8g2_SetBufferCurrTileRow(u8g2_t *u8g2, uint8_t row)
101 | {
102 | u8g2->tile_curr_row = row;
103 | u8g2->cb->update_dimension(u8g2);
104 | u8g2->cb->update_page_win(u8g2);
105 | }
106 |
107 | void u8g2_FirstPage(u8g2_t *u8g2)
108 | {
109 | if ( u8g2->is_auto_page_clear )
110 | {
111 | u8g2_ClearBuffer(u8g2);
112 | }
113 | u8g2_SetBufferCurrTileRow(u8g2, 0);
114 | }
115 |
116 | uint8_t u8g2_NextPage(u8g2_t *u8g2)
117 | {
118 | uint8_t row;
119 | u8g2_send_buffer(u8g2);
120 | row = u8g2->tile_curr_row;
121 | row += u8g2->tile_buf_height;
122 | if ( row >= u8g2_GetU8x8(u8g2)->display_info->tile_height )
123 | {
124 | u8x8_RefreshDisplay( u8g2_GetU8x8(u8g2) );
125 | return 0;
126 | }
127 | if ( u8g2->is_auto_page_clear )
128 | {
129 | u8g2_ClearBuffer(u8g2);
130 | }
131 | u8g2_SetBufferCurrTileRow(u8g2, row);
132 | return 1;
133 | }
134 |
135 |
136 |
137 | /*============================================*/
138 | /*
139 | Description:
140 | Update a sub area of the display, given by tile position, width and height.
141 | The arguments are "tile" coordinates. Any u8g2 rotation is ignored.
142 | This procedure only checks whether full buffer mode is active.
143 | There is no error checking for the arguments: It is the responsibility of the
144 | user to ensure, that the provided arguments are correct.
145 |
146 | Limitations:
147 | - Only available in full buffer mode (will not do anything in page mode)
148 | - Tile positions and sizes (pixel position divided by 8)
149 | - Any display rotation/mirror is ignored
150 | - Only works with displays, which support U8x8 API
151 | - Will not send the e-paper refresh message (will probably not work with e-paper devices)
152 | */
153 | void u8g2_UpdateDisplayArea(u8g2_t *u8g2, uint8_t tx, uint8_t ty, uint8_t tw, uint8_t th)
154 | {
155 | uint16_t page_size;
156 | uint8_t *ptr;
157 |
158 | /* check, whether we are in full buffer mode */
159 | if ( u8g2->tile_buf_height != u8g2_GetU8x8(u8g2)->display_info->tile_height )
160 | return; /* not in full buffer mode, do nothing */
161 |
162 | page_size = u8g2->pixel_buf_width; /* 8*u8g2->u8g2_GetU8x8(u8g2)->display_info->tile_width */
163 |
164 | ptr = u8g2_GetBufferPtr(u8g2);
165 | ptr += tx*8;
166 | ptr += page_size*ty;
167 |
168 | while( th > 0 )
169 | {
170 | u8x8_DrawTile( u8g2_GetU8x8(u8g2), tx, ty, tw, ptr );
171 | ptr += page_size;
172 | ty++;
173 | th--;
174 | }
175 | }
176 |
177 | /* same as sendBuffer, but does not send the ePaper refresh message */
178 | void u8g2_UpdateDisplay(u8g2_t *u8g2)
179 | {
180 | u8g2_send_buffer(u8g2);
181 | }
182 |
183 |
184 | /*============================================*/
185 |
186 | /* vertical_top memory architecture */
187 | void u8g2_WriteBufferPBM(u8g2_t *u8g2, void (*out)(const char *s))
188 | {
189 | u8x8_capture_write_pbm_pre(u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), out);
190 | u8x8_capture_write_pbm_buffer(u8g2_GetBufferPtr(u8g2), u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), u8x8_capture_get_pixel_1, out);
191 | }
192 |
193 | void u8g2_WriteBufferXBM(u8g2_t *u8g2, void (*out)(const char *s))
194 | {
195 | u8x8_capture_write_xbm_pre(u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), out);
196 | u8x8_capture_write_xbm_buffer(u8g2_GetBufferPtr(u8g2), u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), u8x8_capture_get_pixel_1, out);
197 | }
198 |
199 |
200 | /* horizontal right memory architecture */
201 | /* SH1122, LD7032, ST7920, ST7986, LC7981, T6963, SED1330, RA8835, MAX7219, LS0 */
202 | void u8g2_WriteBufferPBM2(u8g2_t *u8g2, void (*out)(const char *s))
203 | {
204 | u8x8_capture_write_pbm_pre(u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), out);
205 | u8x8_capture_write_pbm_buffer(u8g2_GetBufferPtr(u8g2), u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), u8x8_capture_get_pixel_2, out);
206 | }
207 |
208 | void u8g2_WriteBufferXBM2(u8g2_t *u8g2, void (*out)(const char *s))
209 | {
210 | u8x8_capture_write_xbm_pre(u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), out);
211 | u8x8_capture_write_xbm_buffer(u8g2_GetBufferPtr(u8g2), u8g2_GetBufferTileWidth(u8g2), u8g2_GetBufferTileHeight(u8g2), u8x8_capture_get_pixel_2, out);
212 | }
213 |
214 |
--------------------------------------------------------------------------------
/src/u8g2_cleardisplay.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8g2_cleardisplay.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 | #include "u8g2.h"
36 |
37 | /* Clear screen buffer & display reliable for all u8g2 displays. */
38 | /* This is done with u8g2 picture loop, because we can not use the u8x8 function in all cases */
39 | void u8g2_ClearDisplay(u8g2_t *u8g2)
40 | {
41 | u8g2_FirstPage(u8g2);
42 | do {
43 | } while ( u8g2_NextPage(u8g2) );
44 | /*
45 | This function is usually called during startup (u8g2.begin()).
46 | However the user might want to use full buffer mode with clear and
47 | send commands.
48 | This will not work because the current tile row is modified by the picture
49 | loop above. To fix this, reset the tile row to 0, issue #370
50 | A workaround would be, that the user sets the current tile row to 0 manually.
51 | */
52 | u8g2_SetBufferCurrTileRow(u8g2, 0);
53 | }
54 |
55 |
--------------------------------------------------------------------------------
/src/u8g2_fonts.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/src/u8g2_fonts.c
--------------------------------------------------------------------------------
/src/u8g2_input_value.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8g2_input_value.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 | #include "u8g2.h"
37 |
38 | /*
39 | return:
40 | 0: value is not changed (HOME/Break Button pressed)
41 | 1: value has been updated
42 | */
43 |
44 | uint8_t u8g2_UserInterfaceInputValue(u8g2_t *u8g2, const char *title, const char *pre, uint8_t *value, uint8_t lo, uint8_t hi, uint8_t digits, const char *post)
45 | {
46 | uint8_t line_height;
47 | uint8_t height;
48 | u8g2_uint_t pixel_height;
49 | u8g2_uint_t y, yy;
50 | u8g2_uint_t pixel_width;
51 | u8g2_uint_t x, xx;
52 |
53 | uint8_t local_value = *value;
54 | //uint8_t r; /* not used ??? */
55 | uint8_t event;
56 |
57 | /* only horizontal strings are supported, so force this here */
58 | u8g2_SetFontDirection(u8g2, 0);
59 |
60 | /* force baseline position */
61 | u8g2_SetFontPosBaseline(u8g2);
62 |
63 | /* calculate line height */
64 | line_height = u8g2_GetAscent(u8g2);
65 | line_height -= u8g2_GetDescent(u8g2);
66 |
67 |
68 | /* calculate overall height of the input value box */
69 | height = 1; /* value input line */
70 | height += u8x8_GetStringLineCnt(title);
71 |
72 | /* calculate the height in pixel */
73 | pixel_height = height;
74 | pixel_height *= line_height;
75 |
76 |
77 | /* calculate offset from top */
78 | y = 0;
79 | if ( pixel_height < u8g2_GetDisplayHeight(u8g2) )
80 | {
81 | y = u8g2_GetDisplayHeight(u8g2);
82 | y -= pixel_height;
83 | y /= 2;
84 | }
85 |
86 | /* calculate offset from left for the label */
87 | x = 0;
88 | pixel_width = u8g2_GetUTF8Width(u8g2, pre);
89 | pixel_width += u8g2_GetUTF8Width(u8g2, "0") * digits;
90 | pixel_width += u8g2_GetUTF8Width(u8g2, post);
91 | if ( pixel_width < u8g2_GetDisplayWidth(u8g2) )
92 | {
93 | x = u8g2_GetDisplayWidth(u8g2);
94 | x -= pixel_width;
95 | x /= 2;
96 | }
97 |
98 | /* event loop */
99 | for(;;)
100 | {
101 | u8g2_FirstPage(u8g2);
102 | do
103 | {
104 | /* render */
105 | yy = y;
106 | yy += u8g2_DrawUTF8Lines(u8g2, 0, yy, u8g2_GetDisplayWidth(u8g2), line_height, title);
107 | xx = x;
108 | xx += u8g2_DrawUTF8(u8g2, xx, yy, pre);
109 | xx += u8g2_DrawUTF8(u8g2, xx, yy, u8x8_u8toa(local_value, digits));
110 | u8g2_DrawUTF8(u8g2, xx, yy, post);
111 | } while( u8g2_NextPage(u8g2) );
112 |
113 | #ifdef U8G2_REF_MAN_PIC
114 | return 0;
115 | #endif
116 |
117 | for(;;)
118 | {
119 | event = u8x8_GetMenuEvent(u8g2_GetU8x8(u8g2));
120 | if ( event == U8X8_MSG_GPIO_MENU_SELECT )
121 | {
122 | *value = local_value;
123 | return 1;
124 | }
125 | else if ( event == U8X8_MSG_GPIO_MENU_HOME )
126 | {
127 | return 0;
128 | }
129 | else if ( event == U8X8_MSG_GPIO_MENU_NEXT || event == U8X8_MSG_GPIO_MENU_UP )
130 | {
131 | if ( local_value >= hi )
132 | local_value = lo;
133 | else
134 | local_value++;
135 | break;
136 | }
137 | else if ( event == U8X8_MSG_GPIO_MENU_PREV || event == U8X8_MSG_GPIO_MENU_DOWN )
138 | {
139 | if ( local_value <= lo )
140 | local_value = hi;
141 | else
142 | local_value--;
143 | break;
144 | }
145 | }
146 | }
147 |
148 | /* never reached */
149 | //return r;
150 | }
151 |
--------------------------------------------------------------------------------
/src/u8g2_intersection.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8g2_intersection.c
4 |
5 | Intersection calculation, code taken from u8g_clip.c
6 |
7 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
8 |
9 | Copyright (c) 2016, olikraus@gmail.com
10 | All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without modification,
13 | are permitted provided that the following conditions are met:
14 |
15 | * Redistributions of source code must retain the above copyright notice, this list
16 | of conditions and the following disclaimer.
17 |
18 | * Redistributions in binary form must reproduce the above copyright notice, this
19 | list of conditions and the following disclaimer in the documentation and/or other
20 | materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 |
36 | */
37 |
38 | #include "u8g2.h"
39 |
40 | #ifdef __GNUC__
41 | #define U8G2_ALWAYS_INLINE __inline__ __attribute__((always_inline))
42 | #else
43 | #define U8G2_ALWAYS_INLINE
44 | #endif
45 |
46 |
47 | #if defined(U8G2_WITH_INTERSECTION) || defined(U8G2_WITH_CLIP_WINDOW_SUPPORT)
48 |
49 | #ifdef OLD_VERSION_WITH_SYMETRIC_BOUNDARIES
50 |
51 | /*
52 | intersection assumptions:
53 | a1 <= a2 is always true
54 |
55 | minimized version
56 | ---1----0 1 b1 <= a2 && b1 > b2
57 | -----1--0 1 b2 >= a1 && b1 > b2
58 | ---1-1--- 1 b1 <= a2 && b2 >= a1
59 | */
60 |
61 |
62 | /*
63 | calculate the intersection between a0/a1 and v0/v1
64 | The intersection check returns one if the range of a0/a1 has an intersection with v0/v1.
65 | The intersection check includes the boundary values v1 and a1.
66 |
67 | The following asserts will succeed:
68 | assert( u8g2_is_intersection_decision_tree(4, 6, 7, 9) == 0 );
69 | assert( u8g2_is_intersection_decision_tree(4, 6, 6, 9) != 0 );
70 | assert( u8g2_is_intersection_decision_tree(6, 9, 4, 6) != 0 );
71 | assert( u8g2_is_intersection_decision_tree(7, 9, 4, 6) == 0 );
72 | */
73 |
74 | //static uint8_t U8G2_ALWAYS_INLINE u8g2_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1)
75 | static uint8_t u8g2_is_intersection_decision_tree(u8g2_uint_t a0, u8g2_uint_t a1, u8g2_uint_t v0, u8g2_uint_t v1)
76 | {
77 | if ( v0 <= a1 )
78 | {
79 | if ( v1 >= a0 )
80 | {
81 | return 1;
82 | }
83 | else
84 | {
85 | if ( v0 > v1 )
86 | {
87 | return 1;
88 | }
89 | else
90 | {
91 | return 0;
92 | }
93 | }
94 | }
95 | else
96 | {
97 | if ( v1 >= a0 )
98 | {
99 | if ( v0 > v1 )
100 | {
101 | return 1;
102 | }
103 | else
104 | {
105 | return 0;
106 | }
107 | }
108 | else
109 | {
110 | return 0;
111 | }
112 | }
113 | }
114 |
115 | #endif /* OLD_VERSION_WITH_SYMETRIC_BOUNDARIES */
116 |
117 |
118 | /*
119 | version with asymetric boundaries.
120 | a1 and v1 are excluded
121 | v0 == v1 is not support end return 1
122 | */
123 | uint8_t u8g2_is_intersection_decision_tree(u8g2_uint_t a0, u8g2_uint_t a1, u8g2_uint_t v0, u8g2_uint_t v1)
124 | {
125 | if ( v0 < a1 ) // v0 <= a1
126 | {
127 | if ( v1 > a0 ) // v1 >= a0
128 | {
129 | return 1;
130 | }
131 | else
132 | {
133 | if ( v0 > v1 ) // v0 > v1
134 | {
135 | return 1;
136 | }
137 | else
138 | {
139 | return 0;
140 | }
141 | }
142 | }
143 | else
144 | {
145 | if ( v1 > a0 ) // v1 >= a0
146 | {
147 | if ( v0 > v1 ) // v0 > v1
148 | {
149 | return 1;
150 | }
151 | else
152 | {
153 | return 0;
154 | }
155 | }
156 | else
157 | {
158 | return 0;
159 | }
160 | }
161 | }
162 |
163 |
164 |
165 | /* upper limits are not included (asymetric boundaries) */
166 | uint8_t u8g2_IsIntersection(u8g2_t *u8g2, u8g2_uint_t x0, u8g2_uint_t y0, u8g2_uint_t x1, u8g2_uint_t y1)
167 | {
168 | if ( u8g2_is_intersection_decision_tree(u8g2->user_y0, u8g2->user_y1, y0, y1) == 0 )
169 | return 0;
170 |
171 | return u8g2_is_intersection_decision_tree(u8g2->user_x0, u8g2->user_x1, x0, x1);
172 | }
173 |
174 |
175 | #endif /* U8G2_WITH_INTERSECTION */
176 |
177 |
--------------------------------------------------------------------------------
/src/u8g2_kerning.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8g2_kerning.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 | #include "u8g2.h"
37 |
38 | /* this function is used as "u8g2_get_kerning_cb" */
39 | /*
40 | uint8_t u8g2_GetNullKerning(u8g2_t *u8g2, uint16_t e1, uint16_t e2)
41 | {
42 | return 0;
43 | }
44 | */
45 |
46 | /* this function is used as "u8g2_get_kerning_cb" */
47 | uint8_t u8g2_GetKerning(U8X8_UNUSED u8g2_t *u8g2, u8g2_kerning_t *kerning, uint16_t e1, uint16_t e2)
48 | {
49 | uint16_t i1, i2, cnt, end;
50 | if ( kerning == NULL )
51 | return 0;
52 |
53 | /* search for the encoding in the first table */
54 | cnt = kerning->first_table_cnt;
55 | cnt--; /* ignore the last element of the table, which is 0x0ffff */
56 | for( i1 = 0; i1 < cnt; i1++ )
57 | {
58 | if ( kerning->first_encoding_table[i1] == e1 )
59 | break;
60 | }
61 | if ( i1 >= cnt )
62 | return 0; /* e1 not part of the kerning table, return 0 */
63 |
64 | /* get the upper index for i2 */
65 | end = kerning->index_to_second_table[i1+1];
66 | for( i2 = kerning->index_to_second_table[i1]; i2 < end; i2++ )
67 | {
68 | if ( kerning->second_encoding_table[i2] == e2 )
69 | break;
70 | }
71 |
72 | if ( i2 >= end )
73 | return 0; /* e2 not part of any pair with e1, return 0 */
74 |
75 | return kerning->kerning_values[i2];
76 | }
77 |
78 | uint8_t u8g2_GetKerningByTable(U8X8_UNUSED u8g2_t *u8g2, const uint16_t *kt, uint16_t e1, uint16_t e2)
79 | {
80 | uint16_t i;
81 | i = 0;
82 | if ( kt == NULL )
83 | return 0;
84 | for(;;)
85 | {
86 | if ( kt[i] == 0x0ffff )
87 | break;
88 | if ( kt[i] == e1 && kt[i+1] == e2 )
89 | return kt[i+2];
90 | i+=3;
91 | }
92 | return 0;
93 | }
94 |
95 |
--------------------------------------------------------------------------------
/src/u8g2_line.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8g2_box.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 | #include "u8g2.h"
37 |
38 |
39 | void u8g2_DrawLine(u8g2_t *u8g2, u8g2_uint_t x1, u8g2_uint_t y1, u8g2_uint_t x2, u8g2_uint_t y2)
40 | {
41 | u8g2_uint_t tmp;
42 | u8g2_uint_t x,y;
43 | u8g2_uint_t dx, dy;
44 | u8g2_int_t err;
45 | u8g2_int_t ystep;
46 |
47 | uint8_t swapxy = 0;
48 |
49 | /* no intersection check at the moment, should be added... */
50 |
51 | if ( x1 > x2 ) dx = x1-x2; else dx = x2-x1;
52 | if ( y1 > y2 ) dy = y1-y2; else dy = y2-y1;
53 |
54 | if ( dy > dx )
55 | {
56 | swapxy = 1;
57 | tmp = dx; dx =dy; dy = tmp;
58 | tmp = x1; x1 =y1; y1 = tmp;
59 | tmp = x2; x2 =y2; y2 = tmp;
60 | }
61 | if ( x1 > x2 )
62 | {
63 | tmp = x1; x1 =x2; x2 = tmp;
64 | tmp = y1; y1 =y2; y2 = tmp;
65 | }
66 | err = dx >> 1;
67 | if ( y2 > y1 ) ystep = 1; else ystep = -1;
68 | y = y1;
69 |
70 | #ifndef U8G2_16BIT
71 | if ( x2 == 255 )
72 | x2--;
73 | #else
74 | if ( x2 == 0xffff )
75 | x2--;
76 | #endif
77 |
78 | for( x = x1; x <= x2; x++ )
79 | {
80 | if ( swapxy == 0 )
81 | u8g2_DrawPixel(u8g2, x, y);
82 | else
83 | u8g2_DrawPixel(u8g2, y, x);
84 | err -= (uint8_t)dy;
85 | if ( err < 0 )
86 | {
87 | y += (u8g2_uint_t)ystep;
88 | err += (u8g2_uint_t)dx;
89 | }
90 | }
91 | }
92 |
93 |
--------------------------------------------------------------------------------
/src/u8g2_message.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8g2_message.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 | #include "u8g2.h"
37 |
38 | #define SPACE_BETWEEN_BUTTONS_IN_PIXEL 6
39 | #define SPACE_BETWEEN_TEXT_AND_BUTTONS_IN_PIXEL 3
40 |
41 | uint8_t u8g2_draw_button_line(u8g2_t *u8g2, u8g2_uint_t y, u8g2_uint_t w, uint8_t cursor, const char *s)
42 | {
43 | u8g2_uint_t button_line_width;
44 |
45 | uint8_t i;
46 | uint8_t cnt;
47 | uint8_t is_invert;
48 |
49 | u8g2_uint_t d;
50 | u8g2_uint_t x;
51 |
52 | cnt = u8x8_GetStringLineCnt(s);
53 |
54 |
55 | /* calculate the width of the button line */
56 | button_line_width = 0;
57 | for( i = 0; i < cnt; i++ )
58 | {
59 | button_line_width += u8g2_GetUTF8Width(u8g2, u8x8_GetStringLineStart(i, s));
60 | }
61 | button_line_width += (cnt-1)*SPACE_BETWEEN_BUTTONS_IN_PIXEL; /* add some space between the buttons */
62 |
63 | /* calculate the left offset */
64 | d = 0;
65 | if ( button_line_width < w )
66 | {
67 | d = w;
68 | d -= button_line_width;
69 | d /= 2;
70 | }
71 |
72 | /* draw the buttons */
73 | x = d;
74 | for( i = 0; i < cnt; i++ )
75 | {
76 | is_invert = 0;
77 | if ( i == cursor )
78 | is_invert = 1;
79 |
80 | u8g2_DrawUTF8Line(u8g2, x, y, 0, u8x8_GetStringLineStart(i, s), 1, is_invert);
81 | x += u8g2_GetUTF8Width(u8g2, u8x8_GetStringLineStart(i, s));
82 | x += SPACE_BETWEEN_BUTTONS_IN_PIXEL;
83 | }
84 |
85 | /* return the number of buttons */
86 | return cnt;
87 | }
88 |
89 | /*
90 | title1: Multiple lines,separated by '\n'
91 | title2: A single line/string which is terminated by '\0' or '\n' . "title2" accepts the return value from u8x8_GetStringLineStart()
92 | title3: Multiple lines,separated by '\n'
93 | buttons: one more more buttons separated by '\n' and terminated with '\0'
94 | side effects:
95 | u8g2_SetFontDirection(u8g2, 0);
96 | u8g2_SetFontPosBaseline(u8g2);
97 | */
98 |
99 | uint8_t u8g2_UserInterfaceMessage(u8g2_t *u8g2, const char *title1, const char *title2, const char *title3, const char *buttons)
100 | {
101 | uint8_t height;
102 | uint8_t line_height;
103 | u8g2_uint_t pixel_height;
104 | u8g2_uint_t y, yy;
105 |
106 | uint8_t cursor = 0;
107 | uint8_t button_cnt;
108 | uint8_t event;
109 |
110 | /* only horizontal strings are supported, so force this here */
111 | u8g2_SetFontDirection(u8g2, 0);
112 |
113 | /* force baseline position */
114 | u8g2_SetFontPosBaseline(u8g2);
115 |
116 |
117 | /* calculate line height */
118 | line_height = u8g2_GetAscent(u8g2);
119 | line_height -= u8g2_GetDescent(u8g2);
120 |
121 | /* calculate overall height of the message box in lines*/
122 | height = 1; /* button line */
123 | height += u8x8_GetStringLineCnt(title1);
124 | if ( title2 != NULL )
125 | height++;
126 | height += u8x8_GetStringLineCnt(title3);
127 |
128 | /* calculate the height in pixel */
129 | pixel_height = height;
130 | pixel_height *= line_height;
131 |
132 | /* ... and add the space between the text and the buttons */
133 | pixel_height +=SPACE_BETWEEN_TEXT_AND_BUTTONS_IN_PIXEL;
134 |
135 | /* calculate offset from top */
136 | y = 0;
137 | if ( pixel_height < u8g2_GetDisplayHeight(u8g2) )
138 | {
139 | y = u8g2_GetDisplayHeight(u8g2);
140 | y -= pixel_height;
141 | y /= 2;
142 | }
143 | y += u8g2_GetAscent(u8g2);
144 |
145 |
146 | for(;;)
147 | {
148 | u8g2_FirstPage(u8g2);
149 | do
150 | {
151 | yy = y;
152 | /* draw message box */
153 |
154 | yy += u8g2_DrawUTF8Lines(u8g2, 0, yy, u8g2_GetDisplayWidth(u8g2), line_height, title1);
155 | if ( title2 != NULL )
156 | {
157 | u8g2_DrawUTF8Line(u8g2, 0, yy, u8g2_GetDisplayWidth(u8g2), title2, 0, 0);
158 | yy+=line_height;
159 | }
160 | yy += u8g2_DrawUTF8Lines(u8g2, 0, yy, u8g2_GetDisplayWidth(u8g2), line_height, title3);
161 | yy += SPACE_BETWEEN_TEXT_AND_BUTTONS_IN_PIXEL;
162 |
163 | button_cnt = u8g2_draw_button_line(u8g2, yy, u8g2_GetDisplayWidth(u8g2), cursor, buttons);
164 |
165 | } while( u8g2_NextPage(u8g2) );
166 |
167 | #ifdef U8G2_REF_MAN_PIC
168 | return 0;
169 | #endif
170 |
171 | for(;;)
172 | {
173 | event = u8x8_GetMenuEvent(u8g2_GetU8x8(u8g2));
174 | if ( event == U8X8_MSG_GPIO_MENU_SELECT )
175 | return cursor+1;
176 | else if ( event == U8X8_MSG_GPIO_MENU_HOME )
177 | return 0;
178 | else if ( event == U8X8_MSG_GPIO_MENU_NEXT || event == U8X8_MSG_GPIO_MENU_DOWN )
179 | {
180 | cursor++;
181 | if ( cursor >= button_cnt )
182 | cursor = 0;
183 | break;
184 | }
185 | else if ( event == U8X8_MSG_GPIO_MENU_PREV || event == U8X8_MSG_GPIO_MENU_UP )
186 | {
187 | if ( cursor == 0 )
188 | cursor = button_cnt;
189 | cursor--;
190 | break;
191 | }
192 | }
193 | }
194 | /* never reached */
195 | //return 0;
196 | }
197 |
198 |
--------------------------------------------------------------------------------
/src/u8log.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8log.c
4 |
5 |
6 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
7 |
8 | Copyright (c) 2018, olikraus@gmail.com
9 | All rights reserved.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | * Redistributions of source code must retain the above copyright notice, this list
15 | of conditions and the following disclaimer.
16 |
17 | * Redistributions in binary form must reproduce the above copyright notice, this
18 | list of conditions and the following disclaimer in the documentation and/or other
19 | materials provided with the distribution.
20 |
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
22 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
23 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 |
35 | */
36 |
37 | #include
38 | #include
39 | #include "u8x8.h"
40 |
41 |
42 | /*
43 | static uint8_t u8log_is_on_screen(u8log_t *u8log, uint8_t x, uint8_t y)
44 | {
45 | if ( x >= u8log->width )
46 | return 0;
47 | if ( y >= u8log->height )
48 | return 0;
49 | return 1;
50 | }
51 | */
52 |
53 | static void u8log_clear_screen(u8log_t *u8log)
54 | {
55 | uint8_t *dest = u8log->screen_buffer;
56 | uint16_t cnt = u8log->height;
57 | cnt *= u8log->width;
58 | do
59 | {
60 | *dest++ = ' ';
61 | cnt--;
62 | } while( cnt > 0 );
63 |
64 | }
65 |
66 |
67 | /* scroll the content of the complete buffer, set redraw_line to 255 */
68 | static void u8log_scroll_up(u8log_t *u8log)
69 | {
70 | uint8_t *dest = u8log->screen_buffer;
71 | uint8_t *src = dest+u8log->width;
72 | uint16_t cnt = u8log->height;
73 | cnt--;
74 | cnt *= u8log->width;
75 | do
76 | {
77 | *dest++ = *src++;
78 | cnt--;
79 | } while( cnt > 0 );
80 | cnt = u8log->width;
81 | do
82 | {
83 | *dest++ = ' ';
84 | cnt--;
85 | } while(cnt > 0);
86 |
87 | if ( u8log->is_redraw_line_for_each_char )
88 | u8log->is_redraw_all = 1;
89 | else
90 | u8log->is_redraw_all_required_for_next_nl = 1;
91 | }
92 |
93 | /*
94 | Place the cursor on the screen. This will also scroll, if required
95 | */
96 | static void u8log_cursor_on_screen(u8log_t *u8log)
97 | {
98 | //printf("u8log_cursor_on_screen, cursor_y=%d\n", u8log->cursor_y);
99 | if ( u8log->cursor_x >= u8log->width )
100 | {
101 | u8log->cursor_x = 0;
102 | u8log->cursor_y++;
103 | }
104 | while ( u8log->cursor_y >= u8log->height )
105 | {
106 | u8log_scroll_up(u8log);
107 | u8log->cursor_y--;
108 | }
109 | }
110 |
111 | /*
112 | Write a printable, single char on the screen, do any kind of scrolling
113 | */
114 | static void u8log_write_to_screen(u8log_t *u8log, uint8_t c)
115 | {
116 | u8log_cursor_on_screen(u8log);
117 | u8log->screen_buffer[u8log->cursor_y * u8log->width + u8log->cursor_x] = c;
118 | u8log->cursor_x++;
119 |
120 | if ( u8log->is_redraw_line_for_each_char )
121 | {
122 | u8log->is_redraw_line = 1;
123 | u8log->redraw_line = u8log->cursor_y;
124 | }
125 | }
126 |
127 | /*
128 | Handle control codes or write the char to the screen.
129 | Supported control codes are:
130 |
131 | \n 10 Goto first position of the next line. Line is marked for redraw.
132 | \r 13 Goto first position in the same line. Line is marked for redraw.
133 | \t 9 Jump to the next tab position
134 | \f 12 Clear the screen and mark redraw for whole screen
135 | any other char Write char to screen. Line redraw mark depends on
136 | is_redraw_line_for_each_char flag.
137 | */
138 | void u8log_write_char(u8log_t *u8log, uint8_t c)
139 | {
140 | switch(c)
141 | {
142 | case '\n': // 10
143 | u8log->is_redraw_line = 1;
144 | u8log->redraw_line = u8log->cursor_y;
145 | if ( u8log->is_redraw_all_required_for_next_nl )
146 | u8log->is_redraw_all = 1;
147 | u8log->is_redraw_all_required_for_next_nl = 0;
148 | u8log->cursor_y++;
149 | u8log->cursor_x = 0;
150 | break;
151 | case '\r': // 13
152 | u8log->is_redraw_line = 1;
153 | u8log->redraw_line = u8log->cursor_y;
154 | u8log->cursor_x = 0;
155 | break;
156 | case '\t': // 9
157 | u8log->cursor_x = (u8log->cursor_x + 8) & 0xf8;
158 | break;
159 | case '\f': // 12
160 | u8log_clear_screen(u8log);
161 | u8log->is_redraw_all = 1;
162 | u8log->cursor_x = 0;
163 | u8log->cursor_y = 0;
164 | break;
165 | default:
166 | u8log_write_to_screen(u8log, c);
167 | break;
168 | }
169 | }
170 |
171 | void u8log_Init(u8log_t *u8log, uint8_t width, uint8_t height, uint8_t *buf)
172 | {
173 | memset(u8log, 0, sizeof(u8log_t));
174 | u8log->width = width;
175 | u8log->height = height;
176 | u8log->screen_buffer = buf;
177 | u8log_clear_screen(u8log);
178 | }
179 |
180 | void u8log_SetCallback(u8log_t *u8log, u8log_cb cb, void *aux_data)
181 | {
182 | u8log->cb = cb;
183 | u8log->aux_data = aux_data;
184 | }
185 |
186 | void u8log_SetRedrawMode(u8log_t *u8log, uint8_t is_redraw_line_for_each_char)
187 | {
188 | u8log->is_redraw_line_for_each_char = is_redraw_line_for_each_char;
189 | }
190 |
191 | /* offset can be negative or positive, it is 0 by default */
192 | void u8log_SetLineHeightOffset(u8log_t *u8log, int8_t line_height_offset)
193 | {
194 | u8log->line_height_offset = line_height_offset;
195 | }
196 |
197 |
198 |
199 | void u8log_WriteChar(u8log_t *u8log, uint8_t c)
200 | {
201 | u8log_write_char(u8log, c);
202 | if ( u8log->is_redraw_line || u8log->is_redraw_all )
203 | {
204 | if ( u8log->cb != 0 )
205 | {
206 | u8log->cb(u8log);
207 | }
208 | u8log->is_redraw_line = 0;
209 | u8log->is_redraw_all = 0;
210 | }
211 | }
212 |
213 | void u8log_WriteString(u8log_t *u8log, const char *s)
214 | {
215 | while( *s != '\0' )
216 | {
217 | u8log_WriteChar(u8log, *s);
218 | s++;
219 | }
220 | }
221 |
222 | static void u8log_WriteHexHalfByte(u8log_t *u8log, uint8_t b) U8X8_NOINLINE;
223 | static void u8log_WriteHexHalfByte(u8log_t *u8log, uint8_t b)
224 | {
225 | b &= 0x0f;
226 | if ( b < 10 )
227 | u8log_WriteChar(u8log, b+'0');
228 | else
229 | u8log_WriteChar(u8log, b+'a'-10);
230 | }
231 |
232 | void u8log_WriteHex8(u8log_t *u8log, uint8_t b)
233 | {
234 | u8log_WriteHexHalfByte(u8log, b >> 4);
235 | u8log_WriteHexHalfByte(u8log, b);
236 | }
237 |
238 | void u8log_WriteHex16(u8log_t *u8log, uint16_t v)
239 | {
240 | u8log_WriteHex8(u8log, v>>8);
241 | u8log_WriteHex8(u8log, v);
242 | }
243 |
244 | void u8log_WriteHex32(u8log_t *u8log, uint32_t v)
245 | {
246 | u8log_WriteHex16(u8log, v>>16);
247 | u8log_WriteHex16(u8log, v);
248 | }
249 |
250 | /* v = value, d = number of digits (1..3) */
251 | void u8log_WriteDec8(u8log_t *u8log, uint8_t v, uint8_t d)
252 | {
253 | u8log_WriteString(u8log, u8x8_u8toa(v, d));
254 | }
255 |
256 | /* v = value, d = number of digits (1..5) */
257 | void u8log_WriteDec16(u8log_t *u8log, uint16_t v, uint8_t d)
258 | {
259 | u8log_WriteString(u8log, u8x8_u16toa(v, d));
260 | }
261 |
--------------------------------------------------------------------------------
/src/u8log_u8g2.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8log_u8g2.c
4 |
5 |
6 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
7 |
8 | Copyright (c) 2018, olikraus@gmail.com
9 | All rights reserved.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | * Redistributions of source code must retain the above copyright notice, this list
15 | of conditions and the following disclaimer.
16 |
17 | * Redistributions in binary form must reproduce the above copyright notice, this
18 | list of conditions and the following disclaimer in the documentation and/or other
19 | materials provided with the distribution.
20 |
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
22 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
23 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 |
35 | */
36 |
37 | #include "u8g2.h"
38 | /*
39 | Draw the u8log text at the specified x/y position.
40 | x/y position is the reference position of the first char of the first line.
41 | the line height is
42 | u8g2_GetAscent(u8g2) - u8g2_GetDescent(u8g2) + line_height_offset;
43 | line_height_offset can be set with u8log_SetLineHeightOffset()
44 | Use
45 | u8g2_SetFontRefHeightText(u8g2_t *u8g2);
46 | u8g2_SetFontRefHeightExtendedText(u8g2_t *u8g2);
47 | u8g2_SetFontRefHeightAll(u8g2_t *u8g2);
48 | to change the return values for u8g2_GetAscent and u8g2_GetDescent
49 |
50 | */
51 | void u8g2_DrawLog(u8g2_t *u8g2, u8g2_uint_t x, u8g2_uint_t y, u8log_t *u8log)
52 | {
53 | u8g2_uint_t disp_x, disp_y;
54 | uint8_t buf_x, buf_y;
55 | uint8_t c;
56 |
57 | disp_y = y;
58 | u8g2_SetFontDirection(u8g2, 0);
59 | for( buf_y = 0; buf_y < u8log->height; buf_y++ )
60 | {
61 | disp_x = x;
62 | for( buf_x = 0; buf_x < u8log->width; buf_x++ )
63 | {
64 | c = u8log->screen_buffer[buf_y * u8log->width + buf_x];
65 | disp_x += u8g2_DrawGlyph(u8g2, disp_x, disp_y, c);
66 | }
67 | disp_y += u8g2_GetAscent(u8g2) - u8g2_GetDescent(u8g2);
68 | disp_y += u8log->line_height_offset;
69 | }
70 | }
71 |
72 | /*
73 | u8lib callback for u8g2
74 |
75 | Only font direction 0 is supported: u8g2_SetFontDirection(u8g2, 0)
76 | Use
77 | u8g2_SetFontRefHeightText(u8g2_t *u8g2);
78 | u8g2_SetFontRefHeightExtendedText(u8g2_t *u8g2);
79 | u8g2_SetFontRefHeightAll(u8g2_t *u8g2);
80 | to change the top offset and the line height and
81 | u8log_SetLineHeightOffset(u8log_t *u8log, int8_t line_height_offset)
82 | to change the line height.
83 |
84 | */
85 | void u8log_u8g2_cb(u8log_t * u8log)
86 | {
87 | u8g2_t *u8g2 = (u8g2_t *)(u8log->aux_data);
88 | if ( u8log->is_redraw_line || u8log->is_redraw_all )
89 | {
90 | u8g2_FirstPage(u8g2);
91 | do
92 | {
93 | u8g2_DrawLog( u8g2, 0, u8g2_GetAscent(u8g2), u8log);
94 | }
95 | while( u8g2_NextPage(u8g2) );
96 | }
97 | }
98 |
99 |
--------------------------------------------------------------------------------
/src/u8log_u8x8.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8log_u8x8.c
4 |
5 |
6 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
7 |
8 | Copyright (c) 2018, olikraus@gmail.com
9 | All rights reserved.
10 |
11 | Redistribution and use in source and binary forms, with or without modification,
12 | are permitted provided that the following conditions are met:
13 |
14 | * Redistributions of source code must retain the above copyright notice, this list
15 | of conditions and the following disclaimer.
16 |
17 | * Redistributions in binary form must reproduce the above copyright notice, this
18 | list of conditions and the following disclaimer in the documentation and/or other
19 | materials provided with the distribution.
20 |
21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
22 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
23 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 |
35 | */
36 |
37 | #include "u8x8.h"
38 |
39 | static void u8x8_DrawLogLine(u8x8_t *u8x8, uint8_t disp_x, uint8_t disp_y, uint8_t buf_y, u8log_t *u8log) U8X8_NOINLINE;
40 | static void u8x8_DrawLogLine(u8x8_t *u8x8, uint8_t disp_x, uint8_t disp_y, uint8_t buf_y, u8log_t *u8log)
41 | {
42 | uint8_t buf_x;
43 | uint8_t c;
44 | for( buf_x = 0; buf_x < u8log->width; buf_x++ )
45 | {
46 | c = u8log->screen_buffer[buf_y * u8log->width + buf_x];
47 | u8x8_DrawGlyph(u8x8, disp_x, disp_y, c);
48 | disp_x++;
49 | }
50 | }
51 |
52 | void u8x8_DrawLog(u8x8_t *u8x8, uint8_t x, uint8_t y, u8log_t *u8log)
53 | {
54 | uint8_t buf_y;
55 | for( buf_y = 0; buf_y < u8log->height; buf_y++ )
56 | {
57 | u8x8_DrawLogLine(u8x8, x, y, buf_y, u8log);
58 | y++;
59 | }
60 | }
61 |
62 |
63 | void u8log_u8x8_cb(u8log_t * u8log)
64 | {
65 | u8x8_t *u8x8 = (u8x8_t *)(u8log->aux_data);
66 | if ( u8log->is_redraw_all )
67 | {
68 | u8x8_DrawLog(u8x8, 0, 0, u8log);
69 | }
70 | else if ( u8log->is_redraw_line )
71 | {
72 | u8x8_DrawLogLine(u8x8, 0, u8log->redraw_line, u8log->redraw_line, u8log);
73 | }
74 | }
75 |
76 |
--------------------------------------------------------------------------------
/src/u8x8_capture.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_capture.c
4 |
5 | Screen capture funcion
6 |
7 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
8 |
9 | Copyright (c) 2016, olikraus@gmail.com
10 | All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without modification,
13 | are permitted provided that the following conditions are met:
14 |
15 | * Redistributions of source code must retain the above copyright notice, this list
16 | of conditions and the following disclaimer.
17 |
18 | * Redistributions in binary form must reproduce the above copyright notice, this
19 | list of conditions and the following disclaimer in the documentation and/or other
20 | materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 |
36 |
37 | */
38 |
39 | #include "u8x8.h"
40 |
41 | /*========================================================*/
42 |
43 |
44 | /* vertical top lsb memory architecture */
45 | uint8_t u8x8_capture_get_pixel_1(uint16_t x, uint16_t y, uint8_t *dest_ptr, uint8_t tile_width)
46 | {
47 | //uint8_t *dest_ptr = capture->buffer;
48 | //if ( dest_ptr == NULL )
49 | //return 0;
50 | //dest_ptr += (y/8)*capture->tile_width*8;
51 | dest_ptr += (y/8)*tile_width*8;
52 | y &= 7;
53 | dest_ptr += x;
54 | if ( (*dest_ptr & (1<buffer;
64 | //if ( dest_ptr == NULL )
65 | // return 0;
66 | //dest_ptr += y*capture->tile_width;
67 | y *= tile_width;
68 | dest_ptr += y;
69 | dest_ptr += x>>3;
70 | if ( (*dest_ptr & (128>>(x&7))) == 0 )
71 | return 0;
72 | return 1;
73 | }
74 |
75 | void u8x8_capture_write_pbm_pre(uint8_t tile_width, uint8_t tile_height, void (*out)(const char *s))
76 | {
77 | out("P1\n");
78 | out(u8x8_utoa((uint16_t)tile_width*8));
79 | out("\n");
80 | out(u8x8_utoa((uint16_t)tile_height*8));
81 | out("\n");
82 | }
83 |
84 |
85 | void u8x8_capture_write_pbm_buffer(uint8_t *buffer, uint8_t tile_width, uint8_t tile_height, uint8_t (*get_pixel)(uint16_t x, uint16_t y, uint8_t *dest_ptr, uint8_t tile_width), void (*out)(const char *s))
86 | {
87 | uint16_t x, y;
88 | uint16_t w, h;
89 |
90 | w = tile_width;
91 | w *= 8;
92 | h = tile_height;
93 | h *= 8;
94 |
95 | for( y = 0; y < h; y++)
96 | {
97 | for( x = 0; x < w; x++)
98 | {
99 | if ( get_pixel(x, y, buffer, tile_width) )
100 | out("1");
101 | else
102 | out("0");
103 | }
104 | out("\n");
105 | }
106 | }
107 |
108 |
109 |
110 |
111 | void u8x8_capture_write_xbm_pre(uint8_t tile_width, uint8_t tile_height, void (*out)(const char *s))
112 | {
113 | out("#define xbm_width ");
114 | out(u8x8_utoa((uint16_t)tile_width*8));
115 | out("\n");
116 | out("#define xbm_height ");
117 | out(u8x8_utoa((uint16_t)tile_height*8));
118 | out("\n");
119 | out("static unsigned char xbm_bits[] = {\n");
120 | }
121 |
122 | void u8x8_capture_write_xbm_buffer(uint8_t *buffer, uint8_t tile_width, uint8_t tile_height, uint8_t (*get_pixel)(uint16_t x, uint16_t y, uint8_t *dest_ptr, uint8_t tile_width), void (*out)(const char *s))
123 | {
124 | uint16_t x, y;
125 | uint16_t w, h;
126 | uint8_t v, b;
127 | char s[2];
128 | s[1] = '\0';
129 |
130 | w = tile_width;
131 | w *= 8;
132 | h = tile_height;
133 | h *= 8;
134 |
135 | y = 0;
136 | for(;;)
137 | {
138 | x = 0;
139 | for(;;)
140 | {
141 | v = 0;
142 | for( b = 0; b < 8; b++ )
143 | {
144 | v <<= 1;
145 | if ( get_pixel(x+7-b, y, buffer, tile_width) )
146 | v |= 1;
147 | }
148 | out("0x");
149 | s[0] = (v>>4);
150 | if ( s[0] <= 9 )
151 | s[0] += '0';
152 | else
153 | s[0] += 'a'-10;
154 | out(s);
155 | s[0] = (v&15);
156 | if ( s[0] <= 9 )
157 | s[0] += '0';
158 | else
159 | s[0] += 'a'-10;
160 | out(s);
161 | x += 8;
162 | if ( x >= w )
163 | break;
164 | out(",");
165 | }
166 | y++;
167 | if ( y >= h )
168 | break;
169 | out(",");
170 | out("\n");
171 | }
172 | out("};\n");
173 |
174 | }
175 |
176 |
177 |
178 | /*========================================================*/
179 |
180 | #ifdef NOT_YET_IMPLEMENTED_U8X8_SCREEN_CAPTURE
181 |
182 | struct _u8x8_capture_struct
183 | {
184 | u8x8_msg_cb old_cb;
185 | uint8_t *buffer; /* tile_width*tile_height*8 bytes */
186 | uint8_t tile_width;
187 | uint8_t tile_height;
188 | };
189 | typedef struct _u8x8_capture_struct u8x8_capture_t;
190 |
191 |
192 | u8x8_capture_t u8x8_capture;
193 |
194 |
195 | static void u8x8_capture_memory_copy(uint8_t *dest, uint8_t *src, uint16_t cnt)
196 | {
197 | while( cnt > 0 )
198 | {
199 | *dest++ = *src++;
200 | cnt--;
201 | }
202 | }
203 |
204 | static void u8x8_capture_DrawTiles(u8x8_capture_t *capture, uint8_t tx, uint8_t ty, uint8_t tile_cnt, uint8_t *tile_ptr)
205 | {
206 | uint8_t *dest_ptr = capture->buffer;
207 | //printf("tile pos: %d %d, cnt=%d\n", tx, ty, tile_cnt);
208 | if ( dest_ptr == NULL )
209 | return;
210 | dest_ptr += (uint16_t)ty*capture->tile_width*8;
211 | dest_ptr += (uint16_t)tx*8;
212 | u8x8_capture_memory_copy(dest_ptr, tile_ptr, tile_cnt*8);
213 | }
214 |
215 | uint8_t u8x8_d_capture(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
216 | {
217 | if ( msg == U8X8_MSG_DISPLAY_DRAW_TILE )
218 | {
219 | uint8_t x, y, c;
220 | uint8_t *ptr;
221 | x = ((u8x8_tile_t *)arg_ptr)->x_pos;
222 | y = ((u8x8_tile_t *)arg_ptr)->y_pos;
223 | c = ((u8x8_tile_t *)arg_ptr)->cnt;
224 | ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
225 | do
226 | {
227 | u8x8_capture_DrawTiles(&u8x8_capture, x, y, c, ptr);
228 | x += c;
229 | arg_int--;
230 | } while( arg_int > 0 );
231 | }
232 | return u8x8_capture.old_cb(u8x8, msg, arg_int, arg_ptr);
233 | }
234 |
235 | uint8_t u8x8_GetCaptureMemoryPixel(u8x8_t *u8x8, uint16_t x, uint16_t y)
236 | {
237 | return u8x8_capture_GetPixel(&u8x8_capture, x, y);
238 | }
239 |
240 | /* memory: tile_width*tile_height*8 bytes */
241 | void u8x8_ConnectCapture(u8x8_t *u8x8, uint8_t tile_width, uint8_t tile_height, uint8_t *memory)
242 | {
243 | if ( u8x8->display_cb == u8x8_d_capture )
244 | return; /* do nothing, capture already installed */
245 |
246 | u8x8_capture.buffer = memory; /* tile_width*tile_height*8 bytes */
247 | u8x8_capture.tile_width = tile_width;
248 | u8x8_capture.tile_height = tile_height;
249 | u8x8_capture.old_cb = u8x8->display_cb;
250 | u8x8->display_cb = u8x8_d_capture;
251 | return;
252 | }
253 |
254 | #endif
--------------------------------------------------------------------------------
/src/u8x8_d_a2printer.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_d_a2printer.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 |
35 | Use DC2 bitmap command of the A2 Micro panel termal printer
36 | double stroke
37 |
38 |
39 | */
40 |
41 |
42 | #include "u8x8.h"
43 |
44 | #define LINE_MIN_DELAY_MS 15
45 | /* higher values improve quality */
46 | /* however if the value is too high (>=5) then form feed does not work any more */
47 | #define LINE_EXTRA_8PIXEL_DELAY_MS 3
48 | /* this must be a power of two and between 1 and 8 */
49 | /* best quality only with 1 */
50 | #define NO_OF_LINES_TO_SEND_WITHOUT_DELAY 1
51 |
52 | /* calculates the delay, based on the number of black pixel */
53 | /* actually only "none-zero" bytes are calculated which is, of course not so accurate, but should be good enough */
54 | uint16_t get_delay_in_milliseconds(uint8_t cnt, uint8_t *data)
55 | {
56 | uint8_t i;
57 | uint16_t time = LINE_MIN_DELAY_MS;
58 | for ( i = 0; i < cnt; i++ )
59 | if ( data[i] != 0 )
60 | time += LINE_EXTRA_8PIXEL_DELAY_MS;
61 | return time;
62 | }
63 |
64 | uint8_t u8x8_d_a2printer_common(u8x8_t *u8x8, uint8_t msg, U8X8_UNUSED uint8_t arg_int, void *arg_ptr)
65 | {
66 | uint8_t c, i, j;
67 | uint8_t *ptr;
68 | uint16_t delay_in_milliseconds;
69 | switch(msg)
70 | {
71 | /* U8X8_MSG_DISPLAY_SETUP_MEMORY is handled by the calling function */
72 | /*
73 | case U8X8_MSG_DISPLAY_SETUP_MEMORY:
74 | break;
75 | */
76 | case U8X8_MSG_DISPLAY_INIT:
77 | u8x8_d_helper_display_init(u8x8);
78 | // no setup required
79 | // u8x8_cad_SendSequence(u8x8, u8x8_d_a2printer_init_seq);
80 | break;
81 | case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
82 | // no powersave
83 | break;
84 | case U8X8_MSG_DISPLAY_DRAW_TILE:
85 | u8x8_cad_StartTransfer(u8x8);
86 |
87 | u8x8_cad_SendCmd(u8x8, 27); /* ESC */
88 | u8x8_cad_SendCmd(u8x8, 55 ); /* parameter command */
89 | /* increasing the "max printing dots" requires a good power supply, but LINE_EXTRA_8PIXEL_DELAY_MS could be reduced then */
90 | u8x8_cad_SendCmd(u8x8, 0); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1) ... lower values improve, probably my current supply is not sufficient */
91 | u8x8_cad_SendCmd(u8x8, 200); /* 3-255 Heating time,Unit(10us),Default:80(800us) */
92 | u8x8_cad_SendCmd(u8x8, 2); /* 0-255 Heating interval,Unit(10us),Default:2(20us) ... does not have much influence */
93 |
94 | //c = ((u8x8_tile_t *)arg_ptr)->cnt; /* number of tiles */
95 | c = u8x8->display_info->tile_width;
96 | ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr; /* data ptr to the tiles */
97 |
98 | u8x8_cad_SendCmd(u8x8, 18); /* DC2 */
99 | u8x8_cad_SendCmd(u8x8, 42 ); /* * */
100 | u8x8_cad_SendCmd(u8x8, 8 ); /* height */
101 | u8x8_cad_SendCmd(u8x8, c ); /* c, u8x8->display_info->tile_width */
102 |
103 | for( j = 0; j < 8 / NO_OF_LINES_TO_SEND_WITHOUT_DELAY; j ++ )
104 | {
105 |
106 | delay_in_milliseconds = 0;
107 | for( i = 0; i < NO_OF_LINES_TO_SEND_WITHOUT_DELAY; i++ )
108 | {
109 | u8x8_cad_SendData(u8x8, c, ptr); /* c, note: SendData can not handle more than 255 bytes, send one line of data */
110 | delay_in_milliseconds += get_delay_in_milliseconds(c, ptr);
111 | ptr += c;
112 | }
113 |
114 | while( delay_in_milliseconds > 200 )
115 | {
116 | u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_MILLI, 200, NULL);
117 | delay_in_milliseconds -= 200;
118 | }
119 | u8x8->gpio_and_delay_cb(u8x8, U8X8_MSG_DELAY_MILLI, delay_in_milliseconds, NULL);
120 | }
121 |
122 | /* set parameters back to their default values */
123 | u8x8_cad_SendCmd(u8x8, 27); /* ESC */
124 | u8x8_cad_SendCmd(u8x8, 55 ); /* parameter command */
125 | u8x8_cad_SendCmd(u8x8, 7); /* Max printing dots,Unit(8dots),Default:7(64 dots) 8*(x+1)*/
126 | u8x8_cad_SendCmd(u8x8, 80); /* 3-255 Heating time,Unit(10us),Default:80(800us) */
127 | u8x8_cad_SendCmd(u8x8, 2); /* 0-255 Heating interval,Unit(10us),Default:2(20us)*/
128 |
129 | u8x8_cad_EndTransfer(u8x8);
130 |
131 | break;
132 | default:
133 | return 0;
134 | }
135 | return 1;
136 | }
137 |
138 |
139 | static const u8x8_display_info_t u8x8_a2printer_384x240_display_info =
140 | {
141 | /* most of the settings are not required, because this is a serial RS232 printer */
142 |
143 | /* chip_enable_level = */ 1,
144 | /* chip_disable_level = */ 0,
145 |
146 | /* post_chip_enable_wait_ns = */ 5,
147 | /* pre_chip_disable_wait_ns = */ 5,
148 | /* reset_pulse_width_ms = */ 1,
149 | /* post_reset_wait_ms = */ 6,
150 | /* sda_setup_time_ns = */ 20,
151 | /* sck_pulse_width_ns = */ 140,
152 | /* sck_clock_hz = */ 1000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
153 | /* spi_mode = */ 0, /* old: sck_takeover_edge, new: active high (bit 1), rising edge (bit 0) */
154 | /* i2c_bus_clock_100kHz = */ 4,
155 | /* data_setup_time_ns = */ 30,
156 | /* write_pulse_width_ns = */ 40,
157 | /* tile_width = */ 48,
158 | /* tile_hight = */ 30,
159 | /* default_x_offset = */ 0,
160 | /* flipmode_x_offset = */ 0,
161 | /* pixel_width = */ 384,
162 | /* pixel_height = */ 240
163 | };
164 |
165 | uint8_t u8x8_d_a2printer_384x240(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
166 | {
167 | switch(msg)
168 | {
169 | case U8X8_MSG_DISPLAY_SETUP_MEMORY:
170 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_a2printer_384x240_display_info);
171 | break;
172 | default:
173 | return u8x8_d_a2printer_common(u8x8, msg, arg_int, arg_ptr);
174 | }
175 | return 1;
176 | }
177 |
178 |
179 |
180 |
181 |
182 |
--------------------------------------------------------------------------------
/src/u8x8_d_ist7920.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_d_ist7920.c
4 |
5 | this is NOT ST7920!
6 |
7 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
8 |
9 | Copyright (c) 2019, olikraus@gmail.com
10 | All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without modification,
13 | are permitted provided that the following conditions are met:
14 |
15 | * Redistributions of source code must retain the above copyright notice, this list
16 | of conditions and the following disclaimer.
17 |
18 | * Redistributions in binary form must reproduce the above copyright notice, this
19 | list of conditions and the following disclaimer in the documentation and/or other
20 | materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 |
36 |
37 | */
38 | #include "u8x8.h"
39 |
40 |
41 |
42 |
43 | static const uint8_t u8x8_d_ist7920_128x128_powersave0_seq[] = {
44 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
45 | U8X8_C(0x03d), /* display on */
46 | U8X8_END_TRANSFER(), /* disable chip */
47 | U8X8_END() /* end of sequence */
48 | };
49 |
50 | static const uint8_t u8x8_d_ist7920_128x128_powersave1_seq[] = {
51 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
52 | U8X8_C(0x03c), /* display off */
53 | U8X8_END_TRANSFER(), /* disable chip */
54 | U8X8_END() /* end of sequence */
55 | };
56 |
57 | static const uint8_t u8x8_d_ist7920_128x128_flip0_seq[] = {
58 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
59 | U8X8_C(0x064), /* Display Ctrl: Bit3: SHL 2:ADC 1:EON, 0:REV */
60 | U8X8_END_TRANSFER(), /* disable chip */
61 | U8X8_END() /* end of sequence */
62 | };
63 |
64 | static const uint8_t u8x8_d_ist7920_128x128_flip1_seq[] = {
65 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
66 | U8X8_C(0x068), /* Display Ctrl: Bit3: SHL 2:ADC 1:EON, 0:REV */
67 | U8X8_END_TRANSFER(), /* disable chip */
68 | U8X8_END() /* end of sequence */
69 | };
70 |
71 |
72 | static const u8x8_display_info_t u8x8_ist7920_128x128_display_info =
73 | {
74 | /* chip_enable_level = */ 0,
75 | /* chip_disable_level = */ 1,
76 |
77 | /* post_chip_enable_wait_ns = */ 90, /* IST7920 datasheet, page 48 */
78 | /* pre_chip_disable_wait_ns = */ 90, /* IST7920 datasheet, page 48 */
79 | /* reset_pulse_width_ms = */ 10,
80 | /* post_reset_wait_ms = */ 20, /* IST7920 Startup Seq.. */
81 | /* sda_setup_time_ns = */ 45, /* IST7920 datasheet, page 48 */
82 | /* sck_pulse_width_ns = */ 130, /* IST7920 datasheet, page 48 */
83 | /* sck_clock_hz = */ 3000000UL, /* IST7920 datasheet: 260ns */
84 | /* spi_mode = */ 0, /* active high, rising edge (not verified) */
85 | /* i2c_bus_clock_100kHz = */ 4, /* 400kHz according to IST7920 datasheet */
86 | /* data_setup_time_ns = */ 60, /* IST7920 datasheet, page 47 */
87 | /* write_pulse_width_ns = */ 150, /* IST7920 datasheet, page 47 */
88 | /* tile_width = */ 16, /* width of 16*8=128 pixel */
89 | /* tile_hight = */ 16,
90 | /* default_x_offset = */ 0,
91 | /* flipmode_x_offset = */ 0,
92 | /* pixel_width = */ 128,
93 | /* pixel_height = */ 128
94 | };
95 |
96 | /* 1/128 Duty, 1/10 Bias, 128x128 round display */
97 | static const uint8_t u8x8_d_ist7920_128x128_init_seq[] = {
98 |
99 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
100 |
101 | U8X8_C(0x076), /* Software Reset */
102 | U8X8_DLY(50),
103 | U8X8_C(0x03c), /* display off */
104 |
105 |
106 | U8X8_CA(0x090, 128), /* Set Duty */
107 | //U8X8_CAA(0x0b2, 0x011, 0x00), /* Set Frame Control */
108 |
109 | U8X8_CA(0x030, 16), /* Set Bias 0: 1/8, 8: 1/9, 16: 1/10, 24: 1/11, 48: 1/12 ... */
110 | U8X8_CA(0x031, 0x03f), /* Set voltage generate clock(31H/11H) */
111 | //U8X8_CA(0x032, 0x015), /* Temperature compensation */
112 | U8X8_CA(0x033, 0x020), /* Power Control */
113 | U8X8_DLY(100),
114 | U8X8_CA(0x033, 0x02c), /* Power Control */
115 | U8X8_DLY(100),
116 | U8X8_C(0xfd), /* set booster */
117 | U8X8_DLY(100),
118 | U8X8_CA(0x033, 0x02f), /* Power Control */
119 | U8X8_DLY(200),
120 |
121 | U8X8_C(0x064), /* Display Ctrl: Bit3: SHL 2:ADC 1:EON, 0:REV */
122 |
123 | U8X8_CAA(0x074, 0x000, 0x00f), /* AY Window */
124 | U8X8_CAA(0x075, 0x000, 0x07f), /* AX Window */
125 |
126 | U8X8_CA(0x040, 64), /* Start line at 64 */
127 |
128 | U8X8_CA(0x0b1, 100), /* electronic volume */
129 |
130 |
131 | U8X8_END_TRANSFER(), /* disable chip */
132 | U8X8_END() /* end of sequence */
133 | };
134 |
135 | uint8_t u8x8_d_ist7920_128x128(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
136 | {
137 | uint8_t x, c;
138 | uint8_t *ptr;
139 | switch(msg)
140 | {
141 | case U8X8_MSG_DISPLAY_SETUP_MEMORY:
142 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_ist7920_128x128_display_info);
143 | break;
144 | case U8X8_MSG_DISPLAY_INIT:
145 | u8x8_d_helper_display_init(u8x8);
146 | u8x8_cad_SendSequence(u8x8, u8x8_d_ist7920_128x128_init_seq);
147 | break;
148 | case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
149 | if ( arg_int == 0 )
150 | u8x8_cad_SendSequence(u8x8, u8x8_d_ist7920_128x128_powersave0_seq);
151 | else
152 | u8x8_cad_SendSequence(u8x8, u8x8_d_ist7920_128x128_powersave1_seq);
153 | break;
154 | case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
155 | if ( arg_int == 0 )
156 | {
157 | u8x8_cad_SendSequence(u8x8, u8x8_d_ist7920_128x128_flip0_seq);
158 | u8x8->x_offset = u8x8->display_info->default_x_offset;
159 | }
160 | else
161 | {
162 | u8x8_cad_SendSequence(u8x8, u8x8_d_ist7920_128x128_flip1_seq);
163 | u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
164 | }
165 | break;
166 | #ifdef U8X8_WITH_SET_CONTRAST
167 | case U8X8_MSG_DISPLAY_SET_CONTRAST:
168 | u8x8_cad_StartTransfer(u8x8);
169 | u8x8_cad_SendCmd(u8x8, 0x0b1 );
170 | u8x8_cad_SendArg(u8x8, arg_int ); /* st7920 has range from 0 to 255 */
171 | u8x8_cad_EndTransfer(u8x8);
172 | break;
173 | #endif
174 | case U8X8_MSG_DISPLAY_DRAW_TILE:
175 | u8x8_cad_StartTransfer(u8x8);
176 |
177 | x = ((u8x8_tile_t *)arg_ptr)->x_pos;
178 | x *= 8;
179 | x += u8x8->x_offset;
180 | u8x8_cad_SendCmd(u8x8, 0x0c0 );
181 | u8x8_cad_SendArg(u8x8, x );
182 | u8x8_cad_SendCmd(u8x8, 0x001 );
183 | u8x8_cad_SendArg(u8x8, (((u8x8_tile_t *)arg_ptr)->y_pos) );
184 |
185 | c = ((u8x8_tile_t *)arg_ptr)->cnt;
186 | c *= 8;
187 | ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
188 | do
189 | {
190 | u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
191 | arg_int--;
192 | } while( arg_int > 0 );
193 |
194 | u8x8_cad_EndTransfer(u8x8);
195 | break;
196 | default:
197 | return 0;
198 | }
199 | return 1;
200 | }
201 |
202 |
203 |
--------------------------------------------------------------------------------
/src/u8x8_d_pcd8544_84x48.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_d_pcd8544_84x48.c (so called "Nokia 5110" displays)
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 |
35 | */
36 | #include "u8x8.h"
37 |
38 |
39 |
40 |
41 | static const uint8_t u8x8_d_pcd8544_84x48_init_seq[] = {
42 |
43 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
44 |
45 | U8X8_C(0x021), /* activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=1) */
46 | U8X8_C(0x006), /* temp. control: b10 = 2 */
47 | U8X8_C(0x013), /* bias system 1:48 */
48 | U8X8_C(0x0c0), /* medium Vop */
49 |
50 | U8X8_C(0x020), /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
51 | U8X8_C(0x008), /* blank */
52 | U8X8_C(0x024), /* power down (PD=1), horizontal increment (V=0), enter normal command set (H=0) */
53 |
54 | U8X8_END_TRANSFER(), /* disable chip */
55 | U8X8_END() /* end of sequence */
56 | };
57 |
58 | static const uint8_t u8x8_d_pcd8544_84x48_powersave0_seq[] = {
59 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
60 | U8X8_C(0x020), /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
61 | U8X8_C(0x00c), /* display on */
62 | U8X8_END_TRANSFER(), /* disable chip */
63 | U8X8_END() /* end of sequence */
64 | };
65 |
66 | static const uint8_t u8x8_d_pcd8544_84x48_powersave1_seq[] = {
67 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
68 | U8X8_C(0x020), /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
69 | U8X8_C(0x008), /* blank */
70 | U8X8_C(0x024), /* power down (PD=1), horizontal increment (V=0), enter normal command set (H=0) */
71 | U8X8_END_TRANSFER(), /* disable chip */
72 | U8X8_END() /* end of sequence */
73 | };
74 |
75 |
76 |
77 | static const u8x8_display_info_t u8x8_pcd8544_84x48_display_info =
78 | {
79 | /* chip_enable_level = */ 0,
80 | /* chip_disable_level = */ 1,
81 |
82 | /* post_chip_enable_wait_ns = */ 5,
83 | /* pre_chip_disable_wait_ns = */ 5,
84 | /* reset_pulse_width_ms = */ 2,
85 | /* post_reset_wait_ms = */ 2,
86 | /* sda_setup_time_ns = */ 12,
87 | /* sck_pulse_width_ns = */ 75, /* half of cycle time (100ns according to datasheet), AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
88 | /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
89 | /* spi_mode = */ 0, /* active high, rising edge */
90 | /* i2c_bus_clock_100kHz = */ 4,
91 | /* data_setup_time_ns = */ 30,
92 | /* write_pulse_width_ns = */ 40,
93 | /* tile_width = */ 11, /* width of 11*8=88 pixel */
94 | /* tile_hight = */ 6,
95 | /* default_x_offset = */ 0,
96 | /* flipmode_x_offset = */ 0,
97 | /* pixel_width = */ 84,
98 | /* pixel_height = */ 48
99 | };
100 |
101 | uint8_t u8x8_d_pcd8544_84x48(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
102 | {
103 | uint8_t x, c;
104 | uint8_t *ptr;
105 | switch(msg)
106 | {
107 | case U8X8_MSG_DISPLAY_SETUP_MEMORY:
108 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_pcd8544_84x48_display_info);
109 | break;
110 | case U8X8_MSG_DISPLAY_INIT:
111 | u8x8_d_helper_display_init(u8x8);
112 | u8x8_cad_SendSequence(u8x8, u8x8_d_pcd8544_84x48_init_seq);
113 | break;
114 | case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
115 | if ( arg_int == 0 )
116 | u8x8_cad_SendSequence(u8x8, u8x8_d_pcd8544_84x48_powersave0_seq);
117 | else
118 | u8x8_cad_SendSequence(u8x8, u8x8_d_pcd8544_84x48_powersave1_seq);
119 | break;
120 | // case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
121 | // break; NOT SUPPORTED
122 |
123 | #ifdef U8X8_WITH_SET_CONTRAST
124 | case U8X8_MSG_DISPLAY_SET_CONTRAST:
125 | u8x8_cad_StartTransfer(u8x8);
126 | u8x8_cad_SendCmd(u8x8, 0x021 ); /* command mode, extended function set */
127 | u8x8_cad_SendCmd(u8x8, 0x080 | (arg_int >> 1) );
128 | u8x8_cad_EndTransfer(u8x8);
129 | break;
130 | #endif
131 | case U8X8_MSG_DISPLAY_DRAW_TILE:
132 | u8x8_cad_StartTransfer(u8x8);
133 |
134 | x = ((u8x8_tile_t *)arg_ptr)->x_pos;
135 | x *= 8;
136 | x += u8x8->x_offset;
137 | u8x8_cad_SendCmd(u8x8, 0x020 ); /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
138 | u8x8_cad_SendCmd(u8x8, 0x080 | (x) ); /* set X address */
139 | u8x8_cad_SendCmd(u8x8, 0x040 | (((u8x8_tile_t *)arg_ptr)->y_pos) ); /* set Y address */
140 |
141 | ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
142 | c = ((u8x8_tile_t *)arg_ptr)->cnt;
143 | c *= 8;
144 | do
145 | {
146 | if ( c + x > 84u )
147 | {
148 | if ( x >= 84u )
149 | break;
150 | c = 84u;
151 | c -= x;
152 | }
153 | u8x8_cad_SendData(u8x8, c, ptr); /* note: SendData can not handle more than 255 bytes */
154 | x += c;
155 | arg_int--;
156 | } while( arg_int > 0 );
157 |
158 | u8x8_cad_EndTransfer(u8x8);
159 | break;
160 | default:
161 | return 0;
162 | }
163 | return 1;
164 | }
165 |
166 |
167 |
--------------------------------------------------------------------------------
/src/u8x8_d_pcf8812.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_d_pcf8812.c
4 |
5 | pcf8812: 65x102
6 | pcf8814: 65x96
7 |
8 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
9 |
10 | Copyright (c) 2017, olikraus@gmail.com
11 | All rights reserved.
12 |
13 | Redistribution and use in source and binary forms, with or without modification,
14 | are permitted provided that the following conditions are met:
15 |
16 | * Redistributions of source code must retain the above copyright notice, this list
17 | of conditions and the following disclaimer.
18 |
19 | * Redistributions in binary form must reproduce the above copyright notice, this
20 | list of conditions and the following disclaimer in the documentation and/or other
21 | materials provided with the distribution.
22 |
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 |
37 | */
38 |
39 |
40 | #include "u8x8.h"
41 |
42 |
43 |
44 | static const uint8_t u8x8_d_pcf8812_96x65_init_seq[] = {
45 |
46 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
47 |
48 | U8X8_C(0x020), /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
49 | U8X8_C(0x008), /* blank display */
50 |
51 | U8X8_C(0x021), /* activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=1) */
52 | U8X8_C(0x006), /* temp. control: b10 = 2 */
53 | U8X8_C(0x013), /* bias system, 0x010..0x07 1:48 */
54 | U8X8_C(0x09f), /* contrast setting, 0..127 */
55 | //U8X8_CA(0x020 | 2, 0x080 | 0), /* contrast setting, pcf8814 */
56 |
57 | U8X8_C(0x024), /* deactivate chip (PD=1), horizontal increment (V=0), enter normal command set (H=0) */
58 |
59 | U8X8_END_TRANSFER(), /* disable chip */
60 | U8X8_END() /* end of sequence */
61 | };
62 |
63 | static const uint8_t u8x8_d_pcf8812_96x65_powersave0_seq[] = {
64 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
65 | U8X8_C(0x020), /* power on */
66 | U8X8_C(0x00c), /* display on */
67 | U8X8_END_TRANSFER(), /* disable chip */
68 | U8X8_END() /* end of sequence */
69 | };
70 |
71 | static const uint8_t u8x8_d_pcf8812_96x65_powersave1_seq[] = {
72 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
73 | U8X8_C(0x020), /* power on */
74 | U8X8_C(0x008), /* blank display */
75 | U8X8_C(0x024), /* power down */
76 | U8X8_END_TRANSFER(), /* disable chip */
77 | U8X8_END() /* end of sequence */
78 | };
79 |
80 |
81 | static uint8_t u8x8_d_pcf8812_96x65_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
82 | {
83 | uint8_t x, c;
84 | uint8_t *ptr;
85 | switch(msg)
86 | {
87 | /* handled by the calling function
88 | case U8X8_MSG_DISPLAY_SETUP_MEMORY:
89 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_pcf8812_96x65_display_info);
90 | break;
91 | */
92 | case U8X8_MSG_DISPLAY_INIT:
93 | u8x8_d_helper_display_init(u8x8);
94 | u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_init_seq);
95 | break;
96 | case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
97 | if ( arg_int == 0 )
98 | u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_powersave0_seq);
99 | else
100 | u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_powersave1_seq);
101 | break;
102 | /*
103 | case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
104 | if ( arg_int == 0 )
105 | {
106 | u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_flip0_seq);
107 | u8x8->x_offset = u8x8->display_info->default_x_offset;
108 | }
109 | else
110 | {
111 | u8x8_cad_SendSequence(u8x8, u8x8_d_pcf8812_96x65_flip1_seq);
112 | u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
113 | }
114 | break;
115 | */
116 | #ifdef U8X8_WITH_SET_CONTRAST
117 | case U8X8_MSG_DISPLAY_SET_CONTRAST:
118 | u8x8_cad_StartTransfer(u8x8);
119 | u8x8_cad_SendCmd(u8x8, 0x021 ); /* command mode, extended function set */
120 | u8x8_cad_SendArg(u8x8, (arg_int>>1)|0x80 ); /* 0..127 for contrast */
121 | u8x8_cad_EndTransfer(u8x8);
122 | break;
123 | #endif
124 | case U8X8_MSG_DISPLAY_DRAW_TILE:
125 | u8x8_cad_StartTransfer(u8x8);
126 | x = ((u8x8_tile_t *)arg_ptr)->x_pos;
127 | x *= 8;
128 | x += u8x8->x_offset;
129 |
130 | u8x8_cad_SendCmd(u8x8, 0x020 ); /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */
131 | u8x8_cad_SendCmd(u8x8, 0x080 | x);
132 | u8x8_cad_SendCmd(u8x8, 0x040 | ((u8x8_tile_t *)arg_ptr)->y_pos);
133 |
134 | do
135 | {
136 | c = ((u8x8_tile_t *)arg_ptr)->cnt;
137 | ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
138 | u8x8_cad_SendData(u8x8, c*8, ptr); /* note: SendData can not handle more than 255 bytes */
139 | /*
140 | do
141 | {
142 | u8x8_cad_SendData(u8x8, 8, ptr);
143 | ptr += 8;
144 | c--;
145 | } while( c > 0 );
146 | */
147 | arg_int--;
148 | } while( arg_int > 0 );
149 |
150 | u8x8_cad_EndTransfer(u8x8);
151 | break;
152 | default:
153 | return 0;
154 | }
155 | return 1;
156 | }
157 |
158 |
159 | static const u8x8_display_info_t u8x8_pcf8812_96x65_display_info =
160 | {
161 | /* chip_enable_level = */ 0,
162 | /* chip_disable_level = */ 1,
163 |
164 | /* post_chip_enable_wait_ns = */ 100,
165 | /* pre_chip_disable_wait_ns = */ 100,
166 | /* reset_pulse_width_ms = */ 100,
167 | /* post_reset_wait_ms = */ 100,
168 | /* sda_setup_time_ns = */ 100,
169 | /* sck_pulse_width_ns = */ 100,
170 | /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
171 | /* spi_mode = */ 0, /* active high, rising edge */
172 | /* i2c_bus_clock_100kHz = */ 4,
173 | /* data_setup_time_ns = */ 40,
174 | /* write_pulse_width_ns = */ 150,
175 | /* tile_width = */ 12,
176 | /* tile_hight = */ 9,
177 | /* default_x_offset = */ 0,
178 | /* flipmode_x_offset = */ 0,
179 | /* pixel_width = */ 96,
180 | /* pixel_height = */ 65
181 | };
182 |
183 | uint8_t u8x8_d_pcf8812_96x65(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
184 | {
185 | if ( msg == U8X8_MSG_DISPLAY_SETUP_MEMORY )
186 | {
187 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_pcf8812_96x65_display_info);
188 | return 1;
189 | }
190 | return u8x8_d_pcf8812_96x65_generic(u8x8, msg, arg_int, arg_ptr);
191 | }
192 |
193 |
194 |
--------------------------------------------------------------------------------
/src/u8x8_d_pcf8814_hx1230.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_d_pcf8814_hc1230.c
4 |
5 | pcf8814: 65x96
6 | hx1230: 68x96
7 |
8 | pcf8814 and hc1230 are almost identical.
9 |
10 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
11 |
12 | Copyright (c) 2017, olikraus@gmail.com
13 | All rights reserved.
14 |
15 | Redistribution and use in source and binary forms, with or without modification,
16 | are permitted provided that the following conditions are met:
17 |
18 | * Redistributions of source code must retain the above copyright notice, this list
19 | of conditions and the following disclaimer.
20 |
21 | * Redistributions in binary form must reproduce the above copyright notice, this
22 | list of conditions and the following disclaimer in the documentation and/or other
23 | materials provided with the distribution.
24 |
25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
26 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
27 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
29 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
30 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
32 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
34 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
37 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 |
39 | */
40 |
41 |
42 | #include "u8x8.h"
43 |
44 |
45 |
46 | static const uint8_t u8x8_d_hx1230_96x68_init_seq[] = {
47 |
48 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
49 |
50 | U8X8_C(0x0ae), /* display off */
51 | U8X8_C(0x020), /* power off */
52 | U8X8_C(0x080), /* contrast setting, 0..31, set to 0 */
53 | U8X8_C(0x0a6), /* not inverted display */
54 | U8X8_C(0x0a4), /* normal display mode */
55 |
56 | U8X8_C(0x0a0), /* */
57 | U8X8_C(0x0c0), /* */
58 |
59 | U8X8_C(0x040), /* start at scanline 0 */
60 |
61 | U8X8_END_TRANSFER(), /* disable chip */
62 | U8X8_END() /* end of sequence */
63 | };
64 |
65 | static const uint8_t u8x8_d_hx1230_96x68_powersave0_seq[] = {
66 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
67 | U8X8_C(0x02f), /* power on */
68 | U8X8_C(0x0af), /* display on */
69 | U8X8_END_TRANSFER(), /* disable chip */
70 | U8X8_END() /* end of sequence */
71 | };
72 |
73 | static const uint8_t u8x8_d_hx1230_96x68_powersave1_seq[] = {
74 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
75 | U8X8_C(0x0ae), /* display off */
76 | U8X8_C(0x0a5), /* All pixels on = powersave */
77 | U8X8_END_TRANSFER(), /* disable chip */
78 | U8X8_END() /* end of sequence */
79 | };
80 |
81 | static const uint8_t u8x8_d_hx1230_96x68_flip0_seq[] = {
82 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
83 | U8X8_C(0x0a0), /* */
84 | U8X8_C(0x0c0), /* */
85 | U8X8_END_TRANSFER(), /* disable chip */
86 | U8X8_END() /* end of sequence */
87 | };
88 |
89 | static const uint8_t u8x8_d_hx1230_96x68_flip1_seq[] = {
90 | U8X8_START_TRANSFER(), /* enable chip, delay is part of the transfer start */
91 | U8X8_C(0x0a1), /* */
92 | U8X8_C(0x0c8), /* */
93 | U8X8_END_TRANSFER(), /* disable chip */
94 | U8X8_END() /* end of sequence */
95 | };
96 |
97 |
98 | static uint8_t u8x8_d_hx1230_96x68_generic(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
99 | {
100 | uint8_t x, c;
101 | uint8_t *ptr;
102 | switch(msg)
103 | {
104 | /* handled by the calling function
105 | case U8X8_MSG_DISPLAY_SETUP_MEMORY:
106 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_hx1230_96x68_display_info);
107 | break;
108 | */
109 | case U8X8_MSG_DISPLAY_INIT:
110 | u8x8_d_helper_display_init(u8x8);
111 | u8x8_cad_SendSequence(u8x8, u8x8_d_hx1230_96x68_init_seq);
112 | break;
113 | case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
114 | if ( arg_int == 0 )
115 | u8x8_cad_SendSequence(u8x8, u8x8_d_hx1230_96x68_powersave0_seq);
116 | else
117 | u8x8_cad_SendSequence(u8x8, u8x8_d_hx1230_96x68_powersave1_seq);
118 | break;
119 | case U8X8_MSG_DISPLAY_SET_FLIP_MODE:
120 | if ( arg_int == 0 )
121 | {
122 | u8x8_cad_SendSequence(u8x8, u8x8_d_hx1230_96x68_flip0_seq);
123 | u8x8->x_offset = u8x8->display_info->default_x_offset;
124 | }
125 | else
126 | {
127 | u8x8_cad_SendSequence(u8x8, u8x8_d_hx1230_96x68_flip1_seq);
128 | u8x8->x_offset = u8x8->display_info->flipmode_x_offset;
129 | }
130 | break;
131 | #ifdef U8X8_WITH_SET_CONTRAST
132 | case U8X8_MSG_DISPLAY_SET_CONTRAST:
133 | u8x8_cad_StartTransfer(u8x8);
134 | u8x8_cad_SendCmd(u8x8, (arg_int>>3)|0x80 ); /* 0..31 for contrast */
135 | u8x8_cad_EndTransfer(u8x8);
136 | break;
137 | #endif
138 | case U8X8_MSG_DISPLAY_DRAW_TILE:
139 | u8x8_cad_StartTransfer(u8x8);
140 | x = ((u8x8_tile_t *)arg_ptr)->x_pos;
141 | x *= 8;
142 | x += u8x8->x_offset;
143 |
144 | u8x8_cad_SendCmd(u8x8, x&15);
145 | u8x8_cad_SendCmd(u8x8, 0x010 | (x>>4));
146 | u8x8_cad_SendCmd(u8x8, 0x0b0 | ((u8x8_tile_t *)arg_ptr)->y_pos);
147 |
148 | do
149 | {
150 | c = ((u8x8_tile_t *)arg_ptr)->cnt;
151 | ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
152 | u8x8_cad_SendData(u8x8, c*8, ptr); /* note: SendData can not handle more than 255 bytes */
153 | arg_int--;
154 | } while( arg_int > 0 );
155 |
156 | u8x8_cad_EndTransfer(u8x8);
157 | break;
158 | default:
159 | return 0;
160 | }
161 | return 1;
162 | }
163 |
164 | static const u8x8_display_info_t u8x8_hx1230_96x68_display_info =
165 | {
166 | /* chip_enable_level = */ 0,
167 | /* chip_disable_level = */ 1,
168 |
169 | /* post_chip_enable_wait_ns = */ 100,
170 | /* pre_chip_disable_wait_ns = */ 100,
171 | /* reset_pulse_width_ms = */ 100,
172 | /* post_reset_wait_ms = */ 100,
173 | /* sda_setup_time_ns = */ 100,
174 | /* sck_pulse_width_ns = */ 100,
175 | /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
176 | /* spi_mode = */ 0, /* active high, rising edge */
177 | /* i2c_bus_clock_100kHz = */ 4,
178 | /* data_setup_time_ns = */ 40,
179 | /* write_pulse_width_ns = */ 150,
180 | /* tile_width = */ 12,
181 | /* tile_hight = */ 9,
182 | /* default_x_offset = */ 0,
183 | /* flipmode_x_offset = */ 0,
184 | /* pixel_width = */ 96,
185 | /* pixel_height = */ 68
186 | };
187 |
188 | uint8_t u8x8_d_hx1230_96x68(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
189 | {
190 | if ( msg == U8X8_MSG_DISPLAY_SETUP_MEMORY )
191 | {
192 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_hx1230_96x68_display_info);
193 | return 1;
194 | }
195 | return u8x8_d_hx1230_96x68_generic(u8x8, msg, arg_int, arg_ptr);
196 | }
197 |
198 |
199 |
--------------------------------------------------------------------------------
/src/u8x8_d_sbn1661.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_d_sbn1661.c
4 |
5 | SED1520 / SBN1661 122x32 5V LCD
6 |
7 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
8 |
9 | Copyright (c) 2016, olikraus@gmail.com
10 | All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without modification,
13 | are permitted provided that the following conditions are met:
14 |
15 | * Redistributions of source code must retain the above copyright notice, this list
16 | of conditions and the following disclaimer.
17 |
18 | * Redistributions in binary form must reproduce the above copyright notice, this
19 | list of conditions and the following disclaimer in the documentation and/or other
20 | materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 |
36 |
37 | */
38 | #include "u8x8.h"
39 |
40 |
41 |
42 |
43 | static const uint8_t u8x8_d_sbn1661_init_seq[] = {
44 | U8X8_C(0x0c0), /* display start at line 0 */
45 | U8X8_C(0x0a0), /* a0: ADC forward, a1: ADC reverse */
46 | U8X8_C(0x0a4), /* a4: normal driving, a5: power save */
47 | U8X8_C(0x0a9), /* a8: 1/16, a9: 1/32 duty */
48 |
49 | //U8X8_C(0x0af), /* display on */
50 |
51 | U8X8_END() /* end of sequence */
52 | };
53 |
54 | static const uint8_t u8x8_d_sbn1661_powersave0_seq[] = {
55 | U8X8_C(0x0af), /* display on */
56 | U8X8_END() /* end of sequence */
57 | };
58 |
59 | static const uint8_t u8x8_d_sbn1661_powersave1_seq[] = {
60 | U8X8_C(0x0ae), /* display off */
61 | U8X8_END() /* end of sequence */
62 | };
63 |
64 |
65 | struct u8x8_sbn1661_vars
66 | {
67 | uint8_t *ptr;
68 | uint8_t x;
69 | uint8_t c;
70 | uint8_t arg_int;
71 | };
72 |
73 | #ifdef NOT_USED
74 | static void u8x8_sbn1661_out(u8x8_t *u8x8, struct u8x8_sbn1661_vars *v, void *arg_ptr)
75 | {
76 | uint8_t cnt;
77 | u8x8_cad_SendCmd(u8x8, 0x000 | ((v->x << 3) & 63) );
78 | u8x8_cad_SendCmd(u8x8, 0x0b8 | (((u8x8_tile_t *)arg_ptr)->y_pos));
79 |
80 | while( v->arg_int > 0 )
81 | {
82 | /* calculate tiles to next boundary (end or chip limit) */
83 | cnt = v->x;
84 | cnt += 8;
85 | cnt &= 0x0f8;
86 | cnt -= v->x;
87 |
88 | if ( cnt > v->c )
89 | cnt = v->c;
90 |
91 | /* of course we still could use cnt=1 here... */
92 | /* but setting cnt to 1 is not very efficient */
93 | //cnt = 1;
94 |
95 | v->x +=cnt;
96 | v->c-=cnt;
97 | cnt<<=3;
98 | u8x8_cad_SendData(u8x8, cnt, v->ptr); /* note: SendData can not handle more than 255 bytes */
99 | v->ptr += cnt;
100 |
101 | if ( v->c == 0 )
102 | {
103 | v->ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
104 | v->c = ((u8x8_tile_t *)arg_ptr)->cnt;
105 | v->arg_int--;
106 | }
107 | if ( ((v->x) & 7) == 0 )
108 | break;
109 | }
110 | }
111 | #endif /* NOT_USED */
112 |
113 |
114 | static const u8x8_display_info_t u8x8_sbn1661_122x32_display_info =
115 | {
116 | /* chip_enable_level = */ 0, /* sbn1661: Not used */
117 | /* chip_disable_level = */ 1, /* sbn1661: Not used */
118 |
119 | /* post_chip_enable_wait_ns = */ 100,
120 | /* pre_chip_disable_wait_ns = */ 20,
121 | /* reset_pulse_width_ms = */ 1,
122 | /* post_reset_wait_ms = */ 6, /* */
123 | /* sda_setup_time_ns = */ 12,
124 | /* sck_pulse_width_ns = */ 75, /* sbn1661: Not used */
125 | /* sck_clock_hz = */ 4000000UL, /* sbn1661: Not used */
126 | /* spi_mode = */ 0, /* active high, rising edge */
127 | /* i2c_bus_clock_100kHz = */ 4, /* sbn1661: Not used */
128 | /* data_setup_time_ns = */ 200,
129 | /* write_pulse_width_ns = */ 200, /* */
130 | /* tile_width = */ 16, /* width of 16*8=128 pixel */
131 | /* tile_hight = */ 4,
132 | /* default_x_offset = */ 0,
133 | /* flipmode_x_offset = */ 0,
134 | /* pixel_width = */ 122,
135 | /* pixel_height = */ 32
136 | };
137 |
138 | uint8_t u8x8_d_sbn1661_122x32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
139 | {
140 | uint8_t *ptr;
141 | //uint8_t x;
142 | //uint8_t c;
143 |
144 | switch(msg)
145 | {
146 | case U8X8_MSG_DISPLAY_SETUP_MEMORY:
147 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_sbn1661_122x32_display_info);
148 | break;
149 | case U8X8_MSG_DISPLAY_INIT:
150 | u8x8_d_helper_display_init(u8x8);
151 |
152 | u8x8->cad_cb(u8x8, U8X8_MSG_CAD_START_TRANSFER, 0, NULL);
153 | u8x8_cad_SendSequence(u8x8, u8x8_d_sbn1661_init_seq);
154 | u8x8->cad_cb(u8x8, U8X8_MSG_CAD_END_TRANSFER, 0, NULL);
155 |
156 | u8x8->cad_cb(u8x8, U8X8_MSG_CAD_START_TRANSFER, 1, NULL);
157 | u8x8_cad_SendSequence(u8x8, u8x8_d_sbn1661_init_seq);
158 | u8x8->cad_cb(u8x8, U8X8_MSG_CAD_END_TRANSFER, 1, NULL);
159 | break;
160 | case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
161 |
162 | if ( arg_int == 0 )
163 | {
164 | u8x8->cad_cb(u8x8, U8X8_MSG_CAD_START_TRANSFER, 0, NULL);
165 | u8x8_cad_SendSequence(u8x8, u8x8_d_sbn1661_powersave0_seq);
166 | u8x8->cad_cb(u8x8, U8X8_MSG_CAD_END_TRANSFER, 0, NULL);
167 |
168 | u8x8->cad_cb(u8x8, U8X8_MSG_CAD_START_TRANSFER, 1, NULL);
169 | u8x8_cad_SendSequence(u8x8, u8x8_d_sbn1661_powersave0_seq);
170 | u8x8->cad_cb(u8x8, U8X8_MSG_CAD_END_TRANSFER, 1, NULL);
171 | }
172 | else
173 | {
174 | u8x8->cad_cb(u8x8, U8X8_MSG_CAD_START_TRANSFER, 0, NULL);
175 | u8x8_cad_SendSequence(u8x8, u8x8_d_sbn1661_powersave1_seq);
176 | u8x8->cad_cb(u8x8, U8X8_MSG_CAD_END_TRANSFER, 0, NULL);
177 |
178 | u8x8->cad_cb(u8x8, U8X8_MSG_CAD_START_TRANSFER, 1, NULL);
179 | u8x8_cad_SendSequence(u8x8, u8x8_d_sbn1661_powersave1_seq);
180 | u8x8->cad_cb(u8x8, U8X8_MSG_CAD_END_TRANSFER, 1, NULL);
181 |
182 | }
183 | break;
184 | case U8X8_MSG_DISPLAY_DRAW_TILE:
185 |
186 | ptr = ((u8x8_tile_t *)arg_ptr)->tile_ptr;
187 | // x and c are ignored (u8g2 only)
188 | //x = ((u8x8_tile_t *)arg_ptr)->x_pos;
189 | //c = ((u8x8_tile_t *)arg_ptr)->cnt;
190 |
191 | u8x8->cad_cb(u8x8, U8X8_MSG_CAD_START_TRANSFER, 0, NULL);
192 | u8x8_cad_SendCmd(u8x8, 0x000 | 0); // column 0
193 | u8x8_cad_SendCmd(u8x8, 0x0b8 | (((u8x8_tile_t *)arg_ptr)->y_pos));
194 | u8x8_cad_SendData(u8x8, 61, ptr); /* note: SendData can not handle more than 255 bytes */
195 | u8x8->cad_cb(u8x8, U8X8_MSG_CAD_END_TRANSFER, 0, NULL);
196 |
197 | ptr += 61;
198 |
199 | u8x8->cad_cb(u8x8, U8X8_MSG_CAD_START_TRANSFER, 1, NULL);
200 | u8x8_cad_SendCmd(u8x8, 0x000 | 0); // column 0
201 | u8x8_cad_SendCmd(u8x8, 0x0b8 | (((u8x8_tile_t *)arg_ptr)->y_pos));
202 |
203 | u8x8_cad_SendData(u8x8, 61, ptr); /* note: SendData can not handle more than 255 bytes */
204 | u8x8->cad_cb(u8x8, U8X8_MSG_CAD_END_TRANSFER, 1, NULL);
205 |
206 | break;
207 | default:
208 | return 0;
209 | }
210 | return 1;
211 | }
212 |
213 | uint8_t u8x8_d_sed1520_122x32(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
214 | {
215 | return u8x8_d_sbn1661_122x32(u8x8, msg, arg_int, arg_ptr);
216 |
217 | }
218 |
--------------------------------------------------------------------------------
/src/u8x8_d_stdio.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_d_stdio.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 | #include "u8x8.h"
37 |
38 | #include
39 |
40 | #define W 8
41 | #define H 2
42 |
43 | uint8_t bitmap[W*H*8];
44 |
45 | void bitmap_place_tile(uint8_t x, uint8_t y, uint8_t *tile)
46 | {
47 | uint8_t i;
48 | for(i = 0; i < 8; i++ )
49 | bitmap[x*8+y*W*8+i] = tile[i];
50 | }
51 |
52 | void bitmap_show(void)
53 | {
54 | int x, y;
55 | for( y = 0; y < H*8; y++ )
56 | {
57 | for( x = 0; x < W*8; x++ )
58 | {
59 | if ( (bitmap[x+(y/8)*W*8] & (1<<((y&7)))) != 0 )
60 | {
61 | printf("*");
62 | }
63 | else
64 | {
65 | printf(".");
66 | }
67 | }
68 | printf("\n");
69 | }
70 | }
71 |
72 |
73 | uint8_t u8x8_d_stdio(U8X8_UNUSED u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
74 | {
75 | switch(msg)
76 | {
77 | case U8X8_MSG_DISPLAY_INIT:
78 | break;
79 | case U8X8_MSG_DISPLAY_SET_POWER_SAVE:
80 | if ( arg_int == 0 )
81 | bitmap_show();
82 | break;
83 | case U8X8_MSG_DISPLAY_SET_CONTRAST:
84 | break;
85 | case U8X8_MSG_DISPLAY_DRAW_TILE:
86 | bitmap_place_tile(((u8x8_tile_t *)arg_ptr)->x_pos, ((u8x8_tile_t *)arg_ptr)->y_pos, ((u8x8_tile_t *)arg_ptr)->tile_ptr);
87 | break;
88 | default:
89 | break;
90 | }
91 | return 1;
92 | }
93 |
94 |
95 |
96 | void u8x8_SetupStdio(u8x8_t *u8x8)
97 | {
98 | u8x8_SetupDefaults(u8x8);
99 | u8x8->display_cb = u8x8_d_stdio;
100 | }
101 |
102 |
--------------------------------------------------------------------------------
/src/u8x8_debounce.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_debounce.c
4 |
5 | Key/button simple debounce algorithm (Addon for u8x8)
6 |
7 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
8 |
9 | Copyright (c) 2016, olikraus@gmail.com
10 | All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without modification,
13 | are permitted provided that the following conditions are met:
14 |
15 | * Redistributions of source code must retain the above copyright notice, this list
16 | of conditions and the following disclaimer.
17 |
18 | * Redistributions in binary form must reproduce the above copyright notice, this
19 | list of conditions and the following disclaimer in the documentation and/or other
20 | materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 |
36 | */
37 |
38 | #include "u8x8.h"
39 |
40 | static uint8_t u8x8_read_pin_state(u8x8_t *u8x8)
41 | {
42 | uint8_t i;
43 | uint8_t pin_state;
44 |
45 | pin_state = 255; /* be compatible with the setup of the default pin setup, which is 255 */
46 | for( i = 0; i < U8X8_PIN_INPUT_CNT; i++ )
47 | {
48 | pin_state <<= 1;
49 |
50 | /* the callback function should put the return value into this variable */
51 | u8x8->gpio_result = 1;
52 | u8x8_gpio_call(u8x8, U8X8_MSG_GPIO(i+U8X8_PIN_OUTPUT_CNT), 0);
53 | pin_state |= u8x8->gpio_result & 1;
54 | }
55 |
56 | return pin_state;
57 | }
58 |
59 | /*
60 | return 0 to U8X8_PIN_INPUT_CNT-1 if there is a difference
61 | return U8X8_PIN_INPUT_CNT if there is no difference
62 | */
63 | static uint8_t u8x8_find_first_diff(uint8_t a, uint8_t b)
64 | {
65 | uint8_t mask;
66 | uint8_t i;
67 | mask = 1;
68 | i = U8X8_PIN_INPUT_CNT;
69 | do
70 | {
71 | i--;
72 | if ( (a & mask) != (b & mask) )
73 | return i;
74 | mask <<= 1;
75 | } while( i > 0 );
76 | return U8X8_PIN_INPUT_CNT;
77 | }
78 |
79 | /*
80 | State A:
81 | u8x8->debounce_last_pin_state == current_state
82 | --> State A
83 | u8x8->debounce_last_pin_state != current_state
84 | --> u8x8->debounce_last_pin_state = current_state
85 | --> State B + cnt
86 |
87 | State B + cnt
88 | --> state--
89 |
90 | State B
91 | u8x8->debounce_last_pin_state == current_state
92 | --> keypress detected
93 | --> State C
94 | u8x8->debounce_last_pin_state != current_state
95 | --> State A
96 |
97 | State C
98 | u8x8->debounce_last_pin_state == current_state
99 | --> State C
100 | u8x8->debounce_last_pin_state != current_state
101 | --> State A
102 |
103 | */
104 |
105 | #ifdef __unix__xxxxxx_THIS_IS_DISABLED
106 |
107 | #include
108 | #include
109 | uint8_t u8x8_GetMenuEvent(u8x8_t *u8x8)
110 | {
111 | int c;
112 | c = getc(stdin);
113 | switch(c)
114 | {
115 | case 'n':
116 | return U8X8_MSG_GPIO_MENU_NEXT;
117 | case 'p':
118 | return U8X8_MSG_GPIO_MENU_PREV;
119 | case 's':
120 | return U8X8_MSG_GPIO_MENU_SELECT;
121 | case 'h':
122 | return U8X8_MSG_GPIO_MENU_HOME;
123 | case 'x':
124 | exit(0);
125 | default:
126 | puts("press n, p, s, h or x");
127 | break;
128 | }
129 | return 0;
130 | }
131 |
132 |
133 | #else /* __unix__ */
134 |
135 |
136 | #define U8X8_DEBOUNCE_WAIT 2
137 | /* do debounce and return a GPIO msg which indicates the event */
138 | /* returns 0, if there is no event */
139 | #if defined(__GNUC__) && !defined(__CYGWIN__)
140 | # pragma weak u8x8_GetMenuEvent
141 | #endif
142 | uint8_t u8x8_GetMenuEvent(u8x8_t *u8x8)
143 | {
144 | uint8_t pin_state;
145 | uint8_t result_msg = 0; /* invalid message, no event */
146 |
147 | pin_state = u8x8_read_pin_state(u8x8);
148 |
149 | /* States A, B, C & D are encoded in the upper 4 bit*/
150 | switch(u8x8->debounce_state)
151 | {
152 | case 0x00: /* State A, default state */
153 | if ( u8x8->debounce_default_pin_state != pin_state )
154 | {
155 | //u8x8->debounce_last_pin_state = pin_state;
156 | u8x8->debounce_state = 0x010 + U8X8_DEBOUNCE_WAIT;
157 | }
158 | break;
159 | case 0x10: /* State B */
160 | //if ( u8x8->debounce_last_pin_state != pin_state )
161 | if ( u8x8->debounce_default_pin_state == pin_state )
162 | {
163 | u8x8->debounce_state = 0x00; /* back to state A */
164 | }
165 | else
166 | {
167 | /* keypress detected */
168 | u8x8->debounce_last_pin_state = pin_state;
169 | //result_msg = U8X8_MSG_GPIO_MENU_NEXT;
170 | u8x8->debounce_state = 0x020 + U8X8_DEBOUNCE_WAIT; /* got to state C */
171 | }
172 | break;
173 |
174 | case 0x20: /* State C */
175 | if ( u8x8->debounce_last_pin_state != pin_state )
176 | {
177 | u8x8->debounce_state = 0x00; /* back to state A */
178 | }
179 | else
180 | {
181 | u8x8->debounce_state = 0x030; /* got to state D */
182 | }
183 | break;
184 |
185 | case 0x30: /* State D */
186 | /* wait until key release */
187 | if ( u8x8->debounce_default_pin_state == pin_state )
188 | {
189 | u8x8->debounce_state = 0x00; /* back to state A */
190 | result_msg = U8X8_MSG_GPIO(u8x8_find_first_diff(u8x8->debounce_default_pin_state, u8x8->debounce_last_pin_state)+U8X8_PIN_OUTPUT_CNT);
191 | }
192 | else
193 | {
194 | //result_msg = U8X8_MSG_GPIO_MENU_NEXT;
195 | // maybe implement autorepeat here
196 | }
197 | break;
198 | default:
199 | u8x8->debounce_state--; /* count down, until there is a valid state */
200 | break;
201 | }
202 | return result_msg;
203 | }
204 |
205 | #endif /* __unix__ */
206 |
--------------------------------------------------------------------------------
/src/u8x8_display.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_display.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 |
35 | Abstraction layer for the graphics controller.
36 | Main goal is the placement of a 8x8 pixel block (tile) on the display.
37 |
38 | */
39 |
40 |
41 | #include "u8x8.h"
42 |
43 |
44 | /*==========================================*/
45 | /* internal library function */
46 |
47 | /*
48 | this is a helper function for the U8X8_MSG_DISPLAY_SETUP_MEMORY function.
49 | It can be called within the display callback function to carry out the usual standard tasks.
50 |
51 | */
52 | void u8x8_d_helper_display_setup_memory(u8x8_t *u8x8, const u8x8_display_info_t *display_info)
53 | {
54 | /* 1) set display info struct */
55 | u8x8->display_info = display_info;
56 | u8x8->x_offset = u8x8->display_info->default_x_offset;
57 | }
58 |
59 | /*
60 | this is a helper function for the U8X8_MSG_DISPLAY_INIT function.
61 | It can be called within the display callback function to carry out the usual standard tasks.
62 |
63 | */
64 | void u8x8_d_helper_display_init(u8x8_t *u8x8)
65 | {
66 | /* 2) apply port directions to the GPIO lines and apply default values for the IO lines*/
67 | u8x8_gpio_Init(u8x8);
68 | u8x8_cad_Init(u8x8); /* this will also call U8X8_MSG_BYTE_INIT, byte init will NOT call GPIO_INIT */
69 |
70 | /* 3) do reset */
71 | u8x8_gpio_SetReset(u8x8, 1);
72 | u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_MILLI, u8x8->display_info->reset_pulse_width_ms);
73 | u8x8_gpio_SetReset(u8x8, 0);
74 | u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_MILLI, u8x8->display_info->reset_pulse_width_ms);
75 | u8x8_gpio_SetReset(u8x8, 1);
76 | u8x8_gpio_Delay(u8x8, U8X8_MSG_DELAY_MILLI, u8x8->display_info->post_reset_wait_ms);
77 | }
78 |
79 | /*==========================================*/
80 | /* official functions */
81 |
82 | uint8_t u8x8_DrawTile(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t cnt, uint8_t *tile_ptr)
83 | {
84 | u8x8_tile_t tile;
85 | tile.x_pos = x;
86 | tile.y_pos = y;
87 | tile.cnt = cnt;
88 | tile.tile_ptr = tile_ptr;
89 | return u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_DRAW_TILE, 1, (void *)&tile);
90 | }
91 |
92 | /* should be implemented as macro */
93 | void u8x8_SetupMemory(u8x8_t *u8x8)
94 | {
95 | u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SETUP_MEMORY, 0, NULL);
96 | }
97 |
98 | /*
99 | This will just init the display interface, compared to InitDisplay, it will not issue a reset and also not upload the init code.
100 | Comparison:
101 | Call u8x8_InitInterface u8x8_InitDisplay
102 | Init Interface yes yes
103 | Reset Display no yes
104 | Upload Display Init Code no yes
105 |
106 | u8x8_InitInterface() is an alternative function to u8x8_InitDisplay(). Do not call both.
107 |
108 | */
109 | void u8x8_InitInterface(u8x8_t *u8x8)
110 | {
111 | u8x8_gpio_Init(u8x8);
112 | u8x8_cad_Init(u8x8); /* this will also call U8X8_MSG_BYTE_INIT, byte init will NOT call GPIO_INIT */
113 | }
114 |
115 | /*
116 | This will sent the display init message to the display.
117 | The display itself will then call u8x8_d_helper_display_init() from above. This includes:
118 | GPIO Init (set port directions)
119 | BYTE init (part of CAD init: which may set some levels)
120 | CAD init (which will set things like I2C default address)
121 | Issue a reset to the display: This will usually turn off the display
122 | Additonally each display will set the init code to the display, which will also turn of the display in most cases (Arduino code disable power save mode later)
123 |
124 | Actually this procedure should be better called InitInterfaceAndDisplay, because it actually does both.
125 |
126 | InitDisplay is called by the Arduino begin() function.
127 |
128 | In some cases it is not required to init the display (for example if the display is already running, but the controller comes out of deep sleep mode).
129 | Then InitDisplay can be skipped, but u8x8_InitInterface() (== u8x8_gpio_Init() and u8x8_cad_Init()) need to be executed.
130 |
131 | */
132 | void u8x8_InitDisplay(u8x8_t *u8x8)
133 | {
134 | u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_INIT, 0, NULL);
135 | }
136 |
137 | void u8x8_SetPowerSave(u8x8_t *u8x8, uint8_t is_enable)
138 | {
139 | u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SET_POWER_SAVE, is_enable, NULL);
140 | }
141 |
142 | void u8x8_SetFlipMode(u8x8_t *u8x8, uint8_t mode)
143 | {
144 | u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SET_FLIP_MODE, mode, NULL);
145 | }
146 |
147 | void u8x8_SetContrast(u8x8_t *u8x8, uint8_t value)
148 | {
149 | u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_SET_CONTRAST, value, NULL);
150 | }
151 |
152 | void u8x8_RefreshDisplay(u8x8_t *u8x8)
153 | {
154 | u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_REFRESH, 0, NULL);
155 | }
156 |
157 | void u8x8_ClearDisplayWithTile(u8x8_t *u8x8, const uint8_t *buf)
158 | {
159 | u8x8_tile_t tile;
160 | uint8_t h;
161 |
162 | tile.x_pos = 0;
163 | tile.cnt = 1;
164 | tile.tile_ptr = (uint8_t *)buf; /* tile_ptr should be const, but isn't */
165 |
166 | h = u8x8->display_info->tile_height;
167 | tile.y_pos = 0;
168 | do
169 | {
170 | u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_DRAW_TILE, u8x8->display_info->tile_width, (void *)&tile);
171 | tile.y_pos++;
172 | } while( tile.y_pos < h );
173 | }
174 |
175 | void u8x8_ClearDisplay(u8x8_t *u8x8)
176 | {
177 | uint8_t buf[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
178 | u8x8_ClearDisplayWithTile(u8x8, buf);
179 | }
180 |
181 | void u8x8_FillDisplay(u8x8_t *u8x8)
182 | {
183 | uint8_t buf[8] = { 255, 255, 255, 255, 255, 255, 255, 255 };
184 | u8x8_ClearDisplayWithTile(u8x8, buf);
185 | }
186 |
187 | void u8x8_ClearLine(u8x8_t *u8x8, uint8_t line)
188 | {
189 | uint8_t buf[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
190 | u8x8_tile_t tile;
191 | if ( line < u8x8->display_info->tile_height )
192 | {
193 | tile.x_pos = 0;
194 | tile.y_pos = line;
195 | tile.cnt = 1;
196 | tile.tile_ptr = (uint8_t *)buf; /* tile_ptr should be const, but isn't */
197 | u8x8->display_cb(u8x8, U8X8_MSG_DISPLAY_DRAW_TILE, u8x8->display_info->tile_width, (void *)&tile);
198 | }
199 | }
--------------------------------------------------------------------------------
/src/u8x8_fonts.c:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/src/u8x8_fonts.c
--------------------------------------------------------------------------------
/src/u8x8_gpio.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_gpio.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 |
37 | #include "u8x8.h"
38 |
39 |
40 | void u8x8_gpio_call(u8x8_t *u8x8, uint8_t msg, uint8_t arg)
41 | {
42 | u8x8->gpio_and_delay_cb(u8x8, msg, arg, NULL);
43 | }
44 |
45 | /*
46 | void u8x8_gpio_Delay(u8x8_t *u8x8, uint8_t msg, uint8_t dly)
47 | {
48 | u8x8->gpio_and_delay_cb(u8x8, msg, dly, NULL);
49 | }
50 | */
--------------------------------------------------------------------------------
/src/u8x8_input_value.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_input_value.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 | #include "u8x8.h"
37 |
38 | /*
39 | return:
40 | 0: value is not changed (HOME/Break Button pressed)
41 | 1: value has been updated
42 | */
43 |
44 | uint8_t u8x8_UserInterfaceInputValue(u8x8_t *u8x8, const char *title, const char *pre, uint8_t *value, uint8_t lo, uint8_t hi, uint8_t digits, const char *post)
45 | {
46 | uint8_t height;
47 | uint8_t y;
48 | uint8_t width;
49 | uint8_t x;
50 | uint8_t local_value = *value;
51 | uint8_t r;
52 | uint8_t event;
53 |
54 | /* calculate overall height of the input value box */
55 | height = 1; /* button line */
56 | height += u8x8_GetStringLineCnt(title);
57 |
58 | /* calculate offset from top */
59 | y = 0;
60 | if ( height < u8x8_GetRows(u8x8) )
61 | {
62 | y = u8x8_GetRows(u8x8);
63 | y -= height;
64 | y /= 2;
65 | }
66 |
67 | /* calculate offset from left for the label */
68 | x = 0;
69 | width = u8x8_GetUTF8Len(u8x8, pre);
70 | width += digits;
71 | width += u8x8_GetUTF8Len(u8x8, post);
72 | if ( width < u8x8_GetCols(u8x8) )
73 | {
74 | x = u8x8_GetCols(u8x8);
75 | x -= width;
76 | x /= 2;
77 | }
78 |
79 | /* render */
80 | u8x8_ClearDisplay(u8x8); /* required, because not everything is filled */
81 | u8x8_SetInverseFont(u8x8, 0);
82 | y += u8x8_DrawUTF8Lines(u8x8, 0, y, u8x8_GetCols(u8x8), title);
83 | x += u8x8_DrawUTF8(u8x8, x, y, pre);
84 | u8x8_DrawUTF8(u8x8, x+digits, y, post);
85 | u8x8_SetInverseFont(u8x8, 1);
86 |
87 | /* event loop */
88 | u8x8_DrawUTF8(u8x8, x, y, u8x8_u8toa(local_value, digits));
89 | for(;;)
90 | {
91 | event = u8x8_GetMenuEvent(u8x8);
92 | if ( event == U8X8_MSG_GPIO_MENU_SELECT )
93 | {
94 | *value = local_value;
95 | r = 1;
96 | break;
97 | }
98 | else if ( event == U8X8_MSG_GPIO_MENU_HOME )
99 | {
100 | r = 0;
101 | break;
102 | }
103 | else if ( event == U8X8_MSG_GPIO_MENU_NEXT || event == U8X8_MSG_GPIO_MENU_UP )
104 | {
105 | if ( local_value >= hi )
106 | local_value = lo;
107 | else
108 | local_value++;
109 | u8x8_DrawUTF8(u8x8, x, y, u8x8_u8toa(local_value, digits));
110 | }
111 | else if ( event == U8X8_MSG_GPIO_MENU_PREV || event == U8X8_MSG_GPIO_MENU_DOWN )
112 | {
113 | if ( local_value <= lo )
114 | local_value = hi;
115 | else
116 | local_value--;
117 | u8x8_DrawUTF8(u8x8, x, y, u8x8_u8toa(local_value, digits));
118 | }
119 | }
120 |
121 | u8x8_SetInverseFont(u8x8, 0);
122 | return r;
123 | }
124 |
--------------------------------------------------------------------------------
/src/u8x8_message.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_message.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 | #include "u8x8.h"
37 |
38 | uint8_t u8x8_draw_button_line(u8x8_t *u8x8, uint8_t y, uint8_t w, uint8_t cursor, const char *s)
39 | {
40 | uint8_t i;
41 | uint8_t cnt;
42 | uint8_t total;
43 | uint8_t d;
44 | uint8_t x;
45 | cnt = u8x8_GetStringLineCnt(s);
46 |
47 | /* calculate the width of the button */
48 | total = 0;
49 | for( i = 0; i < cnt; i++ )
50 | {
51 | total += u8x8_GetUTF8Len(u8x8, u8x8_GetStringLineStart(i, s));
52 | }
53 | total += (cnt-1); /* had one space between the buttons */
54 |
55 | /* calculate the left offset */
56 | d = 0;
57 | if ( total < w )
58 | {
59 | d = w;
60 | d -= total;
61 | d /= 2;
62 | }
63 |
64 | /* draw the buttons */
65 | x = d;
66 | u8x8_SetInverseFont(u8x8, 0);
67 | for( i = 0; i < cnt; i++ )
68 | {
69 | if ( i == cursor )
70 | u8x8_SetInverseFont(u8x8, 1);
71 |
72 | x+=u8x8_DrawUTF8(u8x8, x, y, u8x8_GetStringLineStart(i, s));
73 | u8x8_SetInverseFont(u8x8, 0);
74 | x+=u8x8_DrawUTF8(u8x8, x, y, " ");
75 | }
76 |
77 | /* return the number of buttons */
78 | return cnt;
79 | }
80 |
81 | /*
82 | title1: Multiple lines,separated by '\n'
83 | title2: A single line/string which is terminated by '\0' or '\n' . "title2" accepts the return value from u8x8_GetStringLineStart()
84 | title3: Multiple lines,separated by '\n'
85 | buttons: one more more buttons separated by '\n' and terminated with '\0'
86 | */
87 |
88 | uint8_t u8x8_UserInterfaceMessage(u8x8_t *u8x8, const char *title1, const char *title2, const char *title3, const char *buttons)
89 | {
90 | uint8_t height;
91 | uint8_t y;
92 | uint8_t cursor = 0;
93 | uint8_t button_cnt;
94 | uint8_t event;
95 |
96 | u8x8_SetInverseFont(u8x8, 0);
97 |
98 | /* calculate overall height of the message box */
99 | height = 1; /* button line */
100 | height += u8x8_GetStringLineCnt(title1);
101 | if ( title2 != NULL )
102 | height ++;
103 | height += u8x8_GetStringLineCnt(title3);
104 |
105 | /* calculate offset from top */
106 | y = 0;
107 | if ( height < u8x8_GetRows(u8x8) )
108 | {
109 | y = u8x8_GetRows(u8x8);
110 | y -= height;
111 | y /= 2;
112 | }
113 |
114 | /* draw message box */
115 |
116 | u8x8_ClearDisplay(u8x8); /* required, because not everything is filled */
117 |
118 | y += u8x8_DrawUTF8Lines(u8x8, 0, y, u8x8_GetCols(u8x8), title1);
119 | if ( title2 != NULL )
120 | {
121 | u8x8_DrawUTF8Line(u8x8, 0, y, u8x8_GetCols(u8x8), title2);
122 | y++;
123 | }
124 | y += u8x8_DrawUTF8Lines(u8x8, 0, y, u8x8_GetCols(u8x8), title3);
125 |
126 | button_cnt = u8x8_draw_button_line(u8x8, y, u8x8_GetCols(u8x8), cursor, buttons);
127 |
128 | for(;;)
129 | {
130 | event = u8x8_GetMenuEvent(u8x8);
131 | if ( event == U8X8_MSG_GPIO_MENU_SELECT )
132 | return cursor+1;
133 | else if ( event == U8X8_MSG_GPIO_MENU_HOME )
134 | break;
135 | else if ( event == U8X8_MSG_GPIO_MENU_NEXT || event == U8X8_MSG_GPIO_MENU_UP )
136 | {
137 | cursor++;
138 | if ( cursor >= button_cnt )
139 | cursor = 0;
140 | u8x8_draw_button_line(u8x8, y, u8x8_GetCols(u8x8), cursor, buttons);
141 | }
142 | else if ( event == U8X8_MSG_GPIO_MENU_PREV || event == U8X8_MSG_GPIO_MENU_DOWN )
143 | {
144 | if ( cursor == 0 )
145 | cursor = button_cnt;
146 | cursor--;
147 | u8x8_draw_button_line(u8x8, y, u8x8_GetCols(u8x8), cursor, buttons);
148 | }
149 | }
150 | return 0;
151 | }
152 |
153 |
--------------------------------------------------------------------------------
/src/u8x8_selection_list.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_selection_list.c
4 |
5 | selection list with scroll option
6 |
7 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
8 |
9 | Copyright (c) 2016, olikraus@gmail.com
10 | All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without modification,
13 | are permitted provided that the following conditions are met:
14 |
15 | * Redistributions of source code must retain the above copyright notice, this list
16 | of conditions and the following disclaimer.
17 |
18 | * Redistributions in binary form must reproduce the above copyright notice, this
19 | list of conditions and the following disclaimer in the documentation and/or other
20 | materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 |
36 | */
37 |
38 | #include "u8x8.h"
39 |
40 | /*
41 | increase the cursor position
42 | */
43 | void u8sl_Next(u8sl_t *u8sl)
44 | {
45 | u8sl->current_pos++;
46 | if ( u8sl->current_pos >= u8sl->total )
47 | {
48 | u8sl->current_pos = 0;
49 | u8sl->first_pos = 0;
50 | }
51 | else
52 | {
53 | if ( u8sl->first_pos + u8sl->visible <= u8sl->current_pos + 1 )
54 | {
55 | u8sl->first_pos = u8sl->current_pos - u8sl->visible + 1;
56 | }
57 | }
58 | }
59 |
60 | void u8sl_Prev(u8sl_t *u8sl)
61 | {
62 | if ( u8sl->current_pos == 0 )
63 | {
64 | u8sl->current_pos = u8sl->total - 1;
65 | u8sl->first_pos = 0;
66 | if ( u8sl->total > u8sl->visible )
67 | u8sl->first_pos = u8sl->total - u8sl->visible;
68 | }
69 | else
70 | {
71 | u8sl->current_pos--;
72 | if ( u8sl->first_pos > u8sl->current_pos )
73 | u8sl->first_pos = u8sl->current_pos;
74 | }
75 | }
76 |
77 | void u8x8_DrawSelectionList(u8x8_t *u8x8, u8sl_t *u8sl, u8x8_sl_cb sl_cb, const void *aux)
78 | {
79 | uint8_t i;
80 | for( i = 0; i < u8sl->visible; i++ )
81 | {
82 | sl_cb(u8x8, u8sl, i+u8sl->first_pos, aux);
83 | }
84 | }
85 |
86 | /* selection list with string line */
87 | void u8x8_sl_string_line_cb(u8x8_t *u8x8, u8sl_t *u8sl, uint8_t idx, const void *aux)
88 | {
89 | const char *s;
90 | uint8_t row;
91 | /* calculate offset from display upper border */
92 | row = u8sl->y;
93 |
94 | /* calculate target pos */
95 | row += idx;
96 | row -= u8sl->first_pos;
97 |
98 | /* check whether this is the current cursor line */
99 | if ( idx == u8sl->current_pos )
100 | u8x8_SetInverseFont(u8x8, 1);
101 | else
102 | u8x8_SetInverseFont(u8x8, 0);
103 |
104 | /* get the line from the array */
105 | s = u8x8_GetStringLineStart(idx, (const char *)aux);
106 |
107 | /* draw the line */
108 | if ( s == NULL )
109 | s = "";
110 | u8x8_DrawUTF8Line(u8x8, u8sl->x, row, u8x8_GetCols(u8x8), s);
111 | u8x8_SetInverseFont(u8x8, 0);
112 | }
113 |
114 | /*
115 | title: NULL for no title, valid str for title line. Can contain mutliple lines, separated by '\n'
116 | start_pos: default position for the cursor (starts with 1)
117 | sl: string list (list of strings separated by \n)
118 | returns 0 if user has pressed the home key
119 | returns the selected line+1 if user has pressed the select key (e.g. 1 for the first line)
120 | */
121 | uint8_t u8x8_UserInterfaceSelectionList(u8x8_t *u8x8, const char *title, uint8_t start_pos, const char *sl)
122 | {
123 | u8sl_t u8sl;
124 | uint8_t event;
125 | uint8_t title_lines;
126 |
127 | if ( start_pos > 0 )
128 | start_pos--;
129 |
130 | u8sl.visible = u8x8_GetRows(u8x8);
131 | u8sl.total = u8x8_GetStringLineCnt(sl);
132 | u8sl.first_pos = 0;
133 | u8sl.current_pos = start_pos;
134 | u8sl.x = 0;
135 | u8sl.y = 0;
136 |
137 |
138 | //u8x8_ClearDisplay(u8x8); /* not required because all is 100% filled */
139 | u8x8_SetInverseFont(u8x8, 0);
140 |
141 | if ( title != NULL )
142 | {
143 | title_lines = u8x8_DrawUTF8Lines(u8x8, u8sl.x, u8sl.y, u8x8_GetCols(u8x8), title);
144 | u8sl.y+=title_lines;
145 | u8sl.visible-=title_lines;
146 | }
147 |
148 | if ( u8sl.current_pos >= u8sl.total )
149 | u8sl.current_pos = u8sl.total-1;
150 |
151 |
152 | u8x8_DrawSelectionList(u8x8, &u8sl, u8x8_sl_string_line_cb, sl);
153 |
154 | for(;;)
155 | {
156 | event = u8x8_GetMenuEvent(u8x8);
157 | if ( event == U8X8_MSG_GPIO_MENU_SELECT )
158 | return u8sl.current_pos+1;
159 | else if ( event == U8X8_MSG_GPIO_MENU_HOME )
160 | return 0;
161 | else if ( event == U8X8_MSG_GPIO_MENU_NEXT || event == U8X8_MSG_GPIO_MENU_DOWN )
162 | {
163 | u8sl_Next(&u8sl);
164 | u8x8_DrawSelectionList(u8x8, &u8sl, u8x8_sl_string_line_cb, sl);
165 | }
166 | else if ( event == U8X8_MSG_GPIO_MENU_PREV || event == U8X8_MSG_GPIO_MENU_UP )
167 | {
168 | u8sl_Prev(&u8sl);
169 | u8x8_DrawSelectionList(u8x8, &u8sl, u8x8_sl_string_line_cb, sl);
170 | }
171 | }
172 | }
173 |
174 |
--------------------------------------------------------------------------------
/src/u8x8_setup.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_setup.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 |
37 | #include "u8x8.h"
38 |
39 | /* universal dummy callback, which will be default for all callbacks */
40 | uint8_t u8x8_dummy_cb(U8X8_UNUSED u8x8_t *u8x8, U8X8_UNUSED uint8_t msg, U8X8_UNUSED uint8_t arg_int, U8X8_UNUSED void *arg_ptr)
41 | {
42 | /* the dummy callback will not handle any message and will fail for all messages */
43 | return 0;
44 | }
45 |
46 |
47 | static const u8x8_display_info_t u8x8_null_display_info =
48 | {
49 | /* chip_enable_level = */ 0,
50 | /* chip_disable_level = */ 1,
51 |
52 | /* post_chip_enable_wait_ns = */ 0,
53 | /* pre_chip_disable_wait_ns = */ 0,
54 | /* reset_pulse_width_ms = */ 0,
55 | /* post_reset_wait_ms = */ 0,
56 | /* sda_setup_time_ns = */ 0,
57 | /* sck_pulse_width_ns = */ 0, /* half of cycle time (100ns according to datasheet), AVR: below 70: 8 MHz, >= 70 --> 4MHz clock */
58 | /* sck_clock_hz = */ 4000000UL, /* since Arduino 1.6.0, the SPI bus speed in Hz. Should be 1000000000/sck_pulse_width_ns */
59 | /* spi_mode = */ 0, /* active high, rising edge */
60 | /* i2c_bus_clock_100kHz = */ 4,
61 | /* data_setup_time_ns = */ 0,
62 | /* write_pulse_width_ns = */ 0,
63 | /* tile_width = */ 1, /* 8x8 */
64 | /* tile_hight = */ 1,
65 | /* default_x_offset = */ 0,
66 | /* flipmode_x_offset = */ 0,
67 | /* pixel_width = */ 8,
68 | /* pixel_height = */ 8
69 | };
70 |
71 |
72 | /* a special null device */
73 | uint8_t u8x8_d_null_cb(u8x8_t *u8x8, uint8_t msg, U8X8_UNUSED uint8_t arg_int, U8X8_UNUSED void *arg_ptr)
74 | {
75 | switch(msg)
76 | {
77 | case U8X8_MSG_DISPLAY_SETUP_MEMORY:
78 | u8x8_d_helper_display_setup_memory(u8x8, &u8x8_null_display_info);
79 | break;
80 | case U8X8_MSG_DISPLAY_INIT:
81 | u8x8_d_helper_display_init(u8x8);
82 | break;
83 | }
84 | /* the null device callback will succeed for all messages */
85 | return 1;
86 | }
87 |
88 |
89 | /*
90 | Description:
91 | Setup u8x8
92 | Args:
93 | u8x8 An empty u8x8 structure
94 | */
95 | void u8x8_SetupDefaults(u8x8_t *u8x8)
96 | {
97 | u8x8->display_info = NULL;
98 | u8x8->display_cb = u8x8_dummy_cb;
99 | u8x8->cad_cb = u8x8_dummy_cb;
100 | u8x8->byte_cb = u8x8_dummy_cb;
101 | u8x8->gpio_and_delay_cb = u8x8_dummy_cb;
102 | u8x8->is_font_inverse_mode = 0;
103 | //u8x8->device_address = 0;
104 | u8x8->utf8_state = 0; /* also reset by u8x8_utf8_init */
105 | u8x8->bus_clock = 0; /* issue 769 */
106 | u8x8->i2c_address = 255;
107 | u8x8->debounce_default_pin_state = 255; /* assume all low active buttons */
108 |
109 | #ifdef U8X8_USE_PINS
110 | {
111 | uint8_t i;
112 | for( i = 0; i < U8X8_PIN_CNT; i++ )
113 | u8x8->pins[i] = U8X8_PIN_NONE;
114 | }
115 | #endif
116 | }
117 |
118 |
119 | /*
120 | Description:
121 | Setup u8x8 and assign the callback function. The dummy
122 | callback "u8x8_dummy_cb" can be used, if no callback is required.
123 | This setup will not communicate with the display itself.
124 | Use u8x8_InitDisplay() to send the startup code to the Display.
125 | Args:
126 | u8x8 An empty u8x8 structure
127 | display_cb Display/controller specific callback function
128 | cad_cb Display controller specific communication callback function
129 | byte_cb Display controller/communication specific callback funtion
130 | gpio_and_delay_cb Environment specific callback function
131 |
132 | */
133 | void u8x8_Setup(u8x8_t *u8x8, u8x8_msg_cb display_cb, u8x8_msg_cb cad_cb, u8x8_msg_cb byte_cb, u8x8_msg_cb gpio_and_delay_cb)
134 | {
135 | /* setup defaults and reset pins to U8X8_PIN_NONE */
136 | u8x8_SetupDefaults(u8x8);
137 |
138 | /* setup specific callbacks */
139 | u8x8->display_cb = display_cb;
140 | u8x8->cad_cb = cad_cb;
141 | u8x8->byte_cb = byte_cb;
142 | u8x8->gpio_and_delay_cb = gpio_and_delay_cb;
143 |
144 | /* setup display info */
145 | u8x8_SetupMemory(u8x8);
146 | }
147 |
148 |
--------------------------------------------------------------------------------
/src/u8x8_string.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_string.c
4 |
5 | string line procedures
6 |
7 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
8 |
9 | Copyright (c) 2016, olikraus@gmail.com
10 | All rights reserved.
11 |
12 | Redistribution and use in source and binary forms, with or without modification,
13 | are permitted provided that the following conditions are met:
14 |
15 | * Redistributions of source code must retain the above copyright notice, this list
16 | of conditions and the following disclaimer.
17 |
18 | * Redistributions in binary form must reproduce the above copyright notice, this
19 | list of conditions and the following disclaimer in the documentation and/or other
20 | materials provided with the distribution.
21 |
22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 |
36 | */
37 |
38 | #include "u8x8.h"
39 |
40 | uint8_t u8x8_GetStringLineCnt(const char *str)
41 | {
42 | char e;
43 | uint8_t line_cnt = 1;
44 | if ( str == NULL )
45 | return 0;
46 | for(;;)
47 | {
48 | e = *str;
49 | if ( e == '\0' )
50 | break;
51 | str++;
52 | if ( e == '\n' )
53 | line_cnt++;
54 | }
55 | return line_cnt;
56 | }
57 |
58 |
59 | /*
60 | Assumes strings, separated by '\n' in "str".
61 | Returns the string at index "line_idx". First strng has line_idx = 0
62 | Example:
63 | Returns "xyz" for line_idx = 1 with str = "abc\nxyz"
64 | Support both UTF8 and normal strings.
65 | */
66 | const char *u8x8_GetStringLineStart(uint8_t line_idx, const char *str )
67 | {
68 | char e;
69 | uint8_t line_cnt = 1;
70 |
71 | if ( line_idx == 0 )
72 | return str;
73 |
74 | for(;;)
75 | {
76 | e = *str;
77 | if ( e == '\0' )
78 | break;
79 | str++;
80 | if ( e == '\n' )
81 | {
82 | if ( line_cnt == line_idx )
83 | return str;
84 | line_cnt++;
85 | }
86 | }
87 | return NULL; /* line not found */
88 | }
89 |
90 | /* copy until first '\n' or '\0' in str */
91 | /* Important: There is no string overflow check, ensure */
92 | /* that the destination buffer is large enough */
93 | void u8x8_CopyStringLine(char *dest, uint8_t line_idx, const char *str)
94 | {
95 | if ( dest == NULL )
96 | return;
97 | str = u8x8_GetStringLineStart( line_idx, str );
98 | if ( str != NULL )
99 | {
100 | for(;;)
101 | {
102 | if ( *str == '\n' || *str == '\0' )
103 | break;
104 | *dest = *str;
105 | dest++;
106 | str++;
107 | }
108 | }
109 | *dest = '\0';
110 | }
111 |
112 | /*
113 | Draw a string
114 | Extend the string to size "w"
115 | Center the string within "w"
116 | return the size of the string
117 |
118 | */
119 | uint8_t u8x8_DrawUTF8Line(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t w, const char *s)
120 | {
121 | uint8_t d, lw;
122 | uint8_t cx, dx;
123 |
124 | d = 0;
125 |
126 | lw = u8x8_GetUTF8Len(u8x8, s);
127 | if ( lw < w )
128 | {
129 | d = w;
130 | d -=lw;
131 | d /= 2;
132 | }
133 |
134 | cx = x;
135 | dx = cx + d;
136 | while( cx < dx )
137 | {
138 | u8x8_DrawUTF8(u8x8, cx, y, " ");
139 | cx++;
140 | }
141 | cx += u8x8_DrawUTF8(u8x8, cx, y, s);
142 | dx = x + w;
143 | while( cx < dx )
144 | {
145 | u8x8_DrawUTF8(u8x8, cx, y, " ");
146 | cx++;
147 | }
148 | cx -= x;
149 | return cx;
150 | }
151 |
152 | /*
153 | draw several lines at position x,y.
154 | lines are stored in s and must be separated with '\n'.
155 | lines can be centered with respect to "w"
156 | if s == NULL nothing is drawn and 0 is returned
157 | returns the number of lines in s
158 | */
159 | uint8_t u8x8_DrawUTF8Lines(u8x8_t *u8x8, uint8_t x, uint8_t y, uint8_t w, const char *s)
160 | {
161 | uint8_t i;
162 | uint8_t cnt;
163 | cnt = u8x8_GetStringLineCnt(s);
164 | for( i = 0; i < cnt; i++ )
165 | {
166 | u8x8_DrawUTF8Line(u8x8, x, y, w, u8x8_GetStringLineStart(i, s));
167 | y++;
168 | }
169 | return cnt;
170 | }
171 |
--------------------------------------------------------------------------------
/src/u8x8_u16toa.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_u16toa.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 |
35 | */
36 |
37 |
38 | #include "u8x8.h"
39 |
40 | const char *u8x8_u16toap(char * dest, uint16_t v)
41 | {
42 | uint8_t pos;
43 | uint8_t d;
44 | uint16_t c;
45 | c = 10000;
46 | for( pos = 0; pos < 5; pos++ )
47 | {
48 | d = '0';
49 | while( v >= c )
50 | {
51 | v -= c;
52 | d++;
53 | }
54 | dest[pos] = d;
55 | c /= 10;
56 | }
57 | dest[5] = '\0';
58 | return dest;
59 | }
60 |
61 | /* v = value, d = number of digits */
62 | const char *u8x8_u16toa(uint16_t v, uint8_t d)
63 | {
64 | static char buf[6];
65 | d = 5-d;
66 | return u8x8_u16toap(buf, v) + d;
67 | }
68 |
69 | const char *u8x8_utoa(uint16_t v)
70 | {
71 | const char *s = u8x8_u16toa(v, 5);
72 | while( *s == '0' )
73 | s++;
74 | if ( *s == '\0' )
75 | s--;
76 | return s;
77 | }
--------------------------------------------------------------------------------
/src/u8x8_u8toa.c:
--------------------------------------------------------------------------------
1 | /*
2 |
3 | u8x8_u8toa.c
4 |
5 | Universal 8bit Graphics Library (https://github.com/olikraus/u8g2/)
6 |
7 | Copyright (c) 2016, olikraus@gmail.com
8 | All rights reserved.
9 |
10 | Redistribution and use in source and binary forms, with or without modification,
11 | are permitted provided that the following conditions are met:
12 |
13 | * Redistributions of source code must retain the above copyright notice, this list
14 | of conditions and the following disclaimer.
15 |
16 | * Redistributions in binary form must reproduce the above copyright notice, this
17 | list of conditions and the following disclaimer in the documentation and/or other
18 | materials provided with the distribution.
19 |
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 |
34 | */
35 |
36 |
37 | #include "u8x8.h"
38 |
39 | static const unsigned char u8x8_u8toa_tab[3] = { 100, 10, 1 } ;
40 | const char *u8x8_u8toap(char * dest, uint8_t v)
41 | {
42 | uint8_t pos;
43 | uint8_t d;
44 | uint8_t c;
45 | for( pos = 0; pos < 3; pos++ )
46 | {
47 | d = '0';
48 | c = *(u8x8_u8toa_tab+pos);
49 | while( v >= c )
50 | {
51 | v -= c;
52 | d++;
53 | }
54 | dest[pos] = d;
55 | }
56 | dest[3] = '\0';
57 | return dest;
58 | }
59 |
60 | /* v = value, d = number of digits */
61 | const char *u8x8_u8toa(uint8_t v, uint8_t d)
62 | {
63 | static char buf[4];
64 | d = 3-d;
65 | return u8x8_u8toap(buf, v) + d;
66 | }
67 |
68 |
--------------------------------------------------------------------------------
/u8g2_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/wuhanstudio/rt-u8g2/4e495bc1064dd76e0e23e2df4d3b7a397c7b31d8/u8g2_logo.png
--------------------------------------------------------------------------------