Skip to content

Commit b84a589

Browse files
committed
Provide abstract base class HardwareCAN (prepare for ArduinoCore-API).
1 parent 069effb commit b84a589

File tree

6 files changed

+84
-44
lines changed

6 files changed

+84
-44
lines changed

Diff for: libraries/CAN/src/CanConst.h

-26
This file was deleted.

Diff for: libraries/CAN/src/CanUtil.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include <tuple>
2121

22-
#include "CanConst.h"
22+
#include "HardwareCAN.h"
2323

2424
/**************************************************************************************
2525
* NAMESPACE

Diff for: libraries/CAN/src/HardwareCAN.h

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright (c) 2022 by Alexander Entinger <[email protected]>
3+
* CAN library for Arduino.
4+
*
5+
* This file is free software; you can redistribute it and/or modify
6+
* it under the terms of either the GNU General Public License version 2
7+
* or the GNU Lesser General Public License version 2.1, both as
8+
* published by the Free Software Foundation.
9+
*/
10+
11+
#ifndef ARDUINOCORE_RENESAS_HARDWARECAN_H
12+
#define ARDUINOCORE_RENESAS_HARDWARECAN_H
13+
14+
/**************************************************************************************
15+
* INCLUDE
16+
**************************************************************************************/
17+
18+
#include "CanMsg.h"
19+
20+
/**************************************************************************************
21+
* TYPEDEF
22+
**************************************************************************************/
23+
24+
enum class CanBitRate : int
25+
{
26+
BR_125k = 125000,
27+
BR_250k = 250000,
28+
BR_500k = 500000,
29+
BR_1000k = 1000000,
30+
};
31+
32+
/**************************************************************************************
33+
* NAMESPACE
34+
**************************************************************************************/
35+
36+
namespace arduino
37+
{
38+
39+
/**************************************************************************************
40+
* CLASS DECLARATION
41+
**************************************************************************************/
42+
43+
class HardwareCAN
44+
{
45+
public:
46+
virtual ~HardwareCAN() {}
47+
48+
49+
virtual bool begin(CanBitRate const can_bitrate) = 0;
50+
virtual void end() = 0;
51+
52+
53+
virtual int write(CanMsg const &msg) = 0;
54+
virtual size_t available() = 0;
55+
virtual CanMsg read() = 0;
56+
};
57+
58+
/**************************************************************************************
59+
* NAMESPACE
60+
**************************************************************************************/
61+
62+
} /* arduino */
63+
64+
#endif /* ARDUINOCORE_RENESAS_HARDWARECAN_H */

Diff for: libraries/CAN/src/R7FA4M1_CAN.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ int R7FA4M1_CAN::write(CanMsg const & msg)
221221
return 1;
222222
}
223223

224-
size_t R7FA4M1_CAN::available() const
224+
size_t R7FA4M1_CAN::available()
225225
{
226226
return _can_rx_buf.available();
227227
}

Diff for: libraries/CAN/src/R7FA4M1_CAN.h

+9-8
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919

2020
#ifdef ARDUINO_SANTIAGO
2121

22+
#include "HardwareCAN.h"
23+
2224
#include "bsp_api.h"
2325

2426
#include "r_can.h"
2527

26-
#include "CanMsg.h"
27-
#include "CanConst.h"
2828
#include "CanMsgRingbuffer.h"
2929

3030
/**************************************************************************************
@@ -44,23 +44,24 @@ namespace arduino
4444
* CLASS DECLARATION
4545
**************************************************************************************/
4646

47-
class R7FA4M1_CAN
47+
class R7FA4M1_CAN final : public HardwareCAN
4848
{
4949
public:
5050
R7FA4M1_CAN(int const can_tx_pin, int const can_rx_pin);
51+
virtual ~R7FA4M1_CAN() { }
5152

5253

53-
bool begin(CanBitRate const can_bitrate);
54-
void end();
54+
bool begin(CanBitRate const can_bitrate) override;
55+
void end() override;
5556

5657

5758
int enableInternalLoopback();
5859
int disableInternalLoopback();
5960

6061

61-
int write(CanMsg const & msg);
62-
size_t available() const;
63-
CanMsg read();
62+
int write(CanMsg const & msg) override;
63+
size_t available() override;
64+
CanMsg read() override;
6465

6566

6667
inline bool isError(int & err_code) const { err_code = _err_code; return _is_error; }

Diff for: libraries/CAN/src/R7FA6M5_CAN.h

+9-8
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919

2020
#ifdef ARDUINO_PORTENTA_H33
2121

22+
#include "HardwareCAN.h"
23+
2224
#include <tuple>
2325

2426
#include "bsp_api.h"
2527

2628
#include "r_canfd.h"
2729

28-
#include "CanMsg.h"
29-
#include "CanConst.h"
3030
#include "CanMsgRingbuffer.h"
3131

3232
/**************************************************************************************
@@ -46,23 +46,24 @@ namespace arduino
4646
* CLASS DECLARATION
4747
**************************************************************************************/
4848

49-
class R7FA6M5_CAN
49+
class R7FA6M5_CAN final : public HardwareCAN
5050
{
5151
public:
5252
R7FA6M5_CAN(int const can_tx_pin, int const can_rx_pin);
53+
virtual ~R7FA6M5_CAN() { }
5354

5455

55-
bool begin(CanBitRate const can_bitrate);
56-
void end();
56+
bool begin(CanBitRate const can_bitrate) override;
57+
void end() override;
5758

5859

5960
int enableInternalLoopback();
6061
int disableInternalLoopback();
6162

6263

63-
int write(CanMsg const & msg);
64-
size_t available();
65-
CanMsg read();
64+
int write(CanMsg const & msg) override;
65+
size_t available() override;
66+
CanMsg read() override;
6667

6768

6869
inline bool isError(int & err_code) const { err_code = _err_code; return _is_error; }

0 commit comments

Comments
 (0)