2015-07-21 08:22:16 +02:00
|
|
|
#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>
|
|
|
|
|
|
|
|
|
2015-07-22 15:12:21 +02:00
|
|
|
gpio freepin;
|
|
|
|
|
2015-07-21 08:22:16 +02:00
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
void ADCCallback( uint16_t adcval )
|
|
|
|
{
|
|
|
|
sampbuff[last_samp_pos] = adcval;
|
|
|
|
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;
|
|
|
|
|
|
|
|
RCC_GetClocksFreq( &RCC_Clocks );
|
|
|
|
|
2015-07-22 15:12:21 +02:00
|
|
|
ConfigureLED(); LED_OFF;
|
2015-07-21 08:22:16 +02:00
|
|
|
|
|
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
|
|
|
2015-07-22 15:12:21 +02:00
|
|
|
//Turn B10 (TX) on, so we can have something positive to bias the ADC with.
|
|
|
|
ConfigureGPIO( GetGPIOFromString( "PB10" ), INOUT_OUT | DEFAULT_ON );
|
2015-07-21 08:22:16 +02:00
|
|
|
|
|
|
|
/* 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();
|
|
|
|
Init(); //Colorchord
|
|
|
|
|
2015-07-22 15:12:21 +02:00
|
|
|
// printf( "Operating at %.3fMHz\n", fv );
|
|
|
|
|
|
|
|
freepin = GetGPIOFromString( "PB11" );
|
|
|
|
ConfigureGPIO( freepin, INOUT_OUT | DEFAULT_ON );
|
2015-07-21 08:22:16 +02:00
|
|
|
|
|
|
|
int this_samp = 0;
|
|
|
|
int wf = 0;
|
|
|
|
|
2015-07-22 15:12:21 +02:00
|
|
|
LED_ON;
|
|
|
|
|
2015-07-21 08:22:16 +02:00
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
if( this_samp != last_samp_pos )
|
|
|
|
{
|
2015-07-22 15:12:21 +02:00
|
|
|
GPIOOn( freepin );
|
2015-07-21 08:22:16 +02:00
|
|
|
PushSample32( sampbuff[this_samp] ); //Can't put in full volume.
|
|
|
|
|
|
|
|
this_samp = (this_samp+1)%CIRCBUFSIZE;
|
|
|
|
|
|
|
|
wf++;
|
|
|
|
if( wf == 128 )
|
|
|
|
{
|
|
|
|
NewFrame();
|
|
|
|
wf = 0;
|
|
|
|
}
|
2015-07-22 15:12:21 +02:00
|
|
|
|
|
|
|
GPIOOff( freepin );
|
2015-07-21 08:22:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimingDelay_Decrement()
|
|
|
|
{
|
2015-07-22 15:12:21 +02:00
|
|
|
LED_TOGGLE;
|
2015-07-21 08:22:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|