Updated core atsha204 driver for avr/samd compatability, renamed macro names in fat library
This commit is contained in:
@@ -42,12 +42,12 @@ void ATSHA204Class::getSerialNumber(uint8_t * response)
|
|||||||
|
|
||||||
void ATSHA204Class::swi_set_signal_pin(uint8_t is_high)
|
void ATSHA204Class::swi_set_signal_pin(uint8_t is_high)
|
||||||
{
|
{
|
||||||
pinMode(device_pin, OUTPUT);
|
SHA204_SET_OUTPUT();
|
||||||
|
|
||||||
if (is_high)
|
if (is_high)
|
||||||
digitalWrite(device_pin, HIGH);
|
SHA204_POUT_HIGH();
|
||||||
else
|
else
|
||||||
digitalWrite(device_pin, LOW);
|
SHA204_POUT_LOW();
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t ATSHA204Class::swi_send_bytes(uint8_t count, uint8_t *buffer)
|
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)
|
|||||||
noInterrupts(); //swi_disable_interrupts();
|
noInterrupts(); //swi_disable_interrupts();
|
||||||
|
|
||||||
// Set signal pin as output.
|
// Set signal pin as output.
|
||||||
pinMode(device_pin, OUTPUT);
|
SHA204_POUT_HIGH();
|
||||||
digitalWrite(device_pin, HIGH);
|
SHA204_SET_OUTPUT();
|
||||||
|
|
||||||
|
|
||||||
// Wait turn around time.
|
// Wait turn around time.
|
||||||
delayMicroseconds(RX_TX_DELAY); //RX_TX_DELAY;
|
delayMicroseconds(RX_TX_DELAY); //RX_TX_DELAY;
|
||||||
@@ -70,21 +71,21 @@ uint8_t ATSHA204Class::swi_send_bytes(uint8_t count, uint8_t *buffer)
|
|||||||
{
|
{
|
||||||
if (bit_mask & buffer[i])
|
if (bit_mask & buffer[i])
|
||||||
{
|
{
|
||||||
digitalWrite(device_pin, LOW); //*device_port_OUT &= ~device_pin;
|
SHA204_POUT_LOW() //*device_port_OUT &= ~device_pin;
|
||||||
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
|
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
|
||||||
digitalWrite(device_pin, HIGH); //*device_port_OUT |= device_pin;
|
SHA204_POUT_HIGH() //*device_port_OUT |= device_pin;
|
||||||
delayMicroseconds(7*BIT_DELAY); //BIT_DELAY_7;
|
delayMicroseconds(7*BIT_DELAY); //BIT_DELAY_7;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Send a zero bit.
|
// Send a zero bit.
|
||||||
digitalWrite(device_pin, LOW); //*device_port_OUT &= ~device_pin;
|
SHA204_POUT_LOW() //*device_port_OUT &= ~device_pin;
|
||||||
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
|
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
|
||||||
digitalWrite(device_pin, HIGH); //*device_port_OUT |= device_pin;
|
SHA204_POUT_HIGH() //*device_port_OUT |= device_pin;
|
||||||
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
|
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
|
||||||
digitalWrite(device_pin, LOW); //*device_port_OUT &= ~device_pin;
|
SHA204_POUT_LOW() //*device_port_OUT &= ~device_pin;
|
||||||
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
|
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
|
||||||
digitalWrite(device_pin, HIGH); //*device_port_OUT |= device_pin;
|
SHA204_POUT_HIGH() //*device_port_OUT |= device_pin;
|
||||||
delayMicroseconds(5*BIT_DELAY); //BIT_DELAY_5;
|
delayMicroseconds(5*BIT_DELAY); //BIT_DELAY_5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,7 +111,7 @@ uint8_t ATSHA204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
|
|||||||
noInterrupts(); //swi_disable_interrupts();
|
noInterrupts(); //swi_disable_interrupts();
|
||||||
|
|
||||||
// Configure signal pin as input.
|
// Configure signal pin as input.
|
||||||
pinMode(device_pin, INPUT);
|
SHA204_SET_INPUT();
|
||||||
|
|
||||||
// Receive bits and store in buffer.
|
// Receive bits and store in buffer.
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++)
|
||||||
@@ -128,7 +129,7 @@ uint8_t ATSHA204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
|
|||||||
while (--timeout_count > 0)
|
while (--timeout_count > 0)
|
||||||
{
|
{
|
||||||
// Wait for falling edge.
|
// Wait for falling edge.
|
||||||
if (digitalRead(device_pin) == 0)
|
if (SHA204_PIN_READ() == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +142,7 @@ uint8_t ATSHA204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
// Wait for rising edge.
|
// Wait for rising edge.
|
||||||
if (digitalRead(device_pin) != 0)
|
if (SHA204_PIN_READ() != 0)
|
||||||
{
|
{
|
||||||
// For an Atmel microcontroller this might be faster than "pulse_count++".
|
// For an Atmel microcontroller this might be faster than "pulse_count++".
|
||||||
pulse_count = 1;
|
pulse_count = 1;
|
||||||
@@ -164,7 +165,7 @@ uint8_t ATSHA204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
|
|||||||
// Detect possible edge indicating zero bit.
|
// Detect possible edge indicating zero bit.
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (digitalRead(device_pin) == 0)
|
if (SHA204_PIN_READ() == 0)
|
||||||
{
|
{
|
||||||
// For an Atmel microcontroller this might be faster than "pulse_count++".
|
// For an Atmel microcontroller this might be faster than "pulse_count++".
|
||||||
pulse_count = 2;
|
pulse_count = 2;
|
||||||
@@ -178,7 +179,7 @@ uint8_t ATSHA204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
|
|||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (digitalRead(device_pin) != 0)
|
if (SHA204_PIN_READ() != 0)
|
||||||
break;
|
break;
|
||||||
} while (timeout_count-- > 0);
|
} while (timeout_count-- > 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -220,6 +220,22 @@
|
|||||||
|
|
||||||
#define SHA204_SERIAL_SZ 9 // The number of bytes the serial number consists of
|
#define SHA204_SERIAL_SZ 9 // The number of bytes the serial number consists of
|
||||||
|
|
||||||
|
/* Low level HW access macros */
|
||||||
|
/* function calls is not working, as it will have too much overhead */
|
||||||
|
#if !defined(ARDUINO_ARCH_AVR) // For everything else than AVR use pinMode / digitalWrite
|
||||||
|
#define SHA204_SET_OUTPUT() pinMode(device_pin, OUTPUT)
|
||||||
|
#define SHA204_SET_INPUT() pinMode(device_pin, INPUT)
|
||||||
|
#define SHA204_POUT_HIGH() digitalWrite(device_pin, HIGH)
|
||||||
|
#define SHA204_POUT_LOW() digitalWrite(device_pin, LOW)
|
||||||
|
#define SHA204_PIN_READ() digitalRead(device_pin)
|
||||||
|
#else
|
||||||
|
#define SHA204_SET_INPUT() *device_port_DDR &= ~device_pin
|
||||||
|
#define SHA204_SET_OUTPUT() *device_port_DDR |= device_pin
|
||||||
|
#define SHA204_POUT_HIGH() *device_port_OUT |= device_pin
|
||||||
|
#define SHA204_POUT_LOW() *device_port_OUT &= ~device_pin
|
||||||
|
#define SHA204_PIN_READ() (*device_port_IN & device_pin)
|
||||||
|
#endif
|
||||||
|
|
||||||
class ATSHA204Class
|
class ATSHA204Class
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -89,10 +89,10 @@ void atsha204Class::swi_set_signal_pin(uint8_t is_high)
|
|||||||
{
|
{
|
||||||
SHA204_SET_OUTPUT();
|
SHA204_SET_OUTPUT();
|
||||||
if (is_high) {
|
if (is_high) {
|
||||||
SHA204_SET_HIGH();
|
SHA204_POUT_HIGH();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
SHA204_SET_LOW();
|
SHA204_POUT_LOW();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -105,7 +105,7 @@ uint8_t atsha204Class::swi_send_bytes(uint8_t count, uint8_t *buffer)
|
|||||||
noInterrupts(); //swi_disable_interrupts();
|
noInterrupts(); //swi_disable_interrupts();
|
||||||
|
|
||||||
// Set signal pin as output.
|
// Set signal pin as output.
|
||||||
SHA204_SET_HIGH();
|
SHA204_POUT_HIGH();
|
||||||
SHA204_SET_OUTPUT();
|
SHA204_SET_OUTPUT();
|
||||||
// Wait turn around time.
|
// Wait turn around time.
|
||||||
delayMicroseconds(RX_TX_DELAY); //RX_TX_DELAY;
|
delayMicroseconds(RX_TX_DELAY); //RX_TX_DELAY;
|
||||||
@@ -116,21 +116,21 @@ uint8_t atsha204Class::swi_send_bytes(uint8_t count, uint8_t *buffer)
|
|||||||
{
|
{
|
||||||
if (bit_mask & buffer[i])
|
if (bit_mask & buffer[i])
|
||||||
{
|
{
|
||||||
SHA204_SET_LOW();
|
SHA204_POUT_LOW();
|
||||||
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
|
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
|
||||||
SHA204_SET_HIGH();
|
SHA204_POUT_HIGH();
|
||||||
delayMicroseconds(7*BIT_DELAY); //BIT_DELAY_7;
|
delayMicroseconds(7*BIT_DELAY); //BIT_DELAY_7;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Send a zero bit.
|
// Send a zero bit.
|
||||||
SHA204_SET_LOW();
|
SHA204_POUT_LOW();
|
||||||
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
|
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
|
||||||
SHA204_SET_HIGH();
|
SHA204_POUT_HIGH();
|
||||||
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
|
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
|
||||||
SHA204_SET_LOW();
|
SHA204_POUT_LOW();
|
||||||
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
|
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
|
||||||
SHA204_SET_HIGH();
|
SHA204_POUT_HIGH();
|
||||||
delayMicroseconds(5*BIT_DELAY); //BIT_DELAY_5;
|
delayMicroseconds(5*BIT_DELAY); //BIT_DELAY_5;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,7 +174,7 @@ uint8_t atsha204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
|
|||||||
while (--timeout_count > 0)
|
while (--timeout_count > 0)
|
||||||
{
|
{
|
||||||
// Wait for falling edge.
|
// Wait for falling edge.
|
||||||
if (SHA204_READ_PIN() == 0)
|
if (SHA204_PIN_READ() == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,7 +187,7 @@ uint8_t atsha204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
|
|||||||
do
|
do
|
||||||
{
|
{
|
||||||
// Wait for rising edge.
|
// Wait for rising edge.
|
||||||
if (SHA204_READ_PIN() != 0)
|
if (SHA204_PIN_READ() != 0)
|
||||||
{
|
{
|
||||||
// For an Atmel microcontroller this might be faster than "pulse_count++".
|
// For an Atmel microcontroller this might be faster than "pulse_count++".
|
||||||
pulse_count = 1;
|
pulse_count = 1;
|
||||||
@@ -210,7 +210,7 @@ uint8_t atsha204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
|
|||||||
// Detect possible edge indicating zero bit.
|
// Detect possible edge indicating zero bit.
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (SHA204_READ_PIN() == 0)
|
if (SHA204_PIN_READ() == 0)
|
||||||
{
|
{
|
||||||
// For an Atmel microcontroller this might be faster than "pulse_count++".
|
// For an Atmel microcontroller this might be faster than "pulse_count++".
|
||||||
pulse_count = 2;
|
pulse_count = 2;
|
||||||
@@ -224,7 +224,7 @@ uint8_t atsha204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
|
|||||||
{
|
{
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (SHA204_READ_PIN() != 0)
|
if (SHA204_PIN_READ() != 0)
|
||||||
break;
|
break;
|
||||||
} while (timeout_count-- > 0);
|
} while (timeout_count-- > 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -284,15 +284,15 @@
|
|||||||
#if !defined(ARDUINO_ARCH_AVR) // For everything else than AVR use pinMode / digitalWrite
|
#if !defined(ARDUINO_ARCH_AVR) // For everything else than AVR use pinMode / digitalWrite
|
||||||
#define SHA204_SET_OUTPUT() pinMode(device_pin, OUTPUT)
|
#define SHA204_SET_OUTPUT() pinMode(device_pin, OUTPUT)
|
||||||
#define SHA204_SET_INPUT() pinMode(device_pin, INPUT)
|
#define SHA204_SET_INPUT() pinMode(device_pin, INPUT)
|
||||||
#define SHA204_SET_HIGH() digitalWrite(device_pin, HIGH)
|
#define SHA204_POUT_HIGH() digitalWrite(device_pin, HIGH)
|
||||||
#define SHA204_SET_LOW() digitalWrite(device_pin, LOW)
|
#define SHA204_POUT_LOW() digitalWrite(device_pin, LOW)
|
||||||
#define SHA204_READ_PIN() digitalRead(device_pin)
|
#define SHA204_PIN_READ() digitalRead(device_pin)
|
||||||
#else
|
#else
|
||||||
#define SHA204_SET_INPUT() *device_port_DDR &= ~device_pin
|
#define SHA204_SET_INPUT() *device_port_DDR &= ~device_pin
|
||||||
#define SHA204_SET_OUTPUT() *device_port_DDR |= device_pin
|
#define SHA204_SET_OUTPUT() *device_port_DDR |= device_pin
|
||||||
#define SHA204_SET_HIGH() *device_port_OUT |= device_pin
|
#define SHA204_POUT_HIGH() *device_port_OUT |= device_pin
|
||||||
#define SHA204_SET_LOW() *device_port_OUT &= ~device_pin
|
#define SHA204_POUT_LOW() *device_port_OUT &= ~device_pin
|
||||||
#define SHA204_READ_PIN() (*device_port_IN & device_pin)
|
#define SHA204_PIN_READ() (*device_port_IN & device_pin)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class atsha204Class
|
class atsha204Class
|
||||||
|
|||||||
Reference in New Issue
Block a user