9void ringbuffer_add_byte(
struct ringbuffer *r, uint8_t b) {
10 uint16_t size = bufsize(r);
12 if (r->writeptr >= size) {
15 r->buf[r->writeptr] = b;
19uint16_t ringbuffer_get_byte(
struct ringbuffer *r) {
20 uint16_t size = bufsize(r);
22 if (r->readptr >= size) {
28 uint8_t res = r->buf[r->readptr];
31 uint16_t foo = (uint16_t)res;
33 mculib_disable_irq(2);
46int ringbuffer_get_to_delimiter(
struct ringbuffer *r,
char delimiter,
char *outbuf,
int outbufsize) {
47 uint16_t size = bufsize(r);
48 uint16_t readptr = r->readptr;
49 uint32_t bytes = r->bytes;
53 if (readptr >= size) {
60 uint8_t res = r->buf[readptr];
63 if ((res == delimiter) || (delimiter ==
'\r' && res ==
'\n') || (delimiter ==
'\n' && res ==
'\r')) {
65 if (readptr >= size) {
70 mculib_disable_irq(2);
71 r->bytes = r->bytes - linelen;
79 outbuf[linelen++] = res;
81 if (linelen >= outbufsize) {