Source

New LiquidCrystal / FastIO.h

The default branch has multiple heads

Diff from to
 // @version API 1.0.0
 //
 // @author Florian Fida -
-//
-// @todo:
+// 2012-03-16 bperrybap mods for chipkit32 (pic32) Arduino
 //  support chipkit:
 // (https://github.com/chipKIT32/chipKIT32-MAX/blob/master/hardware/pic32/
 //   cores/pic32/wiring_digital.c)
 #include <pins_arduino.h> // pleasing sanguino core
 #include <inttypes.h>
 
-#ifdef __AVR__
+
+#define SKIP 0x23
+
+#if defined (__AVR__)
 #include <util/atomic.h> // for critical section management
-#endif
+typedef uint8_t fio_bit;
+typedef volatile uint8_t *fio_register;
 
 
-/*!
- @defined 
- @abstract   Enables IO digitalRead/digitalWrite fall back for non-AVR
-             architectures.
- */
-#ifndef __AVR__
+#elif defined(__PIC32MX__)
+typedef uint32_t fio_bit;
+typedef volatile uint32_t *fio_register;
+
+
+#else
+// fallback to Arduino standard digital i/o routines
 #define FIO_FALLBACK
 #define ATOMIC_BLOCK(dummy) if(true)
 #define ATOMIC_RESTORESTATE
+typedef uint8_t fio_bit;
+typedef uint8_t fio_register;
 #endif
 
-// PUBLIC CONSTANTS DEFINITIONS
-// ---------------------------------------------------------------------------
-/*!
- @defined 
- @abstract   Skip setting IO outputs during IO configuration or when getting
-             the output register associated to an IO pin.k
+
+
+#if !defined(FIO_FALLBACK) && !defined(ATOMIC_BLOCK)
+/*
+ * Define an ATOMIC_BLOCK that implements ATOMIC_FORCEON type
+ * Using the portable Arduino interrupts() and noInterrupts()
  */
-#define SKIP 0x23
+#define ATOMIC_RESTORESTATE ATOMIC_FORCEON // sorry, no support for save/restore yet.
+#define ATOMIC_FORCEON uint8_t sreg_save \
+              __attribute__((__cleanup__(__iSeiParam))) = 0
 
-// PUBLIC TYPE DEFINITIONS
-// ---------------------------------------------------------------------------
-typedef uint8_t fio_bit;
+static __inline__ uint8_t __iCliRetVal(void)
+{
+	noInterrupts();
+	return(1);
+}
+static __inline__ void __iSeiParam(const uint8_t *__s)
+{
+	interrupts();
+}
+#define ATOMIC_BLOCK(type) for(type,  __Todo = __iCliRetVal(); __Todo; __Todo = 0)
 
-/*!
-    @typedef 
-    @abstract   Type definitions for FAST_IOs o NATIVE IDE IO
-    @field      fio_register: IO control register
-*/
+#endif // end of block to create compatible ATOMIC_BLOCK()
 
-#ifndef FIO_FALLBACK
-typedef volatile uint8_t *fio_register;
-#else
-// remove volatile to give optimizer a chance
-typedef uint8_t fio_register;
-#endif
+
 
 /*!
  @function
  @param bitOrder[in] bit order
  */
 void fio_shiftOut( fio_register dataRegister, fio_bit dataBit, fio_register clockRegister, 
-                   fio_bit clockBit, uint8_t value, uint8_t bitOrder );
+                  fio_bit clockBit, uint8_t value, uint8_t bitOrder );
 
 /*!
  @method