├── virtualwire.CHANGES ├── RCSwitch.h ├── RCSwitch.cpp ├── utility ├── chessengine.c ├── u8g_font_data.c ├── u8g_com_null.c ├── u8g_u16toa.c ├── u8g_u8toa.c ├── u8g_dev_null.c ├── u8g_com_arduino_common.c ├── u8g_page.c ├── u8g_line.c ├── u8g_cursor.c ├── u8g_dev_flipdisc_2x7.c ├── u8g_com_api_16gr.c ├── u8g_dev_gprof.c ├── u8g_dev_sbn1661_122x32.c ├── u8g_com_atmega_sw_spi.c ├── u8g_dev_ks0108_128x64.c ├── u8g_state.c ├── u8g_com_arduino_std_sw_spi.c ├── u8g_pb8v2.c ├── u8g_com_arduino_hw_usart_spi.c ├── u8g_bitmap.c ├── u8g_dev_pcd8544_84x48.c ├── u8g_dev_tls8204_84x48.c ├── u8g_pb8h2.c ├── u8g_clip.c ├── u8g_virtual_screen.c ├── u8g_pb16v2.c ├── u8g_pb.c ├── u8g_com_atmega_hw_spi.c ├── u8g_com_api.c ├── u8g_com_arduino_attiny85_hw_spi.c ├── u8g_pbxh16.c ├── u8g_com_atmega_st7920_spi.c ├── u8g_pb8h8.c ├── u8g_pb8v1.c ├── u8g_com_arduino_port_d_wr.c ├── u8g_dev_pcf8812_96x65.c ├── u8g_dev_lc7981_240x64.c └── u8g_dev_lc7981_240x128.c ├── MirfSpiDriver.cpp ├── virtualwire.README ├── MirfSpiDriver.h ├── MirfHardwareSpiDriver.cpp ├── MirfHardwareSpiDriver.h ├── README.md ├── u8g.INSTALL.TXT ├── examples ├── vwReceiver │ └── vwReceiver.ino ├── nRF24Receiver │ └── nRF24Receiver.ino ├── nRF24Sender │ └── nRF24Sender.ino ├── tempDisplay │ └── tempDisplay.ino └── vwSender │ └── vwSender.ino ├── U8glib.cpp ├── Mirf.h ├── VWutil └── crc16.h ├── nRF24L01.h ├── u8g.license.txt ├── VirtualWire_Config.h └── u8g.ChangeLog /virtualwire.CHANGES: -------------------------------------------------------------------------------- 1 | See VirtulWire.h for latest change log 2 | -------------------------------------------------------------------------------- /RCSwitch.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rayshobby/RFToy/HEAD/RCSwitch.h -------------------------------------------------------------------------------- /RCSwitch.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rayshobby/RFToy/HEAD/RCSwitch.cpp -------------------------------------------------------------------------------- /utility/chessengine.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rayshobby/RFToy/HEAD/utility/chessengine.c -------------------------------------------------------------------------------- /utility/u8g_font_data.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rayshobby/RFToy/HEAD/utility/u8g_font_data.c -------------------------------------------------------------------------------- /MirfSpiDriver.cpp: -------------------------------------------------------------------------------- 1 | #include "MirfSpiDriver.h" 2 | 3 | uint8_t MirfSpiDriver::transfer(uint8_t data){ 4 | return 0; 5 | } 6 | 7 | void MirfSpiDriver::begin(){ 8 | } 9 | 10 | void MirfSpiDriver::end(){ 11 | } 12 | -------------------------------------------------------------------------------- /virtualwire.README: -------------------------------------------------------------------------------- 1 | Virtual Wire 2 | 3 | This is the VirtualWire library for Arduino 4 | It provides a simple message passing protocol for a range of inexpensive 5 | transmitter and receiver modules. 6 | 7 | See http://www.open.com.au/mikem/arduino/VirtualWire.pdf for full documentation. 8 | 9 | -------------------------------------------------------------------------------- /MirfSpiDriver.h: -------------------------------------------------------------------------------- 1 | #ifndef __MIRF_SPI_DRIVER 2 | #define __MIRF_SPI_DRIVER 3 | 4 | extern "C" { 5 | #include 6 | #include 7 | } 8 | 9 | class MirfSpiDriver { 10 | public: 11 | virtual uint8_t transfer(uint8_t data); 12 | 13 | virtual void begin(); 14 | virtual void end(); 15 | }; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /MirfHardwareSpiDriver.cpp: -------------------------------------------------------------------------------- 1 | #include "MirfHardwareSpiDriver.h" 2 | uint8_t MirfHardwareSpiDriver::transfer(uint8_t data){ 3 | return SPI.transfer(data); 4 | } 5 | 6 | void MirfHardwareSpiDriver::begin(){ 7 | SPI.begin(); 8 | SPI.setDataMode(SPI_MODE0); 9 | SPI.setClockDivider(SPI_2XCLOCK_MASK); 10 | } 11 | 12 | void MirfHardwareSpiDriver::end(){ 13 | } 14 | 15 | MirfHardwareSpiDriver MirfHardwareSpi; 16 | -------------------------------------------------------------------------------- /MirfHardwareSpiDriver.h: -------------------------------------------------------------------------------- 1 | #include "MirfSpiDriver.h" 2 | 3 | #ifndef __MIRF_HARDWARE_SPI_DRIVER 4 | #define __MIRF_HARDWARE_SPI_DRIVER 5 | 6 | #include 7 | 8 | class MirfHardwareSpiDriver : public MirfSpiDriver { 9 | 10 | public: 11 | virtual uint8_t transfer(uint8_t data); 12 | virtual void begin(); 13 | virtual void end(); 14 | }; 15 | 16 | extern MirfHardwareSpiDriver MirfHardwareSpi; 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | RFToy Arduino Library 2 | ===================== 3 | 4 | Arduino library and example code for RFToy -- 5 | an Arduino-compatible gadget for RF modules. 6 | 7 | Check details at http://rftoy.rayshobby.net 8 | 9 | This folder includes the following open-source 10 | libraries: 11 | - U8g library for 128x64 OLED display 12 | - RCSwitch 13 | - VirtualWire 14 | - Mirf (for nRF24L01) 15 | 16 | RFToy is Arduino-compatible (ATmega328p running 17 | at 3.3V 8MHz). When uploading a program, select 18 | Lilypad w/ ATmega328p (or Arduino Pro 3.3V 8MHz 19 | w/ ATmega328p) as board. 20 | -------------------------------------------------------------------------------- /u8g.INSTALL.TXT: -------------------------------------------------------------------------------- 1 | 2 | U8GLIB 3 | http://code.google.com/p/u8glib/ 4 | 5 | 6 | Install instructions for the Arduino environment. 7 | 8 | 1. Unzip u8glib_arduino_vX.XX.zip into the "libraries" folder 9 | 2. Start Arduino IDE 10 | 11 | Install instructions for the Chipkit (Arduino) environment. 12 | 13 | 1. cd /libraries 14 | 2. unzip u8glib_arduino_vX.XX.zip 15 | 3. cd ///hardware/pic32/libraries 16 | 4. again: u8glib_arduino_vX.XX.zip 17 | 5. Open hardware/pic32/cores/pic32/Print.h 18 | Remove line 19 | #define BYTE 0 20 | from the file, use PRINT_BYTE instead of BYTE. 21 | -------------------------------------------------------------------------------- /examples/vwReceiver/vwReceiver.ino: -------------------------------------------------------------------------------- 1 | /* 2 | VirtualWire Receiver Demo for RFToy 3 | 4 | This demo shows how to use RFToy to make a 5 | wireless temperature sensor. This is the 6 | receiver module which displays the received 7 | temperature value to OLED. The demo uses 8 | the VirtualWire library. 9 | 10 | Because the RF Receiver only works with 5V, 11 | you need to plug in a mini-USB cable. 12 | 13 | Written by Jonathan Goldin @ Rayshobby LLC 14 | Nov 2014 15 | For details, visit http://rayshobby.net/rftoy 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | 24 | U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE); // I2C / TWI 25 | 26 | void setup() 27 | { 28 | Serial.begin(9600); // Debugging only 29 | 30 | vw_set_rx_pin(2); 31 | vw_setup(2000); // Bits per sec 32 | 33 | vw_rx_start(); // Start the receiver PLL running 34 | 35 | u8g.firstPage(); 36 | do{ 37 | u8g.setFont(u8g_font_10x20); 38 | u8g.setFontRefHeightText(); 39 | u8g.setFontPosTop(); 40 | u8g.drawStr(0,0,"No Reading."); 41 | } while(u8g.nextPage()); 42 | 43 | } 44 | 45 | void loop() 46 | { 47 | uint8_t buf[VW_MAX_MESSAGE_LEN]; 48 | uint8_t buflen = VW_MAX_MESSAGE_LEN; 49 | 50 | if (vw_get_message(buf, &buflen)) // Non-blocking 51 | { 52 | String s = String(atof((char*)buf)/10); 53 | s+=(char)(176); 54 | s+="C"; 55 | u8g.firstPage(); 56 | do{ 57 | u8g.setFont(u8g_font_10x20); 58 | u8g.setFontRefHeightText(); 59 | u8g.setFontPosTop(); 60 | u8g.drawStr(0,0,s.c_str()); 61 | 62 | } while(u8g.nextPage()); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /utility/u8g_com_null.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_null.c 4 | 5 | communication null device 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, olikraus@gmail.com 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this list 16 | of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, this 19 | list of conditions and the following disclaimer in the documentation and/or other 20 | materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | */ 38 | 39 | #include "u8g.h" 40 | 41 | uint8_t u8g_com_null_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 42 | { 43 | switch(msg) 44 | { 45 | case U8G_COM_MSG_INIT: 46 | break; 47 | case U8G_COM_MSG_STOP: 48 | break; 49 | 50 | 51 | case U8G_COM_MSG_CHIP_SELECT: 52 | /* arg_val contains the chip number, which should be enabled */ 53 | break; 54 | 55 | 56 | case U8G_COM_MSG_WRITE_BYTE: 57 | break; 58 | case U8G_COM_MSG_WRITE_SEQ: 59 | break; 60 | } 61 | return 1; 62 | } 63 | 64 | -------------------------------------------------------------------------------- /utility/u8g_u16toa.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_u16toa.c 4 | 5 | 6 | Universal 8bit Graphics Library 7 | 8 | Copyright (c) 2012, olikraus@gmail.com 9 | All rights reserved. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | * Redistributions of source code must retain the above copyright notice, this list 15 | of conditions and the following disclaimer. 16 | 17 | * Redistributions in binary form must reproduce the above copyright notice, this 18 | list of conditions and the following disclaimer in the documentation and/or other 19 | materials provided with the distribution. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 22 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 23 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 33 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | 38 | #include "u8g.h" 39 | 40 | const char *u8g_u16toap(char * dest, uint16_t v) 41 | { 42 | uint8_t pos; 43 | uint8_t d; 44 | uint16_t c; 45 | c = 10000; 46 | for( pos = 0; pos < 5; pos++ ) 47 | { 48 | d = '0'; 49 | while( v >= c ) 50 | { 51 | v -= c; 52 | d++; 53 | } 54 | dest[pos] = d; 55 | c /= 10; 56 | } 57 | dest[5] = '\0'; 58 | return dest; 59 | } 60 | 61 | /* v = value, d = number of digits */ 62 | const char *u8g_u16toa(uint16_t v, uint8_t d) 63 | { 64 | static char buf[6]; 65 | d = 5-d; 66 | return u8g_u16toap(buf, v) + d; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /utility/u8g_u8toa.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_u8toa.c 4 | 5 | 6 | Universal 8bit Graphics Library 7 | 8 | Copyright (c) 2011, olikraus@gmail.com 9 | All rights reserved. 10 | 11 | Redistribution and use in source and binary forms, with or without modification, 12 | are permitted provided that the following conditions are met: 13 | 14 | * Redistributions of source code must retain the above copyright notice, this list 15 | of conditions and the following disclaimer. 16 | 17 | * Redistributions in binary form must reproduce the above copyright notice, this 18 | list of conditions and the following disclaimer in the documentation and/or other 19 | materials provided with the distribution. 20 | 21 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 22 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 23 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 25 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 33 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | */ 36 | 37 | 38 | #include "u8g.h" 39 | 40 | static const unsigned char u8g_u8toa_tab[3] = { 100, 10, 1 } ; 41 | const char *u8g_u8toap(char * dest, uint8_t v) 42 | { 43 | uint8_t pos; 44 | uint8_t d; 45 | uint8_t c; 46 | for( pos = 0; pos < 3; pos++ ) 47 | { 48 | d = '0'; 49 | c = *(u8g_u8toa_tab+pos); 50 | while( v >= c ) 51 | { 52 | v -= c; 53 | d++; 54 | } 55 | dest[pos] = d; 56 | } 57 | dest[3] = '\0'; 58 | return dest; 59 | } 60 | 61 | /* v = value, d = number of digits */ 62 | const char *u8g_u8toa(uint8_t v, uint8_t d) 63 | { 64 | static char buf[4]; 65 | d = 3-d; 66 | return u8g_u8toap(buf, v) + d; 67 | } 68 | 69 | -------------------------------------------------------------------------------- /utility/u8g_dev_null.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_null.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | */ 36 | 37 | #include "u8g.h" 38 | 39 | uint8_t u8g_dev_null(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 40 | { 41 | switch(msg) 42 | { 43 | case U8G_DEV_MSG_SET_8PIXEL: /* most often used command */ 44 | break; 45 | case U8G_DEV_MSG_SET_PIXEL: 46 | break; 47 | case U8G_DEV_MSG_INIT: 48 | break; 49 | case U8G_DEV_MSG_STOP: 50 | break; 51 | case U8G_DEV_MSG_PAGE_FIRST: 52 | break; 53 | case U8G_DEV_MSG_PAGE_NEXT: 54 | break; 55 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 56 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 57 | return 1; 58 | #endif 59 | case U8G_DEV_MSG_GET_PAGE_BOX: 60 | break; 61 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 62 | break; 63 | case U8G_DEV_MSG_SET_XY_CB: 64 | break; 65 | } 66 | return 1; 67 | } 68 | -------------------------------------------------------------------------------- /utility/u8g_com_arduino_common.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_arduino_common.c 4 | 5 | shared procedures for the arduino communication procedures 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, olikraus@gmail.com 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this list 16 | of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, this 19 | list of conditions and the following disclaimer in the documentation and/or other 20 | materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | */ 38 | 39 | #include "u8g.h" 40 | 41 | #if defined(ARDUINO) 42 | 43 | #if ARDUINO < 100 44 | #include 45 | #else 46 | #include 47 | #endif 48 | 49 | void u8g_com_arduino_digital_write(u8g_t *u8g, uint8_t pin_index, uint8_t value) 50 | { 51 | uint8_t pin; 52 | pin = u8g->pin_list[pin_index]; 53 | if ( pin != U8G_PIN_NONE ) 54 | digitalWrite(pin, value); 55 | } 56 | 57 | /* this procedure does not set the RW pin */ 58 | void u8g_com_arduino_assign_pin_output_high(u8g_t *u8g) 59 | { 60 | uint8_t i; 61 | /* skip the RW pin, which is the last pin in the list */ 62 | for( i = 0; i < U8G_PIN_LIST_LEN-1; i++ ) 63 | { 64 | if ( u8g->pin_list[i] != U8G_PIN_NONE ) 65 | { 66 | pinMode(u8g->pin_list[i], OUTPUT); 67 | digitalWrite(u8g->pin_list[i], HIGH); 68 | } 69 | } 70 | } 71 | 72 | 73 | #endif 74 | 75 | 76 | -------------------------------------------------------------------------------- /utility/u8g_page.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_page.c 4 | 5 | page helper functions, only called by the dev handler. 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, olikraus@gmail.com 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this list 16 | of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, this 19 | list of conditions and the following disclaimer in the documentation and/or other 20 | materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | */ 38 | 39 | #include "u8g.h" 40 | 41 | /* 42 | setup page count structure 43 | conditions: page_height <= total_height 44 | */ 45 | void u8g_page_Init(u8g_page_t *p, u8g_uint_t page_height, u8g_uint_t total_height ) 46 | { 47 | p->page_height = page_height; 48 | p->total_height = total_height; 49 | p->page = 0; 50 | u8g_page_First(p); 51 | } 52 | 53 | void u8g_page_First(u8g_page_t *p) 54 | { 55 | p->page_y0 = 0; 56 | p->page_y1 = p->page_height; 57 | p->page_y1--; 58 | p->page = 0; 59 | } 60 | 61 | uint8_t u8g_page_Next(u8g_page_t * p) 62 | { 63 | register u8g_uint_t y1; 64 | p->page_y0 += p->page_height; 65 | if ( p->page_y0 >= p->total_height ) 66 | return 0; 67 | p->page++; 68 | y1 = p->page_y1; 69 | y1 += p->page_height; 70 | if ( y1 >= p->total_height ) 71 | { 72 | y1 = p->total_height; 73 | y1--; 74 | } 75 | p->page_y1 = y1; 76 | 77 | return 1; 78 | } 79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /utility/u8g_line.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_line.h 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2012, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | */ 35 | 36 | #include "u8g.h" 37 | 38 | void u8g_DrawLine(u8g_t *u8g, u8g_uint_t x1, u8g_uint_t y1, u8g_uint_t x2, u8g_uint_t y2) 39 | { 40 | u8g_uint_t tmp; 41 | u8g_uint_t x,y; 42 | u8g_uint_t dx, dy; 43 | u8g_int_t err; 44 | u8g_int_t ystep; 45 | 46 | uint8_t swapxy = 0; 47 | 48 | /* no BBX intersection check at the moment, should be added... */ 49 | 50 | if ( x1 > x2 ) dx = x1-x2; else dx = x2-x1; 51 | if ( y1 > y2 ) dy = y1-y2; else dy = y2-y1; 52 | 53 | if ( dy > dx ) 54 | { 55 | swapxy = 1; 56 | tmp = dx; dx =dy; dy = tmp; 57 | tmp = x1; x1 =y1; y1 = tmp; 58 | tmp = x2; x2 =y2; y2 = tmp; 59 | } 60 | if ( x1 > x2 ) 61 | { 62 | tmp = x1; x1 =x2; x2 = tmp; 63 | tmp = y1; y1 =y2; y2 = tmp; 64 | } 65 | err = dx >> 1; 66 | if ( y2 > y1 ) ystep = 1; else ystep = -1; 67 | y = y1; 68 | for( x = x1; x <= x2; x++ ) 69 | { 70 | if ( swapxy == 0 ) 71 | u8g_DrawPixel(u8g, x, y); 72 | else 73 | u8g_DrawPixel(u8g, y, x); 74 | err -= (uint8_t)dy; 75 | if ( err < 0 ) 76 | { 77 | y += (u8g_uint_t)ystep; 78 | err += (u8g_uint_t)dx; 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /U8glib.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | U8glib.cpp 4 | 5 | C++ Interface 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, olikraus@gmail.com 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this list 16 | of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, this 19 | list of conditions and the following disclaimer in the documentation and/or other 20 | materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | */ 37 | 38 | #include "U8glib.h" 39 | 40 | 41 | 42 | uint8_t U8GLIB::initSPI(u8g_dev_t *dev, uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset) 43 | { 44 | prepare(); 45 | return u8g_InitSPI(&u8g, dev, sck, mosi, cs, a0, reset); 46 | } 47 | 48 | uint8_t U8GLIB::initHWSPI(u8g_dev_t *dev, uint8_t cs, uint8_t a0, uint8_t reset) 49 | { 50 | prepare(); 51 | return u8g_InitHWSPI(&u8g, dev, cs, a0, reset); 52 | } 53 | 54 | uint8_t U8GLIB::initI2C(u8g_dev_t *dev, uint8_t options) 55 | { 56 | prepare(); 57 | return u8g_InitI2C(&u8g, dev, options); 58 | } 59 | 60 | uint8_t U8GLIB::init8Bit(u8g_dev_t *dev, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7, 61 | uint8_t en, uint8_t cs1, uint8_t cs2, uint8_t di, uint8_t rw, uint8_t reset) 62 | { 63 | prepare(); 64 | return u8g_Init8Bit(&u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset); 65 | } 66 | 67 | uint8_t U8GLIB::init8BitFixedPort(u8g_dev_t *dev, uint8_t en, uint8_t cs, uint8_t di, uint8_t rw, uint8_t reset) 68 | { 69 | prepare(); 70 | return u8g_Init8BitFixedPort(&u8g, dev, en, cs, di, rw, reset); 71 | } 72 | 73 | uint8_t U8GLIB::initRW8Bit(u8g_dev_t *dev, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7, 74 | uint8_t cs, uint8_t a0, uint8_t wr, uint8_t rd, uint8_t reset) 75 | { 76 | prepare(); 77 | return u8g_InitRW8Bit(&u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, cs, a0, wr, rd, reset); 78 | } 79 | 80 | 81 | -------------------------------------------------------------------------------- /Mirf.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2007 Stefan Engelke 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, copy, 8 | modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | 24 | $Id$ 25 | */ 26 | 27 | #ifndef _MIRF_H_ 28 | #define _MIRF_H_ 29 | 30 | #include 31 | 32 | #include "nRF24L01.h" 33 | #include "MirfSpiDriver.h" 34 | 35 | // Nrf24l settings 36 | 37 | #define mirf_ADDR_LEN 5 38 | #define mirf_CONFIG ((1< 42 | 43 | #define lo8(x) ((x)&0xff) 44 | #define hi8(x) ((x)>>8) 45 | 46 | uint16_t crc16_update(uint16_t crc, uint8_t a) 47 | { 48 | int i; 49 | 50 | crc ^= a; 51 | for (i = 0; i < 8; ++i) 52 | { 53 | if (crc & 1) 54 | crc = (crc >> 1) ^ 0xA001; 55 | else 56 | crc = (crc >> 1); 57 | } 58 | 59 | return crc; 60 | } 61 | 62 | uint16_t crc_xmodem_update (uint16_t crc, uint8_t data) 63 | { 64 | int i; 65 | 66 | crc = crc ^ ((uint16_t)data << 8); 67 | for (i=0; i<8; i++) 68 | { 69 | if (crc & 0x8000) 70 | crc = (crc << 1) ^ 0x1021; 71 | else 72 | crc <<= 1; 73 | } 74 | 75 | return crc; 76 | } 77 | uint16_t _crc_ccitt_update (uint16_t crc, uint8_t data) 78 | { 79 | data ^= lo8 (crc); 80 | data ^= data << 4; 81 | 82 | return ((((uint16_t)data << 8) | hi8 (crc)) ^ (uint8_t)(data >> 4) 83 | ^ ((uint16_t)data << 3)); 84 | } 85 | 86 | uint8_t _crc_ibutton_update(uint8_t crc, uint8_t data) 87 | { 88 | uint8_t i; 89 | 90 | crc = crc ^ data; 91 | for (i = 0; i < 8; i++) 92 | { 93 | if (crc & 0x01) 94 | crc = (crc >> 1) ^ 0x8C; 95 | else 96 | crc >>= 1; 97 | } 98 | 99 | return crc; 100 | } 101 | 102 | 103 | #endif /* _UTIL_CRC16_H_ */ 104 | -------------------------------------------------------------------------------- /nRF24L01.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2007 Stefan Engelke 3 | 4 | Permission is hereby granted, free of charge, to any person 5 | obtaining a copy of this software and associated documentation 6 | files (the "Software"), to deal in the Software without 7 | restriction, including without limitation the rights to use, copy, 8 | modify, merge, publish, distribute, sublicense, and/or sell copies 9 | of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be 13 | included in all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 16 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 17 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 18 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 19 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 20 | WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 | DEALINGS IN THE SOFTWARE. 23 | 24 | $Id$ 25 | */ 26 | 27 | /* Memory Map */ 28 | #define CONFIG 0x00 29 | #define EN_AA 0x01 30 | #define EN_RXADDR 0x02 31 | #define SETUP_AW 0x03 32 | #define SETUP_RETR 0x04 33 | #define RF_CH 0x05 34 | #define RF_SETUP 0x06 35 | #define STATUS 0x07 36 | #define OBSERVE_TX 0x08 37 | #define CD 0x09 38 | #define RX_ADDR_P0 0x0A 39 | #define RX_ADDR_P1 0x0B 40 | #define RX_ADDR_P2 0x0C 41 | #define RX_ADDR_P3 0x0D 42 | #define RX_ADDR_P4 0x0E 43 | #define RX_ADDR_P5 0x0F 44 | #define TX_ADDR 0x10 45 | #define RX_PW_P0 0x11 46 | #define RX_PW_P1 0x12 47 | #define RX_PW_P2 0x13 48 | #define RX_PW_P3 0x14 49 | #define RX_PW_P4 0x15 50 | #define RX_PW_P5 0x16 51 | #define FIFO_STATUS 0x17 52 | 53 | /* Bit Mnemonics */ 54 | #define MASK_RX_DR 6 55 | #define MASK_TX_DS 5 56 | #define MASK_MAX_RT 4 57 | #define EN_CRC 3 58 | #define CRCO 2 59 | #define PWR_UP 1 60 | #define PRIM_RX 0 61 | #define ENAA_P5 5 62 | #define ENAA_P4 4 63 | #define ENAA_P3 3 64 | #define ENAA_P2 2 65 | #define ENAA_P1 1 66 | #define ENAA_P0 0 67 | #define ERX_P5 5 68 | #define ERX_P4 4 69 | #define ERX_P3 3 70 | #define ERX_P2 2 71 | #define ERX_P1 1 72 | #define ERX_P0 0 73 | #define AW 0 74 | #define ARD 4 75 | #define ARC 0 76 | #define PLL_LOCK 4 77 | #define RF_DR 3 78 | #define RF_PWR 1 79 | #define LNA_HCURR 0 80 | #define RX_DR 6 81 | #define TX_DS 5 82 | #define MAX_RT 4 83 | #define RX_P_NO 1 84 | #define TX_FULL 0 85 | #define PLOS_CNT 4 86 | #define ARC_CNT 0 87 | #define TX_REUSE 6 88 | #define FIFO_FULL 5 89 | #define TX_EMPTY 4 90 | #define RX_FULL 1 91 | #define RX_EMPTY 0 92 | 93 | /* Instruction Mnemonics */ 94 | #define R_REGISTER 0x00 95 | #define W_REGISTER 0x20 96 | #define REGISTER_MASK 0x1F 97 | #define R_RX_PAYLOAD 0x61 98 | #define W_TX_PAYLOAD 0xA0 99 | #define FLUSH_TX 0xE1 100 | #define FLUSH_RX 0xE2 101 | #define REUSE_TX_PL 0xE3 102 | #define NOP 0xFF 103 | -------------------------------------------------------------------------------- /examples/nRF24Receiver/nRF24Receiver.ino: -------------------------------------------------------------------------------- 1 | /* 2 | nRF24Receiver Demo for RFToy 3 | 4 | This demo shows how to use RFToy to make a 5 | wireless temperature sensor. This is the 6 | receiver module which displays the received 7 | temperature value to OLED. The demo uses 8 | the Mirf library. 9 | 10 | Written by Jonathan Goldin @ Rayshobby LLC 11 | Nov 2014 12 | For details, visit http://rayshobby.net/rftoy 13 | */ 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include "U8glib.h" 20 | 21 | 22 | U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE); // I2C / TWI 23 | 24 | void setup(){ 25 | Serial.begin(9600); 26 | Serial.println("begin."); 27 | 28 | Mirf.cePin = 17; 29 | Mirf.csnPin = 16; 30 | /* 31 | * Set the SPI Driver. 32 | */ 33 | 34 | Mirf.spi = &MirfHardwareSpi; 35 | 36 | /* 37 | * Setup pins / SPI. 38 | */ 39 | 40 | Mirf.init(); 41 | 42 | /* 43 | * Configure reciving address. 44 | */ 45 | 46 | Mirf.setRADDR((byte *)"serv1"); 47 | 48 | /* 49 | * Set the payload length to sizeof(unsigned long) the 50 | * return type of millis(). 51 | * 52 | * NB: payload on client and server must be the same. 53 | */ 54 | 55 | Mirf.payload = sizeof(long); 56 | 57 | /* 58 | * Write channel and payload config then power up reciver. 59 | */ 60 | 61 | Mirf.config(); 62 | 63 | u8g.firstPage(); 64 | do{ 65 | uint8_t h; 66 | u8g.setFont(u8g_font_10x20); 67 | u8g.setFontRefHeightText(); 68 | u8g.setFontPosTop(); 69 | h = u8g.getFontAscent()-u8g.getFontDescent(); 70 | u8g.drawStr(19,(u8g.getHeight()-h)/2,"LISTENING"); 71 | } 72 | while(u8g.nextPage()); 73 | } 74 | String c = "New Signal."; 75 | String f = "Decoding."; 76 | void loop(){ 77 | /* 78 | * A buffer to store the data. 79 | */ 80 | 81 | byte data[Mirf.payload]; 82 | 83 | /* 84 | * If a packet has been recived. 85 | * 86 | * isSending also restores listening mode when it 87 | * transitions from true to false. 88 | */ 89 | 90 | if(!Mirf.isSending() && Mirf.dataReady()){ 91 | Serial.print("Got packet: "); 92 | 93 | /* 94 | * Get load the packet into the buffer. 95 | */ 96 | 97 | Mirf.getData(data); 98 | 99 | long temp = ((int)data[3] << 24) + ((int)data[2] << 16) + ((int)data[1] << 8) + data[0]; 100 | Serial.println(temp); 101 | double tmp = (double)temp/10; 102 | tmp = 10*(tmp*9/5+32); 103 | 104 | c = String(temp/10); 105 | c += "."; 106 | c += String(temp%10); 107 | f = String((long)tmp/10); 108 | f += "."; 109 | f += String((long)tmp%10); 110 | c += (char)(176); 111 | c += "C"; 112 | f += (char)(176); 113 | f += "F"; 114 | 115 | u8g.firstPage(); 116 | do{ 117 | u8g.setFont(u8g_font_10x20); 118 | u8g.setFontRefHeightText(); 119 | u8g.setFontPosTop(); 120 | u8g.drawStr(0,0,c.c_str()); 121 | u8g.drawStr(0,25,f.c_str()); 122 | } while(u8g.nextPage()); 123 | /* 124 | * Set the send address. 125 | */ 126 | 127 | 128 | Mirf.setTADDR((byte *)"clie1"); 129 | 130 | /* 131 | * Send the data back to the client. 132 | */ 133 | 134 | Mirf.send(data); 135 | 136 | /* 137 | * Wait untill sending has finished 138 | * 139 | * NB: isSending returns the chip to receving after returning true. 140 | */ 141 | 142 | Serial.println("Reply sent."); 143 | } 144 | } 145 | 146 | -------------------------------------------------------------------------------- /utility/u8g_cursor.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_cursor.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | */ 36 | 37 | #include "u8g.h" 38 | 39 | void u8g_SetCursorFont(u8g_t *u8g, const u8g_pgm_uint8_t *cursor_font) 40 | { 41 | u8g->cursor_font = cursor_font; 42 | } 43 | 44 | void u8g_SetCursorStyle(u8g_t *u8g, uint8_t encoding) 45 | { 46 | u8g->cursor_encoding = encoding; 47 | } 48 | 49 | void u8g_SetCursorColor(u8g_t *u8g, uint8_t fg, uint8_t bg) 50 | { 51 | u8g->cursor_bg_color = bg; 52 | u8g->cursor_fg_color = fg; 53 | } 54 | 55 | void u8g_SetCursorPos(u8g_t *u8g, u8g_uint_t cursor_x, u8g_uint_t cursor_y) 56 | { 57 | u8g->cursor_x = cursor_x; 58 | u8g->cursor_y = cursor_y; 59 | } 60 | 61 | void u8g_EnableCursor(u8g_t *u8g) 62 | { 63 | u8g->cursor_fn = u8g_DrawCursor; 64 | } 65 | 66 | void u8g_DisableCursor(u8g_t *u8g) 67 | { 68 | u8g->cursor_fn = (u8g_draw_cursor_fn)0; 69 | } 70 | 71 | void u8g_DrawCursor(u8g_t *u8g) 72 | { 73 | const u8g_pgm_uint8_t *font; 74 | uint8_t color; 75 | uint8_t encoding = u8g->cursor_encoding; 76 | 77 | /* get current values */ 78 | color = u8g_GetColorIndex(u8g); 79 | font = u8g->font; 80 | 81 | /* draw cursor */ 82 | u8g->font = u8g->cursor_font; 83 | encoding++; 84 | u8g_SetColorIndex(u8g, u8g->cursor_bg_color); 85 | /* 27. Jan 2013: replaced call to u8g_DrawGlyph with call to u8g_draw_glyph */ 86 | /* required, because y adjustment should not happen to the cursor fonts */ 87 | u8g_draw_glyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding); 88 | encoding--; 89 | u8g_SetColorIndex(u8g, u8g->cursor_fg_color); 90 | /* 27. Jan 2013: replaced call to u8g_DrawGlyph with call to u8g_draw_glyph */ 91 | /* required, because y adjustment should not happen to the cursor fonts */ 92 | /* u8g_DrawGlyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding); */ 93 | u8g_draw_glyph(u8g, u8g->cursor_x, u8g->cursor_y, encoding); 94 | 95 | /* restore previous values */ 96 | u8g->font = font; 97 | u8g_SetColorIndex(u8g, color); 98 | } 99 | 100 | -------------------------------------------------------------------------------- /utility/u8g_dev_flipdisc_2x7.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_flipdisc.c 4 | 5 | 1-Bit (BW) Driver for flip disc matrix 6 | 2x 7 pixel height 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2011, olikraus@gmail.com 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright notice, this list 17 | of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this 20 | list of conditions and the following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | */ 38 | 39 | #include "u8g.h" 40 | 41 | #define WIDTH 28 42 | #define HEIGHT 14 43 | #define PAGE_HEIGHT 14 44 | 45 | /* 46 | Write data to the flip disc matrix. 47 | This procedure must be implemented by the user. 48 | Arguments: 49 | id: Id for the matrix. Currently always 0. 50 | page: A page has a height of 14 pixel. For a matrix with HEIGHT == 14 this will be always 0 51 | width: The width of the flip disc matrix. Always equal to WIDTH 52 | row1: first data line (7 pixel per byte) 53 | row2: first data line (7 pixel per byte) 54 | */ 55 | void writeFlipDiscMatrix(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2); 56 | 57 | 58 | 59 | void (*u8g_write_flip_disc_matrix)(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2); 60 | 61 | void u8g_SetFlipDiscCallback(u8g_t *u8g, void (*cb)(uint8_t id, uint8_t page, uint8_t width, uint8_t *row1, uint8_t *row2)) 62 | { 63 | u8g_write_flip_disc_matrix = cb; 64 | } 65 | 66 | uint8_t u8g_dev_flipdisc_2x7_bw_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 67 | { 68 | switch(msg) 69 | { 70 | case U8G_DEV_MSG_INIT: 71 | break; 72 | case U8G_DEV_MSG_STOP: 73 | break; 74 | case U8G_DEV_MSG_PAGE_NEXT: 75 | { 76 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 77 | 78 | /* current page: pb->p.page */ 79 | /* ptr to the buffer: pb->buf */ 80 | 81 | (*u8g_write_flip_disc_matrix)(0, pb->p.page, WIDTH, pb->buf, (uint8_t *)(pb->buf)+WIDTH); 82 | } 83 | break; 84 | case U8G_DEV_MSG_CONTRAST: 85 | return 1; 86 | } 87 | return u8g_dev_pb14v1_base_fn(u8g, dev, msg, arg); 88 | } 89 | 90 | uint8_t u8g_dev_flipdisc_2x7_bw_buf[WIDTH*2] U8G_NOCOMMON ; 91 | u8g_pb_t u8g_dev_flipdisc_2x7_bw_pb = { {16, HEIGHT, 0, 0, 0}, WIDTH, u8g_dev_flipdisc_2x7_bw_buf}; 92 | u8g_dev_t u8g_dev_flipdisc_2x7 = { u8g_dev_flipdisc_2x7_bw_fn, &u8g_dev_flipdisc_2x7_bw_pb, u8g_com_null_fn }; 93 | -------------------------------------------------------------------------------- /utility/u8g_com_api_16gr.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_api_16gr.c 4 | 5 | Extension of the com api for devices with 16 graylevels (4 bit per pixel). 6 | This should fit to the 8h and 16h architectures (pb8v1, pb8v2, pb16v1, pb16v2), 7 | mainly intended for SSD OLEDs 8 | 9 | Universal 8bit Graphics Library 10 | 11 | Copyright (c) 2011, olikraus@gmail.com 12 | All rights reserved. 13 | 14 | Redistribution and use in source and binary forms, with or without modification, 15 | are permitted provided that the following conditions are met: 16 | 17 | * Redistributions of source code must retain the above copyright notice, this list 18 | of conditions and the following disclaimer. 19 | 20 | * Redistributions in binary form must reproduce the above copyright notice, this 21 | list of conditions and the following disclaimer in the documentation and/or other 22 | materials provided with the distribution. 23 | 24 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 25 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 26 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 27 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 28 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 29 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 31 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 32 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 33 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 34 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 36 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 37 | 38 | 39 | */ 40 | 41 | #include "u8g.h" 42 | 43 | /* interpret b as a monochrome bit pattern, write value 15 for high bit and value 0 for a low bit */ 44 | /* topbit (msb) is sent last */ 45 | /* example: b = 0x083 will send 0xff, 0x00, 0x00, 0xf0 */ 46 | uint8_t u8g_WriteByteBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b) 47 | { 48 | static uint8_t buf[4]; 49 | static uint8_t map[4] = { 0, 0x00f, 0x0f0, 0x0ff }; 50 | buf [3] = map[b & 3]; 51 | b>>=2; 52 | buf [2] = map[b & 3]; 53 | b>>=2; 54 | buf [1] = map[b & 3]; 55 | b>>=2; 56 | buf [0] = map[b & 3]; 57 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ, 4, buf); 58 | } 59 | 60 | uint8_t u8g_WriteSequenceBWTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr) 61 | { 62 | do 63 | { 64 | if ( u8g_WriteByteBWTo16GrDevice(u8g, dev, *ptr++) == 0 ) 65 | return 0; 66 | cnt--; 67 | } while( cnt != 0 ); 68 | return 1; 69 | } 70 | 71 | /* interpret b as a 4L bit pattern, write values 0x000, 0x004, 0x008, 0x00c */ 72 | uint8_t u8g_WriteByte4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t b) 73 | { 74 | //static uint8_t map[16] = { 0x000, 0x004, 0x008, 0x00c, 0x040, 0x044, 0x048, 0x04c, 0x080, 0x084, 0x088, 0x08c, 0x0c0, 0x0c4, 0x0c8, 0x0cc}; 75 | //static uint8_t map[16] = { 0x000, 0x004, 0x00a, 0x00f, 0x040, 0x044, 0x04a, 0x04f, 0x0a0, 0x0a4, 0x0aa, 0x0af, 0x0f0, 0x0f4, 0x0fa, 0x0ff}; 76 | static uint8_t map[16] = { 0x000, 0x040, 0x0a0, 0x0f0, 0x004, 0x044, 0x0a4, 0x0f4, 0x00a, 0x04a, 0x0aa, 0x0fa, 0x00f, 0x04f, 0x0af, 0x0ff}; 77 | uint8_t bb; 78 | bb = b; 79 | bb &= 15; 80 | b>>=4; 81 | dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, map[bb], NULL); 82 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, map[b], NULL); 83 | } 84 | 85 | uint8_t u8g_WriteSequence4LTo16GrDevice(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *ptr) 86 | { 87 | do 88 | { 89 | if ( u8g_WriteByte4LTo16GrDevice(u8g, dev, *ptr++) == 0 ) 90 | return 0; 91 | cnt--; 92 | } while( cnt != 0 ); 93 | return 1; 94 | } 95 | -------------------------------------------------------------------------------- /u8g.license.txt: -------------------------------------------------------------------------------- 1 | 2 | The U8glib code (http://code.google.com/p/u8glib/) is licensed under the terms of 3 | the new-bsd license (two-clause bsd license). 4 | See also: http://www.opensource.org/licenses/bsd-license.php 5 | 6 | The repository and optionally the releases contain icons, which are 7 | derived from the WPZOOM Developer Icon Set: 8 | http://www.wpzoom.com/wpzoom/new-freebie-wpzoom-developer-icon-set-154-free-icons/ 9 | WPZOOM Developer Icon Set by WPZOOM is licensed under a Creative Commons 10 | Attribution-ShareAlike 3.0 Unported License. 11 | 12 | Fonts are licensed under different conditions. 13 | See http://code.google.com/p/u8glib/wiki/fontgroup for 14 | detailed information on the licensing conditions for each font. 15 | 16 | ============ X11 Fonts COUR, HELV, NCEN, TIM, SYMB ============ 17 | 18 | For fonts derived from the following files, the license below applies. 19 | COURB08.BDF COURB10.BDF COURB12.BDF COURB14.BDF COURB18.BDF 20 | COURB24.BDF COURR08.BDF COURR10.BDF COURR12.BDF COURR14.BDF 21 | COURR18.BDF COURR24.BDF HELVB08.BDF HELVB10.BDF HELVB12.BDF HELVB14.BDF 22 | HELVB18.BDF HELVB24.BDF HELVR08.BDF HELVR10.BDF HELVR12.BDF HELVR14.BDF 23 | HELVR18.BDF HELVR24.BDF NCENB08.BDF NCENB10.BDF NCENB12.BDF 24 | NCENB14.BDF NCENB18.BDF NCENB24.BDF NCENR08.BDF NCENR10.BDF 25 | NCENR12.BDF NCENR14.BDF NCENR18.BDF NCENR24.BDF SYMB08.BDF SYMB10.BDF 26 | SYMB12.BDF SYMB14.BDF SYMB18.BDF SYMB24.BDF TIMB08.BDF TIMB10.BDF 27 | TIMB12.BDF TIMB14.BDF TIMB18.BDF TIMB24.BDF TIMR08.BDF TIMR10.BDF 28 | TIMR12.BDF TIMR14.BDF TIMR18.BDF TIMR24.BDF 29 | 30 | Copyright 1984-1989, 1994 Adobe Systems Incorporated. 31 | Copyright 1988, 1994 Digital Equipment Corporation. 32 | 33 | Adobe is a trademark of Adobe Systems Incorporated which may be 34 | registered in certain jurisdictions. 35 | Permission to use these trademarks is hereby granted only in 36 | association with the images described in this file. 37 | 38 | Permission to use, copy, modify, distribute and sell this software 39 | and its documentation for any purpose and without fee is hereby 40 | granted, provided that the above copyright notices appear in all 41 | copies and that both those copyright notices and this permission 42 | notice appear in supporting documentation, and that the names of 43 | Adobe Systems and Digital Equipment Corporation not be used in 44 | advertising or publicity pertaining to distribution of the software 45 | without specific, written prior permission. Adobe Systems and 46 | Digital Equipment Corporation make no representations about the 47 | suitability of this software for any purpose. It is provided "as 48 | is" without express or implied warranty. 49 | 50 | 51 | ============ BSD License for U8glib Code ============ 52 | 53 | Universal 8bit Graphics Library (http://code.google.com/p/u8glib/) 54 | 55 | Copyright (c) 2011, olikraus@gmail.com 56 | All rights reserved. 57 | 58 | Redistribution and use in source and binary forms, with or without modification, 59 | are permitted provided that the following conditions are met: 60 | 61 | * Redistributions of source code must retain the above copyright notice, this list 62 | of conditions and the following disclaimer. 63 | 64 | * Redistributions in binary form must reproduce the above copyright notice, this 65 | list of conditions and the following disclaimer in the documentation and/or other 66 | materials provided with the distribution. 67 | 68 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 69 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 70 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 71 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 72 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 73 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 74 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 75 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 76 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 77 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 78 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 79 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 80 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 81 | -------------------------------------------------------------------------------- /utility/u8g_dev_gprof.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_gprof.c 4 | 5 | Device for performance measurement with gprof. 6 | Does not write any data, but uses a buffer. 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2011, olikraus@gmail.com 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright notice, this list 17 | of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this 20 | list of conditions and the following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | 38 | 39 | */ 40 | 41 | #include "u8g.h" 42 | 43 | 44 | #define WIDTH 128 45 | #define HEIGHT 64 46 | #define PAGE_HEIGHT 8 47 | 48 | uint8_t u8g_dev_gprof_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg); 49 | 50 | uint8_t u8g_pb_dev_gprof_buf[WIDTH]; 51 | u8g_pb_t u8g_pb_dev_gprof = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_pb_dev_gprof_buf }; 52 | 53 | u8g_dev_t u8g_dev_gprof = { u8g_dev_gprof_fn, &u8g_pb_dev_gprof, NULL }; 54 | 55 | uint8_t u8g_dev_gprof_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 56 | { 57 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 58 | 59 | switch(msg) 60 | { 61 | case U8G_DEV_MSG_INIT: 62 | break; 63 | case U8G_DEV_MSG_STOP: 64 | break; 65 | case U8G_DEV_MSG_PAGE_FIRST: 66 | u8g_pb_Clear(pb); 67 | u8g_page_First(&(pb->p)); 68 | break; 69 | case U8G_DEV_MSG_PAGE_NEXT: 70 | /* 71 | { 72 | uint8_t i, j; 73 | uint8_t page_height; 74 | page_height = pb->p.page_y1; 75 | page_height -= pb->p.page_y0; 76 | page_height++; 77 | for( j = 0; j < page_height; j++ ) 78 | { 79 | printf("%02d ", j); 80 | for( i = 0; i < WIDTH; i++ ) 81 | { 82 | if ( (u8g_pb_dev_stdout_buf[i] & (1<p)) == 0 ) 92 | { 93 | //printf("\n"); 94 | return 0; 95 | } 96 | u8g_pb_Clear(pb); 97 | break; 98 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 99 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 100 | { 101 | u8g_dev_arg_bbx_t *bbx = (u8g_dev_arg_bbx_t *)arg; 102 | u8g_uint_t x2, y2; 103 | 104 | y2 = bbx->y; 105 | y2 += bbx->h; 106 | y2--; 107 | 108 | if ( u8g_pb_IsYIntersection(pb, bbx->y, y2) == 0 ) 109 | return 0; 110 | 111 | /* maybe this one can be skiped... probability is very high to have an intersection, so it would be ok to always return 1 */ 112 | x2 = bbx->x; 113 | x2 += bbx->w; 114 | x2--; 115 | 116 | if ( u8g_pb_IsXIntersection(pb, bbx->x, x2) == 0 ) 117 | return 0; 118 | } 119 | return 1; 120 | #endif 121 | case U8G_DEV_MSG_GET_PAGE_BOX: 122 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 123 | break; 124 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 125 | break; 126 | case U8G_DEV_MSG_SET_XY_CB: 127 | break; 128 | } 129 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 130 | } 131 | -------------------------------------------------------------------------------- /utility/u8g_dev_sbn1661_122x32.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_sbn1661_122x32.c 4 | 5 | WG12232 display with 2xSBN1661 / SED1520 controller (122x32 display) 6 | At the moment only available in the Arduino Environment 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2011, olikraus@gmail.com 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright notice, this list 17 | of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this 20 | list of conditions and the following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | 38 | */ 39 | 40 | #include "u8g.h" 41 | 42 | #define WIDTH 122 43 | #define HEIGHT 32 44 | #define PAGE_HEIGHT 8 45 | 46 | 47 | static const uint8_t u8g_dev_sbn1661_122x32_init_seq[] PROGMEM = { 48 | U8G_ESC_CS(0), /* disable chip */ 49 | U8G_ESC_ADR(0), /* instruction mode */ 50 | U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds */ 51 | U8G_ESC_CS(1), /* enable chip 1 */ 52 | 0x0af, /* display on */ 53 | 0x0c0, /* display start at line 0 */ 54 | 0x0a0, /* a0: ADC forward, a1: ADC reverse */ 55 | 0x0a9, /* a8: 1/16, a9: 1/32 duty */ 56 | U8G_ESC_CS(2), /* enable chip 2 */ 57 | 0x0af, /* display on */ 58 | 0x0c0, /* display start at line 0 */ 59 | 0x0a0, /* a0: ADC forward, a1: ADC reverse */ 60 | 0x0a9, /* a8: 1/16, a9: 1/32 duty */ 61 | 62 | U8G_ESC_CS(0), /* disable chip */ 63 | 64 | 65 | U8G_ESC_END /* end of sequence */ 66 | }; 67 | 68 | uint8_t u8g_dev_sbn1661_122x32_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 69 | { 70 | switch(msg) 71 | { 72 | case U8G_DEV_MSG_INIT: 73 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE); 74 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_sbn1661_122x32_init_seq); 75 | break; 76 | case U8G_DEV_MSG_STOP: 77 | break; 78 | case U8G_DEV_MSG_PAGE_NEXT: 79 | { 80 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 81 | 82 | u8g_SetAddress(u8g, dev, 0); /* command mode */ 83 | u8g_SetChipSelect(u8g, dev, 1); 84 | u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (SBN1661/SED1520) */ 85 | u8g_WriteByte(u8g, dev, 0x000 ); /* set X address */ 86 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 87 | u8g_WriteSequence(u8g, dev, WIDTH/2, pb->buf); 88 | 89 | u8g_SetAddress(u8g, dev, 0); /* command mode */ 90 | u8g_SetChipSelect(u8g, dev, 2); 91 | u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (SBN1661/SED1520) */ 92 | u8g_WriteByte(u8g, dev, 0x000 ); /* set X address */ 93 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 94 | u8g_WriteSequence(u8g, dev, WIDTH/2, WIDTH/2+(uint8_t *)pb->buf); 95 | 96 | u8g_SetChipSelect(u8g, dev, 0); 97 | 98 | } 99 | break; 100 | case U8G_DEV_MSG_CONTRAST: 101 | break; 102 | } 103 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 104 | } 105 | 106 | /* u8g_com_arduino_sw_spi_fn does not work, too fast??? */ 107 | U8G_PB_DEV(u8g_dev_sbn1661_122x32 , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_sbn1661_122x32_fn, u8g_com_arduino_no_en_parallel_fn); 108 | -------------------------------------------------------------------------------- /utility/u8g_com_atmega_sw_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_atmega_sw_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2012, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | */ 36 | 37 | #include "u8g.h" 38 | 39 | #if defined(__AVR__) 40 | 41 | static void u8g_atmega_sw_spi_shift_out(u8g_t *u8g, uint8_t val) U8G_NOINLINE; 42 | static void u8g_atmega_sw_spi_shift_out(u8g_t *u8g, uint8_t val) 43 | { 44 | uint8_t i = 8; 45 | do 46 | { 47 | u8g_SetPILevel(u8g, U8G_PI_MOSI, val & 128 ); 48 | val <<= 1; 49 | u8g_SetPILevel(u8g, U8G_PI_SCK, 1 ); 50 | u8g_MicroDelay(); /* 15 Aug 2012: added for high speed uC */ 51 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 52 | u8g_MicroDelay(); /* 15 Aug 2012: added for high speed uC */ 53 | i--; 54 | } while( i != 0 ); 55 | } 56 | 57 | uint8_t u8g_com_atmega_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 58 | { 59 | switch(msg) 60 | { 61 | case U8G_COM_MSG_INIT: 62 | u8g_SetPIOutput(u8g, U8G_PI_SCK); 63 | u8g_SetPIOutput(u8g, U8G_PI_MOSI); 64 | u8g_SetPIOutput(u8g, U8G_PI_A0); 65 | u8g_SetPIOutput(u8g, U8G_PI_CS); 66 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 67 | 68 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 69 | u8g_SetPILevel(u8g, U8G_PI_MOSI, 0 ); 70 | u8g_SetPILevel(u8g, U8G_PI_CS, 1 ); 71 | u8g_SetPILevel(u8g, U8G_PI_A0, 0); 72 | break; 73 | 74 | case U8G_COM_MSG_STOP: 75 | break; 76 | 77 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 78 | u8g_SetPILevel(u8g, U8G_PI_A0, arg_val); 79 | break; 80 | 81 | case U8G_COM_MSG_CHIP_SELECT: 82 | 83 | if ( arg_val == 0 ) 84 | { 85 | /* disable */ 86 | u8g_SetPILevel(u8g, U8G_PI_CS, 1); 87 | } 88 | else 89 | { 90 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 91 | /* enable */ 92 | u8g_SetPILevel(u8g, U8G_PI_CS, 0); /* CS = 0 (low active) */ 93 | } 94 | break; 95 | 96 | case U8G_COM_MSG_RESET: 97 | u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 98 | break; 99 | 100 | 101 | case U8G_COM_MSG_WRITE_BYTE: 102 | u8g_atmega_sw_spi_shift_out(u8g, arg_val); 103 | break; 104 | 105 | case U8G_COM_MSG_WRITE_SEQ: 106 | { 107 | register uint8_t *ptr = arg_ptr; 108 | while( arg_val > 0 ) 109 | { 110 | u8g_atmega_sw_spi_shift_out(u8g, *ptr++); 111 | arg_val--; 112 | } 113 | } 114 | break; 115 | 116 | case U8G_COM_MSG_WRITE_SEQ_P: 117 | { 118 | register uint8_t *ptr = arg_ptr; 119 | while( arg_val > 0 ) 120 | { 121 | u8g_atmega_sw_spi_shift_out(u8g, u8g_pgm_read(ptr)); 122 | ptr++; 123 | arg_val--; 124 | } 125 | } 126 | break; 127 | } 128 | return 1; 129 | } 130 | 131 | #else 132 | 133 | 134 | uint8_t u8g_com_atmega_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 135 | { 136 | return 1; 137 | } 138 | 139 | 140 | #endif 141 | 142 | -------------------------------------------------------------------------------- /utility/u8g_dev_ks0108_128x64.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_ks0108_128x64.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | ADDRESS = 0 (Command Mode) 36 | 0x03f Display On 37 | 0x0c0 Start Display at line 0 38 | 0x040 | y write to y address (y:0..63) 39 | 0x0b8 | x write to page [0..7] 40 | 41 | 42 | u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset) 43 | u8g_Init8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16, U8G_PIN_NONE) 44 | 45 | */ 46 | 47 | #include "u8g.h" 48 | 49 | #define WIDTH 128 50 | #define HEIGHT 64 51 | #define PAGE_HEIGHT 8 52 | 53 | static const uint8_t u8g_dev_ks0108_128x64_init_seq[] PROGMEM = { 54 | U8G_ESC_CS(0), /* disable chip */ 55 | U8G_ESC_ADR(0), /* instruction mode */ 56 | U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */ 57 | U8G_ESC_CS(1), /* enable chip 1 */ 58 | 0x03f, /* display on */ 59 | 0x0c0, /* start at line 0 */ 60 | U8G_ESC_DLY(20), /* delay 20 ms */ 61 | U8G_ESC_CS(2), /* enable chip 2 */ 62 | 0x03f, /* display on */ 63 | 0x0c0, /* start at line 0 */ 64 | U8G_ESC_DLY(20), /* delay 20 ms */ 65 | U8G_ESC_CS(0), /* disable all chips */ 66 | U8G_ESC_END /* end of sequence */ 67 | }; 68 | 69 | 70 | uint8_t u8g_dev_ks0108_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 71 | { 72 | 73 | switch(msg) 74 | { 75 | case U8G_DEV_MSG_INIT: 76 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE); 77 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_ks0108_128x64_init_seq); 78 | break; 79 | case U8G_DEV_MSG_STOP: 80 | break; 81 | case U8G_DEV_MSG_PAGE_NEXT: 82 | { 83 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 84 | 85 | u8g_SetAddress(u8g, dev, 0); /* command mode */ 86 | u8g_SetChipSelect(u8g, dev, 2); 87 | u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (KS0108b) */ 88 | u8g_WriteByte(u8g, dev, 0x040 ); /* set address 0 */ 89 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 90 | u8g_WriteSequence(u8g, dev, 64, pb->buf); 91 | u8g_SetChipSelect(u8g, dev, 0); 92 | 93 | u8g_SetAddress(u8g, dev, 0); /* command mode */ 94 | u8g_SetChipSelect(u8g, dev, 1); 95 | u8g_WriteByte(u8g, dev, 0x0b8 | pb->p.page); /* select current page (KS0108b) */ 96 | u8g_WriteByte(u8g, dev, 0x040 ); /* set address 0 */ 97 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 98 | u8g_WriteSequence(u8g, dev, 64, 64+(uint8_t *)pb->buf); 99 | u8g_SetChipSelect(u8g, dev, 0); 100 | 101 | } 102 | break; 103 | } 104 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 105 | } 106 | 107 | U8G_PB_DEV(u8g_dev_ks0108_128x64, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ks0108_128x64_fn, U8G_COM_PARALLEL); 108 | U8G_PB_DEV(u8g_dev_ks0108_128x64_fast, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ks0108_128x64_fn, U8G_COM_FAST_PARALLEL); 109 | 110 | 111 | -------------------------------------------------------------------------------- /utility/u8g_state.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_state.c 4 | 5 | backup and restore hardware state 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, olikraus@gmail.com 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this list 16 | of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, this 19 | list of conditions and the following disclaimer in the documentation and/or other 20 | materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | state callback: backup env U8G_STATE_MSG_BACKUP_ENV 38 | device callback: DEV_MSG_INIT 39 | state callback: backup u8g U8G_STATE_MSG_BACKUP_U8G 40 | state callback: restore env U8G_STATE_MSG_RESTORE_ENV 41 | 42 | state callback: backup env U8G_STATE_MSG_BACKUP_ENV 43 | state callback: retore u8g U8G_STATE_MSG_RESTORE_U8G 44 | DEV_MSG_PAGE_FIRST or DEV_MSG_PAGE_NEXT 45 | state callback: restore env U8G_STATE_MSG_RESTORE_ENV 46 | 47 | */ 48 | 49 | #include 50 | #include "u8g.h" 51 | 52 | void u8g_state_dummy_cb(uint8_t msg) 53 | { 54 | /* the dummy procedure does nothing */ 55 | } 56 | 57 | void u8g_SetHardwareBackup(u8g_t *u8g, u8g_state_cb backup_cb) 58 | { 59 | u8g->state_cb = backup_cb; 60 | /* in most cases the init message was already sent, so this will backup the */ 61 | /* current u8g state */ 62 | backup_cb(U8G_STATE_MSG_BACKUP_U8G); 63 | } 64 | 65 | 66 | /*===============================================================*/ 67 | /* register variable for restoring interrupt state */ 68 | 69 | #if defined(__AVR__) 70 | uint8_t global_SREG_backup; 71 | #endif 72 | 73 | 74 | 75 | /*===============================================================*/ 76 | /* AVR */ 77 | 78 | #if defined(__AVR__) 79 | #define U8G_ATMEGA_HW_SPI 80 | 81 | /* remove the definition for attiny */ 82 | #if __AVR_ARCH__ == 2 83 | #undef U8G_ATMEGA_HW_SPI 84 | #endif 85 | #if __AVR_ARCH__ == 25 86 | #undef U8G_ATMEGA_HW_SPI 87 | #endif 88 | #endif 89 | 90 | #if defined(U8G_ATMEGA_HW_SPI) 91 | #include 92 | static uint8_t u8g_state_avr_spi_memory[2]; 93 | 94 | void u8g_backup_spi(uint8_t msg) 95 | { 96 | if ( U8G_STATE_MSG_IS_BACKUP(msg) ) 97 | { 98 | u8g_state_avr_spi_memory[U8G_STATE_MSG_GET_IDX(msg)] = SPCR; 99 | } 100 | else 101 | { 102 | uint8_t tmp = SREG; 103 | cli(); 104 | SPCR = 0; 105 | SPCR = u8g_state_avr_spi_memory[U8G_STATE_MSG_GET_IDX(msg)]; 106 | SREG = tmp; 107 | } 108 | } 109 | 110 | #elif defined(ARDUINO) && defined(__arm__) // Arduino Due, maybe we should better check for __SAM3X8E__ 111 | 112 | #include "sam.h" 113 | 114 | struct sam_backup_struct 115 | { 116 | uint32_t mr; 117 | uint32_t sr; 118 | uint32_t csr[4]; 119 | } sam_backup[2]; 120 | 121 | void u8g_backup_spi(uint8_t msg) 122 | { 123 | uint8_t idx = U8G_STATE_MSG_GET_IDX(msg); 124 | if ( U8G_STATE_MSG_IS_BACKUP(msg) ) 125 | { 126 | sam_backup[idx].mr = SPI0->SPI_MR; 127 | sam_backup[idx].sr = SPI0->SPI_SR; 128 | sam_backup[idx].csr[0] = SPI0->SPI_CSR[0]; 129 | sam_backup[idx].csr[1] = SPI0->SPI_CSR[1]; 130 | sam_backup[idx].csr[2] = SPI0->SPI_CSR[2]; 131 | sam_backup[idx].csr[3] = SPI0->SPI_CSR[3]; 132 | } 133 | else 134 | { 135 | SPI0->SPI_MR = sam_backup[idx].mr; 136 | SPI0->SPI_CSR[0] = sam_backup[idx].csr[0]; 137 | SPI0->SPI_CSR[1] = sam_backup[idx].csr[1]; 138 | SPI0->SPI_CSR[2] = sam_backup[idx].csr[2]; 139 | SPI0->SPI_CSR[3] = sam_backup[idx].csr[3]; 140 | } 141 | } 142 | 143 | #else 144 | 145 | void u8g_backup_spi(uint8_t msg) 146 | { 147 | } 148 | 149 | #endif 150 | 151 | -------------------------------------------------------------------------------- /utility/u8g_com_arduino_std_sw_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_arduino_std_sw_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | */ 35 | 36 | #include "u8g.h" 37 | 38 | 39 | #if defined(ARDUINO) 40 | 41 | #if ARDUINO < 100 42 | #include 43 | #else 44 | #include 45 | #endif 46 | 47 | void u8g_arduino_sw_spi_shift_out(uint8_t dataPin, uint8_t clockPin, uint8_t val) 48 | { 49 | uint8_t i = 8; 50 | do 51 | { 52 | if ( val & 128 ) 53 | digitalWrite(dataPin, HIGH); 54 | else 55 | digitalWrite(dataPin, LOW); 56 | val <<= 1; 57 | u8g_MicroDelay(); /* 23 Sep 2012 */ 58 | //delay(1); 59 | digitalWrite(clockPin, HIGH); 60 | u8g_MicroDelay(); /* 23 Sep 2012 */ 61 | //delay(1); 62 | digitalWrite(clockPin, LOW); 63 | u8g_MicroDelay(); /* 23 Sep 2012 */ 64 | //delay(1); 65 | i--; 66 | } while( i != 0 ); 67 | } 68 | 69 | uint8_t u8g_com_arduino_std_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 70 | { 71 | switch(msg) 72 | { 73 | case U8G_COM_MSG_INIT: 74 | u8g_com_arduino_assign_pin_output_high(u8g); 75 | u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW); 76 | u8g_com_arduino_digital_write(u8g, U8G_PI_MOSI, LOW); 77 | break; 78 | 79 | case U8G_COM_MSG_STOP: 80 | break; 81 | 82 | case U8G_COM_MSG_RESET: 83 | if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE ) 84 | u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); 85 | break; 86 | 87 | case U8G_COM_MSG_CHIP_SELECT: 88 | if ( arg_val == 0 ) 89 | { 90 | /* disable */ 91 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); 92 | } 93 | else 94 | { 95 | /* enable */ 96 | u8g_com_arduino_digital_write(u8g, U8G_PI_SCK, LOW); 97 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW); 98 | } 99 | break; 100 | 101 | case U8G_COM_MSG_WRITE_BYTE: 102 | u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], arg_val); 103 | break; 104 | 105 | case U8G_COM_MSG_WRITE_SEQ: 106 | { 107 | register uint8_t *ptr = arg_ptr; 108 | while( arg_val > 0 ) 109 | { 110 | u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], *ptr++); 111 | arg_val--; 112 | } 113 | } 114 | break; 115 | 116 | case U8G_COM_MSG_WRITE_SEQ_P: 117 | { 118 | register uint8_t *ptr = arg_ptr; 119 | while( arg_val > 0 ) 120 | { 121 | u8g_arduino_sw_spi_shift_out(u8g->pin_list[U8G_PI_MOSI], u8g->pin_list[U8G_PI_SCK], u8g_pgm_read(ptr)); 122 | ptr++; 123 | arg_val--; 124 | } 125 | } 126 | break; 127 | 128 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 129 | u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val); 130 | break; 131 | } 132 | return 1; 133 | } 134 | 135 | #else /* ARDUINO */ 136 | 137 | uint8_t u8g_com_arduino_std_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 138 | { 139 | return 1; 140 | } 141 | 142 | #endif /* ARDUINO */ 143 | 144 | -------------------------------------------------------------------------------- /utility/u8g_pb8v2.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_pb8v2.c 4 | 5 | 8bit height 2 bit per pixel page buffer 6 | byte has vertical orientation 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2011, olikraus@gmail.com 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright notice, this list 17 | of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this 20 | list of conditions and the following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | 38 | */ 39 | 40 | #include "u8g.h" 41 | #include 42 | 43 | void u8g_pb8v2_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) 44 | { 45 | b->buf = buf; 46 | b->width = width; 47 | u8g_pb_Clear(b); 48 | } 49 | 50 | void u8g_pb8v2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) 51 | { 52 | register uint8_t mask; 53 | uint8_t *ptr = b->buf; 54 | y -= b->p.page_y0; 55 | mask = 0x03; 56 | y &= 0x03; 57 | y <<= 1; 58 | mask <<= y; 59 | mask ^=0xff; 60 | color_index &= 3; 61 | color_index <<= y; 62 | ptr += x; 63 | *ptr &= mask; 64 | *ptr |= color_index; 65 | } 66 | 67 | 68 | void u8g_pb8v2_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) 69 | { 70 | if ( arg_pixel->y < b->p.page_y0 ) 71 | return; 72 | if ( arg_pixel->y > b->p.page_y1 ) 73 | return; 74 | if ( arg_pixel->x >= b->width ) 75 | return; 76 | u8g_pb8v2_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 77 | } 78 | 79 | 80 | void u8g_pb8v2_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 81 | { 82 | register uint8_t pixel = arg_pixel->pixel; 83 | do 84 | { 85 | if ( pixel & 128 ) 86 | { 87 | u8g_pb8v2_SetPixel(b, arg_pixel); 88 | } 89 | switch( arg_pixel->dir ) 90 | { 91 | case 0: arg_pixel->x++; break; 92 | case 1: arg_pixel->y++; break; 93 | case 2: arg_pixel->x--; break; 94 | case 3: arg_pixel->y--; break; 95 | } 96 | pixel <<= 1; 97 | } while( pixel != 0 ); 98 | 99 | } 100 | 101 | 102 | 103 | uint8_t u8g_dev_pb8v2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 104 | { 105 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 106 | switch(msg) 107 | { 108 | case U8G_DEV_MSG_SET_8PIXEL: 109 | if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) 110 | { 111 | u8g_pb8v2_Set8PixelStd(pb, (u8g_dev_arg_pixel_t *)arg); 112 | } 113 | break; 114 | case U8G_DEV_MSG_SET_PIXEL: 115 | u8g_pb8v2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 116 | break; 117 | case U8G_DEV_MSG_INIT: 118 | break; 119 | case U8G_DEV_MSG_STOP: 120 | break; 121 | case U8G_DEV_MSG_PAGE_FIRST: 122 | u8g_pb_Clear(pb); 123 | u8g_page_First(&(pb->p)); 124 | break; 125 | case U8G_DEV_MSG_PAGE_NEXT: 126 | if ( u8g_page_Next(&(pb->p)) == 0 ) 127 | return 0; 128 | u8g_pb_Clear(pb); 129 | break; 130 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 131 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 132 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 133 | #endif 134 | case U8G_DEV_MSG_GET_PAGE_BOX: 135 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 136 | break; 137 | case U8G_DEV_MSG_GET_WIDTH: 138 | *((u8g_uint_t *)arg) = pb->width; 139 | break; 140 | case U8G_DEV_MSG_GET_HEIGHT: 141 | *((u8g_uint_t *)arg) = pb->p.total_height; 142 | break; 143 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 144 | break; 145 | case U8G_DEV_MSG_SET_XY_CB: 146 | break; 147 | case U8G_DEV_MSG_GET_MODE: 148 | return U8G_MODE_GRAY2BIT; 149 | } 150 | return 1; 151 | } 152 | 153 | 154 | -------------------------------------------------------------------------------- /utility/u8g_com_arduino_hw_usart_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_arduino_hw_usart_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | SPI Clock Cycle Type 35 | 36 | SSD1351 50ns 20 MHz 37 | SSD1322 300ns 3.3 MHz 38 | SSD1327 300ns 39 | SSD1306 300ns 40 | ST7565 400ns 2.5 MHz 41 | ST7920 400ns 42 | 43 | */ 44 | 45 | #include "u8g.h" 46 | 47 | #if defined(ARDUINO) 48 | 49 | #if defined(__AVR_ATmega32U4__ ) 50 | 51 | #include 52 | #include 53 | 54 | #if ARDUINO < 100 55 | #include 56 | #else 57 | #include 58 | #endif 59 | 60 | 61 | 62 | static uint8_t u8g_usart_spi_out(uint8_t data) 63 | { 64 | /* send data */ 65 | UDR1 = data; 66 | /* wait for empty transmit buffer */ 67 | while(!(UCSR1A & (1 << UDRE1))); 68 | 69 | return UDR1; 70 | } 71 | 72 | 73 | uint8_t u8g_com_arduino_hw_usart_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 74 | { 75 | switch(msg) 76 | { 77 | case U8G_COM_MSG_STOP: 78 | break; 79 | 80 | case U8G_COM_MSG_INIT: 81 | /* SCK is already an output as we overwrite TXLED */ 82 | u8g_com_arduino_assign_pin_output_high(u8g); 83 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); 84 | 85 | // Init interface at 2MHz 86 | UBRR1 = 0x00; 87 | UCSR1C = (1 << UMSEL11) | (1 << UMSEL10); 88 | UCSR1B = (1 << TXEN1); 89 | UBRR1 = 3; 90 | 91 | break; 92 | 93 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 94 | u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val); 95 | break; 96 | 97 | case U8G_COM_MSG_CHIP_SELECT: 98 | if ( arg_val == 0 ) 99 | { 100 | /* disable */ 101 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); 102 | } 103 | else 104 | { 105 | /* enable */ 106 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW); 107 | } 108 | break; 109 | 110 | case U8G_COM_MSG_RESET: 111 | if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE ) 112 | u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); 113 | break; 114 | 115 | case U8G_COM_MSG_WRITE_BYTE: 116 | u8g_usart_spi_out(arg_val); 117 | break; 118 | 119 | case U8G_COM_MSG_WRITE_SEQ: 120 | { 121 | register uint8_t *ptr = arg_ptr; 122 | while( arg_val > 0 ) 123 | { 124 | u8g_usart_spi_out(*ptr++); 125 | arg_val--; 126 | } 127 | } 128 | break; 129 | case U8G_COM_MSG_WRITE_SEQ_P: 130 | { 131 | register uint8_t *ptr = arg_ptr; 132 | while( arg_val > 0 ) 133 | { 134 | u8g_usart_spi_out(u8g_pgm_read(ptr)); 135 | ptr++; 136 | arg_val--; 137 | } 138 | } 139 | break; 140 | } 141 | return 1; 142 | } 143 | 144 | /* #elif defined(__18CXX) || defined(__PIC32MX) */ 145 | /* #elif defined(__arm__) // Arduino Due, maybe we should better check for __SAM3X8E__ */ 146 | 147 | #else /* __AVR_ATmega32U4__ */ 148 | 149 | #endif /* __AVR_ATmega32U4__ */ 150 | 151 | #else /* ARDUINO */ 152 | 153 | uint8_t u8g_com_arduino_hw_usart_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 154 | { 155 | return 1; 156 | } 157 | 158 | #endif /* ARDUINO */ 159 | 160 | -------------------------------------------------------------------------------- /examples/nRF24Sender/nRF24Sender.ino: -------------------------------------------------------------------------------- 1 | /* 2 | nRF24Sender Demo for RFToy 3 | 4 | This demo shows how to use RFToy to make a 5 | wireless temperature sensor. This is the 6 | sender module which transmits the current 7 | temperature value to a receiver module. The 8 | demo uses the Mirf library. 9 | 10 | This demo uses a 100K resistor and 100K 11 | thermistor to form a simple temperature 12 | sensor. Pin A1 is used to read the value. 13 | The connection is: 14 | VCC->100K->A1->thermistor->GND 15 | 16 | Written by Jonathan Goldin @ Rayshobby LLC 17 | Nov 2014 18 | For details, visit http://rayshobby.net/rftoy 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE); // I2C / TWI 28 | 29 | static const float temps[] = { 30 | // according to TDR datasheet: http://www.360yuanjian.com/product/downloadFile-14073-proudct_pdf_doc-pdf.html 31 | // this table defines the reference resistance of the thermistor under each temperature value from -20 to 40 Celcius 32 | 940.885, // -20 Celcius 33 | 888.148, // -19 Celcius 34 | 838.764, 35 | 792.494, 36 | 749.115, 37 | 708.422, 38 | 670.228, 39 | 634.359, 40 | 600.657, 41 | 568.973, 42 | 539.171, 43 | 511.127, 44 | 484.723, 45 | 459.851, 46 | 436.413, 47 | 414.316, 48 | 393.473, 49 | 373.806, 50 | 355.239, 51 | 337.705, 52 | 321.140, 53 | 305.482, 54 | 290.679, 55 | 276.676, 56 | 263.427, 57 | 250.886, 58 | 239.012, 59 | 227.005, 60 | 217.106, 61 | 207.005, 62 | 198.530, 63 | 188.343, 64 | 179.724, 65 | 171.545, 66 | 163.780, 67 | 156.407, 68 | 149.403, 69 | 142.748, 70 | 136.423, 71 | 130.410, 72 | 124.692, 73 | 119.253, 74 | 114.078, 75 | 109.152, 76 | 104.464, 77 | 100.000, 78 | 95.747, 79 | 91.697, 80 | 87.837, 81 | 84.157, 82 | 80.650, 83 | 77.305, 84 | 74.115, 85 | 71.072, 86 | 68.167, 87 | 65.395, 88 | 62.749, 89 | 60.222, 90 | 57.809, 91 | 55.503, 92 | 53.300 // +40 Celcius 93 | }; 94 | 95 | void setup(){ 96 | Serial.begin(9600); 97 | Serial.println("begin."); 98 | 99 | /* 100 | Set ce and csn pins 101 | */ 102 | 103 | Mirf.cePin = 17; 104 | Mirf.csnPin = 16; 105 | 106 | Mirf.spi = &MirfHardwareSpi; 107 | Mirf.init(); 108 | 109 | /* 110 | * Configure reciving address. 111 | */ 112 | 113 | Mirf.setRADDR((byte *)"clie1"); 114 | 115 | /* 116 | * Set the payload length to sizeof(unsigned long) the 117 | * return type of millis(). 118 | * 119 | * NB: payload on client and server must be the same. 120 | */ 121 | 122 | Mirf.payload = sizeof(long); 123 | 124 | /* 125 | * Write channel and payload config then power up reciver. 126 | */ 127 | 128 | /* 129 | * To change channel: 130 | * 131 | * Mirf.channel = 10; 132 | * 133 | * NB: Make sure channel is legal in your area. 134 | */ 135 | 136 | Mirf.config(); 137 | 138 | } 139 | 140 | void loop(){ 141 | long temp = analogRead(A1); 142 | Serial.println(temp); 143 | float resistance = (100.0*temp)/(1024.0-temp); 144 | temp = getTemp(resistance); 145 | 146 | Mirf.setTADDR((byte *)"serv1"); 147 | 148 | Mirf.send((byte *)&temp); 149 | 150 | // OLED 151 | u8g.firstPage(); 152 | do{ 153 | uint8_t h; 154 | u8g.setFont(u8g_font_10x20); 155 | u8g.setFontRefHeightText(); 156 | u8g.setFontPosTop(); 157 | h = u8g.getFontAscent()-u8g.getFontDescent(); 158 | u8g.drawStr(29,(u8g.getHeight()-h)/2,"SENDING"); 159 | } 160 | while(u8g.nextPage()); 161 | 162 | while(Mirf.isSending()){ 163 | } 164 | 165 | Serial.println("Finished sending"); 166 | delay(10); 167 | unsigned long time = millis(); 168 | while(!Mirf.dataReady()){ 169 | //Serial.println("Waiting"); 170 | if ( ( millis() - time ) > 1000 ) { 171 | Serial.println("Timeout on response from server!"); 172 | return; 173 | } 174 | } 175 | int temp2; 176 | Mirf.getData((byte *) &temp2); 177 | 178 | if(temp == temp2){ 179 | Serial.println("response matches"); 180 | } else { 181 | Serial.println("response doesn't match"); 182 | } 183 | 184 | delay(1000); // keep the 'sending' message displayed on OLED for 1 sec 185 | u8g.firstPage(); 186 | do{ 187 | } while(u8g.nextPage()); 188 | 189 | delay(2000); // wait for 2 seconds till next transmission 190 | } 191 | 192 | // search in TDR table for the closest resistance 193 | // then do linear interpolation 194 | long getTemp(float resistance){ 195 | for(int i = 1; i < (sizeof(temps)/sizeof(long)); i++){ 196 | if(resistance >= temps[i]){ 197 | float temp = 10.0*(i-20); 198 | Serial.println(i); 199 | // keep in mind the thermistor is negatively correlated with temperature 200 | temp -= 10.0*(resistance-temps[i])/(temps[i-1]-temps[i]); 201 | Serial.println(temp); 202 | return (long)temp; 203 | } 204 | } 205 | return -40; 206 | } 207 | 208 | 209 | -------------------------------------------------------------------------------- /utility/u8g_bitmap.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_bitmap.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | */ 36 | 37 | #include "u8g.h" 38 | 39 | void u8g_DrawHBitmap(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, const uint8_t *bitmap) 40 | { 41 | while( cnt > 0 ) 42 | { 43 | u8g_Draw8Pixel(u8g, x, y, 0, *bitmap); 44 | bitmap++; 45 | cnt--; 46 | x+=8; 47 | } 48 | } 49 | 50 | void u8g_DrawBitmap(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, u8g_uint_t h, const uint8_t *bitmap) 51 | { 52 | if ( u8g_IsBBXIntersection(u8g, x, y, cnt*8, h) == 0 ) 53 | return; 54 | while( h > 0 ) 55 | { 56 | u8g_DrawHBitmap(u8g, x, y, cnt, bitmap); 57 | bitmap += cnt; 58 | y++; 59 | h--; 60 | } 61 | } 62 | 63 | 64 | void u8g_DrawHBitmapP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, const u8g_pgm_uint8_t *bitmap) 65 | { 66 | while( cnt > 0 ) 67 | { 68 | u8g_Draw8Pixel(u8g, x, y, 0, u8g_pgm_read(bitmap)); 69 | bitmap++; 70 | cnt--; 71 | x+=8; 72 | } 73 | } 74 | 75 | void u8g_DrawBitmapP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, u8g_uint_t h, const u8g_pgm_uint8_t *bitmap) 76 | { 77 | if ( u8g_IsBBXIntersection(u8g, x, y, cnt*8, h) == 0 ) 78 | return; 79 | while( h > 0 ) 80 | { 81 | u8g_DrawHBitmapP(u8g, x, y, cnt, bitmap); 82 | bitmap += cnt; 83 | y++; 84 | h--; 85 | } 86 | } 87 | 88 | /*=========================================================================*/ 89 | 90 | static void u8g_DrawHXBM(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, const uint8_t *bitmap) 91 | { 92 | uint8_t d; 93 | x+=7; 94 | while( w >= 8 ) 95 | { 96 | u8g_Draw8Pixel(u8g, x, y, 2, *bitmap); 97 | bitmap++; 98 | w-= 8; 99 | x+=8; 100 | } 101 | if ( w > 0 ) 102 | { 103 | d = *bitmap; 104 | x -= 7; 105 | do 106 | { 107 | if ( d & 1 ) 108 | u8g_DrawPixel(u8g, x, y); 109 | x++; 110 | w--; 111 | d >>= 1; 112 | } while ( w > 0 ); 113 | } 114 | } 115 | 116 | void u8g_DrawXBM(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, const uint8_t *bitmap) 117 | { 118 | u8g_uint_t b; 119 | b = w; 120 | b += 7; 121 | b >>= 3; 122 | 123 | if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 ) 124 | return; 125 | 126 | while( h > 0 ) 127 | { 128 | u8g_DrawHXBM(u8g, x, y, w, bitmap); 129 | bitmap += b; 130 | y++; 131 | h--; 132 | } 133 | } 134 | 135 | static void u8g_DrawHXBMP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, const u8g_pgm_uint8_t *bitmap) 136 | { 137 | uint8_t d; 138 | x+=7; 139 | while( w >= 8 ) 140 | { 141 | u8g_Draw8Pixel(u8g, x, y, 2, u8g_pgm_read(bitmap)); 142 | bitmap++; 143 | w-= 8; 144 | x+=8; 145 | } 146 | if ( w > 0 ) 147 | { 148 | d = u8g_pgm_read(bitmap); 149 | x -= 7; 150 | do 151 | { 152 | if ( d & 1 ) 153 | u8g_DrawPixel(u8g, x, y); 154 | x++; 155 | w--; 156 | d >>= 1; 157 | } while ( w > 0 ); 158 | } 159 | } 160 | 161 | void u8g_DrawXBMP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, const u8g_pgm_uint8_t *bitmap) 162 | { 163 | u8g_uint_t b; 164 | b = w; 165 | b += 7; 166 | b >>= 3; 167 | 168 | if ( u8g_IsBBXIntersection(u8g, x, y, w, h) == 0 ) 169 | return; 170 | while( h > 0 ) 171 | { 172 | u8g_DrawHXBMP(u8g, x, y, w, bitmap); 173 | bitmap += b; 174 | y++; 175 | h--; 176 | } 177 | } 178 | -------------------------------------------------------------------------------- /utility/u8g_dev_pcd8544_84x48.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_pcd8544_84x48.c 4 | 5 | Display: Nokia 84x48 6 | 7 | Status: Tested with PCF8812 Display 8 | 9 | 10 | Universal 8bit Graphics Library 11 | 12 | Copyright (c) 2011, olikraus@gmail.com 13 | All rights reserved. 14 | 15 | Redistribution and use in source and binary forms, with or without modification, 16 | are permitted provided that the following conditions are met: 17 | 18 | * Redistributions of source code must retain the above copyright notice, this list 19 | of conditions and the following disclaimer. 20 | 21 | * Redistributions in binary form must reproduce the above copyright notice, this 22 | list of conditions and the following disclaimer in the documentation and/or other 23 | materials provided with the distribution. 24 | 25 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 26 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 27 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 28 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 29 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 30 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 31 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 32 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 33 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 34 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 35 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 36 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 37 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 38 | 39 | 40 | */ 41 | 42 | #include "u8g.h" 43 | 44 | #define WIDTH 84 45 | #define HEIGHT 48 46 | #define PAGE_HEIGHT 8 47 | 48 | 49 | static const uint8_t u8g_dev_pcd8544_init_seq[] PROGMEM = { 50 | U8G_ESC_CS(0), /* disable chip */ 51 | U8G_ESC_ADR(0), /* instruction mode */ 52 | U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */ 53 | U8G_ESC_CS(1), /* enable chip */ 54 | 0x021, /* activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=1) */ 55 | 0x006, /* temp. control: b10 = 2 */ 56 | 0x013, /* bias system 1:48 */ 57 | 0x0c0, /* medium Vop */ 58 | 0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ 59 | 0x00c, /* display on, normal operation */ 60 | U8G_ESC_DLY(100), /* delay 100 ms */ 61 | 0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ 62 | 0x00d, /* display on, invert */ 63 | U8G_ESC_DLY(100), /* delay 100 ms */ 64 | U8G_ESC_DLY(100), /* delay 100 ms */ 65 | 0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ 66 | 0x00c, /* display on, normal */ 67 | U8G_ESC_DLY(100), /* delay 100 ms */ 68 | U8G_ESC_CS(0), /* disable chip */ 69 | U8G_ESC_END /* end of sequence */ 70 | }; 71 | 72 | uint8_t u8g_dev_pcd8544_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 73 | { 74 | switch(msg) 75 | { 76 | case U8G_DEV_MSG_INIT: 77 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS); 78 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_pcd8544_init_seq); 79 | break; 80 | case U8G_DEV_MSG_STOP: 81 | break; 82 | case U8G_DEV_MSG_PAGE_NEXT: 83 | { 84 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 85 | u8g_SetAddress(u8g, dev, 0); /* command mode */ 86 | u8g_SetChipSelect(u8g, dev, 1); 87 | u8g_WriteByte(u8g, dev, 0x020 ); /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ 88 | u8g_WriteByte(u8g, dev, 0x080 ); /* set X address */ 89 | u8g_WriteByte(u8g, dev, 0x040 | pb->p.page); /* set Y address */ 90 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 91 | if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 ) 92 | return 0; 93 | u8g_SetChipSelect(u8g, dev, 0); 94 | } 95 | break; 96 | case U8G_DEV_MSG_CONTRAST: 97 | /* the contrast adjustment does not work, needs to be analysed */ 98 | u8g_SetAddress(u8g, dev, 0); /* instruction mode */ 99 | u8g_SetChipSelect(u8g, dev, 1); 100 | u8g_WriteByte(u8g, dev, 0x021); /* command mode, extended function set */ 101 | u8g_WriteByte(u8g, dev, 0x080 | ( (*(uint8_t *)arg) >> 1 ) ); 102 | u8g_SetChipSelect(u8g, dev, 0); 103 | return 1; 104 | } 105 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 106 | } 107 | 108 | 109 | U8G_PB_DEV(u8g_dev_pcd8544_84x48_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_pcd8544_fn, U8G_COM_SW_SPI); 110 | U8G_PB_DEV(u8g_dev_pcd8544_84x48_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_pcd8544_fn, U8G_COM_HW_SPI); 111 | 112 | -------------------------------------------------------------------------------- /utility/u8g_dev_tls8204_84x48.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_tls8204_84x48.c 4 | 5 | Display: Nokia 84x48 6 | 7 | Status: Tested with TLS8204V12 Display by Olimex MOD-LCD3310 8 | 9 | Contributed: http://code.google.com/p/u8glib/issues/detail?id=126 10 | 11 | Universal 8bit Graphics Library 12 | 13 | Copyright (c) 2011, olikraus@gmail.com 14 | All rights reserved. 15 | 16 | Redistribution and use in source and binary forms, with or without modification, 17 | are permitted provided that the following conditions are met: 18 | 19 | * Redistributions of source code must retain the above copyright notice, this list 20 | of conditions and the following disclaimer. 21 | 22 | * Redistributions in binary form must reproduce the above copyright notice, this 23 | list of conditions and the following disclaimer in the documentation and/or other 24 | materials provided with the distribution. 25 | 26 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 27 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 28 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 29 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 30 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 31 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 32 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 33 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 34 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 35 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 36 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 37 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 38 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 39 | 40 | 41 | */ 42 | 43 | #include "u8g.h" 44 | 45 | #define WIDTH 84 46 | #define HEIGHT 48 47 | #define PAGE_HEIGHT 8 48 | 49 | 50 | static const uint8_t u8g_dev_tls8204_init_seq[] PROGMEM = { 51 | U8G_ESC_CS(0), /* disable chip */ 52 | U8G_ESC_ADR(0), /* instruction mode */ 53 | U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */ 54 | U8G_ESC_CS(1), /* enable chip */ 55 | 0x021, /* activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=1) */ 56 | 0x006, /* temp. control: b10 = 2 */ 57 | 0x04 | !!((66-1)&(1u<<6)), 58 | 0x40 | ((66-2) & ((1u<<6)-1)), 59 | 0x013, /* bias system 1:48 */ 60 | 0x0c0, /* medium Vop */ 61 | 0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ 62 | 0x00c, /* display on, normal operation */ 63 | U8G_ESC_DLY(100), /* delay 100 ms */ 64 | 0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ 65 | 0x00d, /* display on, invert */ 66 | U8G_ESC_DLY(100), /* delay 100 ms */ 67 | U8G_ESC_DLY(100), /* delay 100 ms */ 68 | 0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ 69 | 0x00c, /* display on, normal */ 70 | U8G_ESC_DLY(100), /* delay 100 ms */ 71 | U8G_ESC_CS(0), /* disable chip */ 72 | U8G_ESC_END /* end of sequence */ 73 | }; 74 | 75 | 76 | uint8_t u8g_dev_tls8204_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 77 | { 78 | switch(msg) 79 | { 80 | case U8G_DEV_MSG_INIT: 81 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS); 82 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_tls8204_init_seq); 83 | break; 84 | case U8G_DEV_MSG_STOP: 85 | break; 86 | case U8G_DEV_MSG_PAGE_NEXT: 87 | { 88 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 89 | u8g_SetAddress(u8g, dev, 0); /* command mode */ 90 | u8g_SetChipSelect(u8g, dev, 1); 91 | u8g_WriteByte(u8g, dev, 0x020 ); /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ 92 | u8g_WriteByte(u8g, dev, 0x080 ); /* set X address */ 93 | u8g_WriteByte(u8g, dev, 0x040 | pb->p.page); /* set Y address */ 94 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 95 | if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 ) 96 | return 0; 97 | u8g_SetChipSelect(u8g, dev, 0); 98 | } 99 | break; 100 | case U8G_DEV_MSG_CONTRAST: 101 | /* the contrast adjustment does not work, needs to be analysed */ 102 | u8g_SetAddress(u8g, dev, 0); /* instruction mode */ 103 | u8g_SetChipSelect(u8g, dev, 1); 104 | u8g_WriteByte(u8g, dev, 0x021); /* command mode, extended function set */ 105 | u8g_WriteByte(u8g, dev, 0x080 | ( (*(uint8_t *)arg) >> 1 ) ); 106 | u8g_WriteByte(u8g, dev, 0x020); /* command mode, extended function set */ 107 | u8g_SetChipSelect(u8g, dev, 0); 108 | return 1; 109 | } 110 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 111 | } 112 | 113 | 114 | U8G_PB_DEV(u8g_dev_tls8204_84x48_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_tls8204_fn, U8G_COM_SW_SPI); 115 | 116 | -------------------------------------------------------------------------------- /utility/u8g_pb8h2.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_pb8h2.c 4 | 5 | 8bit height 2 bit per pixel page buffer 6 | byte has horizontal orientation 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2011, olikraus@gmail.com 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright notice, this list 17 | of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this 20 | list of conditions and the following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | 38 | */ 39 | 40 | #include "u8g.h" 41 | #include 42 | 43 | void u8g_pb8h2_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) 44 | { 45 | b->buf = buf; 46 | b->width = width; 47 | u8g_pb_Clear(b); 48 | } 49 | 50 | static void u8g_pb8h2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE; 51 | static void u8g_pb8h2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) 52 | { 53 | register uint8_t mask; 54 | register uint16_t tmp; 55 | 56 | uint8_t *ptr = b->buf; 57 | 58 | y -= b->p.page_y0; 59 | 60 | tmp = b->width; 61 | tmp >>= 2; 62 | tmp *= (uint8_t)y; 63 | ptr += tmp; 64 | 65 | tmp = x; 66 | tmp >>= 2; 67 | ptr += tmp; 68 | 69 | tmp = x; 70 | tmp &= 3; 71 | tmp <<= 1; 72 | mask = 3; 73 | mask <<= tmp; 74 | mask = ~mask; 75 | color_index &= 3; 76 | color_index <<= tmp; 77 | 78 | *ptr &= mask; 79 | *ptr |= color_index; 80 | } 81 | 82 | 83 | void u8g_pb8h2_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) 84 | { 85 | if ( arg_pixel->y < b->p.page_y0 ) 86 | return; 87 | if ( arg_pixel->y > b->p.page_y1 ) 88 | return; 89 | if ( arg_pixel->x >= b->width ) 90 | return; 91 | u8g_pb8h2_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 92 | } 93 | 94 | 95 | void u8g_pb8h2_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 96 | { 97 | register uint8_t pixel = arg_pixel->pixel; 98 | do 99 | { 100 | if ( pixel & 128 ) 101 | { 102 | u8g_pb8h2_SetPixel(b, arg_pixel); 103 | } 104 | switch( arg_pixel->dir ) 105 | { 106 | case 0: arg_pixel->x++; break; 107 | case 1: arg_pixel->y++; break; 108 | case 2: arg_pixel->x--; break; 109 | case 3: arg_pixel->y--; break; 110 | } 111 | pixel <<= 1; 112 | } while( pixel != 0 ); 113 | } 114 | 115 | 116 | 117 | uint8_t u8g_dev_pb8h2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 118 | { 119 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 120 | switch(msg) 121 | { 122 | case U8G_DEV_MSG_SET_8PIXEL: 123 | if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) 124 | { 125 | u8g_pb8h2_Set8PixelStd(pb, (u8g_dev_arg_pixel_t *)arg); 126 | } 127 | break; 128 | case U8G_DEV_MSG_SET_PIXEL: 129 | u8g_pb8h2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 130 | break; 131 | case U8G_DEV_MSG_INIT: 132 | break; 133 | case U8G_DEV_MSG_STOP: 134 | break; 135 | case U8G_DEV_MSG_PAGE_FIRST: 136 | u8g_pb_Clear(pb); 137 | u8g_page_First(&(pb->p)); 138 | break; 139 | case U8G_DEV_MSG_PAGE_NEXT: 140 | if ( u8g_page_Next(&(pb->p)) == 0 ) 141 | return 0; 142 | u8g_pb_Clear(pb); 143 | break; 144 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 145 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 146 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 147 | #endif 148 | case U8G_DEV_MSG_GET_PAGE_BOX: 149 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 150 | break; 151 | case U8G_DEV_MSG_GET_WIDTH: 152 | *((u8g_uint_t *)arg) = pb->width; 153 | break; 154 | case U8G_DEV_MSG_GET_HEIGHT: 155 | *((u8g_uint_t *)arg) = pb->p.total_height; 156 | break; 157 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 158 | break; 159 | case U8G_DEV_MSG_SET_XY_CB: 160 | break; 161 | case U8G_DEV_MSG_GET_MODE: 162 | return U8G_MODE_GRAY2BIT; 163 | } 164 | return 1; 165 | } 166 | 167 | 168 | -------------------------------------------------------------------------------- /utility/u8g_clip.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_clip.c 4 | 5 | procedures for clipping 6 | taken over from procs in u8g_pb.c 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2012, olikraus@gmail.com 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright notice, this list 17 | of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this 20 | list of conditions and the following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | Notes 38 | 39 | This is one of the most critical parts of u8glib. It must be fast, but still reliable. 40 | Based on the intersection program (see tools folder), there is minimized version of 41 | the condition for the intersaction test: 42 | minimized version 43 | ---1----0 1 b1 <= a2 && b1 > b2 44 | -----1--0 1 b2 >= a1 && b1 > b2 45 | ---1-1--- 1 b1 <= a2 && b2 >= a1 46 | It includes the assumption, that a1 <= a2 is always true (correct, because 47 | a1, a2 are the page dimensions. 48 | 49 | The direct implementation of the above result is done in: 50 | uint8_t u8g_is_intersection_boolean(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) 51 | However, this is slower than a decision tree version: 52 | static uint8_t u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) 53 | Also suprising is, that the macro implementation is slower than the inlined version. 54 | 55 | The decision tree is based on the expansion of the truth table. 56 | 57 | */ 58 | 59 | #include "u8g.h" 60 | 61 | #ifdef __GNUC__ 62 | #define U8G_ALWAYS_INLINE __inline__ __attribute__((always_inline)) 63 | #else 64 | #define U8G_ALWAYS_INLINE 65 | #endif 66 | 67 | /* 68 | intersection assumptions: 69 | a1 <= a2 is always true 70 | 71 | minimized version 72 | ---1----0 1 b1 <= a2 && b1 > b2 73 | -----1--0 1 b2 >= a1 && b1 > b2 74 | ---1-1--- 1 b1 <= a2 && b2 >= a1 75 | */ 76 | 77 | #ifdef OLD_CODE_WHICH_IS_TOO_SLOW 78 | static uint8_t u8g_is_intersection_boolean(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) 79 | { 80 | uint8_t c1, c2, c3, tmp; 81 | c1 = v0 <= a1; 82 | c2 = v1 >= a0; 83 | c3 = v0 > v1; 84 | 85 | tmp = c1; 86 | c1 &= c2; 87 | c2 &= c3; 88 | c3 &= tmp; 89 | c1 |= c2; 90 | c1 |= c3; 91 | return c1 & 1; 92 | } 93 | #endif 94 | 95 | #define U8G_IS_INTERSECTION_MACRO(a0,a1,v0,v1) ((uint8_t)( (v0) <= (a1) ) ? ( ( (v1) >= (a0) ) ? ( 1 ) : ( (v0) > (v1) ) ) : ( ( (v1) >= (a0) ) ? ( (v0) > (v1) ) : ( 0 ) )) 96 | 97 | //static uint8_t u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) U8G_ALWAYS_INLINE; 98 | static uint8_t U8G_ALWAYS_INLINE u8g_is_intersection_decision_tree(u8g_uint_t a0, u8g_uint_t a1, u8g_uint_t v0, u8g_uint_t v1) 99 | { 100 | /* surprisingly the macro leads to larger code */ 101 | /* return U8G_IS_INTERSECTION_MACRO(a0,a1,v0,v1); */ 102 | if ( v0 <= a1 ) 103 | { 104 | if ( v1 >= a0 ) 105 | { 106 | return 1; 107 | } 108 | else 109 | { 110 | if ( v0 > v1 ) 111 | { 112 | return 1; 113 | } 114 | else 115 | { 116 | return 0; 117 | } 118 | } 119 | } 120 | else 121 | { 122 | if ( v1 >= a0 ) 123 | { 124 | if ( v0 > v1 ) 125 | { 126 | return 1; 127 | } 128 | else 129 | { 130 | return 0; 131 | } 132 | } 133 | else 134 | { 135 | return 0; 136 | } 137 | } 138 | } 139 | 140 | 141 | uint8_t u8g_IsBBXIntersection(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h) 142 | { 143 | register u8g_uint_t tmp; 144 | tmp = y; 145 | tmp += h; 146 | tmp--; 147 | if ( u8g_is_intersection_decision_tree(u8g->current_page.y0, u8g->current_page.y1, y, tmp) == 0 ) 148 | return 0; 149 | 150 | tmp = x; 151 | tmp += w; 152 | tmp--; 153 | return u8g_is_intersection_decision_tree(u8g->current_page.x0, u8g->current_page.x1, x, tmp); 154 | } 155 | 156 | 157 | -------------------------------------------------------------------------------- /utility/u8g_virtual_screen.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_virtual_screen.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2012, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | */ 36 | 37 | #include "u8g.h" 38 | 39 | struct _u8g_vs_t 40 | { 41 | u8g_uint_t x; 42 | u8g_uint_t y; 43 | u8g_t *u8g; 44 | }; 45 | typedef struct _u8g_vs_t u8g_vs_t; 46 | 47 | #define U8g_VS_MAX 4 48 | uint8_t u8g_vs_cnt = 0; 49 | u8g_vs_t u8g_vs_list[U8g_VS_MAX]; 50 | uint8_t u8g_vs_current; 51 | u8g_uint_t u8g_vs_width; 52 | u8g_uint_t u8g_vs_height; 53 | 54 | uint8_t u8g_dev_vs_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 55 | { 56 | switch(msg) 57 | { 58 | default: 59 | { 60 | uint8_t i; 61 | for( i = 0; i < u8g_vs_cnt; i++ ) 62 | { 63 | u8g_call_dev_fn(u8g_vs_list[i].u8g, u8g_vs_list[i].u8g->dev, msg, arg); 64 | } 65 | } 66 | return 1; 67 | case U8G_DEV_MSG_PAGE_FIRST: 68 | u8g_vs_current = 0; 69 | if ( u8g_vs_cnt != 0 ) 70 | return u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); 71 | return 0; 72 | case U8G_DEV_MSG_PAGE_NEXT: 73 | { 74 | uint8_t ret = 0; 75 | if ( u8g_vs_cnt != 0 ) 76 | ret = u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); 77 | if ( ret != 0 ) 78 | return ret; 79 | u8g_vs_current++; /* next device */ 80 | if ( u8g_vs_current >= u8g_vs_cnt ) /* reached end? */ 81 | return 0; 82 | return u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, U8G_DEV_MSG_PAGE_FIRST, arg); 83 | } 84 | return 0; 85 | case U8G_DEV_MSG_GET_WIDTH: 86 | *((u8g_uint_t *)arg) = u8g_vs_width; 87 | break; 88 | case U8G_DEV_MSG_GET_HEIGHT: 89 | *((u8g_uint_t *)arg) = u8g_vs_height; 90 | break; 91 | case U8G_DEV_MSG_GET_PAGE_BOX: 92 | if ( u8g_vs_current < u8g_vs_cnt ) 93 | { 94 | u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); 95 | ((u8g_box_t *)arg)->x0 += u8g_vs_list[u8g_vs_current].x; 96 | ((u8g_box_t *)arg)->x1 += u8g_vs_list[u8g_vs_current].x; 97 | ((u8g_box_t *)arg)->y0 += u8g_vs_list[u8g_vs_current].y; 98 | ((u8g_box_t *)arg)->y1 += u8g_vs_list[u8g_vs_current].y; 99 | } 100 | else 101 | { 102 | ((u8g_box_t *)arg)->x0 = 0; 103 | ((u8g_box_t *)arg)->x1 = 0; 104 | ((u8g_box_t *)arg)->y0 = 0; 105 | ((u8g_box_t *)arg)->y1 = 0; 106 | } 107 | return 1; 108 | case U8G_DEV_MSG_SET_PIXEL: 109 | case U8G_DEV_MSG_SET_8PIXEL: 110 | if ( u8g_vs_current < u8g_vs_cnt ) 111 | { 112 | ((u8g_dev_arg_pixel_t *)arg)->x -= u8g_vs_list[u8g_vs_current].x; 113 | ((u8g_dev_arg_pixel_t *)arg)->y -= u8g_vs_list[u8g_vs_current].y; 114 | return u8g_call_dev_fn(u8g_vs_list[u8g_vs_current].u8g, u8g_vs_list[u8g_vs_current].u8g->dev, msg, arg); 115 | } 116 | break; 117 | } 118 | return 1; 119 | } 120 | 121 | 122 | 123 | u8g_dev_t u8g_dev_vs = { u8g_dev_vs_fn, NULL, NULL }; 124 | 125 | void u8g_SetVirtualScreenDimension(u8g_t *vs_u8g, u8g_uint_t width, u8g_uint_t height) 126 | { 127 | if ( vs_u8g->dev != &u8g_dev_vs ) 128 | return; /* abort if there is no a virtual screen device */ 129 | u8g_vs_width = width; 130 | u8g_vs_height = height; 131 | } 132 | 133 | uint8_t u8g_AddToVirtualScreen(u8g_t *vs_u8g, u8g_uint_t x, u8g_uint_t y, u8g_t *child_u8g) 134 | { 135 | if ( vs_u8g->dev != &u8g_dev_vs ) 136 | return 0; /* abort if there is no a virtual screen device */ 137 | if ( u8g_vs_cnt >= U8g_VS_MAX ) 138 | return 0; /* maximum number of child u8g's reached */ 139 | u8g_vs_list[u8g_vs_cnt].u8g = child_u8g; 140 | u8g_vs_list[u8g_vs_cnt].x = x; 141 | u8g_vs_list[u8g_vs_cnt].y = y; 142 | u8g_vs_cnt++; 143 | return 1; 144 | } 145 | 146 | -------------------------------------------------------------------------------- /utility/u8g_pb16v2.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_pb16v2.c 4 | 5 | 16 bit height 2 bit per pixel page buffer 6 | byte has vertical orientation 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2012, olikraus@gmail.com 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright notice, this list 17 | of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this 20 | list of conditions and the following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | 38 | */ 39 | 40 | #include "u8g.h" 41 | #include 42 | 43 | 44 | void u8g_pb16v2_Clear(u8g_pb_t *b) 45 | { 46 | uint8_t *ptr = (uint8_t *)b->buf; 47 | uint8_t *end_ptr = ptr; 48 | 49 | /* two bits per pixel, 16 bits height --> 8 pixel --> 4 pixel per byte */ 50 | end_ptr += b->width; 51 | end_ptr += b->width; 52 | 53 | do 54 | { 55 | *ptr++ = 0; 56 | } while( ptr != end_ptr ); 57 | } 58 | 59 | void u8g_pb16v2Init(u8g_pb_t *b, void *buf, u8g_uint_t width) 60 | { 61 | b->buf = buf; 62 | b->width = width; 63 | u8g_pb16v2_Clear(b); 64 | } 65 | 66 | void u8g_pb16v2_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) 67 | { 68 | register uint8_t mask; 69 | uint8_t *ptr = b->buf; 70 | y -= b->p.page_y0; 71 | if ( y >= 4 ) 72 | { 73 | ptr += b->width; 74 | } 75 | mask = 0x03; 76 | y &= 0x03; 77 | y <<= 1; 78 | mask <<= y; 79 | mask ^=0xff; 80 | color_index &= 3; 81 | color_index <<= y; 82 | ptr += x; 83 | *ptr &= mask; 84 | *ptr |= color_index; 85 | } 86 | 87 | 88 | void u8g_pb16v2_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) 89 | { 90 | if ( arg_pixel->y < b->p.page_y0 ) 91 | return; 92 | if ( arg_pixel->y > b->p.page_y1 ) 93 | return; 94 | if ( arg_pixel->x >= b->width ) 95 | return; 96 | u8g_pb16v2_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 97 | } 98 | 99 | 100 | void u8g_pb16v2_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 101 | { 102 | register uint8_t pixel = arg_pixel->pixel; 103 | do 104 | { 105 | if ( pixel & 128 ) 106 | { 107 | u8g_pb16v2_SetPixel(b, arg_pixel); 108 | } 109 | switch( arg_pixel->dir ) 110 | { 111 | case 0: arg_pixel->x++; break; 112 | case 1: arg_pixel->y++; break; 113 | case 2: arg_pixel->x--; break; 114 | case 3: arg_pixel->y--; break; 115 | } 116 | pixel <<= 1; 117 | } while( pixel != 0 ); 118 | } 119 | 120 | 121 | 122 | uint8_t u8g_dev_pb16v2_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 123 | { 124 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 125 | switch(msg) 126 | { 127 | case U8G_DEV_MSG_SET_8PIXEL: 128 | if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) 129 | { 130 | u8g_pb16v2_Set8PixelStd(pb, (u8g_dev_arg_pixel_t *)arg); 131 | } 132 | break; 133 | case U8G_DEV_MSG_SET_PIXEL: 134 | u8g_pb16v2_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 135 | break; 136 | case U8G_DEV_MSG_INIT: 137 | break; 138 | case U8G_DEV_MSG_STOP: 139 | break; 140 | case U8G_DEV_MSG_PAGE_FIRST: 141 | u8g_pb16v2_Clear(pb); 142 | u8g_page_First(&(pb->p)); 143 | break; 144 | case U8G_DEV_MSG_PAGE_NEXT: 145 | if ( u8g_page_Next(&(pb->p)) == 0 ) 146 | return 0; 147 | u8g_pb16v2_Clear(pb); 148 | break; 149 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 150 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 151 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 152 | #endif 153 | case U8G_DEV_MSG_GET_PAGE_BOX: 154 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 155 | break; 156 | case U8G_DEV_MSG_GET_WIDTH: 157 | *((u8g_uint_t *)arg) = pb->width; 158 | break; 159 | case U8G_DEV_MSG_GET_HEIGHT: 160 | *((u8g_uint_t *)arg) = pb->p.total_height; 161 | break; 162 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 163 | break; 164 | case U8G_DEV_MSG_SET_XY_CB: 165 | break; 166 | case U8G_DEV_MSG_GET_MODE: 167 | return U8G_MODE_GRAY2BIT; 168 | } 169 | return 1; 170 | } 171 | 172 | 173 | -------------------------------------------------------------------------------- /VirtualWire_Config.h: -------------------------------------------------------------------------------- 1 | #ifndef VirtualWire_Config_h 2 | #define VirtualWire_Config_h 3 | ////////////////////////////////////////////////////////////////////////// 4 | // The following configurations are intented only if VW_PLATFORM == VW_PLATFORM_GENERIC_AVR8 5 | 6 | // Uncomment this to select the platform as generic AVR8 7 | //#define VW_PLATFORM VW_PLATFORM_GENERIC_AVR8 8 | 9 | // OPTIONAL: Define the IO pin used for PTT (push to talk) 10 | // If no PTT port will be defined, the PTT feature will be disabled 11 | //#define VW_PTT_PORT PORT# 12 | //#define VW_PTT_DDR DDR# 13 | //#define VW_PTT_PIN PIN#? 14 | 15 | // Define the IO pin used for transmitting data 16 | //#define VW_TX_PORT PORT# 17 | //#define VW_TX_DDR DDR# 18 | //#define VW_TX_PIN PIN#? 19 | 20 | // Define the IO pin used for receiving data 21 | //#define VW_RX_PORT PIN# 22 | //#define VW_RX_DDR DDR# 23 | //#define VW_RX_PIN PIN#? 24 | 25 | // Define the 16 bits timer index to be used by the library (e.g. 1) 26 | // The default timer configuration will use TIMSKn as interrupt mask register, 27 | // OCRnA as compare register and TIMERn_COMPA_vect as interrupt vector 28 | // If one of the above doesn't suite your current platform, please redefine 29 | // the timer setup routine, as indicated below 30 | //#define VW_TIMER_INDEX 1 31 | 32 | // 33 | // EXAMPLE: configuration suitable for At90USB162 or ATMega32U2 34 | // 35 | 36 | /* 37 | // Select AVR8 platform 38 | #define VW_PLATFORM VW_PLATFORM_GENERIC_AVR8 39 | 40 | // My radio doesn't have PTT feature => VW_PTT_PORT/DDR/PIN will be left undefined 41 | //#define VW_PTT_PORT 42 | //#define VW_PTT_DDR 43 | //#define VW_PTT_PIN 44 | 45 | // VirtualWire TX 46 | #define VW_TX_PORT PORTD 47 | #define VW_TX_DDR DDRD 48 | #define VW_TX_PIN PIND7 49 | 50 | // VirtualWire RX 51 | #define VW_RX_PORT PIND 52 | #define VW_RX_DDR DDRD 53 | #define VW_RX_PIN PIND6 54 | 55 | // Reduce message length, saves up memory 56 | #define VW_MAX_MESSAGE_LEN 40 57 | 58 | // Select Timer 1 as the 16 bits timer used by the library 59 | #define VW_TIMER_INDEX 1 60 | */ 61 | 62 | // 63 | // OPTIONAL: Alternative pin setup for advanced configurations 64 | // Instead of defining VW_PTT_PORT/DDR/PIN, VW_TX_PORT/DDR/PIN or VW_RX_PORT/DDR/PIN 65 | // the user can use the following preprocessor directives to control the way 66 | // VirtualWire library reads the RX and writes to the TX or PTT 67 | // 68 | 69 | //#define vw_pinSetup() 70 | //#define vw_digitalWrite_ptt(value) 71 | //#define vw_digitalRead_rx() 72 | //#define vw_digitalWrite_tx(value) 73 | 74 | // 75 | // EXAMPLE: Advanced pin configuration that lights up a LED when PTT is high 76 | // RX=PORTD7, PTT=PORTD6, LED=PORTD5, TX=PORTD4 77 | // 78 | 79 | /* 80 | // Select AVR8 platform 81 | #define VW_PLATFORM VW_PLATFORM_GENERIC_AVR8 82 | 83 | #define vw_pinSetup()\ 84 | DDRD |= (1< 112 | 113 | // Select AVR8 platform 114 | #define VW_PLATFORM VW_PLATFORM_GENERIC_AVR8 115 | 116 | // Declare my own timer setup function 117 | static inline void my_vw_timerSetup(uint8_t speed) __attribute__ ((always_inline)); 118 | 119 | // VirtualWire has a special routine for detecting prescaler and the number of ticks 120 | // automatically, but needs to be declared first in order to be used 121 | uint8_t vw_timer_calc(uint16_t speed, uint16_t max_ticks, uint16_t *nticks); 122 | 123 | // Instruct VirtualWire to use my timer setup routine and my interrupt vector 124 | #define vw_timerSetup(speed) my_vw_timerSetup(speed); 125 | #define VW_TIMER_VECTOR TIMER1_COMPB_vect 126 | 127 | // Define my setup timer routine, that uses OCR1B as compare register 128 | static inline void my_vw_timerSetup(uint8_t speed) 129 | { 130 | // Figure out prescaler value and counter match value 131 | prescaler = vw_timer_calc(speed, (uint16_t)-1, &nticks); 132 | if (!prescaler) 133 | { 134 | return; // fault 135 | } 136 | 137 | TCCR1A = 0; // Output Compare pins disconnected 138 | TCCR1B = _BV(WGM12); // Turn on CTC mode 139 | 140 | // Convert prescaler index to TCCR1B prescaler bits CS10, CS11, CS12 141 | TCCR1B |= prescaler; 142 | 143 | // Caution: special procedures for setting 16 bit regs 144 | // is handled by the compiler 145 | OCR1B = nticks; 146 | 147 | // Enable interrupt 148 | TIMSK1 |= _BV(OCIE1B); 149 | } 150 | */ 151 | 152 | #endif /* VirtualWire_Config_h */ -------------------------------------------------------------------------------- /utility/u8g_pb.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_pb.c 4 | 5 | common procedures for the page buffer 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2011, olikraus@gmail.com 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this list 16 | of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, this 19 | list of conditions and the following disclaimer in the documentation and/or other 20 | materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | */ 38 | 39 | #include "u8g.h" 40 | 41 | void u8g_pb_Clear(u8g_pb_t *b) 42 | { 43 | uint8_t *ptr = (uint8_t *)b->buf; 44 | uint8_t *end_ptr = ptr; 45 | end_ptr += b->width; 46 | do 47 | { 48 | *ptr++ = 0; 49 | } while( ptr != end_ptr ); 50 | } 51 | 52 | /* the following procedure does not work. why? Can be checked with descpic */ 53 | /* 54 | void u8g_pb_Clear(u8g_pb_t *b) 55 | { 56 | uint8_t *ptr = (uint8_t *)b->buf; 57 | uint8_t cnt = b->width; 58 | do 59 | { 60 | *ptr++ = 0; 61 | cnt--; 62 | } while( cnt != 0 ); 63 | } 64 | */ 65 | 66 | /* 67 | intersection assumptions: 68 | a1 <= a2 is always true 69 | */ 70 | /* 71 | minimized version 72 | ---1----0 1 b1 <= a2 && b1 > b2 73 | -----1--0 1 b2 >= a1 && b1 > b2 74 | ---1-1--- 1 b1 <= a2 && b2 >= a1 75 | */ 76 | /* 77 | uint8_t u8g_pb8v1_IsYIntersection___Old(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1) 78 | { 79 | uint8_t c0, c1, c; 80 | c0 = v0 <= b->p.page_y1; 81 | c1 = v1 >= b->p.page_y0; 82 | c = v0 > v1; 83 | if ( c0 && c1 ) return 1; 84 | if ( c0 && c ) return 1; 85 | if ( c1 && c ) return 1; 86 | return 0; 87 | } 88 | */ 89 | 90 | uint8_t u8g_pb_IsYIntersection(u8g_pb_t *pb, u8g_uint_t v0, u8g_uint_t v1) 91 | { 92 | uint8_t c1, c2, c3, tmp; 93 | c1 = v0 <= pb->p.page_y1; 94 | c2 = v1 >= pb->p.page_y0; 95 | c3 = v0 > v1; 96 | /* 97 | if ( c1 && c2 ) 98 | return 1; 99 | if ( c1 && c3 ) 100 | return 1; 101 | if ( c2 && c3 ) 102 | return 1; 103 | return 0; 104 | */ 105 | 106 | tmp = c1; 107 | c1 &= c2; 108 | c2 &= c3; 109 | c3 &= tmp; 110 | c1 |= c2; 111 | c1 |= c3; 112 | return c1 & 1; 113 | } 114 | 115 | 116 | uint8_t u8g_pb_IsXIntersection(u8g_pb_t *b, u8g_uint_t v0, u8g_uint_t v1) 117 | { 118 | uint8_t /*c0, c1, */ c2, c3; 119 | /* 120 | conditions: b->p.page_y0 < b->p.page_y1 121 | there are no restriction on v0 and v1. If v0 > v1, then warp around unsigned is assumed 122 | */ 123 | /* 124 | c0 = v0 < 0; 125 | c1 = v1 < 0; 126 | */ 127 | c2 = v0 > b->width; 128 | c3 = v1 > b->width; 129 | /*if ( c0 && c1 ) return 0;*/ 130 | if ( c2 && c3 ) return 0; 131 | /*if ( c1 && c2 ) return 0;*/ 132 | return 1; 133 | } 134 | 135 | uint8_t u8g_pb_IsIntersection(u8g_pb_t *pb, u8g_dev_arg_bbx_t *bbx) 136 | { 137 | u8g_uint_t tmp; 138 | 139 | tmp = bbx->y; 140 | tmp += bbx->h; 141 | tmp--; 142 | 143 | if ( u8g_pb_IsYIntersection(pb, bbx->y, tmp) == 0 ) 144 | return 0; 145 | 146 | /* maybe this one can be skiped... probability is very high to have an intersection, so it would be ok to always return 1 */ 147 | tmp = bbx->x; 148 | tmp += bbx->w; 149 | tmp--; 150 | 151 | return u8g_pb_IsXIntersection(pb, bbx->x, tmp); 152 | } 153 | 154 | void u8g_pb_GetPageBox(u8g_pb_t *pb, u8g_box_t *box) 155 | { 156 | box->x0 = 0; 157 | box->y0 = pb->p.page_y0; 158 | box->x1 = pb->width; 159 | box->x1--; 160 | box->y1 = pb->p.page_y1; 161 | } 162 | 163 | 164 | uint8_t u8g_pb_Is8PixelVisible(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 165 | { 166 | u8g_uint_t v0, v1; 167 | v0 = arg_pixel->y; 168 | v1 = v0; 169 | switch( arg_pixel->dir ) 170 | { 171 | case 0: 172 | break; 173 | case 1: 174 | v1 += 8; /* this is independent from the page height */ 175 | break; 176 | case 2: 177 | break; 178 | case 3: 179 | v0 -= 8; 180 | break; 181 | } 182 | return u8g_pb_IsYIntersection(b, v0, v1); 183 | } 184 | 185 | 186 | 187 | uint8_t u8g_pb_WriteBuffer(u8g_pb_t *b, u8g_t *u8g, u8g_dev_t *dev) 188 | { 189 | return u8g_WriteSequence(u8g, dev, b->width, b->buf); 190 | } 191 | 192 | -------------------------------------------------------------------------------- /utility/u8g_com_atmega_hw_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_atmega_hw_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2012, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | Assumes, that 36 | MOSI is at PORTB, Pin 3 37 | and 38 | SCK is at PORTB, Pin 5 39 | 40 | Update for ATOMIC operation done (01 Jun 2013) 41 | U8G_ATOMIC_OR(ptr, val) 42 | U8G_ATOMIC_AND(ptr, val) 43 | U8G_ATOMIC_START() 44 | U8G_ATOMIC_END() 45 | 46 | 47 | 48 | */ 49 | 50 | #include "u8g.h" 51 | 52 | 53 | #if defined(__AVR__) 54 | #define U8G_ATMEGA_HW_SPI 55 | 56 | /* remove the definition for attiny */ 57 | #if __AVR_ARCH__ == 2 58 | #undef U8G_ATMEGA_HW_SPI 59 | #endif 60 | #if __AVR_ARCH__ == 25 61 | #undef U8G_ATMEGA_HW_SPI 62 | #endif 63 | #endif 64 | 65 | 66 | #if defined(U8G_ATMEGA_HW_SPI) 67 | 68 | #include 69 | #include 70 | 71 | 72 | static uint8_t u8g_atmega_spi_out(uint8_t data) 73 | { 74 | /* unsigned char x = 100; */ 75 | /* send data */ 76 | SPDR = data; 77 | /* wait for transmission */ 78 | while (!(SPSR & (1< 0 ) 157 | { 158 | u8g_atmega_spi_out(*ptr++); 159 | arg_val--; 160 | } 161 | } 162 | break; 163 | case U8G_COM_MSG_WRITE_SEQ_P: 164 | { 165 | register uint8_t *ptr = arg_ptr; 166 | while( arg_val > 0 ) 167 | { 168 | u8g_atmega_spi_out(u8g_pgm_read(ptr)); 169 | ptr++; 170 | arg_val--; 171 | } 172 | } 173 | break; 174 | } 175 | return 1; 176 | } 177 | 178 | #else 179 | 180 | uint8_t u8g_com_atmega_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 181 | { 182 | return 1; 183 | } 184 | 185 | #endif 186 | 187 | 188 | -------------------------------------------------------------------------------- /utility/u8g_com_api.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_api.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | */ 36 | 37 | #include "u8g.h" 38 | 39 | uint8_t u8g_InitCom(u8g_t *u8g, u8g_dev_t *dev, uint8_t clk_cycle_time) 40 | { 41 | return dev->com_fn(u8g, U8G_COM_MSG_INIT, clk_cycle_time, NULL); 42 | } 43 | 44 | void u8g_StopCom(u8g_t *u8g, u8g_dev_t *dev) 45 | { 46 | dev->com_fn(u8g, U8G_COM_MSG_STOP, 0, NULL); 47 | } 48 | 49 | /* cs contains the chip number, which should be enabled */ 50 | void u8g_SetChipSelect(u8g_t *u8g, u8g_dev_t *dev, uint8_t cs) 51 | { 52 | dev->com_fn(u8g, U8G_COM_MSG_CHIP_SELECT, cs, NULL); 53 | } 54 | 55 | void u8g_SetResetLow(u8g_t *u8g, u8g_dev_t *dev) 56 | { 57 | dev->com_fn(u8g, U8G_COM_MSG_RESET, 0, NULL); 58 | } 59 | 60 | void u8g_SetResetHigh(u8g_t *u8g, u8g_dev_t *dev) 61 | { 62 | dev->com_fn(u8g, U8G_COM_MSG_RESET, 1, NULL); 63 | } 64 | 65 | 66 | void u8g_SetAddress(u8g_t *u8g, u8g_dev_t *dev, uint8_t address) 67 | { 68 | dev->com_fn(u8g, U8G_COM_MSG_ADDRESS, address, NULL); 69 | } 70 | 71 | uint8_t u8g_WriteByte(u8g_t *u8g, u8g_dev_t *dev, uint8_t val) 72 | { 73 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_BYTE, val, NULL); 74 | } 75 | 76 | uint8_t u8g_WriteSequence(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, uint8_t *seq) 77 | { 78 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ, cnt, seq); 79 | } 80 | 81 | uint8_t u8g_WriteSequenceP(u8g_t *u8g, u8g_dev_t *dev, uint8_t cnt, const uint8_t *seq) 82 | { 83 | return dev->com_fn(u8g, U8G_COM_MSG_WRITE_SEQ_P, cnt, (void *)seq); 84 | } 85 | 86 | /* 87 | sequence := { direct_value | escape_sequence } 88 | direct_value := 0..254 89 | escape_sequence := value_255 | sequence_end | delay | adr | cs | not_used 90 | value_255 := 255 255 91 | sequence_end = 255 254 92 | delay := 255 0..127 93 | adr := 255 0x0e0 .. 0x0ef 94 | cs := 255 0x0d0 .. 0x0df 95 | not_used := 255 101..254 96 | 97 | #define U8G_ESC_DLY(x) 255, ((x) & 0x7f) 98 | #define U8G_ESC_CS(x) 255, (0xd0 | ((x)&0x0f)) 99 | #define U8G_ESC_ADR(x) 255, (0xe0 | ((x)&0x0f)) 100 | #define U8G_ESC_VCC(x) 255, (0xbe | ((x)&0x01)) 101 | #define U8G_ESC_END 255, 254 102 | #define U8G_ESC_255 255, 255 103 | #define U8G_ESC_RST(x) 255, (0xc0 | ((x)&0x0f)) 104 | 105 | */ 106 | uint8_t u8g_WriteEscSeqP(u8g_t *u8g, u8g_dev_t *dev, const uint8_t *esc_seq) 107 | { 108 | uint8_t is_escape = 0; 109 | uint8_t value; 110 | for(;;) 111 | { 112 | value = u8g_pgm_read(esc_seq); 113 | if ( is_escape == 0 ) 114 | { 115 | if ( value != 255 ) 116 | { 117 | if ( u8g_WriteByte(u8g, dev, value) == 0 ) 118 | return 0; 119 | } 120 | else 121 | { 122 | is_escape = 1; 123 | } 124 | } 125 | else 126 | { 127 | if ( value == 255 ) 128 | { 129 | if ( u8g_WriteByte(u8g, dev, value) == 0 ) 130 | return 0; 131 | } 132 | else if ( value == 254 ) 133 | { 134 | break; 135 | } 136 | else if ( value >= 0x0f0 ) 137 | { 138 | /* not yet used, do nothing */ 139 | } 140 | else if ( value >= 0xe0 ) 141 | { 142 | u8g_SetAddress(u8g, dev, value & 0x0f); 143 | } 144 | else if ( value >= 0xd0 ) 145 | { 146 | u8g_SetChipSelect(u8g, dev, value & 0x0f); 147 | } 148 | else if ( value >= 0xc0 ) 149 | { 150 | u8g_SetResetLow(u8g, dev); 151 | value &= 0x0f; 152 | value <<= 4; 153 | value+=2; 154 | u8g_Delay(value); 155 | u8g_SetResetHigh(u8g, dev); 156 | u8g_Delay(value); 157 | } 158 | else if ( value >= 0xbe ) 159 | { 160 | /* not yet implemented */ 161 | /* u8g_SetVCC(u8g, dev, value & 0x01); */ 162 | } 163 | else if ( value <= 127 ) 164 | { 165 | u8g_Delay(value); 166 | } 167 | is_escape = 0; 168 | } 169 | esc_seq++; 170 | } 171 | return 1; 172 | } 173 | 174 | -------------------------------------------------------------------------------- /utility/u8g_com_arduino_attiny85_hw_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_arduino_ATtiny85_std_hw_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | */ 35 | 36 | // Uses code from tinySPI Written by Nick Gammon 37 | // March 2013 38 | 39 | // ATMEL ATTINY45 / ARDUINO pin mappings 40 | // 41 | // +-\/-+ 42 | // RESET Ain0 (D 5) PB5 1| |8 Vcc 43 | // CLK1 Ain3 (D 3) PB3 2| |7 PB2 (D 2) Ain1 SCK / USCK / SCL 44 | // CLK0 Ain2 (D 4) PB4 3| |6 PB1 (D 1) pwm1 MISO / DO 45 | // GND 4| |5 PB0 (D 0) pwm0 MOSI / DI / SDA 46 | // +----+ 47 | 48 | 49 | #include "u8g.h" 50 | 51 | 52 | #if defined(ARDUINO) && defined(__AVR_ATtiny85__) 53 | 54 | #if ARDUINO < 100 55 | #include 56 | #else 57 | #include 58 | #endif 59 | 60 | const byte DI = 0; // D0, pin 5 Data In 61 | const byte DO = 1; // D1, pin 6 Data Out (this is *not* MOSI) 62 | const byte USCK = 2; // D2, pin 7 Universal Serial Interface clock 63 | 64 | uint8_t u8g_arduino_ATtiny85_spi_out(uint8_t val) 65 | { 66 | USIDR = val; // byte to output 67 | USISR = _BV (USIOIF); // clear Counter Overflow Interrupt Flag, set count to zero 68 | do 69 | { 70 | USICR = _BV (USIWM0) // 3-wire mode 71 | | _BV (USICS1) | _BV (USICLK) // Software clock strobe 72 | | _BV (USITC); // Toggle Clock Port Pin 73 | } 74 | while ((USISR & _BV (USIOIF)) == 0); // until Counter Overflow Interrupt Flag set 75 | 76 | return USIDR; // return read data 77 | } 78 | 79 | uint8_t u8g_com_arduino_ATtiny85_std_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 80 | { 81 | switch(msg) 82 | { 83 | case U8G_COM_MSG_INIT: 84 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); // ensure SS stays high until needed 85 | pinMode (USCK, OUTPUT); 86 | pinMode (DO, OUTPUT); 87 | pinMode (u8g->pin_list[U8G_PI_CS], OUTPUT); 88 | pinMode (u8g->pin_list[U8G_PI_A0], OUTPUT); 89 | USICR = _BV (USIWM0); // 3-wire mode 90 | u8g_MicroDelay(); 91 | break; 92 | 93 | case U8G_COM_MSG_STOP: 94 | break; 95 | 96 | case U8G_COM_MSG_RESET: 97 | if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE ) 98 | u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); 99 | break; 100 | 101 | case U8G_COM_MSG_CHIP_SELECT: 102 | if ( arg_val == 0 ) 103 | { 104 | /* disable */ 105 | u8g_MicroDelay(); 106 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, HIGH); 107 | u8g_MicroDelay(); 108 | } 109 | else 110 | { 111 | /* enable */ 112 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS, LOW); 113 | u8g_MicroDelay(); 114 | } 115 | break; 116 | 117 | case U8G_COM_MSG_WRITE_BYTE: 118 | u8g_arduino_ATtiny85_spi_out(arg_val); 119 | u8g_MicroDelay(); 120 | break; 121 | 122 | case U8G_COM_MSG_WRITE_SEQ: 123 | { 124 | register uint8_t *ptr = arg_ptr; 125 | while( arg_val > 0 ) 126 | { 127 | u8g_arduino_ATtiny85_spi_out(*ptr++); 128 | arg_val--; 129 | } 130 | } 131 | break; 132 | 133 | case U8G_COM_MSG_WRITE_SEQ_P: 134 | { 135 | register uint8_t *ptr = arg_ptr; 136 | while( arg_val > 0 ) 137 | { 138 | u8g_arduino_ATtiny85_spi_out(u8g_pgm_read(ptr)); 139 | ptr++; 140 | arg_val--; 141 | } 142 | } 143 | break; 144 | 145 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 146 | u8g_com_arduino_digital_write(u8g, U8G_PI_A0, arg_val); 147 | u8g_MicroDelay(); 148 | break; 149 | } 150 | return 1; 151 | } 152 | 153 | #else /* ARDUINO */ 154 | 155 | uint8_t u8g_com_arduino_ATtiny85_std_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 156 | { 157 | return 1; 158 | } 159 | 160 | #endif /* ARDUINO */ -------------------------------------------------------------------------------- /utility/u8g_pbxh16.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_pbxh16.c 4 | 5 | x lines per page, horizontal, 16 bits per pixel (hi color modes) 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2013, olikraus@gmail.com 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this list 16 | of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, this 19 | list of conditions and the following disclaimer in the documentation and/or other 20 | materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | struct _u8g_pb_t 38 | { 39 | u8g_page_t p; 40 | u8g_uint_t width; 41 | void *buf; 42 | }; 43 | typedef struct _u8g_pb_t u8g_pb_t; 44 | 45 | 46 | uint8_t u8g_index_color_xh16_buf[2*WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ; 47 | u8g_pb_t u8g_index_color_xh16_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_index_color_xh16_buf}; 48 | u8g_dev_t name = { dev_fn, &u8g_index_color_xh16_pb , com_fn } 49 | 50 | */ 51 | 52 | #include "u8g.h" 53 | 54 | /* 55 | #define WIDTH_BITS 7 56 | #define WIDTH (1<buf; 64 | uint8_t *end_ptr = ptr; 65 | uint8_t cnt = b->p.page_height; 66 | do 67 | { 68 | end_ptr += b->width*2; 69 | cnt--; 70 | } while( cnt > 0 ); 71 | do 72 | { 73 | *ptr++ = 0; 74 | } while( ptr != end_ptr ); 75 | } 76 | 77 | 78 | void u8g_pbxh16_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) 79 | { 80 | b->buf = buf; 81 | b->width = width; 82 | u8g_pbxh16_Clear(b); 83 | } 84 | 85 | static void u8g_pbxh16_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t low, uint8_t high) 86 | { 87 | uint16_t tmp; 88 | uint8_t *ptr = b->buf; 89 | y -= b->p.page_y0; 90 | tmp = y; 91 | tmp *= b->width; 92 | tmp += x; 93 | tmp <<= 1; 94 | ptr += tmp; 95 | *ptr = low; 96 | ptr++; 97 | *ptr = high; 98 | } 99 | 100 | void u8g_pbxh16_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) 101 | { 102 | if ( arg_pixel->y < b->p.page_y0 ) 103 | return; 104 | if ( arg_pixel->y > b->p.page_y1 ) 105 | return; 106 | if ( arg_pixel->x >= b->width ) 107 | return; 108 | u8g_pbxh16_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color, arg_pixel->hi_color); 109 | } 110 | 111 | 112 | void u8g_pbxh16_Set8Pixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 113 | { 114 | register uint8_t pixel = arg_pixel->pixel; 115 | u8g_uint_t dx = 0; 116 | u8g_uint_t dy = 0; 117 | 118 | switch( arg_pixel->dir ) 119 | { 120 | case 0: dx++; break; 121 | case 1: dy++; break; 122 | case 2: dx--; break; 123 | case 3: dy--; break; 124 | } 125 | 126 | do 127 | { 128 | if ( pixel & 128 ) 129 | u8g_pbxh16_SetPixel(b, arg_pixel); 130 | arg_pixel->x += dx; 131 | arg_pixel->y += dy; 132 | pixel <<= 1; 133 | } while( pixel != 0 ); 134 | } 135 | 136 | 137 | uint8_t u8g_dev_pbxh16_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 138 | { 139 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 140 | switch(msg) 141 | { 142 | case U8G_DEV_MSG_SET_8PIXEL: 143 | if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) 144 | u8g_pbxh16_Set8Pixel(pb, (u8g_dev_arg_pixel_t *)arg); 145 | break; 146 | case U8G_DEV_MSG_SET_PIXEL: 147 | u8g_pbxh16_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 148 | break; 149 | case U8G_DEV_MSG_INIT: 150 | break; 151 | case U8G_DEV_MSG_STOP: 152 | break; 153 | case U8G_DEV_MSG_PAGE_FIRST: 154 | u8g_pbxh16_Clear(pb); 155 | u8g_page_First(&(pb->p)); 156 | break; 157 | case U8G_DEV_MSG_PAGE_NEXT: 158 | if ( u8g_page_Next(&(pb->p)) == 0 ) 159 | return 0; 160 | u8g_pbxh16_Clear(pb); 161 | break; 162 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 163 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 164 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 165 | #endif 166 | case U8G_DEV_MSG_GET_PAGE_BOX: 167 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 168 | break; 169 | case U8G_DEV_MSG_GET_WIDTH: 170 | *((u8g_uint_t *)arg) = pb->width; 171 | break; 172 | case U8G_DEV_MSG_GET_HEIGHT: 173 | *((u8g_uint_t *)arg) = pb->p.total_height; 174 | break; 175 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 176 | break; 177 | case U8G_DEV_MSG_SET_XY_CB: 178 | break; 179 | case U8G_DEV_MSG_GET_MODE: 180 | return U8G_MODE_HICOLOR; 181 | } 182 | return 1; 183 | } 184 | 185 | -------------------------------------------------------------------------------- /utility/u8g_com_atmega_st7920_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_atmega_st7920_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | A special SPI interface for ST7920 controller 35 | 36 | */ 37 | 38 | #include "u8g.h" 39 | 40 | #if defined(__AVR__) 41 | 42 | static void u8g_atmega_st7920_sw_spi_shift_out(u8g_t *u8g, uint8_t val) U8G_NOINLINE; 43 | static void u8g_atmega_st7920_sw_spi_shift_out(u8g_t *u8g, uint8_t val) 44 | { 45 | uint8_t i = 8; 46 | do 47 | { 48 | u8g_SetPILevel(u8g, U8G_PI_MOSI, val & 128 ); 49 | val <<= 1; 50 | u8g_SetPILevel(u8g, U8G_PI_SCK, 1 ); 51 | u8g_MicroDelay(); /* 15 Aug 2012: added for high speed uC */ 52 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 53 | u8g_MicroDelay(); /* 15 Aug 2012: added for high speed uC */ 54 | i--; 55 | } while( i != 0 ); 56 | } 57 | 58 | static void u8g_com_atmega_st7920_write_byte(u8g_t *u8g, uint8_t rs, uint8_t val) U8G_NOINLINE; 59 | static void u8g_com_atmega_st7920_write_byte(u8g_t *u8g, uint8_t rs, uint8_t val) 60 | { 61 | uint8_t i; 62 | 63 | if ( rs == 0 ) 64 | { 65 | /* command */ 66 | u8g_atmega_st7920_sw_spi_shift_out(u8g, 0x0f8); 67 | } 68 | else if ( rs == 1 ) 69 | { 70 | /* data */ 71 | u8g_atmega_st7920_sw_spi_shift_out(u8g, 0x0fa); 72 | } 73 | 74 | u8g_atmega_st7920_sw_spi_shift_out(u8g, val & 0x0f0); 75 | u8g_atmega_st7920_sw_spi_shift_out(u8g, val << 4); 76 | 77 | for( i = 0; i < 4; i++ ) 78 | u8g_10MicroDelay(); 79 | } 80 | 81 | 82 | uint8_t u8g_com_atmega_st7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 83 | { 84 | switch(msg) 85 | { 86 | case U8G_COM_MSG_INIT: 87 | u8g_SetPIOutput(u8g, U8G_PI_SCK); 88 | u8g_SetPIOutput(u8g, U8G_PI_MOSI); 89 | /* u8g_SetPIOutput(u8g, U8G_PI_A0); */ 90 | u8g_SetPIOutput(u8g, U8G_PI_CS); 91 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 92 | 93 | u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); 94 | u8g_SetPILevel(u8g, U8G_PI_MOSI, 0 ); 95 | u8g_SetPILevel(u8g, U8G_PI_CS, 0 ); 96 | /* u8g_SetPILevel(u8g, U8G_PI_A0, 0); */ 97 | 98 | u8g->pin_list[U8G_PI_A0_STATE] = 0; /* inital RS state: command mode */ 99 | break; 100 | 101 | case U8G_COM_MSG_STOP: 102 | break; 103 | 104 | case U8G_COM_MSG_RESET: 105 | u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 106 | break; 107 | 108 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 109 | u8g->pin_list[U8G_PI_A0_STATE] = arg_val; 110 | break; 111 | 112 | case U8G_COM_MSG_CHIP_SELECT: 113 | if ( arg_val == 0 ) 114 | { 115 | /* disable, note: the st7920 has an active high chip select */ 116 | u8g_SetPILevel(u8g, U8G_PI_CS, 0); 117 | } 118 | else 119 | { 120 | /* u8g_SetPILevel(u8g, U8G_PI_SCK, 0 ); */ 121 | /* enable */ 122 | u8g_SetPILevel(u8g, U8G_PI_CS, 1); /* CS = 1 (high active) */ 123 | } 124 | break; 125 | 126 | 127 | case U8G_COM_MSG_WRITE_BYTE: 128 | u8g_com_atmega_st7920_write_byte(u8g, u8g->pin_list[U8G_PI_A0_STATE], arg_val); 129 | u8g->pin_list[U8G_PI_A0_STATE] = 2; 130 | break; 131 | 132 | case U8G_COM_MSG_WRITE_SEQ: 133 | { 134 | register uint8_t *ptr = arg_ptr; 135 | while( arg_val > 0 ) 136 | { 137 | u8g_com_atmega_st7920_write_byte(u8g, u8g->pin_list[U8G_PI_A0_STATE], *ptr++); 138 | u8g->pin_list[U8G_PI_A0_STATE] = 2; 139 | arg_val--; 140 | } 141 | } 142 | break; 143 | 144 | case U8G_COM_MSG_WRITE_SEQ_P: 145 | { 146 | register uint8_t *ptr = arg_ptr; 147 | while( arg_val > 0 ) 148 | { 149 | u8g_com_atmega_st7920_write_byte(u8g, u8g->pin_list[U8G_PI_A0_STATE], u8g_pgm_read(ptr)); 150 | u8g->pin_list[U8G_PI_A0_STATE] = 2; 151 | ptr++; 152 | arg_val--; 153 | } 154 | } 155 | break; 156 | } 157 | return 1; 158 | } 159 | 160 | #else 161 | 162 | 163 | uint8_t u8g_com_atmega_st7920_sw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 164 | { 165 | return 1; 166 | } 167 | 168 | 169 | #endif 170 | 171 | -------------------------------------------------------------------------------- /utility/u8g_pb8h8.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_pb8h8.c 4 | 5 | 8 lines per page, horizontal, 8 bits per pixel 6 | (22 May 2013: might also support any number of lines --> needs to be checked) 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2012, olikraus@gmail.com 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright notice, this list 17 | of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this 20 | list of conditions and the following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | 38 | struct _u8g_pb_t 39 | { 40 | u8g_page_t p; 41 | u8g_uint_t width; 42 | void *buf; 43 | }; 44 | typedef struct _u8g_pb_t u8g_pb_t; 45 | 46 | 47 | uint8_t u8g_index_color_8h8_buf[WIDTH*PAGE_HEIGHT] U8G_NOCOMMON ; 48 | u8g_pb_t u8g_index_color_8h8_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, u8g_index_color_8h8_buff}; 49 | u8g_dev_t name = { dev_fn, &u8g_index_color_8h8_pb, com_fn } 50 | 51 | */ 52 | 53 | #include "u8g.h" 54 | 55 | /* 56 | #define WIDTH_BITS 7 57 | #define WIDTH (1<buf; 65 | uint8_t *end_ptr = ptr; 66 | uint8_t cnt = b->p.page_height; 67 | end_ptr += b->width*cnt; 68 | /* 69 | do 70 | { 71 | end_ptr += b->width; 72 | cnt--; 73 | } while( cnt > 0 ); 74 | */ 75 | do 76 | { 77 | *ptr++ = 0; 78 | } while( ptr != end_ptr ); 79 | } 80 | 81 | 82 | void u8g_pb8h8_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) 83 | { 84 | b->buf = buf; 85 | b->width = width; 86 | u8g_pb8h8_Clear(b); 87 | } 88 | 89 | static void u8g_pb8h8_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) 90 | { 91 | uint16_t tmp; 92 | uint8_t *ptr = b->buf; 93 | y -= b->p.page_y0; 94 | tmp = y; 95 | tmp *= b->width; 96 | tmp += x; 97 | ptr += tmp; 98 | *ptr = color_index; 99 | } 100 | 101 | void u8g_pb8h8_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) 102 | { 103 | if ( arg_pixel->y < b->p.page_y0 ) 104 | return; 105 | if ( arg_pixel->y > b->p.page_y1 ) 106 | return; 107 | if ( arg_pixel->x >= b->width ) 108 | return; 109 | u8g_pb8h8_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 110 | } 111 | 112 | 113 | void u8g_pb8h8_Set8Pixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 114 | { 115 | register uint8_t pixel = arg_pixel->pixel; 116 | u8g_uint_t dx = 0; 117 | u8g_uint_t dy = 0; 118 | 119 | switch( arg_pixel->dir ) 120 | { 121 | case 0: dx++; break; 122 | case 1: dy++; break; 123 | case 2: dx--; break; 124 | case 3: dy--; break; 125 | } 126 | 127 | do 128 | { 129 | if ( pixel & 128 ) 130 | u8g_pb8h8_SetPixel(b, arg_pixel); 131 | arg_pixel->x += dx; 132 | arg_pixel->y += dy; 133 | pixel <<= 1; 134 | } while( pixel != 0 ); 135 | } 136 | 137 | 138 | uint8_t u8g_dev_pb8h8_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 139 | { 140 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 141 | switch(msg) 142 | { 143 | case U8G_DEV_MSG_SET_8PIXEL: 144 | if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) 145 | u8g_pb8h8_Set8Pixel(pb, (u8g_dev_arg_pixel_t *)arg); 146 | break; 147 | case U8G_DEV_MSG_SET_PIXEL: 148 | u8g_pb8h8_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 149 | break; 150 | case U8G_DEV_MSG_INIT: 151 | break; 152 | case U8G_DEV_MSG_STOP: 153 | break; 154 | case U8G_DEV_MSG_PAGE_FIRST: 155 | u8g_pb8h8_Clear(pb); 156 | u8g_page_First(&(pb->p)); 157 | break; 158 | case U8G_DEV_MSG_PAGE_NEXT: 159 | if ( u8g_page_Next(&(pb->p)) == 0 ) 160 | return 0; 161 | u8g_pb8h8_Clear(pb); 162 | break; 163 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 164 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 165 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 166 | #endif 167 | case U8G_DEV_MSG_GET_PAGE_BOX: 168 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 169 | break; 170 | case U8G_DEV_MSG_GET_WIDTH: 171 | *((u8g_uint_t *)arg) = pb->width; 172 | break; 173 | case U8G_DEV_MSG_GET_HEIGHT: 174 | *((u8g_uint_t *)arg) = pb->p.total_height; 175 | break; 176 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 177 | break; 178 | case U8G_DEV_MSG_SET_XY_CB: 179 | break; 180 | case U8G_DEV_MSG_GET_MODE: 181 | return U8G_MODE_R3G3B2; 182 | } 183 | return 1; 184 | } 185 | 186 | -------------------------------------------------------------------------------- /utility/u8g_pb8v1.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_pb8v1.c 4 | 5 | 8bit height monochrom (1 bit) page buffer 6 | byte has vertical orientation 7 | 8 | Universal 8bit Graphics Library 9 | 10 | Copyright (c) 2011, olikraus@gmail.com 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright notice, this list 17 | of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this 20 | list of conditions and the following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | 38 | */ 39 | 40 | #include "u8g.h" 41 | #include 42 | 43 | 44 | void u8g_pb8v1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) U8G_NOINLINE; 45 | void u8g_pb8v1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) U8G_NOINLINE; 46 | void u8g_pb8v1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) U8G_NOINLINE ; 47 | void u8g_pb8v1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) U8G_NOINLINE; 48 | 49 | /* Obsolete, usually set by the init of the structure */ 50 | void u8g_pb8v1_Init(u8g_pb_t *b, void *buf, u8g_uint_t width) 51 | { 52 | b->buf = buf; 53 | b->width = width; 54 | u8g_pb_Clear(b); 55 | } 56 | 57 | void u8g_pb8v1_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) 58 | { 59 | register uint8_t mask; 60 | uint8_t *ptr = b->buf; 61 | 62 | y -= b->p.page_y0; 63 | mask = 1; 64 | y &= 0x07; 65 | mask <<= y; 66 | ptr += x; 67 | if ( color_index ) 68 | { 69 | *ptr |= mask; 70 | } 71 | else 72 | { 73 | mask ^=0xff; 74 | *ptr &= mask; 75 | } 76 | } 77 | 78 | 79 | void u8g_pb8v1_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) 80 | { 81 | if ( arg_pixel->y < b->p.page_y0 ) 82 | return; 83 | if ( arg_pixel->y > b->p.page_y1 ) 84 | return; 85 | if ( arg_pixel->x >= b->width ) 86 | return; 87 | u8g_pb8v1_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 88 | } 89 | 90 | void u8g_pb8v1_Set8PixelStd(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 91 | { 92 | register uint8_t pixel = arg_pixel->pixel; 93 | do 94 | { 95 | if ( pixel & 128 ) 96 | { 97 | u8g_pb8v1_SetPixel(b, arg_pixel); 98 | } 99 | switch( arg_pixel->dir ) 100 | { 101 | case 0: arg_pixel->x++; break; 102 | case 1: arg_pixel->y++; break; 103 | case 2: arg_pixel->x--; break; 104 | case 3: arg_pixel->y--; break; 105 | } 106 | pixel <<= 1; 107 | } while( pixel != 0 ); 108 | } 109 | 110 | 111 | void u8g_pb8v1_Set8PixelOpt2(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 112 | { 113 | register uint8_t pixel = arg_pixel->pixel; 114 | u8g_uint_t dx = 0; 115 | u8g_uint_t dy = 0; 116 | 117 | switch( arg_pixel->dir ) 118 | { 119 | case 0: dx++; break; 120 | case 1: dy++; break; 121 | case 2: dx--; break; 122 | case 3: dy--; break; 123 | } 124 | 125 | do 126 | { 127 | if ( pixel & 128 ) 128 | u8g_pb8v1_SetPixel(b, arg_pixel); 129 | arg_pixel->x += dx; 130 | arg_pixel->y += dy; 131 | pixel <<= 1; 132 | } while( pixel != 0 ); 133 | 134 | } 135 | 136 | uint8_t u8g_dev_pb8v1_base_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 137 | { 138 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 139 | switch(msg) 140 | { 141 | case U8G_DEV_MSG_SET_8PIXEL: 142 | if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) 143 | u8g_pb8v1_Set8PixelOpt2(pb, (u8g_dev_arg_pixel_t *)arg); 144 | break; 145 | case U8G_DEV_MSG_SET_PIXEL: 146 | u8g_pb8v1_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 147 | break; 148 | case U8G_DEV_MSG_INIT: 149 | break; 150 | case U8G_DEV_MSG_STOP: 151 | break; 152 | case U8G_DEV_MSG_PAGE_FIRST: 153 | u8g_pb_Clear(pb); 154 | u8g_page_First(&(pb->p)); 155 | break; 156 | case U8G_DEV_MSG_PAGE_NEXT: 157 | if ( u8g_page_Next(&(pb->p)) == 0 ) 158 | return 0; 159 | u8g_pb_Clear(pb); 160 | break; 161 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 162 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 163 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 164 | #endif 165 | case U8G_DEV_MSG_GET_PAGE_BOX: 166 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 167 | break; 168 | case U8G_DEV_MSG_GET_WIDTH: 169 | *((u8g_uint_t *)arg) = pb->width; 170 | break; 171 | case U8G_DEV_MSG_GET_HEIGHT: 172 | *((u8g_uint_t *)arg) = pb->p.total_height; 173 | break; 174 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 175 | break; 176 | case U8G_DEV_MSG_SET_XY_CB: 177 | break; 178 | case U8G_DEV_MSG_GET_MODE: 179 | return U8G_MODE_BW; 180 | } 181 | return 1; 182 | } 183 | 184 | 185 | -------------------------------------------------------------------------------- /utility/u8g_com_arduino_port_d_wr.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_arduino_port_d_wr.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2011, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | Assumes PORTD for 8 bit data transfer. 36 | EN is assumed to be a low active write signal (WR) 37 | 38 | ILI9325D_320x240 from iteadstudio.com 39 | RS=19, WR=18, CS=17, RST=16 40 | 41 | 42 | u8g_Init8Bit(u8g, dev, d0, d1, d2, d3, d4, d5, d6, d7, en, cs1, cs2, di, rw, reset) 43 | u8g_Init8Bit(u8g, dev, 8, 9, 10, 11, 4, 5, 6, 7, 18, 14, 15, 17, 16, U8G_PIN_NONE) 44 | 45 | 46 | Update for ATOMIC operation done (01 Jun 2013) 47 | U8G_ATOMIC_OR(ptr, val) 48 | U8G_ATOMIC_AND(ptr, val) 49 | U8G_ATOMIC_START(); 50 | U8G_ATOMIC_END(); 51 | 52 | */ 53 | 54 | #include "u8g.h" 55 | 56 | 57 | #if defined(ARDUINO) && defined(PORTD) 58 | 59 | #if ARDUINO < 100 60 | #include 61 | #else 62 | #include 63 | #endif 64 | 65 | 66 | 67 | 68 | 69 | 70 | static void u8g_com_arduino_port_d_8bit_wr(u8g_t *u8g, uint8_t val) 71 | { 72 | PORTD = val; 73 | 74 | /* WR cycle time must be 1 micro second, digitalWrite is slow enough to do this */ 75 | u8g_com_arduino_digital_write(u8g, U8G_PI_EN, LOW); 76 | u8g_com_arduino_digital_write(u8g, U8G_PI_EN, HIGH); 77 | } 78 | 79 | 80 | uint8_t u8g_com_arduino_port_d_wr_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 81 | { 82 | 83 | switch(msg) 84 | { 85 | case U8G_COM_MSG_INIT: 86 | 87 | #ifdef UCSR0B 88 | UCSR0B = 0; // disable USART 0 89 | #endif 90 | U8G_ATOMIC_START(); 91 | DDRD = 0x0ff; 92 | PORTD = 0x0ff; 93 | U8G_ATOMIC_END(); 94 | 95 | /* setup the RW pin as output and force it to low */ 96 | if ( u8g->pin_list[U8G_PI_RW] != U8G_PIN_NONE ) 97 | { 98 | pinMode(u8g->pin_list[U8G_PI_RW], OUTPUT); 99 | u8g_com_arduino_digital_write(u8g, U8G_PI_RW, HIGH); 100 | } 101 | /* set all pins (except RW pin) */ 102 | u8g_com_arduino_assign_pin_output_high(u8g); 103 | u8g_com_arduino_digital_write(u8g, U8G_PI_EN, HIGH); 104 | break; 105 | case U8G_COM_MSG_STOP: 106 | break; 107 | case U8G_COM_MSG_CHIP_SELECT: 108 | if ( arg_val == 0 ) 109 | { 110 | /* disable */ 111 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, HIGH); 112 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, HIGH); 113 | } 114 | else if ( arg_val == 1 ) 115 | { 116 | /* enable */ 117 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, LOW); 118 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, HIGH); 119 | } 120 | else if ( arg_val == 2 ) 121 | { 122 | /* enable */ 123 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, HIGH); 124 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, LOW); 125 | } 126 | else 127 | { 128 | /* enable */ 129 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS1, LOW); 130 | u8g_com_arduino_digital_write(u8g, U8G_PI_CS2, LOW); 131 | } 132 | break; 133 | case U8G_COM_MSG_WRITE_BYTE: 134 | u8g_com_arduino_port_d_8bit_wr(u8g, arg_val); 135 | break; 136 | case U8G_COM_MSG_WRITE_SEQ: 137 | { 138 | register uint8_t *ptr = arg_ptr; 139 | while( arg_val > 0 ) 140 | { 141 | u8g_com_arduino_port_d_8bit_wr(u8g, *ptr++); 142 | arg_val--; 143 | } 144 | } 145 | break; 146 | case U8G_COM_MSG_WRITE_SEQ_P: 147 | { 148 | register uint8_t *ptr = arg_ptr; 149 | while( arg_val > 0 ) 150 | { 151 | u8g_com_arduino_port_d_8bit_wr(u8g, u8g_pgm_read(ptr)); 152 | ptr++; 153 | arg_val--; 154 | } 155 | } 156 | break; 157 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 158 | u8g_com_arduino_digital_write(u8g, U8G_PI_DI, arg_val); 159 | break; 160 | case U8G_COM_MSG_RESET: 161 | if ( u8g->pin_list[U8G_PI_RESET] != U8G_PIN_NONE ) 162 | u8g_com_arduino_digital_write(u8g, U8G_PI_RESET, arg_val); 163 | break; 164 | } 165 | return 1; 166 | } 167 | 168 | #else 169 | 170 | 171 | uint8_t u8g_com_arduino_port_d_wr_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 172 | { 173 | return 1; 174 | } 175 | 176 | #endif /* ARDUINO && PORTD */ 177 | 178 | -------------------------------------------------------------------------------- /examples/tempDisplay/tempDisplay.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Temperature Display Demo for RFToy 3 | 4 | This demo shows how to use RFToy decode signal 5 | from an off-the-shelf wireless temperature 6 | sensor and display the value to RFToy's OLED. 7 | 8 | Written by Ray Wang @ Rayshobby LLC 9 | Nov 2014 10 | For details, visit 11 | - http://rayshobby.net/rftoy 12 | - http://rayshobby.net/?p=8827 13 | 14 | */ 15 | 16 | #include 17 | #include 18 | 19 | // ring buffer size has to be large enough to fit 20 | // data between two successive sync signals 21 | #define RING_BUFFER_SIZE 256 22 | 23 | #define SYNC_LENGTH 9000 24 | #define SEP_LENGTH 500 25 | #define BIT1_LENGTH 4000 26 | #define BIT0_LENGTH 2000 27 | 28 | #define DATAPIN 2 // D2 is interrupt 0 29 | #define INTPIN 0 30 | 31 | unsigned long timings[RING_BUFFER_SIZE]; 32 | unsigned int syncIndex1 = 0; // index of the first sync signal 33 | unsigned int syncIndex2 = 0; // index of the second sync signal 34 | bool received = false; 35 | 36 | U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE); 37 | 38 | // detect if a sync signal is present 39 | bool isSync(unsigned int idx) { 40 | unsigned long t0 = timings[(idx+RING_BUFFER_SIZE-1) % RING_BUFFER_SIZE]; 41 | unsigned long t1 = timings[idx]; 42 | 43 | // on the temperature sensor, the sync signal 44 | // is roughtly 9.0ms. Accounting for error 45 | // it should be within 8.0ms and 10.0ms 46 | if (t0>(SEP_LENGTH-100) && t0<(SEP_LENGTH+100) && 47 | t1>(SYNC_LENGTH-1000) && t1<(SYNC_LENGTH+1000) && 48 | digitalRead(DATAPIN) == HIGH) { 49 | return true; 50 | } 51 | return false; 52 | } 53 | 54 | /* Interrupt handler */ 55 | void handler() { 56 | static unsigned long duration = 0; 57 | static unsigned long lastTime = 0; 58 | static unsigned int ringIndex = 0; 59 | static unsigned int syncCount = 0; 60 | 61 | // ignore if we haven't processed the previous received signal 62 | if (received == true) { 63 | return; 64 | } 65 | // calculating timing since last change 66 | long time = micros(); 67 | duration = time - lastTime; 68 | lastTime = time; 69 | 70 | // store data in ring buffer 71 | ringIndex = (ringIndex + 1) % RING_BUFFER_SIZE; 72 | timings[ringIndex] = duration; 73 | 74 | // detect sync signal 75 | if (isSync(ringIndex)) { 76 | syncCount ++; 77 | // first time sync is seen, record buffer index 78 | if (syncCount == 1) { 79 | syncIndex1 = (ringIndex+1) % RING_BUFFER_SIZE; 80 | } 81 | else if (syncCount == 2) { 82 | // second time sync is seen, start bit conversion 83 | syncCount = 0; 84 | syncIndex2 = (ringIndex+1) % RING_BUFFER_SIZE; 85 | unsigned int changeCount = (syncIndex2 < syncIndex1) ? (syncIndex2+RING_BUFFER_SIZE - syncIndex1) : (syncIndex2 - syncIndex1); 86 | // changeCount must be 66 -- 32 bits x 2 + 2 for sync 87 | if (changeCount != 66) { 88 | received = false; 89 | syncIndex1 = 0; 90 | syncIndex2 = 0; 91 | } 92 | else { 93 | received = true; 94 | } 95 | } 96 | 97 | } 98 | } 99 | 100 | 101 | void setup() { 102 | 103 | pinMode(DATAPIN, INPUT); 104 | attachInterrupt(INTPIN, handler, CHANGE); 105 | 106 | } 107 | 108 | void loop() { 109 | if (received == true) { 110 | // disable interrupt to avoid new data corrupting the buffer 111 | detachInterrupt(INTPIN); 112 | /* 113 | // loop over buffer data 114 | for(unsigned int i=syncIndex1; i!=syncIndex2; i=(i+2)%RING_BUFFER_SIZE) { 115 | unsigned long t0 = timings[i], t1 = timings[(i+1)%RING_BUFFER_SIZE]; 116 | if (t0>(SEP_LENGTH-100) && t0<(SEP_LENGTH+100)) { 117 | if (t1>(BIT1_LENGTH-1000) && t1<(BIT1_LENGTH+1000)) { 118 | Serial.print("1"); 119 | } else if (t1>(BIT0_LENGTH-1000) && t1<(BIT0_LENGTH+1000)) { 120 | Serial.print("0"); 121 | } else { 122 | Serial.print("SYNC"); // sync signal 123 | } 124 | } else { 125 | Serial.print("?"); // undefined timing 126 | } 127 | } 128 | Serial.println(""); 129 | */ 130 | // loop over the lowest 12 bits of the middle 2 bytes 131 | unsigned long temp = 0; 132 | bool negative = false; 133 | bool fail = false; 134 | for(unsigned int i=(syncIndex1+24)%RING_BUFFER_SIZE; i!=(syncIndex1+48)%RING_BUFFER_SIZE; i=(i+2)%RING_BUFFER_SIZE) { 135 | unsigned long t0 = timings[i], t1 = timings[(i+1)%RING_BUFFER_SIZE]; 136 | if (t0>(SEP_LENGTH-100) && t0<(SEP_LENGTH+100)) { 137 | if (t1>(BIT1_LENGTH-1000) && t1<(BIT1_LENGTH+1000)) { 138 | if(i == (syncIndex1+24)%RING_BUFFER_SIZE) negative = true; 139 | temp = (temp << 1) + 1; 140 | } 141 | else if (t1>(BIT0_LENGTH-1000) && t1<(BIT0_LENGTH+1000)) { 142 | temp = (temp << 1) + 0; 143 | } 144 | else { 145 | fail = true; 146 | } 147 | } 148 | else { 149 | fail = true; 150 | } 151 | } 152 | 153 | 154 | String s; 155 | if (!fail) { 156 | if (negative) { 157 | temp = 4096 - temp; 158 | s = "-"; 159 | } 160 | s+=((temp+5)/10); // round to the nearest integer 161 | s+=(char)176; 162 | s+="C/"; 163 | s+=((temp+5)*9/50+32); // convert to F 164 | s+=(char)176; // degree symbol 165 | s+="F"; 166 | } else { 167 | s+="Decoding error."; 168 | } 169 | 170 | u8g.firstPage(); 171 | do{ 172 | u8g.setFont(u8g_font_10x20); 173 | u8g.setFontRefHeightText(); 174 | u8g.setFontPosTop(); 175 | u8g.drawStr(0,0,s.c_str()); 176 | } while(u8g.nextPage()); 177 | 178 | // delay for 1 second to avoid repetitions 179 | delay(1000); 180 | received = false; 181 | syncIndex1 = 0; 182 | syncIndex2 = 0; 183 | 184 | // re-enable interrupt 185 | attachInterrupt(INTPIN, handler, CHANGE); 186 | } 187 | 188 | } 189 | 190 | -------------------------------------------------------------------------------- /examples/vwSender/vwSender.ino: -------------------------------------------------------------------------------- 1 | /* 2 | VirtualWire Sender Demo for RFToy 3 | 4 | This demo shows how to use RFToy to make a 5 | wireless temperature sensor. This is the 6 | sender module which transmits the current 7 | temperature value to a receiver module. The 8 | demo uses the VirtualWire library. 9 | 10 | This demo also uses power down sleep and 11 | watchdog timer to save battery life, for 12 | long-term monitoring. 13 | 14 | Written by Jonathan Goldin @ Rayshobby LLC 15 | Nov 2014 16 | For details, visit http://rayshobby.net/rftoy 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #define pinReceiverPower 9 27 | #define pinReceiver 2 28 | #define pinTransmitterPower 8 29 | #define pinTransmitter 7 30 | #define pinTemp A1 31 | #define pinLED 13 32 | 33 | volatile int wdt_counter = 0; 34 | 35 | static const float temps[] = { 36 | // according to TDR datasheet: http://www.360yuanjian.com/product/downloadFile-14073-proudct_pdf_doc-pdf.html 37 | // this table defines the reference resistance of the thermistor under each temperature value from -20 to 40 Celcius 38 | 940.885, // -20 Celcius 39 | 888.148, // -19 Celcius 40 | 838.764, 41 | 792.494, 42 | 749.115, 43 | 708.422, 44 | 670.228, 45 | 634.359, 46 | 600.657, 47 | 568.973, 48 | 539.171, 49 | 511.127, 50 | 484.723, 51 | 459.851, 52 | 436.413, 53 | 414.316, 54 | 393.473, 55 | 373.806, 56 | 355.239, 57 | 337.705, 58 | 321.140, 59 | 305.482, 60 | 290.679, 61 | 276.676, 62 | 263.427, 63 | 250.886, 64 | 239.012, 65 | 227.005, 66 | 217.106, 67 | 207.005, 68 | 198.530, 69 | 188.343, 70 | 179.724, 71 | 171.545, 72 | 163.780, 73 | 156.407, 74 | 149.403, 75 | 142.748, 76 | 136.423, 77 | 130.410, 78 | 124.692, 79 | 119.253, 80 | 114.078, 81 | 109.152, 82 | 104.464, 83 | 100.000, 84 | 95.747, 85 | 91.697, 86 | 87.837, 87 | 84.157, 88 | 80.650, 89 | 77.305, 90 | 74.115, 91 | 71.072, 92 | 68.167, 93 | 65.395, 94 | 62.749, 95 | 60.222, 96 | 57.809, 97 | 55.503, 98 | 53.300 // +40 Celcius 99 | }; 100 | 101 | 102 | ISR(WDT_vect) 103 | { 104 | wdt_counter ++; 105 | } 106 | 107 | void enterSleep(void) 108 | { 109 | set_sleep_mode(SLEEP_MODE_PWR_DOWN); /* EDIT: could also use SLEEP_MODE_PWR_DOWN for lowest power consumption. */ 110 | sleep_enable(); 111 | /* Now enter sleep mode. */ 112 | power_all_disable(); 113 | sleep_mode(); 114 | /* The program will continue from here after the WDT timeout*/ 115 | sleep_disable(); /* First thing to do is disable sleep. */ 116 | /* Re-enable the peripherals. */ 117 | power_all_enable(); 118 | } 119 | 120 | 121 | void setup() 122 | { 123 | // set serial pins (0 and 1) to low-power state 124 | pinMode(0, INPUT); 125 | digitalWrite(0, LOW); 126 | pinMode(1, INPUT); 127 | digitalWrite(1, LOW); 128 | 129 | pinMode(pinTransmitterPower, OUTPUT); 130 | digitalWrite(pinTransmitterPower, LOW); 131 | pinMode(pinReceiverPower, OUTPUT); 132 | digitalWrite(pinReceiverPower, LOW); 133 | 134 | pinMode(pinTransmitter, OUTPUT); 135 | digitalWrite(pinTransmitter, LOW); 136 | pinMode(pinReceiver, OUTPUT); 137 | digitalWrite(pinReceiver, LOW); 138 | pinMode(pinLED, OUTPUT); 139 | digitalWrite(pinLED, LOW); 140 | 141 | // Initialise the IO and ISR 142 | vw_set_tx_pin(pinTransmitter); 143 | vw_setup(2000); // Bits per sec 144 | /* Clear the reset flag. */ 145 | MCUSR &= ~(1<= temps[i]){ 201 | float temp = 10.0*(i-20); 202 | // keep in mind the thermistor is negatively correlated with temperature 203 | temp -= 10.0*(resistance-temps[i])/(temps[i-1]-temps[i]); 204 | return (long)temp; 205 | } 206 | } 207 | return -40; 208 | } 209 | 210 | -------------------------------------------------------------------------------- /utility/u8g_dev_pcf8812_96x65.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_pcf8812_96x65.c 4 | 5 | Display: Nokia 96x65 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 | om6206 comaptible to pcf8812 ? 39 | 40 | Status: Tested 41 | 42 | 43 | Display Controller Seen in 44 | LPH7366 (9 pins, 84x48) PCD8544 Nokia 5110 / 5120 / 5130 / 5160 / 6110 / 6150 45 | LPH7677 (8 pins, 84x48) PCD8544 Nokia 3210 46 | LPH7779 (8 pins, 84x48) PCD8544 Nokia 3310 / 3315 / 3330 / 3110, also 3410? 47 | ??? PCD8544 Nokia 5110 / 6110 48 | LPH7690 ? (96x65) PCF8455/OM6202 Nokia 3410 49 | LPH7690 ? (96x65?) SED1565/S1D15605 Nokia 7110 / 3510? 50 | LPH7690 ??? Nokia 6210 51 | 52 | 53 | 54 | */ 55 | 56 | #include "u8g.h" 57 | 58 | #define WIDTH 96 59 | #define HEIGHT 65 60 | #define PAGE_HEIGHT 8 61 | 62 | 63 | static const uint8_t u8g_dev_pcf8812_init_seq[] PROGMEM = { 64 | U8G_ESC_CS(0), /* disable chip */ 65 | U8G_ESC_ADR(0), /* instruction mode */ 66 | U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */ 67 | U8G_ESC_CS(1), /* enable chip */ 68 | 0x021, /* activate chip (PD=0), horizontal increment (V=0), enter extended command set (H=1) */ 69 | 0x006, /* temp. control: b10 = 2 */ 70 | 0x013, /* bias system 1:48 */ 71 | 0x080 | 0x040, /* medium Vop */ 72 | 0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ 73 | 0x00c, /* display on, normal operation */ 74 | U8G_ESC_DLY(100), /* delay 100 ms */ 75 | 0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ 76 | 0x00d, /* display on, invert */ 77 | U8G_ESC_DLY(100), /* delay 100 ms */ 78 | U8G_ESC_DLY(100), /* delay 100 ms */ 79 | 0x020, /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ 80 | 0x00c, /* display on, normal */ 81 | U8G_ESC_DLY(100), /* delay 100 ms */ 82 | U8G_ESC_CS(0), /* disable chip */ 83 | U8G_ESC_END /* end of sequence */ 84 | }; 85 | 86 | uint8_t u8g_dev_pcf8812_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 87 | { 88 | switch(msg) 89 | { 90 | case U8G_DEV_MSG_INIT: 91 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_400NS); 92 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_pcf8812_init_seq); 93 | break; 94 | case U8G_DEV_MSG_STOP: 95 | break; 96 | case U8G_DEV_MSG_PAGE_NEXT: 97 | { 98 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 99 | u8g_SetAddress(u8g, dev, 0); /* command mode */ 100 | u8g_SetChipSelect(u8g, dev, 1); 101 | u8g_WriteByte(u8g, dev, 0x020 ); /* activate chip (PD=0), horizontal increment (V=0), enter normal command set (H=0) */ 102 | u8g_WriteByte(u8g, dev, 0x080 ); /* set X address */ 103 | u8g_WriteByte(u8g, dev, 0x040 | pb->p.page); /* set Y address */ 104 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 105 | if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 ) 106 | return 0; 107 | u8g_SetChipSelect(u8g, dev, 0); 108 | } 109 | break; 110 | case U8G_DEV_MSG_CONTRAST: 111 | /* the contrast adjustment does not work, needs to be analysed */ 112 | u8g_SetAddress(u8g, dev, 0); /* instruction mode */ 113 | u8g_SetChipSelect(u8g, dev, 1); 114 | u8g_WriteByte(u8g, dev, 0x021); /* command mode, extended function set */ 115 | u8g_WriteByte(u8g, dev, 0x080 | ( (*(uint8_t *)arg) >> 1 ) ); 116 | u8g_SetChipSelect(u8g, dev, 0); 117 | return 1; 118 | } 119 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 120 | } 121 | 122 | /* u8g_com_arduino_sw_spi_fn does not work, too fast??? */ 123 | U8G_PB_DEV(u8g_dev_pcf8812_96x65_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_pcf8812_fn, U8G_COM_SW_SPI); 124 | U8G_PB_DEV(u8g_dev_pcf8812_96x65_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_pcf8812_fn, U8G_COM_HW_SPI); 125 | -------------------------------------------------------------------------------- /u8g.ChangeLog: -------------------------------------------------------------------------------- 1 | 2 | u8glib ChangeLog 3 | 4 | 2012-01-01 v0.01 Oliver Kraus 5 | * first beta release for Arduino IDE with simple SSD1325 support 6 | 2012-01-04 v0.02 Oliver Kraus 7 | * support for some more display types 8 | 2012-01-07 v0.03 Oliver Kraus 9 | * fixed some bugs, added more examples 10 | 2012-01-07 v0.04 Oliver Kraus 11 | * single font file 12 | 2012-01-08 v0.05 Oliver Kraus 13 | * Cleanup 14 | * More examples 15 | * SSD1325 graylevel support 16 | 2012-01-15 v0.06 Oliver Kraus 17 | * LM6063 support 18 | 2012-01-17 v0.07 Oliver Kraus 19 | * LM6063 support (update) 20 | 2012-01-19 v0.08 Oliver Kraus 21 | * ST7920 beta device 22 | 2012-01-21 v0.09 Oliver Kraus 23 | * ST7920 fixed (192x32) 24 | * fixed bug in com layer if pins are none 25 | * str reference position 26 | 2012-01-22 v0.10 Oliver Kraus 27 | * Experimental LM6059 28 | 2012-01-24 v0.11 Oliver Kraus 29 | * new st7920 memory layout for 128x64 lcd 30 | * experimental st7920 SPI 31 | 2012-01-25 v0.12 Oliver Kraus 32 | * fixed st7920 memory layout for 128x64 lcd 33 | * ST7920 SPI performance improvement 34 | 2012-01-27 v0.13 Oliver Kraus 35 | * LM6059 (Adafruit Display) fixed 36 | 2012-02-01 v0.14 Oliver Kraus 37 | * undoRotation() 38 | * setRot..() can be used without restrictions 39 | * Class U8GLIB derived from Print class. New function "print" 40 | * Fixed memory index bug in the page management procedures 41 | 2012-02-12 v1.00 Oliver Kraus 42 | * XBM support 43 | * F() macro support 44 | * str-rotation commands support ref-height and ref-position 45 | 2012-03-17 v1.02 Oliver Kraus 46 | * U8GLIB_ST7687_C144MVGD spi experimental 47 | * U8GLIB_LC7981_160X80 8bit 48 | * Intersection test for frame and box procedures 49 | * 4L double memory architecture 50 | * setContrast infrastructure implemented, but not available for all devices 51 | * drawCircle, drawDisc 52 | * Bugfix for drawStr270 53 | * New examples: Chess (ported from dogm128 lib) and GraphicsTest 54 | 2012-03-31 v1.03 Oliver Kraus 55 | * experimental parallel mode atmega 56 | * more unifont code pages 57 | * double memory, for NHD OLED and DOGXL160 58 | * "Menu" example 59 | * drawLine 60 | 2012-04-13 v1.04 Oliver Kraus 61 | * Adjust U8grelease: Same version number with AVR and Arduino variant 62 | 2012-06-10 v1.05 Oliver Kraus 63 | * m2icon font 64 | * experimental lc7981_240x64 device 65 | * experimental ssd1306 66 | * experimental ssd1322 67 | * Hardware state backup/restore procedure 68 | 2012-06-15 v1.06 Oliver Kraus 69 | * SBN1661 (SED1520?) support 70 | * SSD1306 support 71 | * U8G_PROGMEM bugfix 72 | 2012-07-04 v1.07 Oliver Kraus 73 | * Added Makefiles for AVR release (issue 77) 74 | * Fixed examples for Arduino Environment (issue 78) 75 | 2012-10-02 v1.08 Oliver Kraus 76 | * Improved delay calculation for strobe pulse (issue 20) 77 | * Support Chipkit (issue 39) 78 | * Improved speed for ST7920 parallel mode (issue 79) 79 | * Overall speed optimization (new page intersection algorithm) 80 | * Support for Displays Newhaven NHD-C12864, CrystalFontz GFAG20232, Seeedstudio 96x96 OLED 81 | * Added SPI support for ST7920 with plain AVR (issue 85) 82 | * Add more LC7981 devices 83 | 2012-12-23 v1.09 Oliver Kraus 84 | * Support for Displaytech 64128n 85 | * Support for MINI12864 86 | * HW SPI for ST7920 87 | * Add delay after sending a byte with (ST7920 com) 88 | * Support ATTiny 89 | * Support I2C for SSD1306 90 | * bdf2u8g, Windows executable released 91 | * LC7981 320x64 92 | * Scalue up: u8g::setScale2x2 93 | * Added more bitmap fonts 94 | * u8g::drawRBox(), u8g::drawRFrame() 95 | * Support for CFAG20232 (st7920_202x32) 96 | * Fixed ST7920 SW SPI for ChipKit 97 | * Support for tls8204 98 | 2013-02-02 v1.10 Oliver Kraus 99 | * Support for SSD1309 100 | * Support for NHD-C12832A1Z 101 | * Bugfix: Fixed reset controll in parallel modes 102 | * Bugfix: Fixed calculation of cursor position 103 | * Bugfix: ST7920 parallel mode 104 | 2013-03-2 v1.11 Oliver Kraus 105 | * Support for T6963 106 | * Support for Arduino Due 107 | * Sleep Mode 108 | * 4x mode for ST7920 109 | * New C++ interface for ST7920 110 | 2013-03-24 v1.12 Oliver Kraus 111 | * Added touch panel examples 112 | 2013-06-30 v1.13 Oliver Kraus 113 | * Fixed missing "Arduino.h" in u8g_delay.c 114 | * Disable interrupt for port/pin access (AVR), issue 19 115 | * Support for HT1632: U8GLIB_HT1632_24X16 u8g(wr, data, cs), issue 165 116 | * Support for SSD1351 OLED, issue 168 117 | * Cleaned up several compiler warnings 118 | * Fixed conflict with scheduler (Arduino Due), issue 155 119 | * HW SPI for Arduino Due, issue 180 120 | * Performance improvement for ST7920, issue 177 121 | * Added ":" to the "n"umeric variant of the fonts, issue 166 122 | * Added additional argument u8g_InitCom(). Use U8G_SPI_CLK_CYCLE_NONE by default. 123 | * Added double buffer option for many ST7565 devices 124 | * Tested with Arduino 1.0.5 125 | 2013-10-03 v1.14 Oliver Kraus 126 | * Support for ARM controller 127 | * Support for the A2 micro printer (issue 191) 128 | * Ellipse drawing primitive (issue 187) 129 | * Added software reset for UC1701 130 | * Fixed compiler warning (issue 196) 131 | * Support for Freetronics SSD1351 OLED (issue 195) 132 | * Several other fixes and improvements 133 | 134 | 135 | 136 | 137 | -------------------------------------------------------------------------------- /utility/u8g_dev_lc7981_240x64.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_lc7981_240x64.c 4 | 5 | Tested with Nan Ya LM_J6_003_ 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2012, olikraus@gmail.com 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this list 16 | of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, this 19 | list of conditions and the following disclaimer in the documentation and/or other 20 | materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | */ 38 | 39 | #include "u8g.h" 40 | 41 | #define WIDTH 240 42 | #define HEIGHT 64 43 | #define PAGE_HEIGHT 8 44 | 45 | 46 | /* 47 | http://www.mark-products.com/graphics.htm#240x64%20Pixel%20Format 48 | */ 49 | 50 | static const uint8_t u8g_dev_lc7981_240x64_init_seq[] PROGMEM = { 51 | U8G_ESC_CS(0), /* disable chip */ 52 | U8G_ESC_ADR(1), /* instruction mode */ 53 | U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/ 54 | U8G_ESC_CS(1), /* enable chip */ 55 | U8G_ESC_DLY(50), /* delay 50 ms */ 56 | 57 | 58 | U8G_ESC_ADR(1), /* instruction mode */ 59 | 0x000, /* mode register */ 60 | U8G_ESC_ADR(0), /* data mode */ 61 | 0x032, /* display on (bit 5), master mode on (bit 4), graphics mode on (bit 1)*/ 62 | 63 | U8G_ESC_ADR(1), /* instruction mode */ 64 | 0x001, /* character/bits per pixel pitch */ 65 | U8G_ESC_ADR(0), /* data mode */ 66 | 0x007, /* 8 bits per pixel */ 67 | 68 | U8G_ESC_ADR(1), /* instruction mode */ 69 | 0x002, /* number of chars/byte width of the screen */ 70 | U8G_ESC_ADR(0), /* data mode */ 71 | WIDTH/8-1, /* 8 bits per pixel */ 72 | 73 | U8G_ESC_ADR(1), /* instruction mode */ 74 | 0x003, /* time division */ 75 | U8G_ESC_ADR(0), /* data mode */ 76 | 0x07f, /* */ 77 | 78 | U8G_ESC_ADR(1), /* instruction mode */ 79 | 0x008, /* display start low */ 80 | U8G_ESC_ADR(0), /* data mode */ 81 | 0x000, /* */ 82 | 83 | U8G_ESC_ADR(1), /* instruction mode */ 84 | 0x009, /* display start high */ 85 | U8G_ESC_ADR(0), /* data mode */ 86 | 0x000, /* */ 87 | 88 | U8G_ESC_DLY(10), /* delay 10 ms */ 89 | 90 | U8G_ESC_CS(0), /* disable chip */ 91 | U8G_ESC_END /* end of sequence */ 92 | }; 93 | 94 | uint8_t u8g_dev_lc7981_240x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 95 | { 96 | switch(msg) 97 | { 98 | case U8G_DEV_MSG_INIT: 99 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE); 100 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_lc7981_240x64_init_seq); 101 | break; 102 | case U8G_DEV_MSG_STOP: 103 | break; 104 | case U8G_DEV_MSG_PAGE_NEXT: 105 | { 106 | uint8_t y, i; 107 | uint16_t disp_ram_adr; 108 | uint8_t *ptr; 109 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 110 | 111 | u8g_SetAddress(u8g, dev, 1); /* cmd mode */ 112 | u8g_SetChipSelect(u8g, dev, 1); 113 | y = pb->p.page_y0; 114 | ptr = pb->buf; 115 | disp_ram_adr = WIDTH/8; 116 | disp_ram_adr *= y; 117 | for( i = 0; i < 8; i ++ ) 118 | { 119 | u8g_SetAddress(u8g, dev, 1); /* cmd mode */ 120 | u8g_WriteByte(u8g, dev, 0x00a ); /* display ram (cursor) address low byte */ 121 | u8g_SetAddress(u8g, dev, 0); /* data mode */ 122 | u8g_WriteByte(u8g, dev, disp_ram_adr & 0x0ff ); 123 | 124 | u8g_SetAddress(u8g, dev, 1); /* cmd mode */ 125 | u8g_WriteByte(u8g, dev, 0x00b ); /* display ram (cursor) address hight byte */ 126 | u8g_SetAddress(u8g, dev, 0); /* data mode */ 127 | u8g_WriteByte(u8g, dev, disp_ram_adr >> 8 ); 128 | 129 | u8g_SetAddress(u8g, dev, 1); /* cmd mode */ 130 | u8g_WriteByte(u8g, dev, 0x00c ); /* write data */ 131 | u8g_SetAddress(u8g, dev, 0); /* data mode */ 132 | u8g_WriteSequence(u8g, dev, WIDTH/8, ptr); 133 | ptr += WIDTH/8; 134 | disp_ram_adr += WIDTH/8; 135 | } 136 | u8g_SetChipSelect(u8g, dev, 0); 137 | } 138 | break; 139 | } 140 | return u8g_dev_pb8h1f_base_fn(u8g, dev, msg, arg); 141 | } 142 | 143 | U8G_PB_DEV(u8g_dev_lc7981_240x64_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_lc7981_240x64_fn, U8G_COM_FAST_PARALLEL); 144 | 145 | 146 | -------------------------------------------------------------------------------- /utility/u8g_dev_lc7981_240x128.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_lc7981_240x128.c 4 | 5 | Hitachi Display SP14N002 6 | 7 | Universal 8bit Graphics Library 8 | 9 | Copyright (c) 2012, olikraus@gmail.com 10 | All rights reserved. 11 | 12 | Redistribution and use in source and binary forms, with or without modification, 13 | are permitted provided that the following conditions are met: 14 | 15 | * Redistributions of source code must retain the above copyright notice, this list 16 | of conditions and the following disclaimer. 17 | 18 | * Redistributions in binary form must reproduce the above copyright notice, this 19 | list of conditions and the following disclaimer in the documentation and/or other 20 | materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 23 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 24 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 25 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 28 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 29 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 32 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 33 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 34 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 35 | 36 | 37 | */ 38 | 39 | #include "u8g.h" 40 | 41 | #define WIDTH 240 42 | #define HEIGHT 128 43 | #define PAGE_HEIGHT 8 44 | 45 | 46 | /* 47 | http://www.mark-products.com/graphics.htm#240x128%20Pixel%20Format 48 | */ 49 | 50 | static const uint8_t u8g_dev_lc7981_240x128_init_seq[] PROGMEM = { 51 | U8G_ESC_CS(0), /* disable chip */ 52 | U8G_ESC_ADR(1), /* instruction mode */ 53 | U8G_ESC_RST(15), /* do reset low pulse with (15*16)+2 milliseconds (=maximum delay)*/ 54 | U8G_ESC_CS(1), /* enable chip */ 55 | U8G_ESC_DLY(50), /* delay 50 ms */ 56 | 57 | 58 | U8G_ESC_ADR(1), /* instruction mode */ 59 | 0x000, /* mode register */ 60 | U8G_ESC_ADR(0), /* data mode */ 61 | 0x032, /* display on (bit 5), master mode on (bit 4), graphics mode on (bit 1)*/ 62 | 63 | U8G_ESC_ADR(1), /* instruction mode */ 64 | 0x001, /* character/bits per pixel pitch */ 65 | U8G_ESC_ADR(0), /* data mode */ 66 | 0x007, /* 8 bits per pixel */ 67 | 68 | U8G_ESC_ADR(1), /* instruction mode */ 69 | 0x002, /* number of chars/byte width of the screen */ 70 | U8G_ESC_ADR(0), /* data mode */ 71 | WIDTH/8-1, /* 8 bits per pixel */ 72 | 73 | U8G_ESC_ADR(1), /* instruction mode */ 74 | 0x003, /* time division */ 75 | U8G_ESC_ADR(0), /* data mode */ 76 | 0x07f, /* */ 77 | 78 | U8G_ESC_ADR(1), /* instruction mode */ 79 | 0x008, /* display start low */ 80 | U8G_ESC_ADR(0), /* data mode */ 81 | 0x000, /* */ 82 | 83 | U8G_ESC_ADR(1), /* instruction mode */ 84 | 0x009, /* display start high */ 85 | U8G_ESC_ADR(0), /* data mode */ 86 | 0x000, /* */ 87 | 88 | U8G_ESC_DLY(10), /* delay 10 ms */ 89 | 90 | U8G_ESC_CS(0), /* disable chip */ 91 | U8G_ESC_END /* end of sequence */ 92 | }; 93 | 94 | uint8_t u8g_dev_lc7981_240x128_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 95 | { 96 | switch(msg) 97 | { 98 | case U8G_DEV_MSG_INIT: 99 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_NONE); 100 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_lc7981_240x128_init_seq); 101 | break; 102 | case U8G_DEV_MSG_STOP: 103 | break; 104 | case U8G_DEV_MSG_PAGE_NEXT: 105 | { 106 | uint8_t y, i; 107 | uint16_t disp_ram_adr; 108 | uint8_t *ptr; 109 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 110 | 111 | u8g_SetAddress(u8g, dev, 1); /* cmd mode */ 112 | u8g_SetChipSelect(u8g, dev, 1); 113 | y = pb->p.page_y0; 114 | ptr = pb->buf; 115 | disp_ram_adr = WIDTH/8; 116 | disp_ram_adr *= y; 117 | for( i = 0; i < 8; i ++ ) 118 | { 119 | u8g_SetAddress(u8g, dev, 1); /* cmd mode */ 120 | u8g_WriteByte(u8g, dev, 0x00a ); /* display ram (cursor) address low byte */ 121 | u8g_SetAddress(u8g, dev, 0); /* data mode */ 122 | u8g_WriteByte(u8g, dev, disp_ram_adr & 0x0ff ); 123 | 124 | u8g_SetAddress(u8g, dev, 1); /* cmd mode */ 125 | u8g_WriteByte(u8g, dev, 0x00b ); /* display ram (cursor) address hight byte */ 126 | u8g_SetAddress(u8g, dev, 0); /* data mode */ 127 | u8g_WriteByte(u8g, dev, disp_ram_adr >> 8 ); 128 | 129 | u8g_SetAddress(u8g, dev, 1); /* cmd mode */ 130 | u8g_WriteByte(u8g, dev, 0x00c ); /* write data */ 131 | u8g_SetAddress(u8g, dev, 0); /* data mode */ 132 | u8g_WriteSequence(u8g, dev, WIDTH/8, ptr); 133 | ptr += WIDTH/8; 134 | disp_ram_adr += WIDTH/8; 135 | } 136 | u8g_SetChipSelect(u8g, dev, 0); 137 | } 138 | break; 139 | } 140 | return u8g_dev_pb8h1f_base_fn(u8g, dev, msg, arg); 141 | } 142 | 143 | U8G_PB_DEV(u8g_dev_lc7981_240x128_8bit, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_lc7981_240x128_fn, U8G_COM_FAST_PARALLEL); 144 | 145 | 146 | --------------------------------------------------------------------------------