/*◄■■■■■■■■■■■■■■■■■■■■■■■■■■■ JWD-NHR_Common.h ■■■■■■■■■■■■■■■■■■■■■■■■■■■■■►*/

// <editor-fold defaultstate="collapsed" desc="Title">
/******************************************************************************/
/*                        © John William Darsow                               */
/* Created on 10:50 AM Sunday, February 15, 2015                              */
/* Old Version Created on November 3, 2014, 1:52 AM                           */
/* Current Version Date: (see File Date)                                      */
/*                                                                            */
/* JWD-NHR Type Definitions, Constants, Defines & Macros                      */
/*                                                                            */
/* A 'negetive [' or 'negetive a' never hear of one. unsigned short long,     */
/* unsigned long long, 24 or 32, float or double. Drove Me To This.           */
/*                                                                            */
/*  Compilers:                                                                */
/*                 XC8 v1.38         __XC8                                    */
/*                 GNU gcc v4.8.1    __GNUC__                                 */
/*                                                                            */
/* Modifications,UpDates and ToDo's:                                          */
/*    Add Structures & Unions                                                 */
/*                                                                            */
/*                                                                            */
/******************************************************************************/

// </editor-fold>
#ifndef JWD_NHR_COMMON_H
#define	JWD_NHR_COMMON_H

/*════════════════════════════ Generic Definitions ═══════════════════════════*/
// <editor-fold defaultstate="collapsed" desc="Definitions">
#define True                 1
#define False                0
#define Yes                  1
#define No                   0
#define Hi                   1
#define HIGH                 1
#define Lo                   0
#define LOW                  0
#define On                   1
#define Off                  0
#define INPUT                1
#define OUTPUT               0
#define ANALOG               1
#define DIGITAL              0
#define ENABLED              1
#define DISABLED             0
#define RISING_EDGE          1
#define FALLING_EDGE         0
#define NUL                  '\0'      // ASCII null character (NUL)
//Definitions </editor-fold>

/*══════════════════════════════ Generic Macros ══════════════════════════════*/
// <editor-fold defaultstate="collapsed" desc="Macros">

/*─♦─ 2 digit BCD to uInt8 ─♦─ Upper half is Tens + Lower Half is Ones */
#define BCDtoUINT8(aBCD)     ((aBCD) >> 4) * 10 + ((aBCD) & 0x0F)

/*─♦─ uInt8 to 2 digit BCD ─♦─ Upper half is Tens + Lower Half is Ones */
#define UINT8toBCD(auInt8)   ((auInt8) / 10 << 4) | ((auInt8) % 10)

/*─♦─ test to see if bit number, bit, in var, is set ─♦─*/
#define testbit(var, bit) ((var) & (1 <<(bit)))

/*─♦─ set the corresponding bit in var ─♦─*/
#define setbit(var, bit) ((var) |= (1 << (bit)))

/*─♦─ clear the corresponding bit in var ─♦─*/
#define clrbit(var, bit) ((var) &= ~(1 << (bit)))

//Macros </editor-fold>

/*══════════════════════════════ Generic Types ═══════════════════════════════*/
// <editor-fold defaultstate="collapsed" desc="Types">

/*─♦─ Bit ─♦─*/
#ifdef __XC8
typedef enum _Bit { Clear = 0, Set } Bit;
#endif

/*─♦─ Bool ─♦─*/
typedef unsigned char bool;

/*─────────────────────────────────── 8 bit ──────────────────────────────────*/
/*─♦─ Byte ─♦─*/
typedef unsigned char             Byte;          /* 8-bit unsigned */

/*─♦─ Char ─♦─*/
typedef unsigned char             Char;          /* 8-bit unsigned */

/*─♦─ uInt8 ─♦─*/
typedef unsigned char             uInt8;         /* 8-bit unsigned */

/*─♦─ Int8 ─♦─*/
typedef signed char               Int8;          /* 8-bit signed   */

/*────────────────────────────────── 16 bit ──────────────────────────────────*/
/*─♦─ Word ─♦─*/
typedef unsigned int              Word;          /* 16-bit unsigned */

/*─♦─ uInt16 ─♦─*/
typedef unsigned int              uInt16;        /* 16-bit unsigned */

/*─♦─ Int16 ─♦─*/
typedef signed int                Int16;         /* 16-bit signed */

/*────────────────────────────────── 24 bit ───────────── xc8 2.05 no like ────
 ─── use of short long integer types is deprecated; use __int24 or __uint24 ──────────────*/
//#ifdef __XC8
///*─♦─ TByte ─♦─*/                           // Tri-Byte 24-bit
//typedef unsigned short long int   TByte;         /* 24-bit unsigned */
//
///*─♦─ uInt24 ─♦─*/
//typedef unsigned short long int   uInt24;        /* 24-bit unsigned */
//
///*─♦─ Int24 ─♦─*/
//typedef signed short long int     Int24;         /* 24-bit signed */
//#endif

/*────────────────────────────────── 32 bit ──────────────────────────────────*/
/*─♦─ DWord ─♦─*/                           // Double-Word 32-bit
typedef unsigned long int         DWord;         /* 32-bit unsigned */

/*─♦─ QByte ─♦─*/                           // Tri-Byte 32-bit
typedef unsigned long int         QByte;         /* 32-bit unsigned */

/*─♦─ uInt32 ─♦─*/
typedef unsigned long int         uInt32;        /* 32-bit unsigned */

/*─♦─ Int32 ─♦─*/
typedef signed long int           Int32;         /* 32-bit signed */

#ifdef __GNUC__
/*────────────────────────────────── 64 bit ──────────────────────────────────*/
/*─♦─ QWord ─♦─*/                           // Quad-Word Byte 64-bit
typedef unsigned long long int    QWord;         /* 64-bit unsigned */

/*─♦─ uInt64 ─♦─*/
typedef unsigned long long int    uInt64;        /* 64-bit unsigned */

/*─♦─ Int64 ─♦─*/
typedef signed long long int      Int64;         /* 64-bit signed */
#endif

/* * * * * * * * * * * * * * * * Floating Point * * * * * * * * * * * * * * * */

#ifdef __XC8
/*─♦─ Float24 ─♦─*/                              // IEEE 754 modified (truncated) 24-bit
typedef float                     Float24;       // XC8 24-bit format is the default --FLOAT=24 (not needed)

/*─♦─ Float32 ─♦─*/                              // IEEE 754 32bit 7.2(24 bits) ±38(8 bits)
typedef double                    Float32;       // XC8 --DOUBLE=32 option must be used
#endif


#ifdef __GNUC__
/*─♦─ Float32 ─♦─*/                              // IEEE 754 32bit 7.2(24 bits) ±38(8 bits)
typedef float                     Float32;

///*─♦─ Float64 ─♦─*/
//typedef double                    Float64;       // IEEE 754 64bit 15.9(53 bits) ±307(11 bits)

/*─♦─ Float128 ─♦─*/
typedef long double               Float128;      // IEEE 754 128bit 34.0(113 bits) ±4931(15 bits)
#endif

//Types </editor-fold>

#endif	/* JWD_NHR_COMMON_H */
