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:
Fri Aug 19 22:12:11 2016 +0000
Revision:
2:ef14c6dd6b93
Parent:
1:82ccc138bbe6
Child:
3:e8bbba5c43ba
Added image drawing function

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 2:ef14c6dd6b93 24
keithm01 0:2d3fcb6dabd4 25 /* borrowed from the Adafruit library at:
keithm01 0:2d3fcb6dabd4 26 https://developer.mbed.org/teams/ELLA-Robotics-Inc/code/Adafruit_GFX_1351/
keithm01 0:2d3fcb6dabd4 27 Since I don't know enough to make my own function :) */
keithm01 0:2d3fcb6dabd4 28 uint16_t Color565(uint8_t r, uint8_t g, uint8_t b) ;
keithm01 0:2d3fcb6dabd4 29
keithm01 0:2d3fcb6dabd4 30 class OLED {
keithm01 0:2d3fcb6dabd4 31 public:
keithm01 0:2d3fcb6dabd4 32 OLED();
keithm01 0:2d3fcb6dabd4 33 void writeCommand(uint8_t v);
keithm01 0:2d3fcb6dabd4 34 void writeData(uint8_t v);
keithm01 0:2d3fcb6dabd4 35 void begin();
keithm01 0:2d3fcb6dabd4 36 void sleep();
keithm01 0:2d3fcb6dabd4 37 void wake();
keithm01 0:2d3fcb6dabd4 38 void pixel(int16_t x, int16_t y, uint16_t color);
keithm01 0:2d3fcb6dabd4 39 void cursor(int x, int y);
keithm01 0:2d3fcb6dabd4 40 void rect(uint16_t x, uint16_t y, uint16_t w, uint16_t h, uint16_t fillcolor);
keithm01 1:82ccc138bbe6 41 void dim();
keithm01 1:82ccc138bbe6 42 void clear(uint16_t color);
keithm01 2:ef14c6dd6b93 43 void circle(uint16_t x, uint16_t y, uint16_t radius, uint16_t color, uint16_t width = 1);
keithm01 2:ef14c6dd6b93 44 void image (uint16_t x, uint16_t y, const uint8_t* image, uint32_t image_data_size = OLED_IMAGE_SIZE);
keithm01 0:2d3fcb6dabd4 45 private:
keithm01 0:2d3fcb6dabd4 46 SPI _spi;
keithm01 0:2d3fcb6dabd4 47 DigitalOut _cs, _dc, _reset;
keithm01 0:2d3fcb6dabd4 48 };
keithm01 0:2d3fcb6dabd4 49
keithm01 0:2d3fcb6dabd4 50 #endif