I was doing some experimentation with the serial API and I found that if you send bitmap
too quickly the Playdate crashes.
You can use this C program to reproduce (if you're on a posix based system):
#define _DEFAULT_SOURCE
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <termios.h>
#include <unistd.h>
int main(int argc, char *argv[]) {
if (argc < 2) {
printf("No port was given.\n");
return 1;
}
const char *portname = argv[1];
int fd = open(portname, O_RDWR | O_NOCTTY);
if (fd == -1) {
perror("Error opening serial port");
return 1;
}
struct termios tty;
memset(&tty, 0, sizeof tty);
if (tcgetattr(fd, &tty) != 0) {
perror("Error getting terminal attributes");
close(fd);
return 1;
}
cfsetospeed(&tty, B115200);
cfsetispeed(&tty, B115200);
tty.c_cflag &= ~PARENB;
tty.c_cflag &= ~CSTOPB;
tty.c_cflag &= ~CSIZE;
tty.c_cflag |= CS8;
tty.c_cflag &= ~CRTSCTS;
tty.c_cflag |= CREAD | CLOCAL;
tty.c_lflag &= ~ICANON;
tty.c_lflag &= ~ECHO;
tty.c_lflag &= ~ECHOE;
tty.c_lflag &= ~ECHONL;
tty.c_lflag &= ~ISIG;
tty.c_iflag &= ~(IXON | IXOFF | IXANY);
tty.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL);
tty.c_oflag |= OPOST;
tty.c_oflag |= ONLCR;
if (tcsetattr(fd, TCSANOW, &tty) != 0) {
perror("Error setting terminal attributes");
close(fd);
return 1;
}
unsigned int t = 0;
while (1) {
char msg[12007] = "bitmap\n";
for (int i = t; i < t + 500; i++)
msg[i + 7] = 0b11111111;
int n = write(fd, msg, 12007);
if (n < 0) {
perror("Error writing to serial port");
close(fd);
return 1;
}
t += 1;
if (t > 11000) t = 0;
}
close(fd);
return 0;
}