├── Circuit Notes.docx ├── Schematic ├── APRS-Tracker.fzz └── APRS-Tracker_schem.png ├── Arduino └── libraries │ ├── readme.txt │ ├── U8glib │ ├── 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_com_raspberrypi_hw_spi.c │ │ ├── u8g_dev_gprof.c │ │ ├── u8g_dev_sbn1661_122x32.c │ │ ├── u8g_com_atmega_sw_spi.c │ │ ├── u8g_dev_ks0108_128x64.c │ │ ├── u8g_dev_uc1611_dogm240.c │ │ ├── u8g_com_arduino_std_sw_spi.c │ │ ├── u8g_dev_uc1611_dogxl240.c │ │ ├── u8g_pb8v2.c │ │ ├── u8g_com_arduino_hw_usart_spi.c │ │ ├── u8g_state.c │ │ ├── u8g_bitmap.c │ │ ├── u8g_dev_tls8204_84x48.c │ │ ├── u8g_pb8h2.c │ │ ├── u8g_com_raspberrypi_ssd_i2c.c │ │ ├── u8g_clip.c │ │ ├── u8g_virtual_screen.c │ │ ├── u8g_pb16v2.c │ │ ├── u8g_pb.c │ │ ├── u8g_com_api.c │ │ ├── u8g_com_atmega_hw_spi.c │ │ ├── u8g_com_arduino_attiny85_hw_spi.c │ │ ├── u8g_pbxh16.c │ │ ├── u8g_com_atmega_st7920_spi.c │ │ ├── u8g_pb8h8.c │ │ ├── u8g_pb8v1.c │ │ ├── u8g_com_arduino_port_d_wr.c │ │ └── u8g_dev_ssd1309_128x64.c │ ├── INSTALL.TXT │ ├── U8glib.cpp │ ├── license.txt │ └── examples │ │ └── A2Printer │ │ └── A2Printer.ino │ ├── LibAPRS │ ├── constants.h │ ├── HDLC.h │ ├── CRC-CCIT.h │ ├── device.h │ ├── LibAPRS.h │ ├── README.md │ ├── AX25.h │ ├── FIFO.h │ ├── CRC-CCIT.c │ ├── AX25.cpp │ └── examples │ │ └── Basic_usage │ │ └── Basic_usage.ino │ └── TinyGPS │ ├── keywords.txt │ ├── examples │ ├── simple_test │ │ └── simple_test.ino │ ├── test_with_gps_device │ │ └── test_with_gps_device.ino │ └── static_test │ │ └── static_test.ino │ └── TinyGPS.h ├── .gitattributes └── .gitignore /Circuit Notes.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jweers1/Aprs-Tracker/HEAD/Circuit Notes.docx -------------------------------------------------------------------------------- /Schematic/APRS-Tracker.fzz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jweers1/Aprs-Tracker/HEAD/Schematic/APRS-Tracker.fzz -------------------------------------------------------------------------------- /Arduino/libraries/readme.txt: -------------------------------------------------------------------------------- 1 | For information on installing libraries, see: http://arduino.cc/en/Guide/Libraries 2 | -------------------------------------------------------------------------------- /Schematic/APRS-Tracker_schem.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jweers1/Aprs-Tracker/HEAD/Schematic/APRS-Tracker_schem.png -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/utility/chessengine.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jweers1/Aprs-Tracker/HEAD/Arduino/libraries/U8glib/utility/chessengine.c -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/utility/u8g_font_data.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jweers1/Aprs-Tracker/HEAD/Arduino/libraries/U8glib/utility/u8g_font_data.c -------------------------------------------------------------------------------- /Arduino/libraries/LibAPRS/constants.h: -------------------------------------------------------------------------------- 1 | #define m328p 0x01 2 | #define m1284p 0x02 3 | #define m644p 0x03 4 | 5 | #define REF_3V3 0x01 6 | #define REF_5V 0x02 -------------------------------------------------------------------------------- /Arduino/libraries/LibAPRS/HDLC.h: -------------------------------------------------------------------------------- 1 | #ifndef PROTOCOL_HDLC_H 2 | #define PROTOCOL_HDLC_H 3 | 4 | #define HDLC_FLAG 0x7E 5 | #define HDLC_RESET 0x7F 6 | #define AX25_ESC 0x1B 7 | 8 | #endif -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /Arduino/libraries/LibAPRS/CRC-CCIT.h: -------------------------------------------------------------------------------- 1 | // CRC-CCIT Implementation based on work by Francesco Sacchi 2 | 3 | #ifndef CRC_CCIT_H 4 | #define CRC_CCIT_H 5 | 6 | #include 7 | #include 8 | 9 | #define CRC_CCIT_INIT_VAL ((uint16_t)0xFFFF) 10 | 11 | extern const uint16_t crc_ccit_table[256]; 12 | 13 | inline uint16_t update_crc_ccit(uint8_t c, uint16_t prev_crc) { 14 | return (prev_crc >> 8) ^ pgm_read_word(&crc_ccit_table[(prev_crc ^ c) & 0xff]); 15 | } 16 | 17 | 18 | #endif -------------------------------------------------------------------------------- /Arduino/libraries/LibAPRS/device.h: -------------------------------------------------------------------------------- 1 | #include "constants.h" 2 | 3 | #ifndef DEVICE_CONFIGURATION 4 | #define DEVICE_CONFIGURATION 5 | 6 | // CPU settings 7 | #ifndef TARGET_CPU 8 | #define TARGET_CPU m328p 9 | #endif 10 | 11 | #ifndef F_CPU 12 | #define F_CPU 16000000 13 | #endif 14 | 15 | #ifndef FREQUENCY_CORRECTION 16 | #define FREQUENCY_CORRECTION 0 17 | #endif 18 | 19 | // Sampling & timer setup 20 | #define CONFIG_AFSK_DAC_SAMPLERATE 9600 21 | 22 | // Port settings 23 | #if TARGET_CPU == m328p 24 | #define DAC_PORT PORTD 25 | #define DAC_DDR DDRD 26 | #define LED_PORT PORTB 27 | #define LED_DDR DDRB 28 | #define ADC_PORT PORTC 29 | #define ADC_DDR DDRC 30 | #endif 31 | 32 | #endif -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear on external disk 35 | .Spotlight-V100 36 | .Trashes 37 | 38 | # Directories potentially created on remote AFP share 39 | .AppleDB 40 | .AppleDesktop 41 | Network Trash Folder 42 | Temporary Items 43 | .apdisk 44 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/INSTALL.TXT: -------------------------------------------------------------------------------- 1 | 2 | U8GLIB 3 | http://code.google.com/p/u8glib/ 4 | 5 | Install instructions for the Arduino environment. 6 | 7 | 1. Start Arduino IDE 8 | 2. In the Arduino IDE, import the library from the "Add Library" Menu. 9 | 10 | Alternative install instructions for the Arduino environment. 11 | 12 | 1. Unzip u8glib_arduino_vX.XX.zip into the "libraries" folder of the 13 | Arduino install directory 14 | 2. Start Arduino IDE 15 | 16 | Install instructions for the Chipkit (Arduino) environment. 17 | 18 | 1. cd /libraries 19 | 2. unzip u8glib_arduino_vX.XX.zip 20 | 3. cd ///hardware/pic32/libraries 21 | 4. again: u8glib_arduino_vX.XX.zip 22 | 5. Open hardware/pic32/cores/pic32/Print.h 23 | Remove line 24 | #define BYTE 0 25 | from the file, use PRINT_BYTE instead of BYTE. 26 | -------------------------------------------------------------------------------- /Arduino/libraries/LibAPRS/LibAPRS.h: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include 3 | #include 4 | 5 | #include "FIFO.h" 6 | #include "CRC-CCIT.h" 7 | #include "HDLC.h" 8 | #include "AFSK.h" 9 | #include "AX25.h" 10 | 11 | void APRS_init(int reference, bool open_squelch); 12 | void APRS_poll(void); 13 | 14 | void APRS_setCallsign(char *call, int ssid); 15 | void APRS_setDestination(char *call, int ssid); 16 | void APRS_setMessageDestination(char *call, int ssid); 17 | void APRS_setPath1(char *call, int ssid); 18 | void APRS_setPath2(char *call, int ssid); 19 | 20 | void APRS_setPreamble(unsigned long pre); 21 | void APRS_setTail(unsigned long tail); 22 | void APRS_useAlternateSymbolTable(bool use); 23 | void APRS_setSymbol(char sym); 24 | 25 | void APRS_setLat(char *lat); 26 | void APRS_setLon(char *lon); 27 | void APRS_setPower(int s); 28 | void APRS_setHeight(int s); 29 | void APRS_setGain(int s); 30 | void APRS_setDirectivity(int s); 31 | 32 | void APRS_sendPkt(void *_buffer, size_t length); 33 | void APRS_sendLoc(void *_buffer, size_t length); 34 | void APRS_sendMsg(void *_buffer, size_t length); 35 | void APRS_msgRetry(); 36 | 37 | void APRS_printSettings(); 38 | 39 | int freeMemory(); 40 | -------------------------------------------------------------------------------- /Arduino/libraries/TinyGPS/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map for TinyGPS 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | TinyGPS KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | encode KEYWORD2 16 | get_position KEYWORD2 17 | get_datetime KEYWORD2 18 | altitude KEYWORD2 19 | speed KEYWORD2 20 | course KEYWORD2 21 | stats KEYWORD2 22 | f_get_position KEYWORD2 23 | crack_datetime KEYWORD2 24 | f_altitude KEYWORD2 25 | f_course KEYWORD2 26 | f_speed_knots KEYWORD2 27 | f_speed_mph KEYWORD2 28 | f_speed_mps KEYWORD2 29 | f_speed_kmph KEYWORD2 30 | library_version KEYWORD2 31 | distance_between KEYWORD2 32 | course_to KEYWORD2 33 | satellites KEYWORD2 34 | hdop KEYWORD2 35 | 36 | ####################################### 37 | # Constants (LITERAL1) 38 | ####################################### 39 | 40 | GPS_INVALID_AGE LITERAL1 41 | GPS_INVALID_ANGLE LITERAL1 42 | GPS_INVALID_ALTITUDE LITERAL1 43 | GPS_INVALID_DATE LITERAL1 44 | GPS_INVALID_TIME LITERAL1 45 | GPS_INVALID_HDOP LITERAL1 46 | GPS_INVALID_SATELLITES LITERAL1 47 | GPS_INVALID_F_ANGLE LITERAL1 48 | GPS_INVALID_F_ALTITUDE LITERAL1 49 | GPS_INVALID_F_SPEED LITERAL1 50 | -------------------------------------------------------------------------------- /Arduino/libraries/LibAPRS/README.md: -------------------------------------------------------------------------------- 1 | LibAPRS 2 | ========== 3 | 4 | LibAPRS is an Arduino IDE library that makes it easy to send and receive APRS packets with a [MicroModem](http://unsigned.io/micromodem)-compatible modem. 5 | 6 | You can buy a complete modem from [my shop](http://unsigned.io/shop), or you can build one yourself pretty easily. Take a look at the documentation in the [MicroModem](https://github.com/markqvist/MicroModem) repository for information and getting started guides! 7 | 8 | See the example included in the library for info on how to use it! 9 | 10 | ## Some features 11 | 12 | - Send and receive AX.25 APRS packets 13 | - Full modulation and demodulation in software 14 | - Easy configuration of callsign and path settings 15 | - Easily process incoming packets 16 | - Shorthand functions for sending location updates and messages, so you don't need to manually create the packets 17 | - Ability to send raw packets 18 | - Support for settings APRS symbols 19 | - Support for power/height/gain info in location updates 20 | - Can run with open squelch 21 | 22 | ## Installation 23 | 24 | Place the "LibAPRS" folder (the one in the same folder as this readme file) inside your Arduino "libraries" folder. That's all! 25 | 26 | ## Getting started 27 | 28 | You should read through the "Basic_usage" example included with the library. It contains an explanation of all the functions and a basic sketch to get you up and running with sending and receiving packets. 29 | 30 | ## Got bugs? 31 | 32 | This library is very early, and being actively developed all the time. This means you should expect to find bugs. If you do, please report them here, so I can fix them! It also means I might have to make changes that will break code, and that you will have to rewrite your sketch. If you don't think that sounds good, wait a little while for a stable release of the library :) -------------------------------------------------------------------------------- /Arduino/libraries/LibAPRS/AX25.h: -------------------------------------------------------------------------------- 1 | #ifndef PROTOCOL_AX25_H 2 | #define PROTOCOL_AX25_H 3 | 4 | #include 5 | #include 6 | #include "device.h" 7 | 8 | #define AX25_MIN_FRAME_LEN 18 9 | #ifndef CUSTOM_FRAME_SIZE 10 | #define AX25_MAX_FRAME_LEN 330 11 | #else 12 | #define AX25_MAX_FRAME_LEN CUSTOM_FRAME_SIZE 13 | #endif 14 | 15 | #define AX25_CRC_CORRECT 0xF0B8 16 | 17 | #define AX25_CTRL_UI 0x03 18 | #define AX25_PID_NOLAYER3 0xF0 19 | 20 | struct AX25Ctx; // Forward declarations 21 | struct AX25Msg; 22 | 23 | typedef void (*ax25_callback_t)(struct AX25Msg *msg); 24 | 25 | typedef struct AX25Ctx { 26 | uint8_t buf[AX25_MAX_FRAME_LEN]; 27 | FILE *ch; 28 | size_t frame_len; 29 | uint16_t crc_in; 30 | uint16_t crc_out; 31 | ax25_callback_t hook; 32 | bool sync; 33 | bool escape; 34 | } AX25Ctx; 35 | 36 | 37 | #define AX25_CALL(str, id) {.call = (str), .ssid = (id) } 38 | #define AX25_MAX_RPT 8 39 | #define AX25_REPEATED(msg, n) ((msg)->rpt_flags & BV(n)) 40 | 41 | #define CALL_OVERSPACE 1 42 | 43 | typedef struct AX25Call { 44 | char call[6+CALL_OVERSPACE]; 45 | //char STRING_TERMINATION = 0; 46 | uint8_t ssid; 47 | } AX25Call; 48 | 49 | typedef struct AX25Msg { 50 | AX25Call src; 51 | AX25Call dst; 52 | AX25Call rpt_list[AX25_MAX_RPT]; 53 | uint8_t rpt_count; 54 | uint8_t rpt_flags; 55 | uint16_t ctrl; 56 | uint8_t pid; 57 | const uint8_t *info; 58 | size_t len; 59 | } AX25Msg; 60 | 61 | void ax25_sendVia(AX25Ctx *ctx, const AX25Call *path, size_t path_len, const void *_buf, size_t len); 62 | #define ax25_send(ctx, dst, src, buf, len) ax25_sendVia(ctx, ({static AX25Call __path[]={dst, src}; __path;}), 2, buf, len) 63 | 64 | 65 | 66 | void ax25_poll(AX25Ctx *ctx); 67 | void ax25_sendRaw(AX25Ctx *ctx, void *_buf, size_t len); 68 | void ax25_init(AX25Ctx *ctx, ax25_callback_t hook); 69 | 70 | #endif -------------------------------------------------------------------------------- /Arduino/libraries/LibAPRS/FIFO.h: -------------------------------------------------------------------------------- 1 | #ifndef UTIL_FIFO_H 2 | #define UTIL_FIFO_H 3 | 4 | #include 5 | #include 6 | 7 | typedef struct FIFOBuffer 8 | { 9 | unsigned char *begin; 10 | unsigned char *end; 11 | unsigned char * volatile head; 12 | unsigned char * volatile tail; 13 | } FIFOBuffer; 14 | 15 | inline bool fifo_isempty(const FIFOBuffer *f) { 16 | return f->head == f->tail; 17 | } 18 | 19 | inline bool fifo_isfull(const FIFOBuffer *f) { 20 | return ((f->head == f->begin) && (f->tail == f->end)) || (f->tail == f->head - 1); 21 | } 22 | 23 | inline void fifo_push(FIFOBuffer *f, unsigned char c) { 24 | *(f->tail) = c; 25 | 26 | if (f->tail == f->end) { 27 | f->tail = f->begin; 28 | } else { 29 | f->tail++; 30 | } 31 | } 32 | 33 | inline unsigned char fifo_pop(FIFOBuffer *f) { 34 | if(f->head == f->end) { 35 | f->head = f->begin; 36 | return *(f->end); 37 | } else { 38 | return *(f->head++); 39 | } 40 | } 41 | 42 | inline void fifo_flush(FIFOBuffer *f) { 43 | f->head = f->tail; 44 | } 45 | 46 | inline bool fifo_isempty_locked(const FIFOBuffer *f) { 47 | bool result; 48 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { 49 | result = fifo_isempty(f); 50 | } 51 | return result; 52 | } 53 | 54 | inline bool fifo_isfull_locked(const FIFOBuffer *f) { 55 | bool result; 56 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { 57 | result = fifo_isfull(f); 58 | } 59 | return result; 60 | } 61 | 62 | inline void fifo_push_locked(FIFOBuffer *f, unsigned char c) { 63 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { 64 | fifo_push(f, c); 65 | } 66 | } 67 | 68 | inline unsigned char fifo_pop_locked(FIFOBuffer *f) { 69 | unsigned char c; 70 | ATOMIC_BLOCK(ATOMIC_RESTORESTATE) { 71 | c = fifo_pop(f); 72 | } 73 | return c; 74 | } 75 | 76 | inline void fifo_init(FIFOBuffer *f, unsigned char *buffer, size_t size) { 77 | f->head = f->tail = f->begin = buffer; 78 | f->end = buffer + size -1; 79 | } 80 | 81 | inline size_t fifo_len(FIFOBuffer *f) { 82 | return f->end - f->begin; 83 | } 84 | 85 | #endif -------------------------------------------------------------------------------- /Arduino/libraries/TinyGPS/examples/simple_test/simple_test.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | /* This sample code demonstrates the normal use of a TinyGPS object. 6 | It requires the use of SoftwareSerial, and assumes that you have a 7 | 4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx). 8 | */ 9 | 10 | TinyGPS gps; 11 | SoftwareSerial ss(4, 3); 12 | 13 | void setup() 14 | { 15 | Serial.begin(115200); 16 | ss.begin(4800); 17 | 18 | Serial.print("Simple TinyGPS library v. "); Serial.println(TinyGPS::library_version()); 19 | Serial.println("by Mikal Hart"); 20 | Serial.println(); 21 | } 22 | 23 | void loop() 24 | { 25 | bool newData = false; 26 | unsigned long chars; 27 | unsigned short sentences, failed; 28 | 29 | // For one second we parse GPS data and report some key values 30 | for (unsigned long start = millis(); millis() - start < 1000;) 31 | { 32 | while (ss.available()) 33 | { 34 | char c = ss.read(); 35 | // Serial.write(c); // uncomment this line if you want to see the GPS data flowing 36 | if (gps.encode(c)) // Did a new valid sentence come in? 37 | newData = true; 38 | } 39 | } 40 | 41 | if (newData) 42 | { 43 | float flat, flon; 44 | unsigned long age; 45 | gps.f_get_position(&flat, &flon, &age); 46 | Serial.print("LAT="); 47 | Serial.print(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6); 48 | Serial.print(" LON="); 49 | Serial.print(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6); 50 | Serial.print(" SAT="); 51 | Serial.print(gps.satellites() == TinyGPS::GPS_INVALID_SATELLITES ? 0 : gps.satellites()); 52 | Serial.print(" PREC="); 53 | Serial.print(gps.hdop() == TinyGPS::GPS_INVALID_HDOP ? 0 : gps.hdop()); 54 | } 55 | 56 | gps.stats(&chars, &sentences, &failed); 57 | Serial.print(" CHARS="); 58 | Serial.print(chars); 59 | Serial.print(" SENTENCES="); 60 | Serial.print(sentences); 61 | Serial.print(" CSUM ERR="); 62 | Serial.println(failed); 63 | if (chars == 0) 64 | Serial.println("** No characters received from GPS: check wiring **"); 65 | } -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/LibAPRS/CRC-CCIT.c: -------------------------------------------------------------------------------- 1 | #include "CRC-CCIT.h" 2 | 3 | const uint16_t crc_ccit_table[256] PROGMEM = { 4 | 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf, 5 | 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7, 6 | 0x1081, 0x0108, 0x3393, 0x221a, 0x56a5, 0x472c, 0x75b7, 0x643e, 7 | 0x9cc9, 0x8d40, 0xbfdb, 0xae52, 0xdaed, 0xcb64, 0xf9ff, 0xe876, 8 | 0x2102, 0x308b, 0x0210, 0x1399, 0x6726, 0x76af, 0x4434, 0x55bd, 9 | 0xad4a, 0xbcc3, 0x8e58, 0x9fd1, 0xeb6e, 0xfae7, 0xc87c, 0xd9f5, 10 | 0x3183, 0x200a, 0x1291, 0x0318, 0x77a7, 0x662e, 0x54b5, 0x453c, 11 | 0xbdcb, 0xac42, 0x9ed9, 0x8f50, 0xfbef, 0xea66, 0xd8fd, 0xc974, 12 | 0x4204, 0x538d, 0x6116, 0x709f, 0x0420, 0x15a9, 0x2732, 0x36bb, 13 | 0xce4c, 0xdfc5, 0xed5e, 0xfcd7, 0x8868, 0x99e1, 0xab7a, 0xbaf3, 14 | 0x5285, 0x430c, 0x7197, 0x601e, 0x14a1, 0x0528, 0x37b3, 0x263a, 15 | 0xdecd, 0xcf44, 0xfddf, 0xec56, 0x98e9, 0x8960, 0xbbfb, 0xaa72, 16 | 0x6306, 0x728f, 0x4014, 0x519d, 0x2522, 0x34ab, 0x0630, 0x17b9, 17 | 0xef4e, 0xfec7, 0xcc5c, 0xddd5, 0xa96a, 0xb8e3, 0x8a78, 0x9bf1, 18 | 0x7387, 0x620e, 0x5095, 0x411c, 0x35a3, 0x242a, 0x16b1, 0x0738, 19 | 0xffcf, 0xee46, 0xdcdd, 0xcd54, 0xb9eb, 0xa862, 0x9af9, 0x8b70, 20 | 0x8408, 0x9581, 0xa71a, 0xb693, 0xc22c, 0xd3a5, 0xe13e, 0xf0b7, 21 | 0x0840, 0x19c9, 0x2b52, 0x3adb, 0x4e64, 0x5fed, 0x6d76, 0x7cff, 22 | 0x9489, 0x8500, 0xb79b, 0xa612, 0xd2ad, 0xc324, 0xf1bf, 0xe036, 23 | 0x18c1, 0x0948, 0x3bd3, 0x2a5a, 0x5ee5, 0x4f6c, 0x7df7, 0x6c7e, 24 | 0xa50a, 0xb483, 0x8618, 0x9791, 0xe32e, 0xf2a7, 0xc03c, 0xd1b5, 25 | 0x2942, 0x38cb, 0x0a50, 0x1bd9, 0x6f66, 0x7eef, 0x4c74, 0x5dfd, 26 | 0xb58b, 0xa402, 0x9699, 0x8710, 0xf3af, 0xe226, 0xd0bd, 0xc134, 27 | 0x39c3, 0x284a, 0x1ad1, 0x0b58, 0x7fe7, 0x6e6e, 0x5cf5, 0x4d7c, 28 | 0xc60c, 0xd785, 0xe51e, 0xf497, 0x8028, 0x91a1, 0xa33a, 0xb2b3, 29 | 0x4a44, 0x5bcd, 0x6956, 0x78df, 0x0c60, 0x1de9, 0x2f72, 0x3efb, 30 | 0xd68d, 0xc704, 0xf59f, 0xe416, 0x90a9, 0x8120, 0xb3bb, 0xa232, 31 | 0x5ac5, 0x4b4c, 0x79d7, 0x685e, 0x1ce1, 0x0d68, 0x3ff3, 0x2e7a, 32 | 0xe70e, 0xf687, 0xc41c, 0xd595, 0xa12a, 0xb0a3, 0x8238, 0x93b1, 33 | 0x6b46, 0x7acf, 0x4854, 0x59dd, 0x2d62, 0x3ceb, 0x0e70, 0x1ff9, 34 | 0xf78f, 0xe606, 0xd49d, 0xc514, 0xb1ab, 0xa022, 0x92b9, 0x8330, 35 | 0x7bc7, 0x6a4e, 0x58d5, 0x495c, 0x3de3, 0x2c6a, 0x1ef1, 0x0f78, 36 | }; -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/utility/u8g_com_raspberrypi_hw_spi.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_com_raspberrypi_hw_spi.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2012, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | Assumes, that 36 | MOSI is at PORTB, Pin 3 37 | and 38 | SCK is at PORTB, Pin 5 39 | 40 | Update for ATOMIC operation done (01 Jun 2013) 41 | U8G_ATOMIC_OR(ptr, val) 42 | U8G_ATOMIC_AND(ptr, val) 43 | U8G_ATOMIC_START() 44 | U8G_ATOMIC_END() 45 | 46 | 47 | 48 | */ 49 | 50 | #include "u8g.h" 51 | 52 | 53 | 54 | #if defined(U8G_RASPBERRY_PI) 55 | 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | 62 | uint8_t u8g_com_raspberrypi_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 63 | { 64 | switch(msg) 65 | { 66 | case U8G_COM_MSG_STOP: 67 | break; 68 | 69 | case U8G_COM_MSG_INIT: 70 | // check wiringPi setup 71 | if (wiringPiSetup() == -1) 72 | { 73 | printf("wiringPi-Error\n"); 74 | exit(1); 75 | } 76 | 77 | if (wiringPiSPISetup (0, 100000) < 0) 78 | { 79 | printf ("Unable to open SPI device 0: %s\n", strerror (errno)) ; 80 | exit (1) ; 81 | } 82 | 83 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 84 | u8g_SetPIOutput(u8g, U8G_PI_A0); 85 | 86 | break; 87 | 88 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 89 | u8g_SetPILevel(u8g, U8G_PI_A0, arg_val); 90 | break; 91 | 92 | case U8G_COM_MSG_CHIP_SELECT: 93 | /* Done by the SPI hardware */ 94 | break; 95 | 96 | case U8G_COM_MSG_RESET: 97 | u8g_SetPILevel(u8g, U8G_PI_RESET, arg_val); 98 | break; 99 | 100 | case U8G_COM_MSG_WRITE_BYTE: 101 | wiringPiSPIDataRW (0, &arg_val, 1) ; 102 | break; 103 | 104 | case U8G_COM_MSG_WRITE_SEQ: 105 | wiringPiSPIDataRW (0, arg_ptr, arg_val); 106 | break; 107 | 108 | case U8G_COM_MSG_WRITE_SEQ_P: 109 | wiringPiSPIDataRW (0, arg_ptr, arg_val); 110 | break; 111 | } 112 | return 1; 113 | } 114 | 115 | #else 116 | 117 | uint8_t u8g_com_raspberrypi_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 118 | { 119 | return 1; 120 | } 121 | 122 | #endif 123 | 124 | 125 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/license.txt: -------------------------------------------------------------------------------- 1 | 2 | The U8glib code (http://code.google.com/p/u8glib/) is licensed under the terms of 3 | the new-bsd license (two-clause bsd license). 4 | See also: http://www.opensource.org/licenses/bsd-license.php 5 | 6 | The repository and optionally the releases contain icons, which are 7 | derived from the WPZOOM Developer Icon Set: 8 | http://www.wpzoom.com/wpzoom/new-freebie-wpzoom-developer-icon-set-154-free-icons/ 9 | WPZOOM Developer Icon Set by WPZOOM is licensed under a Creative Commons 10 | Attribution-ShareAlike 3.0 Unported License. 11 | 12 | Fonts are licensed under different conditions. 13 | See http://code.google.com/p/u8glib/wiki/fontgroup for 14 | detailed information on the licensing conditions for each font. 15 | 16 | ============ X11 Fonts COUR, HELV, NCEN, TIM, SYMB ============ 17 | 18 | For fonts derived from the following files, the license below applies. 19 | COURB08.BDF COURB10.BDF COURB12.BDF COURB14.BDF COURB18.BDF 20 | COURB24.BDF COURR08.BDF COURR10.BDF COURR12.BDF COURR14.BDF 21 | COURR18.BDF COURR24.BDF HELVB08.BDF HELVB10.BDF HELVB12.BDF HELVB14.BDF 22 | HELVB18.BDF HELVB24.BDF HELVR08.BDF HELVR10.BDF HELVR12.BDF HELVR14.BDF 23 | HELVR18.BDF HELVR24.BDF NCENB08.BDF NCENB10.BDF NCENB12.BDF 24 | NCENB14.BDF NCENB18.BDF NCENB24.BDF NCENR08.BDF NCENR10.BDF 25 | NCENR12.BDF NCENR14.BDF NCENR18.BDF NCENR24.BDF SYMB08.BDF SYMB10.BDF 26 | SYMB12.BDF SYMB14.BDF SYMB18.BDF SYMB24.BDF TIMB08.BDF TIMB10.BDF 27 | TIMB12.BDF TIMB14.BDF TIMB18.BDF TIMB24.BDF TIMR08.BDF TIMR10.BDF 28 | TIMR12.BDF TIMR14.BDF TIMR18.BDF TIMR24.BDF 29 | 30 | Copyright 1984-1989, 1994 Adobe Systems Incorporated. 31 | Copyright 1988, 1994 Digital Equipment Corporation. 32 | 33 | Adobe is a trademark of Adobe Systems Incorporated which may be 34 | registered in certain jurisdictions. 35 | Permission to use these trademarks is hereby granted only in 36 | association with the images described in this file. 37 | 38 | Permission to use, copy, modify, distribute and sell this software 39 | and its documentation for any purpose and without fee is hereby 40 | granted, provided that the above copyright notices appear in all 41 | copies and that both those copyright notices and this permission 42 | notice appear in supporting documentation, and that the names of 43 | Adobe Systems and Digital Equipment Corporation not be used in 44 | advertising or publicity pertaining to distribution of the software 45 | without specific, written prior permission. Adobe Systems and 46 | Digital Equipment Corporation make no representations about the 47 | suitability of this software for any purpose. It is provided "as 48 | is" without express or implied warranty. 49 | 50 | 51 | ============ BSD License for U8glib Code ============ 52 | 53 | Universal 8bit Graphics Library (http://code.google.com/p/u8glib/) 54 | 55 | Copyright (c) 2011, olikraus@gmail.com 56 | All rights reserved. 57 | 58 | Redistribution and use in source and binary forms, with or without modification, 59 | are permitted provided that the following conditions are met: 60 | 61 | * Redistributions of source code must retain the above copyright notice, this list 62 | of conditions and the following disclaimer. 63 | 64 | * Redistributions in binary form must reproduce the above copyright notice, this 65 | list of conditions and the following disclaimer in the documentation and/or other 66 | materials provided with the distribution. 67 | 68 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 69 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 70 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 71 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 72 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 73 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 74 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 75 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 76 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 77 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 78 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 79 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 80 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 81 | 82 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/examples/A2Printer/A2Printer.ino: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | A2Printer.pde 4 | 5 | Special example code for the A2 Mciro Printer (https://www.sparkfun.com/products/10438) 6 | 7 | 8 | Universal 8bit Graphics Library, http://code.google.com/p/u8glib/ 9 | 10 | Copyright (c) 2013, olikraus@gmail.com 11 | All rights reserved. 12 | 13 | Redistribution and use in source and binary forms, with or without modification, 14 | are permitted provided that the following conditions are met: 15 | 16 | * Redistributions of source code must retain the above copyright notice, this list 17 | of conditions and the following disclaimer. 18 | 19 | * Redistributions in binary form must reproduce the above copyright notice, this 20 | list of conditions and the following disclaimer in the documentation and/or other 21 | materials provided with the distribution. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 24 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 25 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 27 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 29 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 30 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 33 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 35 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 | 37 | */ 38 | 39 | 40 | #include "U8glib.h" 41 | 42 | // use this serial interface 43 | #define PRINTER_SERIAL Serial 44 | // #define PRINTER_SERIAL Serial1 45 | 46 | 47 | uint8_t u8g_com_uart(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 48 | switch(msg) { 49 | case U8G_COM_MSG_WRITE_BYTE: 50 | PRINTER_SERIAL.write(arg_val); 51 | break; 52 | } 53 | return 1; 54 | } 55 | 56 | // setup u8g object, please remove comment from one of the following constructor calls 57 | 58 | // half resolution 59 | //U8GLIB u8g(&u8g_dev_a2_micro_printer_192x120_ds, (u8g_com_fnptr)u8g_com_uart); 60 | 61 | // full resolution, requires to uncomment U8G_16BIT in u8g.h 62 | //U8GLIB u8g(&u8g_dev_a2_micro_printer_384x240, (u8g_com_fnptr)u8g_com_uart); 63 | 64 | // half resolution, extra log, requires to uncomment U8G_16BIT in u8g.h 65 | //U8GLIB u8g(&u8g_dev_a2_micro_printer_192x360_ds, (u8g_com_fnptr)u8g_com_uart); 66 | U8GLIB u8g(&u8g_dev_a2_micro_printer_192x720_ds, (u8g_com_fnptr)u8g_com_uart); 67 | 68 | 69 | 70 | void drawLogo(uint8_t d) { 71 | u8g.setFont(u8g_font_gdr25r); 72 | u8g.drawStr(0+d, 30+d, "U"); 73 | u8g.setFont(u8g_font_gdr30n); 74 | u8g.drawStr90(23+d,10+d,"8"); 75 | u8g.setFont(u8g_font_gdr25r); 76 | u8g.drawStr(53+d,30+d,"g"); 77 | 78 | u8g.drawHLine(2+d, 35+d, 47); 79 | u8g.drawVLine(45+d, 32+d, 12); 80 | } 81 | 82 | void drawURL(void) { 83 | u8g.setFont(u8g_font_4x6); 84 | if ( u8g.getHeight() < 59 ) { 85 | u8g.drawStr(53,9,"code.google.com"); 86 | u8g.drawStr(77,18,"/p/u8glib"); 87 | } 88 | else { 89 | u8g.drawStr(1,54,"code.google.com/p/u8glib"); 90 | } 91 | } 92 | 93 | void draw(void) { 94 | // graphic commands to redraw the complete screen should be placed here 95 | 96 | drawLogo(0); 97 | drawURL(); 98 | u8g.drawFrame(0,0,u8g.getWidth(), u8g.getHeight()); 99 | 100 | u8g.setFont(u8g_font_helvR24r); 101 | u8g.setPrintPos(0, 100); 102 | u8g.print(u8g.getWidth(), DEC); 103 | u8g.print("x"); 104 | u8g.print(u8g.getHeight(), DEC); 105 | } 106 | 107 | void setup(void) { 108 | PRINTER_SERIAL.begin(19200); 109 | 110 | // flip screen, if required 111 | // u8g.setRot180(); 112 | 113 | // assign default color value 114 | u8g.setColorIndex(1); // pixel on 115 | } 116 | 117 | void loop(void) { 118 | 119 | // picture loop: This will print the picture 120 | u8g.firstPage(); 121 | do { 122 | draw(); 123 | } while( u8g.nextPage() ); 124 | 125 | // send manual CR to the printer 126 | PRINTER_SERIAL.write('\n'); 127 | 128 | // reprint the picture after 10 seconds 129 | delay(10000); 130 | } 131 | 132 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/utility/u8g_dev_uc1611_dogm240.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_uc1611_dogm240.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2014, dev.menges.jonas@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | */ 36 | 37 | #include "u8g.h" 38 | 39 | 40 | #define WIDTH 240 41 | #define HEIGHT 64 42 | #define PAGE_HEIGHT 8 43 | 44 | 45 | static const uint8_t u8g_dev_uc1611_dogm240_init_seq[] PROGMEM = { 46 | U8G_ESC_CS(1), // enable chip 47 | U8G_ESC_ADR(0), // instruction mode 48 | 0xF1, // set last COM electrode 49 | 0x3F, // 64-1=63 50 | 0xF2, // set display start line 51 | 0x00, // 0 52 | 0xF3, // set display end line 53 | 0x3F, // 64-1=63 54 | 0x81, // set contrast (0-255) 55 | 0xB7, // 183 56 | 0xC0, // set view 57 | //0x04, // topview 58 | 0x02, // bottomview 59 | 0xA3, // set line rate (9.4k) 60 | 0xE9, // set bias ratio (10) 61 | 0xA9, // enable display 62 | 0xD1, // set black and white mode 63 | U8G_ESC_CS(0), // disable chip 64 | U8G_ESC_END // end of sequence 65 | }; 66 | 67 | static void setPage(u8g_t *u8g, u8g_dev_t *dev, unsigned char page) 68 | { 69 | u8g_WriteByte(u8g, dev, 0x70); 70 | u8g_WriteByte(u8g, dev, 0x60 + (page&0x0F)); 71 | } 72 | 73 | static const uint8_t u8g_dev_uc1611_dogm240_data_start[] PROGMEM = { 74 | U8G_ESC_ADR(0), /* instruction mode */ 75 | U8G_ESC_CS(1), /* enable chip */ 76 | 0x10, /* set upper 4 bit of the col adr to 0 */ 77 | 0x00, /* set lower 4 bit of the col adr to 0 */ 78 | U8G_ESC_END /* end of sequence */ 79 | }; 80 | 81 | uint8_t u8g_dev_uc1611_dogm240_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 82 | { 83 | switch(msg) 84 | { 85 | case U8G_DEV_MSG_INIT: 86 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS); 87 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogm240_init_seq); 88 | break; 89 | case U8G_DEV_MSG_STOP: 90 | break; 91 | case U8G_DEV_MSG_PAGE_NEXT: 92 | { 93 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 94 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogm240_data_start); 95 | setPage(u8g, dev, pb->p.page); /* select current page (uc1611) */ 96 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 97 | if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 ) 98 | return 0; 99 | u8g_SetChipSelect(u8g, dev, 1); 100 | } 101 | break; 102 | case U8G_DEV_MSG_CONTRAST: 103 | u8g_SetChipSelect(u8g, dev, 0); 104 | u8g_SetAddress(u8g, dev, 0); /* instruction mode */ 105 | u8g_WriteByte(u8g, dev, 0x81); 106 | u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2); /* set contrast from, keep gain at 0 */ 107 | u8g_SetChipSelect(u8g, dev, 1); 108 | return 1; 109 | } 110 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 111 | } 112 | 113 | U8G_PB_DEV(u8g_dev_uc1611_dogm240_i2c , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogm240_fn, U8G_COM_UC_I2C); 114 | U8G_PB_DEV(u8g_dev_uc1611_dogm240_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogm240_fn, U8G_COM_SW_SPI); 115 | U8G_PB_DEV(u8g_dev_uc1611_dogm240_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogm240_fn, U8G_COM_HW_SPI); 116 | 117 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/utility/u8g_dev_uc1611_dogxl240.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_uc1611_dogxl240.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2014, dev.menges.jonas@gmail.com, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | */ 36 | 37 | #include "u8g.h" 38 | 39 | 40 | #define WIDTH 240 41 | #define HEIGHT 128 42 | #define PAGE_HEIGHT 8 43 | 44 | 45 | static const uint8_t u8g_dev_uc1611_dogxl240_init_seq[] PROGMEM = { 46 | U8G_ESC_CS(1), // enable chip 47 | U8G_ESC_ADR(0), // instruction mode 48 | 0xF1, // set last COM electrode 49 | 0x7F, // DOGXL240 50 | 0xF2, // set display start line 51 | 0x00, // 0 52 | 0xF3, // set display end line 53 | 0x7F, // DOGXL240 54 | 0x81, // set contrast (0-255) 55 | 0xAA, // DOGXL240 56 | 0xC0, // set view 57 | //0x04, // topview 58 | 0x02, // bottomview 59 | 0xA3, // set line rate (9.4k) 60 | 0xE9, // set bias ratio (10) 61 | 0xA9, // enable display 62 | 0xD1, // set black and white mode 63 | U8G_ESC_CS(0), // disable chip 64 | U8G_ESC_END // end of sequence 65 | }; 66 | 67 | static void u8g_dev_dogxl240_set_page(u8g_t *u8g, u8g_dev_t *dev, unsigned char page) 68 | { 69 | u8g_WriteByte(u8g, dev, 0x70); 70 | u8g_WriteByte(u8g, dev, 0x60 + (page&0x0F)); 71 | } 72 | 73 | static const uint8_t u8g_dev_uc1611_dogxl240_data_start[] PROGMEM = { 74 | U8G_ESC_ADR(0), /* instruction mode */ 75 | U8G_ESC_CS(1), /* enable chip */ 76 | 0x10, /* set upper 4 bit of the col adr to 0 */ 77 | 0x00, /* set lower 4 bit of the col adr to 0 */ 78 | U8G_ESC_END /* end of sequence */ 79 | }; 80 | 81 | static uint8_t u8g_dev_uc1611_dogxl240_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 82 | { 83 | switch(msg) 84 | { 85 | case U8G_DEV_MSG_INIT: 86 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS); 87 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogxl240_init_seq); 88 | break; 89 | case U8G_DEV_MSG_STOP: 90 | break; 91 | case U8G_DEV_MSG_PAGE_NEXT: 92 | { 93 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 94 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_uc1611_dogxl240_data_start); 95 | u8g_dev_dogxl240_set_page(u8g, dev, pb->p.page); /* select current page (uc1611) */ 96 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 97 | if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 ) 98 | return 0; 99 | u8g_SetChipSelect(u8g, dev, 1); 100 | } 101 | break; 102 | case U8G_DEV_MSG_CONTRAST: 103 | u8g_SetChipSelect(u8g, dev, 0); 104 | u8g_SetAddress(u8g, dev, 0); /* instruction mode */ 105 | u8g_WriteByte(u8g, dev, 0x81); 106 | u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2); /* set contrast from, keep gain at 0 */ 107 | u8g_SetChipSelect(u8g, dev, 1); 108 | return 1; 109 | } 110 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 111 | } 112 | 113 | U8G_PB_DEV(u8g_dev_uc1611_dogxl240_i2c , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogxl240_fn, U8G_COM_UC_I2C); 114 | U8G_PB_DEV(u8g_dev_uc1611_dogxl240_sw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogxl240_fn, U8G_COM_SW_SPI); 115 | U8G_PB_DEV(u8g_dev_uc1611_dogxl240_hw_spi , WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_uc1611_dogxl240_fn, U8G_COM_HW_SPI); 116 | 117 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 (U8G_RASPBERRY_PI) 111 | 112 | #include 113 | 114 | void u8g_backup_spi(uint8_t msg) { 115 | printf("u8g_backup_spi %d\r\n",msg); 116 | } 117 | 118 | #elif defined(ARDUINO) && defined(__SAM3X8E__) // Arduino Due, maybe we should better check for __SAM3X8E__ 119 | 120 | #include "sam.h" 121 | 122 | struct sam_backup_struct 123 | { 124 | uint32_t mr; 125 | uint32_t sr; 126 | uint32_t csr[4]; 127 | } sam_backup[2]; 128 | 129 | void u8g_backup_spi(uint8_t msg) 130 | { 131 | uint8_t idx = U8G_STATE_MSG_GET_IDX(msg); 132 | if ( U8G_STATE_MSG_IS_BACKUP(msg) ) 133 | { 134 | sam_backup[idx].mr = SPI0->SPI_MR; 135 | sam_backup[idx].sr = SPI0->SPI_SR; 136 | sam_backup[idx].csr[0] = SPI0->SPI_CSR[0]; 137 | sam_backup[idx].csr[1] = SPI0->SPI_CSR[1]; 138 | sam_backup[idx].csr[2] = SPI0->SPI_CSR[2]; 139 | sam_backup[idx].csr[3] = SPI0->SPI_CSR[3]; 140 | } 141 | else 142 | { 143 | SPI0->SPI_MR = sam_backup[idx].mr; 144 | SPI0->SPI_CSR[0] = sam_backup[idx].csr[0]; 145 | SPI0->SPI_CSR[1] = sam_backup[idx].csr[1]; 146 | SPI0->SPI_CSR[2] = sam_backup[idx].csr[2]; 147 | SPI0->SPI_CSR[3] = sam_backup[idx].csr[3]; 148 | } 149 | } 150 | 151 | #else 152 | 153 | void u8g_backup_spi(uint8_t msg) 154 | { 155 | } 156 | 157 | #endif 158 | 159 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/TinyGPS/examples/test_with_gps_device/test_with_gps_device.ino: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #include 4 | 5 | /* This sample code demonstrates the normal use of a TinyGPS object. 6 | It requires the use of SoftwareSerial, and assumes that you have a 7 | 4800-baud serial GPS device hooked up on pins 4(rx) and 3(tx). 8 | */ 9 | 10 | TinyGPS gps; 11 | SoftwareSerial ss(4, 3); 12 | 13 | static void smartdelay(unsigned long ms); 14 | static void print_float(float val, float invalid, int len, int prec); 15 | static void print_int(unsigned long val, unsigned long invalid, int len); 16 | static void print_date(TinyGPS &gps); 17 | static void print_str(const char *str, int len); 18 | 19 | void setup() 20 | { 21 | Serial.begin(115200); 22 | 23 | Serial.print("Testing TinyGPS library v. "); Serial.println(TinyGPS::library_version()); 24 | Serial.println("by Mikal Hart"); 25 | Serial.println(); 26 | Serial.println("Sats HDOP Latitude Longitude Fix Date Time Date Alt Course Speed Card Distance Course Card Chars Sentences Checksum"); 27 | Serial.println(" (deg) (deg) Age Age (m) --- from GPS ---- ---- to London ---- RX RX Fail"); 28 | Serial.println("-------------------------------------------------------------------------------------------------------------------------------------"); 29 | 30 | ss.begin(4800); 31 | } 32 | 33 | void loop() 34 | { 35 | float flat, flon; 36 | unsigned long age, date, time, chars = 0; 37 | unsigned short sentences = 0, failed = 0; 38 | static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002; 39 | 40 | print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 5); 41 | print_int(gps.hdop(), TinyGPS::GPS_INVALID_HDOP, 5); 42 | gps.f_get_position(&flat, &flon, &age); 43 | print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 10, 6); 44 | print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 11, 6); 45 | print_int(age, TinyGPS::GPS_INVALID_AGE, 5); 46 | print_date(gps); 47 | print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 7, 2); 48 | print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2); 49 | print_float(gps.f_speed_kmph(), TinyGPS::GPS_INVALID_F_SPEED, 6, 2); 50 | print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6); 51 | print_int(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0xFFFFFFFF : (unsigned long)TinyGPS::distance_between(flat, flon, LONDON_LAT, LONDON_LON) / 1000, 0xFFFFFFFF, 9); 52 | print_float(flat == TinyGPS::GPS_INVALID_F_ANGLE ? TinyGPS::GPS_INVALID_F_ANGLE : TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2); 53 | print_str(flat == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON)), 6); 54 | 55 | gps.stats(&chars, &sentences, &failed); 56 | print_int(chars, 0xFFFFFFFF, 6); 57 | print_int(sentences, 0xFFFFFFFF, 10); 58 | print_int(failed, 0xFFFFFFFF, 9); 59 | Serial.println(); 60 | 61 | smartdelay(1000); 62 | } 63 | 64 | static void smartdelay(unsigned long ms) 65 | { 66 | unsigned long start = millis(); 67 | do 68 | { 69 | while (ss.available()) 70 | gps.encode(ss.read()); 71 | } while (millis() - start < ms); 72 | } 73 | 74 | static void print_float(float val, float invalid, int len, int prec) 75 | { 76 | if (val == invalid) 77 | { 78 | while (len-- > 1) 79 | Serial.print('*'); 80 | Serial.print(' '); 81 | } 82 | else 83 | { 84 | Serial.print(val, prec); 85 | int vi = abs((int)val); 86 | int flen = prec + (val < 0.0 ? 2 : 1); // . and - 87 | flen += vi >= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1; 88 | for (int i=flen; i 0) 105 | sz[len-1] = ' '; 106 | Serial.print(sz); 107 | smartdelay(0); 108 | } 109 | 110 | static void print_date(TinyGPS &gps) 111 | { 112 | int year; 113 | byte month, day, hour, minute, second, hundredths; 114 | unsigned long age; 115 | gps.crack_datetime(&year, &month, &day, &hour, &minute, &second, &hundredths, &age); 116 | if (age == TinyGPS::GPS_INVALID_AGE) 117 | Serial.print("********** ******** "); 118 | else 119 | { 120 | char sz[32]; 121 | sprintf(sz, "%02d/%02d/%02d %02d:%02d:%02d ", 122 | month, day, year, hour, minute, second); 123 | Serial.print(sz); 124 | } 125 | print_int(age, TinyGPS::GPS_INVALID_AGE, 5); 126 | smartdelay(0); 127 | } 128 | 129 | static void print_str(const char *str, int len) 130 | { 131 | int slen = strlen(str); 132 | for (int i=0; idev_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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/utility/u8g_com_raspberrypi_ssd_i2c.c: -------------------------------------------------------------------------------- 1 | /* 2 | Special pin usage: 3 | U8G_PI_I2C_OPTION additional options 4 | U8G_PI_A0_STATE used to store the last value of the command/data register selection 5 | U8G_PI_SET_A0 1: Signal request to update I2C device with new A0_STATE, 0: Do nothing, A0_STATE matches I2C device 6 | U8G_PI_SCL clock line (NOT USED) 7 | U8G_PI_SDA data line (NOT USED) 8 | 9 | U8G_PI_RESET reset line (currently disabled, see below) 10 | 11 | Protocol: 12 | SLA, Cmd/Data Selection, Arguments 13 | The command/data register is selected by a special instruction byte, which is sent after SLA 14 | 15 | The continue bit is always 0 so that a (re)start is equired for the change from cmd to/data mode 16 | */ 17 | 18 | #include "u8g.h" 19 | 20 | #if defined(U8G_RASPBERRY_PI) 21 | 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | #define I2C_SLA 0x3c 29 | #define I2C_CMD_MODE 0x000 30 | #define I2C_DATA_MODE 0x040 31 | 32 | #if defined(U8G_WITH_PINLIST) 33 | 34 | uint8_t u8g_com_raspberrypi_ssd_start_sequence(u8g_t *u8g) 35 | { 36 | /* are we requested to set the a0 state? */ 37 | if ( u8g->pin_list[U8G_PI_SET_A0] == 0 ) 38 | return 1; 39 | 40 | /* setup bus, might be a repeated start */ 41 | if ( u8g_i2c_start(I2C_SLA) == 0 ) 42 | return 0; 43 | if ( u8g->pin_list[U8G_PI_A0_STATE] == 0 ) 44 | { 45 | if ( u8g_i2c_send_mode(I2C_CMD_MODE) == 0 ) 46 | return 0; 47 | } 48 | else 49 | { 50 | if ( u8g_i2c_send_mode(I2C_DATA_MODE) == 0 ) 51 | return 0; 52 | } 53 | 54 | 55 | u8g->pin_list[U8G_PI_SET_A0] = 0; 56 | return 1; 57 | } 58 | 59 | uint8_t u8g_com_raspberrypi_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 60 | { 61 | switch(msg) 62 | { 63 | case U8G_COM_MSG_INIT: 64 | u8g_i2c_init(u8g->pin_list[U8G_PI_I2C_OPTION]); 65 | u8g_SetPIOutput(u8g, U8G_PI_RESET); 66 | u8g_SetPIOutput(u8g, U8G_PI_A0); 67 | break; 68 | 69 | case U8G_COM_MSG_STOP: 70 | break; 71 | 72 | case U8G_COM_MSG_RESET: 73 | break; 74 | 75 | case U8G_COM_MSG_CHIP_SELECT: 76 | u8g->pin_list[U8G_PI_A0_STATE] = 0; 77 | u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again, also forces start condition */ 78 | if ( arg_val == 0 ) 79 | { 80 | /* disable chip, send stop condition */ 81 | u8g_i2c_stop(); 82 | } 83 | else 84 | { 85 | /* enable, do nothing: any byte writing will trigger the i2c start */ 86 | } 87 | break; 88 | 89 | case U8G_COM_MSG_WRITE_BYTE: 90 | //u8g->pin_list[U8G_PI_SET_A0] = 1; 91 | if ( u8g_com_raspberrypi_ssd_start_sequence(u8g) == 0 ) 92 | return u8g_i2c_stop(), 0; 93 | if ( u8g_i2c_send_byte(arg_val) == 0 ) 94 | return u8g_i2c_stop(), 0; 95 | // u8g_i2c_stop(); 96 | break; 97 | 98 | case U8G_COM_MSG_WRITE_SEQ: 99 | //u8g->pin_list[U8G_PI_SET_A0] = 1; 100 | if ( u8g_com_raspberrypi_ssd_start_sequence(u8g) == 0 ) 101 | return u8g_i2c_stop(), 0; 102 | { 103 | register uint8_t *ptr = (uint8_t *)arg_ptr; 104 | while( arg_val > 0 ) 105 | { 106 | if ( u8g_i2c_send_byte(*ptr++) == 0 ) 107 | return u8g_i2c_stop(), 0; 108 | arg_val--; 109 | } 110 | } 111 | // u8g_i2c_stop(); 112 | break; 113 | 114 | case U8G_COM_MSG_WRITE_SEQ_P: 115 | //u8g->pin_list[U8G_PI_SET_A0] = 1; 116 | if ( u8g_com_raspberrypi_ssd_start_sequence(u8g) == 0 ) 117 | return u8g_i2c_stop(), 0; 118 | { 119 | register uint8_t *ptr = (uint8_t *)arg_ptr; 120 | while( arg_val > 0 ) 121 | { 122 | if ( u8g_i2c_send_byte(u8g_pgm_read(ptr)) == 0 ) 123 | return 0; 124 | ptr++; 125 | arg_val--; 126 | } 127 | } 128 | // u8g_i2c_stop(); 129 | break; 130 | 131 | case U8G_COM_MSG_ADDRESS: /* define cmd (arg_val = 0) or data mode (arg_val = 1) */ 132 | u8g->pin_list[U8G_PI_A0_STATE] = arg_val; 133 | u8g->pin_list[U8G_PI_SET_A0] = 1; /* force a0 to set again */ 134 | 135 | #ifdef OLD_CODE 136 | if ( i2c_state != 0 ) 137 | { 138 | u8g_i2c_stop(); 139 | i2c_state = 0; 140 | } 141 | 142 | if ( u8g_com_raspberrypi_ssd_start_sequence(arg_val) == 0 ) 143 | return 0; 144 | 145 | /* setup bus, might be a repeated start */ 146 | /* 147 | if ( u8g_i2c_start(I2C_SLA) == 0 ) 148 | return 0; 149 | if ( arg_val == 0 ) 150 | { 151 | i2c_state = 1; 152 | 153 | if ( u8g_i2c_send_byte(I2C_CMD_MODE) == 0 ) 154 | return 0; 155 | } 156 | else 157 | { 158 | i2c_state = 2; 159 | if ( u8g_i2c_send_byte(I2C_DATA_MODE) == 0 ) 160 | return 0; 161 | } 162 | */ 163 | #endif 164 | break; 165 | } 166 | return 1; 167 | } 168 | 169 | #else /* defined(U8G_WITH_PINLIST) */ 170 | 171 | uint8_t u8g_com_raspberrypi_ssd_i2c_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) { 172 | return 1; 173 | } 174 | 175 | #endif /* defined(U8G_WITH_PINLIST) */ 176 | #endif 177 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 ) 158 | { 159 | u8g_atmega_spi_out(*ptr++); 160 | arg_val--; 161 | } 162 | } 163 | break; 164 | case U8G_COM_MSG_WRITE_SEQ_P: 165 | { 166 | register uint8_t *ptr = arg_ptr; 167 | while( arg_val > 0 ) 168 | { 169 | u8g_atmega_spi_out(u8g_pgm_read(ptr)); 170 | ptr++; 171 | arg_val--; 172 | } 173 | } 174 | break; 175 | } 176 | return 1; 177 | } 178 | 179 | #else 180 | 181 | uint8_t u8g_com_atmega_hw_spi_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 182 | { 183 | return 1; 184 | } 185 | 186 | #endif 187 | 188 | 189 | -------------------------------------------------------------------------------- /Arduino/libraries/LibAPRS/AX25.cpp: -------------------------------------------------------------------------------- 1 | // Based on work by Francesco Sacchi 2 | 3 | #include "Arduino.h" 4 | #include 5 | #include 6 | #include "AX25.h" 7 | #include "HDLC.h" 8 | #include "CRC-CCIT.h" 9 | #include "AFSK.h" 10 | 11 | #define countof(a) sizeof(a)/sizeof(a[0]) 12 | #define MIN(a,b) ({ typeof(a) _a = (a); typeof(b) _b = (b); ((typeof(_a))((_a < _b) ? _a : _b)); }) 13 | #define DECODE_CALL(buf, addr) for (unsigned i = 0; i < sizeof((addr))-CALL_OVERSPACE; i++) { char c = (*(buf)++ >> 1); (addr)[i] = (c == ' ') ? '\x0' : c; } 14 | #define AX25_SET_REPEATED(msg, idx, val) do { if (val) { (msg)->rpt_flags |= _BV(idx); } else { (msg)->rpt_flags &= ~_BV(idx) ; } } while(0) 15 | 16 | extern int LibAPRS_vref; 17 | extern bool LibAPRS_open_squelch; 18 | 19 | void ax25_init(AX25Ctx *ctx, ax25_callback_t hook) { 20 | memset(ctx, 0, sizeof(*ctx)); 21 | ctx->hook = hook; 22 | ctx->crc_in = ctx->crc_out = CRC_CCIT_INIT_VAL; 23 | } 24 | 25 | static void ax25_decode(AX25Ctx *ctx) { 26 | AX25Msg msg; 27 | uint8_t *buf = ctx->buf; 28 | 29 | DECODE_CALL(buf, msg.dst.call); 30 | msg.dst.ssid = (*buf++ >> 1) & 0x0F; 31 | msg.dst.call[6] = 0; 32 | 33 | DECODE_CALL(buf, msg.src.call); 34 | msg.src.ssid = (*buf >> 1) & 0x0F; 35 | msg.src.call[6] = 0; 36 | 37 | for (msg.rpt_count = 0; !(*buf++ & 0x01) && (msg.rpt_count < countof(msg.rpt_list)); msg.rpt_count++) { 38 | DECODE_CALL(buf, msg.rpt_list[msg.rpt_count].call); 39 | msg.rpt_list[msg.rpt_count].ssid = (*buf >> 1) & 0x0F; 40 | AX25_SET_REPEATED(&msg, msg.rpt_count, (*buf & 0x80)); 41 | } 42 | 43 | msg.ctrl = *buf++; 44 | if (msg.ctrl != AX25_CTRL_UI) { return; } 45 | 46 | msg.pid = *buf++; 47 | if (msg.pid != AX25_PID_NOLAYER3) { return; } 48 | 49 | msg.len = ctx->frame_len - 2 - (buf - ctx->buf); 50 | msg.info = buf; 51 | 52 | if (ctx->hook) { 53 | cli(); 54 | ctx->hook(&msg); 55 | sei(); 56 | } 57 | 58 | } 59 | 60 | void ax25_poll(AX25Ctx *ctx) { 61 | int c; 62 | 63 | while ((c = afsk_getchar()) != EOF) { 64 | if (!ctx->escape && c == HDLC_FLAG) { 65 | if (ctx->frame_len >= AX25_MIN_FRAME_LEN) { 66 | if (ctx->crc_in == AX25_CRC_CORRECT) { 67 | if(LibAPRS_open_squelch) { 68 | LED_RX_ON(); 69 | } 70 | ax25_decode(ctx); 71 | } 72 | } 73 | ctx->sync = true; 74 | ctx->crc_in = CRC_CCIT_INIT_VAL; 75 | ctx->frame_len = 0; 76 | continue; 77 | } 78 | 79 | if (!ctx->escape && c == HDLC_RESET) { 80 | ctx->sync = false; 81 | continue; 82 | } 83 | 84 | if (!ctx->escape && c == AX25_ESC) { 85 | ctx->escape = true; 86 | continue; 87 | } 88 | 89 | if (ctx->sync) { 90 | if (ctx->frame_len < AX25_MAX_FRAME_LEN) { 91 | ctx->buf[ctx->frame_len++] = c; 92 | ctx->crc_in = update_crc_ccit(c, ctx->crc_in); 93 | } else { 94 | ctx->sync = false; 95 | } 96 | } 97 | ctx->escape = false; 98 | } 99 | } 100 | 101 | static void ax25_putchar(AX25Ctx *ctx, uint8_t c) 102 | { 103 | if (c == HDLC_FLAG || c == HDLC_RESET || c == AX25_ESC) afsk_putchar(AX25_ESC); 104 | ctx->crc_out = update_crc_ccit(c, ctx->crc_out); 105 | afsk_putchar(c); 106 | } 107 | 108 | void ax25_sendRaw(AX25Ctx *ctx, void *_buf, size_t len) { 109 | ctx->crc_out = CRC_CCIT_INIT_VAL; 110 | afsk_putchar(HDLC_FLAG); 111 | const uint8_t *buf = (const uint8_t *)_buf; 112 | while (len--) ax25_putchar(ctx, *buf++); 113 | 114 | uint8_t crcl = (ctx->crc_out & 0xff) ^ 0xff; 115 | uint8_t crch = (ctx->crc_out >> 8) ^ 0xff; 116 | ax25_putchar(ctx, crcl); 117 | ax25_putchar(ctx, crch); 118 | 119 | afsk_putchar(HDLC_FLAG); 120 | } 121 | 122 | static void ax25_sendCall(AX25Ctx *ctx, const AX25Call *addr, bool last){ 123 | unsigned len = MIN((sizeof(addr->call) - CALL_OVERSPACE), strlen(addr->call)); 124 | 125 | for (unsigned i = 0; i < len; i++) { 126 | uint8_t c = addr->call[i]; 127 | c = toupper(c); 128 | ax25_putchar(ctx, c << 1); 129 | } 130 | 131 | if (len < (sizeof(addr->call) - CALL_OVERSPACE)) { 132 | for (unsigned i = 0; i < (sizeof(addr->call) - CALL_OVERSPACE) - len; i++) { 133 | ax25_putchar(ctx, ' ' << 1); 134 | } 135 | } 136 | 137 | uint8_t ssid = 0x60 | (addr->ssid << 1) | (last ? 0x01 : 0); 138 | ax25_putchar(ctx, ssid); 139 | } 140 | 141 | void ax25_sendVia(AX25Ctx *ctx, const AX25Call *path, size_t path_len, const void *_buf, size_t len) { 142 | const uint8_t *buf = (const uint8_t *)_buf; 143 | 144 | ctx->crc_out = CRC_CCIT_INIT_VAL; 145 | afsk_putchar(HDLC_FLAG); 146 | 147 | for (size_t i = 0; i < path_len; i++) { 148 | ax25_sendCall(ctx, &path[i], (i == path_len - 1)); 149 | } 150 | 151 | ax25_putchar(ctx, AX25_CTRL_UI); 152 | ax25_putchar(ctx, AX25_PID_NOLAYER3); 153 | 154 | while (len--) { 155 | ax25_putchar(ctx, *buf++); 156 | } 157 | 158 | uint8_t crcl = (ctx->crc_out & 0xff) ^ 0xff; 159 | uint8_t crch = (ctx->crc_out >> 8) ^ 0xff; 160 | ax25_putchar(ctx, crcl); 161 | ax25_putchar(ctx, crch); 162 | 163 | afsk_putchar(HDLC_FLAG); 164 | } 165 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 */ -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/TinyGPS/TinyGPS.h: -------------------------------------------------------------------------------- 1 | /* 2 | TinyGPS - a small GPS library for Arduino providing basic NMEA parsing 3 | Based on work by and "distance_to" and "course_to" courtesy of Maarten Lamers. 4 | Suggestion to add satellites(), course_to(), and cardinal(), by Matt Monson. 5 | Precision improvements suggested by Wayne Holder. 6 | Copyright (C) 2008-2013 Mikal Hart 7 | All rights reserved. 8 | 9 | This library is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Lesser General Public 11 | License as published by the Free Software Foundation; either 12 | version 2.1 of the License, or (at your option) any later version. 13 | 14 | This library is distributed in the hope that it will be useful, 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 17 | Lesser General Public License for more details. 18 | 19 | You should have received a copy of the GNU Lesser General Public 20 | License along with this library; if not, write to the Free Software 21 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 22 | */ 23 | 24 | #ifndef TinyGPS_h 25 | #define TinyGPS_h 26 | 27 | #if defined(ARDUINO) && ARDUINO >= 100 28 | #include "Arduino.h" 29 | #else 30 | #include "WProgram.h" 31 | #endif 32 | 33 | #include 34 | 35 | #define _GPS_VERSION 13 // software version of this library 36 | #define _GPS_MPH_PER_KNOT 1.15077945 37 | #define _GPS_MPS_PER_KNOT 0.51444444 38 | #define _GPS_KMPH_PER_KNOT 1.852 39 | #define _GPS_MILES_PER_METER 0.00062137112 40 | #define _GPS_KM_PER_METER 0.001 41 | // #define _GPS_NO_STATS 42 | 43 | class TinyGPS 44 | { 45 | public: 46 | enum { 47 | GPS_INVALID_AGE = 0xFFFFFFFF, GPS_INVALID_ANGLE = 999999999, 48 | GPS_INVALID_ALTITUDE = 999999999, GPS_INVALID_DATE = 0, 49 | GPS_INVALID_TIME = 0xFFFFFFFF, GPS_INVALID_SPEED = 999999999, 50 | GPS_INVALID_FIX_TIME = 0xFFFFFFFF, GPS_INVALID_SATELLITES = 0xFF, 51 | GPS_INVALID_HDOP = 0xFFFFFFFF 52 | }; 53 | 54 | static const float GPS_INVALID_F_ANGLE, GPS_INVALID_F_ALTITUDE, GPS_INVALID_F_SPEED; 55 | 56 | TinyGPS(); 57 | bool encode(char c); // process one character received from GPS 58 | TinyGPS &operator << (char c) {encode(c); return *this;} 59 | 60 | // lat/long in MILLIONTHs of a degree and age of fix in milliseconds 61 | // (note: versions 12 and earlier gave lat/long in 100,000ths of a degree. 62 | void get_position(long *latitude, long *longitude, unsigned long *fix_age = 0); 63 | 64 | // date as ddmmyy, time as hhmmsscc, and age in milliseconds 65 | void get_datetime(unsigned long *date, unsigned long *time, unsigned long *age = 0); 66 | 67 | // signed altitude in centimeters (from GPGGA sentence) 68 | inline long altitude() { return _altitude; } 69 | 70 | // course in last full GPRMC sentence in 100th of a degree 71 | inline unsigned long course() { return _course; } 72 | 73 | // speed in last full GPRMC sentence in 100ths of a knot 74 | inline unsigned long speed() { return _speed; } 75 | 76 | // satellites used in last full GPGGA sentence 77 | inline unsigned short satellites() { return _numsats; } 78 | 79 | // horizontal dilution of precision in 100ths 80 | inline unsigned long hdop() { return _hdop; } 81 | 82 | void f_get_position(float *latitude, float *longitude, unsigned long *fix_age = 0); 83 | void crack_datetime(int *year, byte *month, byte *day, 84 | byte *hour, byte *minute, byte *second, byte *hundredths = 0, unsigned long *fix_age = 0); 85 | float f_altitude(); 86 | float f_course(); 87 | float f_speed_knots(); 88 | float f_speed_mph(); 89 | float f_speed_mps(); 90 | float f_speed_kmph(); 91 | 92 | static int library_version() { return _GPS_VERSION; } 93 | 94 | static float distance_between (float lat1, float long1, float lat2, float long2); 95 | static float course_to (float lat1, float long1, float lat2, float long2); 96 | static const char *cardinal(float course); 97 | 98 | #ifndef _GPS_NO_STATS 99 | void stats(unsigned long *chars, unsigned short *good_sentences, unsigned short *failed_cs); 100 | #endif 101 | 102 | private: 103 | enum {_GPS_SENTENCE_GPGGA, _GPS_SENTENCE_GPRMC, _GPS_SENTENCE_OTHER}; 104 | 105 | // properties 106 | unsigned long _time, _new_time; 107 | unsigned long _date, _new_date; 108 | long _latitude, _new_latitude; 109 | long _longitude, _new_longitude; 110 | long _altitude, _new_altitude; 111 | unsigned long _speed, _new_speed; 112 | unsigned long _course, _new_course; 113 | unsigned long _hdop, _new_hdop; 114 | unsigned short _numsats, _new_numsats; 115 | 116 | unsigned long _last_time_fix, _new_time_fix; 117 | unsigned long _last_position_fix, _new_position_fix; 118 | 119 | // parsing state variables 120 | byte _parity; 121 | bool _is_checksum_term; 122 | char _term[15]; 123 | byte _sentence_type; 124 | byte _term_number; 125 | byte _term_offset; 126 | bool _gps_data_good; 127 | 128 | #ifndef _GPS_NO_STATS 129 | // statistics 130 | unsigned long _encoded_characters; 131 | unsigned short _good_sentences; 132 | unsigned short _failed_checksum; 133 | unsigned short _passed_checksum; 134 | #endif 135 | 136 | // internal utilities 137 | int from_hex(char a); 138 | unsigned long parse_decimal(); 139 | unsigned long parse_degrees(); 140 | bool term_complete(); 141 | bool gpsisdigit(char c) { return c >= '0' && c <= '9'; } 142 | long gpsatol(const char *str); 143 | int gpsstrcmp(const char *str1, const char *str2); 144 | }; 145 | 146 | #if !defined(ARDUINO) 147 | // Arduino 0012 workaround 148 | #undef int 149 | #undef char 150 | #undef long 151 | #undef byte 152 | #undef float 153 | #undef abs 154 | #undef round 155 | #endif 156 | 157 | #endif 158 | -------------------------------------------------------------------------------- /Arduino/libraries/TinyGPS/examples/static_test/static_test.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* This sample code demonstrates the basic use of a TinyGPS object. 5 | Typically, you would feed it characters from a serial GPS device, but 6 | this example uses static strings for simplicity. 7 | */ 8 | prog_char str1[] PROGMEM = "$GPRMC,201547.000,A,3014.5527,N,09749.5808,W,0.24,163.05,040109,,*1A"; 9 | prog_char str2[] PROGMEM = "$GPGGA,201548.000,3014.5529,N,09749.5808,W,1,07,1.5,225.6,M,-22.5,M,18.8,0000*78"; 10 | prog_char str3[] PROGMEM = "$GPRMC,201548.000,A,3014.5529,N,09749.5808,W,0.17,53.25,040109,,*2B"; 11 | prog_char str4[] PROGMEM = "$GPGGA,201549.000,3014.5533,N,09749.5812,W,1,07,1.5,223.5,M,-22.5,M,18.8,0000*7C"; 12 | prog_char *teststrs[4] = {str1, str2, str3, str4}; 13 | 14 | static void sendstring(TinyGPS &gps, const PROGMEM char *str); 15 | static void gpsdump(TinyGPS &gps); 16 | static void print_float(float val, float invalid, int len, int prec); 17 | static void print_int(unsigned long val, unsigned long invalid, int len); 18 | static void print_date(TinyGPS &gps); 19 | static void print_str(const char *str, int len); 20 | 21 | void setup() 22 | { 23 | TinyGPS test_gps; 24 | Serial.begin(115200); 25 | 26 | Serial.print("Testing TinyGPS library v. "); Serial.println(TinyGPS::library_version()); 27 | Serial.println("by Mikal Hart"); 28 | Serial.println(); 29 | Serial.print("Sizeof(gpsobject) = "); Serial.println(sizeof(TinyGPS)); 30 | Serial.println(); 31 | 32 | Serial.println("Sats HDOP Latitude Longitude Fix Date Time Date Alt Course Speed Card Distance Course Card Chars Sentences Checksum"); 33 | Serial.println(" (deg) (deg) Age Age (m) --- from GPS ---- ---- to London ---- RX RX Fail"); 34 | Serial.println("--------------------------------------------------------------------------------------------------------------------------------------"); 35 | gpsdump(test_gps); 36 | for (int i=0; i<4; ++i) 37 | { 38 | sendstring(test_gps, teststrs[i]); 39 | gpsdump(test_gps); 40 | } 41 | } 42 | 43 | void loop() 44 | { 45 | } 46 | 47 | static void sendstring(TinyGPS &gps, const PROGMEM char *str) 48 | { 49 | while (true) 50 | { 51 | char c = pgm_read_byte_near(str++); 52 | if (!c) break; 53 | gps.encode(c); 54 | } 55 | gps.encode('\r'); 56 | gps.encode('\n'); 57 | } 58 | 59 | static void gpsdump(TinyGPS &gps) 60 | { 61 | float flat, flon; 62 | unsigned long age, date, time, chars = 0; 63 | unsigned short sentences = 0, failed = 0; 64 | static const float LONDON_LAT = 51.508131, LONDON_LON = -0.128002; 65 | 66 | print_int(gps.satellites(), TinyGPS::GPS_INVALID_SATELLITES, 5); 67 | print_int(gps.hdop(), TinyGPS::GPS_INVALID_HDOP, 5); 68 | gps.f_get_position(&flat, &flon, &age); 69 | print_float(flat, TinyGPS::GPS_INVALID_F_ANGLE, 9, 5); 70 | print_float(flon, TinyGPS::GPS_INVALID_F_ANGLE, 10, 5); 71 | print_int(age, TinyGPS::GPS_INVALID_AGE, 5); 72 | 73 | print_date(gps); 74 | 75 | print_float(gps.f_altitude(), TinyGPS::GPS_INVALID_F_ALTITUDE, 8, 2); 76 | print_float(gps.f_course(), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2); 77 | print_float(gps.f_speed_kmph(), TinyGPS::GPS_INVALID_F_SPEED, 6, 2); 78 | print_str(gps.f_course() == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(gps.f_course()), 6); 79 | print_int(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0UL : (unsigned long)TinyGPS::distance_between(flat, flon, LONDON_LAT, LONDON_LON) / 1000, 0xFFFFFFFF, 9); 80 | print_float(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : TinyGPS::course_to(flat, flon, 51.508131, -0.128002), TinyGPS::GPS_INVALID_F_ANGLE, 7, 2); 81 | print_str(flat == TinyGPS::GPS_INVALID_F_ANGLE ? "*** " : TinyGPS::cardinal(TinyGPS::course_to(flat, flon, LONDON_LAT, LONDON_LON)), 6); 82 | 83 | gps.stats(&chars, &sentences, &failed); 84 | print_int(chars, 0xFFFFFFFF, 6); 85 | print_int(sentences, 0xFFFFFFFF, 10); 86 | print_int(failed, 0xFFFFFFFF, 9); 87 | Serial.println(); 88 | } 89 | 90 | static void print_int(unsigned long val, unsigned long invalid, int len) 91 | { 92 | char sz[32]; 93 | if (val == invalid) 94 | strcpy(sz, "*******"); 95 | else 96 | sprintf(sz, "%ld", val); 97 | sz[len] = 0; 98 | for (int i=strlen(sz); i 0) 101 | sz[len-1] = ' '; 102 | Serial.print(sz); 103 | } 104 | 105 | static void print_float(float val, float invalid, int len, int prec) 106 | { 107 | char sz[32]; 108 | if (val == invalid) 109 | { 110 | strcpy(sz, "*******"); 111 | sz[len] = 0; 112 | if (len > 0) 113 | sz[len-1] = ' '; 114 | for (int i=7; i= 1000 ? 4 : vi >= 100 ? 3 : vi >= 10 ? 2 : 1; 124 | for (int i=flen; i 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 | -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/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 | -------------------------------------------------------------------------------- /Arduino/libraries/LibAPRS/examples/Basic_usage/Basic_usage.ino: -------------------------------------------------------------------------------- 1 | // Include LibAPRS 2 | #include 3 | 4 | // You must define what reference voltage the ADC 5 | // of your device is running at. If you bought a 6 | // MicroModem from unsigned.io, it will be running 7 | // at 3.3v if the "hw rev" is greater than 2.0. 8 | // This is the most common. If you build your own 9 | // modem, you should know this value yourself :) 10 | #define ADC_REFERENCE REF_3V3 11 | // OR 12 | //#define ADC_REFERENCE REF_5V 13 | 14 | // You can also define whether your modem will be 15 | // running with an open squelch radio: 16 | #define OPEN_SQUELCH false 17 | 18 | // You always need to include this function. It will 19 | // get called by the library every time a packet is 20 | // received, so you can process incoming packets. 21 | // 22 | // If you are only interested in receiving, you should 23 | // just leave this function empty. 24 | // 25 | // IMPORTANT! This function is called from within an 26 | // interrupt. That means that you should only do things 27 | // here that are FAST. Don't print out info directly 28 | // from this function, instead set a flag and print it 29 | // from your main loop, like this: 30 | 31 | boolean gotPacket = false; 32 | AX25Msg incomingPacket; 33 | uint8_t *packetData; 34 | void aprs_msg_callback(struct AX25Msg *msg) { 35 | // If we already have a packet waiting to be 36 | // processed, we must drop the new one. 37 | if (!gotPacket) { 38 | // Set flag to indicate we got a packet 39 | gotPacket = true; 40 | 41 | // The memory referenced as *msg is volatile 42 | // and we need to copy all the data to a 43 | // local variable for later processing. 44 | memcpy(&incomingPacket, msg, sizeof(AX25Msg)); 45 | 46 | // We need to allocate a new buffer for the 47 | // data payload of the packet. First we check 48 | // if there is enough free RAM. 49 | if (freeMemory() > msg->len) { 50 | packetData = (uint8_t*)malloc(msg->len); 51 | memcpy(packetData, msg->info, msg->len); 52 | incomingPacket.info = packetData; 53 | } else { 54 | // We did not have enough free RAM to receive 55 | // this packet, so we drop it. 56 | gotPacket = false; 57 | } 58 | } 59 | } 60 | 61 | void setup() { 62 | // Set up serial port 63 | Serial.begin(115200); 64 | 65 | // Initialise APRS library - This starts the modem 66 | APRS_init(ADC_REFERENCE, OPEN_SQUELCH); 67 | 68 | // You must at a minimum configure your callsign and SSID 69 | APRS_setCallsign("NOCALL", 1); 70 | 71 | // You don't need to set the destination identifier, but 72 | // if you want to, this is how you do it: 73 | // APRS_setDestination("APZMDM", 0); 74 | 75 | // Path parameters are set to sensible values by 76 | // default, but this is how you can configure them: 77 | // APRS_setPath1("WIDE1", 1); 78 | // APRS_setPath2("WIDE2", 2); 79 | 80 | // You can define preamble and tail like this: 81 | // APRS_setPreamble(350); 82 | // APRS_setTail(50); 83 | 84 | // You can use the normal or alternate symbol table: 85 | // APRS_useAlternateSymbolTable(false); 86 | 87 | // And set what symbol you want to use: 88 | // APRS_setSymbol('n'); 89 | 90 | // We can print out all the settings 91 | APRS_printSettings(); 92 | Serial.print(F("Free RAM: ")); Serial.println(freeMemory()); 93 | } 94 | 95 | void locationUpdateExample() { 96 | // Let's first set our latitude and longtitude. 97 | // These should be in NMEA format! 98 | APRS_setLat("5530.80N"); 99 | APRS_setLon("01143.89E"); 100 | 101 | // We can optionally set power/height/gain/directivity 102 | // information. These functions accept ranges 103 | // from 0 to 10, directivity 0 to 9. 104 | // See this site for a calculator: 105 | // http://www.aprsfl.net/phgr.php 106 | // LibAPRS will only add PHG info if all four variables 107 | // are defined! 108 | APRS_setPower(2); 109 | APRS_setHeight(4); 110 | APRS_setGain(7); 111 | APRS_setDirectivity(0); 112 | 113 | // We'll define a comment string 114 | char *comment = "LibAPRS location update"; 115 | 116 | // And send the update 117 | APRS_sendLoc(comment, strlen(comment)); 118 | 119 | } 120 | 121 | void messageExample() { 122 | // We first need to set the message recipient 123 | APRS_setMessageDestination("AA3BBB", 0); 124 | 125 | // And define a string to send 126 | char *message = "Hi there! This is a message."; 127 | APRS_sendMsg(message, strlen(message)); 128 | 129 | } 130 | 131 | // Here's a function to process incoming packets 132 | // Remember to call this function often, so you 133 | // won't miss any packets due to one already 134 | // waiting to be processed 135 | void processPacket() { 136 | if (gotPacket) { 137 | gotPacket = false; 138 | 139 | Serial.print(F("Received APRS packet. SRC: ")); 140 | Serial.print(incomingPacket.src.call); 141 | Serial.print(F("-")); 142 | Serial.print(incomingPacket.src.ssid); 143 | Serial.print(F(". DST: ")); 144 | Serial.print(incomingPacket.dst.call); 145 | Serial.print(F("-")); 146 | Serial.print(incomingPacket.dst.ssid); 147 | Serial.print(F(". Data: ")); 148 | 149 | for (int i = 0; i < incomingPacket.len; i++) { 150 | Serial.write(incomingPacket.info[i]); 151 | } 152 | Serial.println(""); 153 | 154 | // Remeber to free memory for our buffer! 155 | free(packetData); 156 | 157 | // You can print out the amount of free 158 | // RAM to check you don't have any memory 159 | // leaks 160 | // Serial.print(F("Free RAM: ")); Serial.println(freeMemory()); 161 | } 162 | } 163 | 164 | boolean whichExample = false; 165 | void loop() { 166 | 167 | delay(1000); 168 | if (whichExample) { 169 | locationUpdateExample(); 170 | } else { 171 | messageExample(); 172 | } 173 | whichExample ^= true; 174 | 175 | delay(500); 176 | processPacket(); 177 | } -------------------------------------------------------------------------------- /Arduino/libraries/U8glib/utility/u8g_dev_ssd1309_128x64.c: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | u8g_dev_ssd1309_128x64.c 4 | 5 | Universal 8bit Graphics Library 6 | 7 | Copyright (c) 2012, olikraus@gmail.com 8 | All rights reserved. 9 | 10 | Redistribution and use in source and binary forms, with or without modification, 11 | are permitted provided that the following conditions are met: 12 | 13 | * Redistributions of source code must retain the above copyright notice, this list 14 | of conditions and the following disclaimer. 15 | 16 | * Redistributions in binary form must reproduce the above copyright notice, this 17 | list of conditions and the following disclaimer in the documentation and/or other 18 | materials provided with the distribution. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 21 | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 22 | INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 23 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 25 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 26 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 28 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 29 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 30 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 31 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 32 | ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | 35 | */ 36 | 37 | #include "u8g.h" 38 | 39 | #define WIDTH 128 40 | #define HEIGHT 64 41 | #define PAGE_HEIGHT 8 42 | 43 | 44 | /* ssd1309 ini sequence*/ 45 | static const uint8_t u8g_dev_ssd1309_128x64_init_seq[] PROGMEM={ 46 | U8G_ESC_CS(0), /* disable chip */ 47 | U8G_ESC_ADR(0), /* instruction mode */ 48 | U8G_ESC_RST(1), /* do reset low pulse with (1*16)+2 milliseconds */ 49 | U8G_ESC_CS(1), /* enable chip */ 50 | 51 | 0xfd,0x12, /*Command Lock */ 52 | 0xae, /*Set Display Off */ 53 | 0xd5,0xa0, /*set Display Clock Divide Ratio/Oscillator Frequency */ 54 | 0xa8,0x3f, /*Set Multiplex Ratio */ 55 | 0x3d,0x00, /*Set Display Offset*/ 56 | 0x40, /*Set Display Start Line*/ 57 | 0xa1, /*Set Segment Re-Map*/ 58 | 0xc8, /*Set COM Output Scan Direction*/ 59 | 0xda,0x12, /*Set COM Pins Hardware Configuration*/ 60 | 0x81,0xdf, /*Set Current Control */ 61 | 0xd9,0x82, /*Set Pre-Charge Period */ 62 | 0xdb,0x34, /*Set VCOMH Deselect Level */ 63 | 0xa4, /*Set Entire Display On/Off */ 64 | 0xa6, /*Set Normal/Inverse Display*/ 65 | U8G_ESC_VCC(1), /*Power up VCC & Stabilized */ 66 | U8G_ESC_DLY(50), 67 | 0xaf, /*Set Display On */ 68 | U8G_ESC_DLY(50), 69 | U8G_ESC_CS(0), /* disable chip */ 70 | U8G_ESC_END /* end of sequence */ 71 | }; 72 | 73 | /* select one init sequence here */ 74 | #define u8g_dev_ssd1309_128x64_init_seq u8g_dev_ssd1309_128x64_init_seq 75 | 76 | 77 | static const uint8_t u8g_dev_ssd1309_128x64_data_start[] PROGMEM = { 78 | U8G_ESC_ADR(0), /* instruction mode */ 79 | U8G_ESC_CS(1), /* enable chip */ 80 | 0x010, /* set upper 4 bit of the col adr to 0 */ 81 | 0x000, /* set lower 4 bit of the col adr to 4 */ 82 | U8G_ESC_END /* end of sequence */ 83 | }; 84 | 85 | static const uint8_t u8g_dev_ssd13xx_sleep_on[] PROGMEM = { 86 | U8G_ESC_ADR(0), /* instruction mode */ 87 | U8G_ESC_CS(1), /* enable chip */ 88 | 0x0ae, /* display off */ 89 | U8G_ESC_CS(0), /* disable chip */ 90 | U8G_ESC_END /* end of sequence */ 91 | }; 92 | 93 | static const uint8_t u8g_dev_ssd13xx_sleep_off[] PROGMEM = { 94 | U8G_ESC_ADR(0), /* instruction mode */ 95 | U8G_ESC_CS(1), /* enable chip */ 96 | 0x0af, /* display on */ 97 | U8G_ESC_DLY(50), /* delay 50 ms */ 98 | U8G_ESC_CS(0), /* disable chip */ 99 | U8G_ESC_END /* end of sequence */ 100 | }; 101 | 102 | uint8_t u8g_dev_ssd1309_128x64_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 103 | { 104 | switch(msg) 105 | { 106 | case U8G_DEV_MSG_INIT: 107 | u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS); 108 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1309_128x64_init_seq); 109 | break; 110 | case U8G_DEV_MSG_STOP: 111 | break; 112 | case U8G_DEV_MSG_PAGE_NEXT: 113 | { 114 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 115 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1309_128x64_data_start); 116 | u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (SSD1306) */ 117 | u8g_SetAddress(u8g, dev, 1); /* data mode */ 118 | if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 ) 119 | return 0; 120 | u8g_SetChipSelect(u8g, dev, 0); 121 | } 122 | break; 123 | case U8G_DEV_MSG_CONTRAST: 124 | u8g_SetChipSelect(u8g, dev, 1); 125 | u8g_SetAddress(u8g, dev, 0); /* instruction mode */ 126 | u8g_WriteByte(u8g, dev, 0x081); 127 | u8g_WriteByte(u8g, dev, (*(uint8_t *)arg) >> 2); 128 | u8g_SetChipSelect(u8g, dev, 0); 129 | return 1; 130 | case U8G_DEV_MSG_SLEEP_ON: 131 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on); 132 | return 1; 133 | case U8G_DEV_MSG_SLEEP_OFF: 134 | u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off); 135 | return 1; 136 | } 137 | return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 138 | } 139 | 140 | U8G_PB_DEV(u8g_dev_ssd1309_128x64_hw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1309_128x64_fn, U8G_COM_HW_SPI); 141 | U8G_PB_DEV(u8g_dev_ssd1309_128x64_sw_spi, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1309_128x64_fn, U8G_COM_SW_SPI); 142 | U8G_PB_DEV(u8g_dev_ssd1309_128x64_i2c, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_ssd1309_128x64_fn, U8G_COM_SSD_I2C); 143 | 144 | --------------------------------------------------------------------------------