-
Notifications
You must be signed in to change notification settings - Fork 122
/
FlexCAN.h
45 lines (38 loc) · 980 Bytes
/
FlexCAN.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
// -------------------------------------------------------------
// a simple Arduino Teensy3.1 CAN driver
// by teachop
//
#ifndef __FLEXCAN_H__
#define __FLEXCAN_H__
#include <Arduino.h>
typedef struct CAN_message_t {
uint32_t id; // can identifier
uint8_t ext; // identifier is extended
uint8_t len; // length of data
uint16_t timeout; // milliseconds, zero will disable waiting
uint8_t buf[8];
} CAN_message_t;
typedef struct CAN_filter_t {
uint8_t rtr;
uint8_t ext;
uint32_t id;
} CAN_filter_t;
// -------------------------------------------------------------
class FlexCAN
{
private:
struct CAN_filter_t defaultMask;
public:
FlexCAN(uint32_t baud = 125000);
void begin(const CAN_filter_t &mask);
inline void begin()
{
begin(defaultMask);
}
void setFilter(const CAN_filter_t &filter, uint8_t n);
void end(void);
int available(void);
int write(const CAN_message_t &msg);
int read(CAN_message_t &msg);
};
#endif // __FLEXCAN_H__