/*
 * Hilfsdefinitionen fuer die Kompatibilitaet mit AVR-Code
 * Progmem und Abhängigkeiten
 *
 * Created: 22.12.2013
 *  Author: Nicolas
 */



#ifndef PGMSPACE_H
    #define PGMSPACE_H


    #ifdef AVR
	    #define constflash const __flash
		#include <avr/pgmspace.h>
        #include <stdio.h>

	#elif defined(STM32)
		#define PROGMEM
		#define pgm_read_byte(a) (*(a))
        #define constflash const
		#define PSTR(a) (a)
		#define strlen_P strlen
		#define strncpy_P strncpy
		#define snprintf_P snprintf
		#define printf_P printf
        #define fprintf_P fprintf

    #elif defined __MINGW64__ || defined __linux__
		#define PROGMEM
		#define pgm_read_byte(a) (*(a))
		#define constflash const
		#define PSTR(a) (a)
		#define strlen_P strlen
		#define strncpy_P strncpy

        // _P-Druckfunktionen gehen auf das virtuelle GLCD
        extern int myprintf(const char * format, ...);
        #define printf_P myprintf
        #define fprintf_P fprintf
	    #define snprintf_P snprintf
		#define fputs_P fputs

	#elif defined _MSC_VER
		#define PROGMEM
		#define pgm_read_byte(a) (*(a))
		#define constflash const
		#define PSTR(a) (a)
		#define strlen_P strlen
		#define strncpy_P strncpy

		// _P-Druckfunktionen gehen auf das virtuelle GLCD
		extern int myprintf(const char * format, ...);
		#define printf_P myprintf
		#define fprintf_P fprintf


        /* Hilfsdefinitionen fuer Microsoft Visual C Compiler -
         * schon lange nicht mehr getestet. */
        #define snprintf_P _snprintf // _snprintf ist nicht ganz kompatibel
        #define snprintf _snprintf   // zu snprintf, aber hier reicht es
        #define fputs_P fputs
        
        #define printf mprintf

    #else
		#warning No MCU defined
	#endif

#endif // PGMSPACE_H


