1
0
mirror of https://github.com/TomHarte/CLK.git synced 2026-04-25 11:17:26 +00:00

Add a target for I2C activity.

This commit is contained in:
Thomas Harte
2024-03-16 15:00:23 -04:00
parent 635efd0212
commit 47e9279bd4
7 changed files with 106 additions and 4 deletions
+35
View File
@@ -0,0 +1,35 @@
//
// I2C.cpp
// Clock Signal
//
// Created by Thomas Harte on 16/03/2024.
// Copyright © 2024 Thomas Harte. All rights reserved.
//
#include "I2C.hpp"
using namespace I2C;
void Bus::set_data(bool pulled) {
set_clock_data(clock_, pulled);
}
bool Bus::data() {
return data_;
}
void Bus::set_clock(bool pulled) {
set_clock_data(pulled, data_);
}
bool Bus::clock() {
return clock_;
}
void Bus::set_clock_data(bool clock_pulled, bool data_pulled) {
// TODO: all intelligence.
clock_ = clock_pulled;
data_ = data_pulled;
}
void Bus::add_peripheral(Peripheral *peripheral, int address) {
peripherals_[address] = peripheral;
}
+39
View File
@@ -0,0 +1,39 @@
//
// I2C.hpp
// Clock Signal
//
// Created by Thomas Harte on 16/03/2024.
// Copyright © 2024 Thomas Harte. All rights reserved.
//
#pragma once
#include <unordered_map>
namespace I2C {
/// Provides the virtual interface for an I2C peripheral; attaching this to a bus
/// provides automatic protocol handling.
class Peripheral {
};
class Bus {
public:
void set_data(bool pulled);
bool data();
void set_clock(bool pulled);
bool clock();
void set_clock_data(bool clock_pulled, bool data_pulled);
void add_peripheral(Peripheral *, int address);
private:
bool data_ = false;
bool clock_ = false;
std::unordered_map<int, Peripheral *> peripherals_;
};
}