mirror of
https://github.com/dingusdev/dingusppc.git
synced 2025-01-11 20:29:46 +00:00
displayid.cpp: fix indentation.
This commit is contained in:
parent
54a86972cd
commit
3461f2e353
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||||
Copyright (C) 2018-20 divingkatae and maximum
|
Copyright (C) 2018-20 divingkatae and maximum
|
||||||
(theweirdo) spatium
|
(theweirdo) spatium
|
||||||
|
|
||||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||||
|
|
||||||
@ -24,203 +24,203 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
DisplayID::DisplayID()
|
DisplayID::DisplayID()
|
||||||
{
|
{
|
||||||
/* Initialize Apple monitor codes */
|
/* Initialize Apple monitor codes */
|
||||||
this->std_sense_code = 6;
|
this->std_sense_code = 6;
|
||||||
this->ext_sense_code = 0x2B;
|
this->ext_sense_code = 0x2B;
|
||||||
|
|
||||||
/* Initialize DDC I2C bus */
|
/* Initialize DDC I2C bus */
|
||||||
this->next_state = I2CState::STOP;
|
this->next_state = I2CState::STOP;
|
||||||
this->prev_state = I2CState::STOP;
|
this->prev_state = I2CState::STOP;
|
||||||
this->last_sda = 1;
|
this->last_sda = 1;
|
||||||
this->last_scl = 1;
|
this->last_scl = 1;
|
||||||
this->data_out = 0x3000;
|
this->data_out = 0x3000;
|
||||||
this->data_ptr = 0;
|
this->data_ptr = 0;
|
||||||
|
|
||||||
/* DDC sense mode is on by default */
|
/* DDC sense mode is on by default */
|
||||||
this->i2c_on = true;
|
this->i2c_on = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint16_t DisplayID::set_result(uint8_t sda, uint8_t scl)
|
uint16_t DisplayID::set_result(uint8_t sda, uint8_t scl)
|
||||||
{
|
{
|
||||||
this->last_sda = sda;
|
this->last_sda = sda;
|
||||||
this->last_scl = scl;
|
this->last_scl = scl;
|
||||||
|
|
||||||
if (scl) {
|
if (scl) {
|
||||||
this->data_out |= 0x1000;
|
this->data_out |= 0x1000;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this->data_out &= ~0x1000U;
|
this->data_out &= ~0x1000U;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sda) {
|
if (sda) {
|
||||||
this->data_out |= 0x2000;
|
this->data_out |= 0x2000;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this->data_out &= ~0x2000U;
|
this->data_out &= ~0x2000U;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this->data_out;
|
return this->data_out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint16_t DisplayID::read_monitor_sense(uint16_t data, uint16_t dirs)
|
uint16_t DisplayID::read_monitor_sense(uint16_t data, uint16_t dirs)
|
||||||
{
|
{
|
||||||
uint8_t scl, sda;
|
uint8_t scl, sda;
|
||||||
uint16_t result;
|
uint16_t result;
|
||||||
|
|
||||||
if ((dirs & 0x3100) == 0 && (data & 0x3100) == 0x3100) {
|
if ((dirs & 0x3100) == 0 && (data & 0x3100) == 0x3100) {
|
||||||
LOG_F(WARNING, "DisplayID: Hackish Monitor ID Switch activated!");
|
LOG_F(WARNING, "DisplayID: Hackish Monitor ID Switch activated!");
|
||||||
this->i2c_on = false;
|
this->i2c_on = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this->i2c_on) {
|
if (this->i2c_on) {
|
||||||
/* if GPIO pins are in the output mode, pick up their values
|
/* if GPIO pins are in the output mode, pick up their values
|
||||||
In the input mode, GPIO pins will be read "high" */
|
In the input mode, GPIO pins will be read "high" */
|
||||||
scl = (dirs & 0x1000) ? !!(data & 0x1000) : 1;
|
scl = (dirs & 0x1000) ? !!(data & 0x1000) : 1;
|
||||||
sda = (dirs & 0x2000) ? !!(data & 0x2000) : 1;
|
sda = (dirs & 0x2000) ? !!(data & 0x2000) : 1;
|
||||||
|
|
||||||
return update_ddc_i2c(sda, scl);
|
return update_ddc_i2c(sda, scl);
|
||||||
}
|
}
|
||||||
else { /* Apple legacy monitor codes (see Technical Note HW30) */
|
else { /* Apple legacy monitor codes (see Technical Note HW30) */
|
||||||
switch (dirs & 0x3100) {
|
switch (dirs & 0x3100) {
|
||||||
case 0:
|
case 0:
|
||||||
result = ((this->std_sense_code & 6) << 11) |
|
result = ((this->std_sense_code & 6) << 11) |
|
||||||
((this->std_sense_code & 1) << 8);
|
((this->std_sense_code & 1) << 8);
|
||||||
break;
|
break;
|
||||||
case 0x2000: /* Sense line 2 is low */
|
case 0x2000: /* Sense line 2 is low */
|
||||||
result = ((this->ext_sense_code & 0x20) << 7) |
|
result = ((this->ext_sense_code & 0x20) << 7) |
|
||||||
((this->ext_sense_code & 0x10) << 4);
|
((this->ext_sense_code & 0x10) << 4);
|
||||||
break;
|
break;
|
||||||
case 0x1000: /* Sense line 1 is low */
|
case 0x1000: /* Sense line 1 is low */
|
||||||
result = ((this->ext_sense_code & 8) << 10) |
|
result = ((this->ext_sense_code & 8) << 10) |
|
||||||
((this->ext_sense_code & 4) << 6);
|
((this->ext_sense_code & 4) << 6);
|
||||||
break;
|
break;
|
||||||
case 0x100: /* Sense line 0 is low */
|
case 0x100: /* Sense line 0 is low */
|
||||||
result = ((this->ext_sense_code & 2) << 12) |
|
result = ((this->ext_sense_code & 2) << 12) |
|
||||||
((this->ext_sense_code & 1) << 12);
|
((this->ext_sense_code & 1) << 12);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
result = 0x3100U;
|
result = 0x3100U;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint16_t DisplayID::update_ddc_i2c(uint8_t sda, uint8_t scl)//(uint16_t data, uint16_t dirs)
|
uint16_t DisplayID::update_ddc_i2c(uint8_t sda, uint8_t scl)//(uint16_t data, uint16_t dirs)
|
||||||
{
|
{
|
||||||
bool clk_gone_high = false;
|
bool clk_gone_high = false;
|
||||||
|
|
||||||
if (scl != this->last_scl) {
|
if (scl != this->last_scl) {
|
||||||
this->last_scl = scl;
|
this->last_scl = scl;
|
||||||
if (scl) {
|
if (scl) {
|
||||||
clk_gone_high = true;
|
clk_gone_high = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sda != this->last_sda) {
|
if (sda != this->last_sda) {
|
||||||
/* START = SDA goes high to low while SCL is high */
|
/* START = SDA goes high to low while SCL is high */
|
||||||
/* STOP = SDA goes low to high while SCL is high */
|
/* STOP = SDA goes low to high while SCL is high */
|
||||||
if (this->last_scl) {
|
if (this->last_scl) {
|
||||||
if (!sda) {
|
if (!sda) {
|
||||||
LOG_F(9, "DDC-I2C: START condition detected!");
|
LOG_F(9, "DDC-I2C: START condition detected!");
|
||||||
this->next_state = I2CState::DEV_ADDR;
|
this->next_state = I2CState::DEV_ADDR;
|
||||||
this->bit_count = 0;
|
this->bit_count = 0;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOG_F(9, "DDC-I2C: STOP condition detected!");
|
LOG_F(9, "DDC-I2C: STOP condition detected!");
|
||||||
this->next_state = I2CState::STOP;
|
this->next_state = I2CState::STOP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return set_result(sda, scl);
|
return set_result(sda, scl);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!clk_gone_high) {
|
if (!clk_gone_high) {
|
||||||
return set_result(sda, scl);
|
return set_result(sda, scl);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (this->next_state) {
|
switch (this->next_state) {
|
||||||
case I2CState::STOP:
|
case I2CState::STOP:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case I2CState::ACK:
|
case I2CState::ACK:
|
||||||
this->bit_count = 0;
|
this->bit_count = 0;
|
||||||
this->byte = 0;
|
this->byte = 0;
|
||||||
switch (this->prev_state) {
|
switch (this->prev_state) {
|
||||||
case I2CState::DEV_ADDR:
|
case I2CState::DEV_ADDR:
|
||||||
if ((dev_addr & 0xFE) == 0xA0) {
|
if ((dev_addr & 0xFE) == 0xA0) {
|
||||||
sda = 0; /* send ACK */
|
sda = 0; /* send ACK */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOG_F(ERROR, "DDC-I2C: unknown device address 0x%X", this->dev_addr);
|
LOG_F(ERROR, "DDC-I2C: unknown device address 0x%X", this->dev_addr);
|
||||||
sda = 1; /* send NACK */
|
sda = 1; /* send NACK */
|
||||||
}
|
}
|
||||||
if (this->dev_addr & 1) {
|
if (this->dev_addr & 1) {
|
||||||
this->next_state = I2CState::DATA;
|
this->next_state = I2CState::DATA;
|
||||||
this->data_ptr = this->edid;
|
this->data_ptr = this->edid;
|
||||||
this->byte = *(this->data_ptr++);
|
this->byte = *(this->data_ptr++);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this->next_state = I2CState::REG_ADDR;
|
this->next_state = I2CState::REG_ADDR;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case I2CState::REG_ADDR:
|
case I2CState::REG_ADDR:
|
||||||
this->next_state = I2CState::DATA;
|
this->next_state = I2CState::DATA;
|
||||||
if (!this->reg_addr) {
|
if (!this->reg_addr) {
|
||||||
sda = 0; /* send ACK */
|
sda = 0; /* send ACK */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOG_F(ERROR, "DDC-I2C: unknown register address 0x%X", this->reg_addr);
|
LOG_F(ERROR, "DDC-I2C: unknown register address 0x%X", this->reg_addr);
|
||||||
sda = 1; /* send NACK */
|
sda = 1; /* send NACK */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case I2CState::DATA:
|
case I2CState::DATA:
|
||||||
this->next_state = I2CState::DATA;
|
this->next_state = I2CState::DATA;
|
||||||
if (dev_addr & 1) {
|
if (dev_addr & 1) {
|
||||||
if (!sda) {
|
if (!sda) {
|
||||||
/* load next data byte */
|
/* load next data byte */
|
||||||
this->byte = *(this->data_ptr++);
|
this->byte = *(this->data_ptr++);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOG_F(ERROR, "DDC-I2C: Oops! NACK received");
|
LOG_F(ERROR, "DDC-I2C: Oops! NACK received");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sda = 0; /* send ACK */
|
sda = 0; /* send ACK */
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case I2CState::DEV_ADDR:
|
case I2CState::DEV_ADDR:
|
||||||
case I2CState::REG_ADDR:
|
case I2CState::REG_ADDR:
|
||||||
this->byte = (this->byte << 1) | this->last_sda;
|
this->byte = (this->byte << 1) | this->last_sda;
|
||||||
if (this->bit_count++ >= 7) {
|
if (this->bit_count++ >= 7) {
|
||||||
this->bit_count = 0;
|
this->bit_count = 0;
|
||||||
this->prev_state = this->next_state;
|
this->prev_state = this->next_state;
|
||||||
this->next_state = I2CState::ACK;
|
this->next_state = I2CState::ACK;
|
||||||
if (this->prev_state == I2CState::DEV_ADDR) {
|
if (this->prev_state == I2CState::DEV_ADDR) {
|
||||||
LOG_F(9, "DDC-I2C: device address received, addr=0x%X", this->byte);
|
LOG_F(9, "DDC-I2C: device address received, addr=0x%X", this->byte);
|
||||||
this->dev_addr = this->byte;
|
this->dev_addr = this->byte;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LOG_F(9, "DDC-I2C: register address received, addr=0x%X", this->byte);
|
LOG_F(9, "DDC-I2C: register address received, addr=0x%X", this->byte);
|
||||||
this->reg_addr = this->byte;
|
this->reg_addr = this->byte;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case I2CState::DATA:
|
case I2CState::DATA:
|
||||||
sda = (this->byte >> (7 - this->bit_count)) & 1;
|
sda = (this->byte >> (7 - this->bit_count)) & 1;
|
||||||
if (this->bit_count++ >= 7) {
|
if (this->bit_count++ >= 7) {
|
||||||
this->bit_count = 0;
|
this->bit_count = 0;
|
||||||
this->prev_state = this->next_state;
|
this->prev_state = this->next_state;
|
||||||
this->next_state = I2CState::ACK;
|
this->next_state = I2CState::ACK;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return set_result(sda, scl);
|
return set_result(sda, scl);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user