MHVLib  20111011
An efficiency oriented runtime library for AVR microcontrollers
A:/eclipse/mhvlib/MHV_Display_Holtek_HT1632.h
Go to the documentation of this file.
00001 /* Copyright (c) 2011, Make, Hack, Void Inc
00002  * All rights reserved.
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *  * Redistributions of source code must retain the above copyright
00007  *    notice, this list of conditions and the following disclaimer.
00008  *  * Redistributions in binary form must reproduce the above copyright
00009  *    notice, this list of conditions and the following disclaimer in the
00010  *    documentation and/or other materials provided with the distribution.
00011  *  * Neither the name of the Make, Hack, Void nor the
00012  *    names of its contributors may be used to endorse or promote products
00013  *    derived from this software without specific prior written permission.
00014  *
00015  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
00016  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00017  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00018  * DISCLAIMED. IN NO EVENT SHALL MAKE, HACK, VOID BE LIABLE FOR ANY
00019  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00020  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00021  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00022  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00023  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00024  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00025  */
00026 #ifndef MHV_DISPLAY_HOLTEK_HT1632_H_
00027 #define MHV_DISPLAY_HOLTEK_HT1632_H_
00028 
00029 #include <MHV_Display_Monochrome.h>
00030 
00031 #define MHV_HT1632_BRIGHTNESS_MIN       0
00032 #define MHV_HT1632_BRIGHTNESS_MED       7
00033 #define MHV_HT1632_BRIGHTNESS_MAX       15
00034 
00035 enum mhv_ht1632_command {
00036         MHV_HT1632_COMMAND_READ         =       0b110,
00037         MHV_HT1632_COMMAND_WRITE        =       0b101,
00038         MHV_HT1632_COMMAND_CMD          =       0b100
00039 };
00040 typedef enum mhv_ht1632_command MHV_HT1632_COMMAND;
00041 
00042 enum mhv_ht1632_mode {
00043         MHV_HT1632_NMOS_32x8    =       0b00,
00044         MHV_HT1632_NMOS_24x16   =       0b01,
00045         MHV_HT1632_PMOS_32x8    =       0b10,
00046         MHV_HT1632_PMOS_24x16   =       0b11
00047 };
00048 typedef mhv_ht1632_mode MHV_HT1632_MODE;
00049 
00050 class MHV_Display_Holtek_HT1632 : public MHV_Display_Monochrome
00051 {
00052   private:
00053         volatile uint8_t        *_port;
00054 // Masks on the port
00055         uint8_t                         _data;
00056         uint8_t                         _write;
00057 // The bits for the pins (used for the SHIFTER macros)
00058         uint8_t                         _dataPin;
00059         uint8_t                         _writePin;
00060         void                            (*_csCallback)(uint8_t x, uint8_t y, bool active);
00061         MHV_HT1632_MODE         _mode;
00062         uint8_t                         _arrayX;
00063         uint8_t                         _arrayY;
00064         uint8_t                         _displayX;
00065         uint8_t                         _displayY;
00066         uint8_t                         _displayBytes;
00067         uint8_t                         *_frameBuffer;
00068 
00069     void writeData(uint8_t data, uint8_t length);
00070     void sendCommand(uint8_t moduleX, uint8_t moduleY, MHV_HT1632_COMMAND command);
00071     void commandComplete(uint8_t moduleX, uint8_t moduleY);
00072     void outputStart(uint8_t moduleX, uint8_t moduleY);
00073     void master(uint8_t moduleX, uint8_t moduleY);
00074     void slave(uint8_t moduleX, uint8_t moduleY);
00075     void brightness(uint8_t moduleX, uint8_t moduleY, uint8_t brightness);
00076     void poweroff(uint8_t moduleX, uint8_t moduleY);
00077     void poweron(uint8_t moduleX, uint8_t moduleY);
00078     void setMode(uint8_t moduleX, uint8_t moduleY, MHV_HT1632_MODE mode);
00079 
00080   public:
00081     MHV_Display_Holtek_HT1632(
00082                 volatile uint8_t *dataDir, volatile uint8_t *dataOut, volatile uint8_t *dataIn,
00083                         uint8_t dataPin, int8_t dataPinchangeInterrupt,
00084                 volatile uint8_t *writeDir, volatile uint8_t *writeOut, volatile uint8_t *writeIn,
00085                                 uint8_t writePin, int8_t writePinchangeInterrupt,
00086                         MHV_HT1632_MODE mode,
00087                         uint8_t arrayX, uint8_t arrayY,
00088                         void (*csCallback)(uint8_t x, uint8_t y, bool active),
00089                         uint8_t *frameBuffer, MHV_RingBuffer *txBuffers);
00090     void brightness(uint8_t brightness);
00091     void poweroff();
00092     void poweron();
00093     void flush();
00094 
00095 // Implements MHV_Display_Monochrome
00096         void setPixel(uint16_t row, uint16_t col, uint8_t value);
00097         uint8_t getPixel(uint16_t row, uint16_t col);
00098 
00099 };
00100 
00101 #endif /* MHV_DISPLAY_HOLTEK_HT1632_H_ */