/Users/fmalpartida/Documents/development/mercurial repos/SW/NewLiquidCrystal_lib/FastIO.h
// ---------------------------------------------------------------------------
// Created by Florian Fida on 20/01/12
// Copyright (C) - 2018
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License v3.0
// along with this program.
// If not, see <https://www.gnu.org/licenses/gpl-3.0.en.html>.
//
// ---------------------------------------------------------------------------
//
// fio_shiftOut1 functions are based on Shif1 protocol developed by Roman Black
// (http://www.romanblack.com/shift1.htm)
//
// Thread Safe: No
// Extendable: Yes
//
// @file FastIO.h
// This file implements basic fast IO routines.
//
// @brief
//
// @version API 1.0.0
//
// @author Florian Fida -
// 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)
// ---------------------------------------------------------------------------
#ifndef _FAST_IO_H_
#define _FAST_IO_H_
#if (ARDUINO < 100)
#include <WProgram.h>
#else
#include <Arduino.h>
#endif
#include <pins_arduino.h> // pleasing sanguino core
#include <inttypes.h>
#define SKIP 0x23
#if defined (__AVR__)
#include <util/atomic.h> // for critical section management
typedef uint8_t fio_bit;
typedef volatile uint8_t *fio_register;
// __AVR__ processor end
#elif defined(__PIC32MX__)
typedef uint32_t fio_bit;
typedef volatile uint32_t *fio_register;
// __PIC32MX__ processor end
#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 // Processor dependent fast IO definition
#if !defined(FIO_FALLBACK) && !defined(ATOMIC_BLOCK)
/*
* Define an ATOMIC_BLOCK that implements ATOMIC_FORCEON type
* Using the portable Arduino interrupts() and noInterrupts()
*/
#define ATOMIC_RESTORESTATE ATOMIC_FORCEON // sorry, no support for save/restore yet.
#define ATOMIC_FORCEON uint8_t sreg_save \
__attribute__((__cleanup__(__iSeiParam))) = 0
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)
#endif // end of block to create compatible ATOMIC_BLOCK()
#ifndef _BV
#define _BV(bit) (1 << (bit))
#endif
fio_register fio_pinToOutputRegister(uint8_t pin, uint8_t initial_state = LOW);
fio_register fio_pinToInputRegister(uint8_t pin);
fio_bit fio_pinToBit(uint8_t pin);
// __attribute__ ((always_inline)) /* let the optimizer decide that for now */
void fio_digitalWrite ( fio_register pinRegister, fio_bit pinBit, uint8_t value );
#ifndef FIO_FALLBACK
#define fio_digitalWrite_LOW(reg,bit) *reg &= ~bit
#define fio_digitalWrite_HIGH(reg,bit) *reg |= bit
#define fio_digitalWrite_SWITCH(reg,bit) *reg ^= bit
#define fio_digitalWrite_SWITCHTO(reg,bit,val) fio_digitalWrite_SWITCH(reg,bit)
#else
// reg -> dummy NULL, bit -> pin
#define fio_digitalWrite_HIGH(reg,bit) digitalWrite(bit,HIGH)
#define fio_digitalWrite_LOW(reg,bit) digitalWrite(bit,LOW)
#define fio_digitalWrite_SWITCH(reg,bit) digitalWrite(bit, !digitalRead(bit))
#define fio_digitalWrite_SWITCHTO(reg,bit,val) digitalWrite(bit,val);
#endif
int fio_digitalRead ( fio_register pinRegister, fio_bit pinBit );
void fio_shiftOut( fio_register dataRegister, fio_bit dataBit, fio_register clockRegister,
fio_bit clockBit, uint8_t value, uint8_t bitOrder );
void fio_shiftOut(fio_register dataRegister, fio_bit dataBit, fio_register clockRegister, fio_bit clockBit);
void fio_shiftOut1(fio_register shift1Register, fio_bit shift1Bit, uint8_t value, boolean noLatch = false);
void fio_shiftOut1(uint8_t pin, uint8_t value, boolean noLatch = false);
void fio_shiftOut1_init(fio_register shift1Register, fio_bit shift1Bit);
void fio_shiftOut1_init(uint8_t pin);
#endif // FAST_IO_H