Nimbin[12]?Embedded / snake_compiler / snake_SDL/src/matrix.h

snake_compiler git · main

Snake compiled to a bare-metal RISC-V microcontroller

riscv embedded bare-metal c snake · first commit 2026-01-18 · last commit 2026-01-18 (8 months ago) · synced 3 days ago · upstream: git.ide3.de/hsnr/compilerbau/snake_compiler

C 95.2% Markdown 3.3%
git clone https://git.christianimmanuel.de/embedded/snake_compiler.gitwget https://git.christianimmanuel.de/embedded/snake_compiler/archive/snake_compiler.tar.gz
snake_SDL/src/matrix.h 1 KB · 77 lines raw
#ifndef MATRIX_H
#define MATRIX_H

#include <mdk.h>
#include <stdint.h>
#include <stdbool.h>


#include "defaults.h"
#include "snake.h"


typedef enum GameMode_e {
    NORMAL,
    FANCY,
    GAME_MODE_LAST,
} GameMode;


typedef enum PixelType_e {
    NONE,
    SNAKE,
    APPLE,
} PixelType;

typedef struct Pixel_s {
    Color color;
    PixelType type;
} Pixel;

typedef struct LEDMatrix_s {
    Pixel pixels[MATRIX_HEIGHT][MATRIX_WIDTH];
} LEDMatrix;

typedef struct {
    int pin;
    bool state_init;
    bool state_prev;
    bool state_curr;
} Button;


extern GameMode game_mode;

extern LEDMatrix* matrix;
extern Button*    button_1;
extern Button*    button_2;
extern Button*    button_3;
extern Button*    button_4;

int random_Int(int max);

void
matrix_Init(Color color);

void
matrix_SetPixelColor(int x, int y, Color c);

void 
matrix_ToMdkBuffer();

void
matrix_WriteLed();

void
matrix_ClearAll(Color color);

void
matrix_Blink(int count, unsigned long delay_millis);

void
matrix_Print();

void
matrix_Update();

#endif