Update ColorChord for the ESP8266
This commit is contained in:
parent
ca4c90b1a8
commit
5a4c232d43
22 changed files with 1226 additions and 206 deletions
79
embedded8266/driver/adc.c
Normal file
79
embedded8266/driver/adc.c
Normal file
|
@ -0,0 +1,79 @@
|
|||
//I did not write this file, but I don't know where it came from.
|
||||
|
||||
#include "ets_sys.h"
|
||||
#include "osapi.h"
|
||||
|
||||
#include "driver/adc.h"
|
||||
|
||||
#define i2c_bbpll 0x67
|
||||
#define i2c_bbpll_en_audio_clock_out 4
|
||||
#define i2c_bbpll_en_audio_clock_out_msb 7
|
||||
#define i2c_bbpll_en_audio_clock_out_lsb 7
|
||||
#define i2c_bbpll_hostid 4
|
||||
#define i2c_saradc 0x6C
|
||||
#define i2c_saradc_hostid 2
|
||||
|
||||
#define i2c_saradc_en_test 0
|
||||
#define i2c_saradc_en_test_msb 5
|
||||
#define i2c_saradc_en_test_lsb 5
|
||||
|
||||
#define i2c_writeReg_Mask(block, host_id, reg_add, Msb, Lsb, indata) \
|
||||
rom_i2c_writeReg_Mask(block, host_id, reg_add, Msb, Lsb, indata)
|
||||
|
||||
#define i2c_readReg_Mask(block, host_id, reg_add, Msb, Lsb) \
|
||||
rom_i2c_readReg_Mask_(block, host_id, reg_add, Msb, Lsb)
|
||||
|
||||
#define i2c_writeReg_Mask_def(block, reg_add, indata) \
|
||||
i2c_writeReg_Mask(block, block##_hostid, reg_add, reg_add##_msb, reg_add##_lsb, indata)
|
||||
|
||||
#define i2c_readReg_Mask_def(block, reg_add) \
|
||||
i2c_readReg_Mask(block, block##_hostid, reg_add, reg_add##_msb, reg_add##_lsb)
|
||||
|
||||
|
||||
void ICACHE_FLASH_ATTR hs_adc_start(void)
|
||||
{
|
||||
i2c_writeReg_Mask_def(i2c_saradc, i2c_saradc_en_test, 1); //select test mux
|
||||
|
||||
//PWDET_CAL_EN=0, PKDET_CAL_EN=0
|
||||
SET_PERI_REG_MASK(0x60000D5C, 0x200000);
|
||||
|
||||
while (GET_PERI_REG_BITS(0x60000D50, 26, 24) > 0); //wait r_state == 0
|
||||
|
||||
CLEAR_PERI_REG_MASK(0x60000D50, 0x02); //force_en=0
|
||||
SET_PERI_REG_MASK(0x60000D50, 0x02); //force_en=1
|
||||
}
|
||||
|
||||
uint16 hs_adc_read(void)
|
||||
{
|
||||
uint8 i;
|
||||
uint16 sardata[8];
|
||||
uint16_t sar_dout = 0;
|
||||
|
||||
while (GET_PERI_REG_BITS(0x60000D50, 26, 24) > 0); //wait r_state == 0
|
||||
|
||||
read_sar_dout(sardata);
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
sar_dout += sardata[i];
|
||||
}
|
||||
|
||||
#ifdef OLDWAY_NEEDS_RESTART
|
||||
//tout = (sar_dout + 8) >> 4; //tout is 10 bits fraction
|
||||
// ??? Why does this exist ??? It didn't start commented out, but now that I did comment it, it still seems happy.
|
||||
// i2c_writeReg_Mask_def(i2c_saradc, i2c_saradc_en_test, 1); //select test mux
|
||||
// while (GET_PERI_REG_BITS(0x60000D50, 26, 24) > 0); //wait r_state == 0
|
||||
|
||||
// CLEAR_PERI_REG_MASK(0x60000D5C, 0x200000);
|
||||
// SET_PERI_REG_MASK(0x60000D60, 0x1); //force_en=1
|
||||
// CLEAR_PERI_REG_MASK(0x60000D60, 0x1); //force_en=1
|
||||
#else
|
||||
|
||||
//Start reading a new sample.
|
||||
CLEAR_PERI_REG_MASK(0x60000D50, 0x02); //force_en=0
|
||||
SET_PERI_REG_MASK(0x60000D50, 0x02); //force_en=1
|
||||
#endif
|
||||
|
||||
return sar_dout; //tout is 10 bits fraction
|
||||
}
|
||||
|
||||
|
|
@ -169,52 +169,30 @@ uart0_sendStr(const char *str)
|
|||
* Parameters : void *para - point to ETS_UART_INTR_ATTACH's arg
|
||||
* Returns : NONE
|
||||
*******************************************************************************/
|
||||
extern void at_recvTask(void);
|
||||
|
||||
extern void charrx( uint8_t c );
|
||||
|
||||
LOCAL void
|
||||
uart0_rx_intr_handler(void *para)
|
||||
{
|
||||
/* uart0 and uart1 intr combine togther, when interrupt occur, see reg 0x3ff20020, bit2, bit0 represents
|
||||
* uart1 and uart0 respectively
|
||||
*/
|
||||
// RcvMsgBuff *pRxBuff = (RcvMsgBuff *)para;
|
||||
// uint8 RcvChar;
|
||||
uint8 uart_no = UART0;//UartDev.buff_uart_no;
|
||||
static uint8_t history[4];
|
||||
static uint8_t hhead;
|
||||
|
||||
// if (UART_RXFIFO_FULL_INT_ST != (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_RXFIFO_FULL_INT_ST))
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
if (UART_RXFIFO_FULL_INT_ST == (READ_PERI_REG(UART_INT_ST(uart_no)) & UART_RXFIFO_FULL_INT_ST))
|
||||
{
|
||||
at_recvTask();
|
||||
uint8 uart_no = UART0;//UartDev.buff_uart_no;
|
||||
volatile uint8_t v = READ_PERI_REG(UART_FIFO(uart_no)) & 0xFF;
|
||||
WRITE_PERI_REG(UART_INT_CLR(uart_no), UART_RXFIFO_FULL_INT_CLR);
|
||||
}
|
||||
|
||||
// WRITE_PERI_REG(UART_INT_CLR(uart_no), UART_RXFIFO_FULL_INT_CLR);
|
||||
history[hhead++] = v;
|
||||
if( hhead > 3 ) hhead = 0;
|
||||
|
||||
// if (READ_PERI_REG(UART_STATUS(uart_no)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S))
|
||||
// {
|
||||
// RcvChar = READ_PERI_REG(UART_FIFO(uart_no)) & 0xFF;
|
||||
// at_recvTask();
|
||||
// *(pRxBuff->pWritePos) = RcvChar;
|
||||
//Detect a request to reboot into bootloader.
|
||||
if( history[hhead&3] == 0xc2 && history[(hhead+1)&3] == 0x42 && history[(hhead+2)&3] == 0x56 && history[(hhead+3)&3] == 0xff )
|
||||
{
|
||||
system_restart();
|
||||
}
|
||||
|
||||
// system_os_post(at_recvTaskPrio, NULL, RcvChar);
|
||||
charrx( v );
|
||||
|
||||
// //insert here for get one command line from uart
|
||||
// if (RcvChar == '\r')
|
||||
// {
|
||||
// pRxBuff->BuffState = WRITE_OVER;
|
||||
// }
|
||||
//
|
||||
// pRxBuff->pWritePos++;
|
||||
//
|
||||
// if (pRxBuff->pWritePos == (pRxBuff->pRcvMsgBuff + RX_BUFF_SIZE))
|
||||
// {
|
||||
// // overflow ...we may need more error handle here.
|
||||
// pRxBuff->pWritePos = pRxBuff->pRcvMsgBuff ;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
|
@ -242,6 +220,4 @@ void ICACHE_FLASH_ATTR
|
|||
uart_reattach()
|
||||
{
|
||||
uart_init(BIT_RATE_74880, BIT_RATE_74880);
|
||||
// ETS_UART_INTR_ATTACH(uart_rx_intr_handler_ssc, &(UartDev.rcv_buff));
|
||||
// ETS_UART_INTR_ENABLE();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue