Skip to content

Commit 4746a48

Browse files
committed
Merge branch 'feature/12' into develop
2 parents 9f360af + deb7c47 commit 4746a48

12 files changed

Lines changed: 154 additions & 196 deletions

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ History of the project development
44
## [Unreleased] yyyy-mm-zz
55
The issue #16 changes its public member function. But it is referred internally from ::rpp_driver::Adau1361 class. Not called by user program. Then, the major version number is not needed to change.
66

7+
The issue #12 removed public class I2cMasterInterface. But it is referred internal only for Unit test. So, the major version number is not needed to change.
8+
79
### Added
810
- [Issue #13](https://github.com/suikan4github/rpp_driver/issues/13) Exclude Mock definition from the GCov coverage.
911
### Changed
1012
- [Issue #10](https://github.com/suikan4github/rpp_driver/issues/10) Cover APIs of the Raspberry Pi Pico SDK.
1113
- [Issue #15](https://github.com/suikan4github/rpp_driver/issues/15) Remove the redundant parameter check code from ConfigureSRC()
1214
- [Issue #16](https://github.com/suikan4github/rpp_driver/issues/16) Change the member function name from ConfigureSRC() to ConfigureSrc().
1315
### Deprecated
16+
- [Issue #12](https://github.com/suikan4github/rpp_driver/issues/12) Is I2cMasterInterface needed?
1417
### Removed
1518
### Fixed
1619
- [Issue #11](https://github.com/suikan4github/rpp_driver/issues/11) Fails to compile in MSVC.

src/codec/adau1361.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
#include <assert.h>
1515

16-
#include "i2c/i2cmasterinterface.hpp"
16+
#include "i2c/i2cmaster.hpp"
1717

1818
// Macro for easy-to-read
1919
#define CODEC_SYSLOG(fmt, ...) \

src/codec/adau1361.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#ifndef PICO_DRIVER_SRC_CODEC_ADAU1361_HPP_
1111
#define PICO_DRIVER_SRC_CODEC_ADAU1361_HPP_
1212

13-
#include <i2c/i2cmasterinterface.hpp>
13+
#include <i2c/i2cmaster.hpp>
1414

1515
#include "adau1361lower.hpp"
1616
namespace rpp_driver {

src/codec/adau1361lower.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
#include <algorithm>
66

7-
rpp_driver::Adau1361Lower::Adau1361Lower(
8-
::rpp_driver::I2cMasterInterface& controller, unsigned int i2c_device_addr)
7+
rpp_driver::Adau1361Lower::Adau1361Lower(::rpp_driver::I2cMaster& controller,
8+
unsigned int i2c_device_addr)
99
: i2c_(controller), device_addr_(i2c_device_addr) {
1010
assert((0x3C > device_addr_) &&
1111
"ADAU1361 I2C Address must be lower than 0x3C.");

src/codec/adau1361lower.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class Adau1361Lower {
5454
* @param i2c_device_addr ADAU1361A 7bits I2C device address. Refer device
5555
* deta sheet for details.
5656
*/
57-
Adau1361Lower(::rpp_driver::I2cMasterInterface& controller,
57+
Adau1361Lower(::rpp_driver::I2cMaster& controller,
5858
unsigned int i2c_device_addr);
5959
Adau1361Lower() = delete;
6060
virtual ~Adau1361Lower() {}
@@ -224,7 +224,7 @@ class Adau1361Lower {
224224

225225
protected:
226226
/// @brief Internal variable to hold the I2C controller variable.
227-
::rpp_driver::I2cMasterInterface& i2c_;
227+
::rpp_driver::I2cMaster& i2c_;
228228
/// @brief Internal variable to hold the I2C device address.
229229
const unsigned int device_addr_;
230230
};
@@ -234,7 +234,7 @@ class Adau1361Lower {
234234
// GCOVR_EXCL_START
235235
class MockAdau1361Lower : public Adau1361Lower {
236236
public:
237-
explicit MockAdau1361Lower(::rpp_driver::I2cMasterInterface& controller)
237+
explicit MockAdau1361Lower(::rpp_driver::I2cMaster& controller)
238238
: Adau1361Lower(controller, 0x3A) {};
239239
MOCK_METHOD2(SendCommand, void(const uint8_t command[], int size));
240240
MOCK_METHOD2(SendCommandTable, void(const uint8_t table[][3], int rows));

src/codec/umbadau1361lower.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class UmbAdau1361Lower : public Adau1361Lower {
3232
* @param i2c_device_addr ADAU1361A 7bits I2C device address. Refer device
3333
* deta sheet for details.
3434
*/
35-
UmbAdau1361Lower(::rpp_driver::I2cMasterInterface& controller,
35+
UmbAdau1361Lower(::rpp_driver::I2cMaster& controller,
3636
unsigned int i2c_device_addr)
3737
: Adau1361Lower(controller, i2c_device_addr) {}
3838
UmbAdau1361Lower() = delete;

src/i2c/i2cmaster.hpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ typedef int i2c_inst_t;
2525
#define GPIO_FUNC_I2C 11
2626
#endif // __has_include(<hardware/i2c.h>)
2727

28-
#include "i2c/i2cmasterinterface.hpp"
2928
#include "sdk/sdkwrapper.hpp"
3029

3130
namespace rpp_driver {
@@ -43,7 +42,7 @@ namespace rpp_driver {
4342
* the restart condition, set this parameter to true.
4443
*
4544
*/
46-
class I2cMaster : public I2cMasterInterface {
45+
class I2cMaster {
4746
public:
4847
/**
4948
* @brief Initialize the given I2C port and setup the pins.
@@ -77,8 +76,7 @@ class I2cMaster : public I2cMasterInterface {
7776
* not acknowledged or no device present.
7877
*/
7978

80-
int ReadBlocking(uint8_t addr, uint8_t *dst, size_t len,
81-
bool nostop) override;
79+
virtual int ReadBlocking(uint8_t addr, uint8_t *dst, size_t len, bool nostop);
8280
/**
8381
* @brief Attempt to write specified number of bytes to address, blocking.
8482
* @param addr 7-bit address of device to write to
@@ -90,21 +88,41 @@ class I2cMaster : public I2cMasterInterface {
9088
* @returns Number of bytes written, or PICO_ERROR_GENERIC
9189
* if address not acknowledged, no device present.
9290
*/
93-
int WriteBlocking(uint8_t addr, const uint8_t *src, size_t len,
94-
bool nostop) override;
91+
virtual int WriteBlocking(uint8_t addr, const uint8_t *src, size_t len,
92+
bool nostop);
9593

9694
/**
9795
* @brief Check wether device at specified I2C address exists or not.
9896
* @param addr 7-bit address of device to read from
9997
* @returns true if exist, false if not exist.
10098
*/
10199

102-
bool IsDeviceExisting(uint8_t addr) override;
100+
virtual bool IsDeviceExisting(uint8_t addr);
103101

104102
private:
105103
i2c_inst_t &i2c_;
106104
SdkWrapper &sdk_;
105+
}; // I2cMaster
106+
107+
#if __has_include(<gmock/gmock.h>)
108+
// GCOVR_EXCL_START
109+
class MockI2cMaster : public I2cMaster {
110+
private:
111+
i2c_inst_t dummy_i2c = 3;
112+
113+
public:
114+
MockI2cMaster(SdkWrapper &sdk)
115+
: I2cMaster(sdk, dummy_i2c, 100'000, 10, 11) {
116+
}; // Sdk wrapper and dummy parameters.
117+
MOCK_METHOD4(ReadBlocking,
118+
int(uint8_t addr, uint8_t *dst, size_t len, bool nostop));
119+
MOCK_METHOD4(WriteBlocking,
120+
int(uint8_t addr, const uint8_t *src, size_t len, bool nostop));
121+
MOCK_METHOD1(IsDeviceExisting, bool(uint8_t addr));
107122
};
123+
// GCOVR_EXCL_STOP
124+
#endif // __has_include(<gmock/gmock.h>)
125+
108126
}; // namespace rpp_driver
109127

110128
#endif /* PICO_DRIVER_SRC_I2C_I2CMASATER_HPP_ */

src/i2c/i2cmasterinterface.hpp

Lines changed: 0 additions & 84 deletions
This file was deleted.

test/test_adau1361.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,26 @@
33

44
#include "codec/adau1361.hpp"
55
#include "codec/umbadau1361lower.hpp"
6-
#include "i2c/i2cmasterinterface.hpp"
6+
#include "i2c/i2cmaster.hpp"
77

88
class Adau1361Test : public ::testing::Test {
99
protected:
1010
virtual void SetUp() {
11-
codec_lower_ = new ::rpp_driver::MockAdau1361Lower(i2c_);
11+
i2c_ = new ::rpp_driver::MockI2cMaster(sdk_);
12+
codec_lower_ = new ::rpp_driver::MockAdau1361Lower(*i2c_);
1213
codec_ = new ::rpp_driver::Adau1361(fs_, master_clk_, *codec_lower_);
1314
}
1415

1516
virtual void TearDown() {
1617
delete codec_;
1718
delete codec_lower_;
19+
delete i2c_;
1820
}
1921

2022
uint fs_ = 48000;
2123
uint master_clk_ = 12000000;
22-
::rpp_driver::MockI2cMasterInterface i2c_;
24+
::rpp_driver::SdkWrapper sdk_;
25+
::rpp_driver::MockI2cMaster *i2c_;
2326
::rpp_driver::MockAdau1361Lower *codec_lower_;
2427
::rpp_driver::Adau1361 *codec_;
2528
};

0 commit comments

Comments
 (0)