Commits

Trammell Hudson committed edd2d80 Draft

Moved key rows to PORTA

Comments (0)

Files changed (1)

 #define LCD_CS28	0xE6
 #define LCD_CS29	0xE7
 
-// Shared with LCD data and chip select lines
-#define KEY_ROWS_PIN	PINC
-#define KEY_ROWS_DDR	DDRC
-#define KEY_ROWS_PORT	PORTC
+// Can not be shared with the LCD
+#define KEY_ROWS_PIN	PINA
+#define KEY_ROWS_DDR	DDRA
+#define KEY_ROWS_PORT	PORTA
 
+// Shared with LCD chip select lines
 #define KEY_COLS_PIN	PINF
 #define KEY_COLS_DDR	DDRF
 #define KEY_COLS_PORT	PORTF
 }
 
 
+static uint8_t cur_col;
+static uint8_t cur_row;
+
+static void
+lcd_putc(
+	char c
+)
+{
+	if (c == '\e')
+	{
+		lcd_clear();
+		cur_row = cur_col = 0;
+	} else
+	if (c == '\n')
+	{
+		goto new_row;
+	} else {
+		lcd_char(cur_col, cur_row, c);
+		if (++cur_col == 40)
+			goto new_row;
+	}
+
+	return;
+
+new_row:
+	cur_row = (cur_row + 1) % 8;
+	cur_col = 0;
+}
+
+
 static void
 redraw(void)
 {
 	redraw();
 
 	uint8_t last_key = 0;
-	uint8_t cur_row = 0;
-	uint8_t cur_col = 0;
 
 	char buf[16];
 	int off = 0;
 		int c = usb_serial_getchar();
 		if (c != -1)
 		{
+			lcd_putc(c);
 			usb_serial_putchar(c);
 			if (c == '+')
 			{
 				buf[off++] = '\n';
 				usb_serial_write(buf, off);
 			}
-
-			if (c == ' ')
-				redraw();
 		}
 
 		uint8_t key = keyboard_scan();
 		if (key != last_key)
 		{
 			last_key = key;
+			lcd_putc(key);
+
 			if (key == '\n')
-			{
-				usb_serial_putchar('\n');
 				usb_serial_putchar('\r');
-				cur_row = (cur_row + 1) % 8;
-				cur_col = 0;
-			} else
-			if (key == '\e')
-			{
-				lcd_clear();
-				cur_row = cur_col = 0;
-			} else {
-				usb_serial_putchar(key);
-				lcd_char(cur_col, cur_row, key);
-				if (++cur_col == 40)
-				{
-					cur_row = (cur_row + 1) % 8;
-					cur_col = 0;
-				}
-			}
+			usb_serial_putchar(key);
 		}
 
 		if (bit_is_clear(TIFR0, OCF0A))