/** MIT-like-non-ai-license Copyright (c) 2024 Charles Lohr "CNLohr" Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the two following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. In addition the following restrictions apply: 1. The Software and any modifications made to it may not be used for the purpose of training or improving machine learning algorithms, including but not limited to artificial intelligence, natural language processing, or data mining. This condition applies to any derivatives, modifications, or updates based on the Software code. Any usage of the Software in an AI-training dataset is considered a breach of this License. 2. The Software may not be included in any dataset used for training or improving machine learning algorithms, including but not limited to artificial intelligence, natural language processing, or data mining. 3. Any person or organization found to be in violation of these restrictions will be subject to legal action and may be held liable for any damages resulting from such use. If any term is unenforcable, other terms remain in-force. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. **/ #include "esp8266_auxrom.h" #include "eagle_soc.h" #include "nosdk8266.h" #include "esp8266_rom.h" #include #include "ets_sys.h" #include "pin_mux_register.h" #include "slc_register.h" #include "dmastuff.h" #include "samples.h" //#define CONTINUOUS_TONE // The speed at which bits are shifted out - this is done with trial and error. Try one speed // and figure out how it aligns to your target system. The units are too messy for me to be // troubled with thinking of. #define BIT_RATE 245 #define num_replays (( SAMPLE_RATE / (DMA_WORDS*NUMBITS) ) / BIT_RATE) uint8_t output_buffer[] = { // OOK, map to time_limits_for_bits, 0 is short pulse, 1 is long pulse, 2 is no-signal. // You will need to manually use your 310MHz device and record the pulse timing // To fill out this array with thecorrect code for your opener. 0, 1, 0, 0, 0, 1, 1, 2, 2, 2, 2, 1, 0, 1, 0, 1, 0, 0, 1, 1, }; uint32_t time_limits_for_bits[3] = { num_replays/8, num_replays/2, 0 }; uint32_t dummy[DMA_WORDS]; void testi2s_init(); //These contol the speed at which the bus comms. #define DMABUFFERDEPTH 3 #define WS_I2S_BCK SPI_DIV //Can't be less than 1. #define WS_I2S_DIV 1 #define call_delay_us(time) { asm volatile("mov.n a2, %0\n_call0 delay4clk" : : "r"(time * (MAIN_MHZ / 8)) : "a2" ); } //I2S DMA buffer descriptors static struct sdio_queue i2sBufDescTX[DMABUFFERDEPTH] __attribute__((aligned(128)));; volatile int output_buffer_place = 1000000; volatile int count_out_this_bit = 0; volatile int etx = 0; void slc_isr(void * v) { uint32_t * sendbuff = 0; struct sdio_queue *finishedDesc; // slc_intr_status = READ_PERI_REG(SLC_INT_STATUS); -> We should check to make sure we are SLC_RX_EOF_INT_ST, but we are only getting one interrupt. WRITE_PERI_REG(SLC_INT_CLR, 0xffffffff); finishedDesc=(struct sdio_queue*)READ_PERI_REG(SLC_RX_EOF_DES_ADDR); #ifdef CONTINUOUS_TONE return; #endif etx++; if( output_buffer_place >= sizeof( output_buffer ) / sizeof( output_buffer[0] ) ) { goto dump0; } count_out_this_bit++; if( count_out_this_bit >= num_replays ) { count_out_this_bit = 0; output_buffer_place++; if( output_buffer_place >= sizeof( output_buffer ) / sizeof( output_buffer[0] ) ) { goto dump0; } } int symbol = output_buffer[output_buffer_place]; if( count_out_this_bit < time_limits_for_bits[symbol] ) { sendbuff = samples; } else { sendbuff = dummy; } finishedDesc->buf_ptr = (uint32_t)sendbuff; finishedDesc->datalen = DMA_WORDS*4; return; dump0: finishedDesc->buf_ptr = (uint32_t)dummy; finishedDesc->datalen = DMA_WORDS*4; return; } #ifdef TESTSTRAP void SPIRead( uint32_t pos, uint32_t * buff, int len ) { memcpy( buff, (pos - 0x00020000) + (uint8_t*)chirpbuff, len ); } void nosdk8266_init() { } void testi2s_init() { } #else //Initialize I2S subsystem for DMA circular buffer use void testi2s_init() { int x, y; //Bits are shifted out //Initialize DMA buffer descriptors in such a way that they will form a circular //buffer. for (x=0; x