cores/bitbang: Attach I2C init table directly to I2C cores and avoid global add_i2c_init_table SoC method.

This commit is contained in:
Florent Kermarrec 2022-02-02 10:43:34 +01:00
parent 732529ecdf
commit 7ed448cd52
3 changed files with 16 additions and 7 deletions

View File

@ -22,6 +22,7 @@ class I2CMaster(Module, AutoCSR):
Software get back SDA value with the read CSRStatus (_r). Software get back SDA value with the read CSRStatus (_r).
""" """
init = []
pads_layout = [("scl", 1), ("sda", 1)] pads_layout = [("scl", 1), ("sda", 1)]
def __init__(self, pads=None): def __init__(self, pads=None):
if pads is None: if pads is None:
@ -51,6 +52,9 @@ class I2CMaster(Module, AutoCSR):
i = self._r.fields.sda i = self._r.fields.sda
) )
def add_init(self, addr, init, init_addr_len=1):
self.init.append((addr, init, init_addr_len))
class I2CMasterSim(I2CMaster): class I2CMasterSim(I2CMaster):
"""I2C Master Bit-Banging for Verilator simulation """I2C Master Bit-Banging for Verilator simulation
@ -77,6 +81,16 @@ class I2CMasterSim(I2CMaster):
) )
] ]
# I2C Master Init Collection ----------------------------------------------------------------------
def collect_i2c_init(soc):
i2c_init = []
for name, obj in xdir(soc, True):
if isinstance(obj, I2CMaster) and hasattr(obj, "init"):
for addr, init, init_addr_len in obj.init:
i2c_init.append((name, addr, init, init_addr_len))
return i2c_init
# SPI Master Bit-Banging --------------------------------------------------------------------------- # SPI Master Bit-Banging ---------------------------------------------------------------------------
class SPIMaster(Module, AutoCSR): class SPIMaster(Module, AutoCSR):

View File

@ -204,7 +204,8 @@ class Builder:
write_to_file(os.path.join(self.generated_dir, "csr.h"), csr_contents) write_to_file(os.path.join(self.generated_dir, "csr.h"), csr_contents)
# Generate I2C command/value table # Generate I2C command/value table
i2c_contents = export.get_i2c_header(self.soc.i2c_init) from litex.soc.cores.bitbang import collect_i2c_init
i2c_contents = export.get_i2c_header(collect_i2c_init(self.soc))
write_to_file(os.path.join(self.generated_dir, "i2c.h"), i2c_contents) write_to_file(os.path.join(self.generated_dir, "i2c.h"), i2c_contents)
# Generate Git SHA1 of tools to git.h # Generate Git SHA1 of tools to git.h

View File

@ -174,9 +174,6 @@ class SoCCore(LiteXSoC):
# Wishbone Slaves. # Wishbone Slaves.
self.wb_slaves = {} self.wb_slaves = {}
# I2C initialisation tables
self.i2c_init = []
# Modules instances ------------------------------------------------------------------------ # Modules instances ------------------------------------------------------------------------
# Add SoCController # Add SoCController
@ -272,9 +269,6 @@ class SoCCore(LiteXSoC):
def add_csr_region(self, name, origin, busword, obj): def add_csr_region(self, name, origin, busword, obj):
self.csr_regions[name] = SoCCSRRegion(origin, busword, obj) self.csr_regions[name] = SoCCSRRegion(origin, busword, obj)
def add_i2c_init_table(self, dev, i2c_addr, table, addr_len=1):
self.i2c_init.append((dev, i2c_addr, table, addr_len))
# Finalization --------------------------------------------------------------------------------- # Finalization ---------------------------------------------------------------------------------
def do_finalize(self): def do_finalize(self):