Livt packages

Livt.IO

Version 1.8.1

Memory, UART, I2C, SPI, and Ethernet input/output components for Livt hardware designs.

Published files (126)

src/i2c/I2COpenDrainPins.lvt

namespace Livt.IO

/**
 * Adapts physical bidirectional pins to the logical open-drain I2C bus contract.
 */
component I2COpenDrainPins : I2CBus
{
	// Physical open-drain pins; releasing a pin relies on the board pull-up.
	public physical_scl: inout logic
	public physical_sda: inout logic

	/**
	 * Binds the physical bidirectional pins. The board must provide pull-ups for released
	 * lines.
	 */
	new(physicalScl: inout logic, physicalSda: inout logic)
	{
		this.physical_scl = physicalScl
		this.physical_sda = physicalSda
	}

	/**
	 * Continuously drives zero for an asserted low request and high impedance otherwise. Reads
	 * a physical zero as low and every other resolved value as high.
	 */
	process DrivePins[]()
	{
		if (this.scl_drive_low == 0b1) {
			this.physical_scl = 0b0
		} else {
			this.physical_scl = 0bZ
		}

		if (this.sda_drive_low == 0b1) {
			this.physical_sda = 0b0
		} else {
			this.physical_sda = 0bZ
		}

		if (this.physical_scl == 0b0) {
			this.scl = 0b0
		} else {
			this.scl = 0b1
		}

		if (this.physical_sda == 0b0) {
			this.sda = 0b0
		} else {
			this.sda = 0b1
		}
	}
}