Skip to content

Commit

Permalink
Move everything to be configured by config.h
Browse files Browse the repository at this point in the history
 * Set default configuration as @xfxf requests for LCA2017
  • Loading branch information
mithro committed Jan 14, 2017
1 parent c7d42ad commit f85a83e
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 28 deletions.
51 changes: 49 additions & 2 deletions firmware/config.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,57 @@
#include <generated/csr.h>
#include <generated/mem.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <generated/mem.h>

#ifndef LOCALIP1
#warning "No default IP address"
#define LOCALIP1 0
#define LOCALIP2 0
#define LOCALIP3 0
#define LOCALIP4 0
#endif

#include "config.h"
#include "processor.h"

// Order of default;
// HDMI_IN1 (if it exists)
// HDMI_IN0 (if it exists)
// PATTERN
#ifdef CSR_HDMI_IN1_BASE
#define VIDEO_IN_DEFAULT VIDEO_IN_HDMI_IN1
#warning "Default HDMI In 1"
#else
#ifdef CSR_HDMI_IN0_BASE
#define VIDEO_IN_DEFAULT VIDEO_IN_HDMI_IN0
#warning "Default HDMI In 0"
#else
#define VIDEO_IN_DEFAULT VIDEO_IN_PATTERN
#warning "Default Pattern"
#endif
#endif


static const unsigned char config_defaults[CONFIG_KEY_COUNT] = CONFIG_DEFAULTS;
static const unsigned char config_defaults[CONFIG_KEY_COUNT] = {
// EDID Config
PROCESSOR_MODE_720p_50,
PROCESSOR_MODE_720p_60,
// Input config
false, // Input0
true, // Input1
// Output config
true, VIDEO_IN_DEFAULT, // Output 0
true, VIDEO_IN_DEFAULT, // Output 1
// Encoder
true, VIDEO_IN_DEFAULT, 85, true,
// Networking - MAC Address
0x10, 0xe2, 0xd5, 0x00, 0x00, 0x00,
// Networking - IP Address
LOCALIP1, LOCALIP2, LOCALIP3, LOCALIP4,
// Networking - DHCP
false,
};
static unsigned char config_values[CONFIG_KEY_COUNT];

void config_init(void)
Expand Down
35 changes: 29 additions & 6 deletions firmware/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,39 @@
enum {
CONFIG_KEY_RES_PRIMARY = 0,
CONFIG_KEY_RES_SECONDARY,
CONFIG_KEY_BLEND_USER1,
CONFIG_KEY_BLEND_USER2,
CONFIG_KEY_BLEND_USER3,
CONFIG_KEY_BLEND_USER4,
// Input config
CONFIG_KEY_INPUT0_ENABLED,
CONFIG_KEY_INPUT1_ENABLED,
// Output 0 config
CONFIG_KEY_OUTPUT0_ENABLED,
CONFIG_KEY_OUTPUT0_SOURCE,
// Output 1 config
CONFIG_KEY_OUTPUT1_ENABLED,
CONFIG_KEY_OUTPUT1_SOURCE,
// Encoder config
CONFIG_KEY_ENCODER_ENABLED,
CONFIG_KEY_ENCODER_SOURCE,
CONFIG_KEY_ENCODER_QUALITY,
CONFIG_KEY_FX2_RESET,
// Networking - MAC Address
CONFIG_KEY_NETWORK_MAC0,
CONFIG_KEY_NETWORK_MAC1,
CONFIG_KEY_NETWORK_MAC2,
CONFIG_KEY_NETWORK_MAC3,
CONFIG_KEY_NETWORK_MAC4,
CONFIG_KEY_NETWORK_MAC5,
CONFIG_KEY_NETWORK_MAC6,
// Networking - IP address
CONFIG_KEY_NETWORK_IP0,
CONFIG_KEY_NETWORK_IP1,
CONFIG_KEY_NETWORK_IP2,
CONFIG_KEY_NETWORK_IP3,
// Networking - DHCP enabled?
CONFIG_KEY_NETWORK_DHCP,

CONFIG_KEY_COUNT
};

#define CONFIG_DEFAULTS { PROCESSOR_MODE_720p_60, PROCESSOR_MODE_720p_50, 1, 2, 3, 4 }

void config_init(void);
void config_write_all(void);
unsigned char config_get(unsigned char key);
Expand Down
6 changes: 4 additions & 2 deletions firmware/hdmi_out0.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <generated/csr.h>
#ifdef CSR_HDMI_OUT0_I2C_W_ADDR
#include <stdio.h>
#include "i2c.h"

#include "hdmi_out0.h"

#ifdef CSR_HDMI_OUT0_I2C_W_ADDR
#include "i2c.h"

I2C hdmi_out0_i2c;
int hdmi_out0_debug_enabled = 0;

Expand Down
5 changes: 2 additions & 3 deletions firmware/hdmi_out0.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <generated/csr.h>
#ifdef CSR_HDMI_OUT0_I2C_W_ADDR

#ifdef CSR_HDMI_OUT0_I2C_W_ADDR
void hdmi_out0_i2c_init(void);
void hdmi_out0_print_edid(void);

#endif
#endif
6 changes: 4 additions & 2 deletions firmware/hdmi_out1.c
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#include <generated/csr.h>
#ifdef CSR_HDMI_OUT1_I2C_W_ADDR
#include <stdio.h>
#include "i2c.h"

#include "hdmi_out1.h"

#ifdef CSR_HDMI_OUT1_I2C_W_ADDR
#include "i2c.h"

I2C hdmi_out1_i2c;
int hdmi_out1_debug_enabled = 0;

Expand Down
5 changes: 2 additions & 3 deletions firmware/hdmi_out1.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <generated/csr.h>
#ifdef CSR_HDMI_OUT1_I2C_W_ADDR

#ifdef CSR_HDMI_OUT1_I2C_W_ADDR
void hdmi_out1_i2c_init(void);
void hdmi_out1_print_edid(void);

#endif
#endif
34 changes: 24 additions & 10 deletions firmware/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ static void front_panel_service(void) {
#endif

#ifdef ETHMAC_BASE
static unsigned char mac_addr[6] = {0x10, 0xe2, 0xd5, 0x00, 0x00, 0x00};
static unsigned char ip_addr[4] = {LOCALIP1, LOCALIP2, LOCALIP3, LOCALIP4};
static unsigned char mac_addr[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
static unsigned char ip_addr[4] = {0x00, 0x00, 0x00, 0x00};
#endif

int main(void)
Expand All @@ -57,9 +57,6 @@ int main(void)

#ifdef CSR_OPSIS_I2C_MASTER_W_ADDR
opsis_eeprom_i2c_init();
#ifdef ETHMAC_BASE
opsis_eeprom_mac(mac_addr);
#endif
#endif

config_init();
Expand All @@ -76,36 +73,53 @@ int main(void)
#endif

#ifdef ETHMAC_BASE
// Work out the MAC address
for(int i = 0; i < 6; i++) {
mac_addr[i] = config_get(CONFIG_KEY_NETWORK_MAC0+i);
}
#ifdef CSR_OPSIS_I2C_MASTER_W_ADDR
opsis_eeprom_mac(mac_addr);
#endif
// Work out the IP address
for(int i = 0; i < 4; i++) {
ip_addr[i] = config_get(CONFIG_KEY_NETWORK_IP0+i);
}
// Setup the Ethernet
ethernet_init(mac_addr, ip_addr);
etherbone_init();
telnet_init();
#endif

// FIXME: Explain why secondary res is in _init and primary in _start
processor_init(config_get(CONFIG_KEY_RES_SECONDARY));

#ifdef CSR_HDMI_OUT0_I2C_W_ADDR
hdmi_out0_i2c_init();
#endif
#ifdef CSR_HDMI_OUT0_BASE
processor_set_hdmi_out0_source(VIDEO_IN_PATTERN);
hdmi_out0_core_initiator_enable_write(config_get(CONFIG_KEY_OUTPUT0_ENABLED));
processor_set_hdmi_out0_source(config_get(CONFIG_KEY_OUTPUT0_SOURCE));
#endif

#ifdef CSR_HDMI_OUT1_I2C_W_ADDR
hdmi_out1_i2c_init();
#endif
#ifdef CSR_HDMI_OUT1_BASE
processor_set_hdmi_out1_source(VIDEO_IN_PATTERN);
hdmi_out0_core_initiator_enable_write(config_get(CONFIG_KEY_OUTPUT1_ENABLED));
processor_set_hdmi_out1_source(config_get(CONFIG_KEY_OUTPUT1_SOURCE));
#endif
processor_update();
processor_start(config_get(CONFIG_KEY_RES_PRIMARY));

// Reboot the FX2 chip into HDMI2USB mode
#ifdef CSR_OPSIS_I2C_FX2_RESET_OUT_ADDR
fx2_init();
if (config_get(CONFIG_KEY_FX2_RESET)) {
fx2_init();
}
#endif
#ifdef ENCODER_BASE
processor_set_encoder_source(VIDEO_IN_PATTERN);
encoder_enable(1);
processor_set_encoder_source(config_get(CONFIG_KEY_ENCODER_SOURCE));
encoder_enable(config_get(CONFIG_KEY_ENCODER_ENABLED));
#endif

ci_prompt();
Expand Down

0 comments on commit f85a83e

Please sign in to comment.