-
Notifications
You must be signed in to change notification settings - Fork 0
/
ypbpr2rgb.ino
82 lines (62 loc) · 1.94 KB
/
ypbpr2rgb.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// YPbPr2RGB i2c switcher for Panasonic TC-21FX30LA (Micronas VCT-49xyI)
// Ver. 0.1 - July 20204
#include <ESP8266WiFi.h>
#include <esp_i2c.h>
#define SCL_LOW_PULL_MS 300 // Pull down SCL for X ms
#define SCL_HIGH_WAIT_MS 200 // Wait until SCL stays high for at least X ms
#define I2C_CLOCK 50000L // I2C clock 50 KHz
const uint8_t VSP_ADDR = 0x58;
const uint8_t SDA_PIN = D2;
const uint8_t SCL_PIN = D1;
volatile unsigned long sclHighTimer = 0;
volatile bool sclHigh = false;
void ICACHE_RAM_ATTR handleSCLChange() {
if (digitalRead(SCL_PIN) == HIGH) {
sclHighTimer = millis(); // Start the timer when SCL goes high
sclHigh = true;
} else {
sclHigh = false;
}
}
void setup() {
// Pin Setup
pinMode(SDA_PIN, INPUT_PULLUP);
pinMode(SCL_PIN, INPUT_PULLUP);
// Disable WiFi
WiFi.mode(WIFI_OFF);
esp_i2c_init(SDA_PIN, SCL_PIN);
esp_i2c_set_clock(I2C_CLOCK);
// Interrupt to detect SCL state change
attachInterrupt(digitalPinToInterrupt(SCL_PIN), handleSCLChange, CHANGE);
// Pull the SCL pin low for 300ms
pinMode(SCL_PIN, OUTPUT);
digitalWrite(SCL_PIN, LOW);
delay(SCL_LOW_PULL_MS);
pinMode(SCL_PIN, INPUT_PULLUP);
// Initialize timer
sclHighTimer = millis();
// Wait until SCL stays high for at least SCL_HIGH_WAIT_MS
while (true) {
if (sclHigh && (millis() - sclHighTimer) > SCL_HIGH_WAIT_MS) {
uint8_t dataToSend[3];
// YUVSEL -> RGB: 0x4b 0x81 0x08
dataToSend[0] = 0x4b;
dataToSend[1] = 0x81;
dataToSend[2] = 0x08;
esp_i2c_write_buf(VSP_ADDR, dataToSend, 3, 1);
// ADC_SEL -> 6: 0x49 0xd7 0x5c
dataToSend[0] = 0x49;
dataToSend[1] = 0xd7;
dataToSend[2] = 0x5c;
esp_i2c_write_buf(VSP_ADDR, dataToSend, 3, 1);
// VINSEL6 -> 7: 0x3f 0x4a 0x07
dataToSend[0] = 0x3f;
dataToSend[1] = 0x4a;
dataToSend[2] = 0x07;
esp_i2c_write_buf(VSP_ADDR, dataToSend, 3, 1);
break;
}
}
}
void loop() {
}