oled 1.0
OLED Graphics Control Library
Loading...
Searching...
No Matches
twi_soft.h
Go to the documentation of this file.
1
19
20#ifndef TWI_SOFT_H_
21#define TWI_SOFT_H_
22
23 #ifndef F_CPU
31 #define F_CPU 20000000UL
32 #endif
33
34 #ifndef F_SOFT_TWI
42 #define F_SOFT_TWI 100000UL
43 #endif
44
45 #ifndef TWI_SOFT_CLOCK_PULSE_US
53 #define TWI_SOFT_CLOCK_PULSE_US (float)(1000000.0/(F_SOFT_TWI<<1))
54 #endif
55
56 #ifndef TWI_SOFT_PULLUP_ENABLE
64 #define TWI_SOFT_PULLUP_ENABLE
65
66 #ifdef _DOXYGEN_ // Used for documentation, can be ignored
67 #define TWI_SOFT_PULLUP_ENABLE
68 #endif
69 #endif
70
71 #ifndef TWI_SOFT_PORT
79 #define TWI_SOFT_PORT PORTD
80 #endif
81
82 #ifndef TWI_SOFT_SCL
90 #define TWI_SOFT_SCL SET_PIN(2, _bm)
91
92 #ifndef TWI_SOFT_SCL_CTRL
93 #define TWI_SOFT_SCL_CTRL SET_PIN(2, CTRL)
94 #endif
95 #endif
96
97 #ifndef TWI_SOFT_SDA
105 #define TWI_SOFT_SDA SET_PIN(3, _bm)
106
107 #ifndef TWI_SOFT_SDA_CTRL
108 #define TWI_SOFT_SDA_CTRL SET_PIN(3, CTRL)
109 #endif
110 #endif
111
125 #ifndef TWI_SOFT_STATUS
126 #define TWI_SOFT_STATUS_BUS_INIT_COMPLETE 0x00
127 #define TWI_SOFT_STATUS_TRANSMIT 0x01
128 #define TWI_SOFT_STATUS_RECEIVE 0x02
129 #define TWI_SOFT_STATUS_BUS_ERROR 0xFF
130 #endif
132
133 #ifndef TWI_SOFT_BLOCK_IE
144 // #define TWI_SOFT_BLOCK_IE
145
146 #ifdef _DOXYGEN_ // Used for documentation, can be ignored
147 #define TWI_SOFT_BLOCK_IE
148 #endif
149 #endif
150
151 #include <limits.h>
152 #include <avr/io.h>
153 #include <util/delay.h>
154
155 #ifdef TWI_SOFT_BLOCK_IE
156 #include <avr/interrupt.h>
157 #endif
158
162
171 #define SCL_LOW() { TWI_SOFT_PORT.OUTCLR = TWI_SOFT_SCL; TWI_SOFT_PORT.DIRSET = TWI_SOFT_SCL; }
172 #define SDA_LOW() { TWI_SOFT_PORT.OUTCLR = TWI_SOFT_SDA; TWI_SOFT_PORT.DIRSET = TWI_SOFT_SDA; }
173 #define SCL_HIGH() { TWI_SOFT_PORT.DIRCLR = TWI_SOFT_SCL; TWI_SOFT_PORT.OUTCLR = TWI_SOFT_SCL; }
174 #define SDA_HIGH() { TWI_SOFT_PORT.DIRCLR = TWI_SOFT_SDA; TWI_SOFT_PORT.OUTCLR = TWI_SOFT_SDA; }
176
177 unsigned char twi_soft_init(void);
178 void twi_soft_disable(void);
179 unsigned char twi_soft_status(void);
180
182 void twi_soft_stop(void);
183 TWI_Error twi_soft_address(unsigned char address, TWI_Operation operation);
184 TWI_Error twi_soft_set(unsigned char data);
185 TWI_Error twi_soft_get(unsigned char *data, TWI_Acknowledge acknowledge);
186
187#endif /* TWI_SOFT_H_ */
Macro definitions for port operations.
Macro definitions for TWI/I2C communication flags and operations.
Enumerations for TWI/I2C interface modes, operations, acknowledgment, and error codes.
enum TWI_Acknowledge_t TWI_Acknowledge
Alias for enum TWI_Acknowledge_t representing TWI acknowledge mode.
Definition TWI_enums.h:66
enum TWI_Operation_t TWI_Operation
Alias for enum TWI_Operation_t representing TWI operation modes.
Definition TWI_enums.h:48
enum TWI_Error_t TWI_Error
Alias for enum TWI_Error_t representing TWI error status.
Definition TWI_enums.h:89
void twi_soft_stop(void)
Stop the TWI (I2C) transmission.
Definition twi_soft.c:116
TWI_Error twi_soft_address(unsigned char address, TWI_Operation operation)
Sends the slave address with the read/write operation on the TWI bus.
Definition twi_soft.c:140
TWI_Error twi_soft_get(unsigned char *data, TWI_Acknowledge acknowledge)
Reads a byte of data from the TWI bus and sends an ACK or NACK.
Definition twi_soft.c:216
TWI_Error twi_soft_set(unsigned char data)
Transmit a byte of data on the TWI bus.
Definition twi_soft.c:156
void twi_soft_disable(void)
Disable the software TWI (I2C) interface.
Definition twi_soft.c:56
unsigned char twi_soft_status(void)
Get the current status of the software TWI bus.
Definition twi_soft.c:70
unsigned char twi_soft_init(void)
Initialize the software TWI (I2C) bus.
Definition twi_soft.c:32
TWI_Error twi_soft_start(void)
Generate a TWI start or repeated start condition.
Definition twi_soft.c:87