Skip to content

Commit 28377cf

Browse files
authored
Fix for USB host (#1404)
Fixes the USB host not working by reverting the tinyusb and pico-pio-usb libraries to jfedor's branch. There are several issues that make these libraries not work in SDK 2.1.1, but jfedor's dev branch on pico-pio-usb fixes the issues we were having. I2C breaks on web config in this build, but I will be investigating i2c hal implementation which reverts some of the i2c functionality. If that works, we can add that as a patch as well.
1 parent 0241324 commit 28377cf

14 files changed

Lines changed: 48 additions & 27 deletions

.gitmodules

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
[submodule "lib/pico_pio_usb"]
2-
path = lib/pico_pio_usb
3-
url = https://github.com/sekigon-gonnoc/Pico-PIO-USB
41
[submodule "lib/tinyusb"]
52
path = lib/tinyusb
6-
url = https://github.com/hathach/tinyusb/
3+
url = https://github.com/jfedor2/tinyusb.git
4+
[submodule "lib/pico_pio_usb"]
5+
path = lib/pico_pio_usb
6+
url = https://github.com/jfedor2/Pico-PIO-USB.git

headers/tusb_config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@
153153
// max device support (excluding hub device)
154154
#define CFG_TUH_DEVICE_MAX (CFG_TUH_HUB ? 4 : 1) // hub typically has 4 ports
155155

156-
#define CFG_TUH_HID 4
156+
#define CFG_TUH_HID 4
157157
#define CFG_TUH_HID_EPIN_BUFSIZE 64
158158
#define CFG_TUH_HID_EPOUT_BUFSIZE 64
159159

lib/NeoPico/src/NeoPico.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ void NeoPico::PutPixel(uint32_t pixelData) {
3434
}
3535
}
3636

37-
void NeoPico::Setup(int ledPin, int inNumPixels, LEDFormat inFormat, PIO inPio){
37+
void NeoPico::Setup(int ledPin, int inNumPixels, LEDFormat inFormat, PIO inPio, int inState){
3838
format = inFormat;
3939
pio = inPio;
4040
numPixels = inNumPixels;
41-
stateMachine = 0;
41+
stateMachine = inState;
4242
uint offset = pio_add_program(pio, &ws2812_program);
4343
bool rgbw = (format == LED_FORMAT_GRBW) || (format == LED_FORMAT_RGBW);
4444
ws2812_program_init(pio, stateMachine, offset, ledPin, 800000, rgbw);

lib/NeoPico/src/NeoPico.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class NeoPico
1616
{
1717
public:
1818
NeoPico();
19-
void Setup(int ledPin, int inNumPixels, LEDFormat inFormat, PIO inPio);
19+
void Setup(int ledPin, int inNumPixels, LEDFormat inFormat, PIO inPio, int inState);
2020
void Show();
2121
void Clear();
2222
void Off();

lib/PicoPeripherals/CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1-
add_library(PicoPeripherals peripheral_i2c.cpp peripheral_spi.cpp peripheral_usb.cpp)
1+
add_library(PicoPeripherals
2+
interval_override.cpp
3+
peripheral_i2c.cpp
4+
peripheral_spi.cpp
5+
peripheral_usb.cpp
6+
)
7+
target_include_directories(PicoPeripherals PRIVATE .)
28
target_include_directories(PicoPeripherals INTERFACE .)
39
target_link_libraries(PicoPeripherals
410
pico_stdlib
11+
hardware_dma
512
hardware_gpio
613
hardware_i2c
714
hardware_spi
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "interval_override.h"
2+
3+
volatile uint8_t interval_override = 0;
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef _INTERVAL_OVERRIDE_H_
2+
#define _INTERVAL_OVERRIDE_H_
3+
4+
#include <stdint.h>
5+
6+
extern volatile uint8_t interval_override;
7+
8+
#endif

lib/PicoPeripherals/peripheral_i2c.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,11 @@ int16_t PeripheralI2C::write(uint8_t address, uint8_t *data, uint16_t len, bool
8989

9090
uint8_t PeripheralI2C::test(uint8_t address) {
9191
uint8_t data;
92-
int16_t ret = i2c_read_blocking(_I2C, address, &data, 1, false);
92+
93+
// TODO: Revert to i2c_read_blocking when we have I2C resolved
94+
// int16_t ret = i2c_read_blocking(_I2C, address, &data, 1, false);
95+
absolute_time_t test_timeout = make_timeout_time_ms(100);
96+
int16_t ret = i2c_read_blocking_until(_I2C, address, &data, 1, false, test_timeout);
9397
return (ret >= 0);
9498
}
9599

lib/PicoPeripherals/peripheral_usb.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,7 @@ void PeripheralUSB::setup() {
2929

3030
pio_cfg.pin_dp = _DP;
3131
pio_cfg.pinout = (_Order == 0 ? PIO_USB_PINOUT_DPDM : PIO_USB_PINOUT_DMDP);
32+
pio_cfg.sm_tx = 1; // Move TX to PIO0:1, NeoPico is in PIO0:0
33+
// RX and EOP are PIO1:0, PIO1:1
3234
}
3335
}

0 commit comments

Comments
 (0)