Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
firmware/lm32: refactor i2c (simplify and avoid duplication)
  • Loading branch information
enjoy-digital committed Jan 23, 2016
1 parent b7cefbd commit 2f9f8c3
Show file tree
Hide file tree
Showing 13 changed files with 214 additions and 242 deletions.
69 changes: 0 additions & 69 deletions firmware/lm32/Makefile
Expand Up @@ -8,9 +8,7 @@ OBJECTS=isr.o \
processor.o \
hdmi_in0.o \
hdmi_in1.o \
hdmi_out0_i2c.o \
hdmi_out0.o \
hdmi_out1_i2c.o \
hdmi_out1.o \
pattern.o \
edid.o \
Expand All @@ -21,9 +19,7 @@ OBJECTS=isr.o \
fx2.o \
i2c.o \
main.o \
opsis_eeprom_i2c.o \
opsis_eeprom.o \
tofe_eeprom_i2c.o \
tofe_eeprom.o \

all: firmware.bin
Expand Down Expand Up @@ -58,71 +54,6 @@ main.o: main.c
%.o: %.S
$(assemble)

define gen_i2c
@echo " GEN " $@
@sed -e "s/XI2C/I2C/g;s/Xi2c/i2c/g" $< > $@
endef

i2c.c: Xi2c.c
$(gen_i2c)

i2c.h: Xi2c.h
$(gen_i2c)

i2c.o: i2c.h

define gen_opsis_eeprom_i2c
@echo " GEN " $@
@sed -e "s/XI2C/OPSIS_EEPROM_I2C/g;s/Xi2c/opsis_eeprom_i2c/g" $< > $@
endef

opsis_eeprom_i2c.c: Xi2c.c
$(gen_opsis_eeprom_i2c)

opsis_eeprom_i2c.h: Xi2c.h
$(gen_opsis_eeprom_i2c)

opsis_eeprom_i2c.o: opsis_eeprom_i2c.h

define gen_tofe_eeprom_i2c
@echo " GEN " $@
@sed -e "s/XI2C/TOFE_EEPROM_I2C/g;s/Xi2c/tofe_eeprom_i2c/g" $< > $@
endef

tofe_eeprom_i2c.c: Xi2c.c
$(gen_tofe_eeprom_i2c)

tofe_eeprom_i2c.h: Xi2c.h
$(gen_tofe_eeprom_i2c)

tofe_eeprom_i2c.o: tofe_eeprom_i2c.h

define gen_hdmi_out0_i2c
@echo " GEN " $@
@sed -e "s/XI2C/HDMI_OUT0_I2C/g;s/Xi2c/hdmi_out0_i2c/g" $< > $@
endef

hdmi_out0_i2c.c: Xi2c.c
$(gen_hdmi_out0_i2c)

hdmi_out0_i2c.h: Xi2c.h
$(gen_hdmi_out0_i2c)

hdmi_out0_i2c.o: hdmi_out0_i2c.h

define gen_hdmi_out1_i2c
@echo " GEN " $@
@sed -e "s/XI2C/HDMI_OUT1_I2C/g;s/Xi2c/hdmi_out1_i2c/g" $< > $@
endef

hdmi_out1_i2c.c: Xi2c.c
$(gen_hdmi_out1_i2c)

hdmi_out1_i2c.h: Xi2c.h
$(gen_hdmi_out1_i2c)

hdmi_out1_i2c.o: hdmi_out1_i2c.h

libs:
$(MAKE) -C $(MSCDIR)/software/libcompiler-rt
$(MAKE) -C $(MSCDIR)/software/libbase
Expand Down
113 changes: 0 additions & 113 deletions firmware/lm32/Xi2c.c

This file was deleted.

19 changes: 0 additions & 19 deletions firmware/lm32/Xi2c.h

This file was deleted.

31 changes: 20 additions & 11 deletions firmware/lm32/hdmi_out0.c
@@ -1,28 +1,37 @@
#include <generated/csr.h>
#ifdef CSR_HDMI_OUT0_BASE
#ifdef CSR_HDMI_OUT0_I2C_W_ADDR
#include <stdio.h>
#include "i2c.h"
#include "hdmi_out0.h"

I2C hdmi_out0_i2c;
int hdmi_out0_debug_enabled = 0;

void hdmi_out0_i2c_init(void) {
hdmi_out0_i2c.w_read = hdmi_out0_i2c_w_read;
hdmi_out0_i2c.w_write = hdmi_out0_i2c_w_write;
hdmi_out0_i2c.r_read = hdmi_out0_i2c_r_read;
i2c_init(&hdmi_out0_i2c);
}

void hdmi_out0_print_edid(void) {
int eeprom_addr, e, extension_number = 0;
unsigned char b;
unsigned char sum = 0;

hdmi_out0_i2c_start_cond();
b = hdmi_out0_i2c_write(0xa0);
i2c_start_cond(&hdmi_out0_i2c);
b = i2c_write(&hdmi_out0_i2c, 0xa0);
if (!b && hdmi_out0_debug_enabled)
printf("hdmi_out0: NACK while writing slave address!\n");
b = hdmi_out0_i2c_write(0x00);
b = i2c_write(&hdmi_out0_i2c, 0x00);
if (!b && hdmi_out0_debug_enabled)
printf("hdmi_out0: NACK while writing eeprom address!\n");
hdmi_out0_i2c_start_cond();
b = hdmi_out0_i2c_write(0xa1);
i2c_start_cond(&hdmi_out0_i2c);
b = i2c_write(&hdmi_out0_i2c, 0xa1);
if (!b && hdmi_out0_debug_enabled)
printf("hdmi_out0: NACK while writing slave address (2)!\n");
for (eeprom_addr = 0 ; eeprom_addr < 128 ; eeprom_addr++) {
b = hdmi_out0_i2c_read(eeprom_addr == 127 && extension_number == 0 ? 0 : 1);
b = i2c_read(&hdmi_out0_i2c, eeprom_addr == 127 && extension_number == 0 ? 0 : 1);
sum +=b;
printf("%02X ", b);
if(!((eeprom_addr+1) % 16))
Expand All @@ -32,7 +41,7 @@ void hdmi_out0_print_edid(void) {
if(eeprom_addr == 127 && sum != 0)
{
printf("Checksum ERROR in EDID block 0\n");
hdmi_out0_i2c_stop_cond();
i2c_stop_cond(&hdmi_out0_i2c);
return;
}
}
Expand All @@ -41,20 +50,20 @@ void hdmi_out0_print_edid(void) {
printf("\n");
sum = 0;
for (eeprom_addr = 0 ; eeprom_addr < 128 ; eeprom_addr++) {
b = hdmi_out0_i2c_read(eeprom_addr == 127 && e == extension_number - 1 ? 0 : 1);
b = i2c_read(&hdmi_out0_i2c, eeprom_addr == 127 && e == extension_number - 1 ? 0 : 1);
sum += b;
printf("%02X ", b);
if(!((eeprom_addr+1) % 16))
printf("\n");
if(eeprom_addr == 127 && sum != 0)
{
printf("Checksum ERROR in EDID extension block %d\n", e);
hdmi_out0_i2c_stop_cond();
i2c_stop_cond(&hdmi_out0_i2c);
return;
}
}
}
hdmi_out0_i2c_stop_cond();
i2c_stop_cond(&hdmi_out0_i2c);
}

#endif
2 changes: 1 addition & 1 deletion firmware/lm32/hdmi_out0.h
@@ -1,7 +1,7 @@
#include <generated/csr.h>
#ifdef CSR_HDMI_OUT0_I2C_W_ADDR
#include "hdmi_out0_i2c.h"

void hdmi_out0_i2c_init(void);
void hdmi_out0_print_edid(void);

#endif
31 changes: 20 additions & 11 deletions firmware/lm32/hdmi_out1.c
@@ -1,28 +1,37 @@
#include <generated/csr.h>
#ifdef CSR_HDMI_OUT1_BASE
#ifdef CSR_HDMI_OUT1_I2C_W_ADDR
#include <stdio.h>
#include "i2c.h"
#include "hdmi_out1.h"

I2C hdmi_out1_i2c;
int hdmi_out1_debug_enabled = 0;

void hdmi_out1_i2c_init(void) {
hdmi_out1_i2c.w_read = hdmi_out1_i2c_w_read;
hdmi_out1_i2c.w_write = hdmi_out1_i2c_w_write;
hdmi_out1_i2c.r_read = hdmi_out1_i2c_r_read;
i2c_init(&hdmi_out1_i2c);
}

void hdmi_out1_print_edid(void) {
int eeprom_addr, e, extension_number = 0;
unsigned char b;
unsigned char sum = 0;

hdmi_out1_i2c_start_cond();
b = hdmi_out1_i2c_write(0xa0);
i2c_start_cond(&hdmi_out1_i2c);
b = i2c_write(&hdmi_out1_i2c, 0xa0);
if (!b && hdmi_out1_debug_enabled)
printf("hdmi_out1: NACK while writing slave address!\n");
b = hdmi_out1_i2c_write(0x00);
b = i2c_write(&hdmi_out1_i2c, 0x00);
if (!b && hdmi_out1_debug_enabled)
printf("hdmi_out1: NACK while writing eeprom address!\n");
hdmi_out1_i2c_start_cond();
b = hdmi_out1_i2c_write(0xa1);
i2c_start_cond(&hdmi_out1_i2c);
b = i2c_write(&hdmi_out1_i2c, 0xa1);
if (!b && hdmi_out1_debug_enabled)
printf("hdmi_out1: NACK while writing slave address (2)!\n");
for (eeprom_addr = 0 ; eeprom_addr < 128 ; eeprom_addr++) {
b = hdmi_out1_i2c_read(eeprom_addr == 127 && extension_number == 0 ? 0 : 1);
b = i2c_read(&hdmi_out1_i2c, eeprom_addr == 127 && extension_number == 0 ? 0 : 1);
sum +=b;
printf("%02X ", b);
if(!((eeprom_addr+1) % 16))
Expand All @@ -32,7 +41,7 @@ void hdmi_out1_print_edid(void) {
if(eeprom_addr == 127 && sum != 0)
{
printf("Checksum ERROR in EDID block 0\n");
hdmi_out1_i2c_stop_cond();
i2c_stop_cond(&hdmi_out1_i2c);
return;
}
}
Expand All @@ -41,20 +50,20 @@ void hdmi_out1_print_edid(void) {
printf("\n");
sum = 0;
for (eeprom_addr = 0 ; eeprom_addr < 128 ; eeprom_addr++) {
b = hdmi_out1_i2c_read(eeprom_addr == 127 && e == extension_number - 1 ? 0 : 1);
b = i2c_read(&hdmi_out1_i2c, eeprom_addr == 127 && e == extension_number - 1 ? 0 : 1);
sum += b;
printf("%02X ", b);
if(!((eeprom_addr+1) % 16))
printf("\n");
if(eeprom_addr == 127 && sum != 0)
{
printf("Checksum ERROR in EDID extension block %d\n", e);
hdmi_out1_i2c_stop_cond();
i2c_stop_cond(&hdmi_out1_i2c);
return;
}
}
}
hdmi_out1_i2c_stop_cond();
i2c_stop_cond(&hdmi_out1_i2c);
}

#endif

0 comments on commit 2f9f8c3

Please sign in to comment.