#ifndef BSS_AXIL_SPI_H
#define BSS_AXIL_SPI_H

#include <stdint.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef enum {
    BSS_SPI_OK = 0,
    BSS_SPI_INVALID_ARGUMENT,
    BSS_SPI_BUSY,
    BSS_SPI_TIMEOUT
} bss_spi_result;

/* Provide ordered 32-bit MMIO accessors for the target platform. */
uint32_t bss_spi_read32(uintptr_t address);
void bss_spi_write32(uintptr_t address, uint32_t value);

/* Use an aligned base address and serialize all access to the peripheral. */
bss_spi_result bss_spi_set_divider(uintptr_t base, uint32_t half_period_cycles);

/* Each call sends one mode-0 byte. rx can be null to discard received data.
 * poll_limit bounds completion reads. On timeout, the frame may still finish.
 */
bss_spi_result bss_spi_transfer_byte(uintptr_t base, uint8_t tx, uint8_t *rx,
                                     uint32_t poll_limit);

#ifdef __cplusplus
}
#endif

#endif
