-
Notifications
You must be signed in to change notification settings - Fork 0
/
i2c.h
73 lines (60 loc) · 1.23 KB
/
i2c.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* I2C (TwoWire) AVR library
*
* Copyright (C) 2015-2017 Sergey Denisov.
* Rewritten by Sergey Denisov aka LittleBuster (DenisovS21@gmail.com)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public Licence
* as published by the Free Software Foundation; either version 3
* of the Licence, or (at your option) any later version.
*/
#ifndef __I2C_H__
#define __I2C_H__
#include "stdbool.h"
#include <avr/io.h>
#include <util/twi.h>
#define TWI_FREQ 100000L
/*
* Init lib
*/
void i2c_init(void);
inline bool i2c_busy()
{
return ((TWCR & _BV(TWINT)) == 0);
}
inline uint8_t i2c_status()
{
return TW_STATUS;
}
/*
* Start sending data
*/
bool i2c_start_condition(void);
/*
* Stop sending data
*/
void i2c_stop_condition(void);
/**
* Send byte to device
* @byte: sending byte
*/
void i2c_send_byte(unsigned char byte);
/**
* Send packet to device
* @value: sending data
* @address: device address
*/
void i2c_send_packet(unsigned char value, unsigned char address);
/**
* Receive byte from device
*
* returns: byte
*/
uint8_t i2c_recv_byte(void);
/**
* Receiving last byte from device
*
* returns: byte
*/
uint8_t i2c_recv_last_byte(void);
#endif