keyboard support: WIP builds, broken

This commit is contained in:
Jeff Epler 2024-09-26 13:09:08 -05:00
parent 8b5ed8297f
commit a996994e2d
6 changed files with 118 additions and 5 deletions

View file

@ -13,7 +13,7 @@ pico_sdk_init()
project(pico-cr100)
add_executable(cr100 chargen.c vt.c)
add_executable(cr100 chargen.c vt.c keyboard.c)
pico_enable_stdio_usb(cr100 1)

77
atkbd.pio Normal file
View file

@ -0,0 +1,77 @@
.program atkbd
.pio_version 0
.in 32 right auto
;.out 2 left auto
;.set 2
;; todo: use 'wait gpio' (or 'wait jmp' [rp2350]) so any pair of pins
;; can be used
;wait 1 pin 1 ; wait for keyboard to signal ready (not necessary?)
.wrap_target
start:
jmp !osre send_byte ; if a byte is pending to send, do that
jmp pin start ; otherwise wait for keyboard to send something
; keyboard has signaled start condition
set x 9 ; will receive 10 bits (data + parity + stop)
wait 1 pin 1 ; wait for clock pin to go high (discard start bit)
receive_bit:
wait 0 pin 1
in pins 1
wait 1 pin 1
jmp x-- receive_bit
jmp start
send_byte:
set pins 0 ; will be pulling lines low selectively
set pindirs 2 [31] ; pull clock low to request to send
set pindirs 1 ; set data pin to output & send "R" bit
set x 8 ; will send 9 bits (data + parity)
send_bit:
wait 0 pin 1
out pins 1
wait 1 pin 1
jmp x-- send_bit
set pindirs 0 ; pins back to input mode
wait 0 pin 0
wait 1 pin 0 ; wait for keyboard ACK
.wrap
% c-sdk {
#include "hardware/clocks.h"
void atkbd_program_init(PIO pio, int sm, int base_pin) {
pio_sm_config c = vga_660x400_70_program_get_default_config(offset);
sm_config_set_in_pins(&c, base_pin);
sm_config_set_in_shift(&c, 1, 1, 10);
sm_config_set_out_pins(&c, base_pin, 2);
sm_config_set_out_shift(&c, 0, 1, 9);
sm_config_set_set_pins(&c, base_pin, 2);
sm_config_set_jmp_pin(&c, base_pin + 1);
sm_config_set_clkdiv(&c, clock_get_hz(clk_sys() / 8000000); // 8 MHz
// Set this pin's GPIO function (connect PIO to the pad)
pio_gpio_init(pio, base_pin);
pio_gpio_init(pio, base_pin+1);
// make sure the pins are outputs
pio_sm_set_consecutive_pindirs(pio, sm, pin, 2, false);
// Load our configuration, and jump to the start of the program
pio_sm_init(pio, sm, offset, &c);
// Set the state machine running
pio_sm_set_enabled(pio, sm, true);
}
%}

View file

@ -1,10 +1,14 @@
#define _GNU_SOURCE
#include <stdint.h>
#include "pinout.h"
#include "keyboard.h"
#include "pico.h"
#include "pico/stdlib.h"
#include "pico/multicore.h"
#include "hardware/clocks.h"
#include "vga_660x477_60.pio.h"
#include "vt.h"
@ -157,10 +161,6 @@ int scrnprintf(const char *fmt, ...) {
uint16_t base_shade[] = {0, 0x554, 0xaa8, 0xffc, 0, 0x554, 0xaa8, 0xffc, 0, 0, 0, 0};
#if !STANDALONE
#define HSYNC_PIN (14)
#define VSYNC_PIN (17)
#define G0_PIN (15)
static void setup_vga_hsync(PIO pio) {
uint offset = pio_add_program(pio, &vga_660x477_60_hsync_program);
uint sm = pio_claim_unused_sm(pio, true);
@ -300,6 +300,8 @@ int main() {
}
multicore_launch_core1(core1_entry);
keyboard_setup();
attr = 0x300;
show_cursor();
while (true) {

19
keyboard.c Normal file
View file

@ -0,0 +1,19 @@
#include "atkbd.pio.h"
#include "keyboard.h"
#include "pinout.h"
#include "pico.h"
#include "pico/stdlib.h"
#include "hardware/clocks.h"
extern void keyboard_setup(PIO pio) {
uint offset = pio_add_program(pio, &atkbd_program);
uint sm = pio_claim_unused_sm(pio, true);
atkbd_program_init(pio, sm, offset, KEYBOARD_DATA_PIN);
}
extern void keyboard_poll(queue_t *q) {
}
extern void keyboard_leds(int value) {
}

7
keyboard.h Normal file
View file

@ -0,0 +1,7 @@
#pragma once
#include "pico/util/queue.h"
extern void keyboard_setup();
extern void keyboard_poll(queue_t *q);
extern void keyboard_leds(int value);

8
pinout.h Normal file
View file

@ -0,0 +1,8 @@
#pragma once
#define HSYNC_PIN (14)
#define VSYNC_PIN (17)
#define G0_PIN (15)
#define G1_PIN (G0_PIN + 1)
#define KEYBOARD_DATA_PIN (20)
#define KEYBOARD_CLOCK_PIN (KEYBOARD_DATA_PIN + 1)