summaryrefslogtreecommitdiff
path: root/n/avr/twi-master/test_twi_master.c
diff options
context:
space:
mode:
Diffstat (limited to 'n/avr/twi-master/test_twi_master.c')
-rw-r--r--n/avr/twi-master/test_twi_master.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/n/avr/twi-master/test_twi_master.c b/n/avr/twi-master/test_twi_master.c
new file mode 100644
index 0000000..dbce0ad
--- /dev/null
+++ b/n/avr/twi-master/test_twi_master.c
@@ -0,0 +1,63 @@
+/* test_twi_master.c */
+
+#include "twi_master.h"
+
+#include <n/avr/rs232/rs232.h>
+#include <n/avr/proto/proto.h>
+#include <avr/io.h>
+#include <avr/interrupt.h>
+
+void proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
+{
+ uint8_t data[1] = {0x00};
+ int8_t c;
+ sei ();
+ switch (cmd)
+ {
+ case 's':
+ if (size == 2)
+ {
+ proto_send ('s', 0, 0);
+ twi_master_send (args[0], &args[1], 1);
+ proto_send ('f', 0, 0);
+ }
+ else
+ proto_send ('e', 0, 0);
+ break;
+ case 'r':
+ if (size == 2)
+ {
+ rs232_putc ('r');
+ c = twi_master_read (args[0], data, 1);
+ if (c != 0)
+ proto_send ('e', 1 , 0);
+ else
+ proto_send ('f', 1, data);
+ }
+ else
+ proto_send ('e', 1, 0);
+ break;
+ default:
+ proto_send ('e', 1, 0);
+ }
+}
+
+int
+main (void)
+{
+ uint8_t c;
+ rs232_init ();
+ twi_master_init ();
+ rs232_putc ('m');
+ rs232_putc ('s');
+ rs232_putc ('s');
+ rs232_putc ('\n');
+ //DDRC = 1;
+ //PORTC = 1;
+ while (42)
+ {
+ c = rs232_getc ();
+ proto_accept (c);
+ }
+ return 0;
+}