summaryrefslogtreecommitdiff
path: root/edid_injector.c
diff options
context:
space:
mode:
authorWolfgang Draxinger <Wolfgang.Draxinger@draxit.de>2013-12-22 19:07:27 +0100
committerWolfgang Draxinger <Wolfgang.Draxinger@draxit.de>2013-12-22 19:07:27 +0100
commite9b41c8d6bf9f28a2146652d5ed3b1cd0bc478c7 (patch)
tree717b6344d9c527aaf19759a69d56cc873c712c60 /edid_injector.c
parent217ddb1e32dcb4cde11ecca88418be428895f2dc (diff)
downloadvgaedidinjector-e9b41c8d6bf9f28a2146652d5ed3b1cd0bc478c7.tar.gz
vgaedidinjector-e9b41c8d6bf9f28a2146652d5ed3b1cd0bc478c7.tar.bz2
build system works
Diffstat (limited to 'edid_injector.c')
-rw-r--r--edid_injector.c104
1 files changed, 61 insertions, 43 deletions
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);
-}