Home2L - C/C++ API
v1.4-0-g38cc (2024-05-25)
Smart Tools for a Private Home
brownies
avr
base.h
Go to the documentation of this file.
1
/*
2
* This file is part of the Home2L project.
3
*
4
* (C) 2015-2021 Gundolf Kiefer
5
*
6
* Home2L is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
10
*
11
* Home2L is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License
17
* along with Home2L. If not, see <https://www.gnu.org/licenses/>.
18
*
19
*/
20
21
22
#ifndef _BASE_
23
#define _BASE_
24
25
115
#include <avr/io.h>
116
117
#include "
interface.h
"
118
119
120
121
122
123
// *************************** Basic Helpers ***********************************
124
125
128
129
#define INIT(NAME,VAL) if ((VAL) != 0) NAME = (VAL);
134
135
136
#define LO(X) ((X) & 0xff)
137
#define HI(X) ((X) >> 8)
138
#define HILO(H,L) ((((uint16_t) (H)) << 8) | (L))
140
141
142
#define SHIFT_OF_MASK(X) (((X) & 0x01) ? 0 : ((X) & 0x02) ? 1 : ((X) & 0x04) ? 2 : ((X) & 0x08) ? 3 \
143
: ((X) & 0x10) ? 4 : ((X) & 0x20) ? 5 : ((X) & 0x40) ? 6 : ((X) & 0x80) ? 7 : 8)
145
146
147
148
149
150
// ********************* MCU Port Access Macros ********************************
151
152
156
157
#define P_A0 0x0001
158
#define P_A1 0x0002
159
#define P_A2 0x0004
160
#define P_A3 0x0008
161
#define P_A4 0x0010
162
#define P_A5 0x0020
163
#define P_A6 0x0040
164
#define P_A7 0x0080
165
166
#define P_B0 0x0100
167
#define P_B1 0x0200
168
#define P_B2 0x0400
169
#define P_B3 0x0800
170
#define P_B4 0x1000
171
#define P_B5 0x2000
172
#define P_B6 0x4000
173
#define P_B7 0x8000
174
175
176
#if (defined(PINA) && defined(PORTA) && defined(DDRA)) || DOXYGEN
177
178
179
#define P_IN(P) (LO(P) ? (PINA & LO(P)) : HI(P) ? (PINB & HI(P)) : 0)
181
#define P_IN_MULTI(MASK) ((LO(MASK) ? (PINA & LO(MASK)) : 0) | (HI(MASK) ? ((uint16_t) (PINB & HI(MASK))) << 8 : 0))
183
184
#define P_OUT_0(P) do { if (LO(P)) PORTA &= ~LO(P); if (HI(P)) PORTB &= ~HI(P); } while(0)
185
#define P_OUT_1(P) do { if (LO(P)) PORTA |= LO(P); if (HI(P)) PORTB |= HI(P); } while(0)
188
#define P_OUT_MULTI(MASK, P) do { \
189
if (LO(MASK)) PORTA = (PORTA & ~LO(MASK)) | (LO(P) & LO(MASK)); \
190
if (HI(MASK)) PORTB = (PORTB & ~HI(MASK)) | (HI(P) & HI(MASK)); \
191
} while(0)
193
194
#define P_DDR_IN(P) do { if (LO(P)) DDRA &= ~LO(P); if (HI(P)) DDRB &= ~HI(P); } while(0)
196
#define P_DDR_OUT(P) do { if (LO(P)) DDRA |= LO(P); if (HI(P)) DDRB |= HI(P); } while(0)
198
199
200
#else
// defined(PINA) && defined(PORTA) && defined(DDRA)
201
202
203
#define P_IN(P) (HI(P) ? (PINB & HI(P)) : 0)
204
#define P_IN_MULTI(MASK) ((HI(MASK) ? ((uint16_t) (PINB & HI(MASK))) << 8 : 0))
205
206
#define P_OUT_0(P) do { if (HI(P)) PORTB &= ~HI(P); } while(0)
207
#define P_OUT_1(P) do { if (HI(P)) PORTB |= HI(P); } while(0)
208
#define P_OUT_MULTI(MASK, P) do { if (HI(MASK)) PORTB = (PORTB & ~HI(MASK)) | (HI(P) & HI(MASK)); } while(0)
209
210
#define P_DDR_IN(P) do { if (HI(P)) DDRB &= ~HI(P); } while(0)
211
#define P_DDR_OUT(P) do { if (HI(P)) DDRB |= HI(P); } while(0)
212
213
214
#endif
// defined(PINA) && defined(PORTA) && defined(DDRA)
215
216
217
218
219
220
// *************************** MCU Type ****************************************
221
222
226
227
#if DOXYGEN
228
#define MCU_TYPE
229
#endif
230
231
232
#if defined(__AVR_ATtiny85__)
233
#define MCU_TYPE BR_MCU_ATTINY85
234
#endif
235
236
#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny84A__)
237
#define MCU_TYPE BR_MCU_ATTINY84
238
#endif
239
240
#if defined(__AVR_ATtiny861__) || defined(__AVR_ATtiny861A__)
241
#define MCU_TYPE BR_MCU_ATTINY861
242
#endif
243
244
#ifndef MCU_TYPE
245
#error "Unsupported MCU type!"
246
#endif
247
248
250
252
253
254
#endif
// _BASE_
interface.h
Generated by
1.9.4