Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "driver/i2s.h"
- #include "rom/lldesc.h"
- #define bot 4
- // Meu ESP 3V3 GND D15 D2 D4 RX2 TX2 D5 D18 D19 D21 RX0 TX0 D22 D23
- // VIN GND D13 D12 D14 D27 D26 D25 D33 D32 D35 D34 VN VP EN
- // Port livres D2 D13 D12 D14 D32 D35 D34
- long ledClock = 20000000; // determine a frequencia do PWM
- bool roda = false;
- DMA_ATTR uint32_t dma_buff[2][100];
- DMA_ATTR lldesc_t dma_descriptor[2];
- //----------------------------------------------------------------------------
- void setup()
- {
- Serial.begin(115200);
- Serial.println(ESP.getSdkVersion());
- pinMode(33, OUTPUT); // GPIO_ as Output de PWM
- // pinMode(5, OUTPUT); // GPIO_ as Output de PWM
- pinMode(bot, INPUT_PULLUP); // GPIO_ as Input button
- ledcAttachPin(33, 0); // GPIO_18 attached to PWM Channel 0
- ledcSetup(0, ledClock, 1); // Channel 0 , freq ledClock , 1 bit resolution = 2
- ledcWrite(0, 1); // Enable frequency with dutty cycle 50%
- configue();
- }
- //----------------------------------------------------------------------------
- void configue()
- {
- //buff 0
- dma_descriptor[0].length = 0; //number of byte written to the buffer
- dma_descriptor[0].size = sizeof(dma_buff[0]); //max size of the buffer in bytes
- dma_descriptor[0].owner = 1;
- dma_descriptor[0].sosf = 1;
- dma_descriptor[0].buf = (uint8_t*)&dma_buff[0][0];
- dma_descriptor[0].offset = 0;
- dma_descriptor[0].empty = 0;
- dma_descriptor[0].eof = 0;
- //pointer to the next descriptor
- dma_descriptor[0].qe.stqe_next = &dma_descriptor[1];
- //buff 1
- dma_descriptor[1].length = 0; //number of byte written to the buffer
- dma_descriptor[1].size = sizeof(dma_buff[1]); //max size of the buffer in bytes
- dma_descriptor[1].owner = 1;
- dma_descriptor[1].sosf = 1;
- dma_descriptor[1].buf = (uint8_t*)&dma_buff[1][0];
- dma_descriptor[1].offset = 0;
- dma_descriptor[1].empty = 0;
- dma_descriptor[1].eof = 0;
- //pointer to the next descriptor
- dma_descriptor[1].qe.stqe_next = &dma_descriptor[0];
- //data inputs
- pinMode(18, INPUT);
- pinMode(23, INPUT);
- pinMode(19, INPUT);
- pinMode(21, INPUT);
- pinMode(22, INPUT);
- pinMode(25, INPUT);
- pinMode(26, INPUT);
- pinMode(27, INPUT);
- pinMode(15, INPUT);
- gpio_matrix_in(18, I2S0I_DATA_IN0_IDX, false);
- gpio_matrix_in(23, I2S0I_DATA_IN1_IDX, false);
- gpio_matrix_in(19, I2S0I_DATA_IN2_IDX, false);
- gpio_matrix_in(21, I2S0I_DATA_IN3_IDX, false);
- gpio_matrix_in(22, I2S0I_DATA_IN4_IDX, false);
- gpio_matrix_in(25, I2S0I_DATA_IN5_IDX, false);
- gpio_matrix_in(26, I2S0I_DATA_IN6_IDX, false);
- gpio_matrix_in(27, I2S0I_DATA_IN7_IDX, false);
- gpio_matrix_in(15/*XCLK*/, I2S0I_WS_IN_IDX, false);
- //for i2s in parallel camera input mode data is receiver only when V_SYNC = H_SYNC = H_ENABLE = 1.
- //We don't use these inputs so simply set them High
- gpio_matrix_in(0x38, I2S0I_V_SYNC_IDX, false);
- gpio_matrix_in(0x38, I2S0I_H_SYNC_IDX, false); //0x30 sends 0, 0x38 sends 1
- gpio_matrix_in(0x38, I2S0I_H_ENABLE_IDX, false);
- }
- //----------------------------------------------------------------------------
- void capture()
- {
- // Enable and configure I2S peripheral
- periph_module_enable(PERIPH_I2S0_MODULE);
- // Enable slave mode (sampling clock is external)
- I2S0.conf.rx_slave_mod = 1;
- // Enable parallel mode
- I2S0.conf2.lcd_en = 1;
- // Use HSYNC/VSYNC/HREF to control sampling
- I2S0.conf2.camera_en = 1;
- // Configure clock divider
- I2S0.clkm_conf.clkm_div_a = 1;
- I2S0.clkm_conf.clkm_div_b = 0;
- I2S0.clkm_conf.clkm_div_num = 2;
- I2S0.sample_rate_conf.rx_bck_div_num = 2; //i2s clk is divided before reaches BCK output
- // FIFO will sink data to DMA
- I2S0.fifo_conf.dscr_en = 1;
- // I2S0.fifo_conf.tx_fifo_mod_force_en = 1;
- I2S0.fifo_conf.rx_fifo_mod_force_en = 1;
- // FIFO configuration
- //two bytes per dword packing
- I2S0.fifo_conf.rx_fifo_mod = 0;
- I2S0.conf_chan.rx_chan_mod = 1;
- // Clear flags which are used in I2S serial mode
- I2S0.sample_rate_conf.rx_bits_mod = 0;
- I2S0.conf.rx_right_first = 0;
- I2S0.conf.rx_msb_right = 0;
- I2S0.conf.rx_msb_shift = 0;
- I2S0.conf.rx_mono = 0;
- I2S0.conf.rx_short_sync = 0;
- I2S0.timing.val = 0;
- //start i2s
- I2S0.rx_eof_num = 0xFFFFFFFF;
- I2S0.in_link.addr = (uint32_t)&dma_descriptor[0];
- I2S0.in_link.start = 1;
- I2S0.int_clr.val = I2S0.int_raw.val;
- I2S0.int_ena.val = 0;
- //start i2s + dma
- I2S0.conf.rx_start = 1;
- // delay(10000);
- delay(500);
- //stop i2s + dma
- I2S0.conf.rx_start = 0;
- // Serial.print( sizeof(dma_buff[0]));
- for (uint16_t i = 0; i < sizeof(dma_buff[0]) / 2; i++)
- {
- // for (int j = 0 ; j < 1; j++)
- // {
- Serial.print(*(((uint16_t *)&dma_buff[0][0]) + i), HEX);
- // Serial.print(bitRead(*(((uint16_t *)&dma_buff[0][0]) + i), j));
- // Serial.print(",");
- // Serial.print(*(((uint16_t *)&dma_buff[1][1]) + i));
- // Serial.print(bitRead(*(((uint16_t *)&dma_buff[1][1]) + i), j));
- // digitalWrite(5, bitRead(*(((uint16_t *)&dma_buff[0][0]) + i), j));
- // Serial.print(",");
- // }
- Serial.println(" ");
- delay(10);
- }
- }
- //----------------------------------------------------------------------------
- void loop()
- {
- if (digitalRead(bot) == LOW)
- {
- delay(30);
- if (digitalRead(bot) == LOW)
- {
- roda = true;
- }
- }
- if (roda == true)
- {
- if (digitalRead(bot) == HIGH)
- {
- capture();
- roda = false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement