summaryrefslogtreecommitdiffstats
path: root/bsps/arm/lm3s69xx/include/bsp/io.h
blob: 3e3846e1c68db9cfeb08944922d979124a74d396 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/**
 * @file
 * 
 * @ingroup lm3s69xx_io
 *
 * @brief IO definitions.
 */

/*
 * Copyright © 2013 Eugeniy Meshcheryakov <eugen@debian.org>
 *
 * The license and distribution terms for this file may be
 * found in the file LICENSE in this distribution or at
 * http://www.rtems.org/license/LICENSE.
 */

#ifndef LIBBSP_ARM_LM3S69XX_IO_H
#define LIBBSP_ARM_LM3S69XX_IO_H
#include <bspopts.h>
#include <stdbool.h>

/**
 * @defgroup lm3s69xx_io IO Support
 *
 * @ingroup RTEMSBSPsARMLM3S69XX
 *
 * @brief IO support.
 */

typedef enum {
  LM3S69XX_GPIO_DIRECTION_INPUT,
  LM3S69XX_GPIO_DIRECTION_OUTPUT
} lm3s69xx_gpio_direction;

typedef enum {
  LM3S69XX_GPIO_OTYPE_PUSH_PULL,
  LM3S69XX_GPIO_OTYPE_OPEN_DRAIN
} lm3s69xx_gpio_otype;

typedef enum {
  LM3S69XX_GPIO_DRIVE_2MA,
  LM3S69XX_GPIO_DRIVE_4MA,
  LM3S69XX_GPIO_DRIVE_8MA
} lm3s69xx_gpio_drive;

typedef enum {
  LM3S69XX_GPIO_NO_PULL,
  LM3S69XX_GPIO_PULL_UP,
  LM3S69XX_GPIO_PULL_DOWN
} lm3s69xx_gpio_pull;

typedef enum {
  LM3S69XX_GPIO_DIGITAL_DISABLE,
  LM3S69XX_GPIO_DIGITAL_ENABLE,
} lm3s69xx_gpio_digital;

typedef enum {
  LM3S69XX_GPIO_AF_DISABLE,
  LM3S69XX_GPIO_AF_ENABLE
} lm3s69xx_gpio_af;

typedef enum {
  LM3S69XX_GPIO_ANALOG_DISABLE,
  LM3S69XX_GPIO_ANALOG_ENABLE
} lm3s69xx_gpio_analog;

typedef enum {
  LM3S69XX_GPIO_NO_SLEW_RATE_CONTROL,
  LM3S69XX_GPIO_SLEW_RATE_CONTROL
} lm3s69xx_gpio_slew_rate_control;

typedef struct {
  unsigned int pin_first : 8;
  unsigned int pin_last : 8;
  unsigned int digital : 1;
  unsigned int alternate : 1;
  unsigned int analog : 1;
  unsigned int dir : 1;
  unsigned int otype : 1;
  unsigned int drive : 2;
  unsigned int pull : 2;
  unsigned int slr : 1;
} lm3s69xx_gpio_config;

typedef enum {
  LM3S69XX_PORT_A,
  LM3S69XX_PORT_B,
  LM3S69XX_PORT_C,
  LM3S69XX_PORT_D,
  LM3S69XX_PORT_E,
  LM3S69XX_PORT_F,
  LM3S69XX_PORT_G,
#if LM3S69XX_NUM_GPIO_BLOCKS > 7
  LM3S69XX_PORT_H
#endif
} lm3s69xx_gpio_port;

#define LM3S69XX_GPIO_PIN(port, idx) (((port) << 3) | (idx))
#define LM3S69XX_GPIO_PORT_OF_PIN(pin) (((pin) >> 3) & 0xf)
#define LM3S69XX_GPIO_INDEX_OF_PIN(pin) ((pin) & 0x7)

#define LM3S69XX_PIN_UART_TX(port, idx) \
  { \
    .pin_first = LM3S69XX_GPIO_PIN(port, idx), \
    .pin_last = LM3S69XX_GPIO_PIN(port, idx), \
    .digital = LM3S69XX_GPIO_DIGITAL_ENABLE, \
    .alternate = LM3S69XX_GPIO_AF_ENABLE, \
    .analog = LM3S69XX_GPIO_ANALOG_DISABLE, \
    .dir = LM3S69XX_GPIO_DIRECTION_OUTPUT, \
    .otype = LM3S69XX_GPIO_OTYPE_PUSH_PULL, \
    .drive = LM3S69XX_GPIO_DRIVE_2MA, \
    .pull = LM3S69XX_GPIO_NO_PULL, \
    .slr = LM3S69XX_GPIO_NO_SLEW_RATE_CONTROL \
  }

#define LM3S69XX_PIN_UART_RX(port, idx) \
  { \
    .pin_first = LM3S69XX_GPIO_PIN(port, idx), \
    .pin_last = LM3S69XX_GPIO_PIN(port, idx), \
    .digital = LM3S69XX_GPIO_DIGITAL_ENABLE, \
    .alternate = LM3S69XX_GPIO_AF_ENABLE, \
    .analog = LM3S69XX_GPIO_ANALOG_DISABLE, \
    .dir = LM3S69XX_GPIO_DIRECTION_INPUT, \
    .otype = LM3S69XX_GPIO_OTYPE_PUSH_PULL, \
    .drive = LM3S69XX_GPIO_DRIVE_2MA, \
    .pull = LM3S69XX_GPIO_PULL_UP, \
    .slr = LM3S69XX_GPIO_NO_SLEW_RATE_CONTROL \
  }

#define LM3S69XX_PIN_UART_RTS(port, idx) \
  { \
    .pin_first = LM3S69XX_GPIO_PIN(port, idx), \
    .pin_last = LM3S69XX_GPIO_PIN(port, idx), \
    .digital = LM3S69XX_GPIO_DIGITAL_ENABLE, \
    .alternate = LM3S69XX_GPIO_AF_ENABLE, \
    .analog = LM3S69XX_GPIO_ANALOG_DISABLE, \
    .dir = LM3S69XX_GPIO_DIRECTION_OUTPUT, \
    .otype = LM3S69XX_GPIO_OTYPE_PUSH_PULL, \
    .drive = LM3S69XX_GPIO_DRIVE_2MA, \
    .pull = LM3S69XX_GPIO_NO_PULL, \
    .slr = LM3S69XX_GPIO_NO_SLEW_RATE_CONTROL \
  }

#define LM3S69XX_PIN_UART_CTS(port, idx) \
  { \
    .pin_first = LM3S69XX_GPIO_PIN(port, idx), \
    .pin_last = LM3S69XX_GPIO_PIN(port, idx), \
    .digital = LM3S69XX_GPIO_DIGITAL_ENABLE, \
    .alternate = LM3S69XX_GPIO_AF_ENABLE, \
    .analog = LM3S69XX_GPIO_ANALOG_DISABLE, \
    .dir = LM3S69XX_GPIO_DIRECTION_INPUT, \
    .otype = LM3S69XX_GPIO_OTYPE_PUSH_PULL, \
    .drive = LM3S69XX_GPIO_DRIVE_2MA, \
    .pull = LM3S69XX_GPIO_PULL_UP, \
    .slr = LM3S69XX_GPIO_NO_SLEW_RATE_CONTROL \
  }

#define LM3S69XX_PIN_LED(port, idx) \
  { \
    .pin_first = LM3S69XX_GPIO_PIN(port, idx), \
    .pin_last = LM3S69XX_GPIO_PIN(port, idx), \
    .digital = LM3S69XX_GPIO_DIGITAL_ENABLE, \
    .alternate = LM3S69XX_GPIO_AF_DISABLE, \
    .analog = LM3S69XX_GPIO_ANALOG_DISABLE, \
    .dir = LM3S69XX_GPIO_DIRECTION_OUTPUT, \
    .otype = LM3S69XX_GPIO_OTYPE_PUSH_PULL, \
    .drive = LM3S69XX_GPIO_DRIVE_8MA, \
    .pull = LM3S69XX_GPIO_NO_PULL, \
    .slr = LM3S69XX_GPIO_SLEW_RATE_CONTROL \
  }

#define LM3S69XX_PIN_SSI_TX(port, idx) LM3S69XX_PIN_UART_TX(port, idx)
#define LM3S69XX_PIN_SSI_RX(port, idx) LM3S69XX_PIN_UART_RX(port, idx)

#ifdef __cplusplus
extern "C" {
#endif

void lm3s69xx_gpio_set_config(const lm3s69xx_gpio_config *config);
void lm3s69xx_gpio_set_config_array(const lm3s69xx_gpio_config *configs, unsigned int count);
void lm3s69xx_gpio_digital_enable(unsigned int pin, bool enable);
void lm3s69xx_gpio_analog_mode_select(unsigned int pin, bool enable);

void lm3s69xx_gpio_set_pin(unsigned int pin, bool set);
bool lm3s69xx_gpio_get_pin(unsigned int pin);

#ifdef __cplusplus
}
#endif

#endif /* LIBBSP_ARM_LM3S69XX_IO_H */