-
Notifications
You must be signed in to change notification settings - Fork 2
/
at86rf212_if.hpp
74 lines (60 loc) · 1.83 KB
/
at86rf212_if.hpp
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
/*
* at86rf212 c++ to c driver adapter
* Converts between a c++ driver classes and underlying c function calls.
*
* Copyright 2016 Ryan Kurte
*/
#pragma once
#include "at86rf212.h"
namespace AT86RF212
{
// SPI driver interface class
class DriverInterface
{
public:
virtual int spi_transfer(int len, uint8_t *data_out, uint8_t* data_in) = 0;
virtual int set_sdn(uint8_t val) = 0;
virtual int set_slp_tr(uint8_t val) = 0;
virtual int get_irq(uint8_t *val) = 0;
};
// Adaptor functions, allows c++ object to be called from c(ish) context
int at86rf212_transfer_data_adaptor(void* context, int len, uint8_t* data_out, uint8_t* data_in)
{
AT86RF212::DriverInterface *driver = (AT86RF212::DriverInterface*) context;
return driver->spi_transfer(len, data_out, data_in);
}
int at86rf212_set_sdn_adaptor(void* context, uint8_t val)
{
AT86RF212::DriverInterface *driver = (AT86RF212::DriverInterface*) context;
return driver->set_sdn(val);
}
int at86rf212_set_slp_tr_adaptor(void* context, uint8_t val)
{
AT86RF212::DriverInterface *driver = (AT86RF212::DriverInterface*) context;
return driver->set_slp_tr(val);
}
int at86rf212_get_irq_adaptor(void* context, uint8_t* val)
{
AT86RF212::DriverInterface *driver = (AT86RF212::DriverInterface*) context;
return driver->get_irq(val);
}
// SPI Driver wrapper object
// Adapts C++ driver object for use in C based library
// Note that this can be static as driver context is passed separately to the driver
class DriverWrapper
{
public:
static struct at86rf212_driver_s* GetWrapper()
{
return &driver;
}
private:
static struct at86rf212_driver_s driver;
};
struct at86rf212_driver_s DriverWrapper::driver = {
at86rf212_transfer_data_adaptor,
at86rf212_set_sdn_adaptor,
at86rf212_set_slp_tr_adaptor,
at86rf212_get_irq_adaptor
};
};