Library for drawing on the Hexiwear's OLED - more features being actively worked on

Dependents:   Hexidraw_Demo Hexiwear-FinalProject_v2

Discussion: https://developer.mbed.org/forum/team-4615-Hexiwear-community/topic/26595/

Hexidraw is a library for drawing on the Hexiwear's OLED. Be aware that it is not very optimized, so drawing may be slow, especially when drawing on large areas of the screen.

Please see the wiki for API documentation.

Features:

  • Screen fill with a color
  • Drawing filled rectangles
  • Drawing circles with a set radius and line width
  • Setting individual pixels
  • Turning on and off the OLED's sleep mode
  • Drawing images

Example project: https://developer.mbed.org/users/keithm01/code/Hexidraw_Demo/

Committer:
keithm01
Date:
Sat Aug 20 16:35:58 2016 +0000
Revision:
5:00876457cad4
Parent:
4:9c0b59439725
Changed default value to not using the buffer

Who changed what in which revision?

UserRevisionLine numberNew contents of line
keithm01 0:2d3fcb6dabd4 1
keithm01 0:2d3fcb6dabd4 2 #ifndef _HEXIDRAW_H_
keithm01 0:2d3fcb6dabd4 3 #define _HEXIDRAW_H_
keithm01 0:2d3fcb6dabd4 4
keithm01 0:2d3fcb6dabd4 5 #include <mbed.h>
keithm01 0:2d3fcb6dabd4 6 #include <stdarg.h>
keithm01 0:2d3fcb6dabd4 7
keithm01 0:2d3fcb6dabd4 8 #include "oled_info.h"
keithm01 0:2d3fcb6dabd4 9
keithm01 0:2d3fcb6dabd4 10 #define BLACK 0x0000
keithm01 0:2d3fcb6dabd4 11 #define WHITE 0xffff
keithm01 0:2d3fcb6dabd4 12
keithm01 2:ef14c6dd6b93 13 #define OLED_WIDTH 96
keithm01 2:ef14c6dd6b93 14 #define OLED_HEIGHT 96
keithm01 2:ef14c6dd6b93 15
keithm01 2:ef14c6dd6b93 16 #define OLED_BYTES_PER_PIXEL ( 2 )
keithm01 2:ef14c6dd6b93 17
keithm01 2:ef14c6dd6b93 18 #define OLED_COL_OFFSET 16
keithm01 2:ef14c6dd6b93 19
keithm01 2:ef14c6dd6b93 20 #define OLED_IMAGE_SIZE ( OLED_WIDTH * OLED_HEIGHT * OLED_BYTES_PER_PIXEL )
keithm01 2:ef14c6dd6b93 21 #define OLED_BMP_HEADER_BYTE_SIZE (6)
keithm01 2:ef14c6dd6b93 22
keithm01 2:ef14c6dd6b93 23 #define OLED_SPI_CHUNK (511)
keithm01 3:e8bbba5c43ba 24
keithm01 3:e8bbba5c43ba 25 #define OLED_SKIP_IMAGE_HEADER( imgPtr ) ( (const uint8_t*)(imgPtr) + OLED_BMP_HEADER_BYTE_SIZE )
keithm01 4:9c0b59439725 26
keithm01 5:00876457cad4 27 #define USE_BUFFER 0
keithm01 2:ef14c6dd6b93 28
keithm01 0:2d3fcb6dabd4 29 /* borrowed from the Adafruit library at:
keithm01 0:2d3fcb6dabd4 30 https://developer.mbed.org/teams/ELLA-Robotics-Inc/code/Adafruit_GFX_1351/
keithm01 0:2d3fcb6dabd4 31 Since I don't know enough to make my own function :) */
keithm01 0:2d3fcb6dabd4 32 uint16_t Color565(uint8_t r, uint8_t g, uint8_t b) ;
keithm01 0:2d3fcb6dabd4 33
keithm01 0:2d3fcb6dabd4 34 class OLED {
keithm01 0:2d3fcb6dabd4 35 public:
keithm01 0:2d3fcb6dabd4 36 OLED();
keithm01 0:2d3fcb6dabd4 37 void writeCommand(uint8_t v);
keithm01 0:2d3fcb6dabd4 38 void writeData(uint8_t v);
keithm01 0:2d3fcb6dabd4 39 void begin();
keithm01 0:2d3fcb6dabd4 40 void sleep();
keithm01 0:2d3fcb6dabd4 41 void wake();
keithm01 0:2d3fcb6dabd4 42 void pixel(int16_t x, int16_t y, uint16_t color);
keithm01 0:2d3fcb6dabd4 43 void cursor(int x, int y);
keithm01 0:2d3fcb6dabd4 44 void rect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t fillcolor);
keithm01 1:82ccc138bbe6 45 void dim();
keithm01 1:82ccc138bbe6 46 void clear(uint16_t color);
keithm01 2:ef14c6dd6b93 47 void circle(uint16_t x, uint16_t y, uint16_t radius, uint16_t color, uint16_t width = 1);
keithm01 4:9c0b59439725 48 void image (uint16_t x, uint16_t y, const uint8_t* image);
keithm01 4:9c0b59439725 49 void hline(uint16_t x, uint16_t y, uint16_t width, uint16_t color, uint16_t thickness = 1);
keithm01 4:9c0b59439725 50 void vline(uint16_t x, uint16_t y, uint16_t height, uint16_t color, uint16_t thickness = 1);
keithm01 4:9c0b59439725 51 void draw();
keithm01 0:2d3fcb6dabd4 52 private:
keithm01 0:2d3fcb6dabd4 53 SPI _spi;
keithm01 0:2d3fcb6dabd4 54 DigitalOut _cs, _dc, _reset;
keithm01 4:9c0b59439725 55 uint16_t displayBuffer[OLED_WIDTH * OLED_HEIGHT];
keithm01 4:9c0b59439725 56 void text(uint16_t x, uint16_t y, const uint8_t* text, const uint8_t* font, uint16_t color = WHITE);
keithm01 0:2d3fcb6dabd4 57 };
keithm01 0:2d3fcb6dabd4 58
keithm01 0:2d3fcb6dabd4 59 #endif