From db212811293f91e0f1147eb57e5f6d5df2db10ef Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Mon, 29 Nov 2010 23:07:46 +0100 Subject: digital/avr/modules/twi: cleanup TWI module, refs #29, closes #90 - use contexts - changed interface - merge test programs - share polling mechanism - prepare place for other drivers - add callback system - use english comments --- digital/mimot/src/dirty/avrconfig.h | 28 +++++++++++++++++++++------- digital/mimot/src/dirty/twi_proto.c | 6 +++--- 2 files changed, 24 insertions(+), 10 deletions(-) (limited to 'digital/mimot') diff --git a/digital/mimot/src/dirty/avrconfig.h b/digital/mimot/src/dirty/avrconfig.h index c7cc73f3..ca181554 100644 --- a/digital/mimot/src/dirty/avrconfig.h +++ b/digital/mimot/src/dirty/avrconfig.h @@ -92,13 +92,27 @@ #define AC_ASSERV_TWI_ADDRESS 6 /* twi - TWI module. */ -/** Activate master part. */ -#define AC_TWI_MASTER_ENABLE 0 -/** Activate slave part. */ +/** Driver to implement TWI: HARD, SOFT, or USI. */ +#define AC_TWI_DRIVER HARD +/** Do not use interrupts. */ +#define AC_TWI_NO_INTERRUPT 0 +/** TWI frequency, should really be 100 kHz. */ +#define AC_TWI_FREQ 100000 +/** Enable slave part. */ #define AC_TWI_SLAVE_ENABLE 1 -/** Slave recv buffer size. */ -#define AC_TWI_SL_RECV_BUFFER_SIZE 16 -/** Slave send buffer size. */ -#define AC_TWI_SL_SEND_BUFFER_SIZE 16 +/** Enable master part. */ +#define AC_TWI_MASTER_ENABLE 0 +/** Use polled slave mode: received data is stored in a buffer which can be + * polled using twi_slave_poll. */ +#define AC_TWI_SLAVE_POLLED 1 +/** Slave reception callback to be defined by the user when not in polled + * mode. */ +#undef AC_TWI_SLAVE_RECV +/** Use internal pull up. */ +#define AC_TWI_PULL_UP 0 +/** Slave reception buffer size. */ +#define AC_TWI_SLAVE_RECV_BUFFER_SIZE 16 +/** Slave transmission buffer size. */ +#define AC_TWI_SLAVE_SEND_BUFFER_SIZE 16 #endif /* avrconfig_h */ diff --git a/digital/mimot/src/dirty/twi_proto.c b/digital/mimot/src/dirty/twi_proto.c index a6894109..3048c594 100644 --- a/digital/mimot/src/dirty/twi_proto.c +++ b/digital/mimot/src/dirty/twi_proto.c @@ -67,10 +67,10 @@ twi_proto_init (void) void twi_proto_update (void) { - u8 buf[AC_TWI_SL_RECV_BUFFER_SIZE]; + u8 buf[AC_TWI_SLAVE_RECV_BUFFER_SIZE]; u8 read_data; /* Handle incoming command. */ - while ((read_data = twi_sl_poll (buf, sizeof (buf)))) + while ((read_data = twi_slave_poll (buf, sizeof (buf)))) twi_proto_callback (buf, read_data); /* Update status. */ u8 status_with_crc[8]; @@ -89,7 +89,7 @@ twi_proto_update (void) /* Compute CRC. */ status_with_crc[0] = crc_compute (&status_with_crc[1], sizeof (status_with_crc) - 1); - twi_sl_update (status_with_crc, sizeof (status_with_crc)); + twi_slave_update (status_with_crc, sizeof (status_with_crc)); } /** Handle one command. */ -- cgit v1.2.3