New LiquidCrystal library  1.5.0
Generic LCD control library
/Users/fmalpartida/Documents/development/mercurial repos/SW/NewLiquidCrystal_lib/FastIO.h
1 // ---------------------------------------------------------------------------
2 // Created by Florian Fida on 20/01/12
3 // Copyright (C) - 2018
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License v3.0
16 // along with this program.
17 // If not, see <https://www.gnu.org/licenses/gpl-3.0.en.html>.
18 //
19 // ---------------------------------------------------------------------------
20 //
21 // fio_shiftOut1 functions are based on Shif1 protocol developed by Roman Black
22 // (http://www.romanblack.com/shift1.htm)
23 //
24 // Thread Safe: No
25 // Extendable: Yes
26 //
27 // @file FastIO.h
28 // This file implements basic fast IO routines.
29 //
30 // @brief
31 //
32 // @version API 1.0.0
33 //
34 // @author Florian Fida -
35 // 2012-03-16 bperrybap mods for chipkit32 (pic32) Arduino
36 // support chipkit:
37 // (https://github.com/chipKIT32/chipKIT32-MAX/blob/master/hardware/pic32/
38 // cores/pic32/wiring_digital.c)
39 // ---------------------------------------------------------------------------
40 #ifndef _FAST_IO_H_
41 #define _FAST_IO_H_
42 
43 #if (ARDUINO < 100)
44 #include <WProgram.h>
45 #else
46 #include <Arduino.h>
47 #endif
48 
49 #include <pins_arduino.h> // pleasing sanguino core
50 #include <inttypes.h>
51 
52 
53 #define SKIP 0x23
54 
55 #if defined (__AVR__)
56 #include <util/atomic.h> // for critical section management
57 typedef uint8_t fio_bit;
58 typedef volatile uint8_t *fio_register;
59 // __AVR__ processor end
60 
61 #elif defined(__PIC32MX__)
62 typedef uint32_t fio_bit;
63 typedef volatile uint32_t *fio_register;
64 // __PIC32MX__ processor end
65 
66 #else
67 // fallback to Arduino standard digital i/o routines
68 #define FIO_FALLBACK
69 #define ATOMIC_BLOCK(dummy) if(true)
70 #define ATOMIC_RESTORESTATE
71 typedef uint8_t fio_bit;
72 typedef uint8_t fio_register;
73 #endif // Processor dependent fast IO definition
74 
75 
76 
77 #if !defined(FIO_FALLBACK) && !defined(ATOMIC_BLOCK)
78 /*
79  * Define an ATOMIC_BLOCK that implements ATOMIC_FORCEON type
80  * Using the portable Arduino interrupts() and noInterrupts()
81  */
82 #define ATOMIC_RESTORESTATE ATOMIC_FORCEON // sorry, no support for save/restore yet.
83 #define ATOMIC_FORCEON uint8_t sreg_save \
84  __attribute__((__cleanup__(__iSeiParam))) = 0
85 
86 static __inline__ uint8_t __iCliRetVal(void)
87 {
88  noInterrupts();
89  return(1);
90 }
91 static __inline__ void __iSeiParam(const uint8_t *__s)
92 {
93  interrupts();
94 }
95 #define ATOMIC_BLOCK(type) for(type, __Todo = __iCliRetVal(); __Todo; __Todo = 0)
96 
97 #endif // end of block to create compatible ATOMIC_BLOCK()
98 
109 #ifndef _BV
110 #define _BV(bit) (1 << (bit))
111 #endif
112 
120 fio_register fio_pinToOutputRegister(uint8_t pin, uint8_t initial_state = LOW);
121 
129 fio_register fio_pinToInputRegister(uint8_t pin);
130 
138 fio_bit fio_pinToBit(uint8_t pin);
139 
140 
150 // __attribute__ ((always_inline)) /* let the optimizer decide that for now */
151 void fio_digitalWrite ( fio_register pinRegister, fio_bit pinBit, uint8_t value );
152 
159 #ifndef FIO_FALLBACK
160 #define fio_digitalWrite_LOW(reg,bit) *reg &= ~bit
161 #define fio_digitalWrite_HIGH(reg,bit) *reg |= bit
162 #define fio_digitalWrite_SWITCH(reg,bit) *reg ^= bit
163 #define fio_digitalWrite_SWITCHTO(reg,bit,val) fio_digitalWrite_SWITCH(reg,bit)
164 #else
165 // reg -> dummy NULL, bit -> pin
166 #define fio_digitalWrite_HIGH(reg,bit) digitalWrite(bit,HIGH)
167 #define fio_digitalWrite_LOW(reg,bit) digitalWrite(bit,LOW)
168 #define fio_digitalWrite_SWITCH(reg,bit) digitalWrite(bit, !digitalRead(bit))
169 #define fio_digitalWrite_SWITCHTO(reg,bit,val) digitalWrite(bit,val);
170 #endif
171 
181 int fio_digitalRead ( fio_register pinRegister, fio_bit pinBit );
182 
194 void fio_shiftOut( fio_register dataRegister, fio_bit dataBit, fio_register clockRegister,
195  fio_bit clockBit, uint8_t value, uint8_t bitOrder );
196 
207 void fio_shiftOut(fio_register dataRegister, fio_bit dataBit, fio_register clockRegister, fio_bit clockBit);
208 
217 void fio_shiftOut1(fio_register shift1Register, fio_bit shift1Bit, uint8_t value, boolean noLatch = false);
225 void fio_shiftOut1(uint8_t pin, uint8_t value, boolean noLatch = false);
233 void fio_shiftOut1_init(fio_register shift1Register, fio_bit shift1Bit);
240 void fio_shiftOut1_init(uint8_t pin);
241 
242 #endif // FAST_IO_H