Subversion Repositories HomeAutomation

Rev

Details | Last modification | View Log | SVN | RSS feed

Rev Author Line No. Line
1058 eqlazer 1
/******************************************************************************
2
  gpio.h
3
 
4
  CoreCard GPIO Hardware Abstraction Layer
5
 
6
******************************************************************************/
7
 
8
#ifndef GPIO_H_
9
#define GPIO_H_
10
 
11
#include <inttypes.h>
12
#include <avr/io.h>
13
 
14
/******************************************************************************
15
* void GPIOX_set() sets GPIOX pin to logical 1 level.
16
* void GPIOX_clr() clears GPIOX pin to logical 0 level.
17
* void GPIOX_make_in makes GPIOX pin as input.
18
* void GPIOX_make_out makes GPIOX pin as output.
19
* uint8_t GPIOX_read() returns logical level GPIOX pin.
20
* uint8_t GPIOX_state() returns configuration of GPIOX port.
21
*******************************************************************************/
22
#define INLINE static inline __attribute__ ((always_inline))
23
 
24
#define HAL_ASSIGN_PIN(name, port, bit) \
25
INLINE void  GPIO_##name##_set(void)         {PORT##port |= (1 << bit);} \
26
INLINE void  GPIO_##name##_clr(void)         {PORT##port &= ~(1 << bit);} \
27
INLINE uint8_t  GPIO_##name##_read(void)     {return (PIN##port & (1 << bit)) != 0;} \
28
INLINE uint8_t  GPIO_##name##_state(void)    {return (DDR##port & (1 << bit)) != 0;} \
29
INLINE void  GPIO_##name##_make_out(void)    {DDR##port |= (1 << bit);} \
30
INLINE void  GPIO_##name##_make_in(void)     {DDR##port &= ~(1 << bit); PORT##port &= ~(1 << bit);} \
31
INLINE void  GPIO_##name##_make_pullup(void) {PORT##port |= (1 << bit);}\
32
INLINE void  GPIO_##name##_toggle(void)      {PORT##port ^= (1 << bit);} 
33
 
34
// the macros for the manipulation by EXP_A
35
HAL_ASSIGN_PIN(EXP_A, B, 7);
36
// the macros for the manipulation by EXP_B
37
HAL_ASSIGN_PIN(EXP_B, B, 2);
38
// the macros for the manipulation by EXP_C
39
HAL_ASSIGN_PIN(EXP_C, B, 1);
40
// the macros for the manipulation by EXP_D
41
HAL_ASSIGN_PIN(EXP_D, B, 0);
42
// the macros for the manipulation by EXP_E
43
HAL_ASSIGN_PIN(EXP_E, D, 7);
44
// the macros for the manipulation by EXP_F
45
HAL_ASSIGN_PIN(EXP_F, D, 6);
46
// the macros for the manipulation by EXP_G
47
HAL_ASSIGN_PIN(EXP_G, D, 5);
48
// the macros for the manipulation by EXP_H
49
HAL_ASSIGN_PIN(EXP_H, D, 4);
50
// the macros for the manipulation by EXP_I
51
HAL_ASSIGN_PIN(EXP_I, D, 2);
52
// the macros for the manipulation by EXP_J
53
HAL_ASSIGN_PIN(EXP_J,  D, 1);
54
// the macros for the manipulation by EXP_K
55
HAL_ASSIGN_PIN(EXP_K, D, 0);
56
// the macros for the manipulation by EXP_L
57
HAL_ASSIGN_PIN(EXP_L, C, 5);
58
// the macros for the manipulation by EXP_M
59
HAL_ASSIGN_PIN(EXP_M, C, 4);
60
// the macros for the manipulation by EXP_N
61
HAL_ASSIGN_PIN(EXP_N, C, 2);
62
// the macros for the manipulation by EXP_O
63
HAL_ASSIGN_PIN(EXP_O, C, 5);
64
// the macros for the manipulation by EXP_P
65
HAL_ASSIGN_PIN(EXP_P, C, 1);
66
// the macros for the manipulation by EXP_Q
67
HAL_ASSIGN_PIN(EXP_Q, C, 7);
68
// the macros for the manipulation by EXP_R
69
HAL_ASSIGN_PIN(EXP_R, C, 7);
70
 
71
#endif
72
//eof gpio.h