/** * Reopen a usb-serial port. */ static struct KFile *usb_serial_reopen(struct KFile *fd) { USBSerial *fds = USB_SERIAL_CAST(fd); usb_serial_close(fd); usb_serial_open(fds, fds->unit); return 0; }
/** * Init serial driver for a usb-serial port \a unit. * * \return 0 if OK, a negative value in case of error. */ int usbser_init(struct USBSerial *fds, int unit) { memset(fds, 0, sizeof(*fds)); DB(fds->fd._type = KFT_USB_SERIAL); fds->fd.reopen = usb_serial_reopen; fds->fd.close = usb_serial_close; fds->fd.read = usb_serial_read; fds->fd.write = usb_serial_write; /* TODO: properly implement error handling. */ fds->fd.error = usb_serial_error; fds->fd.clearerr = usb_serial_clearerr; return usb_serial_open(fds, unit); }
int usb_serial_stdio(char *name) { unsigned int subdevice; errno_r = 0; if (usb_serial_open(name, &subdevice)) return -1; // Nuke existing stdin, stdout, stderr device_unregister(0); device_unregister(1); device_unregister(2); // Register new stdin, stdout, stderr device_register_char_fd(0, subdevice, NULL, usb_serial_read, NULL, usb_serial_rxready); device_register_char_fd(1, subdevice, usb_serial_write, NULL, usb_serial_txready, NULL); device_register_char_fd(2, subdevice, usb_serial_write, NULL, usb_serial_txready, NULL); return 0; }