mirror of
https://github.com/dingusdev/dingusppc.git
synced 2024-12-25 03:29:38 +00:00
Initial I2C bus implementation.
This commit is contained in:
parent
75f0e09f5a
commit
753e445b4b
78
devices/i2c.h
Normal file
78
devices/i2c.h
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||
Copyright (C) 2018-20 divingkatae and maximum
|
||||
(theweirdo) spatium
|
||||
|
||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/** @file I2C bus emulation.
|
||||
|
||||
Author: Max Poliakovski
|
||||
*/
|
||||
|
||||
#ifndef I2C_H
|
||||
#define I2C_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
/** Base class for I2C devices */
|
||||
class I2CDevice {
|
||||
public:
|
||||
virtual void start_transaction() = 0;
|
||||
virtual bool send_byte(uint8_t data) = 0;
|
||||
virtual bool receive_byte(uint8_t *p_data) = 0;
|
||||
};
|
||||
|
||||
/** Base class for I2C hosts */
|
||||
class I2CBus {
|
||||
public:
|
||||
I2CBus() { this->dev_list.clear(); };
|
||||
~I2CBus() { this->dev_list.clear(); };
|
||||
|
||||
virtual bool register_device(uint8_t dev_addr, I2CDevice *dev_obj) {
|
||||
if (!this->dev_list[dev_addr]) {
|
||||
return false; /* device address already taken */
|
||||
}
|
||||
this->dev_list[dev_addr] = dev_obj;
|
||||
return true;
|
||||
};
|
||||
|
||||
virtual void start_transaction(uint8_t dev_addr) {
|
||||
if (this->dev_list[dev_addr]) {
|
||||
this->dev_list[dev_addr]->start_transaction();
|
||||
}
|
||||
};
|
||||
|
||||
virtual bool send_byte(uint8_t dev_addr, uint8_t data) {
|
||||
if (!this->dev_list[dev_addr]) {
|
||||
return false; /* no device -> no acknowledge */
|
||||
}
|
||||
return this->dev_list[dev_addr]->send_byte(data);
|
||||
};
|
||||
|
||||
virtual bool receive_byte(uint8_t dev_addr, uint8_t *p_data) {
|
||||
if (!this->dev_list[dev_addr]) {
|
||||
return false; /* no device -> no acknowledge */
|
||||
}
|
||||
return this->dev_list[dev_addr]->receive_byte(p_data);
|
||||
};
|
||||
|
||||
protected:
|
||||
std::vector<I2CDevice *> dev_list; /* list of registered I2C devices */
|
||||
};
|
||||
|
||||
#endif /* I2C_H */
|
@ -129,7 +129,7 @@ void ViaCuda::write(int reg, uint8_t value)
|
||||
|
||||
void ViaCuda::print_enabled_ints()
|
||||
{
|
||||
static char *via_int_src[] = { "CA2", "CA1", "SR", "CB2", "CB1", "T2", "T1" };
|
||||
const char *via_int_src[] = { "CA2", "CA1", "SR", "CB2", "CB1", "T2", "T1" };
|
||||
|
||||
for (int i = 0; i < 7; i++) {
|
||||
if (this->via_regs[VIA_IER] & (1 << i))
|
||||
|
@ -47,6 +47,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include "hwcomponent.h"
|
||||
#include "nvram.h"
|
||||
#include "i2c.h"
|
||||
|
||||
/** VIA register offsets. */
|
||||
enum {
|
||||
@ -100,7 +101,7 @@ enum {
|
||||
};
|
||||
|
||||
|
||||
class ViaCuda : public HWComponent
|
||||
class ViaCuda : public HWComponent, public I2CBus
|
||||
{
|
||||
public:
|
||||
ViaCuda();
|
||||
|
Loading…
Reference in New Issue
Block a user