Taylor Helton / Hexi_OLED_SSD1351

Dependents:   Hexi

Fork of Hexi_OLED_SSD1351 by Hexiwear

Revision:
0:06f42dd3eab3
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OLED_driver.h	Wed Aug 17 22:08:40 2016 +0000
@@ -0,0 +1,282 @@
+#ifndef HG_OLED_DRIVER
+#define HG_OLED_DRIVER
+
+#include "mbed.h"
+#include "OLED_types.h" 
+#include "OLED_info.h"
+
+
+
+class OLED{
+
+public:
+
+
+  OLED(PinName mosi,PinName sclk,PinName pwr, PinName cs,PinName rst, PinName dc);
+
+  ~OLED(); 
+
+  /**
+   * 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 OLED_SendCmd(uint32_t cmd,
+                     uint8_t isFirst);
+
+
+  /**
+   * Send data to OLED
+   * @param  dataToSend data to send to OLED
+   * @param  dataSize   data-size
+   */
+  void OLED_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 OLED_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 OLED_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 OLED_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 OLED_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 OLED_SetFont(
+                              const uint8_t* newFont,
+                                    uint16_t newColor
+                            );
+
+
+  /**
+   * Set OLED dynamic area
+   * @param dynamic_area data-structure with desired values
+   */
+  void OLED_SetDynamicArea(oled_dynamic_area_t *dynamic_area);
+
+  /**
+   * Destroy current OLED dynamic area
+   */
+  void OLED_DestroyDynamicArea();
+
+
+  /**
+   * Set OLED text properties
+   * @param textProperties data-structure with desired properties
+   */
+  void OLED_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 OLED_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 OLED_CharCount(uint8_t width, const uint8_t* font, const uint8_t* text, uint8_t length);
+
+  /**
+   * Add text to the main screen buffer
+   * @param  text text to add
+   * @return      status flag
+   */
+  oled_status_t OLED_AddText( const uint8_t* text );
+
+  /**
+   * Write text on OLED at position set in Dynamic Area Field
+   * @param text desired text
+   * @param x    x-coordinate for the given text, set through .dynamicArea variable 
+   * @param y    y-coordinate for the given text, set through .dynamicArea variable 
+   */
+  oled_status_t OLED_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 OLED_GetImageDimensions(uint8_t *width, uint8_t *height, const uint8_t* image);
+
+
+
+  /**
+   * Add image to the main screen buffer
+   * @param  image      desired image
+   * @return            status flag
+   */
+  oled_status_t OLED_AddImage ( const uint8_t* image );
+
+  /**
+   * Draw image, i.e. send image to OLED GRAM
+   * @param  image      desired image
+   * @param  transition desired transition style for the new image
+   * @return            status flag
+   */
+  oled_status_t OLED_DrawImage ( const uint8_t* image );
+
+  /**
+   * Dim OLED screen on
+   */
+  void OLED_DimScreenON();
+
+  /**
+   * Return OLED back to full contrast
+   */
+  void OLED_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 OLED_Swap(
+                      oled_pixel_t imgDst,
+                    const uint8_t* imgSrc,
+                          uint16_t imgSize
+                  );
+    
+
+  /**
+   * Turn on Power for OLED Display
+   */              
+  void OLED_PowerON();
+
+  /**
+   * Turn off Power for OLED Display
+   */ 
+  void OLED_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 OLED_UpdateBuffer (
+                                uint8_t xCrd,
+                                uint8_t yCrd,
+                                uint8_t width,
+                                uint8_t height,
+                                const uint8_t* image
+                              );
+
+
+
+private:
+
+  SPI oled_SPI;
+  DigitalOut oled_POWER;
+  DigitalOut oled_CS;
+  DigitalOut oled_RST; 
+  DigitalOut oled_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           
\ No newline at end of file