-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathi2c.cpp
More file actions
89 lines (74 loc) · 1.71 KB
/
Copy pathi2c.cpp
File metadata and controls
89 lines (74 loc) · 1.71 KB
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <i2c.h>
#include <irserror.h>
#include <string.h>
using namespace irs;
spi_to_i2c_t::spi_to_i2c_t(i2c_t *a_i2c, irs_u16 a_addr_device, irs_u16 a_buffer_size):
mp_i2c(a_i2c),
m_address_device(a_addr_device),
m_buffer_size(a_buffer_size),
mp_buffer(new irs_u8 [a_buffer_size]())
{
IRS_ASSERT((m_buffer_size != 0) && (mp_buffer != nullptr));
}
void spi_to_i2c_t::write(const irs_u8 *ap_buf, irs_uarc a_size)
{
IRS_ASSERT((a_size != 0) && (ap_buf != nullptr));
memcpy(mp_buffer, ap_buf, a_size);
mp_i2c->set_device_address(m_address_device);
mp_i2c->write(const_cast<irs_u8*>(mp_buffer), a_size);
}
void spi_to_i2c_t::read(irs_u8 *ap_buf,irs_uarc a_size)
{
mp_i2c->set_device_address(m_address_device);
mp_i2c->read(ap_buf, a_size);
}
spi_to_i2c_t::status_t spi_to_i2c_t::get_status()
{
return (mp_i2c->is_free()) ? FREE : BUSY;
}
void spi_to_i2c_t::lock()
{
mp_i2c->lock();
}
void spi_to_i2c_t::unlock()
{
mp_i2c->unlock();
}
bool spi_to_i2c_t::get_lock()
{
return mp_i2c->get_lock();
}
void spi_to_i2c_t::tick()
{
mp_i2c->tick();
}
void spi_to_i2c_t::abort()
{
mp_i2c->abort();
}
bool spi_to_i2c_t::set_data_size(irs_u16 /* a_data_size */)
{
return true;
}
bool spi_to_i2c_t::set_bitrate(irs_u32 /* a_bitrate */)
{
return true;
}
bool spi_to_i2c_t::set_polarity(polarity_t /* a_polarity */)
{
return true;
}
bool spi_to_i2c_t::set_phase(phase_t /* a_phase */)
{
return true;
}
bool spi_to_i2c_t::set_order(order_t /* a_order */)
{
return true;
}
void read_write(irs_u8 *ap_read_buf, const irs_u8 *ap_write_buf, irs_uarc a_size)
{
(void)ap_read_buf;
(void)ap_write_buf;
(void)a_size;
}