| 85 |
theseven |
1 |
//
|
|
|
2 |
//
|
|
|
3 |
// Copyright 2010 TheSeven
|
|
|
4 |
//
|
|
|
5 |
//
|
|
|
6 |
// This file is part of emBIOS.
|
|
|
7 |
//
|
|
|
8 |
// emBIOS is free software: you can redistribute it and/or
|
|
|
9 |
// modify it under the terms of the GNU General Public License as
|
|
|
10 |
// published by the Free Software Foundation, either version 2 of the
|
|
|
11 |
// License, or (at your option) any later version.
|
|
|
12 |
//
|
|
|
13 |
// emBIOS is distributed in the hope that it will be useful,
|
|
|
14 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
15 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
16 |
// See the GNU General Public License for more details.
|
|
|
17 |
//
|
|
|
18 |
// You should have received a copy of the GNU General Public License along
|
|
|
19 |
// with emBIOS. If not, see <http://www.gnu.org/licenses/>.
|
|
|
20 |
//
|
|
|
21 |
//
|
|
|
22 |
|
|
|
23 |
|
|
|
24 |
#include "global.h"
|
|
|
25 |
#include "i2c.h"
|
|
|
26 |
#include "thread.h"
|
|
|
27 |
#include "s5l8720.h"
|
|
|
28 |
|
|
|
29 |
|
|
|
30 |
static struct mutex i2cmutex;
|
|
|
31 |
static struct wakeup i2cwakeup;
|
|
|
32 |
|
|
|
33 |
|
|
|
34 |
void i2c_init()
|
|
|
35 |
{
|
|
|
36 |
mutex_init(&i2cmutex);
|
|
|
37 |
wakeup_init(&i2cwakeup);
|
|
|
38 |
|
|
|
39 |
interrupt_enable(IRQ_IIC, true);
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
void i2c_send(uint32_t bus, uint32_t device, uint32_t address, const uint8_t* data, uint32_t length)
|
|
|
43 |
{
|
|
|
44 |
mutex_lock(&i2cmutex, TIMEOUT_BLOCK);
|
|
|
45 |
|
|
|
46 |
mutex_unlock(&i2cmutex);
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
void i2c_recv(uint32_t bus, uint32_t device, uint32_t address, uint8_t* data, uint32_t length)
|
|
|
50 |
{
|
|
|
51 |
mutex_lock(&i2cmutex, TIMEOUT_BLOCK);
|
|
|
52 |
|
|
|
53 |
mutex_unlock(&i2cmutex);
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
void i2c_sendbyte(uint32_t bus, uint32_t device, uint32_t address, uint32_t data)
|
|
|
57 |
{
|
|
|
58 |
uint8_t buf[1];
|
|
|
59 |
buf[0] = data;
|
|
|
60 |
i2c_send(bus, device, address, buf, 1);
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
uint8_t i2c_recvbyte(uint32_t bus, uint32_t device, uint32_t address)
|
|
|
64 |
{
|
|
|
65 |
uint8_t buf[1];
|
|
|
66 |
i2c_recv(bus, device, address, buf, 1);
|
|
|
67 |
return buf[0];
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
void INT_IIC()
|
|
|
71 |
{
|
|
|
72 |
|
|
|
73 |
wakeup_signal(&i2cwakeup);
|
|
|
74 |
}
|