Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/machine/machine_rp2_spi.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,28 +274,31 @@ func (spi *SPI) tx(tx []byte) error {
}

// Pick the DMA channel reserved for this SPI peripheral.
var ch *dmaChannel
var channel uint32
var dreq uint32
if spi.Bus == rp.SPI0 {
ch = &dmaChannels[spi0DMAChannel]
channel = spi0DMAChannel
dreq = rp.DREQ_SPI0_TX
} else { // SPI1
ch = &dmaChannels[spi1DMAChannel]
channel = spi1DMAChannel
dreq = rp.DREQ_SPI1_TX
}
ch := &dmaChannels[channel]

// Configure the DMA peripheral as follows:
// - set read address, write address, and number of transfer units (bytes)
// - increment read address (in memory), don't increment write address (SSPDR)
// - set data size to single bytes
// - set the DREQ so that the DMA will fill the SPI FIFO as needed
// - chain to itself, which disables chaining
// - start the transfer
ch.READ_ADDR.Set(uint32(unsafeNoEscape(unsafe.Pointer(unsafe.SliceData(tx)))))
ch.WRITE_ADDR.Set(uint32(uintptr(unsafe.Pointer(&spi.Bus.SSPDR))))
ch.TRANS_COUNT.Set(uint32(len(tx)))
ch.CTRL_TRIG.Set(rp.DMA_CH0_CTRL_TRIG_INCR_READ |
rp.DMA_CH0_CTRL_TRIG_DATA_SIZE_SIZE_BYTE<<rp.DMA_CH0_CTRL_TRIG_DATA_SIZE_Pos |
dreq<<rp.DMA_CH0_CTRL_TRIG_TREQ_SEL_Pos |
channel<<rp.DMA_CH0_CTRL_TRIG_CHAIN_TO_Pos |
rp.DMA_CH0_CTRL_TRIG_EN)

// Wait until the transfer is complete.
Expand Down
Loading