aboutsummaryrefslogtreecommitdiff
path: root/Arduino/Libraies/AS1107/AS1107.h
blob: 80b01da5e0e78034a2651190f4cb39e40ea619ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
  AS1107.h - Library for interfacing the AS1107 LED Driver Chip
  Created by Stephan Elsner 2011
  version 0.82

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with this library; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#ifndef AS1107_h
#define AS1107_h

#include "WProgram.h"
#include <avr/pgmspace.h>

#define ON 1
#define OFF 0


// --------------------------------------------------------------------------------------------------------------------------
class AS1107
{
  public:
    AS1107(byte cspin, byte clkpin, byte datapin);
    void WriteRegister2(byte chip, byte reg, byte data);
    void WriteRegister(byte chip, byte reg, byte data);
    void WriteColumn( byte column, byte data);
    void Init(byte *buffer);
    void SetBuffer(byte *buffer);
    void SetLed(int x, int y, byte value);
    void Clear();
    void Update();
    void ShiftLeft();
    void ShiftRight();
    void ShiftUp();
    void ShiftDown();
    void ShiftUp(byte from, byte to);
    void ShiftDown(byte from, byte to);
    void DrawLine(int x0, int y0, int x1, int y1);
    void DrawBox(int x0, int y0, int x1, int y1);
    void DrawEllipse(int xm, int ym, int a, int b);
    void SetScrollText(char *string, int charspacing);
    void DrawText (int x, int y, char *str);
    byte DrawChar (int x, int y, char thechar);

    boolean TextScroll();

    // ***************************************
    // Set your module configuration here
    // ***************************************
    static const byte Maxx=8;      // maximum x - Pixels of the Module
    static const byte Maxy=19;         // maximum y - Pixels of the Module
    static const byte HighestCtrlNum=5; // Number of Matrix modules -1 (0 = single module)

  private:
    byte _cspin;
    byte _clkpin;
    byte _datapin;
    byte *_buffer;                    // pointer to current screen buffer

    static const byte _repcharoff;    // Offset of the replacement for unknown characers
    int  _charoffset[82];             // Start position in Array
    char *_outputstring;              // pointer to start of output string
    char *_curchr;                    // pointer to current char of output String
    int _fontidx;                     // current byte in font to display
    int _colct;                       // to count the columns of character to display
    byte _charspacing;                // the coulumns of space between characters
    boolean _hastext;

    void SetLedInternal(byte x, byte y, byte value);
    boolean NextCharacter();
    void CalculateCharOffsets();
    byte GetInternalCharCode(byte thechar);
};

// --------------------------------------------------------------------------------------------------------------------------
// AS1107-Register
class Registers
{
  public:
    static const byte NoOp   = 0x00;
    static const byte Digit0 = 0x01;
    static const byte Digit1 = 0x02;
    static const byte Digit2 = 0x03;
    static const byte Digit3 = 0x04;
    static const byte Digit4 = 0x05;
    static const byte Digit5 = 0x06;
    static const byte Digit6 = 0x07;
    static const byte Digit7 = 0x08;
    static const byte DecodeMode = 0x09;
    static const byte IntensityControl = 0x0A;
    static const byte ScanLimit = 0x0B;
    static const byte Shutdown = 0x0C;
    static const byte Feature = 0x0E;
    static const byte DisplayTest = 0x0F;
};

// --------------------------------------------------------------------------------------------------------------------------
// Values to write to the Shutdown Register
class ShutdownModes
{
  public:
    static const byte ShutdownResetFeature = 0x00;  // Shutdown Mode, Reset Feature Register to Default Settings
    static const byte Shutdown             = 0x80;  // Shutdown Mode, leaving Feature Register unchanged
    static const byte NormalResetFeature   = 0x01;  // Normal Mode, Reset Feature
    static const byte Normal               = 0x81;  // Normal Mode, Feature unchanged
};

// Bits in the feature-Register, desired Settings must be OR'ed together
class Features
{
  public:
    static const byte ExternalClock        = 0x01;  // ExternalClock active
    static const byte ResetRegisters       = 0x02;  // Resets all control registers except the Feature Register.
    static const byte HexDecoding          = 0x04;  // 1 = Enable HEX decoding, 0 = Enable Code-B decoding
    static const byte SPIEnable            = 0x08;  // Enables the SPI-compatible interface.(AS1106 only).
    static const byte BlinkEnable          = 0x10;  // Enables blinking.
    static const byte BlinkSlow            = 0x20;  // Sets blink with low frequency
                                                    // (with the internal oscillator enabled)

    static const byte BlinkSync            = 0x40;  // Synchronizes blinking on the rising edge of pin LOAD/CSN.
                                                    // The multiplex and blink timing counter is cleared on the
                                                    // rising edge of pin LOAD/CSN. By setting this bit in
                                                    // multiple AS1106/AS1107 devices, the blink timing can
                                                    // be synchronized across all the devices.

    static const byte BlinkStartWithOn     = 0x80;  // Start Blinking with display enabled phase.
                                                    // When bit D4 (blink_en) is set, bit D7
                                                    // determines how blinking starts.
                                                    // 0 = Blinking starts with the display turned off.
                                                    // 1 = Blinking starts with the display turned on.
};

#endif