Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions Firmware/oled/.cproject
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="cdt.managedbuild.toolchain.gnu.base.1775426510">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.toolchain.gnu.base.1775426510" moduleId="org.eclipse.cdt.core.settings" name="Default">
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.GNU_ELF" point="org.eclipse.cdt.core.BinaryParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${ProjName}" buildProperties="" id="cdt.managedbuild.toolchain.gnu.base.1775426510" name="Default" parent="org.eclipse.cdt.build.core.emptycfg">
<folderInfo id="cdt.managedbuild.toolchain.gnu.base.1775426510.1704412513" name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.base.1374300862" name="Linux GCC" superClass="cdt.managedbuild.toolchain.gnu.base">
<targetPlatform archList="all" binaryParser="org.eclipse.cdt.core.GNU_ELF" id="cdt.managedbuild.target.gnu.platform.base.367516017" name="Debug Platform" osList="linux,hpux,aix,qnx" superClass="cdt.managedbuild.target.gnu.platform.base"/>
<builder id="cdt.managedbuild.target.gnu.builder.base.572731329" managedBuildOn="false" name="Gnu Make Builder.Default" superClass="cdt.managedbuild.target.gnu.builder.base"/>
<tool id="cdt.managedbuild.tool.gnu.archiver.base.1507859944" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.base.105737180" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.base"/>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.base.1043919735" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.base"/>
<tool id="cdt.managedbuild.tool.gnu.c.linker.base.968357424" name="GCC C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.base.1201472787" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.base"/>
<tool id="cdt.managedbuild.tool.gnu.assembler.base.1049468604" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.base"/>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="edison-oled.null.900883003" name="edison-oled"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
</cproject>
3 changes: 3 additions & 0 deletions Firmware/oled/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/oled
*.o
/.settings
27 changes: 27 additions & 0 deletions Firmware/oled/.project
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>edison-oled</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>
27 changes: 27 additions & 0 deletions Firmware/oled/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
CPP=g++
CPPFLAGS=-c -Wall -m32 -g
LDFLAGS=-m32
SOURCES=\
src/spi/spi_port_edison.cpp \
src/spi/spi_device_edison.cpp \
src/oled/Edison_OLED.cpp \
src/gpio/gpio_edison.cpp \
# src/edison-oled.cpp \


OBJECTS=$(SOURCES:.cpp=.o)
EXECUTABLE=oled oled-input

all: $(SOURCES) $(EXECUTABLE)

oled: $(OBJECTS) src/edison-oled.o
$(CPP) $(LDFLAGS) $(OBJECTS) src/edison-oled.o -o $@

oled-input: $(OBJECTS) src/input-oled.o
$(CPP) $(LDFLAGS) $(OBJECTS) src/input-oled.o -o $@

.cpp.o:
$(CPP) $(CPPFLAGS) $< -o $@

clean:
rm -rf $(EXECUTABLE) `find src -type f -name '*.o'`
68 changes: 68 additions & 0 deletions Firmware/oled/oled.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/bin/bash

function oled-menu () {
local SELECTION
local SCREEN_BUF
local OPTIONS
local CHOICE
local FROM
local MAXCHOICE
local index
local icount
local button

SELECTION="$1"
SCREEN_BUF="$2"
shift 2

if [[ $# -eq 0 ]]; then
return
fi

MAXCHOICE=0
OPTIONS=()
while [[ $# -gt 0 ]]; do
OPTIONS+=("$1")
shift
[[ $MAXCHOICE -lt 6 ]] && MAXCHOICE=$(( $MAXCHOICE + 1 ))
done

FROM=0
CHOICE=0
while true; do
icount=0
oled clear save "${SCREEN_BUF}"
for o in ${OPTIONS[@]:$FROM}; do
oled load "${SCREEN_BUF}" setCursor 6 $(( $icount * 8 )) print "$o" save "${SCREEN_BUF}"
icount=$(($icount + 1))
[[ $icount -eq 6 ]] && break
done
oled load "${SCREEN_BUF}" \
line 0 $(( $CHOICE * 8 + 1 )) 5 $(( $CHOICE * 8 + 3 )) \
line 0 $(( $CHOICE * 8 + 1 )) 0 $(( $CHOICE * 8 + 5 )) \
line 0 $(( $CHOICE * 8 + 5 )) 5 $(( $CHOICE * 8 + 3 )) \
display
for button in $(oled wait buttons); do
case $button in
U)
CHOICE=$(($CHOICE - 1))
[[ $CHOICE -eq -1 ]] && [[ $FROM -gt 0 ]] && FROM=$(( $FROM - 1 ))
[[ $CHOICE -eq -1 ]] && CHOICE=$(( $CHOICE + 1 ))
;;
D)
CHOICE=$(($CHOICE + 1))
[[ $CHOICE -eq $MAXCHOICE ]] && [[ $FROM -lt $(( ${#OPTIONS[@]} - 6)) ]] && FROM=$(( FROM + 1 ))
[[ $CHOICE -eq $MAXCHOICE ]] && CHOICE=$(( $CHOICE - 1 ))
;;
B)
rm "${SCREEN_BUF}"
oled clear display
return
;;
A)
$SELECTION $(( $CHOICE + $FROM ))
;;
esac
done
done
}
151 changes: 151 additions & 0 deletions Firmware/oled/src/edison-oled.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
//============================================================================
// Name : edison-oled.cpp
// Author : Robin Kirkman
// Version :
// Copyright : GPL
// Description : Hello World in C, Ansi-style
//============================================================================

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#include "oled/Edison_OLED.h"
#include "gpio/gpio.h"

// Define an edOLED object:
edOLED oled;

// Pin definitions:
// All buttons have pull-up resistors on-board, so just declare
// them as regular INPUT's
gpio BUTTON_UP(47, INPUT);
gpio BUTTON_DOWN(44, INPUT);
gpio BUTTON_LEFT(165, INPUT);
gpio BUTTON_RIGHT(45, INPUT);
gpio BUTTON_SELECT(48, INPUT);
gpio BUTTON_A(49, INPUT);
gpio BUTTON_B(46, INPUT);

void eval(char ***cmd);

int main(int argc, char **argv) {
char **cmd = (char**) malloc(sizeof(char*) * argc);
memcpy(cmd, argv+1, sizeof(char*) * (argc - 1));
cmd[argc-1] = 0;

while(*cmd)
eval(&cmd);
}

#define NEXT(c) (*((*c)++))
#define INEXT(c) (atoi(NEXT(c)))

int buttons_value(void);

void eval(char ***cmd) {
char *c = NEXT(cmd);
if(!strcmp("begin", c))
oled.begin();
else if(!strcmp("print", c))
oled.print(NEXT(cmd));
else if(!strcmp("clear", c))
oled.clear(PAGE);
else if(!strcmp("invert", c))
oled.invert(INEXT(cmd));
else if(!strcmp("display", c))
oled.display();
else if(!strcmp("setCursor", c)) {
int x = INEXT(cmd);
int y = INEXT(cmd);
oled.setCursor(x, y);
} else if(!strcmp("pixel", c)) {
int x = INEXT(cmd);
int y = INEXT(cmd);
oled.pixel(x, y);
} else if(!strcmp("line", c)) {
int x0 = INEXT(cmd);
int y0 = INEXT(cmd);
int x1 = INEXT(cmd);
int y1 = INEXT(cmd);
oled.line(x0, y0, x1, y1);
} else if(!strcmp("rect", c)) {
int x = INEXT(cmd);
int y = INEXT(cmd);
int width = INEXT(cmd);
int height = INEXT(cmd);
oled.rect(x, y, width, height);
} else if(!strcmp("rectFill", c)) {
int x = INEXT(cmd);
int y = INEXT(cmd);
int width = INEXT(cmd);
int height = INEXT(cmd);
oled.rectFill(x, y, width, height);
} else if(!strcmp("circle", c)) {
int x = INEXT(cmd);
int y = INEXT(cmd);
int radius = INEXT(cmd);
oled.circle(x, y, radius);
} else if(!strcmp("circleFill", c)) {
int x = INEXT(cmd);
int y = INEXT(cmd);
int radius = INEXT(cmd);
oled.circleFill(x, y, radius);
} else if(!strcmp("setColor", c))
oled.setColor(INEXT(cmd));
else if(!strcmp("setDrawMode", c))
oled.setDrawMode(INEXT(cmd));
else if(!strcmp("buttons", c)) {
if(!BUTTON_UP.pinRead())
printf("U ");
if(!BUTTON_DOWN.pinRead())
printf("D ");
if(!BUTTON_LEFT.pinRead())
printf("L ");
if(!BUTTON_RIGHT.pinRead())
printf("R ");
if(!BUTTON_SELECT.pinRead())
printf("S ");
if(!BUTTON_A.pinRead())
printf("A ");
if(!BUTTON_B.pinRead())
printf("B ");
printf("\n");
} else if(!strcmp("wait", c)) {
for(int bv = buttons_value(); bv == buttons_value();)
usleep(100000);
} else if(!strcmp("displayoff", c)) {
oled.command(DISPLAYOFF);
} else if(!strcmp("displayon", c)) {
oled.command(DISPLAYON);
} else if(!strcmp("save", c)) {
int fd = creat(NEXT(cmd), S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR);
if(fd != -1) {
write(fd, oled.screenmemory, 384);
close(fd);
}
} else if(!strcmp("load", c)) {
int fd = open(NEXT(cmd), O_RDONLY);
if(fd != -1) {
read(fd, oled.screenmemory, 384);
close(fd);
}
}
}

int buttons_value(void) {
int v = 0;
v |= BUTTON_UP.pinRead() << 0;
v |= BUTTON_DOWN.pinRead() << 1;
v |= BUTTON_LEFT.pinRead() << 2;
v |= BUTTON_RIGHT.pinRead() << 3;
v |= BUTTON_SELECT.pinRead() << 4;
v |= BUTTON_A.pinRead() << 5;
v |= BUTTON_B.pinRead() << 6;
return v;

}
53 changes: 53 additions & 0 deletions Firmware/oled/src/gpio/gpio.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#ifndef __gpio_h__
#define __gpio_h__

/* Values that can be taken by a pin. LOW and HIGH are obvious, and NONE is
provided as a useful alternative that may never be used. */
enum PIN_VALUE
{
LOW,
HIGH,
NONE,
};

/* Pin modes. InPUT and OUTPUT should be nearly universal; the others may or
may not be needed depending on platform. On platforms where a particular
value isn't allowed, an exception will be thrown. */
enum PIN_MODE
{
INPUT,
OUTPUT,
INPUT_PU,
INPUT_PD,
SPI,
I2C,
PWM,
ADC,
UART,
};

/* This is the top-level class for a gpio pin. It should be suitable for all
platforms, since it provides the minimum needed for a GPIO pin. All
functions will throw exceptions defined in the sparklibs.h file. */
class gpio
{
public:
gpio(int pinID, PIN_MODE initMode, PIN_VALUE initVal=LOW);
~gpio();
void pinMode(PIN_MODE newMode);
void pinWrite(PIN_VALUE newLevel);
PIN_VALUE pinRead();

private:
/* The gpioHelper is provided to provide a place to hide the
down-and-dirty implementation details that vary from one architecture
to the next; that way, this class doesn't need to provide functions
for, say, file IO which wouldn't get used in an environment without a
filesystem. */
class gpioHelper *helper;
int _pinNumber;
gpio();
};

#endif

Loading