Re: [PATCH] Proposal for new GPIO API and example implementation for STM32F4 BSP

2022-06-25 Thread Karel Gardas



Hello Duc,

one reminder, your API should be more or less portable. That means the 
example which you produce as a testing example should be API-wise 
portable between various BSPs. Is that clear?


I know, I know, sometimes user led 1 on F4 is on different port/pin on 
F7 and then on H7 you get it on even different port/pin, but!


> stm32f4_gpio_get_ctrl(GPIOD, );

do you expect this to be called from app running on RPi4 for example? Or 
on beagle bone white? Or on stm32h757i-eval board?


Please generalize and make that bit portable too.

Thanks,
Karel

On 6/25/22 15:00, Duc Doan wrote:

Hello Christian,

I forgot to send the sample code. Here it a code to turn on an LED:

/*/

// Obtain the pointer to the instance (port D)
rtems_gpio_ctrl_t *ctrl;
stm32f4_gpio_get_ctrl(GPIOD, );

// enable clocks for port D
rtems_gpio_initialize(ctrl);

// configure the pin
rtems_gpio_set_pin_mode(ctrl, _PIN, RTEMS_GPIO_PINMODE_OUTPUT_PP);
rtems_gpio_set_pull(ctrl, _PIN, RTEMS_GPIO_PULLUP);

// output to LED
rtems_gpio_write(ctrl, _PIN, RTEMS_GPIO_PIN_SET);

/*/

Best,

Duc Doan
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH] Proposal for new GPIO API and example implementation for STM32F4 BSP

2022-06-25 Thread Duc Doan
Hello Christian,

I forgot to send the sample code. Here it a code to turn on an LED:

/*/

// Obtain the pointer to the instance (port D)
rtems_gpio_ctrl_t *ctrl;
stm32f4_gpio_get_ctrl(GPIOD, );

// enable clocks for port D
rtems_gpio_initialize(ctrl);

// configure the pin
rtems_gpio_set_pin_mode(ctrl, _PIN, RTEMS_GPIO_PINMODE_OUTPUT_PP);
rtems_gpio_set_pull(ctrl, _PIN, RTEMS_GPIO_PULLUP);

// output to LED
rtems_gpio_write(ctrl, _PIN, RTEMS_GPIO_PIN_SET);

/*/

Best,

Duc Doan
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH] Proposal for new GPIO API and example implementation for STM32F4 BSP

2022-06-25 Thread Duc Doan
Hello Christian,

On Fri, 2022-06-24 at 17:32 +0200, o...@c-mauderer.de wrote:
> Be careful with everything that depends on the BSP. Again: Please
> think 
> about an i2c GPIO expander. That chip can be used on different BSPs.
> It 
> can be even an independent driver that can be used by a user on
> demand 
> on any BSP that supports i2c.

I ended up using a void* so that users can pass anything into it and
the driver/BSP will cast and parse it. Is that a good solution?

Also, here is my updated API:

File: gpio2.h  /* API header **/

typedef struct rtems_gpio_handlers rtems_gpio_handlers_t;
typedef struct rtems_gpio_ctrl rtems_gpio_ctrl_t;
typedef struct rtems_gpio_config rtems_gpio_config_t;
typedef struct rtems_gpio_interrupt_config
rtems_gpio_interrupt_config_t;

struct rtems_gpio_handlers {
rtems_status_code (*initialize)(rtems_gpio_ctrl_t *);

rtems_status_code (*deinitialize)(rtems_gpio_ctrl_t *);

rtems_status_code (*configure)(rtems_gpio_ctrl_t *, void *,
rtems_gpio_config_t *);

rtems_status_code (*configure_interrupt)(rtems_gpio_ctrl_t *, void
*, rtems_gpio_interrupt_config_t *);

rtems_status_code (*enable_interrupt)(rtems_gpio_ctrl_t *, void *,
rtems_gpio_interrupt_config_t *);

rtems_status_code (*disable_interrupt)(rtems_gpio_ctrl_t *, void *,
rtems_gpio_interrupt_config_t *);

rtems_status_code (*set_pin_mode)(rtems_gpio_ctrl_t *, void *,
rtems_gpio_pin_mode);

rtems_status_code (*set_pull)(rtems_gpio_ctrl_t *, void *,
rtems_gpio_pull);

rtems_status_code (*read)(rtems_gpio_ctrl_t *, void *,
rtems_gpio_pin_state *);

rtems_status_code (*write)(rtems_gpio_ctrl_t *, void *,
rtems_gpio_pin_state);

rtems_status_code (*toggle)(rtems_gpio_ctrl_t *, void *);

};

struct rtems_gpio_ctrl {
const rtems_gpio_handlers_t *handlers;
};

struct rtems_gpio_config {
rtems_gpio_pin_mode mode;   /* Pin mode */
rtems_gpio_pull pull;   /* Pull resistor configuration */
};

struct rtems_gpio_interrupt_config {
rtems_gpio_interrupt interrupt_mode;/* Interrupt trigger
mode */
uint32_t interrupt_number;  /* Interrupt number */
uint32_t priority;  /* Interrupt priority
*/
void *bsp;  /* Pointer to BSP-
specific config */
void (*handler) (void *arg);/* Pointer to the IRQ
handler */
void *arg;  /* Pointer to the
arguments of IRQ handler */
};

extern void rtems_gpio_register(
rtems_gpio_ctrl_t *base,
const rtems_gpio_handlers_t *handlers
);

extern rtems_status_code rtems_gpio_initialize(
rtems_gpio_ctrl_t *base
);

extern rtems_status_code rtems_gpio_deinitialize(
rtems_gpio_ctrl_t *base
);

extern rtems_status_code rtems_gpio_configure(
rtems_gpio_ctrl_t *base, 
void *pin, 
rtems_gpio_config_t *config
);

extern rtems_status_code rtems_gpio_set_pin_mode(
rtems_gpio_ctrl_t *base, 
void *pin, 
rtems_gpio_pin_mode mode
);

extern rtems_status_code rtems_gpio_set_pull(
rtems_gpio_ctrl_t *base, 
void *pin, 
rtems_gpio_pull pull
);

extern rtems_status_code rtems_gpio_configure_interrupt(
rtems_gpio_ctrl_t *base, 
void *pin, 
rtems_gpio_interrupt_config_t *int_conf
);

extern rtems_status_code rtems_gpio_enable_interrupt(
rtems_gpio_ctrl_t *base,
void *pin,
rtems_gpio_interrupt_config_t *int_conf
);

extern rtems_status_code rtems_gpio_disable_interrupt(
rtems_gpio_ctrl_t *base,
void *pin,
rtems_gpio_interrupt_config_t *int_conf
);

extern rtems_status_code rtems_gpio_write(
rtems_gpio_ctrl_t *base, 
void *pin, 
rtems_gpio_pin_state value
);

extern rtems_status_code rtems_gpio_read(
rtems_gpio_ctrl_t *base, 
void *pin, 
rtems_gpio_pin_state *value
);

extern rtems_status_code rtems_gpio_ctrl_toggle(
rtems_gpio_ctrl_t *base, 
void *pin
);
//

File: gpio.c (API source)

#include 

void rtems_gpio_register(
rtems_gpio_ctrl_t *base, 
const rtems_gpio_handlers_t *handlers
) 
{
base->handlers = handlers;
}

rtems_status_code rtems_gpio_initialize(
rtems_gpio_ctrl_t *base
)
{
return base->handlers->initialize(base);
}

rtems_status_code rtems_gpio_deinitialize(
rtems_gpio_ctrl_t *base
)
{
return base->handlers->deinitialize(base);
}

rtems_status_code rtems_gpio_configure(
rtems_gpio_ctrl_t *base, 
void *pin,
rtems_gpio_config_t *config
) 
{
return base->handlers->configure(base, pin, config);
}

rtems_status_code rtems_gpio_set_pin_mode(
rtems_gpio_ctrl_t *base, 
void *pin,
rtems_gpio_pin_mode mode
) 
{
return base->handlers->set_pin_mode(base, pin, mode);
}

rtems_status_code rtems_gpio_set_pull(
rtems_gpio_ctrl_t *base, 
void *pin,
rtems_gpio_pull pull
) 
{
return base->handlers->set_pull(base, pin, pull);
}

rtems_status_code rtems_gpio_configure_interrupt(