Update ESP8266 version
This commit is contained in:
parent
102219f9a7
commit
ff2cd22d9a
42 changed files with 3035 additions and 213 deletions
|
@ -1,150 +0,0 @@
|
|||
#include "colorchord.h"
|
||||
|
||||
static uint8_t donefirstrun;
|
||||
static int8_t sintable[512]; //Actually [sin][cos] pairs.
|
||||
|
||||
//LDD instruction on AVR can read with constant offset. We can set Y to be the place in the buffer, and read with offset.
|
||||
static uint16_t datspace[bins*4]; //(advances,places,isses,icses)
|
||||
|
||||
//
|
||||
void HandleProgressiveInt( int8_t sample1, int8_t sample2 )
|
||||
{
|
||||
int i;
|
||||
uint16_t startpl = 0;
|
||||
int16_t ts, tc;
|
||||
int16_t tmp1;
|
||||
int8_t s1, c1;
|
||||
uint16_t ipl, localipl, adv;
|
||||
|
||||
|
||||
//startpl maps to 'Y'
|
||||
//
|
||||
|
||||
|
||||
//Estimated 68 minimum instructions... So for two pairs each... just under 5ksps, theoretical.
|
||||
//Running overall at ~2kHz.
|
||||
for( i = 0; i < bins; i++ ) //Loop, fixed size = 3 + 2 cycles 5
|
||||
{
|
||||
//12 cycles MIN
|
||||
adv = datspace[startpl++]; //Read, indirect from RAM (and increment) 2+2 cycles 4
|
||||
ipl = datspace[startpl++]; //Read, indirect from RAM (and increment) 2+2 cycles 4
|
||||
|
||||
//13 cycles MIN
|
||||
ipl += adv; //Advance, 16bit += 16bit, 1 + 1 cycles 2
|
||||
localipl = (ipl>>8)<<1; //Select upper 8 bits 1 cycles 1
|
||||
|
||||
// need to load Z with 'sintable' and add localipl 2
|
||||
s1 = sintable[localipl++]; //Read s1 component out of table. 2+2 cycles 2
|
||||
c1 = sintable[localipl++]; //Read c1 component out of table. 2 cycles 2
|
||||
|
||||
ts = (s1 * sample1); // 8 x 8 multiply signed + copy R1 out. zero MSB ts 2
|
||||
tc = (c1 * sample1); // 8 x 8 multiply signed + copy R1 out. zero MSB tc 2
|
||||
|
||||
|
||||
//15 cycles MIN
|
||||
ipl += adv; //Advance, 16bit += 16bit, 1 + 1 cycles 2
|
||||
localipl = (ipl>>8)<<1; //Select upper 8 bits 1 cycles 1
|
||||
|
||||
// need to load Z with 'sintable' and add localipl 2
|
||||
s1 = sintable[localipl++]; //Read s1 component out of table. 2 cycles 2
|
||||
c1 = sintable[localipl++]; //Read c1 component out of table. 2 cycles 2
|
||||
|
||||
ts += (s1 * sample2); // 8 x 8 multiply signed + add R1 out. 3
|
||||
tc += (c1 * sample2); // 8 x 8 multiply signed + add R1 out. 3
|
||||
|
||||
|
||||
//Add TS and TC to the datspace stuff. (24 instructions)
|
||||
tmp1 = datspace[startpl]; //Read out, sin component. 4
|
||||
tmp1 -= tmp1>>6; //Subtract from the MSB (with carry) 2
|
||||
tmp1 += ts>>6; //Add MSBs with carry 2
|
||||
|
||||
datspace[startpl++] = tmp1; //Store values back 4
|
||||
|
||||
tmp1 = datspace[startpl]; //Read out, sin component. 4
|
||||
tmp1 -= tmp1>>6; //Subtract from the MSB (with carry) 2
|
||||
tmp1 += tc>>6; //Add MSBs with carry 2
|
||||
|
||||
datspace[startpl++] = tmp1; //Store values back 4
|
||||
|
||||
datspace[startpl-3] = ipl; //Store values back 4
|
||||
}
|
||||
}
|
||||
|
||||
void SetupConstants()
|
||||
{
|
||||
int i;
|
||||
static int last_place;
|
||||
|
||||
if( !donefirstrun )
|
||||
{
|
||||
donefirstrun = 1;
|
||||
for( i = 0; i < 256; i++ )
|
||||
{
|
||||
sintable[i*2+0] = i;//(int8_t)((sin( i / 256.0 * 6.283 ) * 127.0));
|
||||
sintable[i*2+1] = i+1;//(int8_t)((cos( i / 256.0 * 6.283 ) * 127.0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for( i = 0; i < bins; i++ )
|
||||
{
|
||||
float freq = i;//frequencies[i];
|
||||
datspace[i*4] = 65536.0/freq;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
void DoDFTProgressiveInteger( float * outbins, float * frequencies, int bins, const float * databuffer, int place_in_data_buffer, int size_of_data_buffer, float q, float speedup )
|
||||
{
|
||||
int i;
|
||||
static int last_place;
|
||||
|
||||
if( !donefirstrun )
|
||||
{
|
||||
donefirstrun = 1;
|
||||
for( i = 0; i < 256; i++ )
|
||||
{
|
||||
sintable[i*2+0] = (int8_t)((sinf( i / 256.0 * 6.283 ) * 127.0));
|
||||
sintable[i*2+1] = (int8_t)((cosf( i / 256.0 * 6.283 ) * 127.0));
|
||||
}
|
||||
}
|
||||
|
||||
if( gbins != bins )
|
||||
{
|
||||
gbins = bins;
|
||||
if( datspace ) free( datspace );
|
||||
datspace = malloc( bins * 2 * 4 );
|
||||
}
|
||||
|
||||
|
||||
for( i = 0; i < bins; i++ )
|
||||
{
|
||||
float freq = frequencies[i];
|
||||
datspace[i*4] = 65536.0/freq;
|
||||
}
|
||||
|
||||
|
||||
for( i = last_place; i != ( place_in_data_buffer&0xffffe ); i = (i+2)%size_of_data_buffer )
|
||||
{
|
||||
int8_t ifr1 = (int8_t)( ((databuffer[i+0]) ) * 127 );
|
||||
int8_t ifr2 = (int8_t)( ((databuffer[i+1]) ) * 127 );
|
||||
// printf( "%d %d\n", i, place_in_data_buffer&0xffffe );
|
||||
HandleProgressiveInt( ifr1, ifr2 );
|
||||
}
|
||||
|
||||
last_place = place_in_data_buffer&0xfffe;
|
||||
|
||||
//Extract bins.
|
||||
for( i = 0; i < bins; i++ )
|
||||
{
|
||||
int16_t isps = datspace[i*4+2];
|
||||
int16_t ispc = datspace[i*4+3];
|
||||
int16_t mux = ( (isps/256) * (isps/256)) + ((ispc/256) * (ispc/256));
|
||||
// printf( "%d (%d %d)\n", mux, isps, ispc );
|
||||
outbins[i] = sqrt( mux )/100.0;
|
||||
}
|
||||
// printf( "\n");
|
||||
}
|
||||
|
||||
*/
|
|
@ -1,17 +0,0 @@
|
|||
#ifndef _COLORCHORD_H
|
||||
#define _COLORCHORD_H
|
||||
|
||||
#include "mem.h"
|
||||
#include "c_types.h"
|
||||
#include "user_interface.h"
|
||||
#include "ets_sys.h"
|
||||
#include "osapi.h"
|
||||
|
||||
#define bins 120
|
||||
|
||||
void HandleProgressiveInt( int8_t sample1, int8_t sample2 );
|
||||
void SetupConstants();
|
||||
|
||||
#endif
|
||||
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
//Copyright 2015 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or
|
||||
// ColorChord License. You Choose.
|
||||
|
||||
#include "hpatimer.h"
|
||||
#include <driver/adc.h>
|
||||
|
@ -56,3 +58,20 @@ void ICACHE_FLASH_ATTR StartHPATimer()
|
|||
hs_adc_start();
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR PauseHPATimer()
|
||||
{
|
||||
TM1_EDGE_INT_DISABLE();
|
||||
ETS_FRC1_INTR_DISABLE();
|
||||
system_timer_reinit();
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR ContinueHPATimer()
|
||||
{
|
||||
TM1_EDGE_INT_ENABLE();
|
||||
ETS_FRC1_INTR_ENABLE();
|
||||
system_timer_reinit();
|
||||
hs_adc_start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,15 @@
|
|||
//Copyright 2015 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or
|
||||
// ColorChord License. You Choose.
|
||||
|
||||
//This is a tool to make the ESP8266 run its ADC and pipe the samples into
|
||||
//the sounddata fifo.
|
||||
|
||||
#ifndef _HPATIMER_H
|
||||
#define _HPATIMER_H
|
||||
|
||||
#include <c_types.h>
|
||||
#include "ccconfig.h" //For DFREQ
|
||||
|
||||
//Using a system timer on the ESP to poll the ADC in at a regular interval...
|
||||
|
||||
//BUFFSIZE must be a power-of-two
|
||||
|
@ -11,6 +19,9 @@ extern volatile uint16_t soundhead;
|
|||
|
||||
void StartHPATimer();
|
||||
|
||||
void ICACHE_FLASH_ATTR ContinueHPATimer();
|
||||
void ICACHE_FLASH_ATTR PauseHPATimer();
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
#include "mystuff.h"
|
||||
|
||||
char generic_print_buffer[384];
|
||||
|
||||
|
||||
void user_rf_pre_init(void)
|
||||
{
|
||||
//nothing.
|
||||
}
|
||||
|
||||
|
||||
char * strcat( char * dest, char * src )
|
||||
{
|
||||
return strcat(dest, src );
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
#ifndef _MYSTUFF_H
|
||||
#define _MYSTUFF_H
|
||||
|
||||
extern char generic_print_buffer[384];
|
||||
|
||||
#define printf( ... ) ets_sprintf( generic_print_buffer, __VA_ARGS__ ); uart0_sendStr( generic_print_buffer );
|
||||
|
||||
#endif
|
|
@ -1,3 +1,6 @@
|
|||
//Copyright 2015 <>< Charles Lohr Under the MIT/x11 License, NewBSD License or
|
||||
// ColorChord License. You Choose.
|
||||
|
||||
#include "mem.h"
|
||||
#include "c_types.h"
|
||||
#include "user_interface.h"
|
||||
|
@ -11,7 +14,10 @@
|
|||
#include <DFT32.h>
|
||||
#include <embeddednf.h>
|
||||
#include <embeddedout.h>
|
||||
#include "ets_sys.h"
|
||||
#include "gpio.h"
|
||||
|
||||
//#define PROFILE
|
||||
|
||||
#define PORT 7777
|
||||
#define SERVER_TIMEOUT 1500
|
||||
|
@ -30,6 +36,9 @@ extern volatile uint8_t sounddata[HPABUFFSIZE];
|
|||
extern volatile uint16_t soundhead;
|
||||
uint16_t soundtail;
|
||||
|
||||
void user_rf_pre_init()
|
||||
{
|
||||
}
|
||||
|
||||
//Call this once we've stacked together one full colorchord frame.
|
||||
static void NewFrame()
|
||||
|
@ -54,8 +63,12 @@ static void procTask(os_event_t *events)
|
|||
{
|
||||
system_os_post(procTaskPrio, 0, 0 );
|
||||
|
||||
// printf( "%d\n", sounddata[soundtail] );
|
||||
CSTick( 0 );
|
||||
|
||||
//For profiling so we can see how much CPU is spent in this loop.
|
||||
#ifdef PROFILE
|
||||
WRITE_PERI_REG( PERIPHS_GPIO_BASEADDR + GPIO_ID_PIN(0), 1 );
|
||||
#endif
|
||||
while( soundtail != soundhead )
|
||||
{
|
||||
int16_t samp = sounddata[soundtail];
|
||||
|
@ -70,6 +83,9 @@ static void procTask(os_event_t *events)
|
|||
wf = 0;
|
||||
}
|
||||
}
|
||||
#ifdef PROFILE
|
||||
WRITE_PERI_REG( PERIPHS_GPIO_BASEADDR + GPIO_ID_PIN(0), 0 );
|
||||
#endif
|
||||
|
||||
if( events->sig == 0 && events->par == 0 )
|
||||
{
|
||||
|
@ -109,6 +125,7 @@ static void procTask(os_event_t *events)
|
|||
//Timer event.
|
||||
static void myTimer(void *arg)
|
||||
{
|
||||
CSTick( 1 );
|
||||
// uart0_sendStr(".");
|
||||
// printf( "%d/%d\n",soundtail,soundhead );
|
||||
// printf( "%d/%d\n",soundtail,soundhead );
|
||||
|
@ -118,15 +135,14 @@ static void myTimer(void *arg)
|
|||
|
||||
|
||||
//Called when new packet comes in.
|
||||
static void ICACHE_FLASH_ATTR
|
||||
udpserver_recv(void *arg, char *pusrdata, unsigned short len)
|
||||
static void udpserver_recv(void *arg, char *pusrdata, unsigned short len)
|
||||
{
|
||||
struct espconn *pespconn = (struct espconn *)arg;
|
||||
// uint8_t buffer[MAX_FRAME];
|
||||
|
||||
// uint8_t ledout[] = { 0x00, 0xff, 0xaa, 0x00, 0xff, 0xaa, };
|
||||
uart0_sendStr("X");
|
||||
// ws2812_push( pusrdata, len );
|
||||
ws2812_push( pusrdata, len );
|
||||
}
|
||||
|
||||
void ICACHE_FLASH_ATTR charrx( uint8_t c )
|
||||
|
@ -135,13 +151,16 @@ void ICACHE_FLASH_ATTR charrx( uint8_t c )
|
|||
}
|
||||
|
||||
|
||||
void user_init(void)
|
||||
void ICACHE_FLASH_ATTR user_init(void)
|
||||
{
|
||||
uart_init(BIT_RATE_115200, BIT_RATE_115200);
|
||||
int wifiMode = wifi_get_opmode();
|
||||
|
||||
uart0_sendStr("\r\nCustom Server\r\n");
|
||||
|
||||
#ifdef PROFILE
|
||||
GPIO_OUTPUT_SET(GPIO_ID_PIN(0), 0);
|
||||
#endif
|
||||
|
||||
wifi_set_opmode( 2 ); //We broadcast our ESSID, wait for peopel to join.
|
||||
|
||||
|
@ -170,6 +189,8 @@ void user_init(void)
|
|||
while(1) { uart0_sendStr( "\r\nFAULT\r\n" ); }
|
||||
}
|
||||
|
||||
CSInit();
|
||||
|
||||
//Add a process
|
||||
system_os_task(procTask, procTaskPrio, procTaskQueue, procTaskQueueLen);
|
||||
|
||||
|
@ -178,7 +199,7 @@ void user_init(void)
|
|||
os_timer_setfn(&some_timer, (os_timer_func_t *)myTimer, NULL);
|
||||
os_timer_arm(&some_timer, 100, 1);
|
||||
|
||||
Init(); //Init colorchord
|
||||
InitColorChord(); //Init colorchord
|
||||
|
||||
StartHPATimer(); //Init the high speed ADC timer.
|
||||
|
||||
|
@ -187,4 +208,16 @@ void user_init(void)
|
|||
system_os_post(procTaskPrio, 0, 0 );
|
||||
}
|
||||
|
||||
void EnterCritical()
|
||||
{
|
||||
PauseHPATimer();
|
||||
//ets_intr_lock();
|
||||
}
|
||||
|
||||
void ExitCritical()
|
||||
{
|
||||
//ets_intr_unlock();
|
||||
ContinueHPATimer();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/******************************************************************************
|
||||
* Copyright 2013-2015 Espressif Systems
|
||||
* 2015 <>< Charles Lohr
|
||||
*
|
||||
* FileName: i2s_freertos.c
|
||||
*
|
||||
|
@ -27,6 +28,10 @@ Notes:
|
|||
The way it works right now is to keep the DMA running forever and just update
|
||||
the data in the buffer so it continues sending the frame.
|
||||
|
||||
Extra copyright info:
|
||||
Actually not much of this file is Copyright Espressif, comparativly little
|
||||
mostly just the stuff to make the I2S bus go.
|
||||
|
||||
*******************************************************************************/
|
||||
|
||||
|
||||
|
@ -392,6 +397,10 @@ void ICACHE_FLASH_ATTR ws2812_init()
|
|||
}
|
||||
|
||||
|
||||
//All functions below this line are Public Domain 2015 Charles Lohr.
|
||||
//this code may be used by anyone in any way without restriction or limitation.
|
||||
|
||||
|
||||
//Tricky, send out WS2812 bits with coded pulses, one nibble, then the other.
|
||||
static const uint16_t bitpatterns[16] = {
|
||||
0b1000100010001000, 0b1000100010001110, 0b1000100011101000, 0b1000100011101110,
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
#ifndef _I2S_TEST
|
||||
#define _I2S_TEST
|
||||
//Copyright 2015 <>< Charles Lohr, See LICENSE file.
|
||||
//WS2812 sender that abuses the I2S interface on the WS2812.
|
||||
|
||||
#ifndef _WS2812I2S_TEST
|
||||
#define _WS2812I2S_TEST
|
||||
|
||||
//Stuff that should be for the header:
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue