Relay example from Darcy Gong
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@5306 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
308516c028
commit
d700a5844c
@ -49,6 +49,8 @@
|
|||||||
#include "stm32_sdio.h"
|
#include "stm32_sdio.h"
|
||||||
#include "stm32_internal.h"
|
#include "stm32_internal.h"
|
||||||
|
|
||||||
|
#include <nuttx/arch.h>
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
@ -174,6 +176,10 @@
|
|||||||
#define BUTTON_TAMPER_BIT BUTTON_KEY3_BIT
|
#define BUTTON_TAMPER_BIT BUTTON_KEY3_BIT
|
||||||
#define BUTTON_WAKEUP_BIT BUTTON_KEY4_BIT
|
#define BUTTON_WAKEUP_BIT BUTTON_KEY4_BIT
|
||||||
|
|
||||||
|
/* Relays */
|
||||||
|
|
||||||
|
#define NUM_RELAYS 2
|
||||||
|
|
||||||
/* Pin selections ******************************************************************/
|
/* Pin selections ******************************************************************/
|
||||||
/* Ethernet
|
/* Ethernet
|
||||||
*
|
*
|
||||||
@ -426,18 +432,20 @@ EXTERN void stm32_lcdclear(uint16_t color);
|
|||||||
* Relay control functions
|
* Relay control functions
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Non-standard fucntions for relay control from the Shenzhou board.
|
* Non-standard functions for relay control from the Shenzhou board.
|
||||||
|
*
|
||||||
|
* NOTE: These must match the prototypes in include/nuttx/arch.h
|
||||||
*
|
*
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_ARCH_RELAYS
|
#ifdef CONFIG_ARCH_RELAYS
|
||||||
EXTERN void up_relaysinit(void);
|
EXTERN void up_relaysinit(void);
|
||||||
EXTERN void relays_setstat(int relays,bool stat);
|
EXTERN void relays_setstat(int relays, bool stat);
|
||||||
EXTERN bool relays_getstat(int relays);
|
EXTERN bool relays_getstat(int relays);
|
||||||
EXTERN void relays_setstats(uint32_t relays_stat);
|
EXTERN void relays_setstats(uint32_t relays_stat);
|
||||||
EXTERN uint32_t relays_getstats(void);
|
EXTERN uint32_t relays_getstats(void);
|
||||||
EXTERN void relays_onoff(int relays,uint32_t mdelay);
|
EXTERN void relays_onoff(int relays, uint32_t mdelay);
|
||||||
EXTERN void relays_onoffs(uint32_t relays_stat,uint32_t mdelay);
|
EXTERN void relays_onoffs(uint32_t relays_stat, uint32_t mdelay);
|
||||||
EXTERN void relays_resetmode(int relays);
|
EXTERN void relays_resetmode(int relays);
|
||||||
EXTERN void relays_powermode(int relays);
|
EXTERN void relays_powermode(int relays);
|
||||||
EXTERN void relays_resetmodes(uint32_t relays_stat);
|
EXTERN void relays_resetmodes(uint32_t relays_stat);
|
||||||
|
@ -393,9 +393,11 @@
|
|||||||
|
|
||||||
/* Relays */
|
/* Relays */
|
||||||
|
|
||||||
#define NUM_RELAYS 1
|
#define NUM_RELAYS 2
|
||||||
#define GPIO_RELAYS_R00 (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
|
#define GPIO_RELAYS_R00 (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
|
||||||
GPIO_OUTPUT_SET|GPIO_PORTE|GPIO_PIN0)
|
GPIO_OUTPUT_SET|GPIO_PORTE|GPIO_PIN0)
|
||||||
|
#define GPIO_RELAYS_R01 (GPIO_OUTPUT|GPIO_CNF_OUTPP|GPIO_MODE_50MHz|\
|
||||||
|
GPIO_OUTPUT_SET|GPIO_PORTE|GPIO_PIN1)
|
||||||
|
|
||||||
/****************************************************************************************************
|
/****************************************************************************************************
|
||||||
* Public Types
|
* Public Types
|
||||||
|
@ -42,11 +42,13 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <arch/board/board.h>
|
|
||||||
#include "shenzhou-internal.h"
|
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/arch.h>
|
||||||
|
#include <arch/board/board.h>
|
||||||
|
|
||||||
|
#include "shenzhou-internal.h"
|
||||||
|
|
||||||
#ifdef CONFIG_ARCH_RELAYS
|
#ifdef CONFIG_ARCH_RELAYS
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -62,6 +64,7 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static uint32_t g_relays_stat = 0;
|
static uint32_t g_relays_stat = 0;
|
||||||
|
static bool g_relays_init = false;
|
||||||
|
|
||||||
static const uint16_t g_relays[NUM_RELAYS] =
|
static const uint16_t g_relays[NUM_RELAYS] =
|
||||||
{
|
{
|
||||||
@ -173,6 +176,11 @@ void up_relaysinit(void)
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
if (g_relays_init)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Configure the GPIO pins as inputs. NOTE that EXTI interrupts are
|
/* Configure the GPIO pins as inputs. NOTE that EXTI interrupts are
|
||||||
* configured for some pins but NOT used in this file
|
* configured for some pins but NOT used in this file
|
||||||
*/
|
*/
|
||||||
@ -180,7 +188,10 @@ void up_relaysinit(void)
|
|||||||
for (i = 0; i < NUM_RELAYS; i++)
|
for (i = 0; i < NUM_RELAYS; i++)
|
||||||
{
|
{
|
||||||
stm32_configgpio(g_relays[i]);
|
stm32_configgpio(g_relays[i]);
|
||||||
|
stm32_gpiowrite(g_relays[i], false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_relays_init = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void relays_setstat(int relays,bool stat)
|
void relays_setstat(int relays,bool stat)
|
||||||
|
@ -616,6 +616,28 @@ EXTERN uint8_t up_buttons(void);
|
|||||||
EXTERN xcpt_t up_irqbutton(int id, xcpt_t irqhandler);
|
EXTERN xcpt_t up_irqbutton(int id, xcpt_t irqhandler);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/************************************************************************************
|
||||||
|
* Relay control functions
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Non-standard functions for relay control.
|
||||||
|
*
|
||||||
|
************************************************************************************/
|
||||||
|
|
||||||
|
#ifdef CONFIG_ARCH_RELAYS
|
||||||
|
EXTERN void up_relaysinit(void);
|
||||||
|
EXTERN void relays_setstat(int relays, bool stat);
|
||||||
|
EXTERN bool relays_getstat(int relays);
|
||||||
|
EXTERN void relays_setstats(uint32_t relays_stat);
|
||||||
|
EXTERN uint32_t relays_getstats(void);
|
||||||
|
EXTERN void relays_onoff(int relays, uint32_t mdelay);
|
||||||
|
EXTERN void relays_onoffs(uint32_t relays_stat, uint32_t mdelay);
|
||||||
|
EXTERN void relays_resetmode(int relays);
|
||||||
|
EXTERN void relays_powermode(int relays);
|
||||||
|
EXTERN void relays_resetmodes(uint32_t relays_stat);
|
||||||
|
EXTERN void relays_powermodes(uint32_t relays_stat);
|
||||||
|
#endif
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Debug interfaces exported by the architecture-specific logic
|
* Debug interfaces exported by the architecture-specific logic
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
Loading…
Reference in New Issue
Block a user