# HG changeset patch # User Josef 'Jeff' Sipek # Date 1721044974 14400 # Mon Jul 15 08:02:54 2024 -0400 # Node ID 2270713edaecd831e0a8f5b3f73352a345ce31af # Parent 43d2a8cd5054c423dd77e350762ad8039ea45410 arch: add function to concurrently send and receive SPI data (ATmega48P) Signed-off-by: Josef 'Jeff' Sipek diff --git a/arch/atmega48p_spi.h b/arch/atmega48p_spi.h --- a/arch/atmega48p_spi.h +++ b/arch/atmega48p_spi.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Josef 'Jeff' Sipek + * Copyright (c) 2023-2024 Josef 'Jeff' Sipek * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -140,6 +140,20 @@ ; } +/* send & receive a single byte, CS is left up to the caller */ +static inline uint8_t spi_txrx_byte(uint8_t dummy) +{ + mmregs->spdr = dummy; + + /* wait for rx to complete */ + while (!(mmregs->spsr & REG_SPSR_SPIF)) + ; + + return mmregs->spdr; +} + +#define spi_rx_byte() spi_txrx_byte(0) + #endif #endif