diff options
-rw-r--r-- | Makefile | 16 | ||||
-rw-r--r-- | edid_injector.c | 104 | ||||
-rw-r--r-- | eeprom_driver.h | 4 |
3 files changed, 67 insertions, 57 deletions
@@ -2,7 +2,7 @@ ## HWREV: ## 0 -> initial revision MMCU = atxmega16a4 -DEFINES = -DF_CPU=32000000 -DHWREV=0 +DEFINES = -DF_CPU=2000000 -DHWREV=0 # -b baudrate AVRDUDE = avrdude -P usb -c jtag3pdi -p $(MMCU) @@ -21,7 +21,7 @@ VPATH = . CC = avr-gcc CFLAGS = -W -Wall -Os -std=gnu99 -Werror-implicit-function-declaration -all: firmware.bin firmware.hex firmware-eeprom.bin +all: firmware.bin firmware.hex run: all prg @@ -66,20 +66,13 @@ program_fuses: prg: firmware.hex $(AVRDUDE) -Uflash:w:firmware.hex:i -program_bootloader: - $(AVRDUDE) -e -Uflash:w:bootload.hex:i - dump: firmware.elf avr-objdump -D firmware.elf clean: - -rm -f firmware.bin firmware.elf firmware-eeprom.bin firmware.hex + -rm -f firmware.bin firmware.elf firmware.hex -rm -f *.o -firmware-eeprom.bin: firmware.elf - avr-objcopy -j .eeprom -O binary firmware.elf firmware-eeprom.bin - @ls -l firmware-eeprom.bin - firmware.hex: firmware.elf avr-objcopy -j .text -j .data -O ihex firmware.elf firmware.hex @@ -87,6 +80,3 @@ firmware.bin: firmware.elf avr-objcopy -j .text -j .data -O binary firmware.elf firmware.bin @ls -l firmware.bin -asm: - $(CC) -W -Wall -O2 -mmcu=$(MMCU) -S main.c -o main.asm - diff --git a/edid_injector.c b/edid_injector.c index 5a539e4..b938d85 100644 --- a/edid_injector.c +++ b/edid_injector.c @@ -32,21 +32,38 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#include "avr_compiler.h"
+
+#include <string.h>
+
+#include "eeprom_driver.h"
+
#include "twi_master_driver.h"
#include "twi_slave_driver.h"
-#include "eeprom_driver.h"
-/*! AUDRATE 100kHz and Baudrate Register Settings */
+/*! BAUDRATE 100kHz and Baudrate Register Settings */
#define BAUDRATE 100000
#define TWI_BAUDSETTING TWI_BAUD(F_CPU, BAUDRATE)
+#define EDID_SLAVE_ADDRESS 0xA0
+
/* TWIC is on the display side */
TWI_t * const twiDisplay = &TWIC;
TWI_Master_t twimDisplay; /*!< TWI master module. Used for talking with display */
+/*! TWIC Master Interrupt vector. */
+ISR(TWIC_TWIM_vect)
+{
+ TWI_MasterInterruptHandler(&twimDisplay);
+}
+
/* TWIE is on the host side */
TWI_t * const twiHost = &TWIE;
-TWI_Slave_t twimHost; /*!< TWI slave module. Used for talking with host */
+TWI_Slave_t twisHost; /*!< TWI slave module. Used for talking with host */
+/*! TWIC Slave Interrupt vector. */
+ISR(TWIE_TWIS_vect)
+{
+ TWI_SlaveInterruptHandler(&twisHost);
+}
void TWIC_SlaveProcessData(void)
@@ -55,17 +72,56 @@ void TWIC_SlaveProcessData(void) void edid_initHostTWI(void)
{
+ /* Initialize TWI slave. */
+ TWI_SlaveInitializeDriver(&twisHost, twiHost, TWIC_SlaveProcessData);
+ TWI_SlaveInitializeModule(&twisHost,
+ EDID_SLAVE_ADDRESS,
+ TWI_SLAVE_INTLVL_MED_gc );
}
void edid_initDisplayTWI(void)
{
+ /* Initialize TWI master. */
+ TWI_MasterInit(&twimDisplay,
+ twiDisplay,
+ TWI_MASTER_INTLVL_LO_gc,
+ TWI_BAUDSETTING);
+
+ /* Enable internal pull-up on PC0, PC1. */
+ /* If you don't have external pullups enable this */
+#if 0
+ /* Configure several PINxCTRL registers at the same time */
+ PORTCFG.MPCMASK = 0x03;
+
+ /* Enable pull-up to get a defined level on the switches */
+ PORTC.PIN0CTRL = (PORTC.PIN0CTRL & ~PORT_OPC_gm) | PORT_OPC_PULLUP_gc;
+#endif
+
+}
+
+uint8_t edid_genChecksum(uint8_t *ediddata)
+{
+ uint8_t bytessum = 0;
+ for(size_t i = 0; i < 127; i++) {
+ bytessum += ediddata[i];
+ }
+
+ return 0xff - bytessum;
}
void edid_readFromDisplayToEEPROM(void)
{
- uint8_t buffer[128];
- memset(buffer, 0, sizeof(buffer);
+ uint8_t displayedid[128];
+ memset(displayedid, 0, sizeof(displayedid));
+
+ /* read 128 EDID bytes from display */
+
+ /* set EDID Extension Block count / flags to zero */
+
+ /* recalculate checksum */
+ displayedid[127] = edid_genChecksum(displayedid);
+ /* write EDID information to EEPROM */
}
int main(void)
@@ -74,34 +130,7 @@ int main(void) edid_initDisplayTWI();
- /* Initialize PORTE for output and PORTD for inverted input. */
- PORTE.DIRSET = 0xFF;
- PORTD.DIRCLR = 0xFF;
- PORTCFG.MPCMASK = 0xFF;
- PORTD.PIN0CTRL |= PORT_INVEN_bm;
-// PORTCFG.MPCMASK = 0xFF;
-// PORTD.PIN0CTRL = (PORTD.PIN0CTRL & ~PORT_OPC_gm) | PORT_OPC_PULLUP_gc;
-
- // Enable internal pull-up on PC0, PC1.. Uncomment if you don't have external pullups
-// PORTCFG.MPCMASK = 0x03; // Configure several PINxCTRL registers at the same time
-// PORTC.PIN0CTRL = (PORTC.PIN0CTRL & ~PORT_OPC_gm) | PORT_OPC_PULLUP_gc; //Enable pull-up to get a defined level on the switches
-
-
-
- /* Initialize TWI master. */
- TWI_MasterInit(&twiMaster,
- &TWIC,
- TWI_MASTER_INTLVL_LO_gc,
- TWI_BAUDSETTING);
- /* Initialize TWI slave. */
- TWI_SlaveInitializeDriver(&twiSlave, &TWIC, TWIC_SlaveProcessData);
- TWI_SlaveInitializeModule(&twiSlave,
- SLAVE_ADDRESS,
- TWI_SLAVE_INTLVL_LO_gc);
-
- /* Enable LO interrupt level. */
- PMIC.CTRL |= PMIC_LOLVLEN_bm;
sei();
@@ -119,14 +148,3 @@ int main(void) #endif
}
-/*! TWIC Master Interrupt vector. */
-ISR(TWIC_TWIM_vect)
-{
- TWI_MasterInterruptHandler(&twiMaster);
-}
-
-/*! TWIC Slave Interrupt vector. */
-ISR(TWIC_TWIS_vect)
-{
- TWI_SlaveInterruptHandler(&twiSlave);
-}
diff --git a/eeprom_driver.h b/eeprom_driver.h index 90cc8e3..bcd8814 100644 --- a/eeprom_driver.h +++ b/eeprom_driver.h @@ -61,13 +61,15 @@ #include "avr_compiler.h"
+#ifndef MAPPED_EEPROM_START
#define MAPPED_EEPROM_START 0x1000
+#endif
+
#define EEPROM_PAGESIZE 32
#define EEPROM(_pageAddr, _byteAddr) \
((uint8_t *) MAPPED_EEPROM_START)[_pageAddr*EEPROM_PAGESIZE + _byteAddr]
-
/* Definitions of macros. */
/*! \brief Enable EEPROM block sleep-when-not-used mode.
|