Skip to content

Commit 46f28a5

Browse files
author
Owen L - SFE
committed
enable proper buffered output from hwpixel
This got pretty ugly. Relied on some strange assumptions and special conditions to know when to use ```getOffsetColor``` in various ways. Seems to work however. May cause incompatibility with color sequences from HyperDisplay
1 parent b717c8e commit 46f28a5

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

src/HyperDisplay_SSD1309.cpp

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "HyperDisplay_SSD1309.h"
22

3-
3+
const SSD1309_Bite_t ON = { 0x01 };
4+
const SSD1309_Bite_t OFF = { 0x00 };
45

56
SSD1309::SSD1309(uint16_t xSize, uint16_t ySize, SSD1309_Intfc_t interface) : hyperdisplay(xSize, ySize)
67
{
@@ -37,8 +38,29 @@ color_t getOffsetColor(color_t base, uint32_t numPixels); // (required by hyper
3738
*/
3839
color_t SSD1309::getOffsetColor(color_t base, uint32_t numPixels)
3940
{
41+
// For the SSD1309 this function will depend on the current window if it is available
42+
wind_info_t* pwindow = pCurrentWindow;
43+
if(pwindow != NULL){
44+
SSD1309_Bite_t* mirror = (SSD1309_Bite_t*)pwindow->data;
45+
if(mirror != NULL){
46+
// Assume left->right top->bottom for full window width
47+
uint8_t window_width = (pwindow->xMax - pwindow->xMin + 1);
48+
uint8_t x = numPixels % window_width;
49+
uint8_t y = numPixels / window_width;
50+
uint8_t temp = (*(mirror + ((window_width * (y/8)) + x))).bite;
51+
if(temp & (0x01 << (y % 8))){
52+
return (color_t)0x01;
53+
}else{
54+
return (color_t)0x00;
55+
}
56+
}else{
57+
return base; // Also be dumb when there is no mirror data
58+
}
59+
}else{
60+
// When little information available fall back to 'dumb' implementation
61+
return base;
62+
}
4063
return base;
41-
// return (color_t)(((SSD1309_Bite_t*)base + numPixels/8));
4264
}
4365

4466
SSD1309_Status_t SSD1309::refreshDisplay( void )
@@ -142,6 +164,14 @@ void SSD1309::hwpixel(hd_hw_extent_t x0, hd_hw_extent_t y0, color_t data, hd_col
142164
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
143165
color_t value = getOffsetColor(data, startColorOffset);
144166

167+
// If value is either 0 or 1 then interpret it as a direct value...
168+
if((uint32_t)data == 0x00){
169+
value = (color_t)&OFF;
170+
}
171+
if((uint32_t)data == 0x01){
172+
value = (color_t)&ON;
173+
}
174+
145175
SSD1309_Bite_t user = *((SSD1309_Bite_t*)value);
146176
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)
147177
// Need to set the pixel high
@@ -213,7 +243,8 @@ void SSD1309::swpixel( hd_extent_t x0, hd_extent_t y0, color_t data, hd_colors_t
213243
if(colorCycleLength == 0){ return; }
214244

215245
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);
246+
// color_t value = getOffsetColor(data, startColorOffset);
247+
color_t value = data; // have to skip color sequences in buffered writing mode
217248

218249
hd_hw_extent_t x0w = (hd_hw_extent_t)x0; // Cast to hw extent type to be sure of integer values
219250
hd_hw_extent_t y0w = (hd_hw_extent_t)y0;

0 commit comments

Comments
 (0)