1
0
Fork 0

Add i2c support

This commit is contained in:
newell 2024-10-04 23:45:24 -07:00
parent b2a741437d
commit da8817064a
5 changed files with 44 additions and 31 deletions

View File

@ -73,9 +73,19 @@ _ddr = [
)
]
# Connector J3
_i2c = [
(
"i2c",
0,
Subsignal("scl", Pins("U12"), IOStandard("LVCMOS33")),
Subsignal("sda", Pins("V13"), IOStandard("LVCMOS33")),
)
]
class EBAZ4205(SoCCore):
def __init__(self, rtio_clk=100e6, acpki=False):
def __init__(self, rtio_clk=125e6, acpki=False):
self.acpki = acpki
platform = ebaz4205.Platform()
@ -86,6 +96,7 @@ class EBAZ4205(SoCCore):
)
platform.add_extension(_ps)
platform.add_extension(_ddr)
platform.add_extension(_i2c)
gmii = platform.request("gmii")
platform.add_period_constraint(gmii.rx_clk, 10)
@ -97,12 +108,7 @@ class EBAZ4205(SoCCore):
ident = self.__class__.__name__
if self.acpki:
ident = "acpki_" + ident
SoCCore.__init__(
self,
platform=platform,
csr_data_width=32,
ident=ident,
)
SoCCore.__init__(self, platform=platform, csr_data_width=32, ident=ident)
fix_serdes_timing_path(platform)
self.config["RTIO_FREQUENCY"] = str(rtio_clk / 1e6)
platform.add_period_constraint(self.ps7.cd_sys.clk, 10)
@ -128,21 +134,34 @@ class EBAZ4205(SoCCore):
# MDIO
mdio = platform.request("mdio")
self.comb += [
mdio.mdc.eq(self.ps7.enet0.enet.mdio.mdc),
]
mdio_t = Signal()
self.comb += mdio_t.eq(~self.ps7.enet0.enet.mdio.t_n)
self.specials += [
Instance(
self.comb += mdio.mdc.eq(self.ps7.enet0.enet.mdio.mdc)
self.specials += Instance(
"IOBUF",
i_I=self.ps7.enet0.enet.mdio.o,
io_IO=mdio.mdio,
o_O=self.ps7.enet0.enet.mdio.i,
i_T=mdio_t,
i_T=~self.ps7.enet0.enet.mdio.t_n,
)
# I2C
i2c = self.platform.request("i2c")
self.specials += [
# SCL
Instance(
"IOBUF",
i_I=self.ps7.i2c0.scl.o,
io_IO=i2c.scl,
o_O=self.ps7.i2c0.scl.i,
i_T=~self.ps7.i2c0.scl.t_n,
),
# SDA
Instance(
"IOBUF",
i_I=self.ps7.i2c0.sda.o,
io_IO=i2c.sda,
o_O=self.ps7.i2c0.sda.i,
i_T=~self.ps7.i2c0.sda.t_n,
),
]
self.rtio_channels = []
@ -211,7 +230,7 @@ def main():
parser.add_argument(
"-g", default=None, help="build gateware into the specified directory"
)
parser.add_argument("--rtio_clk", default=100e6, help="RTIO Clock Frequency (Hz)")
parser.add_argument("--rtio-clk", default=125e6, help="RTIO Clock Frequency (Hz)")
parser.add_argument(
"--acpki", default=False, action="store_true", help="enable ACPKI"
)

View File

@ -11,9 +11,7 @@ use super::{cache,
core1::rtio_get_destination_status,
dma, linalg,
rpc::{rpc_recv, rpc_send, rpc_send_async}};
use crate::{eh_artiq, rtio};
#[cfg(not(feature = "target_ebaz4205"))]
use crate::i2c;
use crate::{eh_artiq, i2c, rtio};
extern "C" {
fn vsnprintf_(buffer: *mut c_char, count: size_t, format: *const c_char, va: VaList) -> c_int;
@ -111,17 +109,11 @@ pub fn resolve(required: &[u8]) -> Option<u32> {
api!(cache_put = cache::put),
// i2c
#[cfg(not(feature = "target_ebaz4205"))]
api!(i2c_start = i2c::start),
#[cfg(not(feature = "target_ebaz4205"))]
api!(i2c_restart = i2c::restart),
#[cfg(not(feature = "target_ebaz4205"))]
api!(i2c_stop = i2c::stop),
#[cfg(not(feature = "target_ebaz4205"))]
api!(i2c_write = i2c::write),
#[cfg(not(feature = "target_ebaz4205"))]
api!(i2c_read = i2c::read),
#[cfg(not(feature = "target_ebaz4205"))]
api!(i2c_switch_select = i2c::switch_select),
// subkernel

View File

@ -21,7 +21,6 @@ pub use pl::csr::rtio_core;
use void::Void;
pub mod eh_artiq;
#[cfg(not(feature = "target_ebaz4205"))]
pub mod i2c;
pub mod irq;
pub mod kernel;

View File

@ -100,7 +100,6 @@ pub fn main_core0() {
info!("gateware ident: {}", identifier_read(&mut [0; 64]));
#[cfg(not(feature = "target_ebaz4205"))]
ksupport::i2c::init();
#[cfg(feature = "target_kasli_soc")]
{

View File

@ -1,6 +1,8 @@
#[cfg(not(feature = "target_ebaz4205"))]
use embedded_hal::blocking::delay::DelayMs;
#[cfg(has_si5324)]
use ksupport::i2c;
#[cfg(not(feature = "target_ebaz4205"))]
use libboard_artiq::pl;
#[cfg(has_si5324)]
use libboard_artiq::si5324;
@ -10,7 +12,9 @@ use libboard_artiq::si549;
use libboard_zynq::i2c::I2c;
use libboard_zynq::timer::GlobalTimer;
use libconfig::Config;
use log::{info, warn};
use log::warn;
#[cfg(not(feature = "target_ebaz4205"))]
use log::info;
#[derive(Debug, PartialEq, Copy, Clone)]
#[allow(non_camel_case_types)]