summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--digital/avr/modules/spi/spi.c43
-rw-r--r--digital/avr/modules/spi/spi.h19
-rw-r--r--digital/avr/modules/spi/test/test_spi.c28
3 files changed, 23 insertions, 67 deletions
diff --git a/digital/avr/modules/spi/spi.c b/digital/avr/modules/spi/spi.c
index 8fb35bb9..ea8743a8 100644
--- a/digital/avr/modules/spi/spi.c
+++ b/digital/avr/modules/spi/spi.c
@@ -45,36 +45,27 @@ static spi_t spi_global;
* \param user_data the user data to be provieded in the function call back.
*/
void
-spi_init(uint8_t sprc, spi_recv_cb_t cb, void *user_data)
+spi_init(uint8_t sprc)
{
SPCR = sprc;
- spi_global.recv_cb = cb;
- spi_global.recv_user_data = user_data;
spi_global.interruption = sprc >> 7;
}
/** Send a data to the Slave.
* \param data the data to send
- * \param length the length of the data in bytes.
*/
void
-spi_send(uint8_t *data, uint8_t length)
+spi_send(uint8_t data)
{
- uint8_t i;
// enables the SPI if not enabled.
SPCR |= SPI_ENABLE;
- for ( i = 0; i < length; i++)
- {
- // Insert the data in the data register, the SPI will begin to send it
- // automatically.
- SPDR = data[i];
+ SPDR = data;
- if (!spi_global.interruption)
- {
- // Wait the end of the transmission.
- while(!(SPSR & (1<<SPIF)));
- }
+ if (!spi_global.interruption)
+ {
+ // Wait the end of the transmission.
+ while(!(SPSR & (1<<SPIF)));
}
}
@@ -91,18 +82,6 @@ spi_recv(void)
return SPDR;
}
-/** Receive a date from the SPI bus from the address provided by parameters.
- * \param addr the address from which the data shall be read
- * \return the data at the address requested.
- */
-uint8_t
-spi_recv_from (uint8_t addr)
-{
- SPDR = addr;
-
- return spi_recv();
-}
-
/** Return the status register from the SPI driver.
* \return the status register value
*/
@@ -112,12 +91,4 @@ spi_status(void)
return SPSR;
}
-/**
- * Function called by the interruption if an IT is requested.
- */
-SIGNAL (SIG_SPI)
-{
- // call the call back.
- (*spi_global.recv_cb) (spi_global.recv_user_data, SPDR);
-}
diff --git a/digital/avr/modules/spi/spi.h b/digital/avr/modules/spi/spi.h
index 59e09fc7..be1ec0e7 100644
--- a/digital/avr/modules/spi/spi.h
+++ b/digital/avr/modules/spi/spi.h
@@ -50,15 +50,8 @@ enum spi_fosc_t
SPI_FOSC_DIV32
};
-/** Call back use to call the user function on the reception of a data. */
-typedef void (*spi_recv_cb_t) (void *user_data, uint8_t data);
-
struct spi_t
{
- /** Call back function. */
- spi_recv_cb_t recv_cb;
- /** user data on data reception. */
- void *recv_user_data;
/** interruption status. */
int8_t interruption;
};
@@ -70,7 +63,7 @@ typedef struct spi_t spi_t;
* \param user_data the user data to be provieded in the function call back.
*/
void
-spi_init(uint8_t sprc, spi_recv_cb_t cb, void *user_data);
+spi_init(uint8_t sprc);
/** Uninitialise the SPI module.
* Unused on the target
@@ -80,10 +73,9 @@ spi_uninit (void);
/** Send a data to the Slave.
* \param data the data to send
- * \param length the length of the data in bytes.
*/
void
-spi_send(uint8_t *data, uint8_t length);
+spi_send(uint8_t data);
/** Receive a data from the SPI bus.
* \return the data received from the bus.
@@ -91,13 +83,6 @@ spi_send(uint8_t *data, uint8_t length);
uint8_t
spi_recv(void);
-/** Receive a date from the SPI bus from the address provided by parameters.
- * \param addr the address from which the data shall be read
- * \return the data at the address requested.
- */
-uint8_t
-spi_recv_from (uint8_t addr);
-
/** Return the status register from the SPI driver.
* \return the status register value
*/
diff --git a/digital/avr/modules/spi/test/test_spi.c b/digital/avr/modules/spi/test/test_spi.c
index a6060b8b..a7f512f1 100644
--- a/digital/avr/modules/spi/test/test_spi.c
+++ b/digital/avr/modules/spi/test/test_spi.c
@@ -40,38 +40,38 @@ main (void)
uint8_t res;
res = SPI_IT_ENABLE;
- spi_init (res, spi_interruption_function, 0x0);
+ spi_init (res);
res = SPI_IT_DISABLE;
- spi_init (res, spi_interruption_function, 0x0);
+ spi_init (res);
res = SPI_ENABLE;
- spi_init (res, spi_interruption_function, 0x0);
+ spi_init (res);
res = SPI_DISABLE;
- spi_init (res, spi_interruption_function, 0x0);
+ spi_init (res);
res = SPI_LSB_FIRST;
- spi_init (res, spi_interruption_function, 0x0);
+ spi_init (res);
res = SPI_MSB_FIRST;
- spi_init (res, spi_interruption_function, 0x0);
+ spi_init (res);
res = SPI_MASTER;
- spi_init (res, spi_interruption_function, 0x0);
+ spi_init (res);
res = SPI_SLAVE;
- spi_init (res, spi_interruption_function, 0x0);
+ spi_init (res);
res = SPI_CPOL_RISING;
- spi_init (res, spi_interruption_function, 0x0);
+ spi_init (res);
res = SPI_CPOL_FALLING;
- spi_init (res, spi_interruption_function, 0x0);
+ spi_init (res);
res = SPI_CPHA_SAMPLE;
- spi_init (res, spi_interruption_function, 0x0);
+ spi_init (res);
res = SPI_CPHA_SETUP;
- spi_init (res, spi_interruption_function, 0x0);
+ spi_init (res);
//initialise the spi.
- spi_init (0x14, spi_interruption_function, 0x0);
+ spi_init (0x14);
test[0] = 0x2;
test[1] = 0x3;
test[2] = 0x4;
- spi_send (test, 3);
+ spi_send (3);
res = spi_recv ();