src-avr: Add LCD driver for NHD-C0216CU-FN-GWB-3V display
authorKeith Packard <keithp@keithp.com>
Sun, 5 Jun 2011 00:59:48 +0000 (17:59 -0700)
committerKeith Packard <keithp@keithp.com>
Sun, 5 Jun 2011 00:59:48 +0000 (17:59 -0700)
Initializes the Newhaven display and has a few simple commands to show
some text.

Signed-off-by: Keith Packard <keithp@keithp.com>
src-avr/ao.h
src-avr/ao_demo.c
src-avr/ao_lcd.c [new file with mode: 0644]
src-avr/avr-demo/Makefile
src-avr/telescience/Makefile
src/Makefile
src/Makefile.proto
src/ao_flight.c
src/ao_pins.h

index 6d025c99d78acd6ba70bb265b41041e95e747030..ecb334641b777a0409d6924077ec0d1fb87d2374 100644 (file)
@@ -323,6 +323,13 @@ ao_led_for(uint8_t colors, uint16_t ticks) __reentrant;
 void
 ao_led_init(uint8_t enable);
 
+/*
+ * ao_lcd.c
+ */
+
+void
+ao_lcd_init(void);
+
 /*
  * ao_romconfig.c
  */
index d905cec6cec3e212dd150b841d11425541ee8ded..077dbf78748d0096872db9e86606d6733adf94c2 100644 (file)
@@ -43,6 +43,7 @@ main(void)
        ao_timer_init();
        ao_cmd_init();
        ao_usb_init();
+       ao_lcd_init();
 
 //     ao_add_task(&demo_task, ao_demo, "demo");
        /* Turn on the LED until the system is stable */
diff --git a/src-avr/ao_lcd.c b/src-avr/ao_lcd.c
new file mode 100644 (file)
index 0000000..6f95b52
--- /dev/null
@@ -0,0 +1,225 @@
+/*
+ * 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
+
+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);
+}
+
+void
+ao_lcd_send_ins(uint8_t data)
+{
+       printf("send ins %02x\n", data);
+       ao_lcd_wait_idle();
+       ao_lcd_send_nibble(0, data >> 4);
+       ao_lcd_send_nibble(0, data & 0xf);
+}
+
+void
+ao_lcd_send_data(uint8_t data)
+{
+       printf ("send data %02x\n", data);
+       ao_lcd_wait_idle();
+       ao_lcd_send_nibble(1, data >> 4);
+       ao_lcd_send_nibble(1, data & 0x0f);
+}
+
+void
+ao_lcd_send_string(char *string)
+{
+       uint8_t c;
+
+       while ((c = (uint8_t) *string++))
+               ao_lcd_send_data(c);
+}
+
+#define AO_LCD_POWER_CONTROL   0x54
+
+void
+ao_lcd_contrast_set(uint8_t contrast)
+{
+       ao_lcd_send_ins(AO_LCD_POWER_CONTROL | ((contrast >> 4) & 0x3));
+       ao_lcd_send_ins(0x70 | (contrast & 0xf));
+}
+
+void
+ao_lcd_clear(void)
+{
+       ao_lcd_send_ins(0x01);
+       ao_delay(1);
+       /* Entry mode */
+       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);
+
+       /* function set */
+       ao_lcd_send_ins(0x28);
+       /* function set, instruction table 1 */
+       ao_lcd_send_ins(0x29);
+
+       /* freq set */
+       ao_lcd_send_ins(0x14);
+
+       /* Power/icon/contrast control*/
+       ao_lcd_send_ins(AO_LCD_POWER_CONTROL);
+
+       /* Follower control */
+       ao_lcd_send_ins(0x6d);
+       ao_delay(AO_MS_TO_TICKS(200));
+
+       /* contrast set */
+       ao_lcd_contrast_set(0x18);
+
+       /* Display on */
+       ao_lcd_send_ins(0x08 | 0x04);
+
+       /* Clear */
+       ao_lcd_clear();
+
+}
+
+void
+ao_lcd_contrast(void)
+{
+       ao_cmd_hex();
+       if (ao_cmd_status == ao_cmd_success) {
+               printf("setting contrast to %02x\n", ao_cmd_lex_i);
+               ao_lcd_contrast_set(ao_cmd_lex_i & 0x3f);
+       }
+}
+
+void
+ao_lcd_string(void)
+{
+       ao_lcd_clear();
+       ao_cmd_white();
+       while (ao_cmd_lex_c != '\n') {
+               ao_lcd_send_data(ao_cmd_lex_c);
+               ao_cmd_lex();
+       }
+}
+
+__code struct ao_cmds ao_lcd_cmds[] = {
+       { ao_lcd_start, "S\0Start LCD" },
+       { ao_lcd_contrast, "C\0Set LCD contrast" },
+       { ao_lcd_string, "s\0Send string to LCD" },
+       { 0, NULL },
+};
+
+void
+ao_lcd_init(void)
+{
+       DDRB = (1 << PIN_RS) | (1 << PIN_E) | (1 << PIN_RW);
+       PORTB = 0;
+       ao_cmd_register(&ao_lcd_cmds[0]);
+}
index 8b33a1bd556263987de8e0d85d83071ee84e90e2..d23990a24e8181b0e9ee00ba111b2a34f33e067f 100644 (file)
@@ -45,7 +45,8 @@ ALTOS_SRC = \
        ao_task.c \
        ao_timer.c \
        ao_led.c \
-       ao_usb_avr.c
+       ao_usb_avr.c \
+       ao_lcd.c
 
 PRODUCT=AvrDemo-v0.0
 MCU=atmega32u4
index 2618ee066292375660157e72aeb7305f759d99ae..41580d8d18294cc4266a822d493beac8d6b5ef76 100644 (file)
@@ -18,7 +18,7 @@ DUDECPUTYPE=m32u4
 PROGRAMMER=usbtiny
 LOADCMD=avrdude
 LOADARG=-p $(DUDECPUTYPE) -c $(PROGRAMMER) -e -U flash:w:
-CC=avr-gcc
+CC=avr-gcc -v
 OBJCOPY=avr-objcopy
 
 ifndef VERSION
index 3eec3980f6ce9aff2da1fdb0f34ba4a5100194e6..74c986d8349027426c17b528226e7ded66078197 100644 (file)
@@ -6,7 +6,7 @@ CC=sdcc
 
 include Version
 
-SUBDIRS=\
+SUBDIRS=teletest-v1.1 \
        telemetrum-v1.1 telemetrum-v1.0 \
        teledongle-v0.2 teledongle-v0.1 \
        telemini-v0.1 telenano-v0.1 \
index c86de8236c096ef1bc00f605b7bdca3a812eb282..a49a920681005cfd98fea9e0c2f527f86122c881 100644 (file)
@@ -237,6 +237,34 @@ TNANO_BASE_SRC = \
        $(TNANO_TASK_SRC) \
        $(TNANO_MAIN_SRC)
 
+
+#
+# Sources for TeleTest
+#
+
+#
+# Drivers only on TeleTest
+#
+TTEST_DRIVER_SRC = \
+       ao_adc_usb.c \
+       ao_gps_report.c \
+       ao_ignite.c \
+       $(BEEP_DRIVER_SRC) \
+       $(USB_DRIVER_SRC)
+
+TTEST_MAIN_SRC = \
+       ao_telemetrum.c
+
+TTEST_BASE_SRC = \
+       $(ALTOS_SRC) \
+       $(ALTOS_DRIVER_SRC) \
+       $(TELE_DRIVER_SRC) \
+       $(SERIAL_DRIVER_SRC) \
+       $(TELE_COMMON_SRC) \
+       $(TTEST_DRIVER_SRC) \
+       $(TM_TASK_SRC) \
+       $(TM_MAIN_SRC)
+
 #
 # Sources for TeleBluetooth
 #
index 822a20b81f04c777ffb26eee50ed49dcd640fb70..234e7255c67cef46aecf7ad924486178a78c3ebc 100644 (file)
@@ -102,7 +102,7 @@ ao_flight(void)
                        {
                                /* Set pad mode - we can fly! */
                                ao_flight_state = ao_flight_pad;
-#if HAS_USB
+#if HAS_USB && !HAS_USB_TEST
                                /* Disable the USB controller in flight mode
                                 * to save power
                                 */
index 86389c174119f91fa5384fe2dec6653f9a803c77..8f637832bedb2b601a129660489df8108caa0f97 100644 (file)
        #define ASCENT_SIGNAL_PIN       2
 #endif
 
+#if defined(TELETEST_V_1_1)
+       #define HAS_FLIGHT              1
+       #define HAS_USB                 1
+       #define HAS_USB_TEST            1
+       #define HAS_BEEP                1
+       #define HAS_GPS                 1
+       #define HAS_SERIAL_1            1
+       #define USE_SERIAL_STDIN        0
+       #define HAS_ADC                 1
+       #define HAS_EEPROM              1
+       #define USE_INTERNAL_FLASH      0
+       #define HAS_DBG                 1
+       #define DBG_ON_P1               1
+       #define DBG_ON_P0               0
+       #define IGNITE_ON_P2            1
+       #define IGNITE_ON_P0            0
+       #define PACKET_HAS_MASTER       0
+       #define PACKET_HAS_SLAVE        1
+
+       #define AO_LED_RED              1
+       #define LEDS_AVAILABLE          (AO_LED_RED)
+       #define HAS_EXTERNAL_TEMP       0
+       #define HAS_ACCEL_REF           1
+       #define SPI_CS_ON_P1            1
+       #define SPI_CS_ON_P0            0
+       #define M25_CS_MASK             0x02    /* CS0 is P1_1 */
+       #define M25_MAX_CHIPS           1
+       #define HAS_ACCEL               1
+       #define HAS_IGNITE              1
+
+       #define ASCENT_SIGNAL           P1_2    /* Use CS1 to signal ascent */
+       #define ASCENT_SIGNAL_DIR       P1DIR
+       #define ASCENT_SIGNAL_SEL       P1SEL
+       #define ASCENT_SIGNAL_PIN       2
+#endif
+
 #if defined(TELEDONGLE_V_0_2)
        #define HAS_FLIGHT              0
        #define HAS_USB                 1