Skip to content

Commit 1bf0873

Browse files
authored
Cleanly separate IO handlers for different architectures. (#13)
1 parent d89d9e9 commit 1bf0873

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

src/PF1550.cpp

+8-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "PF1550/PF1550_IO_C33.h"
2828
#include "PF1550/PF1550_IO_Portenta_H7.h"
29+
#include "PF1550/PF1550_IO_Nicla_Vision.h"
2930

3031
/******************************************************************************
3132
CTOR/DTOR
@@ -160,10 +161,14 @@ void PF1550::configCharger(IFastCharge const i_fast_charge,
160161
EXTERN DEFINITION
161162
******************************************************************************/
162163

163-
#ifdef ARDUINO_PORTENTA_H33
164-
static PF1550_IO_C33 io(&Wire3, PF1550_I2C_DEFAULT_ADDR);
164+
#if defined(ARDUINO_PORTENTA_H33)
165+
static PF1550_IO_C33 io(&Wire3, PF1550_I2C_DEFAULT_ADDR);
166+
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M4)
167+
static PF1550_IO_Portenta_H7 io(&Wire1, PF1550_I2C_DEFAULT_ADDR);
168+
#elif defined(ARDUINO_NICLA_VISION)
169+
static PF1550_IO_Nicla_Vision io(&Wire1, PF1550_I2C_DEFAULT_ADDR);
165170
#else
166-
static PF1550_IO_Portenta_H7 io(&Wire1, PF1550_I2C_DEFAULT_ADDR);
171+
# error "No IO class defined for this board."
167172
#endif
168173

169174
PF1550 PMIC(io);

src/PF1550/PF1550_IO_Nicla_Vision.h

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright (c) 2019 Arduino. All right reserved.
3+
4+
This library is free software; you can redistribute it and/or
5+
modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 2.1 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12+
See the GNU Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General Public
15+
License along with this library; if not, write to the Free Software
16+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17+
*/
18+
19+
#ifndef PF1550_IO_NICLA_VISION_H_
20+
#define PF1550_IO_NICLA_VISION_H_
21+
22+
/******************************************************************************
23+
INCLUDE
24+
******************************************************************************/
25+
26+
#include "PF1550_IO.h"
27+
28+
/******************************************************************************
29+
CLASS DECLARATION
30+
******************************************************************************/
31+
32+
class PF1550_IO_Nicla_Vision : public PF1550_IO
33+
{
34+
public:
35+
PF1550_IO_Nicla_Vision(arduino::HardwareI2C * wire, uint8_t const i2c_addr) : PF1550_IO(wire, i2c_addr) { }
36+
virtual ~PF1550_IO_Nicla_Vision() { }
37+
38+
39+
protected:
40+
virtual int derived_begin() override { }
41+
};
42+
43+
#endif /* PF1550_IO_NICLA_VISION_H_ */

0 commit comments

Comments
 (0)