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

Committer:
Wayne Roberts
Date:
2019-02-03
Revision:
3:0288d257446a
Parent:
2:d7e05c75f240

File content as of revision 3:0288d257446a:


#define CMD_TEST3               0x00
#define CMD_TEST12              0x01
#define CMD_TEST32              0x02
#define CMD_IRQ                 0x03
#define CMD_BUFFER              0x04

#define CMD_TIMEOUT             0xfd    // indication of smbus timeout
#define CMD_ARLO                0xfe    // indication of arbitration lost
#define CMD_BUSERR              0xff    // indication of start or stop during transfer

typedef union {
    struct __attribute__((packed)) {
        struct {
            uint8_t button  : 1;    // 0
            uint8_t xyz     : 1;    // 1
            uint8_t res     : 6;    // 2,3,4,5,6,7
        } flags;
        uint8_t cnt;     // if flags.button
        uint8_t a;
        int8_t b;
        int8_t c;
    } fields;
    uint8_t buf[5];
} irq_t;

extern const uint8_t cmd_to_length[];