Add GPIO header file + a little bit of GPIO configuration logig

This commit is contained in:
Gregory Nutt 2014-10-19 13:07:52 -06:00
parent 3896f187a6
commit 2a7edd7e1c
3 changed files with 1645 additions and 26 deletions

File diff suppressed because it is too large Load Diff

View File

@ -49,10 +49,133 @@
* Pre-processor Definitions * Pre-processor Definitions
************************************************************************************/ ************************************************************************************/
#define __GPIO_INPUT (1 << 0) /* Bit 0: GPIO is an input */
#define __GPIO_OUTPUT (1 << 1) /* Bit 1: GPIO is an output */
#define __GPIO_DOUT (1 << 2) /* Bit 2: An input modified with DOUT setting */
#define __GPIO_DRIVE (1 << 3) /* Bit 3: An output with drive selection */
/************************************************************************************ /************************************************************************************
* Public Data * Private Data
************************************************************************************/ ************************************************************************************/
static const uint8_t g_gpiomode[16] =
{
(__GPIO_DOUT), /* 0 DISABLED Input disabled. Pullup if DOUT is
* set. */
(__GPIO_INPUT | __GPIO_DOUT), /* 1 INPUT Input enabled. Filter if DOUT is set. */
(__GPIO_INPUT | __GPIO_DOUT), /* 2 INPUTPULL Input enabled. DOUT determines pull
* direction */
(__GPIO_INPUT | __GPIO_DOUT), /* 3 INPUTPULLFILTER Input enabled with filter.
* COUT determines pull direction */
(__GPIO_OUTPUT), /* 4 PUSHPULL Push-pull output */
(__GPIO_OUTPUT | __GPIO_DRIVE), /* 5 PUSHPULLDRIVE Push-pull output with drive-
* strength set by DRIVEMODE */
(__GPIO_OUTPUT), /* 6 WIREDOR Wired-or output */
(__GPIO_OUTPUT), /* 7 WIREDORPULLDOWN Wired-or output with pull-
* down */
(__GPIO_OUTPUT), /* 8 WIREDAND Open-drain output */
(__GPIO_OUTPUT), /* 9 WIREDANDFILTER Open-drain output with filter */
(__GPIO_OUTPUT), /* 10 WIREDANDPULLUP Open-drain output with pullup */
(__GPIO_OUTPUT), /* 11 WIREDANDPULLUPFILTER Open-drain output with
* filter and pullup */
(__GPIO_OUTPUT | __GPIO_DRIVE), /* 12 WIREDANDDRIVE Open-drain output with
* drive-strength set by DRIVEMODE */
(__GPIO_OUTPUT | __GPIO_DRIVE), /* 13 WIREDANDDRIVEFILTER Open-drain output with
* filter and drive-strength set by DRIVEMODE */
(__GPIO_OUTPUT | __GPIO_DRIVE), /* 14 WIREDANDDRIVEPULLUP Open-drain output with
* pullup and drive-strength set by DRIVEMODE */
(__GPIO_OUTPUT | __GPIO_DRIVE) /* 15 WIREDANDDRIVEPULLUPFILTER Open-drain output
* with filter, pullup and drive-strength set
* by DRIVEMODE */
};
/************************************************************************************
* Private Functions
************************************************************************************/
/************************************************************************************
* Name: efm32_port
*
* Description:
* Extract the encoded port number
*
************************************************************************************/
static inline uint8_t efm32_port(gpio_pinset_t cfgset)
{
return (uint8_t)((cfgset & GPIO_PORT_MASK) >> GPIO_PORT_SHIFT);
}
/************************************************************************************
* Name: efm32_pin
*
* Description:
* Extract the encoded pin number
*
************************************************************************************/
static inline uint8_t efm32_pin(gpio_pinset_t cfgset)
{
return (uint8_t)((cfgset & GPIO_PIN_MASK) >> GPIO_PIN_SHIFT);
}
/************************************************************************************
* Name: efm32_mode
*
* Description:
* Extract the encoded pin mode
*
************************************************************************************/
static inline uint8_t efm32_pin(gpio_pinset_t cfgset)
{
return (uint8_t)((cfgset & GPIO_PIN_MASK) >> GPIO_PIN_SHIFT);
}
/************************************************************************************
* Name: efm32_drivestrength
*
* Description:
* Extract the output drive strength
*
************************************************************************************/
static uint8_t efm32_drivestrength(uint8_t mode, gpio_pinset_t cfgset)
{
if ((g_gpiomode[mode] & __GPIO_DRIVE) != 0)
{
return (uint8_t)((cfgset & GPIO_DRIVE_MASK) >> GPIO_DRIVE_SHIFT);
}
else
{
return _GPIO_DRIVE_STANDARD;
}
}
/************************************************************************************
* Name: efm32_dout
*
* Description:
* Extract the encoded port number
*
************************************************************************************/
static uint8_t efm32_dout(uint8_t mode, gpio_pinset_t cfgset)
{
if ((g_gpiomode[mode] & __GPIO_DOUT) != 0)
{
return (uint8_t)((cfgset >> GPIO_MODE_DOUT_SHIFT) & 1);
}
else if ((g_gpiomode[mode] & __GPIO_OUTPUT) != 0)
{
return (uint8_t)((cfgset >> GPIO_OUTPUT_SHIFT) & 1);
}
else
{
return 0;
}
}
/************************************************************************************ /************************************************************************************
* Public Functions * Public Functions
************************************************************************************/ ************************************************************************************/
@ -67,6 +190,12 @@
int efm32_configgpio(gpio_pinset_t cfgset) int efm32_configgpio(gpio_pinset_t cfgset)
{ {
uint8_t port = efm32_pin(cfgset);
uint8_t pin = efm32_port(cfgset);
uint8_t mode = efm32_mode(cfgset);
uint8_t drive = efm32_drivestrength(mode, cfgset);
uint8_t dout = efm32_dout(mode, cfgset);
#warning Missing logic #warning Missing logic
return -ENOSYS; return -ENOSYS;
} }

View File

@ -71,7 +71,10 @@
#define GPIO_MODE_SHIFT (12) /* Bits 12-15: Port mode */ #define GPIO_MODE_SHIFT (12) /* Bits 12-15: Port mode */
#define GPIO_MODE_MASK (15 << GPIO_MODE_SHIFT) #define GPIO_MODE_MASK (15 << GPIO_MODE_SHIFT)
#define GPIO_MODE_DOUT (1 << 11) /* DOUT input mode modifier */
#define GPIO_MODE_DOUT_SHIFT (11) /* Bit 11: Input mode modifer */
#define GPIO_MODE_DOUT_MASK (1 << GPIO_MODE_DOUT_SHIFT)
# define GPIO_MODE_DOUT GPIO_MODE_DOUT_MASK
/* Input modes */ /* Input modes */
@ -127,8 +130,10 @@
* .... V... .... .... * .... V... .... ....
*/ */
#define GPIO_OUTPUT_SET (1 << 11) /* Bit 11: Initial value of output */ #define GPIO_OUTPUT_SHIFT (11) /* Bit 11: Initial value of output */
#define GPIO_OUTPUT_CLEAR (0) #define GPIO_OUTPUT_MASK (1 << GPIO_OUTPUT_SHIFT)
# define GPIO_OUTPUT_SET GPIO_OUTPUT_MASK
# define GPIO_OUTPUT_CLEAR (0)
/* Output drive: /* Output drive:
* *
@ -137,10 +142,14 @@
#define GPIO_DRIVE_SHIFT (9) /* Bits 9-10: Output drive strength */ #define GPIO_DRIVE_SHIFT (9) /* Bits 9-10: Output drive strength */
#define GPIO_DRIVE_MASK (3 << GPIO_MODE_SHIFT) #define GPIO_DRIVE_MASK (3 << GPIO_MODE_SHIFT)
# define GPIO_DRIVE_STANDARD (0 << GPIO_MODE_SHIFT) /* 6 mA drive current */ # define _GPIO_DRIVE_STANDARD (0) /* 6 mA drive current */
# define GPIO_DRIVE_LOWEST (1 << GPIO_MODE_SHIFT) /* 0.5 mA drive current */ # define _GPIO_DRIVE_LOWEST (1) /* 0.5 mA drive current */
# define GPIO_DRIVE_HIGH (2 << GPIO_MODE_SHIFT) /* 20 mA drive current */ # define _GPIO_DRIVE_HIGH (2) /* 20 mA drive current */
# define GPIO_DRIVE_LOW (3 << GPIO_MODE_SHIFT) /* 2 mA drive current */ # define _GPIO_DRIVE_LOW (3) /* 2 mA drive current */
# define GPIO_DRIVE_STANDARD (_GPIO_DRIVE_STANDARD << GPIO_MODE_SHIFT)
# define GPIO_DRIVE_LOWEST (_GPIO_DRIVE_LOWEST << GPIO_MODE_SHIFT)
# define GPIO_DRIVE_HIGH (_GPIO_DRIVE_HIGH << GPIO_MODE_SHIFT)
# define GPIO_DRIVE_LOW (_GPIO_DRIVE_LOW << GPIO_MODE_SHIFT)
/* Interrupt Mode (Input only): /* Interrupt Mode (Input only):
* *
@ -158,7 +167,7 @@
* .... .... .PPP .... * .... .... .PPP ....
*/ */
#define GPIO_PORT_SHIFT (4) /* Bit 4-7: Port number */ #define GPIO_PORT_SHIFT (4) /* Bit 4-6: Port number */
#define GPIO_PORT_MASK (7 << GPIO_PORT_SHIFT) #define GPIO_PORT_MASK (7 << GPIO_PORT_SHIFT)
# define GPIO_PORTA (0 << GPIO_PORT_SHIFT) # define GPIO_PORTA (0 << GPIO_PORT_SHIFT)
# define GPIO_PORTB (1 << GPIO_PORT_SHIFT) # define GPIO_PORTB (1 << GPIO_PORT_SHIFT)
@ -173,23 +182,23 @@
*/ */
#define GPIO_PIN_SHIFT (0) /* Bits 0-3: Pin number: 0-15 */ #define GPIO_PIN_SHIFT (0) /* Bits 0-3: Pin number: 0-15 */
#define GPIO_PIN_MASK (31 << GPIO_PIN_SHIFT) #define GPIO_PIN_MASK (15 << GPIO_PIN_SHIFT)
#define GPIO_PIN0 (0 << GPIO_PIN_SHIFT) # define GPIO_PIN0 (0 << GPIO_PIN_SHIFT)
#define GPIO_PIN1 (1 << GPIO_PIN_SHIFT) # define GPIO_PIN1 (1 << GPIO_PIN_SHIFT)
#define GPIO_PIN2 (2 << GPIO_PIN_SHIFT) # define GPIO_PIN2 (2 << GPIO_PIN_SHIFT)
#define GPIO_PIN3 (3 << GPIO_PIN_SHIFT) # define GPIO_PIN3 (3 << GPIO_PIN_SHIFT)
#define GPIO_PIN4 (4 << GPIO_PIN_SHIFT) # define GPIO_PIN4 (4 << GPIO_PIN_SHIFT)
#define GPIO_PIN5 (5 << GPIO_PIN_SHIFT) # define GPIO_PIN5 (5 << GPIO_PIN_SHIFT)
#define GPIO_PIN6 (6 << GPIO_PIN_SHIFT) # define GPIO_PIN6 (6 << GPIO_PIN_SHIFT)
#define GPIO_PIN7 (7 << GPIO_PIN_SHIFT) # define GPIO_PIN7 (7 << GPIO_PIN_SHIFT)
#define GPIO_PIN8 (8 << GPIO_PIN_SHIFT) # define GPIO_PIN8 (8 << GPIO_PIN_SHIFT)
#define GPIO_PIN9 (9 << GPIO_PIN_SHIFT) # define GPIO_PIN9 (9 << GPIO_PIN_SHIFT)
#define GPIO_PIN10 (10 << GPIO_PIN_SHIFT) # define GPIO_PIN10 (10 << GPIO_PIN_SHIFT)
#define GPIO_PIN11 (11 << GPIO_PIN_SHIFT) # define GPIO_PIN11 (11 << GPIO_PIN_SHIFT)
#define GPIO_PIN12 (12 << GPIO_PIN_SHIFT) # define GPIO_PIN12 (12 << GPIO_PIN_SHIFT)
#define GPIO_PIN13 (13 << GPIO_PIN_SHIFT) # define GPIO_PIN13 (13 << GPIO_PIN_SHIFT)
#define GPIO_PIN14 (14 << GPIO_PIN_SHIFT) # define GPIO_PIN14 (14 << GPIO_PIN_SHIFT)
#define GPIO_PIN15 (15 << GPIO_PIN_SHIFT) # define GPIO_PIN15 (15 << GPIO_PIN_SHIFT)
/************************************************************************************ /************************************************************************************
* Public Types * Public Types