dc33-retro-tech-addon/firmware/retro_tech_fw/code/ch32x035_it.c
true 805489c98f initial commit of in-progress port
what remains to be done:
- soft i2c master timings
- clock mode switching and render compensation when using i2c master code
- testing
2025-07-24 03:37:26 -07:00

86 lines
1.9 KiB
C

/********************************** (C) COPYRIGHT *******************************
* File Name : ch32x035_it.c
* Author : WCH
* Version : V1.0.0
* Date : 2024/10/28
* Description : Main Interrupt Service Routines.
*********************************************************************************
* Copyright (c) 2021 Nanjing Qinheng Microelectronics Co., Ltd.
* Attention: This software (modified or not) and binary are used for
* microcontroller manufactured by Nanjing Qinheng Microelectronics.
*******************************************************************************/
#include "ch32x035_it.h"
#include "ch32x035.h"
#include "src/adc.h"
#include "src/btn.h"
#include "src/led.h"
/* __attribute__((interrupt("WCH-Interrupt-fast"))); */
void NMI_Handler(void);
void HardFault_Handler(void);
void SysTick_Handler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
/*********************************************************************
* @fn NMI_Handler
*
* @brief This function handles NMI exception.
*
* @return none
*/
void NMI_Handler(void)
{
while (1);
}
/*********************************************************************
* @fn HardFault_Handler
*
* @brief This function handles Hard Fault exception.
*
* @return none
*/
void HardFault_Handler(void)
{
NVIC_SystemReset();
while (1);
}
/* retro tech code
*/
volatile uint16_t ticnt;
volatile uint32_t uptime;
void SysTick_Handler(void)
{
if (++ticnt > 0x1ff) {
ticnt = 0;
uptime++;
}
// send new LEDs (1/128 duty)
if ((ticnt & 0x3) == 0) {
led_send();
}
// process buttons (1/512 duty)
btn_poll();
// process ADC (1/256 duty)
if ((ticnt & 0x1) == 0) {
adc_convert();
}
if ((ticnt & 0x1) == 1) {
adc_read();
}
// clear comparison flag
SysTick->SR = 0;
return;
}