-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
firmware: add support for the raspberry pi pico
- Loading branch information
1 parent
07ce023
commit 76df2fd
Showing
26 changed files
with
1,577 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
cmake_minimum_required(VERSION 3.17) | ||
set_property(GLOBAL PROPERTY USE_FOLDERS ON) | ||
# set(CMAKE_C_COMPILER_WORKS 1) | ||
|
||
#set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
include(${CMAKE_CURRENT_SOURCE_DIR}/../lib/tinyusb/hw/bsp/family_support.cmake) | ||
|
||
# gets PROJECT name for the example (e.g. <BOARD>-<DIR_NAME>) | ||
family_get_project_name(PROJECT ${CMAKE_CURRENT_LIST_DIR}) | ||
|
||
project(${PROJECT} C CXX ASM) | ||
|
||
# Checks this example is valid for the family and initializes the project | ||
family_initialize_project(${PROJECT} ${CMAKE_CURRENT_LIST_DIR}) | ||
|
||
# Espressif has its own cmake build system | ||
if(FAMILY STREQUAL "espressif") | ||
return() | ||
endif() | ||
|
||
add_executable(${PROJECT}) | ||
|
||
# Example source | ||
target_sources(${PROJECT} PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/console.c | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/debug_spi.c | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/jtag.c | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/jtag_tap.c | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/main.c | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/vendor.c | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/boards/${BOARD}/button.c | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/boards/${BOARD}/dfu.c | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/boards/${BOARD}/jtag.c | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/boards/${BOARD}/fpga.c | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/boards/${BOARD}/debug_spi.c | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/boards/${BOARD}/spi.c | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/boards/${BOARD}/led.c | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/boards/${BOARD}/uart.c | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/boards/${BOARD}/usb_descriptors.c | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/boards/${BOARD}/usb_switch.c | ||
) | ||
|
||
# Example include | ||
target_include_directories(${PROJECT} PUBLIC | ||
${CMAKE_CURRENT_SOURCE_DIR}/src | ||
${CMAKE_CURRENT_SOURCE_DIR}/src/boards/${BOARD} | ||
) | ||
|
||
target_compile_definitions(${PROJECT} PUBLIC | ||
# CFG_TUSB_OS=OPT_OS_PICO | ||
_BOARD_REVISION_MAJOR_=${BOARD_REVISION_MAJOR} | ||
_BOARD_REVISION_MINOR_=${BOARD_REVISION_MINOR} | ||
) | ||
|
||
# Configure compilation flags and libraries for the example... see the corresponding function | ||
# in hw/bsp/FAMILY/family.cmake for details. | ||
# family_configure_device_example(${PROJECT} noos) | ||
family_configure_target(${PROJECT} noos) | ||
target_link_libraries(${PROJECT} PUBLIC pico_stdlib tinyusb_device pico_unique_id pico_fix_rp2040_usb_device_enumeration hardware_spi) | ||
|
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* button handler | ||
* | ||
* Copyright (c) 2023 Great Scott Gadgets <[email protected]> | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
#include "button.h" | ||
#include "usb_switch.h" | ||
#include "fpga.h" | ||
#include "apollo_board.h" | ||
#include <hal/include/hal_gpio.h> | ||
|
||
|
||
/** | ||
* Detect button press. | ||
*/ | ||
bool button_pressed(void) | ||
{ | ||
#ifdef BOARD_HAS_PROGRAM_BUTTON | ||
return (gpio_get_pin_level(PROGRAM_BUTTON) == false); | ||
#else | ||
return false; | ||
#endif | ||
} | ||
|
||
|
||
/** | ||
* Handle button events. | ||
*/ | ||
void button_task(void) | ||
{ | ||
if (button_pressed()) { | ||
force_fpga_offline(); | ||
take_over_usb(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* switch control for USB port shared by Apollo and FPGA | ||
* | ||
* This file is part of Apollo. | ||
* | ||
* Copyright (c) 2023 Great Scott Gadgets <[email protected]> | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
#include "usb_switch.h" | ||
#include "apollo_board.h" | ||
#include <hal/include/hal_gpio.h> | ||
|
||
|
||
/** | ||
* Hand off shared USB port to FPGA. | ||
*/ | ||
void hand_off_usb(void) | ||
{ | ||
#ifdef BOARD_HAS_USB_SWITCH | ||
gpio_set_pin_level(USB_SWITCH, false); | ||
gpio_set_pin_direction(USB_SWITCH, GPIO_DIRECTION_OUT); | ||
#endif | ||
} | ||
|
||
|
||
/** | ||
* Take control of USB port from FPGA. | ||
*/ | ||
void take_over_usb(void) | ||
{ | ||
#ifdef BOARD_HAS_USB_SWITCH | ||
gpio_set_pin_level(USB_SWITCH, true); | ||
gpio_set_pin_direction(USB_SWITCH, GPIO_DIRECTION_OUT); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* button handler | ||
* | ||
* Copyright (c) 2023 Great Scott Gadgets <[email protected]> | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
#include "button.h" | ||
#include "usb_switch.h" | ||
#include "fpga.h" | ||
#include "apollo_board.h" | ||
#include <hal/include/hal_gpio.h> | ||
|
||
|
||
/** | ||
* Detect button press. | ||
*/ | ||
bool button_pressed(void) | ||
{ | ||
#ifdef BOARD_HAS_PROGRAM_BUTTON | ||
return (gpio_get_pin_level(PROGRAM_BUTTON) == false); | ||
#else | ||
return false; | ||
#endif | ||
} | ||
|
||
|
||
/** | ||
* Handle button events. | ||
*/ | ||
void button_task(void) | ||
{ | ||
if (button_pressed()) { | ||
force_fpga_offline(); | ||
take_over_usb(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* switch control for USB port shared by Apollo and FPGA | ||
* | ||
* This file is part of Apollo. | ||
* | ||
* Copyright (c) 2023 Great Scott Gadgets <[email protected]> | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
#include "usb_switch.h" | ||
#include "apollo_board.h" | ||
#include <hal/include/hal_gpio.h> | ||
|
||
|
||
/** | ||
* Hand off shared USB port to FPGA. | ||
*/ | ||
void hand_off_usb(void) | ||
{ | ||
#ifdef BOARD_HAS_USB_SWITCH | ||
gpio_set_pin_level(USB_SWITCH, false); | ||
gpio_set_pin_direction(USB_SWITCH, GPIO_DIRECTION_OUT); | ||
#endif | ||
} | ||
|
||
|
||
/** | ||
* Take control of USB port from FPGA. | ||
*/ | ||
void take_over_usb(void) | ||
{ | ||
#ifdef BOARD_HAS_USB_SWITCH | ||
gpio_set_pin_level(USB_SWITCH, true); | ||
gpio_set_pin_direction(USB_SWITCH, GPIO_DIRECTION_OUT); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* button handler | ||
* | ||
* Copyright (c) 2023 Great Scott Gadgets <[email protected]> | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
#include "button.h" | ||
#include "usb_switch.h" | ||
#include "fpga.h" | ||
#include "apollo_board.h" | ||
#include <hal/include/hal_gpio.h> | ||
|
||
|
||
/** | ||
* Detect button press. | ||
*/ | ||
bool button_pressed(void) | ||
{ | ||
#ifdef BOARD_HAS_PROGRAM_BUTTON | ||
return (gpio_get_pin_level(PROGRAM_BUTTON) == false); | ||
#else | ||
return false; | ||
#endif | ||
} | ||
|
||
|
||
/** | ||
* Handle button events. | ||
*/ | ||
void button_task(void) | ||
{ | ||
if (button_pressed()) { | ||
force_fpga_offline(); | ||
take_over_usb(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* switch control for USB port shared by Apollo and FPGA | ||
* | ||
* This file is part of Apollo. | ||
* | ||
* Copyright (c) 2023 Great Scott Gadgets <[email protected]> | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
#include "usb_switch.h" | ||
#include "apollo_board.h" | ||
#include <hal/include/hal_gpio.h> | ||
|
||
|
||
/** | ||
* Hand off shared USB port to FPGA. | ||
*/ | ||
void hand_off_usb(void) | ||
{ | ||
#ifdef BOARD_HAS_USB_SWITCH | ||
gpio_set_pin_level(USB_SWITCH, false); | ||
gpio_set_pin_direction(USB_SWITCH, GPIO_DIRECTION_OUT); | ||
#endif | ||
} | ||
|
||
|
||
/** | ||
* Take control of USB port from FPGA. | ||
*/ | ||
void take_over_usb(void) | ||
{ | ||
#ifdef BOARD_HAS_USB_SWITCH | ||
gpio_set_pin_level(USB_SWITCH, true); | ||
gpio_set_pin_direction(USB_SWITCH, GPIO_DIRECTION_OUT); | ||
#endif | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/** | ||
* Apollo board definitions for Adafruit QT Py RP2040 | ||
* | ||
* This file is part of LUNA. | ||
* | ||
* Copyright (c) 2020 Great Scott Gadgets <[email protected]> | ||
* Copyright (c) 2022 Markus Blechschmidt <[email protected]> | ||
* SPDX-License-Identifier: BSD-3-Clause | ||
*/ | ||
|
||
#ifndef __APOLLO_BOARD_H__ | ||
#define __APOLLO_BOARD_H__ | ||
|
||
#include <stdbool.h> | ||
|
||
#include "boards/pico.h" | ||
#include "bsp/rp2040/board.h" | ||
#include "pico/stdlib.h" | ||
#include "hardware/gpio.h" | ||
#include "hardware/sync.h" | ||
|
||
|
||
#define __NOP() {asm volatile("nop");} | ||
|
||
|
||
typedef unsigned int gpio_t; | ||
|
||
|
||
typedef enum gpio_direction{ | ||
GPIO_DIRECTION_IN = GPIO_IN, | ||
GPIO_DIRECTION_OUT = GPIO_OUT, | ||
} gpio_direction_t; | ||
|
||
|
||
typedef enum gpio_pull_mode { | ||
GPIO_PULL_OFF, | ||
GPIO_PULL_UP, | ||
GPIO_PULL_DOWN, | ||
} gpio_pull_mode_t; | ||
|
||
|
||
/** | ||
* GPIO pins for each of the microcontroller LEDs. | ||
*/ | ||
typedef enum { | ||
LED_A = LED_PIN, // Green | ||
|
||
LED_COUNT = 1, | ||
} led_t; | ||
|
||
/** | ||
* GPIO pin numbers. | ||
*/ | ||
|
||
|
||
|
||
enum { | ||
// // Each of the JTAG pins. SPI0 | ||
TMS_GPIO = 5, | ||
TDI_GPIO = 3, // MOSI | ||
TDO_GPIO = 4, // MISO | ||
TCK_GPIO = 6, // SCK | ||
|
||
// // Connected to orangecrab pins 0 and 1. SERCOM0 | ||
UART_RX = UART_RX_PIN, | ||
UART_TX = UART_TX_PIN, | ||
}; | ||
|
||
|
||
static inline void gpio_set_pin_level(const gpio_t gpio_pin, bool level) { | ||
gpio_put(gpio_pin, level); | ||
} | ||
|
||
|
||
static inline bool gpio_get_pin_level(const gpio_t gpio_pin) { | ||
return gpio_get(gpio_pin); | ||
} | ||
|
||
|
||
static inline void gpio_toggle_pin_level(const gpio_t gpio_pin) { | ||
gpio_set_pin_level(gpio_pin, !gpio_get_pin_level(gpio_pin)); | ||
} | ||
|
||
|
||
static inline void gpio_set_pin_direction(const gpio_t gpio_pin, const enum gpio_direction direction) { | ||
gpio_init(gpio_pin); | ||
gpio_set_dir(gpio_pin, direction); | ||
} | ||
|
||
|
||
static inline void gpio_set_pin_pull_mode(const gpio_t gpio_pin, const gpio_pull_mode_t pull_mode) { | ||
switch(pull_mode) { | ||
case GPIO_PULL_OFF: { | ||
gpio_disable_pulls(gpio_pin); | ||
} break; | ||
case GPIO_PULL_UP: { | ||
gpio_pull_up(gpio_pin); | ||
} break; | ||
case GPIO_PULL_DOWN: { | ||
gpio_pull_down(gpio_pin); | ||
} break; | ||
default: { | ||
|
||
} break; | ||
} | ||
} | ||
|
||
|
||
#endif |
Oops, something went wrong.