Skip to content

Commit 62f9d9e

Browse files
committed
Updated core atsha204 driver for avr/samd compatability, renamed macro names in fat library
1 parent e2f4525 commit 62f9d9e

File tree

4 files changed

+53
-36
lines changed

4 files changed

+53
-36
lines changed

libraries/MySensors/drivers/ATSHA204/ATSHA204.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ void ATSHA204Class::getSerialNumber(uint8_t * response)
4242

4343
void ATSHA204Class::swi_set_signal_pin(uint8_t is_high)
4444
{
45-
pinMode(device_pin, OUTPUT);
45+
SHA204_SET_OUTPUT();
4646

4747
if (is_high)
48-
digitalWrite(device_pin, HIGH);
48+
SHA204_POUT_HIGH();
4949
else
50-
digitalWrite(device_pin, LOW);
50+
SHA204_POUT_LOW();
5151
}
5252

5353
uint8_t ATSHA204Class::swi_send_bytes(uint8_t count, uint8_t *buffer)
@@ -58,8 +58,9 @@ uint8_t ATSHA204Class::swi_send_bytes(uint8_t count, uint8_t *buffer)
5858
noInterrupts(); //swi_disable_interrupts();
5959

6060
// Set signal pin as output.
61-
pinMode(device_pin, OUTPUT);
62-
digitalWrite(device_pin, HIGH);
61+
SHA204_POUT_HIGH();
62+
SHA204_SET_OUTPUT();
63+
6364

6465
// Wait turn around time.
6566
delayMicroseconds(RX_TX_DELAY); //RX_TX_DELAY;
@@ -70,21 +71,21 @@ uint8_t ATSHA204Class::swi_send_bytes(uint8_t count, uint8_t *buffer)
7071
{
7172
if (bit_mask & buffer[i])
7273
{
73-
digitalWrite(device_pin, LOW); //*device_port_OUT &= ~device_pin;
74+
SHA204_POUT_LOW() //*device_port_OUT &= ~device_pin;
7475
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
75-
digitalWrite(device_pin, HIGH); //*device_port_OUT |= device_pin;
76+
SHA204_POUT_HIGH() //*device_port_OUT |= device_pin;
7677
delayMicroseconds(7*BIT_DELAY); //BIT_DELAY_7;
7778
}
7879
else
7980
{
8081
// Send a zero bit.
81-
digitalWrite(device_pin, LOW); //*device_port_OUT &= ~device_pin;
82+
SHA204_POUT_LOW() //*device_port_OUT &= ~device_pin;
8283
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
83-
digitalWrite(device_pin, HIGH); //*device_port_OUT |= device_pin;
84+
SHA204_POUT_HIGH() //*device_port_OUT |= device_pin;
8485
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
85-
digitalWrite(device_pin, LOW); //*device_port_OUT &= ~device_pin;
86+
SHA204_POUT_LOW() //*device_port_OUT &= ~device_pin;
8687
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
87-
digitalWrite(device_pin, HIGH); //*device_port_OUT |= device_pin;
88+
SHA204_POUT_HIGH() //*device_port_OUT |= device_pin;
8889
delayMicroseconds(5*BIT_DELAY); //BIT_DELAY_5;
8990
}
9091
}
@@ -110,8 +111,8 @@ uint8_t ATSHA204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
110111
noInterrupts(); //swi_disable_interrupts();
111112

112113
// Configure signal pin as input.
113-
pinMode(device_pin, INPUT);
114-
114+
SHA204_SET_INPUT();
115+
115116
// Receive bits and store in buffer.
116117
for (i = 0; i < count; i++)
117118
{
@@ -128,7 +129,7 @@ uint8_t ATSHA204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
128129
while (--timeout_count > 0)
129130
{
130131
// Wait for falling edge.
131-
if (digitalRead(device_pin) == 0)
132+
if (SHA204_PIN_READ() == 0)
132133
break;
133134
}
134135

@@ -141,7 +142,7 @@ uint8_t ATSHA204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
141142
do
142143
{
143144
// Wait for rising edge.
144-
if (digitalRead(device_pin) != 0)
145+
if (SHA204_PIN_READ() != 0)
145146
{
146147
// For an Atmel microcontroller this might be faster than "pulse_count++".
147148
pulse_count = 1;
@@ -164,7 +165,7 @@ uint8_t ATSHA204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
164165
// Detect possible edge indicating zero bit.
165166
do
166167
{
167-
if (digitalRead(device_pin) == 0)
168+
if (SHA204_PIN_READ() == 0)
168169
{
169170
// For an Atmel microcontroller this might be faster than "pulse_count++".
170171
pulse_count = 2;
@@ -178,7 +179,7 @@ uint8_t ATSHA204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
178179
{
179180
do
180181
{
181-
if (digitalRead(device_pin) != 0)
182+
if (SHA204_PIN_READ() != 0)
182183
break;
183184
} while (timeout_count-- > 0);
184185
}

libraries/MySensors/drivers/ATSHA204/ATSHA204.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,22 @@
220220

221221
#define SHA204_SERIAL_SZ 9 // The number of bytes the serial number consists of
222222

223+
/* Low level HW access macros */
224+
/* function calls is not working, as it will have too much overhead */
225+
#if !defined(ARDUINO_ARCH_AVR) // For everything else than AVR use pinMode / digitalWrite
226+
#define SHA204_SET_OUTPUT() pinMode(device_pin, OUTPUT)
227+
#define SHA204_SET_INPUT() pinMode(device_pin, INPUT)
228+
#define SHA204_POUT_HIGH() digitalWrite(device_pin, HIGH)
229+
#define SHA204_POUT_LOW() digitalWrite(device_pin, LOW)
230+
#define SHA204_PIN_READ() digitalRead(device_pin)
231+
#else
232+
#define SHA204_SET_INPUT() *device_port_DDR &= ~device_pin
233+
#define SHA204_SET_OUTPUT() *device_port_DDR |= device_pin
234+
#define SHA204_POUT_HIGH() *device_port_OUT |= device_pin
235+
#define SHA204_POUT_LOW() *device_port_OUT &= ~device_pin
236+
#define SHA204_PIN_READ() (*device_port_IN & device_pin)
237+
#endif
238+
223239
class ATSHA204Class
224240
{
225241
private:

libraries/sha204/sha204_library.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ void atsha204Class::swi_set_signal_pin(uint8_t is_high)
8989
{
9090
SHA204_SET_OUTPUT();
9191
if (is_high) {
92-
SHA204_SET_HIGH();
92+
SHA204_POUT_HIGH();
9393
}
9494
else {
95-
SHA204_SET_LOW();
95+
SHA204_POUT_LOW();
9696
}
9797

9898
}
@@ -105,7 +105,7 @@ uint8_t atsha204Class::swi_send_bytes(uint8_t count, uint8_t *buffer)
105105
noInterrupts(); //swi_disable_interrupts();
106106

107107
// Set signal pin as output.
108-
SHA204_SET_HIGH();
108+
SHA204_POUT_HIGH();
109109
SHA204_SET_OUTPUT();
110110
// Wait turn around time.
111111
delayMicroseconds(RX_TX_DELAY); //RX_TX_DELAY;
@@ -116,21 +116,21 @@ uint8_t atsha204Class::swi_send_bytes(uint8_t count, uint8_t *buffer)
116116
{
117117
if (bit_mask & buffer[i])
118118
{
119-
SHA204_SET_LOW();
119+
SHA204_POUT_LOW();
120120
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
121-
SHA204_SET_HIGH();
121+
SHA204_POUT_HIGH();
122122
delayMicroseconds(7*BIT_DELAY); //BIT_DELAY_7;
123123
}
124124
else
125125
{
126126
// Send a zero bit.
127-
SHA204_SET_LOW();
127+
SHA204_POUT_LOW();
128128
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
129-
SHA204_SET_HIGH();
129+
SHA204_POUT_HIGH();
130130
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
131-
SHA204_SET_LOW();
131+
SHA204_POUT_LOW();
132132
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
133-
SHA204_SET_HIGH();
133+
SHA204_POUT_HIGH();
134134
delayMicroseconds(5*BIT_DELAY); //BIT_DELAY_5;
135135
}
136136
}
@@ -174,7 +174,7 @@ uint8_t atsha204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
174174
while (--timeout_count > 0)
175175
{
176176
// Wait for falling edge.
177-
if (SHA204_READ_PIN() == 0)
177+
if (SHA204_PIN_READ() == 0)
178178
break;
179179
}
180180

@@ -187,7 +187,7 @@ uint8_t atsha204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
187187
do
188188
{
189189
// Wait for rising edge.
190-
if (SHA204_READ_PIN() != 0)
190+
if (SHA204_PIN_READ() != 0)
191191
{
192192
// For an Atmel microcontroller this might be faster than "pulse_count++".
193193
pulse_count = 1;
@@ -210,7 +210,7 @@ uint8_t atsha204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
210210
// Detect possible edge indicating zero bit.
211211
do
212212
{
213-
if (SHA204_READ_PIN() == 0)
213+
if (SHA204_PIN_READ() == 0)
214214
{
215215
// For an Atmel microcontroller this might be faster than "pulse_count++".
216216
pulse_count = 2;
@@ -224,7 +224,7 @@ uint8_t atsha204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
224224
{
225225
do
226226
{
227-
if (SHA204_READ_PIN() != 0)
227+
if (SHA204_PIN_READ() != 0)
228228
break;
229229
} while (timeout_count-- > 0);
230230
}

libraries/sha204/sha204_library.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -284,15 +284,15 @@
284284
#if !defined(ARDUINO_ARCH_AVR) // For everything else than AVR use pinMode / digitalWrite
285285
#define SHA204_SET_OUTPUT() pinMode(device_pin, OUTPUT)
286286
#define SHA204_SET_INPUT() pinMode(device_pin, INPUT)
287-
#define SHA204_SET_HIGH() digitalWrite(device_pin, HIGH)
288-
#define SHA204_SET_LOW() digitalWrite(device_pin, LOW)
289-
#define SHA204_READ_PIN() digitalRead(device_pin)
287+
#define SHA204_POUT_HIGH() digitalWrite(device_pin, HIGH)
288+
#define SHA204_POUT_LOW() digitalWrite(device_pin, LOW)
289+
#define SHA204_PIN_READ() digitalRead(device_pin)
290290
#else
291291
#define SHA204_SET_INPUT() *device_port_DDR &= ~device_pin
292292
#define SHA204_SET_OUTPUT() *device_port_DDR |= device_pin
293-
#define SHA204_SET_HIGH() *device_port_OUT |= device_pin
294-
#define SHA204_SET_LOW() *device_port_OUT &= ~device_pin
295-
#define SHA204_READ_PIN() (*device_port_IN & device_pin)
293+
#define SHA204_POUT_HIGH() *device_port_OUT |= device_pin
294+
#define SHA204_POUT_LOW() *device_port_OUT &= ~device_pin
295+
#define SHA204_PIN_READ() (*device_port_IN & device_pin)
296296
#endif
297297

298298
class atsha204Class

0 commit comments

Comments
 (0)