demo of driving MAX2719 dot matrix displays with STM32F103 Bluepill
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
f103-dotmatrix/project/main.c

181 lines
2.7 KiB

#include "main.h"
#include "hw_init.h"
#include "com/debug.h"
#include "com/com_fileio.h"
#include "com/com_iface.h"
#include "bus/event_queue.h"
#include "bus/event_handler.h"
#include "utils/timebase.h"
#include "colorled.h"
#include "display.h"
#include <math.h>
//#include <sbmp.h>
#include "dotmatrix.h"
9 years ago
9 years ago
#include <arm_math.h>
#include "mode_audio.h"
9 years ago
#include "mode_snake.h"
#include "mode_life.h"
#include "scrolltext.h"
/** Functional mode */
typedef enum {
MODE_AUDIO,
MODE_LIFE,
MODE_SNAKE,
MODE_END,
} GameMode;
9 years ago
static void poll_subsystems(void);
static void gamepad_rx(ComIface *iface);
static void switch_mode(void *unused); // circle b/w modes
static void activate_mode(void); // activate currently selected mode
static GameMode app_mode;
static void switch_mode(void *unused)
9 years ago
{
(void)unused;
if (++app_mode == MODE_END) {
app_mode = 0;
}
activate_mode();
9 years ago
// discard buffer
uint8_t x;
while(com_rx(gamepad_iface, &x));
}
9 years ago
#define SCROLL_STEP 22
static void activate_mode(void)
{
// --- Audio FFT mode ---
if (app_mode == MODE_AUDIO) {
info("MODE: Audio");
9 years ago
scrolltext("AUDIO", SCROLL_STEP);
mode_audio_start();
} else {
mode_audio_stop();
}
// --- Game Of Life ---
if (app_mode == MODE_LIFE) {
info("MODE: Life");
9 years ago
scrolltext("CONWAY", SCROLL_STEP);
9 years ago
mode_life_start();
} else {
9 years ago
mode_life_stop();
}
// --- Snake Minigame ---
if (app_mode == MODE_SNAKE) {
info("MODE: Snake");
9 years ago
scrolltext("SNAKE", SCROLL_STEP);
9 years ago
mode_snake_start();
} else {
9 years ago
mode_snake_stop();
9 years ago
}
}
9 years ago
int main(void)
{
hw_init();
9 years ago
9 years ago
banner("*** FFT dot matrix display ***");
banner_info("(c) Ondrej Hruska, 2016");
9 years ago
gamepad_iface->rx_callback = gamepad_rx;
9 years ago
mode_audio_init();
9 years ago
mode_life_init();
mode_snake_init();
mode_audio_start();
ms_time_t last;
9 years ago
while (1) {
9 years ago
if (ms_loop_elapsed(&last, 500)) {
GPIOC->ODR ^= 1 << 13;
}
9 years ago
poll_subsystems();
}
}
9 years ago
9 years ago
static void poll_subsystems(void)
{
// poll serial buffers (runs callback)
com_poll(debug_iface);
//com_poll(data_iface);
com_poll(gamepad_iface);
// run queued tasks
tq_poll();
// handle queued events
Event evt;
until_timeout(2) { // take 2 ms max
if (eq_take(&evt)) {
run_event_handler(&evt);
} else {
break;
9 years ago
}
9 years ago
}
}
static void gamepad_rx(ComIface *iface)
{
9 years ago
char ch;
while(com_rx(iface, (uint8_t*)&ch)) {
switch (ch) {
case 'I': // Select pressed
tq_post(switch_mode, NULL);
break;
9 years ago
9 years ago
case 'i': // Select released
break;
default:
switch (app_mode) {
case MODE_AUDIO:
// discard
break;
case MODE_LIFE:
mode_life_btn(ch);
break;
case MODE_SNAKE:
mode_snake_btn(ch);
break;
}
}
}
}
//void dlnk_rx(SBMP_Datagram *dg)
//{
// (void)dg;
// //dbg("Rx dg type %d", dg->type);
//}