// -------------------------------------------------- //
// This file is autogenerated by pioasm; do not edit! //
// -------------------------------------------------- //
#pragma once
#if !PICO_NO_HARDWARE
#include "hardware/pio.h"
#endif
// --------- //
// slave_I2S //
// --------- //
#define slave_I2S_wrap_target 0
#define slave_I2S_wrap 9
static const uint16_t slave_I2S_program_instructions[] = {
// .wrap_target
0x20a2, // 0: wait 1 pin, 2
0x2022, // 1: wait 0 pin, 2
0xe027, // 2: set x, 7
0x2021, // 3: wait 0 pin, 1
0x20a1, // 4: wait 1 pin, 1
0x4001, // 5: in pins, 1
0x0043, // 6: jmp x--, 3
0xe027, // 7: set x, 7
0xc000, // 8: irq nowait 0
0x0003, // 9: jmp 3
// .wrap
};
#if !PICO_NO_HARDWARE
static const struct pio_program slave_I2S_program = {
.instructions = slave_I2S_program_instructions,
.length = 10,
.origin = -1,
};
static inline pio_sm_config slave_I2S_program_get_default_config(uint offset) {
pio_sm_config c = pio_get_default_sm_config();
sm_config_set_wrap(&c, offset + slave_I2S_wrap_target, offset + slave_I2S_wrap);
return c;
}
uint mysm;
PIO mypio=pio0;
static void pio_irq(){
Serial1.println("Interupt !");
pio_interrupt_clear(mypio, mysm);
if(pio_sm_is_rx_fifo_full(mypio,mysm)){
uint32_t val = pio_sm_get(mypio,mysm);
Serial1.println("fifo is full!!");
Serial1.println(val);
pio_sm_clear_fifos(mypio,mysm);
}
}
static inline void slave_I2S_program_init(PIO pio, uint sm, uint offset, uint dataPin, uint sckPin, uint lrckPin) {
pio_sm_config c = slave_I2S_program_get_default_config(offset);
sm_config_set_in_pins(&c, dataPin);
pio_sm_set_consecutive_pindirs(pio, sm, dataPin, 3, false);
pio_gpio_init(pio, dataPin); // data = Pin in 0 (11)
pio_gpio_init(pio, sckPin); // sck = Pin in 1 (12)
pio_gpio_init(pio, lrckPin); // lrck = Pin in 2 (13)
sm_config_set_in_shift(
&c,
false, // Shift-to-right = false (i.e. shift to left)
true, // Autopush enabled
24 // Autopush threshold = 8
);
// We only receive, so disable the TX FIFO to make the RX FIFO deeper.
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX);
// IRQ
//pio_set_irq0_source_enabled(pio,pis_sm0_rx_fifo_not_empty ,true);
//irq_set_exclusive_handler(PIO0_IRQ_0, pio_irq);
irq_add_shared_handler(PIO0_IRQ_0, pio_irq, PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY);
irq_set_enabled(PIO0_IRQ_0, true);
// Load our configuration, and jump to the start of the program
sm_config_set_clkdiv(&c, 1.f);
pio_sm_init(pio, sm, offset, &c);
Serial1.println("State machine started !!");
}
#endif
// -------------------------------------------------- //
// This file is autogenerated by pioasm; do not edit! //
// -------------------------------------------------- //
/*
#pragma once
#if !PICO_NO_HARDWARE
#include "hardware/pio.h"
#include "hardware/dma.h"
#endif
// --------- //
// slave_I2S //
// --------- //
#define slave_I2S_wrap_target 0
#define slave_I2S_wrap 5
static const uint16_t slave_I2S_program_instructions[] = {
// .wrap_target
0x208c, // 0: wait 1 gpio, 12
0x200c, // 1: wait 0 gpio, 12
// 0x208d, // 2: wait 1 gpio, 13
0x4001, // 3: in pins, 1
0x200d, // 4: wait 0 gpio, 13
0x0000, // 5: jmp 2
// .wrap
};
#if !PICO_NO_HARDWARE
static const struct pio_program slave_I2S_program = {
.instructions = slave_I2S_program_instructions,
.length = 6,
.origin = -1,
};
static inline pio_sm_config slave_I2S_program_get_default_config(uint offset) {
pio_sm_config c = pio_get_default_sm_config();
sm_config_set_wrap(&c, offset + slave_I2S_wrap_target, offset + slave_I2S_wrap);
return c;
}
uint mysm;
PIO mypio=pio0;
static void pio_irq(){
Serial1.println("Interupt !");
pio_interrupt_clear(mypio, mysm);
if(pio_sm_is_rx_fifo_full(mypio,mysm)){
uint32_t val = pio_sm_get(mypio,mysm);
Serial1.println("fifo is full!!");
Serial1.println(val);
pio_sm_clear_fifos(mypio,mysm);
}
}
static inline void slave_I2S_program_init(PIO pio, uint sm, uint offset, uint dataPin, uint sckPin, uint lrckPin) {
pio_sm_config c = slave_I2S_program_get_default_config(offset);
// On vient définir les pins utilisés (tous les pins sont des pins d'entrée)
// Set the pin directions to input at the PIO
// Connect these GPIOs to this PIO block
sm_config_set_in_pins(&c, dataPin);
sm_config_set_sideset_pins(&c, sckPin);
pio_sm_set_consecutive_pindirs(pio, sm, dataPin, 3, false);
pio_gpio_init(pio, dataPin); // data = Pin in 0 (11)
pio_gpio_init(pio, sckPin); // sck = Pin in 1 (12)
pio_gpio_init(pio, lrckPin); // lrck = Pin in 2 (13)
gpio_set_outover(sckPin, GPIO_OVERRIDE_NORMAL);//cpol ? GPIO_OVERRIDE_INVERT : GPIO_OVERRIDE_NORMAL);
// Shifting to left matches the customary MSB-first ordering of SPI.
sm_config_set_in_shift(
&c,
false, // Shift-to-right = false (i.e. shift to left)
true, // Autopush enabled
2 // Autopush threshold = 8
);
// We only receive, so disable the TX FIFO to make the RX FIFO deeper.
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX);
// Enable IRQ
//pio_set_irq0_source_enabled(pio,pis_interrupt0,true);
pio_set_irq0_source_enabled(pio,pis_sm0_rx_fifo_not_empty ,true);
//irq_set_exclusive_handler(PIO0_IRQ_0, pio_irq);
irq_add_shared_handler(PIO0_IRQ_0, pio_irq, PICO_SHARED_IRQ_HANDLER_DEFAULT_ORDER_PRIORITY);
irq_set_enabled(PIO0_IRQ_0, true);
// Load our configuration, and start the program from the beginning
sm_config_set_clkdiv(&c, 1.f);
pio_sm_init(pio, sm, offset, &c);
//pio_sm_set_enabled(pio, sm, true);
Serial1.println("State machine started");
}
#endif*/
void setup() {
// put your setup code here, to run once:
Serial1.begin(115200);
Serial1.println("Hello, Raspberry Pi Pico!");
uint offset = pio_add_program(mypio, &slave_I2S_program);
mysm = pio_claim_unused_sm(mypio, true);
slave_I2S_program_init(mypio,mysm, offset,11,12,13);
pio_sm_set_enabled(mypio, mysm, false);
pio_sm_clear_fifos(mypio, mysm);
pio_sm_restart(mypio, mysm);
/*
Serial1.println(sizeof(uint32_t));
uint32_t *capture_buf;// = malloc(256);
uint dma_chan = 0;
//hard_assert(capture_buf);
dma_channel_config c = dma_channel_get_default_config(dma_chan);
channel_config_set_read_increment(&c, false);
channel_config_set_write_increment(&c, true);
channel_config_set_dreq(&c, pio_get_dreq(mypio, mysm, false));
dma_channel_configure(dma_chan, &c,
capture_buf, // Destination pointer
&mypio->rxf[mysm], // Source pointer
16, // Number of transfers
true // Start immediately
);
*/
pio_sm_set_enabled(mypio, mysm, true);
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
// On lit la fifo
//uint8_t rxdata = pio_sm_get_blocking(pio, sm);
//printf("%02x %s\n", rxdata, rxdata == txbuf[i] ? "OK" : "FAIL");
}