Skip to content

Commit

Permalink
firmware: add support for Cynthion r1
Browse files Browse the repository at this point in the history
  • Loading branch information
mossmann committed Mar 31, 2023
1 parent c3016c1 commit dc07f9f
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 21 deletions.
19 changes: 12 additions & 7 deletions firmware/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions firmware/src/boards/daisho/usb_switch.c
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
* 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)
{
}
14 changes: 10 additions & 4 deletions firmware/src/boards/luna_d11/apollo_board.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ typedef enum {


/**
* GPIO pin numbers.
* GPIO pins for FPGA JTAG
*/
enum {
// Each of the JTAG pins.
Expand All @@ -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
};


Expand Down
18 changes: 8 additions & 10 deletions firmware/src/boards/luna_d11/fpga.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}


Expand All @@ -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);
}


Expand All @@ -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);
}
50 changes: 50 additions & 0 deletions firmware/src/boards/luna_d11/usb_switch.c
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
* SPDX-License-Identifier: BSD-3-Clause
*/

#include "usb_switch.h"
#include "apollo_board.h"
#include "led.h"
#include <hal/include/hal_gpio.h>

/**
* 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();
}
}
34 changes: 34 additions & 0 deletions firmware/src/boards/luna_d21/usb_switch.c
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
* 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)
{
}
31 changes: 31 additions & 0 deletions firmware/src/boards/samd11_xplained/usb_switch.c
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
* 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)
{
}
3 changes: 3 additions & 0 deletions firmware/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "fpga.h"
#include "console.h"
#include "debug_spi.h"
#include "usb_switch.h"
//#include "selftest.h"


Expand All @@ -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
Expand All @@ -62,6 +64,7 @@ int main(void)
tud_task(); // tinyusb device task
console_task();
heartbeat_task();
switch_control_task();
}

return 0;
Expand Down

0 comments on commit dc07f9f

Please sign in to comment.