1+ // qwiic_oled_custom.h
2+ //
3+ // This is a library written for SparkFun Qwiic OLED boards that use the SSD1306.
4+ //
5+ // SparkFun sells these at its website: www.sparkfun.com
6+ //
7+ // Do you like this library? Help support SparkFun. Buy a board!
8+ //
9+ // Micro OLED https://www.sparkfun.com/products/14532
10+ // Transparent OLED https://www.sparkfun.com/products/15173
11+ // "Narrow" OLED https://www.sparkfun.com/products/17153
12+ // 1.3" OLED https://www.sparkfun.com/products/23453
13+ //
14+ //
15+ // Written by Kirk Benell @ SparkFun Electronics, March 2022
16+ //
17+ // This library configures and draws graphics to OLED boards that use the
18+ // SSD1306 display hardware. The library only supports I2C.
19+ //
20+ // Repository:
21+ // https://github.com/sparkfun/SparkFun_Qwiic_OLED_Arduino_Library
22+ //
23+ // Documentation:
24+ // https://sparkfun.github.io/SparkFun_Qwiic_OLED_Arduino_Library/
25+ //
26+ //
27+ // SparkFun code, firmware, and software is released under the MIT License(http://opensource.org/licenses/MIT).
28+ //
29+ // SPDX-License-Identifier: MIT
30+ //
31+ // The MIT License (MIT)
32+ //
33+ // Copyright (c) 2022 SparkFun Electronics
34+ // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
35+ // associated documentation files (the "Software"), to deal in the Software without restriction,
36+ // including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
37+ // and/or sell copies of the Software, and to permit persons to whom the Software is furnished to
38+ // do so, subject to the following conditions:
39+ // The above copyright notice and this permission notice shall be included in all copies or substantial
40+ // portions of the Software.
41+ // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
42+ // NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
43+ // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
44+ // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
45+ // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
46+
47+ // Implementation for the 1.3" OLED device
48+
49+ #pragma once
50+
51+ #include " qwiic_grssd1306.h"
52+
53+ // ////////////////////////////////////////////////////////////////
54+ // Set the defaults for the SparkFun Qwiic MicroOLED
55+
56+ #define kOLEDCustomDefaultWidth 128
57+ #define kOLEDCustomDefaultHeight 64
58+
59+ #define kOLEDCustomDefaultXOffset 0
60+ #define kOLEDCustomDefaultYOffset 0
61+
62+ // Parameters for this device
63+ #define kOLEDCustomDefaultPinConfig 0x12
64+ #define kOLEDCustomDefaultPreCharge 0xF1
65+ #define kOLEDCustomDefaultVCOM 0x40
66+ #define kOLEDCustomDefaultContrast 0xCF
67+
68+ #define kOLEDCustomDefaultDefaultAddress 0x3D
69+ #define kOLEDCustomDefaultAltAddress 0x3C
70+
71+ class QwOLEDCustom : public QwGrSSD1306 {
72+
73+ public:
74+ // Constructor - setup the viewport and default address for this device.
75+ QwOLEDCustom ()
76+ : QwGrSSD1306(kOLEDCustomDefaultXOffset , kOLEDCustomDefaultYOffset , kOLEDCustomDefaultWidth , kOLEDCustomDefaultHeight )
77+ {
78+ default_address = kOLEDCustomDefaultDefaultAddress ;
79+ };
80+
81+ ~QwOLEDCustom ()
82+ {
83+ if (m_graphicsBuffer != nullptr )
84+ delete[] m_graphicsBuffer;
85+ };
86+
87+ // set up the specific device settings
88+ bool init (void )
89+ {
90+ setViewport (xOffset, yOffset, displayWidth, displayHeight);
91+
92+ setCommPins (pinConfig);
93+ setPreCharge (preCharge);
94+ setVcomDeselect (vcomDeselect);
95+ setContrast (contrast);
96+
97+ if (m_graphicsBuffer != nullptr )
98+ delete[] m_graphicsBuffer;
99+ m_graphicsBuffer = new uint8_t [(uint16_t )displayWidth * (uint16_t )displayHeight / 8 ];
100+ setBuffer (m_graphicsBuffer); // The buffer to use
101+
102+ // Call the super class to do all the work
103+ return this ->QwGrSSD1306 ::init ();
104+ };
105+
106+ uint8_t xOffset = kOLEDCustomDefaultXOffset ;
107+ uint8_t yOffset = kOLEDCustomDefaultYOffset ;
108+ uint8_t displayWidth = kOLEDCustomDefaultWidth ;
109+ uint8_t displayHeight = kOLEDCustomDefaultHeight ;
110+ uint8_t pinConfig = kOLEDCustomDefaultPinConfig ;
111+ uint8_t preCharge = kOLEDCustomDefaultPreCharge ;
112+ uint8_t vcomDeselect = kOLEDCustomDefaultVCOM ;
113+ uint8_t contrast = kOLEDCustomDefaultContrast ;
114+
115+ protected:
116+ // Graphics buffer for this device.
117+ uint8_t *m_graphicsBuffer = nullptr ;
118+ };
0 commit comments