Skip to content

Commit

Permalink
feat(PeriphDrivers): Add SPI Target Transaction functions
Browse files Browse the repository at this point in the history
  • Loading branch information
sihyung-maxim committed Jul 11, 2023
1 parent 0116a6f commit a6e6cde
Show file tree
Hide file tree
Showing 4 changed files with 462 additions and 19 deletions.
32 changes: 32 additions & 0 deletions Libraries/PeriphDrivers/Include/MAX78002/spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -1039,6 +1039,38 @@ int MXC_SPI_SlaveTransactionAsync(mxc_spi_req_t *req);
*/
int MXC_SPI_SlaveTransactionDMA(mxc_spi_req_t *req);

/**
* @brief Setup an interrupt-driven, non-blocking SPI Target transaction.
*
* @param spi Pointer to SPI instance's registers.
* @param tx_buffer Pointer to transmit buffer (in terms of bytes).
* @param tx_fr_len Number of frames to transmit from transmit buffer.
* @param rx_buffer Pointer to transmit buffer (in terms of bytes).
* @param rx_fr_len Number of frames to store in recieve buffer.
* @param deassert True(1)/False(0) whether to deassert target select at end of transactions.
*
* @return See \ref MXC_Error_Codes for the list of error return codes.
*/
int MXC_SPI_TargetTransaction(mxc_spi_regs_t *spi, uint8_t *tx_buffer,
uint32_t tx_fr_len, uint8_t *rx_buffer, uint32_t rx_fr_len,
uint8_t deassert);

/**
* @brief Setup a DMA driven SPI Target transaction.
*
* @param spi Pointer to SPI instance's registers.
* @param tx_buffer Pointer to transmit buffer (in terms of bytes).
* @param tx_fr_len Number of frames to transmit from transmit buffer.
* @param rx_buffer Pointer to transmit buffer (in terms of bytes).
* @param rx_fr_len Number of frames to store in recieve buffer.
* @param deassert True(1)/False(0) whether to deassert target select at end of transactions.
*
* @return See \ref MXC_Error_Codes for the list of error return codes.
*/
int MXC_SPI_TargetTransactionDMA(mxc_spi_regs_t *spi, uint8_t *tx_buffer,
uint32_t tx_fr_len, uint8_t *rx_buffer, uint32_t rx_fr_len,
uint8_t deassert);

/* ** Handler Functions ** */

/**
Expand Down
60 changes: 56 additions & 4 deletions Libraries/PeriphDrivers/Source/SPI/spi_ai87_v2.c
Original file line number Diff line number Diff line change
Expand Up @@ -774,8 +774,8 @@ int MXC_SPI_MasterTransactionAsync(mxc_spi_req_t *req)
}

return MXC_SPI_RevA2_ControllerTransaction((mxc_spi_reva_regs_t *)(req->spi), req->tx_buffer,
req->tx_len, req->rx_buffer, req->rx_len,
req->deassert, &target);
req->tx_len, req->rx_buffer, req->rx_len,
req->deassert, &target);
}

int MXC_SPI_MasterTransactionDMA(mxc_spi_req_t *req)
Expand Down Expand Up @@ -866,12 +866,64 @@ int MXC_SPI_SlaveTransaction(mxc_spi_req_t *req)

int MXC_SPI_SlaveTransactionAsync(mxc_spi_req_t *req)
{
return E_NOT_SUPPORTED;
int error;

error = MXC_SPI_SetCallback(req->spi, req->callback, req->callback_data);
if (error != E_NO_ERROR) {
return error;
}

return MXC_SPI_RevA2_TargetTransaction((mxc_spi_reva_regs_t *)(req->spi), req->tx_buffer, req->tx_len, req->rx_buffer, req->rx_len, req->deassert);
}

int MXC_SPI_SlaveTransactionDMA(mxc_spi_req_t *req)
{
return E_NOT_SUPPORTED;
int error;
mxc_spi_init_t init;

init.use_dma = true;
init.dma = MXC_DMA;

// More overhead, but this function will initalize DMA if not initialized.
if (MXC_SPI_DMA_GetInitialized(req->spi) == false) {
error = MXC_SPI_DMA_Init(&init);
if (error != E_NO_ERROR) {
return error;
}
}

error = MXC_SPI_SetCallback(req->spi, req->callback, req);
if (error != E_NO_ERROR) {
return error;
}

error = MXC_SPI_DMA_SetRequestSelect(req->spi, req->tx_buffer, req->rx_buffer);
if (error != E_NO_ERROR) {
return error;
}

return MXC_SPI_RevA2_TargetTransactionDMA((mxc_spi_reva_regs_t *)(req->spi), req->tx_buffer, req->tx_len, req->rx_buffer, req->rx_len, req->deassert);
}

int MXC_SPI_TargetTransaction(mxc_spi_regs_t *spi, uint8_t *tx_buffer, uint32_t tx_fr_len,
uint8_t *rx_buffer, uint32_t rx_fr_len, uint8_t deassert)
{
return MXC_SPI_RevA2_TargetTransaction((mxc_spi_reva_regs_t *)spi, tx_buffer, tx_fr_len,
rx_buffer, rx_fr_len, deassert);
}

int MXC_SPI_TargetTransactionDMA(mxc_spi_regs_t *spi, uint8_t *tx_buffer, uint32_t tx_fr_len,
uint8_t *rx_buffer, uint32_t rx_fr_len, uint8_t deassert)
{
int error;

error = MXC_SPI_DMA_SetRequestSelect(spi, tx_buffer, rx_buffer);
if (error != E_NO_ERROR) {
return error;
}

return MXC_SPI_RevA2_TargetTransactionDMA((mxc_spi_reva_regs_t *)spi, tx_buffer, tx_fr_len,
rx_buffer, rx_fr_len, deassert);
}

/* ** Handler Functions ** */
Expand Down
Loading

0 comments on commit a6e6cde

Please sign in to comment.