prepare display

This commit is contained in:
2024-03-22 18:38:30 +01:00
parent 10a09e3ad3
commit a32ef8fa5b
7 changed files with 73 additions and 5 deletions

View File

@ -11,7 +11,7 @@ CFLAGS=-Wall -mmcu=$(MCU) -std=gnu99 -I $(TOOLCHAIN_PREFIX)/include -O1 -g0
LDFLAGS=-mmcu=$(MCU) -L $(TOOLCHAIN_PREFIX)/include LDFLAGS=-mmcu=$(MCU) -L $(TOOLCHAIN_PREFIX)/include
$(ARTIFACT).elf: main.o spi.o scheduler.o canvas.o shapes.o game.o buttons.o myrand.o $(ARTIFACT).elf: main.o spi.o scheduler.o canvas.o shapes.o game.o buttons.o myrand.o display.o
$(CC) -o $@ $(LDFLAGS) $^ $(CC) -o $@ $(LDFLAGS) $^
$(OBJDUMP) -D $(ARTIFACT).elf > $(ARTIFACT).txt $(OBJDUMP) -D $(ARTIFACT).elf > $(ARTIFACT).txt

50
game-ctrl/display.c Normal file
View File

@ -0,0 +1,50 @@
#include <stdint.h>
#include "display.h"
#include "spi.h"
uint16_t score;
void displayInit() {
score = 0;
spiSendBegin(e_SPI_DISPLAY);
// display test off
spiSendOctet(0x0f);
spiSendOctet(0x01);
// BCD decode for all digits
spiSendOctet(0x09);
spiSendOctet(0xff);
// scan limit to digits 0-3
spiSendOctet(0x0b);
spiSendOctet(0x03);
// intensity
spiSendOctet(0x0a);
spiSendOctet(0x0f);
// normal operation
spiSendOctet(0x0C);
spiSendOctet(0x01);
spiSendEnd(e_SPI_DISPLAY);
}
void displaySetScore(uint16_t v) {
score = v;
spiSendBegin(e_SPI_DISPLAY);
spiSendOctet(0x01);
spiSendOctet(0x07);
spiSendEnd(e_SPI_DISPLAY);
}

13
game-ctrl/display.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef _DISPLAY_H_
#define _DISPLAY_H_
#include <stdint.h>
void displayInit();
void displaySetScore(uint16_t v);
#endif // _DISPLAY_H_

View File

@ -6,6 +6,7 @@
#include "shapes.h" #include "shapes.h"
#include "canvas.h" #include "canvas.h"
#include "../rgb-driver/colors.h" #include "../rgb-driver/colors.h"
#include "display.h"
#define GAME_CYCLE_TIME 100 #define GAME_CYCLE_TIME 100
@ -116,6 +117,8 @@ void gameExec(void *handle) {
} }
} }
} }
displaySetScore(7);
} }
void gameInit() { void gameInit() {

View File

@ -11,6 +11,7 @@
#include "shapes.h" #include "shapes.h"
#include "myrand.h" #include "myrand.h"
#include "spi.h" #include "spi.h"
#include "display.h"
int main() { int main() {
@ -27,6 +28,7 @@ int main() {
schInit(); schInit();
spiInit(); spiInit();
displayInit();
myRandInit(); myRandInit();
canvasInit(); canvasInit();

View File

@ -2,8 +2,8 @@
#include "spi.h" #include "spi.h"
void spiInit() { void spiInit() {
// SPI in master mode // SPI in master mode, most significant bit first
UCB0CTL0 = UCMST; UCB0CTL0 = UCMST | UCMSB;
// SPI timing config // SPI timing config
UCB0CTL1 = UCSSEL_3; UCB0CTL1 = UCSSEL_3;
// Faster than 8 ends up in strange communication errors // Faster than 8 ends up in strange communication errors

View File

@ -122,8 +122,8 @@ init:
mov.w #OUTMOD_7,&TA1CCTL2 mov.w #OUTMOD_7,&TA1CCTL2
;; spi configuration ;; spi configuration
;; USCI B to slave mode ;; USCI B to slave mode, enable STE and most significant bit first
mov.b #UCSYNC|UCMODE_2, &UCB0CTL0 mov.b #UCSYNC|UCMODE_2|UCMSB, &UCB0CTL0
mov.b #0x00, &UCB0CTL1 mov.b #0x00, &UCB0CTL1
;; make sure the isr will not immediately start ;; make sure the isr will not immediately start