example of i2c slave device supporting block transfers
Dependencies: lib_i2c_slave_block
Tested on nucleo board as slave. Use with i2c_master_block_example on raspberry pi as master.
Master I2C write will print on serial terminal 115200. User button will raise an irq; the RPi test program will service the interrupt.
See lib_i2c_slave_block for explanation of code.
cmds.h@3:0288d257446a, 2019-02-03 (annotated)
- Committer:
- Wayne Roberts
- Date:
- Sun Feb 03 16:56:15 2019 -0800
- Revision:
- 3:0288d257446a
- Parent:
- 2:d7e05c75f240
indicate errors if reported by i2c
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wayne Roberts |
0:3ccfaf358115 | 1 | |
Wayne Roberts |
0:3ccfaf358115 | 2 | #define CMD_TEST3 0x00 |
Wayne Roberts |
0:3ccfaf358115 | 3 | #define CMD_TEST12 0x01 |
Wayne Roberts |
0:3ccfaf358115 | 4 | #define CMD_TEST32 0x02 |
Wayne Roberts |
0:3ccfaf358115 | 5 | #define CMD_IRQ 0x03 |
Wayne Roberts |
2:d7e05c75f240 | 6 | #define CMD_BUFFER 0x04 |
Wayne Roberts |
0:3ccfaf358115 | 7 | |
Wayne Roberts |
3:0288d257446a | 8 | #define CMD_TIMEOUT 0xfd // indication of smbus timeout |
Wayne Roberts |
3:0288d257446a | 9 | #define CMD_ARLO 0xfe // indication of arbitration lost |
Wayne Roberts |
3:0288d257446a | 10 | #define CMD_BUSERR 0xff // indication of start or stop during transfer |
Wayne Roberts |
3:0288d257446a | 11 | |
Wayne Roberts |
0:3ccfaf358115 | 12 | typedef union { |
Wayne Roberts |
0:3ccfaf358115 | 13 | struct __attribute__((packed)) { |
Wayne Roberts |
0:3ccfaf358115 | 14 | struct { |
Wayne Roberts |
0:3ccfaf358115 | 15 | uint8_t button : 1; // 0 |
Wayne Roberts |
0:3ccfaf358115 | 16 | uint8_t xyz : 1; // 1 |
Wayne Roberts |
0:3ccfaf358115 | 17 | uint8_t res : 6; // 2,3,4,5,6,7 |
Wayne Roberts |
0:3ccfaf358115 | 18 | } flags; |
Wayne Roberts |
0:3ccfaf358115 | 19 | uint8_t cnt; // if flags.button |
Wayne Roberts |
0:3ccfaf358115 | 20 | uint8_t a; |
Wayne Roberts |
0:3ccfaf358115 | 21 | int8_t b; |
Wayne Roberts |
0:3ccfaf358115 | 22 | int8_t c; |
Wayne Roberts |
0:3ccfaf358115 | 23 | } fields; |
Wayne Roberts |
0:3ccfaf358115 | 24 | uint8_t buf[5]; |
Wayne Roberts |
0:3ccfaf358115 | 25 | } irq_t; |
Wayne Roberts |
0:3ccfaf358115 | 26 | |
Wayne Roberts |
0:3ccfaf358115 | 27 | extern const uint8_t cmd_to_length[]; |