mirror of
https://github.com/openshwprojects/OpenBK7231T_App.git
synced 2026-02-04 14:05:31 +00:00
cosmetic only - finally move hal interrupts to _pins files
* moive out * fixes * fs * f1 * fx * fx?
This commit is contained in:
@ -1,370 +1,9 @@
|
||||
// HLW8012 aka BL0937
|
||||
#include "drv_bl0937.h"
|
||||
#include "../obk_config.h"
|
||||
|
||||
|
||||
|
||||
#include "../hal/hal_pins.h"
|
||||
#include "../new_pins.h"
|
||||
|
||||
OBKInterruptHandler g_handlers[PLATFORM_GPIO_MAX];
|
||||
OBKInterruptType g_modes[PLATFORM_GPIO_MAX];
|
||||
|
||||
#if PLATFORM_BEKEN
|
||||
|
||||
#include "BkDriverTimer.h"
|
||||
#include "BkDriverGpio.h"
|
||||
#include "sys_timer.h"
|
||||
#include "gw_intf.h"
|
||||
|
||||
void Beken_Interrupt(unsigned char pinNum) {
|
||||
if (g_handlers[pinNum]) {
|
||||
g_handlers[pinNum](pinNum);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_AttachInterrupt(int pinIndex, OBKInterruptType mode, OBKInterruptHandler function) {
|
||||
g_handlers[pinIndex] = function;
|
||||
int bk_mode;
|
||||
if (mode == INTERRUPT_RISING) {
|
||||
bk_mode = IRQ_TRIGGER_RISING_EDGE;
|
||||
}
|
||||
else {
|
||||
bk_mode = IRQ_TRIGGER_FALLING_EDGE;
|
||||
}
|
||||
gpio_int_enable(pinIndex, bk_mode, Beken_Interrupt);
|
||||
}
|
||||
void HAL_DetachInterrupt(int pinIndex) {
|
||||
if (g_handlers[pinIndex] == 0) {
|
||||
return; // already removed;
|
||||
}
|
||||
gpio_int_disable(pinIndex);
|
||||
g_handlers[pinIndex] = 0;
|
||||
}
|
||||
|
||||
#elif PLATFORM_W600 || PLATFORM_W800
|
||||
|
||||
void W600_Interrupt(void* context) {
|
||||
int obkPinNum = (int)(intptr_t)context;
|
||||
int w600Pin = HAL_GetGPIOPin(obkPinNum);
|
||||
tls_clr_gpio_irq_status(w600Pin);
|
||||
if (g_handlers[obkPinNum]) {
|
||||
g_handlers[obkPinNum](obkPinNum);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_AttachInterrupt(int pinIndex, OBKInterruptType mode, OBKInterruptHandler function) {
|
||||
g_handlers[pinIndex] = function;
|
||||
int w600Pin = HAL_GetGPIOPin(pinIndex);
|
||||
tls_gpio_isr_register(w600Pin, W600_Interrupt, (void*)(intptr_t)pinIndex);
|
||||
int w_mode;
|
||||
if (mode == INTERRUPT_RISING) {
|
||||
w_mode = WM_GPIO_IRQ_TRIG_RISING_EDGE;
|
||||
}
|
||||
else {
|
||||
w_mode = WM_GPIO_IRQ_TRIG_FALLING_EDGE;
|
||||
}
|
||||
tls_gpio_irq_enable(w600Pin, w_mode);
|
||||
}
|
||||
void HAL_DetachInterrupt(int pinIndex) {
|
||||
if (g_handlers[pinIndex] == 0) {
|
||||
return; // already removed;
|
||||
}
|
||||
int w600Pin = HAL_GetGPIOPin(pinIndex);
|
||||
tls_gpio_irq_disable(w600Pin);
|
||||
g_handlers[pinIndex] = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#elif PLATFORM_BL602
|
||||
|
||||
#include "hal_gpio.h"
|
||||
#include "bl_gpio.h"
|
||||
|
||||
void BL602_Interrupt(void* context) {
|
||||
int obkPinNum = (int)context;
|
||||
if (g_handlers[obkPinNum]) {
|
||||
g_handlers[obkPinNum](obkPinNum);
|
||||
}
|
||||
bl_gpio_intmask(obkPinNum, 0);
|
||||
}
|
||||
|
||||
void HAL_AttachInterrupt(int pinIndex, OBKInterruptType mode, OBKInterruptHandler function) {
|
||||
g_handlers[pinIndex] = function;
|
||||
int bl_mode;
|
||||
if (mode == INTERRUPT_RISING) {
|
||||
bl_mode = GPIO_INT_TRIG_POS_PULSE;
|
||||
}
|
||||
else {
|
||||
bl_mode = GPIO_INT_TRIG_NEG_PULSE;
|
||||
}
|
||||
hal_gpio_register_handler(BL602_Interrupt, pinIndex,
|
||||
GPIO_INT_CONTROL_ASYNC, bl_mode, (void*)pinIndex);
|
||||
}
|
||||
void HAL_DetachInterrupt(int pinIndex) {
|
||||
if (g_handlers[pinIndex] == 0) {
|
||||
return; // already removed;
|
||||
}
|
||||
g_handlers[pinIndex] = 0;
|
||||
}
|
||||
|
||||
#elif PLATFORM_LN882H
|
||||
|
||||
#include "../../sdk/OpenLN882H/mcu/driver_ln882h/hal/hal_common.h"
|
||||
#include "../../sdk/OpenLN882H/mcu/driver_ln882h/hal/hal_gpio.h"
|
||||
|
||||
uint32_t GetBaseForPin(int pinIndex)
|
||||
{
|
||||
return pinIndex < 16 ? GPIOA_BASE : GPIOB_BASE;
|
||||
}
|
||||
|
||||
int GetIRQForPin(int pinIndex)
|
||||
{
|
||||
return pinIndex < 16 ? GPIOA_IRQn : GPIOB_IRQn;
|
||||
}
|
||||
|
||||
uint16_t GetGPIOForPin(int pinIndex)
|
||||
{
|
||||
return (uint16_t)1 << (uint16_t)(pinIndex % 16);
|
||||
}
|
||||
void Shared_Handler() {
|
||||
for (int i = 0; i < PLATFORM_GPIO_MAX; i++) {
|
||||
if (g_handlers[i]) {
|
||||
uint32_t base = GetBaseForPin(i);
|
||||
uint16_t gpio_pin = GetGPIOForPin(i);
|
||||
if (hal_gpio_pin_get_it_flag(base, gpio_pin) == HAL_SET) {
|
||||
hal_gpio_pin_clr_it_flag(base, gpio_pin);
|
||||
g_handlers[i](i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void GPIOA_IRQHandler()
|
||||
{
|
||||
Shared_Handler();
|
||||
}
|
||||
|
||||
void GPIOB_IRQHandler()
|
||||
{
|
||||
Shared_Handler();
|
||||
}
|
||||
|
||||
void HAL_AttachInterrupt(int pinIndex, OBKInterruptType mode, OBKInterruptHandler function) {
|
||||
g_handlers[pinIndex] = function;
|
||||
|
||||
int ln_mode;
|
||||
if (mode == INTERRUPT_RISING) {
|
||||
ln_mode = GPIO_INT_RISING;
|
||||
}
|
||||
else {
|
||||
ln_mode = GPIO_INT_FALLING;
|
||||
}
|
||||
hal_gpio_pin_it_cfg(GetBaseForPin(pinIndex), GetGPIOForPin(pinIndex), ln_mode);
|
||||
hal_gpio_pin_it_en(GetBaseForPin(pinIndex), GetGPIOForPin(pinIndex), HAL_ENABLE);
|
||||
NVIC_SetPriority(GetIRQForPin(pinIndex), 1);
|
||||
NVIC_EnableIRQ(GetIRQForPin(pinIndex));
|
||||
|
||||
}
|
||||
|
||||
void HAL_DetachInterrupt(int pinIndex) {
|
||||
if (g_handlers[pinIndex] == 0) {
|
||||
return; // already removed;
|
||||
}
|
||||
g_handlers[pinIndex] = 0;
|
||||
}
|
||||
|
||||
#elif PLATFORM_REALTEK
|
||||
|
||||
#include "gpio_irq_api.h"
|
||||
#include "../hal/realtek/hal_pinmap_realtek.h"
|
||||
|
||||
|
||||
void Realtek_Interrupt(uint32_t obkPinNum, gpio_irq_event event)
|
||||
{
|
||||
if (g_handlers[obkPinNum]) {
|
||||
g_handlers[obkPinNum](obkPinNum);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_AttachInterrupt(int pinIndex, OBKInterruptType mode, OBKInterruptHandler function) {
|
||||
g_handlers[pinIndex] = function;
|
||||
|
||||
rtlPinMapping_t *rtl_cf = g_pins + pinIndex;
|
||||
#if PLATFORM_RTL87X0C
|
||||
if (rtl_cf->gpio != NULL)
|
||||
{
|
||||
hal_pinmux_unregister(rtl_cf->pin, PID_GPIO);
|
||||
os_free(rtl_cf->gpio);
|
||||
rtl_cf->gpio = NULL;
|
||||
}
|
||||
#endif
|
||||
rtl_cf->irq = os_malloc(sizeof(gpio_irq_t));
|
||||
memset(rtl_cf->irq, 0, sizeof(gpio_irq_t));
|
||||
|
||||
int rtl_mode;
|
||||
if (mode == INTERRUPT_RISING) {
|
||||
rtl_mode = IRQ_RISE;
|
||||
}
|
||||
else {
|
||||
rtl_mode = IRQ_FALL;
|
||||
}
|
||||
gpio_irq_init(rtl_cf->irq, rtl_cf->pin, Realtek_Interrupt, pinIndex);
|
||||
gpio_irq_set(rtl_cf->irq, rtl_mode, 1);
|
||||
gpio_irq_enable(rtl_cf->irq);
|
||||
|
||||
}
|
||||
void HAL_DetachInterrupt(int pinIndex) {
|
||||
if (g_handlers[pinIndex] == 0) {
|
||||
return; // already removed;
|
||||
}
|
||||
rtlPinMapping_t *rtl_cf = g_pins + pinIndex;
|
||||
gpio_irq_free(rtl_cf->irq);
|
||||
os_free(rtl_cf->irq);
|
||||
rtl_cf->irq = NULL;
|
||||
g_handlers[pinIndex] = 0;
|
||||
}
|
||||
|
||||
|
||||
#elif PLATFORM_ECR6600
|
||||
|
||||
#include "gpio.h"
|
||||
|
||||
void ECR6600_Interrupt(unsigned char obkPinNum) {
|
||||
if (g_handlers[obkPinNum]) {
|
||||
g_handlers[obkPinNum](obkPinNum);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_AttachInterrupt(int pinIndex, OBKInterruptType mode, OBKInterruptHandler function) {
|
||||
g_handlers[pinIndex] = function;
|
||||
|
||||
T_GPIO_ISR_CALLBACK cf1isr;
|
||||
cf1isr.gpio_callback = (&ECR6600_Interrupt);
|
||||
cf1isr.gpio_data = pinIndex;
|
||||
|
||||
int ecr_mode;
|
||||
if (mode == INTERRUPT_RISING) {
|
||||
ecr_mode = DRV_GPIO_ARG_INTR_MODE_P_EDGE;
|
||||
}
|
||||
else {
|
||||
ecr_mode = DRV_GPIO_ARG_INTR_MODE_N_EDGE;
|
||||
}
|
||||
drv_gpio_ioctrl(pinIndex, DRV_GPIO_CTRL_INTR_MODE, ecr_mode);
|
||||
drv_gpio_ioctrl(pinIndex, DRV_GPIO_CTRL_REGISTER_ISR, (int)&cf1isr);
|
||||
drv_gpio_ioctrl(pinIndex, DRV_GPIO_CTRL_INTR_ENABLE, 0);
|
||||
|
||||
}
|
||||
void HAL_DetachInterrupt(int pinIndex) {
|
||||
if (g_handlers[pinIndex] == 0) {
|
||||
return; // already removed;
|
||||
}
|
||||
|
||||
drv_gpio_ioctrl(pinIndex, DRV_GPIO_CTRL_INTR_DISABLE, 0);
|
||||
g_handlers[pinIndex] = 0;
|
||||
}
|
||||
|
||||
|
||||
#elif PLATFORM_XRADIO
|
||||
|
||||
#include "../hal/xradio/hal_pinmap_xradio.h"
|
||||
extern void HAL_XR_ConfigurePin(GPIO_Port port, GPIO_Pin pin, GPIO_WorkMode mode, GPIO_PullType pull);
|
||||
|
||||
|
||||
void XRadio_Interrupt(void* context) {
|
||||
int obkPinNum = (int)context;
|
||||
if (g_handlers[obkPinNum]) {
|
||||
g_handlers[obkPinNum](obkPinNum);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_AttachInterrupt(int pinIndex, OBKInterruptType mode, OBKInterruptHandler function) {
|
||||
g_handlers[pinIndex] = function;
|
||||
|
||||
xrpin_t *xr_cf = g_pins + pinIndex;
|
||||
HAL_XR_ConfigurePin(xr_cf->port, xr_cf->pin, GPIOx_Pn_F6_EINT, GPIO_PULL_UP);
|
||||
GPIO_IrqParam cfparam;
|
||||
int xr_mode;
|
||||
if (mode == INTERRUPT_RISING) {
|
||||
xr_mode = GPIO_IRQ_EVT_RISING_EDGE;
|
||||
}
|
||||
else {
|
||||
xr_mode = GPIO_IRQ_EVT_FALLING_EDGE;
|
||||
}
|
||||
cfparam.event = xr_mode;
|
||||
cfparam.callback = XRadio_Interrupt;
|
||||
cfparam.arg = (void*)pinIndex;
|
||||
HAL_GPIO_EnableIRQ(xr_cf->port, xr_cf->pin, &cfparam);
|
||||
|
||||
}
|
||||
void HAL_DetachInterrupt(int pinIndex) {
|
||||
if (g_handlers[pinIndex] == 0) {
|
||||
return; // already removed;
|
||||
}
|
||||
xrpin_t* xr_cf;
|
||||
xr_cf = g_pins + pinIndex;
|
||||
HAL_GPIO_DeInit(xr_cf->port, xr_cf->pin);
|
||||
HAL_GPIO_DisableIRQ(xr_cf->port, xr_cf->pin);
|
||||
g_handlers[pinIndex] = 0;
|
||||
}
|
||||
|
||||
#elif PLATFORM_ESP8266 || PLATFORM_ESPIDF
|
||||
|
||||
#include "../hal/espidf/hal_pinmap_espidf.h"
|
||||
|
||||
|
||||
void ESP_Interrupt(void* context) {
|
||||
int obkPinNum = (int)context;
|
||||
if (g_handlers[obkPinNum]) {
|
||||
g_handlers[obkPinNum](obkPinNum);
|
||||
}
|
||||
}
|
||||
|
||||
bool b_esp_ready = false;
|
||||
void HAL_AttachInterrupt(int pinIndex, OBKInterruptType mode, OBKInterruptHandler function) {
|
||||
g_handlers[pinIndex] = function;
|
||||
|
||||
if (b_esp_ready == false) {
|
||||
gpio_install_isr_service(0);
|
||||
b_esp_ready = true;
|
||||
}
|
||||
espPinMapping_t* esp_cf = g_pins + pinIndex;
|
||||
int esp_mode;
|
||||
if (mode == INTERRUPT_RISING) {
|
||||
esp_mode = GPIO_INTR_POSEDGE;
|
||||
}
|
||||
else {
|
||||
esp_mode = GPIO_INTR_NEGEDGE;
|
||||
}
|
||||
ESP_ConfigurePin(esp_cf->pin, GPIO_MODE_INPUT, true, false, esp_mode);
|
||||
gpio_isr_handler_add(esp_cf->pin, ESP_Interrupt, (void*)pinIndex);
|
||||
}
|
||||
void HAL_DetachInterrupt(int pinIndex) {
|
||||
if (g_handlers[pinIndex] == 0) {
|
||||
return; // already removed;
|
||||
}
|
||||
|
||||
espPinMapping_t* esp_cf;
|
||||
esp_cf = g_pins + pinIndex;
|
||||
gpio_isr_handler_remove(esp_cf->pin);
|
||||
///gpio_uninstall_isr_service();
|
||||
g_handlers[pinIndex] = 0;
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
void HAL_AttachInterrupt(int pinIndex, OBKInterruptType mode, OBKInterruptHandler function) {
|
||||
|
||||
}
|
||||
void HAL_DetachInterrupt(int pinIndex) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#if ENABLE_DRIVER_BL0937
|
||||
|
||||
//dummy
|
||||
@ -379,10 +18,6 @@ void HAL_DetachInterrupt(int pinIndex) {
|
||||
#include "drv_pwrCal.h"
|
||||
#include "drv_uart.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define DEFAULT_VOLTAGE_CAL 0.13253012048f
|
||||
#define DEFAULT_CURRENT_CAL 0.0118577075f
|
||||
#define DEFAULT_POWER_CAL 1.5f
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include "../../logging/logging.h"
|
||||
#include "../../new_cfg.h"
|
||||
#include "../../new_pins.h"
|
||||
#include "../hal_pins.h"
|
||||
//#include "../../new_pins.h"
|
||||
#include <gpio_pub.h>
|
||||
|
||||
@ -151,3 +152,37 @@ void HAL_PIN_PWM_Update(int index, float value) {
|
||||
unsigned int HAL_GetGPIOPin(int index) {
|
||||
return index;
|
||||
}
|
||||
|
||||
OBKInterruptHandler g_handlers[PLATFORM_GPIO_MAX];
|
||||
OBKInterruptType g_modes[PLATFORM_GPIO_MAX];
|
||||
|
||||
#include "BkDriverTimer.h"
|
||||
#include "BkDriverGpio.h"
|
||||
#include "sys_timer.h"
|
||||
#include "gw_intf.h"
|
||||
|
||||
void Beken_Interrupt(unsigned char pinNum) {
|
||||
if (g_handlers[pinNum]) {
|
||||
g_handlers[pinNum](pinNum);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_AttachInterrupt(int pinIndex, OBKInterruptType mode, OBKInterruptHandler function) {
|
||||
g_handlers[pinIndex] = function;
|
||||
int bk_mode;
|
||||
if (mode == INTERRUPT_RISING) {
|
||||
bk_mode = IRQ_TRIGGER_RISING_EDGE;
|
||||
}
|
||||
else {
|
||||
bk_mode = IRQ_TRIGGER_FALLING_EDGE;
|
||||
}
|
||||
gpio_int_enable(pinIndex, bk_mode, Beken_Interrupt);
|
||||
}
|
||||
void HAL_DetachInterrupt(int pinIndex) {
|
||||
if (g_handlers[pinIndex] == 0) {
|
||||
return; // already removed;
|
||||
}
|
||||
gpio_int_disable(pinIndex);
|
||||
g_handlers[pinIndex] = 0;
|
||||
}
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include "../../new_pins.h"
|
||||
#include "../../new_common.h"
|
||||
#include "../../logging/logging.h"
|
||||
#include "../hal_pins.h"
|
||||
|
||||
|
||||
#include "bl_gpio.h"
|
||||
@ -98,4 +99,36 @@ unsigned int HAL_GetGPIOPin(int index) {
|
||||
return index;
|
||||
}
|
||||
|
||||
OBKInterruptHandler g_handlers[PLATFORM_GPIO_MAX];
|
||||
OBKInterruptType g_modes[PLATFORM_GPIO_MAX];
|
||||
|
||||
#include "hal_gpio.h"
|
||||
|
||||
void BL602_Interrupt(void* context) {
|
||||
int obkPinNum = (int)context;
|
||||
if (g_handlers[obkPinNum]) {
|
||||
g_handlers[obkPinNum](obkPinNum);
|
||||
}
|
||||
bl_gpio_intmask(obkPinNum, 0);
|
||||
}
|
||||
|
||||
void HAL_AttachInterrupt(int pinIndex, OBKInterruptType mode, OBKInterruptHandler function) {
|
||||
g_handlers[pinIndex] = function;
|
||||
int bl_mode;
|
||||
if (mode == INTERRUPT_RISING) {
|
||||
bl_mode = GPIO_INT_TRIG_POS_PULSE;
|
||||
}
|
||||
else {
|
||||
bl_mode = GPIO_INT_TRIG_NEG_PULSE;
|
||||
}
|
||||
hal_gpio_register_handler(BL602_Interrupt, pinIndex,
|
||||
GPIO_INT_CONTROL_ASYNC, bl_mode, (void*)pinIndex);
|
||||
}
|
||||
void HAL_DetachInterrupt(int pinIndex) {
|
||||
if (g_handlers[pinIndex] == 0) {
|
||||
return; // already removed;
|
||||
}
|
||||
g_handlers[pinIndex] = 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include "../../logging/logging.h"
|
||||
#include "../../new_cfg.h"
|
||||
#include "../../new_pins.h"
|
||||
#include "../hal_pins.h"
|
||||
#include "hal_gpio.h"
|
||||
#include "gpio.h"
|
||||
#include "pwm.h"
|
||||
@ -306,4 +307,42 @@ unsigned int HAL_GetGPIOPin(int index)
|
||||
return index;
|
||||
}
|
||||
|
||||
OBKInterruptHandler g_handlers[PLATFORM_GPIO_MAX];
|
||||
OBKInterruptType g_modes[PLATFORM_GPIO_MAX];
|
||||
|
||||
void ECR6600_Interrupt(unsigned char obkPinNum) {
|
||||
if (g_handlers[obkPinNum]) {
|
||||
g_handlers[obkPinNum](obkPinNum);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_AttachInterrupt(int pinIndex, OBKInterruptType mode, OBKInterruptHandler function) {
|
||||
g_handlers[pinIndex] = function;
|
||||
|
||||
T_GPIO_ISR_CALLBACK cf1isr;
|
||||
cf1isr.gpio_callback = (&ECR6600_Interrupt);
|
||||
cf1isr.gpio_data = pinIndex;
|
||||
|
||||
int ecr_mode;
|
||||
if (mode == INTERRUPT_RISING) {
|
||||
ecr_mode = DRV_GPIO_ARG_INTR_MODE_P_EDGE;
|
||||
}
|
||||
else {
|
||||
ecr_mode = DRV_GPIO_ARG_INTR_MODE_N_EDGE;
|
||||
}
|
||||
drv_gpio_ioctrl(pinIndex, DRV_GPIO_CTRL_INTR_MODE, ecr_mode);
|
||||
drv_gpio_ioctrl(pinIndex, DRV_GPIO_CTRL_REGISTER_ISR, (int)&cf1isr);
|
||||
drv_gpio_ioctrl(pinIndex, DRV_GPIO_CTRL_INTR_ENABLE, 0);
|
||||
|
||||
}
|
||||
void HAL_DetachInterrupt(int pinIndex) {
|
||||
if (g_handlers[pinIndex] == 0) {
|
||||
return; // already removed;
|
||||
}
|
||||
|
||||
drv_gpio_ioctrl(pinIndex, DRV_GPIO_CTRL_INTR_DISABLE, 0);
|
||||
g_handlers[pinIndex] = 0;
|
||||
}
|
||||
|
||||
|
||||
#endif // PLATFORM_ECR6600
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include "../../new_pins.h"
|
||||
#include "hal_pinmap_espidf.h"
|
||||
#include "driver/ledc.h"
|
||||
#include "../hal_pins.h"
|
||||
|
||||
#ifdef CONFIG_IDF_TARGET_ESP32C3
|
||||
|
||||
@ -606,4 +607,46 @@ unsigned int HAL_GetGPIOPin(int index)
|
||||
return index;
|
||||
}
|
||||
|
||||
|
||||
OBKInterruptHandler g_handlers[PLATFORM_GPIO_MAX];
|
||||
OBKInterruptType g_modes[PLATFORM_GPIO_MAX];
|
||||
|
||||
void ESP_Interrupt(void* context) {
|
||||
int obkPinNum = (int)context;
|
||||
if (g_handlers[obkPinNum]) {
|
||||
g_handlers[obkPinNum](obkPinNum);
|
||||
}
|
||||
}
|
||||
|
||||
bool b_esp_ready = false;
|
||||
void HAL_AttachInterrupt(int pinIndex, OBKInterruptType mode, OBKInterruptHandler function) {
|
||||
g_handlers[pinIndex] = function;
|
||||
|
||||
if (b_esp_ready == false) {
|
||||
gpio_install_isr_service(0);
|
||||
b_esp_ready = true;
|
||||
}
|
||||
espPinMapping_t* esp_cf = g_pins + pinIndex;
|
||||
int esp_mode;
|
||||
if (mode == INTERRUPT_RISING) {
|
||||
esp_mode = GPIO_INTR_POSEDGE;
|
||||
}
|
||||
else {
|
||||
esp_mode = GPIO_INTR_NEGEDGE;
|
||||
}
|
||||
ESP_ConfigurePin(esp_cf->pin, GPIO_MODE_INPUT, true, false, esp_mode);
|
||||
gpio_isr_handler_add(esp_cf->pin, ESP_Interrupt, (void*)pinIndex);
|
||||
}
|
||||
void HAL_DetachInterrupt(int pinIndex) {
|
||||
if (g_handlers[pinIndex] == 0) {
|
||||
return; // already removed;
|
||||
}
|
||||
|
||||
espPinMapping_t* esp_cf;
|
||||
esp_cf = g_pins + pinIndex;
|
||||
gpio_isr_handler_remove(esp_cf->pin);
|
||||
///gpio_uninstall_isr_service();
|
||||
g_handlers[pinIndex] = 0;
|
||||
}
|
||||
|
||||
#endif // PLATFORM_ESPIDF
|
||||
|
||||
@ -4,10 +4,13 @@
|
||||
#include "../../logging/logging.h"
|
||||
#include "../../new_cfg.h"
|
||||
#include "../../new_pins.h"
|
||||
#include "../hal_pins.h"
|
||||
#include "hal_pinmap_ln882h.h"
|
||||
// LN882H header
|
||||
#include "hal/hal_adv_timer.h"
|
||||
#include "hal/hal_clock.h"
|
||||
#include "hal/hal_common.h"
|
||||
#include "hal/hal_gpio.h"
|
||||
|
||||
#define IS_QSPI_PIN(index) (index > 12 && index < 19)
|
||||
|
||||
@ -239,4 +242,68 @@ unsigned int HAL_GetGPIOPin(int index) {
|
||||
return index;
|
||||
}
|
||||
|
||||
OBKInterruptHandler g_handlers[PLATFORM_GPIO_MAX];
|
||||
OBKInterruptType g_modes[PLATFORM_GPIO_MAX];
|
||||
|
||||
|
||||
uint32_t GetBaseForPin(int pinIndex)
|
||||
{
|
||||
return pinIndex < 16 ? GPIOA_BASE : GPIOB_BASE;
|
||||
}
|
||||
|
||||
int GetIRQForPin(int pinIndex)
|
||||
{
|
||||
return pinIndex < 16 ? GPIOA_IRQn : GPIOB_IRQn;
|
||||
}
|
||||
|
||||
uint16_t GetGPIOForPin(int pinIndex)
|
||||
{
|
||||
return (uint16_t)1 << (uint16_t)(pinIndex % 16);
|
||||
}
|
||||
void Shared_Handler() {
|
||||
for (int i = 0; i < PLATFORM_GPIO_MAX; i++) {
|
||||
if (g_handlers[i]) {
|
||||
uint32_t base = GetBaseForPin(i);
|
||||
uint16_t gpio_pin = GetGPIOForPin(i);
|
||||
if (hal_gpio_pin_get_it_flag(base, gpio_pin) == HAL_SET) {
|
||||
hal_gpio_pin_clr_it_flag(base, gpio_pin);
|
||||
g_handlers[i](i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void GPIOA_IRQHandler()
|
||||
{
|
||||
Shared_Handler();
|
||||
}
|
||||
|
||||
void GPIOB_IRQHandler()
|
||||
{
|
||||
Shared_Handler();
|
||||
}
|
||||
|
||||
void HAL_AttachInterrupt(int pinIndex, OBKInterruptType mode, OBKInterruptHandler function) {
|
||||
g_handlers[pinIndex] = function;
|
||||
|
||||
int ln_mode;
|
||||
if (mode == INTERRUPT_RISING) {
|
||||
ln_mode = GPIO_INT_RISING;
|
||||
}
|
||||
else {
|
||||
ln_mode = GPIO_INT_FALLING;
|
||||
}
|
||||
hal_gpio_pin_it_cfg(GetBaseForPin(pinIndex), GetGPIOForPin(pinIndex), ln_mode);
|
||||
hal_gpio_pin_it_en(GetBaseForPin(pinIndex), GetGPIOForPin(pinIndex), HAL_ENABLE);
|
||||
NVIC_SetPriority(GetIRQForPin(pinIndex), 1);
|
||||
NVIC_EnableIRQ(GetIRQForPin(pinIndex));
|
||||
|
||||
}
|
||||
|
||||
void HAL_DetachInterrupt(int pinIndex) {
|
||||
if (g_handlers[pinIndex] == 0) {
|
||||
return; // already removed;
|
||||
}
|
||||
g_handlers[pinIndex] = 0;
|
||||
}
|
||||
|
||||
#endif // PLATFORM_LN882H
|
||||
|
||||
@ -193,4 +193,54 @@ unsigned int HAL_GetGPIOPin(int index)
|
||||
return index;
|
||||
}
|
||||
|
||||
OBKInterruptHandler g_handlers[PLATFORM_GPIO_MAX];
|
||||
OBKInterruptType g_modes[PLATFORM_GPIO_MAX];
|
||||
|
||||
#include "gpio_irq_api.h"
|
||||
|
||||
void Realtek_Interrupt(uint32_t obkPinNum, gpio_irq_event event)
|
||||
{
|
||||
if (g_handlers[obkPinNum]) {
|
||||
g_handlers[obkPinNum](obkPinNum);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_AttachInterrupt(int pinIndex, OBKInterruptType mode, OBKInterruptHandler function) {
|
||||
g_handlers[pinIndex] = function;
|
||||
|
||||
rtlPinMapping_t *rtl_cf = g_pins + pinIndex;
|
||||
#if PLATFORM_RTL87X0C
|
||||
if (rtl_cf->gpio != NULL)
|
||||
{
|
||||
hal_pinmux_unregister(rtl_cf->pin, PID_GPIO);
|
||||
os_free(rtl_cf->gpio);
|
||||
rtl_cf->gpio = NULL;
|
||||
}
|
||||
#endif
|
||||
rtl_cf->irq = os_malloc(sizeof(gpio_irq_t));
|
||||
memset(rtl_cf->irq, 0, sizeof(gpio_irq_t));
|
||||
|
||||
int rtl_mode;
|
||||
if (mode == INTERRUPT_RISING) {
|
||||
rtl_mode = IRQ_RISE;
|
||||
}
|
||||
else {
|
||||
rtl_mode = IRQ_FALL;
|
||||
}
|
||||
gpio_irq_init(rtl_cf->irq, rtl_cf->pin, Realtek_Interrupt, pinIndex);
|
||||
gpio_irq_set(rtl_cf->irq, rtl_mode, 1);
|
||||
gpio_irq_enable(rtl_cf->irq);
|
||||
|
||||
}
|
||||
void HAL_DetachInterrupt(int pinIndex) {
|
||||
if (g_handlers[pinIndex] == 0) {
|
||||
return; // already removed;
|
||||
}
|
||||
rtlPinMapping_t *rtl_cf = g_pins + pinIndex;
|
||||
gpio_irq_free(rtl_cf->irq);
|
||||
os_free(rtl_cf->irq);
|
||||
rtl_cf->irq = NULL;
|
||||
g_handlers[pinIndex] = 0;
|
||||
}
|
||||
|
||||
#endif // PLATFORM_REALTEK
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
#include "../../logging/logging.h"
|
||||
#include "../../new_cfg.h"
|
||||
#include "../../new_pins.h"
|
||||
#include "../hal_pins.h"
|
||||
#include "drv_gpio.h"
|
||||
#include "drv_pwm.h"
|
||||
#include "soc_pin_mux.h"
|
||||
@ -285,4 +286,13 @@ unsigned int HAL_GetGPIOPin(int index)
|
||||
return index;
|
||||
}
|
||||
|
||||
void HAL_AttachInterrupt(int pinIndex, OBKInterruptType mode, OBKInterruptHandler function) {
|
||||
|
||||
}
|
||||
void HAL_DetachInterrupt(int pinIndex) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // PLATFORM_TR6260
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
|
||||
#include "../../new_common.h"
|
||||
#include "../../logging/logging.h"
|
||||
#include "../hal_pins.h"
|
||||
#include "../../new_pins.h"
|
||||
|
||||
#include "wm_include.h"
|
||||
|
||||
@ -114,7 +116,7 @@ static int IsPinIndexOk(int index) {
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
static int PIN_GetPWMIndexForPinIndex(int index) {
|
||||
int PIN_GetPWMIndexForPinIndex(int index) {
|
||||
return g_pins[index].pwm_channel;
|
||||
}
|
||||
const char* HAL_PIN_GetPinNameAlias(int index) {
|
||||
@ -248,4 +250,39 @@ void HAL_PIN_PWM_Update(int index, float value) {
|
||||
unsigned int HAL_GetGPIOPin(int index) {
|
||||
return g_pins[index].code;
|
||||
}
|
||||
|
||||
OBKInterruptHandler g_handlers[PLATFORM_GPIO_MAX];
|
||||
OBKInterruptType g_modes[PLATFORM_GPIO_MAX];
|
||||
|
||||
void W600_Interrupt(void* context) {
|
||||
int obkPinNum = (int)(intptr_t)context;
|
||||
int w600Pin = HAL_GetGPIOPin(obkPinNum);
|
||||
tls_clr_gpio_irq_status(w600Pin);
|
||||
if (g_handlers[obkPinNum]) {
|
||||
g_handlers[obkPinNum](obkPinNum);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_AttachInterrupt(int pinIndex, OBKInterruptType mode, OBKInterruptHandler function) {
|
||||
g_handlers[pinIndex] = function;
|
||||
int w600Pin = HAL_GetGPIOPin(pinIndex);
|
||||
tls_gpio_isr_register(w600Pin, W600_Interrupt, (void*)(intptr_t)pinIndex);
|
||||
int w_mode;
|
||||
if (mode == INTERRUPT_RISING) {
|
||||
w_mode = WM_GPIO_IRQ_TRIG_RISING_EDGE;
|
||||
}
|
||||
else {
|
||||
w_mode = WM_GPIO_IRQ_TRIG_FALLING_EDGE;
|
||||
}
|
||||
tls_gpio_irq_enable(w600Pin, w_mode);
|
||||
}
|
||||
void HAL_DetachInterrupt(int pinIndex) {
|
||||
if (g_handlers[pinIndex] == 0) {
|
||||
return; // already removed;
|
||||
}
|
||||
int w600Pin = HAL_GetGPIOPin(pinIndex);
|
||||
tls_gpio_irq_disable(w600Pin);
|
||||
g_handlers[pinIndex] = 0;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -226,5 +226,13 @@ unsigned int HAL_GetGPIOPin(int index) {
|
||||
return index;
|
||||
}
|
||||
|
||||
void HAL_AttachInterrupt(int pinIndex, OBKInterruptType mode, OBKInterruptHandler function) {
|
||||
|
||||
}
|
||||
void HAL_DetachInterrupt(int pinIndex) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
#include "../../new_common.h"
|
||||
#include "../../logging/logging.h"
|
||||
#include "../hal_pins.h"
|
||||
|
||||
#include "hal_pinmap_xradio.h"
|
||||
|
||||
@ -123,4 +124,45 @@ void HAL_PIN_PWM_Update(int index, float value)
|
||||
HAL_PWM_ChSetDutyRatio(g_pins[index].pwm, (g_pins[index].max_duty / 100) * value);
|
||||
}
|
||||
|
||||
OBKInterruptHandler g_handlers[PLATFORM_GPIO_MAX];
|
||||
OBKInterruptType g_modes[PLATFORM_GPIO_MAX];
|
||||
|
||||
void XRadio_Interrupt(void* context) {
|
||||
int obkPinNum = (int)context;
|
||||
if (g_handlers[obkPinNum]) {
|
||||
g_handlers[obkPinNum](obkPinNum);
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_AttachInterrupt(int pinIndex, OBKInterruptType mode, OBKInterruptHandler function) {
|
||||
g_handlers[pinIndex] = function;
|
||||
|
||||
xrpin_t *xr_cf = g_pins + pinIndex;
|
||||
HAL_XR_ConfigurePin(xr_cf->port, xr_cf->pin, GPIOx_Pn_F6_EINT, GPIO_PULL_UP);
|
||||
GPIO_IrqParam cfparam;
|
||||
int xr_mode;
|
||||
if (mode == INTERRUPT_RISING) {
|
||||
xr_mode = GPIO_IRQ_EVT_RISING_EDGE;
|
||||
}
|
||||
else {
|
||||
xr_mode = GPIO_IRQ_EVT_FALLING_EDGE;
|
||||
}
|
||||
cfparam.event = xr_mode;
|
||||
cfparam.callback = XRadio_Interrupt;
|
||||
cfparam.arg = (void*)pinIndex;
|
||||
HAL_GPIO_EnableIRQ(xr_cf->port, xr_cf->pin, &cfparam);
|
||||
|
||||
}
|
||||
void HAL_DetachInterrupt(int pinIndex) {
|
||||
if (g_handlers[pinIndex] == 0) {
|
||||
return; // already removed;
|
||||
}
|
||||
xrpin_t* xr_cf;
|
||||
xr_cf = g_pins + pinIndex;
|
||||
HAL_GPIO_DeInit(xr_cf->port, xr_cf->pin);
|
||||
HAL_GPIO_DisableIRQ(xr_cf->port, xr_cf->pin);
|
||||
g_handlers[pinIndex] = 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user