Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1438 - 1
/*****************************************************************************
2
 *   Copyright (C) 2009-2010 Peter "woggle" Mack, mac@denich.net             *
3
 *                                                                           *
4
 *   see this fine thread on RCLine:                                         *
5
 *   http://www.rclineforum.de/forum/thread.php?threadid=226786              *
6
 *                                                                           *
7
 *   This program is free software; you can redistribute it and/or modify    *
8
 *   it under the terms of the GNU General Public License as published by    *
9
 *   the Free Software Foundation; either version 2 of the License.          *
10
 *                                                                           *
11
 *   This program is distributed in the hope that it will be useful,         *
12
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of          *
13
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
14
 *   GNU General Public License for more details.                            *
15
 *                                                                           *
16
 *   You should have received a copy of the GNU General Public License       *
17
 *   along with this program; if not, write to the                           *
18
 *   Free Software Foundation, Inc.,                                         *
19
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.               *
20
 *                                                                           *
21
 *****************************************************************************/
22
 
1521 - 23
 
1438 - 24
#include <avr/io.h>
25
#include <avr/interrupt.h>
26
#include <avr/pgmspace.h>
27
#include <util/delay.h>
28
 
29
#include "main.h"               // LEDs
30
#include "timer.h"      // Keys
31
#include "lcd.h"
32
#include "jeti.h"
33
#include "usart.h"
34
#define font8x8
35
 
36
uint8_t JetiBuffer[32]; // 32 characters
37
volatile uint8_t JetiBufferReady;
38
 
39
 
40
//*****************************************************************************
1521 - 41
//
1438 - 42
#if 0
43
ISR (USART_RXC_vect)
44
{
45
        uint8_t stat;
46
        uint8_t rh;
47
        uint8_t rl;
48
        static uint8_t jbp;
1521 - 49
 
1438 - 50
        stat = UCSRA;
51
        rh = UCSRB;
52
        rl = UDR;
1521 - 53
 
1438 - 54
        if (stat & ((1 << FE) | (1 << DOR0) | (1 << UPE)))
55
        {       // discard buffer and start new on any error
56
                JetiBufferReady = 0;
57
                jbp = 0;
58
                                                                                                                  //1234567890123456
59
                lcd_printpj_at (0, 3, PSTR(" Communication  "), 0);
60
                lcd_printpj_at (0, 4, PSTR("    Error       "), 0);
61
//              LED6_TOGGLE;
62
        }
63
        else if ((rh & (1 << RXB8)) == 0)
64
        {       // control
65
                if (rl == 0xfe)
66
                {       // start condition
67
                        JetiBufferReady = 0;
68
                        jbp = 0;
69
//                      LED1_ON;
70
                }
71
                else if (rl == 0xff)
72
                {       // stop condition
73
                        JetiBufferReady = 1;
74
//                      LED1_OFF;
75
                }
76
        }
77
        else
78
        {       // data
79
                if (jbp < 32)
80
                {
81
                        JetiBuffer[jbp++] = rl;
82
                }
83
        }
84
}
85
#endif
86
//*****************************************************************************
1521 - 87
//
1438 - 88
void JETI_Init (void)
89
{
90
        DDRD  &= ~(1 << DDD3);          // set TXD1 pin as input
91
        PORTD &= ~(1 << PORTD3);        // disable pullup on TXD1 pin
1521 - 92
 
1438 - 93
        // set clock divider
94
#undef BAUD
95
#define BAUD 9600
96
#include <util/setbaud.h>
97
        UBRRH = UBRRH_VALUE;
98
        UBRRL = UBRRL_VALUE;
1521 - 99
 
1438 - 100
#if USE_2X
101
        UCSR1A |= (1 << U2X1);  // enable double speed operation
102
#else
103
        UCSRA &= ~(1 << U2X);   // disable double speed operation
104
#endif
1521 - 105
 
1438 - 106
        // set 9O1
107
        UCSRC = (1 << UPM1) | (1 << UPM1) | (1 << UCSZ1) | (1 << UCSZ0);
108
        UCSRB = (1 << UCSZ2);
1521 - 109
 
1438 - 110
        // flush receive buffer
111
        while ( UCSRA & (1 << RXC) ) UDR;
112
}
113
 
114
//*****************************************************************************
115
// disable the txd pin of usart
116
void JETI_DisableTXD (void)
117
{
118
        UCSRB &= ~(1 << TXEN);  // disable TX}
119
}
120
 
121
//*****************************************************************************
122
// enable the txd pin of usart
123
void JETI_EnableTXD (void)
124
{
125
        UCSRB |=  (1 << TXEN);  // enable TX
126
}
127
 
128
 
129
//*****************************************************************************
1521 - 130
//
1438 - 131
void JETI_putw (uint16_t c)
132
{
133
        loop_until_bit_is_set(UCSRA, UDRE);
134
        UCSRB &= ~(1 << TXB8);
135
        if (c & 0x0100)
136
        {
137
                UCSRB |= (1 << TXB8);
138
        }
139
        UDR = c;
140
}
141
 
142
//*****************************************************************************
1521 - 143
//
1438 - 144
void JETI_putc (uint8_t c)
145
{
146
        loop_until_bit_is_set(UCSRA, UDRE);
147
        //      UCSRB &= ~(1 << TXB8);
148
        UCSRB |= (1 << TXB8);
149
        UDR = c;
150
}
151
 
152
//*****************************************************************************
1521 - 153
//
1438 - 154
void JETI_puts (char *s)
155
{
156
        while (*s)
157
        {
158
                JETI_putc (*s);
159
                s++;
160
        }
161
}
162
 
163
//*****************************************************************************
1521 - 164
//
1438 - 165
void JETI_puts_p (const char *s)
166
{
167
        while (pgm_read_byte(s))
168
        {
169
                JETI_putc (pgm_read_byte(s));
170
                s++;
171
        }
172
}
173
 
174
//*****************************************************************************
1521 - 175
//
1438 - 176
void JETI_put_start (void)
177
{
178
        loop_until_bit_is_set(UCSRA, UDRE);
179
        UCSRB &= ~(1 << TXB8);
180
        UDR = 0xFE;
181
}
182
 
183
//*****************************************************************************
1521 - 184
//
1438 - 185
void JETI_put_stop (void)
186
{
187
        loop_until_bit_is_set(UCSRA, UDRE);
188
        UCSRB &= ~(1 << TXB8);
189
        UDR = 0xFF;
190
}
191
 
192
//*****************************************************************************
1521 - 193
//
1438 - 194
void jeti (void)
195
{
196
        uint8_t key;
197
        uint8_t i;
198
 
199
        // enable Rx
200
        UCSRB |= (1 << RXEN);
201
        UCSRB |= (1 << RXCIE);
1521 - 202
 
1438 - 203
        lcd_cls ();
204
        lcd_printp_at (0, 0, PSTR("Jeti Box Display"), 0);
205
        lcd_printpns_at (0, 7, PSTR(" \x1a    \x1b      \x1c     \x1d"), 0);
1521 - 206
 
1438 - 207
#ifdef font8x8
208
        lcd_line(0, 21, 127, 21, 1);
209
        lcd_line(0, 22, 127, 22, 1);
210
        lcd_line(0, 40, 127, 40, 1);
211
        lcd_line(0, 41, 127, 41, 1);
212
#else
213
        lcd_rect(10, 22, 98, 18, 1);
214
#endif
1521 - 215
 
1438 - 216
        do
217
        {
218
                if (JetiBufferReady)
219
                {
220
                        JETI_EnableTXD();
221
//                      LED2_ON;
222
                        for (i = 0; i < 16; i++)
223
                        {
224
#ifdef font8x8
225
                                lcd_putc_jeti(i, 3, JetiBuffer[i], 0);
226
#else
227
                                lcd_putc (2 + i, 3, JetiBuffer[i], 0);
228
#endif
229
                        }
230
                        for (i = 0; i < 16; i++)
231
                        {
232
#ifdef font8x8
233
                                lcd_putc_jeti(i, 4, JetiBuffer[i + 16], 0);
234
#else
235
                                lcd_putc (2 + i, 4, JetiBuffer[i + 16], 0);
236
#endif
237
                        }
238
                        JetiBufferReady = 0;    // invalidate buffer
239
//                      LED2_OFF;
1521 - 240
 
1438 - 241
                        _delay_ms (1);  //
242
                                                                                                // Writing to the display takes aprox. 5.8 ms @ 7 MHz and 3.2 ms @ 20 MHz.
243
                                                                                                // With the additional 4 ms we had a 10 ms delay.
244
                                                                                                // 10 ms works perfect with the MUI30 and the MT125
245
                                                                                                // But not with the TU transceiver module.
1521 - 246
 
1438 - 247
                        key = get_key_short ((1 << KEY_MINUS) | (1 << KEY_PLUS) | (1 << KEY_ESC) | (1 << KEY_ENTER));
248
                        key = (key << 1) | (key >> 3);
249
                        key = (~key) & 0xf0;
1521 - 250
 
1438 - 251
                        JETI_putw((uint16_t) key);
252
                        _delay_ms (1);
253
                        JETI_DisableTXD();
254
                }
255
        }
256
        while (!get_key_long (1 << KEY_ESC));
257
        get_key_press(KEY_ALL);
258
 
259
        // disable Rx
260
        UCSRB &= ~(1 << RXCIE);
261
        UCSRB &= ~(1 << RXEN);
262
}