diff options
author | jaseg <jaseg@jaseg.net> | 2013-12-17 12:35:28 +0100 |
---|---|---|
committer | jaseg <jaseg@jaseg.net> | 2013-12-17 12:39:00 +0100 |
commit | cc9378fe4f9d270586da733101f0d44d90a71f10 (patch) | |
tree | 8a765c21935be824db6fdd79a1abd7a725146443 /firmware | |
parent | 0410b967b5f38eca56f5e3b775f25cd0b717ba40 (diff) | |
download | matelight-cc9378fe4f9d270586da733101f0d44d90a71f10.tar.gz matelight-cc9378fe4f9d270586da733101f0d44d90a71f10.tar.bz2 matelight-cc9378fe4f9d270586da733101f0d44d90a71f10.zip |
Added double buffering (untested)
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/main.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/firmware/main.c b/firmware/main.c index 89473de..32b9c31 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -67,7 +67,10 @@ unsigned const char const CRATE_MAP[CRATES_PER_BUS] = { #define SYSTICKS_PER_SECOND 100
#define SYSTICK_PERIOD_MS (1000 / SYSTICKS_PER_SECOND)
-unsigned char framebuffer[BUS_COUNT*BUS_SIZE];
+unsigned char framebuffer1[BUS_COUNT*BUS_SIZE];
+unsigned char framebuffer2[BUS_COUNT*BUS_SIZE];
+unsigned char *framebuffer_input = framebuffer1;
+unsigned char *framebuffer_output = framebuffer2;
unsigned long framebuffer_read(void *data, unsigned long len);
/* Kick off DMA transfer from RAM to SPI interfaces */
void kickoff_transfers(void);
@@ -167,10 +170,10 @@ unsigned long framebuffer_read(void *data, unsigned long len) { unsigned int bottle = BOTTLE_MAP[x + y*CRATE_WIDTH];
unsigned int dst = bus*BUS_SIZE + (crate*CRATE_SIZE + bottle)*3;
unsigned int src = (y*CRATE_WIDTH + x)*3;
- // Copy r, g and b data
- framebuffer[dst] = fb->rgb_data[src];
- framebuffer[dst + 1] = fb->rgb_data[src + 1];
- framebuffer[dst + 2] = fb->rgb_data[src + 2];
+ /* Copy r, g and b data */
+ framebuffer_input[dst] = fb->rgb_data[src];
+ framebuffer_input[dst + 1] = fb->rgb_data[src + 1];
+ framebuffer_input[dst + 2] = fb->rgb_data[src + 2];
}
}
@@ -180,6 +183,11 @@ unsigned long framebuffer_read(void *data, unsigned long len) { }
void kickoff_transfers() {
+ /* Swap buffers */
+ unsigned char *tmp = framebuffer_output;
+ framebuffer_output = framebuffer_input;
+ framebuffer_input = tmp;
+ /* Re-schedule DMA transfers */
kickoff_transfer(11, 0, SSI0_BASE);
kickoff_transfer(25, 1, SSI1_BASE);
kickoff_transfer(13, 2, SSI2_BASE);
@@ -187,7 +195,7 @@ void kickoff_transfers() { }
void kickoff_transfer(unsigned int channel, unsigned int offset, int base) {
- ROM_uDMAChannelTransferSet(channel | UDMA_PRI_SELECT, UDMA_MODE_BASIC, framebuffer+BUS_SIZE*offset, (void *)(base + SSI_O_DR), BUS_SIZE);
+ ROM_uDMAChannelTransferSet(channel | UDMA_PRI_SELECT, UDMA_MODE_BASIC, framebuffer_output+BUS_SIZE*offset, (void *)(base + SSI_O_DR), BUS_SIZE);
ROM_uDMAChannelEnable(channel);
}
|