some progress
This commit is contained in:
parent
68bb67e9af
commit
40dbb62db7
2
Makefile
2
Makefile
@ -11,7 +11,7 @@ CFLAGS=-Wall -mmcu=$(MCU) -std=gnu99 -I $(TOOLCHAIN_PREFIX)/include -O3 -g0
|
||||
|
||||
LDFLAGS=-mmcu=$(MCU) -L $(TOOLCHAIN_PREFIX)/include
|
||||
|
||||
$(ARTIFACT).elf: main.o led.o time.o PontCoopScheduler.o spi.o
|
||||
$(ARTIFACT).elf: main.o led.o time.o PontCoopScheduler.o displayDriver.o canvas.o displayTest.o
|
||||
$(CC) -o $@ $(LDFLAGS) $^
|
||||
$(OBJDUMP) -D $(ARTIFACT).elf > $(ARTIFACT).txt
|
||||
|
||||
|
@ -13,7 +13,7 @@
|
||||
|
||||
|
||||
|
||||
#define MAX_NUM_OF_TASKS 32
|
||||
#define MAX_NUM_OF_TASKS 4
|
||||
|
||||
|
||||
typedef struct {
|
||||
|
31
canvas.c
Normal file
31
canvas.c
Normal file
@ -0,0 +1,31 @@
|
||||
#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();
|
||||
}
|
||||
|
||||
|
23
canvas.h
Normal file
23
canvas.h
Normal file
@ -0,0 +1,23 @@
|
||||
#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_
|
54
displayDriver.c
Normal file
54
displayDriver.c
Normal file
@ -0,0 +1,54 @@
|
||||
#include "displayDriver.h"
|
||||
#include "led.h"
|
||||
#include "canvas.h"
|
||||
#include <msp430g2553.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
|
||||
static void spiSendOctet(uint8_t v) {
|
||||
// wait for TX buffer empty
|
||||
while (!(UC0IFG & UCB0TXIFG));
|
||||
// load octet into TX buffer
|
||||
UCB0TXBUF = v;
|
||||
}
|
||||
|
||||
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;
|
||||
spiSendOctet(i);
|
||||
spiSendOctet(*((canvas->canvas)+i));
|
||||
}
|
||||
}
|
||||
spiSendOctet(0xfe);
|
||||
}
|
||||
|
||||
void displayDriverInit() {
|
||||
// SPI in master mode
|
||||
UCB0CTL0 = UCMST;
|
||||
// SPI timing config
|
||||
UCB0CTL1 = UCSSEL_3;
|
||||
UCB0BR0 = 8;
|
||||
UCB0BR1 = 0;
|
||||
|
||||
// BIT5: UCB0CLK
|
||||
// BIT6: UCB0SOMI
|
||||
// BIT7: UCB0SIMO
|
||||
P1SEL |= BIT5 | BIT6 | BIT7;
|
||||
P1SEL2 |= BIT5 | BIT6 | BIT7;
|
||||
P1DIR |= BIT5 | BIT7;
|
||||
|
||||
// P1.3 is signal line
|
||||
P1DIR &= ~BIT3;
|
||||
|
||||
// enable SPI module
|
||||
UCB0CTL1 &= ~UCSWRST;
|
||||
}
|
||||
|
||||
|
9
displayDriver.h
Normal file
9
displayDriver.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef _DISPLAY_DRIVER_H_
|
||||
#define _DISPLAY_DRIVER_H_
|
||||
|
||||
void displayDriverInit();
|
||||
void displayDriverTransferCanvas();
|
||||
|
||||
|
||||
|
||||
#endif // _DISPLAY_DRIVER_H_
|
29
displayTest.c
Normal file
29
displayTest.c
Normal file
@ -0,0 +1,29 @@
|
||||
#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);
|
||||
}
|
||||
|
11
displayTest.h
Normal file
11
displayTest.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef _DISPLAY_TEST_H_
|
||||
#define _DISPLAY_TEST_H_
|
||||
|
||||
|
||||
void displayTestInit();
|
||||
void displayTestExec();
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // _DISPLAY_TEST_H_
|
11
led.c
11
led.c
@ -20,16 +20,14 @@ void ledBlueOff() {
|
||||
P1OUT &= ~BIT1;
|
||||
}
|
||||
|
||||
void ledExec() {
|
||||
void ledExec(void *args) {
|
||||
static int i = 0;
|
||||
|
||||
if (i == 0) {
|
||||
ledGreenOff();
|
||||
ledBlueOn();
|
||||
i = 1;
|
||||
} else {
|
||||
ledGreenOn();
|
||||
ledBlueOff();
|
||||
i = 0;
|
||||
}
|
||||
}
|
||||
@ -38,9 +36,12 @@ void ledInit() {
|
||||
// BIT0: green
|
||||
// BIT1: blue
|
||||
P1DIR |= BIT0|BIT1;
|
||||
P1OUT |= BIT0|BIT1;
|
||||
|
||||
schAdd(ledExec, NULL, 0, 50);
|
||||
ledGreenOff();
|
||||
ledBlueOff();
|
||||
|
||||
|
||||
// schAdd(ledExec, NULL, 0, 50);
|
||||
}
|
||||
|
||||
|
||||
|
10
main.c
10
main.c
@ -5,9 +5,10 @@
|
||||
|
||||
#include "time.h"
|
||||
#include "PontCoopScheduler.h"
|
||||
|
||||
#include "led.h"
|
||||
#include "spi.h"
|
||||
#include "displayDriver.h"
|
||||
#include "canvas.h"
|
||||
#include "displayTest.h"
|
||||
|
||||
|
||||
int main() {
|
||||
@ -26,7 +27,10 @@ int main() {
|
||||
schInit();
|
||||
|
||||
ledInit();
|
||||
spiInit();
|
||||
displayDriverInit();
|
||||
canvasInit();
|
||||
displayTestInit();
|
||||
|
||||
|
||||
__enable_interrupt();
|
||||
|
||||
|
45
spi.c
45
spi.c
@ -1,45 +0,0 @@
|
||||
#include "spi.h"
|
||||
#include <msp430g2553.h>
|
||||
#include "PontCoopScheduler.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
|
||||
static void spiSendOctet(uint8_t v) {
|
||||
while (!(UC0IFG & UCB0TXIFG));
|
||||
UCB0TXBUF = v;
|
||||
}
|
||||
|
||||
void spiExec() {
|
||||
// enable spi
|
||||
UCB0CTL1 &= ~UCSWRST;
|
||||
|
||||
spiSendOctet(0x00);
|
||||
spiSendOctet(0x0d);
|
||||
|
||||
// disable spi
|
||||
UCB0CTL1 |= UCSWRST;
|
||||
|
||||
// reschedule
|
||||
schAdd(spiExec, NULL, 1000, 0);
|
||||
}
|
||||
|
||||
void spiInit() {
|
||||
UCB0CTL0 = UCMST | UCSYNC;
|
||||
UCB0CTL1 = UCSSEL_3;
|
||||
UCB0BR0 = 8;
|
||||
UCB0BR1 = 0;
|
||||
|
||||
// UCB0CLK, UCB0SOMI, UCB0SIMO
|
||||
P1SEL |= BIT5 | BIT6 | BIT7;
|
||||
P1SEL2 |= BIT5 | BIT6 | BIT7;
|
||||
P1OUT |= BIT5 | BIT7;
|
||||
|
||||
// P1.3 is signal line
|
||||
P1DIR &= ~BIT3;
|
||||
|
||||
schAdd(spiExec, NULL, 1000, 0);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user