Skip to content

Commit

Permalink
Fix compatibility with old SDK versions
Browse files Browse the repository at this point in the history
  • Loading branch information
jepler committed Dec 20, 2024
1 parent a7d2b61 commit 38186c1
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/pio_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ static void apply_config(pio_port_t *pp, const pio_usb_configuration_t *c,
pp->ls_tx_program = &usb_tx_dpdm_program;
}

#if PICO_PIO_USE_GPIO_BASE
#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);
Expand Down
20 changes: 20 additions & 0 deletions src/sdk_compat.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#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);
}
#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

9 changes: 1 addition & 8 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 Down
8 changes: 1 addition & 7 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 Down
1 change: 1 addition & 0 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 Down
1 change: 1 addition & 0 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 Down

0 comments on commit 38186c1

Please sign in to comment.