Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: ollin-ja-samin-hieno-ihmislaskin MCLAB10 OLEDrgb_MP OLEDrgb_MIC3_L432KC_OS6_hk
Adafruit_SSD1331.h
00001 /*************************************************** 00002 This is a library for the 0.96" 16-bit Color OLED with SSD1331 driver chip 00003 Pick one up today in the adafruit shop! 00004 ------> http://www.adafruit.com/products/684 00005 These displays use SPI to communicate, 4 or 5 pins are required to 00006 interface 00007 Adafruit invests time and resources providing this open source code, 00008 please support Adafruit and open-source hardware by purchasing 00009 products from Adafruit! 00010 Written by Limor Fried/Ladyada for Adafruit Industries. 00011 BSD license, all text above must be included in any redistribution 00012 ****************************************************/ 00013 00014 #include <stddef.h> 00015 #include "mbed.h" 00016 #include "Adafruit_GFX.h" 00017 00018 #define gfx_swap(a, b) { uint16_t t = a; a = b; b = t; } 00019 00020 #ifdef __SAM3X8E__ 00021 typedef volatile RwReg PortReg; 00022 typedef uint32_t PortMask; 00023 #define _BV(b) (1<<(b)) 00024 #else 00025 typedef volatile uint8_t PortReg; 00026 typedef uint8_t PortMask; 00027 #endif 00028 00029 // Select one of these defines to set the pixel color order 00030 #define SSD1331_COLORORDER_RGB 00031 // #define SSD1331_COLORORDER_BGR 00032 00033 #if defined SSD1331_COLORORDER_RGB && defined SSD1331_COLORORDER_BGR 00034 #error "RGB and BGR can not both be defined for SSD1331_COLORODER." 00035 #endif 00036 00037 // Timing Delays 00038 #define SSD1331_DELAYS_HWFILL (1) 00039 #define SSD1331_DELAYS_HWLINE (0) 00040 #define SSD1331_DELAYS_HWCLEAR (1) 00041 00042 // SSD1331 Commands 00043 #define SSD1331_CMD_DRAWLINE 0x21 00044 #define SSD1331_CMD_DRAWRECT 0x22 00045 #define SSD1331_CMD_FILL 0x26 00046 #define SSD1331_CMD_SETCOLUMN 0x15 00047 #define SSD1331_CMD_SETROW 0x75 00048 #define SSD1331_CMD_CONTRASTA 0x81 00049 #define SSD1331_CMD_CONTRASTB 0x82 00050 #define SSD1331_CMD_CONTRASTC 0x83 00051 #define SSD1331_CMD_MASTERCURRENT 0x87 00052 #define SSD1331_CMD_SETREMAP 0xA0 00053 #define SSD1331_CMD_STARTLINE 0xA1 00054 #define SSD1331_CMD_DISPLAYOFFSET 0xA2 00055 #define SSD1331_CMD_NORMALDISPLAY 0xA4 00056 #define SSD1331_CMD_DISPLAYALLON 0xA5 00057 #define SSD1331_CMD_DISPLAYALLOFF 0xA6 00058 #define SSD1331_CMD_INVERTDISPLAY 0xA7 00059 #define SSD1331_CMD_SETMULTIPLEX 0xA8 00060 #define SSD1331_CMD_SETMASTER 0xAD 00061 #define SSD1331_CMD_DISPLAYOFF 0xAE 00062 #define SSD1331_CMD_DISPLAYON 0xAF 00063 #define SSD1331_CMD_POWERMODE 0xB0 00064 #define SSD1331_CMD_PRECHARGE 0xB1 00065 #define SSD1331_CMD_CLOCKDIV 0xB3 00066 #define SSD1331_CMD_PRECHARGEA 0x8A 00067 #define SSD1331_CMD_PRECHARGEB 0x8B 00068 #define SSD1331_CMD_PRECHARGEC 0x8C 00069 #define SSD1331_CMD_PRECHARGELEVEL 0xBB 00070 #define SSD1331_CMD_VCOMH 0xBE 00071 #define WIDTH 96 00072 #define HEIGHT 64 00073 00074 #define SSD1331_CMD_CLEAR 0x25 00075 00076 class Adafruit_SSD1331 : public Adafruit_GFX { 00077 public: 00078 Adafruit_SSD1331(PinName cs, PinName rs, PinName dc, PinName mosi, PinName miso, PinName sclk); 00079 00080 uint16_t Color565(uint8_t r, uint8_t g, uint8_t b); 00081 00082 // drawing primitives! 00083 void drawPixel(int16_t x, int16_t y, uint16_t color); 00084 void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color); 00085 void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color); 00086 void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t fillcolor); 00087 void clearScreen(); 00088 void clearArea(int16_t x0, int16_t y0, int16_t x1, int16_t y1); 00089 void pushColor(uint16_t c); 00090 00091 // commands 00092 void begin(void); 00093 void goHome(void); 00094 void goTo(int x, int y); 00095 00096 void reset(void); 00097 00098 /* low level */ 00099 00100 void writeData(uint8_t d); 00101 void writeCommand(uint8_t c); 00102 00103 static const int16_t TFTWIDTH = 96; 00104 static const int16_t TFTHEIGHT = 64; 00105 00106 uint8_t cursorX, cursorY; 00107 00108 void writeData_unsafe(uint16_t d); 00109 00110 void setWriteDir(void); 00111 void write8(uint8_t d); 00112 00113 private: 00114 void spiwrite(uint8_t); 00115 00116 DigitalOut CS, RES, DC; 00117 SPI spi; // mosi, miso, sclk 00118 };
Generated on Mon Jul 25 2022 08:09:42 by
1.7.2