Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Adafruit RP2040 boards #1

Merged
merged 2 commits into from
May 25, 2021
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ build
*.txt.user
__pycache__
venv/
.vscode
6 changes: 6 additions & 0 deletions firmware/source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ project(u2if VERSION "0.3.0")
# initialize the Pico SDK
pico_sdk_init()

# define board, pico is default
# BOARD_FEATHER, BOARD_ITSYBITSY, BOARD_QTPY, BOARD_QT2040_TRINKEY
add_compile_definitions(BOARD_FEATHER)
# might help for feather?
#add_compile_definitions(PICO_DEFAULT_BOOT_STAGE2_FILE=${CMAKE_CURRENT_SOURCE_DIR}/../pico-sdk/src/rp2_common/boot_stage2/boot2_generic_03h.S)

# Enable wanted peripherals
set(I2C0_ENABLE 1)
set(I2C1_ENABLE 1)
Expand Down
1 change: 0 additions & 1 deletion firmware/source/interfaces/I2cMaster.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "I2cMaster.h"
#include "string.h"


I2CMaster::I2CMaster(uint8_t i2cIndex, uint streamBufferSize = 512)
: StreamedInterface(streamBufferSize),
_i2cInst(i2cIndex == 0 ? i2c0 : i2c1),
Expand Down
26 changes: 14 additions & 12 deletions firmware/source/interfaces/PicoInterfacesBoard.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef _PICO_INTERFACES_BOARD_H
#define _PICO_INTERFACES_BOARD_H

#include "pins.h"

#define HID_CMD_SIZE 64
#define HID_RESPONSE_SIZE 64

Expand All @@ -22,29 +24,29 @@ namespace Pin {
GP27_ADC1 = 27,

// UART0
GP0_UART0_TX = 0,
GP1_UART0_RX = 1,
GP0_UART0_TX = U2IF_UART0_TX,
GP1_UART0_RX = U2IF_UART0_RX,

// SPI0
GP18_SPI0_CK = 18,
GP19_SPI0_MOSI = 19,
GP16_SPI0_MISO = 16,
GP18_SPI0_CK = U2IF_SPI0_CK,
GP19_SPI0_MOSI = U2IF_SPI0_MOSI,
GP16_SPI0_MISO = U2IF_SPI0_MISO,
GP17_SPI0_CS1 = 17,
GP20_SPI0_CS2 = 20,

// SPI1
GP10_SPI1_CK = 10,
GP11_SPI1_MOSI = 11,
GP12_SPI1_MISO = 12,
GP10_SPI1_CK = U2IF_SPI1_CK,
GP11_SPI1_MOSI = U2IF_SPI1_MOSI,
GP12_SPI1_MISO = U2IF_SPI1_MISO,
GP13_SPI1_CS1 = 13,

// I2C0
GP4_I2C0_SDA = 4,
GP5_I2C0_SCL = 5,
GP4_I2C0_SDA = U2IF_I2C0_SDA,
GP5_I2C0_SCL = U2IF_I2C0_SCL,

// I2C1
GP14_I2C1_SDA = 14,
GP15_I2C1_SCL = 15
GP14_I2C1_SDA = U2IF_I2C1_SDA,
GP15_I2C1_SCL = U2IF_I2C1_SCL
};
}

Expand Down
124 changes: 124 additions & 0 deletions firmware/source/interfaces/pins.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/**
* Pin Mappings
*
* For now, pins are assigned for all interfaces, even if not routed. This
* doesn't seem to cause any issues, and unused interfaces are not exposed
* in Blinka.
*
*/

//---------------------------------------------------------
// Feather
//---------------------------------------------------------
#if defined (BOARD_FEATHER)
// I2C0
#define U2IF_I2C0_SDA 4
#define U2IF_I2C0_SCL 5
// I2C1
#define U2IF_I2C1_SDA 2
#define U2IF_I2C1_SCL 3
// SPI0
#define U2IF_SPI0_CK 18
#define U2IF_SPI0_MOSI 19
#define U2IF_SPI0_MISO 20
// SPI1
#define U2IF_SPI1_CK 10
#define U2IF_SPI1_MOSI 11
#define U2IF_SPI1_MISO 12
// UART0
#define U2IF_UART0_TX 0
#define U2IF_UART0_RX 1

//---------------------------------------------------------
// QT Py
//---------------------------------------------------------
#elif defined (BOARD_QTPY)

// I2C0
#define U2IF_I2C0_SDA 24
#define U2IF_I2C0_SCL 25
// I2C1
#define U2IF_I2C1_SDA 22
#define U2IF_I2C1_SCL 23
// SPI0
#define U2IF_SPI0_CK 6
#define U2IF_SPI0_MOSI 3
#define U2IF_SPI0_MISO 4
// SPI1
#define U2IF_SPI1_CK 10
#define U2IF_SPI1_MOSI 11
#define U2IF_SPI1_MISO 12
// UART0
#define U2IF_UART0_TX 20
#define U2IF_UART0_RX 5

//---------------------------------------------------------
// Itsy Bitsy
//---------------------------------------------------------
#elif defined (BOARD_ITSYBITSY)

// I2C0
#define U2IF_I2C0_SDA 4
#define U2IF_I2C0_SCL 5
// I2C1
#define U2IF_I2C1_SDA 2
#define U2IF_I2C1_SCL 3
// SPI0
#define U2IF_SPI0_CK 18
#define U2IF_SPI0_MOSI 19
#define U2IF_SPI0_MISO 20
// SPI1
#define U2IF_SPI1_CK 10
#define U2IF_SPI1_MOSI 11
#define U2IF_SPI1_MISO 12
// UART0
#define U2IF_UART0_TX 0
#define U2IF_UART0_RX 1

//---------------------------------------------------------
// QT2040 Trinkey
//---------------------------------------------------------
#elif defined (BOARD_QT2040_TRINKEY)

// I2C0
#define U2IF_I2C0_SDA 16
#define U2IF_I2C0_SCL 17
// I2C1
#define U2IF_I2C1_SDA 2
#define U2IF_I2C1_SCL 3
// SPI0
#define U2IF_SPI0_CK 6
#define U2IF_SPI0_MOSI 7
#define U2IF_SPI0_MISO 8
// SPI1
#define U2IF_SPI1_CK 10
#define U2IF_SPI1_MOSI 11
#define U2IF_SPI1_MISO 12
// UART0
#define U2IF_UART0_TX 1
#define U2IF_UART0_RX 2

//---------------------------------------------------------
// Pico (default)
//---------------------------------------------------------
#else

// I2C0
#define U2IF_I2C0_SDA 4
#define U2IF_I2C0_SCL 5
// I2C1
#define U2IF_I2C1_SDA 14
#define U2IF_I2C1_SCL 15
// SPI0
#define U2IF_SPI0_CK 18
#define U2IF_SPI0_MOSI 19
#define U2IF_SPI0_MISO 16
// SPI1
#define U2IF_SPI1_CK 10
#define U2IF_SPI1_MOSI 11
#define U2IF_SPI1_MISO 12
// UART0
#define U2IF_UART0_TX 0
#define U2IF_UART0_RX 1

#endif
36 changes: 31 additions & 5 deletions firmware/source/usb_descriptors.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,34 @@
* [MSB] HID | MSC | CDC [LSB]
*/
#define _PID_MAP(itf, n) ( (CFG_TUD_##itf) << (n) )
#define USB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
_PID_MAP(MIDI, 3) | _PID_MAP(VENDOR, 4) )

#if defined(BOARD_FEATHER)
#define USB_MFG "Adafruit"
#define USB_PRD "Feather RP2040 U2IF"
#define USB_VID 0x239A
#define USB_PID 0x00F1
#elif defined(BOARD_ITSYBITSY)
#define USB_MFG "Adafruit"
#define USB_PRD "ItsyBitsy RP2040 U2IF"
#define USB_VID 0x239A
#define USB_PID 0x00FD
#elif defined(BOARD_QTPY)
#define USB_MFG "Adafruit"
#define USB_PRD "QT Py RP2040 U2IF"
#define USB_VID 0x239A
#define USB_PID 0x00F7
#elif defined(BOARD_QT2040_TRINKEY)
#define USB_MFG "Adafruit"
#define USB_PRD "QT2040 Trinkey U2IF"
#define USB_VID 0x239A
#define USB_PID 0x0109
#else
#define USB_MFG "Pico"
#define USB_PRD "U2IF"
#define USB_VID 0xCAFE
#define USB_PID (0x4000 | _PID_MAP(CDC, 0) | _PID_MAP(MSC, 1) | _PID_MAP(HID, 2) | \
_PID_MAP(MIDI, 3) | _PID_MAP(VENDOR, 4) )
#endif

//--------------------------------------------------------------------+
// Device Descriptors
Expand All @@ -58,7 +84,7 @@ tusb_desc_device_t const desc_device =

.bMaxPacketSize0 = CFG_TUD_ENDPOINT0_SIZE,

.idVendor = 0xCafe,
.idVendor = USB_VID,
.idProduct = USB_PID,
.bcdDevice = 0x0100,

Expand Down Expand Up @@ -146,8 +172,8 @@ uint8_t const *tud_descriptor_configuration_cb(uint8_t index) {
char const *string_desc_arr[] =
{
(const char[]) {0x09, 0x04}, // 0: is supported language is English (0x0409)
"Pico", // 1: Manufacturer
"U2IF", // 2: Product
USB_MFG, // 1: Manufacturer
USB_PRD, // 2: Product
"", // 3: Serials, should use chip ID
"CDC Streamed data channel" , // 4: CDC Interface
"HID Command channel", // 5: HID
Expand Down