diff --git a/libraries/MySensors/drivers/ATSHA204/ATSHA204.cpp b/libraries/MySensors/drivers/ATSHA204/ATSHA204.cpp index 3e16cc3..16b82c3 100644 --- a/libraries/MySensors/drivers/ATSHA204/ATSHA204.cpp +++ b/libraries/MySensors/drivers/ATSHA204/ATSHA204.cpp @@ -7,7 +7,19 @@ // As well as the bit value for each of those registers ATSHA204Class::ATSHA204Class(uint8_t pin) { - device_pin = pin; // Find the bit value of the pin +#if defined(ARDUINO_ARCH_AVR) + device_pin = digitalPinToBitMask(pin); // Find the bit value of the pin + uint8_t port = digitalPinToPort(pin); // temoporarily used to get the next three registers + + // Point to data direction register port of pin + device_port_DDR = portModeRegister(port); + // Point to output register of pin + device_port_OUT = portOutputRegister(port); + // Point to input register of pin + device_port_IN = portInputRegister(port); +#else + device_pin = pin; +#endif } void ATSHA204Class::getSerialNumber(uint8_t * response) @@ -71,21 +83,21 @@ uint8_t ATSHA204Class::swi_send_bytes(uint8_t count, uint8_t *buffer) { if (bit_mask & buffer[i]) { - SHA204_POUT_LOW() //*device_port_OUT &= ~device_pin; + SHA204_POUT_LOW(); //*device_port_OUT &= ~device_pin; delayMicroseconds(BIT_DELAY); //BIT_DELAY_1; - SHA204_POUT_HIGH() //*device_port_OUT |= device_pin; + SHA204_POUT_HIGH(); //*device_port_OUT |= device_pin; delayMicroseconds(7*BIT_DELAY); //BIT_DELAY_7; } else { // Send a zero bit. - SHA204_POUT_LOW() //*device_port_OUT &= ~device_pin; + SHA204_POUT_LOW(); //*device_port_OUT &= ~device_pin; delayMicroseconds(BIT_DELAY); //BIT_DELAY_1; - SHA204_POUT_HIGH() //*device_port_OUT |= device_pin; + SHA204_POUT_HIGH(); //*device_port_OUT |= device_pin; delayMicroseconds(BIT_DELAY); //BIT_DELAY_1; - SHA204_POUT_LOW() //*device_port_OUT &= ~device_pin; + SHA204_POUT_LOW(); //*device_port_OUT &= ~device_pin; delayMicroseconds(BIT_DELAY); //BIT_DELAY_1; - SHA204_POUT_HIGH() //*device_port_OUT |= device_pin; + SHA204_POUT_HIGH(); //*device_port_OUT |= device_pin; delayMicroseconds(5*BIT_DELAY); //BIT_DELAY_5; } } diff --git a/libraries/MySensors/drivers/ATSHA204/ATSHA204.h b/libraries/MySensors/drivers/ATSHA204/ATSHA204.h index 7569e21..8fcf163 100644 --- a/libraries/MySensors/drivers/ATSHA204/ATSHA204.h +++ b/libraries/MySensors/drivers/ATSHA204/ATSHA204.h @@ -240,7 +240,9 @@ class ATSHA204Class { private: uint8_t device_pin; -// volatile uint8_t *device_port_DDR, *device_port_OUT, *device_port_IN; + #ifdef ARDUINO_ARCH_AVR + volatile uint8_t *device_port_DDR, *device_port_OUT, *device_port_IN; + #endif void sha204c_calculate_crc(uint8_t length, uint8_t *data, uint8_t *crc); uint8_t sha204c_check_crc(uint8_t *response); void swi_set_signal_pin(uint8_t is_high);