123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- /*
- RemdesKVM USB-KVM
- Firmware for PCB design v4 or above
- Author: tobychui
- Upload Settings
- CH552G
- 24Mhz (Internal)
- */
- #include <Serial.h>
- uint8_t c = 0x00;
- // Send a CH9329 cmd via UART0
- void send_cmd(uint8_t cmd, uint8_t* data, uint8_t length) {
- uint8_t sum = 0;
- Serial0_write(0x57);
- sum += 0x57;
- Serial0_write(0xAB);
- sum += 0xAB;
- Serial0_write(0x00);
- Serial0_write(cmd);
- sum += cmd;
- Serial0_write(length);
- sum += length;
- for (int i = 0; i < length; i++) {
- Serial0_write(data[i]);
- sum += data[i];
- }
- Serial0_write(sum);
- }
- // flush the serial RX (blocking)
- void flush_cmd_resp() {
- delay(100);
- while (Serial0_available()) {
- uint8_t b = Serial0_read();
- USBSerial_print("0x");
- if (b < 0x10) USBSerial_print("0");
- USBSerial_print(b, HEX);
- USBSerial_print(" ");
- }
- USBSerial_println("");
- }
- // Set the USB descriptor exposed to the slave device
- void setup_keyboard_chip_cfg() {
- //Set manufacturer string
- uint8_t manufacturer_string[9] = { 0x00, 0x07, 'i', 'm', 'u', 's', 'l', 'a', 'b' };
- send_cmd(0x0B, manufacturer_string, 9);
- flush_cmd_resp();
- //Set product string
- uint8_t product_string[11] = { 0x01, 0x09, 'R', 'e', 'm', 'd', 'e', 's', 'K', 'V', 'M' };
- send_cmd(0x0B, product_string, 11);
- flush_cmd_resp();
- }
- //This function handles the incoming data from CH9329
- void handle_cmd_processing() {
- }
- //This function will handle the incoming cmd from RemdesKVM control software
- //return 0x00 if success and 0x01 if error
- void handle_ctrl_cmd() {
- }
- void setup() {
- //Serial0_begin(9600); // CH9329 UART default baudrate (uncomment this before running -cfgchip)
- Serial0_begin(19200);
- delay(100);
- setup_keyboard_chip_cfg();
- }
- void loop() {
- // Read characters into buffer
- if (USBSerial_available()) {
- c = USBSerial_read();
- Serial0_write(c);
- }
- if (Serial0_available()) {
- c = Serial0_read();
- USBSerial_write(c);
- }
- }
|