altos: Split out arch-specific bits of LCD driver
authorKeith Packard <keithp@keithp.com>
Wed, 12 Oct 2011 05:28:02 +0000 (23:28 -0600)
committerKeith Packard <keithp@keithp.com>
Wed, 12 Oct 2011 05:28:02 +0000 (23:28 -0600)
The arch-specific section just puts a single nibble to the device.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/avr/ao_lcd_port.c [new file with mode: 0644]
src/cc1111/ao_lcd_port.c [new file with mode: 0644]
src/cc1111/ao_packet.c
src/core/ao.h
src/core/ao_monitor.c
src/drivers/ao_lcd.c

diff --git a/src/avr/ao_lcd_port.c b/src/avr/ao_lcd_port.c
new file mode 100644 (file)
index 0000000..b1e8aa1
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ *
+ * 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; 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 "ao.h"
+
+#define LCD_PORT       PORTB
+#define LCD_DDR                DDRB
+
+#define PIN_RS         4
+#define PIN_E          5
+#define PIN_RW         6
+
+static void
+ao_lcd_port_set_bits(uint8_t bits)
+{
+#if 0
+       printf("\tLCD data %x RS %d R/W %d E %d\n",
+              bits & 0xf,
+              (bits & (1 << PIN_RS)) ? 1 : 0,
+              (bits & (1 << PIN_RW)) ? 1 : 0,
+              (bits & (1 << PIN_E)) ? 1 : 0);
+#endif
+       LCD_PORT = bits;
+#if 0
+       ao_delay(1);
+       if (bits & (1 << PIN_RW))
+               printf("\tLCD input %x\n", PINB);
+#endif
+}
+
+uint8_t
+ao_lcd_port_get_nibble(uint8_t rs)
+{
+       uint8_t data = (rs ? (1 << PIN_RS) : 0) | (1 << PIN_RW);
+       uint8_t n;
+
+       DDRB = (1 << PIN_RS) | (1 << PIN_E) | (1 << PIN_RW);
+       ao_lcd_port_set_bits(data);
+       ao_lcd_port_set_bits(data | (1 << PIN_E));
+       n = PINB & 0xf;
+       ao_lcd_port_set_bits(data);
+       return n;
+}
+
+void
+ao_lcd_port_put_nibble(uint8_t rs, uint8_t data)
+{
+       data = (data & 0xf) | (rs ? (1 << PIN_RS) : 0);
+       DDRB = (0xf) | (1 << PIN_RS) | (1 << PIN_E) | (1 << PIN_RW);
+       ao_lcd_port_set_bits(data);
+       ao_lcd_port_set_bits(data | (1 << PIN_E));
+       ao_lcd_port_set_bits(data);
+}
+
+void
+ao_lcd_port_init(void)
+{
+       DDRB = (1 << PIN_RS) | (1 << PIN_E) | (1 << PIN_RW);
+       PORTB = 0;
+}
diff --git a/src/cc1111/ao_lcd_port.c b/src/cc1111/ao_lcd_port.c
new file mode 100644 (file)
index 0000000..324cc3d
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * Copyright © 2011 Keith Packard <keithp@keithp.com>
+ *
+ * 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; 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 "ao.h"
+
+void
+ao_lcd_port_put_nibble(uint8_t rs, uint8_t nibble)
+{
+       P0 = (P0 & 0xf0) | (nibble & 0x0f);
+       P1_1 = rs;
+       P1_0 = 1;
+       ao_delay(1);
+       P1_0 = 0;
+       ao_delay(1);
+}
+
+void
+ao_lcd_port_init(void)
+{
+       /* LCD_E and LCD_RS are GPIO outputs */
+       P1DIR |= 0x03;
+       P1SEL &= ~0x03;
+
+       /* LCD D4-D7 are GPIO outputs */
+       P0DIR |= 0x0f;
+       P0SEL &= ~0x0f;
+}
index 37ba92e04c4233a5036ee98fe861249283b06449..f502d67c598295672f1ad73540300f3da747ca2a 100644 (file)
@@ -32,7 +32,9 @@ __xdata uint8_t ao_packet_master_sleeping;
 void
 ao_packet_send(void)
 {
+#ifdef AO_LED_RED
        ao_led_on(AO_LED_RED);
+#endif
        /* If any tx data is pending then copy it into the tx packet */
        if (ao_packet_tx_used && ao_tx_packet.len == 0) {
                ao_xmemcpy(&ao_tx_packet.d, tx_data, ao_packet_tx_used);
@@ -42,7 +44,9 @@ ao_packet_send(void)
                ao_wakeup(&tx_data);
        }
        ao_radio_send(&ao_tx_packet, sizeof (ao_tx_packet));
+#ifdef AO_LED_RED
        ao_led_off(AO_LED_RED);
+#endif
 }
 
 uint8_t
index 94526bc3f87bd8c28283a604cdf50fd380844170..c800f1fc56e16da4b6e0059da948d296ecdb2479 100644 (file)
@@ -1667,9 +1667,37 @@ ao_companion_init(void);
 
 /* ao_lcd.c */
   
+void
+ao_lcd_putchar(uint8_t data);
+
+void
+ao_lcd_putstring(char *string);
+
+void
+ao_lcd_contrast_set(uint8_t contrast);
+
+void
+ao_lcd_clear(void);
+
+#define AO_LCD_ADDR(row,col)   ((row << 6) | (col))
+
+void
+ao_lcd_goto(uint8_t addr);
+
+void
+ao_lcd_start(void);
+
 void
 ao_lcd_init(void);
 
+/* ao_lcd_port.c */
+
+void
+ao_lcd_port_put_nibble(uint8_t rs, uint8_t data);
+
+void
+ao_lcd_port_init(void);
+
 /* ao_aes.c */
 
 __xdata uint8_t ao_aes_mutex;
index 1a8bb52a29fdb1467ad8799c0008f18c52867adf..5a6f61ddf21b093cf6b30b8b8b3437eda21bf9be 100644 (file)
 #error Must define HAS_MONITOR to 1
 #endif
 
+#ifndef LEGACY_MONITOR
+#error Must define LEGACY_MONITOR
+#endif
+
 __data uint8_t ao_monitoring;
 __pdata uint8_t ao_monitor_led;
 
@@ -39,12 +43,14 @@ ao_monitor_get(void)
                case 0:
                        ao_sleep(DATA_TO_XDATA(&ao_monitoring));
                        continue;
+#if LEGACY_MONITOR
                case AO_MONITORING_ORIG:
                        size = sizeof (struct ao_telemetry_orig_recv);
                        break;
                case AO_MONITORING_TINY:
                        size = sizeof (struct ao_telemetry_tiny_recv);
                        break;
+#endif
                default:
                        if (ao_monitoring > AO_MAX_TELEMETRY)
                                ao_monitoring = AO_MAX_TELEMETRY;
@@ -70,12 +76,13 @@ ao_monitor_blink(void)
 void
 ao_monitor_put(void)
 {
+#if LEGACY_MONITOR
        __xdata char callsign[AO_MAX_CALLSIGN+1];
-
+       int16_t rssi;
+#endif
        uint8_t ao_monitor_tail;
        uint8_t state;
        uint8_t sum, byte;
-       int16_t rssi;
        __xdata union ao_monitor        *m;
 
 #define recv_raw       ((m->raw))
@@ -89,6 +96,7 @@ ao_monitor_put(void)
                m = &ao_monitor_ring[ao_monitor_tail];
                ao_monitor_tail = ao_monitor_ring_next(ao_monitor_tail);
                switch (ao_monitoring) {
+#if LEGACY_MONITOR
                case AO_MONITORING_ORIG:
                        state = recv_orig.telemetry_orig.flight_state;
 
@@ -231,6 +239,7 @@ ao_monitor_put(void)
                                printf("CRC INVALID RSSI %3d\n", rssi);
                        }
                        break;
+#endif /* LEGACY_MONITOR */
                default:
                        printf ("TELEM %02x", ao_monitoring + 2);
                        sum = 0x5a;
index 5bc89bbd91efd74f11b62beb7ce471c7ec850617..e62247aecacbcf4c69ccceecaed922de8872f467 100644 (file)
 
 #include "ao.h"
 
-#define LCD_PORT       PORTB
-#define LCD_DDR                DDRB
-
-#define PIN_RS         4
-#define PIN_E          5
-#define PIN_RW         6
-
-void
-ao_lcd_set_bits(uint8_t bits)
-{
-#if 0
-       printf("\tLCD data %x RS %d R/W %d E %d\n",
-              bits & 0xf,
-              (bits & (1 << PIN_RS)) ? 1 : 0,
-              (bits & (1 << PIN_RW)) ? 1 : 0,
-              (bits & (1 << PIN_E)) ? 1 : 0);
-#endif
-       LCD_PORT = bits;
-#if 0
-       ao_delay(1);
-       if (bits & (1 << PIN_RW))
-               printf("\tLCD input %x\n", PINB);
-#endif
-}
-
-uint8_t
-ao_lcd_get_nibble(uint8_t rs)
-{
-       uint8_t data = (rs ? (1 << PIN_RS) : 0) | (1 << PIN_RW);
-       uint8_t n;
-
-       DDRB = (1 << PIN_RS) | (1 << PIN_E) | (1 << PIN_RW);
-       ao_lcd_set_bits(data);
-       ao_lcd_set_bits(data | (1 << PIN_E));
-       n = PINB & 0xf;
-       ao_lcd_set_bits(data);
-       return n;
-}
-
-uint8_t
-ao_lcd_get_status(void)
-{
-       uint8_t high, low;
-       uint8_t data;
-
-       high = ao_lcd_get_nibble(0);
-       low = ao_lcd_get_nibble(0);
-       data = (high << 4) | low;
-       printf ("\tLCD status %02x\n", data);
-       return data;
-}
-
-uint8_t
-ao_lcd_get_data(void)
-{
-       uint8_t high, low;
-       uint8_t data;
-
-       high = ao_lcd_get_nibble(1);
-       low = ao_lcd_get_nibble(1);
-       data = (high << 4) | low;
-       printf ("\tLCD data %02x\n", data);
-       return data;
-}
-
-void
-ao_lcd_wait_idle(void)
-{
-       uint8_t status;
-       uint8_t count = 0;
-
-       do {
-               status = ao_lcd_get_status();
-               count++;
-               if (count > 100) {
-                       printf("idle timeout\n");
-                       break;
-               }
-       } while (0);    /* status & 0x80); */
-}
-
-void
-ao_lcd_send_nibble(uint8_t rs, uint8_t data)
-{
-       data = (data & 0xf) | (rs ? (1 << PIN_RS) : 0);
-       DDRB = (0xf) | (1 << PIN_RS) | (1 << PIN_E) | (1 << PIN_RW);
-       ao_lcd_set_bits(data);
-       ao_lcd_set_bits(data | (1 << PIN_E));
-       ao_lcd_set_bits(data);
-}
-
 static uint16_t        ao_lcd_time = 3;
 
-void
+static void
 ao_lcd_delay(void)
 {
        volatile uint16_t       count;
@@ -119,34 +28,34 @@ ao_lcd_delay(void)
                ;
 }
 
-void
-ao_lcd_send_ins(uint8_t data)
+static void
+ao_lcd_send_ins(uint8_t ins)
 {
-//     printf("send ins %02x\n", data);
+//     printf("send ins %02x\n", ins);
 //     ao_lcd_wait_idle();
 //     ao_delay(1);
        ao_lcd_delay();
-       ao_lcd_send_nibble(0, data >> 4);
-       ao_lcd_send_nibble(0, data & 0xf);
+       ao_lcd_port_put_nibble(0, ins >> 4);
+       ao_lcd_port_put_nibble(0, ins & 0xf);
 }
 
 void
-ao_lcd_send_data(uint8_t data)
+ao_lcd_put_byte(uint8_t c)
 {
-//     printf ("send data %02x\n", data);
+//     printf ("send data %02x\n", c);
 //     ao_lcd_wait_idle();
        ao_lcd_delay();
-       ao_lcd_send_nibble(1, data >> 4);
-       ao_lcd_send_nibble(1, data & 0x0f);
+       ao_lcd_port_put_nibble(1, c >> 4);
+       ao_lcd_port_put_nibble(1, c & 0x0f);
 }
 
 void
-ao_lcd_send_string(char *string)
+ao_lcd_putstring(char *string)
 {
-       uint8_t c;
+       char    c;
 
        while ((c = (uint8_t) *string++))
-               ao_lcd_send_data(c);
+               ao_lcd_put_byte((uint8_t) c);
 }
 
 #define AO_LCD_POWER_CONTROL   0x54
@@ -167,14 +76,21 @@ ao_lcd_clear(void)
        ao_lcd_send_ins(0x04 | 0x02);
 }
 
+void
+ao_lcd_goto(uint8_t addr)
+{
+       ao_lcd_send_ins(0x80 | addr);
+       ao_lcd_send_ins(0x04 | 0x02);
+}
+
 void
 ao_lcd_start(void)
 {
        /* get to 4bit mode */
-       ao_lcd_send_nibble(0, 0x3);
-       ao_lcd_send_nibble(0, 0x3);
-       ao_lcd_send_nibble(0, 0x3);
-       ao_lcd_send_nibble(0, 0x2);
+       ao_lcd_port_put_nibble(0, 0x3);
+       ao_lcd_port_put_nibble(0, 0x3);
+       ao_lcd_port_put_nibble(0, 0x3);
+       ao_lcd_port_put_nibble(0, 0x2);
 
        /* function set */
        ao_lcd_send_ins(0x28);
@@ -199,7 +115,6 @@ ao_lcd_start(void)
 
        /* Clear */
        ao_lcd_clear();
-
 }
 
 void
@@ -229,7 +144,7 @@ void
 ao_lcd_string(void)
 {
        uint8_t col = 0;
-       uint8_t c;
+       char    c;
 
        ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
@@ -244,12 +159,12 @@ ao_lcd_string(void)
                        ao_cmd_lex();
                        c |= ao_cmd_hex_nibble();
                }
-               ao_lcd_send_data(c);
+               ao_lcd_put_byte(c);
                ao_cmd_lex();
                col++;
        }
        while (col < 16) {
-               ao_lcd_send_data(' ');
+               ao_lcd_put_byte(' ');
                col++;
        }
 }
@@ -275,7 +190,6 @@ __code struct ao_cmds ao_lcd_cmds[] = {
 void
 ao_lcd_init(void)
 {
-       DDRB = (1 << PIN_RS) | (1 << PIN_E) | (1 << PIN_RW);
-       PORTB = 0;
+       ao_lcd_port_init();
        ao_cmd_register(&ao_lcd_cmds[0]);
 }