2020-08-07 11:10:18 +08:00
|
|
|
use libregister::{
|
|
|
|
register, register_at,
|
|
|
|
register_bit, register_bits
|
|
|
|
};
|
2020-08-05 17:35:33 +08:00
|
|
|
|
|
|
|
// With reference to:
|
|
|
|
//
|
|
|
|
// artiq:artiq/gateware/targets/kasli.py:
|
|
|
|
// self.submodules.i2c = gpio.GPIOTristate([i2c.scl, i2c.sda])
|
|
|
|
//
|
|
|
|
// misoc:misoc/cores/gpio.py:
|
|
|
|
// class GPIOTristate(Module, AutoCSR):
|
|
|
|
// def __init__(self, signals, reset_out=0, reset_oe=0):
|
|
|
|
// l = len(signals)
|
|
|
|
// self._in = CSRStatus(l)
|
|
|
|
// self._out = CSRStorage(l, reset=reset_out)
|
|
|
|
// self._oe = CSRStorage(l, reset=reset_oe)
|
|
|
|
//
|
|
|
|
// Hence, using GPIOs as SCL and SDA GPIOs respectively.
|
|
|
|
//
|
|
|
|
// Current compatibility:
|
|
|
|
// zc706: GPIO 50, 51 == SCL, SDA
|
2020-11-20 03:17:36 +08:00
|
|
|
// kasli_soc: GPIO 50, 51 == SCL, SDA
|
2020-08-05 17:35:33 +08:00
|
|
|
|
2020-08-13 13:39:04 +08:00
|
|
|
pub struct RegisterBlock {
|
2020-08-05 17:35:33 +08:00
|
|
|
pub gpio_output_mask: &'static mut GPIOOutputMask,
|
|
|
|
pub gpio_input: &'static mut GPIOInput,
|
2020-08-07 11:10:18 +08:00
|
|
|
pub gpio_direction: &'static mut GPIODirection,
|
2020-08-05 17:35:33 +08:00
|
|
|
pub gpio_output_enable: &'static mut GPIOOutputEnable,
|
|
|
|
}
|
|
|
|
|
2020-08-13 13:39:04 +08:00
|
|
|
impl RegisterBlock {
|
|
|
|
pub fn i2c() -> Self {
|
2020-08-05 17:35:33 +08:00
|
|
|
Self {
|
|
|
|
gpio_output_mask: GPIOOutputMask::new(),
|
|
|
|
gpio_input: GPIOInput::new(),
|
2020-08-07 11:10:18 +08:00
|
|
|
gpio_direction: GPIODirection::new(),
|
2020-08-05 17:35:33 +08:00
|
|
|
gpio_output_enable: GPIOOutputEnable::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-20 03:26:48 +08:00
|
|
|
register!(gpio_output_mask,
|
|
|
|
/// MASK_DATA_1_MSW:
|
|
|
|
/// Maskable output data for MIO[53:48]
|
|
|
|
GPIOOutputMask, RW, u32);
|
2020-11-20 03:17:36 +08:00
|
|
|
#[cfg(any(feature = "target_zc706", feature = "target_kasli_soc"))]
|
2020-08-07 11:10:18 +08:00
|
|
|
register_at!(GPIOOutputMask, 0xE000A00C, new);
|
2020-11-20 03:17:36 +08:00
|
|
|
#[cfg(any(feature = "target_zc706", feature = "target_kasli_soc"))]
|
2020-11-20 03:26:48 +08:00
|
|
|
register_bit!(gpio_output_mask,
|
|
|
|
/// Output for SCL
|
|
|
|
scl_o, 2);
|
2020-11-20 03:17:36 +08:00
|
|
|
#[cfg(any(feature = "target_zc706", feature = "target_kasli_soc"))]
|
2020-11-20 03:26:48 +08:00
|
|
|
register_bit!(gpio_output_mask,
|
|
|
|
/// Output for SDA
|
|
|
|
sda_o, 3);
|
2020-11-20 03:17:36 +08:00
|
|
|
#[cfg(any(feature = "target_zc706", feature = "target_kasli_soc"))]
|
2020-11-20 03:26:48 +08:00
|
|
|
register_bits!(gpio_output_mask,
|
|
|
|
/// Mask for keeping bits except SCL and SDA unchanged
|
|
|
|
mask, u16, 16, 31);
|
2020-08-05 17:35:33 +08:00
|
|
|
|
2020-11-20 03:26:48 +08:00
|
|
|
register!(gpio_input,
|
|
|
|
/// DATA_1_RO:
|
|
|
|
/// Input data for MIO[53:32]
|
|
|
|
GPIOInput, RO, u32);
|
2020-11-20 03:17:36 +08:00
|
|
|
#[cfg(any(feature = "target_zc706", feature = "target_kasli_soc"))]
|
2020-08-07 11:10:18 +08:00
|
|
|
register_at!(GPIOInput, 0xE000A064, new);
|
2020-11-20 03:17:36 +08:00
|
|
|
#[cfg(any(feature = "target_zc706", feature = "target_kasli_soc"))]
|
2020-11-20 03:26:48 +08:00
|
|
|
register_bit!(gpio_input,
|
|
|
|
/// Input for SCL
|
|
|
|
scl, 18);
|
2020-11-20 03:17:36 +08:00
|
|
|
#[cfg(any(feature = "target_zc706", feature = "target_kasli_soc"))]
|
2020-11-20 03:26:48 +08:00
|
|
|
register_bit!(gpio_input,
|
|
|
|
/// Input for SDA
|
|
|
|
sda, 19);
|
2020-08-07 11:10:18 +08:00
|
|
|
|
2020-11-20 03:26:48 +08:00
|
|
|
register!(gpio_direction,
|
|
|
|
/// DIRM_1:
|
|
|
|
/// Direction mode for MIO[53:32]; 0/1 = in/out
|
|
|
|
GPIODirection, RW, u32);
|
2020-11-20 03:17:36 +08:00
|
|
|
#[cfg(any(feature = "target_zc706", feature = "target_kasli_soc"))]
|
2020-08-07 11:10:18 +08:00
|
|
|
register_at!(GPIODirection, 0xE000A244, new);
|
2020-11-20 03:17:36 +08:00
|
|
|
#[cfg(any(feature = "target_zc706", feature = "target_kasli_soc"))]
|
2020-11-20 03:26:48 +08:00
|
|
|
register_bit!(gpio_direction,
|
|
|
|
/// Direction for SCL
|
|
|
|
scl, 18);
|
2020-11-20 03:17:36 +08:00
|
|
|
#[cfg(any(feature = "target_zc706", feature = "target_kasli_soc"))]
|
2020-11-20 03:26:48 +08:00
|
|
|
register_bit!(gpio_direction,
|
|
|
|
/// Direction for SDA
|
|
|
|
sda, 19);
|
2020-08-05 17:35:33 +08:00
|
|
|
|
2020-11-20 03:26:48 +08:00
|
|
|
register!(gpio_output_enable,
|
|
|
|
/// OEN_1:
|
|
|
|
/// Output enable for MIO[53:32]
|
|
|
|
GPIOOutputEnable, RW, u32);
|
2020-11-20 03:17:36 +08:00
|
|
|
#[cfg(any(feature = "target_zc706", feature = "target_kasli_soc"))]
|
2020-08-07 11:10:18 +08:00
|
|
|
register_at!(GPIOOutputEnable, 0xE000A248, new);
|
2020-11-20 03:17:36 +08:00
|
|
|
#[cfg(any(feature = "target_zc706", feature = "target_kasli_soc"))]
|
2020-11-20 03:26:48 +08:00
|
|
|
register_bit!(gpio_output_enable,
|
|
|
|
/// Output enable for SCL
|
|
|
|
scl, 18);
|
2020-11-20 03:17:36 +08:00
|
|
|
#[cfg(any(feature = "target_zc706", feature = "target_kasli_soc"))]
|
2020-11-20 03:26:48 +08:00
|
|
|
register_bit!(gpio_output_enable,
|
|
|
|
/// Output enable for SDA
|
|
|
|
sda, 19);
|