Hexiwear OLED Display Driver
Dependents: Hexi_OLED_TextImage_Example Hexi_OLED_Text_Example Hexi_OLED_Image_Example security-console-app ... more
Diff: Hexi_OLED_SSD1351.h
- Revision:
- 1:3b5be0ee5f0c
- Child:
- 2:fc06b5b5bf6a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Hexi_OLED_SSD1351.h Thu Aug 18 23:01:06 2016 +0000 @@ -0,0 +1,313 @@ +#ifndef HG_OLED_DRIVER +#define HG_OLED_DRIVER + +#include "mbed.h" +#include "OLED_types.h" +#include "OLED_info.h" + + + +class SSD1351{ + +public: + + + SSD1351(PinName mosi,PinName sclk,PinName pwr, PinName cs,PinName rst, PinName dc); + + ~SSD1351(); + + /** + * Send the command to OLED + * @param self OLED handle + * @param cmd OLED command from the datasheet + * @param isFirst designate if this is the first byte in the command + */ + void SendCmd(uint32_t cmd, + uint8_t isFirst); + + + /** + * Send data to OLED + * @param dataToSend data to send to OLED + * @param dataSize data-size + */ + void SendData ( const uint8_t* dataToSend, + uint32_t dataSize); + + /** + * draw box on OLED + * @param xCrd x-coordinate for box's uper left corner + * @param yCrd y-coordinate for box's uper left corner + * @param width box's width + * @param height box's height + * @param color color of the box + * @return status flag + */ + oled_status_t DrawBox ( + uint16_t xCrd, + uint16_t yCrd, + uint16_t width, + uint16_t height, + uint16_t color + ); + + /** + * Fill the entire screen with specified color + * @param color color to fill with + */ + void FillScreen( uint16_t color ); + + + + /** + * Draw a single pixel + * @param xCrd pixel's x coordinate + * @param yCrd pixel's y coordinate + * @param color pixel's color + * @return status flag + */ + oled_status_t DrawPixel ( + int16_t xCrd, + int16_t yCrd, + uint16_t color + ); + + + /** + * Draw the whole screen + * @param image image to draw + * @param xCrd image x-coordinate + * @param yCrd image y-coordinate + * @param width image width + * @param height image height + * @param transition transition style for the new image arrival + * @return status flag + */ + oled_status_t DrawScreen ( + const uint8_t* image, + uint8_t xCrd, + uint8_t yCrd, + uint8_t width, + uint8_t height, + oled_transition_t transition + ); + + + /** + * Set the font to use + * @param newFont desired font + * @param newColor desired color + * @return status flag + */ + oled_status_t SetFont( + const uint8_t* newFont, + uint16_t newColor + ); + + + /** + * Set OLED dynamic area + * @param dynamic_area data-structure with desired values + */ + void SetDynamicArea(oled_dynamic_area_t *dynamic_area); + + /** + * Destroy current OLED dynamic area + */ + void DestroyDynamicArea(); + + + /** + * Set OLED text properties + * @param textProperties data-structure with desired properties + */ + void SetTextProperties(oled_text_properties_t *textProperties); + + + /** + * Return the width in [px] required for the given string to be displayed + * @param text desired string + * @return required text width in [px] + */ + uint8_t GetTextWidth(const uint8_t* text); + + + /** + * Count the characters + * @param width text width + * @param font text font + * @param text given text string + * @param length text length + * @return character count + */ + uint8_t CharCount(uint8_t width, const uint8_t* font, const uint8_t* text, uint8_t length); + + /** + * Add text to the main screen buffer at position x,y. + * @param text text to add + * @param xCrd x-coordinate for the given text + * @param yCrd y-coordinate for the given text + * @return status flag + */ + oled_status_t AddText( const uint8_t* text,uint8_t xCrd, uint8_t yCrd ); + /** + * Add text to the main screen buffer. Used with SetDynamicArea() Function. + * @param text text to add + * @return status flag + */ + oled_status_t AddText( const uint8_t* text); + + /** + * Write text on OLED at position x,y. + * @param text desired text + * @param xCrd x-coordinate for the given text + * @param yCrd y-coordinate for the given text + */ + + oled_status_t DrawText ( const uint8_t* text,uint8_t xCrd, uint8_t yCrd ); + + /** + * Write text on OLED at position set in Dynamic Area Field. Used with SetDynamicArea() Function. + * @param text desired text + * @param x x-coordinate for the given text, set through dynamicArea_t variable + * @param y y-coordinate for the given text, set through dynamicArea_t variable + * + */ + oled_status_t DrawText ( const uint8_t* text); + + /** + * Return the dimensions of image + * @param width given image's width + * @param height given image's height + * @param image desired image + */ + void GetImageDimensions(uint8_t *width, uint8_t *height, const uint8_t* image); + + + + /** + * Add image to the main screen buffer.Used with SetDynamicArea() Function. + * @param image desired image + * @return status flag + */ + oled_status_t AddImage ( const uint8_t* image ); + + /** + * Add image to the main screen buffer at position x,y + * @param image desired image + * @return status flag + */ + oled_status_t AddImage ( const uint8_t* image, uint8_t xCrd, uint8_t yCrd ); + + /** + * Draw image, i.e. send image to OLED GRAM.Used with SetDynamicArea() Function. + * @param image desired image + * @param transition desired transition style for the new image + * @return status flag + */ + oled_status_t DrawImage ( const uint8_t* image ); + /** + * Draw image, i.e. send image to OLED GRAM at position x,y. + * @param image desired image + * @param transition desired transition style for the new image + * @return status flag + */ + oled_status_t DrawImage ( const uint8_t* image, uint8_t xCrd, uint8_t yCrd ); + + /** + * Dim OLED screen on + */ + void DimScreenON(); + + /** + * Return OLED back to full contrast + */ + void DimScreenOFF(); + + /** + * Swap image's bytes per pixel to obtain the correct color format + * @param imgDst desired image + * @param imgSrc original image + * @param imgSize image's size + */ + void Swap( + oled_pixel_t imgDst, + const uint8_t* imgSrc, + uint16_t imgSize + ); + + + /** + * Turn on Power for OLED Display + */ + void PowerON(); + + /** + * Turn off Power for OLED Display + */ + void PowerOFF(); + + /** + * update the main screen buffer + * with the given image + + * @param xCrd image x-coordinate + * @param yCrd image y-coordinate + * @param width image width + * @param height image height + * @param image image for buffer + */ + void UpdateBuffer ( + uint8_t xCrd, + uint8_t yCrd, + uint8_t width, + uint8_t height, + const uint8_t* image + ); + + + +private: + + SPI spi; + DigitalOut power; + DigitalOut cs; + DigitalOut rst; + DigitalOut dc; + + + const uint8_t* selectedFont; + + uint8_t + isFontInitialized, + currentChar_width, + currentChar_height, + screenBuf[OLED_GRAM_SIZE]; + + uint16_t + selectedFont_color, + selectedFont_firstChar, // first character in the font table + selectedFont_lastChar, // last character in the font table + selectedFont_height, + colorMask; + + oled_dynamic_area_t oled_dynamic_area; + oled_text_properties_t oled_text_properties; + + + //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, uint8_t xCrd, uint8_t yCrd, uint8_t width, uint8_t height ); + oled_status_t DownTop ( const uint8_t* image, uint8_t xCrd, uint8_t yCrd, uint8_t width, uint8_t height ); + oled_status_t LeftRight ( const uint8_t* image, uint8_t xCrd, uint8_t yCrd, uint8_t width, uint8_t height ); + oled_status_t RightLeft ( const uint8_t* image, uint8_t xCrd, uint8_t yCrd, uint8_t width, uint8_t height ); + void SetBorders( uint8_t xCrd, uint8_t yCrd, uint8_t width, uint8_t height ); + oled_status_t CreateTextBackground(); + void WriteCharToBuf( uint16_t charToWrite, oled_pixel_t* chrBuf ); + oled_status_t AddCharToTextArea( oled_pixel_t chrPtr, uint8_t chrWidth, uint8_t chrHeight, oled_pixel_t copyAddr, uint8_t imgWidth ); + void* AllocateDynamicArea( uint32_t area ); + oled_status_t DestroyDynamicArea(void * ptr); + +}; + +#endif