diff --git a/firmware/config.c b/firmware/config.c index 52abc6db..d9d38f75 100644 --- a/firmware/config.c +++ b/firmware/config.c @@ -1,10 +1,57 @@ +#include +#include +#include #include #include -#include + +#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) diff --git a/firmware/config.h b/firmware/config.h index feb930f8..c1ce7d7a 100644 --- a/firmware/config.h +++ b/firmware/config.h @@ -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); diff --git a/firmware/hdmi_out0.c b/firmware/hdmi_out0.c index 49bf6497..662f0d5a 100644 --- a/firmware/hdmi_out0.c +++ b/firmware/hdmi_out0.c @@ -1,9 +1,11 @@ #include -#ifdef CSR_HDMI_OUT0_I2C_W_ADDR #include -#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; diff --git a/firmware/hdmi_out0.h b/firmware/hdmi_out0.h index 1d7582d2..3ae430ea 100644 --- a/firmware/hdmi_out0.h +++ b/firmware/hdmi_out0.h @@ -1,7 +1,6 @@ #include -#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 \ No newline at end of file +#endif diff --git a/firmware/hdmi_out1.c b/firmware/hdmi_out1.c index 8902a063..9015dc11 100644 --- a/firmware/hdmi_out1.c +++ b/firmware/hdmi_out1.c @@ -1,9 +1,11 @@ #include -#ifdef CSR_HDMI_OUT1_I2C_W_ADDR #include -#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; diff --git a/firmware/hdmi_out1.h b/firmware/hdmi_out1.h index 131decf4..40ffa633 100644 --- a/firmware/hdmi_out1.h +++ b/firmware/hdmi_out1.h @@ -1,7 +1,6 @@ #include -#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 \ No newline at end of file +#endif diff --git a/firmware/main.c b/firmware/main.c index 43e97565..4ba90210 100644 --- a/firmware/main.c +++ b/firmware/main.c @@ -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) @@ -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(); @@ -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();