1eaaa4f7eSrev13@wp.pl /*
2eaaa4f7eSrev13@wp.pl * (C) Copyright 2011
3eaaa4f7eSrev13@wp.pl * Yuri Tikhonov, Emcraft Systems, yur@emcraft.com
4eaaa4f7eSrev13@wp.pl *
5eaaa4f7eSrev13@wp.pl * (C) Copyright 2015
6*5be93569SKamil Lulko * Kamil Lulko, <kamil.lulko@gmail.com>
7eaaa4f7eSrev13@wp.pl *
8eaaa4f7eSrev13@wp.pl * SPDX-License-Identifier: GPL-2.0+
9eaaa4f7eSrev13@wp.pl */
10eaaa4f7eSrev13@wp.pl
11eaaa4f7eSrev13@wp.pl #ifndef _STM32_GPIO_H_
12eaaa4f7eSrev13@wp.pl #define _STM32_GPIO_H_
13eaaa4f7eSrev13@wp.pl
1460570df1Skunhuahuang #if (CONFIG_STM32_USART == 1)
1560570df1Skunhuahuang #define STM32_GPIO_PORT_X STM32_GPIO_PORT_A
1660570df1Skunhuahuang #define STM32_GPIO_PIN_TX STM32_GPIO_PIN_9
1760570df1Skunhuahuang #define STM32_GPIO_PIN_RX STM32_GPIO_PIN_10
1860570df1Skunhuahuang #define STM32_GPIO_USART STM32_GPIO_AF7
1960570df1Skunhuahuang
2060570df1Skunhuahuang #elif (CONFIG_STM32_USART == 2)
2160570df1Skunhuahuang #define STM32_GPIO_PORT_X STM32_GPIO_PORT_D
2260570df1Skunhuahuang #define STM32_GPIO_PIN_TX STM32_GPIO_PIN_5
2360570df1Skunhuahuang #define STM32_GPIO_PIN_RX STM32_GPIO_PIN_6
2460570df1Skunhuahuang #define STM32_GPIO_USART STM32_GPIO_AF7
2560570df1Skunhuahuang
2660570df1Skunhuahuang #elif (CONFIG_STM32_USART == 3)
2760570df1Skunhuahuang #define STM32_GPIO_PORT_X STM32_GPIO_PORT_C
2860570df1Skunhuahuang #define STM32_GPIO_PIN_TX STM32_GPIO_PIN_10
2960570df1Skunhuahuang #define STM32_GPIO_PIN_RX STM32_GPIO_PIN_11
3060570df1Skunhuahuang #define STM32_GPIO_USART STM32_GPIO_AF7
3160570df1Skunhuahuang
3260570df1Skunhuahuang #elif (CONFIG_STM32_USART == 6)
3360570df1Skunhuahuang #define STM32_GPIO_PORT_X STM32_GPIO_PORT_G
3460570df1Skunhuahuang #define STM32_GPIO_PIN_TX STM32_GPIO_PIN_14
3560570df1Skunhuahuang #define STM32_GPIO_PIN_RX STM32_GPIO_PIN_9
3660570df1Skunhuahuang #define STM32_GPIO_USART STM32_GPIO_AF8
3760570df1Skunhuahuang
3860570df1Skunhuahuang #else
3960570df1Skunhuahuang #define STM32_GPIO_PORT_X STM32_GPIO_PORT_A
4060570df1Skunhuahuang #define STM32_GPIO_PIN_TX STM32_GPIO_PIN_9
4160570df1Skunhuahuang #define STM32_GPIO_PIN_RX STM32_GPIO_PIN_10
4260570df1Skunhuahuang #define STM32_GPIO_USART STM32_GPIO_AF7
4360570df1Skunhuahuang
4460570df1Skunhuahuang #endif
4560570df1Skunhuahuang
46eaaa4f7eSrev13@wp.pl enum stm32_gpio_port {
47eaaa4f7eSrev13@wp.pl STM32_GPIO_PORT_A = 0,
48eaaa4f7eSrev13@wp.pl STM32_GPIO_PORT_B,
49eaaa4f7eSrev13@wp.pl STM32_GPIO_PORT_C,
50eaaa4f7eSrev13@wp.pl STM32_GPIO_PORT_D,
51eaaa4f7eSrev13@wp.pl STM32_GPIO_PORT_E,
52eaaa4f7eSrev13@wp.pl STM32_GPIO_PORT_F,
53eaaa4f7eSrev13@wp.pl STM32_GPIO_PORT_G,
54eaaa4f7eSrev13@wp.pl STM32_GPIO_PORT_H,
55eaaa4f7eSrev13@wp.pl STM32_GPIO_PORT_I
56eaaa4f7eSrev13@wp.pl };
57eaaa4f7eSrev13@wp.pl
58eaaa4f7eSrev13@wp.pl enum stm32_gpio_pin {
59eaaa4f7eSrev13@wp.pl STM32_GPIO_PIN_0 = 0,
60eaaa4f7eSrev13@wp.pl STM32_GPIO_PIN_1,
61eaaa4f7eSrev13@wp.pl STM32_GPIO_PIN_2,
62eaaa4f7eSrev13@wp.pl STM32_GPIO_PIN_3,
63eaaa4f7eSrev13@wp.pl STM32_GPIO_PIN_4,
64eaaa4f7eSrev13@wp.pl STM32_GPIO_PIN_5,
65eaaa4f7eSrev13@wp.pl STM32_GPIO_PIN_6,
66eaaa4f7eSrev13@wp.pl STM32_GPIO_PIN_7,
67eaaa4f7eSrev13@wp.pl STM32_GPIO_PIN_8,
68eaaa4f7eSrev13@wp.pl STM32_GPIO_PIN_9,
69eaaa4f7eSrev13@wp.pl STM32_GPIO_PIN_10,
70eaaa4f7eSrev13@wp.pl STM32_GPIO_PIN_11,
71eaaa4f7eSrev13@wp.pl STM32_GPIO_PIN_12,
72eaaa4f7eSrev13@wp.pl STM32_GPIO_PIN_13,
73eaaa4f7eSrev13@wp.pl STM32_GPIO_PIN_14,
74eaaa4f7eSrev13@wp.pl STM32_GPIO_PIN_15
75eaaa4f7eSrev13@wp.pl };
76eaaa4f7eSrev13@wp.pl
77eaaa4f7eSrev13@wp.pl enum stm32_gpio_mode {
78eaaa4f7eSrev13@wp.pl STM32_GPIO_MODE_IN = 0,
79eaaa4f7eSrev13@wp.pl STM32_GPIO_MODE_OUT,
80eaaa4f7eSrev13@wp.pl STM32_GPIO_MODE_AF,
81eaaa4f7eSrev13@wp.pl STM32_GPIO_MODE_AN
82eaaa4f7eSrev13@wp.pl };
83eaaa4f7eSrev13@wp.pl
84eaaa4f7eSrev13@wp.pl enum stm32_gpio_otype {
85eaaa4f7eSrev13@wp.pl STM32_GPIO_OTYPE_PP = 0,
86eaaa4f7eSrev13@wp.pl STM32_GPIO_OTYPE_OD
87eaaa4f7eSrev13@wp.pl };
88eaaa4f7eSrev13@wp.pl
89eaaa4f7eSrev13@wp.pl enum stm32_gpio_speed {
90eaaa4f7eSrev13@wp.pl STM32_GPIO_SPEED_2M = 0,
91eaaa4f7eSrev13@wp.pl STM32_GPIO_SPEED_25M,
92eaaa4f7eSrev13@wp.pl STM32_GPIO_SPEED_50M,
93eaaa4f7eSrev13@wp.pl STM32_GPIO_SPEED_100M
94eaaa4f7eSrev13@wp.pl };
95eaaa4f7eSrev13@wp.pl
96eaaa4f7eSrev13@wp.pl enum stm32_gpio_pupd {
97eaaa4f7eSrev13@wp.pl STM32_GPIO_PUPD_NO = 0,
98eaaa4f7eSrev13@wp.pl STM32_GPIO_PUPD_UP,
99eaaa4f7eSrev13@wp.pl STM32_GPIO_PUPD_DOWN
100eaaa4f7eSrev13@wp.pl };
101eaaa4f7eSrev13@wp.pl
102eaaa4f7eSrev13@wp.pl enum stm32_gpio_af {
103eaaa4f7eSrev13@wp.pl STM32_GPIO_AF0 = 0,
104eaaa4f7eSrev13@wp.pl STM32_GPIO_AF1,
105eaaa4f7eSrev13@wp.pl STM32_GPIO_AF2,
106eaaa4f7eSrev13@wp.pl STM32_GPIO_AF3,
107eaaa4f7eSrev13@wp.pl STM32_GPIO_AF4,
108eaaa4f7eSrev13@wp.pl STM32_GPIO_AF5,
109eaaa4f7eSrev13@wp.pl STM32_GPIO_AF6,
110eaaa4f7eSrev13@wp.pl STM32_GPIO_AF7,
111eaaa4f7eSrev13@wp.pl STM32_GPIO_AF8,
112eaaa4f7eSrev13@wp.pl STM32_GPIO_AF9,
113eaaa4f7eSrev13@wp.pl STM32_GPIO_AF10,
114eaaa4f7eSrev13@wp.pl STM32_GPIO_AF11,
115eaaa4f7eSrev13@wp.pl STM32_GPIO_AF12,
116eaaa4f7eSrev13@wp.pl STM32_GPIO_AF13,
117eaaa4f7eSrev13@wp.pl STM32_GPIO_AF14,
118eaaa4f7eSrev13@wp.pl STM32_GPIO_AF15
119eaaa4f7eSrev13@wp.pl };
120eaaa4f7eSrev13@wp.pl
121eaaa4f7eSrev13@wp.pl struct stm32_gpio_dsc {
122eaaa4f7eSrev13@wp.pl enum stm32_gpio_port port;
123eaaa4f7eSrev13@wp.pl enum stm32_gpio_pin pin;
124eaaa4f7eSrev13@wp.pl };
125eaaa4f7eSrev13@wp.pl
126eaaa4f7eSrev13@wp.pl struct stm32_gpio_ctl {
127eaaa4f7eSrev13@wp.pl enum stm32_gpio_mode mode;
128eaaa4f7eSrev13@wp.pl enum stm32_gpio_otype otype;
129eaaa4f7eSrev13@wp.pl enum stm32_gpio_speed speed;
130eaaa4f7eSrev13@wp.pl enum stm32_gpio_pupd pupd;
131eaaa4f7eSrev13@wp.pl enum stm32_gpio_af af;
132eaaa4f7eSrev13@wp.pl };
133eaaa4f7eSrev13@wp.pl
stm32_gpio_to_port(unsigned gpio)134eaaa4f7eSrev13@wp.pl static inline unsigned stm32_gpio_to_port(unsigned gpio)
135eaaa4f7eSrev13@wp.pl {
136eaaa4f7eSrev13@wp.pl return gpio / 16;
137eaaa4f7eSrev13@wp.pl }
138eaaa4f7eSrev13@wp.pl
stm32_gpio_to_pin(unsigned gpio)139eaaa4f7eSrev13@wp.pl static inline unsigned stm32_gpio_to_pin(unsigned gpio)
140eaaa4f7eSrev13@wp.pl {
141eaaa4f7eSrev13@wp.pl return gpio % 16;
142eaaa4f7eSrev13@wp.pl }
143eaaa4f7eSrev13@wp.pl
144eaaa4f7eSrev13@wp.pl int stm32_gpio_config(const struct stm32_gpio_dsc *gpio_dsc,
145eaaa4f7eSrev13@wp.pl const struct stm32_gpio_ctl *gpio_ctl);
146eaaa4f7eSrev13@wp.pl int stm32_gpout_set(const struct stm32_gpio_dsc *gpio_dsc, int state);
147eaaa4f7eSrev13@wp.pl
148eaaa4f7eSrev13@wp.pl #endif /* _STM32_GPIO_H_ */
149