gpio.h ( File view )

  • By gregkam 2014-10-06
  • View(s):4272
  • Download(s):1
  • Point(s): 1
			/*
 * gpio.h --- STM32 GPIO driver.
 *
 * Copyright (C) 2012, Galois, Inc.
 * All Rights Reserved.
 *
 * This software is released under the "BSD3" license.  Read the file
 * "LICENSE" for more information.
 */

#ifndef __gpio_h
#define __gpio_h

#ifdef __cplusplus
extern "C" {

#endif

#include <stdbool.h>
#include <stdint.h>

#include "hwf4/rcc.h"


/* GPIO Bank Interface ********************************************************/

struct gpio;

/**
 * Enable the clock for the gpio bank
 */
void gpio_enable(struct gpio *gpio);

/**
 * Reset a pin state in the mode register.  The input is a mask for the portions
 * of the register to be reset.
 */
void gpio_reset_moder(struct gpio *gpio, uint32_t val);

/**
 * Update the value of the mode register.
 */
void gpio_update_moder(struct gpio *gpio, uint32_t val);

/**
 * Reset a pin state in the output type register.  The input is a mask for the
 * portions of the register to be reset.
 */
void gpio_reset_otyper(struct gpio *gpio, uint32_t val);

/**
 * Update the value of the output type register.
 */
void gpio_update_otyper(struct gpio *gpio, uint32_t val);

/**
 * Reset a pin state in the output speed register.  The input is a mask for the
 * portions of the register to be reset.
 */
void gpio_reset_ospeedr(struct gpio *gpio, uint32_t val);

/**
 * Update the value of the output speed register.
 */
void gpio_update_ospeedr(struct gpio *gpio, uint32_t val);

/**
 * Reset a pin state in the output pupd register.  The input is a mask for the
 * portions of the register to be reset.
 */
void gpio_reset_pupdr(struct gpio *gpio, uint32_t val);

/**
 * Update the value of the pull up/down register.
 */
void gpio_update_pupdr(struct gpio *gpio, uint32_t val);

/**
 * Get the value of the input register.
 */
uint32_t gpio_get_idr(struct gpio *gpio);

/**
 * Update the value of the output data register.
 */
void gpio_modify_odr(struct gpio *gpio, uint32_t val);

void gpio_reset_afr(struct gpio *gpio, int lh, uint32_t val);

void gpio_modify_afr(struct gpio *gpio, int lh, uint32_t val);

void gpio_set_bsrrl(struct gpio *gpio, uint32_t val);

void gpio_set_bsrrh(struct gpio *gpio, uint32_t val);


/* GPIO Pin Interface *********************************************************/

struct pin;

/**
 * Enable the gpio bank containing a pin.
 */
void pin_enable(struct pin *pin);

enum pin_mode {

    PIN_MODE_INPUT  = 0x00,
    PIN_MODE_OUTPUT = 0x01,
    PIN_MODE_AF     = 0x02,
    PIN_MODE_ANALOG = 0x03

};

/**
 * Set the mode of the pin.
 *
 * NOTE: The mode register for each of the 16 pins takes up two bits of the
 * 32-bit mode register in the gpio bank.
 */
void pin_set_mode(struct pin *pin, enum pin_mode mode);

enum pin_type {

    PIN_TYPE_PUSHPULL  = 0x0,
    PIN_TYPE_OPENDRAIN = 0x1

};

/**
 * Set the output type of the pin.
 */
void pin_set_otype(struct pin *pin, enum pin_type type);

enum pin_speed {

    PIN_SPEED_2MHZ   = 0x00,
    PIN_SPEED_25MHZ  = 0x01,
    PIN_SPEED_50MHZ  = 0x02,
    PIN_SPEED_100MHZ = 0x03

};

/**
 * Set the output speed of the pin.
 */
void pin_set_ospeed(struct pin *pin, enum pin_speed speed);

enum pin_pupd {

    PIN_PUPD_NONE = 0x00,
    PIN_PUPD_UP   = 0x01,
    PIN_PUPD_DOWN = 0x02

};

/**
 * Set the pu/pd for the pin.
 */
void pin_set_pupd(struct pin *pin, enum pin_pupd pupd);

enum pin_af {

    PIN_AF0  = 0x0,
    PIN_AF1  = 0x1,
    PIN_AF2  = 0x2,
    PIN_AF3  = 0x3,
    PIN_AF4  = 0x4,
    PIN_AF5  = 0x5,
    PIN_AF6  = 0x6,
    PIN_AF7  = 0x7,
    PIN_AF8  = 0x8,
    PIN_AF9  = 0x9,
    PIN_AF10 = 0xa,
    PIN_AF11 = 0xb,
    PIN_AF12 = 0xc,
    PIN_AF13 = 0xd,
    PIN_AF14 = 0xe,
    PIN_AF15 = 0xf

};

#define PIN_AF_RTC_50HZ         PIN_AF0
#define PIN_AF_MC0              PIN_AF0
#define PIN_AF_TAMPER           PIN_AF0
#define PIN_AF_SWJ              PIN_AF0
#define PIN_AF_TRACE            PIN_AF0

#define PIN_AF_TIM1             PIN_AF1
#define PIN_AF_TIM2             PIN_AF1

#define PIN_AF_TIM3             PIN_AF2
#define PIN_AF_TIM4             PIN_AF2
#define PIN_AF_TIM5             PIN_AF2

#define PIN_AF_TIM8             PIN_AF3
#define PIN_AF_TIM9             PIN_AF3
#define PIN_AF_TIM10            PIN_AF3
#define PIN_AF_TIM11            PIN_AF3

#define PIN_AF_I2C1             PIN_AF4
#define PIN_AF_I2C2             PIN_AF4
#define PIN_AF_I2C3             PIN_AF4
/* Since all I2C use the same PIN_AFn, generic name for convenience. */
#define PIN_AF_I2C              PIN_AF4

#define PIN_AF_SPI1             PIN_AF5
#define PIN_AF_SPI2             PIN_AF5

#define PIN_AF_SPI3             PIN_AF6

#define PIN_AF_USART1           PIN_AF7
#define PIN_AF_USART2           PIN_AF7
#define PIN_AF_USART3           PIN_AF7
#define PIN_AF_I2S3ext          PIN_AF7

#define PIN_AF_UART4            PIN_AF8
#define PIN_AF_UART5            PIN_AF8
#define PIN_AF_USART6           PIN_AF8

#define PIN_AF_CAN1             PIN_AF9
#define PIN_AF_CAN2             PIN_AF9
#define PIN_AF_TIM12            PIN_AF9
#define PIN_AF_TIM13            PIN_AF9
#define PIN_AF_TIM14            PIN_AF9

#define PIN_AF_OTG_FS           PIN_AF10
#define PIN_AF_OTG_HS           PIN_AF10

#define PIN_AF_ETH              PIN_AF11

#define PIN_AF_FSMC             PIN_AF12
#define PIN_AF_OTG_HS_FS        PIN_AF12
#define PIN_AF_SDIO             PIN_AF12

#define PIN_AF_DCMI             PIN_AF13

#define PIN_AF_EVENTOUT         PIN_AF15

/**
 * Enable an alternate function for a pin.
 */
void pin_set_af(struct pin *pin, enum pin_af af);

/**
 * Reset a pin.
 */
void pin_reset(struct pin *pin);

/**
 * Set a pin.
 */
void pin_set(struct pin *pin);

/**
 * Toggle an output pin.
 */
void pin_toggle(struct pin *pin);

/**
 * Read the value of an input pin.
 */
bool pin_read(struct pin *pin);

/* GPIOA **********************************************************************/

extern struct gpio _gpio_a;
#define gpio_a (&_gpio_a)

extern struct pin _pin_a0;
#define pin_a0 (&_pin_a0)

extern struct pin _pin_a1;
#define pin_a1 (&_pin_a1)

extern struct pin _pin_a2;
#define pin_a2 (&_pin_a2)

extern struct pin _pin_a3;
#define pin_a3 (&_pin_a3)

extern struct pin _pin_a4;
#define pin_a4 (&_pin_a4)

extern struct pin _pin_a5;
#define pin_a5 (&_pin_a5)

extern struct pin _pin_a6;
#define pin_a6 (&_pin_a6)

extern struct pin _pin_a7;
#define pin_a7 (&_pin_a7)

extern struct pin _pin_a8;
#define pin_a8 (&_pin_a8)

extern struct pin _pin_a9;
#define pin_a9 (&_pin_a9)

extern struct pin _pin_a10;
#define pin_a10 (&_pin_a10)

extern struct pin _pin_a11;
#define pin_a11 (&_pin_a11)

extern struct pin _pin_a12;
#define pin_a12 (&_pin_a12)

extern struct pin _pin_a13;
#define pin_a13 (&_pin_a13)

extern struct pin _pin_a14;
#define pin_a14 (&_pin_a14)

extern struct pin _pin_a15;
#define pin_a15 (&_pin_a15)


/* GPIOB **********************************************************************/

extern struct gpio _gpio_b;
#define gpio_b (&_gpio_b)

extern struct pin _pin_b0;
#define pin_b0 (&_pin_b0)

extern struct pin _pin_b1;
#define pin_b1 (&_pin_b1)

extern struct pin _pin_b2;
#define pin_b2 (&_pin_b2)

extern struct pin _pin_b3;
#define pin_b3 (&_pin_b3)

extern struct pin _pin_b4;
#define pin_b4 (&_pin_b4)

extern struct pin _pin_b5;
#define pin_b5 (&_pin_b5)

extern struct pin _pin_b6;
#define pin_b6 (&_pin_b6)

extern struct pin _pin_b7;
#define pin_b7 (&_pin_b7)

extern struct pin _pin_b8;
#define pin_b8 (&_pin_b8)

extern struct pin _pin_b9;
#define pin_b9 (&_pin_b9)

extern struct pin _pin_b10;
#define pin_b10 (&_pin_b10)

extern struct pin _pin_b11;
#define pin_b11 (&_pin_b11)

extern struct pin _pin_b12;
#define pin_b12 (&_pin_b12)

extern struct pin _pin_b13;
#define pin_b13 (&_pin_b13)

extern struct pin _pin_b14;
#define pin_b14 (&_pin_b14)

extern struct pin _pin_b15;
#define pin_b15 (&_pin_b15)


/* GPIOC **********************************************************************/

extern struct gpio _gpio_c;
#define gpio_c (&_gpio_c)

extern struct pin _pin_c0;
#define pin_c0 (&_pin_c0)

extern struct pin _pin_c1;
#define pin_c1 (&_pin_c1)

extern struct pin _pin_c2;
#define pin_c2 (&_pin_c2)

extern struct pin _pin_c3;
#define pin_c3 (&_pin_c3)

extern struct pin _pin_c4;
#define pin_c4 (&_pin_c4)

extern struct pin _pin_c5;
#define pin_c5 (&_pin_c5)

extern struct pin _pin_c6;
#define pin_c6 (&_pin_c6)

extern struct pin _pin_c7;
#define pin_c7 (&_pin_c7)

extern struct pin _pin_c8;
#define pin_c8 (&_pin_c8)

extern struct pin _pin_c9;
#define pin_c9 (&_pin_c9)

extern struct pin _pin_c10;
#define pin_c10 (&_pin_c10)

extern struct pin _pin_c11;
#define pin_c11 (&_pin_c11)

extern struct pin _pin_c12;
#define pin_c12 (&_pin_c12)

extern struct pin _pin_c13;
#define pin_c13 (&_pin_c13)

extern struct pin _pin_c14;
#define pin_c14 (&_pin_c14)

extern struct pin _pin_c15;
#define pin_c15 (&_pin_c15)


/* GPIOD **********************************************************************/

extern struct gpio _gpio_d;
#define gpio_d (&_gpio_d)

extern struct pin _pin_d0;
#define pin_d0 (&_pin_d0)

extern struct pin _pin_d1;
#define pin_d1 (&_pin_d1)

extern struct pin _pin_d2;
#define pin_d2 (&_pin_d2)

extern struct pin _pin_d3;
#define pin_d3 (&_pin_d3)

extern struct pin _pin_d4;
#define pin_d4 (&_pin_d4)

extern struct pin _pin_d5;
#define pin_d5 (&_pin_d5)

extern struct pin _pin_d6;
#define pin_d6 (&_pin_d6)

extern struct pin _pin_d7;
#define pin_d7 (&_pin_d7)

extern struct pin _pin_d8;
#define pin_d8 (&_pin_d8)

extern struct pin _pin_d9;
#define pin_d9 (&_pin_d9)

extern struct pin _pin_d10;
#define pin_d10 (&_pin_d10)

extern struct pin _pin_d11;
#define pin_d11 (&_pin_d11)

extern struct pin _pin_d12;
#define pin_d12 (&_pin_d12)

extern struct pin _pin_d13;
#define pin_d13 (&_pin_d13)

extern struct pin _pin_d14;
#define pin_d14 (&_pin_d14)

extern struct pin _pin_d15;
#define pin_d15 (&_pin_d15)


/* GPIOE **********************************************************************/

extern struct gpio _gpio_e;
#define gpio_e (&_gpio_e)

extern struct pin _pin_e
...
...
(Please download the complete source code to view)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
01.97 kB
.gitignore19.00 B2013-04-23|01:09
01.97 kB
.gitignore8.00 B2013-04-23|01:09
build.mk1.82 kB2013-04-23|01:09
01.97 kB
default_handlers.c6.01 kB2013-04-23|01:09
default_hooks.c159.00 B2013-04-23|01:09
syscalls.c3.28 kB2013-04-23|01:09
Makefile327.00 B2013-04-23|01:09
README.md217.00 B2013-04-23|01:09
config.mk.example151.00 B2013-04-23|01:09
01.97 kB
FreeRTOSConfig.h8.59 kB2013-04-23|01:09
arm_common_tables.h1.09 kB2013-04-23|01:09
arm_math.h234.69 kB2013-04-23|01:09
core_cm0.h31.20 kB2013-04-23|01:09
core_cm3.h68.09 kB2013-04-23|01:09
core_cm4.h77.42 kB2013-04-23|01:09
core_cm4_simd.h23.42 kB2013-04-23|01:09
core_cmFunc.h15.32 kB2013-04-23|01:09
core_cmInstr.h15.73 kB2013-04-23|01:09
stm32f4xx.h507.96 kB2013-04-23|01:09
system_stm32f4xx.h2.17 kB2013-04-23|01:09
01.97 kB
01.97 kB
cortex-m4.mk646.00 B2013-04-23|01:09
01.97 kB
stm32f4.mk131.00 B2013-04-23|01:09
command.mk768.00 B2013-04-23|01:09
toolchain.mk150.00 B2013-04-23|01:09
01.97 kB
build.mk227.00 B2013-04-23|01:09
startup_stm32f4xx.s22.85 kB2013-04-23|01:09
system_stm32f4xx.c22.24 kB2013-04-23|01:09
01.97 kB
.gitignore8.00 B2013-04-23|01:09
build.mk1.04 kB2013-04-23|01:09
01.97 kB
01.97 kB
eeprom.h1.97 kB2013-04-23|01:09
gpio.h14.62 kB2013-04-23|01:09
i2c.h1.63 kB2013-04-23|01:09
interrupt.h1.61 kB2013-04-23|01:09
led.h904.00 B2013-04-23|01:09
rcc.h1.65 kB2013-04-23|01:09
spi.h3.46 kB2013-04-23|01:09
01.97 kB
irq.h6.68 kB2013-04-23|01:09
timer.h2.26 kB2013-04-23|01:09
usart.h3.38 kB2013-04-23|01:09
usb_cdc.h1.32 kB2013-04-23|01:09
01.97 kB
eeprom.c2.97 kB2013-04-23|01:09
fault.c1.38 kB2013-04-23|01:09
gpio.c5.12 kB2013-04-23|01:09
i2c.c9.10 kB2013-04-23|01:09
interrupt.c744.00 B2013-04-23|01:09
led.c2.11 kB2013-04-23|01:09
rcc.c11.74 kB2013-04-23|01:09
spi.c12.33 kB2013-04-23|01:09
timer.c10.08 kB2013-04-23|01:09
usart.c10.83 kB2013-04-23|01:09
usb_cdc.c1.21 kB2013-04-23|01:09
01.97 kB
gdb-init61.00 B2013-04-23|01:09
gdb-tdesc-cortexm-fpa.xml5.74 kB2013-04-23|01:09
openocd-stm32f4.cfg124.00 B2013-04-23|01:09
stm32_flash.ld5.33 kB2013-04-23|01:09
01.97 kB
01.97 kB
main.c2.92 kB2013-04-23|01:09
01.97 kB
main.c1.51 kB2013-04-23|01:09
01.97 kB
.gitignore32.00 B2013-04-23|01:09
build.mk1.12 kB2013-04-23|01:09
main.c740.00 B2013-04-23|01:09
01.97 kB
main.c11.32 kB2013-04-23|01:09
01.97 kB
main.c2.51 kB2013-04-23|01:09
01.97 kB
main.c2.14 kB2013-04-23|01:09
01.97 kB
main.c1.03 kB2013-04-23|01:09
01.97 kB
main.c1.49 kB2013-04-23|01:09
01.97 kB
main.c1.90 kB2013-04-23|01:09
01.97 kB
.gitignore8.00 B2013-04-23|01:09
build.mk1.17 kB2013-04-23|01:09
01.97 kB
01.97 kB
usb_bsp.h2.29 kB2013-04-23|01:09
usb_conf.h10.48 kB2013-04-23|01:09
usb_core.h12.29 kB2013-04-23|01:09
usb_dcd.h4.48 kB2013-04-23|01:09
usb_dcd_int.h3.03 kB2013-04-23|01:09
usb_defines.h6.52 kB2013-04-23|01:09
usb_hcd.h2.76 kB2013-04-23|01:09
usb_hcd_int.h3.65 kB2013-04-23|01:09
usb_otg.h1.97 kB2013-04-23|01:09
usb_regs.h21.22 kB2013-04-23|01:09
usbd_cdc_core.h3.87 kB2013-04-23|01:09
usbd_cdc_if_template.h1.85 kB2013-04-23|01:09
usbd_cdc_vcp.h2.89 kB2013-04-23|01:09
usbd_conf.h3.29 kB2013-04-23|01:09
usbd_core.h2.50 kB2013-04-23|01:09
usbd_def.h4.82 kB2013-04-23|01:09
usbd_desc.h3.35 kB2013-04-23|01:09
usbd_ioreq.h2.89 kB2013-04-23|01:09
usbd_req.h2.50 kB2013-04-23|01:09
usbd_usr.h3.00 kB2013-04-23|01:09
01.97 kB
usb_bsp.c3.27 kB2013-04-23|01:09
usb_core.c55.46 kB2013-04-23|01:09
usb_dcd.c9.21 kB2013-04-23|01:09
usb_dcd_int.c21.32 kB2013-04-23|01:09
usb_hcd.c5.62 kB2013-04-23|01:09
usb_hcd_int.c21.58 kB2013-04-23|01:09
usb_otg.c9.48 kB2013-04-23|01:09
usbd_cdc_core.c24.57 kB2013-04-23|01:09
usbd_cdc_if_template.c6.07 kB2013-04-23|01:09
usbd_cdc_vcp.c6.71 kB2013-04-23|01:09
usbd_core.c11.39 kB2013-04-23|01:09
usbd_desc.c8.23 kB2013-04-23|01:09
usbd_ioreq.c5.38 kB2013-04-23|01:09
usbd_req.c19.55 kB2013-04-23|01:09
usbd_usr.c3.48 kB2013-04-23|01:09
...
Sponsored links

gpio.h (278.02 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D