90 lines
2.4 KiB
C
90 lines
2.4 KiB
C
/*
|
|
* RETRO TECH COMMUNITY
|
|
* GAT Addon Firmware
|
|
* by true
|
|
*
|
|
* code was made for different random addons I designed for dc32,
|
|
* then adapted to each one. so things might be a mess.
|
|
*
|
|
* I had only a few hours on and off over a week to get the code done.
|
|
* lots of shit was copied from demo code and adapted to work. certainly
|
|
* isn't the best way to get this done.
|
|
*
|
|
* I know I could save some power, but seeing as all the badges burn it in
|
|
* LEDs and almost nobody else power optimizes their badge code, who cares?
|
|
*
|
|
* sorry. wasn't procrastination I swear. all the ideas were last minute.
|
|
*/
|
|
|
|
#include <ch32v00x.h>
|
|
#include <stdint.h>
|
|
|
|
#include "src/adc.h"
|
|
#include "src/btn.h"
|
|
#include "src/config.h"
|
|
#include "src/i2c.h"
|
|
#include "src/led.h"
|
|
#include "src/rand.h"
|
|
#include "src/ui.h"
|
|
|
|
|
|
void systick_init(void)
|
|
{
|
|
SysTick->CMP = (SystemCoreClock / 2000) - 1; // we want a 2KHz interrupt
|
|
SysTick->CNT = 0; // clear counter
|
|
SysTick->CTLR = 0xF; // start counter in /1 mode, enable interrupts, auto-reset counter
|
|
SysTick->SR = 0; // clear count comparison flag
|
|
|
|
NVIC_EnableIRQ(SysTicK_IRQn); // enable interrupt
|
|
}
|
|
|
|
/*********************************************************************
|
|
* @fn main
|
|
*
|
|
* @brief Main program.
|
|
*
|
|
* @return none
|
|
*/
|
|
int main(void)
|
|
{
|
|
// configure core
|
|
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
|
|
SystemCoreClockUpdate();
|
|
|
|
// enable peripheral clocks
|
|
RCC_APB1PeriphClockCmd( RCC_APB1Periph_PWR | RCC_APB1Periph_I2C1, ENABLE);
|
|
RCC_APB2PeriphClockCmd( RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA |
|
|
RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD |
|
|
RCC_APB2Periph_ADC1 | RCC_APB2Periph_TIM1, ENABLE);
|
|
|
|
// get saved settings
|
|
i2c_init();
|
|
userconf_load();
|
|
|
|
// configure hardware
|
|
adc_init();
|
|
btn_init();
|
|
led_init();
|
|
|
|
// configure random
|
|
tinymt32_init(&tinymt32_s, DBGMCU_GetCHIPID() | userconf.checksum);
|
|
|
|
// configure UI
|
|
ui_init();
|
|
|
|
// configure systick interrupt
|
|
systick_init();
|
|
|
|
// do system shit
|
|
while(1) {
|
|
__WFI();
|
|
|
|
// after sending LEDs, run our program
|
|
// to update the LED buffer for next time
|
|
// we have approx 7ms to render... plenty of time
|
|
if ((ticnt & 0xf) == 3) {
|
|
ui_render();
|
|
}
|
|
}
|
|
}
|