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:24:54 2016 +0000
Revision:
3:e8bbba5c43ba
Parent:
2:ef14c6dd6b93
Child:
4:9c0b59439725
Small fix for skipping image data header

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