aboutsummaryrefslogtreecommitdiff
path: root/drivers/avr/TWIlib.h
diff options
context:
space:
mode:
authorJack Humbert <jack.humb@gmail.com>2018-05-08 15:24:18 -0400
committerGitHub <noreply@github.com>2018-05-08 15:24:18 -0400
commit14b7602a65dedaf51db1c9288144765d43a83a15 (patch)
tree8e21e6b77db1581deaeecfa3373fe70470e64c1f /drivers/avr/TWIlib.h
parent46dca121fd2f51c4f5b87e48af37f43340591433 (diff)
downloadqmk_firmware-14b7602a65dedaf51db1c9288144765d43a83a15.tar.gz
qmk_firmware-14b7602a65dedaf51db1c9288144765d43a83a15.zip
Adds IS31FL3731 RGB Matrix Implementation (#2910)
* adds is31fl3731 rgb matrix implementation * fix build script for force pushes * allow bootloader size to be overwritten * adds planck light implementation * split led config into 2 arrays * idk * betterize register handling * update planck implementation * update planck * refine rgb interface * cleanup names, rgb matrix * start documentation * finish up docs * add effects list * clean-up merge * add RGB_MATRIX_SKIP_FRAMES * add support for at90usb1286 to bootloader options
Diffstat (limited to 'drivers/avr/TWIlib.h')
-rw-r--r--drivers/avr/TWIlib.h82
1 files changed, 82 insertions, 0 deletions
diff --git a/drivers/avr/TWIlib.h b/drivers/avr/TWIlib.h
new file mode 100644
index 000000000..23fd1f09a
--- /dev/null
+++ b/drivers/avr/TWIlib.h
@@ -0,0 +1,82 @@
1/*
2 * TWIlib.h
3 *
4 * Created: 6/01/2014 10:38:42 PM
5 * Author: Chris Herring
6 * http://www.chrisherring.net/all/tutorial-interrupt-driven-twi-interface-for-avr-part1/
7 */
8
9
10#ifndef TWILIB_H_
11#define TWILIB_H_
12// TWI bit rate (was 100000)
13#define TWI_FREQ 400000
14// Get TWI status
15#define TWI_STATUS (TWSR & 0xF8)
16// Transmit buffer length
17#define TXMAXBUFLEN 20
18// Receive buffer length
19#define RXMAXBUFLEN 20
20// Global transmit buffer
21uint8_t TWITransmitBuffer[TXMAXBUFLEN];
22// Global receive buffer
23volatile uint8_t TWIReceiveBuffer[RXMAXBUFLEN];
24// Buffer indexes
25volatile int TXBuffIndex; // Index of the transmit buffer. Is volatile, can change at any time.
26int RXBuffIndex; // Current index in the receive buffer
27// Buffer lengths
28int TXBuffLen; // The total length of the transmit buffer
29int RXBuffLen; // The total number of bytes to read (should be less than RXMAXBUFFLEN)
30
31typedef enum {
32 Ready,
33 Initializing,
34 RepeatedStartSent,
35 MasterTransmitter,
36 MasterReceiver,
37 SlaceTransmitter,
38 SlaveReciever
39 } TWIMode;
40
41 typedef struct TWIInfoStruct{
42 TWIMode mode;
43 uint8_t errorCode;
44 uint8_t repStart;
45 }TWIInfoStruct;
46TWIInfoStruct TWIInfo;
47
48
49// TWI Status Codes
50#define TWI_START_SENT 0x08 // Start sent
51#define TWI_REP_START_SENT 0x10 // Repeated Start sent
52// Master Transmitter Mode
53#define TWI_MT_SLAW_ACK 0x18 // SLA+W sent and ACK received
54#define TWI_MT_SLAW_NACK 0x20 // SLA+W sent and NACK received
55#define TWI_MT_DATA_ACK 0x28 // DATA sent and ACK received
56#define TWI_MT_DATA_NACK 0x30 // DATA sent and NACK received
57// Master Receiver Mode
58#define TWI_MR_SLAR_ACK 0x40 // SLA+R sent, ACK received
59#define TWI_MR_SLAR_NACK 0x48 // SLA+R sent, NACK received
60#define TWI_MR_DATA_ACK 0x50 // Data received, ACK returned
61#define TWI_MR_DATA_NACK 0x58 // Data received, NACK returned
62
63// Miscellaneous States
64#define TWI_LOST_ARBIT 0x38 // Arbitration has been lost
65#define TWI_NO_RELEVANT_INFO 0xF8 // No relevant information available
66#define TWI_ILLEGAL_START_STOP 0x00 // Illegal START or STOP condition has been detected
67#define TWI_SUCCESS 0xFF // Successful transfer, this state is impossible from TWSR as bit2 is 0 and read only
68
69
70#define TWISendStart() (TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN)|(1<<TWIE)) // Send the START signal, enable interrupts and TWI, clear TWINT flag to resume transfer.
71#define TWISendStop() (TWCR = (1<<TWINT)|(1<<TWSTO)|(1<<TWEN)|(1<<TWIE)) // Send the STOP signal, enable interrupts and TWI, clear TWINT flag.
72#define TWISendTransmit() (TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWIE)) // Used to resume a transfer, clear TWINT and ensure that TWI and interrupts are enabled.
73#define TWISendACK() (TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWIE)|(1<<TWEA)) // FOR MR mode. Resume a transfer, ensure that TWI and interrupts are enabled and respond with an ACK if the device is addressed as a slave or after it receives a byte.
74#define TWISendNACK() (TWCR = (1<<TWINT)|(1<<TWEN)|(1<<TWIE)) // FOR MR mode. Resume a transfer, ensure that TWI and interrupts are enabled but DO NOT respond with an ACK if the device is addressed as a slave or after it receives a byte.
75
76// Function declarations
77uint8_t TWITransmitData(void *const TXdata, uint8_t dataLen, uint8_t repStart);
78void TWIInit(void);
79uint8_t TWIReadData(uint8_t TWIaddr, uint8_t bytesToRead, uint8_t repStart);
80uint8_t isTWIReady(void);
81
82#endif // TWICOMMS_H_ \ No newline at end of file