summaryrefslogtreecommitdiff
path: root/fw/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'fw/main.c')
-rw-r--r--fw/main.c97
1 files changed, 97 insertions, 0 deletions
diff --git a/fw/main.c b/fw/main.c
new file mode 100644
index 0000000..360728e
--- /dev/null
+++ b/fw/main.c
@@ -0,0 +1,97 @@
+/* Megumin LED display firmware
+ * Copyright (C) 2018 Sebastian Götte <code@jaseg.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "global.h"
+#include "i2c.h"
+#include "mpu6050.h"
+
+uint32_t pcg32_random_r() {
+ // *Really* minimal PCG32 code / (c) 2014 M.E. O'Neill / pcg-random.org
+ // Licensed under Apache License 2.0 (NO WARRANTY, etc. see website)
+ static uint64_t state = 0xbc422715d3aef60f;
+ static uint64_t inc = 0x6605e3bc6d1a869b;
+ uint64_t oldstate = state;
+ // Advance internal state
+ state = oldstate * 6364136223846793005ULL + (inc|1);
+ // Calculate output function (XSH RR), uses old state for max ILP
+ uint32_t xorshifted = ((oldstate >> 18u) ^ oldstate) >> 27u;
+ uint32_t rot = oldstate >> 59u;
+ return (xorshifted >> rot) | (xorshifted << ((-rot) & 31));
+}
+
+unsigned char dumb_random() {
+ static unsigned char x=0x66, a=0x05, b=0xe3, c=0xbc;
+ x++; //x is incremented every round and is not affected by any other variable
+ a = (a ^ c ^ x); //note the mix of addition and XOR
+ b = (b + a); //And the use of very few instructions
+ c = ((c + (b >> 1) ^ a)); // the AES S-Box Operation ensures an even distributon of entropy
+ return (c);
+}
+
+int main(void) {
+ /* We're starting out from HSI@8MHz */
+ SystemCoreClockUpdate();
+
+ /* Turn on lots of neat things */
+ RCC->AHBENR |= RCC_AHBENR_GPIOAEN | RCC_AHBENR_GPIOBEN;
+
+ GPIOA->MODER |=
+ (1<<GPIO_MODER_MODER1_Pos)| /* PA1 - Port 1 */
+ (1<<GPIO_MODER_MODER2_Pos)| /* PA2 - Port 2 */
+ (1<<GPIO_MODER_MODER3_Pos)| /* PA3 - Port 3 */
+ (1<<GPIO_MODER_MODER4_Pos)| /* PA4 - Port 4 */
+ (1<<GPIO_MODER_MODER9_Pos); /* PA9 - LED */
+
+ int idx = 1;
+ while (1) {
+ GPIOA->ODR ^= (1<<9);
+ GPIOA->ODR = 2<<idx;
+ idx += 1;
+ if (idx > 4)
+ idx = 1;
+ for (size_t j=0; j<1000000; j++) {
+ asm volatile ("nop");
+ }
+ }
+}
+
+void gdb_dump(void) {
+ /* debugger hook */
+}
+
+void NMI_Handler(void) {
+ asm volatile ("bkpt");
+}
+
+void HardFault_Handler(void) __attribute__((naked));
+void HardFault_Handler() {
+ asm volatile ("bkpt");
+}
+
+void SVC_Handler(void) {
+ asm volatile ("bkpt");
+}
+
+
+void PendSV_Handler(void) {
+ asm volatile ("bkpt");
+}
+
+void SysTick_Handler(void) {
+ asm volatile ("bkpt");
+}
+