Skip to content

FPGAIO: Add MISC IO initialization support #7039

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 1 commit into from
May 31, 2018
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ struct arm_mps2_io_reg_map_t {
* [31:2] : Reserved
* [1:0] : Buttons */
} button_reg;
volatile uint32_t reserved1[16];
volatile uint32_t misc; /* Offset: 0x04C (R/W) Misc control
* [31:7] : Reserved
* [6] : CLCD_BL_CTRL
* [5] : CLCD_RD
* [4] : CLCD_RS
* [3] : CLCD_RESET
* [2] : Reserved
* [1] : SPI_nSS
* [0] : CLCD_CS */
};

void arm_mps2_io_write_leds(struct arm_mps2_io_dev_t* dev,
Expand Down Expand Up @@ -113,6 +123,25 @@ void arm_mps2_io_write_leds(struct arm_mps2_io_dev_t* dev,
}
}

void arm_mps2_io_write_misc(struct arm_mps2_io_dev_t* dev,
enum arm_mps2_io_access_t access,
uint8_t pin_num,
uint32_t value)
{
struct arm_mps2_io_reg_map_t* p_mps2_io_port =
(struct arm_mps2_io_reg_map_t*)dev->cfg->base;

/* The MISC write is for FPGAIO only */
if (dev->cfg->type != ARM_MPS2_IO_TYPE_FPGAIO)
return;

if (value) {
p_mps2_io_port->misc |= (1UL << pin_num);
} else {
p_mps2_io_port->misc &= ~(1UL << pin_num);
}
}

uint32_t arm_mps2_io_read_buttons(struct arm_mps2_io_dev_t* dev,
enum arm_mps2_io_access_t access,
uint8_t pin_num)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ void arm_mps2_io_write_leds(struct arm_mps2_io_dev_t* dev,
uint8_t pin_num,
uint32_t value);

/**
* \brief Writes corresponding pin in FPGA IO MISC register.
*
* \param[in] dev MPS2 IO device where to write \ref arm_mps2_io_dev_t
* \param[in] pin_num Pin number.
* \param[in] value Value to set.
*
* \note This function doesn't check if dev is NULL.
* \note This function doesn't support port access.
*/
void arm_mps2_io_write_misc(struct arm_mps2_io_dev_t* dev,
enum arm_mps2_io_access_t access,
uint8_t pin_num,
uint32_t value);

/**
* \brief Reads the buttons status.
*
Expand Down
52 changes: 51 additions & 1 deletion targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/gpio_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "objects.h"
#include "mbed_error.h"

#define RESERVED_MISC_PIN 7u

enum io_type {
GPIO_DEVICE,
MPS2_IO_DEVICE,
Expand Down Expand Up @@ -63,6 +65,38 @@ uint32_t gpio_set(PinName pin)
}
}

/*
* FPGA MISC bit mapping:
* [31:7] Reserved
* [6] CLCD_BL_CTRL
* [5] CLCD_RD
* [4] CLCD_RS
* [3] CLCD_RESET
* [2] Reserved
* [1] SPI_nSS
* [0] CLCD_CS
*/
static uint32_t gpio_fpga_misc_pin(PinName pin)
{
uint32_t pin_number = RESERVED_MISC_PIN;

if (pin == CLCD_SSEL) {
pin_number = 0u;
} else if (pin == SPI_SSEL) {
pin_number = 1u;
} else if (pin == CLCD_RESET) {
pin_number = 3u;
} else if (pin == CLCD_RS) {
pin_number = 4u;
} else if (pin == CLCD_RD) {
pin_number = 5u;
} else if (pin == CLCD_BL_CTRL){
pin_number = 6u;
}

return pin_number;
}

void gpio_init(gpio_t *obj, PinName pin)
{
struct arm_gpio_dev_t *gpio_dev;
Expand Down Expand Up @@ -100,6 +134,7 @@ void gpio_init(gpio_t *obj, PinName pin)

obj->gpio_dev = gpio_dev;
obj->mps2_io_dev = NULL;
obj->arm_mps2_io_write = NULL;
obj->pin_number = GPIO_PIN_NUMBER(pin);
/* GPIO is input by default */
obj->direction = PIN_INPUT;
Expand All @@ -112,30 +147,43 @@ void gpio_init(gpio_t *obj, PinName pin)
obj->gpio_dev = NULL;
obj->mps2_io_dev = &ARM_MPS2_IO_FPGAIO_DEV;
obj->pin_number = pin - USERLED1;
obj->arm_mps2_io_write = arm_mps2_io_write_leds;
obj->direction = PIN_OUTPUT;
return;
} else if (pin == USERSW1 || pin == USERSW2) {
/* User Push buttons */
obj->gpio_dev = NULL;
obj->mps2_io_dev = &ARM_MPS2_IO_FPGAIO_DEV;
obj->arm_mps2_io_write = NULL;
obj->pin_number = pin - USERSW1;
obj->direction = PIN_INPUT;
return;
}
/* Check if pin is a MISC pin */
obj->pin_number = gpio_fpga_misc_pin(pin);
if (obj->pin_number != RESERVED_MISC_PIN) {
obj->gpio_dev = NULL;
obj->mps2_io_dev = &ARM_MPS2_IO_FPGAIO_DEV;
obj->arm_mps2_io_write = arm_mps2_io_write_misc;
obj->direction = PIN_OUTPUT;
return;
}
#endif /* ARM_MPS2_IO_FPGAIO */

#ifdef ARM_MPS2_IO_SCC
if (pin >= LED1 && pin <= LED8) {
/* MCC LEDs */
obj->gpio_dev = NULL;
obj->mps2_io_dev = &ARM_MPS2_IO_SCC_DEV;
obj->arm_mps2_io_write = NULL;
obj->pin_number = pin - LED1;
obj->direction = PIN_OUTPUT;
return;
} else if (pin >= SW1 && pin <= SW8) {
/* MCC Switches */
obj->gpio_dev = NULL;
obj->mps2_io_dev = &ARM_MPS2_IO_SCC_DEV;
obj->arm_mps2_io_write = NULL;
obj->pin_number = pin - SW1;
obj->direction = PIN_INPUT;
return;
Expand Down Expand Up @@ -208,8 +256,10 @@ void gpio_write(gpio_t *obj, int value)
*/
return;
}
arm_mps2_io_write_leds(obj->mps2_io_dev, ARM_MPS2_IO_ACCESS_PIN,
if (obj->arm_mps2_io_write != NULL) {
obj->arm_mps2_io_write(obj->mps2_io_dev, ARM_MPS2_IO_ACCESS_PIN,
obj->pin_number, (uint32_t)value);
}
return;
case DEVICE_UNKNOWN:
break;
Expand Down
4 changes: 4 additions & 0 deletions targets/TARGET_ARM_SSG/TARGET_CM3DS_MPS2/objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ extern "C" {
typedef struct gpio_s {
struct arm_gpio_dev_t *gpio_dev;
struct arm_mps2_io_dev_t *mps2_io_dev;
void (*arm_mps2_io_write)(struct arm_mps2_io_dev_t* dev,
enum arm_mps2_io_access_t access,
uint8_t pin_num,
uint32_t value);
uint32_t pin_number;
PinDirection direction;
} gpio_t;
Expand Down