sxkbd

Firmware for RP2040-based corne split keyboard
git clone https://git.sinitax.com/sinitax/sxkbd
Log | Files | Refs | Submodules | README | LICENSE | sfeed.txt

usb_stdio.c (776B)


      1#include "usb_stdio.h"
      2
      3#include "pico/stdio.h"
      4#include "pico/stdio/driver.h"
      5#include "tusb.h"
      6
      7static void usb_stdio_write(const char *buf, int len);
      8static void usb_stdio_flush(void);
      9static int usb_stdio_read(char *buf, int len);
     10
     11static struct stdio_driver usb_stdio = {
     12	.out_chars = usb_stdio_write,
     13	.out_flush = usb_stdio_flush,
     14	.in_chars = usb_stdio_read,
     15	.next = NULL
     16};
     17
     18void
     19usb_stdio_write(const char *buf, int len)
     20{
     21	tud_cdc_write(buf, (uint32_t) len);
     22}
     23
     24void
     25usb_stdio_flush(void)
     26{
     27	tud_cdc_write_flush();
     28	tud_task();
     29}
     30
     31int
     32usb_stdio_read(char *buf, int len)
     33{
     34	return (int) tud_cdc_read(buf, (uint32_t) len);
     35}
     36
     37void
     38usb_stdio_init(void)
     39{
     40	stdio_set_driver_enabled(&usb_stdio, true);
     41	stdio_set_translate_crlf(&usb_stdio, true);
     42	stdio_init_all();
     43}