/ src / usb_rx.pio.h
usb_rx.pio.h
  1  // -------------------------------------------------- //
  2  // This file is autogenerated by pioasm; do not edit! //
  3  // -------------------------------------------------- //
  4  
  5  #pragma once
  6  
  7  #if !PICO_NO_HARDWARE
  8  #include "hardware/pio.h"
  9  #endif
 10  
 11  #define IRQ_RX_BS_ERR 1
 12  #define IRQ_RX_EOP 2
 13  #define IRQ_RX_START 3
 14  #define DECODER_TRIGGER 4
 15  
 16  // ----------------- //
 17  // usb_edge_detector //
 18  // ----------------- //
 19  
 20  #define usb_edge_detector_wrap_target 3
 21  #define usb_edge_detector_wrap 9
 22  
 23  static const uint16_t usb_edge_detector_program_instructions[] = {
 24      0xc022, //  0: irq    wait 2                     
 25      0x00c1, //  1: jmp    pin, 1                     
 26      0xc103, //  2: irq    nowait 3               [1] 
 27              //     .wrap_target
 28      0xc104, //  3: irq    nowait 4               [1] 
 29      0x00cc, //  4: jmp    pin, 12                    
 30      0x00cc, //  5: jmp    pin, 12                    
 31      0x00cc, //  6: jmp    pin, 12                    
 32      0x00cc, //  7: jmp    pin, 12                    
 33      0x00cc, //  8: jmp    pin, 12                    
 34      0x00cc, //  9: jmp    pin, 12                    
 35              //     .wrap
 36      0xa226, // 10: mov    x, isr                 [2] 
 37      0x0040, // 11: jmp    x--, 0                     
 38      0xa0c3, // 12: mov    isr, null                  
 39      0x4001, // 13: in     pins, 1                    
 40      0xc004, // 14: irq    nowait 4                   
 41      0x00ca, // 15: jmp    pin, 10                    
 42      0x0005, // 16: jmp    5                          
 43  };
 44  
 45  #if !PICO_NO_HARDWARE
 46  static const struct pio_program usb_edge_detector_program = {
 47      .instructions = usb_edge_detector_program_instructions,
 48      .length = 17,
 49      .origin = -1,
 50  };
 51  
 52  static inline pio_sm_config usb_edge_detector_program_get_default_config(uint offset) {
 53      pio_sm_config c = pio_get_default_sm_config();
 54      sm_config_set_wrap(&c, offset + usb_edge_detector_wrap_target, offset + usb_edge_detector_wrap);
 55      return c;
 56  }
 57  #endif
 58  
 59  // ----------------------- //
 60  // usb_edge_detector_debug //
 61  // ----------------------- //
 62  
 63  #define usb_edge_detector_debug_wrap_target 3
 64  #define usb_edge_detector_debug_wrap 9
 65  
 66  static const uint16_t usb_edge_detector_debug_program_instructions[] = {
 67      0xc022, //  0: irq    wait 2          side 0     
 68      0x10c1, //  1: jmp    pin, 1          side 1     
 69      0xc103, //  2: irq    nowait 3        side 0 [1] 
 70              //     .wrap_target
 71      0xc104, //  3: irq    nowait 4        side 0 [1] 
 72      0x10cc, //  4: jmp    pin, 12         side 1     
 73      0x10cc, //  5: jmp    pin, 12         side 1     
 74      0x10cc, //  6: jmp    pin, 12         side 1     
 75      0x10cc, //  7: jmp    pin, 12         side 1     
 76      0x10cc, //  8: jmp    pin, 12         side 1     
 77      0x10cc, //  9: jmp    pin, 12         side 1     
 78              //     .wrap
 79      0xb226, // 10: mov    x, isr          side 1 [2] 
 80      0x1040, // 11: jmp    x--, 0          side 1     
 81      0xb0c3, // 12: mov    isr, null       side 1     
 82      0x4001, // 13: in     pins, 1         side 0     
 83      0xc004, // 14: irq    nowait 4        side 0     
 84      0x00ca, // 15: jmp    pin, 10         side 0     
 85      0x1005, // 16: jmp    5               side 1     
 86  };
 87  
 88  #if !PICO_NO_HARDWARE
 89  static const struct pio_program usb_edge_detector_debug_program = {
 90      .instructions = usb_edge_detector_debug_program_instructions,
 91      .length = 17,
 92      .origin = -1,
 93  };
 94  
 95  static inline pio_sm_config usb_edge_detector_debug_program_get_default_config(uint offset) {
 96      pio_sm_config c = pio_get_default_sm_config();
 97      sm_config_set_wrap(&c, offset + usb_edge_detector_debug_wrap_target, offset + usb_edge_detector_debug_wrap);
 98      sm_config_set_sideset(&c, 1, false, false);
 99      return c;
100  }
101  #endif
102  
103  // ---------------- //
104  // usb_nrzi_decoder //
105  // ---------------- //
106  
107  #define usb_nrzi_decoder_wrap_target 0
108  #define usb_nrzi_decoder_wrap 6
109  
110  static const uint16_t usb_nrzi_decoder_program_instructions[] = {
111              //     .wrap_target
112      0xe046, //  0: set    y, 6                       
113      0x20c4, //  1: wait   1 irq, 4                   
114      0x0066, //  2: jmp    !y, 6                      
115      0x00c7, //  3: jmp    pin, 7                     
116      0x0028, //  4: jmp    !x, 8                      
117      0x4061, //  5: in     null, 1                    
118      0xa029, //  6: mov    x, !x                      
119              //     .wrap
120      0x0025, //  7: jmp    !x, 5                      
121      0x40e1, //  8: in     osr, 1                     
122      0x0081, //  9: jmp    y--, 1                     
123  };
124  
125  #if !PICO_NO_HARDWARE
126  static const struct pio_program usb_nrzi_decoder_program = {
127      .instructions = usb_nrzi_decoder_program_instructions,
128      .length = 10,
129      .origin = -1,
130  };
131  
132  static inline pio_sm_config usb_nrzi_decoder_program_get_default_config(uint offset) {
133      pio_sm_config c = pio_get_default_sm_config();
134      sm_config_set_wrap(&c, offset + usb_nrzi_decoder_wrap_target, offset + usb_nrzi_decoder_wrap);
135      return c;
136  }
137  #endif
138  
139  // ---------------------- //
140  // usb_nrzi_decoder_debug //
141  // ---------------------- //
142  
143  #define usb_nrzi_decoder_debug_wrap_target 0
144  #define usb_nrzi_decoder_debug_wrap 6
145  
146  static const uint16_t usb_nrzi_decoder_debug_program_instructions[] = {
147              //     .wrap_target
148      0xe046, //  0: set    y, 6                       
149      0x20c4, //  1: wait   1 irq, 4                   
150      0x0066, //  2: jmp    !y, 6                      
151      0x00c7, //  3: jmp    pin, 7                     
152      0x1028, //  4: jmp    !x, 8           side 0     
153      0x4061, //  5: in     null, 1                    
154      0xa029, //  6: mov    x, !x                      
155              //     .wrap
156      0x1825, //  7: jmp    !x, 5           side 1     
157      0x40e1, //  8: in     osr, 1                     
158      0x0081, //  9: jmp    y--, 1                     
159  };
160  
161  #if !PICO_NO_HARDWARE
162  static const struct pio_program usb_nrzi_decoder_debug_program = {
163      .instructions = usb_nrzi_decoder_debug_program_instructions,
164      .length = 10,
165      .origin = -1,
166  };
167  
168  static inline pio_sm_config usb_nrzi_decoder_debug_program_get_default_config(uint offset) {
169      pio_sm_config c = pio_get_default_sm_config();
170      sm_config_set_wrap(&c, offset + usb_nrzi_decoder_debug_wrap_target, offset + usb_nrzi_decoder_debug_wrap);
171      sm_config_set_sideset(&c, 2, true, false);
172      return c;
173  }
174  
175  #include "hardware/clocks.h"
176  #include "sdk_compat.h"
177  static inline void usb_rx_fs_program_init(PIO pio, uint sm, uint offset, uint pin_dp, uint pin_dm, int pin_debug) {
178    if (pin_dp < pin_dm) {
179      pio_sm_set_consecutive_pindirs(pio, sm, pin_dp, 2, false);
180    } else {
181      pio_sm_set_consecutive_pindirs(pio, sm, pin_dm, 2, false);
182    }
183    gpio_pull_down(pin_dp);
184    gpio_pull_down(pin_dm);
185    gpio_set_inover(pin_dp, GPIO_OVERRIDE_INVERT);
186    gpio_set_inover(pin_dm, GPIO_OVERRIDE_INVERT);
187    pio_sm_config c;
188    if (pin_debug < 0) {
189      c = usb_nrzi_decoder_program_get_default_config(offset);
190    } else {
191      c = usb_nrzi_decoder_debug_program_get_default_config(offset);
192      pio_sm_set_pins_with_mask64(pio, sm, 0, 1ull << pin_debug);
193      pio_sm_set_pindirs_with_mask64(pio, sm, 1ull << pin_debug, 1ull << pin_debug);
194      pio_gpio_init(pio, pin_debug);
195      sm_config_set_sideset_pins(&c, pin_debug);
196    }
197    sm_config_set_in_pins(&c, pin_dp);  // for WAIT, IN
198    sm_config_set_jmp_pin(&c, pin_dp);  // for JMP
199    // Shift to right, autopull enabled, 8bit
200    sm_config_set_in_shift(&c, true, true, 8);
201    sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_RX);
202    pio_sm_init(pio, sm, offset, &c);
203    pio_sm_exec(pio, sm, pio_encode_mov_not(pio_osr, pio_null));
204    pio_sm_set_enabled(pio, sm, false);
205  }
206  static inline void eop_detect_fs_program_init(PIO pio, uint sm, uint offset,
207                                             uint pin_dp, uint pin_dm, bool is_fs, int pin_debug) {
208    pio_sm_config c;
209    if (pin_debug < 0) {
210      c = usb_edge_detector_program_get_default_config(offset);
211    } else {
212      c = usb_edge_detector_debug_program_get_default_config(offset);
213      pio_sm_set_pins_with_mask64(pio, sm, 0, 1ull << pin_debug);
214      pio_sm_set_pindirs_with_mask64(pio, sm, 1ull << pin_debug, 1ull << pin_debug);
215      pio_gpio_init(pio, pin_debug);
216      sm_config_set_sideset_pins(&c, pin_debug);
217    }
218    sm_config_set_in_pins(&c, pin_dp);  // for WAIT, IN
219    sm_config_set_jmp_pin(&c, pin_dm);  // for JMP
220    sm_config_set_in_shift(&c, false, false, 8);
221    float div;
222    if (is_fs) {
223      div = (float)clock_get_hz(clk_sys) / (96000000);
224    } else {
225      div = (float)clock_get_hz(clk_sys) / (12000000);
226    }
227    sm_config_set_clkdiv(&c, div);
228    pio_sm_init(pio, sm, offset, &c);
229    pio_sm_set_enabled(pio, sm, true);
230  }
231  
232  #endif
233