summaryrefslogtreecommitdiffhomepage
path: root/digital/avr/modules/twi/test/test_twi_master.c
diff options
context:
space:
mode:
Diffstat (limited to 'digital/avr/modules/twi/test/test_twi_master.c')
-rw-r--r--digital/avr/modules/twi/test/test_twi_master.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/digital/avr/modules/twi/test/test_twi_master.c b/digital/avr/modules/twi/test/test_twi_master.c
index 85b48686..d65d185d 100644
--- a/digital/avr/modules/twi/test/test_twi_master.c
+++ b/digital/avr/modules/twi/test/test_twi_master.c
@@ -65,6 +65,25 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
}
}
break;
+ case c ('r', 2):
+ /* Read n bytes from an address slave
+ * 2 parameter:
+ * - slave address.
+ * - nb of bytes.
+ */
+ {
+ uint8_t data[16];
+ int8_t d = twi_ms_read (args[0], data, args[1]);
+ if (d != 0)
+ proto_send0 ('e');
+ else
+ {
+ while (!twi_ms_is_finished ())
+ ;
+ proto_send ('R', args[1], data);
+ }
+ }
+ break;
case c ('t', 2):
/* Test for sending and receiving multiple data.
* It sends a random number of bytes to the slave and then read back
@@ -141,8 +160,21 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
utils_reset ();
break;
default:
- /* Error */
- proto_send0 ('?');
+ /* Variable number of arguments. */
+ if (cmd == 's')
+ {
+ /* Send n bytes to a slave address.
+ * 1+n parameters:
+ * - slave address;
+ * - n x data.
+ */
+ twi_ms_send (args[0], &args[1], size - 1);
+ while (!twi_ms_is_finished ())
+ ;
+ }
+ else
+ /* Error */
+ proto_send0 ('?');
return;
}
/* Acknowledge what has been done */