├── src ├── clib │ ├── chessengine.c │ ├── u8g_font_data.c │ ├── u8g_com_null.c │ ├── u8g_u16toa.c │ ├── u8g_u8toa.c │ ├── u8g_dev_null.c │ ├── u8g_com_arduino_common.c │ ├── u8g_page.c │ ├── u8g_line.c │ ├── u8g_cursor.c │ ├── u8g_dev_flipdisc_2x7.c │ ├── u8g_com_psoc5_ssd_hw_parallel.c │ ├── u8g_com_api_16gr.c │ ├── u8g_com_raspberrypi_hw_spi.c │ ├── u8g_dev_gprof.c │ ├── u8g_dev_sbn1661_122x32.c │ ├── u8g_com_std_sw_spi.c │ ├── u8g_com_atmega_sw_spi.c │ ├── u8g_dev_ks0108_128x64.c │ ├── u8g_com_arduino_std_sw_spi.c │ ├── u8g_pb8v2.c │ ├── u8g_com_arduino_hw_usart_spi.c │ ├── u8g_state.c │ ├── u8g_bitmap.c │ ├── u8g_dev_tls8204_84x48.c │ ├── u8g_com_linux_ssd_i2c.c │ ├── u8g_pb8h2.c │ ├── u8g_com_raspberrypi_ssd_i2c.c │ ├── u8g_dev_uc1611_dogm240.c │ ├── u8g_clip.c │ ├── u8g_virtual_screen.c │ ├── u8g_pb16v2.c │ ├── u8g_com_atxmega_hw_spi.c │ ├── u8g_dev_uc1611_dogxl240.c │ ├── u8g_pb.c │ ├── u8g_com_api.c │ ├── u8g_com_atmega_hw_spi.c │ ├── u8g_com_arduino_attiny85_hw_spi.c │ ├── u8g_pbxh16.c │ ├── u8g_com_atmega_st7920_spi.c │ ├── u8g_pb8h8.c │ ├── u8g_pb8v1.c │ ├── u8g_com_arduino_port_d_wr.c │ ├── u8g_dev_lc7981_240x64.c │ ├── u8g_dev_lc7981_240x128.c │ ├── u8g_com_atmega_parallel.c │ ├── u8g_com_arduino_parallel.c │ └── u8g_dev_ssd1309_128x64.c └── U8glib.cpp ├── library.properties ├── extras └── INSTALL.TXT ├── README.md ├── license.txt └── examples └── A2Printer └── A2Printer.ino /src/clib/chessengine.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olikraus/U8glib_Arduino/HEAD/src/clib/chessengine.c -------------------------------------------------------------------------------- /src/clib/u8g_font_data.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/olikraus/U8glib_Arduino/HEAD/src/clib/u8g_font_data.c -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=U8glib 2 | version=1.19.1 3 | author=oliver 4 | maintainer=oliver 5 | sentence=A library for monochrome TFTs and OLEDs 6 | paragraph=Supported display controller: SSD1306, SSD1309, SSD1322, SSD1325, SSD1327, SH1106, UC1601, UC1610, UC1611, UC1701, ST7565, ST7920, KS0108, LC7981, PCD8544, PCF8812, SBN1661, TLS8204, T6963. 7 | category=Display 8 | url=https://github.com/olikraus/u8glib 9 | architectures=avr,sam -------------------------------------------------------------------------------- /extras/INSTALL.TXT: -------------------------------------------------------------------------------- 1 | 2 | U8GLIB 3 | http://code.google.com/p/u8glib/ 4 | 5 | Install instructions for the Arduino environment. 6 | 7 | 1. Start Arduino IDE 8 | 2. In the Arduino IDE, import the library from the "Add Library" Menu. 9 | 10 | Alternative install instructions for the Arduino environment. 11 | 12 | 1. Unzip u8glib_arduino_vX.XX.zip into the "libraries" folder of the 13 | Arduino install directory 14 | 2. Start Arduino IDE 15 | 16 | Install instructions for the Chipkit (Arduino) environment. 17 | 18 | 1. cd /libraries 19 | 2. unzip u8glib_arduino_vX.XX.zip 20 | 3. cd ///hardware/pic32/libraries 21 | 4. again: u8glib_arduino_vX.XX.zip 22 | 5. Open hardware/pic32/cores/pic32/Print.h 23 | Remove line 24 | #define BYTE 0 25 | from the file, use PRINT_BYTE instead of BYTE. 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # U8glib 3 | 4 | A graphics library with support for many different monochrome displays. 5 | 6 | ![nhd_oled180.jpg](https://github.com/olikraus/u8glib/wiki/otherpic/nhd_oled180.jpg) ![dogs102_180.jpg](https://github.com/olikraus/u8glib/wiki/otherpic/dogs102_180.jpg) 7 | 8 | Left: NHD-2.7-12864 OLED (SSD1325), right: EA DOGS102 LCD (UC1701) 9 | 10 | * [Gallery](https://github.com/olikraus/u8glib/wiki/gallery) 11 | * [Bintray](https://bintray.com/olikraus/u8glib) download links: 12 | * [U8glib for Arduino](https://bintray.com/olikraus/u8glib/Arduino) 13 | * [U8glib for AVR](https://bintray.com/olikraus/u8glib/AVR) 14 | * [U8glib for ARM](https://bintray.com/olikraus/u8glib/ARM) 15 | * Converter for BDF fonts: [bdf2u8g_101.exe on google drive](https://drive.google.com/folderview?id=0B5b6Dv0wCeCRLWJkYTh2TUlYVDg&usp=sharing). 16 | * Supported environments: 17 | * [Arduino (ATMEGA and ARM)](http://www.arduino.cc/) 18 | * [AVR (ATMEGA)](https://github.com/olikraus/u8glib/wiki/avr) 19 | * [ARM (with example for LPC1114)](https://github.com/olikraus/u8glib/wiki/lpc1114) 20 | * Library for graphic LCDs and OLEDs 21 | * [U8glib documentation and tutorials](https://github.com/olikraus/u8glib/wiki) 22 | * Graphical user interface library (GUI) available: [M2tklib](http://code.google.com/p/m2tklib/) 23 | * COM interfaces: Software SPI, Hardware SPI, 8Bit parallel 24 | * Large number of [fonts](https://github.com/olikraus/u8glib/wiki/fontsize) 25 | * Monospaced and proportional fonts 26 | * Mouse-Cursor support 27 | * Landscape and portrait mode 28 | * Many supported [devices](https://github.com/olikraus/u8glib/wiki/device) (SSD1325, ST7565, ST7920, UC1608, UC1610, UC1701, PCD8544, PCF8812, KS0108, LC7981, SBN1661, SSD1306, SH1106, T6963, LD7032) 29 | * Well-defined interface to the device subsystem 30 | 31 | -------------------------------------------------------------------------------- /src/clib/u8g_com_null.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_null.c 4 | 5 | communication null device 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, 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 "u8g.h" 40 | 41 | uint8_t u8g_com_null_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 42 | { 43 | switch(msg) 44 | { 45 | case U8G_COM_MSG_INIT: 46 | break; 47 | case U8G_COM_MSG_STOP: 48 | break; 49 | 50 | 51 | case U8G_COM_MSG_CHIP_SELECT: 52 | /* arg_val contains the chip number, which should be enabled */ 53 | break; 54 | 55 | 56 | case U8G_COM_MSG_WRITE_BYTE: 57 | break; 58 | case U8G_COM_MSG_WRITE_SEQ: 59 | break; 60 | } 61 | return 1; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /src/clib/u8g_u16toa.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_u16toa.c 4 | 5 | 6 | Universal 8bit Graphics Library 7 | 8 | Copyright (c) 2012, 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 | 38 | #include "u8g.h" 39 | 40 | const char *u8g_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 *u8g_u16toa(uint16_t v, uint8_t d) 63 | { 64 | static char buf[6]; 65 | d = 5-d; 66 | return u8g_u16toap(buf, v) + d; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /src/clib/u8g_u8toa.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_u8toa.c 4 | 5 | 6 | Universal 8bit Graphics Library 7 | 8 | Copyright (c) 2011, 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 | 38 | #include "u8g.h" 39 | 40 | static const unsigned char u8g_u8toa_tab[3] = { 100, 10, 1 } ; 41 | const char *u8g_u8toap(char * dest, uint8_t v) 42 | { 43 | uint8_t pos; 44 | uint8_t d; 45 | uint8_t c; 46 | for( pos = 0; pos < 3; pos++ ) 47 | { 48 | d = '0'; 49 | c = *(u8g_u8toa_tab+pos); 50 | while( v >= c ) 51 | { 52 | v -= c; 53 | d++; 54 | } 55 | dest[pos] = d; 56 | } 57 | dest[3] = '\0'; 58 | return dest; 59 | } 60 | 61 | /* v = value, d = number of digits */ 62 | const char *u8g_u8toa(uint8_t v, uint8_t d) 63 | { 64 | static char buf[4]; 65 | d = 3-d; 66 | return u8g_u8toap(buf, v) + d; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /src/clib/u8g_dev_null.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_null.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, 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 "u8g.h" 38 | 39 | uint8_t u8g_dev_null(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 40 | { 41 | switch(msg) 42 | { 43 | case U8G_DEV_MSG_SET_8PIXEL: /* most often used command */ 44 | break; 45 | case U8G_DEV_MSG_SET_PIXEL: 46 | break; 47 | case U8G_DEV_MSG_INIT: 48 | break; 49 | case U8G_DEV_MSG_STOP: 50 | break; 51 | case U8G_DEV_MSG_PAGE_FIRST: 52 | break; 53 | case U8G_DEV_MSG_PAGE_NEXT: 54 | break; 55 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 56 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 57 | return 1; 58 | #endif 59 | case U8G_DEV_MSG_GET_PAGE_BOX: 60 | break; 61 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 62 | break; 63 | case U8G_DEV_MSG_SET_XY_CB: 64 | break; 65 | } 66 | return 1; 67 | } 68 | -------------------------------------------------------------------------------- /src/clib/u8g_com_arduino_common.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_arduino_common.c 4 | 5 | shared procedures for the arduino communication procedures 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, 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 "u8g.h" 40 | 41 | #if defined(ARDUINO) 42 | 43 | #if ARDUINO < 100 44 | #include 45 | #else 46 | #include 47 | #endif 48 | 49 | void u8g_com_arduino_digital_write(u8g_t *u8g, uint8_t pin_index, uint8_t value) 50 | { 51 | uint8_t pin; 52 | pin = u8g->pin_list[pin_index]; 53 | if ( pin != U8G_PIN_NONE ) 54 | digitalWrite(pin, value); 55 | } 56 | 57 | /* this procedure does not set the RW pin */ 58 | void u8g_com_arduino_assign_pin_output_high(u8g_t *u8g) 59 | { 60 | uint8_t i; 61 | /* skip the RW pin, which is the last pin in the list */ 62 | for( i = 0; i < U8G_PIN_LIST_LEN-1; i++ ) 63 | { 64 | if ( u8g->pin_list[i] != U8G_PIN_NONE ) 65 | { 66 | pinMode(u8g->pin_list[i], OUTPUT); 67 | digitalWrite(u8g->pin_list[i], HIGH); 68 | } 69 | } 70 | } 71 | 72 | 73 | #endif 74 | 75 | 76 | -------------------------------------------------------------------------------- /src/clib/u8g_page.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_page.c 4 | 5 | page helper functions, only called by the dev handler. 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, 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 "u8g.h" 40 | 41 | /* 42 | setup page count structure 43 | conditions: page_height <= total_height 44 | */ 45 | void u8g_page_Init(u8g_page_t *p, u8g_uint_t page_height, u8g_uint_t total_height ) 46 | { 47 | p->page_height = page_height; 48 | p->total_height = total_height; 49 | p->page = 0; 50 | u8g_page_First(p); 51 | } 52 | 53 | void u8g_page_First(u8g_page_t *p) 54 | { 55 | p->page_y0 = 0; 56 | p->page_y1 = p->page_height; 57 | p->page_y1--; 58 | p->page = 0; 59 | } 60 | 61 | uint8_t u8g_page_Next(u8g_page_t * p) 62 | { 63 | register u8g_uint_t y1; 64 | p->page_y0 += p->page_height; 65 | if ( p->page_y0 >= p->total_height ) 66 | return 0; 67 | p->page++; 68 | y1 = p->page_y1; 69 | y1 += p->page_height; 70 | if ( y1 >= p->total_height ) 71 | { 72 | y1 = p->total_height; 73 | y1--; 74 | } 75 | p->page_y1 = y1; 76 | 77 | return 1; 78 | } 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /src/clib/u8g_line.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_line.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2012, 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 "u8g.h" 37 | 38 | void u8g_DrawLine(u8g_t *u8g, u8g_uint_t x1, u8g_uint_t y1, u8g_uint_t x2, u8g_uint_t y2) 39 | { 40 | u8g_uint_t tmp; 41 | u8g_uint_t x,y; 42 | u8g_uint_t dx, dy; 43 | u8g_int_t err; 44 | u8g_int_t ystep; 45 | 46 | uint8_t swapxy = 0; 47 | 48 | /* no BBX intersection check at the moment, should be added... */ 49 | 50 | if ( x1 > x2 ) dx = x1-x2; else dx = x2-x1; 51 | if ( y1 > y2 ) dy = y1-y2; else dy = y2-y1; 52 | 53 | if ( dy > dx ) 54 | { 55 | swapxy = 1; 56 | tmp = dx; dx =dy; dy = tmp; 57 | tmp = x1; x1 =y1; y1 = tmp; 58 | tmp = x2; x2 =y2; y2 = tmp; 59 | } 60 | if ( x1 > x2 ) 61 | { 62 | tmp = x1; x1 =x2; x2 = tmp; 63 | tmp = y1; y1 =y2; y2 = tmp; 64 | } 65 | err = dx >> 1; 66 | if ( y2 > y1 ) ystep = 1; else ystep = -1; 67 | y = y1; 68 | 69 | #ifndef U8G_16BIT 70 | if ( x2 == 255 ) 71 | x2--; 72 | #else 73 | if ( x2 == 0xffff ) 74 | x2--; 75 | #endif 76 | 77 | for( x = x1; x <= x2; x++ ) 78 | { 79 | if ( swapxy == 0 ) 80 | u8g_DrawPixel(u8g, x, y); 81 | else 82 | u8g_DrawPixel(u8g, y, x); 83 | err -= (uint8_t)dy; 84 | if ( err < 0 ) 85 | { 86 | y += (u8g_uint_t)ystep; 87 | err += (u8g_uint_t)dx; 88 | } 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/U8glib.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | U8glib.cpp 4 | 5 | C++ Interface 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, 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 "U8glib.h" 39 | 40 | 41 | #if defined(U8G_WITH_PINLIST) 42 | uint8_t U8GLIB::initSPI(u8g_dev_t *dev, uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset) 43 | { 44 | prepare(); 45 | return u8g_InitSPI(&u8g, dev, sck, mosi, cs, a0, reset); 46 | } 47 | 48 | uint8_t U8GLIB::initHWSPI(u8g_dev_t *dev, uint8_t cs, uint8_t a0, uint8_t reset) 49 | { 50 | prepare(); 51 | return u8g_InitHWSPI(&u8g, dev, cs, a0, reset); 52 | } 53 | 54 | uint8_t U8GLIB::initI2C(u8g_dev_t *dev, uint8_t options) 55 | { 56 | prepare(); 57 | return u8g_InitI2C(&u8g, dev, options); 58 | } 59 | 60 | uint8_t U8GLIB::init8Bit(u8g_dev_t *dev, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7, 61 | uint8_t en, uint8_t cs1, uint8_t cs2, uint8_t di, uint8_t rw, uint8_t reset) 62 | { 63 | prepare(); 64 | return u8g_Init8Bit(&u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset); 65 | } 66 | 67 | uint8_t U8GLIB::init8BitFixedPort(u8g_dev_t *dev, uint8_t en, uint8_t cs, uint8_t di, uint8_t rw, uint8_t reset) 68 | { 69 | prepare(); 70 | return u8g_Init8BitFixedPort(&u8g, dev, en, cs, di, rw, reset); 71 | } 72 | 73 | uint8_t U8GLIB::initRW8Bit(u8g_dev_t *dev, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7, 74 | uint8_t cs, uint8_t a0, uint8_t wr, uint8_t rd, uint8_t reset) 75 | { 76 | prepare(); 77 | return u8g_InitRW8Bit(&u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, cs, a0, wr, rd, reset); 78 | } 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /src/clib/u8g_cursor.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_cursor.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, 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 "u8g.h" 38 | 39 | void u8g_SetCursorFont(u8g_t *u8g, const u8g_pgm_uint8_t *cursor_font) 40 | { 41 | u8g->cursor_font = cursor_font; 42 | } 43 | 44 | void u8g_SetCursorStyle(u8g_t *u8g, uint8_t encoding) 45 | { 46 | u8g->cursor_encoding = encoding; 47 | } 48 | 49 | void u8g_SetCursorColor(u8g_t *u8g, uint8_t fg, uint8_t bg) 50 | { 51 | u8g->cursor_bg_color = bg; 52 | u8g->cursor_fg_color = fg; 53 | } 54 | 55 | void u8g_SetCursorPos(u8g_t *u8g, u8g_uint_t cursor_x, u8g_uint_t cursor_y) 56 | { 57 | u8g->cursor_x = cursor_x; 58 | u8g->cursor_y = cursor_y; 59 | } 60 | 61 | void u8g_EnableCursor(u8g_t *u8g) 62 | { 63 | u8g->cursor_fn = u8g_DrawCursor; 64 | } 65 | 66 | void u8g_DisableCursor(u8g_t *u8g) 67 | { 68 | u8g->cursor_fn = (u8g_draw_cursor_fn)0; 69 | } 70 | 71 | void u8g_DrawCursor(u8g_t *u8g) 72 | { 73 | const u8g_pgm_uint8_t *font; 74 | uint8_t color; 75 | uint8_t encoding = u8g->cursor_encoding; 76 | 77 | /* get current values */ 78 | color = u8g_GetColorIndex(u8g); 79 | font = u8g->font; 80 | 81 | /* draw cursor */ 82 | u8g->font = u8g->cursor_font; 83 | encoding++; 84 | u8g_SetColorIndex(u8g, u8g->cursor_bg_color); 85 | /* 27. Jan 2013: replaced call to u8g_DrawGlyph with call to u8g_draw_glyph */ 86 | /* required, because y adjustment should not happen to the cursor fonts */ 87 | u8g_draw_glyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding); 88 | encoding--; 89 | u8g_SetColorIndex(u8g, u8g->cursor_fg_color); 90 | /* 27. Jan 2013: replaced call to u8g_DrawGlyph with call to u8g_draw_glyph */ 91 | /* required, because y adjustment should not happen to the cursor fonts */ 92 | /* u8g_DrawGlyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding); */ 93 | u8g_draw_glyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding); 94 | 95 | /* restore previous values */ 96 | u8g->font = font; 97 | u8g_SetColorIndex(u8g, color); 98 | } 99 | 100 | -------------------------------------------------------------------------------- /src/clib/u8g_dev_flipdisc_2x7.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_flipdisc.c 4 | 5 | 1-Bit (BW) Driver for flip disc matrix 6 | 2x 7 pixel height 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2011, 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 | #include "u8g.h" 40 | 41 | #define WIDTH 28 42 | #define HEIGHT 14 43 | #define PAGE_HEIGHT 14 44 | 45 | /* 46 | Write data to the flip disc matrix. 47 | This procedure must be implemented by the user. 48 | Arguments: 49 | id: Id for the matrix. Currently always 0. 50 | page: A page has a height of 14 pixel. For a matrix with HEIGHT == 14 this will be always 0 51 | width: The width of the flip disc matrix. Always equal to WIDTH 52 | row1: first data line (7 pixel per byte) 53 | row2: first data line (7 pixel per byte) 54 | */ 55 | void writeFlipDiscMatrix(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2); 56 | 57 | 58 | 59 | void (*u8g_write_flip_disc_matrix)(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2); 60 | 61 | void u8g_SetFlipDiscCallback(u8g_t *u8g, void (*cb)(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2)) 62 | { 63 | u8g_write_flip_disc_matrix = cb; 64 | } 65 | 66 | uint8_t u8g_dev_flipdisc_2x7_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 67 | { 68 | switch(msg) 69 | { 70 | case U8G_DEV_MSG_INIT: 71 | break; 72 | case U8G_DEV_MSG_STOP: 73 | break; 74 | case U8G_DEV_MSG_PAGE_NEXT: 75 | { 76 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 77 | 78 | /* current page: pb->p.page */ 79 | /* ptr to the buffer: pb->buf */ 80 | 81 | (*u8g_write_flip_disc_matrix)(0, pb->p.page, WIDTH, pb->buf, (uint8_t *)(pb->buf)+WIDTH); 82 | } 83 | break; 84 | case U8G_DEV_MSG_CONTRAST: 85 | return 1; 86 | } 87 | return u8g_dev_pb14v1_base_fn(u8g, dev, msg, arg); 88 | } 89 | 90 | uint8_t u8g_dev_flipdisc_2x7_bw_buf[WIDTH*2] U8G_NOCOMMON ; 91 | u8g_pb_t u8g_dev_flipdisc_2x7_bw_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_flipdisc_2x7_bw_buf}; 92 | u8g_dev_t u8g_dev_flipdisc_2x7 = { u8g_dev_flipdisc_2x7_bw_fn, &u8g_dev_flipdisc_2x7_bw_pb, u8g_com_null_fn }; 93 | -------------------------------------------------------------------------------- /src/clib/u8g_com_psoc5_ssd_hw_parallel.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_psoc5_ssd_hw_parallel.c 4 | 5 | com interface for Cypress PSoC5 and the SSDxxxx chip variant 6 | I2C protocol 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2015, olikraus@gmail.com, schmidt.ronny@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 "u8g.h" 41 | 42 | #if defined(U8G_CYPRESS_PSOC5) 43 | 44 | #include 45 | 46 | static uint8 dc = 0; // need to store whether next write is data or command 47 | 48 | uint8_t u8g_com_psoc5_ssd_hw_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 49 | { 50 | switch(msg) 51 | { 52 | case U8G_COM_MSG_STOP: 53 | // stop the device 54 | GraphicLCDIntf_Stop(); 55 | break; 56 | 57 | case U8G_COM_MSG_INIT: 58 | // init hardware interfaces, timers, gpios, ... 59 | GraphicLCDIntf_Init(); 60 | break; 61 | 62 | case U8G_COM_MSG_ADDRESS: 63 | // switch from cmd (arg_val = 0) to data mode (arg_val = 1) or vice versa 64 | dc = arg_val; 65 | break; 66 | 67 | case U8G_COM_MSG_CHIP_SELECT: 68 | /* done by the hardware */ 69 | break; 70 | 71 | case U8G_COM_MSG_RESET: 72 | // toggle the reset pin of the display by value in arg_val 73 | nRES_Write(0); 74 | u8g_10MicroDelay(); 75 | nRES_Write(1); 76 | break; 77 | 78 | case U8G_COM_MSG_WRITE_BYTE: 79 | // write byte to the device 80 | GraphicLCDIntf_Write8(dc, arg_val); 81 | break; 82 | 83 | case U8G_COM_MSG_WRITE_SEQ: 84 | case U8G_COM_MSG_WRITE_SEQ_P: 85 | { 86 | // write a sequence of bytes to the device 87 | register uint8_t *ptr = arg_ptr; 88 | while (arg_val-- > 0) 89 | { 90 | GraphicLCDIntf_Write8(dc, *ptr++); 91 | } 92 | } 93 | break; 94 | 95 | 96 | } 97 | return 1; 98 | } 99 | 100 | #else 101 | 102 | uint8_t u8g_com_psoc5_ssd_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 103 | { 104 | return 1; 105 | } 106 | 107 | #endif 108 | -------------------------------------------------------------------------------- /src/clib/u8g_com_api_16gr.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_api_16gr.c 4 | 5 | Extension of the com api for devices with 16 graylevels (4 bit per pixel). 6 | This should fit to the 8h and 16h architectures (pb8v1, pb8v2, pb16v1, pb16v2), 7 | mainly intended for SSD OLEDs 8 | 9 | Universal 8bit Graphics Library 10 | 11 | Copyright (c) 2011, olikraus@gmail.com 12 | All rights reserved. 13 | 14 | Redistribution and use in source and binary forms, with or without modification, 15 | are permitted provided that the following conditions are met: 16 | 17 | * Redistributions of source code must retain the above copyright notice, this list 18 | of conditions and the following disclaimer. 19 | 20 | * Redistributions in binary form must reproduce the above copyright notice, this 21 | list of conditions and the following disclaimer in the documentation and/or other 22 | materials provided with the distribution. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 25 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 26 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 27 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 29 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 31 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 32 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 36 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | 38 | 39 | */ 40 | 41 | #include "u8g.h" 42 | 43 | /* interpret b as a monochrome bit pattern, write value 15 for high bit and value 0 for a low bit */ 44 | /* topbit (msb) is sent last */ 45 | /* example: b = 0x083 will send 0xff, 0x00, 0x00, 0xf0 */ 46 | uint8_t u8g_WriteByteBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b) 47 | { 48 | static uint8_t buf[4]; 49 | static uint8_t map[4] = { 0, 0x00f, 0x0f0, 0x0ff }; 50 | buf [3] = map[b & 3]; 51 | b>>=2; 52 | buf [2] = map[b & 3]; 53 | b>>=2; 54 | buf [1] = map[b & 3]; 55 | b>>=2; 56 | buf [0] = map[b & 3]; 57 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ, 4, buf); 58 | } 59 | 60 | uint8_t u8g_WriteSequenceBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr) 61 | { 62 | do 63 | { 64 | if ( u8g_WriteByteBWTo16GrDevice(u8g, dev, *ptr++) == 0 ) 65 | return 0; 66 | cnt--; 67 | } while( cnt != 0 ); 68 | return 1; 69 | } 70 | 71 | /* interpret b as a 4L bit pattern, write values 0x000, 0x004, 0x008, 0x00c */ 72 | uint8_t u8g_WriteByte4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b) 73 | { 74 | //static uint8_t map[16] = { 0x000, 0x004, 0x008, 0x00c, 0x040, 0x044, 0x048, 0x04c, 0x080, 0x084, 0x088, 0x08c, 0x0c0, 0x0c4, 0x0c8, 0x0cc}; 75 | //static uint8_t map[16] = { 0x000, 0x004, 0x00a, 0x00f, 0x040, 0x044, 0x04a, 0x04f, 0x0a0, 0x0a4, 0x0aa, 0x0af, 0x0f0, 0x0f4, 0x0fa, 0x0ff}; 76 | static uint8_t map[16] = { 0x000, 0x040, 0x0a0, 0x0f0, 0x004, 0x044, 0x0a4, 0x0f4, 0x00a, 0x04a, 0x0aa, 0x0fa, 0x00f, 0x04f, 0x0af, 0x0ff}; 77 | uint8_t bb; 78 | bb = b; 79 | bb &= 15; 80 | b>>=4; 81 | dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, map[bb], NULL); 82 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, map[b], NULL); 83 | } 84 | 85 | uint8_t u8g_WriteSequence4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr) 86 | { 87 | do 88 | { 89 | if ( u8g_WriteByte4LTo16GrDevice(u8g, dev, *ptr++) == 0 ) 90 | return 0; 91 | cnt--; 92 | } while( cnt != 0 ); 93 | return 1; 94 | } 95 | -------------------------------------------------------------------------------- /src/clib/u8g_com_raspberrypi_hw_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_raspberrypi_hw_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2012, 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 | Assumes, that 36 | MOSI is at PORTB, Pin 3 37 | and 38 | SCK is at PORTB, Pin 5 39 | 40 | Update for ATOMIC operation done (01 Jun 2013) 41 | U8G_ATOMIC_OR(ptr, val) 42 | U8G_ATOMIC_AND(ptr, val) 43 | U8G_ATOMIC_START() 44 | U8G_ATOMIC_END() 45 | 46 | 47 | 48 | */ 49 | 50 | #include "u8g.h" 51 | 52 | 53 | 54 | #if defined(U8G_RASPBERRY_PI) 55 | 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | 62 | uint8_t u8g_com_raspberrypi_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 63 | { 64 | switch(msg) 65 | { 66 | case U8G_COM_MSG_STOP: 67 | break; 68 | 69 | case U8G_COM_MSG_INIT: 70 | // check wiringPi setup 71 | if (wiringPiSetup() == -1) 72 | { 73 | printf("wiringPi-Error\n"); 74 | exit(1); 75 | } 76 | 77 | if (wiringPiSPISetup (0, 100000) < 0) 78 | { 79 | printf ("Unable to open SPI device 0: %s\n", strerror (errno)) ; 80 | exit (1) ; 81 | } 82 | 83 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 84 | u8g_SetPIOutput(u8g, U8G_PI_A0); 85 | 86 | break; 87 | 88 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 89 | u8g_SetPILevel(u8g, U8G_PI_A0, arg_val); 90 | break; 91 | 92 | case U8G_COM_MSG_CHIP_SELECT: 93 | /* Done by the SPI hardware */ 94 | break; 95 | 96 | case U8G_COM_MSG_RESET: 97 | u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 98 | break; 99 | 100 | case U8G_COM_MSG_WRITE_BYTE: 101 | wiringPiSPIDataRW (0, &arg_val, 1) ; 102 | break; 103 | 104 | case U8G_COM_MSG_WRITE_SEQ: 105 | wiringPiSPIDataRW (0, arg_ptr, arg_val); 106 | break; 107 | 108 | case U8G_COM_MSG_WRITE_SEQ_P: 109 | wiringPiSPIDataRW (0, arg_ptr, arg_val); 110 | break; 111 | } 112 | return 1; 113 | } 114 | 115 | #else 116 | 117 | uint8_t u8g_com_raspberrypi_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 118 | { 119 | return 1; 120 | } 121 | 122 | #endif 123 | 124 | 125 | -------------------------------------------------------------------------------- /license.txt: -------------------------------------------------------------------------------- 1 | 2 | The U8glib code (http://code.google.com/p/u8glib/) is licensed under the terms of 3 | the new-bsd license (two-clause bsd license). 4 | See also: http://www.opensource.org/licenses/bsd-license.php 5 | 6 | The repository and optionally the releases contain icons, which are 7 | derived from the WPZOOM Developer Icon Set: 8 | http://www.wpzoom.com/wpzoom/new-freebie-wpzoom-developer-icon-set-154-free-icons/ 9 | WPZOOM Developer Icon Set by WPZOOM is licensed under a Creative Commons 10 | Attribution-ShareAlike 3.0 Unported License. 11 | 12 | Fonts are licensed under different conditions. 13 | See http://code.google.com/p/u8glib/wiki/fontgroup for 14 | 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 U8glib Code ============ 52 | 53 | Universal 8bit Graphics Library (http://code.google.com/p/u8glib/) 54 | 55 | Copyright (c) 2011, 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 | -------------------------------------------------------------------------------- /examples/A2Printer/A2Printer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | A2Printer.pde 4 | 5 | Special example code for the A2 Mciro Printer (https://www.sparkfun.com/products/10438) 6 | 7 | 8 | Universal 8bit Graphics Library, https://github.com/olikraus/u8glib/ 9 | 10 | Copyright (c) 2013, 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 "U8glib.h" 41 | 42 | // use this serial interface 43 | #define PRINTER_SERIAL Serial 44 | // #define PRINTER_SERIAL Serial1 45 | 46 | 47 | uint8_t u8g_com_uart(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 48 | switch(msg) { 49 | case U8G_COM_MSG_WRITE_BYTE: 50 | PRINTER_SERIAL.write(arg_val); 51 | break; 52 | } 53 | return 1; 54 | } 55 | 56 | // setup u8g object, please remove comment from one of the following constructor calls 57 | 58 | // half resolution 59 | //U8GLIB u8g(&u8g_dev_a2_micro_printer_192x120_ds, (u8g_com_fnptr)u8g_com_uart); 60 | 61 | // full resolution, requires to uncomment U8G_16BIT in u8g.h 62 | //U8GLIB u8g(&u8g_dev_a2_micro_printer_384x240, (u8g_com_fnptr)u8g_com_uart); 63 | 64 | // half resolution, extra log, requires to uncomment U8G_16BIT in u8g.h 65 | //U8GLIB u8g(&u8g_dev_a2_micro_printer_192x360_ds, (u8g_com_fnptr)u8g_com_uart); 66 | U8GLIB u8g(&u8g_dev_a2_micro_printer_192x720_ds, (u8g_com_fnptr)u8g_com_uart); 67 | 68 | 69 | 70 | void drawLogo(uint8_t d) { 71 | u8g.setFont(u8g_font_gdr25r); 72 | u8g.drawStr(0+d, 30+d, "U"); 73 | u8g.setFont(u8g_font_gdr30n); 74 | u8g.drawStr90(23+d,10+d,"8"); 75 | u8g.setFont(u8g_font_gdr25r); 76 | u8g.drawStr(53+d,30+d,"g"); 77 | 78 | u8g.drawHLine(2+d, 35+d, 47); 79 | u8g.drawVLine(45+d, 32+d, 12); 80 | } 81 | 82 | void drawURL(void) { 83 | u8g.setFont(u8g_font_4x6); 84 | if ( u8g.getHeight() < 59 ) { 85 | u8g.drawStr(53,9,"code.google.com"); 86 | u8g.drawStr(77,18,"/p/u8glib"); 87 | } 88 | else { 89 | u8g.drawStr(1,54,"code.google.com/p/u8glib"); 90 | } 91 | } 92 | 93 | void draw(void) { 94 | // graphic commands to redraw the complete screen should be placed here 95 | 96 | drawLogo(0); 97 | drawURL(); 98 | u8g.drawFrame(0,0,u8g.getWidth(), u8g.getHeight()); 99 | 100 | u8g.setFont(u8g_font_helvR24r); 101 | u8g.setPrintPos(0, 100); 102 | u8g.print(u8g.getWidth(), DEC); 103 | u8g.print("x"); 104 | u8g.print(u8g.getHeight(), DEC); 105 | } 106 | 107 | void setup(void) { 108 | PRINTER_SERIAL.begin(19200); 109 | 110 | // flip screen, if required 111 | // u8g.setRot180(); 112 | 113 | // assign default color value 114 | u8g.setColorIndex(1); // pixel on 115 | } 116 | 117 | void loop(void) { 118 | 119 | // picture loop: This will print the picture 120 | u8g.firstPage(); 121 | do { 122 | draw(); 123 | } while( u8g.nextPage() ); 124 | 125 | // send manual CR to the printer 126 | PRINTER_SERIAL.write('\n'); 127 | 128 | // reprint the picture after 10 seconds 129 | delay(10000); 130 | } 131 | 132 | -------------------------------------------------------------------------------- /src/clib/u8g_dev_gprof.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_gprof.c 4 | 5 | Device for performance measurement with gprof. 6 | Does not write any data, but uses a buffer. 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2011, 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 | 41 | #include "u8g.h" 42 | 43 | 44 | #define WIDTH 128 45 | #define HEIGHT 64 46 | #define PAGE_HEIGHT 8 47 | 48 | uint8_t u8g_dev_gprof_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); 49 | 50 | uint8_t u8g_pb_dev_gprof_buf[WIDTH]; 51 | u8g_pb_t u8g_pb_dev_gprof = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_pb_dev_gprof_buf }; 52 | 53 | u8g_dev_t u8g_dev_gprof = { u8g_dev_gprof_fn, &u8g_pb_dev_gprof, NULL }; 54 | 55 | uint8_t u8g_dev_gprof_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 56 | { 57 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 58 | 59 | switch(msg) 60 | { 61 | case U8G_DEV_MSG_INIT: 62 | break; 63 | case U8G_DEV_MSG_STOP: 64 | break; 65 | case U8G_DEV_MSG_PAGE_FIRST: 66 | u8g_pb_Clear(pb); 67 | u8g_page_First(&(pb->p)); 68 | break; 69 | case U8G_DEV_MSG_PAGE_NEXT: 70 | /* 71 | { 72 | uint8_t i, j; 73 | uint8_t page_height; 74 | page_height = pb->p.page_y1; 75 | page_height -= pb->p.page_y0; 76 | page_height++; 77 | for( j = 0; j < page_height; j++ ) 78 | { 79 | printf("%02d ", j); 80 | for( i = 0; i < WIDTH; i++ ) 81 | { 82 | if ( (u8g_pb_dev_stdout_buf[i] & (1<p)) == 0 ) 92 | { 93 | //printf("\n"); 94 | return 0; 95 | } 96 | u8g_pb_Clear(pb); 97 | break; 98 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 99 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 100 | { 101 | u8g_dev_arg_bbx_t *bbx = (u8g_dev_arg_bbx_t *)arg; 102 | u8g_uint_t x2, y2; 103 | 104 | y2 = bbx->y; 105 | y2 += bbx->h; 106 | y2--; 107 | 108 | if ( u8g_pb_IsYIntersection(pb, bbx->y, y2) == 0 ) 109 | return 0; 110 | 111 | /* maybe this one can be skiped... probability is very high to have an intersection, so it would be ok to always return 1 */ 112 | x2 = bbx->x; 113 | x2 += bbx->w; 114 | x2--; 115 | 116 | if ( u8g_pb_IsXIntersection(pb, bbx->x, x2) == 0 ) 117 | return 0; 118 | } 119 | return 1; 120 | #endif 121 | case U8G_DEV_MSG_GET_PAGE_BOX: 122 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 123 | break; 124 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 125 | break; 126 | case U8G_DEV_MSG_SET_XY_CB: 127 | break; 128 | } 129 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 130 | } 131 | -------------------------------------------------------------------------------- /src/clib/u8g_dev_sbn1661_122x32.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_sbn1661_122x32.c 4 | 5 | WG12232 display with 2xSBN1661 / SED1520 controller (122x32 display) 6 | At the moment only available in the Arduino Environment 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2011, 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 "u8g.h" 41 | 42 | #define WIDTH 122 43 | #define HEIGHT 32 44 | #define PAGE_HEIGHT 8 45 | 46 | 47 | static const uint8_t u8g_dev_sbn1661_122x32_init_seq[] PROGMEM = { 48 | U8G_ESC_CS(0), /* disable chip */ 49 | U8G_ESC_ADR(0), /* instruction mode */ 50 | U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds */ 51 | U8G_ESC_CS(1), /* enable chip 1 */ 52 | 0x0af, /* display on */ 53 | 0x0c0, /* display start at line 0 */ 54 | 0x0a0, /* a0: ADC forward, a1: ADC reverse */ 55 | 0x0a9, /* a8: 1/16, a9: 1/32 duty */ 56 | U8G_ESC_CS(2), /* enable chip 2 */ 57 | 0x0af, /* display on */ 58 | 0x0c0, /* display start at line 0 */ 59 | 0x0a0, /* a0: ADC forward, a1: ADC reverse */ 60 | 0x0a9, /* a8: 1/16, a9: 1/32 duty */ 61 | 62 | U8G_ESC_CS(0), /* disable chip */ 63 | 64 | 65 | U8G_ESC_END /* end of sequence */ 66 | }; 67 | 68 | uint8_t u8g_dev_sbn1661_122x32_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 69 | { 70 | switch(msg) 71 | { 72 | case U8G_DEV_MSG_INIT: 73 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE); 74 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_sbn1661_122x32_init_seq); 75 | break; 76 | case U8G_DEV_MSG_STOP: 77 | break; 78 | case U8G_DEV_MSG_PAGE_NEXT: 79 | { 80 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 81 | 82 | u8g_SetAddress(u8g, dev, 0); /* command mode */ 83 | u8g_SetChipSelect(u8g, dev, 1); 84 | u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (SBN1661/SED1520) */ 85 | u8g_WriteByte(u8g, dev, 0x000 ); /* set X address */ 86 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 87 | u8g_WriteSequence(u8g, dev, WIDTH/2, pb->buf); 88 | 89 | u8g_SetAddress(u8g, dev, 0); /* command mode */ 90 | u8g_SetChipSelect(u8g, dev, 2); 91 | u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (SBN1661/SED1520) */ 92 | u8g_WriteByte(u8g, dev, 0x000 ); /* set X address */ 93 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 94 | u8g_WriteSequence(u8g, dev, WIDTH/2, WIDTH/2+(uint8_t *)pb->buf); 95 | 96 | u8g_SetChipSelect(u8g, dev, 0); 97 | 98 | } 99 | break; 100 | case U8G_DEV_MSG_CONTRAST: 101 | break; 102 | } 103 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 104 | } 105 | 106 | /* u8g_com_arduino_sw_spi_fn does not work, too fast??? */ 107 | U8G_PB_DEV(u8g_dev_sbn1661_122x32 , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_sbn1661_122x32_fn, u8g_com_arduino_no_en_parallel_fn); 108 | -------------------------------------------------------------------------------- /src/clib/u8g_com_std_sw_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_std_sw_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2015, 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 "u8g.h" 37 | 38 | #if defined(U8G_WITH_PINLIST) 39 | 40 | static void u8g_sw_spi_shift_out(uint8_t dataPin, uint8_t clockPin, uint8_t val) 41 | { 42 | uint8_t i = 8; 43 | do 44 | { 45 | if ( val & 128 ) 46 | u8g_SetPinLevel(dataPin, 1); 47 | else 48 | u8g_SetPinLevel(dataPin, 0); 49 | val <<= 1; 50 | u8g_MicroDelay(); /* 23 Sep 2012 */ 51 | //delay(1); 52 | u8g_SetPinLevel(clockPin, 1); 53 | u8g_MicroDelay(); /* 23 Sep 2012 */ 54 | //delay(1); 55 | u8g_SetPinLevel(clockPin, 0); 56 | u8g_MicroDelay(); /* 23 Sep 2012 */ 57 | //delay(1); 58 | i--; 59 | } while( i != 0 ); 60 | } 61 | 62 | uint8_t u8g_com_std_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 63 | { 64 | switch(msg) 65 | { 66 | case U8G_COM_MSG_INIT: 67 | u8g_SetPIOutput(u8g, U8G_PI_SCK); 68 | u8g_SetPIOutput(u8g, U8G_PI_MOSI); 69 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 70 | u8g_SetPIOutput(u8g, U8G_PI_CS); 71 | u8g_SetPIOutput(u8g, U8G_PI_A0); 72 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0); 73 | u8g_SetPILevel(u8g, U8G_PI_MOSI, 0); 74 | break; 75 | 76 | case U8G_COM_MSG_STOP: 77 | break; 78 | 79 | case U8G_COM_MSG_RESET: 80 | u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 81 | break; 82 | 83 | case U8G_COM_MSG_CHIP_SELECT: 84 | if ( arg_val == 0 ) 85 | { 86 | /* disable */ 87 | u8g_SetPILevel(u8g, U8G_PI_CS, 1); 88 | } 89 | else 90 | { 91 | /* enable */ 92 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0); 93 | u8g_SetPILevel(u8g, U8G_PI_CS, 0); 94 | } 95 | break; 96 | 97 | case U8G_COM_MSG_WRITE_BYTE: 98 | u8g_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], arg_val); 99 | break; 100 | 101 | case U8G_COM_MSG_WRITE_SEQ: 102 | { 103 | register uint8_t *ptr = arg_ptr; 104 | while( arg_val > 0 ) 105 | { 106 | u8g_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], *ptr++); 107 | arg_val--; 108 | } 109 | } 110 | break; 111 | 112 | case U8G_COM_MSG_WRITE_SEQ_P: 113 | { 114 | register uint8_t *ptr = arg_ptr; 115 | while( arg_val > 0 ) 116 | { 117 | u8g_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], u8g_pgm_read(ptr)); 118 | ptr++; 119 | arg_val--; 120 | } 121 | } 122 | break; 123 | 124 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 125 | u8g_SetPILevel(u8g, U8G_PI_A0, arg_val); 126 | break; 127 | } 128 | return 1; 129 | } 130 | 131 | #else 132 | 133 | 134 | uint8_t u8g_com_std_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 135 | { 136 | return 1; 137 | } 138 | 139 | 140 | #endif 141 | -------------------------------------------------------------------------------- /src/clib/u8g_com_atmega_sw_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_atmega_sw_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2012, 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 "u8g.h" 38 | 39 | #if defined(__AVR__) 40 | 41 | static void u8g_atmega_sw_spi_shift_out(u8g_t *u8g, uint8_t val) U8G_NOINLINE; 42 | static void u8g_atmega_sw_spi_shift_out(u8g_t *u8g, uint8_t val) 43 | { 44 | uint8_t i = 8; 45 | do 46 | { 47 | u8g_SetPILevel(u8g, U8G_PI_MOSI, val & 128 ); 48 | val <<= 1; 49 | u8g_SetPILevel(u8g, U8G_PI_SCK, 1 ); 50 | u8g_MicroDelay(); /* 15 Aug 2012: added for high speed uC */ 51 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 52 | u8g_MicroDelay(); /* 15 Aug 2012: added for high speed uC */ 53 | i--; 54 | } while( i != 0 ); 55 | } 56 | 57 | uint8_t u8g_com_atmega_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 58 | { 59 | switch(msg) 60 | { 61 | case U8G_COM_MSG_INIT: 62 | u8g_SetPIOutput(u8g, U8G_PI_SCK); 63 | u8g_SetPIOutput(u8g, U8G_PI_MOSI); 64 | u8g_SetPIOutput(u8g, U8G_PI_A0); 65 | u8g_SetPIOutput(u8g, U8G_PI_CS); 66 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 67 | 68 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 69 | u8g_SetPILevel(u8g, U8G_PI_MOSI, 0 ); 70 | u8g_SetPILevel(u8g, U8G_PI_CS, 1 ); 71 | u8g_SetPILevel(u8g, U8G_PI_A0, 0); 72 | break; 73 | 74 | case U8G_COM_MSG_STOP: 75 | break; 76 | 77 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 78 | u8g_SetPILevel(u8g, U8G_PI_A0, arg_val); 79 | break; 80 | 81 | case U8G_COM_MSG_CHIP_SELECT: 82 | 83 | if ( arg_val == 0 ) 84 | { 85 | /* disable */ 86 | u8g_SetPILevel(u8g, U8G_PI_CS, 1); 87 | } 88 | else 89 | { 90 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 91 | /* enable */ 92 | u8g_SetPILevel(u8g, U8G_PI_CS, 0); /* CS = 0 (low active) */ 93 | } 94 | break; 95 | 96 | case U8G_COM_MSG_RESET: 97 | u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 98 | break; 99 | 100 | 101 | case U8G_COM_MSG_WRITE_BYTE: 102 | u8g_atmega_sw_spi_shift_out(u8g, arg_val); 103 | break; 104 | 105 | case U8G_COM_MSG_WRITE_SEQ: 106 | { 107 | register uint8_t *ptr = arg_ptr; 108 | while( arg_val > 0 ) 109 | { 110 | u8g_atmega_sw_spi_shift_out(u8g, *ptr++); 111 | arg_val--; 112 | } 113 | } 114 | break; 115 | 116 | case U8G_COM_MSG_WRITE_SEQ_P: 117 | { 118 | register uint8_t *ptr = arg_ptr; 119 | while( arg_val > 0 ) 120 | { 121 | u8g_atmega_sw_spi_shift_out(u8g, u8g_pgm_read(ptr)); 122 | ptr++; 123 | arg_val--; 124 | } 125 | } 126 | break; 127 | } 128 | return 1; 129 | } 130 | 131 | #else 132 | 133 | 134 | uint8_t u8g_com_atmega_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 135 | { 136 | return 1; 137 | } 138 | 139 | 140 | #endif 141 | 142 | -------------------------------------------------------------------------------- /src/clib/u8g_dev_ks0108_128x64.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_ks0108_128x64.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, 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 | ADDRESS = 0 (Command Mode) 36 | 0x03f Display On 37 | 0x0c0 Start Display at line 0 38 | 0x040 | y write to y address (y:0..63) 39 | 0x0b8 | x write to page [0..7] 40 | 41 | 42 | u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset) 43 | u8g_Init8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16, U8G_PIN_NONE) 44 | 45 | */ 46 | 47 | #include "u8g.h" 48 | 49 | #define WIDTH 128 50 | #define HEIGHT 64 51 | #define PAGE_HEIGHT 8 52 | 53 | static const uint8_t u8g_dev_ks0108_128x64_init_seq[] PROGMEM = { 54 | U8G_ESC_CS(0), /* disable chip */ 55 | U8G_ESC_ADR(0), /* instruction mode */ 56 | U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */ 57 | U8G_ESC_CS(1), /* enable chip 1 */ 58 | 0x03f, /* display on */ 59 | 0x0c0, /* start at line 0 */ 60 | U8G_ESC_DLY(20), /* delay 20 ms */ 61 | U8G_ESC_CS(2), /* enable chip 2 */ 62 | 0x03f, /* display on */ 63 | 0x0c0, /* start at line 0 */ 64 | U8G_ESC_DLY(20), /* delay 20 ms */ 65 | U8G_ESC_CS(0), /* disable all chips */ 66 | U8G_ESC_END /* end of sequence */ 67 | }; 68 | 69 | 70 | uint8_t u8g_dev_ks0108_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 71 | { 72 | 73 | switch(msg) 74 | { 75 | case U8G_DEV_MSG_INIT: 76 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE); 77 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_ks0108_128x64_init_seq); 78 | break; 79 | case U8G_DEV_MSG_STOP: 80 | break; 81 | case U8G_DEV_MSG_PAGE_NEXT: 82 | { 83 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 84 | 85 | u8g_SetAddress(u8g, dev, 0); /* command mode */ 86 | u8g_SetChipSelect(u8g, dev, 2); 87 | u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (KS0108b) */ 88 | u8g_WriteByte(u8g, dev, 0x040 ); /* set address 0 */ 89 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 90 | u8g_WriteSequence(u8g, dev, 64, pb->buf); 91 | u8g_SetChipSelect(u8g, dev, 0); 92 | 93 | u8g_SetAddress(u8g, dev, 0); /* command mode */ 94 | u8g_SetChipSelect(u8g, dev, 1); 95 | u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (KS0108b) */ 96 | u8g_WriteByte(u8g, dev, 0x040 ); /* set address 0 */ 97 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 98 | u8g_WriteSequence(u8g, dev, 64, 64+(uint8_t *)pb->buf); 99 | u8g_SetChipSelect(u8g, dev, 0); 100 | 101 | } 102 | break; 103 | } 104 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 105 | } 106 | 107 | U8G_PB_DEV(u8g_dev_ks0108_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ks0108_128x64_fn, U8G_COM_PARALLEL); 108 | U8G_PB_DEV(u8g_dev_ks0108_128x64_fast, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ks0108_128x64_fn, U8G_COM_FAST_PARALLEL); 109 | 110 | 111 | -------------------------------------------------------------------------------- /src/clib/u8g_com_arduino_std_sw_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_arduino_std_sw_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, 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 "u8g.h" 37 | 38 | 39 | #if defined(ARDUINO) 40 | 41 | #if ARDUINO < 100 42 | #include 43 | #else 44 | #include 45 | #endif 46 | 47 | void u8g_arduino_sw_spi_shift_out(uint8_t dataPin, uint8_t clockPin, uint8_t val) 48 | { 49 | uint8_t i = 8; 50 | do 51 | { 52 | if ( val & 128 ) 53 | digitalWrite(dataPin, HIGH); 54 | else 55 | digitalWrite(dataPin, LOW); 56 | val <<= 1; 57 | u8g_MicroDelay(); /* 23 Sep 2012 */ 58 | //delay(1); 59 | digitalWrite(clockPin, HIGH); 60 | u8g_MicroDelay(); /* 23 Sep 2012 */ 61 | //delay(1); 62 | digitalWrite(clockPin, LOW); 63 | u8g_MicroDelay(); /* 23 Sep 2012 */ 64 | //delay(1); 65 | i--; 66 | } while( i != 0 ); 67 | } 68 | 69 | uint8_t u8g_com_arduino_std_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 70 | { 71 | switch(msg) 72 | { 73 | case U8G_COM_MSG_INIT: 74 | u8g_com_arduino_assign_pin_output_high(u8g); 75 | u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW); 76 | u8g_com_arduino_digital_write(u8g, U8G_PI_MOSI, LOW); 77 | break; 78 | 79 | case U8G_COM_MSG_STOP: 80 | break; 81 | 82 | case U8G_COM_MSG_RESET: 83 | if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE ) 84 | u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); 85 | break; 86 | 87 | case U8G_COM_MSG_CHIP_SELECT: 88 | if ( arg_val == 0 ) 89 | { 90 | /* disable */ 91 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); 92 | } 93 | else 94 | { 95 | /* enable */ 96 | u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW); 97 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW); 98 | } 99 | break; 100 | 101 | case U8G_COM_MSG_WRITE_BYTE: 102 | u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], arg_val); 103 | break; 104 | 105 | case U8G_COM_MSG_WRITE_SEQ: 106 | { 107 | register uint8_t *ptr = arg_ptr; 108 | while( arg_val > 0 ) 109 | { 110 | u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], *ptr++); 111 | arg_val--; 112 | } 113 | } 114 | break; 115 | 116 | case U8G_COM_MSG_WRITE_SEQ_P: 117 | { 118 | register uint8_t *ptr = arg_ptr; 119 | while( arg_val > 0 ) 120 | { 121 | u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], u8g_pgm_read(ptr)); 122 | ptr++; 123 | arg_val--; 124 | } 125 | } 126 | break; 127 | 128 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 129 | u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val); 130 | break; 131 | } 132 | return 1; 133 | } 134 | 135 | #else /* ARDUINO */ 136 | 137 | uint8_t u8g_com_arduino_std_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 138 | { 139 | return 1; 140 | } 141 | 142 | #endif /* ARDUINO */ 143 | 144 | -------------------------------------------------------------------------------- /src/clib/u8g_pb8v2.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_pb8v2.c 4 | 5 | 8bit height 2 bit per pixel page buffer 6 | byte has vertical orientation 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2011, 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 "u8g.h" 41 | #include 42 | 43 | void u8g_pb8v2_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) 44 | { 45 | b->buf = buf; 46 | b->width = width; 47 | u8g_pb_Clear(b); 48 | } 49 | 50 | void u8g_pb8v2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) 51 | { 52 | register uint8_t mask; 53 | uint8_t *ptr = b->buf; 54 | y -= b->p.page_y0; 55 | mask = 0x03; 56 | y &= 0x03; 57 | y <<= 1; 58 | mask <<= y; 59 | mask ^=0xff; 60 | color_index &= 3; 61 | color_index <<= y; 62 | ptr += x; 63 | *ptr &= mask; 64 | *ptr |= color_index; 65 | } 66 | 67 | 68 | void u8g_pb8v2_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) 69 | { 70 | if ( arg_pixel->y < b->p.page_y0 ) 71 | return; 72 | if ( arg_pixel->y > b->p.page_y1 ) 73 | return; 74 | if ( arg_pixel->x >= b->width ) 75 | return; 76 | u8g_pb8v2_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 77 | } 78 | 79 | 80 | void u8g_pb8v2_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 81 | { 82 | register uint8_t pixel = arg_pixel->pixel; 83 | do 84 | { 85 | if ( pixel & 128 ) 86 | { 87 | u8g_pb8v2_SetPixel(b, arg_pixel); 88 | } 89 | switch( arg_pixel->dir ) 90 | { 91 | case 0: arg_pixel->x++; break; 92 | case 1: arg_pixel->y++; break; 93 | case 2: arg_pixel->x--; break; 94 | case 3: arg_pixel->y--; break; 95 | } 96 | pixel <<= 1; 97 | } while( pixel != 0 ); 98 | 99 | } 100 | 101 | 102 | 103 | uint8_t u8g_dev_pb8v2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 104 | { 105 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 106 | switch(msg) 107 | { 108 | case U8G_DEV_MSG_SET_8PIXEL: 109 | if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) 110 | { 111 | u8g_pb8v2_Set8PixelStd(pb, (u8g_dev_arg_pixel_t *)arg); 112 | } 113 | break; 114 | case U8G_DEV_MSG_SET_PIXEL: 115 | u8g_pb8v2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 116 | break; 117 | case U8G_DEV_MSG_INIT: 118 | break; 119 | case U8G_DEV_MSG_STOP: 120 | break; 121 | case U8G_DEV_MSG_PAGE_FIRST: 122 | u8g_pb_Clear(pb); 123 | u8g_page_First(&(pb->p)); 124 | break; 125 | case U8G_DEV_MSG_PAGE_NEXT: 126 | if ( u8g_page_Next(&(pb->p)) == 0 ) 127 | return 0; 128 | u8g_pb_Clear(pb); 129 | break; 130 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 131 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 132 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 133 | #endif 134 | case U8G_DEV_MSG_GET_PAGE_BOX: 135 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 136 | break; 137 | case U8G_DEV_MSG_GET_WIDTH: 138 | *((u8g_uint_t *)arg) = pb->width; 139 | break; 140 | case U8G_DEV_MSG_GET_HEIGHT: 141 | *((u8g_uint_t *)arg) = pb->p.total_height; 142 | break; 143 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 144 | break; 145 | case U8G_DEV_MSG_SET_XY_CB: 146 | break; 147 | case U8G_DEV_MSG_GET_MODE: 148 | return U8G_MODE_GRAY2BIT; 149 | } 150 | return 1; 151 | } 152 | 153 | 154 | -------------------------------------------------------------------------------- /src/clib/u8g_com_arduino_hw_usart_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_arduino_hw_usart_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, 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 | SPI Clock Cycle Type 35 | 36 | SSD1351 50ns 20 MHz 37 | SSD1322 300ns 3.3 MHz 38 | SSD1327 300ns 39 | SSD1306 300ns 40 | ST7565 400ns 2.5 MHz 41 | ST7920 400ns 42 | 43 | */ 44 | 45 | #include "u8g.h" 46 | 47 | #if defined(ARDUINO) 48 | 49 | #if defined(__AVR_ATmega32U4__ ) 50 | 51 | #include 52 | #include 53 | 54 | #if ARDUINO < 100 55 | #include 56 | #else 57 | #include 58 | #endif 59 | 60 | 61 | 62 | static uint8_t u8g_usart_spi_out(uint8_t data) 63 | { 64 | /* send data */ 65 | UDR1 = data; 66 | /* wait for empty transmit buffer */ 67 | while(!(UCSR1A & (1 << UDRE1))); 68 | 69 | return UDR1; 70 | } 71 | 72 | 73 | uint8_t u8g_com_arduino_hw_usart_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 74 | { 75 | switch(msg) 76 | { 77 | case U8G_COM_MSG_STOP: 78 | break; 79 | 80 | case U8G_COM_MSG_INIT: 81 | /* SCK is already an output as we overwrite TXLED */ 82 | u8g_com_arduino_assign_pin_output_high(u8g); 83 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); 84 | 85 | // Init interface at 2MHz 86 | UBRR1 = 0x00; 87 | UCSR1C = (1 << UMSEL11) | (1 << UMSEL10); 88 | UCSR1B = (1 << TXEN1); 89 | UBRR1 = 3; 90 | 91 | break; 92 | 93 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 94 | u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val); 95 | break; 96 | 97 | case U8G_COM_MSG_CHIP_SELECT: 98 | if ( arg_val == 0 ) 99 | { 100 | /* disable */ 101 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); 102 | } 103 | else 104 | { 105 | /* enable */ 106 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW); 107 | } 108 | break; 109 | 110 | case U8G_COM_MSG_RESET: 111 | if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE ) 112 | u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); 113 | break; 114 | 115 | case U8G_COM_MSG_WRITE_BYTE: 116 | u8g_usart_spi_out(arg_val); 117 | break; 118 | 119 | case U8G_COM_MSG_WRITE_SEQ: 120 | { 121 | register uint8_t *ptr = arg_ptr; 122 | while( arg_val > 0 ) 123 | { 124 | u8g_usart_spi_out(*ptr++); 125 | arg_val--; 126 | } 127 | } 128 | break; 129 | case U8G_COM_MSG_WRITE_SEQ_P: 130 | { 131 | register uint8_t *ptr = arg_ptr; 132 | while( arg_val > 0 ) 133 | { 134 | u8g_usart_spi_out(u8g_pgm_read(ptr)); 135 | ptr++; 136 | arg_val--; 137 | } 138 | } 139 | break; 140 | } 141 | return 1; 142 | } 143 | 144 | /* #elif defined(__18CXX) || defined(__PIC32MX) */ 145 | /* #elif defined(__arm__) // Arduino Due, maybe we should better check for __SAM3X8E__ */ 146 | 147 | #else /* __AVR_ATmega32U4__ */ 148 | 149 | #endif /* __AVR_ATmega32U4__ */ 150 | 151 | #else /* ARDUINO */ 152 | 153 | uint8_t u8g_com_arduino_hw_usart_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 154 | { 155 | return 1; 156 | } 157 | 158 | #endif /* ARDUINO */ 159 | 160 | -------------------------------------------------------------------------------- /src/clib/u8g_state.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_state.c 4 | 5 | backup and restore hardware state 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, 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 | state callback: backup env U8G_STATE_MSG_BACKUP_ENV 38 | device callback: DEV_MSG_INIT 39 | state callback: backup u8g U8G_STATE_MSG_BACKUP_U8G 40 | state callback: restore env U8G_STATE_MSG_RESTORE_ENV 41 | 42 | state callback: backup env U8G_STATE_MSG_BACKUP_ENV 43 | state callback: retore u8g U8G_STATE_MSG_RESTORE_U8G 44 | DEV_MSG_PAGE_FIRST or DEV_MSG_PAGE_NEXT 45 | state callback: restore env U8G_STATE_MSG_RESTORE_ENV 46 | 47 | */ 48 | 49 | #include 50 | #include "u8g.h" 51 | 52 | void u8g_state_dummy_cb(uint8_t msg) 53 | { 54 | /* the dummy procedure does nothing */ 55 | } 56 | 57 | void u8g_SetHardwareBackup(u8g_t *u8g, u8g_state_cb backup_cb) 58 | { 59 | u8g->state_cb = backup_cb; 60 | /* in most cases the init message was already sent, so this will backup the */ 61 | /* current u8g state */ 62 | backup_cb(U8G_STATE_MSG_BACKUP_U8G); 63 | } 64 | 65 | 66 | /*===============================================================*/ 67 | /* register variable for restoring interrupt state */ 68 | 69 | #if defined(__AVR__) 70 | uint8_t global_SREG_backup; 71 | #endif 72 | 73 | 74 | 75 | /*===============================================================*/ 76 | /* AVR */ 77 | 78 | #if defined(__AVR_XMEGA__) 79 | #elif defined(__AVR__) 80 | #define U8G_ATMEGA_HW_SPI 81 | 82 | /* remove the definition for attiny */ 83 | #if __AVR_ARCH__ == 2 84 | #undef U8G_ATMEGA_HW_SPI 85 | #endif 86 | #if __AVR_ARCH__ == 25 87 | #undef U8G_ATMEGA_HW_SPI 88 | #endif 89 | #endif 90 | 91 | #if defined(U8G_ATMEGA_HW_SPI) 92 | #include 93 | static uint8_t u8g_state_avr_spi_memory[2]; 94 | 95 | void u8g_backup_spi(uint8_t msg) 96 | { 97 | if ( U8G_STATE_MSG_IS_BACKUP(msg) ) 98 | { 99 | u8g_state_avr_spi_memory[U8G_STATE_MSG_GET_IDX(msg)] = SPCR; 100 | } 101 | else 102 | { 103 | uint8_t tmp = SREG; 104 | cli(); 105 | SPCR = 0; 106 | SPCR = u8g_state_avr_spi_memory[U8G_STATE_MSG_GET_IDX(msg)]; 107 | SREG = tmp; 108 | } 109 | } 110 | 111 | #elif defined (U8G_RASPBERRY_PI) 112 | 113 | #include 114 | 115 | void u8g_backup_spi(uint8_t msg) { 116 | printf("u8g_backup_spi %d\r\n",msg); 117 | } 118 | 119 | #elif defined(ARDUINO) && defined(__SAM3X8E__) // Arduino Due, maybe we should better check for __SAM3X8E__ 120 | 121 | #include "sam.h" 122 | 123 | struct sam_backup_struct 124 | { 125 | uint32_t mr; 126 | uint32_t sr; 127 | uint32_t csr[4]; 128 | } sam_backup[2]; 129 | 130 | void u8g_backup_spi(uint8_t msg) 131 | { 132 | uint8_t idx = U8G_STATE_MSG_GET_IDX(msg); 133 | if ( U8G_STATE_MSG_IS_BACKUP(msg) ) 134 | { 135 | sam_backup[idx].mr = SPI0->SPI_MR; 136 | sam_backup[idx].sr = SPI0->SPI_SR; 137 | sam_backup[idx].csr[0] = SPI0->SPI_CSR[0]; 138 | sam_backup[idx].csr[1] = SPI0->SPI_CSR[1]; 139 | sam_backup[idx].csr[2] = SPI0->SPI_CSR[2]; 140 | sam_backup[idx].csr[3] = SPI0->SPI_CSR[3]; 141 | } 142 | else 143 | { 144 | SPI0->SPI_MR = sam_backup[idx].mr; 145 | SPI0->SPI_CSR[0] = sam_backup[idx].csr[0]; 146 | SPI0->SPI_CSR[1] = sam_backup[idx].csr[1]; 147 | SPI0->SPI_CSR[2] = sam_backup[idx].csr[2]; 148 | SPI0->SPI_CSR[3] = sam_backup[idx].csr[3]; 149 | } 150 | } 151 | 152 | #else 153 | 154 | void u8g_backup_spi(uint8_t msg) 155 | { 156 | } 157 | 158 | #endif 159 | 160 | -------------------------------------------------------------------------------- /src/clib/u8g_bitmap.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_bitmap.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, 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 "u8g.h" 38 | 39 | void u8g_DrawHBitmap(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, const uint8_t *bitmap) 40 | { 41 | while( cnt > 0 ) 42 | { 43 | u8g_Draw8Pixel(u8g, x, y, 0, *bitmap); 44 | bitmap++; 45 | cnt--; 46 | x+=8; 47 | } 48 | } 49 | 50 | void u8g_DrawBitmap(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, u8g_uint_t h, const uint8_t *bitmap) 51 | { 52 | if ( u8g_IsBBXIntersection(u8g, x, y, cnt*8, h) == 0 ) 53 | return; 54 | while( h > 0 ) 55 | { 56 | u8g_DrawHBitmap(u8g, x, y, cnt, bitmap); 57 | bitmap += cnt; 58 | y++; 59 | h--; 60 | } 61 | } 62 | 63 | 64 | void u8g_DrawHBitmapP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, const u8g_pgm_uint8_t *bitmap) 65 | { 66 | while( cnt > 0 ) 67 | { 68 | u8g_Draw8Pixel(u8g, x, y, 0, u8g_pgm_read(bitmap)); 69 | bitmap++; 70 | cnt--; 71 | x+=8; 72 | } 73 | } 74 | 75 | void u8g_DrawBitmapP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, u8g_uint_t h, const u8g_pgm_uint8_t *bitmap) 76 | { 77 | if ( u8g_IsBBXIntersection(u8g, x, y, cnt*8, h) == 0 ) 78 | return; 79 | while( h > 0 ) 80 | { 81 | u8g_DrawHBitmapP(u8g, x, y, cnt, bitmap); 82 | bitmap += cnt; 83 | y++; 84 | h--; 85 | } 86 | } 87 | 88 | /*=========================================================================*/ 89 | 90 | static void u8g_DrawHXBM(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, const uint8_t *bitmap) 91 | { 92 | uint8_t d; 93 | x+=7; 94 | while( w >= 8 ) 95 | { 96 | u8g_Draw8Pixel(u8g, x, y, 2, *bitmap); 97 | bitmap++; 98 | w-= 8; 99 | x+=8; 100 | } 101 | if ( w > 0 ) 102 | { 103 | d = *bitmap; 104 | x -= 7; 105 | do 106 | { 107 | if ( d & 1 ) 108 | u8g_DrawPixel(u8g, x, y); 109 | x++; 110 | w--; 111 | d >>= 1; 112 | } while ( w > 0 ); 113 | } 114 | } 115 | 116 | void u8g_DrawXBM(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, const uint8_t *bitmap) 117 | { 118 | u8g_uint_t b; 119 | b = w; 120 | b += 7; 121 | b >>= 3; 122 | 123 | if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 ) 124 | return; 125 | 126 | while( h > 0 ) 127 | { 128 | u8g_DrawHXBM(u8g, x, y, w, bitmap); 129 | bitmap += b; 130 | y++; 131 | h--; 132 | } 133 | } 134 | 135 | static void u8g_DrawHXBMP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, const u8g_pgm_uint8_t *bitmap) 136 | { 137 | uint8_t d; 138 | x+=7; 139 | while( w >= 8 ) 140 | { 141 | u8g_Draw8Pixel(u8g, x, y, 2, u8g_pgm_read(bitmap)); 142 | bitmap++; 143 | w-= 8; 144 | x+=8; 145 | } 146 | if ( w > 0 ) 147 | { 148 | d = u8g_pgm_read(bitmap); 149 | x -= 7; 150 | do 151 | { 152 | if ( d & 1 ) 153 | u8g_DrawPixel(u8g, x, y); 154 | x++; 155 | w--; 156 | d >>= 1; 157 | } while ( w > 0 ); 158 | } 159 | } 160 | 161 | void u8g_DrawXBMP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, const u8g_pgm_uint8_t *bitmap) 162 | { 163 | u8g_uint_t b; 164 | b = w; 165 | b += 7; 166 | b >>= 3; 167 | 168 | if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 ) 169 | return; 170 | while( h > 0 ) 171 | { 172 | u8g_DrawHXBMP(u8g, x, y, w, bitmap); 173 | bitmap += b; 174 | y++; 175 | h--; 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /src/clib/u8g_dev_tls8204_84x48.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_tls8204_84x48.c 4 | 5 | Display: Nokia 84x48 6 | 7 | Status: Tested with TLS8204V12 Display by Olimex MOD-LCD3310 8 | 9 | Contributed: http://code.google.com/p/u8glib/issues/detail?id=126 10 | 11 | Universal 8bit Graphics Library 12 | 13 | Copyright (c) 2011, olikraus@gmail.com 14 | All rights reserved. 15 | 16 | Redistribution and use in source and binary forms, with or without modification, 17 | are permitted provided that the following conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright notice, this list 20 | of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright notice, this 23 | list of conditions and the following disclaimer in the documentation and/or other 24 | materials provided with the distribution. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 27 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 28 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 29 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 30 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 31 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 32 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 33 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 37 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 38 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | 40 | 41 | */ 42 | 43 | #include "u8g.h" 44 | 45 | #define WIDTH 84 46 | #define HEIGHT 48 47 | #define PAGE_HEIGHT 8 48 | 49 | 50 | static const uint8_t u8g_dev_tls8204_init_seq[] PROGMEM = { 51 | U8G_ESC_CS(0), /* disable chip */ 52 | U8G_ESC_ADR(0), /* instruction mode */ 53 | U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */ 54 | U8G_ESC_CS(1), /* enable chip */ 55 | 0x021, /* activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=1) */ 56 | 0x006, /* temp. control: b10 = 2 */ 57 | 0x04 | !!((66-1)&(1u<<6)), 58 | 0x40 | ((66-2) & ((1u<<6)-1)), 59 | 0x013, /* bias system 1:48 */ 60 | 0x0c0, /* medium Vop */ 61 | 0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ 62 | 0x00c, /* display on, normal operation */ 63 | U8G_ESC_DLY(100), /* delay 100 ms */ 64 | 0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ 65 | 0x00d, /* display on, invert */ 66 | U8G_ESC_DLY(100), /* delay 100 ms */ 67 | U8G_ESC_DLY(100), /* delay 100 ms */ 68 | 0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ 69 | 0x00c, /* display on, normal */ 70 | U8G_ESC_DLY(100), /* delay 100 ms */ 71 | U8G_ESC_CS(0), /* disable chip */ 72 | U8G_ESC_END /* end of sequence */ 73 | }; 74 | 75 | 76 | uint8_t u8g_dev_tls8204_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 77 | { 78 | switch(msg) 79 | { 80 | case U8G_DEV_MSG_INIT: 81 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS); 82 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_tls8204_init_seq); 83 | break; 84 | case U8G_DEV_MSG_STOP: 85 | break; 86 | case U8G_DEV_MSG_PAGE_NEXT: 87 | { 88 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 89 | u8g_SetAddress(u8g, dev, 0); /* command mode */ 90 | u8g_SetChipSelect(u8g, dev, 1); 91 | u8g_WriteByte(u8g, dev, 0x020 ); /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ 92 | u8g_WriteByte(u8g, dev, 0x080 ); /* set X address */ 93 | u8g_WriteByte(u8g, dev, 0x040 | pb->p.page); /* set Y address */ 94 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 95 | if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 ) 96 | return 0; 97 | u8g_SetChipSelect(u8g, dev, 0); 98 | } 99 | break; 100 | case U8G_DEV_MSG_CONTRAST: 101 | /* the contrast adjustment does not work, needs to be analysed */ 102 | u8g_SetAddress(u8g, dev, 0); /* instruction mode */ 103 | u8g_SetChipSelect(u8g, dev, 1); 104 | u8g_WriteByte(u8g, dev, 0x021); /* command mode, extended function set */ 105 | u8g_WriteByte(u8g, dev, 0x080 | ( (*(uint8_t *)arg) >> 1 ) ); 106 | u8g_WriteByte(u8g, dev, 0x020); /* command mode, extended function set */ 107 | u8g_SetChipSelect(u8g, dev, 0); 108 | return 1; 109 | } 110 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 111 | } 112 | 113 | 114 | U8G_PB_DEV(u8g_dev_tls8204_84x48_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_tls8204_fn, U8G_COM_SW_SPI); 115 | 116 | -------------------------------------------------------------------------------- /src/clib/u8g_com_linux_ssd_i2c.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_linux_ssd_i2c.c 4 | 5 | com interface for linux i2c-dev and the SSDxxxx chip (SOLOMON) variant 6 | I2C protocol 7 | 8 | 9 | Universal 8bit Graphics Library 10 | 11 | Copyright (c) 2012, olikraus@gmail.com 12 | Copyright (c) 2015, daniel@redfelineninja.org.uk 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 | #include "u8g.h" 42 | 43 | #if defined(U8G_LINUX) 44 | 45 | #include 46 | #include 47 | #include 48 | #include 49 | #include 50 | 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | 57 | #include 58 | 59 | 60 | #define I2C_SLA 0x3c 61 | #define I2C_CMD_MODE 0x80 62 | #define I2C_DATA_MODE 0x40 63 | #define MAX_PACKET 64 64 | 65 | #ifndef U8G_WITH_PINLIST 66 | #error U8G_WITH_PINLIST is mandatory for this driver 67 | #endif 68 | 69 | static void set_cmd_mode(u8g_t *u8g, bool cmd_mode) 70 | { 71 | u8g->pin_list[U8G_PI_A0_STATE] = cmd_mode; 72 | } 73 | 74 | static bool get_cmd_mode(u8g_t *u8g) 75 | { 76 | return u8g->pin_list[U8G_PI_A0_STATE]; 77 | } 78 | 79 | static uint8_t send_data_burst(u8g_t *u8g, int fd, uint8_t *buf, size_t buflen) 80 | { 81 | uint8_t i2cbuf[2*MAX_PACKET]; 82 | uint8_t i2clen; 83 | int res; 84 | 85 | /* ignore bursts when there is no file open */ 86 | if (fd < 0) 87 | return 0; 88 | 89 | if (get_cmd_mode(u8g)) { 90 | i2clen = 0; 91 | while (buflen > 0) { 92 | i2cbuf[i2clen++] = I2C_CMD_MODE; 93 | i2cbuf[i2clen++] = *buf++; 94 | buflen--; 95 | } 96 | } else { 97 | i2cbuf[0] = I2C_DATA_MODE; 98 | memcpy(i2cbuf+1, buf, buflen); 99 | i2clen = buflen + 1; 100 | } 101 | 102 | res = write(fd, i2cbuf, i2clen); 103 | if (res < 0) 104 | fprintf(stderr, "I2C write failed (%s)\n", strerror(errno)); 105 | else if (res != i2clen) 106 | fprintf(stderr, "Incomplete I2C write (%d of %d packet)\n", res, i2clen); 107 | 108 | return res == i2clen; 109 | } 110 | 111 | uint8_t u8g_com_linux_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 112 | { 113 | static int fd = -1; 114 | char dev[24]; 115 | 116 | switch(msg) 117 | { 118 | case U8G_COM_MSG_INIT: 119 | sprintf(dev, "/dev/i2c-%d", u8g->pin_list[U8G_PI_I2C_OPTION]); 120 | fd = open(dev, O_RDWR); 121 | if (fd < 0) { 122 | fprintf(stderr, "cannot open %s (%s)\n", dev, strerror(errno)); 123 | return 0; 124 | } 125 | 126 | if (ioctl(fd, I2C_SLAVE, I2C_SLA) < 0) { 127 | fprintf(stderr, "cannot set slave address (%s)\n", strerror(errno)); 128 | return 0; 129 | } 130 | 131 | break; 132 | 133 | case U8G_COM_MSG_STOP: 134 | /* ignored - i2c-dev will automatically stop between writes */ 135 | break; 136 | 137 | case U8G_COM_MSG_RESET: 138 | /* ignored - no obvious means to reset an SSD via I2C */ 139 | break; 140 | 141 | case U8G_COM_MSG_CHIP_SELECT: 142 | set_cmd_mode(u8g, true); 143 | break; 144 | 145 | case U8G_COM_MSG_WRITE_BYTE: 146 | send_data_burst(u8g, fd, &arg_val, 1); 147 | break; 148 | 149 | case U8G_COM_MSG_WRITE_SEQ: 150 | case U8G_COM_MSG_WRITE_SEQ_P: /* no progmem in Linux */ 151 | while (arg_val > MAX_PACKET) { 152 | send_data_burst(u8g, fd, arg_ptr, MAX_PACKET); 153 | arg_ptr += MAX_PACKET; 154 | arg_val -= MAX_PACKET; 155 | } 156 | send_data_burst(u8g, fd, arg_ptr, arg_val); 157 | break; 158 | 159 | case U8G_COM_MSG_ADDRESS: 160 | /* choose cmd (arg_val = 0) or data mode (arg_val = 1) */ 161 | set_cmd_mode(u8g, !arg_val); 162 | break; 163 | } 164 | 165 | return 1; 166 | } 167 | 168 | #endif /* U8G_LINUX */ 169 | -------------------------------------------------------------------------------- /src/clib/u8g_pb8h2.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_pb8h2.c 4 | 5 | 8bit height 2 bit per pixel page buffer 6 | byte has horizontal orientation 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2011, 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 "u8g.h" 41 | #include 42 | 43 | void u8g_pb8h2_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) 44 | { 45 | b->buf = buf; 46 | b->width = width; 47 | u8g_pb_Clear(b); 48 | } 49 | 50 | static void u8g_pb8h2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE; 51 | static void u8g_pb8h2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) 52 | { 53 | register uint8_t mask; 54 | register uint16_t tmp; 55 | 56 | uint8_t *ptr = b->buf; 57 | 58 | y -= b->p.page_y0; 59 | 60 | tmp = b->width; 61 | tmp >>= 2; 62 | tmp *= (uint8_t)y; 63 | ptr += tmp; 64 | 65 | tmp = x; 66 | tmp >>= 2; 67 | ptr += tmp; 68 | 69 | tmp = x; 70 | tmp &= 3; 71 | tmp <<= 1; 72 | mask = 3; 73 | mask <<= tmp; 74 | mask = ~mask; 75 | color_index &= 3; 76 | color_index <<= tmp; 77 | 78 | *ptr &= mask; 79 | *ptr |= color_index; 80 | } 81 | 82 | 83 | void u8g_pb8h2_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) 84 | { 85 | if ( arg_pixel->y < b->p.page_y0 ) 86 | return; 87 | if ( arg_pixel->y > b->p.page_y1 ) 88 | return; 89 | if ( arg_pixel->x >= b->width ) 90 | return; 91 | u8g_pb8h2_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 92 | } 93 | 94 | 95 | void u8g_pb8h2_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 96 | { 97 | register uint8_t pixel = arg_pixel->pixel; 98 | do 99 | { 100 | if ( pixel & 128 ) 101 | { 102 | u8g_pb8h2_SetPixel(b, arg_pixel); 103 | } 104 | switch( arg_pixel->dir ) 105 | { 106 | case 0: arg_pixel->x++; break; 107 | case 1: arg_pixel->y++; break; 108 | case 2: arg_pixel->x--; break; 109 | case 3: arg_pixel->y--; break; 110 | } 111 | pixel <<= 1; 112 | } while( pixel != 0 ); 113 | } 114 | 115 | 116 | 117 | uint8_t u8g_dev_pb8h2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 118 | { 119 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 120 | switch(msg) 121 | { 122 | case U8G_DEV_MSG_SET_8PIXEL: 123 | if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) 124 | { 125 | u8g_pb8h2_Set8PixelStd(pb, (u8g_dev_arg_pixel_t *)arg); 126 | } 127 | break; 128 | case U8G_DEV_MSG_SET_PIXEL: 129 | u8g_pb8h2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 130 | break; 131 | case U8G_DEV_MSG_INIT: 132 | break; 133 | case U8G_DEV_MSG_STOP: 134 | break; 135 | case U8G_DEV_MSG_PAGE_FIRST: 136 | u8g_pb_Clear(pb); 137 | u8g_page_First(&(pb->p)); 138 | break; 139 | case U8G_DEV_MSG_PAGE_NEXT: 140 | if ( u8g_page_Next(&(pb->p)) == 0 ) 141 | return 0; 142 | u8g_pb_Clear(pb); 143 | break; 144 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 145 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 146 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 147 | #endif 148 | case U8G_DEV_MSG_GET_PAGE_BOX: 149 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 150 | break; 151 | case U8G_DEV_MSG_GET_WIDTH: 152 | *((u8g_uint_t *)arg) = pb->width; 153 | break; 154 | case U8G_DEV_MSG_GET_HEIGHT: 155 | *((u8g_uint_t *)arg) = pb->p.total_height; 156 | break; 157 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 158 | break; 159 | case U8G_DEV_MSG_SET_XY_CB: 160 | break; 161 | case U8G_DEV_MSG_GET_MODE: 162 | return U8G_MODE_GRAY2BIT; 163 | } 164 | return 1; 165 | } 166 | 167 | 168 | -------------------------------------------------------------------------------- /src/clib/u8g_com_raspberrypi_ssd_i2c.c: -------------------------------------------------------------------------------- 1 | /* 2 | Special pin usage: 3 | U8G_PI_I2C_OPTION additional options 4 | U8G_PI_A0_STATE used to store the last value of the command/data register selection 5 | U8G_PI_SET_A0 1: Signal request to update I2C device with new A0_STATE, 0: Do nothing, A0_STATE matches I2C device 6 | U8G_PI_SCL clock line (NOT USED) 7 | U8G_PI_SDA data line (NOT USED) 8 | 9 | U8G_PI_RESET reset line (currently disabled, see below) 10 | 11 | Protocol: 12 | SLA, Cmd/Data Selection, Arguments 13 | The command/data register is selected by a special instruction byte, which is sent after SLA 14 | 15 | The continue bit is always 0 so that a (re)start is equired for the change from cmd to/data mode 16 | */ 17 | 18 | #include "u8g.h" 19 | 20 | #if defined(U8G_RASPBERRY_PI) 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #define I2C_SLA 0x3c 29 | #define I2C_CMD_MODE 0x000 30 | #define I2C_DATA_MODE 0x040 31 | 32 | #if defined(U8G_WITH_PINLIST) 33 | 34 | uint8_t u8g_com_raspberrypi_ssd_start_sequence(u8g_t *u8g) 35 | { 36 | /* are we requested to set the a0 state? */ 37 | if ( u8g->pin_list[U8G_PI_SET_A0] == 0 ) 38 | return 1; 39 | 40 | /* setup bus, might be a repeated start */ 41 | if ( u8g_i2c_start(I2C_SLA) == 0 ) 42 | return 0; 43 | if ( u8g->pin_list[U8G_PI_A0_STATE] == 0 ) 44 | { 45 | if ( u8g_i2c_send_mode(I2C_CMD_MODE) == 0 ) 46 | return 0; 47 | } 48 | else 49 | { 50 | if ( u8g_i2c_send_mode(I2C_DATA_MODE) == 0 ) 51 | return 0; 52 | } 53 | 54 | 55 | u8g->pin_list[U8G_PI_SET_A0] = 0; 56 | return 1; 57 | } 58 | 59 | uint8_t u8g_com_raspberrypi_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 60 | { 61 | switch(msg) 62 | { 63 | case U8G_COM_MSG_INIT: 64 | u8g_i2c_init(u8g->pin_list[U8G_PI_I2C_OPTION]); 65 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 66 | u8g_SetPIOutput(u8g, U8G_PI_A0); 67 | break; 68 | 69 | case U8G_COM_MSG_STOP: 70 | break; 71 | 72 | case U8G_COM_MSG_RESET: 73 | break; 74 | 75 | case U8G_COM_MSG_CHIP_SELECT: 76 | u8g->pin_list[U8G_PI_A0_STATE] = 0; 77 | u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again, also forces start condition */ 78 | if ( arg_val == 0 ) 79 | { 80 | /* disable chip, send stop condition */ 81 | u8g_i2c_stop(); 82 | } 83 | else 84 | { 85 | /* enable, do nothing: any byte writing will trigger the i2c start */ 86 | } 87 | break; 88 | 89 | case U8G_COM_MSG_WRITE_BYTE: 90 | //u8g->pin_list[U8G_PI_SET_A0] = 1; 91 | if ( u8g_com_raspberrypi_ssd_start_sequence(u8g) == 0 ) 92 | return u8g_i2c_stop(), 0; 93 | if ( u8g_i2c_send_byte(arg_val) == 0 ) 94 | return u8g_i2c_stop(), 0; 95 | // u8g_i2c_stop(); 96 | break; 97 | 98 | case U8G_COM_MSG_WRITE_SEQ: 99 | //u8g->pin_list[U8G_PI_SET_A0] = 1; 100 | if ( u8g_com_raspberrypi_ssd_start_sequence(u8g) == 0 ) 101 | return u8g_i2c_stop(), 0; 102 | { 103 | register uint8_t *ptr = (uint8_t *)arg_ptr; 104 | while( arg_val > 0 ) 105 | { 106 | if ( u8g_i2c_send_byte(*ptr++) == 0 ) 107 | return u8g_i2c_stop(), 0; 108 | arg_val--; 109 | } 110 | } 111 | // u8g_i2c_stop(); 112 | break; 113 | 114 | case U8G_COM_MSG_WRITE_SEQ_P: 115 | //u8g->pin_list[U8G_PI_SET_A0] = 1; 116 | if ( u8g_com_raspberrypi_ssd_start_sequence(u8g) == 0 ) 117 | return u8g_i2c_stop(), 0; 118 | { 119 | register uint8_t *ptr = (uint8_t *)arg_ptr; 120 | while( arg_val > 0 ) 121 | { 122 | if ( u8g_i2c_send_byte(u8g_pgm_read(ptr)) == 0 ) 123 | return 0; 124 | ptr++; 125 | arg_val--; 126 | } 127 | } 128 | // u8g_i2c_stop(); 129 | break; 130 | 131 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 132 | u8g->pin_list[U8G_PI_A0_STATE] = arg_val; 133 | u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again */ 134 | 135 | #ifdef OLD_CODE 136 | if ( i2c_state != 0 ) 137 | { 138 | u8g_i2c_stop(); 139 | i2c_state = 0; 140 | } 141 | 142 | if ( u8g_com_raspberrypi_ssd_start_sequence(arg_val) == 0 ) 143 | return 0; 144 | 145 | /* setup bus, might be a repeated start */ 146 | /* 147 | if ( u8g_i2c_start(I2C_SLA) == 0 ) 148 | return 0; 149 | if ( arg_val == 0 ) 150 | { 151 | i2c_state = 1; 152 | 153 | if ( u8g_i2c_send_byte(I2C_CMD_MODE) == 0 ) 154 | return 0; 155 | } 156 | else 157 | { 158 | i2c_state = 2; 159 | if ( u8g_i2c_send_byte(I2C_DATA_MODE) == 0 ) 160 | return 0; 161 | } 162 | */ 163 | #endif 164 | break; 165 | } 166 | return 1; 167 | } 168 | 169 | #else /* defined(U8G_WITH_PINLIST) */ 170 | 171 | uint8_t u8g_com_raspberrypi_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 172 | return 1; 173 | } 174 | 175 | #endif /* defined(U8G_WITH_PINLIST) */ 176 | #endif 177 | -------------------------------------------------------------------------------- /src/clib/u8g_dev_uc1611_dogm240.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_uc1611_dogm240.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2014, dev.menges.jonas@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 "u8g.h" 38 | 39 | 40 | #define WIDTH 240 41 | #define HEIGHT 64 42 | #define PAGE_HEIGHT 8 43 | 44 | 45 | static const uint8_t u8g_dev_uc1611_dogm240_init_seq[] PROGMEM = { 46 | U8G_ESC_CS(0), /* disable chip */ 47 | U8G_ESC_ADR(0), /* instruction mode */ 48 | U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */ 49 | U8G_ESC_DLY(200), 50 | U8G_ESC_CS(1), // enable chip 51 | U8G_ESC_ADR(0), // instruction mode 52 | 0xe2, // system reset 53 | U8G_ESC_DLY(1), 54 | 0x2f, // enable internal charge pump 55 | 56 | 0xF1, // set last COM electrode 57 | 0x3F, // 64-1=63 58 | 0xF2, // set display start line 59 | 0x00, // 0 60 | 0xF3, // set display end line 61 | 0x3F, // 64-1=63 62 | 0x81, // set contrast (0-255) 63 | 0xB7, // 183 64 | 0xC0, // set view 65 | //0x04, // topview 66 | 0x02, // bottomview 67 | 0xA3, // set line rate (9.4k) 68 | 0xE9, // set bias ratio (10) 69 | 0xA9, // enable display 70 | 0xD1, // set black and white mode 71 | U8G_ESC_CS(0), // disable chip 72 | U8G_ESC_END // end of sequence 73 | }; 74 | 75 | static void setPage(u8g_t *u8g, u8g_dev_t *dev, unsigned char page) 76 | { 77 | u8g_WriteByte(u8g, dev, 0x70 + (page>>4)); 78 | u8g_WriteByte(u8g, dev, 0x60 + (page&0x0F)); 79 | } 80 | 81 | static const uint8_t u8g_dev_uc1611_dogm240_data_start[] PROGMEM = { 82 | U8G_ESC_ADR(0), /* instruction mode */ 83 | U8G_ESC_CS(1), /* enable chip */ 84 | 0x10, /* set upper 4 bit of the col adr to 0 */ 85 | 0x00, /* set lower 4 bit of the col adr to 0 */ 86 | U8G_ESC_END /* end of sequence */ 87 | }; 88 | 89 | uint8_t u8g_dev_uc1611_dogm240_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 90 | { 91 | switch(msg) 92 | { 93 | case U8G_DEV_MSG_INIT: 94 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS); 95 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogm240_init_seq); 96 | break; 97 | case U8G_DEV_MSG_STOP: 98 | break; 99 | case U8G_DEV_MSG_PAGE_NEXT: 100 | { 101 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 102 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogm240_data_start); 103 | setPage(u8g, dev, pb->p.page); /* select current page (uc1611) */ 104 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 105 | if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 ) 106 | return 0; 107 | u8g_SetChipSelect(u8g, dev, 0); 108 | } 109 | break; 110 | case U8G_DEV_MSG_CONTRAST: 111 | u8g_SetChipSelect(u8g, dev, 1); 112 | u8g_SetAddress(u8g, dev, 0); /* instruction mode */ 113 | u8g_WriteByte(u8g, dev, 0x81); 114 | /* 11 Jul 2015: bugfix, github issue 339 */ 115 | u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) ); /* set contrast from, keep gain at 0 */ 116 | u8g_SetChipSelect(u8g, dev, 0); 117 | return 1; 118 | } 119 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 120 | } 121 | 122 | U8G_PB_DEV(u8g_dev_uc1611_dogm240_i2c , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogm240_fn, U8G_COM_UC_I2C); 123 | U8G_PB_DEV(u8g_dev_uc1611_dogm240_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogm240_fn, U8G_COM_SW_SPI); 124 | U8G_PB_DEV(u8g_dev_uc1611_dogm240_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogm240_fn, U8G_COM_HW_SPI); 125 | U8G_PB_DEV(u8g_dev_uc1611_dogm240_8bit , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogm240_fn, U8G_COM_FAST_PARALLEL); 126 | 127 | -------------------------------------------------------------------------------- /src/clib/u8g_clip.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_clip.c 4 | 5 | procedures for clipping 6 | taken over from procs in u8g_pb.c 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2012, 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 | Notes 38 | 39 | This is one of the most critical parts of u8glib. It must be fast, but still reliable. 40 | Based on the intersection program (see tools folder), there is minimized version of 41 | the condition for the intersaction test: 42 | minimized version 43 | ---1----0 1 b1 <= a2 && b1 > b2 44 | -----1--0 1 b2 >= a1 && b1 > b2 45 | ---1-1--- 1 b1 <= a2 && b2 >= a1 46 | It includes the assumption, that a1 <= a2 is always true (correct, because 47 | a1, a2 are the page dimensions. 48 | 49 | The direct implementation of the above result is done in: 50 | uint8_t u8g_is_intersection_boolean(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) 51 | However, this is slower than a decision tree version: 52 | static uint8_t u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) 53 | Also suprising is, that the macro implementation is slower than the inlined version. 54 | 55 | The decision tree is based on the expansion of the truth table. 56 | 57 | */ 58 | 59 | #include "u8g.h" 60 | 61 | #ifdef __GNUC__ 62 | #define U8G_ALWAYS_INLINE __inline__ __attribute__((always_inline)) 63 | #else 64 | #define U8G_ALWAYS_INLINE 65 | #endif 66 | 67 | /* 68 | intersection assumptions: 69 | a1 <= a2 is always true 70 | 71 | minimized version 72 | ---1----0 1 b1 <= a2 && b1 > b2 73 | -----1--0 1 b2 >= a1 && b1 > b2 74 | ---1-1--- 1 b1 <= a2 && b2 >= a1 75 | */ 76 | 77 | #ifdef OLD_CODE_WHICH_IS_TOO_SLOW 78 | static uint8_t u8g_is_intersection_boolean(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) 79 | { 80 | uint8_t c1, c2, c3, tmp; 81 | c1 = v0 <= a1; 82 | c2 = v1 >= a0; 83 | c3 = v0 > v1; 84 | 85 | tmp = c1; 86 | c1 &= c2; 87 | c2 &= c3; 88 | c3 &= tmp; 89 | c1 |= c2; 90 | c1 |= c3; 91 | return c1 & 1; 92 | } 93 | #endif 94 | 95 | #define U8G_IS_INTERSECTION_MACRO(a0,a1,v0,v1) ((uint8_t)( (v0) <= (a1) ) ? ( ( (v1) >= (a0) ) ? ( 1 ) : ( (v0) > (v1) ) ) : ( ( (v1) >= (a0) ) ? ( (v0) > (v1) ) : ( 0 ) )) 96 | 97 | //static uint8_t u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) U8G_ALWAYS_INLINE; 98 | static uint8_t U8G_ALWAYS_INLINE u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) 99 | { 100 | /* surprisingly the macro leads to larger code */ 101 | /* return U8G_IS_INTERSECTION_MACRO(a0,a1,v0,v1); */ 102 | if ( v0 <= a1 ) 103 | { 104 | if ( v1 >= a0 ) 105 | { 106 | return 1; 107 | } 108 | else 109 | { 110 | if ( v0 > v1 ) 111 | { 112 | return 1; 113 | } 114 | else 115 | { 116 | return 0; 117 | } 118 | } 119 | } 120 | else 121 | { 122 | if ( v1 >= a0 ) 123 | { 124 | if ( v0 > v1 ) 125 | { 126 | return 1; 127 | } 128 | else 129 | { 130 | return 0; 131 | } 132 | } 133 | else 134 | { 135 | return 0; 136 | } 137 | } 138 | } 139 | 140 | 141 | uint8_t u8g_IsBBXIntersection(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h) 142 | { 143 | register u8g_uint_t tmp; 144 | tmp = y; 145 | tmp += h; 146 | tmp--; 147 | if ( u8g_is_intersection_decision_tree(u8g->current_page.y0, u8g->current_page.y1, y, tmp) == 0 ) 148 | return 0; 149 | 150 | tmp = x; 151 | tmp += w; 152 | tmp--; 153 | return u8g_is_intersection_decision_tree(u8g->current_page.x0, u8g->current_page.x1, x, tmp); 154 | } 155 | 156 | 157 | -------------------------------------------------------------------------------- /src/clib/u8g_virtual_screen.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_virtual_screen.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2012, 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 "u8g.h" 38 | 39 | struct _u8g_vs_t 40 | { 41 | u8g_uint_t x; 42 | u8g_uint_t y; 43 | u8g_t *u8g; 44 | }; 45 | typedef struct _u8g_vs_t u8g_vs_t; 46 | 47 | #define U8g_VS_MAX 4 48 | uint8_t u8g_vs_cnt = 0; 49 | u8g_vs_t u8g_vs_list[U8g_VS_MAX]; 50 | uint8_t u8g_vs_current; 51 | u8g_uint_t u8g_vs_width; 52 | u8g_uint_t u8g_vs_height; 53 | 54 | uint8_t u8g_dev_vs_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 55 | { 56 | switch(msg) 57 | { 58 | default: 59 | { 60 | uint8_t i; 61 | for( i = 0; i < u8g_vs_cnt; i++ ) 62 | { 63 | u8g_call_dev_fn(u8g_vs_list[i].u8g, u8g_vs_list[i].u8g->dev, msg, arg); 64 | } 65 | } 66 | return 1; 67 | case U8G_DEV_MSG_PAGE_FIRST: 68 | u8g_vs_current = 0; 69 | if ( u8g_vs_cnt != 0 ) 70 | return u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); 71 | return 0; 72 | case U8G_DEV_MSG_PAGE_NEXT: 73 | { 74 | uint8_t ret = 0; 75 | if ( u8g_vs_cnt != 0 ) 76 | ret = u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); 77 | if ( ret != 0 ) 78 | return ret; 79 | u8g_vs_current++; /* next device */ 80 | if ( u8g_vs_current >= u8g_vs_cnt ) /* reached end? */ 81 | return 0; 82 | return u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, U8G_DEV_MSG_PAGE_FIRST, arg); 83 | } 84 | case U8G_DEV_MSG_GET_WIDTH: 85 | *((u8g_uint_t *)arg) = u8g_vs_width; 86 | break; 87 | case U8G_DEV_MSG_GET_HEIGHT: 88 | *((u8g_uint_t *)arg) = u8g_vs_height; 89 | break; 90 | case U8G_DEV_MSG_GET_PAGE_BOX: 91 | if ( u8g_vs_current < u8g_vs_cnt ) 92 | { 93 | u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); 94 | ((u8g_box_t *)arg)->x0 += u8g_vs_list[u8g_vs_current].x; 95 | ((u8g_box_t *)arg)->x1 += u8g_vs_list[u8g_vs_current].x; 96 | ((u8g_box_t *)arg)->y0 += u8g_vs_list[u8g_vs_current].y; 97 | ((u8g_box_t *)arg)->y1 += u8g_vs_list[u8g_vs_current].y; 98 | } 99 | else 100 | { 101 | ((u8g_box_t *)arg)->x0 = 0; 102 | ((u8g_box_t *)arg)->x1 = 0; 103 | ((u8g_box_t *)arg)->y0 = 0; 104 | ((u8g_box_t *)arg)->y1 = 0; 105 | } 106 | return 1; 107 | case U8G_DEV_MSG_SET_PIXEL: 108 | case U8G_DEV_MSG_SET_8PIXEL: 109 | if ( u8g_vs_current < u8g_vs_cnt ) 110 | { 111 | ((u8g_dev_arg_pixel_t *)arg)->x -= u8g_vs_list[u8g_vs_current].x; 112 | ((u8g_dev_arg_pixel_t *)arg)->y -= u8g_vs_list[u8g_vs_current].y; 113 | return u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); 114 | } 115 | break; 116 | } 117 | return 1; 118 | } 119 | 120 | 121 | 122 | u8g_dev_t u8g_dev_vs = { u8g_dev_vs_fn, NULL, NULL }; 123 | 124 | void u8g_SetVirtualScreenDimension(u8g_t *vs_u8g, u8g_uint_t width, u8g_uint_t height) 125 | { 126 | if ( vs_u8g->dev != &u8g_dev_vs ) 127 | return; /* abort if there is no a virtual screen device */ 128 | u8g_vs_width = width; 129 | u8g_vs_height = height; 130 | } 131 | 132 | uint8_t u8g_AddToVirtualScreen(u8g_t *vs_u8g, u8g_uint_t x, u8g_uint_t y, u8g_t *child_u8g) 133 | { 134 | if ( vs_u8g->dev != &u8g_dev_vs ) 135 | return 0; /* abort if there is no a virtual screen device */ 136 | if ( u8g_vs_cnt >= U8g_VS_MAX ) 137 | return 0; /* maximum number of child u8g's reached */ 138 | u8g_vs_list[u8g_vs_cnt].u8g = child_u8g; 139 | u8g_vs_list[u8g_vs_cnt].x = x; 140 | u8g_vs_list[u8g_vs_cnt].y = y; 141 | u8g_vs_cnt++; 142 | return 1; 143 | } 144 | 145 | -------------------------------------------------------------------------------- /src/clib/u8g_pb16v2.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_pb16v2.c 4 | 5 | 16 bit height 2 bit per pixel page buffer 6 | byte has vertical orientation 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2012, 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 "u8g.h" 41 | #include 42 | 43 | 44 | void u8g_pb16v2_Clear(u8g_pb_t *b) 45 | { 46 | uint8_t *ptr = (uint8_t *)b->buf; 47 | uint8_t *end_ptr = ptr; 48 | 49 | /* two bits per pixel, 16 bits height --> 8 pixel --> 4 pixel per byte */ 50 | end_ptr += b->width; 51 | end_ptr += b->width; 52 | 53 | do 54 | { 55 | *ptr++ = 0; 56 | } while( ptr != end_ptr ); 57 | } 58 | 59 | void u8g_pb16v2Init(u8g_pb_t *b, void *buf, u8g_uint_t width) 60 | { 61 | b->buf = buf; 62 | b->width = width; 63 | u8g_pb16v2_Clear(b); 64 | } 65 | 66 | void u8g_pb16v2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) 67 | { 68 | register uint8_t mask; 69 | uint8_t *ptr = b->buf; 70 | y -= b->p.page_y0; 71 | if ( y >= 4 ) 72 | { 73 | ptr += b->width; 74 | } 75 | mask = 0x03; 76 | y &= 0x03; 77 | y <<= 1; 78 | mask <<= y; 79 | mask ^=0xff; 80 | color_index &= 3; 81 | color_index <<= y; 82 | ptr += x; 83 | *ptr &= mask; 84 | *ptr |= color_index; 85 | } 86 | 87 | 88 | void u8g_pb16v2_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) 89 | { 90 | if ( arg_pixel->y < b->p.page_y0 ) 91 | return; 92 | if ( arg_pixel->y > b->p.page_y1 ) 93 | return; 94 | if ( arg_pixel->x >= b->width ) 95 | return; 96 | u8g_pb16v2_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 97 | } 98 | 99 | 100 | void u8g_pb16v2_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 101 | { 102 | register uint8_t pixel = arg_pixel->pixel; 103 | do 104 | { 105 | if ( pixel & 128 ) 106 | { 107 | u8g_pb16v2_SetPixel(b, arg_pixel); 108 | } 109 | switch( arg_pixel->dir ) 110 | { 111 | case 0: arg_pixel->x++; break; 112 | case 1: arg_pixel->y++; break; 113 | case 2: arg_pixel->x--; break; 114 | case 3: arg_pixel->y--; break; 115 | } 116 | pixel <<= 1; 117 | } while( pixel != 0 ); 118 | } 119 | 120 | 121 | 122 | uint8_t u8g_dev_pb16v2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 123 | { 124 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 125 | switch(msg) 126 | { 127 | case U8G_DEV_MSG_SET_8PIXEL: 128 | if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) 129 | { 130 | u8g_pb16v2_Set8PixelStd(pb, (u8g_dev_arg_pixel_t *)arg); 131 | } 132 | break; 133 | case U8G_DEV_MSG_SET_PIXEL: 134 | u8g_pb16v2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 135 | break; 136 | case U8G_DEV_MSG_INIT: 137 | break; 138 | case U8G_DEV_MSG_STOP: 139 | break; 140 | case U8G_DEV_MSG_PAGE_FIRST: 141 | u8g_pb16v2_Clear(pb); 142 | u8g_page_First(&(pb->p)); 143 | break; 144 | case U8G_DEV_MSG_PAGE_NEXT: 145 | if ( u8g_page_Next(&(pb->p)) == 0 ) 146 | return 0; 147 | u8g_pb16v2_Clear(pb); 148 | break; 149 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 150 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 151 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 152 | #endif 153 | case U8G_DEV_MSG_GET_PAGE_BOX: 154 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 155 | break; 156 | case U8G_DEV_MSG_GET_WIDTH: 157 | *((u8g_uint_t *)arg) = pb->width; 158 | break; 159 | case U8G_DEV_MSG_GET_HEIGHT: 160 | *((u8g_uint_t *)arg) = pb->p.total_height; 161 | break; 162 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 163 | break; 164 | case U8G_DEV_MSG_SET_XY_CB: 165 | break; 166 | case U8G_DEV_MSG_GET_MODE: 167 | return U8G_MODE_GRAY2BIT; 168 | } 169 | return 1; 170 | } 171 | 172 | 173 | -------------------------------------------------------------------------------- /src/clib/u8g_com_atxmega_hw_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_atxmega_hw_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, olikraus@gmail.com 8 | Copyright (c) 2015, florianmenne@t-online.de 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 | A special SPI interface for ST7920 controller with HW SPI Support 36 | 37 | Assumes, that 38 | MOSI is at PORTB, Pin 3 39 | and 40 | SCK is at PORTB, Pin 5 41 | 42 | Update for ATOMIC operation done (01 Jun 2013) 43 | U8G_ATOMIC_OR(ptr, val) 44 | U8G_ATOMIC_AND(ptr, val) 45 | U8G_ATOMIC_START() 46 | U8G_ATOMIC_END() 47 | 48 | 49 | */ 50 | 51 | #include "u8g.h" 52 | 53 | #if defined(__AVR_XMEGA__) 54 | #define U8G_ATXMEGA_HW_SPI 55 | #endif 56 | 57 | 58 | #if defined(U8G_ATXMEGA_HW_SPI) 59 | 60 | #include 61 | #include 62 | 63 | 64 | static uint8_t u8g_atxmega_spi_out(uint8_t data) 65 | { 66 | /* send data */ 67 | SPIC.DATA = data; 68 | 69 | /* wait for transmission */ 70 | while(!(SPIC.STATUS & SPI_IF_bm)); 71 | 72 | /* clear the SPIF flag by reading SPDR */ 73 | return SPIC.DATA; 74 | } 75 | 76 | 77 | uint8_t u8g_com_atxmega_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 78 | { 79 | switch(msg) 80 | { 81 | case U8G_COM_MSG_STOP: 82 | break; 83 | 84 | case U8G_COM_MSG_INIT: 85 | 86 | u8g_SetPIOutput(u8g, U8G_PI_CS); 87 | u8g_SetPIOutput(u8g, U8G_PI_A0); 88 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 89 | 90 | //U8G_ATOMIC_START(); 91 | 92 | PORTC.DIR |= PIN4_bm | PIN5_bm | PIN7_bm; 93 | PORTC.DIR &= ~PIN6_bm; 94 | 95 | //U8G_ATOMIC_END(); 96 | 97 | u8g_SetPILevel(u8g, U8G_PI_CS, 1); 98 | 99 | SPIC.CTRL = 0; 100 | SPIC.CTRL = SPI_PRESCALER_DIV4_gc | // SPI prescaler. 101 | //SPI_CLK2X_bm | //SPI Clock double. 102 | SPI_ENABLE_bm | //Enable SPI module. 103 | //SPI_DORD_bm | //Data order. 104 | SPI_MASTER_bm | //SPI master. 105 | SPI_MODE_0_gc; // SPI mode. 106 | 107 | #ifdef U8G_HW_SPI_2X 108 | SPIC.CTRL |= SPI_CLK2X_bm; /* double speed, issue 89 */ 109 | #endif 110 | 111 | break; 112 | 113 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 114 | u8g_SetPILevel(u8g, U8G_PI_A0, arg_val); 115 | break; 116 | 117 | case U8G_COM_MSG_CHIP_SELECT: 118 | 119 | if ( arg_val == 0 ) 120 | { 121 | /* disable */ 122 | u8g_SetPILevel(u8g, U8G_PI_CS, 1); 123 | } 124 | else 125 | { 126 | //PORTB &= ~_BV(5); /* SCK = 0 */ 127 | PORTC.OUT &= ~PIN7_bm; 128 | /* enable */ 129 | u8g_SetPILevel(u8g, U8G_PI_CS, 0); /* CS = 0 (low active) */ 130 | } 131 | 132 | break; 133 | 134 | case U8G_COM_MSG_RESET: 135 | u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 136 | break; 137 | 138 | case U8G_COM_MSG_WRITE_BYTE: 139 | u8g_atxmega_spi_out(arg_val); 140 | break; 141 | 142 | case U8G_COM_MSG_WRITE_SEQ: 143 | { 144 | register uint8_t *ptr = arg_ptr; 145 | while( arg_val > 0 ) 146 | { 147 | u8g_atxmega_spi_out(*ptr++); 148 | arg_val--; 149 | } 150 | } 151 | break; 152 | case U8G_COM_MSG_WRITE_SEQ_P: 153 | { 154 | register uint8_t *ptr = arg_ptr; 155 | while( arg_val > 0 ) 156 | { 157 | u8g_atxmega_spi_out(u8g_pgm_read(ptr)); 158 | ptr++; 159 | arg_val--; 160 | } 161 | } 162 | break; 163 | } 164 | return 1; 165 | } 166 | 167 | #else 168 | 169 | uint8_t u8g_com_atxmega_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 170 | { 171 | return 1; 172 | } 173 | 174 | #endif -------------------------------------------------------------------------------- /src/clib/u8g_dev_uc1611_dogxl240.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_uc1611_dogxl240.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2014, dev.menges.jonas@gmail.com, 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 "u8g.h" 38 | 39 | 40 | #define WIDTH 240 41 | #define HEIGHT 128 42 | #define PAGE_HEIGHT 8 43 | 44 | 45 | static const uint8_t u8g_dev_uc1611_dogxl240_init_seq[] PROGMEM = { 46 | U8G_ESC_CS(0), /* disable chip */ 47 | U8G_ESC_ADR(0), /* instruction mode */ 48 | U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */ 49 | U8G_ESC_DLY(200), 50 | U8G_ESC_CS(1), // enable chip 51 | U8G_ESC_ADR(0), // instruction mode 52 | 53 | 0xe2, // system reset 54 | U8G_ESC_DLY(1), 55 | 0x2f, // enable internal charge pump 56 | 57 | 0xF1, // set last COM electrode 58 | 0x7F, // DOGXL240 59 | 0xF2, // set display start line 60 | 0x00, // 0 61 | 0xF3, // set display end line 62 | 0x7F, // DOGXL240 63 | 0x81, // set contrast (0-255) 64 | 0xAA, // DOGXL240 65 | 0xC0, // set view 66 | //0x04, // topview 67 | 0x02, // bottomview 68 | 0xA3, // set line rate (9.4k) 69 | 0xE9, // set bias ratio (10) 70 | 0xA9, // enable display 71 | 0xD1, // set black and white mode 72 | U8G_ESC_CS(0), // disable chip 73 | U8G_ESC_END // end of sequence 74 | }; 75 | 76 | static void u8g_dev_dogxl240_set_page(u8g_t *u8g, u8g_dev_t *dev, unsigned char page) 77 | { 78 | u8g_WriteByte(u8g, dev, 0x70); 79 | u8g_WriteByte(u8g, dev, 0x60 + (page&0x0F)); 80 | } 81 | 82 | static const uint8_t u8g_dev_uc1611_dogxl240_data_start[] PROGMEM = { 83 | U8G_ESC_ADR(0), /* instruction mode */ 84 | U8G_ESC_CS(1), /* enable chip */ 85 | 0x10, /* set upper 4 bit of the col adr to 0 */ 86 | 0x00, /* set lower 4 bit of the col adr to 0 */ 87 | U8G_ESC_END /* end of sequence */ 88 | }; 89 | 90 | static uint8_t u8g_dev_uc1611_dogxl240_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 91 | { 92 | switch(msg) 93 | { 94 | case U8G_DEV_MSG_INIT: 95 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS); 96 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogxl240_init_seq); 97 | break; 98 | case U8G_DEV_MSG_STOP: 99 | break; 100 | case U8G_DEV_MSG_PAGE_NEXT: 101 | { 102 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 103 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogxl240_data_start); 104 | u8g_dev_dogxl240_set_page(u8g, dev, pb->p.page); /* select current page (uc1611) */ 105 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 106 | if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 ) 107 | return 0; 108 | u8g_SetChipSelect(u8g, dev, 0); 109 | } 110 | break; 111 | case U8G_DEV_MSG_CONTRAST: 112 | u8g_SetChipSelect(u8g, dev, 1); 113 | u8g_SetAddress(u8g, dev, 0); /* instruction mode */ 114 | u8g_WriteByte(u8g, dev, 0x81); 115 | /* 11 Jul 2015: bugfix, github issue 339 */ 116 | u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) ); /* set contrast from, keep gain at 0 */ 117 | u8g_SetChipSelect(u8g, dev, 0); 118 | return 1; 119 | } 120 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 121 | } 122 | 123 | U8G_PB_DEV(u8g_dev_uc1611_dogxl240_i2c , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogxl240_fn, U8G_COM_UC_I2C); 124 | U8G_PB_DEV(u8g_dev_uc1611_dogxl240_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogxl240_fn, U8G_COM_SW_SPI); 125 | U8G_PB_DEV(u8g_dev_uc1611_dogxl240_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogxl240_fn, U8G_COM_HW_SPI); 126 | U8G_PB_DEV(u8g_dev_uc1611_dogxl240_8bit , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogxl240_fn, U8G_COM_FAST_PARALLEL); 127 | 128 | -------------------------------------------------------------------------------- /src/clib/u8g_pb.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_pb.c 4 | 5 | common procedures for the page buffer 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, 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 "u8g.h" 40 | 41 | void u8g_pb_Clear(u8g_pb_t *b) 42 | { 43 | uint8_t *ptr = (uint8_t *)b->buf; 44 | uint8_t *end_ptr = ptr; 45 | end_ptr += b->width; 46 | do 47 | { 48 | *ptr++ = 0; 49 | } while( ptr != end_ptr ); 50 | } 51 | 52 | /* the following procedure does not work. why? Can be checked with descpic */ 53 | /* 54 | void u8g_pb_Clear(u8g_pb_t *b) 55 | { 56 | uint8_t *ptr = (uint8_t *)b->buf; 57 | uint8_t cnt = b->width; 58 | do 59 | { 60 | *ptr++ = 0; 61 | cnt--; 62 | } while( cnt != 0 ); 63 | } 64 | */ 65 | 66 | /* 67 | intersection assumptions: 68 | a1 <= a2 is always true 69 | */ 70 | /* 71 | minimized version 72 | ---1----0 1 b1 <= a2 && b1 > b2 73 | -----1--0 1 b2 >= a1 && b1 > b2 74 | ---1-1--- 1 b1 <= a2 && b2 >= a1 75 | */ 76 | /* 77 | uint8_t u8g_pb8v1_IsYIntersection___Old(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1) 78 | { 79 | uint8_t c0, c1, c; 80 | c0 = v0 <= b->p.page_y1; 81 | c1 = v1 >= b->p.page_y0; 82 | c = v0 > v1; 83 | if ( c0 && c1 ) return 1; 84 | if ( c0 && c ) return 1; 85 | if ( c1 && c ) return 1; 86 | return 0; 87 | } 88 | */ 89 | 90 | uint8_t u8g_pb_IsYIntersection(u8g_pb_t *pb, u8g_uint_t v0, u8g_uint_t v1) 91 | { 92 | uint8_t c1, c2, c3, tmp; 93 | c1 = v0 <= pb->p.page_y1; 94 | c2 = v1 >= pb->p.page_y0; 95 | c3 = v0 > v1; 96 | /* 97 | if ( c1 && c2 ) 98 | return 1; 99 | if ( c1 && c3 ) 100 | return 1; 101 | if ( c2 && c3 ) 102 | return 1; 103 | return 0; 104 | */ 105 | 106 | tmp = c1; 107 | c1 &= c2; 108 | c2 &= c3; 109 | c3 &= tmp; 110 | c1 |= c2; 111 | c1 |= c3; 112 | return c1 & 1; 113 | } 114 | 115 | 116 | uint8_t u8g_pb_IsXIntersection(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1) 117 | { 118 | uint8_t /*c0, c1, */ c2, c3; 119 | /* 120 | conditions: b->p.page_y0 < b->p.page_y1 121 | there are no restriction on v0 and v1. If v0 > v1, then warp around unsigned is assumed 122 | */ 123 | /* 124 | c0 = v0 < 0; 125 | c1 = v1 < 0; 126 | */ 127 | c2 = v0 > b->width; 128 | c3 = v1 > b->width; 129 | /*if ( c0 && c1 ) return 0;*/ 130 | if ( c2 && c3 ) return 0; 131 | /*if ( c1 && c2 ) return 0;*/ 132 | return 1; 133 | } 134 | 135 | uint8_t u8g_pb_IsIntersection(u8g_pb_t *pb, u8g_dev_arg_bbx_t *bbx) 136 | { 137 | u8g_uint_t tmp; 138 | 139 | tmp = bbx->y; 140 | tmp += bbx->h; 141 | tmp--; 142 | 143 | if ( u8g_pb_IsYIntersection(pb, bbx->y, tmp) == 0 ) 144 | return 0; 145 | 146 | /* maybe this one can be skiped... probability is very high to have an intersection, so it would be ok to always return 1 */ 147 | tmp = bbx->x; 148 | tmp += bbx->w; 149 | tmp--; 150 | 151 | return u8g_pb_IsXIntersection(pb, bbx->x, tmp); 152 | } 153 | 154 | void u8g_pb_GetPageBox(u8g_pb_t *pb, u8g_box_t *box) 155 | { 156 | box->x0 = 0; 157 | box->y0 = pb->p.page_y0; 158 | box->x1 = pb->width; 159 | box->x1--; 160 | box->y1 = pb->p.page_y1; 161 | } 162 | 163 | 164 | uint8_t u8g_pb_Is8PixelVisible(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 165 | { 166 | u8g_uint_t v0, v1; 167 | v0 = arg_pixel->y; 168 | v1 = v0; 169 | switch( arg_pixel->dir ) 170 | { 171 | case 0: 172 | break; 173 | case 1: 174 | v1 += 8; /* this is independent from the page height */ 175 | break; 176 | case 2: 177 | break; 178 | case 3: 179 | v0 -= 8; 180 | break; 181 | } 182 | return u8g_pb_IsYIntersection(b, v0, v1); 183 | } 184 | 185 | 186 | 187 | uint8_t u8g_pb_WriteBuffer(u8g_pb_t *b, u8g_t *u8g, u8g_dev_t *dev) 188 | { 189 | return u8g_WriteSequence(u8g, dev, b->width, b->buf); 190 | } 191 | 192 | -------------------------------------------------------------------------------- /src/clib/u8g_com_api.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_api.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, 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 "u8g.h" 38 | 39 | uint8_t u8g_InitCom(u8g_t *u8g, u8g_dev_t *dev, uint8_t clk_cycle_time) 40 | { 41 | return dev->com_fn(u8g, U8G_COM_MSG_INIT, clk_cycle_time, NULL); 42 | } 43 | 44 | void u8g_StopCom(u8g_t *u8g, u8g_dev_t *dev) 45 | { 46 | dev->com_fn(u8g, U8G_COM_MSG_STOP, 0, NULL); 47 | } 48 | 49 | /* cs contains the chip number, which should be enabled */ 50 | void u8g_SetChipSelect(u8g_t *u8g, u8g_dev_t *dev, uint8_t cs) 51 | { 52 | dev->com_fn(u8g, U8G_COM_MSG_CHIP_SELECT, cs, NULL); 53 | } 54 | 55 | void u8g_SetResetLow(u8g_t *u8g, u8g_dev_t *dev) 56 | { 57 | dev->com_fn(u8g, U8G_COM_MSG_RESET, 0, NULL); 58 | } 59 | 60 | void u8g_SetResetHigh(u8g_t *u8g, u8g_dev_t *dev) 61 | { 62 | dev->com_fn(u8g, U8G_COM_MSG_RESET, 1, NULL); 63 | } 64 | 65 | 66 | void u8g_SetAddress(u8g_t *u8g, u8g_dev_t *dev, uint8_t address) 67 | { 68 | dev->com_fn(u8g, U8G_COM_MSG_ADDRESS, address, NULL); 69 | } 70 | 71 | uint8_t u8g_WriteByte(u8g_t *u8g, u8g_dev_t *dev, uint8_t val) 72 | { 73 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, val, NULL); 74 | } 75 | 76 | uint8_t u8g_WriteSequence(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *seq) 77 | { 78 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ, cnt, seq); 79 | } 80 | 81 | uint8_t u8g_WriteSequenceP(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, const uint8_t *seq) 82 | { 83 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ_P, cnt, (void *)seq); 84 | } 85 | 86 | /* 87 | sequence := { direct_value | escape_sequence } 88 | direct_value := 0..254 89 | escape_sequence := value_255 | sequence_end | delay | adr | cs | not_used 90 | value_255 := 255 255 91 | sequence_end = 255 254 92 | delay := 255 0..127 93 | adr := 255 0x0e0 .. 0x0ef 94 | cs := 255 0x0d0 .. 0x0df 95 | not_used := 255 101..254 96 | 97 | #define U8G_ESC_DLY(x) 255, ((x) & 0x7f) 98 | #define U8G_ESC_CS(x) 255, (0xd0 | ((x)&0x0f)) 99 | #define U8G_ESC_ADR(x) 255, (0xe0 | ((x)&0x0f)) 100 | #define U8G_ESC_VCC(x) 255, (0xbe | ((x)&0x01)) 101 | #define U8G_ESC_END 255, 254 102 | #define U8G_ESC_255 255, 255 103 | #define U8G_ESC_RST(x) 255, (0xc0 | ((x)&0x0f)) 104 | 105 | */ 106 | uint8_t u8g_WriteEscSeqP(u8g_t *u8g, u8g_dev_t *dev, const uint8_t *esc_seq) 107 | { 108 | uint8_t is_escape = 0; 109 | uint8_t value; 110 | for(;;) 111 | { 112 | value = u8g_pgm_read(esc_seq); 113 | if ( is_escape == 0 ) 114 | { 115 | if ( value != 255 ) 116 | { 117 | if ( u8g_WriteByte(u8g, dev, value) == 0 ) 118 | return 0; 119 | } 120 | else 121 | { 122 | is_escape = 1; 123 | } 124 | } 125 | else 126 | { 127 | if ( value == 255 ) 128 | { 129 | if ( u8g_WriteByte(u8g, dev, value) == 0 ) 130 | return 0; 131 | } 132 | else if ( value == 254 ) 133 | { 134 | break; 135 | } 136 | else if ( value >= 0x0f0 ) 137 | { 138 | /* not yet used, do nothing */ 139 | } 140 | else if ( value >= 0xe0 ) 141 | { 142 | u8g_SetAddress(u8g, dev, value & 0x0f); 143 | } 144 | else if ( value >= 0xd0 ) 145 | { 146 | u8g_SetChipSelect(u8g, dev, value & 0x0f); 147 | } 148 | else if ( value >= 0xc0 ) 149 | { 150 | u8g_SetResetLow(u8g, dev); 151 | value &= 0x0f; 152 | value <<= 4; 153 | value+=2; 154 | u8g_Delay(value); 155 | u8g_SetResetHigh(u8g, dev); 156 | u8g_Delay(value); 157 | } 158 | else if ( value >= 0xbe ) 159 | { 160 | /* not yet implemented */ 161 | /* u8g_SetVCC(u8g, dev, value & 0x01); */ 162 | } 163 | else if ( value <= 127 ) 164 | { 165 | u8g_Delay(value); 166 | } 167 | is_escape = 0; 168 | } 169 | esc_seq++; 170 | } 171 | return 1; 172 | } 173 | 174 | -------------------------------------------------------------------------------- /src/clib/u8g_com_atmega_hw_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_atmega_hw_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2012, 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 | Assumes, that 36 | MOSI is at PORTB, Pin 3 37 | and 38 | SCK is at PORTB, Pin 5 39 | 40 | Update for ATOMIC operation done (01 Jun 2013) 41 | U8G_ATOMIC_OR(ptr, val) 42 | U8G_ATOMIC_AND(ptr, val) 43 | U8G_ATOMIC_START() 44 | U8G_ATOMIC_END() 45 | 46 | 47 | 48 | */ 49 | 50 | #include "u8g.h" 51 | 52 | #if defined(__AVR_XMEGA__) 53 | #elif defined(__AVR__) 54 | #define U8G_ATMEGA_HW_SPI 55 | 56 | /* remove the definition for attiny */ 57 | #if __AVR_ARCH__ == 2 58 | #undef U8G_ATMEGA_HW_SPI 59 | #endif 60 | #if __AVR_ARCH__ == 25 61 | #undef U8G_ATMEGA_HW_SPI 62 | #endif 63 | #endif 64 | 65 | 66 | #if defined(U8G_ATMEGA_HW_SPI) 67 | 68 | #include 69 | #include 70 | 71 | 72 | static uint8_t u8g_atmega_spi_out(uint8_t data) 73 | { 74 | /* unsigned char x = 100; */ 75 | /* send data */ 76 | SPDR = data; 77 | /* wait for transmission */ 78 | while (!(SPSR & (1< 0 ) 158 | { 159 | u8g_atmega_spi_out(*ptr++); 160 | arg_val--; 161 | } 162 | } 163 | break; 164 | case U8G_COM_MSG_WRITE_SEQ_P: 165 | { 166 | register uint8_t *ptr = arg_ptr; 167 | while( arg_val > 0 ) 168 | { 169 | u8g_atmega_spi_out(u8g_pgm_read(ptr)); 170 | ptr++; 171 | arg_val--; 172 | } 173 | } 174 | break; 175 | } 176 | return 1; 177 | } 178 | 179 | #else 180 | 181 | uint8_t u8g_com_atmega_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 182 | { 183 | return 1; 184 | } 185 | 186 | #endif 187 | 188 | 189 | -------------------------------------------------------------------------------- /src/clib/u8g_com_arduino_attiny85_hw_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_arduino_ATtiny85_std_hw_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, 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 | // Uses code from tinySPI Written by Nick Gammon 37 | // March 2013 38 | 39 | // ATMEL ATTINY45 / ARDUINO pin mappings 40 | // 41 | // +-\/-+ 42 | // RESET Ain0 (D 5) PB5 1| |8 Vcc 43 | // CLK1 Ain3 (D 3) PB3 2| |7 PB2 (D 2) Ain1 SCK / USCK / SCL 44 | // CLK0 Ain2 (D 4) PB4 3| |6 PB1 (D 1) pwm1 MISO / DO 45 | // GND 4| |5 PB0 (D 0) pwm0 MOSI / DI / SDA 46 | // +----+ 47 | 48 | 49 | #include "u8g.h" 50 | 51 | 52 | #if defined(ARDUINO) && defined(__AVR_ATtiny85__) 53 | 54 | #if ARDUINO < 100 55 | #include 56 | #else 57 | #include 58 | #endif 59 | 60 | const byte DI = 0; // D0, pin 5 Data In 61 | const byte DO = 1; // D1, pin 6 Data Out (this is *not* MOSI) 62 | const byte USCK = 2; // D2, pin 7 Universal Serial Interface clock 63 | 64 | uint8_t u8g_arduino_ATtiny85_spi_out(uint8_t val) 65 | { 66 | USIDR = val; // byte to output 67 | USISR = _BV (USIOIF); // clear Counter Overflow Interrupt Flag, set count to zero 68 | do 69 | { 70 | USICR = _BV (USIWM0) // 3-wire mode 71 | | _BV (USICS1) | _BV (USICLK) // Software clock strobe 72 | | _BV (USITC); // Toggle Clock Port Pin 73 | } 74 | while ((USISR & _BV (USIOIF)) == 0); // until Counter Overflow Interrupt Flag set 75 | 76 | return USIDR; // return read data 77 | } 78 | 79 | uint8_t u8g_com_arduino_ATtiny85_std_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 80 | { 81 | switch(msg) 82 | { 83 | case U8G_COM_MSG_INIT: 84 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); // ensure SS stays high until needed 85 | pinMode (USCK, OUTPUT); 86 | pinMode (DO, OUTPUT); 87 | pinMode (u8g->pin_list[U8G_PI_CS], OUTPUT); 88 | pinMode (u8g->pin_list[U8G_PI_A0], OUTPUT); 89 | USICR = _BV (USIWM0); // 3-wire mode 90 | u8g_MicroDelay(); 91 | break; 92 | 93 | case U8G_COM_MSG_STOP: 94 | break; 95 | 96 | case U8G_COM_MSG_RESET: 97 | if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE ) 98 | u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); 99 | break; 100 | 101 | case U8G_COM_MSG_CHIP_SELECT: 102 | if ( arg_val == 0 ) 103 | { 104 | /* disable */ 105 | u8g_MicroDelay(); 106 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); 107 | u8g_MicroDelay(); 108 | } 109 | else 110 | { 111 | /* enable */ 112 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW); 113 | u8g_MicroDelay(); 114 | } 115 | break; 116 | 117 | case U8G_COM_MSG_WRITE_BYTE: 118 | u8g_arduino_ATtiny85_spi_out(arg_val); 119 | u8g_MicroDelay(); 120 | break; 121 | 122 | case U8G_COM_MSG_WRITE_SEQ: 123 | { 124 | register uint8_t *ptr = arg_ptr; 125 | while( arg_val > 0 ) 126 | { 127 | u8g_arduino_ATtiny85_spi_out(*ptr++); 128 | arg_val--; 129 | } 130 | } 131 | break; 132 | 133 | case U8G_COM_MSG_WRITE_SEQ_P: 134 | { 135 | register uint8_t *ptr = arg_ptr; 136 | while( arg_val > 0 ) 137 | { 138 | u8g_arduino_ATtiny85_spi_out(u8g_pgm_read(ptr)); 139 | ptr++; 140 | arg_val--; 141 | } 142 | } 143 | break; 144 | 145 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 146 | u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val); 147 | u8g_MicroDelay(); 148 | break; 149 | } 150 | return 1; 151 | } 152 | 153 | #else /* ARDUINO */ 154 | 155 | uint8_t u8g_com_arduino_ATtiny85_std_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 156 | { 157 | return 1; 158 | } 159 | 160 | #endif /* ARDUINO */ -------------------------------------------------------------------------------- /src/clib/u8g_pbxh16.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_pbxh16.c 4 | 5 | x lines per page, horizontal, 16 bits per pixel (hi color modes) 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2013, 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 | struct _u8g_pb_t 38 | { 39 | u8g_page_t p; 40 | u8g_uint_t width; 41 | void *buf; 42 | }; 43 | typedef struct _u8g_pb_t u8g_pb_t; 44 | 45 | 46 | uint8_t u8g_index_color_xh16_buf[2*WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ; 47 | u8g_pb_t u8g_index_color_xh16_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_index_color_xh16_buf}; 48 | u8g_dev_t name = { dev_fn, &u8g_index_color_xh16_pb , com_fn } 49 | 50 | */ 51 | 52 | #include "u8g.h" 53 | 54 | /* 55 | #define WIDTH_BITS 7 56 | #define WIDTH (1<buf; 64 | uint8_t *end_ptr = ptr; 65 | uint8_t cnt = b->p.page_height; 66 | do 67 | { 68 | end_ptr += b->width*2; 69 | cnt--; 70 | } while( cnt > 0 ); 71 | do 72 | { 73 | *ptr++ = 0; 74 | } while( ptr != end_ptr ); 75 | } 76 | 77 | 78 | void u8g_pbxh16_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) 79 | { 80 | b->buf = buf; 81 | b->width = width; 82 | u8g_pbxh16_Clear(b); 83 | } 84 | 85 | static void u8g_pbxh16_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t low, uint8_t high) 86 | { 87 | uint16_t tmp; 88 | uint8_t *ptr = b->buf; 89 | y -= b->p.page_y0; 90 | tmp = y; 91 | tmp *= b->width; 92 | tmp += x; 93 | tmp <<= 1; 94 | ptr += tmp; 95 | *ptr = low; 96 | ptr++; 97 | *ptr = high; 98 | } 99 | 100 | void u8g_pbxh16_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) 101 | { 102 | if ( arg_pixel->y < b->p.page_y0 ) 103 | return; 104 | if ( arg_pixel->y > b->p.page_y1 ) 105 | return; 106 | if ( arg_pixel->x >= b->width ) 107 | return; 108 | u8g_pbxh16_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color, arg_pixel->hi_color); 109 | } 110 | 111 | 112 | void u8g_pbxh16_Set8Pixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 113 | { 114 | register uint8_t pixel = arg_pixel->pixel; 115 | u8g_uint_t dx = 0; 116 | u8g_uint_t dy = 0; 117 | 118 | switch( arg_pixel->dir ) 119 | { 120 | case 0: dx++; break; 121 | case 1: dy++; break; 122 | case 2: dx--; break; 123 | case 3: dy--; break; 124 | } 125 | 126 | do 127 | { 128 | if ( pixel & 128 ) 129 | u8g_pbxh16_SetPixel(b, arg_pixel); 130 | arg_pixel->x += dx; 131 | arg_pixel->y += dy; 132 | pixel <<= 1; 133 | } while( pixel != 0 ); 134 | } 135 | 136 | 137 | uint8_t u8g_dev_pbxh16_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 138 | { 139 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 140 | switch(msg) 141 | { 142 | case U8G_DEV_MSG_SET_8PIXEL: 143 | if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) 144 | u8g_pbxh16_Set8Pixel(pb, (u8g_dev_arg_pixel_t *)arg); 145 | break; 146 | case U8G_DEV_MSG_SET_PIXEL: 147 | u8g_pbxh16_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 148 | break; 149 | case U8G_DEV_MSG_INIT: 150 | break; 151 | case U8G_DEV_MSG_STOP: 152 | break; 153 | case U8G_DEV_MSG_PAGE_FIRST: 154 | u8g_pbxh16_Clear(pb); 155 | u8g_page_First(&(pb->p)); 156 | break; 157 | case U8G_DEV_MSG_PAGE_NEXT: 158 | if ( u8g_page_Next(&(pb->p)) == 0 ) 159 | return 0; 160 | u8g_pbxh16_Clear(pb); 161 | break; 162 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 163 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 164 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 165 | #endif 166 | case U8G_DEV_MSG_GET_PAGE_BOX: 167 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 168 | break; 169 | case U8G_DEV_MSG_GET_WIDTH: 170 | *((u8g_uint_t *)arg) = pb->width; 171 | break; 172 | case U8G_DEV_MSG_GET_HEIGHT: 173 | *((u8g_uint_t *)arg) = pb->p.total_height; 174 | break; 175 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 176 | break; 177 | case U8G_DEV_MSG_SET_XY_CB: 178 | break; 179 | case U8G_DEV_MSG_GET_MODE: 180 | return U8G_MODE_HICOLOR; 181 | } 182 | return 1; 183 | } 184 | 185 | -------------------------------------------------------------------------------- /src/clib/u8g_com_atmega_st7920_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_atmega_st7920_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, 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 | A special SPI interface for ST7920 controller 35 | 36 | */ 37 | 38 | #include "u8g.h" 39 | 40 | #if defined(__AVR__) 41 | 42 | static void u8g_atmega_st7920_sw_spi_shift_out(u8g_t *u8g, uint8_t val) U8G_NOINLINE; 43 | static void u8g_atmega_st7920_sw_spi_shift_out(u8g_t *u8g, uint8_t val) 44 | { 45 | uint8_t i = 8; 46 | do 47 | { 48 | u8g_SetPILevel(u8g, U8G_PI_MOSI, val & 128 ); 49 | val <<= 1; 50 | u8g_SetPILevel(u8g, U8G_PI_SCK, 1 ); 51 | u8g_MicroDelay(); /* 15 Aug 2012: added for high speed uC */ 52 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 53 | u8g_MicroDelay(); /* 15 Aug 2012: added for high speed uC */ 54 | i--; 55 | } while( i != 0 ); 56 | } 57 | 58 | static void u8g_com_atmega_st7920_write_byte(u8g_t *u8g, uint8_t rs, uint8_t val) U8G_NOINLINE; 59 | static void u8g_com_atmega_st7920_write_byte(u8g_t *u8g, uint8_t rs, uint8_t val) 60 | { 61 | uint8_t i; 62 | 63 | if ( rs == 0 ) 64 | { 65 | /* command */ 66 | u8g_atmega_st7920_sw_spi_shift_out(u8g, 0x0f8); 67 | } 68 | else if ( rs == 1 ) 69 | { 70 | /* data */ 71 | u8g_atmega_st7920_sw_spi_shift_out(u8g, 0x0fa); 72 | } 73 | 74 | u8g_atmega_st7920_sw_spi_shift_out(u8g, val & 0x0f0); 75 | u8g_atmega_st7920_sw_spi_shift_out(u8g, val << 4); 76 | 77 | for( i = 0; i < 4; i++ ) 78 | u8g_10MicroDelay(); 79 | } 80 | 81 | 82 | uint8_t u8g_com_atmega_st7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 83 | { 84 | switch(msg) 85 | { 86 | case U8G_COM_MSG_INIT: 87 | u8g_SetPIOutput(u8g, U8G_PI_SCK); 88 | u8g_SetPIOutput(u8g, U8G_PI_MOSI); 89 | /* u8g_SetPIOutput(u8g, U8G_PI_A0); */ 90 | u8g_SetPIOutput(u8g, U8G_PI_CS); 91 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 92 | 93 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 94 | u8g_SetPILevel(u8g, U8G_PI_MOSI, 0 ); 95 | u8g_SetPILevel(u8g, U8G_PI_CS, 0 ); 96 | /* u8g_SetPILevel(u8g, U8G_PI_A0, 0); */ 97 | 98 | u8g->pin_list[U8G_PI_A0_STATE] = 0; /* inital RS state: command mode */ 99 | break; 100 | 101 | case U8G_COM_MSG_STOP: 102 | break; 103 | 104 | case U8G_COM_MSG_RESET: 105 | u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 106 | break; 107 | 108 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 109 | u8g->pin_list[U8G_PI_A0_STATE] = arg_val; 110 | break; 111 | 112 | case U8G_COM_MSG_CHIP_SELECT: 113 | if ( arg_val == 0 ) 114 | { 115 | /* disable, note: the st7920 has an active high chip select */ 116 | u8g_SetPILevel(u8g, U8G_PI_CS, 0); 117 | } 118 | else 119 | { 120 | /* u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); */ 121 | /* enable */ 122 | u8g_SetPILevel(u8g, U8G_PI_CS, 1); /* CS = 1 (high active) */ 123 | } 124 | break; 125 | 126 | 127 | case U8G_COM_MSG_WRITE_BYTE: 128 | u8g_com_atmega_st7920_write_byte(u8g, u8g->pin_list[U8G_PI_A0_STATE], arg_val); 129 | u8g->pin_list[U8G_PI_A0_STATE] = 2; 130 | break; 131 | 132 | case U8G_COM_MSG_WRITE_SEQ: 133 | { 134 | register uint8_t *ptr = arg_ptr; 135 | while( arg_val > 0 ) 136 | { 137 | u8g_com_atmega_st7920_write_byte(u8g, u8g->pin_list[U8G_PI_A0_STATE], *ptr++); 138 | u8g->pin_list[U8G_PI_A0_STATE] = 2; 139 | arg_val--; 140 | } 141 | } 142 | break; 143 | 144 | case U8G_COM_MSG_WRITE_SEQ_P: 145 | { 146 | register uint8_t *ptr = arg_ptr; 147 | while( arg_val > 0 ) 148 | { 149 | u8g_com_atmega_st7920_write_byte(u8g, u8g->pin_list[U8G_PI_A0_STATE], u8g_pgm_read(ptr)); 150 | u8g->pin_list[U8G_PI_A0_STATE] = 2; 151 | ptr++; 152 | arg_val--; 153 | } 154 | } 155 | break; 156 | } 157 | return 1; 158 | } 159 | 160 | #else 161 | 162 | 163 | uint8_t u8g_com_atmega_st7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 164 | { 165 | return 1; 166 | } 167 | 168 | 169 | #endif 170 | 171 | -------------------------------------------------------------------------------- /src/clib/u8g_pb8h8.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_pb8h8.c 4 | 5 | 8 lines per page, horizontal, 8 bits per pixel 6 | (22 May 2013: might also support any number of lines --> needs to be checked) 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2012, 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 | struct _u8g_pb_t 39 | { 40 | u8g_page_t p; 41 | u8g_uint_t width; 42 | void *buf; 43 | }; 44 | typedef struct _u8g_pb_t u8g_pb_t; 45 | 46 | 47 | uint8_t u8g_index_color_8h8_buf[WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ; 48 | u8g_pb_t u8g_index_color_8h8_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_index_color_8h8_buff}; 49 | u8g_dev_t name = { dev_fn, &u8g_index_color_8h8_pb, com_fn } 50 | 51 | */ 52 | 53 | #include "u8g.h" 54 | 55 | /* 56 | #define WIDTH_BITS 7 57 | #define WIDTH (1<buf; 65 | uint8_t *end_ptr = ptr; 66 | uint8_t cnt = b->p.page_height; 67 | end_ptr += b->width*cnt; 68 | /* 69 | do 70 | { 71 | end_ptr += b->width; 72 | cnt--; 73 | } while( cnt > 0 ); 74 | */ 75 | do 76 | { 77 | *ptr++ = 0; 78 | } while( ptr != end_ptr ); 79 | } 80 | 81 | 82 | void u8g_pb8h8_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) 83 | { 84 | b->buf = buf; 85 | b->width = width; 86 | u8g_pb8h8_Clear(b); 87 | } 88 | 89 | static void u8g_pb8h8_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) 90 | { 91 | uint16_t tmp; 92 | uint8_t *ptr = b->buf; 93 | y -= b->p.page_y0; 94 | tmp = y; 95 | tmp *= b->width; 96 | tmp += x; 97 | ptr += tmp; 98 | *ptr = color_index; 99 | } 100 | 101 | void u8g_pb8h8_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) 102 | { 103 | if ( arg_pixel->y < b->p.page_y0 ) 104 | return; 105 | if ( arg_pixel->y > b->p.page_y1 ) 106 | return; 107 | if ( arg_pixel->x >= b->width ) 108 | return; 109 | u8g_pb8h8_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 110 | } 111 | 112 | 113 | void u8g_pb8h8_Set8Pixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 114 | { 115 | register uint8_t pixel = arg_pixel->pixel; 116 | u8g_uint_t dx = 0; 117 | u8g_uint_t dy = 0; 118 | 119 | switch( arg_pixel->dir ) 120 | { 121 | case 0: dx++; break; 122 | case 1: dy++; break; 123 | case 2: dx--; break; 124 | case 3: dy--; break; 125 | } 126 | 127 | do 128 | { 129 | if ( pixel & 128 ) 130 | u8g_pb8h8_SetPixel(b, arg_pixel); 131 | arg_pixel->x += dx; 132 | arg_pixel->y += dy; 133 | pixel <<= 1; 134 | } while( pixel != 0 ); 135 | } 136 | 137 | 138 | uint8_t u8g_dev_pb8h8_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 139 | { 140 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 141 | switch(msg) 142 | { 143 | case U8G_DEV_MSG_SET_8PIXEL: 144 | if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) 145 | u8g_pb8h8_Set8Pixel(pb, (u8g_dev_arg_pixel_t *)arg); 146 | break; 147 | case U8G_DEV_MSG_SET_PIXEL: 148 | u8g_pb8h8_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 149 | break; 150 | case U8G_DEV_MSG_INIT: 151 | break; 152 | case U8G_DEV_MSG_STOP: 153 | break; 154 | case U8G_DEV_MSG_PAGE_FIRST: 155 | u8g_pb8h8_Clear(pb); 156 | u8g_page_First(&(pb->p)); 157 | break; 158 | case U8G_DEV_MSG_PAGE_NEXT: 159 | if ( u8g_page_Next(&(pb->p)) == 0 ) 160 | return 0; 161 | u8g_pb8h8_Clear(pb); 162 | break; 163 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 164 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 165 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 166 | #endif 167 | case U8G_DEV_MSG_GET_PAGE_BOX: 168 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 169 | break; 170 | case U8G_DEV_MSG_GET_WIDTH: 171 | *((u8g_uint_t *)arg) = pb->width; 172 | break; 173 | case U8G_DEV_MSG_GET_HEIGHT: 174 | *((u8g_uint_t *)arg) = pb->p.total_height; 175 | break; 176 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 177 | break; 178 | case U8G_DEV_MSG_SET_XY_CB: 179 | break; 180 | case U8G_DEV_MSG_GET_MODE: 181 | return U8G_MODE_R3G3B2; 182 | } 183 | return 1; 184 | } 185 | 186 | -------------------------------------------------------------------------------- /src/clib/u8g_pb8v1.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_pb8v1.c 4 | 5 | 8bit height monochrom (1 bit) page buffer 6 | byte has vertical orientation 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2011, 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 "u8g.h" 41 | #include 42 | 43 | 44 | void u8g_pb8v1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) U8G_NOINLINE; 45 | void u8g_pb8v1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE; 46 | void u8g_pb8v1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) U8G_NOINLINE ; 47 | void u8g_pb8v1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) U8G_NOINLINE; 48 | 49 | /* Obsolete, usually set by the init of the structure */ 50 | void u8g_pb8v1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) 51 | { 52 | b->buf = buf; 53 | b->width = width; 54 | u8g_pb_Clear(b); 55 | } 56 | 57 | void u8g_pb8v1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) 58 | { 59 | register uint8_t mask; 60 | uint8_t *ptr = b->buf; 61 | 62 | y -= b->p.page_y0; 63 | mask = 1; 64 | y &= 0x07; 65 | mask <<= y; 66 | ptr += x; 67 | if ( color_index ) 68 | { 69 | *ptr |= mask; 70 | } 71 | else 72 | { 73 | mask ^=0xff; 74 | *ptr &= mask; 75 | } 76 | } 77 | 78 | 79 | void u8g_pb8v1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) 80 | { 81 | if ( arg_pixel->y < b->p.page_y0 ) 82 | return; 83 | if ( arg_pixel->y > b->p.page_y1 ) 84 | return; 85 | if ( arg_pixel->x >= b->width ) 86 | return; 87 | u8g_pb8v1_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 88 | } 89 | 90 | void u8g_pb8v1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 91 | { 92 | register uint8_t pixel = arg_pixel->pixel; 93 | do 94 | { 95 | if ( pixel & 128 ) 96 | { 97 | u8g_pb8v1_SetPixel(b, arg_pixel); 98 | } 99 | switch( arg_pixel->dir ) 100 | { 101 | case 0: arg_pixel->x++; break; 102 | case 1: arg_pixel->y++; break; 103 | case 2: arg_pixel->x--; break; 104 | case 3: arg_pixel->y--; break; 105 | } 106 | pixel <<= 1; 107 | } while( pixel != 0 ); 108 | } 109 | 110 | 111 | void u8g_pb8v1_Set8PixelOpt2(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 112 | { 113 | register uint8_t pixel = arg_pixel->pixel; 114 | u8g_uint_t dx = 0; 115 | u8g_uint_t dy = 0; 116 | 117 | switch( arg_pixel->dir ) 118 | { 119 | case 0: dx++; break; 120 | case 1: dy++; break; 121 | case 2: dx--; break; 122 | case 3: dy--; break; 123 | } 124 | 125 | do 126 | { 127 | if ( pixel & 128 ) 128 | u8g_pb8v1_SetPixel(b, arg_pixel); 129 | arg_pixel->x += dx; 130 | arg_pixel->y += dy; 131 | pixel <<= 1; 132 | } while( pixel != 0 ); 133 | 134 | } 135 | 136 | uint8_t u8g_dev_pb8v1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 137 | { 138 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 139 | switch(msg) 140 | { 141 | case U8G_DEV_MSG_SET_8PIXEL: 142 | if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) 143 | u8g_pb8v1_Set8PixelOpt2(pb, (u8g_dev_arg_pixel_t *)arg); 144 | break; 145 | case U8G_DEV_MSG_SET_PIXEL: 146 | u8g_pb8v1_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 147 | break; 148 | case U8G_DEV_MSG_INIT: 149 | break; 150 | case U8G_DEV_MSG_STOP: 151 | break; 152 | case U8G_DEV_MSG_PAGE_FIRST: 153 | u8g_pb_Clear(pb); 154 | u8g_page_First(&(pb->p)); 155 | break; 156 | case U8G_DEV_MSG_PAGE_NEXT: 157 | if ( u8g_page_Next(&(pb->p)) == 0 ) 158 | return 0; 159 | u8g_pb_Clear(pb); 160 | break; 161 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 162 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 163 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 164 | #endif 165 | case U8G_DEV_MSG_GET_PAGE_BOX: 166 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 167 | break; 168 | case U8G_DEV_MSG_GET_WIDTH: 169 | *((u8g_uint_t *)arg) = pb->width; 170 | break; 171 | case U8G_DEV_MSG_GET_HEIGHT: 172 | *((u8g_uint_t *)arg) = pb->p.total_height; 173 | break; 174 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 175 | break; 176 | case U8G_DEV_MSG_SET_XY_CB: 177 | break; 178 | case U8G_DEV_MSG_GET_MODE: 179 | return U8G_MODE_BW; 180 | } 181 | return 1; 182 | } 183 | 184 | 185 | -------------------------------------------------------------------------------- /src/clib/u8g_com_arduino_port_d_wr.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_arduino_port_d_wr.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, 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 | Assumes PORTD for 8 bit data transfer. 36 | EN is assumed to be a low active write signal (WR) 37 | 38 | ILI9325D_320x240 from iteadstudio.com 39 | RS=19, WR=18, CS=17, RST=16 40 | 41 | 42 | u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset) 43 | u8g_Init8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16, U8G_PIN_NONE) 44 | 45 | 46 | Update for ATOMIC operation done (01 Jun 2013) 47 | U8G_ATOMIC_OR(ptr, val) 48 | U8G_ATOMIC_AND(ptr, val) 49 | U8G_ATOMIC_START(); 50 | U8G_ATOMIC_END(); 51 | 52 | */ 53 | 54 | #include "u8g.h" 55 | 56 | 57 | #if defined(ARDUINO) && defined(PORTD) 58 | 59 | #if ARDUINO < 100 60 | #include 61 | #else 62 | #include 63 | #endif 64 | 65 | 66 | 67 | 68 | 69 | 70 | static void u8g_com_arduino_port_d_8bit_wr(u8g_t *u8g, uint8_t val) 71 | { 72 | PORTD = val; 73 | 74 | /* WR cycle time must be 1 micro second, digitalWrite is slow enough to do this */ 75 | u8g_com_arduino_digital_write(u8g, U8G_PI_EN, LOW); 76 | u8g_com_arduino_digital_write(u8g, U8G_PI_EN, HIGH); 77 | } 78 | 79 | 80 | uint8_t u8g_com_arduino_port_d_wr_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 81 | { 82 | 83 | switch(msg) 84 | { 85 | case U8G_COM_MSG_INIT: 86 | 87 | #ifdef UCSR0B 88 | UCSR0B = 0; // disable USART 0 89 | #endif 90 | U8G_ATOMIC_START(); 91 | DDRD = 0x0ff; 92 | PORTD = 0x0ff; 93 | U8G_ATOMIC_END(); 94 | 95 | /* setup the RW pin as output and force it to low */ 96 | if ( u8g->pin_list[U8G_PI_RW] != U8G_PIN_NONE ) 97 | { 98 | pinMode(u8g->pin_list[U8G_PI_RW], OUTPUT); 99 | u8g_com_arduino_digital_write(u8g, U8G_PI_RW, HIGH); 100 | } 101 | /* set all pins (except RW pin) */ 102 | u8g_com_arduino_assign_pin_output_high(u8g); 103 | u8g_com_arduino_digital_write(u8g, U8G_PI_EN, HIGH); 104 | break; 105 | case U8G_COM_MSG_STOP: 106 | break; 107 | case U8G_COM_MSG_CHIP_SELECT: 108 | if ( arg_val == 0 ) 109 | { 110 | /* disable */ 111 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, HIGH); 112 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, HIGH); 113 | } 114 | else if ( arg_val == 1 ) 115 | { 116 | /* enable */ 117 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, LOW); 118 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, HIGH); 119 | } 120 | else if ( arg_val == 2 ) 121 | { 122 | /* enable */ 123 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, HIGH); 124 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, LOW); 125 | } 126 | else 127 | { 128 | /* enable */ 129 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, LOW); 130 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, LOW); 131 | } 132 | break; 133 | case U8G_COM_MSG_WRITE_BYTE: 134 | u8g_com_arduino_port_d_8bit_wr(u8g, arg_val); 135 | break; 136 | case U8G_COM_MSG_WRITE_SEQ: 137 | { 138 | register uint8_t *ptr = arg_ptr; 139 | while( arg_val > 0 ) 140 | { 141 | u8g_com_arduino_port_d_8bit_wr(u8g, *ptr++); 142 | arg_val--; 143 | } 144 | } 145 | break; 146 | case U8G_COM_MSG_WRITE_SEQ_P: 147 | { 148 | register uint8_t *ptr = arg_ptr; 149 | while( arg_val > 0 ) 150 | { 151 | u8g_com_arduino_port_d_8bit_wr(u8g, u8g_pgm_read(ptr)); 152 | ptr++; 153 | arg_val--; 154 | } 155 | } 156 | break; 157 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 158 | u8g_com_arduino_digital_write(u8g, U8G_PI_DI, arg_val); 159 | break; 160 | case U8G_COM_MSG_RESET: 161 | if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE ) 162 | u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); 163 | break; 164 | } 165 | return 1; 166 | } 167 | 168 | #else 169 | 170 | 171 | uint8_t u8g_com_arduino_port_d_wr_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 172 | { 173 | return 1; 174 | } 175 | 176 | #endif /* ARDUINO && PORTD */ 177 | 178 | -------------------------------------------------------------------------------- /src/clib/u8g_dev_lc7981_240x64.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_lc7981_240x64.c 4 | 5 | Tested with Nan Ya LM_J6_003_ 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2012, 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 "u8g.h" 40 | 41 | #define WIDTH 240 42 | #define HEIGHT 64 43 | #define PAGE_HEIGHT 8 44 | 45 | 46 | /* 47 | http://www.mark-products.com/graphics.htm#240x64%20Pixel%20Format 48 | */ 49 | 50 | static const uint8_t u8g_dev_lc7981_240x64_init_seq[] PROGMEM = { 51 | U8G_ESC_CS(0), /* disable chip */ 52 | U8G_ESC_ADR(1), /* instruction mode */ 53 | U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/ 54 | U8G_ESC_CS(1), /* enable chip */ 55 | U8G_ESC_DLY(50), /* delay 50 ms */ 56 | 57 | 58 | U8G_ESC_ADR(1), /* instruction mode */ 59 | 0x000, /* mode register */ 60 | U8G_ESC_ADR(0), /* data mode */ 61 | 0x032, /* display on (bit 5), master mode on (bit 4), graphics mode on (bit 1)*/ 62 | 63 | U8G_ESC_ADR(1), /* instruction mode */ 64 | 0x001, /* character/bits per pixel pitch */ 65 | U8G_ESC_ADR(0), /* data mode */ 66 | 0x007, /* 8 bits per pixel */ 67 | 68 | U8G_ESC_ADR(1), /* instruction mode */ 69 | 0x002, /* number of chars/byte width of the screen */ 70 | U8G_ESC_ADR(0), /* data mode */ 71 | WIDTH/8-1, /* 8 bits per pixel */ 72 | 73 | U8G_ESC_ADR(1), /* instruction mode */ 74 | 0x003, /* time division */ 75 | U8G_ESC_ADR(0), /* data mode */ 76 | 0x07f, /* */ 77 | 78 | U8G_ESC_ADR(1), /* instruction mode */ 79 | 0x008, /* display start low */ 80 | U8G_ESC_ADR(0), /* data mode */ 81 | 0x000, /* */ 82 | 83 | U8G_ESC_ADR(1), /* instruction mode */ 84 | 0x009, /* display start high */ 85 | U8G_ESC_ADR(0), /* data mode */ 86 | 0x000, /* */ 87 | 88 | U8G_ESC_DLY(10), /* delay 10 ms */ 89 | 90 | U8G_ESC_CS(0), /* disable chip */ 91 | U8G_ESC_END /* end of sequence */ 92 | }; 93 | 94 | uint8_t u8g_dev_lc7981_240x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 95 | { 96 | switch(msg) 97 | { 98 | case U8G_DEV_MSG_INIT: 99 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE); 100 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_lc7981_240x64_init_seq); 101 | break; 102 | case U8G_DEV_MSG_STOP: 103 | break; 104 | case U8G_DEV_MSG_PAGE_NEXT: 105 | { 106 | uint8_t y, i; 107 | uint16_t disp_ram_adr; 108 | uint8_t *ptr; 109 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 110 | 111 | u8g_SetAddress(u8g, dev, 1); /* cmd mode */ 112 | u8g_SetChipSelect(u8g, dev, 1); 113 | y = pb->p.page_y0; 114 | ptr = pb->buf; 115 | disp_ram_adr = WIDTH/8; 116 | disp_ram_adr *= y; 117 | for( i = 0; i < 8; i ++ ) 118 | { 119 | u8g_SetAddress(u8g, dev, 1); /* cmd mode */ 120 | u8g_WriteByte(u8g, dev, 0x00a ); /* display ram (cursor) address low byte */ 121 | u8g_SetAddress(u8g, dev, 0); /* data mode */ 122 | u8g_WriteByte(u8g, dev, disp_ram_adr & 0x0ff ); 123 | 124 | u8g_SetAddress(u8g, dev, 1); /* cmd mode */ 125 | u8g_WriteByte(u8g, dev, 0x00b ); /* display ram (cursor) address hight byte */ 126 | u8g_SetAddress(u8g, dev, 0); /* data mode */ 127 | u8g_WriteByte(u8g, dev, disp_ram_adr >> 8 ); 128 | 129 | u8g_SetAddress(u8g, dev, 1); /* cmd mode */ 130 | u8g_WriteByte(u8g, dev, 0x00c ); /* write data */ 131 | u8g_SetAddress(u8g, dev, 0); /* data mode */ 132 | u8g_WriteSequence(u8g, dev, WIDTH/8, ptr); 133 | ptr += WIDTH/8; 134 | disp_ram_adr += WIDTH/8; 135 | } 136 | u8g_SetChipSelect(u8g, dev, 0); 137 | } 138 | break; 139 | } 140 | return u8g_dev_pb8h1f_base_fn(u8g, dev, msg, arg); 141 | } 142 | 143 | U8G_PB_DEV(u8g_dev_lc7981_240x64_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_lc7981_240x64_fn, U8G_COM_FAST_PARALLEL); 144 | 145 | 146 | -------------------------------------------------------------------------------- /src/clib/u8g_dev_lc7981_240x128.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_lc7981_240x128.c 4 | 5 | Hitachi Display SP14N002 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2012, 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 "u8g.h" 40 | 41 | #define WIDTH 240 42 | #define HEIGHT 128 43 | #define PAGE_HEIGHT 8 44 | 45 | 46 | /* 47 | http://www.mark-products.com/graphics.htm#240x128%20Pixel%20Format 48 | */ 49 | 50 | static const uint8_t u8g_dev_lc7981_240x128_init_seq[] PROGMEM = { 51 | U8G_ESC_CS(0), /* disable chip */ 52 | U8G_ESC_ADR(1), /* instruction mode */ 53 | U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/ 54 | U8G_ESC_CS(1), /* enable chip */ 55 | U8G_ESC_DLY(50), /* delay 50 ms */ 56 | 57 | 58 | U8G_ESC_ADR(1), /* instruction mode */ 59 | 0x000, /* mode register */ 60 | U8G_ESC_ADR(0), /* data mode */ 61 | 0x032, /* display on (bit 5), master mode on (bit 4), graphics mode on (bit 1)*/ 62 | 63 | U8G_ESC_ADR(1), /* instruction mode */ 64 | 0x001, /* character/bits per pixel pitch */ 65 | U8G_ESC_ADR(0), /* data mode */ 66 | 0x007, /* 8 bits per pixel */ 67 | 68 | U8G_ESC_ADR(1), /* instruction mode */ 69 | 0x002, /* number of chars/byte width of the screen */ 70 | U8G_ESC_ADR(0), /* data mode */ 71 | WIDTH/8-1, /* 8 bits per pixel */ 72 | 73 | U8G_ESC_ADR(1), /* instruction mode */ 74 | 0x003, /* time division */ 75 | U8G_ESC_ADR(0), /* data mode */ 76 | 0x07f, /* */ 77 | 78 | U8G_ESC_ADR(1), /* instruction mode */ 79 | 0x008, /* display start low */ 80 | U8G_ESC_ADR(0), /* data mode */ 81 | 0x000, /* */ 82 | 83 | U8G_ESC_ADR(1), /* instruction mode */ 84 | 0x009, /* display start high */ 85 | U8G_ESC_ADR(0), /* data mode */ 86 | 0x000, /* */ 87 | 88 | U8G_ESC_DLY(10), /* delay 10 ms */ 89 | 90 | U8G_ESC_CS(0), /* disable chip */ 91 | U8G_ESC_END /* end of sequence */ 92 | }; 93 | 94 | uint8_t u8g_dev_lc7981_240x128_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 95 | { 96 | switch(msg) 97 | { 98 | case U8G_DEV_MSG_INIT: 99 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE); 100 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_lc7981_240x128_init_seq); 101 | break; 102 | case U8G_DEV_MSG_STOP: 103 | break; 104 | case U8G_DEV_MSG_PAGE_NEXT: 105 | { 106 | uint8_t y, i; 107 | uint16_t disp_ram_adr; 108 | uint8_t *ptr; 109 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 110 | 111 | u8g_SetAddress(u8g, dev, 1); /* cmd mode */ 112 | u8g_SetChipSelect(u8g, dev, 1); 113 | y = pb->p.page_y0; 114 | ptr = pb->buf; 115 | disp_ram_adr = WIDTH/8; 116 | disp_ram_adr *= y; 117 | for( i = 0; i < 8; i ++ ) 118 | { 119 | u8g_SetAddress(u8g, dev, 1); /* cmd mode */ 120 | u8g_WriteByte(u8g, dev, 0x00a ); /* display ram (cursor) address low byte */ 121 | u8g_SetAddress(u8g, dev, 0); /* data mode */ 122 | u8g_WriteByte(u8g, dev, disp_ram_adr & 0x0ff ); 123 | 124 | u8g_SetAddress(u8g, dev, 1); /* cmd mode */ 125 | u8g_WriteByte(u8g, dev, 0x00b ); /* display ram (cursor) address hight byte */ 126 | u8g_SetAddress(u8g, dev, 0); /* data mode */ 127 | u8g_WriteByte(u8g, dev, disp_ram_adr >> 8 ); 128 | 129 | u8g_SetAddress(u8g, dev, 1); /* cmd mode */ 130 | u8g_WriteByte(u8g, dev, 0x00c ); /* write data */ 131 | u8g_SetAddress(u8g, dev, 0); /* data mode */ 132 | u8g_WriteSequence(u8g, dev, WIDTH/8, ptr); 133 | ptr += WIDTH/8; 134 | disp_ram_adr += WIDTH/8; 135 | } 136 | u8g_SetChipSelect(u8g, dev, 0); 137 | } 138 | break; 139 | } 140 | return u8g_dev_pb8h1f_base_fn(u8g, dev, msg, arg); 141 | } 142 | 143 | U8G_PB_DEV(u8g_dev_lc7981_240x128_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_lc7981_240x128_fn, U8G_COM_FAST_PARALLEL); 144 | 145 | 146 | -------------------------------------------------------------------------------- /src/clib/u8g_com_atmega_parallel.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_atmega_parallel.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2012, 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 | PIN_D0 8 36 | PIN_D1 9 37 | PIN_D2 10 38 | PIN_D3 11 39 | PIN_D4 4 40 | PIN_D5 5 41 | PIN_D6 6 42 | PIN_D7 7 43 | 44 | PIN_CS1 14 45 | PIN_CS2 15 46 | PIN_RW 16 47 | PIN_DI 17 48 | PIN_EN 18 49 | 50 | u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset) 51 | u8g_Init8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16, U8G_PIN_NONE) 52 | 53 | */ 54 | 55 | #include "u8g.h" 56 | 57 | #if defined(__AVR__) 58 | 59 | static void u8g_com_atmega_parallel_write(u8g_t *u8g, uint8_t val) U8G_NOINLINE; 60 | static void u8g_com_atmega_parallel_write(u8g_t *u8g, uint8_t val) 61 | { 62 | 63 | u8g_SetPILevel(u8g, U8G_PI_D0, val&1); 64 | val >>= 1; 65 | u8g_SetPILevel(u8g, U8G_PI_D1, val&1); 66 | val >>= 1; 67 | u8g_SetPILevel(u8g, U8G_PI_D2, val&1); 68 | val >>= 1; 69 | u8g_SetPILevel(u8g, U8G_PI_D3, val&1); 70 | val >>= 1; 71 | u8g_SetPILevel(u8g, U8G_PI_D4, val&1); 72 | val >>= 1; 73 | u8g_SetPILevel(u8g, U8G_PI_D5, val&1); 74 | val >>= 1; 75 | u8g_SetPILevel(u8g, U8G_PI_D6, val&1); 76 | val >>= 1; 77 | u8g_SetPILevel(u8g, U8G_PI_D7, val&1); 78 | 79 | /* EN cycle time must be 1 micro second */ 80 | u8g_SetPILevel(u8g, U8G_PI_EN, 1); 81 | u8g_MicroDelay(); /* delay by 1000ns, reference: ST7920: 140ns, SBN1661: 100ns */ 82 | u8g_SetPILevel(u8g, U8G_PI_EN, 0); 83 | u8g_10MicroDelay(); /* ST7920 commands: 72us */ 84 | u8g_10MicroDelay(); /* ST7920 commands: 72us */ 85 | } 86 | 87 | 88 | uint8_t u8g_com_atmega_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 89 | { 90 | switch(msg) 91 | { 92 | case U8G_COM_MSG_INIT: 93 | /* setup the RW pin as output and force it to low */ 94 | u8g_SetPIOutput(u8g, U8G_PI_RW); 95 | u8g_SetPILevel(u8g, U8G_PI_RW, 0); 96 | 97 | u8g_SetPIOutput(u8g, U8G_PI_D0); 98 | u8g_SetPIOutput(u8g, U8G_PI_D1); 99 | u8g_SetPIOutput(u8g, U8G_PI_D2); 100 | u8g_SetPIOutput(u8g, U8G_PI_D3); 101 | u8g_SetPIOutput(u8g, U8G_PI_D4); 102 | u8g_SetPIOutput(u8g, U8G_PI_D5); 103 | u8g_SetPIOutput(u8g, U8G_PI_D6); 104 | u8g_SetPIOutput(u8g, U8G_PI_D7); 105 | u8g_SetPIOutput(u8g, U8G_PI_EN); 106 | u8g_SetPIOutput(u8g, U8G_PI_CS1); 107 | u8g_SetPIOutput(u8g, U8G_PI_CS2); 108 | u8g_SetPIOutput(u8g, U8G_PI_DI); 109 | u8g_SetPILevel(u8g, U8G_PI_CS1, 1); 110 | u8g_SetPILevel(u8g, U8G_PI_CS2, 1); 111 | 112 | break; 113 | case U8G_COM_MSG_STOP: 114 | break; 115 | case U8G_COM_MSG_CHIP_SELECT: 116 | if ( arg_val == 0 ) 117 | { 118 | /* disable */ 119 | u8g_SetPILevel(u8g, U8G_PI_CS1, 1); 120 | u8g_SetPILevel(u8g, U8G_PI_CS2, 1); 121 | } 122 | else if ( arg_val == 1 ) 123 | { 124 | /* enable */ 125 | u8g_SetPILevel(u8g, U8G_PI_CS1, 0); 126 | u8g_SetPILevel(u8g, U8G_PI_CS2, 1); 127 | } 128 | else if ( arg_val == 2 ) 129 | { 130 | /* enable */ 131 | u8g_SetPILevel(u8g, U8G_PI_CS1, 1); 132 | u8g_SetPILevel(u8g, U8G_PI_CS2, 0); 133 | } 134 | else 135 | { 136 | /* enable */ 137 | u8g_SetPILevel(u8g, U8G_PI_CS1, 0); 138 | u8g_SetPILevel(u8g, U8G_PI_CS2, 0); 139 | } 140 | break; 141 | case U8G_COM_MSG_WRITE_BYTE: 142 | u8g_com_atmega_parallel_write(u8g, arg_val); 143 | break; 144 | case U8G_COM_MSG_WRITE_SEQ: 145 | { 146 | register uint8_t *ptr = arg_ptr; 147 | while( arg_val > 0 ) 148 | { 149 | u8g_com_atmega_parallel_write(u8g, *ptr++); 150 | arg_val--; 151 | } 152 | } 153 | break; 154 | case U8G_COM_MSG_WRITE_SEQ_P: 155 | { 156 | register uint8_t *ptr = arg_ptr; 157 | while( arg_val > 0 ) 158 | { 159 | u8g_com_atmega_parallel_write(u8g, u8g_pgm_read(ptr)); 160 | ptr++; 161 | arg_val--; 162 | } 163 | } 164 | break; 165 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 166 | u8g_SetPILevel(u8g, U8G_PI_DI, arg_val); 167 | break; 168 | case U8G_COM_MSG_RESET: 169 | u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 170 | break; 171 | } 172 | return 1; 173 | } 174 | 175 | #else 176 | 177 | uint8_t u8g_com_atmega_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 178 | { 179 | return 1; 180 | } 181 | 182 | #endif /* ARDUINO */ 183 | 184 | -------------------------------------------------------------------------------- /src/clib/u8g_com_arduino_parallel.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_arduino_parallel.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, 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 | PIN_D0 8 36 | PIN_D1 9 37 | PIN_D2 10 38 | PIN_D3 11 39 | PIN_D4 4 40 | PIN_D5 5 41 | PIN_D6 6 42 | PIN_D7 7 43 | 44 | PIN_CS1 14 45 | PIN_CS2 15 46 | PIN_RW 16 47 | PIN_DI 17 48 | PIN_EN 18 49 | 50 | u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset) 51 | u8g_Init8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16, U8G_PIN_NONE) 52 | 53 | */ 54 | 55 | #include "u8g.h" 56 | 57 | 58 | #if defined(ARDUINO) 59 | 60 | #if ARDUINO < 100 61 | #include 62 | #else 63 | #include 64 | #endif 65 | 66 | 67 | 68 | 69 | 70 | 71 | void u8g_com_arduino_parallel_write(u8g_t *u8g, uint8_t val) 72 | { 73 | u8g_com_arduino_digital_write(u8g, U8G_PI_D0, val&1); 74 | val >>= 1; 75 | u8g_com_arduino_digital_write(u8g, U8G_PI_D1, val&1); 76 | val >>= 1; 77 | u8g_com_arduino_digital_write(u8g, U8G_PI_D2, val&1); 78 | val >>= 1; 79 | u8g_com_arduino_digital_write(u8g, U8G_PI_D3, val&1); 80 | val >>= 1; 81 | u8g_com_arduino_digital_write(u8g, U8G_PI_D4, val&1); 82 | val >>= 1; 83 | u8g_com_arduino_digital_write(u8g, U8G_PI_D5, val&1); 84 | val >>= 1; 85 | u8g_com_arduino_digital_write(u8g, U8G_PI_D6, val&1); 86 | val >>= 1; 87 | u8g_com_arduino_digital_write(u8g, U8G_PI_D7, val&1); 88 | 89 | /* EN cycle time must be 1 micro second, digitalWrite is slow enough to do this */ 90 | u8g_com_arduino_digital_write(u8g, U8G_PI_EN, HIGH); 91 | u8g_MicroDelay(); /* delay by 1000ns, reference: ST7920: 140ns, SBN1661: 100ns */ 92 | u8g_com_arduino_digital_write(u8g, U8G_PI_EN, LOW); 93 | u8g_10MicroDelay(); /* ST7920 commands: 72us */ 94 | } 95 | 96 | 97 | uint8_t u8g_com_arduino_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 98 | { 99 | switch(msg) 100 | { 101 | case U8G_COM_MSG_INIT: 102 | /* setup the RW pin as output and force it to low */ 103 | if ( u8g->pin_list[U8G_PI_RW] != U8G_PIN_NONE ) 104 | { 105 | pinMode(u8g->pin_list[U8G_PI_RW], OUTPUT); 106 | u8g_com_arduino_digital_write(u8g, U8G_PI_RW, LOW); 107 | } 108 | /* set all pins (except RW pin) */ 109 | u8g_com_arduino_assign_pin_output_high(u8g); 110 | break; 111 | case U8G_COM_MSG_STOP: 112 | break; 113 | case U8G_COM_MSG_CHIP_SELECT: 114 | if ( arg_val == 0 ) 115 | { 116 | /* disable */ 117 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, HIGH); 118 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, HIGH); 119 | } 120 | else if ( arg_val == 1 ) 121 | { 122 | /* enable */ 123 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, LOW); 124 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, HIGH); 125 | } 126 | else if ( arg_val == 2 ) 127 | { 128 | /* enable */ 129 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, HIGH); 130 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, LOW); 131 | } 132 | else 133 | { 134 | /* enable */ 135 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, LOW); 136 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, LOW); 137 | } 138 | break; 139 | case U8G_COM_MSG_WRITE_BYTE: 140 | u8g_com_arduino_parallel_write(u8g, arg_val); 141 | break; 142 | case U8G_COM_MSG_WRITE_SEQ: 143 | { 144 | register uint8_t *ptr = arg_ptr; 145 | while( arg_val > 0 ) 146 | { 147 | u8g_com_arduino_parallel_write(u8g, *ptr++); 148 | arg_val--; 149 | } 150 | } 151 | break; 152 | case U8G_COM_MSG_WRITE_SEQ_P: 153 | { 154 | register uint8_t *ptr = arg_ptr; 155 | while( arg_val > 0 ) 156 | { 157 | u8g_com_arduino_parallel_write(u8g, u8g_pgm_read(ptr)); 158 | ptr++; 159 | arg_val--; 160 | } 161 | } 162 | break; 163 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 164 | u8g_com_arduino_digital_write(u8g, U8G_PI_DI, arg_val); 165 | break; 166 | case U8G_COM_MSG_RESET: 167 | if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE ) 168 | u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); 169 | break; 170 | 171 | } 172 | return 1; 173 | } 174 | 175 | #else 176 | 177 | 178 | uint8_t u8g_com_arduino_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 179 | { 180 | return 1; 181 | } 182 | 183 | #endif /* ARDUINO */ 184 | 185 | -------------------------------------------------------------------------------- /src/clib/u8g_dev_ssd1309_128x64.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_ssd1309_128x64.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2012, 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 "u8g.h" 38 | 39 | #define WIDTH 128 40 | #define HEIGHT 64 41 | #define PAGE_HEIGHT 8 42 | 43 | 44 | /* ssd1309 ini sequence*/ 45 | static const uint8_t u8g_dev_ssd1309_128x64_init_seq[] PROGMEM={ 46 | U8G_ESC_CS(0), /* disable chip */ 47 | U8G_ESC_ADR(0), /* instruction mode */ 48 | U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */ 49 | U8G_ESC_CS(1), /* enable chip */ 50 | 51 | 0xfd,0x12, /*Command Lock */ 52 | 0xae, /*Set Display Off */ 53 | 0xd5,0xa0, /*set Display Clock Divide Ratio/Oscillator Frequency */ 54 | 0xa8,0x3f, /*Set Multiplex Ratio */ 55 | 0x3d,0x00, /*Set Display Offset*/ 56 | 0x40, /*Set Display Start Line*/ 57 | 0xa1, /*Set Segment Re-Map*/ 58 | 0xc8, /*Set COM Output Scan Direction*/ 59 | 0xda,0x12, /*Set COM Pins Hardware Configuration*/ 60 | 0x81,0xdf, /*Set Current Control */ 61 | 0xd9,0x82, /*Set Pre-Charge Period */ 62 | 0xdb,0x34, /*Set VCOMH Deselect Level */ 63 | 0xa4, /*Set Entire Display On/Off */ 64 | 0xa6, /*Set Normal/Inverse Display*/ 65 | U8G_ESC_VCC(1), /*Power up VCC & Stabilized */ 66 | U8G_ESC_DLY(50), 67 | 0xaf, /*Set Display On */ 68 | U8G_ESC_DLY(50), 69 | U8G_ESC_CS(0), /* disable chip */ 70 | U8G_ESC_END /* end of sequence */ 71 | }; 72 | 73 | /* select one init sequence here */ 74 | #define u8g_dev_ssd1309_128x64_init_seq u8g_dev_ssd1309_128x64_init_seq 75 | 76 | 77 | static const uint8_t u8g_dev_ssd1309_128x64_data_start[] PROGMEM = { 78 | U8G_ESC_ADR(0), /* instruction mode */ 79 | U8G_ESC_CS(1), /* enable chip */ 80 | 0x010, /* set upper 4 bit of the col adr to 0 */ 81 | 0x000, /* set lower 4 bit of the col adr to 4 */ 82 | U8G_ESC_END /* end of sequence */ 83 | }; 84 | 85 | static const uint8_t u8g_dev_ssd13xx_sleep_on[] PROGMEM = { 86 | U8G_ESC_ADR(0), /* instruction mode */ 87 | U8G_ESC_CS(1), /* enable chip */ 88 | 0x0ae, /* display off */ 89 | U8G_ESC_CS(0), /* disable chip */ 90 | U8G_ESC_END /* end of sequence */ 91 | }; 92 | 93 | static const uint8_t u8g_dev_ssd13xx_sleep_off[] PROGMEM = { 94 | U8G_ESC_ADR(0), /* instruction mode */ 95 | U8G_ESC_CS(1), /* enable chip */ 96 | 0x0af, /* display on */ 97 | U8G_ESC_DLY(50), /* delay 50 ms */ 98 | U8G_ESC_CS(0), /* disable chip */ 99 | U8G_ESC_END /* end of sequence */ 100 | }; 101 | 102 | uint8_t u8g_dev_ssd1309_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 103 | { 104 | switch(msg) 105 | { 106 | case U8G_DEV_MSG_INIT: 107 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS); 108 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1309_128x64_init_seq); 109 | break; 110 | case U8G_DEV_MSG_STOP: 111 | break; 112 | case U8G_DEV_MSG_PAGE_NEXT: 113 | { 114 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 115 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1309_128x64_data_start); 116 | u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (SSD1306) */ 117 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 118 | if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 ) 119 | return 0; 120 | u8g_SetChipSelect(u8g, dev, 0); 121 | } 122 | break; 123 | case U8G_DEV_MSG_CONTRAST: 124 | u8g_SetChipSelect(u8g, dev, 1); 125 | u8g_SetAddress(u8g, dev, 0); /* instruction mode */ 126 | u8g_WriteByte(u8g, dev, 0x081); 127 | u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) ); /* 11 Jul 2015: fixed contrast calculation */ 128 | u8g_SetChipSelect(u8g, dev, 0); 129 | return 1; 130 | case U8G_DEV_MSG_SLEEP_ON: 131 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on); 132 | return 1; 133 | case U8G_DEV_MSG_SLEEP_OFF: 134 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off); 135 | return 1; 136 | } 137 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 138 | } 139 | 140 | U8G_PB_DEV(u8g_dev_ssd1309_128x64_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1309_128x64_fn, U8G_COM_HW_SPI); 141 | U8G_PB_DEV(u8g_dev_ssd1309_128x64_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1309_128x64_fn, U8G_COM_SW_SPI); 142 | U8G_PB_DEV(u8g_dev_ssd1309_128x64_i2c, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1309_128x64_fn, U8G_COM_SSD_I2C); 143 | --------------------------------------------------------------------------------