Root/fw/io.h

Source at commit fbb75b7c6eaf3576774f864452644ac9a72e9f82 created 11 years 4 days ago.
By Werner Almesberger, BOOKSHELF: add LIS3DH app note; add push-pull uSD card holder
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_A1 C, 0
20#define LED_A2 C, 1
21#define LED_A3 C, 2
22#define LED_A4 C, 3
23#define LED_A5 C, 4
24#define LED_A6 C, 5
25#define LED_A7 D, 0
26#define LED_A8 D, 1
27
28#define LED_B1 D, 2
29#define LED_B2 D, 3
30#define LED_B3 D, 4
31#define LED_B4 B, 6
32#define LED_B5 B, 7
33#define LED_B6 D, 5
34#define LED_B7 D, 6
35#define LED_B8 D, 7
36
37#define ADC_X 6
38#define ADC_Y 7
39
40#define RF_SCLK B, 5
41#define RF_MISO B, 4
42#define RF_MOSI B, 3
43#define RF_nSS B, 2 /* called nSS in schematics */
44#define RF_IRQ B, 1
45#define RF_nRST B, 0
46
47#define __SET(port, bit) PORT##port |= 1 << (bit)
48#define __CLR(port, bit) PORT##port &= ~(1 << (bit))
49#define __OUT(port, bit) DDR##port |= 1 << (bit)
50#define __IN(port, bit) DDR##port &= ~(1 << (bit))
51#define __PIN(port, bit) ((PIN##port >> (bit)) & 1)
52
53#define SET(...) __SET(__VA_ARGS__)
54#define CLR(...) __CLR(__VA_ARGS__)
55#define OUT(...) __OUT(__VA_ARGS__)
56#define IN(...) __IN(__VA_ARGS__)
57#define PIN(...) __PIN(__VA_ARGS__)
58
59#define __SEL_BB(v) (v)
60#define __SEL_CC(v) (v)
61#define __SEL_DD(v) (v)
62
63#define __SEL_BC(v) (0)
64#define __SEL_BD(v) (0)
65#define __SEL_CB(v) (0)
66#define __SEL_CD(v) (0)
67#define __SEL_DB(v) (0)
68#define __SEL_DC(v) (0)
69
70#define __MASK(sel, port, bit) __SEL_##sel##port(1 << (bit))
71#define MASK(...) __MASK(__VA_ARGS__)
72
73#endif /* IO_H */
74

Archive Download this file

Branches:
master
tornado-v1



interactive