Software License Agreement (BSD License)
- Copyright (c) 2010, microBuilder SARL
+ Copyright (c) 2011, microBuilder SARL
All rights reserved.
Redistribution and use in source and binary forms, with or without
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**************************************************************************/
+#include <stdlib.h>
#include <stdio.h>
+#include <string.h>
#include "projectconfig.h"
#include "sysinit.h"
-#include "drivers/sensors/pn532/pn532.h"
-#include "drivers/sensors/pn532/pn532_drvr.h"
+#include "core/gpio/gpio.h"
+#include "core/systick/systick.h"
+
+#include "drivers/displays/segment/as1115/as1115.h"
+
+#ifdef CFG_INTERFACE
+ #include "core/cmd/cmd.h"
+#endif
/**************************************************************************/
/*!
Main program entry point. After reset, normal code execution will
begin here.
-
- Note: CFG_INTERFACE is normally enabled by default. If you wish to
- enable the blinking LED code in main, you will need to open
- projectconfig.h, comment out "#define CFG_INTERFACE" and
- rebuild the project.
*/
/**************************************************************************/
-int main (void)
+int main(void)
{
- #ifdef CFG_INTERFACE
- //#error "CFG_INTERFACE must be disabled in projectconfig.h for this demo"
- #endif
- #if !defined CFG_PRINTF_USBCDC
- #error "CFG_PRINTF_USBCDC must be enabled in projectconfig.h for this demo"
- #endif
-
// Configure cpu and mandatory peripherals
systemInit();
-
- // Wait 5 second for someone to open the USB connection for printf
- systickDelay(5000);
- // Initialise the PN532
- pn532Init();
+ uint32_t currentSecond, lastSecond;
+ currentSecond = lastSecond = 0;
- byte_t response[256];
- size_t responseLen;
- pn532_error_t error;
+ // lcdTest();
- // Setup command to initialise a single ISO14443A target at 106kbps
- byte_t abtCommand[] = { PN532_COMMAND_INLISTPASSIVETARGET, 0x01, PN532_MODULATION_ISO14443A_106KBPS };
- while (1)
- {
- printf("%s", CFG_PRINTF_NEWLINE);
- printf("Wait for an ISO14443A card (Mifare Classic, etc.)%s", CFG_PRINTF_NEWLINE);
+ // as1115Test();
- // Send the command
- error = pn532Write(abtCommand, sizeof(abtCommand));
+ uint8_t displaybuffer[8];
- // Wait until we get a response or an unexpected error message
- do
- {
- error = pn532Read(response, &responseLen);
- systickDelay(25);
- }
- #ifdef PN532_UART
- while (error == PN532_ERROR_RESPONSEBUFFEREMPTY);
- #endif
- #ifdef PN532_SPI
- while ((error == PN532_ERROR_RESPONSEBUFFEREMPTY) || (error = PN532_ERROR_SPIREADYSTATUSTIMEOUT));
- #endif
+ displaybuffer[0] = 0x01 | 0x80;
+ displaybuffer[1] = 0x02 | 0x40;
+ displaybuffer[2] = 0x04 | 0x20;
+ displaybuffer[3] = 0x08 | 0x10;
+ displaybuffer[4] = 0x10 | 0x08,
+ displaybuffer[5] = 0x20 | 0x04;
+ displaybuffer[6] = 0x40 | 0X02;
+ displaybuffer[7] = 0x80 | 0X01;
- // Print the card details if possible
- if (!error)
- {
- /* Response for ISO14443A 106KBPS (Mifare Classic, etc.)
- See UM0701-02 section 7.3.5 for more information
-
- byte Description
- ------------- ------------------------------------------
- b7 Tags Found
- b8 Tag Number (only one used in this example)
- b9..10 SENS_RES
- b11 SEL_RES
- b12 NFCID Length
- b13..NFCIDLen NFCID
-
- SENS_RES SEL_RES Manufacturer/Card Type NFCID Len
- -------- ------- ----------------------- ---------
- 00 04 08 NXP Mifare Classic 1K 4 bytes */
-
- printf("%s", CFG_PRINTF_NEWLINE);
- printf("%-12s: %d %s", "Tags Found", response[7], CFG_PRINTF_NEWLINE);
- printf("%-12s: %02X %02X %s", "SENS_RES", response[9], response[10], CFG_PRINTF_NEWLINE);
- printf("%-12s: %02X %s", "SEL_RES", response[11], CFG_PRINTF_NEWLINE);
- printf("%-12s: ", "NFCID");
- size_t pos;
- for (pos=0; pos < response[12]; pos++)
- {
- printf("%02x ", response[13 + pos]);
- }
- printf(CFG_PRINTF_NEWLINE);
- }
- else
+ as1115WriteBuffer(displaybuffer);
+
+ while (1)
+ {
+ // Toggle LED once per second
+ currentSecond = systickGetSecondsActive();
+ if (currentSecond != lastSecond)
{
- // Oops .... something bad happened. Check 'error'
- printf("Ooops! Error %02X %s", error, CFG_PRINTF_NEWLINE);
+ lastSecond = currentSecond;
+ gpioSetValue(CFG_LED_PORT, CFG_LED_PIN, !(gpioGetValue(CFG_LED_PORT, CFG_LED_PIN)));
}
- // Wait at least one second before trying again
- systickDelay(1000);
+ // Poll for CLI input if CFG_INTERFACE is enabled in projectconfig.h
+ #ifdef CFG_INTERFACE
+ cmdPoll();
+ #endif
}
+
+ return 0;
}