Add reading of dip switches

Renamed the variable c that was used for saving the i2c offset that a
computer wants to read. Additionally, a 4bit dip-switch can be read in
using the Pins A0-A3.
This commit is contained in:
Nick Hahn 2020-12-29 14:19:38 +01:00
parent dedb6857a3
commit 73518e6be4

View file

@ -4,14 +4,14 @@
#include <Wire.h> //Patch wire.h: BUFFER_LENGTH = 256 TWI_BUFFER_LENGTH 256
// ToDo: Eigene Wire.h einbinden mit vorgepatchen Werten
/*uint8_t edid[256] = {
/*const uint8_t edid[256] = {
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x4C, 0x2D, 0xF4, 0x0C, 0x45, 0x52, 0x46, 0x31, 0x15, 0x19, 0x01, 0x03, 0x80, 0x3C, 0x22, 0x78, 0x2A, 0x52, 0x95, 0xA5, 0x56, 0x54, 0x9D, 0x25, 0x0E, 0x50, 0x54, 0xBF, 0xEF, 0x80, 0x71, 0x4F, 0x81, 0xC0, 0x81, 0x00, 0x81, 0x80, 0x95, 0x00, 0xA9, 0xC0, 0xB3, 0x00, 0x01, 0x01, 0x02, 0x3A, 0x80, 0x18, 0x71, 0x38, 0x2D, 0x40, 0x58, 0x2C, 0x45, 0x00, 0x56, 0x50, 0x21, 0x00, 0x00, 0x1E, 0x01, 0x1D, 0x00, 0x72, 0x51, 0xD0, 0x1E, 0x20, 0x6E, 0x28, 0x55, 0x00, 0x56, 0x50, 0x21, 0x00, 0x00, 0x1E, 0x00, 0x00, 0x00, 0xFD, 0x00, 0x32, 0x4B, 0x1E, 0x51, 0x11, 0x00, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x00, 0x00, 0x00, 0xFC, 0x00, 0x53, 0x32, 0x37, 0x45, 0x33, 0x37, 0x30, 0x0A, 0x20, 0x20, 0x20, 0x20, 0x20, 0x01, 0x62, 0x02, 0x03, 0x1B, 0xF1, 0x46, 0x90, 0x04, 0x1F, 0x13, 0x03, 0x12, 0x67, 0x03, 0x0C, 0x00, 0x10, 0x00, 0x80, 0x22, 0x23, 0x09, 0x07, 0x07, 0x83, 0x01, 0x00, 0x00, 0x01, 0x1D, 0x00, 0xBC, 0x52, 0xD0, 0x1E, 0x20, 0xB8, 0x28, 0x55, 0x40, 0x56, 0x50, 0x21, 0x00, 0x00, 0x1E, 0x8C, 0x0A, 0xD0, 0x90, 0x20, 0x40, 0x31, 0x20, 0x0C, 0x40, 0x55, 0x00, 0x56, 0x50, 0x21, 0x00, 0x00, 0x18, 0x8C, 0x0A, 0xD0, 0x8A, 0x20, 0xE0, 0x2D, 0x10, 0x10, 0x3E, 0x96, 0x00, 0x56, 0x50, 0x21, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3D
};*/
#define EDID_LENGTH 128
// 800x600
uint8_t edid[EDID_LENGTH] = {
const uint8_t edid[EDID_LENGTH] = {
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x1E, 0x6D, 0x7D, 0x58, 0xC1, 0x90, 0x02, 0x00,
0x08, 0x16, 0x01, 0x03, 0x80, 0x33, 0x1D, 0x78, 0xEA, 0x5E, 0xA5, 0xA2, 0x55, 0x4D, 0xA0, 0x26,
0x11, 0x50, 0x54, 0x27, 0x4B, 0x00, 0xB3, 0x00, 0x81, 0x80, 0x81, 0x40, 0x71, 0x4F, 0x01, 0x01,
@ -22,7 +22,7 @@ uint8_t edid[EDID_LENGTH] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xB7};
// IPS235 1920x1080
/*uint8_t edid[128] = {
/*const uint8_t edid[128] = {
0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x1E, 0x6D, 0x7E, 0x58, 0xC1, 0x90, 0x02, 0x00,
0x08, 0x16, 0x01, 0x03, 0x80, 0x33, 0x1D, 0x78, 0xEA, 0x5E, 0xA5, 0xA2, 0x55, 0x4D, 0xA0, 0x26,
0x11, 0x50, 0x54, 0x21, 0x08, 0x00, 0xB3, 0x00, 0x81, 0x80, 0x81, 0x40, 0x71, 0x40, 0x01, 0x01,
@ -33,14 +33,28 @@ uint8_t edid[EDID_LENGTH] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xA8
};*/
unsigned int c;
unsigned int edid_offset;
uint8_t edid_select;
//SoftWire sw(A2, A3);
void read_dip_switches()
{
if (digitalRead(A0) == 1)
edid_select |= 0b10000000;
if (digitalRead(A1) == 1)
edid_select |= 0b01000000;
if (digitalRead(A2) == 1)
edid_select |= 0b00100000;
if (digitalRead(A3) == 1)
edid_select |= 0b00010000;
}
void receiveEvent(int receivedByte)
{
while (0 < Wire.available())
{
c = Wire.read(); /* receive start position */
edid_offset = Wire.read(); /* receive start position */
//Serial.print(c, HEX); /* print the requested position */
}
//Serial.println(); /* to newline */
@ -50,7 +64,7 @@ void receiveEvent(int receivedByte)
void requestEvent()
{
// Send virtual EEPROM in full length from start position
Wire.write(edid + c, EDID_LENGTH - c);
Wire.write(edid + edid_offset, EDID_LENGTH - edid_offset);
}
void setup()
@ -58,6 +72,14 @@ void setup()
Serial.begin(9600);
Serial.println("**** HDMI ****");
pinMode(4, OUTPUT); //Hot plug detection
// Input for DIP switches for selecting from edids
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(A2, INPUT);
pinMode(A3, INPUT);
read_dip_switches();
Wire.begin(0x50); // EDID Register
digitalWrite(4, LOW);
delay(20);