forked from ImperialRacingGreen/EV2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsn65hvd234.cpp
151 lines (125 loc) · 3.15 KB
/
sn65hvd234.cpp
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/*
Copyright (c) 2013 Arduino. All right reserved.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* \file
*
* Implementation of the SN65HVD234 drivers.
*
*/
#include "sn65hvd234.h"
#include <string.h>
/**
* \brief Initialize SN65HVD234 component data
*
* \param pComponent pointer on SSN65HVD234_Data
*
* \return 0 if OK
*/
uint32_t SSN65HVD234::Init()
{
dwPin_Rs=0u ;
dwPin_EN=0u ;
return 0u ;
}
SSN65HVD234::SSN65HVD234(uint32_t Rs, uint32_t En)
{
dwPin_Rs=Rs ;
pinMode(dwPin_Rs, OUTPUT ) ;
dwPin_EN=En;
pinMode( dwPin_EN, OUTPUT ) ;
}
/**
* \brief Initialize Rs pin of transceiver
*
* \param pComponent pointer on SSN65HVD234_Data
* \param pPIO_Rs pointer on PIOx base for transceiver Rs pin
* \param dwPin_Rs PIO pin index for transceiver Rs pin
*
* \return 0 if OK
*/
uint32_t SSN65HVD234::SetRs(uint32_t Rs )
{
dwPin_Rs=Rs ;
pinMode(dwPin_Rs, OUTPUT ) ;
return 0u ;
}
/**
* \brief Initialize EN pin of transceiver
*
* \param pComponent pointer on SSN65HVD234_Data
* \param pPIO_EN pointer on PIOx base for transceiver EN pin
* \param dwPin_EN PIO pin index for transceiver EN pin
*
* \return 0 if OK
*/
uint32_t SSN65HVD234::SetEN(uint32_t EN )
{
dwPin_EN=EN ;
pinMode( dwPin_EN, OUTPUT ) ;
return 0u ;
}
/**
* \brief Enable transceiver
*
* \param pComponent pointer on SSN65HVD234_Data
*
* \return 0 if OK
*/
uint32_t SSN65HVD234::Enable()
{
// Raise EN of SN65HVD234 to High Level (Vcc)
digitalWrite(dwPin_EN, HIGH ) ;
return 0u ;
}
/**
* \brief Disable transceiver
*
* \param pComponent pointer on SSN65HVD234_Data
*
* \return 0 if OK
*/
uint32_t SSN65HVD234::Disable()
{
// Lower EN of SN65HVD234 to Low Level (0.0v)
digitalWrite(dwPin_EN, LOW ) ;
return 0u ;
}
/**
* \brief Turn component into lowpower mode
*
* \param pComponent pointer on SSN65HVD234_Data
*
* \return 0 if OK
*/
uint32_t SSN65HVD234::EnableLowPower()
{
// Raise Rs of SN65HVD234 to more than 0.75v
digitalWrite(dwPin_Rs, HIGH ) ;
// Now, SN65HVD234 is only listening
return 0u ;
}
/**
* \brief Restore Normal mode by leaving lowpower mode
*
* \param pComponent pointer on SSN65HVD234_Data
*
* \return 0 if OK
*/
uint32_t SSN65HVD234::DisableLowPower()
{
// Lower Rs of SN65HVD234 to 0.0v < 0.33v
digitalWrite(dwPin_Rs, LOW ) ;
return 0u ;
}