mirror of https://github.com/ARMmbed/mbed-os.git
FPGAIO: Add MISC IO initialization support
parent
5d8570be39
commit
5be69f3143
|
@ -46,6 +46,16 @@ struct arm_mps2_io_reg_map_t {
|
||||||
* [31:2] : Reserved
|
* [31:2] : Reserved
|
||||||
* [1:0] : Buttons */
|
* [1:0] : Buttons */
|
||||||
} button_reg;
|
} 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,
|
void arm_mps2_io_write_leds(struct arm_mps2_io_dev_t* dev,
|
||||||
|
@ -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,
|
uint32_t arm_mps2_io_read_buttons(struct arm_mps2_io_dev_t* dev,
|
||||||
enum arm_mps2_io_access_t access,
|
enum arm_mps2_io_access_t access,
|
||||||
uint8_t pin_num)
|
uint8_t pin_num)
|
||||||
|
|
|
@ -65,6 +65,21 @@ void arm_mps2_io_write_leds(struct arm_mps2_io_dev_t* dev,
|
||||||
uint8_t pin_num,
|
uint8_t pin_num,
|
||||||
uint32_t value);
|
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.
|
* \brief Reads the buttons status.
|
||||||
*
|
*
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
#include "objects.h"
|
#include "objects.h"
|
||||||
#include "mbed_error.h"
|
#include "mbed_error.h"
|
||||||
|
|
||||||
|
#define RESERVED_MISC_PIN 7u
|
||||||
|
|
||||||
enum io_type {
|
enum io_type {
|
||||||
GPIO_DEVICE,
|
GPIO_DEVICE,
|
||||||
MPS2_IO_DEVICE,
|
MPS2_IO_DEVICE,
|
||||||
|
@ -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)
|
void gpio_init(gpio_t *obj, PinName pin)
|
||||||
{
|
{
|
||||||
struct arm_gpio_dev_t *gpio_dev;
|
struct arm_gpio_dev_t *gpio_dev;
|
||||||
|
@ -100,6 +134,7 @@ void gpio_init(gpio_t *obj, PinName pin)
|
||||||
|
|
||||||
obj->gpio_dev = gpio_dev;
|
obj->gpio_dev = gpio_dev;
|
||||||
obj->mps2_io_dev = NULL;
|
obj->mps2_io_dev = NULL;
|
||||||
|
obj->arm_mps2_io_write = NULL;
|
||||||
obj->pin_number = GPIO_PIN_NUMBER(pin);
|
obj->pin_number = GPIO_PIN_NUMBER(pin);
|
||||||
/* GPIO is input by default */
|
/* GPIO is input by default */
|
||||||
obj->direction = PIN_INPUT;
|
obj->direction = PIN_INPUT;
|
||||||
|
@ -112,16 +147,27 @@ void gpio_init(gpio_t *obj, PinName pin)
|
||||||
obj->gpio_dev = NULL;
|
obj->gpio_dev = NULL;
|
||||||
obj->mps2_io_dev = &ARM_MPS2_IO_FPGAIO_DEV;
|
obj->mps2_io_dev = &ARM_MPS2_IO_FPGAIO_DEV;
|
||||||
obj->pin_number = pin - USERLED1;
|
obj->pin_number = pin - USERLED1;
|
||||||
|
obj->arm_mps2_io_write = arm_mps2_io_write_leds;
|
||||||
obj->direction = PIN_OUTPUT;
|
obj->direction = PIN_OUTPUT;
|
||||||
return;
|
return;
|
||||||
} else if (pin == USERSW1 || pin == USERSW2) {
|
} else if (pin == USERSW1 || pin == USERSW2) {
|
||||||
/* User Push buttons */
|
/* User Push buttons */
|
||||||
obj->gpio_dev = NULL;
|
obj->gpio_dev = NULL;
|
||||||
obj->mps2_io_dev = &ARM_MPS2_IO_FPGAIO_DEV;
|
obj->mps2_io_dev = &ARM_MPS2_IO_FPGAIO_DEV;
|
||||||
|
obj->arm_mps2_io_write = NULL;
|
||||||
obj->pin_number = pin - USERSW1;
|
obj->pin_number = pin - USERSW1;
|
||||||
obj->direction = PIN_INPUT;
|
obj->direction = PIN_INPUT;
|
||||||
return;
|
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 */
|
#endif /* ARM_MPS2_IO_FPGAIO */
|
||||||
|
|
||||||
#ifdef ARM_MPS2_IO_SCC
|
#ifdef ARM_MPS2_IO_SCC
|
||||||
|
@ -129,6 +175,7 @@ void gpio_init(gpio_t *obj, PinName pin)
|
||||||
/* MCC LEDs */
|
/* MCC LEDs */
|
||||||
obj->gpio_dev = NULL;
|
obj->gpio_dev = NULL;
|
||||||
obj->mps2_io_dev = &ARM_MPS2_IO_SCC_DEV;
|
obj->mps2_io_dev = &ARM_MPS2_IO_SCC_DEV;
|
||||||
|
obj->arm_mps2_io_write = NULL;
|
||||||
obj->pin_number = pin - LED1;
|
obj->pin_number = pin - LED1;
|
||||||
obj->direction = PIN_OUTPUT;
|
obj->direction = PIN_OUTPUT;
|
||||||
return;
|
return;
|
||||||
|
@ -136,6 +183,7 @@ void gpio_init(gpio_t *obj, PinName pin)
|
||||||
/* MCC Switches */
|
/* MCC Switches */
|
||||||
obj->gpio_dev = NULL;
|
obj->gpio_dev = NULL;
|
||||||
obj->mps2_io_dev = &ARM_MPS2_IO_SCC_DEV;
|
obj->mps2_io_dev = &ARM_MPS2_IO_SCC_DEV;
|
||||||
|
obj->arm_mps2_io_write = NULL;
|
||||||
obj->pin_number = pin - SW1;
|
obj->pin_number = pin - SW1;
|
||||||
obj->direction = PIN_INPUT;
|
obj->direction = PIN_INPUT;
|
||||||
return;
|
return;
|
||||||
|
@ -208,8 +256,10 @@ void gpio_write(gpio_t *obj, int value)
|
||||||
*/
|
*/
|
||||||
return;
|
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);
|
obj->pin_number, (uint32_t)value);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
case DEVICE_UNKNOWN:
|
case DEVICE_UNKNOWN:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -30,6 +30,10 @@ extern "C" {
|
||||||
typedef struct gpio_s {
|
typedef struct gpio_s {
|
||||||
struct arm_gpio_dev_t *gpio_dev;
|
struct arm_gpio_dev_t *gpio_dev;
|
||||||
struct arm_mps2_io_dev_t *mps2_io_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;
|
uint32_t pin_number;
|
||||||
PinDirection direction;
|
PinDirection direction;
|
||||||
} gpio_t;
|
} gpio_t;
|
||||||
|
|
Loading…
Reference in New Issue