Skip to content

Commit

Permalink
Merge pull request #4 from Rbb666/main
Browse files Browse the repository at this point in the history
修复pin-irq问题,spi初始化问题
  • Loading branch information
Guozhanxin authored May 25, 2023
2 parents a4cdaaf + 001e71c commit 8e50180
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 24 deletions.
17 changes: 11 additions & 6 deletions project_0/libraries/HAL_Drivers/drv_gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2022-07-1 Rbb666 first version
* 2023-05-25 Rbb666 fix pin irq problem
*/

#include "drv_gpio.h"
Expand All @@ -19,6 +20,8 @@

#define PIN_IFXPORT_MAX __IFX_PORT_MAX

static cyhal_gpio_callback_data_t irq_cb_data[PIN_IFXPORT_MAX];

static const struct pin_irq_map pin_irq_map[] =
{
{CYHAL_PORT_0, ioss_interrupts_gpio_0_IRQn},
Expand Down Expand Up @@ -66,6 +69,8 @@ static struct rt_pin_irq_hdr pin_irq_handler_tab[] =

rt_inline void pin_irq_handler(int irqno)
{
Cy_GPIO_ClearInterrupt(CYHAL_GET_PORTADDR(irqno), CYHAL_GET_PIN(irqno));

if (pin_irq_handler_tab[irqno].hdr)
{
pin_irq_handler_tab[irqno].hdr(pin_irq_handler_tab[irqno].args);
Expand Down Expand Up @@ -93,8 +98,6 @@ static void irq_callback(void *callback_arg, cyhal_gpio_event_t event)
rt_interrupt_leave();
}

cyhal_gpio_callback_data_t irq_cb_data;

static void ifx_pin_mode(rt_device_t dev, rt_base_t pin, rt_uint8_t mode)
{
rt_uint16_t gpio_pin;
Expand Down Expand Up @@ -247,7 +250,6 @@ static rt_err_t ifx_pin_irq_enable(struct rt_device *device, rt_base_t pin,
rt_uint16_t gpio_pin;
rt_base_t level;
rt_uint8_t pin_irq_mode;

const struct pin_irq_map *irqmap;

if (PORT_GET(pin) < PIN_IFXPORT_MAX)
Expand All @@ -272,10 +274,13 @@ static rt_err_t ifx_pin_irq_enable(struct rt_device *device, rt_base_t pin,

irqmap = &pin_irq_map[gpio_port];

irq_cb_data.callback = irq_callback;
irq_cb_data.callback_arg = (rt_uint16_t *)&pin_irq_map[gpio_port].port;
#if !defined(COMPONENT_CAT1C)
IRQn_Type irqn = (IRQn_Type)(irqmap->irqno + PORT_GET(irqmap->port));
#endif
irq_cb_data[irqn].callback = irq_callback;
irq_cb_data[irqn].callback_arg = (rt_uint16_t *)&pin_irq_map[gpio_port].port;

cyhal_gpio_register_callback(gpio_pin, &irq_cb_data);
cyhal_gpio_register_callback(gpio_pin, &irq_cb_data[irqn]);

Cy_GPIO_ClearInterrupt(CYHAL_GET_PORTADDR(gpio_pin), CYHAL_GET_PIN(gpio_pin));

Expand Down
41 changes: 23 additions & 18 deletions project_0/libraries/HAL_Drivers/drv_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,30 +93,35 @@ static void ifx_spi_init(struct ifx_spi *spi_device)

rt_err_t result = RT_EOK;

result = cyhal_spi_init(spi_device->spi_handle_t->spi_obj, spi_device->spi_handle_t->mosi_pin, spi_device->spi_handle_t->miso_pin,
spi_device->spi_handle_t->sck_pin, NC, NULL, spi_device->spi_handle_t->spi_obj->data_bits,
spi_device->spi_handle_t->spi_obj->mode, false);
static uint8_t init_flag = 1;

if (result != RT_EOK)
if (init_flag)
{
LOG_E("spi%s init fail", spi_device->spi_handle_t->bus_name);
return;
}
result = cyhal_spi_init(spi_device->spi_handle_t->spi_obj, spi_device->spi_handle_t->mosi_pin, spi_device->spi_handle_t->miso_pin,
spi_device->spi_handle_t->sck_pin, NC, NULL, spi_device->spi_handle_t->spi_obj->data_bits,
spi_device->spi_handle_t->spi_obj->mode, false);
if (result != RT_EOK)
{
LOG_E("spi%s init fail", spi_device->spi_handle_t->bus_name);
return;
}

LOG_I("[%s] freq:[%d]HZ\n", spi_device->spi_handle_t->bus_name, spi_device->spi_handle_t->freq);
result = cyhal_spi_set_frequency(spi_device->spi_handle_t->spi_obj, spi_device->spi_handle_t->freq);
if (result == CYHAL_SPI_RSLT_CLOCK_ERROR)
{
LOG_E("%s set frequency fail", spi_device->spi_handle_t->bus_name);
return;
}
LOG_I("[%s] freq:[%d]HZ\n", spi_device->spi_handle_t->bus_name, spi_device->spi_handle_t->freq);

result = cyhal_spi_set_frequency(spi_device->spi_handle_t->spi_obj, spi_device->spi_handle_t->freq);
if (result == CYHAL_SPI_RSLT_CLOCK_ERROR)
{
LOG_E("%s set frequency fail", spi_device->spi_handle_t->bus_name);
return;
}
/* Register a callback function to be called when the interrupt fires */
cyhal_spi_register_callback(spi_device->spi_handle_t->spi_obj, spi_interrupt_callback, spi_device);

/* Register a callback function to be called when the interrupt fires */
cyhal_spi_register_callback(spi_device->spi_handle_t->spi_obj, spi_interrupt_callback, spi_device);
/* Enable the events that will trigger the call back function */
cyhal_spi_enable_event(spi_device->spi_handle_t->spi_obj, CYHAL_SPI_IRQ_DONE, 4, true);
}

/* Enable the events that will trigger the call back function */
cyhal_spi_enable_event(spi_device->spi_handle_t->spi_obj, CYHAL_SPI_IRQ_DONE, 4, true);
init_flag = 0;
}

static rt_err_t spi_configure(struct rt_spi_device *device,
Expand Down

0 comments on commit 8e50180

Please sign in to comment.