MHVLib  20111227
An efficiency oriented runtime library for AVR microcontrollers
A:/eclipse/mhvlib/MHV_PWMMatrix.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 
00027 #ifndef MHV_PWMMATRIX_H_
00028 #define MHV_PWMMATRIX_H_
00029 
00030 #include <inttypes.h>
00031 #include <MHV_Display_Monochrome_Buffered.h>
00032 
00044 #define MHV_PWMMATRIX_CREATE(_mhvObjectName, _mhvRows, _mhvCols, _mhvTxElements, \
00045                 _mhvMatrixRowOn, _mhvMatrixRowOff, _mhvMatrixColOn, _mhvMatrixColOff) \
00046         uint8_t _mhvObjectName ## FrameBuffer[_mhvRows * _mhvCols]; \
00047         MHV_TX_BUFFER_CREATE(_mhvObjectName ## TX, _mhvTxElements); \
00048         MHV_PWMMatrix _mhvObjectName(_mhvRows, _mhvCols, _mhvObjectName ## FrameBuffer, _mhvObjectName ## TX, \
00049                         _mhvMatrixRowOn, _mhvMatrixRowOff, _mhvMatrixColOn, _mhvMatrixColOff);
00050 
00051 enum MHV_PWMMatrix_Mode {
00052         MHV_PWMMATRIX_MODE_AUTO,
00053         MHV_PWMMATRIX_MODE_ROWS,
00054         MHV_PWMMATRIX_MODE_COLS,
00055         MHV_PWMMATRIX_MODE_INDIVIDUAL
00056 };
00057 typedef enum MHV_PWMMatrix_Mode MHV_PWMMATRIX_MODE;
00058 
00059 class MHV_PWMMatrix : public MHV_Display_Monochrome_Buffered {
00060 private:
00061         uint16_t                                _currentRow;
00062         uint16_t                                _currentCol;
00063         uint8_t                                 _currentLevel;
00064         MHV_PWMMATRIX_MODE              _mode;
00065         void                                    (*_rowOn)(uint16_t row);
00066         void                                    (*_rowOff)(uint16_t row);
00067         void                                    (*_colOn)(uint16_t column);
00068         void                                    (*_colOff)(uint16_t column);
00069 
00070         void tickRow();
00071         void tickCol();
00072         void tickPixel();
00073 
00074 public:
00075         MHV_PWMMatrix(uint16_t rowCount, uint16_t colCount, uint8_t *frameBuffer, MHV_RingBuffer &txBuffers,
00076                 void (*rowOn)(uint16_t row),
00077                 void (*rowOff)(uint16_t row),
00078                 void (*colOn)(uint16_t column),
00079                 void (*colOff)(uint16_t column),
00080                 MHV_PWMMATRIX_MODE mode = MHV_PWMMATRIX_MODE_AUTO);
00081         void tick();
00082 };
00083 
00084 #endif /* MHV_PWMMATRIX_H_ */