diff --git a/firmware/Makefile b/firmware/Makefile index 956e241..3d84fd7 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -4,19 +4,24 @@ # Ensure that a APOLLO_BOARD is selected. ifeq ($(APOLLO_BOARD), ) - BOARD:=$(error You need to specify an APOLLO_BOARD as a make variable (e.g. APOLLO_BOARD=luna)!) + BOARD:=$(error You need to specify an APOLLO_BOARD as a make variable (e.g. APOLLO_BOARD=cynthion)!) endif -# If the board is specified as 'luna' without a processor, we'll try to emulate the behavior -# of LUNA's Apollo as much as we can. +ifeq ($(APOLLO_BOARD), cynthion) + BOARD := luna_d11 +endif + +# Allow Cynthion's old name "LUNA" for backward compatibility. ifeq ($(APOLLO_BOARD), luna) BOARD := luna_d11 +endif - # These should default to the latest revision; but can be set on the command line. - BOARD_REVISION_MAJOR ?= 0 - BOARD_REVISION_MINOR ?= 4 +ifeq ($(BOARD), luna_d11) + # These should default to the latest revision but can be set on the command line. + BOARD_REVISION_MAJOR ?= 1 + BOARD_REVISION_MINOR ?= 0 - # On r0.1 or r0.2 boards, we want to target the SAMD21 / luna_d11 configuration. + # On r0.1 or r0.2 boards, we target the SAMD21 configuration. ifeq ($(BOARD_REVISION_MAJOR), 0) ifeq ($(BOARD_REVISION_MINOR), 1) BOARD := luna_d21 diff --git a/firmware/src/boards/daisho/usb_switch.c b/firmware/src/boards/daisho/usb_switch.c new file mode 100644 index 0000000..21646b3 --- /dev/null +++ b/firmware/src/boards/daisho/usb_switch.c @@ -0,0 +1,31 @@ +/** + * switch control for USB port shared by Apollo and FPGA + * + * This file is part of Apollo. + * + * Copyright (c) 2023 Great Scott Gadgets + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "usb_switch.h" + +/** + * Hand off shared USB port to FPGA. + */ +void hand_off_usb(void) +{ +} + +/** + * Take control of USB port from FPGA. + */ +void take_over_usb(void) +{ +} + +/** + * Handle switch control user request. + */ +void switch_control_task(void) +{ +} diff --git a/firmware/src/boards/luna_d11/apollo_board.h b/firmware/src/boards/luna_d11/apollo_board.h index e3675eb..be13ceb 100644 --- a/firmware/src/boards/luna_d11/apollo_board.h +++ b/firmware/src/boards/luna_d11/apollo_board.h @@ -29,7 +29,7 @@ typedef enum { /** - * GPIO pin numbers. + * GPIO pins for FPGA JTAG */ enum { // Each of the JTAG pins. @@ -41,11 +41,17 @@ enum { /** - * List of pins used for FPGA interfacing. + * Other GPIO pins */ enum { - PROGRAM_GPIO = PIN_PA08, - PIN_PHY_RESET = PIN_PA09 + FPGA_PROGRAM = PIN_PA08, +#if _BOARD_REVISION_MAJOR_ == 1 + PROGRAM_BUTTON = PIN_PA02, + USB_SWITCH = PIN_PA06 +#else + PROGRAM_BUTTON = PIN_PA16, + PHY_RESET = PIN_PA09 +#endif }; diff --git a/firmware/src/boards/luna_d11/fpga.c b/firmware/src/boards/luna_d11/fpga.c index 23ca893..bdafd4e 100644 --- a/firmware/src/boards/luna_d11/fpga.c +++ b/firmware/src/boards/luna_d11/fpga.c @@ -18,10 +18,8 @@ void fpga_io_init(void) { // By default, keep PROGRAM_N from being driven. - gpio_set_pin_level(PROGRAM_GPIO, true); - gpio_set_pin_direction(PROGRAM_GPIO, GPIO_DIRECTION_IN); - - gpio_set_pin_direction(PIN_PHY_RESET, GPIO_DIRECTION_IN); + gpio_set_pin_level(FPGA_PROGRAM, true); + gpio_set_pin_direction(FPGA_PROGRAM, GPIO_DIRECTION_IN); } @@ -30,13 +28,13 @@ void fpga_io_init(void) */ void trigger_fpga_reconfiguration(void) { - gpio_set_pin_direction(PROGRAM_GPIO, GPIO_DIRECTION_OUT); - gpio_set_pin_level(PROGRAM_GPIO, false); + gpio_set_pin_direction(FPGA_PROGRAM, GPIO_DIRECTION_OUT); + gpio_set_pin_level(FPGA_PROGRAM, false); board_delay(1); - gpio_set_pin_level(PROGRAM_GPIO, true); - gpio_set_pin_direction(PROGRAM_GPIO, GPIO_DIRECTION_IN); + gpio_set_pin_level(FPGA_PROGRAM, true); + gpio_set_pin_direction(FPGA_PROGRAM, GPIO_DIRECTION_IN); } @@ -45,6 +43,6 @@ void trigger_fpga_reconfiguration(void) */ void force_fpga_offline(void) { - gpio_set_pin_direction(PROGRAM_GPIO, GPIO_DIRECTION_OUT); - gpio_set_pin_level(PROGRAM_GPIO, false); + gpio_set_pin_direction(FPGA_PROGRAM, GPIO_DIRECTION_OUT); + gpio_set_pin_level(FPGA_PROGRAM, false); } diff --git a/firmware/src/boards/luna_d11/usb_switch.c b/firmware/src/boards/luna_d11/usb_switch.c new file mode 100644 index 0000000..82a82d8 --- /dev/null +++ b/firmware/src/boards/luna_d11/usb_switch.c @@ -0,0 +1,50 @@ +/** + * switch control for USB port shared by Apollo and FPGA + * + * This file is part of Apollo. + * + * Copyright (c) 2023 Great Scott Gadgets + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "usb_switch.h" +#include "apollo_board.h" +#include "led.h" +#include + +/** + * Hand off shared USB port to FPGA. + */ +void hand_off_usb(void) +{ +#if _BOARD_REVISION_MAJOR_ == 1 + gpio_set_pin_level(USB_SWITCH, false); + gpio_set_pin_direction(USB_SWITCH, GPIO_DIRECTION_OUT); + led_off(LED_D); +#else + led_on(LED_D); +#endif +} + +/** + * Take control of USB port from FPGA. + */ +void take_over_usb(void) +{ +#if _BOARD_REVISION_MAJOR_ == 1 + gpio_set_pin_level(USB_SWITCH, true); + gpio_set_pin_direction(USB_SWITCH, GPIO_DIRECTION_OUT); +#endif + led_on(LED_D); +} + +/** + * Handle switch control user request. + */ +void switch_control_task(void) +{ + gpio_set_pin_direction(PROGRAM_BUTTON, GPIO_DIRECTION_IN); + if (gpio_get_pin_level(PROGRAM_BUTTON) == false) { + take_over_usb(); + } +} diff --git a/firmware/src/boards/luna_d21/usb_switch.c b/firmware/src/boards/luna_d21/usb_switch.c new file mode 100644 index 0000000..3fc31aa --- /dev/null +++ b/firmware/src/boards/luna_d21/usb_switch.c @@ -0,0 +1,34 @@ +/** + * switch control for USB port shared by Apollo and FPGA + * + * This file is part of Apollo. + * + * Copyright (c) 2023 Great Scott Gadgets + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "led.h" +#include "usb_switch.h" + +/** + * Hand off shared USB port to FPGA. + */ +void hand_off_usb(void) +{ + led_on(LED_D); +} + +/** + * Take control of USB port from FPGA. + */ +void take_over_usb(void) +{ + led_on(LED_D); +} + +/** + * Handle switch control user request. + */ +void switch_control_task(void) +{ +} diff --git a/firmware/src/boards/samd11_xplained/usb_switch.c b/firmware/src/boards/samd11_xplained/usb_switch.c new file mode 100644 index 0000000..21646b3 --- /dev/null +++ b/firmware/src/boards/samd11_xplained/usb_switch.c @@ -0,0 +1,31 @@ +/** + * switch control for USB port shared by Apollo and FPGA + * + * This file is part of Apollo. + * + * Copyright (c) 2023 Great Scott Gadgets + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include "usb_switch.h" + +/** + * Hand off shared USB port to FPGA. + */ +void hand_off_usb(void) +{ +} + +/** + * Take control of USB port from FPGA. + */ +void take_over_usb(void) +{ +} + +/** + * Handle switch control user request. + */ +void switch_control_task(void) +{ +} diff --git a/firmware/src/main.c b/firmware/src/main.c index de46101..d5a57c6 100644 --- a/firmware/src/main.c +++ b/firmware/src/main.c @@ -37,6 +37,7 @@ #include "fpga.h" #include "console.h" #include "debug_spi.h" +#include "usb_switch.h" //#include "selftest.h" @@ -52,6 +53,7 @@ int main(void) fpga_io_init(); led_init(); debug_spi_init(); + hand_off_usb(); // Trigger an FPGA reconfiguration; so the FPGA automatically // configures itself from its SPI ROM on reset. This effectively @@ -62,6 +64,7 @@ int main(void) tud_task(); // tinyusb device task console_task(); heartbeat_task(); + switch_control_task(); } return 0;