-
Notifications
You must be signed in to change notification settings - Fork 141
/
I2CHost.h
55 lines (44 loc) · 1.48 KB
/
I2CHost.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
/*
* Copyright (C) 2019 by Andy Uribe CA6JAU
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#if !defined(I2CHost_H)
#define I2CHost_H
#include "Config.h"
#if defined(STM32_I2C_HOST)
#define I2C_CLK_FREQ 100000U
#define I2C_TX_FIFO_SIZE 512U
#define I2C_RX_FIFO_SIZE 512U
class CI2CHost {
public:
CI2CHost();
void Init(void);
void I2C_EVHandler(void);
uint8_t AvailI2C(void);
uint8_t ReadI2C(void);
void WriteI2C(const uint8_t* data, uint16_t length);
private:
void I2C2_ClearFlag(void);
uint16_t txFIFO_level(void);
uint16_t rxFIFO_level(void);
uint8_t txFIFO_put(uint8_t next);
volatile uint8_t txFIFO[I2C_TX_FIFO_SIZE];
volatile uint8_t rxFIFO[I2C_RX_FIFO_SIZE];
volatile uint16_t txFIFO_head, txFIFO_tail;
volatile uint16_t rxFIFO_head, rxFIFO_tail;
};
#endif
#endif