forked from CalcProgrammer1/Stepper-Motor-Controller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
usi_i2c_slave.h
43 lines (30 loc) · 1.27 KB
/
usi_i2c_slave.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*! \file
USI I2C Slave Driver
copyright (c) 2015 Joerg Albert <[email protected]>
This implementation is based on the one from
Adam Honse (https://github.com/CalcProgrammer1/Stepper-Motor-Controller)
but uses function pointer to process and generate the
data received/transmitted.
DESCRIPTION:
Call for initialisation
USI_I2C_Slave_Init(slave_addr, read_proc, write_proc)
where
slave_addr - the TWI slave address (8 bit)
read_proc - gets called on every read access from the master; the signature is
uint8_t read_proc(uint8_t index)
where index is the number of the data byte in the current read access
write_proc - gets called on every write access from the master; the signature is
bool write_proc(uint8_t data, uint8_t index)
where index is the number of the data byte in the current write access
and data is the byte just written by the master
This procedure returns false if the slave shall assert NAK immediately
*/
#ifndef USI_I2C_SLAVE_H
#define USI_I2C_SLAVE_H
#include <stdint.h>
#include <avr/io.h>
#include <avr/interrupt.h>
typedef uint8_t (*ReadProc_t)(uint8_t);
typedef bool (*WriteProc_t)(uint8_t, uint8_t);
void USI_I2C_Slave_Init(uint8_t address, ReadProc_t rproc, WriteProc_t wproc);
#endif /* #ifndef USI_I2C_SLAVE_H */