diff --git a/misc/Foenix Scan Code 1 Mapping.ods b/misc/Foenix Scan Code 1 Mapping.ods new file mode 100644 index 0000000..a21581d Binary files /dev/null and b/misc/Foenix Scan Code 1 Mapping.ods differ diff --git a/src/dev/Makefile b/src/dev/Makefile index 53d775b..00668d0 100644 --- a/src/dev/Makefile +++ b/src/dev/Makefile @@ -37,7 +37,7 @@ else ifeq ($(UNIT),F256) AS=as65816 AR=nlib - SRCS_FOR_UNIT=txt_f256.c indicators_c256.c interrupts_f256.c # timers_c256.c + SRCS_FOR_UNIT=txt_f256.c kbd_f256k.c indicators_c256.c interrupts_f256.c # timers_c256.c CFLAGS_FOR_UNIT=-DMODEL=2 -DCPU=255 --code-model large --data-model large # --target Foenix endif @@ -45,7 +45,7 @@ INCLUDES=-I.. -I../include CFLAGS=$(INCLUDES) $(CFLAGS_FOR_UNIT) -l ASFLAGS=$(INCLUDES) -SRCS = block.c channel.c console.c fsys.c txt_screen.c uart.c $(SRCS_FOR_UNIT) # pata.c bitmap.c dma.c ps2.c sdc.c rtc.c +SRCS = block.c channel.c console.c fsys.c txt_screen.c rtc.c uart.c $(SRCS_FOR_UNIT) # pata.c bitmap.c dma.c ps2.c sdc.c OBJS = $(patsubst %.c,%.o,$(SRCS)) OBJS4RM = $(subst /,\\,$(OBJS)) diff --git a/src/dev/kbd_f256k.c b/src/dev/kbd_f256k.c index 20507d2..da756a1 100644 --- a/src/dev/kbd_f256k.c +++ b/src/dev/kbd_f256k.c @@ -9,11 +9,16 @@ * */ +#include "log.h" +#include "ring_buffer.h" #include "dev/kbd_f256k.h" #include "F256/via_f256.h" #include #include +#include +#include "uart.h" + // // Constants // @@ -26,15 +31,25 @@ // Map a key's matrix position to its scan code (FoenixMCP scan codes are used here) // -static const uint8_t kbd_scan_codes[KBD_COLUMNS][KBD_ROWS] = { - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} +// PB0 PB1 PB2 PB3 PB4 PB5 PB6 PB7 PB8 +// PA0 DELETE RETURN LEFT F7 F1 F3 F5 UP DOWN +// PA1 3 W A 4 Z S E L-SHIFT +// PA2 5 R D 6 C F T X +// PA3 7 Y G 8 B H U V +// PA4 9 I J 0 M K O N +// PA5 - P L CAPS . : [ , +// PA6 = ] ' HOME R-SHIFT ALT TAB / RIGHT +// PA7 1 BKSP CTRL 2 SPACE Foenix Q RUN/STOP + +static const uint8_t kbd_scan_codes[KBD_ROWS][KBD_COLUMNS] = { + {0x65, 0x1c, 0x69, 0x41, 0x3b, 0x3d, 0x3f, 0x68, 0x6a}, + {0x04, 0x11, 0x1e, 0x05, 0x2c, 0x1f, 0x12, 0x2a, 0x00}, + {0x06, 0x13, 0x20, 0x07, 0x2e, 0x21, 0x14, 0x2d, 0x00}, + {0x08, 0x15, 0x22, 0x09, 0x30, 0x23, 0x16, 0x2f, 0x00}, + {0x0a, 0x17, 0x24, 0x0b, 0x32, 0x25, 0x18, 0x31, 0x00}, + {0x0c, 0x19, 0x26, 0x3a, 0x34, 0x27, 0x1a, 0x33, 0x00}, + {0x0d, 0x1b, 0x28, 0x63, 0x36, 0x5c, 0x0f, 0x35, 0x6b}, + {0x02, 0x01, 0x1d, 0x03, 0x39, 0x5b, 0x10, 0x61, 0x00} }; // @@ -44,16 +59,7 @@ static const uint8_t kbd_scan_codes[KBD_COLUMNS][KBD_ROWS] = { static uint8_t kbd_stat[KBD_MATRIX_SIZE]; static short counter = 0; static uint8_t last_press = 0; - -// PB0 PB1 PB2 PB3 PB4 PB5 PB6 PB7 PB8 -// PA7 1 <== CTRL RUN SPC F Q 2 -// PA1 3 W A L-SHIFT Z S E 4 -// PA2 5 R D X C F T 6 -// PA3 7 Y G V B H U 8 -// PA4 9 I J N M K O 0 -// PA5 + P L , . : @ CAPS -// PA6 - * ; / R-SHIFT ALT TAB HOME RIGHT -// PA0 DEL RETURN LEFT UP F1 F3 F5 F7 DOWN +static t_word_ring scan_code_buffer; /** * @brief Get the keys selected in a given column @@ -65,15 +71,19 @@ static uint8_t kbd_get_rows(short column) { uint8_t result = 0x00; if (column > 7) { + via0->pb = 0x00; + result = via1->pa; via0->pb = 0x80; - result = via1->pa; - via0->pb = 0; } else { - via1->pb = 0x01 << column; + via1->pb = ~(0x01 << column); result = via1->pa; - via1->pb = 0; + via1->pb = 0xff; } + char message[80]; + sprintf(message, "Row: %02X, %02X", result, column); + uart_writeln(0, message); + return result; } @@ -85,7 +95,7 @@ static uint8_t kbd_get_rows(short column) { * @param is_pressed TRUE, the key is down... FALSE, the key is up */ static void kbd_process_key(short column, short row, bool is_pressed) { - uint8_t scan_code = kbd_scan_codes[column][row]; + uint8_t scan_code = kbd_scan_codes[row][column]; if (scan_code != 0) { if (!is_pressed) { if (last_press == scan_code) { @@ -101,7 +111,23 @@ static void kbd_process_key(short column, short row, bool is_pressed) { last_press = scan_code; } - // TODO: queue the scan code + if (!rb_word_full(&scan_code_buffer)) { + rb_word_put(&scan_code_buffer, (unsigned short)scan_code); + } + } +} + +/* + * Try to retrieve the next scancode from the keyboard. + * + * Returns: + * The next scancode to be processed, 0 if nothing. + */ +unsigned short kbd_get_scancode() { + if (rb_word_empty(&scan_code_buffer)) { + return 0; + } else { + return rb_word_get(&scan_code_buffer); } } @@ -154,4 +180,9 @@ short kbd_init() { for (short i = 0; i < KBD_MATRIX_SIZE; i++) { kbd_stat[i] = 0; } + + // Set up and clear out the buffer for the scan codes + rb_word_init(&scan_code_buffer); + + return 1; } diff --git a/src/dev/kbd_f256k.h b/src/dev/kbd_f256k.h index 8876ee8..fc23115 100644 --- a/src/dev/kbd_f256k.h +++ b/src/dev/kbd_f256k.h @@ -18,6 +18,14 @@ */ extern void kbd_handle_irq(); +/* + * Try to retrieve the next scancode from the keyboard. + * + * Returns: + * The next scancode to be processed, 0 if nothing. + */ +extern unsigned short kbd_get_scancode(); + /* * Initialize the matrix keyboard * diff --git a/src/dev/rtc.c b/src/dev/rtc.c index d908502..2c170a2 100644 --- a/src/dev/rtc.c +++ b/src/dev/rtc.c @@ -259,6 +259,6 @@ SYSTEMCALL void rtc_get_time(p_time time) { * the number of jiffies since the last reset */ long rtc_get_jiffies() { - return timers_jiffies(); + return 0; // timers_jiffies(); } diff --git a/src/include/F256/via_f256.h b/src/include/F256/via_f256.h index 65daefb..b069884 100644 --- a/src/include/F256/via_f256.h +++ b/src/include/F256/via_f256.h @@ -52,8 +52,6 @@ typedef struct via_s { #define VIA_INT_IRQ 0x80 #define via0 ((volatile __attribute__((far)) via_p)0xf01c00) -#if MODEL == MODEL_FOENIX_F256K || MODEL ==MODEL_FOENIX_F256K2 #define via1 ((volatile __attribute__((far)) via_p)0xf01b00) -#endif #endif diff --git a/src/include/rtc_reg.h b/src/include/rtc_reg.h index 1359ef8..66c2aff 100644 --- a/src/include/rtc_reg.h +++ b/src/include/rtc_reg.h @@ -27,7 +27,7 @@ #define RTC_CTRL ((volatile unsigned char *)0xFEC0008E) #define RTC_CENTURY ((volatile unsigned char *)0xFEC0008F) -#elif MODEL_FOENIX_A2560U || MODEL == MODEL_FOENIX_A2560U_PLUS +#elif MODEL == MODEL_FOENIX_A2560U || MODEL == MODEL_FOENIX_A2560U_PLUS #define RTC_BASE ((volatile unsigned char *)0x00B00080) #define RTC_SEC ((volatile unsigned char *)0x00B00080) diff --git a/src/toolbox.c b/src/toolbox.c index 49e34a4..4aaeeba 100644 --- a/src/toolbox.c +++ b/src/toolbox.c @@ -34,6 +34,7 @@ #include "dev/txt_evid.h" #elif MODEL == MODEL_FOENIX_F256 || MODEL == MODEL_FOENIX_F256K || MODEL == MODEL_FOENIX_F256K2 #include "dev/txt_f256.h" +#include "dev/kbd_f256k.h" #endif #include "syscalls.h" @@ -133,7 +134,7 @@ void initialize() { #error Cannot identify screen setup #endif - printf("Foenix Toolbox v%d.%02d.%04d starting up...\n", VER_MAJOR, VER_MINOR, VER_BUILD); + printf("Foenix Toolbox v%d.%02d.%04d starting up...\nHello, F256k!\n", VER_MAJOR, VER_MINOR, VER_BUILD); INFO("Text system initialized."); // // Initialize the bitmap system @@ -178,9 +179,21 @@ void initialize() { // timers_init(); // INFO("Timers initialized"); -// /* Initialize the real time clock */ -// rtc_init(); -// INFO("Real time clock initialized"); + /* Initialize the real time clock */ + rtc_init(); + INFO("Real time clock initialized"); + + t_time time; + time.year = 2024; + time.month = 6; + time.day = 24; + time.hour = 22; + time.minute = 0; + time.second = 0; + rtc_set_time(&time); + + rtc_get_time(&time); + INFO3("%04d-%02d-%02d", time.year, time.month, time.day); // target_jiffies = sys_time_jiffies() + 300; /* 5 seconds minimum */ // DEBUG1("target_jiffies assigned: %d", target_jiffies); @@ -259,6 +272,12 @@ void initialize() { // } } +char dec2hex(uint8_t x) { + char * hex_digits = "0123456789ABCDEF"; + + return hex_digits[x & 0x0f]; +} + int main(int argc, char * argv[]) { short result; short i; @@ -266,6 +285,16 @@ int main(int argc, char * argv[]) { initialize(); + // while (1) { + // kbd_handle_irq(); + // unsigned short scan_code = kbd_get_scancode(); + // if (scan_code != 0) { + // tvky_text_matrix[0] = dec2hex((scan_code & 0xf0) >> 4); + // tvky_text_matrix[1] = dec2hex(scan_code & 0x0f); + // tvky_text_matrix[2] += 1; + // } + // } + // Attempt to start up the user code // log(LOG_INFO, "Looking for user startup code:"); // boot_launch();