Skip to content

Commit b717c8e

Browse files
author
Owen L - SFE
committed
add swpixel implementation
this accesses bit-packed display memory correctly, however there is still the issue of getting hwfillFromArray to properly utilize the bit-packed data
1 parent f568c43 commit b717c8e

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/HyperDisplay_SSD1309.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,29 @@ SSD1309_Status_t SSD1309::clearMirrorPixel(hd_hw_extent_t x, hd_hw_extent_t y)
100100
return SSD1309_Nominal;
101101
}
102102

103+
SSD1309_Status_t SSD1309::setWindowPixel(hd_hw_extent_t x, hd_hw_extent_t y, wind_info_t* pwindow)
104+
{
105+
pwindow = (pwindow == NULL) ? pCurrentWindow : pwindow; // Fall back to current window if not secified
106+
if(pwindow->data == NULL){ return SSD1309_Error; }
107+
108+
SSD1309_Bite_t* windowMirror = (SSD1309_Bite_t*)pwindow->data;
109+
uint8_t temp = (*(windowMirror + (((pwindow->xMax - pwindow->xMin) * (y/8)) + x))).bite;
110+
temp |= (0x01 << (y % 8));
111+
(*(windowMirror + (((pwindow->xMax - pwindow->xMin) * (y/8)) + x))).bite = temp;
112+
return SSD1309_Nominal;
113+
}
114+
115+
SSD1309_Status_t SSD1309::clearWindowPixel(hd_hw_extent_t x, hd_hw_extent_t y, wind_info_t* pwindow)
116+
{
117+
pwindow = (pwindow == NULL) ? pCurrentWindow : pwindow; // Fall back to current window if not secified
118+
if(pwindow->data == NULL){ return SSD1309_Error; }
119+
120+
SSD1309_Bite_t* windowMirror = (SSD1309_Bite_t*)pwindow->data;
121+
uint8_t temp = (*(windowMirror + (((pwindow->xMax - pwindow->xMin) * (y/8)) + x))).bite;
122+
temp &= (~(0x01 << (y % 8)));
123+
(*(windowMirror + (((pwindow->xMax - pwindow->xMin) * (y/8)) + x))).bite = temp;
124+
return SSD1309_Nominal;
125+
}
103126

104127

105128
////////////////////////////////////////////////////////////
@@ -183,8 +206,29 @@ void SSD1309::hwpixel(hd_hw_extent_t x0, hd_hw_extent_t y0, color_t data, hd_col
183206
// // To implement this consider writing 0xFF bytes into a single column
184207
// }
185208

209+
// Implementation of swpixel for SSD1309
210+
void SSD1309::swpixel( hd_extent_t x0, hd_extent_t y0, color_t data, hd_colors_t colorCycleLength, hd_colors_t startColorOffset)
211+
{
212+
if(data == NULL){ return; }
213+
if(colorCycleLength == 0){ return; }
214+
215+
startColorOffset = getNewColorOffset(colorCycleLength, startColorOffset, 0); // This line is needed to condition the user's input start color offset because it could be greater than the cycle length
216+
color_t value = getOffsetColor(data, startColorOffset);
186217

218+
hd_hw_extent_t x0w = (hd_hw_extent_t)x0; // Cast to hw extent type to be sure of integer values
219+
hd_hw_extent_t y0w = (hd_hw_extent_t)y0;
187220

221+
SSD1309_Bite_t user = *((SSD1309_Bite_t*)value);
222+
if(user.b0){ // Check if the user's bit is set or not (this implies that the user should always set bit 0 of a 'bite' to the pixel value they want)
223+
// Need to set the pixel high
224+
setWindowPixel(x0, y0, pCurrentWindow);
225+
}else{
226+
// Need to clear the pixel
227+
clearWindowPixel(x0, y0, pCurrentWindow);
228+
}
229+
// updateRefreshZone( x0, x0, y0, y0); // Tell where we need updates
230+
// refreshDisplay(); // Perform updates
231+
}
188232

189233
// Functions that don't need color arguments, for simplicity.
190234

src/HyperDisplay_SSD1309.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ class SSD1309 : virtual public hyperdisplay{
177177
SSD1309_Status_t updateRefreshZone( hd_hw_extent_t colStart, hd_hw_extent_t colEnd, hd_hw_extent_t rowStart, hd_hw_extent_t rowEnd );
178178
SSD1309_Status_t setMirrorPixel(hd_hw_extent_t x, hd_hw_extent_t y);
179179
SSD1309_Status_t clearMirrorPixel(hd_hw_extent_t x, hd_hw_extent_t y);
180+
SSD1309_Status_t setWindowPixel(hd_hw_extent_t x, hd_hw_extent_t y, wind_info_t* pwindow = NULL);
181+
SSD1309_Status_t clearWindowPixel(hd_hw_extent_t x, hd_hw_extent_t y, wind_info_t* pwindow = NULL);
180182

181183
public:
182184

@@ -190,6 +192,8 @@ class SSD1309 : virtual public hyperdisplay{
190192
// void hwrectangle(hd_hw_extent_t x0, hd_hw_extent_t y0, hd_hw_extent_t x1, hd_hw_extent_t y1, bool filled = false, color_t data = NULL, hd_colors_t colorCycleLength = 1, hd_colors_t startColorOffset = 0, bool reverseGradient = false, bool gradientVertical = false); // More efficient rectangle imp in window-relative coordinates
191193
// void hwfillFromArray(hd_hw_extent_t x0, hd_hw_extent_t y0, hd_hw_extent_t x1, hd_hw_extent_t y1, color_t data = NULL, hd_pixels_t numPixels = 0, bool Vh = false ); // More efficient fill from array implementation. Uses screen-relative coordinates
192194

195+
// Buffered drawing API
196+
void swpixel( hd_extent_t x0, hd_extent_t y0, color_t data = NULL, hd_colors_t colorCycleLength = 1, hd_colors_t startColorOffset = 0);
193197

194198
// Functions that don't need color arguments, for simplicity.
195199
void setWindowColorSet(wind_info_t* pwindow = NULL);

0 commit comments

Comments
 (0)