From 36928bb57ae74e96e7cd93edfd208d162e0592e1 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Sat, 8 Sep 2012 15:59:41 +0200 Subject: Led matrix test. --- .gdbinit | 23 ++++++++++++++++ .gitignore | 5 ++++ .gitmodules | 3 +++ SConstruct | 11 ++++++++ laks | 1 + main.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 132 insertions(+) create mode 100644 .gdbinit create mode 100644 .gitignore create mode 100644 .gitmodules create mode 100644 SConstruct create mode 160000 laks create mode 100644 main.cpp 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 index 0000000..9ae9159 --- /dev/null +++ b/laks @@ -0,0 +1 @@ +Subproject commit 9ae91599772ee81d352014a8ff293c5feec0439b 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 +#include +#include +#include + +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; + } +} -- cgit v1.2.3