90 Commits

Author SHA1 Message Date
007548efbb O done 2024-03-15 12:54:32 +01:00
14f6018f5a motion table and next orientation table down 2024-03-15 10:22:11 +01:00
f4b614bf0f first motion table 2024-03-14 17:25:45 +01:00
a7ea698f9b move and rotate of i 2024-03-14 14:46:31 +01:00
1959a3f578 game-ctrl merged 2024-03-14 11:10:18 +01:00
349c93b68f Merge remote-tracking branch 'repo-game-ctrl/shapes' 2024-03-14 11:09:26 +01:00
9c1a8a6e21 moved 2024-03-14 11:07:10 +01:00
9003528897 colors.h added 2024-03-14 10:57:09 +01:00
2b34a3e51d start game 2024-03-13 17:35:46 +01:00
e5381a8c9d Merge branch 'main' into shapes 2024-03-13 14:55:04 +01:00
8bd6197c02 spi timing 2024-03-13 14:54:53 +01:00
f5b0e67056 shapes 2024-03-13 14:52:46 +01:00
19be1a6e48 more tests 2024-03-12 23:00:17 +01:00
05de9326d7 some more display tests 2024-03-12 18:18:26 +01:00
633fc814b2 display tests 2024-03-12 17:53:42 +01:00
88e0cff853 11 rows 2024-03-12 10:19:16 +01:00
6020118fc2 110 leds 2024-03-12 10:19:02 +01:00
d3846c3e08 up and down 2024-03-08 15:54:34 +01:00
30ab5287da rename isr 2024-03-08 15:09:05 +01:00
fb16cfaa6f clean up cleaned up 2024-03-08 15:06:35 +01:00
cf62e0c0a0 Merge branch 'main' of gitea.hottis.de:wn/game-ctrl-01 2024-03-08 15:01:33 +01:00
044779681b more images 2024-03-08 15:01:01 +01:00
167617ad2c faster spi 2024-03-08 14:13:21 +01:00
26db6bf03d a funny light show 2024-03-08 14:07:09 +01:00
a4adf6ac27 synchronize scheduler, now it works 2024-03-08 13:12:55 +01:00
da3c2a5ffb image 2024-03-08 08:23:51 +01:00
a5438cef14 accept multiple address/data octets 2024-03-08 08:16:56 +01:00
d295a36598 receivedata added 2024-03-07 21:50:09 +01:00
3eaf90dbd6 works again 2024-03-07 15:43:27 +01:00
25ad1ad7df try math 2024-03-06 13:17:08 +01:00
6536dc5534 try math 2024-03-06 13:16:18 +01:00
730ac0df30 try math 2024-03-06 13:15:56 +01:00
152c9f60d4 try math 2024-03-06 13:14:43 +01:00
2f07e37b5d try math 2024-03-06 13:12:59 +01:00
d61986630c try math 2024-03-06 13:12:13 +01:00
2e19371fac try math 2024-03-06 13:08:18 +01:00
53e33bf4ff try math 2024-03-06 13:08:04 +01:00
01c645d8df try math 2024-03-06 13:07:38 +01:00
75acdd3171 try math 2024-03-06 13:04:32 +01:00
e6db62c9a5 try math 2024-03-06 13:04:14 +01:00
2ccef81175 try math 2024-03-06 13:03:49 +01:00
ad37bb2280 fix for new image 2024-03-06 12:57:37 +01:00
fd6eb582eb new image 2024-03-06 12:55:36 +01:00
8292d59cf0 doc on reset circuit 2024-03-06 10:44:31 +01:00
1e77cdaddf Merge branch 'main' of gitea.hottis.de:wn/rgb-driver-01 2024-03-06 10:39:23 +01:00
d0219a3c77 violet 2024-03-06 10:39:10 +01:00
2bef7bf2c2 Merge branch 'main' of gitea.hottis.de:wn/rgb-driver-01 2024-03-06 10:37:12 +01:00
9f50f6010b reset circuit 2024-03-06 10:36:43 +01:00
c35ec0991c dimm factor introduced 2024-03-05 17:01:53 +01:00
584e834b0d comment 2024-03-05 16:21:56 +01:00
fbe779d3b8 code beautified 2024-03-05 16:18:19 +01:00
49d78662e2 rolling led 2024-03-05 16:14:13 +01:00
c502303a36 use of subroutines work 2024-03-05 15:27:34 +01:00
2d532a6403 this is working 2024-03-05 15:06:42 +01:00
86fb74bd49 adjust color offsets 2024-02-29 18:13:58 +01:00
42c06f0da4 drop unnecessary .extern statements 2024-02-28 12:10:22 +01:00
b4ebe4978b readme 2024-02-27 20:53:13 +01:00
a5536e63b7 six leds 2024-02-27 20:49:06 +01:00
4f70ea392b readme 2024-02-27 20:39:27 +01:00
9c493d515e image 2024-02-27 20:35:48 +01:00
201a371a57 names refactor 2024-02-27 19:11:36 +01:00
40c49b6809 names refactor 2024-02-27 19:09:50 +01:00
c9b8fbba52 readme 2024-02-27 19:03:57 +01:00
d8755709cd readme 2024-02-27 19:02:02 +01:00
785810924e timing images 2024-02-27 19:00:19 +01:00
a0794dd9c1 refactor names, 6 2024-02-27 18:59:57 +01:00
4104cbf3d6 refactor names, 5 2024-02-27 18:30:08 +01:00
c829a76273 refactor names, 4 2024-02-27 17:48:22 +01:00
e1b7c328f8 refactor names, 3 2024-02-27 17:45:40 +01:00
2435cee771 refactor names, 2 2024-02-27 17:34:11 +01:00
75598f973a refactor names, 1 2024-02-27 17:32:16 +01:00
155b7153e9 refactor 2024-02-27 16:58:43 +01:00
5c2a6c42d2 hold data in ram 2024-02-27 15:33:45 +01:00
b390b8ec8f hold data in ram 2024-02-27 15:32:35 +01:00
cbf8a3cf86 color wheel from https://learn.sparkfun.com/tutorials/lilypad-protosnap-plus-activity-guide/3-custom-color-mixing 2024-02-27 15:11:27 +01:00
f0e8bf7616 color definitions 2024-02-27 15:10:38 +01:00
8f143104f6 works with leds attached 2024-02-27 14:23:32 +01:00
80801e185b readme 2024-02-27 12:09:39 +01:00
68490a4f83 schematics 2024-02-27 12:08:47 +01:00
5d7c75b358 fix 2024-02-27 11:58:02 +01:00
4e6fd76b08 Merge branch 'main' of gitea.hottis.de:wn/msp430-experiment-02 2024-02-27 11:56:31 +01:00
cea174197f add images 2024-02-27 11:56:06 +01:00
df9faabc7f readme 2024-02-27 11:54:19 +01:00
5128d36a75 readme fixed 2024-02-27 11:42:54 +01:00
b3ee547b64 remove dead code 2024-02-27 11:38:44 +01:00
92fb90983f cycles work now 2024-02-27 11:25:57 +01:00
fd801003a8 seems to work so far 2024-02-23 21:20:16 +01:00
491a544919 changes 2024-02-23 10:39:57 +01:00
b411a05d0e change Makefile 2024-02-20 13:05:32 +01:00
29c2c88c71 initial 2024-02-20 12:50:23 +01:00
48 changed files with 1507 additions and 133 deletions

View File

@ -1,31 +0,0 @@
#include <string.h>
#include <stdint.h>
#include "canvas.h"
#include "displayDriver.h"
static canvas_t canvas;
static uint8_t canvasStorage[CANVAS_WIDTH * CANVAS_HEIGHT];
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);
displayDriverTransferCanvas();
}
canvas_t *canvasGet() {
return &canvas;
}
void canvasShow() {
displayDriverTransferCanvas();
}

View File

@ -1,23 +0,0 @@
#ifndef _CANVAS_H_
#define _CANVAS_H_
#include <stdint.h>
#define CANVAS_WIDTH 10
#define CANVAS_HEIGHT 6
typedef struct {
uint8_t width;
uint8_t height;
uint8_t size;
uint8_t *canvas;
} canvas_t;
void canvasInit();
canvas_t *canvasGet();
void canvasShow();
#endif // _CANVAS_H_

View File

@ -1,29 +0,0 @@
#include <stdlib.h>
#include "canvas.h"
#include "PontCoopScheduler.h"
static canvas_t *canvas;
static uint8_t lastPixel = 0xff;
static uint8_t currentPixel = 0;
void displayTestExec(void *args) {
if (lastPixel != 0xff) {
*((canvas->canvas)+lastPixel) = 0x80;
}
lastPixel = currentPixel;
*((canvas->canvas)+currentPixel) = 0x81;
currentPixel++;
if (currentPixel >= canvas->size) {
currentPixel = 0;
}
canvasShow();
}
void displayTestInit() {
canvas = canvasGet();
schAdd(displayTestExec, NULL, 0, 50);
}

View File

@ -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 game.o buttons.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

View File

@ -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;
}

View File

@ -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;

98
game-ctrl/buttons.c Normal file
View File

@ -0,0 +1,98 @@
#include "stddef.h"
#include "stdint.h"
#include "buttons.h"
#include "PontCoopScheduler.h"
#include "shapes.h"
#include "canvas.h"
#include "led.h"
// TEST CODE
uint16_t counter;
static uint8_t buttonsMoveLeftPressed() {
// -----------------------
// TEST CODE
//if (counter == 95) {
// ledGreenToggle();
// return 1;
//}
// -----------------------
return 0;
}
static uint8_t buttonsMoveRightPressed() {
// -----------------------
// TEST CODE
if (counter == 95) {
ledGreenToggle();
return 1;
}
// -----------------------
return 0;
}
static uint8_t buttonsRotateLeftPressed() {
return 0;
}
static uint8_t buttonsRotateRightPressed() {
// -----------------------
// TEST CODE
if (counter == 35) {
ledGreenToggle();
return 1;
}
// -----------------------
// -----------------------
// TEST CODE
if (counter == 45) {
ledGreenToggle();
return 1;
}
// -----------------------
return 0;
}
void buttonsExec(void *handle) {
if (! stoneIsValid()) {
// don't do anything, the stone has not been initialized
return;
}
// TEST CODE
counter++;
uint8_t buttonPressed = 0;
if (buttonsMoveLeftPressed()) {
stoneMoveLeft();
buttonPressed = 1;
}
if (buttonsMoveRightPressed()) {
stoneMoveRight();
buttonPressed = 1;
}
if (buttonsRotateLeftPressed()) {
stoneRotateLeft();
buttonPressed = 1;
}
if (buttonsRotateRightPressed()) {
stoneRotateRight();
buttonPressed = 1;
}
if (buttonPressed == 1) {
canvasShow();
}
}
void buttonsInit() {
// TEST CODE
counter = 0;
schAdd(buttonsExec, NULL, 0, 100);
}

7
game-ctrl/buttons.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef _BUTTONS_H_
#define _BUTTONS_H_
void buttonsInit();
#endif // _BUTTONS_H_

61
game-ctrl/canvas.c Normal file
View File

@ -0,0 +1,61 @@
#include <string.h>
#include <stdint.h>
#include "canvas.h"
#include "displayDriver.h"
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() {
canvasClear();
displayDriverTransferCanvas();
}
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;
}
uint8_t canvasIsPixelFree(uint8_t column, uint8_t row) {
return (*((canvas.canvas) + (row * canvas.width + column)) == 0) &&
(column < canvas.width) &&
(row < canvas.height);
}

28
game-ctrl/canvas.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef _CANVAS_H_
#define _CANVAS_H_
#include <stdint.h>
#define CANVAS_WIDTH 10
#define CANVAS_HEIGHT 11
typedef struct {
const uint8_t width;
const uint8_t height;
const uint8_t size;
uint8_t * const canvas;
} canvas_t;
void canvasInit();
void canvasClear();
void canvasSetAll(uint8_t color);
void canvasShow();
void canvasSetPixel(uint8_t column, uint8_t row, uint8_t color);
uint8_t canvasIsPixelFree(uint8_t column, uint8_t row);
void canvasWipeRow(uint8_t row);
uint8_t canvasIsRowFilled(uint8_t row);
extern const canvas_t canvas;
#endif // _CANVAS_H_

View File

@ -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

184
game-ctrl/displayTest.c Normal file
View File

@ -0,0 +1,184 @@
#include <stdlib.h>
#include "canvas.h"
#include "PontCoopScheduler.h"
#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) {
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;
}
color++;
if (color > MAX_COLOR) {
color = 1;
}
canvasShow();
}
void displayTestInit() {
schAdd(displayTestExec, NULL, 0, 50);
}

75
game-ctrl/displayTest2.c Normal file
View 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
game-ctrl/displayTest2.h Normal file
View 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
game-ctrl/displayTest3.c Normal file
View 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
game-ctrl/displayTest3.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef _DISPLAY_TEST_3_H_
#define _DISPLAY_TEST_3_H_
void displayTest3Init();
void displayTest3Exec();
#endif // _DISPLAY_TEST_3_H_

View File

Before

Width:  |  Height:  |  Size: 5.4 KiB

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.0 KiB

67
game-ctrl/game.c Normal file
View 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-ctrl/game.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef _GAME_H_
#define _GAME_H_
void gameInit();
#endif // _GAME_H_

View File

@ -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);
}

View File

@ -4,8 +4,10 @@
void ledBlueOff();
void ledBlueOn();
void ledBlueToggle();
void ledGreenOff();
void ledGreenOn();
void ledGreenToggle();
void ledInit();
void ledExec();

View File

@ -8,7 +8,9 @@
#include "led.h"
#include "displayDriver.h"
#include "canvas.h"
#include "displayTest.h"
#include "game.h"
#include "buttons.h"
#include "shapes.h"
int main() {
@ -22,15 +24,16 @@ int main() {
BCSCTL2 = 0;
BCSCTL3 = 0;
timeInit();
schInit();
ledInit();
displayDriverInit();
canvasInit();
displayTestInit();
shapesInit();
gameInit();
buttonsInit();
__enable_interrupt();

227
game-ctrl/shapes.c Normal file
View File

@ -0,0 +1,227 @@
#include <stdint.h>
#include <stddef.h>
#include "shapes.h"
#include "canvas.h"
#include "../rgb-driver/colors.h"
typedef enum { e_I=0, e_O, e_T, e_Z, e_S, e_L, e_J, e_ShapeInvalid } shape_t;
typedef enum { e_MoveDown, e_MoveLeft, e_MoveRight, e_RotateLeft, e_RotateRight } direction_t;
typedef enum { e_0, e_90, e_180, e_270, e_Keep } orientation_t;
typedef struct {
shape_t shape;
orientation_t orientation;
uint8_t x; // column
uint8_t y; // row
} stone_t;
typedef struct {
uint8_t x;
uint8_t y;
} pixel_t;
typedef struct {
int8_t x;
int8_t y;
} offset_t;
typedef struct {
offset_t set[4];
offset_t reset[4];
offset_t offset;
} motion_t;
typedef struct {
uint8_t color;
uint8_t nullRotation;
pixel_t draw[4];
motion_t motion[5][4];
} motionTable_t;
const motionTable_t motions[2] = { // 2 = number of implemented stones
{ // I
.color = _cyan,
.nullRotation = 0,
.draw = { { 0, 0}, { 0, 1}, { 0, 2}, { 0, 3} },
.motion = {
{
// move down
{ .set = { { 0, 4}, { 0, 4}, { 0, 4}, { 0, 4} }, .reset = { { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0} }, .offset = { 0, 1} }, // 0
{ .set = { { 0, 1}, { 1, 1}, { 2, 1}, { 3, 1} }, .reset = { { 0, 0}, { 1, 0}, { 2, 0}, { 3, 0} }, .offset = { 0, 1} }, // 90
{ .set = { { 0, 4}, { 0, 4}, { 0, 4}, { 0, 4} }, .reset = { { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0} }, .offset = { 0, 1} }, // 180
{ .set = { { 0, 1}, { 1, 1}, { 2, 1}, { 3, 1} }, .reset = { { 0, 0}, { 1, 0}, { 2, 0}, { 3, 0} }, .offset = { 0, 1} } // 270
},
{
// move left
{ .set = { {-1, 0}, {-1, 1}, {-1, 2}, {-1, 3} }, .reset = { { 0, 0}, { 0, 1}, { 0, 2}, { 0, 3} }, .offset = {-1, 0} }, // 0
{ .set = { {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0} }, .reset = { { 3, 0}, { 3, 0}, { 3, 0}, { 3, 0} }, .offset = {-1, 0} }, // 90
{ .set = { {-1, 0}, {-1, 1}, {-1, 2}, {-1, 3} }, .reset = { { 0, 0}, { 0, 1}, { 0, 2}, { 0, 3} }, .offset = {-1, 0} }, // 180
{ .set = { {-1, 0}, {-1, 0}, {-1, 0}, {-1, 0} }, .reset = { { 3, 0}, { 3, 0}, { 3, 0}, { 3, 0} }, .offset = {-1, 0} }, // 270
},
{
// move right
{ .set = { { 1, 0}, { 1, 1}, { 1, 2}, { 1, 3} }, .reset = { { 0, 0}, { 0, 1}, { 0, 2}, { 0, 3} }, .offset = { 1, 0} }, // 0
{ .set = { { 4, 0}, { 4, 0}, { 4, 0}, { 4, 0} }, .reset = { { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0} }, .offset = { 1, 0} }, // 90
{ .set = { { 1, 0}, { 1, 1}, { 1, 2}, { 1, 3} }, .reset = { { 0, 0}, { 0, 1}, { 0, 2}, { 0, 3} }, .offset = { 1, 0} }, // 180
{ .set = { { 4, 0}, { 4, 0}, { 4, 0}, { 4, 0} }, .reset = { { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0} }, .offset = { 1, 0} }, // 270
},
{
// rotate left
{ .set = { {-1, 1}, { 1, 1}, { 2, 1}, { 2, 1} }, .reset = { { 0, 0}, { 0, 2}, { 0, 3}, { 0, 3} }, .offset = {-1, 1} }, // 0
{ .set = { { 1,-2}, { 1,-1}, { 1, 1}, { 1, 1} }, .reset = { { 0, 0}, { 2, 0}, { 3, 0}, { 3, 0} }, .offset = { 1,-2} }, // 90
{ .set = { {-1, 1}, { 1, 1}, { 2, 1}, { 2, 1} }, .reset = { { 0, 0}, { 0, 2}, { 0, 3}, { 0, 3} }, .offset = {-1, 1} }, // 180
{ .set = { { 1,-2}, { 1,-1}, { 1, 1}, { 1, 1} }, .reset = { { 0, 0}, { 2, 0}, { 3, 0}, { 3, 0} }, .offset = { 1,-2} }, // 270
},
{
// rotate right
{ .set = { {-2, 1}, {-1, 1}, { 1, 1}, { 1, 1} }, .reset = { { 0, 0}, { 0, 2}, { 0, 3}, { 0, 3} }, .offset = {-2, 1} }, // 0
{ .set = { { 1,-1}, { 1, 1}, { 1, 2}, { 1, 2} }, .reset = { { 0, 0}, { 2, 0}, { 3, 0}, { 3, 0} }, .offset = { 1,-1} }, // 90
{ .set = { {-2, 1}, {-1, 1}, { 1, 1}, { 1, 1} }, .reset = { { 0, 0}, { 0, 2}, { 0, 3}, { 0, 3} }, .offset = {-2, 1} }, // 180
{ .set = { { 1,-1}, { 1, 1}, { 1, 2}, { 1, 2} }, .reset = { { 0, 0}, { 2, 0}, { 3, 0}, { 3, 0} }, .offset = { 1,-1} }, // 270
},
}
},
{ // O
.color = _yellow,
.nullRotation = 1,
.draw = { { 0, 0}, { 0, 1}, { 1, 0}, { 1, 1} },
.motion = {
{
// move down
{ .set = { { 0, 2}, { 1, 2}, { 1, 2}, { 1, 2} }, .reset = { { 0, 0}, { 1, 0}, { 1, 0}, { 1, 0} }, .offset = { 0, 1} }, // 0
{ .set = { { 0, 2}, { 1, 2}, { 1, 2}, { 1, 2} }, .reset = { { 0, 0}, { 1, 0}, { 1, 0}, { 1, 0} }, .offset = { 0, 1} }, // 90
{ .set = { { 0, 2}, { 1, 2}, { 1, 2}, { 1, 2} }, .reset = { { 0, 0}, { 1, 0}, { 1, 0}, { 1, 0} }, .offset = { 0, 1} }, // 180
{ .set = { { 0, 2}, { 1, 2}, { 1, 2}, { 1, 2} }, .reset = { { 0, 0}, { 1, 0}, { 1, 0}, { 1, 0} }, .offset = { 0, 1} }, // 270
},
{
// move left
{ .set = { {-1, 0}, {-1, 1}, {-1, 1}, {-1, 1} }, .reset = { { 1, 0}, { 1, 1}, { 1, 1}, { 1, 1} }, .offset = {-1, 0} }, // 0
{ .set = { {-1, 0}, {-1, 1}, {-1, 1}, {-1, 1} }, .reset = { { 1, 0}, { 1, 1}, { 1, 1}, { 1, 1} }, .offset = {-1, 0} }, // 90
{ .set = { {-1, 0}, {-1, 1}, {-1, 1}, {-1, 1} }, .reset = { { 1, 0}, { 1, 1}, { 1, 1}, { 1, 1} }, .offset = {-1, 0} }, // 180
{ .set = { {-1, 0}, {-1, 1}, {-1, 1}, {-1, 1} }, .reset = { { 1, 0}, { 1, 1}, { 1, 1}, { 1, 1} }, .offset = {-1, 0} }, // 270
},
{
// move right
{ .set = { { 2, 0}, { 2, 1}, { 2, 1}, { 2, 1} }, .reset = { { 0, 0}, { 0, 1}, { 0, 1}, { 0, 1} }, .offset = { 1, 0} }, // 0
{ .set = { { 2, 0}, { 2, 1}, { 2, 1}, { 2, 1} }, .reset = { { 0, 0}, { 0, 1}, { 0, 1}, { 0, 1} }, .offset = { 1, 0} }, // 90
{ .set = { { 2, 0}, { 2, 1}, { 2, 1}, { 2, 1} }, .reset = { { 0, 0}, { 0, 1}, { 0, 1}, { 0, 1} }, .offset = { 1, 0} }, // 180
{ .set = { { 2, 0}, { 2, 1}, { 2, 1}, { 2, 1} }, .reset = { { 0, 0}, { 0, 1}, { 0, 1}, { 0, 1} }, .offset = { 1, 0} }, // 270
},
{
// rotate left
{ .set = { { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0} }, .reset = { { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0} }, .offset = { 0, 0} }, // 0
{ .set = { { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0} }, .reset = { { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0} }, .offset = { 0, 0} }, // 90
{ .set = { { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0} }, .reset = { { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0} }, .offset = { 0, 0} }, // 180
{ .set = { { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0} }, .reset = { { 0, 0}, { 0, 0}, { 0, 0}, { 0, 0} }, .offset = { 0, 0} }, // 270
},
{
// rotate right
{ .set = { {-2, 1}, {-1, 1}, { 1, 1}, { 1, 1} }, .reset = { { 0, 0}, { 0, 2}, { 0, 3}, { 0, 3} }, .offset = {-2, 1} }, // 0
{ .set = { { 1,-1}, { 1, 1}, { 1, 2}, { 1, 2} }, .reset = { { 0, 0}, { 2, 0}, { 3, 0}, { 3, 0} }, .offset = { 1,-1} }, // 90
{ .set = { {-2, 1}, {-1, 1}, { 1, 1}, { 1, 1} }, .reset = { { 0, 0}, { 0, 2}, { 0, 3}, { 0, 3} }, .offset = {-2, 1} }, // 180
{ .set = { { 1,-1}, { 1, 1}, { 1, 2}, { 1, 2} }, .reset = { { 0, 0}, { 2, 0}, { 3, 0}, { 3, 0} }, .offset = { 1,-1} }, // 270
},
}
}
};
const orientation_t nextOrientation[5][4] = { // 5 = number of directions to move, 4 = number of orientation a stone can have
{ e_Keep, e_Keep, e_Keep, e_Keep }, // move down, current orientation: 0, 90, 180, 270
{ e_Keep, e_Keep, e_Keep, e_Keep }, // move left
{ e_Keep, e_Keep, e_Keep, e_Keep }, // move right
{ e_270, e_0, e_90, e_180 }, // rotate left
{ e_90, e_180, e_270, e_0 } // rotate right
};
stone_t stone;
void shapesInit() {
stone.shape = e_ShapeInvalid;
}
void stoneCreate() {
static uint8_t cnt = 0;
stone.shape = ((shape_t[]){ e_I, e_O, e_T, e_Z, e_S, e_L, e_J })[cnt];
cnt++;
if (cnt > 1) {
cnt = 0;
}
stone.orientation = e_0;
stone.x = 5;
stone.y = 0;
}
uint8_t stoneIsValid() {
return stone.shape != e_ShapeInvalid;
}
// all of them return 1 in case of success and 0 in case of error
static uint8_t move(direction_t direction) {
if (motions[stone.shape].nullRotation && (direction == e_RotateLeft || direction == e_RotateRight)) {
return 1;
}
if (canvasIsPixelFree(stone.x + motions[stone.shape].motion[direction][stone.orientation].set[0].x, stone.y + motions[stone.shape].motion[direction][stone.orientation].set[0].y) &&
canvasIsPixelFree(stone.x + motions[stone.shape].motion[direction][stone.orientation].set[1].x, stone.y + motions[stone.shape].motion[direction][stone.orientation].set[1].y) &&
canvasIsPixelFree(stone.x + motions[stone.shape].motion[direction][stone.orientation].set[2].x, stone.y + motions[stone.shape].motion[direction][stone.orientation].set[2].y) &&
canvasIsPixelFree(stone.x + motions[stone.shape].motion[direction][stone.orientation].set[3].x, stone.y + motions[stone.shape].motion[direction][stone.orientation].set[3].y)) {
canvasSetPixel(stone.x + motions[stone.shape].motion[direction][stone.orientation].reset[0].x, stone.y + motions[stone.shape].motion[direction][stone.orientation].reset[0].y, _off);
canvasSetPixel(stone.x + motions[stone.shape].motion[direction][stone.orientation].reset[1].x, stone.y + motions[stone.shape].motion[direction][stone.orientation].reset[1].y, _off);
canvasSetPixel(stone.x + motions[stone.shape].motion[direction][stone.orientation].reset[2].x, stone.y + motions[stone.shape].motion[direction][stone.orientation].reset[2].y, _off);
canvasSetPixel(stone.x + motions[stone.shape].motion[direction][stone.orientation].reset[3].x, stone.y + motions[stone.shape].motion[direction][stone.orientation].reset[3].y, _off);
canvasSetPixel(stone.x + motions[stone.shape].motion[direction][stone.orientation].set[0].x, stone.y + motions[stone.shape].motion[direction][stone.orientation].set[0].y, motions[stone.shape].color);
canvasSetPixel(stone.x + motions[stone.shape].motion[direction][stone.orientation].set[1].x, stone.y + motions[stone.shape].motion[direction][stone.orientation].set[1].y, motions[stone.shape].color);
canvasSetPixel(stone.x + motions[stone.shape].motion[direction][stone.orientation].set[2].x, stone.y + motions[stone.shape].motion[direction][stone.orientation].set[2].y, motions[stone.shape].color);
canvasSetPixel(stone.x + motions[stone.shape].motion[direction][stone.orientation].set[3].x, stone.y + motions[stone.shape].motion[direction][stone.orientation].set[3].y, motions[stone.shape].color);
stone.x += motions[stone.shape].motion[direction][stone.orientation].offset.x;
stone.y += motions[stone.shape].motion[direction][stone.orientation].offset.y;
stone.orientation = (nextOrientation[direction][stone.orientation] == e_Keep) ? stone.orientation : nextOrientation[direction][stone.orientation];
return 1;
}
return 0;
}
uint8_t stoneDraw() {
uint8_t res = 0;
if (canvasIsPixelFree(stone.x + motions[stone.shape].draw[0].x, stone.y + motions[stone.shape].draw[0].y) &&
canvasIsPixelFree(stone.x + motions[stone.shape].draw[1].x, stone.y + motions[stone.shape].draw[1].y) &&
canvasIsPixelFree(stone.x + motions[stone.shape].draw[2].x, stone.y + motions[stone.shape].draw[2].y) &&
canvasIsPixelFree(stone.x + motions[stone.shape].draw[3].x, stone.y + motions[stone.shape].draw[3].y)) {
canvasSetPixel(stone.x + motions[stone.shape].draw[0].x, stone.y + motions[stone.shape].draw[0].y, motions[stone.shape].color);
canvasSetPixel(stone.x + motions[stone.shape].draw[1].x, stone.y + motions[stone.shape].draw[1].y, motions[stone.shape].color);
canvasSetPixel(stone.x + motions[stone.shape].draw[2].x, stone.y + motions[stone.shape].draw[2].y, motions[stone.shape].color);
canvasSetPixel(stone.x + motions[stone.shape].draw[3].x, stone.y + motions[stone.shape].draw[3].y, motions[stone.shape].color);
res = 1;
}
return res;
}
uint8_t stoneMoveDown() {
return move(e_MoveDown);
}
uint8_t stoneMoveLeft() {
return move(e_MoveLeft);
}
uint8_t stoneMoveRight() {
return move(e_MoveRight);
}
uint8_t stoneRotateLeft() {
return move(e_RotateLeft);
}
uint8_t stoneRotateRight() {
return move(e_RotateRight);
}

17
game-ctrl/shapes.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef _SHAPES_H_
#define _SHAPES_H_
#include <stdint.h>
void shapesInit();
void stoneCreate();
uint8_t stoneIsValid();
uint8_t stoneDraw();
uint8_t stoneMoveDown();
uint8_t stoneMoveLeft();
uint8_t stoneMoveRight();
uint8_t stoneRotateLeft();
uint8_t stoneRotateRight();
#endif // _SHAPES_H_

View File

@ -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);
}

View File

@ -4,8 +4,6 @@
#include <stdint.h>
void timeInit();
uint32_t getMillis();
void ms_active_delay(uint16_t delay);

35
rgb-driver/Makefile Normal file
View File

@ -0,0 +1,35 @@
TOOLCHAIN_PREFIX=/opt/msp430-gcc
CC=$(TOOLCHAIN_PREFIX)/bin/msp430-elf-gcc
OBJDUMP=$(TOOLCHAIN_PREFIX)/bin/msp430-elf-objdump
MCU=msp430g2553
ARTIFACT=firmware
COMMON=-Wall -mmcu=$(MCU) -std=gnu99 -I $(TOOLCHAIN_PREFIX)/include -Os -g0 -fdata-sections -ffunction-sections -ggdb -gdwarf-2
CFLAGS=$(COMMON)
ASFLAGS=$(COMMON) -D__ASSEMBLER__
LDFLAGS=-L $(TOOLCHAIN_PREFIX)/include -Wl,-Map,firmware.map -nostdlib -nostartfiles -T $(MCU).ld
$(ARTIFACT).elf: colors.o main.o
$(CC) -o $@ $(LDFLAGS) $^
$(OBJDUMP) -D $(ARTIFACT).elf > $(ARTIFACT).txt
.c.o:
$(CC) $(CFLAGS) -c $<
.S.o:
$(CC) $(ASFLAGS) -c $<
.PHONY: all
all: $(ARTIFACT).elf
.PHONY: clean
clean:
-rm -f *.o *.elf *.map *.txt
.PHONY: upload
upload: $(ARTIFACT).elf
mspdebug rf2500 "prog $(ARTIFACT).elf"

38
rgb-driver/colors.S Normal file
View File

@ -0,0 +1,38 @@
#include "colors.h"
#define DIMM_FACTOR 3
.section ".rodata","a"
;; color definitions according to
;; https://learn.sparkfun.com/tutorials/lilypad-protosnap-plus-activity-guide/3-custom-color-mixing
colors:
.global colors
;; red, green, blue, padding
off:
.byte 0x00, 0x00, 0x00, 0
blue:
.byte 0x00>>DIMM_FACTOR, 0x00>>DIMM_FACTOR, 0xff>>DIMM_FACTOR, 0
green:
.byte 0x00>>DIMM_FACTOR, 0xff>>DIMM_FACTOR, 0x00>>DIMM_FACTOR, 0
orange:
.byte 0xff>>DIMM_FACTOR, 0x80>>DIMM_FACTOR, 0x00>>DIMM_FACTOR, 0
rose:
.byte 0xff>>DIMM_FACTOR, 0x00>>DIMM_FACTOR, 0x80>>DIMM_FACTOR, 0
magenta:
.byte 0xff>>DIMM_FACTOR, 0x00>>DIMM_FACTOR, 0xff>>DIMM_FACTOR, 0
violet:
.byte 0x80>>DIMM_FACTOR, 0x00>>DIMM_FACTOR, 0xff>>DIMM_FACTOR, 0
azure:
.byte 0x00>>DIMM_FACTOR, 0x80>>DIMM_FACTOR, 0xff>>DIMM_FACTOR, 0
cyan:
.byte 0x00>>DIMM_FACTOR, 0xff>>DIMM_FACTOR, 0xff>>DIMM_FACTOR, 0
springgreen:
.byte 0x00>>DIMM_FACTOR, 0xff>>DIMM_FACTOR, 0x80>>DIMM_FACTOR, 0
chartreuse:
.byte 0x80>>DIMM_FACTOR, 0xff>>DIMM_FACTOR, 0x00>>DIMM_FACTOR, 0
yellow:
.byte 0xff>>DIMM_FACTOR, 0xff>>DIMM_FACTOR, 0x00>>DIMM_FACTOR, 0
white:
.byte 0xff>>DIMM_FACTOR, 0xff>>DIMM_FACTOR, 0xff>>DIMM_FACTOR, 0
red:
.byte 0xff>>DIMM_FACTOR, 0x00>>DIMM_FACTOR, 0x00>>DIMM_FACTOR, 0

22
rgb-driver/colors.h Normal file
View 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

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 726 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 899 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 326 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.6 KiB

392
rgb-driver/main.S Normal file
View File

@ -0,0 +1,392 @@
#include <msp430g2553.h>
#include "colors.h"
#define PC r0
#define SP r1
#define SR r2
;; ----------------------------------------------------
;; --- r4, r5 and r6 must not be used for any other ---
;; --- purpose ---
;; required for communication between drawscreen and isr
#define SIGNAL_REGISTER r4
#define SIGNAL_OCTET_DONE 0x01
#define SIGNAL_ISR_ENABLE 0x02
#define SIGNAL_ALL_DATA_DONE 0x04
#define SIGNAL_INIT_VALUE SIGNAL_OCTET_DONE
;; required for handover of data between drawscreen and isr
#define DATA_REGISTER r5
;; required for sequencing of isr
#define BIT_COUNTER_REGISTER r6
#define BIT_COUNTER_INIT_VALUE 0x01
;; ----------------------------------------------------
;; 2.48us
#define TIMER_COMPLETE 45
;; 1.18us
#define TIMER_LONG 22
;; 550ns
#define TIMER_SHORT 10
.macro set_data_bit
bis #BIT0, &P1OUT
.endm
.macro clear_data_bit
bic #BIT0, &P1OUT
.endm
.macro set_output_enable
bis #BIT1, &P1OUT
.endm
.macro clear_output_enable
bic #BIT1, &P1OUT
.endm
.macro set_debug
bis #BIT2, &P1OUT
.endm
.macro clear_debug
bic #BIT2, &P1OUT
.endm
.macro set_signal_waiting_for_data
bis #BIT3, &P1OUT
.endm
.macro clear_signal_waiting_for_data
bic #BIT3, &P1OUT
.endm
.section ".data"
screendata:
.rept 110 ;; number of leds in hardward
.byte 0
.endr
screendataend:
.byte 0xff
data_forward_pointer:
.word 0
;; .text is the name of the section, it is a hint for the linker to
;; allocate the section
;; ax: a means allocatable by linker, x means executable
;; @progbits is a hint for the linker to allocate this section into
;; program memory (flash)
.section ".text","ax",@progbits
;; ----------------------------------------------------
_start:
;; disable watchdog
mov.w #WDTPW|WDTHOLD,&WDTCTL
;; configure clock system to the highest frequency
mov.b #DCO0|DCO1|DCO2,&DCOCTL
mov.b #XT2OFF|RSEL0|RSEL1|RSEL2|RSEL3,&BCSCTL1
mov.b #0,&BCSCTL2
mov.b #0,&BCSCTL3
;; initialize stack pointer with value from linker
mov.w #__stack, SP
init:
;; configuration of GPIO Ports
;; BIT0: data bit
;; BIT1: output enable
;; BIT2: debug
;; BIT3: Signal waiting for data
mov.b #BIT0|BIT1|BIT2|BIT3, &P1DIR
mov.b #0,&P1OUT
;; BIT5: spi, UCB0CLK
;; BIT6: spi, UCB0SOMI
;; BIT7: spi, UCB0SIMO
mov.b #BIT5|BIT6|BIT7, &P1SEL
mov.b #BIT5|BIT6|BIT7, &P1SEL2
;; BIT4: long pulse
;; BIT1: short pulse
mov.b #BIT1|BIT4,&P2DIR
mov.b #BIT1|BIT4,&P2SEL
;; timer configuration
;; configure and stop timer
;; cycle time is 56.25ns
mov.w #ID_0|MC_0|TACLR|TASSEL_2,&TA1CTL
;; 2.0us
mov.w #TIMER_COMPLETE,&TA1CCR0
;; a bit less
mov.w #TIMER_SHORT,&TA1CCR1
mov.w #TIMER_LONG,&TA1CCR2
;; configure output mode for TA0.1
mov.w #CCIE,&TA1CCTL0
mov.w #OUTMOD_7,&TA1CCTL1
mov.w #OUTMOD_7,&TA1CCTL2
;; spi configuration
;; USCI B to slave mode
mov.b #UCSYNC, &UCB0CTL0
mov.b #0x00, &UCB0CTL1
;; make sure the isr will not immediately start
mov.b #SIGNAL_INIT_VALUE, SIGNAL_REGISTER
;; start timer in up mode
bis.w #MC0,&TA1CTL
;; enable interrupts
eint
;; ----------------------------------------------------
mainloop:
call #forwardscreen_init
call #resetscreen
mainloop_draw:
call #drawscreen
;; signal waiting for data
set_signal_waiting_for_data
;call #forwardscreen
;call #wait
call #receivedata
;; data has been received, clear signal
clear_signal_waiting_for_data
jmp mainloop_draw
;; ----------------------------------------------------
wait:
push r11
push r12
mov.w #0x0040, r11
wait_continue_1:
mov.w #0xffff, r12
wait_continue_2:
dec.w r12
jnz wait_continue_2
dec.w r11
jnz wait_continue_1
pop r12
pop r11
ret
;; ----------------------------------------------------
forwardscreen_init:
mov.w #screendata, &data_forward_pointer
ret
;; ----------------------------------------------------
forwardscreen:
push r8
push r10
mov.w #screendataend, r8
mov.w data_forward_pointer, r10
mov.b #_off, @r10
inc.w r10
mov.b #_blue, @r10
cmp.w r10, r8
jnz forwardscreen_done
mov.w #screendata, r10
forwardscreen_done:
mov.w r10, data_forward_pointer
pop r10
pop r8
ret
;; ----------------------------------------------------
resetscreen:
push r7
push r8
;; reset screen data
mov.w #screendata, r7
mov.w #screendataend, r8
resetscreen_continue:
mov.b #_off, @r7
inc.w r7
cmp.w r7, r8
jnz resetscreen_continue
pop r8
pop r7
ret
;; ----------------------------------------------------
receivedata:
push r9
push r10
;; wait for first octet
receivedata_wait_for_control_octet:
bit #UCB0RXIFG, &UC0IFG
jz receivedata_wait_for_control_octet
;; get control or address octet from buffer register
mov.b UCB0RXBUF, r9
;; check whether value == 0xff (wait for the whole
;; set of data to fill the screendata)
cmp.b #0xff, r9
;; receive all data
jz receivedata_wait_for_all_data
;; check whether value == 0xfe (no more data)
cmp.b #0xfe, r9
;; no more data
jz receivedata_end
;; it is an address octet
receivedata_wait_for_octet:
bit #UCB0RXIFG, &UC0IFG
jz receivedata_wait_for_octet
;; get data octet from buffer register
mov.b UCB0RXBUF, r10
;; move it to the destination
mov.b r10, screendata(r9)
;; next address/control octet
jmp receivedata_wait_for_control_octet
receivedata_wait_for_all_data:
;; this is a bit dangerous, if the application controller
;; sends too few data, we are in a dead lock
receivedata_end:
pop r10
pop r9
ret
;; ----------------------------------------------------
drawscreen:
push r7
push r8
push r9
#define DATA_NEXT_ADDRESS_REGISTER r7
#define DATA_END_ADDRESS_REGISTER r8
#define NEXT_DATA_REGISTER r9
;; initialize bit-counter for isr
mov.b #BIT_COUNTER_INIT_VALUE, BIT_COUNTER_REGISTER
;; initialize isr-sync register, signal BYTE_DONE for the first start
mov.b #SIGNAL_OCTET_DONE, SIGNAL_REGISTER
;; screen data start/next into r7
mov.w #screendata, DATA_NEXT_ADDRESS_REGISTER
;; screen data end into r8
mov.w #screendataend, DATA_END_ADDRESS_REGISTER
drawscreen_continue:
;; prepare next byte to handle by isr
cmp.w DATA_NEXT_ADDRESS_REGISTER, DATA_END_ADDRESS_REGISTER
jz drawscreen_data_done
;; load next data byte
mov.b @DATA_NEXT_ADDRESS_REGISTER, NEXT_DATA_REGISTER
inc.w DATA_NEXT_ADDRESS_REGISTER
;; multiple color code by four to get color data
rla.b NEXT_DATA_REGISTER
rla.b NEXT_DATA_REGISTER
;; enable isr
bis #SIGNAL_ISR_ENABLE, SIGNAL_REGISTER
drawscreen_wait_for_isr_0:
;; check bit0 in sync register
bit #SIGNAL_OCTET_DONE, SIGNAL_REGISTER
jz drawscreen_wait_for_isr_0
;; load data
mov.b colors(NEXT_DATA_REGISTER), DATA_REGISTER
;; clear BYTE_DONE
bic #SIGNAL_OCTET_DONE, SIGNAL_REGISTER
drawscreen_wait_for_isr_1:
;; check bit0 in sync register
bit #SIGNAL_OCTET_DONE, SIGNAL_REGISTER
jz drawscreen_wait_for_isr_1
;; load data
mov.b colors+1(NEXT_DATA_REGISTER), DATA_REGISTER
;; clear BYTE_DONE
bic #SIGNAL_OCTET_DONE, SIGNAL_REGISTER
drawscreen_wait_for_isr_2:
;; check bit0 in sync register
bit #SIGNAL_OCTET_DONE, SIGNAL_REGISTER
jz drawscreen_wait_for_isr_2
;; load data
mov.b colors+2(NEXT_DATA_REGISTER), DATA_REGISTER
;; clear BYTE_DONE
bic #SIGNAL_OCTET_DONE, SIGNAL_REGISTER
;; continue
jmp drawscreen_continue
drawscreen_data_done:
;; signal all data processed, isr finish
bis #SIGNAL_ALL_DATA_DONE, SIGNAL_REGISTER
pop r9
pop r8
pop r7
ret
;; ----------------------------------------------------
; --- timer isr ---
;; r6: exclusively used by isr as bit-counter
shifter_isr:
;; check isr enable bit
bit #SIGNAL_ISR_ENABLE, SIGNAL_REGISTER
jz shifter_isr_exit
;; shift msb of data register r5 into carry flag and set or reset P1.0 accordingly
rla.b DATA_REGISTER
jnc shifter_isr_false_bit
set_data_bit
jmp shifter_isr_end
shifter_isr_false_bit:
clear_data_bit
shifter_isr_end:
;; enable output
set_output_enable
;; roll bit-counter
rla.b BIT_COUNTER_REGISTER
jnc shifter_isr_exit
;; reset bit-counter
mov.b #BIT_COUNTER_INIT_VALUE, BIT_COUNTER_REGISTER
;; signal byte done
bis #SIGNAL_OCTET_DONE, SIGNAL_REGISTER
;; check whether all data are processed
bit #SIGNAL_ALL_DATA_DONE, SIGNAL_REGISTER
jz shifter_isr_exit
;; disable isr
bic #SIGNAL_ISR_ENABLE, SIGNAL_REGISTER
;; disable output
clear_output_enable
shifter_isr_exit:
reti
;; ----------------------------------------------------
.section "__interrupt_vector_14","ax",@progbits
.word shifter_isr
;; .resetvec comes from linker
.section ".resetvec","ax",@progbits
.word _start
.end

97
rgb-driver/readme.md Normal file
View File

@ -0,0 +1,97 @@
## Debugging
```
mspdebug rf2500 gdb
msp430-gdb -x firmware.gdb
```
Attention: the gdb in the TI toolchain package is broken, use the one from Debian
## Signals Working Cycler
These signals are related to code under tag `cycler_works_include_output_stage`.
First octets:
![](./docs/cycler_working_first_octets.png)
Last octets:
![](./docs/cycler_working_last_octets.png)
Schematics and legend for signals:
![](./docs/schematics.jpeg)
## Timing
Complete cycle: 2.48us
![](./docs/pulse_complete.png)
Short pulse: 550ns
![](./docs/pulse_short.png)
Long pulse: 1.18us
![](./docs/pulse_long.png)
## Load Time
During of loading data into five LEDs: 297us
![](./docs/five_leds.png)
During of loading data into six LEDs: 297us
![](./docs/six_leds.png)
| # of LEDs | Load Time measured | calculated |
| --------- | ------------------ | ---------- |
| 5 | 297us | |
| 6 | 354us | 356.4us |
| 10 | | 594us |
| 100 | | 5.9ms |
| 200 | | 11.8ms |
## Reset Circuitry
It appears that the output voltage of the power supply raises that slow, that the MCU
will not handle the reset correctly.
The following circuitry should generate a valid reset signal far enough from the raise
of the supply voltage:
![](./docs/reset-circuit.jpeg)
The circuit generates the following signals:
![](./docs/reset-signal.png)
#### Reference voltage (green):
```math
U_ref = 3.3V \frac{22k\Omega}{22k\Omega + 10k\Omega} = 2.2V
```
#### Trigger voltage (purple):
```math
U_trigg = 3.3V \frac{330k\Omega}{330k\Omega + 82k\Omega} = 2.64V
```
#### RC constant:
```math
\tau = 82k\Omega \cdot 100nF = 8.2ms
```