Skip to content

Commit 073cd4c

Browse files
committed
Moved macros that are not part of the twi API from twi.h to twi.cpp.
Replaced TWI_STATE preprocessor macro by enum TWI_STATE. Added #pragma once in twi.h.
1 parent 9cc9ada commit 073cd4c

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

libraries/Wire/src/utility/twi.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,22 @@
4040
#include "pins_arduino.h"
4141
#include "twi.h"
4242

43+
#ifndef TWI_FREQ
44+
#define TWI_FREQ 100000L
45+
#endif
46+
47+
#ifndef TWI_BUFFER_LENGTH
48+
#define TWI_BUFFER_LENGTH 32
49+
#endif
50+
51+
enum TWI_STATE {
52+
TWI_READY = 0,
53+
TWI_MRX = 1,
54+
TWI_MTX = 2,
55+
TWI_SRX = 3,
56+
TWI_STX = 4,
57+
};
58+
4359
static volatile uint8_t twi_state;
4460
static volatile uint8_t twi_slarw;
4561
static volatile uint8_t twi_sendStop; // should the transaction end with a stop

libraries/Wire/src/utility/twi.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,15 @@
1919
Modified 2020 by Greyson Christoforo ([email protected]) to implement timeouts
2020
*/
2121

22+
#pragma once
23+
2224
#ifndef twi_h
2325
#define twi_h
2426

2527
#include <inttypes.h>
2628

2729
//#define ATMEGA8
2830

29-
#ifndef TWI_FREQ
30-
#define TWI_FREQ 100000L
31-
#endif
32-
33-
#ifndef TWI_BUFFER_LENGTH
34-
#define TWI_BUFFER_LENGTH 32
35-
#endif
36-
37-
#define TWI_READY 0
38-
#define TWI_MRX 1
39-
#define TWI_MTX 2
40-
#define TWI_SRX 3
41-
#define TWI_STX 4
42-
4331
void twi_init(void);
4432
void twi_disable(void);
4533
void twi_setAddress(uint8_t);
@@ -56,4 +44,4 @@
5644
void twi_handleTimeout(bool);
5745
bool twi_manageTimeoutFlag(bool);
5846

59-
#endif
47+
#endif // #ifndef twi_h

0 commit comments

Comments
 (0)