Modified version of the DmTftLibrary, optimized for the LPC4088 Experiment Base Board

Dependents:   lpc4088_ebb_dm_calc lpc4088_ebb_dm_bubbles

Fork of DmTftLibrary by Display Module

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers dm_platform.h Source File

dm_platform.h

00001 #ifndef DM_PLATFORM_h
00002 #define DM_PLATFORM_h
00003 
00004 // Determine type of system
00005 #if defined (__AVR__)
00006   #define DM_TOOLCHAIN_ARDUINO
00007 #elif defined(TOOLCHAIN_ARM) || defined(TOOLCHAIN_ARM_MICRO)
00008   #define DM_TOOLCHAIN_MBED
00009 #else
00010   #error Only Arduino and Mbed toolchains are supported
00011 #endif
00012 
00013 // Arduino
00014 #if defined (DM_TOOLCHAIN_ARDUINO)
00015 
00016   // Mandatory includes for Arduino
00017   #include <Arduino.h>
00018   #include <avr/pgmspace.h>
00019   #include <SPI.h>
00020 
00021   // Clear bit, Set bit, High pulse and Low pulse macros
00022   #define cbi(reg, _bitmask) *reg &= ~_bitmask
00023   #define sbi(reg, _bitmask) *reg |= _bitmask
00024   #define pulse_high(reg, _bitmask) sbi(reg, _bitmask); cbi(reg, _bitmask);
00025   #define pulse_low(reg, _bitmask) cbi(reg, _bitmask); sbi(reg, _bitmask);
00026 
00027   // Map of mandatory pin names, from Arduino names to D* and A*
00028   #define D2   2
00029   #define D3   3
00030   #define D4   4
00031   #define D5   5
00032   #define D6   6
00033   #define D9   9
00034   #define D10 10
00035   #define A2  16
00036   #define A3  17
00037   #define A4  18
00038   #define A5  19
00039 
00040   // Needed typedefs, not normally present in the Arduino environment
00041   #ifndef uint8_t
00042     #define uint8_t unsigned char
00043   #endif
00044   #ifndef int8_t
00045     #define int8_t signed char
00046   #endif
00047   #ifndef uint16_t
00048     #define uint16_t unsigned short
00049   #endif
00050   #ifndef uint32_t
00051     #define uint32_t unsigned long
00052   #endif
00053 
00054 // Mbed
00055 #elif defined(DM_TOOLCHAIN_MBED)
00056 
00057   // Mandatory includes for Mbed
00058   #include "mbed.h"
00059 
00060   // Clear bit, Set bit, High pulse, Low pulse, Boundary limits and Delay macros
00061   #define sbi(reg, _bitmask) (*(reg) = 1)
00062   #define cbi(reg, _bitmask) (*(reg) = 0)
00063   #define pulse_high(reg, _bitmask) do { *(reg) = 1; *(reg) = 0; } while(0)
00064   #define pulse_low(reg, _bitmask) do { *(reg) = 0; *(reg) = 1; } while(0)
00065   #define constrain(amt,low,high) ((amt)<=(low)?(low):((amt)>(high)?(high):(amt)))
00066   #define delay(ms) wait_ms(ms)
00067 
00068   // Change pinning for LPC4088 Experiment Base Board as it is different compared
00069   // to the LPC4088 QSB Base Board (i.e. D2<->D8  and  D5<->D9)
00070   #undef  D2
00071   #define D2 p8
00072   #undef  D5
00073   #define D5 p39
00074   #undef  D8
00075   #define D8 p31
00076   #undef  D9
00077   #define D9 p37
00078   
00079 
00080   // On Arduino no extra delay is needed, but on faster platforms the simulated
00081   // SPI bus may get a too high frequency so a delay here will lower it. This
00082   // delay should ideally be configurable per platform but for now it will have
00083   // to be ok to lower the frequency to 500KHz  
00084   #if defined(__LPC407x_8x_177x_8x_H__)
00085     //#define slow_pulse_delay()  wait_us(1)
00086     #define slow_pulse_delay() do {\
00087       volatile unsigned _xyz = 10; \
00088       for (; _xyz > 0; _xyz--); \
00089     } while(0)
00090     //#define slow_pulse_delay()
00091   #else
00092     #define slow_pulse_delay()
00093   #endif
00094   #define slow_pulse_high(reg, _bitmask) do {\
00095        *(reg) = 1;    \
00096        slow_pulse_delay(); \
00097        *(reg) = 0;    \
00098        slow_pulse_delay(); \
00099     } while(0)
00100   #define slow_pulse_low(reg, _bitmask) do {\
00101        *(reg) = 0;    \
00102        slow_pulse_delay(); \
00103        *(reg) = 1;    \
00104        slow_pulse_delay(); \
00105     } while(0)
00106 
00107   // Special handling for the LPC1549 LPCXpresso board with solder bump
00108   #ifdef LPC15XX_H
00109     #define SPECIAL_D5  P0_11
00110   #else
00111     #define SPECIAL_D5  D5
00112   #endif
00113 #endif
00114 
00115 #endif /* DM_PLATFORM_h */
00116