summaryrefslogtreecommitdiff
path: root/usb-i2c-sl018
diff options
context:
space:
mode:
authorOthmar Gsenger <otti@wirdorange.org>2013-01-27 18:50:31 +0000
committerOthmar Gsenger <otti@wirdorange.org>2013-01-27 18:50:31 +0000
commitd6e79be8c754144211e7c5dc2424583604a458cc (patch)
tree551f35ae81e1d8ddd7cc300594efcfd20b8cce15 /usb-i2c-sl018
parentbasic working version usb-i2c-sl018 (diff)
UID readout working
git-svn-id: https://svn.spreadspace.org/avr/trunk@69 aa12f405-d877-488e-9caf-2d797e2a1cc7
Diffstat (limited to 'usb-i2c-sl018')
-rw-r--r--usb-i2c-sl018/tuer-rfid.c43
1 files changed, 40 insertions, 3 deletions
diff --git a/usb-i2c-sl018/tuer-rfid.c b/usb-i2c-sl018/tuer-rfid.c
index f37c857..64831c1 100644
--- a/usb-i2c-sl018/tuer-rfid.c
+++ b/usb-i2c-sl018/tuer-rfid.c
@@ -24,6 +24,9 @@
#define PIN_B_INTERRUPT 1<<TAG_STA_BIT
//#define PIN_C_INTERRUPT 0
//#define PIN_D_INTERRUPT 0
+#define CARD_IN 0xe1
+#define CARD_OUT 0xe0
+
#include <avr/io.h>
#include <avr/wdt.h>
@@ -34,6 +37,7 @@
#include "led.h"
#include "LUFA/Drivers/Peripheral/TWI.h"
+#include "LUFA/Drivers/Misc/RingBuffer.h"
//const uint8_t SL018_ADDR = B10100000:
const uint8_t SL018_ADDR = 0xa0;
@@ -59,6 +63,8 @@ const unsigned char SL018CMD_ComRedLedOff[] ={2,0x40,0};
const unsigned char SL018CMD_ComGetFirmwareVersion[] ={1,0xF0};
unsigned char twi_rcv_buff[256];
+RingBuffer_t CmdBuffer;
+uint8_t CmdBufferData[128];
typedef struct __attribute__((__packed__))
@@ -118,7 +124,7 @@ unsigned char sl018_send_buffer(const unsigned char * buffer)
{
uint8_t len = 0;
uint8_t pos = 0;
- unsigned char ret;
+ //unsigned char ret;
len = buffer[0];
if (TWI_StartTransmission(SL018_ADDR | SL018_WRITE,10) == TWI_ERROR_NoError)
{
@@ -147,6 +153,7 @@ unsigned char sl018_send_buffer(const unsigned char * buffer)
void handle_cmd(uint8_t cmd)
{
char foo[10];
+ uint8_t pos;
switch(cmd) {
case '0': led_off(); break;
case '1': led_on(); break;
@@ -189,6 +196,27 @@ void handle_cmd(uint8_t cmd)
CDC_Device_SendString(&VirtualSerial_CDC_Interface, "I2C error\n\r");
}
break;
+ case CARD_IN:
+ CDC_Device_SendString(&VirtualSerial_CDC_Interface, "CARD IN\n\r");
+ if(sl018_send_buffer(SL018CMD_ComSelectCard))
+ {
+ led_toggle();
+ CDC_Device_SendString(&VirtualSerial_CDC_Interface, "I2C error\n\r");
+ } else {
+ snprintf(foo,sizeof(foo),"%x\n\r",twi_message->status);
+ CDC_Device_SendString(&VirtualSerial_CDC_Interface, "Status: ");
+ CDC_Device_SendString(&VirtualSerial_CDC_Interface, foo);
+ for (pos=twi_message->len - 4 ; pos< 255; pos--)
+ {
+ snprintf(foo,sizeof(foo),"%02X",twi_message->data[pos]);
+ CDC_Device_SendString(&VirtualSerial_CDC_Interface, foo);
+ }
+ CDC_Device_SendString(&VirtualSerial_CDC_Interface, "\n\r");
+ }
+ break;
+ case CARD_OUT:
+ CDC_Device_SendString(&VirtualSerial_CDC_Interface, "CARD OUT\n\r");
+ break;
default: CDC_Device_SendString(&VirtualSerial_CDC_Interface, "error\n\r"); return;
}
CDC_Device_SendString(&VirtualSerial_CDC_Interface, "ok\n\r");
@@ -198,9 +226,13 @@ void handle_cmd(uint8_t cmd)
static void PCint(void)
{
if( (TAG_STA_PIN >> TAG_STA_BIT) & 1)
+ {
+ RingBuffer_Insert(&CmdBuffer,CARD_OUT);
led_on();
- else
+ } else {
+ RingBuffer_Insert(&CmdBuffer,CARD_IN);
led_off();
+ }
}
SIGNAL(PCINT0_vect) {
@@ -223,6 +255,7 @@ int main(void)
//PCMSK1=PIN_C_INTERRUPT;
//PCMSK2=PIN_D_INTERRUPT;
PCICR|=1<<PCIE0;
+ RingBuffer_InitBuffer(&CmdBuffer, CmdBufferData, sizeof(CmdBufferData));
cpu_init();
led_init();
@@ -236,10 +269,14 @@ int main(void)
int16_t ReceivedByte = CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface);
if(!(ReceivedByte < 0)) {
handle_cmd(ReceivedByte);
+ RingBuffer_Insert(&CmdBuffer,(uint8_t) ReceivedByte);
}
BytesReceived--;
}
-
+ while(! RingBuffer_IsEmpty(&CmdBuffer) )
+ {
+ handle_cmd(RingBuffer_Remove(&CmdBuffer));
+ }
CDC_Device_USBTask(&VirtualSerial_CDC_Interface);
USB_USBTask();
}