Various changes for smartlcd boards
[hackover2013-badge-firmware.git] / main.c
diff --git a/main.c b/main.c
index 2011970..8b75435 100644 (file)
--- a/main.c
+++ b/main.c
@@ -7,7 +7,7 @@
 
     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"
+
+#ifdef CFG_INTERFACE
+  #include "core/cmd/cmd.h"
+#endif
 
 /**************************************************************************/
 /*! 
-    Main program entry point.  After reset, normal code execution will
-    begin here.
+    Approximates a 1 millisecond delay using "nop".  This is less
+    accurate than a dedicated timer, but is useful in certain situations.
 
-    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.
+    The number of ticks to delay depends on the optimisation level set
+    when compiling (-O).  Depending on the compiler settings, one of the
+    two defined values for 'delay' should be used.
 */
 /**************************************************************************/
-int main (void)
+void delayms(uint32_t ms)
 {
-  #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
+  uint32_t delay = ms * ((CFG_CPU_CCLK / 100) / 45);      // Release Mode (-Os)
+  // uint32_t delay = ms * ((CFG_CPU_CCLK / 100) / 120);  // Debug Mode (No optimisations)
+
+  while (delay > 0)
+  {
+    __asm volatile ("nop");
+    delay--;
+  }
+}
 
+/**************************************************************************/
+/*! 
+    Main program entry point.  After reset, normal code execution will
+    begin here.
+*/
+/**************************************************************************/
+int main(void)
+{
   // Configure cpu and mandatory peripherals
   systemInit();
-  
-  // Wait 5 second for someone to open the USB connection for printf
-  systickDelay(5000);
-
-  // Initialise the PN532
-  pn532Init();
 
-  byte_t response[256];
-  size_t responseLen;
-  pn532_error_t error;
-
-  // Setup command to initialise a single ISO14443A target at 106kbps 
-  byte_t abtCommand[] = { PN532_COMMAND_INLISTPASSIVETARGET, 0x01, PN532_MODULATION_ISO14443A_106KBPS };
+  uint32_t currentSecond, lastSecond;
+  currentSecond = lastSecond = 0;
 
   while (1)
   {
-    printf("%s", CFG_PRINTF_NEWLINE);
-    printf("Wait for an ISO14443A card (Mifare Classic, etc.)%s", CFG_PRINTF_NEWLINE);
-
-    // Send the command
-    error = pn532Write(abtCommand, sizeof(abtCommand));
-
-    // 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
-
-    // Print the card details if possible
-    if (!error)
+    // Toggle LED once per second ... rollover = 136 years :)
+    currentSecond = systickGetSecondsActive();
+    if (currentSecond != lastSecond)
     {
-      /* 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++) 
+      lastSecond = currentSecond;
+      if (gpioGetValue(CFG_LED_PORT, CFG_LED_PIN) == CFG_LED_OFF)
       {
-        printf("%02x ", response[13 + pos]);
+        gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_ON); 
+      }
+      else
+      {
+        gpioSetValue (CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF); 
       }
-      printf(CFG_PRINTF_NEWLINE);
-    }
-    else
-    {
-      // Oops .... something bad happened.  Check 'error'
-      printf("Ooops! Error %02X %s", error, CFG_PRINTF_NEWLINE);
     }
 
-    // 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;
 }
This page took 0.028589 seconds and 4 git commands to generate.