Skip to content

Commit da330c5

Browse files
committed
altos: Bring up basic TeleTerra v0.2 UI
Lots of fun stuff here -- multiple panes of information. Signed-off-by: Keith Packard <[email protected]>
1 parent 8e4ccee commit da330c5

File tree

17 files changed

+710
-52
lines changed

17 files changed

+710
-52
lines changed

src/cc1111/ao_arch.h

+10-4
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,23 @@ struct ao_adc {
205205
#define AO_ADC_RING 32
206206

207207
/* ao_button.c */
208+
#ifdef HAS_BUTTON
208209
void
209-
ao_p2_isr(void);
210+
ao_p0_isr(void) ao_arch_interrupt(13);
210211

211212
void
212-
ao_button_init(void);
213+
ao_p1_isr(void) ao_arch_interrupt(15);
213214

214-
#if HAS_BUTTON_P0
215215
void
216-
ao_p0_isr(void) ao_arch_interrupt(13);
216+
ao_p2_isr(void);
217+
218+
#define HAS_P2_ISR 1
219+
217220
#endif
218221

222+
void
223+
ao_button_init(void);
224+
219225
char
220226
ao_button_get(void) __critical;
221227

src/cc1111/ao_button.c

+86-29
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,22 @@
1919

2020
volatile __xdata struct ao_fifo ao_button_fifo;
2121

22-
#define BUTTON_1_PIN (P0_4)
23-
#define BUTTON_1_MASK (1 << 4) /* P0_4 */
22+
static __code struct {
23+
uint8_t mask;
24+
uint8_t reg;
25+
} ao_buttons[] = {
26+
#ifdef BUTTON_1_MASK
27+
{ BUTTON_1_MASK, BUTTON_1_REG },
28+
#endif
29+
#ifdef BUTTON_2_MASK
30+
{ BUTTON_2_MASK, BUTTON_2_REG },
31+
#endif
32+
#ifdef BUTTON_3_MASK
33+
{ BUTTON_3_MASK, BUTTON_3_REG },
34+
#endif
35+
};
2436

25-
#define BUTTON_2_PIN (P2_3)
26-
#define BUTTON_2_MASK (1 << 3) /* P2_3 */
27-
28-
#define BUTTON_3_PIN (P2_4)
29-
#define BUTTON_3_MASK (1 << 4) /* P2_4 */
37+
#define NUM_BUTTONS ((sizeof ao_buttons) / sizeof (ao_buttons[0]))
3038

3139
static void
3240
ao_button_insert(char n)
@@ -35,52 +43,101 @@ ao_button_insert(char n)
3543
ao_wakeup(&ao_button_fifo);
3644
}
3745

46+
static void
47+
ao_button_isr(uint8_t flag, uint8_t reg)
48+
{
49+
uint8_t b;
50+
51+
for (b = 0; b < NUM_BUTTONS; b++)
52+
if (ao_buttons[b].reg == reg && (ao_buttons[b].mask & flag))
53+
ao_button_insert(b + 1);
54+
}
55+
56+
static uint8_t
57+
ao_button_mask(uint8_t reg)
58+
{
59+
uint8_t b;
60+
uint8_t mask = 0;
61+
62+
for (b = 0; b < NUM_BUTTONS; b++)
63+
if (ao_buttons[b].reg == reg)
64+
mask |= ao_buttons[b].mask;
65+
return mask;
66+
}
67+
3868
char
3969
ao_button_get(void) __critical
4070
{
4171
char b;
4272

4373
while (ao_fifo_empty(ao_button_fifo))
44-
ao_sleep(&ao_button_fifo);
74+
if (ao_sleep(&ao_button_fifo))
75+
return 0;
4576
ao_fifo_remove(ao_button_fifo, b);
4677
return b;
4778
}
4879

4980
void
50-
ao_p2_isr(void)
81+
ao_p0_isr(void) ao_arch_interrupt(13)
5182
{
52-
if (P2IFG & BUTTON_2_MASK)
53-
ao_button_insert(2);
54-
if (P2IFG & BUTTON_3_MASK)
55-
ao_button_insert(3);
56-
P2IFG = 0;
83+
P0IF = 0;
84+
ao_button_isr(P0IFG, 0);
85+
P0IFG = 0;
5786
}
5887

5988
void
60-
ao_p0_isr(void) ao_arch_interrupt(13)
89+
ao_p1_isr(void) ao_arch_interrupt(15)
6190
{
62-
P0IF = 0;
63-
if (P0IFG & BUTTON_1_MASK)
64-
ao_button_insert(1);
65-
P0IFG = 0;
91+
P1IF = 0;
92+
ao_button_isr(P1IFG, 1);
93+
P1IFG = 0;
94+
}
95+
96+
/* Shared with USB */
97+
void
98+
ao_p2_isr(void)
99+
{
100+
ao_button_isr(P2IFG, 2);
101+
P2IFG = 0;
66102
}
67103

68104
void
69105
ao_button_init(void)
70106
{
107+
uint8_t mask;
108+
71109
/* Pins are configured as inputs with pull-up by default */
72110

73-
/* Enable interrupts for P2_0 - P2_4
74-
* Enable interrupts for P0_4 - P0_7
75-
* Set P2 interrupts to falling edge
76-
* Set P0 interrupts to falling edge
77-
*/
78-
79111
/* Enable interrupts for P0 inputs */
80-
IEN1 |= IEN1_P0IE;
112+
mask = ao_button_mask(0);
113+
if (mask) {
114+
if (mask & 0x0f)
115+
PICTL |= PICTL_P0IENL;
116+
if (mask & 0xf0)
117+
PICTL |= PICTL_P0IENH;
118+
P0IFG = 0;
119+
P0IF = 0;
120+
IEN1 |= IEN1_P0IE;
121+
PICTL |= PICTL_P0ICON;
122+
}
81123

82-
/* Enable interrupts for P2 inputs */
83-
IEN2 |= IEN2_P2IE;
124+
/* Enable interrupts for P1 inputs */
125+
mask = ao_button_mask(1);
126+
if (mask) {
127+
P1IEN |= mask;
128+
P1IFG = 0;
129+
P1IF = 0;
130+
IEN2 |= IEN2_P1IE;
131+
PICTL |= PICTL_P1ICON;
132+
}
84133

85-
PICTL |= PICTL_P2IEN | PICTL_P0IENH | PICTL_P2ICON | PICTL_P0ICON;
134+
/* Enable interrupts for P2 inputs */
135+
mask = ao_button_mask(2);
136+
if (mask) {
137+
PICTL |= PICTL_P2IEN;
138+
P2IFG = 0;
139+
P2IF = 0;
140+
IEN2 |= IEN2_P2IE;
141+
PICTL |= PICTL_P2ICON;
142+
}
86143
}

src/cc1111/ao_lcd_port.c

+11-2
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,24 @@
1717

1818
#include "ao.h"
1919

20+
static void
21+
ao_lcd_port_delay(void)
22+
{
23+
uint8_t i;
24+
25+
for (i = 0; i < 100; i++)
26+
ao_arch_nop();
27+
}
28+
2029
void
2130
ao_lcd_port_put_nibble(uint8_t rs, uint8_t nibble)
2231
{
2332
P0 = (P0 & 0xf0) | (nibble & 0x0f);
2433
P1_1 = rs;
2534
P1_0 = 1;
26-
ao_delay(1);
35+
ao_lcd_port_delay();
2736
P1_0 = 0;
28-
ao_delay(1);
37+
ao_lcd_port_delay();
2938
}
3039

3140
void

src/core/ao.h

+21-3
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,11 @@ ao_spi_slave(void);
996996
*/
997997
#define AO_MAX_CALLSIGN 8
998998
#define AO_MAX_VERSION 8
999+
#if LEGACY_MONITOR
9991000
#define AO_MAX_TELEMETRY 128
1001+
#else
1002+
#define AO_MAX_TELEMETRY 32
1003+
#endif
10001004

10011005
struct ao_telemetry_generic {
10021006
uint16_t serial; /* 0 */
@@ -1156,6 +1160,12 @@ union ao_telemetry_all {
11561160
struct ao_telemetry_baro baro;
11571161
};
11581162

1163+
struct ao_telemetry_all_recv {
1164+
union ao_telemetry_all telemetry;
1165+
int8_t rssi;
1166+
uint8_t status;
1167+
};
1168+
11591169
/*
11601170
* ao_gps.c
11611171
*/
@@ -1372,9 +1382,10 @@ extern const char const * const ao_state_names[];
13721382
#define AO_MONITOR_RING 8
13731383

13741384
union ao_monitor {
1375-
struct ao_telemetry_raw_recv raw;
1376-
struct ao_telemetry_orig_recv orig;
1377-
struct ao_telemetry_tiny_recv tiny;
1385+
struct ao_telemetry_raw_recv raw;
1386+
struct ao_telemetry_all_recv all;
1387+
struct ao_telemetry_orig_recv orig;
1388+
struct ao_telemetry_tiny_recv tiny;
13781389
};
13791390

13801391
extern __xdata union ao_monitor ao_monitor_ring[AO_MONITOR_RING];
@@ -1873,4 +1884,11 @@ void
18731884
ao_battery_init(void);
18741885
#endif /* BATTERY_PIN */
18751886

1887+
/*
1888+
* ao_sqrt.c
1889+
*/
1890+
1891+
uint32_t
1892+
ao_sqrt(uint32_t op);
1893+
18761894
#endif /* _AO_H_ */

src/core/ao_monitor.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
#error Must define LEGACY_MONITOR
2727
#endif
2828

29+
#ifndef HAS_MONITOR_PUT
30+
#define HAS_MONIOTOR_PUT 1
31+
#endif
32+
2933
__data uint8_t ao_monitoring;
3034
__pdata uint8_t ao_monitor_led;
3135

@@ -73,6 +77,7 @@ ao_monitor_blink(void)
7377
}
7478
}
7579

80+
#if HAS_MONITOR_PUT
7681
void
7782
ao_monitor_put(void)
7883
{
@@ -260,9 +265,10 @@ ao_monitor_put(void)
260265
ao_usb_flush();
261266
}
262267
}
268+
__xdata struct ao_task ao_monitor_put_task;
269+
#endif
263270

264271
__xdata struct ao_task ao_monitor_get_task;
265-
__xdata struct ao_task ao_monitor_put_task;
266272
__xdata struct ao_task ao_monitor_blink_task;
267273

268274
void
@@ -293,7 +299,9 @@ ao_monitor_init(uint8_t monitor_led, uint8_t monitoring) __reentrant
293299
ao_monitoring = monitoring;
294300
ao_cmd_register(&ao_monitor_cmds[0]);
295301
ao_add_task(&ao_monitor_get_task, ao_monitor_get, "monitor_get");
302+
#if HAS_MONITOR_PUT
296303
ao_add_task(&ao_monitor_put_task, ao_monitor_put, "monitor_put");
304+
#endif
297305
if (ao_monitor_led)
298306
ao_add_task(&ao_monitor_blink_task, ao_monitor_blink, "monitor_blink");
299307
}

src/core/ao_sqrt.c

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright © 2011 Keith Packard <[email protected]>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; version 2 of the License.
7+
*
8+
* This program is distributed in the hope that it will be useful, but
9+
* WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
* General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU General Public License along
14+
* with this program; if not, write to the Free Software Foundation, Inc.,
15+
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
16+
*/
17+
18+
#include "ao.h"
19+
20+
/* Adapted from int_sqrt.c in the linux kernel, which is licensed GPLv2 */
21+
/**
22+
* int_sqrt - rough approximation to sqrt
23+
* @x: integer of which to calculate the sqrt
24+
*
25+
* A very rough approximation to the sqrt() function.
26+
*/
27+
28+
uint32_t
29+
ao_sqrt(uint32_t op)
30+
{
31+
uint32_t res = 0;
32+
uint32_t one = 1UL << (sizeof (one) * 8 - 2);
33+
34+
while (one > op)
35+
one >>= 2;
36+
37+
while (one != 0) {
38+
if (op >= res + one) {
39+
op = op - (res + one);
40+
res = res + 2 * one;
41+
}
42+
res /= 2;
43+
one /= 4;
44+
}
45+
return res;
46+
}

0 commit comments

Comments
 (0)