Skip to content

Commit 19a45ad

Browse files
committed
wip
1 parent a9c7599 commit 19a45ad

File tree

9 files changed

+151
-110
lines changed

9 files changed

+151
-110
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: build
1+
name: build examples
22

33
on: [pull_request, push]
44

@@ -32,7 +32,7 @@ jobs:
3232
python -m pip install --upgrade pip
3333
pip install --upgrade platformio
3434
- name: Run PlatformIO
35-
run: pio ci -c platformio.ini --lib=src/
35+
run: pio ci -c platformio_ci.ini --lib=src/
3636
env:
3737
PLATFORMIO_CI_SRC: ${{ matrix.example }}
3838

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ repos:
1616
# - id: clang-format
1717
# args: ["-style=file"]
1818
- id: cpplint
19-
# - id: cppcheck
19+
- id: cppcheck

platformio.ini

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
description = Library to support Microchip MPC3x6xR 16/24bit analog to digital converters.
1313

1414
[env]
15+
check_tool = cppcheck, clangtidy
1516
test_build_src = yes
1617

1718
# Arduino UNO shaped boards
@@ -82,10 +83,3 @@ board = esp32-c3-devkitc-02
8283
framework = arduino
8384
platform = teensy
8485
board = teensy40
85-
86-
87-
# native / CI / Fake
88-
89-
[env:native]
90-
platform = native
91-
#build_type = test

platformio_ci.ini

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
[platformio]
2+
extra_configs = platformio.ini
3+
4+
[ci]
5+
;platform = native
6+
lib_deps =
7+
ArduinoFake=https://github.com/FabioBatSilva/ArduinoFake
8+
build_flags =
9+
-DPIO_NATIVE_TESTING
10+
-std=gnu++17
11+
-frtti
12+
-fexceptions
13+
#build_unflags =
14+
# -std=gnu++11
15+
# -fno-rtti
16+
# -fno-exceptions
17+
18+
# extends board config
19+
20+
[env:ESP32_ci]
21+
extends = ci, env:ESP32
22+
23+
[env:ESP8266_ci]
24+
extends = ci, env:ESP8266
25+
26+
[env:ATMEGA328P_ci]
27+
extends = ci, env:ATMEGA328P
28+
29+
[env:SAMD21G18A_ci]
30+
extends = ci, env:SAMD21G18A
31+
32+
[env:SAMD51P20A_ci]
33+
extends = ci, env:SAMD51P20A
34+
35+
[env:ATMEGA32U4_ci]
36+
extends = ci, env:ATMEGA32U4
37+
38+
[env:STM32F405RGT6_ci]
39+
extends = ci, env:STM32F405RGT6
40+
41+
[env:NRF52832_ci]
42+
extends = ci, env:NRF52832
43+
44+
[env:ESP32-S3_ci]
45+
extends = ci, env:ESP32-S3
46+
47+
[env:ESP32-C3_ci]
48+
extends = ci, env:ESP32-C3
49+
50+
[env:IMXRT1062_ci]
51+
extends = ci, env:IMXRT1062

src/MCP3x6x.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313

1414
#include "MCP3x6x.h"
1515

16-
#include <wiring_private.h>
16+
// #ifdef ARDUINO_ARCH_SAMD
17+
// # include <wiring_private.h>
18+
// #endif
1719

1820
MCP3x6x::MCP3x6x(const uint16_t MCP3x6x_DEVICE_TYPE, const uint8_t pinCS, SPIClass *theSPI,
1921
const uint8_t pinMOSI, const uint8_t pinMISO, const uint8_t pinCLK) {
@@ -43,7 +45,6 @@ MCP3x6x::MCP3x6x(const uint16_t MCP3x6x_DEVICE_TYPE, const uint8_t pinCS, SPICla
4345
_channels_max = 8;
4446
break;
4547
default:
46-
#warning "undefined MCP3x6x_DEVICE_TYPE"
4748
break;
4849
}
4950

@@ -94,12 +95,12 @@ bool MCP3x6x::begin(uint16_t channelmask, float vref) {
9495
digitalWrite(_pinCS, HIGH);
9596

9697
_spi->begin();
97-
#if ARDUINO_ARCH_SAMD
98-
// todo figure out how to get dynamicaly sercom index
99-
pinPeripheral(_pinMISO, PIO_SERCOM);
100-
pinPeripheral(_pinMOSI, PIO_SERCOM);
101-
pinPeripheral(_pinCLK, PIO_SERCOM);
102-
#endif
98+
// #if ARDUINO_ARCH_SAMD
99+
// // todo figure out how to get dynamicaly sercom index
100+
// pinPeripheral(_pinMISO, PIO_SERCOM);
101+
// pinPeripheral(_pinMOSI, PIO_SERCOM);
102+
// pinPeripheral(_pinCLK, PIO_SERCOM);
103+
// #endif
103104

104105
_status = reset();
105106
setClockSelection(clk_sel::INTERN); // todo make configurable by function parameter

src/MCP3x6x.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,6 @@
1616

1717
#define MCP3x6x_DEBUG DEBUG //!< sets debug active
1818

19-
#if ARDUINO >= 100
20-
# include "Arduino.h"
21-
#else
22-
# include "WProgram.h"
23-
#endif
24-
2519
#include <SPI.h>
2620

2721
#define MCP_OFFSET (0x88) //!< corresponding mux setting
@@ -88,6 +82,10 @@
8882
#define MCP3x6x_ADR_RESERVED3 (MCP3x6x_SPI_ADR | (0xE << 2)) //!< Register
8983
#define MCP3x6x_ADR_CRCCFG (MCP3x6x_SPI_ADR | (0xF << 2)) //!< Register CRCCFG address
9084

85+
// #ifdef __cplusplus
86+
// extern "C" {
87+
// #endif
88+
9189
/**
9290
* @brief base class
9391
*
@@ -1317,4 +1315,8 @@ class MCP3564 : public MCP3x6x {
13171315
*/
13181316
extern void mcp_wrapper();
13191317

1318+
// #ifdef __cplusplus
1319+
// }
1320+
// #endif // __cplusplus
1321+
13201322
#endif // SRC_MCP3X6X_H_

test/test_MCP3461/test_MCP3461.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
/**
4+
* @file test_MCP3461.cpp
5+
* @author Stefan Herold (stefan.herold@posteo.de)
6+
* @brief
7+
* @version 0.0.2
8+
* @date 2023-10-10
9+
*
10+
* @copyright Copyright (c) 2023
11+
*
12+
*/
13+
14+
#ifdef PIO_NATIVE_TESTING
15+
// # ifdef __cplusplus
16+
# include <ArduinoFake.h>
17+
using fakeit;
18+
namespace fakeit;
19+
// # endif
20+
#endif
21+
22+
#include <unity.h>
23+
24+
#include "MCP3x6x.h"
25+
#include "test_MCP3461.h"
26+
27+
void setup(void) {
28+
// Wait ~2 seconds before the Unity test runner
29+
// establishes connection with a board Serial interface
30+
delay(2000);
31+
32+
runUnityTests();
33+
}
34+
35+
void loop(void) {}
36+
37+
int runUnityTests(void) {
38+
UNITY_BEGIN();
39+
40+
RUN_TEST(test_instance);
41+
42+
return UNITY_END();
43+
}
44+
45+
void suiteSetUp(void) {
46+
#ifdef PIO_NATIVE_TESTING
47+
48+
ArduinoFakeReset();
49+
When(Method(ArduinoFake(), sei)).AlwaysReturn();
50+
When(Method(ArduinoFake(), cli)).AlwaysReturn();
51+
When(Method(ArduinoFake(), digitalWrite)).AlwaysReturn();
52+
When(Method(ArduinoFake(), pinMode)).AlwaysReturn();
53+
When(Method(ArduinoFake(), attachInterrupt)).AlwaysReturn();
54+
When(OverloadedMethod(ArduinoFake(SPI), begin, void(void))).AlwaysReturn();
55+
When(OverloadedMethod(ArduinoFake(SPI), end, void(void))).AlwaysReturn();
56+
When(OverloadedMethod(ArduinoFake(SPI), beginTransaction, void(SPISettings))).AlwaysReturn();
57+
When(OverloadedMethod(ArduinoFake(SPI), endTransaction, void(void))).AlwaysReturn();
58+
When(OverloadedMethod(ArduinoFake(SPI), transfer, byte(uint8_t))).AlwaysReturn();
59+
When(OverloadedMethod(ArduinoFake(SPI), transfer, void(void *, size_t))).AlwaysReturn();
60+
#endif
61+
}
62+
63+
void suiteTearDown(void) {}
64+
65+
void setUp(void) {}
66+
67+
void tearDown(void) {}
68+
69+
// actual test cases
70+
71+
void test_instance(void) { MCP3461 mcp(); }
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// SPDX-License-Identifier: MIT
22

33
/**
4-
* @file test_MCP3x6x.h
4+
* @file test_MCP3461.h
55
* @author Stefan Herold (stefan.herold@posteo.de)
66
* @brief
77
* @version 0.0.2
@@ -11,22 +11,17 @@
1111
*
1212
*/
1313

14-
#ifndef TEST_TEST_MCP3X6X_H_
15-
#define TEST_TEST_MCP3X6X_H_
14+
#ifndef TEST_TEST_MCP3461_TEST_MCP3461_H_
15+
#define TEST_TEST_MCP3461_TEST_MCP3461_H_
1616

17-
#ifdef __cplusplus
18-
extern "C" {
19-
#endif
17+
int runUnityTests(void);
18+
19+
void suiteSetUp(void);
20+
void suiteTearDown(void);
2021

2122
void setUp(void);
2223
void tearDown(void);
23-
int runUnityTests(void);
24-
25-
#ifdef __cplusplus
26-
}
27-
#endif
2824

29-
// tests
3025
void test_instance(void);
3126

32-
#endif // TEST_TEST_MCP3X6X_H_
27+
#endif // TEST_TEST_MCP3461_TEST_MCP3461_H_

test/test_MCP3x6x.cpp

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

0 commit comments

Comments
 (0)