├── .gitignore ├── src ├── clib │ ├── u8g_font_data.c │ ├── HAL_example_files │ │ ├── LCD_I2C_routines.h │ │ ├── LCD_delay.h │ │ ├── LCD_pin_routines.h │ │ ├── LPC1768_LCD_defines.h │ │ ├── HAL_LCD_defines.h │ │ └── LCD_pin_routines.c.example │ ├── u8g_com_mfl_hw_spi.cpp │ ├── u8g_com_esp32_ssd_i2c_fn.cpp │ ├── u8g_com_null.c │ ├── u8g_u16toa.c │ ├── u8g_u8toa.c │ ├── u8g_com_stm32duino_hw_spi.cpp │ ├── u8g_com_mfl_ssd_i2c.cpp │ ├── u8g_dev_null.c │ ├── u8g_com_stm32duino_ssd_i2c.cpp │ ├── u8g_page.c │ ├── u8g_com_arduino_common.c │ ├── u8g_line.c │ ├── u8g_com_samd51_hw_spi.cpp │ ├── u8g_com_samd51_st7920_hw_spi.cpp │ ├── 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_sbn1661_122x32.c │ ├── u8g_com_atmega_sw_spi.c │ ├── u8g_dev_gprof.c │ ├── u8g_dev_ks0108_128x64.c │ ├── u8g_com_std_sw_spi.c │ ├── u8g_pb8v2.c │ ├── u8g_com_arduino_std_sw_spi.c │ ├── u8g_bitmap.c │ ├── u8g_dev_uc1611_dogm240.c │ ├── u8g_dev_uc1611_dogxl240.c │ ├── u8g_com_arduino_hw_usart_spi.c │ ├── u8g_pb8h2.c │ ├── u8g_state.c │ ├── u8g_dev_tls8204_84x48.c │ ├── u8g_clip.c │ ├── u8g_pb16v2.c │ ├── u8g_com_api.c │ ├── u8g_pb.c │ ├── u8g_virtual_screen.c │ ├── u8g_com_atxmega_hw_spi.c │ ├── u8g_pb8v1.c │ ├── u8g_com_atmega_st7920_spi.c │ ├── u8g_com_linux_ssd_i2c.c │ ├── u8g_com_arduino_attiny85_hw_spi.c │ ├── u8g_com_atmega_hw_spi.c │ ├── u8g_pbxh16.c │ ├── u8g_pb16v1.c │ ├── u8g_pb8h8.c │ └── u8g_pb14v1.c ├── U8glibPrintable.h ├── U8glibPrint.h └── U8glib-HAL.cpp ├── library.properties ├── library.json ├── README.md └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.tar.gz 3 | -------------------------------------------------------------------------------- /src/clib/u8g_font_data.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MarlinFirmware/U8glib-HAL/HEAD/src/clib/u8g_font_data.c -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=U8glib-HAL 2 | version=0.5.5 3 | author=Scott Lahteine 4 | maintainer=Scott Lahteine 5 | sentence=A library supporting monochrome TFTs and OLEDs, specifically for use with Marlin Firmware. 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/MarlinFirmware/U8glib-HAL 9 | architectures=avr,AVR,atmelavr,megaavr,megaAVR,sam,atmelsam,stm32,STM32,ststm32,STM32F1,stm32f4,STM32F4,stm32duino,teensy,esp,esp32,ESP32,espressif32,arduino_esp32,linux_x86_64,windows_x86 10 | -------------------------------------------------------------------------------- /library.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "U8glib-HAL", 3 | "keywords": "u8g, u8glib, arm, hal, lcd, tft, dogm, st7920, ssd1306, ssd1309, graphical, display, driver", 4 | "id": 1932, 5 | "description": "Unofficial repository for combined U8G and U8Glib-ARM with Marlin extensions", 6 | "repository": 7 | { 8 | "type": "git", 9 | "url": "https://github.com/MarlinFirmware/U8glib-HAL.git" 10 | }, 11 | "version": "0.5.5", 12 | "authors": 13 | [ 14 | { 15 | "url": null, 16 | "maintainer": false, 17 | "email": "u8glib@thinkyhead.com", 18 | "name": "Scott Lahteine" 19 | } 20 | ], 21 | "license": "BSD-2-Clause", 22 | "frameworks": "*", 23 | "platforms": "*", 24 | "headers": [ "U8glib-HAL.h" ] 25 | } 26 | -------------------------------------------------------------------------------- /src/clib/HAL_example_files/LCD_I2C_routines.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Marlin 3D Printer Firmware 3 | * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] 4 | * 5 | * Based on Sprinter and grbl. 6 | * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | * 21 | */ 22 | 23 | void u8g_i2c_init(uint8_t options); 24 | uint8_t u8g_i2c_wait(uint8_t mask, uint8_t pos); 25 | uint8_t u8g_i2c_start(uint8_t sla); 26 | uint8_t u8g_i2c_send_byte(uint8_t data); 27 | void u8g_i2c_stop(void); 28 | -------------------------------------------------------------------------------- /src/clib/HAL_example_files/LCD_delay.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Marlin 3D Printer Firmware 3 | * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] 4 | * 5 | * Based on Sprinter and grbl. 6 | * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | * 21 | */ 22 | 23 | /** 24 | * LCD delay routines - used by all the drivers. 25 | * 26 | * These are based on the LPC1768 routines. 27 | * 28 | * Couldn't just call exact copies because the overhead resulted in the 29 | * one microsecond delay being about 4uS. 30 | */ 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | void U8g_delay(int msec); 37 | void u8g_MicroDelay(void); 38 | void u8g_10MicroDelay(void); 39 | 40 | #ifdef __cplusplus 41 | } 42 | #endif -------------------------------------------------------------------------------- /src/U8glibPrintable.h: -------------------------------------------------------------------------------- 1 | /* 2 | Printable.h - Interface class that allows printing of complex types 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | #pragma once 20 | 21 | #include 22 | #include 23 | 24 | class U8glibPrint; 25 | 26 | /** The Printable class provides a way for new classes to allow themselves to be printed. 27 | By deriving from Printable and implementing the printTo method, it will then be possible 28 | for users to print out instances of this class by passing them into the usual 29 | Print::print and Print::println methods. 30 | */ 31 | 32 | class U8glibPrintable 33 | { 34 | public: 35 | virtual size_t printTo(U8glibPrint& p) const = 0; 36 | }; 37 | -------------------------------------------------------------------------------- /src/clib/HAL_example_files/LCD_pin_routines.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Marlin 3D Printer Firmware 3 | * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] 4 | * 5 | * Based on Sprinter and grbl. 6 | * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | * 21 | */ 22 | 23 | /** 24 | * Low level pin manipulation routines - used by all the drivers. 25 | * 26 | * These are based on the LPC1768 pinMode, digitalRead & digitalWrite routines. 27 | * 28 | * Couldn't just call exact copies because the overhead killed the LCD update speed 29 | * With an intermediate level the softspi was running in the 10-20kHz range which 30 | * resulted in using about about 25% of the CPU's time. 31 | */ 32 | 33 | void u8g_SetPinOutput(uint8_t internal_pin_number); 34 | void u8g_SetPinInput(uint8_t internal_pin_number); 35 | void u8g_SetPinLevel(uint8_t pin, uint8_t pin_status); 36 | uint8_t u8g_GetPinLevel(uint8_t pin); 37 | -------------------------------------------------------------------------------- /src/clib/u8g_com_mfl_hw_spi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | u8g_com_mfl_hw_spi.cpp 3 | 4 | communication interface for SPI protocol 5 | */ 6 | 7 | #ifdef ARDUINO_ARCH_MFL 8 | 9 | #include "u8g.h" 10 | #include 11 | 12 | static SPISettings spiConfig; 13 | static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT 14 | 15 | uint8_t u8g_com_mfl_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 16 | if (msgInitCount) { 17 | if (msg == U8G_COM_MSG_INIT) msgInitCount--; 18 | if (msgInitCount) return -1; 19 | } 20 | 21 | switch(msg) { 22 | case U8G_COM_MSG_STOP: 23 | break; 24 | case U8G_COM_MSG_INIT: 25 | u8g_SetPIOutput(u8g, U8G_PI_CS); 26 | u8g_SetPIOutput(u8g, U8G_PI_A0); 27 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 28 | u8g_SetPILevel(u8g, U8G_PI_CS, 1); 29 | spiConfig = SPISettings(2500000, MSBFIRST, SPI_MODE0); // 2.5 Mbits base clock 30 | SPI.begin(); 31 | break; 32 | case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1) 33 | u8g_SetPILevel(u8g, U8G_PI_A0, arg_val); 34 | break; 35 | case U8G_COM_MSG_CHIP_SELECT: // arg_val == 0 means HIGH level of U8G_PI_CS 36 | u8g_SetPILevel(u8g, U8G_PI_CS, arg_val ? LOW : HIGH); // CS = 0 (low active) 37 | break; 38 | case U8G_COM_MSG_RESET: 39 | u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 40 | break; 41 | case U8G_COM_MSG_WRITE_BYTE: 42 | SPI.beginTransaction(spiConfig); 43 | SPI.transfer(arg_val); 44 | SPI.endTransaction(); 45 | break; 46 | case U8G_COM_MSG_WRITE_SEQ: 47 | SPI.beginTransaction(spiConfig); 48 | SPI.transfer((uint8_t *)arg_ptr, arg_val); 49 | SPI.endTransaction(); 50 | break; 51 | } 52 | return 1; 53 | } 54 | 55 | #endif // ARDUINO_ARCH_MFL 56 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # U8glib-HAL 2 | 3 | u8g by Oliver Kraus with extensions for ARM and the Marlin HAL. 4 | 5 | The extensions allow access to the u8g library by "non native" CPUs/systems. 6 | 7 | AVR, Arduino, and Due access to the library is not changed. 8 | 9 | Enabling the extensions by defining the flag **`U8G_HAL_LINKS`**. This can be done in `platformio.ini` by adding **`-DU8G_HAL_LINKS`** to any environment's build flags. 10 | 11 | ### The following files provide the links between the u8g library and the "non native" CPUs/systems. 12 | 13 | #### `#include ` 14 | The `LCD_defines.h` header brings in the top level link file which: 15 | - Defines link files for SPI routines, delay routines, I2C routines and class definitions. 16 | - Connects u8g com generic com defines to the desired HAL com routine. 17 | 18 | #### `#include ` 19 | Contains code or declarations for the u8g routines: 20 | - `void U8g_delay(int msec)` 21 | - `void u8g_MicroDelay(void)` 22 | - `void u8g_10MicroDelay(void)` 23 | 24 | #### `#include ` 25 | Contains code or declarations for the u8g routines: 26 | - `void u8g_SetPinOutput(uint8_t internal_pin_number)` 27 | - `void u8g_SetPinInput(uint8_t internal_pin_number)` 28 | - `void u8g_SetPinLevel(uint8_t pin, uint8_t pin_status)` 29 | - `uint8_t u8g_GetPinLevel(uint8_t pin)` 30 | 31 | #### `#include ` 32 | Contains code or declarations for the u8g routines: 33 | - `void u8g_i2c_init(uint8_t options)` 34 | - `uint8_t u8g_i2c_wait(uint8_t mask, uint8_t pos)` 35 | - `uint8_t u8g_i2c_start(uint8_t sla)` 36 | - `uint8_t u8g_i2c_send_byte(uint8_t data)` 37 | - `void u8g_i2c_stop(void)` 38 | 39 | #### MarlinFirmware Changes 40 | - Empty constructors are now provided so the u8g instance can be initialized later. 41 | Data members are still constructed early when the u8g object is declared static global. 42 | - Constructors that just take an "options" argument now *require* the argument (e.g., `U8G_I2C_OPT_NONE`) or they will be treated as default empty constructors and won't be initialized. 43 | -------------------------------------------------------------------------------- /src/clib/u8g_com_esp32_ssd_i2c_fn.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * u8g_com_esp32_ssd_i2c.cpp 3 | * 4 | * communication interface for SSDxxxx chip variant I2C protocol 5 | */ 6 | #ifdef ARDUINO_ARCH_ESP32 7 | 8 | #include "u8g.h" 9 | #include 10 | 11 | /** 12 | * BUFFER_LENGTH is defined in libraries\Wire\utility\WireBase.h 13 | * Default value is 32 14 | * Increase this value to 144 to send U8G_COM_MSG_WRITE_SEQ in single block 15 | */ 16 | 17 | #if defined(BUFFER_LENGTH) && BUFFER_LENGTH < 144 18 | #define I2C_MAX_LENGTH (BUFFER_LENGTH - 1) 19 | #endif // BUFFER_LENGTH 20 | 21 | static uint8_t control; 22 | 23 | uint8_t u8g_com_esp32_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 24 | switch (msg) { 25 | case U8G_COM_MSG_INIT: 26 | Wire.setClock(400000); 27 | Wire.begin(); 28 | break; 29 | 30 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 31 | control = arg_val ? 0x40 : 0x00; 32 | break; 33 | 34 | case U8G_COM_MSG_WRITE_BYTE: 35 | Wire.beginTransmission(0x3c); 36 | Wire.write(control); 37 | Wire.write(arg_val); 38 | Wire.endTransmission(); 39 | break; 40 | 41 | case U8G_COM_MSG_WRITE_SEQ: { 42 | #ifdef I2C_MAX_LENGTH 43 | while (arg_val > 0) { 44 | Wire.beginTransmission(0x3c); 45 | Wire.write(control); 46 | if (arg_val <= I2C_MAX_LENGTH) { 47 | Wire.write((uint8_t *) arg_ptr, arg_val); 48 | arg_val = 0; 49 | } 50 | else { 51 | Wire.write((uint8_t *) arg_ptr, I2C_MAX_LENGTH); 52 | arg_val -= I2C_MAX_LENGTH; 53 | arg_ptr += I2C_MAX_LENGTH; 54 | } 55 | Wire.endTransmission(); 56 | } 57 | #else 58 | Wire.beginTransmission(0x3c); 59 | Wire.write(control); 60 | Wire.write((uint8_t *) arg_ptr, arg_val); 61 | Wire.endTransmission(); 62 | #endif // I2C_MAX_LENGTH 63 | break; 64 | } 65 | 66 | } 67 | return 1; 68 | } 69 | 70 | #endif // ARDUINO_ARCH_ESP32 71 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 39 | 40 | uint8_t u8g_com_null_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 41 | switch (msg) { 42 | case U8G_COM_MSG_INIT: 43 | break; 44 | case U8G_COM_MSG_STOP: 45 | break; 46 | 47 | case U8G_COM_MSG_CHIP_SELECT: 48 | // arg_val contains the chip number, which should be enabled 49 | break; 50 | 51 | case U8G_COM_MSG_WRITE_BYTE: 52 | break; 53 | case U8G_COM_MSG_WRITE_SEQ: 54 | break; 55 | } 56 | return 1; 57 | } 58 | -------------------------------------------------------------------------------- /src/clib/u8g_u16toa.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_u16toa.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 | const char *u8g_u16toap(char * dest, uint16_t v) { 39 | uint8_t pos; 40 | uint8_t d; 41 | uint16_t c; 42 | c = 10000; 43 | for ( pos = 0; pos < 5; pos++ ) { 44 | d = '0'; 45 | while (v >= c) { 46 | v -= c; 47 | d++; 48 | } 49 | dest[pos] = d; 50 | c /= 10; 51 | } 52 | dest[5] = '\0'; 53 | return dest; 54 | } 55 | 56 | // v = value, d = number of digits 57 | const char *u8g_u16toa(uint16_t v, uint8_t d) { 58 | static char buf[6]; 59 | d = 5 - d; 60 | return u8g_u16toap(buf, v) + d; 61 | } 62 | -------------------------------------------------------------------------------- /src/clib/u8g_u8toa.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_u8toa.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 | static const unsigned char u8g_u8toa_tab[3] = { 100, 10, 1 }; 39 | const char *u8g_u8toap(char * dest, uint8_t v) { 40 | uint8_t pos; 41 | uint8_t d; 42 | uint8_t c; 43 | for ( pos = 0; pos < 3; pos++ ) { 44 | d = '0'; 45 | c = *(u8g_u8toa_tab + pos); 46 | while (v >= c) { 47 | v -= c; 48 | d++; 49 | } 50 | dest[pos] = d; 51 | } 52 | dest[3] = '\0'; 53 | return dest; 54 | } 55 | 56 | // v = value, d = number of digits 57 | const char *u8g_u8toa(uint8_t v, uint8_t d) { 58 | static char buf[4]; 59 | d = 3 - d; 60 | return u8g_u8toap(buf, v) + d; 61 | } 62 | -------------------------------------------------------------------------------- /src/clib/u8g_com_stm32duino_hw_spi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | u8g_com_stm32duino_hw_spi.cpp 3 | 4 | communication interface for SPI protocol 5 | */ 6 | 7 | #ifdef ARDUINO_ARCH_STM32 8 | 9 | #include "u8g.h" 10 | #include 11 | 12 | static SPISettings spiConfig; 13 | static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT 14 | 15 | uint8_t u8g_com_stm32duino_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 16 | if (msgInitCount) { 17 | if (msg == U8G_COM_MSG_INIT) msgInitCount --; 18 | if (msgInitCount) return -1; 19 | } 20 | 21 | switch(msg) { 22 | case U8G_COM_MSG_STOP: 23 | break; 24 | case U8G_COM_MSG_INIT: 25 | u8g_SetPIOutput(u8g, U8G_PI_CS); 26 | u8g_SetPIOutput(u8g, U8G_PI_A0); 27 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 28 | 29 | u8g_SetPILevel(u8g, U8G_PI_CS, 1); 30 | 31 | spiConfig = SPISettings(2500000, MSBFIRST, SPI_MODE0); // 2.5 Mbits base clock 32 | SPI.begin(); 33 | break; 34 | 35 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 36 | u8g_SetPILevel(u8g, U8G_PI_A0, arg_val); 37 | break; 38 | 39 | case U8G_COM_MSG_CHIP_SELECT: /* arg_val == 0 means HIGH level of U8G_PI_CS */ 40 | u8g_SetPILevel(u8g, U8G_PI_CS, arg_val ? LOW : HIGH); /* CS = 0 (low active) */ 41 | break; 42 | 43 | case U8G_COM_MSG_RESET: 44 | u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 45 | break; 46 | 47 | case U8G_COM_MSG_WRITE_BYTE: 48 | SPI.beginTransaction(spiConfig); 49 | #if defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F4) 50 | SPI.send(arg_val); 51 | #else 52 | SPI.transfer(arg_val); 53 | #endif 54 | SPI.endTransaction(); 55 | break; 56 | 57 | case U8G_COM_MSG_WRITE_SEQ: 58 | SPI.beginTransaction(spiConfig); 59 | #if defined(ARDUINO_ARCH_STM32F1) || defined(ARDUINO_ARCH_STM32F4) 60 | SPI.send((uint8_t *)arg_ptr, arg_val); 61 | #else 62 | SPI.transfer((uint8_t *)arg_ptr, arg_val); 63 | #endif 64 | SPI.endTransaction(); 65 | break; 66 | } 67 | return 1; 68 | } 69 | 70 | #endif // ARDUINO_ARCH_STM32 71 | -------------------------------------------------------------------------------- /src/clib/u8g_com_mfl_ssd_i2c.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | u8g_com_mfl_ssd_i2c.cpp 3 | 4 | communication interface for SSDxxxx chip variant I2C protocol 5 | */ 6 | 7 | #ifdef ARDUINO_ARCH_MFL 8 | 9 | #include "u8g.h" 10 | #include 11 | 12 | /* 13 | WIRE_BUFFER_LENGTH is defined in arduino framework libraries\Wire\src\Wire.h 14 | Default value is 32 15 | Increate this value to 144 to send U8G_COM_MSG_WRITE_SEQ in single block 16 | */ 17 | 18 | #if defined(WIRE_BUFFER_LENGTH) && WIRE_BUFFER_LENGTH < 144 19 | #define I2C_MAX_LENGTH (WIRE_BUFFER_LENGTH - 1) 20 | #endif // WIRE_BUFFER_LENGTH 21 | 22 | static uint8_t control; 23 | static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT 24 | 25 | uint8_t u8g_com_mfl_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 26 | if (msgInitCount) { 27 | if (msg == U8G_COM_MSG_INIT) msgInitCount--; 28 | if (msgInitCount) return -1; 29 | } 30 | 31 | switch (msg) { 32 | case U8G_COM_MSG_INIT: 33 | Wire.setClock(400000); 34 | Wire.begin(); 35 | break; 36 | case U8G_COM_MSG_ADDRESS: // Define cmd (arg_val = 0) or data mode (arg_val = 1) 37 | control = arg_val ? 0x40 : 0x00; 38 | break; 39 | case U8G_COM_MSG_WRITE_BYTE: 40 | Wire.beginTransmission(0x3c); 41 | Wire.write(control); 42 | Wire.write(arg_val); 43 | Wire.endTransmission(); 44 | break; 45 | case U8G_COM_MSG_WRITE_SEQ: { 46 | uint8_t* dataptr = (uint8_t*)arg_ptr; 47 | #ifdef I2C_MAX_LENGTH 48 | while (arg_val > 0) { 49 | Wire.beginTransmission(0x3c); 50 | Wire.write(control); 51 | if (arg_val <= I2C_MAX_LENGTH) { 52 | Wire.write(dataptr, arg_val); 53 | arg_val = 0; 54 | } 55 | else { 56 | Wire.write(dataptr, I2C_MAX_LENGTH); 57 | arg_val -= I2C_MAX_LENGTH; 58 | dataptr += I2C_MAX_LENGTH; 59 | } 60 | Wire.endTransmission(); 61 | } 62 | #else 63 | Wire.beginTransmission(0x3c); 64 | Wire.write(control); 65 | Wire.write(dataptr, arg_val); 66 | Wire.endTransmission(); 67 | #endif // I2C_MAX_LENGTH 68 | break; 69 | } 70 | 71 | } 72 | return 1; 73 | } 74 | 75 | #endif // ARDUINO_ARCH_MFL 76 | -------------------------------------------------------------------------------- /src/clib/HAL_example_files/LPC1768_LCD_defines.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Marlin 3D Printer Firmware 3 | * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] 4 | * 5 | * Based on Sprinter and grbl. 6 | * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | * 21 | */ 22 | 23 | /** 24 | * LPC1768 LCD specific defines 25 | */ 26 | 27 | // The following are optional depending on the platform. 28 | 29 | // definitions of HAL specific com and device drivers. 30 | uint8_t u8g_com_HAL_LPC1768_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); 31 | uint8_t u8g_com_HAL_LPC1768_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); 32 | uint8_t u8g_com_HAL_LPC1768_ST7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); 33 | uint8_t u8g_com_HAL_LPC1768_ST7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); 34 | uint8_t u8g_com_HAL_LPC1768_ssd_hw_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr); 35 | 36 | // connect U8g com generic com names to the desired driver 37 | #define U8G_COM_HW_SPI u8g_com_HAL_LPC1768_hw_spi_fn // use LPC1768 specific hardware SPI routine 38 | #define U8G_COM_SW_SPI u8g_com_HAL_LPC1768_sw_spi_fn // use LPC1768 specific software SPI routine 39 | #define U8G_COM_ST7920_HW_SPI u8g_com_HAL_LPC1768_ST7920_hw_spi_fn 40 | #define U8G_COM_ST7920_SW_SPI u8g_com_HAL_LPC1768_ST7920_sw_spi_fn 41 | #define U8G_COM_SSD_I2C u8g_com_HAL_LPC1768_ssd_hw_i2c_fn 42 | 43 | // let these default for now 44 | #define U8G_COM_PARALLEL u8g_com_null_fn 45 | #define U8G_COM_T6963 u8g_com_null_fn 46 | #define U8G_COM_FAST_PARALLEL u8g_com_null_fn 47 | #define U8G_COM_UC_I2C u8g_com_null_fn 48 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 37 | 38 | uint8_t u8g_dev_null(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) { 39 | switch (msg) { 40 | case U8G_DEV_MSG_SET_8PIXEL: // most often used command 41 | break; 42 | case U8G_DEV_MSG_SET_PIXEL: 43 | break; 44 | case U8G_DEV_MSG_INIT: 45 | break; 46 | case U8G_DEV_MSG_STOP: 47 | break; 48 | case U8G_DEV_MSG_PAGE_FIRST: 49 | break; 50 | case U8G_DEV_MSG_PAGE_NEXT: 51 | break; 52 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 53 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 54 | return 1; 55 | #endif 56 | case U8G_DEV_MSG_GET_PAGE_BOX: 57 | break; 58 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 59 | break; 60 | case U8G_DEV_MSG_SET_XY_CB: 61 | break; 62 | } 63 | return 1; 64 | } 65 | -------------------------------------------------------------------------------- /src/clib/u8g_com_stm32duino_ssd_i2c.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | u8g_com_stm32duino_ssd_i2c.cpp 3 | 4 | communication interface for SSDxxxx chip variant I2C protocol 5 | */ 6 | 7 | #if defined(ARDUINO_ARCH_STM32) && !defined(HAL_I2C_MODULE_DISABLED) 8 | 9 | #include "u8g.h" 10 | #include 11 | 12 | /* 13 | BUFFER_LENGTH is defined in libraries\Wire\utility\WireBase.h 14 | Default value is 32 15 | Increate this value to 144 to send U8G_COM_MSG_WRITE_SEQ in single block 16 | */ 17 | 18 | #if defined(BUFFER_LENGTH) && BUFFER_LENGTH < 144 19 | #define I2C_MAX_LENGTH (BUFFER_LENGTH - 1) 20 | #endif // BUFFER_LENGTH 21 | 22 | static uint8_t control; 23 | static uint8_t msgInitCount = 2; // Ignore all messages until 2nd U8G_COM_MSG_INIT 24 | 25 | uint8_t u8g_com_stm32duino_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 26 | { 27 | if (msgInitCount) { 28 | if (msg == U8G_COM_MSG_INIT) msgInitCount--; 29 | if (msgInitCount) return -1; 30 | } 31 | 32 | switch (msg) 33 | { 34 | case U8G_COM_MSG_INIT: 35 | Wire.setClock(400000); 36 | Wire.begin(); 37 | break; 38 | 39 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 40 | control = arg_val ? 0x40 : 0x00; 41 | break; 42 | 43 | case U8G_COM_MSG_WRITE_BYTE: 44 | Wire.beginTransmission(0x3c); 45 | Wire.write(control); 46 | Wire.write(arg_val); 47 | Wire.endTransmission(); 48 | break; 49 | 50 | case U8G_COM_MSG_WRITE_SEQ: 51 | { 52 | uint8_t* dataptr = (uint8_t*)arg_ptr; 53 | #ifdef I2C_MAX_LENGTH 54 | while (arg_val > 0) { 55 | Wire.beginTransmission(0x3c); 56 | Wire.write(control); 57 | if (arg_val <= I2C_MAX_LENGTH) { 58 | Wire.write(dataptr, arg_val); 59 | arg_val = 0; 60 | } 61 | else { 62 | Wire.write(dataptr, I2C_MAX_LENGTH); 63 | arg_val -= I2C_MAX_LENGTH; 64 | dataptr += I2C_MAX_LENGTH; 65 | } 66 | Wire.endTransmission(); 67 | } 68 | #else 69 | Wire.beginTransmission(0x3c); 70 | Wire.write(control); 71 | Wire.write(dataptr, arg_val); 72 | Wire.endTransmission(); 73 | #endif // I2C_MAX_LENGTH 74 | break; 75 | } 76 | 77 | } 78 | return 1; 79 | } 80 | 81 | #endif // ARDUINO_ARCH_STM32 82 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 39 | 40 | /* 41 | setup page count structure 42 | conditions: page_height <= total_height 43 | */ 44 | void u8g_page_Init(u8g_page_t *p, u8g_uint_t page_height, u8g_uint_t total_height ) { 45 | p->page_height = page_height; 46 | p->total_height = total_height; 47 | p->page = 0; 48 | u8g_page_First(p); 49 | } 50 | 51 | void u8g_page_First(u8g_page_t *p) { 52 | p->page_y0 = 0; 53 | p->page_y1 = p->page_height; 54 | p->page_y1--; 55 | p->page = 0; 56 | } 57 | 58 | uint8_t u8g_page_Next(u8g_page_t * p) { 59 | register u8g_uint_t y1; 60 | p->page_y0 += p->page_height; 61 | if (p->page_y0 >= p->total_height) 62 | return 0; 63 | p->page++; 64 | y1 = p->page_y1; 65 | y1 += p->page_height; 66 | if (y1 >= p->total_height) { 67 | y1 = p->total_height; 68 | y1--; 69 | } 70 | p->page_y1 = y1; 71 | 72 | return 1; 73 | } 74 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 39 | 40 | #if defined(ARDUINO) && !defined(ARDUINO_ARCH_STM32) && !defined(ARDUINO_ARCH_MFL) 41 | 42 | #if ARDUINO < 100 43 | #include 44 | #else 45 | #include 46 | #endif 47 | 48 | void u8g_com_arduino_digital_write(u8g_t *u8g, uint8_t pin_index, uint8_t value) { 49 | uint8_t pin; 50 | pin = u8g->pin_list[pin_index]; 51 | if (pin != U8G_PIN_NONE) 52 | digitalWrite(pin, value); 53 | } 54 | 55 | // this procedure does not set the RW pin 56 | void u8g_com_arduino_assign_pin_output_high(u8g_t *u8g) { 57 | uint8_t i; 58 | // skip the RW pin, which is the last pin in the list 59 | for ( i = 0; i < U8G_PIN_LIST_LEN - 1; i++ ) { 60 | if (u8g->pin_list[i] != U8G_PIN_NONE) { 61 | pinMode(u8g->pin_list[i], OUTPUT); 62 | digitalWrite(u8g->pin_list[i], HIGH); 63 | } 64 | } 65 | } 66 | 67 | #endif // if defined(ARDUINO) && !defined(ARDUINO_ARCH_STM32) && !defined(ARDUINO_ARCH_MFL) 68 | -------------------------------------------------------------------------------- /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 | u8g_uint_t tmp; 40 | u8g_uint_t x, y; 41 | u8g_uint_t dx, dy; 42 | u8g_int_t err; 43 | u8g_int_t ystep; 44 | 45 | uint8_t swapxy = 0; 46 | 47 | // no BBX intersection check at the moment, should be added... 48 | 49 | if (x1 > x2) dx = x1 - x2; else dx = x2 - x1; 50 | if (y1 > y2) dy = y1 - y2; else dy = y2 - y1; 51 | 52 | if (dy > dx) { 53 | swapxy = 1; 54 | tmp = dx; dx = dy; dy = tmp; 55 | tmp = x1; x1 = y1; y1 = tmp; 56 | tmp = x2; x2 = y2; y2 = tmp; 57 | } 58 | if (x1 > x2) { 59 | tmp = x1; x1 = x2; x2 = tmp; 60 | tmp = y1; y1 = y2; y2 = tmp; 61 | } 62 | err = dx >> 1; 63 | if (y2 > y1) ystep = 1; else ystep = -1; 64 | y = y1; 65 | 66 | #ifndef U8G_16BIT 67 | if (x2 == 255) 68 | x2--; 69 | #else 70 | if (x2 == 0xffff) 71 | x2--; 72 | #endif 73 | 74 | for ( x = x1; x <= x2; x++ ) { 75 | if (swapxy == 0) 76 | u8g_DrawPixel(u8g, x, y); 77 | else 78 | u8g_DrawPixel(u8g, y, x); 79 | err -= (uint8_t)dy; 80 | if (err < 0) { 81 | y += (u8g_uint_t)ystep; 82 | err += (u8g_uint_t)dx; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/U8glibPrint.h: -------------------------------------------------------------------------------- 1 | /* 2 | Print.h - Base class that provides print() and println() 3 | Copyright (c) 2008 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | #pragma once 20 | 21 | #include 22 | #include // for size_t 23 | #include 24 | 25 | #include "U8glibPrintable.h" 26 | 27 | #define DEC 10 28 | #define HEX 16 29 | #define OCT 8 30 | #define BIN 2 31 | 32 | class U8glibPrint { 33 | private: 34 | int write_error; 35 | size_t printNumber(unsigned long, uint8_t); 36 | size_t printFloat(double, uint8_t); 37 | protected: 38 | void setWriteError(int err = 1) { write_error = err; } 39 | public: 40 | U8glibPrint() : write_error(0) {} 41 | 42 | int getWriteError() { return write_error; } 43 | void clearWriteError() { setWriteError(0); } 44 | 45 | virtual size_t write(uint8_t) = 0; 46 | size_t write(const char *str) { 47 | 48 | if (str == NULL) return 0; 49 | return write((const uint8_t *)str, strlen(str)); 50 | } 51 | virtual size_t write(const uint8_t *buffer, size_t size); 52 | size_t write(const char *buffer, size_t size) { 53 | return write((const uint8_t *)buffer, size); 54 | } 55 | 56 | size_t print(const char[]); 57 | size_t print(char); 58 | size_t print(unsigned char, int = DEC); 59 | size_t print(int, int = DEC); 60 | size_t print(unsigned int, int = DEC); 61 | size_t print(long, int = DEC); 62 | size_t print(unsigned long, int = DEC); 63 | size_t print(double, int = 2); 64 | size_t print(const U8glibPrintable&); 65 | 66 | size_t println(const char[]); 67 | size_t println(char); 68 | size_t println(unsigned char, int = DEC); 69 | size_t println(int, int = DEC); 70 | size_t println(unsigned int, int = DEC); 71 | size_t println(long, int = DEC); 72 | size_t println(unsigned long, int = DEC); 73 | size_t println(double, int = 2); 74 | size_t println(const U8glibPrintable&); 75 | size_t println(void); 76 | size_t printf(const char *argList, ...); 77 | }; 78 | -------------------------------------------------------------------------------- /src/clib/HAL_example_files/HAL_LCD_defines.h: -------------------------------------------------------------------------------- 1 | /** 2 | * Marlin 3D Printer Firmware 3 | * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] 4 | * 5 | * Based on Sprinter and grbl. 6 | * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | * 21 | */ 22 | 23 | /** 24 | * The U8glib-ARM has multiple hooks in it to facilitate adding ARM/HAL specific 25 | * routines to the library. This file selects the appropriate definition file based 26 | * on the platform being compiled. 27 | * 28 | * The U8glib-ARM system usually selects the appropriate software via a long chain of 29 | * "if this platform then .." terminated by a "if not defined yet then use the default/dummy 30 | * option". As long as the ARM/HAL definition is in place before the start of the chain 31 | * then it's what'll be used. It can't be done after the chain is completed. 32 | * 33 | * The hooks the U8glib-ARM library are all prefaced with "defined(__arm__)". They are: 34 | * u8g.h - enables the U8G_WITH_PINLIST routines 35 | * - just after the data structures are defined and before the chains start, this 36 | * file gets pulled in. Here we define the pointers to the code needed by supporting 37 | * files and here is were we define any custom communication and/or device drivers 38 | * and where we define what drivers will be used. 39 | * u8g_com_io.c - pulls in the "LCD_pin_routines.h" file which contains the low level 40 | * pin setup and pin write routines. 41 | * u8g_delay.c - pulls in the "LCD_delay.h" file which provides the delay functions. 42 | * 43 | * You will also find "defined(__arm__)" is used by Teensy to pull in their custom code. These 44 | * are always buried inside other qualifiers so the ARM/HAL and the Teensy items are independent 45 | * of each other. 46 | */ 47 | #pragma once 48 | 49 | #ifdef ARDUINO_ARCH_SAM 50 | //#include 51 | 52 | #elif defined(IS_32BIT_TEENSY) 53 | //#include 54 | 55 | #elif defined(ARDUINO_ARCH_AVR) 56 | //#include 57 | 58 | #elif defined(TARGET_LPC1768) 59 | #include 60 | 61 | #else 62 | #error "Unsupported Platform!" 63 | #endif 64 | -------------------------------------------------------------------------------- /src/U8glib-HAL.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | U8glib-HAL.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-HAL.h" 39 | 40 | #ifdef U8G_WITH_PINLIST 41 | uint8_t U8GLIB::initSPI(u8g_dev_t *dev, uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset) 42 | { 43 | prepare(); 44 | return u8g_InitSPI(&u8g, dev, sck, mosi, cs, a0, reset); 45 | } 46 | 47 | uint8_t U8GLIB::initHWSPI(u8g_dev_t *dev, uint8_t cs, uint8_t a0, uint8_t reset) 48 | { 49 | prepare(); 50 | return u8g_InitHWSPI(&u8g, dev, cs, a0, reset); 51 | } 52 | 53 | uint8_t U8GLIB::initI2C(u8g_dev_t *dev, uint8_t options) 54 | { 55 | prepare(); 56 | return u8g_InitI2C(&u8g, dev, options); 57 | } 58 | 59 | 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, 60 | uint8_t en, uint8_t cs1, uint8_t cs2, uint8_t di, uint8_t rw, uint8_t reset) 61 | { 62 | prepare(); 63 | return u8g_Init8Bit(&u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset); 64 | } 65 | 66 | uint8_t U8GLIB::init8BitFixedPort(u8g_dev_t *dev, uint8_t en, uint8_t cs, uint8_t di, uint8_t rw, uint8_t reset) 67 | { 68 | prepare(); 69 | return u8g_Init8BitFixedPort(&u8g, dev, en, cs, di, rw, reset); 70 | } 71 | 72 | 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, 73 | uint8_t cs, uint8_t a0, uint8_t wr, uint8_t rd, uint8_t reset) 74 | { 75 | prepare(); 76 | return u8g_InitRW8Bit(&u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, cs, a0, wr, rd, reset); 77 | } 78 | #endif 79 | -------------------------------------------------------------------------------- /src/clib/u8g_com_samd51_hw_spi.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * u8g_com_samd51_hw_spi.cpp 3 | * Universal 8bit Graphics Library 4 | * 5 | * Copyright (c) 2012, olikraus@gmail.com 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without modification, 9 | * are permitted provided that the following conditions are met: 10 | * 11 | * - Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * - Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 30 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | 33 | #ifdef __SAMD51__ 34 | 35 | #include "u8g.h" 36 | #include 37 | 38 | static SPISettings lcdSPIConfig; 39 | 40 | uint8_t u8g_com_samd51_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 41 | switch (msg) { 42 | case U8G_COM_MSG_STOP: 43 | break; 44 | 45 | case U8G_COM_MSG_INIT: 46 | u8g_SetPIOutput(u8g, U8G_PI_CS); 47 | u8g_SetPIOutput(u8g, U8G_PI_A0); 48 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 49 | 50 | u8g_SetPILevel(u8g, U8G_PI_CS, HIGH); 51 | 52 | lcdSPIConfig = SPISettings(SPI_CLOCK_DIV2, MSBFIRST, SPI_MODE0); 53 | SPI.begin(); 54 | break; 55 | 56 | case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1) 57 | u8g_SetPILevel(u8g, U8G_PI_A0, arg_val); 58 | break; 59 | 60 | case U8G_COM_MSG_CHIP_SELECT: // arg_val == 0 means HIGH level of U8G_PI_CS 61 | u8g_SetPILevel(u8g, U8G_PI_CS, arg_val ? LOW : HIGH); 62 | break; 63 | 64 | case U8G_COM_MSG_RESET: 65 | u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 66 | break; 67 | 68 | case U8G_COM_MSG_WRITE_BYTE: 69 | SPI.beginTransaction(lcdSPIConfig); 70 | SPI.transfer(arg_val); 71 | SPI.endTransaction(); 72 | break; 73 | 74 | case U8G_COM_MSG_WRITE_SEQ: 75 | SPI.beginTransaction(lcdSPIConfig); 76 | SPI.transfer((uint8_t *)arg_ptr, arg_val); 77 | SPI.endTransaction(); 78 | break; 79 | } 80 | return 1; 81 | } 82 | 83 | #endif // __SAMD51__ 84 | -------------------------------------------------------------------------------- /src/clib/u8g_com_samd51_st7920_hw_spi.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | * u8g_com_samd51_st7920_hw_spi.cpp 3 | * Universal 8bit Graphics Library 4 | * 5 | * Copyright (c) 2012, olikraus@gmail.com 6 | * All rights reserved. 7 | * 8 | * Redistribution and use in source and binary forms, with or without modification, 9 | * are permitted provided that the following conditions are met: 10 | * 11 | * - Redistributions of source code must retain the above copyright notice, this list 12 | * of conditions and the following disclaimer. 13 | * 14 | * - Redistributions in binary form must reproduce the above copyright notice, this 15 | * list of conditions and the following disclaimer in the documentation and/or other 16 | * materials provided with the distribution. 17 | * 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 19 | * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 20 | * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 21 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 22 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 23 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 24 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 26 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 28 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 30 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | * 32 | * A special SPI interface for ST7920 controller with HW SPI Support 33 | */ 34 | 35 | #ifdef __SAMD51__ 36 | 37 | #include "u8g.h" 38 | #include 39 | 40 | static SPISettings lcdSPIConfig; 41 | 42 | uint8_t u8g_com_samd51_st7920_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 43 | switch (msg) { 44 | case U8G_COM_MSG_STOP: 45 | break; 46 | 47 | case U8G_COM_MSG_INIT: 48 | u8g_SetPIOutput(u8g, U8G_PI_CS); 49 | 50 | u8g_SetPILevel(u8g, U8G_PI_CS, HIGH); 51 | 52 | lcdSPIConfig = SPISettings(SPI_CLOCK_DIV2, MSBFIRST, SPI_MODE0); 53 | SPI.begin(); 54 | break; 55 | 56 | case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1) 57 | u8g_SetPILevel(u8g, U8G_PI_A0, arg_val); 58 | break; 59 | 60 | case U8G_COM_MSG_CHIP_SELECT: // arg_val == 0 means LOW level of U8G_PI_CS 61 | u8g_SetPILevel(u8g, U8G_PI_CS, arg_val ? HIGH : LOW); // (ST7920 has active high CS) 62 | break; 63 | 64 | case U8G_COM_MSG_RESET: 65 | u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 66 | break; 67 | 68 | case U8G_COM_MSG_WRITE_BYTE: 69 | SPI.beginTransaction(lcdSPIConfig); 70 | SPI.transfer(arg_val); 71 | SPI.endTransaction(); 72 | break; 73 | 74 | case U8G_COM_MSG_WRITE_SEQ: 75 | SPI.beginTransaction(lcdSPIConfig); 76 | SPI.transfer((uint8_t*)arg_ptr, arg_val); 77 | SPI.endTransaction(); 78 | break; 79 | } 80 | return 1; 81 | } 82 | 83 | #endif // __SAMD51__ 84 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 37 | 38 | void u8g_SetCursorFont(u8g_t *u8g, const u8g_pgm_uint8_t *cursor_font) { 39 | u8g->cursor_font = cursor_font; 40 | } 41 | 42 | void u8g_SetCursorStyle(u8g_t *u8g, uint8_t encoding) { 43 | u8g->cursor_encoding = encoding; 44 | } 45 | 46 | void u8g_SetCursorColor(u8g_t *u8g, uint8_t fg, uint8_t bg) { 47 | u8g->cursor_bg_color = bg; 48 | u8g->cursor_fg_color = fg; 49 | } 50 | 51 | void u8g_SetCursorPos(u8g_t *u8g, u8g_uint_t cursor_x, u8g_uint_t cursor_y) { 52 | u8g->cursor_x = cursor_x; 53 | u8g->cursor_y = cursor_y; 54 | } 55 | 56 | void u8g_EnableCursor(u8g_t *u8g) { 57 | u8g->cursor_fn = u8g_DrawCursor; 58 | } 59 | 60 | void u8g_DisableCursor(u8g_t *u8g) { 61 | u8g->cursor_fn = (u8g_draw_cursor_fn)0; 62 | } 63 | 64 | void u8g_DrawCursor(u8g_t *u8g) { 65 | const u8g_pgm_uint8_t *font; 66 | uint8_t color; 67 | uint8_t encoding = u8g->cursor_encoding; 68 | 69 | // get current values 70 | color = u8g_GetColorIndex(u8g); 71 | font = u8g->font; 72 | 73 | // draw cursor 74 | u8g->font = u8g->cursor_font; 75 | encoding++; 76 | u8g_SetColorIndex(u8g, u8g->cursor_bg_color); 77 | // 27. Jan 2013: replaced call to u8g_DrawGlyph with call to u8g_draw_glyph 78 | // required, because y adjustment should not happen to the cursor fonts 79 | u8g_draw_glyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding); 80 | encoding--; 81 | u8g_SetColorIndex(u8g, u8g->cursor_fg_color); 82 | // 27. Jan 2013: replaced call to u8g_DrawGlyph with call to u8g_draw_glyph 83 | // required, because y adjustment should not happen to the cursor fonts 84 | // u8g_DrawGlyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding); 85 | u8g_draw_glyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding); 86 | 87 | // restore previous values 88 | u8g->font = font; 89 | u8g_SetColorIndex(u8g, color); 90 | } 91 | -------------------------------------------------------------------------------- /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 | void (*u8g_write_flip_disc_matrix)(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2); 58 | 59 | void u8g_SetFlipDiscCallback(u8g_t *u8g, void (*cb)(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2)) { 60 | u8g_write_flip_disc_matrix = cb; 61 | } 62 | 63 | uint8_t u8g_dev_flipdisc_2x7_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) { 64 | switch (msg) { 65 | case U8G_DEV_MSG_INIT: 66 | break; 67 | case U8G_DEV_MSG_STOP: 68 | break; 69 | case U8G_DEV_MSG_PAGE_NEXT: { 70 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 71 | 72 | // current page: pb->p.page 73 | // ptr to the buffer: pb->buf 74 | 75 | (*u8g_write_flip_disc_matrix)(0, pb->p.page, WIDTH, pb->buf, (uint8_t *)(pb->buf) + WIDTH); 76 | } 77 | break; 78 | case U8G_DEV_MSG_CONTRAST: 79 | return 1; 80 | } 81 | return u8g_dev_pb14v1_base_fn(u8g, dev, msg, arg); 82 | } 83 | 84 | uint8_t u8g_dev_flipdisc_2x7_bw_buf[WIDTH * 2] U8G_NOCOMMON; 85 | u8g_pb_t u8g_dev_flipdisc_2x7_bw_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_flipdisc_2x7_bw_buf}; 86 | u8g_dev_t u8g_dev_flipdisc_2x7 = { u8g_dev_flipdisc_2x7_bw_fn, &u8g_dev_flipdisc_2x7_bw_pb, u8g_com_null_fn }; 87 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 40 | 41 | #ifdef U8G_CYPRESS_PSOC5 42 | 43 | #include 44 | 45 | static uint8 dc = 0; // need to store whether next write is data or command 46 | 47 | uint8_t u8g_com_psoc5_ssd_hw_parallel_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 48 | switch (msg) { 49 | case U8G_COM_MSG_STOP: 50 | // stop the device 51 | GraphicLCDIntf_Stop(); 52 | break; 53 | 54 | case U8G_COM_MSG_INIT: 55 | // init hardware interfaces, timers, gpios, ... 56 | GraphicLCDIntf_Init(); 57 | break; 58 | 59 | case U8G_COM_MSG_ADDRESS: 60 | // switch from cmd (arg_val = 0) to data mode (arg_val = 1) or vice versa 61 | dc = arg_val; 62 | break; 63 | 64 | case U8G_COM_MSG_CHIP_SELECT: 65 | // done by the hardware 66 | break; 67 | 68 | case U8G_COM_MSG_RESET: 69 | // toggle the reset pin of the display by value in arg_val 70 | nRES_Write(0); 71 | u8g_10MicroDelay(); 72 | nRES_Write(1); 73 | break; 74 | 75 | case U8G_COM_MSG_WRITE_BYTE: 76 | // write byte to the device 77 | GraphicLCDIntf_Write8(dc, arg_val); 78 | break; 79 | 80 | case U8G_COM_MSG_WRITE_SEQ: 81 | case U8G_COM_MSG_WRITE_SEQ_P: { 82 | // write a sequence of bytes to the device 83 | register uint8_t *ptr = arg_ptr; 84 | while (arg_val-- > 0) { 85 | GraphicLCDIntf_Write8(dc, *ptr++); 86 | } 87 | } 88 | break; 89 | 90 | } 91 | return 1; 92 | } 93 | 94 | #else // ifdef U8G_CYPRESS_PSOC5 95 | 96 | uint8_t u8g_com_psoc5_ssd_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 97 | return 1; 98 | } 99 | 100 | #endif // ifdef U8G_CYPRESS_PSOC5 101 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 41 | 42 | // interpret b as a monochrome bit pattern, write value 15 for high bit and value 0 for a low bit 43 | // topbit (msb) is sent last 44 | // example: b = 0x083 will send 0xff, 0x00, 0x00, 0xf0 45 | uint8_t u8g_WriteByteBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b) { 46 | static uint8_t buf[4]; 47 | static uint8_t map[4] = { 0, 0x00f, 0x0f0, 0x0ff }; 48 | buf [3] = map[b & 3]; 49 | b >>= 2; 50 | buf [2] = map[b & 3]; 51 | b >>= 2; 52 | buf [1] = map[b & 3]; 53 | b >>= 2; 54 | buf [0] = map[b & 3]; 55 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ, 4, buf); 56 | } 57 | 58 | uint8_t u8g_WriteSequenceBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr) { 59 | do { 60 | if (u8g_WriteByteBWTo16GrDevice(u8g, dev, *ptr++) == 0) 61 | return 0; 62 | cnt--; 63 | } while (cnt != 0); 64 | return 1; 65 | } 66 | 67 | // interpret b as a 4L bit pattern, write values 0x000, 0x004, 0x008, 0x00c 68 | uint8_t u8g_WriteByte4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b) { 69 | // static uint8_t map[16] = { 0x000, 0x004, 0x008, 0x00c, 0x040, 0x044, 0x048, 0x04c, 0x080, 0x084, 0x088, 0x08c, 0x0c0, 0x0c4, 0x0c8, 0x0cc}; 70 | // static uint8_t map[16] = { 0x000, 0x004, 0x00a, 0x00f, 0x040, 0x044, 0x04a, 0x04f, 0x0a0, 0x0a4, 0x0aa, 0x0af, 0x0f0, 0x0f4, 0x0fa, 0x0ff}; 71 | static uint8_t map[16] = { 0x000, 0x040, 0x0a0, 0x0f0, 0x004, 0x044, 0x0a4, 0x0f4, 0x00a, 0x04a, 0x0aa, 0x0fa, 0x00f, 0x04f, 0x0af, 0x0ff}; 72 | uint8_t bb; 73 | bb = b; 74 | bb &= 15; 75 | b >>= 4; 76 | dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, map[bb], NULL); 77 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, map[b], NULL); 78 | } 79 | 80 | uint8_t u8g_WriteSequence4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr) { 81 | do { 82 | if (u8g_WriteByte4LTo16GrDevice(u8g, dev, *ptr++) == 0) 83 | return 0; 84 | cnt--; 85 | } while (cnt != 0); 86 | return 1; 87 | } 88 | -------------------------------------------------------------------------------- /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 | Assumes, that 35 | MOSI is at PORTB, Pin 3 36 | and 37 | SCK is at PORTB, Pin 5 38 | 39 | Update for ATOMIC operation done (01 Jun 2013) 40 | U8G_ATOMIC_OR(ptr, val) 41 | U8G_ATOMIC_AND(ptr, val) 42 | U8G_ATOMIC_START() 43 | U8G_ATOMIC_END() 44 | 45 | */ 46 | 47 | #include "u8g.h" 48 | 49 | #ifdef U8G_RASPBERRY_PI 50 | 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | 57 | uint8_t u8g_com_raspberrypi_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 58 | switch (msg) { 59 | case U8G_COM_MSG_STOP: 60 | break; 61 | 62 | case U8G_COM_MSG_INIT: 63 | // check wiringPi setup 64 | if (wiringPiSetup() == -1) { 65 | printf("wiringPi-Error\n"); 66 | exit(1); 67 | } 68 | 69 | if (wiringPiSPISetup(0, 100000) < 0) { 70 | printf("Unable to open SPI device 0: %s\n", strerror(errno)); 71 | exit(1); 72 | } 73 | 74 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 75 | u8g_SetPIOutput(u8g, U8G_PI_A0); 76 | 77 | break; 78 | 79 | case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1) 80 | u8g_SetPILevel(u8g, U8G_PI_A0, arg_val); 81 | break; 82 | 83 | case U8G_COM_MSG_CHIP_SELECT: 84 | // Done by the SPI hardware 85 | break; 86 | 87 | case U8G_COM_MSG_RESET: 88 | u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 89 | break; 90 | 91 | case U8G_COM_MSG_WRITE_BYTE: 92 | wiringPiSPIDataRW(0, &arg_val, 1); 93 | break; 94 | 95 | case U8G_COM_MSG_WRITE_SEQ: 96 | wiringPiSPIDataRW(0, arg_ptr, arg_val); 97 | break; 98 | 99 | case U8G_COM_MSG_WRITE_SEQ_P: 100 | wiringPiSPIDataRW(0, arg_ptr, arg_val); 101 | break; 102 | } 103 | return 1; 104 | } 105 | 106 | #else // ifdef U8G_RASPBERRY_PI 107 | 108 | uint8_t u8g_com_raspberrypi_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 109 | return 1; 110 | } 111 | 112 | #endif // ifdef U8G_RASPBERRY_PI 113 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 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 | ============ BSD License for U8glib Code ============ 51 | 52 | Universal 8bit Graphics Library (http://code.google.com/p/u8glib/) 53 | 54 | Copyright (c) 2011, olikraus@gmail.com 55 | All rights reserved. 56 | 57 | Redistribution and use in source and binary forms, with or without modification, 58 | are permitted provided that the following conditions are met: 59 | 60 | * Redistributions of source code must retain the above copyright notice, this list 61 | of conditions and the following disclaimer. 62 | 63 | * Redistributions in binary form must reproduce the above copyright notice, this 64 | list of conditions and the following disclaimer in the documentation and/or other 65 | materials provided with the distribution. 66 | 67 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 68 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 69 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 70 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 71 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 72 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 73 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 74 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 75 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 76 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 77 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 78 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 79 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 80 | -------------------------------------------------------------------------------- /src/clib/HAL_example_files/LCD_pin_routines.c.example: -------------------------------------------------------------------------------- 1 | /** 2 | * Marlin 3D Printer Firmware 3 | * Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] 4 | * 5 | * Based on Sprinter and grbl. 6 | * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | * 21 | */ 22 | 23 | /** 24 | * Low level pin manipulation routines - used by all the drivers. 25 | * 26 | * These are based on the LPC1768 pinMode, digitalRead & digitalWrite routines. 27 | * 28 | * Couldn't just call exact copies because the overhead killed the LCD update speed 29 | * With an intermediate level the softspi was running in the 10-20kHz range which 30 | * resulted in using about about 25% of the CPU's time. 31 | */ 32 | 33 | #ifdef TARGET_LPC1768 34 | 35 | #include 36 | #include 37 | #include "src/core/macros.h" 38 | //#include "pinmapping.h" 39 | 40 | #define LPC_PORT_OFFSET (0x0020) 41 | #define LPC_PIN(pin) (1UL << pin) 42 | #define LPC_GPIO(port) ((volatile LPC_GPIO_TypeDef *)(LPC_GPIO0_BASE + LPC_PORT_OFFSET * port)) 43 | 44 | #define INPUT 0 45 | #define OUTPUT 1 46 | #define INPUT_PULLUP 2 47 | 48 | uint8_t LPC1768_PIN_PORT(const uint8_t pin); 49 | uint8_t LPC1768_PIN_PIN(const uint8_t pin); 50 | 51 | #ifdef __cplusplus 52 | extern "C" { 53 | #endif 54 | 55 | // IO functions 56 | // As defined by Arduino INPUT(0x0), OUPUT(0x1), INPUT_PULLUP(0x2) 57 | void pinMode_LCD(uint8_t pin, uint8_t mode) { 58 | #define LPC1768_PIN_PORT(pin) ((uint8_t)((pin >> 5) & 0b111)) 59 | #define LPC1768_PIN_PIN(pin) ((uint8_t)(pin & 0b11111)) 60 | PINSEL_CFG_Type config = { LPC1768_PIN_PORT(pin), 61 | LPC1768_PIN_PIN(pin), 62 | PINSEL_FUNC_0, 63 | PINSEL_PINMODE_TRISTATE, 64 | PINSEL_PINMODE_NORMAL }; 65 | switch (mode) { 66 | case INPUT: 67 | LPC_GPIO(LPC1768_PIN_PORT(pin))->FIODIR &= ~LPC_PIN(LPC1768_PIN_PIN(pin)); 68 | PINSEL_ConfigPin(&config); 69 | break; 70 | case OUTPUT: 71 | LPC_GPIO(LPC1768_PIN_PORT(pin))->FIODIR |= LPC_PIN(LPC1768_PIN_PIN(pin)); 72 | PINSEL_ConfigPin(&config); 73 | break; 74 | case INPUT_PULLUP: 75 | LPC_GPIO(LPC1768_PIN_PORT(pin))->FIODIR &= ~LPC_PIN(LPC1768_PIN_PIN(pin)); 76 | config.Pinmode = PINSEL_PINMODE_PULLUP; 77 | PINSEL_ConfigPin(&config); 78 | break; 79 | default: 80 | break; 81 | } 82 | } 83 | 84 | void u8g_SetPinOutput(uint8_t internal_pin_number) { 85 | pinMode_LCD(internal_pin_number, 1); // OUTPUT 86 | } 87 | 88 | void u8g_SetPinInput(uint8_t internal_pin_number) { 89 | pinMode_LCD(internal_pin_number, 0); // INPUT 90 | } 91 | 92 | void u8g_SetPinLevel(uint8_t pin, uint8_t pin_status) { 93 | #define LPC1768_PIN_PORT(pin) ((uint8_t)((pin >> 5) & 0b111)) 94 | #define LPC1768_PIN_PIN(pin) ((uint8_t)(pin & 0b11111)) 95 | if (pin_status) 96 | LPC_GPIO(LPC1768_PIN_PORT(pin))->FIOSET = LPC_PIN(LPC1768_PIN_PIN(pin)); 97 | else 98 | LPC_GPIO(LPC1768_PIN_PORT(pin))->FIOCLR = LPC_PIN(LPC1768_PIN_PIN(pin)); 99 | } 100 | 101 | uint8_t u8g_GetPinLevel(uint8_t pin) { 102 | #define LPC1768_PIN_PORT(pin) ((uint8_t)((pin >> 5) & 0b111)) 103 | #define LPC1768_PIN_PIN(pin) ((uint8_t)(pin & 0b11111)) 104 | return (uint32_t)LPC_GPIO(LPC1768_PIN_PORT(pin))->FIOPIN & LPC_PIN(LPC1768_PIN_PIN(pin)) ? 1 : 0; 105 | } 106 | 107 | #ifdef __cplusplus 108 | } 109 | #endif 110 | 111 | #endif 112 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 40 | 41 | #define WIDTH 122 42 | #define HEIGHT 32 43 | #define PAGE_HEIGHT 8 44 | 45 | static const uint8_t u8g_dev_sbn1661_122x32_init_seq[] PROGMEM = { 46 | U8G_ESC_CS(0), // disable chip 47 | U8G_ESC_ADR(0), // instruction mode 48 | U8G_ESC_RST(15), // do reset low pulse with (15*16)+2 milliseconds 49 | U8G_ESC_CS(1), // enable chip 1 50 | 0x0af, // display on 51 | 0x0c0, // display start at line 0 52 | 0x0a0, // a0: ADC forward, a1: ADC reverse 53 | 0x0a9, // a8: 1/16, a9: 1/32 duty 54 | U8G_ESC_CS(2), // enable chip 2 55 | 0x0af, // display on 56 | 0x0c0, // display start at line 0 57 | 0x0a0, // a0: ADC forward, a1: ADC reverse 58 | 0x0a9, // a8: 1/16, a9: 1/32 duty 59 | 60 | U8G_ESC_CS(0), // disable chip 61 | 62 | U8G_ESC_END // end of sequence 63 | }; 64 | 65 | uint8_t u8g_dev_sbn1661_122x32_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) { 66 | switch (msg) { 67 | case U8G_DEV_MSG_INIT: 68 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE); 69 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_sbn1661_122x32_init_seq); 70 | break; 71 | case U8G_DEV_MSG_STOP: 72 | break; 73 | case U8G_DEV_MSG_PAGE_NEXT: { 74 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 75 | 76 | u8g_SetAddress(u8g, dev, 0); // command mode 77 | u8g_SetChipSelect(u8g, dev, 1); 78 | u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); // select current page (SBN1661/SED1520) 79 | u8g_WriteByte(u8g, dev, 0x000 ); // set X address 80 | u8g_SetAddress(u8g, dev, 1); // data mode 81 | u8g_WriteSequence(u8g, dev, WIDTH / 2, pb->buf); 82 | 83 | u8g_SetAddress(u8g, dev, 0); // command mode 84 | u8g_SetChipSelect(u8g, dev, 2); 85 | u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); // select current page (SBN1661/SED1520) 86 | u8g_WriteByte(u8g, dev, 0x000 ); // set X address 87 | u8g_SetAddress(u8g, dev, 1); // data mode 88 | u8g_WriteSequence(u8g, dev, WIDTH / 2, WIDTH / 2 + (uint8_t *)pb->buf); 89 | 90 | u8g_SetChipSelect(u8g, dev, 0); 91 | 92 | } 93 | break; 94 | case U8G_DEV_MSG_CONTRAST: 95 | break; 96 | } 97 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 98 | } 99 | 100 | // u8g_com_arduino_sw_spi_fn does not work, too fast??? 101 | U8G_PB_DEV(u8g_dev_sbn1661_122x32, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_sbn1661_122x32_fn, u8g_com_arduino_no_en_parallel_fn); 102 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 37 | 38 | #ifdef __AVR__ 39 | 40 | static void u8g_atmega_sw_spi_shift_out(u8g_t *u8g, uint8_t val) { 41 | uint8_t i = 8; 42 | do { 43 | u8g_SetPILevel(u8g, U8G_PI_MOSI, val & 128 ); 44 | val <<= 1; 45 | u8g_SetPILevel(u8g, U8G_PI_SCK, 1 ); 46 | u8g_MicroDelay(); // 15 Aug 2012: added for high speed uC 47 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 48 | u8g_MicroDelay(); // 15 Aug 2012: added for high speed uC 49 | i--; 50 | } while (i != 0); 51 | } 52 | 53 | uint8_t u8g_com_atmega_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 54 | switch (msg) { 55 | case U8G_COM_MSG_INIT: 56 | u8g_SetPIOutput(u8g, U8G_PI_SCK); 57 | u8g_SetPIOutput(u8g, U8G_PI_MOSI); 58 | u8g_SetPIOutput(u8g, U8G_PI_A0); 59 | u8g_SetPIOutput(u8g, U8G_PI_CS); 60 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 61 | 62 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 63 | u8g_SetPILevel(u8g, U8G_PI_MOSI, 0 ); 64 | u8g_SetPILevel(u8g, U8G_PI_CS, 1 ); 65 | u8g_SetPILevel(u8g, U8G_PI_A0, 0); 66 | break; 67 | 68 | case U8G_COM_MSG_STOP: 69 | break; 70 | 71 | case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1) 72 | u8g_SetPILevel(u8g, U8G_PI_A0, arg_val); 73 | break; 74 | 75 | case U8G_COM_MSG_CHIP_SELECT: 76 | 77 | if (arg_val == 0) { 78 | // disable 79 | u8g_SetPILevel(u8g, U8G_PI_CS, 1); 80 | } 81 | else { 82 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 83 | // enable 84 | u8g_SetPILevel(u8g, U8G_PI_CS, 0); // CS = 0 (low active) 85 | } 86 | break; 87 | 88 | case U8G_COM_MSG_RESET: 89 | u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 90 | break; 91 | 92 | case U8G_COM_MSG_WRITE_BYTE: 93 | u8g_atmega_sw_spi_shift_out(u8g, arg_val); 94 | break; 95 | 96 | case U8G_COM_MSG_WRITE_SEQ: { 97 | register uint8_t *ptr = arg_ptr; 98 | while (arg_val > 0) { 99 | u8g_atmega_sw_spi_shift_out(u8g, *ptr++); 100 | arg_val--; 101 | } 102 | } 103 | break; 104 | 105 | case U8G_COM_MSG_WRITE_SEQ_P: { 106 | register uint8_t *ptr = arg_ptr; 107 | while (arg_val > 0) { 108 | u8g_atmega_sw_spi_shift_out(u8g, u8g_pgm_read(ptr)); 109 | ptr++; 110 | arg_val--; 111 | } 112 | } 113 | break; 114 | } 115 | return 1; 116 | } 117 | 118 | #else // ifdef __AVR__ 119 | 120 | uint8_t u8g_com_atmega_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 121 | return 1; 122 | } 123 | 124 | #endif // ifdef __AVR__ 125 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 40 | 41 | #define WIDTH 128 42 | #define HEIGHT 64 43 | #define PAGE_HEIGHT 8 44 | 45 | uint8_t u8g_dev_gprof_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); 46 | 47 | uint8_t u8g_pb_dev_gprof_buf[WIDTH]; 48 | u8g_pb_t u8g_pb_dev_gprof = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_pb_dev_gprof_buf }; 49 | 50 | u8g_dev_t u8g_dev_gprof = { u8g_dev_gprof_fn, &u8g_pb_dev_gprof, NULL }; 51 | 52 | uint8_t u8g_dev_gprof_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) { 53 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 54 | 55 | switch (msg) { 56 | case U8G_DEV_MSG_INIT: 57 | break; 58 | case U8G_DEV_MSG_STOP: 59 | break; 60 | case U8G_DEV_MSG_PAGE_FIRST: 61 | u8g_pb_Clear(pb); 62 | u8g_page_First(&(pb->p)); 63 | break; 64 | case U8G_DEV_MSG_PAGE_NEXT: 65 | /* 66 | { 67 | uint8_t i, j; 68 | uint8_t page_height; 69 | page_height = pb->p.page_y1; 70 | page_height -= pb->p.page_y0; 71 | page_height++; 72 | for( j = 0; j < page_height; j++ ) 73 | { 74 | printf("%02d ", j); 75 | for( i = 0; i < WIDTH; i++ ) 76 | { 77 | if ( (u8g_pb_dev_stdout_buf[i] & (1<p)) == 0) 87 | // printf("\n"); 88 | return 0; 89 | u8g_pb_Clear(pb); 90 | break; 91 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 92 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: { 93 | u8g_dev_arg_bbx_t *bbx = (u8g_dev_arg_bbx_t *)arg; 94 | u8g_uint_t x2, y2; 95 | 96 | y2 = bbx->y; 97 | y2 += bbx->h; 98 | y2--; 99 | 100 | if (u8g_pb_IsYIntersection(pb, bbx->y, y2) == 0) 101 | return 0; 102 | 103 | // maybe this one can be skiped... probability is very high to have an intersection, so it would be ok to always return 1 104 | x2 = bbx->x; 105 | x2 += bbx->w; 106 | x2--; 107 | 108 | if (u8g_pb_IsXIntersection(pb, bbx->x, x2) == 0) 109 | return 0; 110 | } 111 | return 1; 112 | #endif // ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 113 | case U8G_DEV_MSG_GET_PAGE_BOX: 114 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 115 | break; 116 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 117 | break; 118 | case U8G_DEV_MSG_SET_XY_CB: 119 | break; 120 | } 121 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 122 | } 123 | -------------------------------------------------------------------------------- /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 | ADDRESS = 0 (Command Mode) 35 | 0x03f Display On 36 | 0x0c0 Start Display at line 0 37 | 0x040 | y write to y address (y:0..63) 38 | 0x0b8 | x write to page [0..7] 39 | 40 | u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset) 41 | u8g_Init8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16, U8G_PIN_NONE) 42 | 43 | */ 44 | 45 | #include "u8g.h" 46 | 47 | #define WIDTH 128 48 | #define HEIGHT 64 49 | #define PAGE_HEIGHT 8 50 | 51 | static const uint8_t u8g_dev_ks0108_128x64_init_seq[] PROGMEM = { 52 | U8G_ESC_CS(0), // disable chip 53 | U8G_ESC_ADR(0), // instruction mode 54 | U8G_ESC_RST(1), // do reset low pulse with (1*16)+2 milliseconds 55 | U8G_ESC_CS(1), // enable chip 1 56 | 0x03f, // display on 57 | 0x0c0, // start at line 0 58 | U8G_ESC_DLY(20), // delay 20 ms 59 | U8G_ESC_CS(2), // enable chip 2 60 | 0x03f, // display on 61 | 0x0c0, // start at line 0 62 | U8G_ESC_DLY(20), // delay 20 ms 63 | U8G_ESC_CS(0), // disable all chips 64 | U8G_ESC_END // end of sequence 65 | }; 66 | 67 | uint8_t u8g_dev_ks0108_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) { 68 | 69 | switch (msg) { 70 | case U8G_DEV_MSG_INIT: 71 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE); 72 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_ks0108_128x64_init_seq); 73 | break; 74 | case U8G_DEV_MSG_STOP: 75 | break; 76 | case U8G_DEV_MSG_PAGE_NEXT: { 77 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 78 | 79 | u8g_SetAddress(u8g, dev, 0); // command mode 80 | u8g_SetChipSelect(u8g, dev, 2); 81 | u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); // select current page (KS0108b) 82 | u8g_WriteByte(u8g, dev, 0x040 ); // set address 0 83 | u8g_SetAddress(u8g, dev, 1); // data mode 84 | u8g_WriteSequence(u8g, dev, 64, pb->buf); 85 | u8g_SetChipSelect(u8g, dev, 0); 86 | 87 | u8g_SetAddress(u8g, dev, 0); // command mode 88 | u8g_SetChipSelect(u8g, dev, 1); 89 | u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); // select current page (KS0108b) 90 | u8g_WriteByte(u8g, dev, 0x040 ); // set address 0 91 | u8g_SetAddress(u8g, dev, 1); // data mode 92 | u8g_WriteSequence(u8g, dev, 64, 64 + (uint8_t *)pb->buf); 93 | u8g_SetChipSelect(u8g, dev, 0); 94 | 95 | } 96 | break; 97 | } 98 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 99 | } 100 | 101 | U8G_PB_DEV(u8g_dev_ks0108_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ks0108_128x64_fn, U8G_COM_PARALLEL); 102 | U8G_PB_DEV(u8g_dev_ks0108_128x64_fast, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ks0108_128x64_fn, U8G_COM_FAST_PARALLEL); 103 | -------------------------------------------------------------------------------- /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 | #ifdef U8G_WITH_PINLIST 39 | 40 | static void u8g_sw_spi_shift_out(uint8_t dataPin, uint8_t clockPin, uint8_t val) { 41 | uint8_t i = 8; 42 | do { 43 | if (val & 128) 44 | u8g_SetPinLevel(dataPin, 1); 45 | else 46 | u8g_SetPinLevel(dataPin, 0); 47 | val <<= 1; 48 | u8g_MicroDelay(); // 23 Sep 2012 49 | // delay(1); 50 | u8g_SetPinLevel(clockPin, 1); 51 | u8g_MicroDelay(); // 23 Sep 2012 52 | // delay(1); 53 | u8g_SetPinLevel(clockPin, 0); 54 | u8g_MicroDelay(); // 23 Sep 2012 55 | // delay(1); 56 | i--; 57 | } while (i != 0); 58 | } 59 | 60 | uint8_t u8g_com_std_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 61 | switch (msg) { 62 | case U8G_COM_MSG_INIT: 63 | u8g_SetPIOutput(u8g, U8G_PI_SCK); 64 | u8g_SetPIOutput(u8g, U8G_PI_MOSI); 65 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 66 | u8g_SetPIOutput(u8g, U8G_PI_CS); 67 | u8g_SetPIOutput(u8g, U8G_PI_A0); 68 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0); 69 | u8g_SetPILevel(u8g, U8G_PI_MOSI, 0); 70 | break; 71 | 72 | case U8G_COM_MSG_STOP: 73 | break; 74 | 75 | case U8G_COM_MSG_RESET: 76 | u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 77 | break; 78 | 79 | case U8G_COM_MSG_CHIP_SELECT: 80 | if (arg_val == 0) { 81 | // disable 82 | u8g_SetPILevel(u8g, U8G_PI_CS, 1); 83 | } 84 | else { 85 | // enable 86 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0); 87 | u8g_SetPILevel(u8g, U8G_PI_CS, 0); 88 | } 89 | break; 90 | 91 | case U8G_COM_MSG_WRITE_BYTE: 92 | u8g_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], arg_val); 93 | break; 94 | 95 | case U8G_COM_MSG_WRITE_SEQ: { 96 | register uint8_t *ptr = arg_ptr; 97 | while (arg_val > 0) { 98 | u8g_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], *ptr++); 99 | arg_val--; 100 | } 101 | } 102 | break; 103 | 104 | case U8G_COM_MSG_WRITE_SEQ_P: { 105 | register uint8_t *ptr = arg_ptr; 106 | while (arg_val > 0) { 107 | u8g_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], u8g_pgm_read(ptr)); 108 | ptr++; 109 | arg_val--; 110 | } 111 | } 112 | break; 113 | 114 | case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1) 115 | u8g_SetPILevel(u8g, U8G_PI_A0, arg_val); 116 | break; 117 | } 118 | return 1; 119 | } 120 | 121 | #else // ifdef U8G_WITH_PINLIST 122 | 123 | uint8_t u8g_com_std_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 124 | return 1; 125 | } 126 | 127 | #endif // ifdef U8G_WITH_PINLIST 128 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 40 | #include 41 | 42 | void u8g_pb8v2_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) { 43 | b->buf = buf; 44 | b->width = width; 45 | u8g_pb_Clear(b); 46 | } 47 | 48 | void u8g_pb8v2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) { 49 | register uint8_t mask; 50 | uint8_t *ptr = b->buf; 51 | y -= b->p.page_y0; 52 | mask = 0x03; 53 | y &= 0x03; 54 | y <<= 1; 55 | mask <<= y; 56 | mask ^= 0xff; 57 | color_index &= 3; 58 | color_index <<= y; 59 | ptr += x; 60 | *ptr &= mask; 61 | *ptr |= color_index; 62 | } 63 | 64 | void u8g_pb8v2_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) { 65 | if (arg_pixel->y < b->p.page_y0) 66 | return; 67 | if (arg_pixel->y > b->p.page_y1) 68 | return; 69 | if (arg_pixel->x >= b->width) 70 | return; 71 | u8g_pb8v2_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 72 | } 73 | 74 | void u8g_pb8v2_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) { 75 | register uint8_t pixel = arg_pixel->pixel; 76 | do { 77 | if (pixel & 128) 78 | u8g_pb8v2_SetPixel(b, arg_pixel); 79 | switch (arg_pixel->dir) { 80 | case 0: arg_pixel->x++; break; 81 | case 1: arg_pixel->y++; break; 82 | case 2: arg_pixel->x--; break; 83 | case 3: arg_pixel->y--; break; 84 | } 85 | pixel <<= 1; 86 | } while (pixel != 0); 87 | 88 | } 89 | 90 | uint8_t u8g_dev_pb8v2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) { 91 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 92 | switch (msg) { 93 | case U8G_DEV_MSG_SET_8PIXEL: 94 | if (u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg)) 95 | u8g_pb8v2_Set8PixelStd(pb, (u8g_dev_arg_pixel_t *)arg); 96 | break; 97 | case U8G_DEV_MSG_SET_PIXEL: 98 | u8g_pb8v2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 99 | break; 100 | case U8G_DEV_MSG_INIT: 101 | break; 102 | case U8G_DEV_MSG_STOP: 103 | break; 104 | case U8G_DEV_MSG_PAGE_FIRST: 105 | u8g_pb_Clear(pb); 106 | u8g_page_First(&(pb->p)); 107 | break; 108 | case U8G_DEV_MSG_PAGE_NEXT: 109 | if (u8g_page_Next(&(pb->p)) == 0) 110 | return 0; 111 | u8g_pb_Clear(pb); 112 | break; 113 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 114 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 115 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 116 | #endif 117 | case U8G_DEV_MSG_GET_PAGE_BOX: 118 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 119 | break; 120 | case U8G_DEV_MSG_GET_WIDTH: 121 | *((u8g_uint_t *)arg) = pb->width; 122 | break; 123 | case U8G_DEV_MSG_GET_HEIGHT: 124 | *((u8g_uint_t *)arg) = pb->p.total_height; 125 | break; 126 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 127 | break; 128 | case U8G_DEV_MSG_SET_XY_CB: 129 | break; 130 | case U8G_DEV_MSG_GET_MODE: 131 | return U8G_MODE_GRAY2BIT; 132 | } 133 | return 1; 134 | } 135 | -------------------------------------------------------------------------------- /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 | #if defined(ARDUINO) && !defined(ARDUINO_ARCH_STM32) && !defined(ARDUINO_ARCH_MFL) 39 | 40 | #if ARDUINO < 100 41 | #include 42 | #else 43 | #include 44 | #endif 45 | 46 | void u8g_arduino_sw_spi_shift_out(uint8_t dataPin, uint8_t clockPin, uint8_t val) { 47 | uint8_t i = 8; 48 | do { 49 | if (val & 128) 50 | digitalWrite(dataPin, HIGH); 51 | else 52 | digitalWrite(dataPin, LOW); 53 | val <<= 1; 54 | u8g_MicroDelay(); // 23 Sep 2012 55 | // delay(1); 56 | digitalWrite(clockPin, HIGH); 57 | u8g_MicroDelay(); // 23 Sep 2012 58 | // delay(1); 59 | digitalWrite(clockPin, LOW); 60 | u8g_MicroDelay(); // 23 Sep 2012 61 | // delay(1); 62 | i--; 63 | } while (i != 0); 64 | } 65 | 66 | uint8_t u8g_com_arduino_std_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 67 | switch (msg) { 68 | case U8G_COM_MSG_INIT: 69 | u8g_com_arduino_assign_pin_output_high(u8g); 70 | u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW); 71 | u8g_com_arduino_digital_write(u8g, U8G_PI_MOSI, LOW); 72 | break; 73 | 74 | case U8G_COM_MSG_STOP: 75 | break; 76 | 77 | case U8G_COM_MSG_RESET: 78 | if (u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE) 79 | u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); 80 | break; 81 | 82 | case U8G_COM_MSG_CHIP_SELECT: 83 | if (arg_val == 0) { 84 | // disable 85 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); 86 | } 87 | else { 88 | // enable 89 | u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW); 90 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW); 91 | } 92 | break; 93 | 94 | case U8G_COM_MSG_WRITE_BYTE: 95 | u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], arg_val); 96 | break; 97 | 98 | case U8G_COM_MSG_WRITE_SEQ: { 99 | register uint8_t *ptr = arg_ptr; 100 | while (arg_val > 0) { 101 | u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], *ptr++); 102 | arg_val--; 103 | } 104 | } 105 | break; 106 | 107 | case U8G_COM_MSG_WRITE_SEQ_P: { 108 | register uint8_t *ptr = arg_ptr; 109 | while (arg_val > 0) { 110 | u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], u8g_pgm_read(ptr)); 111 | ptr++; 112 | arg_val--; 113 | } 114 | } 115 | break; 116 | 117 | case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1) 118 | u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val); 119 | break; 120 | } 121 | return 1; 122 | } 123 | 124 | #else /* ARDUINO */ 125 | 126 | uint8_t u8g_com_arduino_std_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 127 | return 1; 128 | } 129 | 130 | #endif /* ARDUINO */ 131 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 37 | 38 | void u8g_DrawHBitmap(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, const uint8_t *bitmap) { 39 | while (cnt > 0) { 40 | u8g_Draw8Pixel(u8g, x, y, 0, *bitmap); 41 | bitmap++; 42 | cnt--; 43 | x += 8; 44 | } 45 | } 46 | 47 | 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) { 48 | if (u8g_IsBBXIntersection(u8g, x, y, cnt * 8, h) == 0) 49 | return; 50 | while (h > 0) { 51 | u8g_DrawHBitmap(u8g, x, y, cnt, bitmap); 52 | bitmap += cnt; 53 | y++; 54 | h--; 55 | } 56 | } 57 | 58 | void u8g_DrawHBitmapP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, const u8g_pgm_uint8_t *bitmap) { 59 | while (cnt > 0) { 60 | u8g_Draw8Pixel(u8g, x, y, 0, u8g_pgm_read(bitmap)); 61 | bitmap++; 62 | cnt--; 63 | x += 8; 64 | } 65 | } 66 | 67 | 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) { 68 | if (u8g_IsBBXIntersection(u8g, x, y, cnt * 8, h) == 0) 69 | return; 70 | while (h > 0) { 71 | u8g_DrawHBitmapP(u8g, x, y, cnt, bitmap); 72 | bitmap += cnt; 73 | y++; 74 | h--; 75 | } 76 | } 77 | 78 | //========================================================================= 79 | 80 | static void u8g_DrawHXBM(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, const uint8_t *bitmap) { 81 | uint8_t d; 82 | x += 7; 83 | while (w >= 8) { 84 | u8g_Draw8Pixel(u8g, x, y, 2, *bitmap); 85 | bitmap++; 86 | w -= 8; 87 | x += 8; 88 | } 89 | if (w > 0) { 90 | d = *bitmap; 91 | x -= 7; 92 | do { 93 | if (d & 1) 94 | u8g_DrawPixel(u8g, x, y); 95 | x++; 96 | w--; 97 | d >>= 1; 98 | } while (w > 0); 99 | } 100 | } 101 | 102 | 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) { 103 | u8g_uint_t b; 104 | b = w; 105 | b += 7; 106 | b >>= 3; 107 | 108 | if (u8g_IsBBXIntersection(u8g, x, y, w, h) == 0) 109 | return; 110 | 111 | while (h > 0) { 112 | u8g_DrawHXBM(u8g, x, y, w, bitmap); 113 | bitmap += b; 114 | y++; 115 | h--; 116 | } 117 | } 118 | 119 | 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) { 120 | uint8_t d; 121 | x += 7; 122 | while (w >= 8) { 123 | u8g_Draw8Pixel(u8g, x, y, 2, u8g_pgm_read(bitmap)); 124 | bitmap++; 125 | w -= 8; 126 | x += 8; 127 | } 128 | if (w > 0) { 129 | d = u8g_pgm_read(bitmap); 130 | x -= 7; 131 | do { 132 | if (d & 1) 133 | u8g_DrawPixel(u8g, x, y); 134 | x++; 135 | w--; 136 | d >>= 1; 137 | } while (w > 0); 138 | } 139 | } 140 | 141 | 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) { 142 | u8g_uint_t b; 143 | b = w; 144 | b += 7; 145 | b >>= 3; 146 | 147 | if (u8g_IsBBXIntersection(u8g, x, y, w, h) == 0) 148 | return; 149 | while (h > 0) { 150 | u8g_DrawHXBMP(u8g, x, y, w, bitmap); 151 | bitmap += b; 152 | y++; 153 | h--; 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 37 | 38 | #define WIDTH 240 39 | #define HEIGHT 64 40 | #define PAGE_HEIGHT 8 41 | 42 | static const uint8_t u8g_dev_uc1611_dogm240_init_seq[] PROGMEM = { 43 | U8G_ESC_CS(1), // enable chip 44 | U8G_ESC_ADR(0), // instruction mode 45 | 0xF1, // set last COM electrode 46 | 0x3F, // 64-1=63 47 | 0xF2, // set display start line 48 | 0x00, // 0 49 | 0xF3, // set display end line 50 | 0x3F, // 64-1=63 51 | 0x81, // set contrast (0-255) 52 | 0xB7, // 183 53 | 0xC0, // set view 54 | // 0x04, // topview 55 | 0x02, // bottomview 56 | 0xA3, // set line rate (9.4k) 57 | 0xE9, // set bias ratio (10) 58 | 0xA9, // enable display 59 | 0xD1, // set black and white mode 60 | U8G_ESC_CS(0), // disable chip 61 | U8G_ESC_END // end of sequence 62 | }; 63 | 64 | static void setPage(u8g_t *u8g, u8g_dev_t *dev, unsigned char page) { 65 | u8g_WriteByte(u8g, dev, 0x70 + (page >> 4)); 66 | u8g_WriteByte(u8g, dev, 0x60 + (page & 0x0F)); 67 | } 68 | 69 | static const uint8_t u8g_dev_uc1611_dogm240_data_start[] PROGMEM = { 70 | U8G_ESC_ADR(0), // instruction mode 71 | U8G_ESC_CS(1), // enable chip 72 | 0x10, // set upper 4 bit of the col adr to 0 73 | 0x00, // set lower 4 bit of the col adr to 0 74 | U8G_ESC_END // end of sequence 75 | }; 76 | 77 | uint8_t u8g_dev_uc1611_dogm240_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) { 78 | switch (msg) { 79 | case U8G_DEV_MSG_INIT: 80 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS); 81 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogm240_init_seq); 82 | break; 83 | case U8G_DEV_MSG_STOP: 84 | break; 85 | case U8G_DEV_MSG_PAGE_NEXT: { 86 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 87 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogm240_data_start); 88 | setPage(u8g, dev, pb->p.page); // select current page (uc1611) 89 | u8g_SetAddress(u8g, dev, 1); // data mode 90 | if (u8g_pb_WriteBuffer(pb, u8g, dev) == 0) 91 | return 0; 92 | u8g_SetChipSelect(u8g, dev, 1); 93 | } 94 | break; 95 | case U8G_DEV_MSG_CONTRAST: 96 | u8g_SetChipSelect(u8g, dev, 0); 97 | u8g_SetAddress(u8g, dev, 0); // instruction mode 98 | u8g_WriteByte(u8g, dev, 0x81); 99 | // 11 Jul 2015: bugfix, github issue 339 100 | u8g_WriteByte(u8g, dev, (*(uint8_t *)arg)); // set contrast from, keep gain at 0 101 | u8g_SetChipSelect(u8g, dev, 1); 102 | return 1; 103 | } 104 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 105 | } 106 | 107 | U8G_PB_DEV(u8g_dev_uc1611_dogm240_i2c, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogm240_fn, U8G_COM_UC_I2C); 108 | U8G_PB_DEV(u8g_dev_uc1611_dogm240_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogm240_fn, U8G_COM_SW_SPI); 109 | U8G_PB_DEV(u8g_dev_uc1611_dogm240_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogm240_fn, U8G_COM_HW_SPI); 110 | U8G_PB_DEV(u8g_dev_uc1611_dogm240_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogm240_fn, U8G_COM_FAST_PARALLEL); 111 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 37 | 38 | #define WIDTH 240 39 | #define HEIGHT 128 40 | #define PAGE_HEIGHT 8 41 | 42 | static const uint8_t u8g_dev_uc1611_dogxl240_init_seq[] PROGMEM = { 43 | U8G_ESC_CS(1), // enable chip 44 | U8G_ESC_ADR(0), // instruction mode 45 | 0xF1, // set last COM electrode 46 | 0x7F, // DOGXL240 47 | 0xF2, // set display start line 48 | 0x00, // 0 49 | 0xF3, // set display end line 50 | 0x7F, // DOGXL240 51 | 0x81, // set contrast (0-255) 52 | 0xAA, // DOGXL240 53 | 0xC0, // set view 54 | // 0x04, // topview 55 | 0x02, // bottomview 56 | 0xA3, // set line rate (9.4k) 57 | 0xE9, // set bias ratio (10) 58 | 0xA9, // enable display 59 | 0xD1, // set black and white mode 60 | U8G_ESC_CS(0), // disable chip 61 | U8G_ESC_END // end of sequence 62 | }; 63 | 64 | static void u8g_dev_dogxl240_set_page(u8g_t *u8g, u8g_dev_t *dev, unsigned char page) { 65 | u8g_WriteByte(u8g, dev, 0x70); 66 | u8g_WriteByte(u8g, dev, 0x60 + (page & 0x0F)); 67 | } 68 | 69 | static const uint8_t u8g_dev_uc1611_dogxl240_data_start[] PROGMEM = { 70 | U8G_ESC_ADR(0), // instruction mode 71 | U8G_ESC_CS(1), // enable chip 72 | 0x10, // set upper 4 bit of the col adr to 0 73 | 0x00, // set lower 4 bit of the col adr to 0 74 | U8G_ESC_END // end of sequence 75 | }; 76 | 77 | static uint8_t u8g_dev_uc1611_dogxl240_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) { 78 | switch (msg) { 79 | case U8G_DEV_MSG_INIT: 80 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS); 81 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogxl240_init_seq); 82 | break; 83 | case U8G_DEV_MSG_STOP: 84 | break; 85 | case U8G_DEV_MSG_PAGE_NEXT: { 86 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 87 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogxl240_data_start); 88 | u8g_dev_dogxl240_set_page(u8g, dev, pb->p.page); // select current page (uc1611) 89 | u8g_SetAddress(u8g, dev, 1); // data mode 90 | if (u8g_pb_WriteBuffer(pb, u8g, dev) == 0) 91 | return 0; 92 | u8g_SetChipSelect(u8g, dev, 1); 93 | } 94 | break; 95 | case U8G_DEV_MSG_CONTRAST: 96 | u8g_SetChipSelect(u8g, dev, 0); 97 | u8g_SetAddress(u8g, dev, 0); // instruction mode 98 | u8g_WriteByte(u8g, dev, 0x81); 99 | // 11 Jul 2015: bugfix, github issue 339 100 | u8g_WriteByte(u8g, dev, (*(uint8_t *)arg)); // set contrast from, keep gain at 0 101 | u8g_SetChipSelect(u8g, dev, 1); 102 | return 1; 103 | } 104 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 105 | } 106 | 107 | U8G_PB_DEV(u8g_dev_uc1611_dogxl240_i2c, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogxl240_fn, U8G_COM_UC_I2C); 108 | U8G_PB_DEV(u8g_dev_uc1611_dogxl240_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogxl240_fn, U8G_COM_SW_SPI); 109 | U8G_PB_DEV(u8g_dev_uc1611_dogxl240_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogxl240_fn, U8G_COM_HW_SPI); 110 | U8G_PB_DEV(u8g_dev_uc1611_dogxl240_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogxl240_fn, U8G_COM_FAST_PARALLEL); 111 | -------------------------------------------------------------------------------- /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 | #ifdef ARDUINO 48 | 49 | #ifdef __AVR_ATmega32U4__ 50 | 51 | #include 52 | #include 53 | 54 | #if ARDUINO < 100 55 | #include 56 | #else 57 | #include 58 | #endif 59 | 60 | static uint8_t u8g_usart_spi_out(uint8_t data) { 61 | // send data 62 | UDR1 = data; 63 | // wait for empty transmit buffer 64 | while (!(UCSR1A & (1 << UDRE1))); 65 | 66 | return UDR1; 67 | } 68 | 69 | uint8_t u8g_com_arduino_hw_usart_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 70 | switch (msg) { 71 | case U8G_COM_MSG_STOP: 72 | break; 73 | 74 | case U8G_COM_MSG_INIT: 75 | // SCK is already an output as we overwrite TXLED 76 | u8g_com_arduino_assign_pin_output_high(u8g); 77 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); 78 | 79 | // Init interface at 2MHz 80 | UBRR1 = 0x00; 81 | UCSR1C = (1 << UMSEL11) | (1 << UMSEL10); 82 | UCSR1B = (1 << TXEN1); 83 | UBRR1 = 3; 84 | 85 | break; 86 | 87 | case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1) 88 | u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val); 89 | break; 90 | 91 | case U8G_COM_MSG_CHIP_SELECT: 92 | if (arg_val == 0) 93 | // disable 94 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); 95 | else 96 | // enable 97 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW); 98 | break; 99 | 100 | case U8G_COM_MSG_RESET: 101 | if (u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE) 102 | u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); 103 | break; 104 | 105 | case U8G_COM_MSG_WRITE_BYTE: 106 | u8g_usart_spi_out(arg_val); 107 | break; 108 | 109 | case U8G_COM_MSG_WRITE_SEQ: { 110 | register uint8_t *ptr = arg_ptr; 111 | while (arg_val > 0) { 112 | u8g_usart_spi_out(*ptr++); 113 | arg_val--; 114 | } 115 | } 116 | break; 117 | case U8G_COM_MSG_WRITE_SEQ_P: { 118 | register uint8_t *ptr = arg_ptr; 119 | while (arg_val > 0) { 120 | u8g_usart_spi_out(u8g_pgm_read(ptr)); 121 | ptr++; 122 | arg_val--; 123 | } 124 | } 125 | break; 126 | } 127 | return 1; 128 | } 129 | 130 | // #elif defined(__18CXX) || defined(__PIC32MX) 131 | // #elif defined(__arm__) // Arduino Due, maybe we should better check for __SAM3X8E__ 132 | 133 | #else /* __AVR_ATmega32U4__ */ 134 | 135 | #endif /* __AVR_ATmega32U4__ */ 136 | 137 | #else /* ARDUINO */ 138 | 139 | uint8_t u8g_com_arduino_hw_usart_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 140 | return 1; 141 | } 142 | 143 | #endif /* ARDUINO */ 144 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 40 | #include 41 | 42 | void u8g_pb8h2_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) { 43 | b->buf = buf; 44 | b->width = width; 45 | u8g_pb_Clear(b); 46 | } 47 | 48 | static void u8g_pb8h2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) { 49 | register uint8_t mask; 50 | register uint16_t tmp; 51 | 52 | uint8_t *ptr = b->buf; 53 | 54 | y -= b->p.page_y0; 55 | 56 | tmp = b->width; 57 | tmp >>= 2; 58 | tmp *= (uint8_t)y; 59 | ptr += tmp; 60 | 61 | tmp = x; 62 | tmp >>= 2; 63 | ptr += tmp; 64 | 65 | tmp = x; 66 | tmp &= 3; 67 | tmp <<= 1; 68 | mask = 3; 69 | mask <<= tmp; 70 | mask = ~mask; 71 | color_index &= 3; 72 | color_index <<= tmp; 73 | 74 | *ptr &= mask; 75 | *ptr |= color_index; 76 | } 77 | 78 | void u8g_pb8h2_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) { 79 | if (arg_pixel->y < b->p.page_y0) 80 | return; 81 | if (arg_pixel->y > b->p.page_y1) 82 | return; 83 | if (arg_pixel->x >= b->width) 84 | return; 85 | u8g_pb8h2_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 86 | } 87 | 88 | void u8g_pb8h2_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) { 89 | register uint8_t pixel = arg_pixel->pixel; 90 | do { 91 | if (pixel & 128) 92 | u8g_pb8h2_SetPixel(b, arg_pixel); 93 | switch (arg_pixel->dir) { 94 | case 0: arg_pixel->x++; break; 95 | case 1: arg_pixel->y++; break; 96 | case 2: arg_pixel->x--; break; 97 | case 3: arg_pixel->y--; break; 98 | } 99 | pixel <<= 1; 100 | } while (pixel != 0); 101 | } 102 | 103 | uint8_t u8g_dev_pb8h2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) { 104 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 105 | switch (msg) { 106 | case U8G_DEV_MSG_SET_8PIXEL: 107 | if (u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg)) 108 | u8g_pb8h2_Set8PixelStd(pb, (u8g_dev_arg_pixel_t *)arg); 109 | break; 110 | case U8G_DEV_MSG_SET_PIXEL: 111 | u8g_pb8h2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 112 | break; 113 | case U8G_DEV_MSG_INIT: 114 | break; 115 | case U8G_DEV_MSG_STOP: 116 | break; 117 | case U8G_DEV_MSG_PAGE_FIRST: 118 | u8g_pb_Clear(pb); 119 | u8g_page_First(&(pb->p)); 120 | break; 121 | case U8G_DEV_MSG_PAGE_NEXT: 122 | if (u8g_page_Next(&(pb->p)) == 0) 123 | return 0; 124 | u8g_pb_Clear(pb); 125 | break; 126 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 127 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 128 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 129 | #endif 130 | case U8G_DEV_MSG_GET_PAGE_BOX: 131 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 132 | break; 133 | case U8G_DEV_MSG_GET_WIDTH: 134 | *((u8g_uint_t *)arg) = pb->width; 135 | break; 136 | case U8G_DEV_MSG_GET_HEIGHT: 137 | *((u8g_uint_t *)arg) = pb->p.total_height; 138 | break; 139 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 140 | break; 141 | case U8G_DEV_MSG_SET_XY_CB: 142 | break; 143 | case U8G_DEV_MSG_GET_MODE: 144 | return U8G_MODE_GRAY2BIT; 145 | } 146 | return 1; 147 | } 148 | -------------------------------------------------------------------------------- /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 | state callback: backup env U8G_STATE_MSG_BACKUP_ENV 37 | device callback: DEV_MSG_INIT 38 | state callback: backup u8g U8G_STATE_MSG_BACKUP_U8G 39 | state callback: restore env U8G_STATE_MSG_RESTORE_ENV 40 | 41 | state callback: backup env U8G_STATE_MSG_BACKUP_ENV 42 | state callback: retore u8g U8G_STATE_MSG_RESTORE_U8G 43 | DEV_MSG_PAGE_FIRST or DEV_MSG_PAGE_NEXT 44 | state callback: restore env U8G_STATE_MSG_RESTORE_ENV 45 | 46 | */ 47 | 48 | #include 49 | #include "u8g.h" 50 | 51 | void u8g_state_dummy_cb(uint8_t msg) { 52 | // the dummy procedure does nothing 53 | } 54 | 55 | void u8g_SetHardwareBackup(u8g_t *u8g, u8g_state_cb backup_cb) { 56 | u8g->state_cb = backup_cb; 57 | // in most cases the init message was already sent, so this will backup the 58 | // current u8g state 59 | backup_cb(U8G_STATE_MSG_BACKUP_U8G); 60 | } 61 | 62 | //=============================================================== 63 | // register variable for restoring interrupt state 64 | 65 | #ifdef __AVR__ 66 | uint8_t global_SREG_backup; 67 | #endif 68 | 69 | //=============================================================== 70 | // AVR 71 | 72 | #ifdef __AVR__ 73 | #define U8G_ATMEGA_HW_SPI 74 | 75 | // remove the definition for attiny 76 | #if __AVR_ARCH__ == 2 77 | #undef U8G_ATMEGA_HW_SPI 78 | #endif 79 | #if __AVR_ARCH__ == 25 80 | #undef U8G_ATMEGA_HW_SPI 81 | #endif 82 | #endif 83 | 84 | #ifdef U8G_ATMEGA_HW_SPI 85 | #include 86 | static uint8_t u8g_state_avr_spi_memory[2]; 87 | 88 | void u8g_backup_spi(uint8_t msg) { 89 | if (U8G_STATE_MSG_IS_BACKUP(msg)) { 90 | u8g_state_avr_spi_memory[U8G_STATE_MSG_GET_IDX(msg)] = SPCR; 91 | } 92 | else { 93 | uint8_t tmp = SREG; 94 | cli(); 95 | SPCR = 0; 96 | SPCR = u8g_state_avr_spi_memory[U8G_STATE_MSG_GET_IDX(msg)]; 97 | SREG = tmp; 98 | } 99 | } 100 | 101 | #elif defined (U8G_RASPBERRY_PI) 102 | 103 | #include 104 | 105 | void u8g_backup_spi(uint8_t msg) { 106 | printf("u8g_backup_spi %d\r\n", msg); 107 | } 108 | 109 | #elif defined(ARDUINO) && defined(__SAM3X8E__) // Arduino Due, maybe we should better check for __SAM3X8E__ 110 | 111 | #include "sam.h" 112 | 113 | struct sam_backup_struct { 114 | uint32_t mr; 115 | uint32_t sr; 116 | uint32_t csr[4]; 117 | } 118 | sam_backup[2]; 119 | 120 | void u8g_backup_spi(uint8_t msg) { 121 | uint8_t idx = U8G_STATE_MSG_GET_IDX(msg); 122 | if (U8G_STATE_MSG_IS_BACKUP(msg)) { 123 | sam_backup[idx].mr = SPI0->SPI_MR; 124 | sam_backup[idx].sr = SPI0->SPI_SR; 125 | sam_backup[idx].csr[0] = SPI0->SPI_CSR[0]; 126 | sam_backup[idx].csr[1] = SPI0->SPI_CSR[1]; 127 | sam_backup[idx].csr[2] = SPI0->SPI_CSR[2]; 128 | sam_backup[idx].csr[3] = SPI0->SPI_CSR[3]; 129 | } 130 | else { 131 | SPI0->SPI_MR = sam_backup[idx].mr; 132 | SPI0->SPI_CSR[0] = sam_backup[idx].csr[0]; 133 | SPI0->SPI_CSR[1] = sam_backup[idx].csr[1]; 134 | SPI0->SPI_CSR[2] = sam_backup[idx].csr[2]; 135 | SPI0->SPI_CSR[3] = sam_backup[idx].csr[3]; 136 | } 137 | } 138 | 139 | #else // ifdef U8G_ATMEGA_HW_SPI 140 | 141 | void u8g_backup_spi(uint8_t msg) { 142 | } 143 | 144 | #endif // ifdef U8G_ATMEGA_HW_SPI 145 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 43 | 44 | #define WIDTH 84 45 | #define HEIGHT 48 46 | #define PAGE_HEIGHT 8 47 | 48 | static const uint8_t u8g_dev_tls8204_init_seq[] PROGMEM = { 49 | U8G_ESC_CS(0), // disable chip 50 | U8G_ESC_ADR(0), // instruction mode 51 | U8G_ESC_RST(1), // do reset low pulse with (1*16)+2 milliseconds 52 | U8G_ESC_CS(1), // enable chip 53 | 0x021, // activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=1) 54 | 0x006, // temp. control: b10 = 2 55 | 0x04 | !!((66 - 1) & (1u << 6)), 56 | 0x40 | ((66 - 2) & ((1u << 6) - 1)), 57 | 0x013, // bias system 1:48 58 | 0x0c0, // medium Vop 59 | 0x020, // activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) 60 | 0x00c, // display on, normal operation 61 | U8G_ESC_DLY(100), // delay 100 ms 62 | 0x020, // activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) 63 | 0x00d, // display on, invert 64 | U8G_ESC_DLY(100), // delay 100 ms 65 | U8G_ESC_DLY(100), // delay 100 ms 66 | 0x020, // activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) 67 | 0x00c, // display on, normal 68 | U8G_ESC_DLY(100), // delay 100 ms 69 | U8G_ESC_CS(0), // disable chip 70 | U8G_ESC_END // end of sequence 71 | }; 72 | 73 | uint8_t u8g_dev_tls8204_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) { 74 | switch (msg) { 75 | case U8G_DEV_MSG_INIT: 76 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS); 77 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_tls8204_init_seq); 78 | break; 79 | case U8G_DEV_MSG_STOP: 80 | break; 81 | case U8G_DEV_MSG_PAGE_NEXT: { 82 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 83 | u8g_SetAddress(u8g, dev, 0); // command mode 84 | u8g_SetChipSelect(u8g, dev, 1); 85 | u8g_WriteByte(u8g, dev, 0x020 ); // activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) 86 | u8g_WriteByte(u8g, dev, 0x080 ); // set X address 87 | u8g_WriteByte(u8g, dev, 0x040 | pb->p.page); // set Y address 88 | u8g_SetAddress(u8g, dev, 1); // data mode 89 | if (u8g_pb_WriteBuffer(pb, u8g, dev) == 0) 90 | return 0; 91 | u8g_SetChipSelect(u8g, dev, 0); 92 | } 93 | break; 94 | case U8G_DEV_MSG_CONTRAST: 95 | // the contrast adjustment does not work, needs to be analysed 96 | u8g_SetAddress(u8g, dev, 0); // instruction mode 97 | u8g_SetChipSelect(u8g, dev, 1); 98 | u8g_WriteByte(u8g, dev, 0x021); // command mode, extended function set 99 | u8g_WriteByte(u8g, dev, 0x080 | ((*(uint8_t *)arg) >> 1 )); 100 | u8g_WriteByte(u8g, dev, 0x020); // command mode, extended function set 101 | u8g_SetChipSelect(u8g, dev, 0); 102 | return 1; 103 | } 104 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 105 | } 106 | 107 | U8G_PB_DEV(u8g_dev_tls8204_84x48_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_tls8204_fn, U8G_COM_SW_SPI); 108 | -------------------------------------------------------------------------------- /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 | uint8_t c1, c2, c3, tmp; 80 | c1 = v0 <= a1; 81 | c2 = v1 >= a0; 82 | c3 = v0 > v1; 83 | 84 | tmp = c1; 85 | c1 &= c2; 86 | c2 &= c3; 87 | c3 &= tmp; 88 | c1 |= c2; 89 | c1 |= c3; 90 | return c1 & 1; 91 | } 92 | #endif 93 | 94 | #define U8G_IS_INTERSECTION_MACRO(a0, a1, v0, v1) ((uint8_t)((v0) <= (a1)) ? (((v1) >= (a0)) ? ( 1 ) : ((v0) > (v1))) : (((v1) >= (a0)) ? ((v0) > (v1)) : ( 0 ))) 95 | 96 | // 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; 97 | 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) { 98 | // surprisingly the macro leads to larger code 99 | // return U8G_IS_INTERSECTION_MACRO(a0,a1,v0,v1); 100 | if (v0 <= a1) { 101 | if (v1 >= a0) { 102 | return 1; 103 | } 104 | else { 105 | if (v0 > v1) 106 | return 1; 107 | else 108 | return 0; 109 | } 110 | } 111 | else { 112 | if (v1 >= a0) { 113 | if (v0 > v1) 114 | return 1; 115 | else 116 | return 0; 117 | } 118 | else { 119 | return 0; 120 | } 121 | } 122 | } 123 | 124 | uint8_t u8g_IsBBXIntersection(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h) { 125 | register u8g_uint_t tmp; 126 | tmp = y; 127 | tmp += h; 128 | tmp--; 129 | if (u8g_is_intersection_decision_tree(u8g->current_page.y0, u8g->current_page.y1, y, tmp) == 0) 130 | return 0; 131 | 132 | tmp = x; 133 | tmp += w; 134 | tmp--; 135 | return u8g_is_intersection_decision_tree(u8g->current_page.x0, u8g->current_page.x1, x, tmp); 136 | } 137 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 40 | #include 41 | 42 | void u8g_pb16v2_Clear(u8g_pb_t *b) { 43 | uint8_t *ptr = (uint8_t *)b->buf; 44 | uint8_t *end_ptr = ptr; 45 | 46 | // two bits per pixel, 16 bits height --> 8 pixel --> 4 pixel per byte 47 | end_ptr += b->width; 48 | end_ptr += b->width; 49 | 50 | do { 51 | *ptr++ = 0; 52 | } while (ptr != end_ptr); 53 | } 54 | 55 | void u8g_pb16v2Init(u8g_pb_t *b, void *buf, u8g_uint_t width) { 56 | b->buf = buf; 57 | b->width = width; 58 | u8g_pb16v2_Clear(b); 59 | } 60 | 61 | void u8g_pb16v2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) { 62 | register uint8_t mask; 63 | uint8_t *ptr = b->buf; 64 | y -= b->p.page_y0; 65 | if (y >= 4) 66 | ptr += b->width; 67 | mask = 0x03; 68 | y &= 0x03; 69 | y <<= 1; 70 | mask <<= y; 71 | mask ^= 0xff; 72 | color_index &= 3; 73 | color_index <<= y; 74 | ptr += x; 75 | *ptr &= mask; 76 | *ptr |= color_index; 77 | } 78 | 79 | void u8g_pb16v2_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) { 80 | if (arg_pixel->y < b->p.page_y0) 81 | return; 82 | if (arg_pixel->y > b->p.page_y1) 83 | return; 84 | if (arg_pixel->x >= b->width) 85 | return; 86 | u8g_pb16v2_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 87 | } 88 | 89 | void u8g_pb16v2_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) { 90 | register uint8_t pixel = arg_pixel->pixel; 91 | do { 92 | if (pixel & 128) 93 | u8g_pb16v2_SetPixel(b, arg_pixel); 94 | switch (arg_pixel->dir) { 95 | case 0: arg_pixel->x++; break; 96 | case 1: arg_pixel->y++; break; 97 | case 2: arg_pixel->x--; break; 98 | case 3: arg_pixel->y--; break; 99 | } 100 | pixel <<= 1; 101 | } while (pixel != 0); 102 | } 103 | 104 | uint8_t u8g_dev_pb16v2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) { 105 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 106 | switch (msg) { 107 | case U8G_DEV_MSG_SET_8PIXEL: 108 | if (u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg)) 109 | u8g_pb16v2_Set8PixelStd(pb, (u8g_dev_arg_pixel_t *)arg); 110 | break; 111 | case U8G_DEV_MSG_SET_PIXEL: 112 | u8g_pb16v2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 113 | break; 114 | case U8G_DEV_MSG_INIT: 115 | break; 116 | case U8G_DEV_MSG_STOP: 117 | break; 118 | case U8G_DEV_MSG_PAGE_FIRST: 119 | u8g_pb16v2_Clear(pb); 120 | u8g_page_First(&(pb->p)); 121 | break; 122 | case U8G_DEV_MSG_PAGE_NEXT: 123 | if (u8g_page_Next(&(pb->p)) == 0) 124 | return 0; 125 | u8g_pb16v2_Clear(pb); 126 | break; 127 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 128 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 129 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 130 | #endif 131 | case U8G_DEV_MSG_GET_PAGE_BOX: 132 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 133 | break; 134 | case U8G_DEV_MSG_GET_WIDTH: 135 | *((u8g_uint_t *)arg) = pb->width; 136 | break; 137 | case U8G_DEV_MSG_GET_HEIGHT: 138 | *((u8g_uint_t *)arg) = pb->p.total_height; 139 | break; 140 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 141 | break; 142 | case U8G_DEV_MSG_SET_XY_CB: 143 | break; 144 | case U8G_DEV_MSG_GET_MODE: 145 | return U8G_MODE_GRAY2BIT; 146 | } 147 | return 1; 148 | } 149 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 37 | 38 | uint8_t u8g_InitCom(u8g_t *u8g, u8g_dev_t *dev, uint8_t clk_cycle_time) { 39 | return dev->com_fn(u8g, U8G_COM_MSG_INIT, clk_cycle_time, NULL); 40 | } 41 | 42 | void u8g_StopCom(u8g_t *u8g, u8g_dev_t *dev) { 43 | dev->com_fn(u8g, U8G_COM_MSG_STOP, 0, NULL); 44 | } 45 | 46 | // cs contains the chip number, which should be enabled 47 | void u8g_SetChipSelect(u8g_t *u8g, u8g_dev_t *dev, uint8_t cs) { 48 | dev->com_fn(u8g, U8G_COM_MSG_CHIP_SELECT, cs, NULL); 49 | } 50 | 51 | void u8g_SetResetLow(u8g_t *u8g, u8g_dev_t *dev) { 52 | dev->com_fn(u8g, U8G_COM_MSG_RESET, 0, NULL); 53 | } 54 | 55 | void u8g_SetResetHigh(u8g_t *u8g, u8g_dev_t *dev) { 56 | dev->com_fn(u8g, U8G_COM_MSG_RESET, 1, NULL); 57 | } 58 | 59 | void u8g_SetAddress(u8g_t *u8g, u8g_dev_t *dev, uint8_t address) { 60 | dev->com_fn(u8g, U8G_COM_MSG_ADDRESS, address, NULL); 61 | } 62 | 63 | uint8_t u8g_WriteByte(u8g_t *u8g, u8g_dev_t *dev, uint8_t val) { 64 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, val, NULL); 65 | } 66 | 67 | uint8_t u8g_WriteSequence(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *seq) { 68 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ, cnt, seq); 69 | } 70 | 71 | uint8_t u8g_WriteSequenceP(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, const uint8_t *seq) { 72 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ_P, cnt, (void *)seq); 73 | } 74 | 75 | /* 76 | sequence := { direct_value | escape_sequence } 77 | direct_value := 0..254 78 | escape_sequence := value_255 | sequence_end | delay | adr | cs | not_used 79 | value_255 := 255 255 80 | sequence_end = 255 254 81 | delay := 255 0..127 82 | adr := 255 0x0e0 .. 0x0ef 83 | cs := 255 0x0d0 .. 0x0df 84 | not_used := 255 101..254 85 | 86 | #define U8G_ESC_DLY(x) 255, ((x) & 0x7f) 87 | #define U8G_ESC_CS(x) 255, (0xd0 | ((x)&0x0f)) 88 | #define U8G_ESC_ADR(x) 255, (0xe0 | ((x)&0x0f)) 89 | #define U8G_ESC_VCC(x) 255, (0xbe | ((x)&0x01)) 90 | #define U8G_ESC_END 255, 254 91 | #define U8G_ESC_255 255, 255 92 | #define U8G_ESC_RST(x) 255, (0xc0 | ((x)&0x0f)) 93 | 94 | */ 95 | uint8_t u8g_WriteEscSeqP(u8g_t *u8g, u8g_dev_t *dev, const uint8_t *esc_seq) { 96 | uint8_t is_escape = 0; 97 | uint8_t value; 98 | for (;;) { 99 | value = u8g_pgm_read(esc_seq); 100 | if (is_escape == 0) { 101 | if (value != 255) { 102 | if (u8g_WriteByte(u8g, dev, value) == 0) 103 | return 0; 104 | } 105 | else { 106 | is_escape = 1; 107 | } 108 | } 109 | else { 110 | if (value == 255) { 111 | if (u8g_WriteByte(u8g, dev, value) == 0) 112 | return 0; 113 | } 114 | else if (value == 254) { 115 | break; 116 | } 117 | else if (value >= 0x0f0) { 118 | // not yet used, do nothing 119 | } 120 | else if (value >= 0xe0) { 121 | u8g_SetAddress(u8g, dev, value & 0x0f); 122 | } 123 | else if (value >= 0xd0) { 124 | u8g_SetChipSelect(u8g, dev, value & 0x0f); 125 | } 126 | else if (value >= 0xc0) { 127 | u8g_SetResetLow(u8g, dev); 128 | value &= 0x0f; 129 | value <<= 4; 130 | value += 2; 131 | u8g_Delay(value); 132 | u8g_SetResetHigh(u8g, dev); 133 | u8g_Delay(value); 134 | } 135 | else if (value >= 0xbe) { 136 | // not yet implemented 137 | // u8g_SetVCC(u8g, dev, value & 0x01); 138 | } 139 | else if (value <= 127) { 140 | u8g_Delay(value); 141 | } 142 | is_escape = 0; 143 | } 144 | esc_seq++; 145 | } 146 | return 1; 147 | } 148 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 39 | 40 | void u8g_pb_Clear(u8g_pb_t *b) { 41 | uint8_t *ptr = (uint8_t *)b->buf; 42 | uint8_t *end_ptr = ptr; 43 | end_ptr += b->width; 44 | do { 45 | *ptr++ = 0; 46 | } while (ptr != end_ptr); 47 | } 48 | 49 | // the following procedure does not work. why? Can be checked with descpic 50 | /* 51 | void u8g_pb_Clear(u8g_pb_t *b) 52 | { 53 | uint8_t *ptr = (uint8_t *)b->buf; 54 | uint8_t cnt = b->width; 55 | do 56 | { 57 | *ptr++ = 0; 58 | cnt--; 59 | } while( cnt != 0 ); 60 | } 61 | */ 62 | 63 | /* 64 | intersection assumptions: 65 | a1 <= a2 is always true 66 | */ 67 | /* 68 | minimized version 69 | ---1----0 1 b1 <= a2 && b1 > b2 70 | -----1--0 1 b2 >= a1 && b1 > b2 71 | ---1-1--- 1 b1 <= a2 && b2 >= a1 72 | */ 73 | /* 74 | uint8_t u8g_pb8v1_IsYIntersection___Old(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1) 75 | { 76 | uint8_t c0, c1, c; 77 | c0 = v0 <= b->p.page_y1; 78 | c1 = v1 >= b->p.page_y0; 79 | c = v0 > v1; 80 | if ( c0 && c1 ) return 1; 81 | if ( c0 && c ) return 1; 82 | if ( c1 && c ) return 1; 83 | return 0; 84 | } 85 | */ 86 | 87 | uint8_t u8g_pb_IsYIntersection(u8g_pb_t *pb, u8g_uint_t v0, u8g_uint_t v1) { 88 | uint8_t c1, c2, c3, tmp; 89 | c1 = v0 <= pb->p.page_y1; 90 | c2 = v1 >= pb->p.page_y0; 91 | c3 = v0 > v1; 92 | /* 93 | if ( c1 && c2 ) 94 | return 1; 95 | if ( c1 && c3 ) 96 | return 1; 97 | if ( c2 && c3 ) 98 | return 1; 99 | return 0; 100 | */ 101 | 102 | tmp = c1; 103 | c1 &= c2; 104 | c2 &= c3; 105 | c3 &= tmp; 106 | c1 |= c2; 107 | c1 |= c3; 108 | return c1 & 1; 109 | } 110 | 111 | uint8_t u8g_pb_IsXIntersection(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1) { 112 | uint8_t /*c0, c1, */ c2, c3; 113 | /* 114 | conditions: b->p.page_y0 < b->p.page_y1 115 | there are no restriction on v0 and v1. If v0 > v1, then warp around unsigned is assumed 116 | */ 117 | /* 118 | c0 = v0 < 0; 119 | c1 = v1 < 0; 120 | */ 121 | c2 = v0 > b->width; 122 | c3 = v1 > b->width; 123 | //if ( c0 && c1 ) return 0; 124 | if (c2 && c3) return 0; 125 | //if ( c1 && c2 ) return 0; 126 | return 1; 127 | } 128 | 129 | uint8_t u8g_pb_IsIntersection(u8g_pb_t *pb, u8g_dev_arg_bbx_t *bbx) { 130 | u8g_uint_t tmp; 131 | 132 | tmp = bbx->y; 133 | tmp += bbx->h; 134 | tmp--; 135 | 136 | if (u8g_pb_IsYIntersection(pb, bbx->y, tmp) == 0) 137 | return 0; 138 | 139 | // maybe this one can be skiped... probability is very high to have an intersection, so it would be ok to always return 1 140 | tmp = bbx->x; 141 | tmp += bbx->w; 142 | tmp--; 143 | 144 | return u8g_pb_IsXIntersection(pb, bbx->x, tmp); 145 | } 146 | 147 | void u8g_pb_GetPageBox(u8g_pb_t *pb, u8g_box_t *box) { 148 | box->x0 = 0; 149 | box->y0 = pb->p.page_y0; 150 | box->x1 = pb->width; 151 | box->x1--; 152 | box->y1 = pb->p.page_y1; 153 | } 154 | 155 | uint8_t u8g_pb_Is8PixelVisible(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) { 156 | u8g_uint_t v0, v1; 157 | v0 = arg_pixel->y; 158 | v1 = v0; 159 | switch (arg_pixel->dir) { 160 | case 0: 161 | break; 162 | case 1: 163 | v1 += 8; // this is independent from the page height 164 | break; 165 | case 2: 166 | break; 167 | case 3: 168 | v0 -= 8; 169 | break; 170 | } 171 | return u8g_pb_IsYIntersection(b, v0, v1); 172 | } 173 | 174 | uint8_t u8g_pb_WriteBuffer(u8g_pb_t *b, u8g_t *u8g, u8g_dev_t *dev) { 175 | return u8g_WriteSequence(u8g, dev, b->width, b->buf); 176 | } 177 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 37 | 38 | struct _u8g_vs_t { 39 | u8g_uint_t x; 40 | u8g_uint_t y; 41 | u8g_t *u8g; 42 | }; 43 | typedef struct _u8g_vs_t u8g_vs_t; 44 | 45 | #define U8g_VS_MAX 4 46 | uint8_t u8g_vs_cnt = 0; 47 | u8g_vs_t u8g_vs_list[U8g_VS_MAX]; 48 | uint8_t u8g_vs_current; 49 | u8g_uint_t u8g_vs_width; 50 | u8g_uint_t u8g_vs_height; 51 | 52 | uint8_t u8g_dev_vs_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) { 53 | switch (msg) { 54 | default: { 55 | uint8_t i; 56 | for ( i = 0; i < u8g_vs_cnt; i++ ) { 57 | u8g_call_dev_fn(u8g_vs_list[i].u8g, u8g_vs_list[i].u8g->dev, msg, arg); 58 | } 59 | } 60 | return 1; 61 | case U8G_DEV_MSG_PAGE_FIRST: 62 | u8g_vs_current = 0; 63 | if (u8g_vs_cnt != 0) 64 | return u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); 65 | return 0; 66 | case U8G_DEV_MSG_PAGE_NEXT: { 67 | uint8_t ret = 0; 68 | if (u8g_vs_cnt != 0) 69 | ret = u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); 70 | if (ret != 0) 71 | return ret; 72 | u8g_vs_current++; // next device 73 | if (u8g_vs_current >= u8g_vs_cnt) // reached end? 74 | return 0; 75 | 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); 76 | } 77 | case U8G_DEV_MSG_GET_WIDTH: 78 | *((u8g_uint_t *)arg) = u8g_vs_width; 79 | break; 80 | case U8G_DEV_MSG_GET_HEIGHT: 81 | *((u8g_uint_t *)arg) = u8g_vs_height; 82 | break; 83 | case U8G_DEV_MSG_GET_PAGE_BOX: 84 | if (u8g_vs_current < u8g_vs_cnt) { 85 | u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); 86 | ((u8g_box_t *)arg)->x0 += u8g_vs_list[u8g_vs_current].x; 87 | ((u8g_box_t *)arg)->x1 += u8g_vs_list[u8g_vs_current].x; 88 | ((u8g_box_t *)arg)->y0 += u8g_vs_list[u8g_vs_current].y; 89 | ((u8g_box_t *)arg)->y1 += u8g_vs_list[u8g_vs_current].y; 90 | } 91 | else { 92 | ((u8g_box_t *)arg)->x0 = 0; 93 | ((u8g_box_t *)arg)->x1 = 0; 94 | ((u8g_box_t *)arg)->y0 = 0; 95 | ((u8g_box_t *)arg)->y1 = 0; 96 | } 97 | return 1; 98 | case U8G_DEV_MSG_SET_PIXEL: 99 | case U8G_DEV_MSG_SET_8PIXEL: 100 | if (u8g_vs_current < u8g_vs_cnt) { 101 | ((u8g_dev_arg_pixel_t *)arg)->x -= u8g_vs_list[u8g_vs_current].x; 102 | ((u8g_dev_arg_pixel_t *)arg)->y -= u8g_vs_list[u8g_vs_current].y; 103 | return u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); 104 | } 105 | break; 106 | } 107 | return 1; 108 | } 109 | 110 | u8g_dev_t u8g_dev_vs = { u8g_dev_vs_fn, NULL, NULL }; 111 | 112 | void u8g_SetVirtualScreenDimension(u8g_t *vs_u8g, u8g_uint_t width, u8g_uint_t height) { 113 | if (vs_u8g->dev != &u8g_dev_vs) 114 | return; // abort if there is no a virtual screen device 115 | u8g_vs_width = width; 116 | u8g_vs_height = height; 117 | } 118 | 119 | uint8_t u8g_AddToVirtualScreen(u8g_t *vs_u8g, u8g_uint_t x, u8g_uint_t y, u8g_t *child_u8g) { 120 | if (vs_u8g->dev != &u8g_dev_vs) 121 | return 0; // abort if there is no a virtual screen device 122 | if (u8g_vs_cnt >= U8g_VS_MAX) 123 | return 0; // maximum number of child u8g's reached 124 | u8g_vs_list[u8g_vs_cnt].u8g = child_u8g; 125 | u8g_vs_list[u8g_vs_cnt].x = x; 126 | u8g_vs_list[u8g_vs_cnt].y = y; 127 | u8g_vs_cnt++; 128 | return 1; 129 | } 130 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 51 | 52 | #ifdef __AVR_XMEGA__ 53 | #define U8G_ATXMEGA_HW_SPI 54 | #endif 55 | 56 | #ifdef U8G_ATXMEGA_HW_SPI 57 | 58 | #include 59 | #include 60 | 61 | static uint8_t u8g_atxmega_spi_out(uint8_t data) { 62 | // send data 63 | SPIC.DATA = data; 64 | 65 | // wait for transmission 66 | while (!(SPIC.STATUS & SPI_IF_bm)); 67 | 68 | // clear the SPIF flag by reading SPDR 69 | return SPIC.DATA; 70 | } 71 | 72 | uint8_t u8g_com_atxmega_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 73 | switch (msg) { 74 | case U8G_COM_MSG_STOP: 75 | break; 76 | 77 | case U8G_COM_MSG_INIT: 78 | 79 | u8g_SetPIOutput(u8g, U8G_PI_CS); 80 | u8g_SetPIOutput(u8g, U8G_PI_A0); 81 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 82 | 83 | // U8G_ATOMIC_START(); 84 | 85 | PORTC.DIR |= PIN4_bm | PIN5_bm | PIN7_bm; 86 | PORTC.DIR &= ~PIN6_bm; 87 | 88 | // U8G_ATOMIC_END(); 89 | 90 | u8g_SetPILevel(u8g, U8G_PI_CS, 1); 91 | 92 | SPIC.CTRL = 0; 93 | SPIC.CTRL = SPI_PRESCALER_DIV4_gc |// SPI prescaler. 94 | // SPI_CLK2X_bm | //SPI Clock double. 95 | SPI_ENABLE_bm | // Enable SPI module. 96 | // SPI_DORD_bm | //Data order. 97 | SPI_MASTER_bm | // SPI master. 98 | SPI_MODE_0_gc; // SPI mode. 99 | 100 | #ifdef U8G_HW_SPI_2X 101 | SPIC.CTRL |= SPI_CLK2X_bm; // double speed, issue 89 102 | #endif 103 | 104 | break; 105 | 106 | case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1) 107 | u8g_SetPILevel(u8g, U8G_PI_A0, arg_val); 108 | break; 109 | 110 | case U8G_COM_MSG_CHIP_SELECT: 111 | 112 | if (arg_val == 0) { 113 | // disable 114 | u8g_SetPILevel(u8g, U8G_PI_CS, 1); 115 | } 116 | else { 117 | // PORTB &= ~_BV(5); /* SCK = 0 */ 118 | PORTC.OUT &= ~PIN7_bm; 119 | // enable 120 | u8g_SetPILevel(u8g, U8G_PI_CS, 0); // CS = 0 (low active) 121 | } 122 | 123 | break; 124 | 125 | case U8G_COM_MSG_RESET: 126 | u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 127 | break; 128 | 129 | case U8G_COM_MSG_WRITE_BYTE: 130 | u8g_atxmega_spi_out(arg_val); 131 | break; 132 | 133 | case U8G_COM_MSG_WRITE_SEQ: { 134 | register uint8_t *ptr = arg_ptr; 135 | while (arg_val > 0) { 136 | u8g_atxmega_spi_out(*ptr++); 137 | arg_val--; 138 | } 139 | } 140 | break; 141 | case U8G_COM_MSG_WRITE_SEQ_P: { 142 | register uint8_t *ptr = arg_ptr; 143 | while (arg_val > 0) { 144 | u8g_atxmega_spi_out(u8g_pgm_read(ptr)); 145 | ptr++; 146 | arg_val--; 147 | } 148 | } 149 | break; 150 | } 151 | return 1; 152 | } 153 | 154 | #else // ifdef U8G_ATXMEGA_HW_SPI 155 | 156 | uint8_t u8g_com_atxmega_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 157 | return 1; 158 | } 159 | 160 | #endif // ifdef U8G_ATXMEGA_HW_SPI -------------------------------------------------------------------------------- /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 | #include "u8g.h" 40 | #include 41 | 42 | // Obsolete, usually set by the init of the structure 43 | void u8g_pb8v1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) { 44 | b->buf = buf; 45 | b->width = width; 46 | u8g_pb_Clear(b); 47 | } 48 | 49 | void u8g_pb8v1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) { 50 | register uint8_t mask; 51 | uint8_t *ptr = b->buf; 52 | 53 | y -= b->p.page_y0; 54 | mask = 1; 55 | y &= 0x07; 56 | mask <<= y; 57 | ptr += x; 58 | if (color_index) { 59 | *ptr |= mask; 60 | } 61 | else { 62 | mask ^= 0xff; 63 | *ptr &= mask; 64 | } 65 | } 66 | 67 | void u8g_pb8v1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) { 68 | if (arg_pixel->y < b->p.page_y0) 69 | return; 70 | if (arg_pixel->y > b->p.page_y1) 71 | return; 72 | if (arg_pixel->x >= b->width) 73 | return; 74 | u8g_pb8v1_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 75 | } 76 | 77 | void u8g_pb8v1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) { 78 | register uint8_t pixel = arg_pixel->pixel; 79 | do { 80 | if (pixel & 128) 81 | u8g_pb8v1_SetPixel(b, arg_pixel); 82 | switch (arg_pixel->dir) { 83 | case 0: arg_pixel->x++; break; 84 | case 1: arg_pixel->y++; break; 85 | case 2: arg_pixel->x--; break; 86 | case 3: arg_pixel->y--; break; 87 | } 88 | pixel <<= 1; 89 | } while (pixel != 0); 90 | } 91 | 92 | void u8g_pb8v1_Set8PixelOpt2(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) { 93 | register uint8_t pixel = arg_pixel->pixel; 94 | u8g_uint_t dx = 0; 95 | u8g_uint_t dy = 0; 96 | 97 | switch (arg_pixel->dir) { 98 | case 0: dx++; break; 99 | case 1: dy++; break; 100 | case 2: dx--; break; 101 | case 3: dy--; break; 102 | } 103 | 104 | do { 105 | if (pixel & 128) 106 | u8g_pb8v1_SetPixel(b, arg_pixel); 107 | arg_pixel->x += dx; 108 | arg_pixel->y += dy; 109 | pixel <<= 1; 110 | } while (pixel != 0); 111 | 112 | } 113 | 114 | uint8_t u8g_dev_pb8v1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) { 115 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 116 | switch (msg) { 117 | case U8G_DEV_MSG_SET_8PIXEL: 118 | if (u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg)) 119 | u8g_pb8v1_Set8PixelOpt2(pb, (u8g_dev_arg_pixel_t *)arg); 120 | break; 121 | case U8G_DEV_MSG_SET_PIXEL: 122 | u8g_pb8v1_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 123 | break; 124 | case U8G_DEV_MSG_INIT: 125 | break; 126 | case U8G_DEV_MSG_STOP: 127 | break; 128 | case U8G_DEV_MSG_PAGE_FIRST: 129 | u8g_pb_Clear(pb); 130 | u8g_page_First(&(pb->p)); 131 | break; 132 | case U8G_DEV_MSG_PAGE_NEXT: 133 | if (u8g_page_Next(&(pb->p)) == 0) 134 | return 0; 135 | u8g_pb_Clear(pb); 136 | break; 137 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 138 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 139 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 140 | #endif 141 | case U8G_DEV_MSG_GET_PAGE_BOX: 142 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 143 | break; 144 | case U8G_DEV_MSG_GET_WIDTH: 145 | *((u8g_uint_t *)arg) = pb->width; 146 | break; 147 | case U8G_DEV_MSG_GET_HEIGHT: 148 | *((u8g_uint_t *)arg) = pb->p.total_height; 149 | break; 150 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 151 | break; 152 | case U8G_DEV_MSG_SET_XY_CB: 153 | break; 154 | case U8G_DEV_MSG_GET_MODE: 155 | return U8G_MODE_BW; 156 | } 157 | return 1; 158 | } 159 | -------------------------------------------------------------------------------- /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 | #ifdef __AVR__ 41 | 42 | static void u8g_atmega_st7920_sw_spi_shift_out(u8g_t *u8g, uint8_t val) { 43 | uint8_t i = 8; 44 | do { 45 | u8g_SetPILevel(u8g, U8G_PI_MOSI, val & 128 ); 46 | val <<= 1; 47 | u8g_SetPILevel(u8g, U8G_PI_SCK, 1 ); 48 | u8g_MicroDelay(); // 15 Aug 2012: added for high speed uC 49 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 50 | u8g_MicroDelay(); // 15 Aug 2012: added for high speed uC 51 | i--; 52 | } while (i != 0); 53 | } 54 | 55 | static void u8g_com_atmega_st7920_write_byte(u8g_t *u8g, uint8_t rs, uint8_t val) { 56 | uint8_t i; 57 | 58 | if (rs == 0) 59 | // command 60 | u8g_atmega_st7920_sw_spi_shift_out(u8g, 0x0f8); 61 | else if (rs == 1) 62 | // data 63 | u8g_atmega_st7920_sw_spi_shift_out(u8g, 0x0fa); 64 | 65 | u8g_atmega_st7920_sw_spi_shift_out(u8g, val & 0x0f0); 66 | u8g_atmega_st7920_sw_spi_shift_out(u8g, val << 4); 67 | 68 | for ( i = 0; i < 4; i++ ) u8g_10MicroDelay(); 69 | } 70 | 71 | uint8_t u8g_com_atmega_st7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 72 | switch (msg) { 73 | case U8G_COM_MSG_INIT: 74 | u8g_SetPIOutput(u8g, U8G_PI_SCK); 75 | u8g_SetPIOutput(u8g, U8G_PI_MOSI); 76 | // u8g_SetPIOutput(u8g, U8G_PI_A0); 77 | u8g_SetPIOutput(u8g, U8G_PI_CS); 78 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 79 | 80 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 81 | u8g_SetPILevel(u8g, U8G_PI_MOSI, 0 ); 82 | u8g_SetPILevel(u8g, U8G_PI_CS, 0 ); 83 | // u8g_SetPILevel(u8g, U8G_PI_A0, 0); 84 | 85 | u8g->pin_list[U8G_PI_A0_STATE] = 0; // inital RS state: command mode 86 | break; 87 | 88 | case U8G_COM_MSG_STOP: 89 | break; 90 | 91 | case U8G_COM_MSG_RESET: 92 | u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 93 | break; 94 | 95 | case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1) 96 | u8g->pin_list[U8G_PI_A0_STATE] = arg_val; 97 | break; 98 | 99 | case U8G_COM_MSG_CHIP_SELECT: 100 | if (arg_val == 0) 101 | // disable, note: the st7920 has an active high chip select 102 | u8g_SetPILevel(u8g, U8G_PI_CS, 0); 103 | else 104 | // u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 105 | // enable 106 | u8g_SetPILevel(u8g, U8G_PI_CS, 1); // CS = 1 (high active) 107 | break; 108 | 109 | case U8G_COM_MSG_WRITE_BYTE: 110 | u8g_com_atmega_st7920_write_byte(u8g, u8g->pin_list[U8G_PI_A0_STATE], arg_val); 111 | u8g->pin_list[U8G_PI_A0_STATE] = 2; 112 | break; 113 | 114 | case U8G_COM_MSG_WRITE_SEQ: { 115 | register uint8_t *ptr = arg_ptr; 116 | while (arg_val > 0) { 117 | u8g_com_atmega_st7920_write_byte(u8g, u8g->pin_list[U8G_PI_A0_STATE], *ptr++); 118 | u8g->pin_list[U8G_PI_A0_STATE] = 2; 119 | arg_val--; 120 | } 121 | } 122 | break; 123 | 124 | case U8G_COM_MSG_WRITE_SEQ_P: { 125 | register uint8_t *ptr = arg_ptr; 126 | while (arg_val > 0) { 127 | u8g_com_atmega_st7920_write_byte(u8g, u8g->pin_list[U8G_PI_A0_STATE], u8g_pgm_read(ptr)); 128 | u8g->pin_list[U8G_PI_A0_STATE] = 2; 129 | ptr++; 130 | arg_val--; 131 | } 132 | } 133 | break; 134 | } 135 | return 1; 136 | } 137 | 138 | #else // ifdef __AVR__ 139 | 140 | uint8_t u8g_com_atmega_st7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 141 | return 1; 142 | } 143 | 144 | #endif // ifdef __AVR__ 145 | -------------------------------------------------------------------------------- /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 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2012, olikraus@gmail.com 11 | Copyright (c) 2015, daniel@redfelineninja.org.uk 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 | #include "u8g.h" 41 | 42 | #ifdef U8G_LINUX 43 | 44 | #include 45 | #include 46 | #include 47 | #include 48 | #include 49 | 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | 56 | #include 57 | 58 | #define I2C_SLA 0x3c 59 | #define I2C_CMD_MODE 0x80 60 | #define I2C_DATA_MODE 0x40 61 | #define MAX_PACKET 64 62 | 63 | #ifndef U8G_WITH_PINLIST 64 | #error U8G_WITH_PINLIST is mandatory for this driver 65 | #endif 66 | 67 | static void set_cmd_mode(u8g_t *u8g, bool cmd_mode) { 68 | u8g->pin_list[U8G_PI_A0_STATE] = cmd_mode; 69 | } 70 | 71 | static bool get_cmd_mode(u8g_t *u8g) { 72 | return u8g->pin_list[U8G_PI_A0_STATE]; 73 | } 74 | 75 | static uint8_t send_data_burst(u8g_t *u8g, int fd, uint8_t *buf, size_t buflen) { 76 | uint8_t i2cbuf[2 * MAX_PACKET]; 77 | uint8_t i2clen; 78 | int res; 79 | 80 | // ignore bursts when there is no file open 81 | if (fd < 0) 82 | return 0; 83 | 84 | if (get_cmd_mode(u8g)) { 85 | i2clen = 0; 86 | while (buflen > 0) { 87 | i2cbuf[i2clen++] = I2C_CMD_MODE; 88 | i2cbuf[i2clen++] = *buf++; 89 | buflen--; 90 | } 91 | } 92 | else { 93 | i2cbuf[0] = I2C_DATA_MODE; 94 | memcpy(i2cbuf + 1, buf, buflen); 95 | i2clen = buflen + 1; 96 | } 97 | 98 | res = write(fd, i2cbuf, i2clen); 99 | if (res < 0) 100 | fprintf(stderr, "I2C write failed (%s)\n", strerror(errno)); 101 | else if (res != i2clen) 102 | fprintf(stderr, "Incomplete I2C write (%d of %d packet)\n", res, i2clen); 103 | 104 | return res == i2clen; 105 | } 106 | 107 | uint8_t u8g_com_linux_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 108 | static int fd = -1; 109 | char dev[24]; 110 | 111 | switch (msg) { 112 | case U8G_COM_MSG_INIT: 113 | sprintf(dev, "/dev/i2c-%d", u8g->pin_list[U8G_PI_I2C_OPTION]); 114 | fd = open(dev, O_RDWR); 115 | if (fd < 0) { 116 | fprintf(stderr, "cannot open %s (%s)\n", dev, strerror(errno)); 117 | return 0; 118 | } 119 | 120 | if (ioctl(fd, I2C_SLAVE, I2C_SLA) < 0) { 121 | fprintf(stderr, "cannot set slave address (%s)\n", strerror(errno)); 122 | return 0; 123 | } 124 | 125 | break; 126 | 127 | case U8G_COM_MSG_STOP: 128 | // ignored - i2c-dev will automatically stop between writes 129 | break; 130 | 131 | case U8G_COM_MSG_RESET: 132 | // ignored - no obvious means to reset an SSD via I2C 133 | break; 134 | 135 | case U8G_COM_MSG_CHIP_SELECT: 136 | set_cmd_mode(u8g, true); 137 | break; 138 | 139 | case U8G_COM_MSG_WRITE_BYTE: 140 | send_data_burst(u8g, fd, &arg_val, 1); 141 | break; 142 | 143 | case U8G_COM_MSG_WRITE_SEQ: 144 | case U8G_COM_MSG_WRITE_SEQ_P: // no progmem in Linux 145 | while (arg_val > MAX_PACKET) { 146 | send_data_burst(u8g, fd, arg_ptr, MAX_PACKET); 147 | arg_ptr += MAX_PACKET; 148 | arg_val -= MAX_PACKET; 149 | } 150 | send_data_burst(u8g, fd, arg_ptr, arg_val); 151 | break; 152 | 153 | case U8G_COM_MSG_ADDRESS: 154 | // choose cmd (arg_val = 0) or data mode (arg_val = 1) 155 | set_cmd_mode(u8g, !arg_val); 156 | break; 157 | } 158 | 159 | return 1; 160 | } 161 | 162 | #endif /* U8G_LINUX */ 163 | -------------------------------------------------------------------------------- /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 | #include "u8g.h" 49 | 50 | #if defined(ARDUINO) && defined(__AVR_ATtiny85__) 51 | 52 | #if ARDUINO < 100 53 | #include 54 | #else 55 | #include 56 | #endif 57 | 58 | const byte DI = 0;// D0, pin 5 Data In 59 | const byte DO = 1;// D1, pin 6 Data Out (this is *not* MOSI) 60 | const byte USCK = 2; // D2, pin 7 Universal Serial Interface clock 61 | 62 | uint8_t u8g_arduino_ATtiny85_spi_out(uint8_t val) { 63 | USIDR = val; // byte to output 64 | USISR = _BV(USIOIF); // clear Counter Overflow Interrupt Flag, set count to zero 65 | do { 66 | USICR = _BV(USIWM0) // 3-wire mode 67 | | _BV(USICS1) | _BV(USICLK) // Software clock strobe 68 | | _BV(USITC); // Toggle Clock Port Pin 69 | } 70 | while ((USISR & _BV(USIOIF)) == 0); // until Counter Overflow Interrupt Flag set 71 | 72 | return USIDR; // return read data 73 | } 74 | 75 | uint8_t u8g_com_arduino_ATtiny85_std_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 76 | switch (msg) { 77 | case U8G_COM_MSG_INIT: 78 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); // ensure SS stays high until needed 79 | pinMode(USCK, OUTPUT); 80 | pinMode(DO, OUTPUT); 81 | pinMode(u8g->pin_list[U8G_PI_CS], OUTPUT); 82 | pinMode(u8g->pin_list[U8G_PI_A0], OUTPUT); 83 | USICR = _BV(USIWM0); // 3-wire mode 84 | u8g_MicroDelay(); 85 | break; 86 | 87 | case U8G_COM_MSG_STOP: 88 | break; 89 | 90 | case U8G_COM_MSG_RESET: 91 | if (u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE) 92 | u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); 93 | break; 94 | 95 | case U8G_COM_MSG_CHIP_SELECT: 96 | if (arg_val == 0) { 97 | // disable 98 | u8g_MicroDelay(); 99 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); 100 | u8g_MicroDelay(); 101 | } 102 | else { 103 | // enable 104 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW); 105 | u8g_MicroDelay(); 106 | } 107 | break; 108 | 109 | case U8G_COM_MSG_WRITE_BYTE: 110 | u8g_arduino_ATtiny85_spi_out(arg_val); 111 | u8g_MicroDelay(); 112 | break; 113 | 114 | case U8G_COM_MSG_WRITE_SEQ: { 115 | register uint8_t *ptr = arg_ptr; 116 | while (arg_val > 0) { 117 | u8g_arduino_ATtiny85_spi_out(*ptr++); 118 | arg_val--; 119 | } 120 | } 121 | break; 122 | 123 | case U8G_COM_MSG_WRITE_SEQ_P: { 124 | register uint8_t *ptr = arg_ptr; 125 | while (arg_val > 0) { 126 | u8g_arduino_ATtiny85_spi_out(u8g_pgm_read(ptr)); 127 | ptr++; 128 | arg_val--; 129 | } 130 | } 131 | break; 132 | 133 | case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1) 134 | u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val); 135 | u8g_MicroDelay(); 136 | break; 137 | } 138 | return 1; 139 | } 140 | 141 | #else /* ARDUINO */ 142 | 143 | uint8_t u8g_com_arduino_ATtiny85_std_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 144 | return 1; 145 | } 146 | 147 | #endif /* ARDUINO */ -------------------------------------------------------------------------------- /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 | Assumes, that 35 | MOSI is at PORTB, Pin 3 36 | and 37 | SCK is at PORTB, Pin 5 38 | 39 | Update for ATOMIC operation done (01 Jun 2013) 40 | U8G_ATOMIC_OR(ptr, val) 41 | U8G_ATOMIC_AND(ptr, val) 42 | U8G_ATOMIC_START() 43 | U8G_ATOMIC_END() 44 | 45 | */ 46 | 47 | #include "u8g.h" 48 | 49 | #ifdef __AVR_XMEGA__ 50 | #elif defined(__AVR__) 51 | #define U8G_ATMEGA_HW_SPI 52 | 53 | // remove the definition for attiny 54 | #if __AVR_ARCH__ == 2 55 | #undef U8G_ATMEGA_HW_SPI 56 | #endif 57 | #if __AVR_ARCH__ == 25 58 | #undef U8G_ATMEGA_HW_SPI 59 | #endif 60 | #endif 61 | 62 | #ifdef U8G_ATMEGA_HW_SPI 63 | 64 | #include 65 | #include 66 | 67 | static uint8_t u8g_atmega_spi_out(uint8_t data) { 68 | // unsigned char x = 100; 69 | // send data 70 | SPDR = data; 71 | // wait for transmission 72 | while (!(SPSR & (1 << SPIF))); 73 | // clear the SPIF flag by reading SPDR 74 | return SPDR; 75 | } 76 | 77 | uint8_t u8g_com_atmega_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 78 | switch (msg) { 79 | case U8G_COM_MSG_STOP: 80 | break; 81 | 82 | case U8G_COM_MSG_INIT: 83 | 84 | u8g_SetPIOutput(u8g, U8G_PI_CS); 85 | u8g_SetPIOutput(u8g, U8G_PI_A0); 86 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 87 | 88 | U8G_ATOMIC_START(); 89 | 90 | DDRB |= _BV(3); // D0, MOSI 91 | DDRB |= _BV(5); // SCK 92 | DDRB |= _BV(2); // slave select 93 | 94 | PORTB &= ~_BV(3); // D0, MOSI = 0 95 | PORTB &= ~_BV(5); // SCK = 0 96 | 97 | U8G_ATOMIC_END(); 98 | 99 | u8g_SetPILevel(u8g, U8G_PI_CS, 1); 100 | 101 | /* 102 | SPR1 SPR0 103 | 0 0 fclk/4 x 104 | 0 1 fclk/16 105 | 1 0 fclk/64 106 | 1 1 fclk/128 107 | */ 108 | SPCR = 0; 109 | SPCR = (1 << SPE) | (1 << MSTR) | (0 << SPR1) | (0 << SPR0) | (0 << CPOL) | (0 << CPHA); 110 | #ifdef U8G_HW_SPI_2X 111 | SPSR = (1 << SPI2X); // double speed, issue 89 112 | #endif 113 | 114 | break; 115 | 116 | case U8G_COM_MSG_ADDRESS: // define cmd (arg_val = 0) or data mode (arg_val = 1) 117 | u8g_SetPILevel(u8g, U8G_PI_A0, arg_val); 118 | break; 119 | 120 | case U8G_COM_MSG_CHIP_SELECT: 121 | 122 | if (arg_val == 0) { 123 | // disable 124 | u8g_SetPILevel(u8g, U8G_PI_CS, 1); 125 | } 126 | else { 127 | PORTB &= ~_BV(5); // SCK = 0 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_atmega_spi_out(arg_val); 140 | break; 141 | 142 | case U8G_COM_MSG_WRITE_SEQ: { 143 | register uint8_t *ptr = arg_ptr; 144 | while (arg_val > 0) { 145 | u8g_atmega_spi_out(*ptr++); 146 | arg_val--; 147 | } 148 | } 149 | break; 150 | case U8G_COM_MSG_WRITE_SEQ_P: { 151 | register uint8_t *ptr = arg_ptr; 152 | while (arg_val > 0) { 153 | u8g_atmega_spi_out(u8g_pgm_read(ptr)); 154 | ptr++; 155 | arg_val--; 156 | } 157 | } 158 | break; 159 | } 160 | return 1; 161 | } 162 | 163 | #else // ifdef U8G_ATMEGA_HW_SPI 164 | 165 | uint8_t u8g_com_atmega_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 166 | return 1; 167 | } 168 | 169 | #endif // ifdef U8G_ATMEGA_HW_SPI 170 | -------------------------------------------------------------------------------- /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 | struct _u8g_pb_t 37 | { 38 | u8g_page_t p; 39 | u8g_uint_t width; 40 | void *buf; 41 | }; 42 | typedef struct _u8g_pb_t u8g_pb_t; 43 | 44 | uint8_t u8g_index_color_xh16_buf[2*WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ; 45 | u8g_pb_t u8g_index_color_xh16_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_index_color_xh16_buf}; 46 | u8g_dev_t name = { dev_fn, &u8g_index_color_xh16_pb , com_fn } 47 | 48 | */ 49 | 50 | #include "u8g.h" 51 | 52 | /* 53 | #define WIDTH_BITS 7 54 | #define WIDTH (1<buf; 61 | uint8_t *end_ptr = ptr; 62 | uint8_t cnt = b->p.page_height; 63 | do { 64 | end_ptr += b->width * 2; 65 | cnt--; 66 | } while (cnt > 0); 67 | do { 68 | *ptr++ = 0; 69 | } while (ptr != end_ptr); 70 | } 71 | 72 | void u8g_pbxh16_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) { 73 | b->buf = buf; 74 | b->width = width; 75 | u8g_pbxh16_Clear(b); 76 | } 77 | 78 | static void u8g_pbxh16_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t low, uint8_t high) { 79 | uint16_t tmp; 80 | uint8_t *ptr = b->buf; 81 | y -= b->p.page_y0; 82 | tmp = y; 83 | tmp *= b->width; 84 | tmp += x; 85 | tmp <<= 1; 86 | ptr += tmp; 87 | *ptr = low; 88 | ptr++; 89 | *ptr = high; 90 | } 91 | 92 | void u8g_pbxh16_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) { 93 | if (arg_pixel->y < b->p.page_y0) 94 | return; 95 | if (arg_pixel->y > b->p.page_y1) 96 | return; 97 | if (arg_pixel->x >= b->width) 98 | return; 99 | u8g_pbxh16_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color, arg_pixel->hi_color); 100 | } 101 | 102 | void u8g_pbxh16_Set8Pixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) { 103 | register uint8_t pixel = arg_pixel->pixel; 104 | u8g_uint_t dx = 0; 105 | u8g_uint_t dy = 0; 106 | 107 | switch (arg_pixel->dir) { 108 | case 0: dx++; break; 109 | case 1: dy++; break; 110 | case 2: dx--; break; 111 | case 3: dy--; break; 112 | } 113 | 114 | do { 115 | if (pixel & 128) 116 | u8g_pbxh16_SetPixel(b, arg_pixel); 117 | arg_pixel->x += dx; 118 | arg_pixel->y += dy; 119 | pixel <<= 1; 120 | } while (pixel != 0); 121 | } 122 | 123 | uint8_t u8g_dev_pbxh16_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) { 124 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 125 | switch (msg) { 126 | case U8G_DEV_MSG_SET_8PIXEL: 127 | if (u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg)) 128 | u8g_pbxh16_Set8Pixel(pb, (u8g_dev_arg_pixel_t *)arg); 129 | break; 130 | case U8G_DEV_MSG_SET_PIXEL: 131 | u8g_pbxh16_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 132 | break; 133 | case U8G_DEV_MSG_INIT: 134 | break; 135 | case U8G_DEV_MSG_STOP: 136 | break; 137 | case U8G_DEV_MSG_PAGE_FIRST: 138 | u8g_pbxh16_Clear(pb); 139 | u8g_page_First(&(pb->p)); 140 | break; 141 | case U8G_DEV_MSG_PAGE_NEXT: 142 | if (u8g_page_Next(&(pb->p)) == 0) 143 | return 0; 144 | u8g_pbxh16_Clear(pb); 145 | break; 146 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 147 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 148 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 149 | #endif 150 | case U8G_DEV_MSG_GET_PAGE_BOX: 151 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 152 | break; 153 | case U8G_DEV_MSG_GET_WIDTH: 154 | *((u8g_uint_t *)arg) = pb->width; 155 | break; 156 | case U8G_DEV_MSG_GET_HEIGHT: 157 | *((u8g_uint_t *)arg) = pb->p.total_height; 158 | break; 159 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 160 | break; 161 | case U8G_DEV_MSG_SET_XY_CB: 162 | break; 163 | case U8G_DEV_MSG_GET_MODE: 164 | return U8G_MODE_HICOLOR; 165 | } 166 | return 1; 167 | } 168 | -------------------------------------------------------------------------------- /src/clib/u8g_pb16v1.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_pb16v1.c 4 | 5 | 16bit 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 | #include "u8g.h" 40 | #include 41 | 42 | void u8g_pb16v1_Clear(u8g_pb_t *b) { 43 | uint8_t *ptr = (uint8_t *)b->buf; 44 | uint8_t *end_ptr = ptr; 45 | end_ptr += b->width * 2; 46 | do { 47 | *ptr++ = 0; 48 | } while (ptr != end_ptr); 49 | } 50 | 51 | // Obsolete, usually set by the init of the structure 52 | void u8g_pb16v1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) { 53 | b->buf = buf; 54 | b->width = width; 55 | u8g_pb16v1_Clear(b); 56 | } 57 | 58 | void u8g_pb16v1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) { 59 | register uint8_t mask; 60 | uint8_t *ptr = b->buf; 61 | 62 | y -= b->p.page_y0; 63 | if (y >= 8) { 64 | ptr += b->width; 65 | y &= 0x07; 66 | } 67 | mask = 1; 68 | mask <<= y; 69 | ptr += x; 70 | if (color_index) { 71 | *ptr |= mask; 72 | } 73 | else { 74 | mask ^= 0xff; 75 | *ptr &= mask; 76 | } 77 | } 78 | 79 | void u8g_pb16v1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) { 80 | if (arg_pixel->y < b->p.page_y0) 81 | return; 82 | if (arg_pixel->y > b->p.page_y1) 83 | return; 84 | if (arg_pixel->x >= b->width) 85 | return; 86 | u8g_pb16v1_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 87 | } 88 | 89 | void u8g_pb16v1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) { 90 | register uint8_t pixel = arg_pixel->pixel; 91 | do { 92 | if (pixel & 128) 93 | u8g_pb16v1_SetPixel(b, arg_pixel); 94 | switch (arg_pixel->dir) { 95 | case 0: arg_pixel->x++; break; 96 | case 1: arg_pixel->y++; break; 97 | case 2: arg_pixel->x--; break; 98 | case 3: arg_pixel->y--; break; 99 | } 100 | pixel <<= 1; 101 | } while (pixel != 0); 102 | } 103 | 104 | void u8g_pb16v1_Set8PixelOpt2(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) { 105 | register uint8_t pixel = arg_pixel->pixel; 106 | u8g_uint_t dx = 0; 107 | u8g_uint_t dy = 0; 108 | 109 | switch (arg_pixel->dir) { 110 | case 0: dx++; break; 111 | case 1: dy++; break; 112 | case 2: dx--; break; 113 | case 3: dy--; break; 114 | } 115 | 116 | do { 117 | if (pixel & 128) 118 | u8g_pb16v1_SetPixel(b, arg_pixel); 119 | arg_pixel->x += dx; 120 | arg_pixel->y += dy; 121 | pixel <<= 1; 122 | } while (pixel != 0); 123 | 124 | } 125 | 126 | uint8_t u8g_dev_pb16v1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) { 127 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 128 | switch (msg) { 129 | case U8G_DEV_MSG_SET_8PIXEL: 130 | if (u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg)) 131 | u8g_pb16v1_Set8PixelOpt2(pb, (u8g_dev_arg_pixel_t *)arg); 132 | break; 133 | case U8G_DEV_MSG_SET_PIXEL: 134 | u8g_pb16v1_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_pb16v1_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_pb16v1_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_BW; 168 | } 169 | return 1; 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 | 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 | uint8_t u8g_index_color_8h8_buf[WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ; 46 | u8g_pb_t u8g_index_color_8h8_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_index_color_8h8_buff}; 47 | u8g_dev_t name = { dev_fn, &u8g_index_color_8h8_pb, com_fn } 48 | 49 | */ 50 | 51 | #include "u8g.h" 52 | 53 | /* 54 | #define WIDTH_BITS 7 55 | #define WIDTH (1<buf; 62 | uint8_t *end_ptr = ptr; 63 | uint8_t cnt = b->p.page_height; 64 | end_ptr += b->width * cnt; 65 | /* 66 | do 67 | { 68 | end_ptr += b->width; 69 | cnt--; 70 | } while( cnt > 0 ); 71 | */ 72 | do { 73 | *ptr++ = 0; 74 | } while (ptr != end_ptr); 75 | } 76 | 77 | void u8g_pb8h8_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) { 78 | b->buf = buf; 79 | b->width = width; 80 | u8g_pb8h8_Clear(b); 81 | } 82 | 83 | static void u8g_pb8h8_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) { 84 | uint16_t tmp; 85 | uint8_t *ptr = b->buf; 86 | y -= b->p.page_y0; 87 | tmp = y; 88 | tmp *= b->width; 89 | tmp += x; 90 | ptr += tmp; 91 | *ptr = color_index; 92 | } 93 | 94 | void u8g_pb8h8_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) { 95 | if (arg_pixel->y < b->p.page_y0) 96 | return; 97 | if (arg_pixel->y > b->p.page_y1) 98 | return; 99 | if (arg_pixel->x >= b->width) 100 | return; 101 | u8g_pb8h8_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 102 | } 103 | 104 | void u8g_pb8h8_Set8Pixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) { 105 | register uint8_t pixel = arg_pixel->pixel; 106 | u8g_uint_t dx = 0; 107 | u8g_uint_t dy = 0; 108 | 109 | switch (arg_pixel->dir) { 110 | case 0: dx++; break; 111 | case 1: dy++; break; 112 | case 2: dx--; break; 113 | case 3: dy--; break; 114 | } 115 | 116 | do { 117 | if (pixel & 128) 118 | u8g_pb8h8_SetPixel(b, arg_pixel); 119 | arg_pixel->x += dx; 120 | arg_pixel->y += dy; 121 | pixel <<= 1; 122 | } while (pixel != 0); 123 | } 124 | 125 | uint8_t u8g_dev_pb8h8_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) { 126 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 127 | switch (msg) { 128 | case U8G_DEV_MSG_SET_8PIXEL: 129 | if (u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg)) 130 | u8g_pb8h8_Set8Pixel(pb, (u8g_dev_arg_pixel_t *)arg); 131 | break; 132 | case U8G_DEV_MSG_SET_PIXEL: 133 | u8g_pb8h8_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 134 | break; 135 | case U8G_DEV_MSG_INIT: 136 | break; 137 | case U8G_DEV_MSG_STOP: 138 | break; 139 | case U8G_DEV_MSG_PAGE_FIRST: 140 | u8g_pb8h8_Clear(pb); 141 | u8g_page_First(&(pb->p)); 142 | break; 143 | case U8G_DEV_MSG_PAGE_NEXT: 144 | if (u8g_page_Next(&(pb->p)) == 0) 145 | return 0; 146 | u8g_pb8h8_Clear(pb); 147 | break; 148 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 149 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 150 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 151 | #endif 152 | case U8G_DEV_MSG_GET_PAGE_BOX: 153 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 154 | break; 155 | case U8G_DEV_MSG_GET_WIDTH: 156 | *((u8g_uint_t *)arg) = pb->width; 157 | break; 158 | case U8G_DEV_MSG_GET_HEIGHT: 159 | *((u8g_uint_t *)arg) = pb->p.total_height; 160 | break; 161 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 162 | break; 163 | case U8G_DEV_MSG_SET_XY_CB: 164 | break; 165 | case U8G_DEV_MSG_GET_MODE: 166 | return U8G_MODE_R3G3B2; 167 | } 168 | return 1; 169 | } 170 | -------------------------------------------------------------------------------- /src/clib/u8g_pb14v1.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_pb14v1.c 4 | 5 | 14bit height monochrom (1 bit) page buffer, 6 | byte has vertical orientation, 7 bits per byte 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 | #include 41 | 42 | void u8g_pb14v1_Clear(u8g_pb_t *b) { 43 | uint8_t *ptr = (uint8_t *)b->buf; 44 | uint8_t *end_ptr = ptr; 45 | end_ptr += b->width * 2; 46 | do { 47 | *ptr++ = 0; 48 | } while (ptr != end_ptr); 49 | } 50 | 51 | // Obsolete, usually set by the init of the structure 52 | void u8g_pb14v1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) { 53 | b->buf = buf; 54 | b->width = width; 55 | u8g_pb14v1_Clear(b); 56 | } 57 | 58 | void u8g_pb14v1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) { 59 | register uint8_t mask; 60 | uint8_t *ptr = b->buf; 61 | 62 | y -= b->p.page_y0; 63 | if (y >= 7) { 64 | ptr += b->width; 65 | y -= 7; 66 | } 67 | mask = 1; 68 | mask <<= y; 69 | ptr += x; 70 | if (color_index) { 71 | *ptr |= mask; 72 | } 73 | else { 74 | mask ^= 0xff; 75 | *ptr &= mask; 76 | } 77 | } 78 | 79 | void u8g_pb14v1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) { 80 | if (arg_pixel->y < b->p.page_y0) 81 | return; 82 | if (arg_pixel->y > b->p.page_y1) 83 | return; 84 | if (arg_pixel->x >= b->width) 85 | return; 86 | u8g_pb14v1_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 87 | } 88 | 89 | void u8g_pb14v1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) { 90 | register uint8_t pixel = arg_pixel->pixel; 91 | do { 92 | if (pixel & 128) 93 | u8g_pb14v1_SetPixel(b, arg_pixel); 94 | switch (arg_pixel->dir) { 95 | case 0: arg_pixel->x++; break; 96 | case 1: arg_pixel->y++; break; 97 | case 2: arg_pixel->x--; break; 98 | case 3: arg_pixel->y--; break; 99 | } 100 | pixel <<= 1; 101 | } while (pixel != 0); 102 | } 103 | 104 | void u8g_pb14v1_Set8PixelOpt2(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) { 105 | register uint8_t pixel = arg_pixel->pixel; 106 | u8g_uint_t dx = 0; 107 | u8g_uint_t dy = 0; 108 | 109 | switch (arg_pixel->dir) { 110 | case 0: dx++; break; 111 | case 1: dy++; break; 112 | case 2: dx--; break; 113 | case 3: dy--; break; 114 | } 115 | 116 | do { 117 | if (pixel & 128) 118 | u8g_pb14v1_SetPixel(b, arg_pixel); 119 | arg_pixel->x += dx; 120 | arg_pixel->y += dy; 121 | pixel <<= 1; 122 | } while (pixel != 0); 123 | 124 | } 125 | 126 | uint8_t u8g_dev_pb14v1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) { 127 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 128 | switch (msg) { 129 | case U8G_DEV_MSG_SET_8PIXEL: 130 | if (u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg)) 131 | u8g_pb14v1_Set8PixelOpt2(pb, (u8g_dev_arg_pixel_t *)arg); 132 | break; 133 | case U8G_DEV_MSG_SET_PIXEL: 134 | u8g_pb14v1_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_pb14v1_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_pb14v1_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_BW; 168 | } 169 | return 1; 170 | } 171 | --------------------------------------------------------------------------------