-
-
Notifications
You must be signed in to change notification settings - Fork 212
/
Copy pathArduino_CAN.h
86 lines (63 loc) · 2.62 KB
/
Arduino_CAN.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Copyright (c) 2022 by Alexander Entinger <[email protected]>
* CAN library for Arduino.
*
* This file is free software; you can redistribute it and/or modify
* it under the terms of either the GNU General Public License version 2
* or the GNU Lesser General Public License version 2.1, both as
* published by the Free Software Foundation.
*/
#ifndef ARDUINO_CORE_MBED_CAN_H_
#define ARDUINO_CORE_MBED_CAN_H_
/**************************************************************************************
* INCLUDE
**************************************************************************************/
#include <Arduino.h>
#include <mbed.h>
#include "api/HardwareCAN.h"
/**************************************************************************************
* COMPILE TIME CHECKS
**************************************************************************************/
#if !(defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_GIGA) || defined(CORE_CM4))
# error "CAN only available on Arduino Portenta H7 and Arduino Giga (of all ArduinoCore-mbed enabled boards)."
#endif
/**************************************************************************************
* TYPEDEF
**************************************************************************************/
typedef arduino::CanMsg CanMsg;
/**************************************************************************************
* NAMESPACE
**************************************************************************************/
namespace arduino
{
/**************************************************************************************
* CLASS DECLARATION
**************************************************************************************/
class Arduino_CAN final : public HardwareCAN
{
public:
Arduino_CAN(PinName const can_tx_pin, PinName const can_rx_pin);
virtual ~Arduino_CAN() { }
bool begin(CanBitRate const can_bitrate) override;
void end() override;
int write(CanMsg const & msg) override;
size_t available() override;
CanMsg read() override;
private:
mbed::CAN _can;
CanMsgRingbuffer _rx_msg_buf;
};
/**************************************************************************************
* NAMESPACE
**************************************************************************************/
} /* arduino */
/**************************************************************************************
* EXTERN DECLARATION
**************************************************************************************/
#if CAN_HOWMANY > 0
extern arduino::Arduino_CAN CAN;
#endif
#if CAN_HOWMANY > 1
extern arduino::Arduino_CAN CAN1;
#endif
#endif /* ARDUINO_CORE_MBED_CAN_H_ */