#ifndef __SERIAL_H__
#define __SERIAL_H__

#define SERIAL_DTR 0
#define SERIAL_RTS 1

struct baud_code {
  int baud;
  int code;
};

struct ring_buf {
  char data[4096];
  unsigned int start;
  unsigned int size;
};

struct serial_device {
  int fd;
  struct ring_buf in_buf;
  struct ring_buf out_buf;
};

extern const struct baud_code baud_codes[];

int serial_open(struct serial_device *port, const char *path, int baud);
void serial_close(struct serial_device *port);
int serial_setbaud(struct serial_device *port, int baud);
void serial_setline(struct serial_device *port, int line, int state);
int serial_read(struct serial_device *port, char *buf, int len, int timeout);
void serial_write(struct serial_device *port, const char *text);

#endif