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.
Fork of Hexi_OLED_SSD1351 by
Revision 7:9961c525e249, committed 2016-08-26
- Comitter:
- khuang
- Date:
- Fri Aug 26 22:54:49 2016 +0000
- Parent:
- 6:0060ffa3f4dc
- Child:
- 8:ae5fad429790
- Commit message:
- Added GetTextProperties to SSD1351 Class
Changed in this revision
| Hexi_OLED_SSD1351.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Hexi_OLED_SSD1351.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Hexi_OLED_SSD1351.cpp Fri Aug 26 19:56:07 2016 +0000
+++ b/Hexi_OLED_SSD1351.cpp Fri Aug 26 22:54:49 2016 +0000
@@ -170,35 +170,31 @@
{
- uint16_t* arrayPtr = (uint16_t*)dataToSend;
+ uint16_t* arrayPtr = (uint16_t*)dataToSend;
- for( uint32_t i = 0; i < dataSize/2; i++ )
- {
- arrayPtr[i] &= colorMask;
- }
+ for( uint32_t i = 0; i < dataSize/2; i++ )
+ {
+ arrayPtr[i] &= colorMask;
+ }
- this->SendCmd( OLED_CMD_WRITERAM, CMD_BYTE );
+ SendCmd( OLED_CMD_WRITERAM, CMD_BYTE );
-
- // sending data -> set DC pin
-
+ /* sending data -> set DC pin */
dc = 1;
cs = 0 ;
+ const uint8_t*
+ /* traversing pointer */
+ bufPtr = dataToSend;
- const uint8_t*
- // traversing pointer
- bufPtr = dataToSend;
-
- for ( uint32_t i = 0; i < dataSize; i++)
- {
- spi.write(*bufPtr);
- bufPtr += 1;
- }
+ for ( uint32_t i = 0; i < dataSize; i++)
+ {
+ spi.write(*bufPtr);
+ bufPtr += 1;
+ }
-
cs = 1;
}
@@ -226,7 +222,7 @@
SetDynamicArea( &boxArea );
- // helper pointer
+ /* helper pointer */
uint8_t*
boxBuf = (uint8_t*)oled_dynamic_area.areaBuffer;
@@ -236,7 +232,7 @@
return OLED_STATUS_ERROR;
}
- // check the bounds
+ /* check the bounds */
if AreCoordsNotValid( xCrd, yCrd, width, height )
{
status = OLED_STATUS_INIT_ERROR;
@@ -244,7 +240,7 @@
else
{
- /** fill the buffer with color */
+ /* fill the buffer with color */
for ( uint16_t i = 0; i < boxSize; i++ )
{
@@ -252,9 +248,9 @@
boxBuf[ 2*i + 1 ] = color;
}
- /** set the locations */
+ /* set the locations */
- // adjust for the offset
+ /* adjust for the offset */
OLED_AdjustColumnOffset(xCrd);
OLED_AdjustRowOffset(yCrd);
@@ -263,12 +259,10 @@
SendCmd( xCrd + (width-1), DATA_BYTE );
SendCmd( OLED_CMD_SET_ROW, CMD_BYTE );
SendCmd( yCrd, DATA_BYTE );
- SendCmd( yCrd + (height-1), DATA_BYTE );
+ SendCmd( yCrd + (height-1), DATA_BYTE );
-
- // fill the GRAM
+ /* fill the GRAM */
SendData( (uint8_t*)boxBuf, boxSize*OLED_BYTES_PER_PIXEL );
-
DestroyDynamicArea();
}
@@ -283,17 +277,17 @@
*/
void SSD1351::FillScreen( uint16_t color )
{
- /** fill the screen buffer with color */
+ /* fill the screen buffer with color */
for ( uint16_t i = 0; i < ( OLED_SCREEN_WIDTH * OLED_SCREEN_HEIGHT ); i++ )
{
screenBuf[ 2*i ] = color >> 8;
screenBuf[ 2*i + 1 ] = color;
}
- /** set the locations */
+ /* set the locations */
SetBorders( 0, 0, OLED_SCREEN_WIDTH, OLED_SCREEN_HEIGHT );
- /** fill GRAM */
+ /* fill GRAM */
SendData( (uint8_t*)screenBuf, OLED_SCREEN_WIDTH * OLED_SCREEN_HEIGHT * OLED_BYTES_PER_PIXEL );
}
@@ -306,7 +300,7 @@
uint16_t color
)
{
- // check the bounds
+ /* check the bounds */
if AreCoordsNotValid( xCrd, yCrd, 1, 1 )
{
return OLED_STATUS_INIT_ERROR;
@@ -314,16 +308,16 @@
else
{
- // set directions
+ /* set directions */
SetBorders( xCrd, yCrd, OLED_SCREEN_WIDTH, OLED_SCREEN_HEIGHT);
uint16_t
- // swap bytes
+ /* swap bytes */
dot = color;
OLED_SwapMe(dot);
- // fill the GRAM
+ /* fill the GRAM */
SendData( (uint8_t*)&dot, 2 );
return OLED_STATUS_SUCCESS;
@@ -351,10 +345,10 @@
switch ( transition )
{
case OLED_TRANSITION_NONE: {
- /** set the locations */
+ /* set the locations */
SetBorders( xCrd, yCrd, width, height);
- // fill the GRAM
+ /* fill the GRAM */
SendData( (const uint8_t*)image, width * height * OLED_BYTES_PER_PIXEL );
break;
}
@@ -391,12 +385,10 @@
uint16_t newColor
)
{
- /** save the new values in intern variables */
+ /* save the new values in intern variables */
selectedFont = newFont;
- // selectedFont_firstChar = newFont[2] + (newFont[3] << 8);
selectedFont_firstChar = newFont[2] | ( (uint16_t)newFont[3] << 8 );
- // selectedFont_lastChar = newFont[4] + (newFont[5] << 8);
selectedFont_lastChar = newFont[4] | ( (uint16_t)newFont[5] << 8 );
selectedFont_height = newFont[6];
selectedFont_color = newColor;
@@ -450,8 +442,13 @@
SetFont( oled_text_properties.font, oled_text_properties.fontColor );
}
-
-
+void SSD1351::GetTextProperties(oled_text_properties_t *textProperties)
+{
+ textProperties->font = oled_text_properties.font;
+ textProperties->fontColor = oled_text_properties.fontColor;
+ textProperties->alignParam = oled_text_properties.alignParam;
+ textProperties->background = oled_text_properties.background;
+}
uint8_t SSD1351::GetTextWidth(const uint8_t* text)
{
@@ -461,10 +458,10 @@
while ( 0 != text[chrCnt] )
{
text_width += *( selectedFont + 8 + (uint16_t)( ( text[chrCnt++] - selectedFont_firstChar ) << 2 ) );
- // make 1px space between chars
+ /* make 1px space between chars */
text_width++;
}
- // remove the final space
+ /* remove the final space */
text_width--;
return text_width;
@@ -488,7 +485,7 @@
chrCnt--;
break;
}
- // make 1px space between chars
+ /* make 1px space between chars */
text_width++;
}
@@ -515,21 +512,19 @@
text_width = GetTextWidth(text);
- /**
+ /*
* set default values, if necessary
*/
text_height = selectedFont_height;
oled_dynamic_area_t textArea;
-
textArea.width = text_width;
textArea.height = text_height;
textArea.xCrd = xCrd;
textArea.yCrd = yCrd;
SetDynamicArea(&textArea);
-
currentChar_y = ( oled_dynamic_area.height - text_height ) >> 1;
switch ( oled_text_properties.alignParam & OLED_TEXT_HALIGN_MASK )
@@ -565,7 +560,7 @@
return OLED_STATUS_ERROR;
}
- /**
+ /*
* write the characters into designated space, one by one
*/
@@ -591,7 +586,7 @@
return OLED_STATUS_ERROR;
}
- // copy data
+ /* copy data */
oled_pixel_t
copyAddr = oled_dynamic_area.areaBuffer + ( currentChar_y * oled_dynamic_area.width + currentChar_x );
@@ -710,7 +705,7 @@
return OLED_STATUS_ERROR;
}
- // copy data
+ /* copy data */
oled_pixel_t
copyAddr = oled_dynamic_area.areaBuffer + ( currentChar_y * oled_dynamic_area.width + currentChar_x );
@@ -746,12 +741,12 @@
}
AddText(text);
- // set the locations
+ /* set the locations */
SetBorders( oled_dynamic_area.xCrd, oled_dynamic_area.yCrd, oled_dynamic_area.width, oled_dynamic_area.height );
- // fill the GRAM
+ /* fill the GRAM */
SendData( (const uint8_t*)oled_dynamic_area.areaBuffer, oled_dynamic_area.width * oled_dynamic_area.height * OLED_BYTES_PER_PIXEL );
-// free( currentTextAreaImage );
+ //free( currentTextAreaImage );
return OLED_STATUS_SUCCESS;
}
@@ -768,7 +763,7 @@
oled_status_t
status = OLED_STATUS_SUCCESS;
- // check the bounds
+ /* check the bounds */
if AreCoordsNotValid( oled_dynamic_area.xCrd, oled_dynamic_area.yCrd, oled_dynamic_area.width, oled_dynamic_area.height )
{
status = OLED_STATUS_INIT_ERROR;
@@ -778,7 +773,7 @@
{
Swap( (oled_pixel_t)oled_dynamic_area.areaBuffer, BMP_SkipHeader(image), oled_dynamic_area.width*oled_dynamic_area.height );
- // update the main screen buffer
+ /* update the main screen buffer */
UpdateBuffer( oled_dynamic_area.xCrd, oled_dynamic_area.yCrd, oled_dynamic_area.width, oled_dynamic_area.height, (const uint8_t *)oled_dynamic_area.areaBuffer );
}
@@ -799,7 +794,7 @@
GetImageDimensions(&image_dynamicArea.width, &image_dynamicArea.height, image);
SetDynamicArea(&image_dynamicArea);
- // check the bounds
+ /* check the bounds */
if AreCoordsNotValid( oled_dynamic_area.xCrd, oled_dynamic_area.yCrd, oled_dynamic_area.width, oled_dynamic_area.height )
{
status = OLED_STATUS_INIT_ERROR;
@@ -809,7 +804,7 @@
{
Swap( (oled_pixel_t)oled_dynamic_area.areaBuffer, BMP_SkipHeader(image), oled_dynamic_area.width*oled_dynamic_area.height );
- // update the main screen buffer
+ /* update the main screen buffer */
UpdateBuffer( oled_dynamic_area.xCrd, oled_dynamic_area.yCrd, oled_dynamic_area.width, oled_dynamic_area.height, (const uint8_t *)oled_dynamic_area.areaBuffer );
}
@@ -826,10 +821,10 @@
status = AddImage( image );
- // set the locations
+ /* set the locations */
SetBorders( oled_dynamic_area.xCrd, oled_dynamic_area.yCrd, oled_dynamic_area.width, oled_dynamic_area.height );
- // fill the GRAM
+ /* fill the GRAM */
SendData( (const uint8_t*)oled_dynamic_area.areaBuffer, oled_dynamic_area.width * oled_dynamic_area.height * OLED_BYTES_PER_PIXEL );
@@ -844,10 +839,10 @@
status = AddImage( image,xCrd,yCrd);
- // set the locations
+ /* set the locations */
SetBorders( oled_dynamic_area.xCrd, oled_dynamic_area.yCrd, oled_dynamic_area.width, oled_dynamic_area.height );
- // fill the GRAM
+ /* fill the GRAM */
SendData( (const uint8_t*)oled_dynamic_area.areaBuffer, oled_dynamic_area.width * oled_dynamic_area.height * OLED_BYTES_PER_PIXEL );
@@ -863,7 +858,7 @@
SendCmd( OLED_CMD_CONTRASTMASTER, CMD_BYTE );
SendCmd( 0xC0 | (0xF-i), DATA_BYTE );
wait_ms(20);
- //OSA_TimeDelay( 20 );
+ // OSA_TimeDelay( 20 );
}
}
@@ -905,7 +900,7 @@
- //Formerly Known as GuiDriver_UpdateScreen
+ /* Formerly Known as GuiDriver_UpdateScreen */
void SSD1351::UpdateBuffer (
int8_t xCrd,
int8_t yCrd,
@@ -914,7 +909,7 @@
const uint8_t* image
)
{
- // copy data
+ /* copy data */
oled_pixel_t
copyAddr = (oled_pixel_t)screenBuf + ( yCrd*OLED_SCREEN_WIDTH + xCrd );
@@ -937,13 +932,13 @@
AddText(text,xCrd,yCrd);
- // set the locations
+ /* set the locations */
SetBorders( oled_dynamic_area.xCrd, oled_dynamic_area.yCrd, oled_dynamic_area.width, oled_dynamic_area.height );
- // fill the GRAM
+ /* fill the GRAM */
SendData( (const uint8_t*)oled_dynamic_area.areaBuffer, oled_dynamic_area.width * oled_dynamic_area.height * OLED_BYTES_PER_PIXEL );
-// free( currentTextAreaImage );
+ //free( currentTextAreaImage );
return OLED_STATUS_SUCCESS;
}
@@ -1101,7 +1096,7 @@
|| ( yCrd_moving < yCrd )
)
{
- // draw full image
+ /* draw full image */
SetBorders( xCrd, yCrd, width, height );
SendData( (const uint8_t*)image, width * height * OLED_BYTES_PER_PIXEL );
break;
@@ -1159,7 +1154,7 @@
SetDynamicArea( &transImageArea );
- // helper pointer
+ /* helper pointer */
oled_pixel_t
transImage = (oled_pixel_t)oled_dynamic_area.areaBuffer;
@@ -1168,8 +1163,7 @@
return OLED_STATUS_INIT_ERROR;
}
- // Transpose( (oled_pixel_t)transImage, (const oled_pixel_t)image, width, height );
- Transpose( transImage,(oled_pixel_t)image, width, height );
+ Transpose( transImage,(oled_pixel_t)image, width, height );
SendCmd( OLED_CMD_SET_REMAP, CMD_BYTE );
SendCmd( OLED_REMAP_SETTINGS | REMAP_VERTICAL_INCREMENT, DATA_BYTE );
@@ -1210,7 +1204,6 @@
SendCmd( OLED_CMD_SET_REMAP, CMD_BYTE );
SendCmd( OLED_REMAP_SETTINGS, DATA_BYTE );
-
DestroyDynamicArea();
return status;
}
@@ -1245,7 +1238,7 @@
SetDynamicArea( &transImageArea );
- // helper pointer
+ /* helper pointer */
oled_pixel_t
transImage = oled_dynamic_area.areaBuffer;
@@ -1254,7 +1247,6 @@
return OLED_STATUS_INIT_ERROR;
}
- //Transpose( (oled_pixel_t)transImage, (const oled_pixel_t)image, width, height );
Transpose(transImage, (oled_pixel_t)image, width, height );
SendCmd( OLED_CMD_SET_REMAP, CMD_BYTE );
@@ -1320,7 +1312,7 @@
)
{
- // adjust for the offset
+ /* adjust for the offset*/
OLED_AdjustColumnOffset(xCrd);
OLED_AdjustRowOffset(yCrd);
@@ -1355,7 +1347,7 @@
const uint8_t*
background = oled_text_properties.background;
- /** copy data */
+ /* copy data */
if (
( NULL == imgBuf )
@@ -1418,7 +1410,7 @@
const uint8_t*
pChBitMap = selectedFont + offset;
- // allocate space for char image
+ /* allocate space for char image */
*chrBuf = (oled_pixel_t)AllocateDynamicArea( currentChar_height * currentChar_width );
if ( NULL == *chrBuf )
@@ -1454,7 +1446,6 @@
}
-
/**
* Add subimage/character to the active image buffer
* @param xOffset offset for the x-coordinate
@@ -1525,10 +1516,3 @@
return OLED_STATUS_SUCCESS;
}
-
-
-
-
-
-
-
--- a/Hexi_OLED_SSD1351.h Fri Aug 26 19:56:07 2016 +0000
+++ b/Hexi_OLED_SSD1351.h Fri Aug 26 22:54:49 2016 +0000
@@ -56,6 +56,14 @@
* @param csPin OLED Chip Select Pin
* @param rstPin OLED Reset Pin
* @param dcPin OLED DC Pin
+ *
+ * @note Default TextProperties
+ *
+ * .font = OpenSans_10x15_Regular,
+ * .fontColor = COLOR_WHITE,
+ * .alignParam = OLED_TEXT_ALIGN_CENTER,
+ * .background = NULL
+ *
*/
SSD1351(PinName mosiPin,PinName sclkPin,PinName pwrPin, PinName csPin,PinName rstPin, PinName dcPin);
@@ -165,11 +173,16 @@
/**
- * Set OLED text properties
+ * Set OLED class text properties from parameter
* @param textProperties data-structure with desired properties
*/
void SetTextProperties(oled_text_properties_t *textProperties);
+ /**
+ * Copy OLED class text properties to parameter
+ * @param textProperties destination data-structure
+ */
+ void GetTextProperties(oled_text_properties_t *textProperties);
/**
* Return the width in [px] required for the given string to be displayed
@@ -348,8 +361,8 @@
uint16_t
selectedFont_color,
- selectedFont_firstChar, // first character in the font table
- selectedFont_lastChar, // last character in the font table
+ selectedFont_firstChar, /* first character in the font table */
+ selectedFont_lastChar, /* last character in the font table */
selectedFont_height,
colorMask;
@@ -357,7 +370,7 @@
oled_text_properties_t oled_text_properties;
- //Internal Functions
+ /* Internal Functions */
void Transpose( oled_pixel_t transImage, const oled_pixel_t image, uint8_t width, uint8_t height );
oled_status_t TopDown ( const uint8_t* image, int8_t xCrd, int8_t yCrd, uint8_t width, uint8_t height );
oled_status_t DownTop ( const uint8_t* image, int8_t xCrd, int8_t yCrd, uint8_t width, uint8_t height );
