Root/tornado/fw/avr/io.h

Source at commit 30c683effd7ab362d1517950700c96cfa09e45e8 created 11 years 17 days ago.
By Werner Almesberger, tornado/fw/sim/p: pass arguments to "alg"; label graphs; better separate "up"
1/*
2 * fw/io.h - I/O helper macros
3 *
4 * Written 2012 by Werner Almesberger
5 * Copyright 2012 Werner Almesberger
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13#ifndef IO_H
14#define IO_H
15
16#include <avr/io.h>
17
18
19#define LED_DS D, 1
20#define LED_LCLK D, 2
21#define LED_SCLK D, 4
22
23#define CARD_nPWR B, 6
24#define CARD_DAT2 B, 2
25#define CARD_DAT3 B, 1
26#define CARD_CMD B, 3
27#define CARD_CLK B, 0
28#define CARD_DAT0 B, 4
29#define CARD_DAT1 B, 5
30
31#define SW_N C, 3
32#define SW_E C, 4
33#define SW_S C, 0
34#define SW_W C, 2
35#define SW_SW C, 1
36
37#define ADC_X 6
38#define ADC_Y 7
39
40#define __SET(port, bit) PORT##port |= 1 << (bit)
41#define __CLR(port, bit) PORT##port &= ~(1 << (bit))
42#define __OUT(port, bit) DDR##port |= 1 << (bit)
43#define __IN(port, bit) DDR##port &= ~(1 << (bit))
44#define __PIN(port, bit) ((PIN##port >> (bit)) & 1)
45
46#define SET(...) __SET(__VA_ARGS__)
47#define CLR(...) __CLR(__VA_ARGS__)
48#define OUT(...) __OUT(__VA_ARGS__)
49#define IN(...) __IN(__VA_ARGS__)
50#define PIN(...) __PIN(__VA_ARGS__)
51
52#define __SEL_BB(v) (v)
53#define __SEL_CC(v) (v)
54#define __SEL_DD(v) (v)
55
56#define __SEL_BC(v) (0)
57#define __SEL_BD(v) (0)
58#define __SEL_CB(v) (0)
59#define __SEL_CD(v) (0)
60#define __SEL_DB(v) (0)
61#define __SEL_DC(v) (0)
62
63#define __MASK(sel, port, bit) __SEL_##sel##port(1 << (bit))
64#define MASK(...) __MASK(__VA_ARGS__)
65
66#endif /* IO_H */
67

Archive Download this file

Branches:
master
tornado-v1



interactive