forked from apache/nuttx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f3c477
commit e67df47
Showing
5 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/**************************************************************************** | ||
* boards/xtensa/esp32/common/include/esp32_zerocross.h | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. The | ||
* ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
****************************************************************************/ | ||
|
||
#ifndef __BOARDS_EXTENSA_ESP32_COMMON_INCLUDE_ESPM32_ZEROCROSS_H | ||
#define __BOARDS_EXTENSA_ESP32_COMMON_INCLUDE_ESPM32_ZEROCROSS_H | ||
|
||
/**************************************************************************** | ||
* Included Files | ||
****************************************************************************/ | ||
|
||
#include <nuttx/config.h> | ||
|
||
/**************************************************************************** | ||
* Pre-processor Definitions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Public Types | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Public Data | ||
****************************************************************************/ | ||
|
||
#ifdef __cplusplus | ||
#define EXTERN extern "C" | ||
extern "C" | ||
{ | ||
#else | ||
#define EXTERN extern | ||
#endif | ||
|
||
/**************************************************************************** | ||
* Inline Functions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Public Function Prototypes | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Name: esp32_zerocross_initialize | ||
* | ||
* Description: | ||
* Initialize and register the zero cross driver | ||
* | ||
****************************************************************************/ | ||
|
||
int board_zerocross_initialize(int devno); | ||
|
||
#undef EXTERN | ||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif /* __BOARDS_EXTENSA_ESP32_COMMON_INCLUDE_ESPM32_ZEROCROSS_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/**************************************************************************** | ||
* boards/xtensa/esp32/common/src/esp32_zerocross.c | ||
* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. The | ||
* ASF licenses this file to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance with the | ||
* License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations | ||
* under the License. | ||
* | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Included Files | ||
****************************************************************************/ | ||
|
||
#include <nuttx/config.h> | ||
|
||
#include <stdint.h> | ||
#include <assert.h> | ||
#include <debug.h> | ||
|
||
#include <nuttx/irq.h> | ||
#include <nuttx/arch.h> | ||
#include <arch/board/board.h> | ||
#include <nuttx/sensors/zerocross.h> | ||
|
||
#include "esp32_gpio.h" | ||
#include "hardware/esp32_gpio_sigmap.h" | ||
#include "esp32-wrover-kit.h" | ||
#include "esp32_zerocross.h" | ||
|
||
/**************************************************************************** | ||
* Private Function Prototypes | ||
****************************************************************************/ | ||
|
||
static void zcross_enable(const struct zc_lowerhalf_s *lower, | ||
zc_interrupt_t handler, void *arg); | ||
|
||
static int zcross_interrupt(int irq, void *context, void *arg); | ||
|
||
/**************************************************************************** | ||
* Private Data | ||
****************************************************************************/ | ||
|
||
/* Current interrupt handler and argument */ | ||
|
||
static zc_interrupt_t g_zcrosshandler; | ||
static void *g_zcrossarg; | ||
|
||
/* This is the zero cross lower half driver interface */ | ||
|
||
static struct zc_lowerhalf_s g_zcrosslower = | ||
{ | ||
.zc_enable = zcross_enable, | ||
}; | ||
|
||
/**************************************************************************** | ||
* Private Functions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Name: zcross_enable | ||
* | ||
* Description: | ||
* Enable interrupts on the selected zero cross pin. And empty | ||
* set will disable all interrupts. | ||
* | ||
****************************************************************************/ | ||
|
||
static void zcross_enable(const struct zc_lowerhalf_s *lower, | ||
zc_interrupt_t handler, void *arg) | ||
{ | ||
irqstate_t flags; | ||
int irq = ESP32_PIN2IRQ(GPIO_ZERO_CROSS_IRQ); | ||
int ret; | ||
|
||
flags = enter_critical_section(); | ||
|
||
if (handler) | ||
{ | ||
g_zcrosshandler = handler; | ||
g_zcrossarg = arg; | ||
} | ||
|
||
/* Start with all interrupts disabled */ | ||
|
||
esp32_gpioirqdisable(irq); | ||
|
||
ret = irq_attach(irq, zcross_interrupt, NULL); | ||
if (ret < 0) | ||
{ | ||
syslog(LOG_ERR, "ERROR: zcross_enable() failed: %d\n", ret); | ||
leave_critical_section(flags); | ||
} | ||
|
||
esp32_gpioirqenable(irq, RISING); | ||
|
||
leave_critical_section(flags); | ||
} | ||
|
||
/**************************************************************************** | ||
* Name: zcross_interrupt | ||
* | ||
* Description: | ||
* Zero Cross interrupt handler | ||
* | ||
****************************************************************************/ | ||
|
||
static int zcross_interrupt(int irq, void *context, void *arg) | ||
{ | ||
DEBUGASSERT(g_zcrosshandler != NULL); | ||
if (g_zcrosshandler) | ||
{ | ||
g_zcrosshandler(&g_zcrosslower, g_zcrossarg); | ||
} | ||
|
||
return OK; | ||
} | ||
|
||
/**************************************************************************** | ||
* Public Functions | ||
****************************************************************************/ | ||
|
||
/**************************************************************************** | ||
* Name: esp32_zerocross_initialize | ||
* | ||
* Description: | ||
* Initialize and register the zero cross driver | ||
* | ||
****************************************************************************/ | ||
|
||
int board_zerocross_initialize(int devno) | ||
{ | ||
esp32_configgpio(GPIO_ZERO_CROSS_IRQ, INPUT_FUNCTION_3 | PULLUP); | ||
|
||
/* Register the zero cross device as /dev/zc0 */ | ||
|
||
return zc_register("/dev/zc0", &g_zcrosslower); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters