aboutsummaryrefslogtreecommitdiff
path: root/include/libopenstm32/gpio.h
blob: 87182709922076ccc47898780a972933b0d3d5bc (plain)
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
/*
 * This file is part of the libopenstm32 project.
 *
 * Copyright (C) 2009 Uwe Hermann <uwe@hermann-uwe.de>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 */

#ifndef LIBOPENSTM32_GPIO_H
#define LIBOPENSTM32_GPIO_H

#include "libopenstm32.h"

/* GPIO port base addresses */
#define GPIO_BASE_A			(PERIPH_BASE_APB2 + 0x0800)
#define GPIO_BASE_B			(PERIPH_BASE_APB2 + 0x0c00)
#define GPIO_BASE_C			(PERIPH_BASE_APB2 + 0x1000)
#define GPIO_BASE_D			(PERIPH_BASE_APB2 + 0x1400)
#define GPIO_BASE_E			(PERIPH_BASE_APB2 + 0x1800)
#define GPIO_BASE_F			(PERIPH_BASE_APB2 + 0x1c00)
#define GPIO_BASE_G			(PERIPH_BASE_APB2 + 0x2000)

/* Register offsets */
#define GPIO_CTRL_LO			0x00	/* 32 bit */
#define GPIO_CTRL_HI			0x04	/* 32 bit */
#define GPIO_INPUT_DATA			0x08	/* 32 bit, only 15:0 used */
#define GPIO_OUTPUT_DATA		0x0c	/* 32 bit, only 15:0 used */
#define GPIO_BIT_SET_RESET		0x10	/* 32 bit */
#define GPIO_BIT_RESET			0x14	/* 16 bit */
#define GPIO_LOCK			0x18	/* 32 bit */

/* Output mode (MODE[1:0]) values */
#define GPIO_MODE_INPUT			0x00	/* Default */
#define GPIO_MODE_OUTPUT_10_MHZ		0x01
#define GPIO_MODE_OUTPUT_2_MHZ		0x02
#define GPIO_MODE_OUTPUT_50_MHZ		0x03

/* CNF[1:0] values when MODE[1:0] is 00 (input mode). */
#define GPIO_CNF_INPUT_ANALOG		0x00
#define GPIO_CNF_INPUT_FLOAT		0x01	/* Default */
#define GPIO_CNF_INPUT_PULL_UPDOWN	0x02

/* CNF[1:0] values when MODE[1:0] is != 00 (one of the output modes). */
#define GPIO_CNF_OUTPUT_PUSHPULL	0x00
#define GPIO_CNF_OUTPUT_OPENDRAIN	0x01
#define GPIO_CNF_OUTPUT_ALTFN_PUSHPULL	0x02
#define GPIO_CNF_OUTPUT_ALTFN_OPENDRAIN	0x03

void gpio_set(int gpio);
void gpio_clear(int gpio);
void gpio_toggle(int gpio);

#endif