Subversion Repositories HomeAutomation

Rev

Rev 1794 | Rev 1798 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 1794 Rev 1796
Line 31... Line 31...
31
 
31
 
32
#define OUTPUT  0
32
#define OUTPUT  0
33
#define INPUT   1
33
#define INPUT   1
34
 
34
 
35
volatile GrLcdStateType GrLcdState;
35
volatile GrLcdStateType GrLcdState;
-
 
36
uint8_t dotmatrixFramebuf[8][4];
-
 
37
uint8_t dotmatrixRowCounter=0;
-
 
38
uint16_t dotmatrixBrightness=0;
36
 
39
 
-
 
40
/* Write a byte on SPI */
37
void dotmatrixSetControls(uint8_t RS, uint8_t RW){
41
void dotmatrixSPIWrite(uint8_t data) {
-
 
42
    uint8_t dummy = 0;
38
//  if(RS) {gpio_set_pin(LCD_CONTROL_RS);} else {gpio_clr_pin(LCD_CONTROL_RS);}
43
    /* Wait for empty transmit buffer */
39
//  if(RW) {gpio_set_pin(LCD_CONTROL_RW);} else {gpio_clr_pin(LCD_CONTROL_RW);}
44
    while ( !( UCSR0A & (1<<UDRE0)) );
-
 
45
    // write data
-
 
46
    dummy = UDR0;
-
 
47
    UDR0 = data;
-
 
48
    waitspi();
40
}
49
}
41
 
50
 
42
void dotmatrixSetData(uint8_t Data){
-
 
43
/*  if(Data&0x01) {gpio_set_pin(LCD_DATA_DB0);} else {gpio_clr_pin(LCD_DATA_DB0);}
-
 
44
    if(Data&0x02) {gpio_set_pin(LCD_DATA_DB1);} else {gpio_clr_pin(LCD_DATA_DB1);}
-
 
45
    if(Data&0x04) {gpio_set_pin(LCD_DATA_DB2);} else {gpio_clr_pin(LCD_DATA_DB2);}
-
 
46
    if(Data&0x08) {gpio_set_pin(LCD_DATA_DB3);} else {gpio_clr_pin(LCD_DATA_DB3);}
-
 
47
    if(Data&0x10) {gpio_set_pin(LCD_DATA_DB4);} else {gpio_clr_pin(LCD_DATA_DB4);}
-
 
48
    if(Data&0x20) {gpio_set_pin(LCD_DATA_DB5);} else {gpio_clr_pin(LCD_DATA_DB5);}
-
 
49
    if(Data&0x40) {gpio_set_pin(LCD_DATA_DB6);} else {gpio_clr_pin(LCD_DATA_DB6);}
-
 
50
    if(Data&0x80) {gpio_set_pin(LCD_DATA_DB7);} else {gpio_clr_pin(LCD_DATA_DB7);}*/
-
 
51
}
-
 
52
uint8_t dotmatrixGetData(void){
-
 
53
    uint8_t input = 0;
-
 
54
/*  if (gpio_get_state(LCD_DATA_DB0)) {input += 1;}
-
 
55
    if (gpio_get_state(LCD_DATA_DB1)) {input += 2;}
-
 
56
    if (gpio_get_state(LCD_DATA_DB2)) {input += 4;}
-
 
57
    if (gpio_get_state(LCD_DATA_DB3)) {input += 8;}
-
 
58
    if (gpio_get_state(LCD_DATA_DB4)) {input += 16;}
-
 
59
    if (gpio_get_state(LCD_DATA_DB5)) {input += 32;}
-
 
60
    if (gpio_get_state(LCD_DATA_DB6)) {input += 64;}
-
 
61
    if (gpio_get_state(LCD_DATA_DB7)) {input += 128;}*/
-
 
62
    return input;
-
 
63
}
-
 
64
 
-
 
65
void dotmatrixDisable(){
-
 
66
//  gpio_clr_pin(LCD_CONTROL_E);
-
 
67
}
-
 
68
 
-
 
69
void dotmatrixDelay(){
-
 
70
//  delay_us(2);
-
 
71
}
-
 
72
 
-
 
73
void dotmatrixEnable(){
-
 
74
/*  dotmatrixDelay();
-
 
75
    gpio_set_pin(LCD_CONTROL_E);
-
 
76
    dotmatrixDelay();
-
 
77
    dotmatrixDisable();
-
 
78
    dotmatrixDelay();*/
-
 
79
}
-
 
80
 
-
 
81
void dotmatrixSetDirection(uint8_t dir){
-
 
82
/*  if (dir == OUTPUT){
-
 
83
    gpio_set_out(LCD_DATA_DB0);
-
 
84
    gpio_set_out(LCD_DATA_DB1);
-
 
85
    gpio_set_out(LCD_DATA_DB2);
-
 
86
    gpio_set_out(LCD_DATA_DB3);
-
 
87
    gpio_set_out(LCD_DATA_DB4);
-
 
88
    gpio_set_out(LCD_DATA_DB5);
-
 
89
    gpio_set_out(LCD_DATA_DB6);
-
 
90
    gpio_set_out(LCD_DATA_DB7);
-
 
91
  }else if (dir == INPUT){
-
 
92
    gpio_set_in(LCD_DATA_DB0);
-
 
93
    gpio_set_in(LCD_DATA_DB1);
-
 
94
    gpio_set_in(LCD_DATA_DB2);
-
 
95
    gpio_set_in(LCD_DATA_DB3);
-
 
96
    gpio_set_in(LCD_DATA_DB4);
-
 
97
    gpio_set_in(LCD_DATA_DB5);
-
 
98
    gpio_set_in(LCD_DATA_DB6);
-
 
99
    gpio_set_in(LCD_DATA_DB7);
-
 
100
  }*/
-
 
101
}
-
 
102
void dotmatrixSetColor(uint8_t color){
51
void dotmatrixSetColor(uint8_t color){
103
  GrLcdState.color=color;
52
  GrLcdState.color=color;
104
}
53
}
105
uint8_t dotmatrixGetColor(void){
54
uint8_t dotmatrixGetColor(void){
106
  return GrLcdState.color;
55
  return GrLcdState.color;
107
}
56
}
108
void dotmatrixWriteData(uint8_t data, uint8_t color){
57
void dotmatrixWriteData(uint8_t data, uint8_t color){
109
/*  dotmatrixSetControls(1,0);
58
/*  dotmatrixSetControls(1,0);
110
    if (color == GLCD_COLOR_CLEAR)
59
    if (color == GLCD_COLOR_CLEAR)
111
      data = ~data;
60
      data = ~data;
112
    if (GrLcdState.color == GLCD_COLOR_BLACK)
61
    if (GrLcdState.color == GLCD_COLOR_BLACK)
113
      dotmatrixSetData(data);
62
      dotmatrixSetData(data);
114
    else
63
    else
115
      dotmatrixSetData(~data);
64
      dotmatrixSetData(~data);
116
    dotmatrixEnable();
65
    dotmatrixEnable();
117
    GrLcdState.lcdXAddr++;
66
    GrLcdState.lcdXAddr++;
118
 
67
 
119
    if (GrLcdState.lcdXAddr == 64 ){
68
    if (GrLcdState.lcdXAddr == 64 ){
120
        dotmatrixSetXY(GrLcdState.lcdXAddr,GrLcdState.lcdYAddr);
69
        dotmatrixSetXY(GrLcdState.lcdXAddr,GrLcdState.lcdYAddr);
121
    }
70
    }
122
#if KS0108_WIDTH > 128
71
#if KS0108_WIDTH > 128
123
else if (GrLcdState.lcdXAddr == 128 ){
72
else if (GrLcdState.lcdXAddr == 128 ){
124
        dotmatrixSetXY(GrLcdState.lcdXAddr,GrLcdState.lcdYAddr);
73
        dotmatrixSetXY(GrLcdState.lcdXAddr,GrLcdState.lcdYAddr);
Line 129... Line 78...
129
    }*/
78
    }*/
130
}
79
}
131
void dotmatrixWriteDataTransparent(uint8_t inputdata, uint8_t color){
80
void dotmatrixWriteDataTransparent(uint8_t inputdata, uint8_t color){
132
/*  uint8_t data = 0;
81
/*  uint8_t data = 0;
133
    dotmatrixSetDirection(INPUT);
82
    dotmatrixSetDirection(INPUT);
134
    dotmatrixSetControls(1,1);
83
    dotmatrixSetControls(1,1);
135
    dotmatrixEnable();  //dummy read
84
    dotmatrixEnable();  //dummy read
136
    dotmatrixDelay();
85
    dotmatrixDelay();
137
    gpio_set_pin(LCD_CONTROL_E);
86
    gpio_set_pin(LCD_CONTROL_E);
138
    dotmatrixDelay();
87
    dotmatrixDelay();
139
    if (GrLcdState.color == GLCD_COLOR_BLACK)
88
    if (GrLcdState.color == GLCD_COLOR_BLACK)
140
      data = dotmatrixGetData();
89
      data = dotmatrixGetData();
141
    else
90
    else
142
      data = ~dotmatrixGetData();
91
      data = ~dotmatrixGetData();
Line 150... Line 99...
150
      data = data&(~inputdata);
99
      data = data&(~inputdata);
151
    else
100
    else
152
      data = data|inputdata;
101
      data = data|inputdata;
153
    if (GrLcdState.color == GLCD_COLOR_BLACK)
102
    if (GrLcdState.color == GLCD_COLOR_BLACK)
154
      dotmatrixSetData(data);
103
      dotmatrixSetData(data);
155
    else
104
    else
156
      dotmatrixSetData(~data);
105
      dotmatrixSetData(~data);
157
    dotmatrixEnable();
106
    dotmatrixEnable();
158
    GrLcdState.lcdXAddr++;
107
    GrLcdState.lcdXAddr++;
159
 
108
 
160
 
109
 
161
    if (GrLcdState.lcdXAddr == 64 ){
110
    if (GrLcdState.lcdXAddr == 64 ){
162
        dotmatrixSetXY(GrLcdState.lcdXAddr,GrLcdState.lcdYAddr);
111
        dotmatrixSetXY(GrLcdState.lcdXAddr,GrLcdState.lcdYAddr);
163
    }
112
    }
164
#if KS0108_WIDTH > 128
113
#if KS0108_WIDTH > 128
165
    else if (GrLcdState.lcdXAddr == 128 ){
114
    else if (GrLcdState.lcdXAddr == 128 ){
166
        dotmatrixSetXY(GrLcdState.lcdXAddr,GrLcdState.lcdYAddr);
115
        dotmatrixSetXY(GrLcdState.lcdXAddr,GrLcdState.lcdYAddr);
167
    }
116
    }
168
#endif
117
#endif
169
    if (GrLcdState.lcdXAddr > KS0108_WIDTH ){
118
    if (GrLcdState.lcdXAddr > KS0108_WIDTH ){
170
        dotmatrixSetXY(0,GrLcdState.lcdYAddr+8);
119
        dotmatrixSetXY(0,GrLcdState.lcdYAddr+8);
171
    }*/
120
    }*/
172
}
121
}
173
 
122
 
174
uint8_t dotmatrixReadData(void){
123
uint8_t dotmatrixReadData(void){
175
    uint8_t data = 0;
124
    uint8_t data = 0;
176
/*  dotmatrixSetDirection(INPUT);
125
/*  dotmatrixSetDirection(INPUT);
177
    dotmatrixSetControls(1,1);
126
    dotmatrixSetControls(1,1);
178
    dotmatrixEnable();  //dummy read
127
    dotmatrixEnable();  //dummy read
Line 189... Line 138...
189
    dotmatrixSetDirection(OUTPUT);
138
    dotmatrixSetDirection(OUTPUT);
190
    dotmatrixSetXY(GrLcdState.lcdXAddr, GrLcdState.lcdYAddr);*/
139
    dotmatrixSetXY(GrLcdState.lcdXAddr, GrLcdState.lcdYAddr);*/
191
    return data;
140
    return data;
192
}
141
}
193
 
142
 
-
 
143
/* Callback run periodically to manage rows.
-
 
144
   For each time callback is run, the next row is enabled and the last disabled
-
 
145
 */
194
void dotmatrixRefresh()
146
void dotmatrixRefresh()
195
{
147
{
-
 
148
    /* Increase row counter */
-
 
149
    if (dotmatrixRowCounter++ == 8) {dotmatrixRowCounter = 0;}
-
 
150
 
-
 
151
    /* Disable all rows */
-
 
152
    gpio_clr_pin(dotmatrixROW_IO1);
-
 
153
    gpio_clr_pin(dotmatrixROW_IO2);
-
 
154
    gpio_clr_pin(dotmatrixROW_IO3);
-
 
155
    gpio_clr_pin(dotmatrixROW_IO4);
-
 
156
    gpio_clr_pin(dotmatrixROW_IO5);
-
 
157
    gpio_clr_pin(dotmatrixROW_IO6);
-
 
158
    gpio_clr_pin(dotmatrixROW_IO7);
-
 
159
    gpio_clr_pin(dotmatrixROW_IO8);
-
 
160
 
-
 
161
    /* Write one column of frame buffer to shift registers */
-
 
162
    dotmatrixSPIWrite(dotmatrixFramebuf[7-dotmatrixRowCounter][3]);
-
 
163
    dotmatrixSPIWrite(dotmatrixFramebuf[7-dotmatrixRowCounter][2]);
-
 
164
    dotmatrixSPIWrite(dotmatrixFramebuf[7-dotmatrixRowCounter][1]);
-
 
165
    dotmatrixSPIWrite(dotmatrixFramebuf[7-dotmatrixRowCounter][0]);
-
 
166
    /* Add more here to support 8-module panels */
-
 
167
 
-
 
168
    /* Toggle shift register latch */
-
 
169
    gpio_clr_pin(dotmatrixLATCHCLOCK_IO);
-
 
170
    gpio_set_pin(dotmatrixLATCHCLOCK_IO);
-
 
171
 
-
 
172
    /* Enable one row */
-
 
173
    switch (dotmatrixRowCounter)
-
 
174
    {
-
 
175
        case 0:
-
 
176
            gpio_set_pin(dotmatrixROW_IO1);
-
 
177
            break;
-
 
178
        case 1:
-
 
179
            gpio_set_pin(dotmatrixROW_IO2);
-
 
180
            break;
-
 
181
        case 2:
-
 
182
            gpio_set_pin(dotmatrixROW_IO3);
-
 
183
            break;
-
 
184
        case 3:
-
 
185
            gpio_set_pin(dotmatrixROW_IO4);
-
 
186
            break;
-
 
187
        case 4:
-
 
188
            gpio_set_pin(dotmatrixROW_IO5);
-
 
189
            break;
-
 
190
        case 5:
-
 
191
            gpio_set_pin(dotmatrixROW_IO6);
-
 
192
            break;
-
 
193
        case 6:
-
 
194
            gpio_set_pin(dotmatrixROW_IO7);
-
 
195
            break;
-
 
196
        case 7:
-
 
197
            gpio_set_pin(dotmatrixROW_IO8);
-
 
198
            break;
-
 
199
           
-
 
200
        default:
-
 
201
            break;
-
 
202
    }
-
 
203
}
-
 
204
 
-
 
205
void dotmatrixInit(){
-
 
206
    /* Set up row driver IO as low output */
-
 
207
    gpio_clr_pin(dotmatrixROW_IO1);
-
 
208
    gpio_set_out(dotmatrixROW_IO1);
-
 
209
    gpio_clr_pin(dotmatrixROW_IO2);
-
 
210
    gpio_set_out(dotmatrixROW_IO2);
-
 
211
    gpio_clr_pin(dotmatrixROW_IO3);
-
 
212
    gpio_set_out(dotmatrixROW_IO3);
-
 
213
    gpio_clr_pin(dotmatrixROW_IO4);
-
 
214
    gpio_set_out(dotmatrixROW_IO4);
-
 
215
    gpio_clr_pin(dotmatrixROW_IO5);
-
 
216
    gpio_set_out(dotmatrixROW_IO5);
-
 
217
    gpio_clr_pin(dotmatrixROW_IO6);
-
 
218
    gpio_set_out(dotmatrixROW_IO6);
-
 
219
    gpio_clr_pin(dotmatrixROW_IO7);
-
 
220
    gpio_set_out(dotmatrixROW_IO7);
-
 
221
    gpio_clr_pin(dotmatrixROW_IO8);
-
 
222
    gpio_set_out(dotmatrixROW_IO8);
-
 
223
 
-
 
224
    /* Set up PWM controlling brightness */
-
 
225
//  TCCR0A |= (1<<COM0B1)|(1<<WGM01)|(1<<WGM00);
-
 
226
//  TCCR0B |= (1<<CS00);
-
 
227
//  OCR0B = 0xff-act_DotMatrix_INITIAL_BRIGHTNESS;
-
 
228
//  DDRD |= (1<<PD5);
-
 
229
 
-
 
230
    /* Set up output latch clock */
-
 
231
    gpio_clr_pin(dotmatrixLATCHCLOCK_IO);
-
 
232
    gpio_set_out(dotmatrixLATCHCLOCK_IO);
-
 
233
 
-
 
234
    /* Initialize USART in SPI-mode */
-
 
235
    UBRR0 = 0;
-
 
236
    USART_SPI_XCK_DDR |= (1<<USART_SPI_XCK); // xck (sck) output
-
 
237
    UCSR0C = (1<<UMSEL01)|(1<<UMSEL00)|(0<<UCPHA0)|(0<<UCPOL0);
-
 
238
    UCSR0B = (1<<RXEN0)|(1<<TXEN0);
-
 
239
    UBRR0 = 0;
196
 
240
 
197
}
241
    dotmatrixClear();
198
 
242
   
199
void dotmatrixInit(){
-
 
200
/*  gpio_set_out(LCD_CONTROL_RS);
243
/*  gpio_set_out(LCD_CONTROL_RS);
201
    gpio_set_out(LCD_CONTROL_RW);
244
    gpio_set_out(LCD_CONTROL_RW);
202
    gpio_set_out(LCD_CONTROL_E);
245
    gpio_set_out(LCD_CONTROL_E);
203
    gpio_set_out(LCD_CONTROL_CS1);
246
    gpio_set_out(LCD_CONTROL_CS1);
204
    gpio_set_out(LCD_CONTROL_CS2);
247
    gpio_set_out(LCD_CONTROL_CS2);
205
 
248
 
206
    dotmatrixSetDirection(OUTPUT);
249
    dotmatrixSetDirection(OUTPUT);
207
    GrLcdState.color = GLCD_COLOR_WHITE;
250
    GrLcdState.color = GLCD_COLOR_WHITE;
208
#if KS0108_INVERT_CS == 1
251
#if KS0108_INVERT_CS == 1
209
    gpio_clr_pin(LCD_CONTROL_CS1);
252
    gpio_clr_pin(LCD_CONTROL_CS1);
210
    gpio_clr_pin(LCD_CONTROL_CS2);
253
    gpio_clr_pin(LCD_CONTROL_CS2);
211
#else
254
#else
212
    gpio_set_pin(LCD_CONTROL_CS1);
255
    gpio_set_pin(LCD_CONTROL_CS1);
213
    gpio_set_pin(LCD_CONTROL_CS2);
256
    gpio_set_pin(LCD_CONTROL_CS2);
214
#endif
257
#endif
215
    dotmatrixDisable();
258
    dotmatrixDisable();
216
    dotmatrixDelay();
-
 
217
    //set display on
-
 
218
    dotmatrixSetControls(0,0);
-
 
219
    dotmatrixSetData(0x3F);
-
 
220
    dotmatrixEnable();
-
 
221
 
-
 
222
    //set startaddress of the first row (set to row 0)
-
 
223
    dotmatrixSetControls(0,0);
-
 
224
    dotmatrixSetData(0xc0);
-
 
225
    dotmatrixEnable();
-
 
226
    dotmatrixClear();*/
-
 
227
}
-
 
228
 
-
 
229
void dotmatrixClear(){
-
 
230
/*
-
 
231
#if KS0108_INVERT_CS == 1
-
 
232
    gpio_clr_pin(LCD_CONTROL_CS1);
-
 
233
    gpio_clr_pin(LCD_CONTROL_CS2);
-
 
234
#else
-
 
235
    gpio_set_pin(LCD_CONTROL_CS1);
-
 
236
    gpio_set_pin(LCD_CONTROL_CS2);
-
 
237
#endif
-
 
238
    dotmatrixEnable();
-
 
239
    dotmatrixDelay();
259
    dotmatrixDelay();
-
 
260
    //set display on
240
    dotmatrixDisable();
261
    dotmatrixSetControls(0,0);
241
 
-
 
242
    uint8_t i;
262
    dotmatrixSetData(0x3F);
243
    uint8_t j;
263
    dotmatrixEnable();
244
 
264
 
245
    for(j = 0; j < 8; j++){
265
    //set startaddress of the first row (set to row 0)
246
        dotmatrixSetControls(0,0);
266
    dotmatrixSetControls(0,0);
247
        dotmatrixSetData(0xB8 + j);
267
    dotmatrixSetData(0xc0);
248
        dotmatrixEnable();
268
    dotmatrixEnable();
-
 
269
    dotmatrixClear();*/
-
 
270
}
249
 
271
 
250
        dotmatrixSetControls(0,0);
272
void dotmatrixClear(){
251
        dotmatrixSetData(0x40);
273
    /* Clear buffer memory */
252
        dotmatrixEnable();
-
 
253
        for (i = 0; i < 64; i++){
274
    for (uint8_t i=0; i<8; i++)
254
            dotmatrixSetControls(1,0);
-
 
255
            if (GrLcdState.color == GLCD_COLOR_BLACK)
-
 
-
 
275
    {
256
              dotmatrixSetData(0x00);
276
        for (uint8_t j=0; j<4; j++)
257
            else
277
        {
258
              dotmatrixSetData(0xff);
278
            dotmatrixFramebuf[i][j] = dotmatrixINITIAL_ROW;
259
            dotmatrixEnable();
-
 
260
        }
279
        }
261
    }
280
    }
262
*/
-
 
263
}
281
}
264
 
282
 
265
void dotmatrixSetXY(uint8_t x, uint8_t y){
283
void dotmatrixSetXY(uint8_t x, uint8_t y){
266
/*  GrLcdState.lcdXAddr = x;
284
/*  GrLcdState.lcdXAddr = x;
267
    GrLcdState.lcdYAddr = y;
285
    GrLcdState.lcdYAddr = y;