/* Megumin LED display firmware * Copyright (C) 2018 Sebastian Götte * * 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 . */ #include "global.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)); } int main(void){ /* We're starting out from HSI@8MHz */ SystemCoreClockUpdate(); SCB->SCR &= (~SCB_SCR_SLEEPONEXIT_Msk) & (~SCB_SCR_SLEEPDEEP_Msk); /* Disable for now */ for (int i=0; i<50000; i++) asm volatile ("nop"); /* Turn on lots of neat things */ RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_AFIOEN; RCC->APB1ENR |= RCC_APB1ENR_TIM3EN | RCC_APB1ENR_TIM4EN; GPIOC->CRH |= (0<CRL |= (2<MAPR |= (2 << AFIO_MAPR_TIM3_REMAP_Pos); /* Map TIM3_CH2 to PB5 */ GPIOB->CRH |= (2<ODR |= 1<<13; /* LED */ TIM3->SMCR = (3<CR2 = (4<CCR3 = thr[0]; TIM4->CCR4 = thr[1]; TIM4->CCR1 = thr[0]; TIM3->CCR2 = thr[1] - thr[0]; TIM3->ARR = 0xfffe; TIM4->ARR = 0xffff; TIM3->CCER = TIM_CCER_CC2E; TIM3->CCMR1 = (0<CCER = TIM_CCER_CC3E | TIM_CCER_CC4E | TIM_CCER_CC1E | TIM_CCER_CC3P | TIM_CCER_CC4P; TIM4->CCMR1 = (0<CCMR2 = (0<CR1 = TIM_CR1_ARPE | TIM_CR1_OPM | TIM_CR1_OPM; TIM4->CR1 = TIM_CR1_ARPE | TIM_CR1_CEN; for (;;) { } } 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"); }