Skip to content

Add a gpio pinmap #10644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions TESTS/mbed_hal/pinmap/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

using namespace utest::v1;

#include "gpio_api.h"
#include "analogin_api.h"
#include "analogout_api.h"
#include "can_api.h"
Expand All @@ -38,6 +39,7 @@ typedef struct {
} pinmap_info_t;

const pinmap_info_t pinmap_functions[] = {
PINMAP_TEST_ENTRY(gpio_pinmap),
#if DEVICE_ANALOGIN
PINMAP_TEST_ENTRY(analogin_pinmap),
#endif
Expand Down
13 changes: 13 additions & 0 deletions hal/gpio_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include <stdint.h>
#include "device.h"
#include "pinmap.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -135,6 +136,18 @@ void gpio_init_out_ex(gpio_t *gpio, PinName pin, int value);
*/
void gpio_init_inout(gpio_t *gpio, PinName pin, PinDirection direction, PinMode mode, int value);

/** Get the pins that support all GPIO tests
*
* Return a PinMap array of pins that support GPIO. The
* array is terminated with {NC, NC, 0}.
*
* Targets should override the weak implementation of this
* function to provide the actual pinmap for GPIO testing.
*
* @return PinMap array
*/
const PinMap *gpio_pinmap(void);

/**@}*/

#ifdef __cplusplus
Expand Down
51 changes: 51 additions & 0 deletions hal/mbed_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* limitations under the License.
*/
#include "hal/gpio_api.h"
#include "platform/mbed_toolchain.h"

static inline void _gpio_init_in(gpio_t *gpio, PinName pin, PinMode mode)
{
Expand Down Expand Up @@ -66,3 +67,53 @@ void gpio_init_inout(gpio_t *gpio, PinName pin, PinDirection direction, PinMode
_gpio_init_out(gpio, pin, mode, value);
}
}

#ifdef TARGET_FF_ARDUINO

typedef enum {
DEFAULT_GPIO = 0,
} DefaultGPIOPeripheralName;

MBED_WEAK const PinMap *gpio_pinmap()
{
// Targets should override this weak implementation to provide correct data.
static const PinMap empty_gpio_pinmap[] = {
{D0, DEFAULT_GPIO, 0},
{D1, DEFAULT_GPIO, 0},
{D2, DEFAULT_GPIO, 0},
{D3, DEFAULT_GPIO, 0},
{D4, DEFAULT_GPIO, 0},
{D5, DEFAULT_GPIO, 0},
{D6, DEFAULT_GPIO, 0},
{D7, DEFAULT_GPIO, 0},
{D8, DEFAULT_GPIO, 0},
{D9, DEFAULT_GPIO, 0},
{D10, DEFAULT_GPIO, 0},
{D11, DEFAULT_GPIO, 0},
{D12, DEFAULT_GPIO, 0},
{D13, DEFAULT_GPIO, 0},
{D14, DEFAULT_GPIO, 0},
{D15, DEFAULT_GPIO, 0},
{A0, DEFAULT_GPIO, 0},
{A1, DEFAULT_GPIO, 0},
{A2, DEFAULT_GPIO, 0},
{A3, DEFAULT_GPIO, 0},
{A4, DEFAULT_GPIO, 0},
{A5, DEFAULT_GPIO, 0},

{NC, NC, 0},
};
return empty_gpio_pinmap;
}

#else

MBED_WEAK const PinMap *gpio_pinmap()
{
static const PinMap empty_gpio_pinmap[] = {
{NC, NC, 0},
};
return empty_gpio_pinmap;
}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
extern "C" {
#endif

typedef enum {
GPIO_X = 0, // dummy peripheral used instead of GPIO_A..GPIO_E
} GPIOName;

typedef enum {
OSC32KCLK = 0,
} RTCName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,47 @@

#include "PeripheralPins.h"

/************GPIO***************/
const PinMap PinMap_GPIO[] = {
{PTA0, GPIO_X, 1},
{PTA1, GPIO_X, 1},
{PTA2, GPIO_X, 1},
{PTA3, GPIO_X, 1},
{PTA4, GPIO_X, 1},
{PTA18, GPIO_X, 1},
{PTA19, GPIO_X, 1},

{PTC4, GPIO_X, 1},
{PTC5, GPIO_X, 1},
{PTC6, GPIO_X, 1},
{PTC7, GPIO_X, 1},

{PTD1, GPIO_X, 1},
{PTD2, GPIO_X, 1},
{PTD3, GPIO_X, 1},
{PTD4, GPIO_X, 1},
{PTD5, GPIO_X, 1},
{PTD6, GPIO_X, 1},
{PTD7, GPIO_X, 1},

{PTE0, GPIO_X, 1},
{PTE1, GPIO_X, 1},
{PTE2, GPIO_X, 1},
{PTE3, GPIO_X, 1},
{PTE4, GPIO_X, 1},
{PTE16, GPIO_X, 1},
{PTE17, GPIO_X, 1},
{PTE18, GPIO_X, 1},
{PTE19, GPIO_X, 1},

{NC , NC , 0}
};

const PinMap *gpio_pinmap()
{
return PinMap_GPIO;
}

/************RTC***************/
const PinMap PinMap_RTC[] = {
{NC, OSC32KCLK, 0},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
extern "C" {
#endif

typedef enum {
GPIO_X = 0, // dummy peripheral used instead of GPIO_A..GPIO_C
} GPIOName;

typedef enum {
OSC32KCLK = 0
} RTCName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,45 @@

#include "PeripheralPins.h"

/************GPIO***************/
const PinMap PinMap_GPIO[] = {
{PTA0, GPIO_X, 1},
{PTA1, GPIO_X, 1},
{PTA2, GPIO_X, 1},
{PTA16, GPIO_X, 1},
{PTA17, GPIO_X, 1},
{PTA18, GPIO_X, 1},
{PTA19, GPIO_X, 1},

{PTB0, GPIO_X, 1},
{PTB1, GPIO_X, 1},
{PTB2, GPIO_X, 1},
{PTB3, GPIO_X, 1},
{PTB16, GPIO_X, 1},
{PTB17, GPIO_X, 1},
{PTB18, GPIO_X, 1},

// {PTC0, GPIO_X, 1}, // PTC0 is not available on the 48-pin Laminate QFN package.
{PTC1, GPIO_X, 1},
{PTC2, GPIO_X, 1},
{PTC3, GPIO_X, 1},
{PTC4, GPIO_X, 1},
{PTC5, GPIO_X, 1},
{PTC6, GPIO_X, 1},
{PTC7, GPIO_X, 1},
{PTC16, GPIO_X, 1},
{PTC17, GPIO_X, 1},
{PTC18, GPIO_X, 1},
{PTC19, GPIO_X, 1},

{NC , NC , 0}
};

const PinMap *gpio_pinmap()
{
return PinMap_GPIO;
}

/************RTC***************/
const PinMap PinMap_RTC[] = {
{NC, OSC32KCLK, 0},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
extern "C" {
#endif

typedef enum {
GPIO_X = 0, // dummy peripheral used instead of GPIO_A..GPIO_E
} GPIOName;

typedef enum {
OSC32KCLK = 0,
} RTCName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,123 @@

#include "PeripheralPins.h"

/************GPIO***************/
const PinMap PinMap_GPIO[] = {
{PTA0, GPIO_X, 1},
{PTA1, GPIO_X, 1},
{PTA2, GPIO_X, 1},
{PTA3, GPIO_X, 1},
{PTA4, GPIO_X, 1},
{PTA5, GPIO_X, 1},
{PTA6, GPIO_X, 1},
{PTA7, GPIO_X, 1},
{PTA8, GPIO_X, 1},
{PTA9, GPIO_X, 1},
{PTA10, GPIO_X, 1},
{PTA11, GPIO_X, 1},
{PTA12, GPIO_X, 1},
{PTA13, GPIO_X, 1},
{PTA14, GPIO_X, 1},
{PTA15, GPIO_X, 1},
{PTA16, GPIO_X, 1},
{PTA17, GPIO_X, 1},
{PTA18, GPIO_X, 1},
{PTA19, GPIO_X, 1},
{PTA24, GPIO_X, 1},
{PTA25, GPIO_X, 1},
{PTA26, GPIO_X, 1},
{PTA27, GPIO_X, 1},
{PTA28, GPIO_X, 1},
{PTA29, GPIO_X, 1},

{PTB0, GPIO_X, 1},
{PTB1, GPIO_X, 1},
{PTB2, GPIO_X, 1},
{PTB3, GPIO_X, 1},
{PTB4, GPIO_X, 1},
{PTB5, GPIO_X, 1},
{PTB6, GPIO_X, 1},
{PTB7, GPIO_X, 1},
{PTB8, GPIO_X, 1},
{PTB9, GPIO_X, 1},
{PTB10, GPIO_X, 1},
{PTB11, GPIO_X, 1},
{PTB12, GPIO_X, 1},
{PTB13, GPIO_X, 1},
{PTB16, GPIO_X, 1},
{PTB17, GPIO_X, 1},
{PTB18, GPIO_X, 1},
{PTB19, GPIO_X, 1},
{PTB20, GPIO_X, 1},
{PTB21, GPIO_X, 1},
{PTB22, GPIO_X, 1},
{PTB23, GPIO_X, 1},

{PTC0, GPIO_X, 1},
{PTC1, GPIO_X, 1},
{PTC2, GPIO_X, 1},
{PTC3, GPIO_X, 1},
{PTC4, GPIO_X, 1},
{PTC5, GPIO_X, 1},
{PTC6, GPIO_X, 1},
{PTC7, GPIO_X, 1},
{PTC8, GPIO_X, 1},
{PTC9, GPIO_X, 1},
{PTC10, GPIO_X, 1},
{PTC11, GPIO_X, 1},
{PTC12, GPIO_X, 1},
{PTC13, GPIO_X, 1},
{PTC14, GPIO_X, 1},
{PTC15, GPIO_X, 1},
{PTC16, GPIO_X, 1},
{PTC17, GPIO_X, 1},
{PTC18, GPIO_X, 1},
{PTC19, GPIO_X, 1},

{PTD0, GPIO_X, 1},
{PTD1, GPIO_X, 1},
{PTD2, GPIO_X, 1},
{PTD3, GPIO_X, 1},
{PTD4, GPIO_X, 1},
{PTD5, GPIO_X, 1},
{PTD6, GPIO_X, 1},
{PTD7, GPIO_X, 1},
{PTD8, GPIO_X, 1},
{PTD9, GPIO_X, 1},
{PTD10, GPIO_X, 1},
{PTD11, GPIO_X, 1},
{PTD12, GPIO_X, 1},
{PTD13, GPIO_X, 1},
{PTD14, GPIO_X, 1},
{PTD15, GPIO_X, 1},

{PTE0, GPIO_X, 1},
{PTE1, GPIO_X, 1},
{PTE2, GPIO_X, 1},
{PTE3, GPIO_X, 1},
{PTE4, GPIO_X, 1},
{PTE5, GPIO_X, 1},
{PTE6, GPIO_X, 1},
{PTE7, GPIO_X, 1},
{PTE8, GPIO_X, 1},
{PTE9, GPIO_X, 1},
{PTE10, GPIO_X, 1},
{PTE11, GPIO_X, 1},
{PTE12, GPIO_X, 1},
// {PTE24, GPIO_X, 1}, // fixed pull-up (for I2C)
// {PTE25, GPIO_X, 1}, // fixed pull-up (for I2C)
{PTE26, GPIO_X, 1},
{PTE27, GPIO_X, 1},
{PTE28, GPIO_X, 1},

{NC , NC , 0}
};

const PinMap *gpio_pinmap()
{
return PinMap_GPIO;
}

/************RTC***************/
const PinMap PinMap_RTC[] = {
{NC, OSC32KCLK, 0},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
#include "pinmap.h"
#include "PeripheralNames.h"

/************GPIO***************/
extern const PinMap PinMap_GPIO[];

/************RTC***************/
extern const PinMap PinMap_RTC[];

Expand Down