Add LED strip example

.. not yet working
This commit is contained in:
Ralf Schlatterbeck 2015-01-25 18:31:17 +01:00
parent baaa2c5741
commit e946cd4c13
10 changed files with 479 additions and 5 deletions

3
.gitmodules vendored
View file

@ -4,3 +4,6 @@
[submodule "tools/cc2538-bsl"]
path = tools/cc2538-bsl
url = https://github.com/JelmerT/cc2538-bsl.git
[submodule "platform/osd-merkur/dev/LED_Strip_Suli"]
path = platform/osd-merkur/dev/LED_Strip_Suli
url = https://github.com/Seeed-Studio/LED_Strip_Suli

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, Ralf Schlatterbeck Open Source Consulting
* Copyright (c) 2014-15, Ralf Schlatterbeck Open Source Consulting
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -177,7 +177,6 @@ static inline uint32_t micros (void)
* behaviour of arduino implementation.
*/
#define millis() (((uint32_t)clock_time())*1000L/CLOCK_SECOND)
#define micros() (clock_seconds()*1000L+
#define delay(ms) clock_delay_msec(ms)
#define delayMicroseconds(us) clock_delay_usec(us)

View file

@ -0,0 +1,94 @@
SERIAL=/dev/ttyUSB0
ifeq ($(TARGET), osd-merkur)
PLATFORM_FILES= avr-size led-strip.osd-merkur.hex \
led-strip.osd-merkur.eep
endif
all: led-strip $(PLATFORM_FILES)
CONTIKI=../../..
# Contiki IPv6 configuration
WITH_UIP6=1
UIP_CONF_IPV6=1
CFLAGS += -DUIP_CONF_IPV6=1
CFLAGS += -DUIP_CONF_IPV6_RPL=1
CFLAGS += -DPROJECT_CONF_H=\"project-conf.h\"
# automatically build RESTful resources
REST_RESOURCES_DIR = ./resources
REST_RESOURCES_DIR_COMMON = ../resources-common
REST_RESOURCES_FILES= $(notdir \
$(shell find $(REST_RESOURCES_DIR_COMMON) -name '*.c') \
)
PROJECTDIRS += $(REST_RESOURCES_DIR_COMMON)
PROJECT_SOURCEFILES += $(REST_RESOURCES_FILES)
# linker optimizations
SMALL=1
# REST Engine shall use Erbium CoAP implementation
APPS += er-coap
APPS += rest-engine
APPS += json json-resource
# optional rules to get assembly
#CUSTOM_RULE_C_TO_OBJECTDIR_O = 1
#CUSTOM_RULE_S_TO_OBJECTDIR_O = 1
include $(CONTIKI)/Makefile.include
# minimal-net target is currently broken in Contiki
ifeq ($(TARGET), minimal-net)
CFLAGS += -DHARD_CODED_ADDRESS=\"fdfd::10\"
${info INFO: compiling with large buffers}
CFLAGS += -DUIP_CONF_BUFFER_SIZE=1300
CFLAGS += -DREST_MAX_CHUNK_SIZE=1024
CFLAGS += -DCOAP_MAX_HEADER_SIZE=176
CFLAGS += -DUIP_CONF_IPV6_RPL=0
endif
# optional rules to get assembly
#$(OBJECTDIR)/%.o: asmdir/%.S
# $(CC) $(CFLAGS) -MMD -c $< -o $@
# @$(FINALIZE_DEPENDENCY)
#
#asmdir/%.S: %.c
# $(CC) $(CFLAGS) -MMD -S $< -o $@
# border router rules
$(CONTIKI)/tools/tunslip6: $(CONTIKI)/tools/tunslip6.c
(cd $(CONTIKI)/tools && $(MAKE) tunslip6)
connect-router: $(CONTIKI)/tools/tunslip6
sudo $(CONTIKI)/tools/tunslip6 aaaa::1/64
connect-router-cooja: $(CONTIKI)/tools/tunslip6
sudo $(CONTIKI)/tools/tunslip6 -a 127.0.0.1 -p 60001 aaaa::1/64
connect-router-native: $(CONTIKI)/examples/ipv6/native-border-router/border-router.native
sudo $(CONTIKI)/exmples/ipv6/native-border-router/border-router.native -a 127.0.0.1 -p 60001 aaaa::1/64
connect-minimal:
sudo ip address add fdfd::1/64 dev tap0
avr-size: led-strip.osd-merkur
avr-size -C --mcu=MCU=atmega128rfa1 led-strip.osd-merkur
led-strip.osd-merkur.hex: led-strip.osd-merkur
avr-objcopy -j .text -j .data -O ihex led-strip.osd-merkur \
led-strip.osd-merkur.hex
led-strip.osd-merkur.eep: led-strip.osd-merkur
avr-objcopy -j .eeprom --set-section-flags=.eeprom="alloc,load" \
--change-section-lma .eeprom=0 -O ihex \
led-strip.osd-merkur led-strip.osd-merkur.eep
flash: led-strip.osd-merkur.hex led-strip.osd-merkur.eep
avrdude -pm128rfa1 -c arduino -P$(SERIAL) -b57600 -e -U \
flash:w:led-strip.osd-merkur.hex:a -U \
eeprom:w:led-strip.osd-merkur.eep:a
.PHONY: flash avr-size

View file

@ -0,0 +1,2 @@
#!/bin/bash
make flash TARGET=osd-merkur

View file

@ -0,0 +1,160 @@
/*
* Copyright (c) 2014-15, Ralf Schlatterbeck Open Source Consulting
* 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 Institute 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 INSTITUTE 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 INSTITUTE 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.
*
* This file is part of the Contiki operating system.
*/
/**
* \file
* LED-strip driver for Seeed Studio LED-Strip
* \author
* Ralf Schlatterbeck <rsc@runtux.com>
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include "contiki.h"
#include "contiki-net.h"
#include "rest-engine.h"
#include "generic_resource.h"
/*
* Resources to be activated need to be imported through the extern keyword.
* The build system automatically compiles the resources in the
* corresponding sub-directory.
*/
#if PLATFORM_HAS_BATTERY
#include "dev/battery-sensor.h"
extern resource_t res_battery;
#endif
#if PLATFORM_HAS_RADIO
#include "dev/radio-sensor.h"
extern resource_t res_radio;
#endif
#include "LED_Strip_Suli.h"
int color_rgb [3] = {0, 255, 0};
static uint8_t name_to_offset (const char * name)
{
uint8_t offset = 0;
if (0 == strcmp (name, "green")) {
offset = 1;
} else if (0 == strcmp (name, "blue")) {
offset = 2;
}
return offset;
}
static size_t
color_to_string (const char *name, uint8_t is_json, char *buf, size_t bsize)
{
char *fmt = "%d";
if (is_json) {
fmt = "\"%d\"";
}
return snprintf (buf, bsize, fmt, color_rgb [name_to_offset (name)]);
}
void color_from_string (const char *name, const char *s)
{
color_rgb [name_to_offset (name)] = atoi (s);
led_strip_begin ();
led_strip_set_color (color_rgb [0], color_rgb [1], color_rgb [2]);
led_strip_end ();
printf ("Set to R:%d G:%d B:%d\n"
, color_rgb [0], color_rgb [1], color_rgb [2])
;
}
GENERIC_RESOURCE
( red
, RED_LED
, s
, color_from_string
, color_to_string
);
GENERIC_RESOURCE
( green
, GREEN_LED
, s
, color_from_string
, color_to_string
);
GENERIC_RESOURCE
( blue
, BLUE_LED
, s
, color_from_string
, color_to_string
);
PROCESS(led_strip, "LED Strip Example");
AUTOSTART_PROCESSES(&led_strip);
PROCESS_THREAD(led_strip, ev, data)
{
PROCESS_BEGIN();
/* Initialize the REST engine. */
rest_init_engine ();
printf ("Initialized\n");
led_strip_init (3, 14);
led_strip_begin ();
led_strip_set_color (color_rgb [0], color_rgb [1], color_rgb [2]);
led_strip_end ();
printf ("Set to R:%d G:%d B:%d\n"
, color_rgb [0], color_rgb [1], color_rgb [2])
;
/* Activate the application-specific resources. */
#if PLATFORM_HAS_BATTERY
SENSORS_ACTIVATE(battery_sensor);
rest_activate_resource (&res_battery,"s/battery");
#endif
rest_activate_resource (&res_red, "led/R");
rest_activate_resource (&res_green, "led/G");
rest_activate_resource (&res_blue, "led/B");
/* Define application-specific events here. */
/* Don't do anything for now, everything done in resources */
while(1) {
PROCESS_WAIT_EVENT();
} /* while (1) */
PROCESS_END();
}

View file

@ -0,0 +1,101 @@
/*
* Copyright (c) 2013, Matthias Kovatsch
* 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 Institute 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 INSTITUTE 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 INSTITUTE 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.
*
*
*/
#ifndef PROJECT_ERBIUM_CONF_H_
#define PROJECT_ERBIUM_CONF_H_
#define PLATFORM_HAS_INFO 1
#define PLATFORM_HAS_BATTERY 1
#define PLATFORM_HAS_DS1820 1
#define PLATFORM_HAS_DHT11HUM 1
//#define PLATFORM_HAS_DHT11TEMP 1
#define PLATFORM_HAS_LEDS 1
/* Some platforms have weird includes. */
#undef IEEE802154_CONF_PANID
/* Disabling RDC for demo purposes. Core updates often require more memory. */
/* For projects, optimize memory and enable RDC again. */
// #undef NETSTACK_CONF_RDC
//#define NETSTACK_CONF_RDC nullrdc_driver
/* Increase rpl-border-router IP-buffer when using more than 64. */
#undef REST_MAX_CHUNK_SIZE
#define REST_MAX_CHUNK_SIZE 64
/* Estimate your header size, especially when using Proxy-Uri. */
/*
#undef COAP_MAX_HEADER_SIZE
#define COAP_MAX_HEADER_SIZE 70
*/
/* The IP buffer size must fit all other hops, in particular the border router. */
#undef UIP_CONF_BUFFER_SIZE
#define UIP_CONF_BUFFER_SIZE 256
/* Multiplies with chunk size, be aware of memory constraints. */
#undef COAP_MAX_OPEN_TRANSACTIONS
#define COAP_MAX_OPEN_TRANSACTIONS 4
/* Must be <= open transaction number, default is COAP_MAX_OPEN_TRANSACTIONS-1. */
/*
#undef COAP_MAX_OBSERVERS
#define COAP_MAX_OBSERVERS 2
*/
/* Filtering .well-known/core per query can be disabled to save space. */
/*
#undef COAP_LINK_FORMAT_FILTERING
#define COAP_LINK_FORMAT_FILTERING 0
*/
/* Save some memory for the sky platform. */
/*
#undef NBR_TABLE_CONF_MAX_NEIGHBORS
#define NBR_TABLE_CONF_MAX_NEIGHBORS 10
#undef UIP_CONF_MAX_ROUTES
#define UIP_CONF_MAX_ROUTES 10
*/
/* Reduce 802.15.4 frame queue to save RAM. */
/*
#undef QUEUEBUF_CONF_NUM
#define QUEUEBUF_CONF_NUM 4
*/
/*
#undef SICSLOWPAN_CONF_FRAG
#define SICSLOWPAN_CONF_FRAG 1
*/
#endif /* PROJECT_ERBIUM_CONF_H_ */

5
examples/osd/led-strip/run.sh Executable file
View file

@ -0,0 +1,5 @@
#!/bin/bash
# For the new bootloader (using a jump-table) you want to use
# BOOTLOADER_GET_MAC=0x0001ff80 (which is the current default)
make clean TARGET=osd-merkur
make TARGET=osd-merkur BOOTLOADER_GET_MAC=0x0001f3a0

View file

@ -1,4 +1,4 @@
CONTIKI_TARGET_DIRS = . dev apps net loader
CONTIKI_TARGET_DIRS = . dev dev/LED_Strip_Suli apps net loader
CONTIKI_CORE=contiki-main
CONTIKI_TARGET_MAIN = ${CONTIKI_CORE}.o
@ -28,6 +28,9 @@ CONTIKI_TARGET_SOURCEFILES += servo.c servo-sensor.c
CONTIKI_TARGET_SOURCEFILES += relay.c relay-sensor.c
# Arduino
CONTIKI_TARGET_SOURCEFILES += wiring_digital.c
CONTIKI_TARGET_SOURCEFILES += LED_Strip_Suli.c
SULI_DIR=$(CONTIKI)/platform/$(TARGET)/dev/LED_Strip_Suli
CONTIKIBOARD=.
BOOTLOADER_START = 0x1F000
@ -67,8 +70,8 @@ LDFLAGS += -Wl,--defsym,bootloader_get_mac=$(BOOTLOADER_GET_MAC)
include $(CONTIKIAVR)/Makefile.avr
include $(CONTIKIAVR)/radio/Makefile.radio
MODULES += core/net/mac core/net core/net/mac/sicslowmac core/net/mac/contikimac \
core/net/llsec \
MODULES += core/net/mac core/net core/net/mac/sicslowmac \
core/net/mac/contikimac core/net/llsec \
# core/net/ipv6 core/net/ipv4 core/net/ip \
# core/net/rime \
# core/net/rpl \

@ -0,0 +1 @@
Subproject commit 81c254d66305abd993ce139f6aea3647a45781dc

View file

@ -0,0 +1,106 @@
/*
* Copyright (c) 2015, Ralf Schlatterbeck Open Source Consulting
* 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 Institute 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 INSTITUTE 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 INSTITUTE 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.
*
* This file is part of the Contiki operating system.
*/
/**
* \defgroup Suli compatibility
*
* Seeed Unified Library Interface for Contiki OS
* See also https://github.com/Seeed-Studio/Suli
*
* Note: For now this only implements what we need to the LED_Strip example
* working. We're re-using existing Arduino wrappers where possible.
*
* @{
*/
/**
* \file
* Header file for Seeed compatibility
* \author
* Ralf Schlatterbeck <rsc@runtux.com>
*/
#include <Arduino.h>
#ifdef __cplusplus
extern "C" {
#endif
#define suli_delay_ms(ms) clock_delay_msec(ms)
#define suli_delay_us(us) clock_delay_usec(us)
/* These are used by Suli */
typedef uint8_t uint8;
typedef uint16_t uint16;
typedef uint32_t uint32;
typedef int16_t int16;
typedef int32_t int32;
typedef int IO_T; // IO type
typedef int PIN_T; // pin name
typedef int DIR_T; // pin direction
/* From Arduino.h */
#define HAL_PIN_INPUT INPUT
#define HAL_PIN_OUTPUT OUTPUT
#define HAL_PIN_HIGH HIGH
#define HAL_PIN_LOW LOW
static inline void suli_pin_init (IO_T *pio, PIN_T pin)
{
*pio = pin;
}
static inline void suli_pin_dir (IO_T *pio, DIR_T dir)
{
pinMode (*pio, dir);
}
static inline void suli_pin_write (IO_T *pio, int16 state)
{
digitalWrite (*pio, state);
}
static inline int16 suli_pin_read (IO_T *pio)
{
return digitalRead (*pio);
}
#ifdef __cplusplus
} // extern "C"
#endif
/*
* VI settings, see coding style
* ex:ts=8:et:sw=2
*/
/** @} */