Updated core atsha204 driver for avr/samd compatability, renamed macro names in fat library

This commit is contained in:
Thomas Mørch
2015-12-10 17:24:58 +01:00
parent e2f45251a0
commit 62f9d9e654
4 changed files with 53 additions and 36 deletions
@@ -42,12 +42,12 @@ void ATSHA204Class::getSerialNumber(uint8_t * response)
void ATSHA204Class::swi_set_signal_pin(uint8_t is_high)
{
pinMode(device_pin, OUTPUT);
SHA204_SET_OUTPUT();
if (is_high)
digitalWrite(device_pin, HIGH);
SHA204_POUT_HIGH();
else
digitalWrite(device_pin, LOW);
SHA204_POUT_LOW();
}
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();
// Set signal pin as output.
pinMode(device_pin, OUTPUT);
digitalWrite(device_pin, HIGH);
SHA204_POUT_HIGH();
SHA204_SET_OUTPUT();
// Wait turn around time.
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])
{
digitalWrite(device_pin, LOW); //*device_port_OUT &= ~device_pin;
SHA204_POUT_LOW() //*device_port_OUT &= ~device_pin;
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;
}
else
{
// 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;
digitalWrite(device_pin, HIGH); //*device_port_OUT |= device_pin;
SHA204_POUT_HIGH() //*device_port_OUT |= device_pin;
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;
digitalWrite(device_pin, HIGH); //*device_port_OUT |= device_pin;
SHA204_POUT_HIGH() //*device_port_OUT |= device_pin;
delayMicroseconds(5*BIT_DELAY); //BIT_DELAY_5;
}
}
@@ -110,8 +111,8 @@ uint8_t ATSHA204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
noInterrupts(); //swi_disable_interrupts();
// Configure signal pin as input.
pinMode(device_pin, INPUT);
SHA204_SET_INPUT();
// Receive bits and store in buffer.
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)
{
// Wait for falling edge.
if (digitalRead(device_pin) == 0)
if (SHA204_PIN_READ() == 0)
break;
}
@@ -141,7 +142,7 @@ uint8_t ATSHA204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
do
{
// 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++".
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.
do
{
if (digitalRead(device_pin) == 0)
if (SHA204_PIN_READ() == 0)
{
// For an Atmel microcontroller this might be faster than "pulse_count++".
pulse_count = 2;
@@ -178,7 +179,7 @@ uint8_t ATSHA204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
{
do
{
if (digitalRead(device_pin) != 0)
if (SHA204_PIN_READ() != 0)
break;
} while (timeout_count-- > 0);
}
@@ -220,6 +220,22 @@
#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
{
private:
+13 -13
View File
@@ -89,10 +89,10 @@ void atsha204Class::swi_set_signal_pin(uint8_t is_high)
{
SHA204_SET_OUTPUT();
if (is_high) {
SHA204_SET_HIGH();
SHA204_POUT_HIGH();
}
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();
// Set signal pin as output.
SHA204_SET_HIGH();
SHA204_POUT_HIGH();
SHA204_SET_OUTPUT();
// Wait turn around time.
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])
{
SHA204_SET_LOW();
SHA204_POUT_LOW();
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
SHA204_SET_HIGH();
SHA204_POUT_HIGH();
delayMicroseconds(7*BIT_DELAY); //BIT_DELAY_7;
}
else
{
// Send a zero bit.
SHA204_SET_LOW();
SHA204_POUT_LOW();
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
SHA204_SET_HIGH();
SHA204_POUT_HIGH();
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
SHA204_SET_LOW();
SHA204_POUT_LOW();
delayMicroseconds(BIT_DELAY); //BIT_DELAY_1;
SHA204_SET_HIGH();
SHA204_POUT_HIGH();
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)
{
// Wait for falling edge.
if (SHA204_READ_PIN() == 0)
if (SHA204_PIN_READ() == 0)
break;
}
@@ -187,7 +187,7 @@ uint8_t atsha204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
do
{
// 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++".
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.
do
{
if (SHA204_READ_PIN() == 0)
if (SHA204_PIN_READ() == 0)
{
// For an Atmel microcontroller this might be faster than "pulse_count++".
pulse_count = 2;
@@ -224,7 +224,7 @@ uint8_t atsha204Class::swi_receive_bytes(uint8_t count, uint8_t *buffer)
{
do
{
if (SHA204_READ_PIN() != 0)
if (SHA204_PIN_READ() != 0)
break;
} while (timeout_count-- > 0);
}
+6 -6
View File
@@ -284,15 +284,15 @@
#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_SET_HIGH() digitalWrite(device_pin, HIGH)
#define SHA204_SET_LOW() digitalWrite(device_pin, LOW)
#define SHA204_READ_PIN() digitalRead(device_pin)
#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_SET_HIGH() *device_port_OUT |= device_pin
#define SHA204_SET_LOW() *device_port_OUT &= ~device_pin
#define SHA204_READ_PIN() (*device_port_IN & 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