Library for Sure Electronics HT1632 based LED matrix displays. Supports multiple displays connected together.

Dependents:   HT1632MsgScroller SMS_LEDMatrixPrinter

Revision:
9:8a3c981babd9
Parent:
6:80f554fd77a0
Child:
10:af973a9c48b2
--- a/HT1632_LedMatrix.h	Sat Nov 24 21:58:03 2012 +0000
+++ b/HT1632_LedMatrix.h	Wed Nov 28 14:03:35 2012 +0000
@@ -45,10 +45,14 @@
 #ifndef _HT1632_LEDMATRIX_H
 #define _HT1632_LEDMATRIX_H
 
+#include <inttypes.h>
+
 // To include the graphic functions use the following. Comment out to exclude them 
 #define USE_GRAPHIC
 
-#include <inttypes.h>
+// Defines for display sizes
+#define HT1632_32x08  1 
+#define HT1632_24x16  2
 
 /*
  * commands written to the chip consist of a 3 bit "ID", followed by
@@ -79,53 +83,226 @@
 
 /** class HT1632_LedMatrix
 */
-class HT1632_LedMatrix  //: public Print
+class HT1632_LedMatrix
 {
 private:
-    /** Select a specific display
+    /** Select a specific display, numbers as 0 to 3
      *
      * @param chip number
      */
     void chipselect( uint8_t );
+    /** Deselect a specific display, numbers as 0 to 3
+     *
+     * @param chip number
+     */
     void chipfree( uint8_t );
+    
+    /** Write bits to HT1632 on pins HT1632_DATA, HT1632_WRCLK
+     * Chip is assumed to already be chip-selected
+     * Bits are shifted out from MSB to LSB, with the first bit sent
+     * being (bits & firstbit), shifted till firsbit is zero.
+     * @param bits
+     * @param firstbit
+     */ 
     void writebits( uint8_t, uint8_t );
+    
+    /** Write databits to HT1632 on pins HT1632_DATA, HT1632_WRCLK
+     * Chip is assumed to already be chip-selected
+     * Bits are shifted out from LSB to MSB
+     * @param bits
+     * @param count
+     */
     void writedatabits( uint8_t, uint8_t );
+    
+    /**  * Send a command to the ht1632 chip.
+     * A command consists of a 3-bit "CMD" ID, an 8bit command, and
+     * one "don't care bit".
+     *   Select 1 0 0 c7 c6 c5 c4 c3 c2 c1 c0 xx Free
+     * @param chipno the number of the chip/display to write command to
+     * @param command to send
+     */
     void sendcmd( uint8_t, uint8_t );
+    
+    /** Send a nibble (4 bits) of data to a particular memory location of the
+     * ht1632.  The command has 3 bit ID, 7 bits of address, and 4 bits of data.
+     *    Select 1 0 1 A6 A5 A4 A3 A2 A1 A0 D0 D1 D2 D3 Free
+     * Note that the address is sent MSB first, while the data is sent LSB first!
+     * This means that somewhere a bit reversal will have to be done to get
+     * zero-based addressing of words and dots within words.
+     * @param chipno
+     * @param address
+     * @param data
+     */
     void senddata( uint8_t, uint8_t, uint8_t );
+
+    /** Send a byte of data to a particular memory location of the
+     * ht1632.  The command has 3 bit ID, 7 bits of address, and 8 bits of data.
+     *    Select 1 0 1 A6 A5 A4 A3 A2 A1 A0 D0 D1 D2 D3 D4 D5 D6 D7 D8 Free
+     * Note that the address is sent MSB first, while the data is sent LSB first!
+     * This means that somewhere a bit reversal will have to be done to get
+     * zero-based addressing of words and dots within words.
+     * @param chipno
+     * @param address
+     * @param data
+     */
     void sendcol( uint8_t, uint8_t, uint8_t );
 
 public:
-    /** Default Constructor
+    /** Default Constructor for the display driver
      */
     HT1632_LedMatrix( );
 
-    // Init/Clear/position functions
-    void init( uint8_t, uint8_t );
-    void displayOff( void ) ;
-    void displayOn( void ) ;
+    /** Initialise the library with the display configuration
+     * @param Number of horizontal displays, max 4
+     * @param Number of vertical displays, max 4
+     * @param Type of displays being used, either 32x8 or 24x16
+     */
+    void init( uint8_t, uint8_t, uint8_t displayType = HT1632_32x08 );
+    
+    /** Turn off the display
+     */
+    void displayOff( void );
+    
+    /** Turn on the display
+     */
+    void displayOn( void );
+    
+    /** Clear the display, and the shadow memory, and the snapshot
+     * memory.  This uses the "write multiple words" capability of
+     * the chipset by writing all 96 words of memory without raising
+     * the chipselect signal.
+     */
     void clear(void);
+    
+    /** Set display brightness. Brighness is from 0 to 15
+     * @param brightness value, range x-y
+     */
     void setBrightness( unsigned char );
+    
+    /** Copy a character glyph from the font data structure to
+     * display memory, with its upper left at the given coordinate
+     * This is unoptimized and simply uses plot() to draw each dot.
+     * returns number of columns that didn't fit
+     * @param column
+     * @param row
+     * @param character to write
+     * @returns the number of columns that couldnt be displayed on current matrix
+     */
     uint8_t putChar( int, int, char );
+
+    /** Copy a character glyph from the font data structure to
+     * display memory, with its upper left at the given coordinate
+     * This is a wrapper for putChar that uses current cursor position
+     */
     void write( uint8_t );
+
+    /** Write a string at the position specified
+     * x and y start from 0 and count number of pixels, 2nd row on a 2 row display is y=8
+     * @param x position
+     * @param y position
+     * @param pointer to character data to display
+     */
     void putString( int, int, char* );
+    
+    /** Plot a point on the display, with the upper left hand corner
+     * being (0,0), and the lower right hand corner being (xMax-1, yMax-1).
+     * Note that Y increases going "downward" in contrast with most
+     * mathematical coordiate systems, but in common with many displays
+     * basic bounds checking used.
+     * @param column
+     * @param row
+     * @param point on or off
+     */
     void plot( int, int, char );
+    
+    /** Set cursor position
+     * @param x or column position, 0 is to left
+     * @param y or row position, 0 is at top
+     */
     void gotoXY(int , int);
+    
+    /** Return the current cursor position
+     * @param column pointer
+     * @param row pointer
+     */
     void getXY(int* , int*);
+
+    /** Return the maximum size of the display
+     * @param column pointer
+     * @param row pointer
+     */
     void getXYMax(int*, int*);
+    
+    /** Shift cursor X position a number of positions either left or right.
+     * @param increment, -1 for one position left, 1 for right
+     */
     void shiftCursorX(int );
+    
+    /** Create a custom character. 8 character slots are availabe.
+     * @param character number, 0 to 7
+     * @param array of character bit maps
+     */
     void setCustomChar( int, unsigned char[]);
+    
+    /** Create a custom character. 8 character slots are availabe.
+     * @param character number, 0 to 7
+     * @param array of character bit maps
+     * @param width of chaaracter in columns
+     */
     void setCustomChar( int, unsigned char[], uint8_t );
+    
+    /** Scroll row to the left
+     * @param number fo columns to scroll
+     * @param row number to scroll, used when displays are stacked vertically or when more than 8 high displays are used
+     */
     void scrollLeft(uint8_t, uint8_t);
+    
+    /** Write shaddow ram to display
+     */
     void putShadowRam();
+    
+    /** Write shadow ram to a specific dasipaly board
+     * @param chip or display number
+     */
     void putShadowRam(uint8_t);
     // Graphic functions
 #ifdef  USE_GRAPHIC
+
+    /** Draws a line between two points on the display
+     * @param start column
+     * @param start row
+     * @param end column
+     * @param end row
+     * @param point on or off, off to erase, on to draw
+     */
     void drawLine(unsigned char x1, unsigned char y1,
                   unsigned char x2, unsigned char y2, unsigned char c);
+
+    /** Draw a rectangle given to top left and bottom right points
+     * @param top left column
+     * @param top left row
+     * @param bottom right column
+     * @param bottom right row
+     * @param point on or off, off to erase, on to draw
+     */                  
     void drawRectangle(unsigned char x1, unsigned char y1,
                        unsigned char x2, unsigned char y2, unsigned char c);
+    /** Draw a filled rectangle given to top left and bottom right points
+     * @param top left column
+     * @param top left row
+     * @param bottom right column
+     * @param bottom right row
+     * @param point on or off, off to erase, on to draw
+     */                  
     void drawFilledRectangle(unsigned char x1, unsigned char y1,
                              unsigned char x2, unsigned char y2, unsigned char c);
+    /** Draw a circle using Bresenham's algorithm.
+     * Some small circles will look like squares!!
+     * @param centre column
+     * @param centre row
+     * @param radius
+     * @param point on or off, off to erase, on to draw
+     */
     void drawCircle(unsigned char xc, unsigned char yc,
                     unsigned char r, unsigned char c);
 #endif