commit 6c15dbb7f2084763dadae426c519fb4b534b1907
parent 63cd1eab4d03fa024d3521a1402e5290e593e71f
Author: Henry Wilson <m3henry@googlemail.com>
Date: Fri, 9 Feb 2018 02:13:12 +0000
Added missing files from previous commits
Diffstat:
A | ctrl.cpp | | | 4 | ++++ |
A | ctrl.h | | | 15 | +++++++++++++++ |
A | hidModule.cpp | | | 39 | +++++++++++++++++++++++++++++++++++++++ |
A | hidModule.h | | | 61 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | lcd.h | | | 113 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
A | utils.h | | | 20 | ++++++++++++++++++++ |
6 files changed, 252 insertions(+), 0 deletions(-)
diff --git a/ctrl.cpp b/ctrl.cpp
@@ -0,0 +1,4 @@
+
+#include "ctrl.h"
+
+volatile uint8_t& ctrl::mcu = memory(0x55);
diff --git a/ctrl.h b/ctrl.h
@@ -0,0 +1,15 @@
+#pragma once
+#include "utils.h"
+
+namespace ctrl
+{
+extern volatile uint8_t& mcu;
+
+inline void disableJTAG()
+{
+ auto tmp = mcu | bit(7);
+ mcu = tmp;
+ mcu = tmp;
+}
+
+}
diff --git a/hidModule.cpp b/hidModule.cpp
@@ -0,0 +1,39 @@
+#include "hidModule.h"
+#include "ctrl.h"
+
+void hid::test()
+{
+ ctrl::disableJTAG();
+
+ io::direction::B() = ledRED;
+
+ io::direction::C() = 0;
+ io::out::C() = 0xFF;
+
+ uint8_t stateD = 0;
+ io::out::D() = buttonCOM;
+ io::direction::D() = buttonCOM | wheelCOM | ledYEL | ledGRN;
+
+ for (;;)
+ {
+ auto val = ~io::pin::C();
+ io::out::D() = wheelCOM | stateD;
+ auto r = (val << 3) & ledRED;
+ auto a = (val << 2) & ledYEL;
+ auto b = (val << 3) & ledGRN;
+
+ io::out::B() = r;
+ io::out::D() = wheelCOM | (stateD = a | b);
+
+ auto butts = ~io::pin::C();
+ io::out::D() = buttonCOM | stateD;
+
+ if (butts & buttonD) butts = 0xFF;
+ auto x = (butts << 3) & ledRED;
+ auto y = (butts << 2) & ledYEL;
+ auto z = (butts << 3) & ledGRN;
+
+ io::out::B() = x;
+ io::out::D() = buttonCOM | (stateD = y | z);
+ }
+}
diff --git a/hidModule.h b/hidModule.h
@@ -0,0 +1,61 @@
+#pragma once
+
+#include "io.h"
+
+/*
+10 GND
+ 9 C5
+8
+ 7 AREF
+6 _RESET_
+ 5 C3
+4 AVCC
+ 3 C4
+2 GND
+ 1 C2
+
+
+ B0
+ B1 SD ???
+ B2 !USB!
+ B3 !USB!
+ B4 SD _SS_
+ B5 SD MOSI
+ B6 SD MISO
+ B7 SD SCLK | LED red
+
+ C2 U-B | W-A
+ C3 D-B | W-B
+ C4 R-B | C-B
+ C5 L-B
+
+ D0 BUTTON COM B
+ D1 WHEEL COM A
+ D2 RS232 RX1
+ D3 RS232 TX1
+ D4 LED yellow
+ D5 L OC1A | ADC5
+ D6 LED green
+ D7 R OC2A | ADC7
+*/
+namespace hid {
+
+constexpr auto buttonCOM = bit(0);
+constexpr auto buttonL = bit(2);
+constexpr auto buttonU = bit(3);
+constexpr auto buttonR = bit(4);
+constexpr auto buttonD = bit(5);
+
+constexpr auto wheelCOM = bit(1);
+constexpr auto wheelA = bit(2);
+constexpr auto wheelB = bit(3);
+constexpr auto buttonC = bit(4);
+
+constexpr auto ledRED = bit(7);
+constexpr auto ledYEL = bit(4);
+constexpr auto ledGRN = bit(6);
+
+[[noreturn]]
+void test();
+
+}
diff --git a/lcd.h b/lcd.h
@@ -0,0 +1,113 @@
+#pragma once
+
+#include "io.h"
+
+#include <util/delay.h>
+
+/*
+ A0~ chip select
+ A1 Backlight
+ A2~ Reset
+ A3~ Write
+ A4~ Command
+ A5~ Read
+ A6~ Vsync
+ A7~ Hsync
+
+ C[0-7] DATA BUS
+*/
+namespace lcd {
+
+constexpr auto n_select = ~bit(0);
+constexpr auto backlight = bit(1);
+constexpr auto n_reset = ~bit(2);
+constexpr auto n_write = ~bit(3);
+constexpr auto n_command = ~bit(4);
+constexpr auto n_read = ~bit(5);
+constexpr auto n_vsync = ~bit(6);
+constexpr auto n_hsync = ~bit(7);
+
+constexpr auto defaultControl = n_select;
+
+auto& control = io::out::A();
+auto& data = io::out::C();
+auto& controlDir = io::direction::A();
+auto& dataDir = io::direction::C();
+
+[[noreturn]] void test();
+
+void send(const uint8_t d)
+{
+ control = defaultControl & n_write;
+ data = d;
+ control = defaultControl;
+}
+
+void send(const uint16_t d)
+{
+ send(uint8_t(d >> 8));
+ send(uint8_t(d));
+}
+
+template <typename...Ts>
+void cmd(const uint8_t c, Ts... params)
+{
+ control = defaultControl & n_command & n_write;
+ data = c;
+ control = defaultControl;
+
+ // https://stackoverflow.com/questions/25680461/variadic-template-pack-expansion#25683817
+ // TODO:(C++17) send(params), ...;
+ char dummy[] __attribute__((unused)) {0, (send(uint8_t(params)), '\0')...};
+}
+
+void init()
+{
+ controlDir = 0xFF;
+ dataDir = 0xFF;
+
+ control = defaultControl & n_reset;
+ _delay_us(16);
+ control = defaultControl;
+ _delay_ms(128);
+
+
+ cmd(0x11); // awake
+ _delay_ms(6);
+
+ cmd(0x3A, 0x55); // 16 bits per pixel
+
+ cmd(0x29); // display ON
+}
+
+[[noreturn]]
+void test()
+{
+ union pixel
+ {
+ struct __attribute__((packed)) {
+ uint8_t r:5;
+ uint8_t g:6;
+ uint8_t b:5;
+ };
+ uint16_t word;
+
+ pixel() : word(0) {}
+ } p;
+
+ static_assert(sizeof(pixel) == sizeof(uint16_t), "not correct size");
+
+ init();
+
+ cmd(0x2C);
+
+ for (;;)
+ {
+ if (0 == ++p.r) if (0 == ++p.b) --p.g;
+
+ send(p.word);
+ //send(uint16_t(0xF800));
+ }
+}
+
+}
diff --git a/utils.h b/utils.h
@@ -0,0 +1,20 @@
+#pragma once
+#include <inttypes.h>
+
+template <typename T = uint8_t>
+constexpr T volatile& memory(const uintptr_t addr)
+{
+ return *reinterpret_cast<T*>(addr);
+}
+
+inline constexpr uint8_t bit(const uint8_t shift)
+{
+// static_assert(8 > shift, "must be in range (0, 7)");
+ return uint8_t(1) << shift;
+}
+
+inline constexpr uint16_t wbit(const uint8_t shift)
+{
+// static_assert(8 > shift, "must be in range (0, 7)");
+ return uint8_t(1) << shift;
+}