Skip to content

Commit

Permalink
cpu/kinetis_common: reworked GPIO driver
Browse files Browse the repository at this point in the history
  • Loading branch information
haukepetersen committed Feb 19, 2016
1 parent 2b2ce92 commit 4cf040b
Show file tree
Hide file tree
Showing 2 changed files with 181 additions and 334 deletions.
45 changes: 24 additions & 21 deletions cpu/kinetis_common/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

#include <stdint.h>

#include "periph/dev_enums.h"
#include "cpu.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -40,20 +40,10 @@ typedef uint16_t gpio_t;
*/
#define GPIO_UNDEF (0xffff)

/**
* @brief Definition of pin and port positions in the gpio_t type
* @{
*/
#define GPIO_PORT_SHIFT (8)
#define GPIO_PORT_MASK (0xff << (GPIO_PORT_SHIFT))
#define GPIO_PIN_SHIFT (0)
#define GPIO_PIN_MASK (0xff << (GPIO_PIN_SHIFT))
/** @} */

/**
* @brief Define a CPU specific GPIO pin generator macro
*/
#define GPIO_PIN(port, pin) ((port << GPIO_PORT_SHIFT) | pin)
#define GPIO_PIN(x, y) (((x + 1) << 12) | (x << 6) | y)

/**
* @brief Length of the CPU_ID in octets
Expand All @@ -66,9 +56,9 @@ typedef uint16_t gpio_t;
*/
#define HAVE_GPIO_PP_T
typedef enum {
GPIO_NOPULL = 4, /**< do not use internal pull resistors */
GPIO_PULLUP = 9, /**< enable internal pull-up resistor */
GPIO_PULLDOWN = 8 /**< enable internal pull-down resistor */
GPIO_NOPULL = 0x0, /**< do not use internal pull resistors */
GPIO_PULLUP = 0x3, /**< enable internal pull-up resistor */
GPIO_PULLDOWN = 0x2 /**< enable internal pull-down resistor */
} gpio_pp_t;
/** @} */

Expand All @@ -78,16 +68,16 @@ typedef enum {
*/
#define HAVE_GPIO_FLANK_T
typedef enum {
GPIO_LOGIC_ZERO = 0x8, /**< interrupt on logic zero */
GPIO_RISING = 0x9, /**< emit interrupt on rising flank */
GPIO_FALLING = 0xa, /**< emit interrupt on falling flank */
GPIO_BOTH = 0xb, /**< emit interrupt on both flanks */
GPIO_LOGIC_ONE = 0xc, /**< interrupt on logic one */
GPIO_RISING = PORT_PCR_IRQC(0x9), /**< emit interrupt on rising flank */
GPIO_FALLING = PORT_PCR_IRQC(0xa), /**< emit interrupt on falling flank */
GPIO_BOTH = PORT_PCR_IRQC(0xb), /**< emit interrupt on both flanks */
} gpio_flank_t;
/** @} */

/**
* @brief Available ports on the Kinetis family
*
* @todo This is not equal for all members of the Kinetis family, right?
*/
enum {
PORT_A = 0, /**< port A */
Expand All @@ -97,9 +87,22 @@ enum {
PORT_E = 4, /**< port E */
PORT_F = 5, /**< port F */
PORT_G = 6, /**< port G */
PORT_NUMOF
};

/**
* @brief Definition of possible alternate function modes for the pin mux
*/
typedef enum {
GPIO_AF_ANALOG = PORT_PCR_MUX(0),
GPIO_AF_GPIO = PORT_PCR_MUX(1),
GPIO_AF2 = PORT_PCR_MUX(2),
GPIO_AF3 = PORT_PCR_MUX(3),
GPIO_AF4 = PORT_PCR_MUX(4),
GPIO_AF5 = PORT_PCR_MUX(5),
GPIO_AF6 = PORT_PCR_MUX(6),
GPIO_AF7 = PORT_PCR_MUX(7)
} gpio_af_t;

#ifdef __cplusplus
}
#endif
Expand Down
Loading

0 comments on commit 4cf040b

Please sign in to comment.