Skip to content

Commit d1df111

Browse files
committed
Added tiny_i2c double
1 parent 4359426 commit d1df111

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"maintainer": true
1414
}
1515
],
16-
"version": "7.1.3",
16+
"version": "7.2.0",
1717
"frameworks": "*",
1818
"platforms": "*",
1919
"export": {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*!
2+
* @file
3+
* @brief
4+
*/
5+
6+
#ifndef tiny_i2c_double_hpp
7+
#define tiny_i2c_double_hpp
8+
9+
extern "C" {
10+
#include "hal/i_tiny_i2c.h"
11+
}
12+
13+
typedef struct {
14+
i_tiny_i2c_t interface;
15+
} tiny_i2c_double_t;
16+
17+
/*!
18+
* Initializes an I2C double.
19+
*/
20+
void tiny_i2c_double_init(tiny_i2c_double_t* self);
21+
22+
#endif

test/src/tiny_i2c_double.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*!
2+
* @file
3+
* @brief
4+
*/
5+
6+
#include "CppUTestExt/MockSupport.h"
7+
#include "double/tiny_i2c_double.hpp"
8+
9+
static bool write(
10+
i_tiny_i2c_t* self,
11+
uint8_t address,
12+
bool prepare_for_restart,
13+
const void* buffer,
14+
uint16_t buffer_size)
15+
{
16+
return mock()
17+
.actualCall("write")
18+
.onObject(self)
19+
.withParameter("address", address)
20+
.withParameter("prepare_for_restart", prepare_for_restart)
21+
.withMemoryBufferParameter("buffer", reinterpret_cast<const uint8_t*>(buffer), buffer_size)
22+
.returnBoolValue();
23+
}
24+
25+
static bool read(
26+
i_tiny_i2c_t* self,
27+
uint8_t address,
28+
bool prepare_for_restart,
29+
void* buffer,
30+
uint16_t buffer_size)
31+
{
32+
(void)buffer_size;
33+
34+
return mock()
35+
.actualCall("read")
36+
.onObject(self)
37+
.withParameter("address", address)
38+
.withParameter("prepare_for_restart", prepare_for_restart)
39+
.withOutputParameter("buffer", buffer)
40+
.returnBoolValue();
41+
}
42+
43+
static void reset(i_tiny_i2c_t* self)
44+
{
45+
mock()
46+
.actualCall("reset")
47+
.onObject(self);
48+
}
49+
50+
static const i_tiny_i2c_api_t api = { write, read, reset };
51+
52+
void tiny_i2c_double_init(tiny_i2c_double_t* self)
53+
{
54+
self->interface.api = &api;
55+
}

0 commit comments

Comments
 (0)