Skip to content

Commit

Permalink
Merge pull request #18 from mayank-sirotiya-imgtec/add_drivers
Browse files Browse the repository at this point in the history
platform/mikro-e/dev: add motion click driver and update relay click driver
  • Loading branch information
Abhijit A. Mahajani committed Jun 23, 2016
2 parents 89e59c8 + ac94758 commit bb4e4ba
Show file tree
Hide file tree
Showing 14 changed files with 368 additions and 7 deletions.
19 changes: 19 additions & 0 deletions platform/mikro-e/apps/test-motion/Makefile
@@ -0,0 +1,19 @@
CONTIKI_PROJECT = test-motion
CONTIKI = ../../../..

MOTION_CLICK = motion-click

CFLAGS += -DMOTION_CLICK

APPS += motion-click
APPDIRS += ../../dev

all: $(CONTIKI_PROJECT)
xc32-bin2hex $(CONTIKI_PROJECT).$(TARGET)

distclean: cleanall

cleanall:
rm -f symbols.*

include $(CONTIKI)/Makefile.include
72 changes: 72 additions & 0 deletions platform/mikro-e/apps/test-motion/test-motion.c
@@ -0,0 +1,72 @@
/*
* Copyright (c) 2016, Imagination Technologies Limited and/or its
* affiliated group companies.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/**
* \file
* A test application for motion-click.
* http://www.mikroe.com/click/motion/
*
*/

#include <contiki.h>
#include <stdio.h>
#include <lib/sensors.h>
#include "dev/common-clicks.h"
#include "dev/leds.h"
#include "sys/clock.h"
/*---------------------------------------------------------------------------*/
PROCESS(test_motion, "Motion click test");
AUTOSTART_PROCESSES(&test_motion);
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(test_motion, ev, data)
{
PROCESS_EXITHANDLER(goto exit;)
PROCESS_BEGIN();
static int i;
// static struct etimer timer;
SENSORS_ACTIVATE(motion_sensor);
while(1) {
PROCESS_WAIT_EVENT_UNTIL((ev == sensors_event));
if (data == &motion_sensor) {
printf("Motion event received\n");
leds_on(LEDS_ALL);
/* Delay for 500ms */
for(i=0;i<=500;++i) {
clock_delay_usec(1000);
}
leds_off(LEDS_ALL);
}
}
exit:
SENSORS_DEACTIVATE(motion_sensor);
PROCESS_END();
}
/*---------------------------------------------------------------------------*/
13 changes: 9 additions & 4 deletions platform/mikro-e/apps/test-relay/Makefile
@@ -1,10 +1,15 @@
CONTIKI_PROJECT=test-relay
CONTIKI=../../../..
CONTIKI_PROJECT = test-relay
CONTIKI = ../../../..

APPS += dev
APPDIRS += ../..
RELAY_CLICK = relay-click

CFLAGS += -DRELAY_CLICK

APPS += relay-click
APPDIRS += ../../dev

all: $(CONTIKI_PROJECT)
xc32-bin2hex $(CONTIKI_PROJECT).$(TARGET)

distclean: cleanall

Expand Down
2 changes: 1 addition & 1 deletion platform/mikro-e/apps/test-relay/test-relay.c
Expand Up @@ -37,7 +37,7 @@
*/

#include "contiki.h"
#include "relay-click.h"
#include "dev/common-clicks.h"
/*---------------------------------------------------------------------------*/
PROCESS(test_relay_click, "Test relay-click");
AUTOSTART_PROCESSES(&test_relay_click);
Expand Down
Binary file removed platform/mikro-e/apps/test-relay/test-relay.mikro-e
Binary file not shown.
13 changes: 12 additions & 1 deletion platform/mikro-e/contiki-mikro-e-main.c
Expand Up @@ -48,15 +48,21 @@
#include <leds.h>
#include <sensors.h>
#include "button-sensor.h"
#include "dev/common-clicks.h"

#define UART_DEBUG_BAUDRATE 115200

#ifdef MOTION_CLICK
SENSORS(&button_sensor, &button_sensor2, &motion_sensor);
#else
SENSORS(&button_sensor, &button_sensor2);
#endif

/*---------------------------------------------------------------------------*/
int
main(int argc, char **argv)
{
int32_t r;
int32_t r = 0;

pic32_init();
watchdog_init();
Expand Down Expand Up @@ -103,6 +109,11 @@ ISR(_CHANGE_NOTICE_VECTOR)
} else if(BUTTON2_CHECK_IRQ()) {
/* Button2 was pressed */
button2_isr();
#ifdef MOTION_CLICK
} else if(MOTION_SENSOR_CHECK_IRQ()) {
/* Motion was detected */
motion_sensor_isr();
#endif
}
}

Expand Down
1 change: 0 additions & 1 deletion platform/mikro-e/dev/Makefile.dev

This file was deleted.

43 changes: 43 additions & 0 deletions platform/mikro-e/dev/common-clicks.h
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2016, Imagination Technologies Limited and/or its
* affiliated group companies.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote
* products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef __COMMON_CLICKS_H__
#define __COMMON_CLICKS_H__

#ifdef MOTION_CLICK
#include "motion-click/motion-click.h"
#endif

#ifdef RELAY_CLICK
#include "relay-click/relay-click.h"
#endif

#endif /* __COMMON_CLICKS_H__ */
2 changes: 2 additions & 0 deletions platform/mikro-e/dev/motion-click/Makefile.motion-click
@@ -0,0 +1,2 @@

motion-click_src += motion-click.c
117 changes: 117 additions & 0 deletions platform/mikro-e/dev/motion-click/motion-click.c
@@ -0,0 +1,117 @@
/*
* Copyright (c) 2016, Imagination Technologies Limited and/or its affiliated
* group companies.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

/**
* \file
* Motion click driver.
* http://www.mikroe.com/click/motion/
*
*/

#include <lib/sensors.h>
#include "motion-click.h"

static struct timer debouncetimer;
static int motion_sensor_mode;
static int motion_sensor_state;
/*---------------------------------------------------------------------------*/
static void motion_sensor_read(const struct sensors_sensor *s)
{
if (!motion_sensor_state) {
if (timer_expired(&debouncetimer)) {
motion_sensor_state = 1;
/* Set a timer for 100ms to ignore false notifications */
timer_set(&debouncetimer, CLOCK_SECOND / 10);
/* Notify processes that Motion has been detected */
sensors_changed(s);
}
} else {
if (timer_expired(&debouncetimer)) {
motion_sensor_state = 0;
/* Set a timer for 100ms to ignore false notifications */
timer_set(&debouncetimer, CLOCK_SECOND / 10);
}
}
}

void motion_sensor_isr(void)
{
motion_sensor_read(&motion_sensor);
MOTION_SENSOR_CLEAR_IRQ();
}
/*---------------------------------------------------------------------------*/
static int
motion_sensor_configure(int type, int value)
{
switch(type) {
case SENSORS_HW_INIT:
/* Configure gpio pins and initialize interrupt */
MOTION_SENSOR_IRQ_INIT();
motion_sensor_state = 0;
return 1;

case SENSORS_ACTIVE:
if(value) {
if(!motion_sensor_mode) {
/* Enable interrupt for Motion sensor */
timer_set(&debouncetimer, 0);
MOTION_SENSOR_IRQ_ENABLE();
motion_sensor_mode = 1;
}
} else {
/* Disable interrupt for Motion sensor */
MOTION_SENSOR_IRQ_DISABLE();
motion_sensor_mode = 0;
}
return 1;

default:
return 0;
}
}
/*---------------------------------------------------------------------------*/
static int
motion_sensor_status(int type)
{
return motion_sensor_mode;
}
/*---------------------------------------------------------------------------*/
static int
motion_sensor_value(int type)
{
return motion_sensor_state;
}
/*---------------------------------------------------------------------------*/
SENSORS_SENSOR(motion_sensor, MOTION_SENSOR, motion_sensor_value, motion_sensor_configure,
motion_sensor_status);
/*---------------------------------------------------------------------------*/

0 comments on commit bb4e4ba

Please sign in to comment.