Pārlūkot izejas kodu

"Merged" guus branch with developer

jancoow 9 gadi atpakaļ
vecāks
revīzija
00ae6d71b1
6 mainītis faili ar 1033 papildinājumiem un 784 dzēšanām
  1. 239 223
      display.c
  2. 65 63
      display.h
  3. 326 326
      keyboard.c
  4. 113 112
      keyboard.h
  5. 35 60
      main.c
  6. 255 0
      make.sh

+ 239 - 223
display.c

@@ -1,223 +1,239 @@
-/* ========================================================================
- * [PROJECT]    SIR100
- * [MODULE]     Display
- * [TITLE]      display source file
- * [FILE]       display.c
- * [VSN]        1.0
- * [CREATED]    26092003
- * [LASTCHNGD]  06102006
- * [COPYRIGHT]  Copyright (C) STREAMIT BV
- * [PURPOSE]    contains all interface- and low-level routines to
- *              control the LCD and write characters or strings (menu-items)
- * ======================================================================== */
-
-#define LOG_MODULE  LOG_DISPLAY_MODULE
-
-#include <stdio.h>
-#include <string.h>
-
-#include <sys/types.h>
-#include <sys/timer.h>
-#include <sys/event.h>
-#include <sys/thread.h>
-#include <sys/heap.h>
-
-#include "system.h"
-#include "portio.h"
-#include "display.h"
-#include "log.h"
-
-/*-------------------------------------------------------------------------*/
-/* local defines                                                           */
-/*-------------------------------------------------------------------------*/
-/*-------------------------------------------------------------------------*/
-/* local variable definitions                                              */
-/*-------------------------------------------------------------------------*/
-
-
-/*-------------------------------------------------------------------------*/
-/* local routines (prototyping)                                            */
-/*-------------------------------------------------------------------------*/
-static void LcdWriteByte(u_char, u_char);
-static void LcdWriteNibble(u_char, u_char);
-static void LcdWaitBusy(void);
-
-/*!
- * \addtogroup Display
- */
-
-/*@{*/
-
-/*-------------------------------------------------------------------------*/
-/*                         start of code                                   */
-/*-------------------------------------------------------------------------*/
-
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
-/*!
- * \brief control backlight
- */
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
-void LcdBackLight(u_char Mode)
-{
-    if (Mode==LCD_BACKLIGHT_ON)
-    {
-        sbi(LCD_BL_PORT, LCD_BL_BIT);   // Turn on backlight
-    }
-
-    if (Mode==LCD_BACKLIGHT_OFF)
-    {
-        cbi(LCD_BL_PORT, LCD_BL_BIT);   // Turn off backlight
-    }
-}
-
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
-/*!
- * \brief Write a single character on the LCD
- *
- * Writes a single character on the LCD on the current cursor position
- *
- * \param LcdChar character to write
- */
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
-void LcdChar(char MyChar)
-{
-    LcdWriteByte(WRITE_DATA, MyChar);
-}
-
-
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
-/*!
- * \brief Low-level initialisation function of the LCD-controller
- *
- * Initialise the controller and send the User-Defined Characters to CG-RAM
- * settings: 4-bit interface, cursor invisible and NOT blinking
- *           1 line dislay, 10 dots high characters
- *
- */
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
- void LcdLowLevelInit()
-{
-    u_char i;
-
-    NutDelay(140);                               // wait for more than 140 ms after Vdd rises to 2.7 V
-
-    for (i=0; i<3; ++i)
-    {
-        LcdWriteNibble(WRITE_COMMAND, 0x33);      // function set: 8-bit mode; necessary to guarantee that
-        NutDelay(4);                              // SIR starts up always in 5x10 dot mode
-    }
-
-    LcdWriteNibble(WRITE_COMMAND, 0x22);        // function set: 4-bit mode; necessary because KS0070 doesn't
-    NutDelay(1);                                // accept combined 4-bit mode & 5x10 dot mode programming
-
-    //LcdWriteByte(WRITE_COMMAND, 0x24);        // function set: 4-bit mode, 5x10 dot mode, 1-line
-    LcdWriteByte(WRITE_COMMAND, 0x28);          // function set: 4-bit mode, 5x7 dot mode, 2-lines
-    NutDelay(5);
-
-    LcdWriteByte(WRITE_COMMAND, 0x0C);          // display ON/OFF: display ON, cursor OFF, blink OFF
-    NutDelay(5);
-
-    LcdWriteByte(WRITE_COMMAND, 0x01);          // display clear
-    NutDelay(5);
-
-    LcdWriteByte(WRITE_COMMAND, 0x06);          // entry mode set: increment mode, entire shift OFF
-
-
-    LcdWriteByte(WRITE_COMMAND, 0x80);          // DD-RAM address counter (cursor pos) to '0'
-}
-
-
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
-/*!
- * \brief Low-level routine to write a byte to LCD-controller
- *
- * Writes one byte to the LCD-controller (by  calling LcdWriteNibble twice)
- * CtrlState determines if the byte is written to the instruction register
- * or to the data register.
- *
- * \param CtrlState destination: instruction or data
- * \param LcdByte byte to write
- *
- */
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
-static void LcdWriteByte(u_char CtrlState, u_char LcdByte)
-{
-    LcdWaitBusy();                      // see if the controller is ready to receive next byte
-    LcdWriteNibble(CtrlState, LcdByte & 0xF0);
-    LcdWriteNibble(CtrlState, LcdByte << 4);
-
-}
-
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
-/*!
- * \brief Low-level routine to write a nibble to LCD-controller
- *
- * Writes a nibble to the LCD-controller (interface is a 4-bit databus, so
- * only 4 databits can be send at once).
- * The nibble to write is in the upper 4 bits of LcdNibble
- *
- * \param CtrlState destination: instruction or data
- * \param LcdNibble nibble to write (upper 4 bits in this byte
- *
- */
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
-static void LcdWriteNibble(u_char CtrlState, u_char LcdNibble)
-{
-    outp((inp(LCD_DATA_DDR) & 0x0F) | 0xF0, LCD_DATA_DDR);  // set data-port to output again
-
-    outp((inp(LCD_DATA_PORT) & 0x0F) | (LcdNibble & 0xF0), LCD_DATA_PORT); // prepare databus with nibble to write
-
-    if (CtrlState == WRITE_COMMAND)
-    {
-        cbi(LCD_RS_PORT, LCD_RS);     // command: RS low
-    }
-    else
-    {
-        sbi(LCD_RS_PORT, LCD_RS);     // data: RS high
-    }
-
-    sbi(LCD_EN_PORT, LCD_EN);
-
-    asm("nop\n\tnop");                    // small delay
-
-    cbi(LCD_EN_PORT, LCD_EN);
-    cbi(LCD_RS_PORT, LCD_RS);
-    outp((inp(LCD_DATA_DDR) & 0x0F), LCD_DATA_DDR);           // set upper 4-bits of data-port to input
-    outp((inp(LCD_DATA_PORT) & 0x0F) | 0xF0, LCD_DATA_PORT);  // enable pull-ups in data-port
-}
-
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
-/*!
- * \brief Low-level routine to see if the controller is ready to receive
- *
- * This routine repeatetly reads the databus and checks if the highest bit (bit 7)
- * has become '0'. If a '0' is detected on bit 7 the function returns.
- *
- */
-/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
-static void LcdWaitBusy()
-{
-    u_char Busy = 1;
-	u_char LcdStatus = 0;
-
-    cbi (LCD_RS_PORT, LCD_RS);              // select instruction register
-
-    sbi (LCD_RW_PORT, LCD_RW);              // we are going to read
-
-    while (Busy)
-    {
-        sbi (LCD_EN_PORT, LCD_EN);          // set 'enable' to catch 'Ready'
-
-        asm("nop\n\tnop");                  // small delay
-        LcdStatus =  inp(LCD_IN_PORT);      // LcdStatus is used elsewhere in this module as well
-        Busy = LcdStatus & 0x80;            // break out of while-loop cause we are ready (b7='0')
-    }
-
-    cbi (LCD_EN_PORT, LCD_EN);              // all ctrlpins low
-    cbi (LCD_RS_PORT, LCD_RS);
-    cbi (LCD_RW_PORT, LCD_RW);              // we are going to write
-}
-
-/* ---------- end of module ------------------------------------------------ */
-
-/*@}*/
+/* ========================================================================
+ * [PROJECT]    SIR100
+ * [MODULE]     Display
+ * [TITLE]      display source file
+ * [FILE]       display.c
+ * [VSN]        1.0
+ * [CREATED]    26092003
+ * [LASTCHNGD]  06102006
+ * [COPYRIGHT]  Copyright (C) STREAMIT BV
+ * [PURPOSE]    contains all interface- and low-level routines to
+ *              control the LCD and write characters or strings (menu-items)
+ * ======================================================================== */
+
+#define LOG_MODULE  LOG_DISPLAY_MODULE
+
+#include <stdio.h>
+#include <string.h>
+
+#include <sys/types.h>
+#include <sys/timer.h>
+#include <sys/event.h>
+#include <sys/thread.h>
+#include <sys/heap.h>
+
+#include "system.h"
+#include "portio.h"
+#include "display.h"
+#include "log.h"
+
+/*-------------------------------------------------------------------------*/
+/* local defines                                                           */
+/*-------------------------------------------------------------------------*/
+/*-------------------------------------------------------------------------*/
+/* local variable definitions                                              */
+/*-------------------------------------------------------------------------*/
+
+
+/*-------------------------------------------------------------------------*/
+/* local routines (prototyping)                                            */
+/*-------------------------------------------------------------------------*/
+static void LcdWriteByte(u_char, u_char);
+static void LcdWriteNibble(u_char, u_char);
+static void LcdWaitBusy(void);
+
+/*!
+ * \addtogroup Display
+ */
+
+/*@{*/
+
+/*-------------------------------------------------------------------------*/
+/*                         start of code                                   */
+/*-------------------------------------------------------------------------*/
+
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/*!
+ * \brief control backlight
+ */
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+void LcdBackLight(u_char Mode)
+{
+    if (Mode==LCD_BACKLIGHT_ON)
+    {
+        sbi(LCD_BL_PORT, LCD_BL_BIT);   // Turn on backlight
+    }
+
+    if (Mode==LCD_BACKLIGHT_OFF)
+    {
+        cbi(LCD_BL_PORT, LCD_BL_BIT);   // Turn off backlight
+    }
+}
+
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/*!
+ * \brief Write a single character on the LCD
+ *
+ * Writes a single character on the LCD on the current cursor position
+ *
+ * \param LcdChar character to write
+ */
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+void LcdChar(char MyChar)
+{
+    LcdWriteByte(WRITE_DATA, MyChar);
+}
+
+
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/*!
+ * \brief Low-level initialisation function of the LCD-controller
+ *
+ * Initialise the controller and send the User-Defined Characters to CG-RAM
+ * settings: 4-bit interface, cursor invisible and NOT blinking
+ *           1 line dislay, 10 dots high characters
+ *
+ */
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+ void LcdLowLevelInit()
+{
+    u_char i;
+
+    NutDelay(140);                               // wait for more than 140 ms after Vdd rises to 2.7 V
+
+    for (i=0; i<3; ++i)
+    {
+        LcdWriteNibble(WRITE_COMMAND, 0x33);      // function set: 8-bit mode; necessary to guarantee that
+        NutDelay(4);                              // SIR starts up always in 5x10 dot mode
+    }
+
+    LcdWriteNibble(WRITE_COMMAND, 0x22);        // function set: 4-bit mode; necessary because KS0070 doesn't
+    NutDelay(1);                                // accept combined 4-bit mode & 5x10 dot mode programming
+
+    //LcdWriteByte(WRITE_COMMAND, 0x24);        // function set: 4-bit mode, 5x10 dot mode, 1-line
+    LcdWriteByte(WRITE_COMMAND, 0x28);          // function set: 4-bit mode, 5x7 dot mode, 2-lines
+    NutDelay(5);
+
+    LcdWriteByte(WRITE_COMMAND, 0x0C);          // display ON/OFF: display ON, cursor OFF, blink OFF
+    NutDelay(5);
+
+    LcdWriteByte(WRITE_COMMAND, 0x01);          // display clear
+    NutDelay(5);
+
+    LcdWriteByte(WRITE_COMMAND, 0x06);          // entry mode set: increment mode, entire shift OFF
+
+
+    LcdWriteByte(WRITE_COMMAND, 0x80);          // DD-RAM address counter (cursor pos) to '0'
+}
+
+
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/*!
+ * \brief Low-level routine to write a byte to LCD-controller
+ *
+ * Writes one byte to the LCD-controller (by  calling LcdWriteNibble twice)
+ * CtrlState determines if the byte is written to the instruction register
+ * or to the data register.
+ *
+ * \param CtrlState destination: instruction or data
+ * \param LcdByte byte to write
+ *
+ */
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+static void LcdWriteByte(u_char CtrlState, u_char LcdByte)
+{
+    LcdWaitBusy();                      // see if the controller is ready to receive next byte
+    LcdWriteNibble(CtrlState, LcdByte & 0xF0);
+    LcdWriteNibble(CtrlState, LcdByte << 4);
+
+}
+
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/*!
+ * \brief Low-level routine to write a nibble to LCD-controller
+ *
+ * Writes a nibble to the LCD-controller (interface is a 4-bit databus, so
+ * only 4 databits can be send at once).
+ * The nibble to write is in the upper 4 bits of LcdNibble
+ *
+ * \param CtrlState destination: instruction or data
+ * \param LcdNibble nibble to write (upper 4 bits in this byte
+ *
+ */
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+static void LcdWriteNibble(u_char CtrlState, u_char LcdNibble)
+{
+    outp((inp(LCD_DATA_DDR) & 0x0F) | 0xF0, LCD_DATA_DDR);  // set data-port to output again
+
+    outp((inp(LCD_DATA_PORT) & 0x0F) | (LcdNibble & 0xF0), LCD_DATA_PORT); // prepare databus with nibble to write
+
+    if (CtrlState == WRITE_COMMAND)
+    {
+        cbi(LCD_RS_PORT, LCD_RS);     // command: RS low
+    }
+    else
+    {
+        sbi(LCD_RS_PORT, LCD_RS);     // data: RS high
+    }
+
+    sbi(LCD_EN_PORT, LCD_EN);
+
+    asm("nop\n\tnop");                    // small delay
+
+    cbi(LCD_EN_PORT, LCD_EN);
+    cbi(LCD_RS_PORT, LCD_RS);
+    outp((inp(LCD_DATA_DDR) & 0x0F), LCD_DATA_DDR);           // set upper 4-bits of data-port to input
+    outp((inp(LCD_DATA_PORT) & 0x0F) | 0xF0, LCD_DATA_PORT);  // enable pull-ups in data-port
+}
+
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/*!
+ * \brief Low-level routine to see if the controller is ready to receive
+ *
+ * This routine repeatetly reads the databus and checks if the highest bit (bit 7)
+ * has become '0'. If a '0' is detected on bit 7 the function returns.
+ *
+ */
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+static void LcdWaitBusy()
+{
+    u_char Busy = 1;
+	u_char LcdStatus = 0;
+
+    cbi (LCD_RS_PORT, LCD_RS);              // select instruction register
+
+    sbi (LCD_RW_PORT, LCD_RW);              // we are going to read
+
+    while (Busy)
+    {
+        sbi (LCD_EN_PORT, LCD_EN);          // set 'enable' to catch 'Ready'
+
+        asm("nop\n\tnop");                  // small delay
+        LcdStatus =  inp(LCD_IN_PORT);      // LcdStatus is used elsewhere in this module as well
+        Busy = LcdStatus & 0x80;            // break out of while-loop cause we are ready (b7='0')
+    }
+
+    cbi (LCD_EN_PORT, LCD_EN);              // all ctrlpins low
+    cbi (LCD_RS_PORT, LCD_RS);
+    cbi (LCD_RW_PORT, LCD_RW);              // we are going to write
+}
+//clears the Lcd screen
+void ClearLcd()
+{
+	LcdWriteByte(WRITE_COMMAND, 0x01);
+}
+
+void LcdArray(char *data, int size)
+{
+	int i;
+	
+	ClearLcd();
+	NutSleep(5);
+	for(i = 0; i < size; i = i + 1){
+		LcdChar(data[i]);
+	}
+}
+
+/* ---------- end of module ------------------------------------------------ */
+	
+/*@}*/

+ 65 - 63
display.h

@@ -1,63 +1,65 @@
-/* ========================================================================
- * [PROJECT]    SIR100
- * [MODULE]     Display
- * [TITLE]      display header file
- * [FILE]       display.h
- * [VSN]        1.0
- * [CREATED]    030414
- * [LASTCHNGD]  030414
- * [COPYRIGHT]  Copyright (C) STREAMIT BV 2010
- * [PURPOSE]    API and gobal defines for display module
- * ======================================================================== */
-
-#ifndef _Display_H
-#define _Display_H
-
-
-/*-------------------------------------------------------------------------*/
-/* global defines                                                          */
-/*-------------------------------------------------------------------------*/
-#define DISPLAY_SIZE                16
-#define NROF_LINES                  2
-#define MAX_SCREEN_CHARS            (NROF_LINES*DISPLAY_SIZE)
-
-#define LINE_0                      0
-#define LINE_1                      1
-
-#define FIRSTPOS_LINE_0             0
-#define FIRSTPOS_LINE_1             0x40
-
-
-#define LCD_BACKLIGHT_ON            1
-#define LCD_BACKLIGHT_OFF           0
-
-#define ALL_ZERO          			0x00      // 0000 0000 B
-#define WRITE_COMMAND     			0x02      // 0000 0010 B
-#define WRITE_DATA        			0x03      // 0000 0011 B
-#define READ_COMMAND      			0x04      // 0000 0100 B
-#define READ_DATA         			0x06      // 0000 0110 B
-
-
-/*-------------------------------------------------------------------------*/
-/* typedefs & structs                                                      */
-/*-------------------------------------------------------------------------*/
-
-/*--------------------------------------------------------------------------*/
-/*  Global variables                                                        */
-/*--------------------------------------------------------------------------*/
-
-/*-------------------------------------------------------------------------*/
-/* export global routines (interface)                                      */
-/*-------------------------------------------------------------------------*/
-extern void LcdChar(char);
-extern void LcdBackLight(u_char);
-extern void LcdInit(void);
-extern void LcdLowLevelInit(void);
-
-#endif /* _Display_H */
-/*  ÍÍÍÍ  End Of File  ÍÍÍÍÍÍÍÍ ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
-
-
-
-
-
+/* ========================================================================
+ * [PROJECT]    SIR100
+ * [MODULE]     Display
+ * [TITLE]      display header file
+ * [FILE]       display.h
+ * [VSN]        1.0
+ * [CREATED]    030414
+ * [LASTCHNGD]  030414
+ * [COPYRIGHT]  Copyright (C) STREAMIT BV 2010
+ * [PURPOSE]    API and gobal defines for display module
+ * ======================================================================== */
+
+#ifndef _Display_H
+#define _Display_H
+
+
+/*-------------------------------------------------------------------------*/
+/* global defines                                                          */
+/*-------------------------------------------------------------------------*/
+#define DISPLAY_SIZE                16
+#define NROF_LINES                  2
+#define MAX_SCREEN_CHARS            (NROF_LINES*DISPLAY_SIZE)
+
+#define LINE_0                      0
+#define LINE_1                      1
+
+#define FIRSTPOS_LINE_0             0
+#define FIRSTPOS_LINE_1             0x40
+
+
+#define LCD_BACKLIGHT_ON            1
+#define LCD_BACKLIGHT_OFF           0
+
+#define ALL_ZERO          			0x00      // 0000 0000 B
+#define WRITE_COMMAND     			0x02      // 0000 0010 B
+#define WRITE_DATA        			0x03      // 0000 0011 B
+#define READ_COMMAND      			0x04      // 0000 0100 B
+#define READ_DATA         			0x06      // 0000 0110 B
+
+
+/*-------------------------------------------------------------------------*/
+/* typedefs & structs                                                      */
+/*-------------------------------------------------------------------------*/
+
+/*--------------------------------------------------------------------------*/
+/*  Global variables                                                        */
+/*--------------------------------------------------------------------------*/
+
+/*-------------------------------------------------------------------------*/
+/* export global routines (interface)                                      */
+/*-------------------------------------------------------------------------*/
+extern void LcdChar(char);
+extern void LcdBackLight(u_char);
+extern void LcdInit(void);
+extern void LcdLowLevelInit(void);
+void ClearLcd(void);
+void LcdArray(char*, int);
+
+#endif /* _Display_H */
+/*  ÍÍÍÍ  End Of File  ÍÍÍÍÍÍÍÍ ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+
+
+
+
+

+ 326 - 326
keyboard.c

@@ -1,326 +1,326 @@
-/*! \file
- * keyboard.c contains the low-level keyboard scan and the
- * interfacing with NutOS (signalling)
- *  Copyright STREAMIT, 2010.
- *  \version 1.0
- *  \date 26 september 2003
- */
-
-
-#define LOG_MODULE  LOG_KEYBOARD_MODULE
-
-#include <sys/atom.h>
-#include <sys/event.h>
-
-//#pragma text:appcode
-
-#include "keyboard.h"
-#include "portio.h"
-#include "system.h"
-
-/*-------------------------------------------------------------------------*/
-/* local defines                                                          */
-/*-------------------------------------------------------------------------*/
-/*
- *  definition of raw keys as found in keyboardscan
- *  Note that these 16-bit values are remapped before
- *  the application uses them
- */
-#define RAW_KEY_01         0xFFFB
-#define RAW_KEY_02         0xFFFD
-#define RAW_KEY_03         0xFF7F
-#define RAW_KEY_04         0xFFF7
-#define RAW_KEY_05         0xFFFE
-#define RAW_KEY_ALT        0xFFBF
-
-#define RAW_KEY_ESC        0xFFEF
-#define RAW_KEY_UP         0xF7FF
-#define RAW_KEY_OK         0xFFDF
-#define RAW_KEY_LEFT       0xFEFF
-#define RAW_KEY_DOWN       0xFBFF
-#define RAW_KEY_RIGHT      0xFDFF
-
-#define RAW_KEY_POWER      0xEFFF
-
-#define RAW_KEY_SETUP      0xFFCF       // combine 'ESCAPE' (0xFFEF') with 'OK' (0xFFDF)
-
-/*-------------------------------------------------------------------------*/
-/* local variable definitions                                              */
-/*-------------------------------------------------------------------------*/
-static HANDLE  hKBEvent;
-static u_short KeyFound;        // use short for 4 nibbles (4 colums)
-static u_char KeyBuffer[KB_BUFFER_SIZE];
-static u_short HoldCounter;
-static u_char KbState;
-static u_char KeyRepeatArray[KEY_NROF_KEYS];
-
-/*-------------------------------------------------------------------------*/
-/* local routines (prototyping)                                            */
-/*-------------------------------------------------------------------------*/
-static void KbClearEvent(HANDLE*);
-static u_char KbRemapKey(u_short LongKey);
-
-
-/*!
- * \addtogroup Keyboard
- */
-
-/*@{*/
-
-/*-------------------------------------------------------------------------*/
-/*                         start of code                                   */
-/*-------------------------------------------------------------------------*/
-
-
-
-
-/* ����������������������������������������������������������������������� */
-/*!
- * \brief Clear the eventbuffer of this module
- *
- * This routine is called during module initialization.
- *
- * \param *pEvent pointer to the event queue
- */
-/* ����������������������������������������������������������������������� */
-static void KbClearEvent(HANDLE *pEvent)
-{
-    NutEnterCritical();
-
-    *pEvent = 0;
-
-    NutExitCritical();
-}
-
-/* ����������������������������������������������������������������������� */
-/*!
- * \brief Low-level keyboard scan
- *
- * KbScan is called each 4.44 msec from MainBeat interrupt
- * Remember: pressed key gives a '0' on KB_IN_READ
- *
- * After each keyboard-scan, check for a valid MMCard
- */
-/* ����������������������������������������������������������������������� */
-void KbScan()
-{
-    u_char KeyNibble0, KeyNibble1, KeyNibble2, KeyNibble3;
-
-    /*
-     *  we must scan 4 colums, 2 in PORTG and 2 in PORTD
-     */
-
-#ifndef USE_JTAG
-    // scan keys in COL 0
-    cbi (KB_OUT_WRITE_A, KB_COL_0);
-    asm("nop\n\tnop");                    // small delay
-    KeyNibble0 = inp(KB_IN_READ) & KB_ROW_MASK;
-    sbi (KB_OUT_WRITE_A, KB_COL_0);
-
-    // scan keys in COL 1
-    cbi (KB_OUT_WRITE_A, KB_COL_1);
-    asm("nop\n\tnop");                    // small delay
-    KeyNibble1 = inp(KB_IN_READ) & KB_ROW_MASK;
-    sbi (KB_OUT_WRITE_A, KB_COL_1);
-
-    // scan keys in COL 2
-    cbi (KB_OUT_WRITE_B, KB_COL_2);
-    asm("nop\n\tnop");                    // small delay
-    KeyNibble2 = inp(KB_IN_READ) & KB_ROW_MASK;
-    sbi (KB_OUT_WRITE_B, KB_COL_2);
-
-    // scan keys in COL 3
-    cbi (KB_OUT_WRITE_B, KB_COL_3);
-    asm("nop\n\tnop");                    // small delay
-    KeyNibble3 = inp(KB_IN_READ) & KB_ROW_MASK;
-    sbi (KB_OUT_WRITE_B, KB_COL_3);
-
-
-    /*
-     *  we want to detect exactly 1 key in exactly 1 colom
-     *  exception is the combination of VOLMIN & POWER (-> SETUP)
-     *  meaning: Keynibble0==[0000 1011] (KEY_VOLMIN) & KeyNibble1==[0111 0000] (KEY_POWER)
-     */
-
-    /*
-     *  put all 4 seperate nibbles in place in 'KeyFound'
-     *
-     *  KeyNibble0 on b3...b0  (col 0)
-     *  KeyNibble1 on b7...b4  (col 1)
-     *  KeyNibble2 on b11..b8  (col 2)
-     *  KeyNibble3 on b15..b12 (col 3)
-     */
-
-    KeyFound =  ((KeyNibble0>>4) & 0x000F);     // b7..b4 in 'KeyNibble0' to b3...b0  in 'KeyFound' >> shift 4 right
-    KeyFound |= (KeyNibble1 & 0x00F0);          // b7..b4 in 'KeyNibble1' to b7...b4  in 'KeyFound' -- do nothing
-    KeyFound |= ((KeyNibble2<<4) & 0x0F00);     // b7..b4 in 'KeyNibble2' to b11..b8  in 'KeyFound' << shift 4 left
-    KeyFound |= ((KeyNibble3<<8) & 0xF000);     // b7..b4 in 'KeyNibble3' to b15..b12 in 'KeyFound' << shift 8 left
-
-
-#endif  // USE_JTAG
-
-}
-
-/* ����������������������������������������������������������������������� */
-/*!
- * \brief Remap the 16-bit value for the active key to an 8-bit value
- *
- */
-/* ����������������������������������������������������������������������� */
-static u_char KbRemapKey(u_short LongKey)
-{
-    switch (LongKey)
-    {
-        case RAW_KEY_01:        return(KEY_01);
-        case RAW_KEY_02:        return(KEY_02);
-        case RAW_KEY_03:        return(KEY_03);
-        case RAW_KEY_04:        return(KEY_04);
-        case RAW_KEY_05:        return(KEY_05);
-        case RAW_KEY_ALT:       return(KEY_ALT);
-
-        case RAW_KEY_ESC:       return(KEY_ESC);
-        case RAW_KEY_UP:        return(KEY_UP);
-        case RAW_KEY_OK:        return(KEY_OK);
-        case RAW_KEY_LEFT:      return(KEY_LEFT);
-        case RAW_KEY_DOWN:      return(KEY_DOWN);
-        case RAW_KEY_RIGHT:     return(KEY_RIGHT);
-
-        case RAW_KEY_POWER:     return(KEY_POWER);
-        case RAW_KEY_SETUP:     return(KEY_SETUP);      // combined key
-
-        default:                return(KEY_UNDEFINED);
-    }
-}
-
-/* ����������������������������������������������������������������������� */
-/*!
- * \brief Return the repeating property for this key
- *
- * \return 'TRUE' in case the key was repeating, 'FALSE' if not
- *
- */
-/* ����������������������������������������������������������������������� */
-static u_char KbKeyIsRepeating(u_short Key)
-{
-    return(KeyRepeatArray[KbRemapKey(Key)]==KEY_REPEAT);
-}
-
-/* ����������������������������������������������������������������������� */
-/*!
- * \brief set the property of this key to repeating or not-repeating
- *
- */
-/* ����������������������������������������������������������������������� */
-void KbSetKeyRepeating(u_char Key, u_char Property)
-{
-    // check arguments
-    if (((Property==KEY_REPEAT) || (Property==KEY_NO_REPEAT)) && (Key < KEY_NROF_KEYS))
-    {
-        KeyRepeatArray[Key]=Property;
-    }
-}
-
-/* ����������������������������������������������������������������������� */
-/*!
- * \brief Wait until an event was pushed on the eventqueue for this module
- *
- * This routine provides the event interface for other Luks-modules
- *
- * \param dwTimeout time in milisecs that this routine should wait before
- * it will return with KB_ERROR
- *
- * \return KB_OK in case an event was found
- * \return KB_ERROR in case no event was found (return due to timeout)
- */
-/* ����������������������������������������������������������������������� */
-int KbWaitForKeyEvent(u_long dwTimeout)
-{
-
-    int nError = KB_OK;
-    int nTimeout;
-
-    nTimeout = NutEventWait(&hKBEvent, dwTimeout);
-    if (nTimeout == -1)
-    {
-        nError = KB_ERROR;
-    }
-
-    return(nError);
-}
-
-/* ����������������������������������������������������������������������� */
-/*!
- * \brief Return the databyte that was receeived in the IR-stream
- *
- * In case a valid key is found in the keyboard scan, the key-code is
- * stored in the keyboardbuffer. This routine returns the first available
- * valid key in this buffer
-
- * \return the keycode that was found by the keyboard scan
- *
- * \todo implement a key-buffer for this routine
- */
-/* ����������������������������������������������������������������������� */
-u_char KbGetKey()
-{
-    return(KeyBuffer[0]);
-}
-
-/*!
- * \brief inject a virtual key into the system
- *
- */
-void KbInjectKey(u_char VirtualKey)
-{
-    KeyBuffer[0]=VirtualKey;
-    NutEventPostFromIrq(&hKBEvent);   // 'valid key' detected -> generate Event
-}
-/* ����������������������������������������������������������������������� */
-/*!
- * \brief Initialise the Keyboard module
- *
- *
- * - initialise the keyboard read- and write port
- * - flush the keyboardbuffer
- * - flush the eventqueue for this module
- *
- * \note PORTF uses internal pull-ups. That's why a '1' is read
- * when no key is pressed. Use negative logic to detect keys.
- * So default state of the colums is '1'
- */
-/* ����������������������������������������������������������������������� */
-void KbInit()
-{
-    u_char i;
-
-    sbi (KB_OUT_WRITE_A, KB_COL_0);
-    sbi (KB_OUT_WRITE_A, KB_COL_1);
-    sbi (KB_OUT_WRITE_B, KB_COL_2);
-    sbi (KB_OUT_WRITE_B, KB_COL_3);
-
-    KbState = KB_IDLE;
-    KeyFound = KEY_NO_KEY;
-
-    KbClearEvent(&hKBEvent);
-
-    for (i=0;i<KB_BUFFER_SIZE;++i)
-    {
-        KeyBuffer[i] = (u_char)KEY_NO_KEY;
-    }
-
-    for (i=0; i<KEY_NROF_KEYS; ++i)
-    {
-        KeyRepeatArray[i]=KEY_NO_REPEAT;
-    }
-
-    HoldCounter=0;
-
-    // arrow keys are repeating keys by default
-    KbSetKeyRepeating(KEY_UP, KEY_REPEAT);
-    KbSetKeyRepeating(KEY_DOWN, KEY_REPEAT);
-    KbSetKeyRepeating(KEY_LEFT, KEY_REPEAT);
-    KbSetKeyRepeating(KEY_RIGHT, KEY_REPEAT);
-}
-/* ---------- end of module ------------------------------------------------ */
-
-/*@}*/
+/*! \file
+ * keyboard.c contains the low-level keyboard scan and the
+ * interfacing with NutOS (signalling)
+ *  Copyright STREAMIT, 2010.
+ *  \version 1.0
+ *  \date 26 september 2003
+ */
+
+
+#define LOG_MODULE  LOG_KEYBOARD_MODULE
+
+#include <sys/atom.h>
+#include <sys/event.h>
+
+//#pragma text:appcode
+
+#include "log.h"
+#include "keyboard.h"
+#include "portio.h"
+#include "system.h"
+
+/*-------------------------------------------------------------------------*/
+/* local defines                                                          */
+/*-------------------------------------------------------------------------*/
+/*
+ *  definition of raw keys as found in keyboardscan
+ *  Note that these 16-bit values are remapped before
+ *  the application uses them
+ */
+#define RAW_KEY_01         0xFFFB
+#define RAW_KEY_02         0xFFFD
+#define RAW_KEY_03         0xFF7F
+#define RAW_KEY_04         0xFFF7
+#define RAW_KEY_05         0xFFFE
+#define RAW_KEY_ALT        0xFFBF
+
+#define RAW_KEY_ESC        0xFFEF
+#define RAW_KEY_UP         0xF7FF
+#define RAW_KEY_OK         0xFFDF
+#define RAW_KEY_LEFT       0xFEFF
+#define RAW_KEY_DOWN       0xFBFF
+#define RAW_KEY_RIGHT      0xFDFF
+
+#define RAW_KEY_POWER      0xEFFF
+
+#define RAW_KEY_SETUP      0xFFCF       // combine 'ESCAPE' (0xFFEF') with 'OK' (0xFFDF)
+
+/*-------------------------------------------------------------------------*/
+/* local variable definitions                                              */
+/*-------------------------------------------------------------------------*/
+static HANDLE  hKBEvent;
+static u_short KeyFound;        // use short for 4 nibbles (4 colums)
+static u_char KeyBuffer[KB_BUFFER_SIZE];
+static u_short HoldCounter;
+static u_char KbState;
+static u_char KeyRepeatArray[KEY_NROF_KEYS];
+
+/*-------------------------------------------------------------------------*/
+/* local routines (prototyping)                                            */
+/*-------------------------------------------------------------------------*/
+static void KbClearEvent(HANDLE*);
+static u_char KbRemapKey(u_short LongKey);
+
+
+/*!
+ * \addtogroup Keyboard
+ */
+
+/*@{*/
+
+/*-------------------------------------------------------------------------*/
+/*                         start of code                                   */
+/*-------------------------------------------------------------------------*/
+
+
+
+
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/*!
+ * \brief Clear the eventbuffer of this module
+ *
+ * This routine is called during module initialization.
+ *
+ * \param *pEvent pointer to the event queue
+ */
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+static void KbClearEvent(HANDLE *pEvent)
+{
+    NutEnterCritical();
+
+    *pEvent = 0;
+
+    NutExitCritical();
+}
+
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/*!
+ * \brief Low-level keyboard scan
+ *
+ * KbScan is called each 4.44 msec from MainBeat interrupt
+ * Remember: pressed key gives a '0' on KB_IN_READ
+ *
+ * After each keyboard-scan, check for a valid MMCard
+ */
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+int KbScan()
+{
+    u_char KeyNibble0, KeyNibble1, KeyNibble2, KeyNibble3;
+
+    /*
+     *  we must scan 4 colums, 2 in PORTG and 2 in PORTD
+     */
+
+#ifndef USE_JTAG
+    // scan keys in COL 0
+    cbi (KB_OUT_WRITE_A, KB_COL_0);
+    asm("nop\n\tnop");                    // small delay
+    KeyNibble0 = inp(KB_IN_READ) & KB_ROW_MASK;
+    sbi (KB_OUT_WRITE_A, KB_COL_0);
+
+    // scan keys in COL 1
+    cbi (KB_OUT_WRITE_A, KB_COL_1);
+    asm("nop\n\tnop");                    // small delay
+    KeyNibble1 = inp(KB_IN_READ) & KB_ROW_MASK;
+    sbi (KB_OUT_WRITE_A, KB_COL_1);
+
+    // scan keys in COL 2
+    cbi (KB_OUT_WRITE_B, KB_COL_2);
+    asm("nop\n\tnop");                    // small delay
+    KeyNibble2 = inp(KB_IN_READ) & KB_ROW_MASK;
+    sbi (KB_OUT_WRITE_B, KB_COL_2);
+
+    // scan keys in COL 3
+    cbi (KB_OUT_WRITE_B, KB_COL_3);
+    asm("nop\n\tnop");                    // small delay
+    KeyNibble3 = inp(KB_IN_READ) & KB_ROW_MASK;
+    sbi (KB_OUT_WRITE_B, KB_COL_3);
+
+
+    /*
+     *  we want to detect exactly 1 key in exactly 1 colom
+     *  exception is the combination of VOLMIN & POWER (-> SETUP)
+     *  meaning: Keynibble0==[0000 1011] (KEY_VOLMIN) & KeyNibble1==[0111 0000] (KEY_POWER)
+     */
+
+    /*
+     *  put all 4 seperate nibbles in place in 'KeyFound'
+     *
+     *  KeyNibble0 on b3...b0  (col 0)
+     *  KeyNibble1 on b7...b4  (col 1)
+     *  KeyNibble2 on b11..b8  (col 2)
+     *  KeyNibble3 on b15..b12 (col 3)
+     */
+
+    KeyFound =  ((KeyNibble0>>4) & 0x000F);     // b7..b4 in 'KeyNibble0' to b3...b0  in 'KeyFound' >> shift 4 right
+    KeyFound |= (KeyNibble1 & 0x00F0);          // b7..b4 in 'KeyNibble1' to b7...b4  in 'KeyFound' -- do nothing
+    KeyFound |= ((KeyNibble2<<4) & 0x0F00);     // b7..b4 in 'KeyNibble2' to b11..b8  in 'KeyFound' << shift 4 left
+    KeyFound |= ((KeyNibble3<<8) & 0xF000);     // b7..b4 in 'KeyNibble3' to b15..b12 in 'KeyFound' << shift 8 left
+	return KeyFound;
+#endif  // USE_JTAG
+
+}
+
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/*!
+ * \brief Remap the 16-bit value for the active key to an 8-bit value
+ *
+ */
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+static u_char KbRemapKey(u_short LongKey)
+{
+    switch (LongKey)
+    {
+        case RAW_KEY_01:        return(KEY_01);
+        case RAW_KEY_02:        return(KEY_02);
+        case RAW_KEY_03:        return(KEY_03);
+        case RAW_KEY_04:        return(KEY_04);
+        case RAW_KEY_05:        return(KEY_05);
+        case RAW_KEY_ALT:       return(KEY_ALT);
+
+        case RAW_KEY_ESC:       return(KEY_ESC);
+        case RAW_KEY_UP:        return(KEY_UP);
+        case RAW_KEY_OK:        return(KEY_OK);
+        case RAW_KEY_LEFT:      return(KEY_LEFT);
+        case RAW_KEY_DOWN:      return(KEY_DOWN);
+        case RAW_KEY_RIGHT:     return(KEY_RIGHT);
+
+        case RAW_KEY_POWER:     return(KEY_POWER);
+        case RAW_KEY_SETUP:     return(KEY_SETUP);      // combined key
+
+        default:                return(KEY_UNDEFINED);
+    }
+}
+
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/*!
+ * \brief Return the repeating property for this key
+ *
+ * \return 'TRUE' in case the key was repeating, 'FALSE' if not
+ *
+ */
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+static u_char KbKeyIsRepeating(u_short Key)
+{
+    return(KeyRepeatArray[KbRemapKey(Key)]==KEY_REPEAT);
+}
+
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/*!
+ * \brief set the property of this key to repeating or not-repeating
+ *
+ */
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+void KbSetKeyRepeating(u_char Key, u_char Property)
+{
+    // check arguments
+    if (((Property==KEY_REPEAT) || (Property==KEY_NO_REPEAT)) && (Key < KEY_NROF_KEYS))
+    {
+        KeyRepeatArray[Key]=Property;
+    }
+}
+
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/*!
+ * \brief Wait until an event was pushed on the eventqueue for this module
+ *
+ * This routine provides the event interface for other Luks-modules
+ *
+ * \param dwTimeout time in milisecs that this routine should wait before
+ * it will return with KB_ERROR
+ *
+ * \return KB_OK in case an event was found
+ * \return KB_ERROR in case no event was found (return due to timeout)
+ */
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+int KbWaitForKeyEvent(u_long dwTimeout)
+{
+
+    int nError = KB_OK;
+    int nTimeout;
+
+    nTimeout = NutEventWait(&hKBEvent, dwTimeout);
+    if (nTimeout == -1)
+    {
+        nError = KB_ERROR;
+    }
+
+    return(nError);
+}
+
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/*!
+ * \brief Return the databyte that was receeived in the IR-stream
+ *
+ * In case a valid key is found in the keyboard scan, the key-code is
+ * stored in the keyboardbuffer. This routine returns the first available
+ * valid key in this buffer
+
+ * \return the keycode that was found by the keyboard scan
+ *
+ * \todo implement a key-buffer for this routine
+ */
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+u_char KbGetKey()
+{
+    return(KeyBuffer[0]);
+}
+
+/*!
+ * \brief inject a virtual key into the system
+ *
+ */
+void KbInjectKey(u_char VirtualKey)
+{
+    KeyBuffer[0]=VirtualKey;
+    NutEventPostFromIrq(&hKBEvent);   // 'valid key' detected -> generate Event
+}
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+/*!
+ * \brief Initialise the Keyboard module
+ *
+ *
+ * - initialise the keyboard read- and write port
+ * - flush the keyboardbuffer
+ * - flush the eventqueue for this module
+ *
+ * \note PORTF uses internal pull-ups. That's why a '1' is read
+ * when no key is pressed. Use negative logic to detect keys.
+ * So default state of the colums is '1'
+ */
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+void KbInit()
+{
+    u_char i;
+
+    sbi (KB_OUT_WRITE_A, KB_COL_0);
+    sbi (KB_OUT_WRITE_A, KB_COL_1);
+    sbi (KB_OUT_WRITE_B, KB_COL_2);
+    sbi (KB_OUT_WRITE_B, KB_COL_3);
+
+    KbState = KB_IDLE;
+    KeyFound = KEY_NO_KEY;
+
+    KbClearEvent(&hKBEvent);
+
+    for (i=0;i<KB_BUFFER_SIZE;++i)
+    {
+        KeyBuffer[i] = (u_char)KEY_NO_KEY;
+    }
+
+    for (i=0; i<KEY_NROF_KEYS; ++i)
+    {
+        KeyRepeatArray[i]=KEY_NO_REPEAT;
+    }
+
+    HoldCounter=0;
+
+    // arrow keys are repeating keys by default
+    KbSetKeyRepeating(KEY_UP, KEY_REPEAT);
+    KbSetKeyRepeating(KEY_DOWN, KEY_REPEAT);
+    KbSetKeyRepeating(KEY_LEFT, KEY_REPEAT);
+    KbSetKeyRepeating(KEY_RIGHT, KEY_REPEAT);
+}
+/* ---------- end of module ------------------------------------------------ */
+
+/*@}*/

+ 113 - 112
keyboard.h

@@ -1,112 +1,113 @@
-/* ========================================================================
- * [PROJECT]    SIR
- * [MODULE]     Keyboard module
- * [TITLE]      keyboard module source file
- * [FILE]       keyboard.h
- * [VSN]        1.0
- * [CREATED]    28 july 2003
- * [LASTCHNGD]  18 august 2003
- * [COPYRIGHT]  Copyright (C) STREAMIT BV 2010
- * [PURPOSE]    Keyboard routines
- * ======================================================================== */
-
-/*-------------------------------------------------------------------------*/
-/* global defines                                                          */
-/*-------------------------------------------------------------------------*/
-#define KB_COL_0       3
-#define KB_COL_1       4
-#define KB_COL_2       3
-#define KB_COL_3       2
-
-#define KB_ROW_0       0
-#define KB_ROW_1       1
-#define KB_ROW_2       2
-#define KB_ROW_3       3
-
-#define KB_ROW_MASK    0xF0
-
-#define KB_OK          0x00
-#define KB_ERROR       0x01
-
-/* state machine defines -------------------------------------------------- */
-#define KB_IDLE        0x00
-#define KB_KEY         0x01
-#define KB_VALID       0x02
-#define KB_RELEASE     0x03
-
-#define KB_COUNTER_OK  0x03    // # a key must be seen before declared 'valid'
-#define KB_LONG_HOLD_TIME 500  // 500 x 4.4 msec = 2200 msec
-#define KB_BUFFER_SIZE 1
-
-
-/*
- *  below are the keys after they where remapped to 8-bit values
- *  These definitions are used by the application
- */
-
-#define KEY_SPEC       0
-#define KEY_01         1
-#define KEY_02         2
-#define KEY_03         3
-#define KEY_04         4
-#define KEY_05         5
-#define KEY_ALT        6
-
-#define KEY_ESC        7
-#define KEY_UP         8
-#define KEY_OK         9
-#define KEY_LEFT       10
-#define KEY_DOWN       11
-#define KEY_RIGHT      12
-
-#define KEY_POWER      13
-#define KEY_SETUP      14
-#define KEY_LCD        15       // virtual key, generated when '1' is pressed and hold for > 2 secs
-
-#define KEY_07         18       // only on RC and only used for selftest
-
-#define KEY_NROF_KEYS  16
-
-// next 2 'keys' are simulated when inserting or removing a MMC
-#define KEY_MMC_IN     16
-#define KEY_MMC_OUT    17
-
-
-// remove these, not available on SIR100
-#define KEY_00         0xFC
-
-#define IS_IR_KEY(key)  (((key>=KEY_01) && (key<=KEY_09)) || (key==KEY_00))
-
-/* definition of virtual special keys ------------------------------------- */
-#define KEY_UNDEFINED  0x88
-#define KEY_TIMEOUT    0xAA
-#define KEY_NO_KEY     0xFFFF   // yes, indeed no u_char....
-
-#define KEY_REPEAT_TIME     100 // 100 * 4.48 = about half a second
-#define KEY_REPEAT          1
-#define KEY_NO_REPEAT       2
-
-/*-------------------------------------------------------------------------*/
-/* export global routines (interface)                                      */
-/*-------------------------------------------------------------------------*/
-void    KbInit(void);
-void    KbScan(void);
-int     KbWaitForKeyEvent(u_long);
-u_char  KbGetKey(void);
-void    KbSetKeyRepeating(u_char, u_char);
-void    KbInjectKey(u_char VirtualKey);
-
-/*  ÍÍÍÍ  End Of File  ÍÍÍÍÍÍÍÍ ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
-
-
-
-
-
-
-
-
-
-
-
-
-
+/* ========================================================================
+ * [PROJECT]    SIR
+ * [MODULE]     Keyboard module
+ * [TITLE]      keyboard module source file
+ * [FILE]       keyboard.h
+ * [VSN]        1.0
+ * [CREATED]    28 july 2003
+ * [LASTCHNGD]  18 august 2003
+ * [COPYRIGHT]  Copyright (C) STREAMIT BV 2010
+ * [PURPOSE]    Keyboard routines
+ * ======================================================================== */
+
+/*-------------------------------------------------------------------------*/
+/* global defines                                                          */
+/*-------------------------------------------------------------------------*/
+#define KB_COL_0       3
+#define KB_COL_1       4
+#define KB_COL_2       3
+#define KB_COL_3       2
+
+#define KB_ROW_0       0
+#define KB_ROW_1       1
+#define KB_ROW_2       2
+#define KB_ROW_3       3
+
+#define KB_ROW_MASK    0xF0
+
+#define KB_OK          0x00
+#define KB_ERROR       0x01
+
+/* state machine defines -------------------------------------------------- */
+#define KB_IDLE        0x00
+#define KB_KEY         0x01
+#define KB_VALID       0x02
+#define KB_RELEASE     0x03
+
+#define KB_COUNTER_OK  0x03    // # a key must be seen before declared 'valid'
+#define KB_LONG_HOLD_TIME 500  // 500 x 4.4 msec = 2200 msec
+#define KB_BUFFER_SIZE 1
+
+
+/*
+ *  below are the keys after they where remapped to 8-bit values
+ *  These definitions are used by the application
+ */
+
+#define KEY_SPEC       0
+#define KEY_01         1
+#define KEY_02         2
+#define KEY_03         3
+#define KEY_04         4
+#define KEY_05         5
+#define KEY_ALT        6
+
+#define KEY_ESC        7
+#define KEY_UP         8
+#define KEY_OK         9
+#define KEY_LEFT       10
+#define KEY_DOWN       11
+#define KEY_RIGHT      12
+
+#define KEY_POWER      13
+#define KEY_SETUP      14
+#define KEY_LCD        15       // virtual key, generated when '1' is pressed and hold for > 2 secs
+
+#define KEY_07         18       // only on RC and only used for selftest
+
+#define KEY_NROF_KEYS  16
+
+// next 2 'keys' are simulated when inserting or removing a MMC
+#define KEY_MMC_IN     16
+#define KEY_MMC_OUT    17
+
+
+// remove these, not available on SIR100
+#define KEY_00         0xFC
+
+#define IS_IR_KEY(key)  (((key>=KEY_01) && (key<=KEY_09)) || (key==KEY_00))
+
+/* definition of virtual special keys ------------------------------------- */
+#define KEY_UNDEFINED  0x88
+#define KEY_TIMEOUT    0xAA
+#define KEY_NO_KEY     0xFFFF   // yes, indeed no u_char....
+
+#define KEY_REPEAT_TIME     100 // 100 * 4.48 = about half a second
+#define KEY_REPEAT          1
+#define KEY_NO_REPEAT       2
+
+/*-------------------------------------------------------------------------*/
+/* export global routines (interface)                                      */
+/*-------------------------------------------------------------------------*/
+void    KbInit(void);
+int    KbScan(void);
+int 	CheckKey();
+int     KbWaitForKeyEvent(u_long);
+u_char  KbGetKey(void);
+void    KbSetKeyRepeating(u_char, u_char);
+void    KbInjectKey(u_char VirtualKey);
+
+/*  ÍÍÍÍ  End Of File  ÍÍÍÍÍÍÍÍ ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
+
+
+
+
+
+
+
+
+
+
+
+
+

+ 35 - 60
main.c

@@ -42,6 +42,7 @@
 #include "flash.h"
 #include "spidrv.h"
 
+
 #include <time.h>
 #include "rtc.h"
 
@@ -77,7 +78,7 @@ static void SysControlMainBeat(u_char);
 /*-------------------------------------------------------------------------*/
 
 
-/* ����������������������������������������������������������������������� */
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
 /*!
  * \brief ISR MainBeat Timer Interrupt (Timer 2 for Mega128, Timer 0 for Mega256).
  *
@@ -88,7 +89,7 @@ static void SysControlMainBeat(u_char);
  *
  * \param *p not used (might be used to pass parms from the ISR)
  */
-/* ����������������������������������������������������������������������� */
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
 static void SysMainBeatInterrupt(void *p)
 {
 
@@ -100,7 +101,7 @@ static void SysMainBeatInterrupt(void *p)
 }
 
 
-/* ����������������������������������������������������������������������� */
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
 /*!
  * \brief Initialise Digital IO
  *  init inputs to '0', outputs to '1' (DDRxn='0' or '1')
@@ -108,7 +109,7 @@ static void SysMainBeatInterrupt(void *p)
  *  Pull-ups are enabled when the pin is set to input (DDRxn='0') and then a '1'
  *  is written to the pin (PORTxn='1')
  */
-/* ����������������������������������������������������������������������� */
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
 void SysInitIO(void)
 {
     /*
@@ -165,12 +166,12 @@ void SysInitIO(void)
     outp(0x18, DDRG);
 }
 
-/* ����������������������������������������������������������������������� */
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
 /*!
  * \brief Starts or stops the 4.44 msec mainbeat of the system
  * \param OnOff indicates if the mainbeat needs to start or to stop
  */
-/* ����������������������������������������������������������������������� */
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
 static void SysControlMainBeat(u_char OnOff)
 {
     int nError = 0;
@@ -190,7 +191,21 @@ static void SysControlMainBeat(u_char OnOff)
     }
 }
 
-/* ����������������������������������������������������������������������� */
+int timer(time_t start){
+	time_t diff = time(0) - start;
+	return diff;
+}
+
+int checkOffPressed(){
+	if (KbScan() < -1){
+		LcdBackLight(LCD_BACKLIGHT_ON);
+		return 1;
+	} else {
+		return 0;
+	}
+}
+
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
 /*!
  * \brief Main entry of the SIR firmware
  *
@@ -201,10 +216,11 @@ static void SysControlMainBeat(u_char OnOff)
  *
  * \return \b never returns
  */
-/* ����������������������������������������������������������������������� */
+/* ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ */
 int main(void)
 {
-    int i;
+	time_t start;
+	int running = 0;
 	/* 
 	 * Kroeske: time struct uit nut/os time.h (http://www.ethernut.de/api/time_8h-source.html)
 	 *
@@ -232,7 +248,7 @@ int main(void)
     Uart0DriverInit();
     Uart0DriverStart();
 	LogInit();
-	LogMsg_P(LOG_INFO, PSTR("Hello World"));
+	
 
     CardInit();
 
@@ -265,63 +281,22 @@ int main(void)
 
 	/* Enable global interrupts */
 	sei();
-/**
     for (;;)
-    {
-        NutSleep(100);
-		if( !((t++)%15) )
-		{
-			LogMsg_P(LOG_INFO, PSTR("Yes!, I'm alive ... [%d]"),t);
-			
-			LedControl(LED_TOGGLE);
+    {		
+		if (checkOffPressed() == 1){
+			start = time(0);
+			running = 1;
+		}
 		
-			if( x )
-			{
-				LcdBackLight(LCD_BACKLIGHT_ON);
-				x = 0;
-			}
-			else
-			{
+		if (running == 1){
+			if (timer(start) >= 10){
+				running = 0;
 				LcdBackLight(LCD_BACKLIGHT_OFF);
-				x = 1;
 			}
 		}
 		
         WatchDogRestart();
     }
-**/
-    LedControl(LED_ON);
-    LcdBackLight(LCD_BACKLIGHT_OFF);
-
-    char string[1000];
-    strcpy(string, "RADIO TEST");
-    LcdBackLight(LCD_BACKLIGHT_ON);
-    LcdChar('test');
-
-    for(;;){
-        u_char x = KbGetKey();
-        if(x == KEY_OK){
-            LcdBackLight(LCD_BACKLIGHT_ON);
-            //NutSleep(3000);                   // dit weer terug zetten als je opdracht 1 wil tonen.
-        }
-
-        if(x == KEY_ESC){                       // dit uit commenten als je opdracht 1 wil tonen.
-            LcdBackLight(LCD_BACKLIGHT_OFF);    // ^
-        }                                       // ^
-
-        if(x == KEY_ALT){
-            for(i = 0; i < strlen(string); i++) {
-                LcdChar(string[i]);
-            }
-        }
-
-        if(x == KEY_POWER){
-        }
-    }
 
     return(0);      // never reached, but 'main()' returns a non-void, so.....
-}
-/* ---------- end of module ------------------------------------------------ */
-
-/*@}*/
-
+}

+ 255 - 0
make.sh

@@ -0,0 +1,255 @@
+/**
+ * @file time.h
+ * Copyright 2012, 2013 MinGW.org project
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ */
+#ifndef	_TIME_H
+#define	_TIME_H
+#pragma GCC system_header
+#include <_mingw.h>
+
+#define __need_wchar_t
+#define __need_size_t
+#define __need_NULL
+
+#ifndef RC_INVOKED
+#include <stddef.h>
+#endif	/* Not RC_INVOKED */
+
+/*
+ * Number of clock ticks per second. A clock tick is the unit by which
+ * processor time is measured and is returned by 'clock'.
+ */
+#define	CLOCKS_PER_SEC	((clock_t)1000)
+#define	CLK_TCK		CLOCKS_PER_SEC
+
+
+#ifndef RC_INVOKED
+
+/*
+ * A type for storing the current time and date. This is the number of
+ * seconds since midnight Jan 1, 1970.
+ * NOTE: This is also defined in non-ISO sys/types.h.
+ */
+#ifndef _TIME32_T_DEFINED
+typedef __int32 __time32_t;
+#define _TIME32_T_DEFINED
+#endif
+
+#ifndef _TIME64_T_DEFINED
+/* A 64-bit time_t to get to Y3K */
+typedef __int64 __time64_t;
+#define _TIME64_T_DEFINED
+#endif
+
+#ifndef _TIME_T_DEFINED
+# if defined(_USE_32BIT_TIME_T) && MSVCRT_VERSION >= 800
+   typedef	__time32_t time_t;
+# else
+   typedef	__time64_t time_t;
+# endif /* _USE_32BIT_TIME_T */
+# define _TIME_T_DEFINED
+#endif
+
+/*
+ * A type for measuring processor time (in clock ticks).
+ */
+#ifndef _CLOCK_T_DEFINED
+typedef	long	clock_t;
+#define _CLOCK_T_DEFINED
+#endif
+
+#ifndef _TM_DEFINED
+/*
+ * A structure for storing all kinds of useful information about the
+ * current (or another) time.
+ */
+struct tm
+{
+	int	tm_sec;		/* Seconds: 0-59 (K&R says 0-61?) */
+	int	tm_min;		/* Minutes: 0-59 */
+	int	tm_hour;	/* Hours since midnight: 0-23 */
+	int	tm_mday;	/* Day of the month: 1-31 */
+	int	tm_mon;		/* Months *since* january: 0-11 */
+	int	tm_year;	/* Years since 1900 */
+	int	tm_wday;	/* Days since Sunday (0-6) */
+	int	tm_yday;	/* Days since Jan. 1: 0-365 */
+	int	tm_isdst;	/* +1 Daylight Savings Time, 0 No DST,
+				 * -1 don't know */
+};
+#define _TM_DEFINED
+#endif
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+_CRTIMP clock_t __cdecl __MINGW_NOTHROW	clock (void);
+_CRTIMP time_t __cdecl __MINGW_NOTHROW	time (time_t*);
+_CRTIMP double __cdecl __MINGW_NOTHROW	difftime (time_t, time_t);
+_CRTIMP time_t __cdecl __MINGW_NOTHROW	mktime (struct tm*);
+
+/*
+ * These functions write to and return pointers to static buffers that may
+ * be overwritten by other function calls. Yikes!
+ *
+ * NOTE: localtime, and perhaps the others of the four functions grouped
+ * below may return NULL if their argument is not 'acceptable'. Also note
+ * that calling asctime with a NULL pointer will produce an Invalid Page
+ * Fault and crap out your program. Guess how I know. Hint: stat called on
+ * a directory gives 'invalid' times in st_atime etc...
+ */
+_CRTIMP char* __cdecl __MINGW_NOTHROW		asctime (const struct tm*);
+_CRTIMP char* __cdecl __MINGW_NOTHROW		ctime (const time_t*);
+_CRTIMP struct tm*  __cdecl __MINGW_NOTHROW	gmtime (const time_t*);
+_CRTIMP struct tm*  __cdecl __MINGW_NOTHROW	localtime (const time_t*);
+
+_CRTIMP size_t __cdecl __MINGW_NOTHROW		strftime (char*, size_t, const char*, const struct tm*);
+
+#ifndef __STRICT_ANSI__
+
+extern _CRTIMP void __cdecl __MINGW_NOTHROW	_tzset (void);
+
+#ifndef _NO_OLDNAMES
+extern _CRTIMP void __cdecl __MINGW_NOTHROW	tzset (void);
+#endif
+
+_CRTIMP char* __cdecl __MINGW_NOTHROW	_strdate(char*);
+_CRTIMP char* __cdecl __MINGW_NOTHROW	_strtime(char*);
+
+/* These require newer versions of msvcrt.dll (6.10 or higher). */
+_CRTIMP __time64_t __cdecl __MINGW_NOTHROW  _time64( __time64_t*);
+_CRTIMP __time64_t __cdecl __MINGW_NOTHROW  _mktime64 (struct tm*);
+_CRTIMP char* __cdecl __MINGW_NOTHROW _ctime64 (const __time64_t*);
+_CRTIMP struct tm*  __cdecl __MINGW_NOTHROW _gmtime64 (const __time64_t*);
+_CRTIMP struct tm*  __cdecl __MINGW_NOTHROW _localtime64 (const __time64_t*);
+
+/* These require newer versions of msvcrt.dll (8.00 or higher). */
+#ifdef MSVCRT_VERSION >= 800
+_CRTIMP __time32_t __cdecl __MINGW_NOTHROW	_time32     (__time32_t*);
+_CRTIMP double	   __cdecl __MINGW_NOTHROW	_difftime32 (__time32_t, __time32_t);
+_CRTIMP double	   __cdecl __MINGW_NOTHROW	_difftime64 (__time64_t, __time64_t);
+_CRTIMP __time32_t __cdecl __MINGW_NOTHROW	_mktime32   (struct tm*);
+_CRTIMP __time32_t __cdecl __MINGW_NOTHROW	_mkgmtime32 (struct tm*);
+_CRTIMP __time64_t __cdecl __MINGW_NOTHROW	_mkgmtime64 (struct tm*);
+_CRTIMP char*	   __cdecl __MINGW_NOTHROW	_ctime32    (const __time32_t*);
+_CRTIMP struct tm* __cdecl __MINGW_NOTHROW	_gmtime32   (const __time32_t*);
+_CRTIMP struct tm* __cdecl __MINGW_NOTHROW	_localtime32(const __time32_t*);
+
+#if defined(_USE_32BIT_TIME_T)
+_CRTALIAS time_t	   __cdecl __MINGW_NOTHROW	time (time_t* _v)
+    { return(_time32 (_v)); }
+_CRTALIAS double	   __cdecl __MINGW_NOTHROW	difftime(time_t _v1, time_t _v2)
+    { return(_difftime32 (_v1,_v2)); }
+_CRTALIAS time_t	   __cdecl __MINGW_NOTHROW	mktime (struct tm* _v)
+    { return(_mktime32 (_v)); }
+_CRTALIAS time_t	   __cdecl __MINGW_NOTHROW	_mkgmtime (struct tm* _v)
+    { return(_mkgmtime32 (_v)); }
+_CRTALIAS char*		   __cdecl __MINGW_NOTHROW	ctime (const time_t* _v)
+    { return(_ctime32 (_v)); }
+_CRTALIAS struct tm*   __cdecl __MINGW_NOTHROW	gmtime (const time_t* _v)
+    { return(_gmtime32 (_v)); }
+_CRTALIAS struct tm*   __cdecl __MINGW_NOTHROW	localtime (const time_t* _v)
+    { return(_localtime32 (_v)); }
+
+#else
+_CRTALIAS time_t	   __cdecl __MINGW_NOTHROW	time (time_t* _v)
+    { return(_time64 (_v)); }
+_CRTALIAS double	   __cdecl __MINGW_NOTHROW	difftime(time_t _v1, time_t _v2)
+    { return(_difftime64 (_v1,_v2)); }
+_CRTALIAS time_t	   __cdecl __MINGW_NOTHROW	mktime (struct tm* _v)
+    { return(_mktime64 (_v)); }
+_CRTALIAS time_t	   __cdecl __MINGW_NOTHROW	_mkgmtime (struct tm* _v)
+    { return(_mkgmtime64 (_v)); }
+_CRTALIAS char*		   __cdecl __MINGW_NOTHROW	ctime (const time_t* _v)
+    { return(_ctime64 (_v)); }
+_CRTALIAS struct tm*   __cdecl __MINGW_NOTHROW	gmtime (const time_t* _v)
+    { return(_gmtime64 (_v)); }
+_CRTALIAS struct tm*   __cdecl __MINGW_NOTHROW	localtime (const time_t* _v)
+    { return(_localtime64 (_v)); }
+#endif /* _USE_32BIT_TIME_T */
+
+#else /* MSVCRT_VERSION < 800 */
+_CRTIMP time_t     __cdecl __MINGW32_NOTHROW time       (time_t*);
+_CRTIMP double     __cdecl __MINGW32_NOTHROW difftime   (time_t, time_t);
+_CRTIMP time_t     __cdecl __MINGW32_NOTHROW mktime     (struct tm*);
+_CRTIMP char*      __cdecl __MINGW32_NOTRHOW ctime      (const time_t*);
+_CRTIMP struct tm* __cdecl __MINGW32_NOTHROW gmtime     (const time_t*);
+_CRTIMP struct tm* __cdecl __MINGW32_NOTHROW localtime  (const time_t*);
+#endif /* MSVCRT_VERSION >= 800 */
+
+/*
+ * _daylight: non zero if daylight savings time is used.
+ * _timezone: difference in seconds between GMT and local time.
+ * _tzname: standard/daylight savings time zone names (an array with two
+ *          elements).
+ */
+
+/* These are for compatibility with pre-VC 5.0 suppied MSVCRT. */
+extern _CRTIMP int* __cdecl __MINGW_NOTHROW	__p__daylight (void);
+extern _CRTIMP long* __cdecl __MINGW_NOTHROW	__p__timezone (void);
+extern _CRTIMP char** __cdecl __MINGW_NOTHROW	__p__tzname (void);
+
+__MINGW_IMPORT int	_daylight;
+__MINGW_IMPORT long	_timezone;
+__MINGW_IMPORT char 	*_tzname[2];
+
+#endif	/* Not __STRICT_ANSI__ */
+
+#ifndef _NO_OLDNAMES
+/* These go in the oldnames import library for MSVCRT. */
+__MINGW_IMPORT int	daylight;
+__MINGW_IMPORT long	timezone;
+__MINGW_IMPORT char 	*tzname[2];
+#endif	/* Not _NO_OLDNAMES */
+
+#ifndef _WTIME_DEFINED
+/* wide function prototypes, also declared in wchar.h */
+
+#ifndef __STRICT_ANSI__
+_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW	_wasctime(const struct tm*);
+_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW	_wctime(const time_t*);
+_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW	_wstrdate(wchar_t*);
+_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW	_wstrtime(wchar_t*);
+_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW	_wctime64 (const __time64_t*);
+#ifdef MSVCRT_VERSION >= 800
+_CRTIMP wchar_t* __cdecl __MINGW_NOTHROW	_wctime32 (const __time32_t*);
+#endif
+
+#ifdef _USE_32BIT_TIME_T && MSVCRT_VERSION >= 800
+_CRTALIAS wchar_t* __cdecl __MINGW_NOTHROW	_wctime (const time_t* _v) { return(_wctime32 (_v)); }
+#else
+_CRTALIAS wchar_t* __cdecl __MINGW_NOTHROW	_wctime (const time_t* _v) { return(_wctime64 (_v)); }
+#endif
+
+#endif /* __STRICT_ANSI__ */
+
+_CRTIMP size_t __cdecl __MINGW_NOTHROW		wcsftime (wchar_t*, size_t, const wchar_t*, const struct tm*);
+#define _WTIME_DEFINED
+#endif /* _WTIME_DEFINED */
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* Not RC_INVOKED */
+
+#endif	/* Not _TIME_H */