Skip to content

Commit 8c469fc

Browse files
author
Owen
authored
Control buffered mem access (#1)
Control buffered mem access
2 parents f568c43 + 46f28a5 commit 8c469fc

File tree

2 files changed

+81
-2
lines changed

2 files changed

+81
-2
lines changed

src/HyperDisplay_SSD1309.cpp

Lines changed: 77 additions & 2 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 )
@@ -100,6 +122,29 @@ SSD1309_Status_t SSD1309::clearMirrorPixel(hd_hw_extent_t x, hd_hw_extent_t y)
100122
return SSD1309_Nominal;
101123
}
102124

125+
SSD1309_Status_t SSD1309::setWindowPixel(hd_hw_extent_t x, hd_hw_extent_t y, wind_info_t* pwindow)
126+
{
127+
pwindow = (pwindow == NULL) ? pCurrentWindow : pwindow; // Fall back to current window if not secified
128+
if(pwindow->data == NULL){ return SSD1309_Error; }
129+
130+
SSD1309_Bite_t* windowMirror = (SSD1309_Bite_t*)pwindow->data;
131+
uint8_t temp = (*(windowMirror + (((pwindow->xMax - pwindow->xMin) * (y/8)) + x))).bite;
132+
temp |= (0x01 << (y % 8));
133+
(*(windowMirror + (((pwindow->xMax - pwindow->xMin) * (y/8)) + x))).bite = temp;
134+
return SSD1309_Nominal;
135+
}
136+
137+
SSD1309_Status_t SSD1309::clearWindowPixel(hd_hw_extent_t x, hd_hw_extent_t y, wind_info_t* pwindow)
138+
{
139+
pwindow = (pwindow == NULL) ? pCurrentWindow : pwindow; // Fall back to current window if not secified
140+
if(pwindow->data == NULL){ return SSD1309_Error; }
141+
142+
SSD1309_Bite_t* windowMirror = (SSD1309_Bite_t*)pwindow->data;
143+
uint8_t temp = (*(windowMirror + (((pwindow->xMax - pwindow->xMin) * (y/8)) + x))).bite;
144+
temp &= (~(0x01 << (y % 8)));
145+
(*(windowMirror + (((pwindow->xMax - pwindow->xMin) * (y/8)) + x))).bite = temp;
146+
return SSD1309_Nominal;
147+
}
103148

104149

105150
////////////////////////////////////////////////////////////
@@ -119,6 +164,14 @@ void SSD1309::hwpixel(hd_hw_extent_t x0, hd_hw_extent_t y0, color_t data, hd_col
119164
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
120165
color_t value = getOffsetColor(data, startColorOffset);
121166

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+
122175
SSD1309_Bite_t user = *((SSD1309_Bite_t*)value);
123176
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)
124177
// Need to set the pixel high
@@ -183,8 +236,30 @@ void SSD1309::hwpixel(hd_hw_extent_t x0, hd_hw_extent_t y0, color_t data, hd_col
183236
// // To implement this consider writing 0xFF bytes into a single column
184237
// }
185238

239+
// Implementation of swpixel for SSD1309
240+
void SSD1309::swpixel( hd_extent_t x0, hd_extent_t y0, color_t data, hd_colors_t colorCycleLength, hd_colors_t startColorOffset)
241+
{
242+
if(data == NULL){ return; }
243+
if(colorCycleLength == 0){ return; }
244+
245+
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
246+
// color_t value = getOffsetColor(data, startColorOffset);
247+
color_t value = data; // have to skip color sequences in buffered writing mode
186248

249+
hd_hw_extent_t x0w = (hd_hw_extent_t)x0; // Cast to hw extent type to be sure of integer values
250+
hd_hw_extent_t y0w = (hd_hw_extent_t)y0;
187251

252+
SSD1309_Bite_t user = *((SSD1309_Bite_t*)value);
253+
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)
254+
// Need to set the pixel high
255+
setWindowPixel(x0, y0, pCurrentWindow);
256+
}else{
257+
// Need to clear the pixel
258+
clearWindowPixel(x0, y0, pCurrentWindow);
259+
}
260+
// updateRefreshZone( x0, x0, y0, y0); // Tell where we need updates
261+
// refreshDisplay(); // Perform updates
262+
}
188263

189264
// Functions that don't need color arguments, for simplicity.
190265

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)