forked from contiki-os/contiki
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from mayank-sirotiya-imgtec/add_drivers
platform/mikro-e/dev: add motion click driver and update relay click driver
- Loading branch information
Showing
14 changed files
with
368 additions
and
7 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,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 |
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,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(); | ||
} | ||
/*---------------------------------------------------------------------------*/ |
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
Binary file not shown.
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 was deleted.
Oops, something went wrong.
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,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__ */ |
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,2 @@ | ||
|
||
motion-click_src += motion-click.c |
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,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); | ||
/*---------------------------------------------------------------------------*/ |
Oops, something went wrong.