From f5b0e67056e27398cf3c3ddd22e331bbb403f65b Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Wed, 13 Mar 2024 14:52:46 +0100 Subject: [PATCH] shapes --- Makefile | 6 ++-- PontCoopScheduler.h | 4 +-- displayDriver.c | 8 +++-- displayTest3.c | 12 +++---- main.c | 7 ++-- shape_i.c | 26 +++++++++++++++ shape_i.h | 14 ++++++++ shape_j.c | 26 +++++++++++++++ shape_j.h | 14 ++++++++ shape_l.c | 26 +++++++++++++++ shape_l.h | 14 ++++++++ shape_o.c | 26 +++++++++++++++ shape_o.h | 14 ++++++++ shape_s.c | 26 +++++++++++++++ shape_s.h | 14 ++++++++ shape_t.c | 26 +++++++++++++++ shape_t.h | 14 ++++++++ shape_z.c | 26 +++++++++++++++ shape_z.h | 14 ++++++++ shapes.c | 81 +++++++++++++++++++++++++++++++++++++++++++++ shapes.h | 11 ++++++ 21 files changed, 391 insertions(+), 18 deletions(-) create mode 100644 shape_i.c create mode 100644 shape_i.h create mode 100644 shape_j.c create mode 100644 shape_j.h create mode 100644 shape_l.c create mode 100644 shape_l.h create mode 100644 shape_o.c create mode 100644 shape_o.h create mode 100644 shape_s.c create mode 100644 shape_s.h create mode 100644 shape_t.c create mode 100644 shape_t.h create mode 100644 shape_z.c create mode 100644 shape_z.h create mode 100644 shapes.c create mode 100644 shapes.h diff --git a/Makefile b/Makefile index 09f9dfa..83acf0e 100644 --- a/Makefile +++ b/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 displayTest2.o displayTest3.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 $(CC) -o $@ $(LDFLAGS) $^ $(OBJDUMP) -D $(ARTIFACT).elf > $(ARTIFACT).txt diff --git a/PontCoopScheduler.h b/PontCoopScheduler.h index b47ef04..f2357b5 100644 --- a/PontCoopScheduler.h +++ b/PontCoopScheduler.h @@ -17,8 +17,8 @@ typedef struct { - uint32_t delay; - uint32_t period; + uint16_t delay; + uint16_t period; uint8_t run; void (*exec)(void *handle); void *handle; diff --git a/displayDriver.c b/displayDriver.c index 6012ac7..04fd7b5 100644 --- a/displayDriver.c +++ b/displayDriver.c @@ -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 @@ -33,7 +33,11 @@ void displayDriverInit() { UCB0CTL0 = UCMST; // SPI timing config UCB0CTL1 = UCSSEL_3; - UCB0BR0 = 4; // 2 would be too fast and ends up with errors + // 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 diff --git a/displayTest3.c b/displayTest3.c index 9ab60c7..6ce6b3c 100644 --- a/displayTest3.c +++ b/displayTest3.c @@ -20,22 +20,22 @@ void displayTest3Exec(void *args) { break; case e_delay: - canvasClear(); state = e_start; break; case e_start: + canvasClear(); state = e_fillArea; break; case e_fillArea: - memset((canvas.canvas)+(canvas.width*7), 0x84, 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); + 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, 0x05); + canvasSetPixel(i, 6, 0x01); } } state = e_placeObject; diff --git a/main.c b/main.c index 2aa0f8b..101ddeb 100644 --- a/main.c +++ b/main.c @@ -8,9 +8,7 @@ #include "led.h" #include "displayDriver.h" #include "canvas.h" -#include "displayTest.h" -#include "displayTest2.h" -#include "displayTest3.h" +#include "shapes.h" int main() { @@ -24,15 +22,14 @@ int main() { BCSCTL2 = 0; BCSCTL3 = 0; - timeInit(); schInit(); ledInit(); displayDriverInit(); canvasInit(); - displayTest3Init(); + shapesInit(); __enable_interrupt(); diff --git a/shape_i.c b/shape_i.c new file mode 100644 index 0000000..5e65414 --- /dev/null +++ b/shape_i.c @@ -0,0 +1,26 @@ +#include "shapes.h" +#include "shape_i.h" + +uint8_t draw_i() { + return 0; +} + +uint8_t moveDown_i() { + return 0; +} + +uint8_t moveLeft_i() { + return 0; +} + +uint8_t moveRight_i() { + return 0; +} + +uint8_t rotateLeft_i() { + return 0; +} + +uint8_t rotateRight_i() { + return 0; +} diff --git a/shape_i.h b/shape_i.h new file mode 100644 index 0000000..83f0e98 --- /dev/null +++ b/shape_i.h @@ -0,0 +1,14 @@ +#ifndef _SHAPE_I_H_ +#define _SHAPE_I_H_ + +#include + +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_ diff --git a/shape_j.c b/shape_j.c new file mode 100644 index 0000000..5f0e7b6 --- /dev/null +++ b/shape_j.c @@ -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; +} diff --git a/shape_j.h b/shape_j.h new file mode 100644 index 0000000..af6f141 --- /dev/null +++ b/shape_j.h @@ -0,0 +1,14 @@ +#ifndef _SHAPE_J_H_ +#define _SHAPE_J_H_ + +#include + +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_ diff --git a/shape_l.c b/shape_l.c new file mode 100644 index 0000000..9d7b421 --- /dev/null +++ b/shape_l.c @@ -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; +} diff --git a/shape_l.h b/shape_l.h new file mode 100644 index 0000000..1426d04 --- /dev/null +++ b/shape_l.h @@ -0,0 +1,14 @@ +#ifndef _SHAPE_L_H_ +#define _SHAPE_L_H_ + +#include + +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_ diff --git a/shape_o.c b/shape_o.c new file mode 100644 index 0000000..ba84f7f --- /dev/null +++ b/shape_o.c @@ -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; +} diff --git a/shape_o.h b/shape_o.h new file mode 100644 index 0000000..927371f --- /dev/null +++ b/shape_o.h @@ -0,0 +1,14 @@ +#ifndef _SHAPE_O_H_ +#define _SHAPE_O_H_ + +#include + +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_ diff --git a/shape_s.c b/shape_s.c new file mode 100644 index 0000000..07ef3c9 --- /dev/null +++ b/shape_s.c @@ -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; +} diff --git a/shape_s.h b/shape_s.h new file mode 100644 index 0000000..ea1837b --- /dev/null +++ b/shape_s.h @@ -0,0 +1,14 @@ +#ifndef _SHAPE_S_H_ +#define _SHAPE_S_H_ + +#include + +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_ diff --git a/shape_t.c b/shape_t.c new file mode 100644 index 0000000..09638e0 --- /dev/null +++ b/shape_t.c @@ -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; +} diff --git a/shape_t.h b/shape_t.h new file mode 100644 index 0000000..f1b6c4c --- /dev/null +++ b/shape_t.h @@ -0,0 +1,14 @@ +#ifndef _SHAPE_T_H_ +#define _SHAPE_T_H_ + +#include + +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_ diff --git a/shape_z.c b/shape_z.c new file mode 100644 index 0000000..12e2857 --- /dev/null +++ b/shape_z.c @@ -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; +} diff --git a/shape_z.h b/shape_z.h new file mode 100644 index 0000000..d90a8fa --- /dev/null +++ b/shape_z.h @@ -0,0 +1,14 @@ +#ifndef _SHAPE_Z_H_ +#define _SHAPE_Z_H_ + +#include + +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_ diff --git a/shapes.c b/shapes.c new file mode 100644 index 0000000..bf396ee --- /dev/null +++ b/shapes.c @@ -0,0 +1,81 @@ +#include +#include + +#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 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; + +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; + +uint8_t draw() { + return stoneOperations[stone.shape].draw(); +} + +uint8_t moveDown() { + return stoneOperations[stone.shape].moveDown(); +} + +uint8_t moveLeft() { + return stoneOperations[stone.shape].moveLeft(); +} + +uint8_t moveRight() { + return stoneOperations[stone.shape].moveRight(); +} + +uint8_t rotateLeft() { + return stoneOperations[stone.shape].rotateLeft(); +} + +uint8_t rotateRight() { + return stoneOperations[stone.shape].rotateRight(); +} + +void shapesExec(void *handle) { + draw(); +} + +void shapesInit() { + shapesExec(NULL); +} + + + + + + diff --git a/shapes.h b/shapes.h new file mode 100644 index 0000000..1861010 --- /dev/null +++ b/shapes.h @@ -0,0 +1,11 @@ +#ifndef _SHAPES_H_ +#define _SHAPES_H_ + + + +void shapesInit(); +void shapesExec(void *handle); + + + +#endif // _SHAPES_H_