colorchord/embeddedstm32f303/main.c

129 lines
2.1 KiB
C
Raw Normal View History

#include <stdint.h>
#include <stm32f30x_rcc.h>
#include <stm32f30x_gpio.h>
#include <stm32f30x_dbgmcu.h>
#include <stdio.h>
#include <math.h>
#include <systems.h>
#include <DFT32.h>
#include <embeddednf.h>
#include <embeddedout.h>
2020-08-05 19:28:14 +02:00
#include "spi2812.h"
#include "adc.h"
gpio freepin;
RCC_ClocksTypeDef RCC_Clocks;
volatile int adcer;
volatile int hit = 0;
#define CIRCBUFSIZE 256
volatile int last_samp_pos;
int16_t sampbuff[CIRCBUFSIZE];
volatile int samples;
2020-08-05 19:28:14 +02:00
int UseNumLinLeds = 20;
int Gain = 10;
void ADCCallback( int16_t adcval )
{
2020-08-05 10:41:18 +02:00
#ifdef TQFP32
2020-08-05 19:28:14 +02:00
sampbuff[last_samp_pos] = adcval*Gain;
2020-08-05 10:41:18 +02:00
#else
sampbuff[last_samp_pos] = adcval;
2020-08-05 10:41:18 +02:00
#endif
last_samp_pos = ((last_samp_pos+1)%CIRCBUFSIZE);
samples++;
}
//Call this once we've stacked together one full colorchord frame.
void NewFrame()
{
uint8_t led_outs[NUM_LIN_LEDS*3];
int i;
HandleFrameInfo();
UpdateLinearLEDs();
SendSPI2812( ledOut, NUM_LIN_LEDS );
}
int main(void)
{
uint32_t i = 0;
2020-08-05 10:41:18 +02:00
send_text( "TEST1\n" );
RCC_GetClocksFreq( &RCC_Clocks );
GPIO_InitTypeDef GPIO_InitStructure;
//Turn B10 (TX) on, so we can have something positive to bias the ADC with.
2020-08-05 10:41:18 +02:00
#ifndef TQFP32
ConfigureLED(); LED_OFF;
ConfigureGPIO( GetGPIOFromString( "PB10" ), INOUT_OUT | DEFAULT_ON );
2020-08-05 10:41:18 +02:00
#endif
/* SysTick end of count event each 10ms */
SysTick_Config( RCC_Clocks.HCLK_Frequency/100 ); /// 100);
float fv = RCC_Clocks.HCLK_Frequency/1000000.0;
InitSPI2812();
InitADC();
2020-08-05 10:41:18 +02:00
InitColorChord(); //Colorchord
// printf( "Operating at %.3fMHz\n", fv );
2020-08-05 10:41:18 +02:00
#ifndef TQFP32
freepin = GetGPIOFromString( "PB11" );
ConfigureGPIO( freepin, INOUT_OUT | DEFAULT_ON );
2020-08-05 10:41:18 +02:00
#endif
int this_samp = 0;
int wf = 0;
2020-08-05 10:41:18 +02:00
#ifndef TQFP32
LED_ON;
2020-08-05 10:41:18 +02:00
#endif
while(1)
{
if( this_samp != last_samp_pos )
{
2020-08-05 10:41:18 +02:00
#ifndef TQFP32
GPIOOn( freepin );
2020-08-05 10:41:18 +02:00
#endif
PushSample32( sampbuff[this_samp] ); //Can't put in full volume.
this_samp = (this_samp+1)%CIRCBUFSIZE;
wf++;
if( wf == 128 )
{
NewFrame();
wf = 0;
}
2020-08-05 10:41:18 +02:00
#ifndef TQFP32
GPIOOff( freepin );
2020-08-05 10:41:18 +02:00
#endif
}
}
}
void TimingDelay_Decrement()
{
2020-08-05 10:41:18 +02:00
#ifndef TQFP32
LED_TOGGLE;
2020-08-05 10:41:18 +02:00
#endif
}