got LEDs working, ribbon trail program initially implemented

- fixed soft I2C master set hi/lo routines
- fixed bug in matrix_send not setting all LEDs from map
- fix AWU interrupt not firing; requires EXTI line to be configured too even if unused
- fixed wrong dividers used in system clock set function
This commit is contained in:
true
2026-05-08 16:12:18 -07:00
parent d95af918fa
commit abd985e3a1
10 changed files with 117 additions and 56 deletions

View File

@@ -47,10 +47,15 @@ void clk_init()
void periphclk_init()
{
// needed for GPIO, remap, ADC, SPI
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO |
RCC_APB2Periph_ADC1 | RCC_APB2Periph_SPI1, ENABLE);
// may be needed for AWU
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
// needed for DMA, USBPD
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1 | RCC_AHBPeriph_USBPD, ENABLE);
}
@@ -100,6 +105,31 @@ void gpio_init()
// todo later
}
void awu_init()
{
NVIC_InitTypeDef nvic;
EXTI_InitTypeDef exti = {0};
// configure AWU
AWU_SetPrescaler(AWU_Prescaler_1);
AWU_SetWindowValue(0x2f);
AutoWakeUpCmd(ENABLE);
// configure EXTI line
exti.EXTI_Line = EXTI_Line27;
exti.EXTI_Mode = EXTI_Mode_Interrupt;
exti.EXTI_Trigger = EXTI_Trigger_Rising;
exti.EXTI_LineCmd = ENABLE;
EXTI_Init(&exti);
// configure PFIC interrupt
nvic.NVIC_IRQChannel = AWU_IRQn;
nvic.NVIC_IRQChannelPreemptionPriority = 0;
nvic.NVIC_IRQChannelSubPriority = 0;
nvic.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvic);
}
/*********************************************************************
@@ -130,22 +160,20 @@ int main(void)
// set up accelerometer
spim_init();
// configure AWU to provide ~1440Hz wakeup interrupt for main program
// configure AWU to provide ~997Hz wakeup interrupt for main program
// TODO: confirm if the counter is reset / preloaded
AWU_SetPrescaler(AWU_Prescaler_32);
AWU_SetWindowValue(0x3e);
AutoWakeUpCmd(ENABLE);
awu_init();
while (1) {
// low-priority tasks like
// rendering next LED program output frame
if (lp_render) {
lp_render = 0;
lp_ribbon_upward(800, 3, 2);
lp_ribbon_upward(200, 3, 4);
}
// stay a while
// __WFI();
__WFI();
}
}
@@ -154,13 +182,13 @@ void AWU_IRQHandler(void) __attribute__((interrupt("WCH-Interrupt-fast")));
void AWU_IRQHandler(void)
{
cnt++;
if (cnt >= 1440) {
if (cnt >= 1000) {
cnt = 0;
wake_uptime++;
}
// handle render new frame at 90Hz
if ((cnt & 0xf) == 0) {
// handle render new frame at ~100Hz
if ((cnt % 10) == 0) {
lp_render = 1;
}
@@ -172,4 +200,7 @@ void AWU_IRQHandler(void)
// handle buttons
// do we sleep?
// clear interrupt
EXTI_ClearFlag(EXTI_Line27);
}