2020from .ips .spi import SPISignature , SPIPeripheral
2121from .ips .i2c import I2CSignature , I2CPeripheral
2222from .ips .pwm import PWMPins , PWMPeripheral
23+ from .ips .pdm import PDMPeripheral
2324
2425__all__ = ["JTAGSignature" , "MySoC" ]
2526
@@ -45,7 +46,7 @@ def __init__(self):
4546 self .user_spi_count = 3
4647 self .i2c_count = 2
4748 self .motor_count = 10
48- self .pdm_ao_width = 6
49+ self .pdm_ao_count = 6
4950 self .uart_count = 2
5051
5152 self .gpio_banks = 2
@@ -60,7 +61,8 @@ def __init__(self):
6061 for i in range (self .motor_count ):
6162 interfaces [f"motor_pwm{ i } " ] = Out (PWMPins .Signature ())
6263
63- interfaces [f"pdm_ao" ] = Out (self .pdm_ao_width )
64+ for i in range (self .pdm_ao_count ):
65+ interfaces [f"pdm_ao_{ i } " ] = Out (1 )
6466
6567 for i in range (self .uart_count ):
6668 interfaces [f"uart_{ i } " ] = Out (UARTPins .Signature ())
@@ -90,8 +92,9 @@ def __init__(self):
9092 self .csr_motor_base = 0xb7000000
9193 self .csr_pdm_ao_base = 0xb8000000
9294
93- self .periph_offset = 0x00100000
94- self .motor_offset = 0x00000100
95+ self .periph_offset = 0x00100000
96+ self .motor_offset = 0x00000100
97+ self .pdm_ao_offset = 0x00000010
9598
9699 self .sram_size = 0x800 # 2KiB
97100 self .bios_start = 0x100000 # 1MiB into spiflash to make room for a bitstream
@@ -213,18 +216,15 @@ def elaborate(self, platform):
213216 sw .add_periph ("motor_pwm" , f"MOTOR_PWM{ i } " , base_addr )
214217 setattr (m .submodules , f"motor_pwm{ i } " , motor_pwm )
215218
216- # PDM for analog outputs
217- # TODO: create a PDM peripheral and replace this GPIO
218- soft_pdm_pins = GPIOPins (width = self .pdm_ao_width )
219- pdm = GPIOPeripheral (name = f"pdm_ao" , pins = soft_pdm_pins )
220-
221- csr_decoder .add (pdm .bus , addr = self .csr_pdm_ao_base - self .csr_base )
222- sw .add_periph ("gpio" , f"PDM_AO_{ i } " , self .csr_pdm_ao_base )
223-
224- # FIXME: This assignment will disappear once we have a relevant peripheral available
225- m .d .comb += [self .pdm_ao .eq (soft_pdm_pins .o )]
226-
227- m .submodules .pdm_ao = pdm
219+ # pdm_ao
220+ for i in range (self .pdm_ao_count ):
221+ pdm = PDMPeripheral (name = f"pdm{ i } " , bitwidth = 10 )
222+ base_addr = self .csr_pdm_ao_base + i * self .pdm_ao_offset
223+ csr_decoder .add (pdm .bus , addr = base_addr - self .csr_base )
224+
225+ sw .add_periph ("pdm" , f"PDM{ i } " , base_addr )
226+ setattr (m .submodules , f"pdm{ i } " , pdm )
227+ m .d .comb += getattr (self , f"pdm_ao_{ i } " ).eq (pdm .pdm_ao )
228228
229229 # SoC ID
230230
0 commit comments