Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit b9c58a1

Browse files
committed
modieifed rs485 to support mbede
1 parent 0c4b2eb commit b9c58a1

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

src/AutomationCarrier.h

+10-8
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "utility/QEI/QEI.h"
88
#include "utility/ioexpander/TCA6424A.h"
99

10+
#include "Arduino.h"
1011
#include "mbed.h"
1112

1213
namespace automation {
@@ -25,12 +26,14 @@ class RTDClass {
2526
}
2627
}
2728

28-
Adafruit_MAX31865 rtd = Adafruit_MAX31865(PA_6);
29-
THERMClass t = THERMClass(7);
29+
Adafruit_MAX31865 rtd = Adafruit_MAX31865(cs_rtd);
30+
THERMClass t = THERMClass(cs_tc);
3031

3132
private:
32-
mbed::DigitalOut ch_sel[3] = { mbed::DigitalOut(PA_0), mbed::DigitalOut(PI_4), mbed::DigitalOut(PJ_9) };
33-
mbed::DigitalOut rtd_th = mbed::DigitalOut(PH_9);
33+
mbed::DigitalOut ch_sel[3] = { mbed::DigitalOut(PA_0), mbed::DigitalOut(PI_4), mbed::DigitalOut(PG_10) };
34+
mbed::DigitalOut rtd_th = mbed::DigitalOut(PC_15);
35+
mbed::DigitalOut cs_tc = mbed::DigitalOut(PI_0);
36+
mbed::DigitalOut cs_rtd = mbed::DigitalOut(PA_6);
3437
};
3538

3639
extern RTDClass temp_probes;
@@ -46,11 +49,10 @@ class COMMClass {
4649
can_disable = 1;
4750
}
4851

49-
UART _UART4_ = arduino::UART(PA_0, PI_9, PI_10, PI_13);
52+
UART _UART4_ = arduino::UART(PA_0, PI_9, NC, NC);
5053
mbed::CAN& can = _can;
5154

52-
RS485Class rs485 = RS485Class(_UART4_);
53-
55+
RS485Class rs485 = RS485Class(_UART4_,PA_0, PI_13,PI_10);
5456
private:
5557
mbed::DigitalOut can_disable = mbed::DigitalOut(PA_13, 0);
5658

@@ -192,7 +194,7 @@ class DigitalOutputsClass {
192194
}
193195
private:
194196
mbed::DigitalOut out[8] = {
195-
mbed::DigitalOut(PI_6), mbed::DigitalOut(PC_15), mbed::DigitalOut(PG_10), mbed::DigitalOut(PE_2),
197+
mbed::DigitalOut(PI_6), mbed::DigitalOut(PH_9), mbed::DigitalOut(PJ_9), mbed::DigitalOut(PE_2),
196198
mbed::DigitalOut(PI_3), mbed::DigitalOut(PI_2), mbed::DigitalOut(PD_3), mbed::DigitalOut(PA_14)
197199
};
198200
};

src/utility/ArduinoRS485/src/RS485.cpp

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

2020
#include "RS485.h"
2121

22-
RS485Class::RS485Class(HardwareSerial& hwSerial, int txPin, int dePin, int rePin) :
22+
RS485Class::RS485Class(HardwareSerial& hwSerial, PinName txPin, PinName dePin, PinName rePin) :
2323
_serial(&hwSerial),
2424
_txPin(txPin),
2525
_dePin(dePin),
@@ -38,12 +38,12 @@ void RS485Class::begin(unsigned long baudrate, uint16_t config)
3838
_baudrate = baudrate;
3939
_config = config;
4040

41-
if (_dePin > -1) {
41+
if (_dePin != NC) {
4242
pinMode(_dePin, OUTPUT);
4343
digitalWrite(_dePin, LOW);
4444
}
4545

46-
if (_rePin > -1) {
46+
if (_rePin != NC) {
4747
pinMode(_rePin, OUTPUT);
4848
digitalWrite(_rePin, HIGH);
4949
}
@@ -57,12 +57,12 @@ void RS485Class::end()
5757
{
5858
_serial->end();
5959

60-
if (_rePin > -1) {
60+
if (_rePin != NC) {
6161
digitalWrite(_rePin, LOW);
6262
pinMode(_dePin, INPUT);
6363
}
6464

65-
if (_dePin > -1) {
65+
if (_dePin != NC) {
6666
digitalWrite(_dePin, LOW);
6767
pinMode(_rePin, INPUT);
6868
}
@@ -117,7 +117,7 @@ void RS485Class::endTransmission()
117117
{
118118
_serial->flush();
119119

120-
if (_dePin > -1) {
120+
if (_dePin != NC) {
121121
delayMicroseconds(50);
122122
digitalWrite(_dePin, LOW);
123123
}
@@ -127,14 +127,14 @@ void RS485Class::endTransmission()
127127

128128
void RS485Class::receive()
129129
{
130-
if (_rePin > -1) {
130+
if (_rePin != NC) {
131131
digitalWrite(_rePin, LOW);
132132
}
133133
}
134134

135135
void RS485Class::noReceive()
136136
{
137-
if (_rePin > -1) {
137+
if (_rePin != NC) {
138138
digitalWrite(_rePin, HIGH);
139139
}
140140
}
@@ -143,7 +143,7 @@ void RS485Class::sendBreak(unsigned int duration)
143143
{
144144
_serial->flush();
145145
_serial->end();
146-
if (_txPin > -1) {
146+
if (_txPin != NC) {
147147
pinMode(_txPin, OUTPUT);
148148
digitalWrite(_txPin, LOW);
149149
}
@@ -155,15 +155,15 @@ void RS485Class::sendBreakMicroseconds(unsigned int duration)
155155
{
156156
_serial->flush();
157157
_serial->end();
158-
if (_txPin > -1) {
158+
if (_txPin != NC) {
159159
pinMode(_txPin, OUTPUT);
160160
digitalWrite(_txPin, LOW);
161161
}
162162
delayMicroseconds(duration);
163163
_serial->begin(_baudrate, _config);
164164
}
165165

166-
void RS485Class::setPins(int txPin, int dePin, int rePin)
166+
void RS485Class::setPins(PinName txPin, PinName dePin, PinName rePin)
167167
{
168168
_txPin = txPin;
169169
_dePin = dePin;

src/utility/ArduinoRS485/src/RS485.h

+7-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#include <Arduino.h>
2424

25+
#include "mbed.h"
26+
2527
#ifdef PIN_SERIAL1_TX
2628
#define RS485_DEFAULT_TX_PIN PIN_SERIAL1_TX
2729
#else
@@ -38,7 +40,7 @@
3840

3941
class RS485Class : public Stream {
4042
public:
41-
RS485Class(HardwareSerial& hwSerial, int txPin = -1, int dePin = -1, int rePin = -1);
43+
RS485Class(HardwareSerial& hwSerial, PinName txPin = NC, PinName dePin = NC, PinName rePin = NC);
4244

4345
virtual void begin(unsigned long baudrate);
4446
virtual void begin(unsigned long baudrate, uint16_t config);
@@ -59,7 +61,7 @@ class RS485Class : public Stream {
5961
void sendBreak(unsigned int duration);
6062
void sendBreakMicroseconds(unsigned int duration);
6163

62-
void setPins(int txPin, int dePin, int rePin);
64+
void setPins(PinName txPin, PinName dePin, PinName rePin);
6365

6466
mbed::DigitalOut half_duplex = mbed::DigitalOut(PA_9);
6567
mbed::DigitalOut sel_485 = mbed::DigitalOut(PA_10);
@@ -70,9 +72,9 @@ class RS485Class : public Stream {
7072

7173
private:
7274
HardwareSerial* _serial;
73-
int _txPin;
74-
int _dePin = -1;
75-
int _rePin = -1;
75+
PinName _txPin;
76+
PinName _dePin = NC;
77+
PinName _rePin = NC;
7678

7779

7880
bool _transmisionBegun;

0 commit comments

Comments
 (0)