Add lfsr pseudorandom

This commit is contained in:
hkz 2025-07-16 15:01:09 +02:00
commit 7d44a2b4a7
2 changed files with 11 additions and 0 deletions

View file

@ -13,6 +13,16 @@ uint8_t bit_count(uint8_t b) {
return b;
}
uint16_t lfsr_update(void) {
static uint16_t lfsr = 0xF00D;
uint16_t bit;
bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 5)) & 1;
lfsr = (lfsr >> 1) | (bit << 15);
return lfsr;
}
// Note that the horizontal values here are in group of 7 pixels
void clear_box(uint8_t w, uint8_t h, uint8_t off_x, uint8_t off_y, uint8_t *disp_buf) {
for(uint8_t y = off_y; y < off_y + h; y++) {

View file

@ -19,6 +19,7 @@
#define ARRAY_SIZE(x) (sizeof(x)/sizeof((x)[0]))
uint8_t bit_count(uint8_t b);
uint16_t lfsr_update(void);
void clear_box(uint8_t w, uint8_t h, uint8_t off_x, uint8_t off_y, uint8_t *disp_buf);
void draw_pic(uint16_t w, uint8_t h, uint8_t off_x, uint8_t off_y, const uint8_t *data, uint8_t *disp_buf);
void print_line(const char* line, uint8_t off_x, uint8_t off_y);