├── .gitignore ├── LICENSE ├── ble_app_uart_adafruit_gfx ├── ble_app_uart.eww ├── main.c └── pca10056 │ └── s140 │ ├── config │ └── sdk_config.h │ └── ses │ ├── ble_app_uart_pca10056_s140.emProject │ ├── ble_app_uart_pca10056_s140.emSession │ ├── ble_app_uart_pca10056_s140_Debug.jlink │ └── flash_placement.xml ├── ble_app_uart_adafruit_gfx_nrfx_twim ├── main.c └── pca10056 │ └── s140 │ ├── config │ └── sdk_config.h │ └── ses │ ├── ble_app_uart_pca10056_s140.emProject │ ├── ble_app_uart_pca10056_s140.emSession │ └── flash_placement.xml ├── ble_app_uart_ssd1306 ├── main.c └── pca10056 │ └── s140 │ ├── config │ └── sdk_config.h │ └── ses │ ├── ble_app_uart_pca10056_s140.emProject │ ├── ble_app_uart_pca10056_s140.emSession │ └── flash_placement.xml ├── images ├── SSD1306_128_32_NRF52840_DK_board.png └── SSD1306_128_64_NRF52840_DK_board.png ├── module ├── ssd1306_driver │ ├── SSD1306.c │ ├── SSD1306.h │ ├── binary.h │ └── glcdfont.c └── ssd1306_driver_adafruit │ ├── Adafruit_GFX.c │ ├── Adafruit_GFX.h │ ├── SSD1306.c │ ├── SSD1306.h │ ├── glcdfont.c │ ├── ssd1306_nrfx_twim.c │ └── ssd1306_nrfx_twim.h └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | -------------------------------------------------------------------------------- /ble_app_uart_adafruit_gfx/ble_app_uart.eww: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | $WS_DIR$\pca10040\s112\iar\ble_app_uart_pca10040_s112.ewp 5 | 6 | $WS_DIR$\pca10040\s132\iar\ble_app_uart_pca10040_s132.ewp 7 | 8 | $WS_DIR$\pca10056\s140\iar\ble_app_uart_pca10056_s140.ewp 9 | 10 | $WS_DIR$\pca10040e\s112\iar\ble_app_uart_pca10040e_s112.ewp 11 | 12 | -------------------------------------------------------------------------------- /ble_app_uart_adafruit_gfx/pca10056/s140/ses/ble_app_uart_pca10056_s140.emProject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 137 | 138 | 142 | 146 | 147 | -------------------------------------------------------------------------------- /ble_app_uart_adafruit_gfx/pca10056/s140/ses/ble_app_uart_pca10056_s140.emSession: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /ble_app_uart_adafruit_gfx/pca10056/s140/ses/ble_app_uart_pca10056_s140_Debug.jlink: -------------------------------------------------------------------------------- 1 | [BREAKPOINTS] 2 | ForceImpTypeAny = 0 3 | ShowInfoWin = 1 4 | EnableFlashBP = 2 5 | BPDuringExecution = 0 6 | [CFI] 7 | CFISize = 0x00 8 | CFIAddr = 0x00 9 | [CPU] 10 | MonModeVTableAddr = 0xFFFFFFFF 11 | MonModeDebug = 0 12 | MaxNumAPs = 0 13 | LowPowerHandlingMode = 0 14 | OverrideMemMap = 0 15 | AllowSimulation = 1 16 | ScriptFile="" 17 | [FLASH] 18 | CacheExcludeSize = 0x00 19 | CacheExcludeAddr = 0x00 20 | MinNumBytesFlashDL = 0 21 | SkipProgOnCRCMatch = 1 22 | VerifyDownload = 1 23 | AllowCaching = 1 24 | EnableFlashDL = 2 25 | Override = 0 26 | Device="ARM7" 27 | [GENERAL] 28 | WorkRAMSize = 0x00 29 | WorkRAMAddr = 0x00 30 | RAMUsageLimit = 0x00 31 | [SWO] 32 | SWOLogFile="" 33 | [MEM] 34 | RdOverrideOrMask = 0x00 35 | RdOverrideAndMask = 0xFFFFFFFF 36 | RdOverrideAddr = 0xFFFFFFFF 37 | WrOverrideOrMask = 0x00 38 | WrOverrideAndMask = 0xFFFFFFFF 39 | WrOverrideAddr = 0xFFFFFFFF 40 | -------------------------------------------------------------------------------- /ble_app_uart_adafruit_gfx/pca10056/s140/ses/flash_placement.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /ble_app_uart_adafruit_gfx_nrfx_twim/pca10056/s140/ses/ble_app_uart_pca10056_s140.emProject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 137 | 138 | 142 | 146 | 147 | -------------------------------------------------------------------------------- /ble_app_uart_adafruit_gfx_nrfx_twim/pca10056/s140/ses/ble_app_uart_pca10056_s140.emSession: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /ble_app_uart_adafruit_gfx_nrfx_twim/pca10056/s140/ses/flash_placement.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /ble_app_uart_ssd1306/pca10056/s140/ses/ble_app_uart_pca10056_s140.emProject: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 135 | 136 | 140 | 144 | 145 | -------------------------------------------------------------------------------- /ble_app_uart_ssd1306/pca10056/s140/ses/ble_app_uart_pca10056_s140.emSession: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /ble_app_uart_ssd1306/pca10056/s140/ses/flash_placement.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /images/SSD1306_128_32_NRF52840_DK_board.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jimmywong2003/SSD1306-LCD-on-NRF52/4ca746a075d3628c971d63ee42bb9b67d5787345/images/SSD1306_128_32_NRF52840_DK_board.png -------------------------------------------------------------------------------- /images/SSD1306_128_64_NRF52840_DK_board.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jimmywong2003/SSD1306-LCD-on-NRF52/4ca746a075d3628c971d63ee42bb9b67d5787345/images/SSD1306_128_64_NRF52840_DK_board.png -------------------------------------------------------------------------------- /module/ssd1306_driver/SSD1306.h: -------------------------------------------------------------------------------- 1 | #ifndef __SSD1306_LIB_H 2 | #define __SSD1306_LIB_H 3 | 4 | #ifdef __AVR__ 5 | #include 6 | #elif defined(ESP8266) 7 | #include 8 | #else 9 | #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) 10 | #endif 11 | 12 | #include 13 | 14 | typedef volatile uint8_t PortReg; 15 | typedef uint32_t PortMask; 16 | 17 | 18 | #define BLACK 0 19 | #define WHITE 1 20 | #define INVERSE 2 21 | 22 | #define SSD1306_I2C_ADDRESS (0x3C) // 011110+SA0+RW - 0x3C or 0x3D 23 | // Address for 128x32 is 0x3C 24 | // Address for 128x64 is 0x3D (default) or 0x3C (if SA0 is grounded) 25 | 26 | /*========================================================================= 27 | SSD1306 Displays 28 | ----------------------------------------------------------------------- 29 | The driver is used in multiple displays (128x64, 128x32, etc.). 30 | Select the appropriate display below to create an appropriately 31 | sized framebuffer, etc. 32 | SSD1306_128_64 128x64 pixel display 33 | SSD1306_128_32 128x32 pixel display 34 | SSD1306_96_16 35 | -----------------------------------------------------------------------*/ 36 | #define SSD1306_128_64 37 | // #define SSD1306_128_32 38 | // #define SSD1306_96_16 39 | /*=========================================================================*/ 40 | 41 | 42 | #if defined SSD1306_128_64 43 | #define SSD1306_LCDWIDTH 128 44 | #define SSD1306_LCDHEIGHT 64 45 | #endif 46 | #if defined SSD1306_128_32 47 | #define SSD1306_LCDWIDTH 128 48 | #define SSD1306_LCDHEIGHT 32 49 | #endif 50 | #if defined SSD1306_96_16 51 | #define SSD1306_LCDWIDTH 96 52 | #define SSD1306_LCDHEIGHT 16 53 | #endif 54 | 55 | #define SSD1306_SETCONTRAST 0x81 56 | #define SSD1306_DISPLAYALLON_RESUME 0xA4 57 | #define SSD1306_DISPLAYALLON 0xA5 58 | #define SSD1306_NORMALDISPLAY 0xA6 59 | #define SSD1306_INVERTDISPLAY 0xA7 60 | #define SSD1306_DISPLAYOFF 0xAE 61 | #define SSD1306_DISPLAYON 0xAF 62 | 63 | #define SSD1306_SETDISPLAYOFFSET 0xD3 64 | #define SSD1306_SETCOMPINS 0xDA 65 | 66 | #define SSD1306_SETVCOMDETECT 0xDB 67 | 68 | #define SSD1306_SETDISPLAYCLOCKDIV 0xD5 69 | #define SSD1306_SETPRECHARGE 0xD9 70 | 71 | #define SSD1306_SETMULTIPLEX 0xA8 72 | 73 | #define SSD1306_SETLOWCOLUMN 0x00 74 | #define SSD1306_SETHIGHCOLUMN 0x10 75 | 76 | #define SSD1306_SETSTARTLINE 0x40 77 | 78 | #define SSD1306_MEMORYMODE 0x20 79 | #define SSD1306_COLUMNADDR 0x21 80 | #define SSD1306_PAGEADDR 0x22 81 | 82 | #define SSD1306_COMSCANINC 0xC0 83 | #define SSD1306_COMSCANDEC 0xC8 84 | 85 | #define SSD1306_SEGREMAP 0xA0 86 | 87 | #define SSD1306_CHARGEPUMP 0x8D 88 | 89 | #define SSD1306_EXTERNALVCC 0x1 90 | #define SSD1306_SWITCHCAPVCC 0x2 91 | 92 | // Scrolling #defines 93 | #define SSD1306_ACTIVATE_SCROLL 0x2F 94 | #define SSD1306_DEACTIVATE_SCROLL 0x2E 95 | #define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3 96 | #define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26 97 | #define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27 98 | #define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29 99 | #define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A 100 | 101 | #ifdef __cplusplus 102 | extern "C" { 103 | #endif 104 | 105 | int16_t ssd1306_width(void); 106 | int16_t ssd1306_height(void); 107 | void set_rotation(uint8_t x); 108 | void ssd1306_init(uint32_t dc, uint32_t rs, uint32_t cs, uint32_t clk, uint32_t mosi); 109 | void ssd1306_init_i2c(uint32_t scl, uint32_t sda); 110 | void ssd1306_command(uint8_t c); 111 | void ssd1306_begin(uint8_t vccstate, uint8_t i2caddr, bool reset); 112 | void ssd1306_draw_pixel(int16_t x, int16_t y, uint16_t color); 113 | void ssd1306_invert_display(uint8_t i); 114 | void ssd1306_start_scroll_right(uint8_t start, uint8_t stop); 115 | void ssd1306_start_scroll_left(uint8_t start, uint8_t stop); 116 | void ssd1306_start_scroll_diag_right(uint8_t start, uint8_t stop); 117 | void ssd1306_start_scroll_diag_left(uint8_t start, uint8_t stop); 118 | void ssd1306_stop_scroll(void); 119 | void ssd1306_dim(bool dim); 120 | void ssd1306_data(uint8_t c); 121 | void ssd1306_display(void); 122 | void ssd1306_clear_display(void); 123 | void ssd1306_draw_fast_hline(int16_t x, int16_t y, int16_t w, uint16_t color); 124 | void ssd1306_draw_fast_hline_internal(int16_t x, int16_t y, int16_t w, uint16_t color); 125 | void ssd1306_draw_fast_vline(int16_t x, int16_t y, int16_t h, uint16_t color); 126 | void ssd1306_draw_fast_vline_internal(int16_t x, int16_t __y, int16_t __h, uint16_t color); 127 | void ssd1306_draw_circle(int16_t x0, int16_t y0, int16_t r, uint16_t color); 128 | void ssd1306_draw_circle_helper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color); 129 | void ssd1306_fill_circle(int16_t x0, int16_t y0, int16_t r, uint16_t color); 130 | void ssd1306_fill_circle_helper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color); 131 | void ssd1306_draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color); 132 | void ssd1306_draw_rect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); 133 | void ssd1306_fill_rect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); 134 | void ssd1306_fill_screen(uint16_t color); 135 | void ssd1306_draw_round_rect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color); 136 | void ssd1306_fill_round_rect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color); 137 | void ssd1306_draw_triangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); 138 | void ssd1306_fill_triangle( int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); 139 | void ssd1306_draw_bitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color); 140 | void ssd1306_draw_bitmap_bg(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg); 141 | void ssd1306_draw_xbitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color); 142 | size_t ssd1306_write(uint8_t c); 143 | void ssd1306_draw_char(int16_t x, int16_t y, uint8_t c, uint16_t color, uint16_t bg, uint8_t size); 144 | void ssd1306_set_cursor(int16_t x, int16_t y); 145 | int16_t ssd1306_get_cursor_x(void); 146 | int16_t ssd1306_get_cursor_y(void); 147 | void ssd1306_set_textsize(uint8_t s); 148 | void ssd1306_set_textcolor(uint16_t c); 149 | void ssd1306_set_textcolor_bg(uint16_t c, uint16_t b); 150 | void ssd1306_set_textwrap(bool w); 151 | uint8_t ssd1306_get_rotation(void); 152 | void ssd1306_set_rotation(uint8_t x); 153 | void ssd1306_cp437(bool x); 154 | void ssd1306_putstring(char* buffer); 155 | void ssd1306_puts(char* buffer); 156 | #ifdef __cplusplus 157 | } 158 | #endif 159 | 160 | #endif /* __SSD1306_LIB_H */ 161 | -------------------------------------------------------------------------------- /module/ssd1306_driver/binary.h: -------------------------------------------------------------------------------- 1 | /* 2 | binary.h - Definitions for binary constants 3 | Copyright (c) 2006 David A. Mellis. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Binary_h 21 | #define Binary_h 22 | 23 | #define B0 0 24 | #define B00 0 25 | #define B000 0 26 | #define B0000 0 27 | #define B00000 0 28 | #define B000000 0 29 | #define B0000000 0 30 | #define B00000000 0 31 | #define B1 1 32 | #define B01 1 33 | #define B001 1 34 | #define B0001 1 35 | #define B00001 1 36 | #define B000001 1 37 | #define B0000001 1 38 | #define B00000001 1 39 | #define B10 2 40 | #define B010 2 41 | #define B0010 2 42 | #define B00010 2 43 | #define B000010 2 44 | #define B0000010 2 45 | #define B00000010 2 46 | #define B11 3 47 | #define B011 3 48 | #define B0011 3 49 | #define B00011 3 50 | #define B000011 3 51 | #define B0000011 3 52 | #define B00000011 3 53 | #define B100 4 54 | #define B0100 4 55 | #define B00100 4 56 | #define B000100 4 57 | #define B0000100 4 58 | #define B00000100 4 59 | #define B101 5 60 | #define B0101 5 61 | #define B00101 5 62 | #define B000101 5 63 | #define B0000101 5 64 | #define B00000101 5 65 | #define B110 6 66 | #define B0110 6 67 | #define B00110 6 68 | #define B000110 6 69 | #define B0000110 6 70 | #define B00000110 6 71 | #define B111 7 72 | #define B0111 7 73 | #define B00111 7 74 | #define B000111 7 75 | #define B0000111 7 76 | #define B00000111 7 77 | #define B1000 8 78 | #define B01000 8 79 | #define B001000 8 80 | #define B0001000 8 81 | #define B00001000 8 82 | #define B1001 9 83 | #define B01001 9 84 | #define B001001 9 85 | #define B0001001 9 86 | #define B00001001 9 87 | #define B1010 10 88 | #define B01010 10 89 | #define B001010 10 90 | #define B0001010 10 91 | #define B00001010 10 92 | #define B1011 11 93 | #define B01011 11 94 | #define B001011 11 95 | #define B0001011 11 96 | #define B00001011 11 97 | #define B1100 12 98 | #define B01100 12 99 | #define B001100 12 100 | #define B0001100 12 101 | #define B00001100 12 102 | #define B1101 13 103 | #define B01101 13 104 | #define B001101 13 105 | #define B0001101 13 106 | #define B00001101 13 107 | #define B1110 14 108 | #define B01110 14 109 | #define B001110 14 110 | #define B0001110 14 111 | #define B00001110 14 112 | #define B1111 15 113 | #define B01111 15 114 | #define B001111 15 115 | #define B0001111 15 116 | #define B00001111 15 117 | #define B10000 16 118 | #define B010000 16 119 | #define B0010000 16 120 | #define B00010000 16 121 | #define B10001 17 122 | #define B010001 17 123 | #define B0010001 17 124 | #define B00010001 17 125 | #define B10010 18 126 | #define B010010 18 127 | #define B0010010 18 128 | #define B00010010 18 129 | #define B10011 19 130 | #define B010011 19 131 | #define B0010011 19 132 | #define B00010011 19 133 | #define B10100 20 134 | #define B010100 20 135 | #define B0010100 20 136 | #define B00010100 20 137 | #define B10101 21 138 | #define B010101 21 139 | #define B0010101 21 140 | #define B00010101 21 141 | #define B10110 22 142 | #define B010110 22 143 | #define B0010110 22 144 | #define B00010110 22 145 | #define B10111 23 146 | #define B010111 23 147 | #define B0010111 23 148 | #define B00010111 23 149 | #define B11000 24 150 | #define B011000 24 151 | #define B0011000 24 152 | #define B00011000 24 153 | #define B11001 25 154 | #define B011001 25 155 | #define B0011001 25 156 | #define B00011001 25 157 | #define B11010 26 158 | #define B011010 26 159 | #define B0011010 26 160 | #define B00011010 26 161 | #define B11011 27 162 | #define B011011 27 163 | #define B0011011 27 164 | #define B00011011 27 165 | #define B11100 28 166 | #define B011100 28 167 | #define B0011100 28 168 | #define B00011100 28 169 | #define B11101 29 170 | #define B011101 29 171 | #define B0011101 29 172 | #define B00011101 29 173 | #define B11110 30 174 | #define B011110 30 175 | #define B0011110 30 176 | #define B00011110 30 177 | #define B11111 31 178 | #define B011111 31 179 | #define B0011111 31 180 | #define B00011111 31 181 | #define B100000 32 182 | #define B0100000 32 183 | #define B00100000 32 184 | #define B100001 33 185 | #define B0100001 33 186 | #define B00100001 33 187 | #define B100010 34 188 | #define B0100010 34 189 | #define B00100010 34 190 | #define B100011 35 191 | #define B0100011 35 192 | #define B00100011 35 193 | #define B100100 36 194 | #define B0100100 36 195 | #define B00100100 36 196 | #define B100101 37 197 | #define B0100101 37 198 | #define B00100101 37 199 | #define B100110 38 200 | #define B0100110 38 201 | #define B00100110 38 202 | #define B100111 39 203 | #define B0100111 39 204 | #define B00100111 39 205 | #define B101000 40 206 | #define B0101000 40 207 | #define B00101000 40 208 | #define B101001 41 209 | #define B0101001 41 210 | #define B00101001 41 211 | #define B101010 42 212 | #define B0101010 42 213 | #define B00101010 42 214 | #define B101011 43 215 | #define B0101011 43 216 | #define B00101011 43 217 | #define B101100 44 218 | #define B0101100 44 219 | #define B00101100 44 220 | #define B101101 45 221 | #define B0101101 45 222 | #define B00101101 45 223 | #define B101110 46 224 | #define B0101110 46 225 | #define B00101110 46 226 | #define B101111 47 227 | #define B0101111 47 228 | #define B00101111 47 229 | #define B110000 48 230 | #define B0110000 48 231 | #define B00110000 48 232 | #define B110001 49 233 | #define B0110001 49 234 | #define B00110001 49 235 | #define B110010 50 236 | #define B0110010 50 237 | #define B00110010 50 238 | #define B110011 51 239 | #define B0110011 51 240 | #define B00110011 51 241 | #define B110100 52 242 | #define B0110100 52 243 | #define B00110100 52 244 | #define B110101 53 245 | #define B0110101 53 246 | #define B00110101 53 247 | #define B110110 54 248 | #define B0110110 54 249 | #define B00110110 54 250 | #define B110111 55 251 | #define B0110111 55 252 | #define B00110111 55 253 | #define B111000 56 254 | #define B0111000 56 255 | #define B00111000 56 256 | #define B111001 57 257 | #define B0111001 57 258 | #define B00111001 57 259 | #define B111010 58 260 | #define B0111010 58 261 | #define B00111010 58 262 | #define B111011 59 263 | #define B0111011 59 264 | #define B00111011 59 265 | #define B111100 60 266 | #define B0111100 60 267 | #define B00111100 60 268 | #define B111101 61 269 | #define B0111101 61 270 | #define B00111101 61 271 | #define B111110 62 272 | #define B0111110 62 273 | #define B00111110 62 274 | #define B111111 63 275 | #define B0111111 63 276 | #define B00111111 63 277 | #define B1000000 64 278 | #define B01000000 64 279 | #define B1000001 65 280 | #define B01000001 65 281 | #define B1000010 66 282 | #define B01000010 66 283 | #define B1000011 67 284 | #define B01000011 67 285 | #define B1000100 68 286 | #define B01000100 68 287 | #define B1000101 69 288 | #define B01000101 69 289 | #define B1000110 70 290 | #define B01000110 70 291 | #define B1000111 71 292 | #define B01000111 71 293 | #define B1001000 72 294 | #define B01001000 72 295 | #define B1001001 73 296 | #define B01001001 73 297 | #define B1001010 74 298 | #define B01001010 74 299 | #define B1001011 75 300 | #define B01001011 75 301 | #define B1001100 76 302 | #define B01001100 76 303 | #define B1001101 77 304 | #define B01001101 77 305 | #define B1001110 78 306 | #define B01001110 78 307 | #define B1001111 79 308 | #define B01001111 79 309 | #define B1010000 80 310 | #define B01010000 80 311 | #define B1010001 81 312 | #define B01010001 81 313 | #define B1010010 82 314 | #define B01010010 82 315 | #define B1010011 83 316 | #define B01010011 83 317 | #define B1010100 84 318 | #define B01010100 84 319 | #define B1010101 85 320 | #define B01010101 85 321 | #define B1010110 86 322 | #define B01010110 86 323 | #define B1010111 87 324 | #define B01010111 87 325 | #define B1011000 88 326 | #define B01011000 88 327 | #define B1011001 89 328 | #define B01011001 89 329 | #define B1011010 90 330 | #define B01011010 90 331 | #define B1011011 91 332 | #define B01011011 91 333 | #define B1011100 92 334 | #define B01011100 92 335 | #define B1011101 93 336 | #define B01011101 93 337 | #define B1011110 94 338 | #define B01011110 94 339 | #define B1011111 95 340 | #define B01011111 95 341 | #define B1100000 96 342 | #define B01100000 96 343 | #define B1100001 97 344 | #define B01100001 97 345 | #define B1100010 98 346 | #define B01100010 98 347 | #define B1100011 99 348 | #define B01100011 99 349 | #define B1100100 100 350 | #define B01100100 100 351 | #define B1100101 101 352 | #define B01100101 101 353 | #define B1100110 102 354 | #define B01100110 102 355 | #define B1100111 103 356 | #define B01100111 103 357 | #define B1101000 104 358 | #define B01101000 104 359 | #define B1101001 105 360 | #define B01101001 105 361 | #define B1101010 106 362 | #define B01101010 106 363 | #define B1101011 107 364 | #define B01101011 107 365 | #define B1101100 108 366 | #define B01101100 108 367 | #define B1101101 109 368 | #define B01101101 109 369 | #define B1101110 110 370 | #define B01101110 110 371 | #define B1101111 111 372 | #define B01101111 111 373 | #define B1110000 112 374 | #define B01110000 112 375 | #define B1110001 113 376 | #define B01110001 113 377 | #define B1110010 114 378 | #define B01110010 114 379 | #define B1110011 115 380 | #define B01110011 115 381 | #define B1110100 116 382 | #define B01110100 116 383 | #define B1110101 117 384 | #define B01110101 117 385 | #define B1110110 118 386 | #define B01110110 118 387 | #define B1110111 119 388 | #define B01110111 119 389 | #define B1111000 120 390 | #define B01111000 120 391 | #define B1111001 121 392 | #define B01111001 121 393 | #define B1111010 122 394 | #define B01111010 122 395 | #define B1111011 123 396 | #define B01111011 123 397 | #define B1111100 124 398 | #define B01111100 124 399 | #define B1111101 125 400 | #define B01111101 125 401 | #define B1111110 126 402 | #define B01111110 126 403 | #define B1111111 127 404 | #define B01111111 127 405 | #define B10000000 128 406 | #define B10000001 129 407 | #define B10000010 130 408 | #define B10000011 131 409 | #define B10000100 132 410 | #define B10000101 133 411 | #define B10000110 134 412 | #define B10000111 135 413 | #define B10001000 136 414 | #define B10001001 137 415 | #define B10001010 138 416 | #define B10001011 139 417 | #define B10001100 140 418 | #define B10001101 141 419 | #define B10001110 142 420 | #define B10001111 143 421 | #define B10010000 144 422 | #define B10010001 145 423 | #define B10010010 146 424 | #define B10010011 147 425 | #define B10010100 148 426 | #define B10010101 149 427 | #define B10010110 150 428 | #define B10010111 151 429 | #define B10011000 152 430 | #define B10011001 153 431 | #define B10011010 154 432 | #define B10011011 155 433 | #define B10011100 156 434 | #define B10011101 157 435 | #define B10011110 158 436 | #define B10011111 159 437 | #define B10100000 160 438 | #define B10100001 161 439 | #define B10100010 162 440 | #define B10100011 163 441 | #define B10100100 164 442 | #define B10100101 165 443 | #define B10100110 166 444 | #define B10100111 167 445 | #define B10101000 168 446 | #define B10101001 169 447 | #define B10101010 170 448 | #define B10101011 171 449 | #define B10101100 172 450 | #define B10101101 173 451 | #define B10101110 174 452 | #define B10101111 175 453 | #define B10110000 176 454 | #define B10110001 177 455 | #define B10110010 178 456 | #define B10110011 179 457 | #define B10110100 180 458 | #define B10110101 181 459 | #define B10110110 182 460 | #define B10110111 183 461 | #define B10111000 184 462 | #define B10111001 185 463 | #define B10111010 186 464 | #define B10111011 187 465 | #define B10111100 188 466 | #define B10111101 189 467 | #define B10111110 190 468 | #define B10111111 191 469 | #define B11000000 192 470 | #define B11000001 193 471 | #define B11000010 194 472 | #define B11000011 195 473 | #define B11000100 196 474 | #define B11000101 197 475 | #define B11000110 198 476 | #define B11000111 199 477 | #define B11001000 200 478 | #define B11001001 201 479 | #define B11001010 202 480 | #define B11001011 203 481 | #define B11001100 204 482 | #define B11001101 205 483 | #define B11001110 206 484 | #define B11001111 207 485 | #define B11010000 208 486 | #define B11010001 209 487 | #define B11010010 210 488 | #define B11010011 211 489 | #define B11010100 212 490 | #define B11010101 213 491 | #define B11010110 214 492 | #define B11010111 215 493 | #define B11011000 216 494 | #define B11011001 217 495 | #define B11011010 218 496 | #define B11011011 219 497 | #define B11011100 220 498 | #define B11011101 221 499 | #define B11011110 222 500 | #define B11011111 223 501 | #define B11100000 224 502 | #define B11100001 225 503 | #define B11100010 226 504 | #define B11100011 227 505 | #define B11100100 228 506 | #define B11100101 229 507 | #define B11100110 230 508 | #define B11100111 231 509 | #define B11101000 232 510 | #define B11101001 233 511 | #define B11101010 234 512 | #define B11101011 235 513 | #define B11101100 236 514 | #define B11101101 237 515 | #define B11101110 238 516 | #define B11101111 239 517 | #define B11110000 240 518 | #define B11110001 241 519 | #define B11110010 242 520 | #define B11110011 243 521 | #define B11110100 244 522 | #define B11110101 245 523 | #define B11110110 246 524 | #define B11110111 247 525 | #define B11111000 248 526 | #define B11111001 249 527 | #define B11111010 250 528 | #define B11111011 251 529 | #define B11111100 252 530 | #define B11111101 253 531 | #define B11111110 254 532 | #define B11111111 255 533 | 534 | #endif 535 | -------------------------------------------------------------------------------- /module/ssd1306_driver/glcdfont.c: -------------------------------------------------------------------------------- 1 | #ifndef FONT5X7_H 2 | #define FONT5X7_H 3 | 4 | #ifdef __AVR__ 5 | #include 6 | #include 7 | #else 8 | #define PROGMEM 9 | #endif 10 | 11 | // Standard ASCII 5x7 font 12 | 13 | static const unsigned char font[] PROGMEM = { 14 | 0x00, 0x00, 0x00, 0x00, 0x00, 15 | 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 16 | 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 17 | 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 18 | 0x18, 0x3C, 0x7E, 0x3C, 0x18, 19 | 0x1C, 0x57, 0x7D, 0x57, 0x1C, 20 | 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 21 | 0x00, 0x18, 0x3C, 0x18, 0x00, 22 | 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 23 | 0x00, 0x18, 0x24, 0x18, 0x00, 24 | 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 25 | 0x30, 0x48, 0x3A, 0x06, 0x0E, 26 | 0x26, 0x29, 0x79, 0x29, 0x26, 27 | 0x40, 0x7F, 0x05, 0x05, 0x07, 28 | 0x40, 0x7F, 0x05, 0x25, 0x3F, 29 | 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 30 | 0x7F, 0x3E, 0x1C, 0x1C, 0x08, 31 | 0x08, 0x1C, 0x1C, 0x3E, 0x7F, 32 | 0x14, 0x22, 0x7F, 0x22, 0x14, 33 | 0x5F, 0x5F, 0x00, 0x5F, 0x5F, 34 | 0x06, 0x09, 0x7F, 0x01, 0x7F, 35 | 0x00, 0x66, 0x89, 0x95, 0x6A, 36 | 0x60, 0x60, 0x60, 0x60, 0x60, 37 | 0x94, 0xA2, 0xFF, 0xA2, 0x94, 38 | 0x08, 0x04, 0x7E, 0x04, 0x08, 39 | 0x10, 0x20, 0x7E, 0x20, 0x10, 40 | 0x08, 0x08, 0x2A, 0x1C, 0x08, 41 | 0x08, 0x1C, 0x2A, 0x08, 0x08, 42 | 0x1E, 0x10, 0x10, 0x10, 0x10, 43 | 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 44 | 0x30, 0x38, 0x3E, 0x38, 0x30, 45 | 0x06, 0x0E, 0x3E, 0x0E, 0x06, 46 | 0x00, 0x00, 0x00, 0x00, 0x00, 47 | 0x00, 0x00, 0x5F, 0x00, 0x00, 48 | 0x00, 0x07, 0x00, 0x07, 0x00, 49 | 0x14, 0x7F, 0x14, 0x7F, 0x14, 50 | 0x24, 0x2A, 0x7F, 0x2A, 0x12, 51 | 0x23, 0x13, 0x08, 0x64, 0x62, 52 | 0x36, 0x49, 0x56, 0x20, 0x50, 53 | 0x00, 0x08, 0x07, 0x03, 0x00, 54 | 0x00, 0x1C, 0x22, 0x41, 0x00, 55 | 0x00, 0x41, 0x22, 0x1C, 0x00, 56 | 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 57 | 0x08, 0x08, 0x3E, 0x08, 0x08, 58 | 0x00, 0x80, 0x70, 0x30, 0x00, 59 | 0x08, 0x08, 0x08, 0x08, 0x08, 60 | 0x00, 0x00, 0x60, 0x60, 0x00, 61 | 0x20, 0x10, 0x08, 0x04, 0x02, 62 | 0x3E, 0x51, 0x49, 0x45, 0x3E, 63 | 0x00, 0x42, 0x7F, 0x40, 0x00, 64 | 0x72, 0x49, 0x49, 0x49, 0x46, 65 | 0x21, 0x41, 0x49, 0x4D, 0x33, 66 | 0x18, 0x14, 0x12, 0x7F, 0x10, 67 | 0x27, 0x45, 0x45, 0x45, 0x39, 68 | 0x3C, 0x4A, 0x49, 0x49, 0x31, 69 | 0x41, 0x21, 0x11, 0x09, 0x07, 70 | 0x36, 0x49, 0x49, 0x49, 0x36, 71 | 0x46, 0x49, 0x49, 0x29, 0x1E, 72 | 0x00, 0x00, 0x14, 0x00, 0x00, 73 | 0x00, 0x40, 0x34, 0x00, 0x00, 74 | 0x00, 0x08, 0x14, 0x22, 0x41, 75 | 0x14, 0x14, 0x14, 0x14, 0x14, 76 | 0x00, 0x41, 0x22, 0x14, 0x08, 77 | 0x02, 0x01, 0x59, 0x09, 0x06, 78 | 0x3E, 0x41, 0x5D, 0x59, 0x4E, 79 | 0x7C, 0x12, 0x11, 0x12, 0x7C, 80 | 0x7F, 0x49, 0x49, 0x49, 0x36, 81 | 0x3E, 0x41, 0x41, 0x41, 0x22, 82 | 0x7F, 0x41, 0x41, 0x41, 0x3E, 83 | 0x7F, 0x49, 0x49, 0x49, 0x41, 84 | 0x7F, 0x09, 0x09, 0x09, 0x01, 85 | 0x3E, 0x41, 0x41, 0x51, 0x73, 86 | 0x7F, 0x08, 0x08, 0x08, 0x7F, 87 | 0x00, 0x41, 0x7F, 0x41, 0x00, 88 | 0x20, 0x40, 0x41, 0x3F, 0x01, 89 | 0x7F, 0x08, 0x14, 0x22, 0x41, 90 | 0x7F, 0x40, 0x40, 0x40, 0x40, 91 | 0x7F, 0x02, 0x1C, 0x02, 0x7F, 92 | 0x7F, 0x04, 0x08, 0x10, 0x7F, 93 | 0x3E, 0x41, 0x41, 0x41, 0x3E, 94 | 0x7F, 0x09, 0x09, 0x09, 0x06, 95 | 0x3E, 0x41, 0x51, 0x21, 0x5E, 96 | 0x7F, 0x09, 0x19, 0x29, 0x46, 97 | 0x26, 0x49, 0x49, 0x49, 0x32, 98 | 0x03, 0x01, 0x7F, 0x01, 0x03, 99 | 0x3F, 0x40, 0x40, 0x40, 0x3F, 100 | 0x1F, 0x20, 0x40, 0x20, 0x1F, 101 | 0x3F, 0x40, 0x38, 0x40, 0x3F, 102 | 0x63, 0x14, 0x08, 0x14, 0x63, 103 | 0x03, 0x04, 0x78, 0x04, 0x03, 104 | 0x61, 0x59, 0x49, 0x4D, 0x43, 105 | 0x00, 0x7F, 0x41, 0x41, 0x41, 106 | 0x02, 0x04, 0x08, 0x10, 0x20, 107 | 0x00, 0x41, 0x41, 0x41, 0x7F, 108 | 0x04, 0x02, 0x01, 0x02, 0x04, 109 | 0x40, 0x40, 0x40, 0x40, 0x40, 110 | 0x00, 0x03, 0x07, 0x08, 0x00, 111 | 0x20, 0x54, 0x54, 0x78, 0x40, 112 | 0x7F, 0x28, 0x44, 0x44, 0x38, 113 | 0x38, 0x44, 0x44, 0x44, 0x28, 114 | 0x38, 0x44, 0x44, 0x28, 0x7F, 115 | 0x38, 0x54, 0x54, 0x54, 0x18, 116 | 0x00, 0x08, 0x7E, 0x09, 0x02, 117 | 0x18, 0xA4, 0xA4, 0x9C, 0x78, 118 | 0x7F, 0x08, 0x04, 0x04, 0x78, 119 | 0x00, 0x44, 0x7D, 0x40, 0x00, 120 | 0x20, 0x40, 0x40, 0x3D, 0x00, 121 | 0x7F, 0x10, 0x28, 0x44, 0x00, 122 | 0x00, 0x41, 0x7F, 0x40, 0x00, 123 | 0x7C, 0x04, 0x78, 0x04, 0x78, 124 | 0x7C, 0x08, 0x04, 0x04, 0x78, 125 | 0x38, 0x44, 0x44, 0x44, 0x38, 126 | 0xFC, 0x18, 0x24, 0x24, 0x18, 127 | 0x18, 0x24, 0x24, 0x18, 0xFC, 128 | 0x7C, 0x08, 0x04, 0x04, 0x08, 129 | 0x48, 0x54, 0x54, 0x54, 0x24, 130 | 0x04, 0x04, 0x3F, 0x44, 0x24, 131 | 0x3C, 0x40, 0x40, 0x20, 0x7C, 132 | 0x1C, 0x20, 0x40, 0x20, 0x1C, 133 | 0x3C, 0x40, 0x30, 0x40, 0x3C, 134 | 0x44, 0x28, 0x10, 0x28, 0x44, 135 | 0x4C, 0x90, 0x90, 0x90, 0x7C, 136 | 0x44, 0x64, 0x54, 0x4C, 0x44, 137 | 0x00, 0x08, 0x36, 0x41, 0x00, 138 | 0x00, 0x00, 0x77, 0x00, 0x00, 139 | 0x00, 0x41, 0x36, 0x08, 0x00, 140 | 0x02, 0x01, 0x02, 0x04, 0x02, 141 | 0x3C, 0x26, 0x23, 0x26, 0x3C, 142 | 0x1E, 0xA1, 0xA1, 0x61, 0x12, 143 | 0x3A, 0x40, 0x40, 0x20, 0x7A, 144 | 0x38, 0x54, 0x54, 0x55, 0x59, 145 | 0x21, 0x55, 0x55, 0x79, 0x41, 146 | 0x22, 0x54, 0x54, 0x78, 0x42, // a-umlaut 147 | 0x21, 0x55, 0x54, 0x78, 0x40, 148 | 0x20, 0x54, 0x55, 0x79, 0x40, 149 | 0x0C, 0x1E, 0x52, 0x72, 0x12, 150 | 0x39, 0x55, 0x55, 0x55, 0x59, 151 | 0x39, 0x54, 0x54, 0x54, 0x59, 152 | 0x39, 0x55, 0x54, 0x54, 0x58, 153 | 0x00, 0x00, 0x45, 0x7C, 0x41, 154 | 0x00, 0x02, 0x45, 0x7D, 0x42, 155 | 0x00, 0x01, 0x45, 0x7C, 0x40, 156 | 0x7D, 0x12, 0x11, 0x12, 0x7D, // A-umlaut 157 | 0xF0, 0x28, 0x25, 0x28, 0xF0, 158 | 0x7C, 0x54, 0x55, 0x45, 0x00, 159 | 0x20, 0x54, 0x54, 0x7C, 0x54, 160 | 0x7C, 0x0A, 0x09, 0x7F, 0x49, 161 | 0x32, 0x49, 0x49, 0x49, 0x32, 162 | 0x3A, 0x44, 0x44, 0x44, 0x3A, // o-umlaut 163 | 0x32, 0x4A, 0x48, 0x48, 0x30, 164 | 0x3A, 0x41, 0x41, 0x21, 0x7A, 165 | 0x3A, 0x42, 0x40, 0x20, 0x78, 166 | 0x00, 0x9D, 0xA0, 0xA0, 0x7D, 167 | 0x3D, 0x42, 0x42, 0x42, 0x3D, // O-umlaut 168 | 0x3D, 0x40, 0x40, 0x40, 0x3D, 169 | 0x3C, 0x24, 0xFF, 0x24, 0x24, 170 | 0x48, 0x7E, 0x49, 0x43, 0x66, 171 | 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, 172 | 0xFF, 0x09, 0x29, 0xF6, 0x20, 173 | 0xC0, 0x88, 0x7E, 0x09, 0x03, 174 | 0x20, 0x54, 0x54, 0x79, 0x41, 175 | 0x00, 0x00, 0x44, 0x7D, 0x41, 176 | 0x30, 0x48, 0x48, 0x4A, 0x32, 177 | 0x38, 0x40, 0x40, 0x22, 0x7A, 178 | 0x00, 0x7A, 0x0A, 0x0A, 0x72, 179 | 0x7D, 0x0D, 0x19, 0x31, 0x7D, 180 | 0x26, 0x29, 0x29, 0x2F, 0x28, 181 | 0x26, 0x29, 0x29, 0x29, 0x26, 182 | 0x30, 0x48, 0x4D, 0x40, 0x20, 183 | 0x38, 0x08, 0x08, 0x08, 0x08, 184 | 0x08, 0x08, 0x08, 0x08, 0x38, 185 | 0x2F, 0x10, 0xC8, 0xAC, 0xBA, 186 | 0x2F, 0x10, 0x28, 0x34, 0xFA, 187 | 0x00, 0x00, 0x7B, 0x00, 0x00, 188 | 0x08, 0x14, 0x2A, 0x14, 0x22, 189 | 0x22, 0x14, 0x2A, 0x14, 0x08, 190 | 0xAA, 0x00, 0x55, 0x00, 0xAA, 191 | 0xAA, 0x55, 0xAA, 0x55, 0xAA, 192 | 0x00, 0x00, 0x00, 0xFF, 0x00, 193 | 0x10, 0x10, 0x10, 0xFF, 0x00, 194 | 0x14, 0x14, 0x14, 0xFF, 0x00, 195 | 0x10, 0x10, 0xFF, 0x00, 0xFF, 196 | 0x10, 0x10, 0xF0, 0x10, 0xF0, 197 | 0x14, 0x14, 0x14, 0xFC, 0x00, 198 | 0x14, 0x14, 0xF7, 0x00, 0xFF, 199 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 200 | 0x14, 0x14, 0xF4, 0x04, 0xFC, 201 | 0x14, 0x14, 0x17, 0x10, 0x1F, 202 | 0x10, 0x10, 0x1F, 0x10, 0x1F, 203 | 0x14, 0x14, 0x14, 0x1F, 0x00, 204 | 0x10, 0x10, 0x10, 0xF0, 0x00, 205 | 0x00, 0x00, 0x00, 0x1F, 0x10, 206 | 0x10, 0x10, 0x10, 0x1F, 0x10, 207 | 0x10, 0x10, 0x10, 0xF0, 0x10, 208 | 0x00, 0x00, 0x00, 0xFF, 0x10, 209 | 0x10, 0x10, 0x10, 0x10, 0x10, 210 | 0x10, 0x10, 0x10, 0xFF, 0x10, 211 | 0x00, 0x00, 0x00, 0xFF, 0x14, 212 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 213 | 0x00, 0x00, 0x1F, 0x10, 0x17, 214 | 0x00, 0x00, 0xFC, 0x04, 0xF4, 215 | 0x14, 0x14, 0x17, 0x10, 0x17, 216 | 0x14, 0x14, 0xF4, 0x04, 0xF4, 217 | 0x00, 0x00, 0xFF, 0x00, 0xF7, 218 | 0x14, 0x14, 0x14, 0x14, 0x14, 219 | 0x14, 0x14, 0xF7, 0x00, 0xF7, 220 | 0x14, 0x14, 0x14, 0x17, 0x14, 221 | 0x10, 0x10, 0x1F, 0x10, 0x1F, 222 | 0x14, 0x14, 0x14, 0xF4, 0x14, 223 | 0x10, 0x10, 0xF0, 0x10, 0xF0, 224 | 0x00, 0x00, 0x1F, 0x10, 0x1F, 225 | 0x00, 0x00, 0x00, 0x1F, 0x14, 226 | 0x00, 0x00, 0x00, 0xFC, 0x14, 227 | 0x00, 0x00, 0xF0, 0x10, 0xF0, 228 | 0x10, 0x10, 0xFF, 0x10, 0xFF, 229 | 0x14, 0x14, 0x14, 0xFF, 0x14, 230 | 0x10, 0x10, 0x10, 0x1F, 0x00, 231 | 0x00, 0x00, 0x00, 0xF0, 0x10, 232 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 233 | 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 234 | 0xFF, 0xFF, 0xFF, 0x00, 0x00, 235 | 0x00, 0x00, 0x00, 0xFF, 0xFF, 236 | 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 237 | 0x38, 0x44, 0x44, 0x38, 0x44, 238 | 0xFC, 0x4A, 0x4A, 0x4A, 0x34, // sharp-s or beta 239 | 0x7E, 0x02, 0x02, 0x06, 0x06, 240 | 0x02, 0x7E, 0x02, 0x7E, 0x02, 241 | 0x63, 0x55, 0x49, 0x41, 0x63, 242 | 0x38, 0x44, 0x44, 0x3C, 0x04, 243 | 0x40, 0x7E, 0x20, 0x1E, 0x20, 244 | 0x06, 0x02, 0x7E, 0x02, 0x02, 245 | 0x99, 0xA5, 0xE7, 0xA5, 0x99, 246 | 0x1C, 0x2A, 0x49, 0x2A, 0x1C, 247 | 0x4C, 0x72, 0x01, 0x72, 0x4C, 248 | 0x30, 0x4A, 0x4D, 0x4D, 0x30, 249 | 0x30, 0x48, 0x78, 0x48, 0x30, 250 | 0xBC, 0x62, 0x5A, 0x46, 0x3D, 251 | 0x3E, 0x49, 0x49, 0x49, 0x00, 252 | 0x7E, 0x01, 0x01, 0x01, 0x7E, 253 | 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 254 | 0x44, 0x44, 0x5F, 0x44, 0x44, 255 | 0x40, 0x51, 0x4A, 0x44, 0x40, 256 | 0x40, 0x44, 0x4A, 0x51, 0x40, 257 | 0x00, 0x00, 0xFF, 0x01, 0x03, 258 | 0xE0, 0x80, 0xFF, 0x00, 0x00, 259 | 0x08, 0x08, 0x6B, 0x6B, 0x08, 260 | 0x36, 0x12, 0x36, 0x24, 0x36, 261 | 0x06, 0x0F, 0x09, 0x0F, 0x06, 262 | 0x00, 0x00, 0x18, 0x18, 0x00, 263 | 0x00, 0x00, 0x10, 0x10, 0x00, 264 | 0x30, 0x40, 0xFF, 0x01, 0x01, 265 | 0x00, 0x1F, 0x01, 0x01, 0x1E, 266 | 0x00, 0x19, 0x1D, 0x17, 0x12, 267 | 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 268 | 0x00, 0x00, 0x00, 0x00, 0x00 269 | }; 270 | #endif // FONT5X7_H 271 | -------------------------------------------------------------------------------- /module/ssd1306_driver_adafruit/Adafruit_GFX.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | This is a port of the Adafruit GFX library to Nordic nRF52832. 3 | 4 | electronut.in 5 | ******************************************************************/ 6 | 7 | /****************************************************************** 8 | This is the core graphics library for all our displays, providing 9 | basic graphics primitives (points, lines, circles, etc.). It needs 10 | to be paired with a hardware-specific library for each display 11 | device we carry (handling the lower-level functions). 12 | 13 | Adafruit invests time and resources providing this open 14 | source code, please support Adafruit and open-source hardware 15 | by purchasing products from Adafruit! 16 | 17 | Written by Limor Fried/Ladyada for Adafruit Industries. 18 | BSD license, check license.txt for more information. 19 | All text above must be included in any redistribution. 20 | ******************************************************************/ 21 | 22 | #include 23 | 24 | #include "Adafruit_GFX.h" 25 | #include "glcdfont.c" 26 | 27 | #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) 28 | 29 | static int16_t WIDTH, HEIGHT; // this is the 'raw' display w/h - never changes 30 | static int16_t _width, _height; // dependent on rotation 31 | static int16_t cursor_x, cursor_y; 32 | static uint16_t textcolor, textbgcolor; 33 | static uint8_t textsize; 34 | static uint8_t rotation; 35 | static bool wrap; // If set, 'wrap' text at right edge of display 36 | static DrawPixelHandler _drawPixel; 37 | 38 | void Adafruit_GFX_init(int16_t w, int16_t h, DrawPixelHandler drawPixel) 39 | { 40 | _width = WIDTH = w; 41 | _height = HEIGHT = h; 42 | _drawPixel = drawPixel; 43 | 44 | rotation = 0; 45 | cursor_y = cursor_x = 0; 46 | textsize = 1; 47 | textcolor = textbgcolor = 0xFFFF; 48 | wrap = true; 49 | } 50 | 51 | // draw a circle outline 52 | void Adafruit_GFX_drawCircle(int16_t x0, int16_t y0, int16_t r, 53 | uint16_t color) 54 | { 55 | int16_t f = 1 - r; 56 | int16_t ddF_x = 1; 57 | int16_t ddF_y = -2 * r; 58 | int16_t x = 0; 59 | int16_t y = r; 60 | 61 | Adafruit_GFX_drawPixel(x0, y0+r, color); 62 | Adafruit_GFX_drawPixel(x0, y0-r, color); 63 | Adafruit_GFX_drawPixel(x0+r, y0, color); 64 | Adafruit_GFX_drawPixel(x0-r, y0, color); 65 | 66 | while (x= 0) { 68 | y--; 69 | ddF_y += 2; 70 | f += ddF_y; 71 | } 72 | x++; 73 | ddF_x += 2; 74 | f += ddF_x; 75 | 76 | Adafruit_GFX_drawPixel(x0 + x, y0 + y, color); 77 | Adafruit_GFX_drawPixel(x0 - x, y0 + y, color); 78 | Adafruit_GFX_drawPixel(x0 + x, y0 - y, color); 79 | Adafruit_GFX_drawPixel(x0 - x, y0 - y, color); 80 | Adafruit_GFX_drawPixel(x0 + y, y0 + x, color); 81 | Adafruit_GFX_drawPixel(x0 - y, y0 + x, color); 82 | Adafruit_GFX_drawPixel(x0 + y, y0 - x, color); 83 | Adafruit_GFX_drawPixel(x0 - y, y0 - x, color); 84 | } 85 | } 86 | 87 | void Adafruit_GFX_drawCircleHelper( int16_t x0, int16_t y0, 88 | int16_t r, uint8_t cornername, uint16_t color) { 89 | int16_t f = 1 - r; 90 | int16_t ddF_x = 1; 91 | int16_t ddF_y = -2 * r; 92 | int16_t x = 0; 93 | int16_t y = r; 94 | 95 | while (x= 0) { 97 | y--; 98 | ddF_y += 2; 99 | f += ddF_y; 100 | } 101 | x++; 102 | ddF_x += 2; 103 | f += ddF_x; 104 | if (cornername & 0x4) { 105 | Adafruit_GFX_drawPixel(x0 + x, y0 + y, color); 106 | Adafruit_GFX_drawPixel(x0 + y, y0 + x, color); 107 | } 108 | if (cornername & 0x2) { 109 | Adafruit_GFX_drawPixel(x0 + x, y0 - y, color); 110 | Adafruit_GFX_drawPixel(x0 + y, y0 - x, color); 111 | } 112 | if (cornername & 0x8) { 113 | Adafruit_GFX_drawPixel(x0 - y, y0 + x, color); 114 | Adafruit_GFX_drawPixel(x0 - x, y0 + y, color); 115 | } 116 | if (cornername & 0x1) { 117 | Adafruit_GFX_drawPixel(x0 - y, y0 - x, color); 118 | Adafruit_GFX_drawPixel(x0 - x, y0 - y, color); 119 | } 120 | } 121 | } 122 | 123 | void Adafruit_GFX_fillCircle(int16_t x0, int16_t y0, int16_t r, 124 | uint16_t color) { 125 | Adafruit_GFX_drawFastVLine(x0, y0-r, 2*r+1, color); 126 | Adafruit_GFX_fillCircleHelper(x0, y0, r, 3, 0, color); 127 | } 128 | 129 | // used to do circles and roundrects! 130 | void Adafruit_GFX_fillCircleHelper(int16_t x0, int16_t y0, int16_t r, 131 | uint8_t cornername, int16_t delta, uint16_t color) { 132 | 133 | int16_t f = 1 - r; 134 | int16_t ddF_x = 1; 135 | int16_t ddF_y = -2 * r; 136 | int16_t x = 0; 137 | int16_t y = r; 138 | 139 | while (x= 0) { 141 | y--; 142 | ddF_y += 2; 143 | f += ddF_y; 144 | } 145 | x++; 146 | ddF_x += 2; 147 | f += ddF_x; 148 | 149 | if (cornername & 0x1) { 150 | Adafruit_GFX_drawFastVLine(x0+x, y0-y, 2*y+1+delta, color); 151 | Adafruit_GFX_drawFastVLine(x0+y, y0-x, 2*x+1+delta, color); 152 | } 153 | if (cornername & 0x2) { 154 | Adafruit_GFX_drawFastVLine(x0-x, y0-y, 2*y+1+delta, color); 155 | Adafruit_GFX_drawFastVLine(x0-y, y0-x, 2*x+1+delta, color); 156 | } 157 | } 158 | } 159 | 160 | // bresenham's algorithm - thx wikpedia 161 | void Adafruit_GFX_drawLine(int16_t x0, int16_t y0, 162 | int16_t x1, int16_t y1, 163 | uint16_t color) { 164 | int16_t steep = abs(y1 - y0) > abs(x1 - x0); 165 | if (steep) { 166 | swap(x0, y0); 167 | swap(x1, y1); 168 | } 169 | 170 | if (x0 > x1) { 171 | swap(x0, x1); 172 | swap(y0, y1); 173 | } 174 | 175 | int16_t dx, dy; 176 | dx = x1 - x0; 177 | dy = abs(y1 - y0); 178 | 179 | int16_t err = dx / 2; 180 | int16_t ystep; 181 | 182 | if (y0 < y1) { 183 | ystep = 1; 184 | } else { 185 | ystep = -1; 186 | } 187 | 188 | for (; x0<=x1; x0++) { 189 | if (steep) { 190 | Adafruit_GFX_drawPixel(y0, x0, color); 191 | } else { 192 | Adafruit_GFX_drawPixel(x0, y0, color); 193 | } 194 | err -= dy; 195 | if (err < 0) { 196 | y0 += ystep; 197 | err += dx; 198 | } 199 | } 200 | } 201 | 202 | 203 | // draw a rectangle 204 | void Adafruit_GFX_drawRect(int16_t x, int16_t y, 205 | int16_t w, int16_t h, 206 | uint16_t color) { 207 | Adafruit_GFX_drawFastHLine(x, y, w, color); 208 | Adafruit_GFX_drawFastHLine(x, y+h-1, w, color); 209 | Adafruit_GFX_drawFastVLine(x, y, h, color); 210 | Adafruit_GFX_drawFastVLine(x+w-1, y, h, color); 211 | } 212 | 213 | void Adafruit_GFX_drawFastVLine(int16_t x, int16_t y, 214 | int16_t h, uint16_t color) { 215 | // stupidest version - update in subclasses if desired! 216 | Adafruit_GFX_drawLine(x, y, x, y+h-1, color); 217 | } 218 | 219 | 220 | void Adafruit_GFX_drawFastHLine(int16_t x, int16_t y, 221 | int16_t w, uint16_t color) { 222 | // stupidest version - update in subclasses if desired! 223 | Adafruit_GFX_drawLine(x, y, x+w-1, y, color); 224 | } 225 | 226 | void Adafruit_GFX_fillRect(int16_t x, int16_t y, int16_t w, int16_t h, 227 | uint16_t color) { 228 | // stupidest version - update in subclasses if desired! 229 | for (int16_t i=x; i= y1 >= y0) 282 | if (y0 > y1) { 283 | swap(y0, y1); swap(x0, x1); 284 | } 285 | if (y1 > y2) { 286 | swap(y2, y1); swap(x2, x1); 287 | } 288 | if (y0 > y1) { 289 | swap(y0, y1); swap(x0, x1); 290 | } 291 | 292 | if(y0 == y2) { // Handle awkward all-on-same-line case as its own thing 293 | a = b = x0; 294 | if(x1 < a) a = x1; 295 | else if(x1 > b) b = x1; 296 | if(x2 < a) a = x2; 297 | else if(x2 > b) b = x2; 298 | Adafruit_GFX_drawFastHLine(a, y0, b-a+1, color); 299 | return; 300 | } 301 | 302 | int16_t 303 | dx01 = x1 - x0, 304 | dy01 = y1 - y0, 305 | dx02 = x2 - x0, 306 | dy02 = y2 - y0, 307 | dx12 = x2 - x1, 308 | dy12 = y2 - y1, 309 | sa = 0, 310 | sb = 0; 311 | 312 | // For upper part of triangle, find scanline crossings for segments 313 | // 0-1 and 0-2. If y1=y2 (flat-bottomed triangle), the scanline y1 314 | // is included here (and second loop will be skipped, avoiding a /0 315 | // error there), otherwise scanline y1 is skipped here and handled 316 | // in the second loop...which also avoids a /0 error here if y0=y1 317 | // (flat-topped triangle). 318 | if(y1 == y2) last = y1; // Include y1 scanline 319 | else last = y1-1; // Skip it 320 | 321 | for(y=y0; y<=last; y++) { 322 | a = x0 + sa / dy01; 323 | b = x0 + sb / dy02; 324 | sa += dx01; 325 | sb += dx02; 326 | /* longhand: 327 | a = x0 + (x1 - x0) * (y - y0) / (y1 - y0); 328 | b = x0 + (x2 - x0) * (y - y0) / (y2 - y0); 329 | */ 330 | if(a > b) swap(a,b); 331 | Adafruit_GFX_drawFastHLine(a, y, b-a+1, color); 332 | } 333 | 334 | // For lower part of triangle, find scanline crossings for segments 335 | // 0-2 and 1-2. This loop is skipped if y1=y2. 336 | sa = dx12 * (y - y1); 337 | sb = dx02 * (y - y0); 338 | for(; y<=y2; y++) { 339 | a = x1 + sa / dy12; 340 | b = x0 + sb / dy02; 341 | sa += dx12; 342 | sb += dx02; 343 | /* longhand: 344 | a = x1 + (x2 - x1) * (y - y1) / (y2 - y1); 345 | b = x0 + (x2 - x0) * (y - y0) / (y2 - y0); 346 | */ 347 | if(a > b) swap(a,b); 348 | Adafruit_GFX_drawFastHLine(a, y, b-a+1, color); 349 | } 350 | } 351 | 352 | void Adafruit_GFX_drawBitmap(int16_t x, int16_t y, 353 | const uint8_t *bitmap, int16_t w, int16_t h, 354 | uint16_t color) { 355 | 356 | int16_t i, j, byteWidth = (w + 7) / 8; 357 | 358 | for(j=0; j> (i & 7))) { 361 | Adafruit_GFX_drawPixel(x+i, y+j, color); 362 | } 363 | } 364 | } 365 | } 366 | 367 | 368 | void Adafruit_GFX_write(uint8_t c) { 369 | if (c == '\n') { 370 | cursor_y += textsize*8; 371 | cursor_x = 0; 372 | } else if (c == '\r') { 373 | // skip em 374 | } else { 375 | Adafruit_GFX_drawChar(cursor_x, cursor_y, c, textcolor, textbgcolor, textsize); 376 | cursor_x += textsize*6; 377 | if (wrap && (cursor_x > (_width - textsize*6))) { 378 | cursor_y += textsize*8; 379 | cursor_x = 0; 380 | } 381 | } 382 | 383 | } 384 | 385 | // draw a character 386 | void Adafruit_GFX_drawChar(int16_t x, int16_t y, unsigned char c, 387 | uint16_t color, uint16_t bg, uint8_t size) { 388 | 389 | if((x >= _width) || // Clip right 390 | (y >= _height) || // Clip bottom 391 | ((x + 5 * size - 1) < 0) || // Clip left 392 | ((y + 8 * size - 1) < 0)) // Clip top 393 | return; 394 | 395 | for (int8_t i=0; i<6; i++ ) { 396 | uint8_t line; 397 | if (i == 5) 398 | line = 0x0; 399 | else 400 | line = pgm_read_byte(font+(c*5)+i); 401 | for (int8_t j = 0; j<8; j++) { 402 | if (line & 0x1) { 403 | if (size == 1) // default size 404 | Adafruit_GFX_drawPixel(x+i, y+j, color); 405 | else { // big size 406 | Adafruit_GFX_fillRect(x+(i*size), y+(j*size), size, size, color); 407 | } 408 | } else if (bg != color) { 409 | if (size == 1) // default size 410 | Adafruit_GFX_drawPixel(x+i, y+j, bg); 411 | else { // big size 412 | Adafruit_GFX_fillRect(x+i*size, y+j*size, size, size, bg); 413 | } 414 | } 415 | line >>= 1; 416 | } 417 | } 418 | } 419 | 420 | void Adafruit_GFX_setCursor(int16_t x, int16_t y) { 421 | cursor_x = x; 422 | cursor_y = y; 423 | } 424 | 425 | 426 | void Adafruit_GFX_setTextSize(uint8_t s) { 427 | textsize = (s > 0) ? s : 1; 428 | } 429 | 430 | 431 | 432 | void Adafruit_GFX_setTextColor(uint16_t c, uint16_t b) { 433 | textcolor = c; 434 | textbgcolor = b; 435 | } 436 | 437 | void Adafruit_GFX_setTextWrap(bool w) { 438 | wrap = w; 439 | } 440 | 441 | uint8_t Adafruit_GFX_getRotation(void) { 442 | rotation %= 4; 443 | return rotation; 444 | } 445 | 446 | void Adafruit_GFX_setRotation(uint8_t x) { 447 | x %= 4; // cant be higher than 3 448 | rotation = x; 449 | switch (x) { 450 | case 0: 451 | case 2: 452 | _width = WIDTH; 453 | _height = HEIGHT; 454 | break; 455 | case 1: 456 | case 3: 457 | _width = HEIGHT; 458 | _height = WIDTH; 459 | break; 460 | } 461 | } 462 | 463 | void Adafruit_GFX_invertDisplay(bool i) { 464 | // do nothing, can be subclassed 465 | } 466 | 467 | 468 | // return the size of the display which depends on the rotation! 469 | int16_t Adafruit_GFX_width(void) { 470 | return _width; 471 | } 472 | 473 | int16_t Adafruit_GFX_height(void) { 474 | return _height; 475 | } 476 | 477 | void Adafruit_GFX_drawPixel(int16_t x, int16_t y, uint16_t color) { 478 | if(_drawPixel) { 479 | _drawPixel(x, y, color); 480 | } 481 | } 482 | -------------------------------------------------------------------------------- /module/ssd1306_driver_adafruit/Adafruit_GFX.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | This is a port of the Adafruit GFX library to Nordic nRF52832. 3 | 4 | electronut.in 5 | ******************************************************************/ 6 | 7 | /****************************************************************** 8 | This is the core graphics library for all our displays, providing 9 | basic graphics primitives (points, lines, circles, etc.). It needs 10 | to be paired with a hardware-specific library for each display 11 | device we carry (handling the lower-level functions). 12 | 13 | Adafruit invests time and resources providing this open 14 | source code, please support Adafruit and open-source hardware 15 | by purchasing products from Adafruit! 16 | 17 | Written by Limor Fried/Ladyada for Adafruit Industries. 18 | BSD license, check license.txt for more information. 19 | All text above must be included in any redistribution. 20 | ******************************************************************/ 21 | 22 | #ifndef _ADAFRUIT_GFX_H 23 | #define _ADAFRUIT_GFX_H 24 | 25 | #include 26 | #include 27 | #include "nordic_common.h" 28 | 29 | #define swap(a, b) { int16_t t = a; a = b; b = t; } 30 | 31 | 32 | 33 | // function pointer for drawPixels 34 | typedef void (*DrawPixelHandler)(int16_t x, int16_t y, uint16_t color) ; 35 | 36 | 37 | // need to pass in the handler for drawing a pixel 38 | void Adafruit_GFX_init(int16_t w, int16_t h, DrawPixelHandler drawPixel); 39 | 40 | // 41 | void Adafruit_GFX_drawPixel(int16_t x, int16_t y, uint16_t color); 42 | 43 | void Adafruit_GFX_invertDisplay(bool i); 44 | 45 | // these are 'generic' drawing functions, so we can share them! 46 | void Adafruit_GFX_drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, 47 | uint16_t color); 48 | void Adafruit_GFX_drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); 49 | void Adafruit_GFX_drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); 50 | void Adafruit_GFX_drawRect(int16_t x, int16_t y, int16_t w, int16_t h, 51 | uint16_t color); 52 | void Adafruit_GFX_fillRect(int16_t x, int16_t y, int16_t w, int16_t h, 53 | uint16_t color); 54 | void Adafruit_GFX_fillScreen(uint16_t color); 55 | 56 | void Adafruit_GFX_drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color); 57 | void Adafruit_GFX_drawCircleHelper(int16_t x0, int16_t y0, 58 | int16_t r, uint8_t cornername, uint16_t color); 59 | void Adafruit_GFX_fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color); 60 | void Adafruit_GFX_fillCircleHelper(int16_t x0, int16_t y0, int16_t r, 61 | uint8_t cornername, int16_t delta, uint16_t color); 62 | 63 | void Adafruit_GFX_drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, 64 | int16_t x2, int16_t y2, uint16_t color); 65 | void Adafruit_GFX_fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, 66 | int16_t x2, int16_t y2, uint16_t color); 67 | void Adafruit_GFX_drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, 68 | int16_t radius, uint16_t color); 69 | void Adafruit_GFX_fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h, 70 | int16_t radius, uint16_t color); 71 | 72 | void Adafruit_GFX_drawBitmap(int16_t x, int16_t y, 73 | const uint8_t *bitmap, int16_t w, int16_t h, 74 | uint16_t color); 75 | void Adafruit_GFX_drawChar(int16_t x, int16_t y, unsigned char c, 76 | uint16_t color, uint16_t bg, uint8_t size); 77 | 78 | void Adafruit_GFX_write(uint8_t); 79 | 80 | void Adafruit_GFX_setCursor(int16_t x, int16_t y); 81 | void Adafruit_GFX_setTextColor(uint16_t c, uint16_t bg); 82 | void Adafruit_GFX_setTextSize(uint8_t s); 83 | void Adafruit_GFX_setTextWrap(bool w); 84 | 85 | int16_t Adafruit_GFX_height(void); 86 | int16_t Adafruit_GFX_width(void); 87 | 88 | void Adafruit_GFX_setRotation(uint8_t r); 89 | uint8_t Adafruit_GFX_getRotation(void); 90 | 91 | #endif 92 | -------------------------------------------------------------------------------- /module/ssd1306_driver_adafruit/SSD1306.c: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | This is a port of the Adafruit SSD1306 driver to Nordic nRF52832. 3 | 4 | Currently only I2C supported. 5 | 6 | Original: 7 | 8 | https://github.com/adafruit/Adafruit_SSD1306 9 | 10 | electronut.in 11 | *********************************************************************/ 12 | 13 | #include 14 | #include 15 | 16 | #include "nrf_drv_twi.h" 17 | #include "app_error.h" 18 | 19 | #include "SSD1306.h" 20 | 21 | // TWI handle 22 | extern nrf_drv_twi_t m_twi_master; 23 | 24 | static int WIDTH = SSD1306_LCDWIDTH; 25 | static int HEIGHT = SSD1306_LCDHEIGHT; 26 | 27 | static int8_t _i2caddr, _vccstate; 28 | /* 29 | // You will need something like this in your main.c: 30 | 31 | const nrf_drv_twi_t m_twi_master = NRF_DRV_TWI_INSTANCE(0); 32 | 33 | void twi_init (void) 34 | { 35 | ret_code_t err_code; 36 | 37 | const nrf_drv_twi_config_t twi_sensors_config = { 38 | .scl = 11, 39 | .sda = 13, 40 | .frequency = NRF_TWI_FREQ_100K, 41 | .interrupt_priority = APP_IRQ_PRIORITY_HIGH 42 | }; 43 | 44 | err_code = nrf_drv_twi_init(&m_twi_master, &twi_sensors_config, NULL, NULL); // twi in blocking mode. 45 | APP_ERROR_CHECK(err_code); 46 | 47 | nrf_drv_twi_enable(&m_twi_master); 48 | } 49 | */ 50 | 51 | // the memory buffer for the LCD 52 | #if 0 53 | static uint8_t buffer[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8] = { 54 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 55 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 56 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 57 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 58 | 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 59 | 0x00, 0x80, 0x80, 0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 60 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 61 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 62 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 63 | 0x00, 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xF8, 0xE0, 0x00, 0x00, 0x00, 0x00, 64 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 65 | 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00, 0xFF, 66 | #if (SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH > 96*16) 67 | 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 68 | 0x80, 0xFF, 0xFF, 0x80, 0x80, 0x00, 0x80, 0x80, 0x00, 0x80, 0x80, 0x80, 0x80, 0x00, 0x80, 0x80, 69 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x80, 0x00, 0x00, 0x8C, 0x8E, 0x84, 0x00, 0x00, 0x80, 0xF8, 70 | 0xF8, 0xF8, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 71 | 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 0xE0, 0xE0, 0xC0, 0x80, 72 | 0x00, 0xE0, 0xFC, 0xFE, 0xFF, 0xFF, 0xFF, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 73 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xC7, 0x01, 0x01, 74 | 0x01, 0x01, 0x83, 0xFF, 0xFF, 0x00, 0x00, 0x7C, 0xFE, 0xC7, 0x01, 0x01, 0x01, 0x01, 0x83, 0xFF, 75 | 0xFF, 0xFF, 0x00, 0x38, 0xFE, 0xC7, 0x83, 0x01, 0x01, 0x01, 0x83, 0xC7, 0xFF, 0xFF, 0x00, 0x00, 76 | 0x01, 0xFF, 0xFF, 0x01, 0x01, 0x00, 0xFF, 0xFF, 0x07, 0x01, 0x01, 0x01, 0x00, 0x00, 0x7F, 0xFF, 77 | 0x80, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x7F, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x01, 0xFF, 78 | 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 79 | 0x03, 0x0F, 0x3F, 0x7F, 0x7F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE7, 0xC7, 0xC7, 0x8F, 80 | 0x8F, 0x9F, 0xBF, 0xFF, 0xFF, 0xC3, 0xC0, 0xF0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFC, 0xFC, 0xFC, 81 | 0xFC, 0xFC, 0xFC, 0xFC, 0xFC, 0xF8, 0xF8, 0xF0, 0xF0, 0xE0, 0xC0, 0x00, 0x01, 0x03, 0x03, 0x03, 82 | 0x03, 0x03, 0x01, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 83 | 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x03, 0x01, 0x01, 0x03, 0x03, 0x00, 0x00, 84 | 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 85 | 0x03, 0x03, 0x03, 0x03, 0x03, 0x01, 0x00, 0x00, 0x00, 0x01, 0x03, 0x01, 0x00, 0x00, 0x00, 0x03, 86 | 0x03, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 87 | #if (SSD1306_LCDHEIGHT == 64) 88 | 0x00, 0x00, 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF9, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3F, 0x1F, 0x0F, 89 | 0x87, 0xC7, 0xF7, 0xFF, 0xFF, 0x1F, 0x1F, 0x3D, 0xFC, 0xF8, 0xF8, 0xF8, 0xF8, 0x7C, 0x7D, 0xFF, 90 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x3F, 0x0F, 0x07, 0x00, 0x30, 0x30, 0x00, 0x00, 91 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 92 | 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0xFC, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 93 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xC0, 0x00, 94 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x30, 0x00, 0x00, 0x00, 0x00, 95 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 96 | 0x00, 0xC0, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x7F, 0x7F, 0x3F, 0x1F, 97 | 0x0F, 0x07, 0x1F, 0x7F, 0xFF, 0xFF, 0xF8, 0xF8, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFE, 0xF8, 0xE0, 98 | 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 99 | 0x00, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x0E, 0xFC, 0xF8, 0x00, 0x00, 0xF0, 0xF8, 0x1C, 0x0E, 100 | 0x06, 0x06, 0x06, 0x0C, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0x00, 0x00, 0xFC, 101 | 0xFE, 0xFC, 0x00, 0x18, 0x3C, 0x7E, 0x66, 0xE6, 0xCE, 0x84, 0x00, 0x00, 0x06, 0xFF, 0xFF, 0x06, 102 | 0x06, 0xFC, 0xFE, 0xFC, 0x0C, 0x06, 0x06, 0x06, 0x00, 0x00, 0xFE, 0xFE, 0x00, 0x00, 0xC0, 0xF8, 103 | 0xFC, 0x4E, 0x46, 0x46, 0x46, 0x4E, 0x7C, 0x78, 0x40, 0x18, 0x3C, 0x76, 0xE6, 0xCE, 0xCC, 0x80, 104 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 105 | 0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0F, 0x1F, 0x1F, 0x3F, 0x3F, 0x3F, 0x3F, 0x1F, 0x0F, 0x03, 106 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 107 | 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x03, 0x07, 0x0E, 0x0C, 108 | 0x18, 0x18, 0x0C, 0x06, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x01, 0x0F, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 109 | 0x07, 0x01, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 110 | 0x00, 0x0F, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0x0F, 0x00, 0x00, 0x00, 0x07, 111 | 0x07, 0x0C, 0x0C, 0x18, 0x1C, 0x0C, 0x06, 0x06, 0x00, 0x04, 0x0E, 0x0C, 0x18, 0x0C, 0x0F, 0x07, 112 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 113 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 114 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 115 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 116 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 117 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 118 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 119 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 120 | #endif 121 | #endif 122 | }; 123 | #else 124 | 125 | static uint8_t buffer[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8] = 126 | { 127 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc0, 128 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc0, 129 | 0xff,0xff,0xff,0xff,0xff,0xe1,0xff,0xff,0xff,0xff,0xc0, 130 | 0xff,0xff,0xff,0xff,0xff,0xe0,0xff,0xff,0xff,0xff,0xc0, 131 | 0xff,0xff,0xff,0xff,0xff,0xc0,0xff,0xff,0xff,0xff,0xc0, 132 | 0xff,0xff,0xff,0xff,0xff,0x80,0x7f,0xff,0xff,0xff,0xc0, 133 | 0xff,0xff,0xff,0xff,0xff,0x0,0x7f,0xff,0xff,0xff,0xc0, 134 | 0xff,0xff,0xff,0xff,0xff,0x0,0x7f,0xff,0xff,0xff,0xc0, 135 | 0xff,0xff,0xff,0xff,0xfe,0x0,0x3f,0xff,0xff,0xff,0xc0, 136 | 0xff,0xff,0xff,0xff,0xfc,0x0,0x3f,0xff,0xff,0xff,0xc0, 137 | 0xff,0xff,0xff,0xff,0xfc,0x0,0x3f,0xff,0xff,0xff,0xc0, 138 | 0xff,0xff,0xff,0xff,0xf8,0x0,0x1f,0xff,0xff,0xff,0xc0, 139 | 0xff,0xff,0xff,0xff,0xf0,0x0,0x1f,0xff,0xff,0xff,0xc0, 140 | 0xff,0xff,0xff,0xff,0xe0,0x0,0x1f,0xff,0xff,0xff,0xc0, 141 | 0xff,0xff,0xff,0xff,0xe0,0x0,0x1f,0xff,0xff,0xff,0xc0, 142 | 0xff,0xff,0xff,0xff,0xc0,0x0,0xf,0xff,0xff,0xff,0xc0, 143 | 0xff,0xff,0xff,0xff,0xc0,0x0,0xf,0xff,0xff,0xff,0xc0, 144 | 0xff,0xff,0xff,0xff,0x80,0x0,0xf,0xff,0xff,0xff,0xc0, 145 | 0xff,0xff,0xff,0xff,0x80,0x0,0x7,0xff,0xff,0xff,0xc0, 146 | 0xff,0xff,0xff,0xff,0x80,0x0,0x7,0xff,0xff,0xff,0xc0, 147 | 0xff,0x0,0x0,0x3f,0x80,0x0,0x7,0xff,0xff,0xff,0xc0, 148 | 0xfe,0x0,0x0,0x7,0x80,0x0,0x7,0xff,0xff,0xff,0xc0, 149 | 0xfe,0x0,0x0,0x1,0x80,0x0,0x7,0xff,0xff,0xff,0xc0, 150 | 0xfe,0x0,0x0,0x0,0x80,0x0,0x7,0xff,0xff,0xff,0xc0, 151 | 0xfe,0x0,0x0,0x0,0x0,0x0,0xf,0xff,0xff,0xff,0xc0, 152 | 0xff,0x0,0x0,0x0,0x0,0x0,0xf,0xff,0xff,0xff,0xc0, 153 | 0xff,0x80,0x0,0x0,0x0,0x60,0x18,0x3,0xff,0xff,0xc0, 154 | 0xff,0xc0,0x0,0x0,0x0,0xe0,0x0,0x0,0x3f,0xff,0xc0, 155 | 0xff,0xc0,0x0,0x0,0x0,0xe0,0x0,0x0,0x7,0xff,0xc0, 156 | 0xff,0xe0,0x0,0x0,0x0,0xe0,0x0,0x0,0x0,0xff,0xc0, 157 | 0xff,0xf0,0x0,0x0,0x0,0xe0,0x0,0x0,0x0,0x1f,0xc0, 158 | 0xff,0xf0,0x0,0x0,0x1,0xe0,0x0,0x0,0x0,0xf,0xc0, 159 | 0xff,0xf8,0x0,0xf,0x0,0xe0,0x0,0x0,0x0,0xf,0xc0, 160 | 0xff,0xfc,0x0,0x7,0xc0,0xc0,0x0,0x0,0x0,0xf,0xc0, 161 | 0xff,0xfe,0x0,0x7,0xf0,0x80,0x0,0x0,0x0,0xf,0xc0, 162 | 0xff,0xfe,0x0,0x1,0xf0,0x1,0xf0,0x0,0x0,0x1f,0xc0, 163 | 0xff,0xff,0x0,0x0,0xf8,0x7,0xf8,0x0,0x0,0x3f,0xc0, 164 | 0xff,0xff,0x80,0x0,0x0,0xf,0xf0,0x0,0x0,0xff,0xc0, 165 | 0xff,0xff,0xe0,0x0,0x0,0xf,0xc0,0x0,0x1,0xff,0xc0, 166 | 0xff,0xff,0xf0,0x0,0x0,0x0,0x0,0x0,0x3,0xff,0xc0, 167 | 0xff,0xff,0xfe,0x0,0x0,0x0,0x0,0x0,0xf,0xff,0xc0, 168 | 0xff,0xff,0xff,0x0,0x1c,0x0,0x0,0x0,0x1f,0xff,0xc0, 169 | 0xff,0xff,0xfc,0x0,0x3c,0x70,0x0,0x0,0x7f,0xff,0xc0, 170 | 0xff,0xff,0xf8,0x0,0xf8,0x70,0x0,0x0,0xff,0xff,0xc0, 171 | 0xff,0xff,0xf0,0x0,0xf0,0x78,0x0,0x3,0xff,0xff,0xc0, 172 | 0xff,0xff,0xe0,0x1,0xe0,0x3c,0x2,0x1f,0xff,0xff,0xc0, 173 | 0xff,0xff,0xe0,0x1,0xc0,0x3c,0x1,0xff,0xff,0xff,0xc0, 174 | 0xff,0xff,0xc0,0x1,0x80,0x1c,0x0,0xff,0xff,0xff,0xc0, 175 | 0xff,0xff,0xc0,0x0,0x0,0x1c,0x0,0xff,0xff,0xff,0xc0, 176 | 0xff,0xff,0x80,0x0,0x0,0xc,0x0,0x7f,0xff,0xff,0xc0, 177 | 0xff,0xff,0x80,0x0,0x0,0x0,0x0,0x7f,0xff,0xff,0xc0, 178 | 0xff,0xff,0x80,0x0,0x0,0x0,0x0,0x3f,0xff,0xff,0xc0, 179 | 0xff,0xff,0x0,0x0,0x0,0x0,0x0,0x3f,0xff,0xff,0xc0, 180 | 0xff,0xff,0x0,0x0,0x0,0x0,0x0,0x3f,0xff,0xff,0xc0, 181 | 0xff,0xff,0x0,0x0,0x4,0x0,0x0,0x3f,0xff,0xff,0xc0, 182 | 0xff,0xfe,0x0,0x0,0x4,0x0,0x0,0x3f,0xff,0xff,0xc0, 183 | 0xff,0xfe,0x0,0x0,0xc,0x0,0x0,0x3f,0xff,0xff,0xc0, 184 | 0xff,0xfe,0x0,0x0,0x1e,0x0,0x0,0x3f,0xff,0xff,0xc0, 185 | 0xff,0xfc,0x0,0x0,0x3e,0x0,0x0,0x3f,0xff,0xff,0xc0, 186 | 0xff,0xfc,0x0,0x0,0x7f,0x0,0x0,0x3f,0xff,0xff,0xc0, 187 | 0xff,0xfc,0x0,0x1,0xff,0x0,0x0,0x3f,0xff,0xff,0xc0, 188 | 0xff,0xf8,0x0,0xf,0xff,0x80,0x0,0x3f,0xff,0xff,0xc0, 189 | 0xff,0xf8,0x0,0x7f,0xff,0xc0,0x0,0x3f,0xff,0xff,0xc0, 190 | 0xff,0xf8,0x3,0xff,0xff,0xe0,0x0,0x3f,0xff,0xff,0xc0, 191 | 0xff,0xfc,0x1f,0xff,0xff,0xf8,0x0,0x3f,0xff,0xff,0xc0, 192 | 0xff,0xff,0xff,0xff,0xff,0xfc,0x0,0x3f,0xff,0xff,0xc0, 193 | 0xff,0xff,0xff,0xff,0xff,0xfe,0x0,0x3f,0xff,0xff,0xc0, 194 | 0xff,0xff,0xff,0xff,0xff,0xff,0x80,0x3f,0xff,0xff,0xc0, 195 | 0xff,0xff,0xff,0xff,0xff,0xff,0xc0,0x3f,0xff,0xff,0xc0, 196 | 0xff,0xff,0xff,0xff,0xff,0xff,0xe0,0x3f,0xff,0xff,0xc0, 197 | 0xff,0xff,0xff,0xff,0xff,0xff,0xf8,0x3f,0xff,0xff,0xc0, 198 | 0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0x7f,0xff,0xff,0xc0, 199 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc0, 200 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc0, 201 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc0, 202 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc0, 203 | 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc0 204 | }; 205 | 206 | #endif 207 | 208 | 209 | 210 | #define ssd1306_swap(a, b) { int16_t t = a; a = b; b = t; } 211 | 212 | static int width() { 213 | return SSD1306_LCDWIDTH; 214 | } 215 | static int height() { 216 | return SSD1306_LCDHEIGHT; 217 | } 218 | static int getRotation() { 219 | return 0; 220 | } 221 | 222 | 223 | // the most basic function, set a single pixel 224 | void SSD1306_drawPixel(int16_t x, int16_t y, uint16_t color) 225 | { 226 | if ((x < 0) || (x >= width()) || (y < 0) || (y >= height())) 227 | return; 228 | 229 | // check rotation, move pixel around if necessary 230 | switch (getRotation()) { 231 | case 1: 232 | ssd1306_swap(x, y); 233 | x = WIDTH - x - 1; 234 | break; 235 | case 2: 236 | x = WIDTH - x - 1; 237 | y = HEIGHT - y - 1; 238 | break; 239 | case 3: 240 | ssd1306_swap(x, y); 241 | y = HEIGHT - y - 1; 242 | break; 243 | } 244 | 245 | // x is which column 246 | int index = x+ (y/8)*SSD1306_LCDWIDTH; 247 | //printf("index = %d\n", index); 248 | 249 | switch (color) 250 | { 251 | case WHITE: buffer[index] |= (1 << (y&7)); break; 252 | case BLACK: buffer[index] &= ~(1 << (y&7)); break; 253 | case INVERSE: buffer[index] ^= (1 << (y&7)); break; 254 | } 255 | 256 | } 257 | 258 | 259 | void SSD1306_begin(uint8_t vccstate, uint8_t i2caddr, bool reset) { 260 | 261 | _vccstate = vccstate; 262 | _i2caddr = i2caddr; 263 | 264 | // Init sequence 265 | SSD1306_command(SSD1306_DISPLAYOFF); // 0xAE 266 | SSD1306_command(SSD1306_SETDISPLAYCLOCKDIV); // 0xD5 267 | SSD1306_command(0x80); // the suggested ratio 0x80 268 | 269 | SSD1306_command(SSD1306_SETMULTIPLEX); // 0xA8 270 | SSD1306_command(SSD1306_LCDHEIGHT - 1); 271 | 272 | SSD1306_command(SSD1306_SETDISPLAYOFFSET); // 0xD3 273 | SSD1306_command(0x0); // no offset 274 | SSD1306_command(SSD1306_SETSTARTLINE | 0x0); // line #0 275 | SSD1306_command(SSD1306_CHARGEPUMP); // 0x8D 276 | if (vccstate == SSD1306_EXTERNALVCC) 277 | { SSD1306_command(0x10); } 278 | else 279 | { SSD1306_command(0x14); } 280 | SSD1306_command(SSD1306_MEMORYMODE); // 0x20 281 | SSD1306_command(0x00); // 0x0 act like ks0108 282 | SSD1306_command(SSD1306_SEGREMAP | 0x1); 283 | SSD1306_command(SSD1306_COMSCANDEC); 284 | 285 | #if defined SSD1306_128_32 286 | SSD1306_command(SSD1306_SETCOMPINS); // 0xDA 287 | SSD1306_command(0x02); 288 | SSD1306_command(SSD1306_SETCONTRAST); // 0x81 289 | SSD1306_command(0x8F); 290 | 291 | #elif defined SSD1306_128_64 292 | SSD1306_command(SSD1306_SETCOMPINS); // 0xDA 293 | SSD1306_command(0x12); 294 | SSD1306_command(SSD1306_SETCONTRAST); // 0x81 295 | if (vccstate == SSD1306_EXTERNALVCC) 296 | { SSD1306_command(0x9F); } 297 | else 298 | { SSD1306_command(0xCF); } 299 | 300 | #elif defined SSD1306_96_16 301 | SSD1306_command(SSD1306_SETCOMPINS); // 0xDA 302 | SSD1306_command(0x2); //ada x12 303 | SSD1306_command(SSD1306_SETCONTRAST); // 0x81 304 | if (vccstate == SSD1306_EXTERNALVCC) 305 | { SSD1306_command(0x10); } 306 | else 307 | { SSD1306_command(0xAF); } 308 | 309 | #endif 310 | 311 | SSD1306_command(SSD1306_SETPRECHARGE); // 0xd9 312 | if (vccstate == SSD1306_EXTERNALVCC) 313 | { SSD1306_command(0x22); } 314 | else 315 | { SSD1306_command(0xF1); } 316 | SSD1306_command(SSD1306_SETVCOMDETECT); // 0xDB 317 | SSD1306_command(0x40); 318 | SSD1306_command(SSD1306_DISPLAYALLON_RESUME); // 0xA4 319 | SSD1306_command(SSD1306_NORMALDISPLAY); // 0xA6 320 | 321 | SSD1306_command(SSD1306_DEACTIVATE_SCROLL); 322 | 323 | SSD1306_command(SSD1306_DISPLAYON);//--turn on oled panel 324 | } 325 | 326 | 327 | void SSD1306_invertDisplay(uint8_t i) { 328 | if (i) { 329 | SSD1306_command(SSD1306_INVERTDISPLAY); 330 | } else { 331 | SSD1306_command(SSD1306_NORMALDISPLAY); 332 | } 333 | } 334 | 335 | void SSD1306_command(uint8_t c) 336 | { 337 | ret_code_t ret; 338 | uint8_t data[] = {0x00, c}; 339 | ret = nrf_drv_twi_tx(&m_twi_master, _i2caddr, data, 2, false); 340 | APP_ERROR_CHECK(ret); 341 | } 342 | 343 | // startscrollright 344 | // Activate a right handed scroll for rows start through stop 345 | // Hint, the display is 16 rows tall. To scroll the whole display, run: 346 | // display.scrollright(0x00, 0x0F) 347 | void SSD1306_startscrollright(uint8_t start, uint8_t stop){ 348 | SSD1306_command(SSD1306_RIGHT_HORIZONTAL_SCROLL); 349 | SSD1306_command(0X00); 350 | SSD1306_command(start); 351 | SSD1306_command(0X00); 352 | SSD1306_command(stop); 353 | SSD1306_command(0X00); 354 | SSD1306_command(0XFF); 355 | SSD1306_command(SSD1306_ACTIVATE_SCROLL); 356 | } 357 | 358 | // startscrollleft 359 | // Activate a right handed scroll for rows start through stop 360 | // Hint, the display is 16 rows tall. To scroll the whole display, run: 361 | // display.scrollright(0x00, 0x0F) 362 | void SSD1306_startscrollleft(uint8_t start, uint8_t stop){ 363 | SSD1306_command(SSD1306_LEFT_HORIZONTAL_SCROLL); 364 | SSD1306_command(0X00); 365 | SSD1306_command(start); 366 | SSD1306_command(0X00); 367 | SSD1306_command(stop); 368 | SSD1306_command(0X00); 369 | SSD1306_command(0XFF); 370 | SSD1306_command(SSD1306_ACTIVATE_SCROLL); 371 | } 372 | 373 | // startscrolldiagright 374 | // Activate a diagonal scroll for rows start through stop 375 | // Hint, the display is 16 rows tall. To scroll the whole display, run: 376 | // display.scrollright(0x00, 0x0F) 377 | void SSD1306_startscrolldiagright(uint8_t start, uint8_t stop) 378 | { 379 | SSD1306_command(SSD1306_SET_VERTICAL_SCROLL_AREA); 380 | SSD1306_command(0X00); 381 | SSD1306_command(SSD1306_LCDHEIGHT); 382 | SSD1306_command(SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL); 383 | SSD1306_command(0X00); 384 | SSD1306_command(start); 385 | SSD1306_command(0X00); 386 | SSD1306_command(stop); 387 | SSD1306_command(0X01); 388 | SSD1306_command(SSD1306_ACTIVATE_SCROLL); 389 | } 390 | 391 | // startscrolldiagleft 392 | // Activate a diagonal scroll for rows start through stop 393 | // Hint, the display is 16 rows tall. To scroll the whole display, run: 394 | // display.scrollright(0x00, 0x0F) 395 | void SSD1306_startscrolldiagleft(uint8_t start, uint8_t stop) 396 | { 397 | SSD1306_command(SSD1306_SET_VERTICAL_SCROLL_AREA); 398 | SSD1306_command(0X00); 399 | SSD1306_command(SSD1306_LCDHEIGHT); 400 | SSD1306_command(SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL); 401 | SSD1306_command(0X00); 402 | SSD1306_command(start); 403 | SSD1306_command(0X00); 404 | SSD1306_command(stop); 405 | SSD1306_command(0X01); 406 | SSD1306_command(SSD1306_ACTIVATE_SCROLL); 407 | } 408 | 409 | void SSD1306_stopscroll(void){ 410 | SSD1306_command(SSD1306_DEACTIVATE_SCROLL); 411 | } 412 | 413 | // Dim the display 414 | // dim = true: display is dimmed 415 | // dim = false: display is normal 416 | void SSD1306_dim(bool dim) { 417 | uint8_t contrast; 418 | 419 | if (dim) { 420 | contrast = 0; // Dimmed display 421 | } else { 422 | if (_vccstate == SSD1306_EXTERNALVCC) { 423 | contrast = 0x9F; 424 | } else { 425 | contrast = 0xCF; 426 | } 427 | } 428 | // the range of contrast to too small to be really useful 429 | // it is useful to dim the display 430 | SSD1306_command(SSD1306_SETCONTRAST); 431 | SSD1306_command(contrast); 432 | } 433 | 434 | void SSD1306_display(void) 435 | { 436 | SSD1306_command(SSD1306_COLUMNADDR); 437 | SSD1306_command(0); // Column start address (0 = reset) 438 | SSD1306_command(SSD1306_LCDWIDTH-1); // Column end address (127 = reset) 439 | 440 | SSD1306_command(SSD1306_PAGEADDR); 441 | SSD1306_command(0); // Page start address (0 = reset) 442 | #if SSD1306_LCDHEIGHT == 64 443 | SSD1306_command(7); // Page end address 444 | #endif 445 | #if SSD1306_LCDHEIGHT == 32 446 | SSD1306_command(3); // Page end address 447 | #endif 448 | #if SSD1306_LCDHEIGHT == 16 449 | SSD1306_command(1); // Page end address 450 | #endif 451 | 452 | 453 | // save I2C bitrate 454 | #ifdef TWBR 455 | uint8_t twbrbackup = TWBR; 456 | TWBR = 12; // upgrade to 400KHz! 457 | #endif 458 | 459 | 460 | // I2C 461 | for (uint16_t i=0; i<(SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8); i++) { 462 | uint8_t tmpBuf[17]; 463 | // SSD1306_SETSTARTLINE 464 | tmpBuf[0] = 0x40; 465 | // data 466 | for (uint8_t j = 0; j < 16; j++) { 467 | tmpBuf[j+1] = buffer[i]; 468 | i++; 469 | } 470 | i--; 471 | 472 | ret_code_t ret; 473 | ret = nrf_drv_twi_tx(&m_twi_master, _i2caddr, tmpBuf, sizeof(tmpBuf), false); 474 | APP_ERROR_CHECK(ret); 475 | } 476 | 477 | #ifdef TWBR 478 | TWBR = twbrbackup; 479 | #endif 480 | 481 | } 482 | 483 | // clear everything 484 | void SSD1306_clearDisplay(void) 485 | { 486 | memset(buffer, 0, (SSD1306_LCDWIDTH*SSD1306_LCDHEIGHT/8)); 487 | } 488 | 489 | 490 | void SSD1306_drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color) { 491 | bool bSwap = false; 492 | switch(getRotation()) 493 | { 494 | case 0: 495 | // 0 degree rotation, do nothing 496 | break; 497 | case 1: 498 | // 90 degree rotation, swap x & y for rotation, then invert x 499 | bSwap = true; 500 | ssd1306_swap(x, y); 501 | x = WIDTH - x - 1; 502 | break; 503 | case 2: 504 | // 180 degree rotation, invert x and y - then shift y around for height. 505 | x = WIDTH - x - 1; 506 | y = HEIGHT - y - 1; 507 | x -= (w-1); 508 | break; 509 | case 3: 510 | // 270 degree rotation, swap x & y for rotation, then invert y and adjust y for w (not to become h) 511 | bSwap = true; 512 | ssd1306_swap(x, y); 513 | y = HEIGHT - y - 1; 514 | y -= (w-1); 515 | break; 516 | } 517 | 518 | if(bSwap) { 519 | SSD1306_drawFastVLineInternal(x, y, w, color); 520 | } else { 521 | SSD1306_drawFastHLineInternal(x, y, w, color); 522 | } 523 | } 524 | 525 | void SSD1306_drawFastHLineInternal(int16_t x, int16_t y, int16_t w, uint16_t color) { 526 | // Do bounds/limit checks 527 | if(y < 0 || y >= HEIGHT) { return; } 528 | 529 | // make sure we don't try to draw below 0 530 | if(x < 0) { 531 | w += x; 532 | x = 0; 533 | } 534 | 535 | // make sure we don't go off the edge of the display 536 | if( (x + w) > WIDTH) { 537 | w = (WIDTH - x); 538 | } 539 | 540 | // if our width is now negative, punt 541 | if(w <= 0) { return; } 542 | 543 | // set up the pointer for movement through the buffer 544 | register uint8_t *pBuf = buffer; 545 | // adjust the buffer pointer for the current row 546 | pBuf += ((y/8) * SSD1306_LCDWIDTH); 547 | // and offset x columns in 548 | pBuf += x; 549 | 550 | register uint8_t mask = 1 << (y&7); 551 | 552 | switch (color) 553 | { 554 | case WHITE: while(w--) { *pBuf++ |= mask; }; break; 555 | case BLACK: mask = ~mask; while(w--) { *pBuf++ &= mask; }; break; 556 | case INVERSE: while(w--) { *pBuf++ ^= mask; }; break; 557 | } 558 | } 559 | 560 | void SSD1306_drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color) { 561 | bool bSwap = false; 562 | switch(getRotation()) { 563 | case 0: 564 | break; 565 | case 1: 566 | // 90 degree rotation, swap x & y for rotation, then invert x and adjust x for h (now to become w) 567 | bSwap = true; 568 | ssd1306_swap(x, y); 569 | x = WIDTH - x - 1; 570 | x -= (h-1); 571 | break; 572 | case 2: 573 | // 180 degree rotation, invert x and y - then shift y around for height. 574 | x = WIDTH - x - 1; 575 | y = HEIGHT - y - 1; 576 | y -= (h-1); 577 | break; 578 | case 3: 579 | // 270 degree rotation, swap x & y for rotation, then invert y 580 | bSwap = true; 581 | ssd1306_swap(x, y); 582 | y = HEIGHT - y - 1; 583 | break; 584 | } 585 | 586 | if(bSwap) { 587 | SSD1306_drawFastHLineInternal(x, y, h, color); 588 | } else { 589 | SSD1306_drawFastVLineInternal(x, y, h, color); 590 | } 591 | } 592 | 593 | 594 | void SSD1306_drawFastVLineInternal(int16_t x, int16_t __y, int16_t __h, uint16_t color) { 595 | 596 | // do nothing if we're off the left or right side of the screen 597 | if(x < 0 || x >= WIDTH) { return; } 598 | 599 | // make sure we don't try to draw below 0 600 | if(__y < 0) { 601 | // __y is negative, this will subtract enough from __h to account for __y being 0 602 | __h += __y; 603 | __y = 0; 604 | 605 | } 606 | 607 | // make sure we don't go past the height of the display 608 | if( (__y + __h) > HEIGHT) { 609 | __h = (HEIGHT - __y); 610 | } 611 | 612 | // if our height is now negative, punt 613 | if(__h <= 0) { 614 | return; 615 | } 616 | 617 | // this display doesn't need ints for coordinates, use local byte registers for faster juggling 618 | register uint8_t y = __y; 619 | register uint8_t h = __h; 620 | 621 | 622 | // set up the pointer for fast movement through the buffer 623 | register uint8_t *pBuf = buffer; 624 | // adjust the buffer pointer for the current row 625 | pBuf += ((y/8) * SSD1306_LCDWIDTH); 626 | // and offset x columns in 627 | pBuf += x; 628 | 629 | // do the first partial byte, if necessary - this requires some masking 630 | register uint8_t mod = (y&7); 631 | if(mod) { 632 | // mask off the high n bits we want to set 633 | mod = 8-mod; 634 | 635 | // note - lookup table results in a nearly 10% performance improvement in fill* functions 636 | // register uint8_t mask = ~(0xFF >> (mod)); 637 | static uint8_t premask[8] = {0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE }; 638 | register uint8_t mask = premask[mod]; 639 | 640 | // adjust the mask if we're not going to reach the end of this byte 641 | if( h < mod) { 642 | mask &= (0XFF >> (mod-h)); 643 | } 644 | 645 | switch (color) 646 | { 647 | case WHITE: *pBuf |= mask; break; 648 | case BLACK: *pBuf &= ~mask; break; 649 | case INVERSE: *pBuf ^= mask; break; 650 | } 651 | 652 | // fast exit if we're done here! 653 | if(h= 8) { 663 | if (color == INVERSE) {// separate copy of the code so we don't impact performance of the black/white write version with an extra comparison per loop 664 | do { 665 | *pBuf=~(*pBuf); 666 | 667 | // adjust the buffer forward 8 rows worth of data 668 | pBuf += SSD1306_LCDWIDTH; 669 | 670 | // adjust h & y (there's got to be a faster way for me to do this, but this should still help a fair bit for now) 671 | h -= 8; 672 | } while(h >= 8); 673 | } 674 | else { 675 | // store a local value to work with 676 | register uint8_t val = (color == WHITE) ? 255 : 0; 677 | 678 | do { 679 | // write our value in 680 | *pBuf = val; 681 | 682 | // adjust the buffer forward 8 rows worth of data 683 | pBuf += SSD1306_LCDWIDTH; 684 | 685 | // adjust h & y (there's got to be a faster way for me to do this, but this should still help a fair bit for now) 686 | h -= 8; 687 | } while(h >= 8); 688 | } 689 | } 690 | 691 | // now do the final partial byte, if necessary 692 | if(h) { 693 | mod = h & 7; 694 | // this time we want to mask the low bits of the byte, vs the high bits we did above 695 | // register uint8_t mask = (1 << mod) - 1; 696 | // note - lookup table results in a nearly 10% performance improvement in fill* functions 697 | static uint8_t postmask[8] = {0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F }; 698 | register uint8_t mask = postmask[mod]; 699 | switch (color) 700 | { 701 | case WHITE: *pBuf |= mask; break; 702 | case BLACK: *pBuf &= ~mask; break; 703 | case INVERSE: *pBuf ^= mask; break; 704 | } 705 | } 706 | } 707 | -------------------------------------------------------------------------------- /module/ssd1306_driver_adafruit/SSD1306.h: -------------------------------------------------------------------------------- 1 | /********************************************************************* 2 | This is a port of the Adafruit SSD1306 driver to Nordic nRF52832. 3 | 4 | Currently only I2C supported. 5 | 6 | Original: 7 | 8 | https://github.com/adafruit/Adafruit_SSD1306 9 | 10 | electronut.in 11 | *********************************************************************/ 12 | 13 | 14 | #ifndef _SSD1306_H_ 15 | #define _SSD1306_H_ 16 | 17 | #include 18 | #include 19 | #include "nordic_common.h" 20 | 21 | #define BLACK 0 22 | #define WHITE 1 23 | #define INVERSE 2 24 | 25 | #define NRFX_TWIM_SSD1306 26 | 27 | #define SSD1306_I2C_ADDRESS 0x3C // 011110+SA0+RW - 0x3C or 0x3D // both 128_64 and 128_32 are using 0x3C 28 | // Address for 128x32 is 0x3C 29 | // Address for 128x64 is 0x3D (default) or 0x3C (if SA0 is grounded) 30 | 31 | /*========================================================================= 32 | SSD1306 Displays 33 | ----------------------------------------------------------------------- 34 | The driver is used in multiple displays (128x64, 128x32, etc.). 35 | Select the appropriate display below to create an appropriately 36 | sized framebuffer, etc. 37 | 38 | SSD1306_128_64 128x64 pixel display 39 | 40 | SSD1306_128_32 128x32 pixel display 41 | 42 | SSD1306_96_16 43 | 44 | -----------------------------------------------------------------------*/ 45 | #define SSD1306_128_64 46 | //#define SSD1306_128_32 47 | // #define SSD1306_96_16 48 | /*=========================================================================*/ 49 | 50 | #if defined SSD1306_128_64 && defined SSD1306_128_32 51 | #error "Only one SSD1306 display can be specified at once in SSD1306.h" 52 | #endif 53 | #if !defined SSD1306_128_64 && !defined SSD1306_128_32 && !defined SSD1306_96_16 54 | #error "At least one SSD1306 display must be specified in SSD1306.h" 55 | #endif 56 | 57 | #if defined SSD1306_128_64 58 | #define SSD1306_LCDWIDTH 128 59 | #define SSD1306_LCDHEIGHT 64 60 | #endif 61 | #if defined SSD1306_128_32 62 | #define SSD1306_LCDWIDTH 128 63 | #define SSD1306_LCDHEIGHT 32 64 | #endif 65 | #if defined SSD1306_96_16 66 | #define SSD1306_LCDWIDTH 96 67 | #define SSD1306_LCDHEIGHT 16 68 | #endif 69 | 70 | #define SSD1306_SETCONTRAST 0x81 71 | #define SSD1306_DISPLAYALLON_RESUME 0xA4 72 | #define SSD1306_DISPLAYALLON 0xA5 73 | #define SSD1306_NORMALDISPLAY 0xA6 74 | #define SSD1306_INVERTDISPLAY 0xA7 75 | #define SSD1306_DISPLAYOFF 0xAE 76 | #define SSD1306_DISPLAYON 0xAF 77 | 78 | #define SSD1306_SETDISPLAYOFFSET 0xD3 79 | #define SSD1306_SETCOMPINS 0xDA 80 | 81 | #define SSD1306_SETVCOMDETECT 0xDB 82 | 83 | #define SSD1306_SETDISPLAYCLOCKDIV 0xD5 84 | #define SSD1306_SETPRECHARGE 0xD9 85 | 86 | #define SSD1306_SETMULTIPLEX 0xA8 87 | 88 | #define SSD1306_SETLOWCOLUMN 0x00 89 | #define SSD1306_SETHIGHCOLUMN 0x10 90 | 91 | #define SSD1306_SETSTARTLINE 0x40 92 | 93 | #define SSD1306_MEMORYMODE 0x20 94 | #define SSD1306_COLUMNADDR 0x21 95 | #define SSD1306_PAGEADDR 0x22 96 | 97 | #define SSD1306_COMSCANINC 0xC0 98 | #define SSD1306_COMSCANDEC 0xC8 99 | 100 | #define SSD1306_SEGREMAP 0xA0 101 | 102 | #define SSD1306_CHARGEPUMP 0x8D 103 | 104 | #define SSD1306_EXTERNALVCC 0x1 105 | #define SSD1306_SWITCHCAPVCC 0x2 106 | 107 | // Scrolling #defines 108 | #define SSD1306_ACTIVATE_SCROLL 0x2F 109 | #define SSD1306_DEACTIVATE_SCROLL 0x2E 110 | #define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3 111 | #define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26 112 | #define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27 113 | #define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29 114 | #define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A 115 | 116 | ret_code_t twim_master_init(uint32_t scl, uint32_t sda); 117 | 118 | void SSD1306_begin(uint8_t switchvcc, uint8_t i2caddr, bool reset); 119 | void SSD1306_command(uint8_t c); 120 | 121 | void SSD1306_clearDisplay(void); 122 | void SSD1306_invertDisplay(uint8_t i); 123 | void SSD1306_display(); 124 | 125 | void SSD1306_startscrollright(uint8_t start, uint8_t stop); 126 | void SSD1306_startscrollleft(uint8_t start, uint8_t stop); 127 | 128 | void SSD1306_startscrolldiagright(uint8_t start, uint8_t stop); 129 | void SSD1306_startscrolldiagleft(uint8_t start, uint8_t stop); 130 | void SSD1306_stopscroll(void); 131 | 132 | void SSD1306_dim(bool dim); 133 | 134 | void SSD1306_drawPixel(int16_t x, int16_t y, uint16_t color); 135 | 136 | void SSD1306_drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color); 137 | void SSD1306_drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color); 138 | 139 | void SSD1306_drawFastVLineInternal(int16_t x, int16_t y, int16_t h, uint16_t color); //__attribute__((always_inline)); 140 | void SSD1306_drawFastHLineInternal(int16_t x, int16_t y, int16_t w, uint16_t color); //__attribute__((always_inline)); 141 | 142 | 143 | 144 | static const uint8_t el_logo[SSD1306_LCDHEIGHT * SSD1306_LCDWIDTH / 8] = 145 | { 146 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 147 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 148 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 149 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 150 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 151 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 152 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 153 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 154 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 155 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 156 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 157 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 158 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3,0x3,0x3,0x80,0x0,0x0,0x0,0x0, 159 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7,0x87,0x87,0x80,0x0,0x0,0x0,0x0, 160 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x5,0x86,0x86,0xc0,0x0,0x0,0x0,0x0, 161 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7,0x3,0x83,0x80,0x0,0x0,0x0,0x0, 162 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3,0x3,0x1,0x0,0x0,0x0,0x0,0x0, 163 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3,0x3,0x1,0x0,0x0,0x0,0x0,0x0, 164 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3,0x3,0x3,0x0,0x0,0x0,0x0,0x0, 165 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x83,0x6,0x0,0x0,0x0,0x0,0x0, 166 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc3,0xc,0x0,0x0,0x0,0x0,0x0, 167 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x63,0x18,0x0,0x0,0x0,0x0,0x40, 168 | 0x7,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x33,0x30,0x0,0x0,0x0,0x1,0xe0, 169 | 0x4,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xe0,0x33,0x30,0x1f,0xff,0xff,0xff,0xa0, 170 | 0x7,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x30,0x31,0x10,0x30,0x0,0x0,0x1,0xe0, 171 | 0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x10,0x0,0x0,0x20,0x0,0x0,0x0,0xc0, 172 | 0x0,0x0,0x10,0x0,0x0,0x0,0x2,0x0,0x18,0x3f,0xf8,0x60,0x0,0x0,0x3,0x0, 173 | 0x0,0x0,0x18,0x0,0x0,0x0,0x3,0x0,0xe,0x40,0x9,0xc0,0x0,0x0,0x3,0x0, 174 | 0x3,0xf0,0x18,0x1f,0xc0,0x7f,0x3,0xc1,0xe6,0x4f,0xc9,0xdf,0xe0,0x61,0x83,0xc0, 175 | 0x7,0xf8,0x18,0x3f,0xe0,0xff,0x3,0xc1,0xf0,0x5f,0xe8,0x1f,0xf0,0xe1,0x83,0xe0, 176 | 0x7,0xfc,0x18,0x3f,0xe0,0xff,0x3,0x81,0xe0,0x7f,0xe8,0x1f,0xf0,0xe1,0x83,0xc0, 177 | 0x7,0xfc,0x18,0x3f,0xe0,0xe0,0x3,0x1,0x80,0x58,0x68,0x18,0x70,0xe1,0x83,0x0, 178 | 0x7,0xfc,0x18,0x3f,0xe0,0xe0,0x3,0x1,0x80,0x58,0x6c,0x18,0x70,0xe1,0x83,0x0, 179 | 0x7,0x0,0x18,0x38,0x0,0xe0,0x3,0x1,0x80,0x58,0x68,0x18,0x70,0xe1,0x83,0x0, 180 | 0x7,0xf8,0x18,0x3f,0xc0,0xff,0x83,0xc1,0x80,0x5f,0xe8,0x18,0x70,0xff,0x83,0xc0, 181 | 0x7,0xf8,0x18,0x1f,0xc0,0x7f,0x83,0xc1,0x86,0x5f,0xe9,0x98,0x70,0x7f,0x83,0xe0, 182 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xe,0x40,0x9,0xc0,0x0,0x0,0x0,0x0, 183 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x18,0x7f,0xf8,0x60,0x0,0x0,0x0,0x0, 184 | 0x2,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x10,0x3f,0xf0,0x20,0x0,0x0,0x0,0x0, 185 | 0x7,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x30,0x0,0x0,0x30,0x0,0x0,0x0,0xe0, 186 | 0x5,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xe0,0x33,0x30,0x1f,0xff,0xff,0xff,0xa0, 187 | 0x7,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xc0,0x33,0x30,0xf,0xff,0xff,0xff,0xe0, 188 | 0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x33,0x18,0x0,0x0,0x0,0x0,0xc0, 189 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x63,0xc,0x0,0x3,0x0,0xc,0x0, 190 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xc3,0x6,0x4,0x3,0xf,0x9e,0x0, 191 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x1,0x83,0x3,0x4,0x7,0xd,0xb0,0x0, 192 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3,0x3,0x1,0x4,0x4,0x8c,0x90,0x0, 193 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3,0x3,0x1,0x4,0xd,0xcf,0x9c,0x0, 194 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3,0x3,0x3,0x84,0xf,0xcf,0xc6,0x0, 195 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7,0x87,0x83,0x84,0x17,0xac,0xc2,0x0, 196 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x5,0x86,0x86,0xc6,0x93,0x2d,0xf6,0x0, 197 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7,0x3,0x83,0x87,0xdf,0xef,0x9e,0x0, 198 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 199 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 200 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 201 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 202 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 203 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 204 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 205 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 206 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 207 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 208 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0, 209 | 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 210 | }; 211 | 212 | #endif /* _SSD1306_H_ */ 213 | -------------------------------------------------------------------------------- /module/ssd1306_driver_adafruit/glcdfont.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #ifndef FONT5X7_H 4 | #define FONT5X7_H 5 | 6 | // standard ascii 5x7 font 7 | 8 | static unsigned char font[] = { 9 | 0x00, 0x00, 0x00, 0x00, 0x00, 10 | 0x3E, 0x5B, 0x4F, 0x5B, 0x3E, 11 | 0x3E, 0x6B, 0x4F, 0x6B, 0x3E, 12 | 0x1C, 0x3E, 0x7C, 0x3E, 0x1C, 13 | 0x18, 0x3C, 0x7E, 0x3C, 0x18, 14 | 0x1C, 0x57, 0x7D, 0x57, 0x1C, 15 | 0x1C, 0x5E, 0x7F, 0x5E, 0x1C, 16 | 0x00, 0x18, 0x3C, 0x18, 0x00, 17 | 0xFF, 0xE7, 0xC3, 0xE7, 0xFF, 18 | 0x00, 0x18, 0x24, 0x18, 0x00, 19 | 0xFF, 0xE7, 0xDB, 0xE7, 0xFF, 20 | 0x30, 0x48, 0x3A, 0x06, 0x0E, 21 | 0x26, 0x29, 0x79, 0x29, 0x26, 22 | 0x40, 0x7F, 0x05, 0x05, 0x07, 23 | 0x40, 0x7F, 0x05, 0x25, 0x3F, 24 | 0x5A, 0x3C, 0xE7, 0x3C, 0x5A, 25 | 0x7F, 0x3E, 0x1C, 0x1C, 0x08, 26 | 0x08, 0x1C, 0x1C, 0x3E, 0x7F, 27 | 0x14, 0x22, 0x7F, 0x22, 0x14, 28 | 0x5F, 0x5F, 0x00, 0x5F, 0x5F, 29 | 0x06, 0x09, 0x7F, 0x01, 0x7F, 30 | 0x00, 0x66, 0x89, 0x95, 0x6A, 31 | 0x60, 0x60, 0x60, 0x60, 0x60, 32 | 0x94, 0xA2, 0xFF, 0xA2, 0x94, 33 | 0x08, 0x04, 0x7E, 0x04, 0x08, 34 | 0x10, 0x20, 0x7E, 0x20, 0x10, 35 | 0x08, 0x08, 0x2A, 0x1C, 0x08, 36 | 0x08, 0x1C, 0x2A, 0x08, 0x08, 37 | 0x1E, 0x10, 0x10, 0x10, 0x10, 38 | 0x0C, 0x1E, 0x0C, 0x1E, 0x0C, 39 | 0x30, 0x38, 0x3E, 0x38, 0x30, 40 | 0x06, 0x0E, 0x3E, 0x0E, 0x06, 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 42 | 0x00, 0x00, 0x5F, 0x00, 0x00, 43 | 0x00, 0x07, 0x00, 0x07, 0x00, 44 | 0x14, 0x7F, 0x14, 0x7F, 0x14, 45 | 0x24, 0x2A, 0x7F, 0x2A, 0x12, 46 | 0x23, 0x13, 0x08, 0x64, 0x62, 47 | 0x36, 0x49, 0x56, 0x20, 0x50, 48 | 0x00, 0x08, 0x07, 0x03, 0x00, 49 | 0x00, 0x1C, 0x22, 0x41, 0x00, 50 | 0x00, 0x41, 0x22, 0x1C, 0x00, 51 | 0x2A, 0x1C, 0x7F, 0x1C, 0x2A, 52 | 0x08, 0x08, 0x3E, 0x08, 0x08, 53 | 0x00, 0x80, 0x70, 0x30, 0x00, 54 | 0x08, 0x08, 0x08, 0x08, 0x08, 55 | 0x00, 0x00, 0x60, 0x60, 0x00, 56 | 0x20, 0x10, 0x08, 0x04, 0x02, 57 | 0x3E, 0x51, 0x49, 0x45, 0x3E, 58 | 0x00, 0x42, 0x7F, 0x40, 0x00, 59 | 0x72, 0x49, 0x49, 0x49, 0x46, 60 | 0x21, 0x41, 0x49, 0x4D, 0x33, 61 | 0x18, 0x14, 0x12, 0x7F, 0x10, 62 | 0x27, 0x45, 0x45, 0x45, 0x39, 63 | 0x3C, 0x4A, 0x49, 0x49, 0x31, 64 | 0x41, 0x21, 0x11, 0x09, 0x07, 65 | 0x36, 0x49, 0x49, 0x49, 0x36, 66 | 0x46, 0x49, 0x49, 0x29, 0x1E, 67 | 0x00, 0x00, 0x14, 0x00, 0x00, 68 | 0x00, 0x40, 0x34, 0x00, 0x00, 69 | 0x00, 0x08, 0x14, 0x22, 0x41, 70 | 0x14, 0x14, 0x14, 0x14, 0x14, 71 | 0x00, 0x41, 0x22, 0x14, 0x08, 72 | 0x02, 0x01, 0x59, 0x09, 0x06, 73 | 0x3E, 0x41, 0x5D, 0x59, 0x4E, 74 | 0x7C, 0x12, 0x11, 0x12, 0x7C, 75 | 0x7F, 0x49, 0x49, 0x49, 0x36, 76 | 0x3E, 0x41, 0x41, 0x41, 0x22, 77 | 0x7F, 0x41, 0x41, 0x41, 0x3E, 78 | 0x7F, 0x49, 0x49, 0x49, 0x41, 79 | 0x7F, 0x09, 0x09, 0x09, 0x01, 80 | 0x3E, 0x41, 0x41, 0x51, 0x73, 81 | 0x7F, 0x08, 0x08, 0x08, 0x7F, 82 | 0x00, 0x41, 0x7F, 0x41, 0x00, 83 | 0x20, 0x40, 0x41, 0x3F, 0x01, 84 | 0x7F, 0x08, 0x14, 0x22, 0x41, 85 | 0x7F, 0x40, 0x40, 0x40, 0x40, 86 | 0x7F, 0x02, 0x1C, 0x02, 0x7F, 87 | 0x7F, 0x04, 0x08, 0x10, 0x7F, 88 | 0x3E, 0x41, 0x41, 0x41, 0x3E, 89 | 0x7F, 0x09, 0x09, 0x09, 0x06, 90 | 0x3E, 0x41, 0x51, 0x21, 0x5E, 91 | 0x7F, 0x09, 0x19, 0x29, 0x46, 92 | 0x26, 0x49, 0x49, 0x49, 0x32, 93 | 0x03, 0x01, 0x7F, 0x01, 0x03, 94 | 0x3F, 0x40, 0x40, 0x40, 0x3F, 95 | 0x1F, 0x20, 0x40, 0x20, 0x1F, 96 | 0x3F, 0x40, 0x38, 0x40, 0x3F, 97 | 0x63, 0x14, 0x08, 0x14, 0x63, 98 | 0x03, 0x04, 0x78, 0x04, 0x03, 99 | 0x61, 0x59, 0x49, 0x4D, 0x43, 100 | 0x00, 0x7F, 0x41, 0x41, 0x41, 101 | 0x02, 0x04, 0x08, 0x10, 0x20, 102 | 0x00, 0x41, 0x41, 0x41, 0x7F, 103 | 0x04, 0x02, 0x01, 0x02, 0x04, 104 | 0x40, 0x40, 0x40, 0x40, 0x40, 105 | 0x00, 0x03, 0x07, 0x08, 0x00, 106 | 0x20, 0x54, 0x54, 0x78, 0x40, 107 | 0x7F, 0x28, 0x44, 0x44, 0x38, 108 | 0x38, 0x44, 0x44, 0x44, 0x28, 109 | 0x38, 0x44, 0x44, 0x28, 0x7F, 110 | 0x38, 0x54, 0x54, 0x54, 0x18, 111 | 0x00, 0x08, 0x7E, 0x09, 0x02, 112 | 0x18, 0xA4, 0xA4, 0x9C, 0x78, 113 | 0x7F, 0x08, 0x04, 0x04, 0x78, 114 | 0x00, 0x44, 0x7D, 0x40, 0x00, 115 | 0x20, 0x40, 0x40, 0x3D, 0x00, 116 | 0x7F, 0x10, 0x28, 0x44, 0x00, 117 | 0x00, 0x41, 0x7F, 0x40, 0x00, 118 | 0x7C, 0x04, 0x78, 0x04, 0x78, 119 | 0x7C, 0x08, 0x04, 0x04, 0x78, 120 | 0x38, 0x44, 0x44, 0x44, 0x38, 121 | 0xFC, 0x18, 0x24, 0x24, 0x18, 122 | 0x18, 0x24, 0x24, 0x18, 0xFC, 123 | 0x7C, 0x08, 0x04, 0x04, 0x08, 124 | 0x48, 0x54, 0x54, 0x54, 0x24, 125 | 0x04, 0x04, 0x3F, 0x44, 0x24, 126 | 0x3C, 0x40, 0x40, 0x20, 0x7C, 127 | 0x1C, 0x20, 0x40, 0x20, 0x1C, 128 | 0x3C, 0x40, 0x30, 0x40, 0x3C, 129 | 0x44, 0x28, 0x10, 0x28, 0x44, 130 | 0x4C, 0x90, 0x90, 0x90, 0x7C, 131 | 0x44, 0x64, 0x54, 0x4C, 0x44, 132 | 0x00, 0x08, 0x36, 0x41, 0x00, 133 | 0x00, 0x00, 0x77, 0x00, 0x00, 134 | 0x00, 0x41, 0x36, 0x08, 0x00, 135 | 0x02, 0x01, 0x02, 0x04, 0x02, 136 | 0x3C, 0x26, 0x23, 0x26, 0x3C, 137 | 0x1E, 0xA1, 0xA1, 0x61, 0x12, 138 | 0x3A, 0x40, 0x40, 0x20, 0x7A, 139 | 0x38, 0x54, 0x54, 0x55, 0x59, 140 | 0x21, 0x55, 0x55, 0x79, 0x41, 141 | 0x21, 0x54, 0x54, 0x78, 0x41, 142 | 0x21, 0x55, 0x54, 0x78, 0x40, 143 | 0x20, 0x54, 0x55, 0x79, 0x40, 144 | 0x0C, 0x1E, 0x52, 0x72, 0x12, 145 | 0x39, 0x55, 0x55, 0x55, 0x59, 146 | 0x39, 0x54, 0x54, 0x54, 0x59, 147 | 0x39, 0x55, 0x54, 0x54, 0x58, 148 | 0x00, 0x00, 0x45, 0x7C, 0x41, 149 | 0x00, 0x02, 0x45, 0x7D, 0x42, 150 | 0x00, 0x01, 0x45, 0x7C, 0x40, 151 | 0xF0, 0x29, 0x24, 0x29, 0xF0, 152 | 0xF0, 0x28, 0x25, 0x28, 0xF0, 153 | 0x7C, 0x54, 0x55, 0x45, 0x00, 154 | 0x20, 0x54, 0x54, 0x7C, 0x54, 155 | 0x7C, 0x0A, 0x09, 0x7F, 0x49, 156 | 0x32, 0x49, 0x49, 0x49, 0x32, 157 | 0x32, 0x48, 0x48, 0x48, 0x32, 158 | 0x32, 0x4A, 0x48, 0x48, 0x30, 159 | 0x3A, 0x41, 0x41, 0x21, 0x7A, 160 | 0x3A, 0x42, 0x40, 0x20, 0x78, 161 | 0x00, 0x9D, 0xA0, 0xA0, 0x7D, 162 | 0x39, 0x44, 0x44, 0x44, 0x39, 163 | 0x3D, 0x40, 0x40, 0x40, 0x3D, 164 | 0x3C, 0x24, 0xFF, 0x24, 0x24, 165 | 0x48, 0x7E, 0x49, 0x43, 0x66, 166 | 0x2B, 0x2F, 0xFC, 0x2F, 0x2B, 167 | 0xFF, 0x09, 0x29, 0xF6, 0x20, 168 | 0xC0, 0x88, 0x7E, 0x09, 0x03, 169 | 0x20, 0x54, 0x54, 0x79, 0x41, 170 | 0x00, 0x00, 0x44, 0x7D, 0x41, 171 | 0x30, 0x48, 0x48, 0x4A, 0x32, 172 | 0x38, 0x40, 0x40, 0x22, 0x7A, 173 | 0x00, 0x7A, 0x0A, 0x0A, 0x72, 174 | 0x7D, 0x0D, 0x19, 0x31, 0x7D, 175 | 0x26, 0x29, 0x29, 0x2F, 0x28, 176 | 0x26, 0x29, 0x29, 0x29, 0x26, 177 | 0x30, 0x48, 0x4D, 0x40, 0x20, 178 | 0x38, 0x08, 0x08, 0x08, 0x08, 179 | 0x08, 0x08, 0x08, 0x08, 0x38, 180 | 0x2F, 0x10, 0xC8, 0xAC, 0xBA, 181 | 0x2F, 0x10, 0x28, 0x34, 0xFA, 182 | 0x00, 0x00, 0x7B, 0x00, 0x00, 183 | 0x08, 0x14, 0x2A, 0x14, 0x22, 184 | 0x22, 0x14, 0x2A, 0x14, 0x08, 185 | 0xAA, 0x00, 0x55, 0x00, 0xAA, 186 | 0xAA, 0x55, 0xAA, 0x55, 0xAA, 187 | 0x00, 0x00, 0x00, 0xFF, 0x00, 188 | 0x10, 0x10, 0x10, 0xFF, 0x00, 189 | 0x14, 0x14, 0x14, 0xFF, 0x00, 190 | 0x10, 0x10, 0xFF, 0x00, 0xFF, 191 | 0x10, 0x10, 0xF0, 0x10, 0xF0, 192 | 0x14, 0x14, 0x14, 0xFC, 0x00, 193 | 0x14, 0x14, 0xF7, 0x00, 0xFF, 194 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 195 | 0x14, 0x14, 0xF4, 0x04, 0xFC, 196 | 0x14, 0x14, 0x17, 0x10, 0x1F, 197 | 0x10, 0x10, 0x1F, 0x10, 0x1F, 198 | 0x14, 0x14, 0x14, 0x1F, 0x00, 199 | 0x10, 0x10, 0x10, 0xF0, 0x00, 200 | 0x00, 0x00, 0x00, 0x1F, 0x10, 201 | 0x10, 0x10, 0x10, 0x1F, 0x10, 202 | 0x10, 0x10, 0x10, 0xF0, 0x10, 203 | 0x00, 0x00, 0x00, 0xFF, 0x10, 204 | 0x10, 0x10, 0x10, 0x10, 0x10, 205 | 0x10, 0x10, 0x10, 0xFF, 0x10, 206 | 0x00, 0x00, 0x00, 0xFF, 0x14, 207 | 0x00, 0x00, 0xFF, 0x00, 0xFF, 208 | 0x00, 0x00, 0x1F, 0x10, 0x17, 209 | 0x00, 0x00, 0xFC, 0x04, 0xF4, 210 | 0x14, 0x14, 0x17, 0x10, 0x17, 211 | 0x14, 0x14, 0xF4, 0x04, 0xF4, 212 | 0x00, 0x00, 0xFF, 0x00, 0xF7, 213 | 0x14, 0x14, 0x14, 0x14, 0x14, 214 | 0x14, 0x14, 0xF7, 0x00, 0xF7, 215 | 0x14, 0x14, 0x14, 0x17, 0x14, 216 | 0x10, 0x10, 0x1F, 0x10, 0x1F, 217 | 0x14, 0x14, 0x14, 0xF4, 0x14, 218 | 0x10, 0x10, 0xF0, 0x10, 0xF0, 219 | 0x00, 0x00, 0x1F, 0x10, 0x1F, 220 | 0x00, 0x00, 0x00, 0x1F, 0x14, 221 | 0x00, 0x00, 0x00, 0xFC, 0x14, 222 | 0x00, 0x00, 0xF0, 0x10, 0xF0, 223 | 0x10, 0x10, 0xFF, 0x10, 0xFF, 224 | 0x14, 0x14, 0x14, 0xFF, 0x14, 225 | 0x10, 0x10, 0x10, 0x1F, 0x00, 226 | 0x00, 0x00, 0x00, 0xF0, 0x10, 227 | 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 228 | 0xF0, 0xF0, 0xF0, 0xF0, 0xF0, 229 | 0xFF, 0xFF, 0xFF, 0x00, 0x00, 230 | 0x00, 0x00, 0x00, 0xFF, 0xFF, 231 | 0x0F, 0x0F, 0x0F, 0x0F, 0x0F, 232 | 0x38, 0x44, 0x44, 0x38, 0x44, 233 | 0x7C, 0x2A, 0x2A, 0x3E, 0x14, 234 | 0x7E, 0x02, 0x02, 0x06, 0x06, 235 | 0x02, 0x7E, 0x02, 0x7E, 0x02, 236 | 0x63, 0x55, 0x49, 0x41, 0x63, 237 | 0x38, 0x44, 0x44, 0x3C, 0x04, 238 | 0x40, 0x7E, 0x20, 0x1E, 0x20, 239 | 0x06, 0x02, 0x7E, 0x02, 0x02, 240 | 0x99, 0xA5, 0xE7, 0xA5, 0x99, 241 | 0x1C, 0x2A, 0x49, 0x2A, 0x1C, 242 | 0x4C, 0x72, 0x01, 0x72, 0x4C, 243 | 0x30, 0x4A, 0x4D, 0x4D, 0x30, 244 | 0x30, 0x48, 0x78, 0x48, 0x30, 245 | 0xBC, 0x62, 0x5A, 0x46, 0x3D, 246 | 0x3E, 0x49, 0x49, 0x49, 0x00, 247 | 0x7E, 0x01, 0x01, 0x01, 0x7E, 248 | 0x2A, 0x2A, 0x2A, 0x2A, 0x2A, 249 | 0x44, 0x44, 0x5F, 0x44, 0x44, 250 | 0x40, 0x51, 0x4A, 0x44, 0x40, 251 | 0x40, 0x44, 0x4A, 0x51, 0x40, 252 | 0x00, 0x00, 0xFF, 0x01, 0x03, 253 | 0xE0, 0x80, 0xFF, 0x00, 0x00, 254 | 0x08, 0x08, 0x6B, 0x6B, 0x08, 255 | 0x36, 0x12, 0x36, 0x24, 0x36, 256 | 0x06, 0x0F, 0x09, 0x0F, 0x06, 257 | 0x00, 0x00, 0x18, 0x18, 0x00, 258 | 0x00, 0x00, 0x10, 0x10, 0x00, 259 | 0x30, 0x40, 0xFF, 0x01, 0x01, 260 | 0x00, 0x1F, 0x01, 0x01, 0x1E, 261 | 0x00, 0x19, 0x1D, 0x17, 0x12, 262 | 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 263 | 0x00, 0x00, 0x00, 0x00, 0x00, 264 | }; 265 | #endif 266 | -------------------------------------------------------------------------------- /module/ssd1306_driver_adafruit/ssd1306_nrfx_twim.h: -------------------------------------------------------------------------------- 1 | #ifndef __SSD1306_LIB_H 2 | #define __SSD1306_LIB_H 3 | 4 | #ifdef __AVR__ 5 | #include 6 | #elif defined(ESP8266) 7 | #include 8 | #else 9 | #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) 10 | #endif 11 | 12 | #include 13 | 14 | typedef volatile uint8_t PortReg; 15 | typedef uint32_t PortMask; 16 | 17 | #define BLACK 0 18 | #define WHITE 1 19 | #define INVERSE 2 20 | 21 | #define SSD1306_I2C_ADDRESS (0x3C) // 011110+SA0+RW - 0x3C or 0x3D 22 | // Address for 128x32 is 0x3C 23 | // Address for 128x64 is 0x3D (default) or 0x3C (if SA0 is grounded) 24 | 25 | /*========================================================================= 26 | SSD1306 Displays 27 | ----------------------------------------------------------------------- 28 | The driver is used in multiple displays (128x64, 128x32, etc.). 29 | Select the appropriate display below to create an appropriately 30 | sized framebuffer, etc. 31 | SSD1306_128_64 128x64 pixel display 32 | SSD1306_128_32 128x32 pixel display 33 | SSD1306_96_16 34 | -----------------------------------------------------------------------*/ 35 | #define SSD1306_128_64 36 | // #define SSD1306_128_32 37 | // #define SSD1306_96_16 38 | /*=========================================================================*/ 39 | 40 | 41 | #if defined SSD1306_128_64 42 | #define SSD1306_LCDWIDTH 128 43 | #define SSD1306_LCDHEIGHT 64 44 | #endif 45 | #if defined SSD1306_128_32 46 | #define SSD1306_LCDWIDTH 128 47 | #define SSD1306_LCDHEIGHT 32 48 | #endif 49 | #if defined SSD1306_96_16 50 | #define SSD1306_LCDWIDTH 96 51 | #define SSD1306_LCDHEIGHT 16 52 | #endif 53 | 54 | #define SSD1306_SETCONTRAST 0x81 55 | #define SSD1306_DISPLAYALLON_RESUME 0xA4 56 | #define SSD1306_DISPLAYALLON 0xA5 57 | #define SSD1306_NORMALDISPLAY 0xA6 58 | #define SSD1306_INVERTDISPLAY 0xA7 59 | #define SSD1306_DISPLAYOFF 0xAE 60 | #define SSD1306_DISPLAYON 0xAF 61 | 62 | #define SSD1306_SETDISPLAYOFFSET 0xD3 63 | #define SSD1306_SETCOMPINS 0xDA 64 | 65 | #define SSD1306_SETVCOMDETECT 0xDB 66 | 67 | #define SSD1306_SETDISPLAYCLOCKDIV 0xD5 68 | #define SSD1306_SETPRECHARGE 0xD9 69 | 70 | #define SSD1306_SETMULTIPLEX 0xA8 71 | 72 | #define SSD1306_SETLOWCOLUMN 0x00 73 | #define SSD1306_SETHIGHCOLUMN 0x10 74 | 75 | #define SSD1306_SETSTARTLINE 0x40 76 | 77 | #define SSD1306_MEMORYMODE 0x20 78 | #define SSD1306_COLUMNADDR 0x21 79 | #define SSD1306_PAGEADDR 0x22 80 | 81 | #define SSD1306_COMSCANINC 0xC0 82 | #define SSD1306_COMSCANDEC 0xC8 83 | 84 | #define SSD1306_SEGREMAP 0xA0 85 | 86 | #define SSD1306_CHARGEPUMP 0x8D 87 | 88 | #define SSD1306_EXTERNALVCC 0x1 89 | #define SSD1306_SWITCHCAPVCC 0x2 90 | 91 | // Scrolling #defines 92 | #define SSD1306_ACTIVATE_SCROLL 0x2F 93 | #define SSD1306_DEACTIVATE_SCROLL 0x2E 94 | #define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3 95 | #define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26 96 | #define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27 97 | #define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29 98 | #define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A 99 | 100 | #ifdef __cplusplus 101 | extern "C" { 102 | #endif 103 | 104 | int16_t ssd1306_width(void); 105 | int16_t ssd1306_height(void); 106 | void set_rotation(uint8_t x); 107 | void ssd1306_init(uint32_t dc, uint32_t rs, uint32_t cs, uint32_t clk, uint32_t mosi); 108 | void ssd1306_init_i2c(uint32_t scl, uint32_t sda); 109 | void ssd1306_command(uint8_t c); 110 | void ssd1306_begin(uint8_t vccstate, uint8_t i2caddr, bool reset); 111 | void ssd1306_draw_pixel(int16_t x, int16_t y, uint16_t color); 112 | void ssd1306_invert_display(uint8_t i); 113 | void ssd1306_start_scroll_right(uint8_t start, uint8_t stop); 114 | void ssd1306_start_scroll_left(uint8_t start, uint8_t stop); 115 | void ssd1306_start_scroll_diag_right(uint8_t start, uint8_t stop); 116 | void ssd1306_start_scroll_diag_left(uint8_t start, uint8_t stop); 117 | void ssd1306_stop_scroll(void); 118 | void ssd1306_dim(bool dim); 119 | void ssd1306_data(uint8_t c); 120 | void ssd1306_display(void); 121 | void ssd1306_clear_display(void); 122 | void ssd1306_draw_fast_hline(int16_t x, int16_t y, int16_t w, uint16_t color); 123 | void ssd1306_draw_fast_hline_internal(int16_t x, int16_t y, int16_t w, uint16_t color); 124 | void ssd1306_draw_fast_vline(int16_t x, int16_t y, int16_t h, uint16_t color); 125 | void ssd1306_draw_fast_vline_internal(int16_t x, int16_t __y, int16_t __h, uint16_t color); 126 | void ssd1306_draw_circle(int16_t x0, int16_t y0, int16_t r, uint16_t color); 127 | void ssd1306_draw_circle_helper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, uint16_t color); 128 | void ssd1306_fill_circle(int16_t x0, int16_t y0, int16_t r, uint16_t color); 129 | void ssd1306_fill_circle_helper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername, int16_t delta, uint16_t color); 130 | void ssd1306_draw_line(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color); 131 | void ssd1306_draw_rect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); 132 | void ssd1306_fill_rect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); 133 | void ssd1306_fill_screen(uint16_t color); 134 | void ssd1306_draw_round_rect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color); 135 | void ssd1306_fill_round_rect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t r, uint16_t color); 136 | void ssd1306_draw_triangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); 137 | void ssd1306_fill_triangle( int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2, int16_t y2, uint16_t color); 138 | void ssd1306_draw_bitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color); 139 | void ssd1306_draw_bitmap_bg(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color, uint16_t bg); 140 | void ssd1306_draw_xbitmap(int16_t x, int16_t y, const uint8_t *bitmap, int16_t w, int16_t h, uint16_t color); 141 | size_t ssd1306_write(uint8_t c); 142 | void ssd1306_draw_char(int16_t x, int16_t y, uint8_t c, uint16_t color, uint16_t bg, uint8_t size); 143 | void ssd1306_set_cursor(int16_t x, int16_t y); 144 | int16_t ssd1306_get_cursor_x(void); 145 | int16_t ssd1306_get_cursor_y(void); 146 | void ssd1306_set_textsize(uint8_t s); 147 | void ssd1306_set_textcolor(uint16_t c); 148 | void ssd1306_set_textcolor_bg(uint16_t c, uint16_t b); 149 | void ssd1306_set_textwrap(bool w); 150 | uint8_t ssd1306_get_rotation(void); 151 | void ssd1306_set_rotation(uint8_t x); 152 | void ssd1306_cp437(bool x); 153 | void ssd1306_putstring(char* buffer); 154 | void ssd1306_puts(char* buffer); 155 | #ifdef __cplusplus 156 | } 157 | #endif 158 | 159 | #endif /* __SSD1306_LIB_H */ 160 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # nrf52 LCD display with SSD1306 through TWI interface 2 | 3 | ## Description 4 | ----------- 5 | There are two examples to run on SSD1306 (128x32 / 128x64) resolution with nRF52840 DK. 6 | 7 | 1) Port the Adafruit SSD1306 Library / GFX Library (refer to http://electronut.in/bluey/) 8 | 9 | 2) Port on the SSD1306 driver (refer to https://github.com/monpetit/nrf52-spi-i2c-master-ssd1306) 10 | 11 | 12 | ## Configuration of the display resolution 13 | 14 | Define in SSD1306.h 15 | 16 | ```c 17 | #define SSD1306_128_64 18 | //#define SSD1306_128_32 19 | //#define SSD1306_96_16 20 | ``` 21 | 22 | ![Image of SSD1306 128_32](/images/SSD1306_128_32_NRF52840_DK_board.png) 23 | 24 | ![Image of SSD1306 128_64](/images/SSD1306_128_64_NRF52840_DK_board.png) 25 | 26 | 27 | 28 | # Requirements 29 | ------------ 30 | - nRF5 SDK version 15.2.0 31 | - nRF52840 DK 32 | 33 | The project may need modifications to work with later versions or other boards. 34 | 35 | To compile it, clone the repository in the /nRF5_SDK_15.2.0/examples/ directory. 36 | 37 | The application is built to be used with the official nRF5 SDK that can be downloaded from developer.nordicsemi.com 38 | 39 | --------------------------------------------------------------------------------