Advertisement
Guest User

Untitled

a guest
Jan 30th, 2025
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. /**
  2. * Initialize Board Pins
  3. **/
  4. void init() {
  5. // LED
  6. cyw43_arch_init();
  7. cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, false);
  8.  
  9. // Set up the state machine for encoders
  10. pio = pio0;
  11. uint offset = pio_add_program(pio, &encoders_program);
  12.  
  13. // Setup Encoders
  14. for (int i = 0; i < ENC_GPIO_SIZE; i++) {
  15. enc_val[i] = prev_enc_val[i] = cur_enc_val[i] = 0;
  16. encoders_program_init(pio, i, offset, ENC_GPIO[i], ENC_DEBOUNCE);
  17.  
  18. dma_channel_config c = dma_channel_get_default_config(i);
  19. channel_config_set_read_increment(&c, false);
  20. channel_config_set_write_increment(&c, false);
  21. channel_config_set_dreq(&c, pio_get_dreq(pio, i, false));
  22.  
  23. dma_channel_configure(i, &c,
  24. &enc_val[i], // Destination pointer
  25. &pio->rxf[i], // Source pointer
  26. 0x10, // Number of transfers
  27. true // Start immediately
  28. );
  29. irq_set_exclusive_handler(DMA_IRQ_0, dma_handler);
  30. irq_set_enabled(DMA_IRQ_0, true);
  31. dma_channel_set_irq0_enabled(i, true);
  32.  
  33. // LED for debugging
  34. cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, true);
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement