Build a power-of-two ring buffer for UART RX.
Ring buffers are everywhere in firmware (UART RX, sensor sampling, audio).
```c
#define RB_SIZE 16
static unsigned char buf[RB_SIZE];
static unsigned int head = 0, tail = 0;
int rb_push(unsigned char b); // -1 if full
int rb_pop(unsigned char *out); // -1 if empty
```
Use `(head + 1) & (RB_SIZE - 1)` for wrap-around (RB_SIZE must be a power of two).
Sign in to save your code and track progress across devices.