Compare commits
17 Commits
Author | SHA1 | Date | |
---|---|---|---|
9003528897 | |||
2b34a3e51d | |||
e5381a8c9d | |||
8bd6197c02 | |||
f5b0e67056 | |||
19be1a6e48 | |||
05de9326d7 | |||
633fc814b2 | |||
88e0cff853 | |||
d3846c3e08 | |||
fb16cfaa6f | |||
cf62e0c0a0
|
|||
044779681b
|
|||
167617ad2c | |||
26db6bf03d | |||
a4adf6ac27 | |||
8da88e96c2
|
8
Makefile
8
Makefile
@ -4,14 +4,14 @@ OBJDUMP=$(TOOLCHAIN_PREFIX)/bin/msp430-elf-objdump
|
||||
|
||||
ARTIFACT=firmware
|
||||
MCU=msp430g2553
|
||||
CFLAGS=-Wall -mmcu=$(MCU) -std=gnu99 -I $(TOOLCHAIN_PREFIX)/include -O3 -g0
|
||||
CFLAGS=-Wall -mmcu=$(MCU) -std=gnu99 -I $(TOOLCHAIN_PREFIX)/include -O1 -g0
|
||||
|
||||
# for debugging
|
||||
#CFLAGS=-Wall -mmcu=$(MCU) -std=gnu99 -I $(TOOLCHAIN_PREFIX)/include -g3 -ggdb -gdwarf-2
|
||||
# CFLAGS+= -g3 -ggdb -gdwarf-2
|
||||
|
||||
LDFLAGS=-mmcu=$(MCU) -L $(TOOLCHAIN_PREFIX)/include
|
||||
|
||||
$(ARTIFACT).elf: main.o led.o time.o PontCoopScheduler.o displayDriver.o canvas.o displayTest.o
|
||||
$(ARTIFACT).elf: main.o led.o time.o PontCoopScheduler.o displayDriver.o canvas.o shapes.o shape_i.o shape_j.o shape_l.o shape_o.o shape_s.o shape_t.o shape_z.o game.o
|
||||
$(CC) -o $@ $(LDFLAGS) $^
|
||||
$(OBJDUMP) -D $(ARTIFACT).elf > $(ARTIFACT).txt
|
||||
|
||||
@ -24,7 +24,7 @@ all: $(ARTIFACT).elf
|
||||
|
||||
.PHONY: clean
|
||||
clean:
|
||||
-rm -f *.o *.elf
|
||||
-rm -f *.o $(ARTIFACT).elf $(ARTIFACT).txt
|
||||
|
||||
.PHONY: upload
|
||||
upload: $(ARTIFACT).elf
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <msp430g2553.h>
|
||||
|
||||
|
||||
#include "PontCoopScheduler.h"
|
||||
@ -15,7 +16,7 @@ tTask tasks[MAX_NUM_OF_TASKS];
|
||||
|
||||
|
||||
void schInit() {
|
||||
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
for (uint16_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
tasks[i].delay = 0;
|
||||
tasks[i].period = 0;
|
||||
tasks[i].run = 0;
|
||||
@ -25,7 +26,7 @@ void schInit() {
|
||||
}
|
||||
|
||||
void schAdd(void (*exec)(void *), void *handle, uint32_t delay, uint32_t period) {
|
||||
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
for (uint16_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
if (tasks[i].exec == NULL) {
|
||||
tasks[i].delay = delay;
|
||||
tasks[i].period = period;
|
||||
@ -41,23 +42,34 @@ void schAdd(void (*exec)(void *), void *handle, uint32_t delay, uint32_t period)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
void schDel(void (*exec)(void *), void *handle) {
|
||||
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
for (uint16_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
if ((tasks[i].exec == exec) && (tasks[i].handle == handle)) {
|
||||
tasks[i].exec = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void schExec() {
|
||||
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
for (uint16_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
// synchronize access to tasks[].run
|
||||
__disable_interrupt();
|
||||
if (tasks[i].exec != NULL && tasks[i].run > 0) {
|
||||
tasks[i].run--;
|
||||
// synchronize access to tasks[].run
|
||||
// reenable interrupts before actually executing task
|
||||
__enable_interrupt();
|
||||
tasks[i].exec(tasks[i].handle);
|
||||
if (tasks[i].period == 0) {
|
||||
tasks[i].exec = NULL;
|
||||
}
|
||||
} else {
|
||||
// synchronize access to tasks[].run
|
||||
// reenable interrupts in case task is not yet executable
|
||||
__enable_interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -65,7 +77,7 @@ void schExec() {
|
||||
|
||||
|
||||
void schUpdate() {
|
||||
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
for (uint16_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
if (tasks[i].exec != NULL) {
|
||||
if (tasks[i].delay == 0) {
|
||||
tasks[i].delay = tasks[i].period;
|
||||
@ -76,13 +88,3 @@ void schUpdate() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t schTaskCnt() {
|
||||
uint8_t cnt = 0;
|
||||
for (uint8_t i = 0; i < MAX_NUM_OF_TASKS; i++) {
|
||||
if (tasks[i].exec != NULL){
|
||||
cnt++;
|
||||
}
|
||||
}
|
||||
return cnt;
|
||||
}
|
@ -13,12 +13,12 @@
|
||||
|
||||
|
||||
|
||||
#define MAX_NUM_OF_TASKS 4
|
||||
#define MAX_NUM_OF_TASKS 2
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint32_t delay;
|
||||
uint32_t period;
|
||||
uint16_t delay;
|
||||
uint16_t period;
|
||||
uint8_t run;
|
||||
void (*exec)(void *handle);
|
||||
void *handle;
|
||||
|
46
canvas.c
46
canvas.c
@ -5,27 +5,51 @@
|
||||
#include "displayDriver.h"
|
||||
|
||||
|
||||
static canvas_t canvas;
|
||||
static uint8_t canvasStorage[CANVAS_WIDTH * CANVAS_HEIGHT];
|
||||
const canvas_t canvas = {
|
||||
.height = CANVAS_HEIGHT,
|
||||
.width = CANVAS_WIDTH,
|
||||
.size = CANVAS_WIDTH * CANVAS_HEIGHT,
|
||||
.canvas = canvasStorage
|
||||
};
|
||||
|
||||
void canvasInit() {
|
||||
canvas.height = CANVAS_HEIGHT;
|
||||
canvas.width = CANVAS_WIDTH;
|
||||
canvas.size = CANVAS_HEIGHT * CANVAS_WIDTH;
|
||||
canvas.canvas = canvasStorage;
|
||||
|
||||
// Bit7 signals need to be transfered for octet
|
||||
memset(canvasStorage, 0x80, canvas.size);
|
||||
|
||||
canvasClear();
|
||||
displayDriverTransferCanvas();
|
||||
}
|
||||
|
||||
canvas_t *canvasGet() {
|
||||
return &canvas;
|
||||
void canvasClear() {
|
||||
memset(canvas.canvas, 0x80, canvas.size);
|
||||
}
|
||||
|
||||
void canvasSetAll(uint8_t color) {
|
||||
memset(canvas.canvas, color + 0x80, canvas.size);
|
||||
}
|
||||
|
||||
void canvasShow() {
|
||||
displayDriverTransferCanvas();
|
||||
}
|
||||
|
||||
void canvasSetPixel(uint8_t column, uint8_t row, uint8_t color) {
|
||||
*((canvas.canvas) + (row * canvas.width + column)) = (color + 0x80);
|
||||
}
|
||||
|
||||
void canvasWipeRow(uint8_t row) {
|
||||
memmove(((canvas.canvas)+canvas.width), canvas.canvas, canvas.width*row);
|
||||
for (uint8_t i = 10; i < canvas.width*(row+1); i++) {
|
||||
*((canvas.canvas)+i) += 0x80;
|
||||
}
|
||||
memset(canvas.canvas, 0x80, canvas.width);
|
||||
}
|
||||
|
||||
uint8_t canvasIsRowFilled(uint8_t row) {
|
||||
uint8_t res = 1;
|
||||
for (uint8_t column = 0; column < canvas.width; column++) {
|
||||
if (*((canvas.canvas) + (row * canvas.width + column)) == 0) {
|
||||
res = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
|
18
canvas.h
18
canvas.h
@ -5,19 +5,23 @@
|
||||
|
||||
|
||||
#define CANVAS_WIDTH 10
|
||||
#define CANVAS_HEIGHT 6
|
||||
#define CANVAS_HEIGHT 11
|
||||
|
||||
typedef struct {
|
||||
uint8_t width;
|
||||
uint8_t height;
|
||||
uint8_t size;
|
||||
uint8_t *canvas;
|
||||
const uint8_t width;
|
||||
const uint8_t height;
|
||||
const uint8_t size;
|
||||
uint8_t * const canvas;
|
||||
} canvas_t;
|
||||
|
||||
void canvasInit();
|
||||
canvas_t *canvasGet();
|
||||
void canvasClear();
|
||||
void canvasSetAll(uint8_t color);
|
||||
void canvasShow();
|
||||
void canvasSetPixel(uint8_t column, uint8_t row, uint8_t color);
|
||||
void canvasWipeRow(uint8_t row);
|
||||
uint8_t canvasIsRowFilled(uint8_t row);
|
||||
|
||||
|
||||
extern const canvas_t canvas;
|
||||
|
||||
#endif // _CANVAS_H_
|
||||
|
22
colors.h
Normal file
22
colors.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef _COLORS_H_
|
||||
#define _COLORS_H_
|
||||
|
||||
|
||||
#define _off 0x00
|
||||
#define _blue 0x01
|
||||
#define _green 0x02
|
||||
#define _orange 0x03
|
||||
#define _rose 0x04
|
||||
#define _magenta 0x05
|
||||
#define _violet 0x06
|
||||
#define _azure 0x07
|
||||
#define _cyan 0x08
|
||||
#define _springgreen 0x09
|
||||
#define _chartreuse 0x0a
|
||||
#define _yellow 0x0b
|
||||
#define _white 0x0c
|
||||
#define _red 0x0d
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -7,7 +7,7 @@
|
||||
|
||||
|
||||
|
||||
static void spiSendOctet(uint8_t v) {
|
||||
inline static void spiSendOctet(uint8_t v) {
|
||||
// wait for TX buffer empty
|
||||
while (!(UC0IFG & UCB0TXIFG));
|
||||
// load octet into TX buffer
|
||||
@ -18,12 +18,11 @@ void displayDriverTransferCanvas() {
|
||||
// wait for signal waiting for data
|
||||
while ((P1IN & BIT3) == 0);
|
||||
|
||||
canvas_t *canvas = canvasGet();
|
||||
for (uint8_t i = 0; i < canvas->size; i++) {
|
||||
if ((*((canvas->canvas)+i) & 0x80) != 0) {
|
||||
*((canvas->canvas)+i) &= ~0x80;
|
||||
for (uint8_t i = 0; i < canvas.size; i++) {
|
||||
if ((*((canvas.canvas)+i) & 0x80) != 0) {
|
||||
*((canvas.canvas)+i) &= ~0x80;
|
||||
spiSendOctet(i);
|
||||
spiSendOctet(*((canvas->canvas)+i));
|
||||
spiSendOctet(*((canvas.canvas)+i));
|
||||
}
|
||||
}
|
||||
spiSendOctet(0xfe);
|
||||
@ -34,7 +33,11 @@ void displayDriverInit() {
|
||||
UCB0CTL0 = UCMST;
|
||||
// SPI timing config
|
||||
UCB0CTL1 = UCSSEL_3;
|
||||
UCB0BR0 = 8;
|
||||
// Faster than 8 ends up in strange communication errors
|
||||
// between the both MCUs.
|
||||
// With 8 the transfer of a complete 110 pixel canvas takes
|
||||
// about 720us.
|
||||
UCB0BR0 = 8;
|
||||
UCB0BR1 = 0;
|
||||
|
||||
// BIT5: UCB0CLK
|
||||
|
177
displayTest.c
177
displayTest.c
@ -3,27 +3,182 @@
|
||||
#include "PontCoopScheduler.h"
|
||||
|
||||
|
||||
static canvas_t *canvas;
|
||||
static uint8_t lastPixel = 0xff;
|
||||
static uint8_t currentPixel = 0;
|
||||
#define MAX_COLOR 0x0d
|
||||
|
||||
typedef enum {
|
||||
e_WIPE_LAST_COLUMN_DOWN,
|
||||
e_PIXELS_UP,
|
||||
e_WIPE_LAST_PIXEL_UP,
|
||||
e_PIXELS_DOWN,
|
||||
e_WIPE_LAST_PIXEL_DOWN,
|
||||
e_ROWS_UP,
|
||||
e_WIPE_LAST_ROW_UP,
|
||||
e_ROWS_DOWN,
|
||||
e_WIPE_LAST_ROW_DOWN,
|
||||
e_COLUMNS_UP,
|
||||
e_WIPE_LAST_COLUMN_UP,
|
||||
e_COLUMNS_DOWN
|
||||
} t_State;
|
||||
|
||||
void displayTestExec(void *args) {
|
||||
if (lastPixel != 0xff) {
|
||||
*((canvas->canvas)+lastPixel) = 0x80;
|
||||
static int16_t last = 0xff;
|
||||
static int16_t current = 0;
|
||||
static uint8_t color = 0x01;
|
||||
static t_State state = e_PIXELS_UP;
|
||||
|
||||
switch (state) {
|
||||
// wipe last column
|
||||
case e_WIPE_LAST_COLUMN_DOWN:
|
||||
for (uint16_t i = 0; i < canvas.height; i++) {
|
||||
canvasSetPixel(last, i, 0);
|
||||
}
|
||||
last = 0xff;
|
||||
state = e_PIXELS_UP;
|
||||
// pixels up
|
||||
case e_PIXELS_UP:
|
||||
if (last != 0xff) {
|
||||
*((canvas.canvas)+last) = 0x80;
|
||||
}
|
||||
|
||||
last = current;
|
||||
*((canvas.canvas)+current) = (color + 0x80);
|
||||
current++;
|
||||
if (current >= canvas.size) {
|
||||
current = 0;
|
||||
state = e_WIPE_LAST_PIXEL_UP;
|
||||
}
|
||||
break;
|
||||
// wipe last pixel
|
||||
case e_WIPE_LAST_PIXEL_UP:
|
||||
*((canvas.canvas)+last) = 0x80;
|
||||
last = 0xff;
|
||||
current = canvas.size - 1;
|
||||
state = e_PIXELS_DOWN;
|
||||
// pixels down
|
||||
case e_PIXELS_DOWN:
|
||||
if (last != 0xff) {
|
||||
*((canvas.canvas)+last) = 0x80;
|
||||
}
|
||||
|
||||
last = current;
|
||||
*((canvas.canvas)+current) = (color + 0x80);
|
||||
current--;
|
||||
if (current < 0) {
|
||||
current = 0;
|
||||
state = e_WIPE_LAST_PIXEL_DOWN;
|
||||
}
|
||||
break;
|
||||
// wipe last pixel
|
||||
case e_WIPE_LAST_PIXEL_DOWN:
|
||||
*((canvas.canvas)+last) = 0x80;
|
||||
last = 0xff;
|
||||
state = e_ROWS_UP;
|
||||
// rows up
|
||||
case e_ROWS_UP:
|
||||
if (last != 0xff) {
|
||||
for (uint16_t i = 0; i < canvas.width; i++) {
|
||||
canvasSetPixel(i, last, 0);
|
||||
}
|
||||
}
|
||||
|
||||
last = current;
|
||||
for (uint16_t i = 0; i < canvas.width; i++) {
|
||||
canvasSetPixel(i, current, color);
|
||||
}
|
||||
current++;
|
||||
if (current >= canvas.height) {
|
||||
current = 0;
|
||||
state = e_WIPE_LAST_ROW_UP;
|
||||
}
|
||||
break;
|
||||
// wipe last row
|
||||
case e_WIPE_LAST_ROW_UP:
|
||||
for (uint16_t i = 0; i < canvas.width; i++) {
|
||||
canvasSetPixel(i, last, 0);
|
||||
}
|
||||
last = 0xff;
|
||||
current = canvas.height - 1;
|
||||
state = e_ROWS_DOWN;
|
||||
// rows down
|
||||
case e_ROWS_DOWN:
|
||||
if (last != 0xff) {
|
||||
for (uint16_t i = 0; i < canvas.width; i++) {
|
||||
canvasSetPixel(i, last, 0);
|
||||
}
|
||||
}
|
||||
|
||||
last = current;
|
||||
for (uint16_t i = 0; i < canvas.width; i++) {
|
||||
canvasSetPixel(i, current, color);
|
||||
}
|
||||
current--;
|
||||
if (current < 0) {
|
||||
current = 0;
|
||||
state = e_WIPE_LAST_ROW_DOWN;
|
||||
}
|
||||
break;
|
||||
// wipe last row
|
||||
case e_WIPE_LAST_ROW_DOWN:
|
||||
for (uint16_t i = 0; i < canvas.width; i++) {
|
||||
canvasSetPixel(i, last, 0);
|
||||
}
|
||||
last = 0xff;
|
||||
state = e_COLUMNS_UP;
|
||||
// columns up
|
||||
case e_COLUMNS_UP:
|
||||
if (last != 0xff) {
|
||||
for (uint16_t i = 0; i < canvas.height; i++) {
|
||||
canvasSetPixel(last, i, 0);
|
||||
}
|
||||
}
|
||||
|
||||
last = current;
|
||||
for (uint16_t i = 0; i < canvas.height; i++) {
|
||||
canvasSetPixel(current, i, color);
|
||||
}
|
||||
current++;
|
||||
if (current >= canvas.width) {
|
||||
current = 0;
|
||||
state = e_WIPE_LAST_COLUMN_UP;
|
||||
}
|
||||
break;
|
||||
// wipe last column
|
||||
case e_WIPE_LAST_COLUMN_UP:
|
||||
for (uint16_t i = 0; i < canvas.height; i++) {
|
||||
canvasSetPixel(last, i, 0);
|
||||
}
|
||||
last = 0xff;
|
||||
current = canvas.width - 1;
|
||||
state = e_COLUMNS_DOWN;
|
||||
// columns down
|
||||
case e_COLUMNS_DOWN:
|
||||
if (last != 0xff) {
|
||||
for (uint16_t i = 0; i < canvas.height; i++) {
|
||||
canvasSetPixel(last, i, 0);
|
||||
}
|
||||
}
|
||||
|
||||
last = current;
|
||||
for (uint16_t i = 0; i < canvas.height; i++) {
|
||||
canvasSetPixel(current, i, color);
|
||||
}
|
||||
current--;
|
||||
if (current < 0) {
|
||||
current = 0;
|
||||
state = e_WIPE_LAST_COLUMN_DOWN;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
lastPixel = currentPixel;
|
||||
*((canvas->canvas)+currentPixel) = 0x81;
|
||||
currentPixel++;
|
||||
if (currentPixel >= canvas->size) {
|
||||
currentPixel = 0;
|
||||
color++;
|
||||
if (color > MAX_COLOR) {
|
||||
color = 1;
|
||||
}
|
||||
|
||||
canvasShow();
|
||||
}
|
||||
|
||||
void displayTestInit() {
|
||||
canvas = canvasGet();
|
||||
schAdd(displayTestExec, NULL, 0, 50);
|
||||
}
|
||||
|
||||
|
75
displayTest2.c
Normal file
75
displayTest2.c
Normal file
@ -0,0 +1,75 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "canvas.h"
|
||||
#include "PontCoopScheduler.h"
|
||||
#include "displayTest2.h"
|
||||
|
||||
|
||||
|
||||
|
||||
typedef enum { e_idle, e_start, e_fillArea, e_placeObject, e_wipeLines_7, e_wipeLines_8, e_wipeLines_9, e_wipeLines_10 } t_state;
|
||||
|
||||
void displayTest2Exec(void *args) {
|
||||
static t_state state = e_start;
|
||||
|
||||
switch (state) {
|
||||
case e_idle:
|
||||
break;
|
||||
|
||||
case e_start:
|
||||
state = e_fillArea;
|
||||
break;
|
||||
|
||||
case e_fillArea:
|
||||
memset((canvas.canvas)+(canvas.width*7), 0x81, canvas.width);
|
||||
memset((canvas.canvas)+(canvas.width*8), 0x8d, canvas.width);
|
||||
memset((canvas.canvas)+(canvas.width*9), 0x82, canvas.width);
|
||||
memset((canvas.canvas)+(canvas.width*10), 0x88, canvas.width);
|
||||
for (uint8_t i = 0; i < canvas.width; i++) {
|
||||
if (i != 4 && i != 5) {
|
||||
canvasSetPixel(i, 6, 0x05);
|
||||
}
|
||||
}
|
||||
state = e_placeObject;
|
||||
break;
|
||||
|
||||
case e_placeObject:
|
||||
canvasSetPixel(4, 0, 0x04);
|
||||
canvasSetPixel(5, 0, 0x04);
|
||||
canvasSetPixel(6, 0, 0x04);
|
||||
canvasSetPixel(5, 1, 0x04);
|
||||
state = e_wipeLines_7;
|
||||
break;
|
||||
|
||||
case e_wipeLines_7:
|
||||
canvasWipeRow(7);
|
||||
state = e_wipeLines_8;
|
||||
break;
|
||||
|
||||
case e_wipeLines_8:
|
||||
canvasWipeRow(8);
|
||||
state = e_wipeLines_9;
|
||||
break;
|
||||
|
||||
case e_wipeLines_9:
|
||||
canvasWipeRow(9);
|
||||
state = e_wipeLines_10;
|
||||
break;
|
||||
|
||||
case e_wipeLines_10:
|
||||
canvasWipeRow(10);
|
||||
state = e_idle;
|
||||
break;
|
||||
|
||||
default:
|
||||
state = e_idle;
|
||||
break;
|
||||
}
|
||||
|
||||
canvasShow();
|
||||
}
|
||||
|
||||
void displayTest2Init() {
|
||||
schAdd(displayTest2Exec, NULL, 0, 5000);
|
||||
}
|
||||
|
11
displayTest2.h
Normal file
11
displayTest2.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef _DISPLAY_TEST_2_H_
|
||||
#define _DISPLAY_TEST_2_H_
|
||||
|
||||
|
||||
void displayTest2Init();
|
||||
void displayTest2Exec();
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // _DISPLAY_TEST_2_H_
|
78
displayTest3.c
Normal file
78
displayTest3.c
Normal file
@ -0,0 +1,78 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "canvas.h"
|
||||
#include "PontCoopScheduler.h"
|
||||
#include "displayTest3.h"
|
||||
#include "led.h"
|
||||
|
||||
|
||||
typedef enum { e_idle, e_delay, e_start, e_fillArea, e_placeObject, e_preWipeLines, e_wipeLines } t_state;
|
||||
|
||||
void displayTest3Exec(void *args) {
|
||||
static t_state state = e_start;
|
||||
static uint8_t wipeLineHelper = 0;
|
||||
|
||||
ledBlueToggle();
|
||||
|
||||
switch (state) {
|
||||
case e_idle:
|
||||
state = e_delay;
|
||||
break;
|
||||
|
||||
case e_delay:
|
||||
state = e_start;
|
||||
break;
|
||||
|
||||
case e_start:
|
||||
canvasClear();
|
||||
state = e_fillArea;
|
||||
break;
|
||||
|
||||
case e_fillArea:
|
||||
memset((canvas.canvas)+(canvas.width*7), 0x82, canvas.width);
|
||||
memset((canvas.canvas)+(canvas.width*8), 0x83, canvas.width);
|
||||
memset((canvas.canvas)+(canvas.width*9), 0x84, canvas.width);
|
||||
memset((canvas.canvas)+(canvas.width*10), 0x85, canvas.width);
|
||||
for (uint8_t i = 0; i < canvas.width; i++) {
|
||||
if (i != 4 && i != 5) {
|
||||
canvasSetPixel(i, 6, 0x01);
|
||||
}
|
||||
}
|
||||
state = e_placeObject;
|
||||
break;
|
||||
|
||||
case e_placeObject:
|
||||
canvasSetPixel(4, 0, 0x04);
|
||||
canvasSetPixel(5, 0, 0x04);
|
||||
canvasSetPixel(6, 0, 0x04);
|
||||
canvasSetPixel(5, 1, 0x04);
|
||||
state = e_preWipeLines;
|
||||
break;
|
||||
|
||||
case e_preWipeLines:
|
||||
wipeLineHelper = 0;
|
||||
state = e_wipeLines;
|
||||
// no break
|
||||
|
||||
case e_wipeLines:
|
||||
if (canvasIsRowFilled(wipeLineHelper) == 1) {
|
||||
canvasWipeRow(wipeLineHelper);
|
||||
}
|
||||
wipeLineHelper++;
|
||||
if (wipeLineHelper >= canvas.height) {
|
||||
state = e_idle;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
state = e_idle;
|
||||
break;
|
||||
}
|
||||
|
||||
canvasShow();
|
||||
}
|
||||
|
||||
void displayTest3Init() {
|
||||
schAdd(displayTest3Exec, NULL, 0, 1000);
|
||||
}
|
||||
|
11
displayTest3.h
Normal file
11
displayTest3.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef _DISPLAY_TEST_3_H_
|
||||
#define _DISPLAY_TEST_3_H_
|
||||
|
||||
|
||||
void displayTest3Init();
|
||||
void displayTest3Exec();
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // _DISPLAY_TEST_3_H_
|
BIN
docs/1second.png
Normal file
BIN
docs/1second.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.4 KiB |
BIN
docs/one-color.png
Normal file
BIN
docs/one-color.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.8 KiB |
BIN
docs/working-transfer.png
Normal file
BIN
docs/working-transfer.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.0 KiB |
67
game.c
Normal file
67
game.c
Normal file
@ -0,0 +1,67 @@
|
||||
#include "stddef.h"
|
||||
#include "stdint.h"
|
||||
|
||||
#include "game.h"
|
||||
#include "PontCoopScheduler.h"
|
||||
#include "shapes.h"
|
||||
#include "canvas.h"
|
||||
|
||||
|
||||
typedef enum { e_idle, e_start, e_newStone, e_down, e_gameOver, e_delay } state_t;
|
||||
|
||||
void gameExec(void *handle) {
|
||||
static state_t state = e_start;
|
||||
static uint8_t delay;
|
||||
|
||||
switch (state) {
|
||||
case e_idle:
|
||||
break;
|
||||
|
||||
case e_start:
|
||||
canvasClear();
|
||||
state = e_newStone;
|
||||
break;
|
||||
|
||||
case e_newStone:
|
||||
stoneCreate();
|
||||
if (stoneDraw()) {
|
||||
state = e_down;
|
||||
} else {
|
||||
state = e_gameOver;
|
||||
}
|
||||
break;
|
||||
|
||||
case e_down:
|
||||
if (! stoneMoveDown()) {
|
||||
state = e_newStone;
|
||||
}
|
||||
break;
|
||||
|
||||
case e_gameOver:
|
||||
for (uint8_t c = 0; c < canvas.width; c++) {
|
||||
canvasSetPixel(c, 0, 0x0d);
|
||||
canvasSetPixel(c, canvas.height-1, 0x0d);
|
||||
}
|
||||
for (uint8_t r = 0; r < canvas.height; r++) {
|
||||
canvasSetPixel(0, r, 0x0d);
|
||||
canvasSetPixel(canvas.width-1, r, 0x0d);
|
||||
}
|
||||
delay = 10;
|
||||
state = e_delay;
|
||||
break;
|
||||
|
||||
case e_delay:
|
||||
delay--;
|
||||
if (delay == 0) {
|
||||
state = e_start;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
canvasShow();
|
||||
}
|
||||
|
||||
void gameInit() {
|
||||
schAdd(gameExec, NULL, 0, 1000);
|
||||
}
|
||||
|
7
game.h
Normal file
7
game.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef _GAME_H_
|
||||
#define _GAME_H_
|
||||
|
||||
void gameInit();
|
||||
|
||||
|
||||
#endif // _GAME_H_
|
12
led.c
12
led.c
@ -12,6 +12,10 @@ void ledGreenOff() {
|
||||
P1OUT &= ~BIT0;
|
||||
}
|
||||
|
||||
void ledGreenToggle() {
|
||||
P1OUT ^= BIT0;
|
||||
}
|
||||
|
||||
void ledBlueOn() {
|
||||
P1OUT |= BIT1;
|
||||
}
|
||||
@ -20,8 +24,12 @@ void ledBlueOff() {
|
||||
P1OUT &= ~BIT1;
|
||||
}
|
||||
|
||||
void ledBlueToggle() {
|
||||
P1OUT ^= BIT1;
|
||||
}
|
||||
|
||||
void ledExec(void *args) {
|
||||
static int i = 0;
|
||||
static uint16_t i = 0;
|
||||
|
||||
if (i == 0) {
|
||||
ledGreenOff();
|
||||
@ -41,7 +49,7 @@ void ledInit() {
|
||||
ledBlueOff();
|
||||
|
||||
|
||||
// schAdd(ledExec, NULL, 0, 50);
|
||||
// schAdd(ledExec, NULL, 0, 500);
|
||||
}
|
||||
|
||||
|
||||
|
2
led.h
2
led.h
@ -4,8 +4,10 @@
|
||||
|
||||
void ledBlueOff();
|
||||
void ledBlueOn();
|
||||
void ledBlueToggle();
|
||||
void ledGreenOff();
|
||||
void ledGreenOn();
|
||||
void ledGreenToggle();
|
||||
|
||||
void ledInit();
|
||||
void ledExec();
|
||||
|
5
main.c
5
main.c
@ -8,7 +8,7 @@
|
||||
#include "led.h"
|
||||
#include "displayDriver.h"
|
||||
#include "canvas.h"
|
||||
#include "displayTest.h"
|
||||
#include "game.h"
|
||||
|
||||
|
||||
int main() {
|
||||
@ -22,15 +22,14 @@ int main() {
|
||||
BCSCTL2 = 0;
|
||||
BCSCTL3 = 0;
|
||||
|
||||
|
||||
timeInit();
|
||||
schInit();
|
||||
|
||||
ledInit();
|
||||
displayDriverInit();
|
||||
canvasInit();
|
||||
displayTestInit();
|
||||
|
||||
gameInit();
|
||||
|
||||
__enable_interrupt();
|
||||
|
||||
|
31
shape_i.c
Normal file
31
shape_i.c
Normal file
@ -0,0 +1,31 @@
|
||||
#include "shapes.h"
|
||||
#include "shape_i.h"
|
||||
#include "canvas.h"
|
||||
|
||||
uint8_t draw_i() {
|
||||
canvasSetPixel(stone.x, stone.y, 0x01);
|
||||
canvasSetPixel(stone.x, stone.y+1, 0x01);
|
||||
canvasSetPixel(stone.x, stone.y+2, 0x01);
|
||||
canvasSetPixel(stone.x, stone.y+3, 0x01);
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t moveDown_i() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t moveLeft_i() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t moveRight_i() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t rotateLeft_i() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t rotateRight_i() {
|
||||
return 1;
|
||||
}
|
14
shape_i.h
Normal file
14
shape_i.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef _SHAPE_I_H_
|
||||
#define _SHAPE_I_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint8_t draw_i();
|
||||
uint8_t moveDown_i();
|
||||
uint8_t moveRight_i();
|
||||
uint8_t moveLeft_i();
|
||||
uint8_t rotateLeft_i();
|
||||
uint8_t rotateRight_i();
|
||||
|
||||
|
||||
#endif // _SHAPE_I_H_
|
26
shape_j.c
Normal file
26
shape_j.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include "shapes.h"
|
||||
#include "shape_j.h"
|
||||
|
||||
uint8_t draw_j() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t moveDown_j() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t moveLeft_j() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t moveRight_j() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t rotateLeft_j() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t rotateRight_j() {
|
||||
return 0;
|
||||
}
|
14
shape_j.h
Normal file
14
shape_j.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef _SHAPE_J_H_
|
||||
#define _SHAPE_J_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint8_t draw_j();
|
||||
uint8_t moveDown_j();
|
||||
uint8_t moveRight_j();
|
||||
uint8_t moveLeft_j();
|
||||
uint8_t rotateLeft_j();
|
||||
uint8_t rotateRight_j();
|
||||
|
||||
|
||||
#endif // _SHAPE_J_H_
|
26
shape_l.c
Normal file
26
shape_l.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include "shapes.h"
|
||||
#include "shape_l.h"
|
||||
|
||||
uint8_t draw_l() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t moveDown_l() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t moveLeft_l() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t moveRight_l() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t rotateLeft_l() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t rotateRight_l() {
|
||||
return 0;
|
||||
}
|
14
shape_l.h
Normal file
14
shape_l.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef _SHAPE_L_H_
|
||||
#define _SHAPE_L_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint8_t draw_l();
|
||||
uint8_t moveDown_l();
|
||||
uint8_t moveRight_l();
|
||||
uint8_t moveLeft_l();
|
||||
uint8_t rotateLeft_l();
|
||||
uint8_t rotateRight_l();
|
||||
|
||||
|
||||
#endif // _SHAPE_L_H_
|
26
shape_o.c
Normal file
26
shape_o.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include "shapes.h"
|
||||
#include "shape_o.h"
|
||||
|
||||
uint8_t draw_o() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t moveDown_o() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t moveLeft_o() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t moveRight_o() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t rotateLeft_o() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t rotateRight_o() {
|
||||
return 0;
|
||||
}
|
14
shape_o.h
Normal file
14
shape_o.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef _SHAPE_O_H_
|
||||
#define _SHAPE_O_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint8_t draw_o();
|
||||
uint8_t moveDown_o();
|
||||
uint8_t moveRight_o();
|
||||
uint8_t moveLeft_o();
|
||||
uint8_t rotateLeft_o();
|
||||
uint8_t rotateRight_o();
|
||||
|
||||
|
||||
#endif // _SHAPE_O_H_
|
26
shape_s.c
Normal file
26
shape_s.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include "shapes.h"
|
||||
#include "shape_s.h"
|
||||
|
||||
uint8_t draw_s() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t moveDown_s() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t moveLeft_s() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t moveRight_s() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t rotateLeft_s() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t rotateRight_s() {
|
||||
return 0;
|
||||
}
|
14
shape_s.h
Normal file
14
shape_s.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef _SHAPE_S_H_
|
||||
#define _SHAPE_S_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint8_t draw_s();
|
||||
uint8_t moveDown_s();
|
||||
uint8_t moveRight_s();
|
||||
uint8_t moveLeft_s();
|
||||
uint8_t rotateLeft_s();
|
||||
uint8_t rotateRight_s();
|
||||
|
||||
|
||||
#endif // _SHAPE_S_H_
|
26
shape_t.c
Normal file
26
shape_t.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include "shapes.h"
|
||||
#include "shape_t.h"
|
||||
|
||||
uint8_t draw_t() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t moveDown_t() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t moveLeft_t() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t moveRight_t() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t rotateLeft_t() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t rotateRight_t() {
|
||||
return 0;
|
||||
}
|
14
shape_t.h
Normal file
14
shape_t.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef _SHAPE_T_H_
|
||||
#define _SHAPE_T_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint8_t draw_t();
|
||||
uint8_t moveDown_t();
|
||||
uint8_t moveRight_t();
|
||||
uint8_t moveLeft_t();
|
||||
uint8_t rotateLeft_t();
|
||||
uint8_t rotateRight_t();
|
||||
|
||||
|
||||
#endif // _SHAPE_T_H_
|
26
shape_z.c
Normal file
26
shape_z.c
Normal file
@ -0,0 +1,26 @@
|
||||
#include "shapes.h"
|
||||
#include "shape_z.h"
|
||||
|
||||
uint8_t draw_z() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t moveDown_z() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t moveLeft_z() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t moveRight_z() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t rotateLeft_z() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t rotateRight_z() {
|
||||
return 0;
|
||||
}
|
14
shape_z.h
Normal file
14
shape_z.h
Normal file
@ -0,0 +1,14 @@
|
||||
#ifndef _SHAPE_Z_H_
|
||||
#define _SHAPE_Z_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
uint8_t draw_z();
|
||||
uint8_t moveDown_z();
|
||||
uint8_t moveRight_z();
|
||||
uint8_t moveLeft_z();
|
||||
uint8_t rotateLeft_z();
|
||||
uint8_t rotateRight_z();
|
||||
|
||||
|
||||
#endif // _SHAPE_Z_H_
|
73
shapes.c
Normal file
73
shapes.c
Normal file
@ -0,0 +1,73 @@
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "shapes.h"
|
||||
#include "shape_i.h"
|
||||
#include "shape_o.h"
|
||||
#include "shape_t.h"
|
||||
#include "shape_z.h"
|
||||
#include "shape_s.h"
|
||||
#include "shape_l.h"
|
||||
#include "shape_j.h"
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
uint8_t (* draw)();
|
||||
uint8_t (*moveDown)();
|
||||
uint8_t (*moveLeft)();
|
||||
uint8_t (*moveRight)();
|
||||
uint8_t (*rotateLeft)();
|
||||
uint8_t (*rotateRight)();
|
||||
} stoneOperations_t;
|
||||
|
||||
const stoneOperations_t stoneOperations[] = {
|
||||
{ .draw = draw_i, .moveDown = moveDown_i, .moveLeft = moveLeft_i, .moveRight = moveRight_i, .rotateLeft = rotateLeft_i, .rotateRight = rotateRight_i },
|
||||
{ .draw = draw_o, .moveDown = moveDown_o, .moveLeft = moveLeft_o, .moveRight = moveRight_o, .rotateLeft = rotateLeft_o, .rotateRight = rotateRight_o },
|
||||
{ .draw = draw_t, .moveDown = moveDown_t, .moveLeft = moveLeft_t, .moveRight = moveRight_t, .rotateLeft = rotateLeft_t, .rotateRight = rotateRight_t },
|
||||
{ .draw = draw_z, .moveDown = moveDown_z, .moveLeft = moveLeft_z, .moveRight = moveRight_z, .rotateLeft = rotateLeft_z, .rotateRight = rotateRight_z },
|
||||
{ .draw = draw_s, .moveDown = moveDown_s, .moveLeft = moveLeft_s, .moveRight = moveRight_s, .rotateLeft = rotateLeft_s, .rotateRight = rotateRight_s },
|
||||
{ .draw = draw_l, .moveDown = moveDown_l, .moveLeft = moveLeft_l, .moveRight = moveRight_l, .rotateLeft = rotateLeft_l, .rotateRight = rotateRight_l },
|
||||
{ .draw = draw_j, .moveDown = moveDown_j, .moveLeft = moveLeft_j, .moveRight = moveRight_j, .rotateLeft = rotateLeft_j, .rotateRight = rotateRight_j }
|
||||
};
|
||||
|
||||
stone_t stone;
|
||||
|
||||
void stoneCreate() {
|
||||
stone.shape = e_I;
|
||||
stone.orientation = e_0;
|
||||
stone.x = 5;
|
||||
stone.y = 0;
|
||||
}
|
||||
|
||||
// all of them return 1 in case of success and 0 in case of error
|
||||
uint8_t stoneDraw() {
|
||||
return stoneOperations[stone.shape].draw();
|
||||
}
|
||||
|
||||
uint8_t stoneMoveDown() {
|
||||
return stoneOperations[stone.shape].moveDown();
|
||||
}
|
||||
|
||||
uint8_t stoneMoveLeft() {
|
||||
return stoneOperations[stone.shape].moveLeft();
|
||||
}
|
||||
|
||||
uint8_t stoneMoveRight() {
|
||||
return stoneOperations[stone.shape].moveRight();
|
||||
}
|
||||
|
||||
uint8_t stoneRotateLeft() {
|
||||
return stoneOperations[stone.shape].rotateLeft();
|
||||
}
|
||||
|
||||
uint8_t stoneRotateRight() {
|
||||
return stoneOperations[stone.shape].rotateRight();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
28
shapes.h
Normal file
28
shapes.h
Normal file
@ -0,0 +1,28 @@
|
||||
#ifndef _SHAPES_H_
|
||||
#define _SHAPES_H_
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void stoneCreate();
|
||||
uint8_t stoneDraw();
|
||||
uint8_t stoneMoveDown();
|
||||
uint8_t stoneMoveLeft();
|
||||
uint8_t stoneMoveRight();
|
||||
uint8_t stoneRotateLeft();
|
||||
uint8_t stoneRotateRight();
|
||||
|
||||
|
||||
typedef enum { e_I=0, e_O, e_T, e_Z, e_S, e_L, e_J, e_ShapeEnd } shape_t;
|
||||
typedef enum { e_0, e_90, e_180, e_270 } orientation_t;
|
||||
|
||||
typedef struct {
|
||||
shape_t shape;
|
||||
orientation_t orientation;
|
||||
uint8_t x; // column
|
||||
uint8_t y; // row
|
||||
} stone_t;
|
||||
|
||||
|
||||
extern stone_t stone;
|
||||
|
||||
#endif // _SHAPES_H_
|
14
time.c
14
time.c
@ -1,30 +1,16 @@
|
||||
#include <msp430g2553.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "time.h"
|
||||
#include "PontCoopScheduler.h"
|
||||
|
||||
|
||||
volatile uint32_t timestamp;
|
||||
|
||||
void __attribute__ ((interrupt (TIMER0_A0_VECTOR))) ta0_isr() {
|
||||
timestamp++;
|
||||
schUpdate();
|
||||
}
|
||||
|
||||
void timeInit() {
|
||||
timestamp = 0;
|
||||
|
||||
TACCR0 = 32;
|
||||
TACCTL0 = CCIE;
|
||||
TACTL = MC_1 | ID_0 | TASSEL_1 | TACLR;
|
||||
}
|
||||
|
||||
uint32_t getMillis() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
void ms_active_delay(uint16_t delay) {
|
||||
uint32_t start = timestamp;
|
||||
while (start + delay > timestamp);
|
||||
}
|
||||
|
Reference in New Issue
Block a user