API  2.2
TSmarT Software Library
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
db_dio.c

This is an example showing how to read a value from a Digital Input/Output (DIO) (Polling USE_INTERRUPT=0 or with Interrupts USE_INTERRUPT=1). When a Choose Button is Pushed the Selected Leds are

/*
* @file db_dio.c
* @author TST
* @version V0.0
* @date 19/06/2012
* @brief DIO example. This is an example showing how to read a value from a Digital Input/Output (DIO).
* User must set a high level voltage (3.3 Volts) to the selected reading DIO, then the LED connected
* to its associated DIO will switch on.
*
*/
#include "tsmart.h"
/*
* Task function. Main process to read a selected DIO through its associated PIN and switch on a LED if we
* read a high level value.
*
*/
/* CHOOSE ONE */
//#define LED1 &tsmart_dio0a
#define BUTTON1 &tsmart_dio0a
/* CHOOSE ONE */
//#define LED2 &tsmart_dio1a
#define BUTTON2 &tsmart_dio1a
/* CHOOSE ONE */
#define LED3 &tsmart_dio7
//#define BUTTON3 &tsmart_dio7
/* Fill the Values */
#define LEDS 1
#define BUTTONS 2
#define USE_INTERRUPT 1
#define USE_GROUP_INTERRUPT 1
void vEXAMPLE(void *pvParameters){
/* Variables */
uint8_t value1 = 1;
uint8_t value2 = 1;
uint8_t value3 = 1;
for(;;){
if (USE_INTERRUPT == 0){
#ifdef BUTTON1
value1 = TSMART_DIO_Read(BUTTON1);
#endif
#ifdef BUTTON2
value2 = TSMART_DIO_Read(BUTTON2);
#endif
#ifdef BUTTON3
value3 = TSMART_DIO_Read(BUTTON3);
#endif
/* If the value read is low ('0') any Push Button, we switch on the LED connected */
if(value1 == 0 || value2 == 0 || value3 == 0){
/* Set DIO. This function switches on/off the LED connected */
#ifdef LED1
#endif
#ifdef LED2
#endif
#ifdef LED3
#endif
}else{
#ifdef LED1
#endif
#ifdef LED2
#endif
#ifdef LED3
#endif
}
}else{
if (!USE_GROUP_INTERRUPT){
#ifdef BUTTON1
TSMART_DIO_Wfi(BUTTON1,portMAX_DELAY);
#endif
#ifdef BUTTON2
TSMART_DIO_Wfi(BUTTON2,portMAX_DELAY);
#endif
#ifdef BUTTON3
TSMART_DIO_Wfi(BUTTON3,portMAX_DELAY);
#endif
#ifdef LED1
#endif
#ifdef LED2
#endif
#ifdef LED3
#endif
}else{
#ifdef LED1
#endif
#ifdef LED2
#endif
#ifdef LED3
#endif
}
}
}
}
/*
* @brief init() function
*
* This is the first thing that the user must do for using TSmarT.
* It initializes the specific hardware resources (GPRS, GPS, AI, DIO, MODBUS, MSA...)
* and software resources (queues, mutex, tasks...) for the user application.
*
* The way to fill in this function properly is to initialize first
* hardware resources and after that software resources.
*
* This function must return: TSMART_PASS when every thing is OK or
* TSMART_FAIL when a failure happened.
*
* @return
* @arg TSMART_PASS
* @arg TSMART_FAIL
*/
int32_t init() {
/* Variables */
tsmart_dio_config_t tsmart_dio_config;
tsmart_dio_config_t tsmart_dio_config_read;
/* ************************************************************************* */
/* Debug Mode */
/* ************************************************************************* */
/* ************************************************************************* */
/* Initialize resources */
/* ************************************************************************* */
/* DIO configuration. User needs to configure the DIO to connect a LED */
tsmart_dio_config.mode = TSMART_DIO_OD;
tsmart_dio_config.irq_mode = TSMART_DIO_IRQ_NULL;
/* DIO configuration for reading. User needs to define the DIO as an input */
tsmart_dio_config_read.mode = TSMART_DIO_IPU;//TSMART_DIO_IPD
if (USE_INTERRUPT !=0){
tsmart_dio_config_read.irq_mode = TSMART_DIO_IRQ_FALLING;
if (USE_GROUP_INTERRUPT==1){
}
}else{
tsmart_dio_config_read.irq_mode = TSMART_DIO_IRQ_NULL;
}
/* Initialize DIOs
* User must initialize the DIOs to use. In this example one for reading a value and another one for
* connecting a LED */
#ifdef LED1
TSMART_DIO_Init(LED1, &tsmart_dio_config);
#endif
#ifdef LED2
TSMART_DIO_Init(LED2, &tsmart_dio_config);
#endif
#ifdef LED3
TSMART_DIO_Init(LED3, &tsmart_dio_config);
#endif
#ifdef BUTTON1
TSMART_DIO_Init(BUTTON1, &tsmart_dio_config_read);
if (USE_GROUP_INTERRUPT==1){
}
#endif
#ifdef BUTTON2
TSMART_DIO_Init(BUTTON2, &tsmart_dio_config_read);
if (USE_GROUP_INTERRUPT==1){
}
#endif
#ifdef BUTTON3
TSMART_DIO_Init(BUTTON3, &tsmart_dio_config_read);
if (USE_GROUP_INTERRUPT==1){
}
#endif
/* ************************************************************************* */
/* Application task */
/* ************************************************************************* */
/* Create the DIO_READ_EXAMPLE task */
if(xTaskCreate(vEXAMPLE, "EXAMPLE", 512, NULL, 7, NULL) != pdPASS){
return TSMART_FAIL;
}
/* Everything OK */
return TSMART_PASS;
}