0,0 → 1,261 |
/***************************************************************************** |
* Copyright (C) 2009-2010 Peter "woggle" Mack, mac@denich.net * |
* * |
* see this fine thread on RCLine: * |
* http://www.rclineforum.de/forum/thread.php?threadid=226786 * |
* * |
* This program is free software; you can redistribute it and/or modify * |
* it under the terms of the GNU General Public License as published by * |
* the Free Software Foundation; either version 2 of the License. * |
* * |
* This program 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 General Public License for more details. * |
* * |
* You should have received a copy of the GNU General Public License * |
* along with this program; if not, write to the * |
* Free Software Foundation, Inc., * |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
* * |
*****************************************************************************/ |
|
#include <avr/io.h> |
#include <avr/interrupt.h> |
#include <avr/pgmspace.h> |
#include <util/delay.h> |
|
#include "main.h" // LEDs |
#include "timer.h" // Keys |
#include "lcd.h" |
#include "jeti.h" |
#include "usart.h" |
#define font8x8 |
|
uint8_t JetiBuffer[32]; // 32 characters |
volatile uint8_t JetiBufferReady; |
|
|
//***************************************************************************** |
// |
#if 0 |
ISR (USART_RXC_vect) |
{ |
uint8_t stat; |
uint8_t rh; |
uint8_t rl; |
static uint8_t jbp; |
|
stat = UCSRA; |
rh = UCSRB; |
rl = UDR; |
|
if (stat & ((1 << FE) | (1 << DOR0) | (1 << UPE))) |
{ // discard buffer and start new on any error |
JetiBufferReady = 0; |
jbp = 0; |
//1234567890123456 |
lcd_printpj_at (0, 3, PSTR(" Communication "), 0); |
lcd_printpj_at (0, 4, PSTR(" Error "), 0); |
// LED6_TOGGLE; |
} |
else if ((rh & (1 << RXB8)) == 0) |
{ // control |
if (rl == 0xfe) |
{ // start condition |
JetiBufferReady = 0; |
jbp = 0; |
// LED1_ON; |
} |
else if (rl == 0xff) |
{ // stop condition |
JetiBufferReady = 1; |
// LED1_OFF; |
} |
} |
else |
{ // data |
if (jbp < 32) |
{ |
JetiBuffer[jbp++] = rl; |
} |
} |
} |
#endif |
//***************************************************************************** |
// |
void JETI_Init (void) |
{ |
DDRD &= ~(1 << DDD3); // set TXD1 pin as input |
PORTD &= ~(1 << PORTD3); // disable pullup on TXD1 pin |
|
// set clock divider |
#undef BAUD |
#define BAUD 9600 |
#include <util/setbaud.h> |
UBRRH = UBRRH_VALUE; |
UBRRL = UBRRL_VALUE; |
|
#if USE_2X |
UCSR1A |= (1 << U2X1); // enable double speed operation |
#else |
UCSRA &= ~(1 << U2X); // disable double speed operation |
#endif |
|
// set 9O1 |
UCSRC = (1 << UPM1) | (1 << UPM1) | (1 << UCSZ1) | (1 << UCSZ0); |
UCSRB = (1 << UCSZ2); |
|
// flush receive buffer |
while ( UCSRA & (1 << RXC) ) UDR; |
} |
|
//***************************************************************************** |
// disable the txd pin of usart |
void JETI_DisableTXD (void) |
{ |
UCSRB &= ~(1 << TXEN); // disable TX} |
} |
|
//***************************************************************************** |
// enable the txd pin of usart |
void JETI_EnableTXD (void) |
{ |
UCSRB |= (1 << TXEN); // enable TX |
} |
|
|
//***************************************************************************** |
// |
void JETI_putw (uint16_t c) |
{ |
loop_until_bit_is_set(UCSRA, UDRE); |
UCSRB &= ~(1 << TXB8); |
if (c & 0x0100) |
{ |
UCSRB |= (1 << TXB8); |
} |
UDR = c; |
} |
|
//***************************************************************************** |
// |
void JETI_putc (uint8_t c) |
{ |
loop_until_bit_is_set(UCSRA, UDRE); |
// UCSRB &= ~(1 << TXB8); |
UCSRB |= (1 << TXB8); |
UDR = c; |
} |
|
//***************************************************************************** |
// |
void JETI_puts (char *s) |
{ |
while (*s) |
{ |
JETI_putc (*s); |
s++; |
} |
} |
|
//***************************************************************************** |
// |
void JETI_puts_p (const char *s) |
{ |
while (pgm_read_byte(s)) |
{ |
JETI_putc (pgm_read_byte(s)); |
s++; |
} |
} |
|
//***************************************************************************** |
// |
void JETI_put_start (void) |
{ |
loop_until_bit_is_set(UCSRA, UDRE); |
UCSRB &= ~(1 << TXB8); |
UDR = 0xFE; |
} |
|
//***************************************************************************** |
// |
void JETI_put_stop (void) |
{ |
loop_until_bit_is_set(UCSRA, UDRE); |
UCSRB &= ~(1 << TXB8); |
UDR = 0xFF; |
} |
|
//***************************************************************************** |
// |
void jeti (void) |
{ |
uint8_t key; |
uint8_t i; |
|
// enable Rx |
UCSRB |= (1 << RXEN); |
UCSRB |= (1 << RXCIE); |
|
lcd_cls (); |
lcd_printp_at (0, 0, PSTR("Jeti Box Display"), 0); |
lcd_printpns_at (0, 7, PSTR(" \x1a \x1b \x1c \x1d"), 0); |
|
#ifdef font8x8 |
lcd_line(0, 21, 127, 21, 1); |
lcd_line(0, 22, 127, 22, 1); |
lcd_line(0, 40, 127, 40, 1); |
lcd_line(0, 41, 127, 41, 1); |
#else |
lcd_rect(10, 22, 98, 18, 1); |
#endif |
|
do |
{ |
if (JetiBufferReady) |
{ |
JETI_EnableTXD(); |
// LED2_ON; |
for (i = 0; i < 16; i++) |
{ |
#ifdef font8x8 |
lcd_putc_jeti(i, 3, JetiBuffer[i], 0); |
#else |
lcd_putc (2 + i, 3, JetiBuffer[i], 0); |
#endif |
} |
for (i = 0; i < 16; i++) |
{ |
#ifdef font8x8 |
lcd_putc_jeti(i, 4, JetiBuffer[i + 16], 0); |
#else |
lcd_putc (2 + i, 4, JetiBuffer[i + 16], 0); |
#endif |
} |
JetiBufferReady = 0; // invalidate buffer |
// LED2_OFF; |
|
_delay_ms (1); // |
// Writing to the display takes aprox. 5.8 ms @ 7 MHz and 3.2 ms @ 20 MHz. |
// With the additional 4 ms we had a 10 ms delay. |
// 10 ms works perfect with the MUI30 and the MT125 |
// But not with the TU transceiver module. |
|
key = get_key_short ((1 << KEY_MINUS) | (1 << KEY_PLUS) | (1 << KEY_ESC) | (1 << KEY_ENTER)); |
key = (key << 1) | (key >> 3); |
key = (~key) & 0xf0; |
|
JETI_putw((uint16_t) key); |
_delay_ms (1); |
JETI_DisableTXD(); |
} |
} |
while (!get_key_long (1 << KEY_ESC)); |
get_key_press(KEY_ALL); |
|
// disable Rx |
UCSRB &= ~(1 << RXCIE); |
UCSRB &= ~(1 << RXEN); |
} |