You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to send characters through a serial connection to my Raspberry Pi Pico, and then have it control PS/2 output to emit corresponding characters. However, I'm encountering an issue where the PS/2 interface continuously emits the first character and cannot be stopped unless I disconnect the PS/2 device. Below is my program:
_#include <stdlib.h>
#include <stdio.h>
#include <string.h>
// ASCII to HID_KEY mapping table
typedef struct {
uint8_t hid_key; // HID key value
bool shift_required; // Whether Shift key is required
} HidKeyMap;
HidKeyMap convert_ascii_to_hid_key(char ascii) {
switch (ascii) {
// Lowercase letters (no Shift needed)
case 'a': return (HidKeyMap){HID_KEY_A, false};
case 'b': return (HidKeyMap){HID_KEY_B, false};
case 'c': return (HidKeyMap){HID_KEY_C, false};
// ... specify the same logic for other lowercase letters ...
case 'z': return (HidKeyMap){HID_KEY_Z, false};
// Uppercase letters (Shift needed)
case 'A': return (HidKeyMap){HID_KEY_A, true};
case 'B': return (HidKeyMap){HID_KEY_B, true};
case 'C': return (HidKeyMap){HID_KEY_C, true};
case '\n': return (HidKeyMap){HID_KEY_ENTER, false};
// Unknown character
default: return (HidKeyMap){0, false};
}
}
static int chars_rxed = 0;
// UART RX interrupt handler
void on_uart_rx() {
while (uart_is_readable(UART_ID)) {
char c = uart_getc(UART_ID);
if (uart_rx_index < UART_BUFFER_SIZE - 1) {
uart_rx_buffer[uart_rx_index++] = c;
uart_putc(UART_ID, c);
uart_data_ready = true; // Mark data as ready
}
}
uart_rx_buffer[uart_rx_index] = '\0'; // Ensure buffer ends with '\0'
}
I am trying to send characters through a serial connection to my Raspberry Pi Pico, and then have it control PS/2 output to emit corresponding characters. However, I'm encountering an issue where the PS/2 interface continuously emits the first character and cannot be stopped unless I disconnect the PS/2 device. Below is my program:
_#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "hardware/watchdog.h"
#include "hardware/gpio.h"
#include "hardware/uart.h"
#include "hardware/irq.h"
#include "bsp/board_api.h"
#include "tusb.h"
#include "ps2x2pico.h"
#include "ps2kb.h"
// UART configuration
#define UART_ID uart1
#define BAUD_RATE 115200
#define UART_TX_PIN 8
#define UART_RX_PIN 9
// Receive buffer
#define UART_BUFFER_SIZE 128
volatile char uart_rx_buffer[UART_BUFFER_SIZE];
volatile int uart_rx_index = 0;
volatile bool uart_data_ready = false;
// ASCII to HID_KEY mapping table
typedef struct {
uint8_t hid_key; // HID key value
bool shift_required; // Whether Shift key is required
} HidKeyMap;
HidKeyMap convert_ascii_to_hid_key(char ascii) {
switch (ascii) {
// Lowercase letters (no Shift needed)
case 'a': return (HidKeyMap){HID_KEY_A, false};
case 'b': return (HidKeyMap){HID_KEY_B, false};
case 'c': return (HidKeyMap){HID_KEY_C, false};
// ... specify the same logic for other lowercase letters ...
case 'z': return (HidKeyMap){HID_KEY_Z, false};
}
static int chars_rxed = 0;
// UART RX interrupt handler
void on_uart_rx() {
while (uart_is_readable(UART_ID)) {
char c = uart_getc(UART_ID);
if (uart_rx_index < UART_BUFFER_SIZE - 1) {
uart_rx_buffer[uart_rx_index++] = c;
uart_putc(UART_ID, c);
uart_data_ready = true; // Mark data as ready
}
}
uart_rx_buffer[uart_rx_index] = '\0'; // Ensure buffer ends with '\0'
}
// Initialize UART
void init_uart() {
uart_init(UART_ID, BAUD_RATE);
gpio_set_function(UART_TX_PIN, GPIO_FUNC_UART);
gpio_set_function(UART_RX_PIN, GPIO_FUNC_UART);
}
// Process UART input data
void process_uart_input() {
if (uart_data_ready) {
uart_data_ready = false; // Reset flag
}
int main() {
board_init();
}
void reset() {
printf("\n\n *** PANIC via tinyusb: watchdog reset!\n\n");
watchdog_enable(100, false);
}_
Could you please help me identify what might be causing this issue and suggest any potential fixes?
Thank you!
The text was updated successfully, but these errors were encountered: