Fix 2.2.2RC1 no gvar compile (#5961)
[opentx.git] / radio / src / telemetry / jeti.cpp
blobd41642b58de894fd1842cb174d8e4d1b501503cd
1 /*
2 * Copyright (C) OpenTX
4 * Based on code named
5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
21 #include "opentx.h"
23 uint8_t jetiRxBuffer[32];
24 uint8_t jetiReady;
25 uint16_t jetiKeys;
27 void telemetryInterrupt10ms()
29 if (jetiReady) {
30 jetiKeys = JETI_KEY_NOCHANGE;
31 if (switchState(KEY_UP)) jetiKeys &= JETI_KEY_UP;
32 if (switchState(KEY_DOWN)) jetiKeys &= JETI_KEY_DOWN;
33 if (switchState(KEY_LEFT)) jetiKeys &= JETI_KEY_LEFT;
34 if (switchState(KEY_RIGHT)) jetiKeys &= JETI_KEY_RIGHT;
36 jetiReady = 0; // invalidate buffer
38 JETI_EnableTXD();
42 #ifndef SIMU
43 ISR(USART0_UDRE_vect)
45 if (jetiKeys != 0xff) {
46 UCSR0B &= ~(1 << TXB80);
48 if (jetiKeys & 0x0100)
49 UCSR0B |= (1 << TXB80);
51 UDR0 = jetiKeys;
53 jetiKeys = 0xff;
55 else {
56 JETI_DisableTXD();
60 ISR (USART0_RX_vect)
62 uint8_t stat;
63 uint8_t rh;
64 uint8_t rl;
65 static uint8_t jbp;
67 stat = UCSR0A;
68 rh = UCSR0B;
69 rl = UDR0;
71 if (stat & ((1 << FE0) | (1 << DOR0) | (1 << UPE0))) {
72 // discard buffer and start new on any error
73 jetiReady = 0;
74 jbp = 0;
76 else if ((rh & (1 << RXB80)) == 0) {
77 // control
78 if (rl == 0xfe) {
79 // start condition
80 jetiReady = 0;
81 jbp = 0;
83 else if (rl == 0xff) {
84 // stop condition
85 jetiReady = 1;
88 else {
89 // data
90 if (jbp < 32) {
91 if (rl==0xDF)
92 jetiRxBuffer[jbp++] = '@'; //@ => ° Issue 163
93 else
94 jetiRxBuffer[jbp++] = rl;
98 #endif
100 void JETI_Init (void)
102 DDRE &= ~(1 << DDE0); // set RXD0 pin as input
103 PORTE &= ~(1 << PORTE0); // disable pullup on RXD0 pin
105 #ifndef SIMU
107 #undef BAUD
108 #define BAUD 9600
109 #include <util/setbaud.h>
110 UBRR0H = UBRRH_VALUE;
111 UBRR0L = UBRRL_VALUE;
113 UCSR0A &= ~(1 << U2X0); // disable double speed operation
115 // set 9O1
116 UCSR0C = (1 << UPM01) | (1 << UPM00) | (1 << UCSZ01) | (1 << UCSZ00);
117 UCSR0B = (1 << UCSZ02);
119 // flush receive buffer
120 while ( UCSR0A & (1 << RXC0) ) UDR0;
122 #endif
125 void JETI_EnableTXD (void)
127 UCSR0B |= (1 << TXEN0); // enable TX
128 UCSR0B |= (1 << UDRIE0); // enable UDRE0 interrupt
131 void JETI_DisableTXD (void)
133 UCSR0B &= ~(1 << TXEN0); // disable TX
134 UCSR0B &= ~(1 << UDRIE0); // disable UDRE0 interrupt
137 void JETI_EnableRXD (void)
139 UCSR0B |= (1 << RXEN0); // enable RX
140 UCSR0B |= (1 << RXCIE0); // enable Interrupt
143 void JETI_DisableRXD (void)
145 UCSR0B &= ~(1 << RXEN0); // disable RX
146 UCSR0B &= ~(1 << RXCIE0); // disable Interrupt
149 #if 0
150 void JETI_putw (uint16_t c)
152 loop_until_bit_is_set(UCSR0A, UDRE0);
153 UCSR0B &= ~(1 << TXB80);
154 if (c & 0x0100)
156 UCSR0B |= (1 << TXB80);
158 UDR0 = c;
161 void JETI_putc (uint8_t c)
163 loop_until_bit_is_set(UCSR0A, UDRE0);
164 // UCSRB &= ~(1 << TXB8);
165 UCSR0B |= (1 << TXB80);
166 UDR0 = c;
169 void JETI_puts (char *s)
171 while (*s)
173 JETI_putc (*s);
174 s++;
178 void JETI_put_start (void)
180 loop_until_bit_is_set(UCSR0A, UDRE0);
181 UCSR0B &= ~(1 << TXB80);
182 UDR0 = 0xFE;
185 void JETI_put_stop (void)
187 loop_until_bit_is_set(UCSR0A, UDRE0);
188 UCSR0B &= ~(1 << TXB80);
189 UDR0 = 0xFF;
191 #endif
193 void menuViewTelemetryJeti(event_t event)
195 drawTelemetryTopBar();
197 for (uint8_t i=0; i<16; i++) {
198 lcdDrawChar((i+2)*FW, 3*FH, jetiRxBuffer[i], BSS);
199 lcdDrawChar((i+2)*FW, 4*FH, jetiRxBuffer[i+16], BSS);
202 if (event == EVT_KEY_FIRST(KEY_EXIT)) {
203 JETI_DisableRXD();
204 jetiReady = 0;
205 chainMenu(menuMainView);