NetBurner 3.5.8
PDF Version
Toggle main menu visibility
i2cfuncs.h
1
/*NB_REVISION*/
2
3
/*NB_COPYRIGHT*/
4
5
#ifndef _I2CFUNCS_H_
6
#define _I2CFUNCS_H_
7
8
#ifdef SUPPORTED_I2C_PLATFORM
9
10
#if (defined NANO54415 || defined MOD5441X || defined SB800EX)
11
#include <multichanneli2c.h>
12
#elif (defined SAME70)
13
#include <i2c.h>
14
#include <bb_i2c.h>
15
#else
16
#warning I2C features not supported for this platform
17
#endif
18
19
#ifdef __cplusplus
20
extern
"C"
21
{
22
#endif
23
24
#define I2C_MODULE_NUM 0
// use I2C0/TW0
25
#define I2C_BUS_SPEED (100000)
// bus speed of 100kHz
26
27
#define MAX_I2C_BUS_SPEED (400000)
// SAME70 specific value. Max bus speed for the TWI is 400 kHz in Fast Mode
28
#define I2C_LOW_ADDR_LIMIT (0x07)
29
#define I2C_HIGH_ADDR_LIMIT (0x78)
30
31
#define I2C_MAX_BUF_SIZE (64)
// Size allocated to input and output buffers in slave mode I2C
32
#define I2C_SLAVE_TX_TERM_CHAR (0)
// Terminating char to be sent when Slave TX buffer is empty
33
#define NB_FACTORY_I2C_ERR_VALUE (0)
// Error value if there is a failure to extract webpage form data
34
35
/* defined I2C Timeout values will be used if user does not include the 'ticks_to_wait'
36
parameter when calling I2C functions */
37
#define I2C_RX_TX_TIMEOUT (5)
// Ticks allowed before timeout of a single byte transmission
38
#define I2C_START_TIMEOUT (20)
// Ticks allowed before timeout when attempting start on I2C bus
39
40
#define I2C_MAX_WRITE_LEN (255)
41
#define I2C_MAX_READ_LEN (255)
42
// *2 to account for inputting values in a 2-digit hex format
43
#define MAX_BUFFER_LEN ((I2C_MAX_WRITE_LEN > I2C_MAX_READ_LEN) ? I2C_MAX_WRITE_LEN * 2 : I2C_MAX_READ_LEN * 2)
44
#define MAX_I2C_DEVICES (128)
45
46
// These are the values the NetBurner I2C functions will return
47
#define I2C_OK (0)
// Last instruction terminated correctly
48
#define I2C_NEXT_WRITE_OK (1)
// I2C bus is OK for a write
49
#define I2C_NEXT_READ_OK (2)
// I2C bus is OK for a read
50
#define I2C_MASTER_OK (3)
// I2C finished transmission but still owns but (need to stop or restart)
51
#define I2C_TIMEOUT (4)
// A timeout occurred while trying communicate on I2C bus
52
#define I2C_BUS_NOT_AVAIL (5)
// A timeout occurred while trying gain I2C bus control
53
#define I2C_NOT_READY (6)
// A read or write was attempted before I2C ready or during a slave transmission
54
#define I2C_LOST_ARB (7)
// Lost arbitration during start
55
#define I2C_LOST_ARB_ADD (8)
// Lost arbitration and then winner addressed our slave address
56
#define I2C_NO_LINK_RX_ACK (9)
// We are in Master TX mode and received no ACK from slave device, possibly during start
57
58
59
struct
ModuleI2CAddress_Struct
60
{
61
unsigned
char
byteAddress;
62
unsigned
char
asciiAddress[3];
63
};
64
65
// This structure stores the I2C address retrieved from Non-volatile memory
66
// typedef struct NVSettings_Struct
67
//{
68
// char slaveI2CAddress[3];
69
//};
70
71
// Stores ascii and byte versions of I2C parameters
72
struct
I2CParam_Struct
73
{
74
char
asciiAddress[3];
75
char
asciiData[MAX_BUFFER_LEN];
76
char
asciiLength[3];
77
unsigned
char
byteAddress;
78
unsigned
char
byteData;
79
unsigned
char
byteBuffer[MAX_BUFFER_LEN];
80
int
length;
81
};
82
83
// Used for handling the web I2C functions
84
struct
I2CWebFuncs_Struct
85
{
86
I2CParam_Struct WriteReadByteParams;
87
I2CParam_Struct WriteReadBufferParams;
88
I2CParam_Struct WriteByteParams;
89
I2CParam_Struct ReadByteParams;
90
I2CParam_Struct WriteBufferParams;
91
I2CParam_Struct ReadBufferParams;
92
};
93
94
// Used for handling the serial I2C functions
95
struct
SerialParams_Struct
96
{
97
// int strLen;
98
unsigned
char
buf[3];
99
unsigned
char
byteData;
100
unsigned
char
length;
101
unsigned
char
addr;
102
unsigned
char
byteToWrite;
103
unsigned
char
commBuffer[MAX_BUFFER_LEN];
104
};
105
106
struct
I2CBusStatus_Struct
107
{
108
volatile
uint8_t status;
109
const
char
*statusMsgs[7];
110
};
111
112
#if (defined SAME70)
113
extern
BBI2C
bbI2C;
114
void
InitI2C(uint32_t busSpeed = 0);
115
void
bbInitI2C(uint32_t busSpeed = 0);
116
int
bbI2CScan(
bool
*discovered);
117
#else
118
#error Multi_I2CInit declaration missing for defined platform
119
#endif
120
121
unsigned
char
Ascii2Byte(
char
*buf);
122
int
I2CScan(
bool
*discovered,
unsigned
char
slaveAddress);
123
void
I2CStatus();
124
125
#ifdef __cplusplus
126
}
127
128
#endif
// __cplusplus
129
#endif
// SUPPORTED_I2C_PLATFORM
130
#endif
// _I2CFUNCS_H_
BBI2C
Software (bit-banged) I2C master driver.
Definition
bb_i2c.h:153
examples
SSH
SecureSerToEthFactoryApp
src
i2cfuncs.h
Generated by
1.18.0