Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
fail-fast: false
matrix:
sdk_version:
- '2.1.0'
- '2.0.0'
- '1.5.1'
runs-on: ubuntu-latest
Expand Down
23 changes: 18 additions & 5 deletions src/pio_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,25 +283,38 @@ static void configure_tx_channel(uint8_t ch, PIO pio, uint sm) {

static void apply_config(pio_port_t *pp, const pio_usb_configuration_t *c,
root_port_t *port) {
pp->pio_usb_tx = c->pio_tx_num == 0 ? pio0 : pio1;
pp->pio_usb_tx = pio_get_instance(c->pio_tx_num);
pp->sm_tx = c->sm_tx;
pp->tx_ch = c->tx_ch;
pp->pio_usb_rx = c->pio_rx_num == 0 ? pio0 : pio1;
pp->pio_usb_rx = pio_get_instance(c->pio_rx_num);
pp->sm_rx = c->sm_rx;
pp->sm_eop = c->sm_eop;
port->pin_dp = c->pin_dp;

uint highest_pin;
if (c->pinout == PIO_USB_PINOUT_DPDM) {
port->pin_dm = c->pin_dp + 1;
highest_pin = port->pin_dm;
pp->fs_tx_program = &usb_tx_dpdm_program;
pp->fs_tx_pre_program = &usb_tx_pre_dpdm_program;
pp->ls_tx_program = &usb_tx_dmdp_program;
} else {
port->pin_dm = c->pin_dp - 1;
highest_pin = port->pin_dp;
pp->fs_tx_program = &usb_tx_dmdp_program;
pp->fs_tx_pre_program = &usb_tx_pre_dmdp_program;
pp->ls_tx_program = &usb_tx_dpdm_program;
}

#if defined(PICO_PIO_USE_GPIO_BASE) && PICO_PIO_USE_GPIO_BASE+0
if (highest_pin > 32) {
pio_set_gpio_base(pp->pio_usb_tx, 16);
pio_set_gpio_base(pp->pio_usb_rx, 16);
}
#else
(void)highest_pin;
#endif

port->pinout = c->pinout;

pp->debug_pin_rx = c->debug_pin_rx;
Expand All @@ -323,7 +336,7 @@ void pio_usb_bus_init(pio_port_t *pp, const pio_usb_configuration_t *c,
root_port_t *root) {
memset(root, 0, sizeof(root_port_t));

pp->pio_usb_tx = c->pio_tx_num == 0 ? pio0 : pio1;
pp->pio_usb_tx = pio_get_instance(c->pio_tx_num);
dma_claim_mask(1<<c->tx_ch);
configure_tx_channel(c->tx_ch, pp->pio_usb_tx, c->sm_tx);

Expand Down Expand Up @@ -573,8 +586,8 @@ int pio_usb_host_add_port(uint8_t pin_dp, PIO_USB_PINOUT pinout) {
pio_gpio_init(pio_port[0].pio_usb_tx, root->pin_dm);
gpio_set_inover(pin_dp, GPIO_OVERRIDE_INVERT);
gpio_set_inover(root->pin_dm, GPIO_OVERRIDE_INVERT);
pio_sm_set_pindirs_with_mask(pio_port[0].pio_usb_tx, pio_port[0].sm_tx, 0,
(1 << pin_dp) | (1 << root->pin_dm));
pio_sm_set_pindirs_with_mask64(pio_port[0].pio_usb_tx, pio_port[0].sm_tx, 0,
(1ull << pin_dp) | (1ull << root->pin_dm));
port_pin_drive_setting(root);
root->initialized = true;

Expand Down
2 changes: 1 addition & 1 deletion src/pio_usb_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ usb_device_t *pio_usb_device_init(const pio_usb_configuration_t *c,
// configure PIOx_IRQ_0 to detect packet receive start
pio_set_irqn_source_enabled(pp->pio_usb_rx, 0, pis_interrupt0 + IRQ_RX_START,
true);
pp->device_rx_irq_num = (pp->pio_usb_rx == pio0) ? PIO0_IRQ_0 : PIO1_IRQ_0;
pp->device_rx_irq_num = PIO_IRQ_NUM(pp->pio_usb_rx, 0);
irq_set_exclusive_handler(pp->device_rx_irq_num, usb_device_packet_handler);
irq_set_enabled(pp->device_rx_irq_num, true);

Expand Down
31 changes: 31 additions & 0 deletions src/sdk_compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#pragma once

#if PICO_SDK_VERSION_MAJOR < 2
static __always_inline void pio_sm_set_jmp_pin(PIO pio, uint sm, uint jmp_pin) {
pio->sm[sm].execctrl =
(pio->sm[sm].execctrl & ~PIO_SM0_EXECCTRL_JMP_PIN_BITS) |
(jmp_pin << PIO_SM0_EXECCTRL_JMP_PIN_LSB);
}

static_assert(PIO1_BASE - PIO0_BASE == (1u << 20), "hardware layout mismatch");
#define PIO_INSTANCE(instance) ((pio_hw_t *)(PIO0_BASE + (instance) * (1u << 20)))
static __always_inline PIO pio_get_instance(uint instance) {
return PIO_INSTANCE(instance);
}

#define PIO_NUM(pio) (((uintptr_t)(pio) - PIO0_BASE) >> 20)
#define NUM_PIO_IRQS (2u)
#define PIO_IRQ_NUM(pio, irqn) (PIO0_IRQ_0 + NUM_PIO_IRQS * PIO_NUM(pio) + (irqn))

#endif

#if PICO_SDK_VERSION_MAJOR < 2 || (PICO_SDK_VERSION_MAJOR == 2 && PICO_SDK_VERSION_MINOR < 1)
static void pio_sm_set_pins_with_mask64(PIO pio, uint sm, uint64_t pin_values, uint64_t pin_mask) {
pio_sm_set_pins_with_mask(pio, sm, (uint32_t) pin_values, (uint32_t) pin_mask);
}

static void pio_sm_set_pindirs_with_mask64(PIO pio, uint sm, uint64_t pin_values, uint64_t pin_mask) {
pio_sm_set_pindirs_with_mask(pio, sm, (uint32_t) pin_values, (uint32_t) pin_mask);
}
#endif

19 changes: 6 additions & 13 deletions src/usb_rx.pio
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,7 @@ J2:

% c-sdk {
#include "hardware/clocks.h"

#if PICO_SDK_VERSION_MAJOR < 2
static __always_inline void pio_sm_set_jmp_pin(PIO pio, uint sm, uint jmp_pin) {
pio->sm[sm].execctrl =
(pio->sm[sm].execctrl & ~PIO_SM0_EXECCTRL_JMP_PIN_BITS) |
(jmp_pin << PIO_SM0_EXECCTRL_JMP_PIN_LSB);
}
#endif
#include "sdk_compat.h"

static inline void usb_rx_fs_program_init(PIO pio, uint sm, uint offset, uint pin_dp, uint pin_dm, int pin_debug) {
if (pin_dp < pin_dm) {
Expand All @@ -182,8 +175,8 @@ static inline void usb_rx_fs_program_init(PIO pio, uint sm, uint offset, uint pi
} else {
c = usb_nrzi_decoder_debug_program_get_default_config(offset);

pio_sm_set_pins_with_mask(pio, sm, 0, 1 << pin_debug);
pio_sm_set_pindirs_with_mask(pio, sm, 1 << pin_debug, 1 << pin_debug);
pio_sm_set_pins_with_mask64(pio, sm, 0, 1ull << pin_debug);
pio_sm_set_pindirs_with_mask64(pio, sm, 1ull << pin_debug, 1ull << pin_debug);
pio_gpio_init(pio, pin_debug);
sm_config_set_sideset_pins(&c, pin_debug);
}
Expand All @@ -208,8 +201,8 @@ static inline void eop_detect_fs_program_init(PIO pio, uint sm, uint offset,
c = usb_edge_detector_program_get_default_config(offset);
} else {
c = usb_edge_detector_debug_program_get_default_config(offset);
pio_sm_set_pins_with_mask(pio, sm, 0, 1 << pin_debug);
pio_sm_set_pindirs_with_mask(pio, sm, 1 << pin_debug, 1 << pin_debug);
pio_sm_set_pins_with_mask64(pio, sm, 0, 1ull << pin_debug);
pio_sm_set_pindirs_with_mask64(pio, sm, 1ull << pin_debug, 1ull << pin_debug);
pio_gpio_init(pio, pin_debug);
sm_config_set_sideset_pins(&c, pin_debug);
}
Expand All @@ -232,4 +225,4 @@ static inline void eop_detect_fs_program_init(PIO pio, uint sm, uint offset,
pio_sm_set_enabled(pio, sm, true);
}

%}
%}
16 changes: 5 additions & 11 deletions src/usb_rx.pio.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,7 @@ static inline pio_sm_config usb_nrzi_decoder_debug_program_get_default_config(ui
}

#include "hardware/clocks.h"
#if PICO_SDK_VERSION_MAJOR < 2
static __always_inline void pio_sm_set_jmp_pin(PIO pio, uint sm, uint jmp_pin) {
pio->sm[sm].execctrl =
(pio->sm[sm].execctrl & ~PIO_SM0_EXECCTRL_JMP_PIN_BITS) |
(jmp_pin << PIO_SM0_EXECCTRL_JMP_PIN_LSB);
}
#endif
#include "sdk_compat.h"
static inline void usb_rx_fs_program_init(PIO pio, uint sm, uint offset, uint pin_dp, uint pin_dm, int pin_debug) {
if (pin_dp < pin_dm) {
pio_sm_set_consecutive_pindirs(pio, sm, pin_dp, 2, false);
Expand All @@ -195,8 +189,8 @@ static inline void usb_rx_fs_program_init(PIO pio, uint sm, uint offset, uint pi
c = usb_nrzi_decoder_program_get_default_config(offset);
} else {
c = usb_nrzi_decoder_debug_program_get_default_config(offset);
pio_sm_set_pins_with_mask(pio, sm, 0, 1 << pin_debug);
pio_sm_set_pindirs_with_mask(pio, sm, 1 << pin_debug, 1 << pin_debug);
pio_sm_set_pins_with_mask64(pio, sm, 0, 1ull << pin_debug);
pio_sm_set_pindirs_with_mask64(pio, sm, 1ull << pin_debug, 1ull << pin_debug);
pio_gpio_init(pio, pin_debug);
sm_config_set_sideset_pins(&c, pin_debug);
}
Expand All @@ -216,8 +210,8 @@ static inline void eop_detect_fs_program_init(PIO pio, uint sm, uint offset,
c = usb_edge_detector_program_get_default_config(offset);
} else {
c = usb_edge_detector_debug_program_get_default_config(offset);
pio_sm_set_pins_with_mask(pio, sm, 0, 1 << pin_debug);
pio_sm_set_pindirs_with_mask(pio, sm, 1 << pin_debug, 1 << pin_debug);
pio_sm_set_pins_with_mask64(pio, sm, 0, 1ull << pin_debug);
pio_sm_set_pindirs_with_mask64(pio, sm, 1ull << pin_debug, 1ull << pin_debug);
pio_gpio_init(pio, pin_debug);
sm_config_set_sideset_pins(&c, pin_debug);
}
Expand Down
7 changes: 4 additions & 3 deletions src/usb_tx.pio
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ set pindirs, 0b11 side FJ_LK

% c-sdk {
#include "hardware/clocks.h"
#include "sdk_compat.h"

static void __no_inline_not_in_flash_func(usb_tx_configure_pins)(PIO pio, uint sm, uint pin_dp, uint pin_dm) {
if (pin_dp < pin_dm) {
Expand All @@ -106,7 +107,7 @@ set pindirs, 0b11 side FJ_LK

static inline void usb_tx_fs_program_init(PIO pio, uint sm, uint offset,
uint pin_dp, uint pin_dm) {
pio_sm_set_pins_with_mask(pio, sm, (1 << pin_dp), ((1 << pin_dp) | (1 << pin_dm)));
pio_sm_set_pins_with_mask64(pio, sm, (1ull << pin_dp), ((1ull << pin_dp) | (1ull << pin_dm)));

gpio_pull_down(pin_dp);
gpio_pull_down(pin_dm);
Expand All @@ -132,7 +133,7 @@ set pindirs, 0b11 side FJ_LK

static inline void usb_tx_ls_program_init(PIO pio, uint sm, uint offset,
uint pin_dp, uint pin_dm) {
pio_sm_set_pins_with_mask(pio, sm, (1 << pin_dm), ((1 << pin_dp) | (1 << pin_dm)));
pio_sm_set_pins_with_mask64(pio, sm, (1ull << pin_dm), ((1ull << pin_dp) | (1ull << pin_dm)));

gpio_pull_down(pin_dp);
gpio_pull_down(pin_dm);
Expand All @@ -156,4 +157,4 @@ set pindirs, 0b11 side FJ_LK
pio_sm_set_enabled(pio, sm, true);
}

%}
%}
5 changes: 3 additions & 2 deletions src/usb_tx.pio.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ static inline pio_sm_config usb_tx_pre_dmdp_program_get_default_config(uint offs
}

#include "hardware/clocks.h"
#include "sdk_compat.h"
static void __no_inline_not_in_flash_func(usb_tx_configure_pins)(PIO pio, uint sm, uint pin_dp, uint pin_dm) {
if (pin_dp < pin_dm) {
pio_sm_set_out_pins(pio, sm, pin_dp, 2);
Expand All @@ -151,7 +152,7 @@ static inline pio_sm_config usb_tx_pre_dmdp_program_get_default_config(uint offs
}
static inline void usb_tx_fs_program_init(PIO pio, uint sm, uint offset,
uint pin_dp, uint pin_dm) {
pio_sm_set_pins_with_mask(pio, sm, (1 << pin_dp), ((1 << pin_dp) | (1 << pin_dm)));
pio_sm_set_pins_with_mask64(pio, sm, (1ull << pin_dp), ((1ull << pin_dp) | (1ull << pin_dm)));
gpio_pull_down(pin_dp);
gpio_pull_down(pin_dm);
pio_gpio_init(pio, pin_dp);
Expand All @@ -170,7 +171,7 @@ static inline pio_sm_config usb_tx_pre_dmdp_program_get_default_config(uint offs
}
static inline void usb_tx_ls_program_init(PIO pio, uint sm, uint offset,
uint pin_dp, uint pin_dm) {
pio_sm_set_pins_with_mask(pio, sm, (1 << pin_dm), ((1 << pin_dp) | (1 << pin_dm)));
pio_sm_set_pins_with_mask64(pio, sm, (1ull << pin_dm), ((1ull << pin_dp) | (1ull << pin_dm)));
gpio_pull_down(pin_dp);
gpio_pull_down(pin_dm);
pio_gpio_init(pio, pin_dp);
Expand Down