d50c190957
* moving folders and files and adjust server demo build * Fix Makefile for apps/server on Linux * fix unit test source file folders * fix datetime convert UTC functions. Add Code::Blocks project for datetime testing * added some ignore extensions * disable parallel make option * fix build for abort, dcc, and epics apps * fix build for dcc, epics, error, and getevent apps. * Fixed building of all apps * fix the ipv4 to ipv6 router app build * Change indent style from Google to Webkit * make pretty to re-format style * removed common Makefile since we already had one and two was too many * remove scripts from root folder that are no longer maintained or used * remove mercurial EOL and ignore files for git repo * remove .vscodeconfig files from repo * tweak clang-format style * clang-format src and apps with tweaked style * added clang-tidy to fix readability if braces in src * result of make tidy for src and apps * fix clang-tidy mangling * Added code::blocks project for BACnet server simulation * added code::blocks linux project for WhoIs app * update text files for EOL * fix EOL in some files * fixed make win32 apps for older gcc * Removed Borland C++ Makefile in apps. Unable to maintain support for Borland C++ compiler. * created codeblocks project for apps/epics for Windows * fixing ports/xplained to work with new data structure. * fix ports/xplained example for Atmel Studio compile * fix ports/stm32f10x example for gcc Makefile compile * fix ports/stm32f10x example for IAR EWARM compile * fix ports/xplained timer callback * fix ports/bdk_atxx_mspt build with subdirs * fix ports/bdk_atxx_mspt build with subdirs * updated git ignore for IAR build artifacts * updated gitignore for non-tracked files and folders * fixed bdk-atxx4-mstp port for Rowley Crossworks project file * fixed bdk-atxx4-mstp port for GCC AVR Makefile * fixed atmega168 port for IAR AVR and GCC AVR Makefile * fixed at91sam7s port for IAR ARM and GCC ARM Makefile * removed unmaintainable DOS, RTOS32, and atmega8 ports. Updated rx62n (untested). * changed arm7 to uip port
204 lines
5.3 KiB
C
204 lines
5.3 KiB
C
/**************************************************************************
|
|
*
|
|
* Copyright (C) 2009 Steve Karg <skarg@users.sourceforge.net>
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
* a copy of this software and associated documentation files (the
|
|
* "Software"), to deal in the Software without restriction, including
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
* the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included
|
|
* in all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
*********************************************************************/
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
#include "hardware.h"
|
|
#include "bacnet/basic/sys/mstimer.h"
|
|
/* me */
|
|
#include "input.h"
|
|
|
|
#ifndef BDK_VERSION
|
|
#define BDK_VERSION 4
|
|
#endif
|
|
|
|
static uint8_t Address_Switch;
|
|
static uint8_t Buttons;
|
|
static struct mstimer Debounce_Timer;
|
|
|
|
#ifndef BDK_V1_HACK
|
|
#define BDK_V1_HACK 0
|
|
#endif
|
|
|
|
#if BDK_V1_HACK
|
|
/* version 1 BDK workaournd for floating inputs */
|
|
static void input_switch_workaround(
|
|
void)
|
|
{
|
|
/* configure the port pins for the switch - as outputs */
|
|
BIT_SET(DDRA, DDA0);
|
|
BIT_SET(DDRA, DDA1);
|
|
BIT_SET(DDRA, DDA2);
|
|
BIT_SET(DDRA, DDA3);
|
|
BIT_SET(DDRA, DDA4);
|
|
BIT_SET(DDRA, DDA5);
|
|
BIT_SET(DDRA, DDA6);
|
|
/* turn off the outputs */
|
|
BIT_CLEAR(PORTA, PORTA0);
|
|
BIT_CLEAR(PORTA, PORTA1);
|
|
BIT_CLEAR(PORTA, PORTA2);
|
|
BIT_CLEAR(PORTA, PORTA3);
|
|
BIT_CLEAR(PORTA, PORTA4);
|
|
BIT_CLEAR(PORTA, PORTA5);
|
|
BIT_CLEAR(PORTA, PORTA6);
|
|
/* configure the port pins for the switch - as inputs */
|
|
BIT_CLEAR(DDRA, DDA0);
|
|
BIT_CLEAR(DDRA, DDA1);
|
|
BIT_CLEAR(DDRA, DDA2);
|
|
BIT_CLEAR(DDRA, DDA3);
|
|
BIT_CLEAR(DDRA, DDA4);
|
|
BIT_CLEAR(DDRA, DDA5);
|
|
BIT_CLEAR(DDRA, DDA6);
|
|
|
|
return;
|
|
}
|
|
#endif
|
|
|
|
/* debounce the inputs */
|
|
void input_task(
|
|
void)
|
|
{
|
|
uint8_t value;
|
|
static uint8_t old_address = 0;
|
|
static uint8_t old_buttons = 0;
|
|
|
|
/* only check the inputs every debounce time */
|
|
if (mstimer_expired(&Debounce_Timer)) {
|
|
mstimer_reset(&Debounce_Timer);
|
|
/* pins used are PA6, PA5, PA4, PA3, PA2, PA1, PA0 */
|
|
#if BDK_V1_HACK
|
|
/* version 1 BDK - workaround */
|
|
value = (PINA & 0x7F);
|
|
#else
|
|
/* version 2 BDK - has inverted inputs */
|
|
value = ~PINA;
|
|
value &= 0x7F;
|
|
#endif
|
|
if (value == old_address) {
|
|
/* stable value */
|
|
Address_Switch = old_address;
|
|
}
|
|
old_address = value;
|
|
#if (BDK_VERSION==4)
|
|
/* pins used are PB3, PB2, PB1 */
|
|
value = BITMASK_CHECK(PINB, 0x0E);
|
|
value >>= 1;
|
|
#else
|
|
/* pins used are PB4, PB3, PB2, PB1, PB0 */
|
|
value = BITMASK_CHECK(PINB, 0x1F);
|
|
#endif
|
|
if (value == old_buttons) {
|
|
/* stable value */
|
|
Buttons = old_buttons;
|
|
}
|
|
old_buttons = value;
|
|
}
|
|
#if BDK_V1_HACK
|
|
input_switch_workaround();
|
|
#endif
|
|
}
|
|
|
|
uint8_t input_address(
|
|
void)
|
|
{
|
|
return Address_Switch;
|
|
}
|
|
|
|
uint8_t input_rotary_value(
|
|
uint8_t index)
|
|
{
|
|
return Buttons;
|
|
}
|
|
|
|
bool input_button_value(
|
|
uint8_t index)
|
|
{
|
|
bool value = false;
|
|
|
|
switch (index) {
|
|
case 0:
|
|
value = BIT_CHECK(Buttons, 0);
|
|
break;
|
|
case 1:
|
|
value = BIT_CHECK(Buttons, 1);
|
|
break;
|
|
case 2:
|
|
value = BIT_CHECK(Buttons, 2);
|
|
break;
|
|
case 3:
|
|
value = BIT_CHECK(Buttons, 3);
|
|
break;
|
|
case 4:
|
|
value = BIT_CHECK(Buttons, 4);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
|
|
return value;
|
|
}
|
|
|
|
|
|
void input_init(
|
|
void)
|
|
{
|
|
/* configure the port pins for the switch */
|
|
BIT_CLEAR(DDRA, DDA0);
|
|
BIT_CLEAR(DDRA, DDA1);
|
|
BIT_CLEAR(DDRA, DDA2);
|
|
BIT_CLEAR(DDRA, DDA3);
|
|
BIT_CLEAR(DDRA, DDA4);
|
|
BIT_CLEAR(DDRA, DDA5);
|
|
BIT_CLEAR(DDRA, DDA6);
|
|
/* activate the internal pull up resistors */
|
|
BIT_SET(PORTA, PORTA0);
|
|
BIT_SET(PORTA, PORTA1);
|
|
BIT_SET(PORTA, PORTA2);
|
|
BIT_SET(PORTA, PORTA3);
|
|
BIT_SET(PORTA, PORTA4);
|
|
BIT_SET(PORTA, PORTA5);
|
|
BIT_SET(PORTA, PORTA6);
|
|
/* configure the port pins for rotary switch inputs */
|
|
#if (BDK_VERSION==4)
|
|
BIT_CLEAR(DDRB, DDB1);
|
|
BIT_CLEAR(DDRB, DDB2);
|
|
BIT_CLEAR(DDRB, DDB3);
|
|
/* activate the internal pull up resistors */
|
|
BIT_SET(PORTB, PORTB1);
|
|
BIT_SET(PORTB, PORTB2);
|
|
BIT_SET(PORTB, PORTB3);
|
|
#else
|
|
BIT_CLEAR(DDRB, DDB1);
|
|
BIT_CLEAR(DDRB, DDB2);
|
|
BIT_CLEAR(DDRB, DDB3);
|
|
BIT_CLEAR(DDRB, DDB4);
|
|
/* activate the internal pull up resistors */
|
|
BIT_SET(PORTB, PORTB1);
|
|
BIT_SET(PORTB, PORTB2);
|
|
BIT_SET(PORTB, PORTB3);
|
|
BIT_SET(PORTB, PORTB4);
|
|
#endif
|
|
mstimer_set(&Debounce_Timer, 30);
|
|
}
|