summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVegard Storheil Eriksen <zyp@jvnv.net>2012-09-08 15:59:41 +0200
committerVegard Storheil Eriksen <zyp@jvnv.net>2012-09-08 15:59:41 +0200
commit36928bb57ae74e96e7cd93edfd208d162e0592e1 (patch)
treee71b3d18e3b402e7150b1e02c3824f6ea8f2ccdd
Led matrix test.led_matrix
-rw-r--r--.gdbinit23
-rw-r--r--.gitignore5
-rw-r--r--.gitmodules3
-rw-r--r--SConstruct11
m---------laks0
-rw-r--r--main.cpp89
6 files changed, 131 insertions, 0 deletions
diff --git a/.gdbinit b/.gdbinit
new file mode 100644
index 0000000..2844d70
--- /dev/null
+++ b/.gdbinit
@@ -0,0 +1,23 @@
+define flash
+file demo.elf
+load
+end
+
+define restart
+run
+end
+
+define attach_swd
+mon swdp_scan
+attach 1
+end
+
+define attach_jtag
+mon jtag_scan
+attach 1
+end
+
+file demo.elf
+target extended-remote /dev/cu.usbmodem7FC181B1
+
+set mem inaccessible-by-default off
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..b137a4a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+*.o
+*.a
+*.elf
+*.swp
+.sconsign.dblite
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..cd4f3c2
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "laks"]
+ path = laks
+ url = git://git.jvnv.net/laks.git
diff --git a/SConstruct b/SConstruct
new file mode 100644
index 0000000..ff0e6ce
--- /dev/null
+++ b/SConstruct
@@ -0,0 +1,11 @@
+import os
+
+env = Environment(
+ ENV = os.environ,
+)
+
+SConscript('laks/build_rules')
+
+env.SelectMCU('stm32f407zg')
+
+env.Firmware('demo.elf', Glob('*.cpp'))
diff --git a/laks b/laks
new file mode 160000
+Subproject 9ae91599772ee81d352014a8ff293c5feec0439
diff --git a/main.cpp b/main.cpp
new file mode 100644
index 0000000..eab4e69
--- /dev/null
+++ b/main.cpp
@@ -0,0 +1,89 @@
+#include <rcc/rcc.h>
+#include <gpio/pin.h>
+#include <spi/spi.h>
+#include <os/time.h>
+
+Pin& noe = PA3;
+Pin& vsync = PA4;
+Pin& clk = PA5; // SCK
+Pin& hsync = PA6;
+Pin& data = PA7; // MOSI
+
+inline void nopdelay(uint32_t iterations) {
+ while(iterations--) {
+ asm volatile("nop");
+ }
+}
+
+uint32_t buf[] = {
+ 0b1001010100000000,
+ 0b1001010100000000,
+ 0b1111010100000000,
+ 0b1001010000000000,
+ 0b1001010100000000,
+ 0b0000000000000000,
+ 0b0000000000000000,
+ 0b0000000000000000,
+ 0b0000000000000000,
+ 0b0000000000000000,
+ 0b0000000000000000,
+ 0b0000000000000000,
+ 0b0000000000000000,
+ 0b0000000000000000,
+ 0b0000000000000000,
+ 0b0000000000000000,
+};
+
+int main() {
+ // Initialize system timer.
+ STK.LOAD = 168000000 / 8 / 1000; // 1000 Hz.
+ STK.CTRL = 0x03;
+
+ RCC.enable(RCC.GPIOA);
+ RCC.enable(RCC.SPI1);
+
+ noe.set_mode(Pin::Output);
+ noe.off();
+
+ hsync.set_mode(Pin::Output);
+ hsync.off();
+
+ vsync.set_mode(Pin::Output);
+ vsync.on();
+
+ clk.set_mode(Pin::AF);
+ clk.set_af(5);
+
+ data.set_mode(Pin::AF);
+ data.set_af(5);
+
+ SPI1.reg.CR1 = 0xbfc;
+
+ uint32_t row = 0;
+
+ while(1) {
+ // Shift out a row.
+ SPI1.reg.DR = buf[row];
+ while(!(SPI1.reg.SR & 0x01));
+ (void)SPI1.reg.DR;
+
+ // Assert vsync if this is first row.
+ if(row == 0) {
+ vsync.off();
+ }
+
+ // Strobe hsync.
+ hsync.on();
+ nopdelay(10);
+ hsync.off();
+
+ // Deassert vsync.
+ if(row == 0) {
+ vsync.on();
+ }
+
+ Time::sleep(1);
+
+ row = (row + 1) & 0xf;
+ }
+}