Use the GPIO HAL (Zoul)
This commit is contained in:
parent
095a89d937
commit
749c4e5cd8
@ -43,6 +43,7 @@
|
|||||||
#include "dev/nvic.h"
|
#include "dev/nvic.h"
|
||||||
#include "dev/ioc.h"
|
#include "dev/ioc.h"
|
||||||
#include "dev/gpio.h"
|
#include "dev/gpio.h"
|
||||||
|
#include "dev/gpio-hal.h"
|
||||||
#include "dev/button-sensor.h"
|
#include "dev/button-sensor.h"
|
||||||
#include "sys/timer.h"
|
#include "sys/timer.h"
|
||||||
#include "sys/ctimer.h"
|
#include "sys/ctimer.h"
|
||||||
@ -94,15 +95,8 @@ value(int type)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
/**
|
|
||||||
* \brief Callback registered with the GPIO module. Gets fired with a button
|
|
||||||
* port/pin generates an interrupt
|
|
||||||
* \param port The port number that generated the interrupt
|
|
||||||
* \param pin The pin number that generated the interrupt. This is the pin
|
|
||||||
* absolute number (i.e. 0, 1, ..., 7), not a mask
|
|
||||||
*/
|
|
||||||
static void
|
static void
|
||||||
btn_callback(uint8_t port, uint8_t pin)
|
button_press_handler(gpio_hal_pin_mask_t pin_mask)
|
||||||
{
|
{
|
||||||
if(!timer_expired(&debouncetimer)) {
|
if(!timer_expired(&debouncetimer)) {
|
||||||
return;
|
return;
|
||||||
@ -123,6 +117,12 @@ btn_callback(uint8_t port, uint8_t pin)
|
|||||||
sensors_changed(&button_sensor);
|
sensors_changed(&button_sensor);
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static gpio_hal_event_handler_t press_handler = {
|
||||||
|
.next = NULL,
|
||||||
|
.handler = button_press_handler,
|
||||||
|
.pin_mask = gpio_hal_pin_to_mask(BUTTON_USER_PIN) << (BUTTON_USER_PORT << 3),
|
||||||
|
};
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
/**
|
/**
|
||||||
* \brief Init function for the User button.
|
* \brief Init function for the User button.
|
||||||
* \param type SENSORS_ACTIVE: Activate / Deactivate the sensor (value == 1
|
* \param type SENSORS_ACTIVE: Activate / Deactivate the sensor (value == 1
|
||||||
@ -152,7 +152,7 @@ config_user(int type, int value)
|
|||||||
|
|
||||||
ioc_set_over(BUTTON_USER_PORT, BUTTON_USER_PIN, IOC_OVERRIDE_PUE);
|
ioc_set_over(BUTTON_USER_PORT, BUTTON_USER_PIN, IOC_OVERRIDE_PUE);
|
||||||
|
|
||||||
gpio_register_callback(btn_callback, BUTTON_USER_PORT, BUTTON_USER_PIN);
|
gpio_hal_register_handler(&press_handler);
|
||||||
break;
|
break;
|
||||||
case SENSORS_ACTIVE:
|
case SENSORS_ACTIVE:
|
||||||
if(value) {
|
if(value) {
|
||||||
|
@ -52,6 +52,7 @@
|
|||||||
#include "dev/spi.h"
|
#include "dev/spi.h"
|
||||||
#include "dev/ssi.h"
|
#include "dev/ssi.h"
|
||||||
#include "dev/gpio.h"
|
#include "dev/gpio.h"
|
||||||
|
#include "dev/gpio-hal.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
#define CC1200_SPI_CLK_PORT_BASE GPIO_PORT_TO_BASE(SPI0_CLK_PORT)
|
#define CC1200_SPI_CLK_PORT_BASE GPIO_PORT_TO_BASE(SPI0_CLK_PORT)
|
||||||
@ -92,7 +93,7 @@
|
|||||||
extern int cc1200_rx_interrupt(void);
|
extern int cc1200_rx_interrupt(void);
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
cc1200_int_handler(uint8_t port, uint8_t pin)
|
cc1200_int_handler(gpio_hal_pin_mask_t pin_mask)
|
||||||
{
|
{
|
||||||
/* To keep the gpio_register_callback happy */
|
/* To keep the gpio_register_callback happy */
|
||||||
cc1200_rx_interrupt();
|
cc1200_rx_interrupt();
|
||||||
@ -166,6 +167,14 @@ cc1200_arch_spi_rw(uint8_t *inbuf, const uint8_t *write_buf, uint16_t len)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static gpio_hal_event_handler_t interrupt_handler = {
|
||||||
|
.next = NULL,
|
||||||
|
.handler = cc1200_int_handler,
|
||||||
|
.pin_mask =
|
||||||
|
(gpio_hal_pin_to_mask(CC1200_GDO0_PIN) << (CC1200_GDO0_PORT << 3)) |
|
||||||
|
(gpio_hal_pin_to_mask(CC1200_GDO2_PIN) << (CC1200_GDO2_PORT << 3))
|
||||||
|
};
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
cc1200_arch_gpio0_setup_irq(int rising)
|
cc1200_arch_gpio0_setup_irq(int rising)
|
||||||
{
|
{
|
||||||
@ -184,8 +193,7 @@ cc1200_arch_gpio0_setup_irq(int rising)
|
|||||||
GPIO_ENABLE_INTERRUPT(CC1200_GDO0_PORT_BASE, CC1200_GDO0_PIN_MASK);
|
GPIO_ENABLE_INTERRUPT(CC1200_GDO0_PORT_BASE, CC1200_GDO0_PIN_MASK);
|
||||||
ioc_set_over(CC1200_GDO0_PORT, CC1200_GDO0_PIN, IOC_OVERRIDE_PUE);
|
ioc_set_over(CC1200_GDO0_PORT, CC1200_GDO0_PIN, IOC_OVERRIDE_PUE);
|
||||||
NVIC_EnableIRQ(CC1200_GPIOx_VECTOR);
|
NVIC_EnableIRQ(CC1200_GPIOx_VECTOR);
|
||||||
gpio_register_callback(cc1200_int_handler, CC1200_GDO0_PORT,
|
gpio_hal_register_handler(&interrupt_handler);
|
||||||
CC1200_GDO0_PIN);
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
@ -206,8 +214,7 @@ cc1200_arch_gpio2_setup_irq(int rising)
|
|||||||
GPIO_ENABLE_INTERRUPT(CC1200_GDO2_PORT_BASE, CC1200_GDO2_PIN_MASK);
|
GPIO_ENABLE_INTERRUPT(CC1200_GDO2_PORT_BASE, CC1200_GDO2_PIN_MASK);
|
||||||
ioc_set_over(CC1200_GDO2_PORT, CC1200_GDO2_PIN, IOC_OVERRIDE_PUE);
|
ioc_set_over(CC1200_GDO2_PORT, CC1200_GDO2_PIN, IOC_OVERRIDE_PUE);
|
||||||
NVIC_EnableIRQ(CC1200_GPIOx_VECTOR);
|
NVIC_EnableIRQ(CC1200_GPIOx_VECTOR);
|
||||||
gpio_register_callback(cc1200_int_handler, CC1200_GDO2_PORT,
|
gpio_hal_register_handler(&interrupt_handler);
|
||||||
CC1200_GDO2_PIN);
|
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
void
|
void
|
||||||
|
@ -735,7 +735,7 @@ rtcc_print(uint8_t value)
|
|||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
static void
|
static void
|
||||||
rtcc_interrupt_handler(uint8_t port, uint8_t pin)
|
rtcc_interrupt_handler(gpio_hal_pin_mask_t pin_mask)
|
||||||
{
|
{
|
||||||
process_poll(&rtcc_int_process);
|
process_poll(&rtcc_int_process);
|
||||||
}
|
}
|
||||||
@ -912,6 +912,12 @@ rtcc_set_calibration(uint8_t mode, int32_t adjust)
|
|||||||
return AB08_SUCCESS;
|
return AB08_SUCCESS;
|
||||||
}
|
}
|
||||||
/*---------------------------------------------------------------------------*/
|
/*---------------------------------------------------------------------------*/
|
||||||
|
static gpio_hal_event_handler_t rtcc_handler = {
|
||||||
|
.next = NULL,
|
||||||
|
.handler = rtcc_interrupt_handler,
|
||||||
|
.pin_mask = gpio_hal_pin_to_mask(RTC_INT1_PIN) << (RTC_INT1_PORT << 3),
|
||||||
|
};
|
||||||
|
/*---------------------------------------------------------------------------*/
|
||||||
int8_t
|
int8_t
|
||||||
rtcc_init(void)
|
rtcc_init(void)
|
||||||
{
|
{
|
||||||
@ -937,7 +943,7 @@ rtcc_init(void)
|
|||||||
GPIO_DETECT_EDGE(RTC_INT1_PORT_BASE, RTC_INT1_PIN_MASK);
|
GPIO_DETECT_EDGE(RTC_INT1_PORT_BASE, RTC_INT1_PIN_MASK);
|
||||||
GPIO_TRIGGER_SINGLE_EDGE(RTC_INT1_PORT_BASE, RTC_INT1_PIN_MASK);
|
GPIO_TRIGGER_SINGLE_EDGE(RTC_INT1_PORT_BASE, RTC_INT1_PIN_MASK);
|
||||||
GPIO_DETECT_FALLING(RTC_INT1_PORT_BASE, RTC_INT1_PIN_MASK);
|
GPIO_DETECT_FALLING(RTC_INT1_PORT_BASE, RTC_INT1_PIN_MASK);
|
||||||
gpio_register_callback(rtcc_interrupt_handler, RTC_INT1_PORT, RTC_INT1_PIN);
|
gpio_hal_register_handler(&rtcc_handler);
|
||||||
|
|
||||||
/* Spin process until an interrupt is received */
|
/* Spin process until an interrupt is received */
|
||||||
process_start(&rtcc_int_process, NULL);
|
process_start(&rtcc_int_process, NULL);
|
||||||
|
Loading…
Reference in New Issue
Block a user