Refactored for teensy 4.0, xEvi hardware
- Switched to platformio, ino -> cpp - MPRLS for pressure sensor - Added basic ICM support - Removed widi, battery, other features not supported in xEvi - Removed legacy options/processing - Added LED strip support - Added encoder support - Reworked menu code to use encoders/be more flexible
This commit is contained in:
parent
c58c3f9e46
commit
01d193c9b3
92 changed files with 69119 additions and 73272 deletions
|
|
@ -1,85 +1,85 @@
|
|||
CC=clang
|
||||
CXX=clang++
|
||||
|
||||
CFLAGS=-Wall -Wextra -Wpedantic -Wno-gnu -mmacosx-version-min=10.9 -F/Library/Frameworks
|
||||
CFLAGS += -DARDUINO=10808 -DTEENSYDUINO=146 -D__MK20DX256__ -DUSB_MIDI
|
||||
|
||||
RELEASE ?= 0
|
||||
ifeq ($(RELEASE), 1)
|
||||
CFLAGS +=-O3
|
||||
else
|
||||
CFLAGS += -O0 -g
|
||||
endif
|
||||
|
||||
|
||||
CXXFLAGS= $(CFLAGS) -std=c++14
|
||||
|
||||
LIBS=-framework SDL2 -lc++ -lc -framework OpenGL
|
||||
LDFLAGS=-macosx_version_min 10.9 -rpath @executable_path/../Frameworks
|
||||
|
||||
SYSINC = ./include
|
||||
INCS = ../NuEVI ./include ./imgui ./gl3w
|
||||
|
||||
INCDIRS = $(addprefix -isystem ,$(SYSINC))
|
||||
INCDIRS += $(addprefix -I,$(INCS))
|
||||
|
||||
|
||||
TARGET=nuevisim
|
||||
|
||||
CXXFILES= ../NuEVI/menu.cpp \
|
||||
../NuEVI/adjustmenu.cpp \
|
||||
../NuEVI/midi.cpp \
|
||||
../NuEVI/settings.cpp \
|
||||
../NuEVI/led.cpp \
|
||||
src/nuevisim.cpp \
|
||||
src/simeeprom.cpp \
|
||||
src/Print.cpp \
|
||||
src/simserial.cpp \
|
||||
src/simwire.cpp \
|
||||
src/simusbmidi.cpp \
|
||||
src/filters.cpp \
|
||||
src/Adafruit_GFX_sim.cpp \
|
||||
src/Adafruit_SSD1306_sim.cpp \
|
||||
src/Adafruit_MPR121_sim.cpp \
|
||||
imgui/imgui.cpp \
|
||||
imgui/imgui_draw.cpp \
|
||||
imgui/imgui_widgets.cpp \
|
||||
imgui/examples/imgui_impl_sdl.cpp \
|
||||
imgui/examples/imgui_impl_opengl3.cpp
|
||||
|
||||
|
||||
CFILES= gl3w/gl3w.c
|
||||
|
||||
OBJS=$(CXXFILES:.cpp=.o) $(CFILES:.c=.o)
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
nuevisim: $(OBJS)
|
||||
$(LD) $(LDFLAGS) -o $(TARGET) $(LIBS) $^
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) $(INCDIRS) -c -o $@ $<
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) $(INCDIRS) -c -o $@ $<
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET) $(OBJS) *.o
|
||||
|
||||
.PHONY: all
|
||||
|
||||
|
||||
# Dependecies
|
||||
DEPS=make.deps
|
||||
|
||||
.PHONY: deps mrproper
|
||||
mrproper: clean
|
||||
rm $(DEPS)
|
||||
deps: $(DEPS)
|
||||
|
||||
H_DEPS=$(wildcard src/*.h) $(wildcard ../NuEVI/*.h)
|
||||
|
||||
make.deps: $(CXXFILES) $(H_DEPS)
|
||||
$(CXX) $(CXXFLAGS) -Wno-deprecated $(INCDIRS) -MM $(DEPS_HS) $^ > $@
|
||||
|
||||
-include .deps/*
|
||||
CC=clang
|
||||
CXX=clang++
|
||||
|
||||
CFLAGS=-Wall -Wextra -Wpedantic -Wno-gnu -mmacosx-version-min=10.9 -F/Library/Frameworks
|
||||
CFLAGS += -DARDUINO=10808 -DTEENSYDUINO=146 -D__MK20DX256__ -DUSB_MIDI
|
||||
|
||||
RELEASE ?= 0
|
||||
ifeq ($(RELEASE), 1)
|
||||
CFLAGS +=-O3
|
||||
else
|
||||
CFLAGS += -O0 -g
|
||||
endif
|
||||
|
||||
|
||||
CXXFLAGS= $(CFLAGS) -std=c++14
|
||||
|
||||
LIBS=-framework SDL2 -lc++ -lc -framework OpenGL
|
||||
LDFLAGS=-macosx_version_min 10.9 -rpath @executable_path/../Frameworks
|
||||
|
||||
SYSINC = ./include
|
||||
INCS = ../NuEVI ./include ./imgui ./gl3w
|
||||
|
||||
INCDIRS = $(addprefix -isystem ,$(SYSINC))
|
||||
INCDIRS += $(addprefix -I,$(INCS))
|
||||
|
||||
|
||||
TARGET=nuevisim
|
||||
|
||||
CXXFILES= ../NuEVI/menu.cpp \
|
||||
../NuEVI/adjustmenu.cpp \
|
||||
../NuEVI/midi.cpp \
|
||||
../NuEVI/settings.cpp \
|
||||
../NuEVI/led.cpp \
|
||||
src/nuevisim.cpp \
|
||||
src/simeeprom.cpp \
|
||||
src/Print.cpp \
|
||||
src/simserial.cpp \
|
||||
src/simwire.cpp \
|
||||
src/simusbmidi.cpp \
|
||||
src/filters.cpp \
|
||||
src/Adafruit_GFX_sim.cpp \
|
||||
src/Adafruit_SSD1306_sim.cpp \
|
||||
src/Adafruit_MPR121_sim.cpp \
|
||||
imgui/imgui.cpp \
|
||||
imgui/imgui_draw.cpp \
|
||||
imgui/imgui_widgets.cpp \
|
||||
imgui/examples/imgui_impl_sdl.cpp \
|
||||
imgui/examples/imgui_impl_opengl3.cpp
|
||||
|
||||
|
||||
CFILES= gl3w/gl3w.c
|
||||
|
||||
OBJS=$(CXXFILES:.cpp=.o) $(CFILES:.c=.o)
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
nuevisim: $(OBJS)
|
||||
$(LD) $(LDFLAGS) -o $(TARGET) $(LIBS) $^
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(CFLAGS) $(INCDIRS) -c -o $@ $<
|
||||
|
||||
%.o: %.cpp
|
||||
$(CXX) $(CXXFLAGS) $(INCDIRS) -c -o $@ $<
|
||||
|
||||
clean:
|
||||
rm -f $(TARGET) $(OBJS) *.o
|
||||
|
||||
.PHONY: all
|
||||
|
||||
|
||||
# Dependecies
|
||||
DEPS=make.deps
|
||||
|
||||
.PHONY: deps mrproper
|
||||
mrproper: clean
|
||||
rm $(DEPS)
|
||||
deps: $(DEPS)
|
||||
|
||||
H_DEPS=$(wildcard src/*.h) $(wildcard ../NuEVI/*.h)
|
||||
|
||||
make.deps: $(CXXFILES) $(H_DEPS)
|
||||
$(CXX) $(CXXFLAGS) -Wno-deprecated $(INCDIRS) -MM $(DEPS_HS) $^ > $@
|
||||
|
||||
-include .deps/*
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -1,233 +1,233 @@
|
|||
#ifndef _ADAFRUIT_GFX_H
|
||||
#define _ADAFRUIT_GFX_H
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#include "Print.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
#include "gfxfont.h"
|
||||
|
||||
/// A generic graphics superclass that can handle all sorts of drawing. At a minimum you can subclass and provide drawPixel(). At a maximum you can do a ton of overriding to optimize. Used for any/all Adafruit displays!
|
||||
class Adafruit_GFX : public Print {
|
||||
|
||||
public: // Exposed simulation variables...
|
||||
bool dimmed_;
|
||||
bool enabled_;
|
||||
bool inverted_;
|
||||
bool dirty_;
|
||||
|
||||
public:
|
||||
|
||||
Adafruit_GFX(int16_t w, int16_t h); // Constructor
|
||||
|
||||
// This MUST be defined by the subclass:
|
||||
virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; ///< Virtual drawPixel() function to draw to the screen/framebuffer/etc, must be overridden in subclass. @param x X coordinate. @param y Y coordinate. @param color 16-bit pixel color.
|
||||
|
||||
// TRANSACTION API / CORE DRAW API
|
||||
// These MAY be overridden by the subclass to provide device-specific
|
||||
// optimized code. Otherwise 'generic' versions are used.
|
||||
virtual void startWrite(void);
|
||||
virtual void writePixel(int16_t x, int16_t y, uint16_t color);
|
||||
virtual void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
|
||||
virtual void writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
|
||||
virtual void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
|
||||
virtual void writeLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
|
||||
virtual void endWrite(void);
|
||||
|
||||
// CONTROL API
|
||||
// These MAY be overridden by the subclass to provide device-specific
|
||||
// optimized code. Otherwise 'generic' versions are used.
|
||||
virtual void setRotation(uint8_t r);
|
||||
virtual void invertDisplay(boolean i);
|
||||
|
||||
// BASIC DRAW API
|
||||
// These MAY be overridden by the subclass to provide device-specific
|
||||
// optimized code. Otherwise 'generic' versions are used.
|
||||
virtual void
|
||||
// It's good to implement those, even if using transaction API
|
||||
drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
|
||||
drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
|
||||
fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color),
|
||||
fillScreen(uint16_t color),
|
||||
// Optional and probably not necessary to change
|
||||
drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color),
|
||||
drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
|
||||
|
||||
// These exist only with Adafruit_GFX (no subclass overrides)
|
||||
void
|
||||
drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
|
||||
drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
|
||||
uint16_t color),
|
||||
fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
|
||||
fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
|
||||
int16_t delta, uint16_t color),
|
||||
drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
|
||||
int16_t x2, int16_t y2, uint16_t color),
|
||||
fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
|
||||
int16_t x2, int16_t y2, uint16_t color),
|
||||
drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
|
||||
int16_t radius, uint16_t color),
|
||||
fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
|
||||
int16_t radius, uint16_t color),
|
||||
drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
|
||||
int16_t w, int16_t h, uint16_t color),
|
||||
drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
|
||||
int16_t w, int16_t h, uint16_t color, uint16_t bg),
|
||||
drawBitmap(int16_t x, int16_t y, uint8_t *bitmap,
|
||||
int16_t w, int16_t h, uint16_t color),
|
||||
drawBitmap(int16_t x, int16_t y, uint8_t *bitmap,
|
||||
int16_t w, int16_t h, uint16_t color, uint16_t bg),
|
||||
drawXBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
|
||||
int16_t w, int16_t h, uint16_t color),
|
||||
drawGrayscaleBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
|
||||
int16_t w, int16_t h),
|
||||
drawGrayscaleBitmap(int16_t x, int16_t y, uint8_t *bitmap,
|
||||
int16_t w, int16_t h),
|
||||
drawGrayscaleBitmap(int16_t x, int16_t y,
|
||||
const uint8_t bitmap[], const uint8_t mask[],
|
||||
int16_t w, int16_t h),
|
||||
drawGrayscaleBitmap(int16_t x, int16_t y,
|
||||
uint8_t *bitmap, uint8_t *mask, int16_t w, int16_t h),
|
||||
drawRGBBitmap(int16_t x, int16_t y, const uint16_t bitmap[],
|
||||
int16_t w, int16_t h),
|
||||
drawRGBBitmap(int16_t x, int16_t y, uint16_t *bitmap,
|
||||
int16_t w, int16_t h),
|
||||
drawRGBBitmap(int16_t x, int16_t y,
|
||||
const uint16_t bitmap[], const uint8_t mask[],
|
||||
int16_t w, int16_t h),
|
||||
drawRGBBitmap(int16_t x, int16_t y,
|
||||
uint16_t *bitmap, uint8_t *mask, int16_t w, int16_t h),
|
||||
drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color,
|
||||
uint16_t bg, uint8_t size),
|
||||
setCursor(int16_t x, int16_t y),
|
||||
setTextColor(uint16_t c),
|
||||
setTextColor(uint16_t c, uint16_t bg),
|
||||
setTextSize(uint8_t s),
|
||||
setTextWrap(boolean w),
|
||||
cp437(boolean x=true),
|
||||
setFont(const GFXfont *f = NULL),
|
||||
getTextBounds(const char *string, int16_t x, int16_t y,
|
||||
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h),
|
||||
getTextBounds(const __FlashStringHelper *s, int16_t x, int16_t y,
|
||||
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h),
|
||||
getTextBounds(const String &str, int16_t x, int16_t y,
|
||||
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);
|
||||
|
||||
|
||||
#if ARDUINO >= 100
|
||||
virtual size_t write(uint8_t);
|
||||
#else
|
||||
virtual void write(uint8_t);
|
||||
#endif
|
||||
|
||||
int16_t height(void) const;
|
||||
int16_t width(void) const;
|
||||
|
||||
uint8_t getRotation(void) const;
|
||||
|
||||
// get current cursor position (get rotation safe maximum values, using: width() for x, height() for y)
|
||||
int16_t getCursorX(void) const;
|
||||
int16_t getCursorY(void) const;
|
||||
|
||||
protected:
|
||||
void
|
||||
charBounds(char c, int16_t *x, int16_t *y,
|
||||
int16_t *minx, int16_t *miny, int16_t *maxx, int16_t *maxy);
|
||||
const int16_t
|
||||
WIDTH, ///< This is the 'raw' display width - never changes
|
||||
HEIGHT; ///< This is the 'raw' display height - never changes
|
||||
int16_t
|
||||
_width, ///< Display width as modified by current rotation
|
||||
_height, ///< Display height as modified by current rotation
|
||||
cursor_x, ///< x location to start print()ing text
|
||||
cursor_y; ///< y location to start print()ing text
|
||||
uint16_t
|
||||
textcolor, ///< 16-bit background color for print()
|
||||
textbgcolor; ///< 16-bit text color for print()
|
||||
uint8_t
|
||||
textsize, ///< Desired magnification of text to print()
|
||||
rotation; ///< Display rotation (0 thru 3)
|
||||
boolean
|
||||
wrap, ///< If set, 'wrap' text at right edge of display
|
||||
_cp437; ///< If set, use correct CP437 charset (default is off)
|
||||
GFXfont
|
||||
*gfxFont; ///< Pointer to special font
|
||||
};
|
||||
|
||||
|
||||
/// A simple drawn button UI element
|
||||
class Adafruit_GFX_Button {
|
||||
|
||||
public:
|
||||
Adafruit_GFX_Button(void);
|
||||
// "Classic" initButton() uses center & size
|
||||
void initButton(Adafruit_GFX *gfx, int16_t x, int16_t y,
|
||||
uint16_t w, uint16_t h, uint16_t outline, uint16_t fill,
|
||||
uint16_t textcolor, char *label, uint8_t textsize);
|
||||
// New/alt initButton() uses upper-left corner & size
|
||||
void initButtonUL(Adafruit_GFX *gfx, int16_t x1, int16_t y1,
|
||||
uint16_t w, uint16_t h, uint16_t outline, uint16_t fill,
|
||||
uint16_t textcolor, char *label, uint8_t textsize);
|
||||
void drawButton(boolean inverted = false);
|
||||
boolean contains(int16_t x, int16_t y);
|
||||
|
||||
void press(boolean p);
|
||||
boolean isPressed();
|
||||
boolean justPressed();
|
||||
boolean justReleased();
|
||||
|
||||
private:
|
||||
Adafruit_GFX *_gfx;
|
||||
int16_t _x1, _y1; // Coordinates of top-left corner
|
||||
uint16_t _w, _h;
|
||||
uint8_t _textsize;
|
||||
uint16_t _outlinecolor, _fillcolor, _textcolor;
|
||||
char _label[10];
|
||||
|
||||
boolean currstate, laststate;
|
||||
};
|
||||
|
||||
|
||||
/// A GFX 1-bit canvas context for graphics
|
||||
class GFXcanvas1 : public Adafruit_GFX {
|
||||
public:
|
||||
GFXcanvas1(uint16_t w, uint16_t h);
|
||||
~GFXcanvas1(void);
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color),
|
||||
fillScreen(uint16_t color);
|
||||
uint8_t *getBuffer(void);
|
||||
private:
|
||||
uint8_t *buffer;
|
||||
};
|
||||
|
||||
|
||||
/// A GFX 8-bit canvas context for graphics
|
||||
class GFXcanvas8 : public Adafruit_GFX {
|
||||
public:
|
||||
GFXcanvas8(uint16_t w, uint16_t h);
|
||||
~GFXcanvas8(void);
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color),
|
||||
fillScreen(uint16_t color),
|
||||
writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
|
||||
|
||||
uint8_t *getBuffer(void);
|
||||
private:
|
||||
uint8_t *buffer;
|
||||
};
|
||||
|
||||
|
||||
/// A GFX 16-bit canvas context for graphics
|
||||
class GFXcanvas16 : public Adafruit_GFX {
|
||||
public:
|
||||
GFXcanvas16(uint16_t w, uint16_t h);
|
||||
~GFXcanvas16(void);
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color),
|
||||
fillScreen(uint16_t color);
|
||||
uint16_t *getBuffer(void);
|
||||
private:
|
||||
uint16_t *buffer;
|
||||
};
|
||||
|
||||
#endif // _ADAFRUIT_GFX_H
|
||||
#ifndef _ADAFRUIT_GFX_H
|
||||
#define _ADAFRUIT_GFX_H
|
||||
|
||||
#if ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#include "Print.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
#include "gfxfont.h"
|
||||
|
||||
/// A generic graphics superclass that can handle all sorts of drawing. At a minimum you can subclass and provide drawPixel(). At a maximum you can do a ton of overriding to optimize. Used for any/all Adafruit displays!
|
||||
class Adafruit_GFX : public Print {
|
||||
|
||||
public: // Exposed simulation variables...
|
||||
bool dimmed_;
|
||||
bool enabled_;
|
||||
bool inverted_;
|
||||
bool dirty_;
|
||||
|
||||
public:
|
||||
|
||||
Adafruit_GFX(int16_t w, int16_t h); // Constructor
|
||||
|
||||
// This MUST be defined by the subclass:
|
||||
virtual void drawPixel(int16_t x, int16_t y, uint16_t color) = 0; ///< Virtual drawPixel() function to draw to the screen/framebuffer/etc, must be overridden in subclass. @param x X coordinate. @param y Y coordinate. @param color 16-bit pixel color.
|
||||
|
||||
// TRANSACTION API / CORE DRAW API
|
||||
// These MAY be overridden by the subclass to provide device-specific
|
||||
// optimized code. Otherwise 'generic' versions are used.
|
||||
virtual void startWrite(void);
|
||||
virtual void writePixel(int16_t x, int16_t y, uint16_t color);
|
||||
virtual void writeFillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
|
||||
virtual void writeFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
|
||||
virtual void writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
|
||||
virtual void writeLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
|
||||
virtual void endWrite(void);
|
||||
|
||||
// CONTROL API
|
||||
// These MAY be overridden by the subclass to provide device-specific
|
||||
// optimized code. Otherwise 'generic' versions are used.
|
||||
virtual void setRotation(uint8_t r);
|
||||
virtual void invertDisplay(boolean i);
|
||||
|
||||
// BASIC DRAW API
|
||||
// These MAY be overridden by the subclass to provide device-specific
|
||||
// optimized code. Otherwise 'generic' versions are used.
|
||||
virtual void
|
||||
// It's good to implement those, even if using transaction API
|
||||
drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color),
|
||||
drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color),
|
||||
fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color),
|
||||
fillScreen(uint16_t color),
|
||||
// Optional and probably not necessary to change
|
||||
drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color),
|
||||
drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
|
||||
|
||||
// These exist only with Adafruit_GFX (no subclass overrides)
|
||||
void
|
||||
drawCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
|
||||
drawCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
|
||||
uint16_t color),
|
||||
fillCircle(int16_t x0, int16_t y0, int16_t r, uint16_t color),
|
||||
fillCircleHelper(int16_t x0, int16_t y0, int16_t r, uint8_t cornername,
|
||||
int16_t delta, uint16_t color),
|
||||
drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
|
||||
int16_t x2, int16_t y2, uint16_t color),
|
||||
fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1,
|
||||
int16_t x2, int16_t y2, uint16_t color),
|
||||
drawRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
|
||||
int16_t radius, uint16_t color),
|
||||
fillRoundRect(int16_t x0, int16_t y0, int16_t w, int16_t h,
|
||||
int16_t radius, uint16_t color),
|
||||
drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
|
||||
int16_t w, int16_t h, uint16_t color),
|
||||
drawBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
|
||||
int16_t w, int16_t h, uint16_t color, uint16_t bg),
|
||||
drawBitmap(int16_t x, int16_t y, uint8_t *bitmap,
|
||||
int16_t w, int16_t h, uint16_t color),
|
||||
drawBitmap(int16_t x, int16_t y, uint8_t *bitmap,
|
||||
int16_t w, int16_t h, uint16_t color, uint16_t bg),
|
||||
drawXBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
|
||||
int16_t w, int16_t h, uint16_t color),
|
||||
drawGrayscaleBitmap(int16_t x, int16_t y, const uint8_t bitmap[],
|
||||
int16_t w, int16_t h),
|
||||
drawGrayscaleBitmap(int16_t x, int16_t y, uint8_t *bitmap,
|
||||
int16_t w, int16_t h),
|
||||
drawGrayscaleBitmap(int16_t x, int16_t y,
|
||||
const uint8_t bitmap[], const uint8_t mask[],
|
||||
int16_t w, int16_t h),
|
||||
drawGrayscaleBitmap(int16_t x, int16_t y,
|
||||
uint8_t *bitmap, uint8_t *mask, int16_t w, int16_t h),
|
||||
drawRGBBitmap(int16_t x, int16_t y, const uint16_t bitmap[],
|
||||
int16_t w, int16_t h),
|
||||
drawRGBBitmap(int16_t x, int16_t y, uint16_t *bitmap,
|
||||
int16_t w, int16_t h),
|
||||
drawRGBBitmap(int16_t x, int16_t y,
|
||||
const uint16_t bitmap[], const uint8_t mask[],
|
||||
int16_t w, int16_t h),
|
||||
drawRGBBitmap(int16_t x, int16_t y,
|
||||
uint16_t *bitmap, uint8_t *mask, int16_t w, int16_t h),
|
||||
drawChar(int16_t x, int16_t y, unsigned char c, uint16_t color,
|
||||
uint16_t bg, uint8_t size),
|
||||
setCursor(int16_t x, int16_t y),
|
||||
setTextColor(uint16_t c),
|
||||
setTextColor(uint16_t c, uint16_t bg),
|
||||
setTextSize(uint8_t s),
|
||||
setTextWrap(boolean w),
|
||||
cp437(boolean x=true),
|
||||
setFont(const GFXfont *f = NULL),
|
||||
getTextBounds(const char *string, int16_t x, int16_t y,
|
||||
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h),
|
||||
getTextBounds(const __FlashStringHelper *s, int16_t x, int16_t y,
|
||||
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h),
|
||||
getTextBounds(const String &str, int16_t x, int16_t y,
|
||||
int16_t *x1, int16_t *y1, uint16_t *w, uint16_t *h);
|
||||
|
||||
|
||||
#if ARDUINO >= 100
|
||||
virtual size_t write(uint8_t);
|
||||
#else
|
||||
virtual void write(uint8_t);
|
||||
#endif
|
||||
|
||||
int16_t height(void) const;
|
||||
int16_t width(void) const;
|
||||
|
||||
uint8_t getRotation(void) const;
|
||||
|
||||
// get current cursor position (get rotation safe maximum values, using: width() for x, height() for y)
|
||||
int16_t getCursorX(void) const;
|
||||
int16_t getCursorY(void) const;
|
||||
|
||||
protected:
|
||||
void
|
||||
charBounds(char c, int16_t *x, int16_t *y,
|
||||
int16_t *minx, int16_t *miny, int16_t *maxx, int16_t *maxy);
|
||||
const int16_t
|
||||
WIDTH, ///< This is the 'raw' display width - never changes
|
||||
HEIGHT; ///< This is the 'raw' display height - never changes
|
||||
int16_t
|
||||
_width, ///< Display width as modified by current rotation
|
||||
_height, ///< Display height as modified by current rotation
|
||||
cursor_x, ///< x location to start print()ing text
|
||||
cursor_y; ///< y location to start print()ing text
|
||||
uint16_t
|
||||
textcolor, ///< 16-bit background color for print()
|
||||
textbgcolor; ///< 16-bit text color for print()
|
||||
uint8_t
|
||||
textsize, ///< Desired magnification of text to print()
|
||||
rotation; ///< Display rotation (0 thru 3)
|
||||
boolean
|
||||
wrap, ///< If set, 'wrap' text at right edge of display
|
||||
_cp437; ///< If set, use correct CP437 charset (default is off)
|
||||
GFXfont
|
||||
*gfxFont; ///< Pointer to special font
|
||||
};
|
||||
|
||||
|
||||
/// A simple drawn button UI element
|
||||
class Adafruit_GFX_Button {
|
||||
|
||||
public:
|
||||
Adafruit_GFX_Button(void);
|
||||
// "Classic" initButton() uses center & size
|
||||
void initButton(Adafruit_GFX *gfx, int16_t x, int16_t y,
|
||||
uint16_t w, uint16_t h, uint16_t outline, uint16_t fill,
|
||||
uint16_t textcolor, char *label, uint8_t textsize);
|
||||
// New/alt initButton() uses upper-left corner & size
|
||||
void initButtonUL(Adafruit_GFX *gfx, int16_t x1, int16_t y1,
|
||||
uint16_t w, uint16_t h, uint16_t outline, uint16_t fill,
|
||||
uint16_t textcolor, char *label, uint8_t textsize);
|
||||
void drawButton(boolean inverted = false);
|
||||
boolean contains(int16_t x, int16_t y);
|
||||
|
||||
void press(boolean p);
|
||||
boolean isPressed();
|
||||
boolean justPressed();
|
||||
boolean justReleased();
|
||||
|
||||
private:
|
||||
Adafruit_GFX *_gfx;
|
||||
int16_t _x1, _y1; // Coordinates of top-left corner
|
||||
uint16_t _w, _h;
|
||||
uint8_t _textsize;
|
||||
uint16_t _outlinecolor, _fillcolor, _textcolor;
|
||||
char _label[10];
|
||||
|
||||
boolean currstate, laststate;
|
||||
};
|
||||
|
||||
|
||||
/// A GFX 1-bit canvas context for graphics
|
||||
class GFXcanvas1 : public Adafruit_GFX {
|
||||
public:
|
||||
GFXcanvas1(uint16_t w, uint16_t h);
|
||||
~GFXcanvas1(void);
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color),
|
||||
fillScreen(uint16_t color);
|
||||
uint8_t *getBuffer(void);
|
||||
private:
|
||||
uint8_t *buffer;
|
||||
};
|
||||
|
||||
|
||||
/// A GFX 8-bit canvas context for graphics
|
||||
class GFXcanvas8 : public Adafruit_GFX {
|
||||
public:
|
||||
GFXcanvas8(uint16_t w, uint16_t h);
|
||||
~GFXcanvas8(void);
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color),
|
||||
fillScreen(uint16_t color),
|
||||
writeFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
|
||||
|
||||
uint8_t *getBuffer(void);
|
||||
private:
|
||||
uint8_t *buffer;
|
||||
};
|
||||
|
||||
|
||||
/// A GFX 16-bit canvas context for graphics
|
||||
class GFXcanvas16 : public Adafruit_GFX {
|
||||
public:
|
||||
GFXcanvas16(uint16_t w, uint16_t h);
|
||||
~GFXcanvas16(void);
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color),
|
||||
fillScreen(uint16_t color);
|
||||
uint16_t *getBuffer(void);
|
||||
private:
|
||||
uint16_t *buffer;
|
||||
};
|
||||
|
||||
#endif // _ADAFRUIT_GFX_H
|
||||
|
|
|
|||
|
|
@ -1,114 +1,114 @@
|
|||
/*!
|
||||
* @file Adafruit_MPR121.h
|
||||
*
|
||||
This is a library for the MPR121 12-Channel Capacitive Sensor
|
||||
|
||||
Designed specifically to work with the MPR121 breakout from Adafruit
|
||||
----> https://www.adafruit.com/products/1982
|
||||
|
||||
These sensors use I2C to communicate, 2+ pins are required to
|
||||
interface
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
BSD license, all text above must be included in any redistribution
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ADAFRUIT_MPR121_H
|
||||
#define ADAFRUIT_MPR121_H
|
||||
|
||||
// #if (ARDUINO >= 100)
|
||||
#include "Arduino.h"
|
||||
// #else
|
||||
// #include "WProgram.h"
|
||||
// #endif
|
||||
#include <Wire.h>
|
||||
|
||||
// The default I2C address
|
||||
#define MPR121_I2CADDR_DEFAULT 0x5A ///< default I2C address
|
||||
|
||||
/**
|
||||
*****************************************************************************************
|
||||
* @brief Device register map
|
||||
****************************************************************************************/
|
||||
enum {
|
||||
MPR121_TOUCHSTATUS_L = 0x00,
|
||||
MPR121_TOUCHSTATUS_H = 0x01,
|
||||
MPR121_FILTDATA_0L = 0x04,
|
||||
MPR121_FILTDATA_0H = 0x05,
|
||||
MPR121_BASELINE_0 = 0x1E,
|
||||
MPR121_MHDR = 0x2B,
|
||||
MPR121_NHDR = 0x2C,
|
||||
MPR121_NCLR = 0x2D,
|
||||
MPR121_FDLR = 0x2E,
|
||||
MPR121_MHDF = 0x2F,
|
||||
MPR121_NHDF = 0x30,
|
||||
MPR121_NCLF = 0x31,
|
||||
MPR121_FDLF = 0x32,
|
||||
MPR121_NHDT = 0x33,
|
||||
MPR121_NCLT = 0x34,
|
||||
MPR121_FDLT = 0x35,
|
||||
|
||||
MPR121_TOUCHTH_0 = 0x41,
|
||||
MPR121_RELEASETH_0 = 0x42,
|
||||
MPR121_DEBOUNCE = 0x5B,
|
||||
MPR121_CONFIG1 = 0x5C,
|
||||
MPR121_CONFIG2 = 0x5D,
|
||||
MPR121_CHARGECURR_0 = 0x5F,
|
||||
MPR121_CHARGETIME_1 = 0x6C,
|
||||
MPR121_ECR = 0x5E,
|
||||
MPR121_AUTOCONFIG0 = 0x7B,
|
||||
MPR121_AUTOCONFIG1 = 0x7C,
|
||||
MPR121_UPLIMIT = 0x7D,
|
||||
MPR121_LOWLIMIT = 0x7E,
|
||||
MPR121_TARGETLIMIT = 0x7F,
|
||||
|
||||
MPR121_GPIODIR = 0x76,
|
||||
MPR121_GPIOEN = 0x77,
|
||||
MPR121_GPIOSET = 0x78,
|
||||
MPR121_GPIOCLR = 0x79,
|
||||
MPR121_GPIOTOGGLE = 0x7A,
|
||||
|
||||
MPR121_SOFTRESET = 0x80,
|
||||
};
|
||||
|
||||
//.. thru to 0x1C/0x1D
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Class that stores state and functions for interacting with MPR121
|
||||
proximity capacitive touch sensor controller.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class Adafruit_MPR121 {
|
||||
public:
|
||||
// Hardware I2C
|
||||
Adafruit_MPR121(void);
|
||||
|
||||
boolean begin(uint8_t i2caddr = MPR121_I2CADDR_DEFAULT);
|
||||
|
||||
uint16_t filteredData(uint8_t t);
|
||||
uint16_t baselineData(uint8_t t);
|
||||
|
||||
uint8_t readRegister8(uint8_t reg);
|
||||
uint16_t readRegister16(uint8_t reg);
|
||||
void writeRegister(uint8_t reg, uint8_t value);
|
||||
uint16_t touched(void);
|
||||
// Add deprecated attribute so that the compiler shows a warning
|
||||
void setThreshholds(uint8_t touch, uint8_t release) __attribute__((deprecated));
|
||||
void setThresholds(uint8_t touch, uint8_t release);
|
||||
|
||||
uint8_t _registers[48];
|
||||
|
||||
|
||||
// Simulator specific stuff
|
||||
void mockFilteredData(int register, uint16_t value);
|
||||
|
||||
private:
|
||||
int8_t _i2caddr;
|
||||
};
|
||||
|
||||
#endif // ADAFRUIT_MPR121_H
|
||||
/*!
|
||||
* @file Adafruit_MPR121.h
|
||||
*
|
||||
This is a library for the MPR121 12-Channel Capacitive Sensor
|
||||
|
||||
Designed specifically to work with the MPR121 breakout from Adafruit
|
||||
----> https://www.adafruit.com/products/1982
|
||||
|
||||
These sensors use I2C to communicate, 2+ pins are required to
|
||||
interface
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
BSD license, all text above must be included in any redistribution
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef ADAFRUIT_MPR121_H
|
||||
#define ADAFRUIT_MPR121_H
|
||||
|
||||
// #if (ARDUINO >= 100)
|
||||
#include "Arduino.h"
|
||||
// #else
|
||||
// #include "WProgram.h"
|
||||
// #endif
|
||||
#include <Wire.h>
|
||||
|
||||
// The default I2C address
|
||||
#define MPR121_I2CADDR_DEFAULT 0x5A ///< default I2C address
|
||||
|
||||
/**
|
||||
*****************************************************************************************
|
||||
* @brief Device register map
|
||||
****************************************************************************************/
|
||||
enum {
|
||||
MPR121_TOUCHSTATUS_L = 0x00,
|
||||
MPR121_TOUCHSTATUS_H = 0x01,
|
||||
MPR121_FILTDATA_0L = 0x04,
|
||||
MPR121_FILTDATA_0H = 0x05,
|
||||
MPR121_BASELINE_0 = 0x1E,
|
||||
MPR121_MHDR = 0x2B,
|
||||
MPR121_NHDR = 0x2C,
|
||||
MPR121_NCLR = 0x2D,
|
||||
MPR121_FDLR = 0x2E,
|
||||
MPR121_MHDF = 0x2F,
|
||||
MPR121_NHDF = 0x30,
|
||||
MPR121_NCLF = 0x31,
|
||||
MPR121_FDLF = 0x32,
|
||||
MPR121_NHDT = 0x33,
|
||||
MPR121_NCLT = 0x34,
|
||||
MPR121_FDLT = 0x35,
|
||||
|
||||
MPR121_TOUCHTH_0 = 0x41,
|
||||
MPR121_RELEASETH_0 = 0x42,
|
||||
MPR121_DEBOUNCE = 0x5B,
|
||||
MPR121_CONFIG1 = 0x5C,
|
||||
MPR121_CONFIG2 = 0x5D,
|
||||
MPR121_CHARGECURR_0 = 0x5F,
|
||||
MPR121_CHARGETIME_1 = 0x6C,
|
||||
MPR121_ECR = 0x5E,
|
||||
MPR121_AUTOCONFIG0 = 0x7B,
|
||||
MPR121_AUTOCONFIG1 = 0x7C,
|
||||
MPR121_UPLIMIT = 0x7D,
|
||||
MPR121_LOWLIMIT = 0x7E,
|
||||
MPR121_TARGETLIMIT = 0x7F,
|
||||
|
||||
MPR121_GPIODIR = 0x76,
|
||||
MPR121_GPIOEN = 0x77,
|
||||
MPR121_GPIOSET = 0x78,
|
||||
MPR121_GPIOCLR = 0x79,
|
||||
MPR121_GPIOTOGGLE = 0x7A,
|
||||
|
||||
MPR121_SOFTRESET = 0x80,
|
||||
};
|
||||
|
||||
//.. thru to 0x1C/0x1D
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Class that stores state and functions for interacting with MPR121
|
||||
proximity capacitive touch sensor controller.
|
||||
*/
|
||||
/**************************************************************************/
|
||||
class Adafruit_MPR121 {
|
||||
public:
|
||||
// Hardware I2C
|
||||
Adafruit_MPR121(void);
|
||||
|
||||
boolean begin(uint8_t i2caddr = MPR121_I2CADDR_DEFAULT);
|
||||
|
||||
uint16_t filteredData(uint8_t t);
|
||||
uint16_t baselineData(uint8_t t);
|
||||
|
||||
uint8_t readRegister8(uint8_t reg);
|
||||
uint16_t readRegister16(uint8_t reg);
|
||||
void writeRegister(uint8_t reg, uint8_t value);
|
||||
uint16_t touched(void);
|
||||
// Add deprecated attribute so that the compiler shows a warning
|
||||
void setThreshholds(uint8_t touch, uint8_t release) __attribute__((deprecated));
|
||||
void setThresholds(uint8_t touch, uint8_t release);
|
||||
|
||||
uint8_t _registers[48];
|
||||
|
||||
|
||||
// Simulator specific stuff
|
||||
void mockFilteredData(int register, uint16_t value);
|
||||
|
||||
private:
|
||||
int8_t _i2caddr;
|
||||
};
|
||||
|
||||
#endif // ADAFRUIT_MPR121_H
|
||||
|
|
|
|||
|
|
@ -1,169 +1,169 @@
|
|||
/*!
|
||||
* @file Adafruit_SSD1306.h
|
||||
*
|
||||
* This is part of for Adafruit's SSD1306 library for monochrome
|
||||
* OLED displays: http://www.adafruit.com/category/63_98
|
||||
*
|
||||
* These displays use I2C or SPI to communicate. I2C requires 2 pins
|
||||
* (SCL+SDA) and optionally a RESET pin. SPI requires 4 pins (MOSI, SCK,
|
||||
* select, data/command) and optionally a reset pin. Hardware SPI or
|
||||
* 'bitbang' software SPI are both supported.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Limor Fried/Ladyada for Adafruit Industries, with
|
||||
* contributions from the open source community.
|
||||
*
|
||||
* BSD license, all text above, and the splash screen header file,
|
||||
* must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _Adafruit_SSD1306_H_
|
||||
#define _Adafruit_SSD1306_H_
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
#include <Adafruit_GFX.h>
|
||||
|
||||
typedef void* SPIClass;
|
||||
|
||||
// #if defined(__AVR__)
|
||||
// typedef volatile uint8_t PortReg;
|
||||
// typedef uint8_t PortMask;
|
||||
// #define HAVE_PORTREG
|
||||
// #elif defined(__SAM3X8E__)
|
||||
// typedef volatile RwReg PortReg;
|
||||
// typedef uint32_t PortMask;
|
||||
// #define HAVE_PORTREG
|
||||
// #elif defined(__arm__) || defined(ARDUINO_FEATHER52)
|
||||
// typedef volatile uint32_t PortReg;
|
||||
// typedef uint32_t PortMask;
|
||||
// #define HAVE_PORTREG
|
||||
// #endif
|
||||
|
||||
#define BLACK 0 ///< Draw 'off' pixels
|
||||
#define WHITE 1 ///< Draw 'on' pixels
|
||||
#define INVERSE 2 ///< Invert pixels
|
||||
|
||||
#define SSD1306_MEMORYMODE 0x20 ///< See datasheet
|
||||
#define SSD1306_COLUMNADDR 0x21 ///< See datasheet
|
||||
#define SSD1306_PAGEADDR 0x22 ///< See datasheet
|
||||
#define SSD1306_SETCONTRAST 0x81 ///< See datasheet
|
||||
#define SSD1306_CHARGEPUMP 0x8D ///< See datasheet
|
||||
#define SSD1306_SEGREMAP 0xA0 ///< See datasheet
|
||||
#define SSD1306_DISPLAYALLON_RESUME 0xA4 ///< See datasheet
|
||||
#define SSD1306_DISPLAYALLON 0xA5 ///< Not currently used
|
||||
#define SSD1306_NORMALDISPLAY 0xA6 ///< See datasheet
|
||||
#define SSD1306_INVERTDISPLAY 0xA7 ///< See datasheet
|
||||
#define SSD1306_SETMULTIPLEX 0xA8 ///< See datasheet
|
||||
#define SSD1306_DISPLAYOFF 0xAE ///< See datasheet
|
||||
#define SSD1306_DISPLAYON 0xAF ///< See datasheet
|
||||
#define SSD1306_COMSCANINC 0xC0 ///< Not currently used
|
||||
#define SSD1306_COMSCANDEC 0xC8 ///< See datasheet
|
||||
#define SSD1306_SETDISPLAYOFFSET 0xD3 ///< See datasheet
|
||||
#define SSD1306_SETDISPLAYCLOCKDIV 0xD5 ///< See datasheet
|
||||
#define SSD1306_SETPRECHARGE 0xD9 ///< See datasheet
|
||||
#define SSD1306_SETCOMPINS 0xDA ///< See datasheet
|
||||
#define SSD1306_SETVCOMDETECT 0xDB ///< See datasheet
|
||||
|
||||
#define SSD1306_SETLOWCOLUMN 0x00 ///< Not currently used
|
||||
#define SSD1306_SETHIGHCOLUMN 0x10 ///< Not currently used
|
||||
#define SSD1306_SETSTARTLINE 0x40 ///< See datasheet
|
||||
|
||||
#define SSD1306_EXTERNALVCC 0x01 ///< External display voltage source
|
||||
#define SSD1306_SWITCHCAPVCC 0x02 ///< Gen. display voltage from 3.3V
|
||||
|
||||
#define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26 ///< Init rt scroll
|
||||
#define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27 ///< Init left scroll
|
||||
#define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29 ///< Init diag scroll
|
||||
#define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A ///< Init diag scroll
|
||||
#define SSD1306_DEACTIVATE_SCROLL 0x2E ///< Stop scroll
|
||||
#define SSD1306_ACTIVATE_SCROLL 0x2F ///< Start scroll
|
||||
#define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3 ///< Set scroll range
|
||||
|
||||
// Deprecated size stuff for backwards compatibility with old sketches
|
||||
#if defined SSD1306_128_64
|
||||
#define SSD1306_LCDWIDTH 128 ///< DEPRECATED: width w/SSD1306_128_64 defined
|
||||
#define SSD1306_LCDHEIGHT 64 ///< DEPRECATED: height w/SSD1306_128_64 defined
|
||||
#endif
|
||||
#if defined SSD1306_128_32
|
||||
#define SSD1306_LCDWIDTH 128 ///< DEPRECATED: width w/SSD1306_128_32 defined
|
||||
#define SSD1306_LCDHEIGHT 32 ///< DEPRECATED: height w/SSD1306_128_32 defined
|
||||
#endif
|
||||
#if defined SSD1306_96_16
|
||||
#define SSD1306_LCDWIDTH 96 ///< DEPRECATED: width w/SSD1306_96_16 defined
|
||||
#define SSD1306_LCDHEIGHT 16 ///< DEPRECATED: height w/SSD1306_96_16 defined
|
||||
#endif
|
||||
|
||||
/*!
|
||||
@brief Class that stores state and functions for interacting with
|
||||
SSD1306 OLED displays.
|
||||
*/
|
||||
class Adafruit_SSD1306 : public Adafruit_GFX {
|
||||
public:
|
||||
// NEW CONSTRUCTORS -- recommended for new projects
|
||||
Adafruit_SSD1306(uint8_t w, uint8_t h, TwoWire *twi=&Wire, int8_t rst_pin=-1,
|
||||
uint32_t clkDuring=400000UL, uint32_t clkAfter=100000UL);
|
||||
Adafruit_SSD1306(uint8_t w, uint8_t h, int8_t mosi_pin, int8_t sclk_pin,
|
||||
int8_t dc_pin, int8_t rst_pin, int8_t cs_pin);
|
||||
Adafruit_SSD1306(uint8_t w, uint8_t h, SPIClass *spi,
|
||||
int8_t dc_pin, int8_t rst_pin, int8_t cs_pin, uint32_t bitrate=8000000UL);
|
||||
|
||||
// DEPRECATED CONSTRUCTORS - for back compatibility, avoid in new projects
|
||||
Adafruit_SSD1306(int8_t mosi_pin, int8_t sclk_pin, int8_t dc_pin,
|
||||
int8_t rst_pin, int8_t cs_pin);
|
||||
Adafruit_SSD1306(int8_t dc_pin, int8_t rst_pin, int8_t cs_pin);
|
||||
Adafruit_SSD1306(int8_t rst_pin = -1);
|
||||
|
||||
~Adafruit_SSD1306(void);
|
||||
|
||||
boolean begin(uint8_t switchvcc=SSD1306_SWITCHCAPVCC,
|
||||
uint8_t i2caddr=0, boolean reset=true,
|
||||
boolean periphBegin=true);
|
||||
void display(void);
|
||||
void clearDisplay(void);
|
||||
void invertDisplay(boolean i);
|
||||
void dim(boolean dim);
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color);
|
||||
virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
|
||||
virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
|
||||
void startscrollright(uint8_t start, uint8_t stop);
|
||||
void startscrollleft(uint8_t start, uint8_t stop);
|
||||
void startscrolldiagright(uint8_t start, uint8_t stop);
|
||||
void startscrolldiagleft(uint8_t start, uint8_t stop);
|
||||
void stopscroll(void);
|
||||
void ssd1306_command(uint8_t c);
|
||||
boolean getPixel(int16_t x, int16_t y);
|
||||
uint8_t *getBuffer(void);
|
||||
|
||||
private:
|
||||
inline void SPIwrite(uint8_t d) __attribute__((always_inline));
|
||||
void drawFastHLineInternal(int16_t x, int16_t y, int16_t w,
|
||||
uint16_t color);
|
||||
void drawFastVLineInternal(int16_t x, int16_t y, int16_t h,
|
||||
uint16_t color);
|
||||
void ssd1306_command1(uint8_t c);
|
||||
void ssd1306_commandList(const uint8_t *c, uint8_t n);
|
||||
|
||||
SPIClass *spi;
|
||||
TwoWire *wire;
|
||||
uint8_t *buffer;
|
||||
int8_t i2caddr, vccstate, page_end;
|
||||
int8_t mosiPin , clkPin , dcPin , csPin, rstPin;
|
||||
#ifdef HAVE_PORTREG
|
||||
PortReg *mosiPort , *clkPort , *dcPort , *csPort;
|
||||
PortMask mosiPinMask, clkPinMask, dcPinMask, csPinMask;
|
||||
#endif
|
||||
#if defined(SPI_HAS_TRANSACTION)
|
||||
SPISettings spiSettings;
|
||||
#endif
|
||||
#if ARDUINO >= 157
|
||||
uint32_t wireClk; // Wire speed for SSD1306 transfers
|
||||
uint32_t restoreClk; // Wire speed following SSD1306 transfers
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // _Adafruit_SSD1306_H_
|
||||
/*!
|
||||
* @file Adafruit_SSD1306.h
|
||||
*
|
||||
* This is part of for Adafruit's SSD1306 library for monochrome
|
||||
* OLED displays: http://www.adafruit.com/category/63_98
|
||||
*
|
||||
* These displays use I2C or SPI to communicate. I2C requires 2 pins
|
||||
* (SCL+SDA) and optionally a RESET pin. SPI requires 4 pins (MOSI, SCK,
|
||||
* select, data/command) and optionally a reset pin. Hardware SPI or
|
||||
* 'bitbang' software SPI are both supported.
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing
|
||||
* products from Adafruit!
|
||||
*
|
||||
* Written by Limor Fried/Ladyada for Adafruit Industries, with
|
||||
* contributions from the open source community.
|
||||
*
|
||||
* BSD license, all text above, and the splash screen header file,
|
||||
* must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _Adafruit_SSD1306_H_
|
||||
#define _Adafruit_SSD1306_H_
|
||||
|
||||
#include <Wire.h>
|
||||
|
||||
#include <Adafruit_GFX.h>
|
||||
|
||||
typedef void* SPIClass;
|
||||
|
||||
// #if defined(__AVR__)
|
||||
// typedef volatile uint8_t PortReg;
|
||||
// typedef uint8_t PortMask;
|
||||
// #define HAVE_PORTREG
|
||||
// #elif defined(__SAM3X8E__)
|
||||
// typedef volatile RwReg PortReg;
|
||||
// typedef uint32_t PortMask;
|
||||
// #define HAVE_PORTREG
|
||||
// #elif defined(__arm__) || defined(ARDUINO_FEATHER52)
|
||||
// typedef volatile uint32_t PortReg;
|
||||
// typedef uint32_t PortMask;
|
||||
// #define HAVE_PORTREG
|
||||
// #endif
|
||||
|
||||
#define BLACK 0 ///< Draw 'off' pixels
|
||||
#define WHITE 1 ///< Draw 'on' pixels
|
||||
#define INVERSE 2 ///< Invert pixels
|
||||
|
||||
#define SSD1306_MEMORYMODE 0x20 ///< See datasheet
|
||||
#define SSD1306_COLUMNADDR 0x21 ///< See datasheet
|
||||
#define SSD1306_PAGEADDR 0x22 ///< See datasheet
|
||||
#define SSD1306_SETCONTRAST 0x81 ///< See datasheet
|
||||
#define SSD1306_CHARGEPUMP 0x8D ///< See datasheet
|
||||
#define SSD1306_SEGREMAP 0xA0 ///< See datasheet
|
||||
#define SSD1306_DISPLAYALLON_RESUME 0xA4 ///< See datasheet
|
||||
#define SSD1306_DISPLAYALLON 0xA5 ///< Not currently used
|
||||
#define SSD1306_NORMALDISPLAY 0xA6 ///< See datasheet
|
||||
#define SSD1306_INVERTDISPLAY 0xA7 ///< See datasheet
|
||||
#define SSD1306_SETMULTIPLEX 0xA8 ///< See datasheet
|
||||
#define SSD1306_DISPLAYOFF 0xAE ///< See datasheet
|
||||
#define SSD1306_DISPLAYON 0xAF ///< See datasheet
|
||||
#define SSD1306_COMSCANINC 0xC0 ///< Not currently used
|
||||
#define SSD1306_COMSCANDEC 0xC8 ///< See datasheet
|
||||
#define SSD1306_SETDISPLAYOFFSET 0xD3 ///< See datasheet
|
||||
#define SSD1306_SETDISPLAYCLOCKDIV 0xD5 ///< See datasheet
|
||||
#define SSD1306_SETPRECHARGE 0xD9 ///< See datasheet
|
||||
#define SSD1306_SETCOMPINS 0xDA ///< See datasheet
|
||||
#define SSD1306_SETVCOMDETECT 0xDB ///< See datasheet
|
||||
|
||||
#define SSD1306_SETLOWCOLUMN 0x00 ///< Not currently used
|
||||
#define SSD1306_SETHIGHCOLUMN 0x10 ///< Not currently used
|
||||
#define SSD1306_SETSTARTLINE 0x40 ///< See datasheet
|
||||
|
||||
#define SSD1306_EXTERNALVCC 0x01 ///< External display voltage source
|
||||
#define SSD1306_SWITCHCAPVCC 0x02 ///< Gen. display voltage from 3.3V
|
||||
|
||||
#define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26 ///< Init rt scroll
|
||||
#define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27 ///< Init left scroll
|
||||
#define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29 ///< Init diag scroll
|
||||
#define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A ///< Init diag scroll
|
||||
#define SSD1306_DEACTIVATE_SCROLL 0x2E ///< Stop scroll
|
||||
#define SSD1306_ACTIVATE_SCROLL 0x2F ///< Start scroll
|
||||
#define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3 ///< Set scroll range
|
||||
|
||||
// Deprecated size stuff for backwards compatibility with old sketches
|
||||
#if defined SSD1306_128_64
|
||||
#define SSD1306_LCDWIDTH 128 ///< DEPRECATED: width w/SSD1306_128_64 defined
|
||||
#define SSD1306_LCDHEIGHT 64 ///< DEPRECATED: height w/SSD1306_128_64 defined
|
||||
#endif
|
||||
#if defined SSD1306_128_32
|
||||
#define SSD1306_LCDWIDTH 128 ///< DEPRECATED: width w/SSD1306_128_32 defined
|
||||
#define SSD1306_LCDHEIGHT 32 ///< DEPRECATED: height w/SSD1306_128_32 defined
|
||||
#endif
|
||||
#if defined SSD1306_96_16
|
||||
#define SSD1306_LCDWIDTH 96 ///< DEPRECATED: width w/SSD1306_96_16 defined
|
||||
#define SSD1306_LCDHEIGHT 16 ///< DEPRECATED: height w/SSD1306_96_16 defined
|
||||
#endif
|
||||
|
||||
/*!
|
||||
@brief Class that stores state and functions for interacting with
|
||||
SSD1306 OLED displays.
|
||||
*/
|
||||
class Adafruit_SSD1306 : public Adafruit_GFX {
|
||||
public:
|
||||
// NEW CONSTRUCTORS -- recommended for new projects
|
||||
Adafruit_SSD1306(uint8_t w, uint8_t h, TwoWire *twi=&Wire, int8_t rst_pin=-1,
|
||||
uint32_t clkDuring=400000UL, uint32_t clkAfter=100000UL);
|
||||
Adafruit_SSD1306(uint8_t w, uint8_t h, int8_t mosi_pin, int8_t sclk_pin,
|
||||
int8_t dc_pin, int8_t rst_pin, int8_t cs_pin);
|
||||
Adafruit_SSD1306(uint8_t w, uint8_t h, SPIClass *spi,
|
||||
int8_t dc_pin, int8_t rst_pin, int8_t cs_pin, uint32_t bitrate=8000000UL);
|
||||
|
||||
// DEPRECATED CONSTRUCTORS - for back compatibility, avoid in new projects
|
||||
Adafruit_SSD1306(int8_t mosi_pin, int8_t sclk_pin, int8_t dc_pin,
|
||||
int8_t rst_pin, int8_t cs_pin);
|
||||
Adafruit_SSD1306(int8_t dc_pin, int8_t rst_pin, int8_t cs_pin);
|
||||
Adafruit_SSD1306(int8_t rst_pin = -1);
|
||||
|
||||
~Adafruit_SSD1306(void);
|
||||
|
||||
boolean begin(uint8_t switchvcc=SSD1306_SWITCHCAPVCC,
|
||||
uint8_t i2caddr=0, boolean reset=true,
|
||||
boolean periphBegin=true);
|
||||
void display(void);
|
||||
void clearDisplay(void);
|
||||
void invertDisplay(boolean i);
|
||||
void dim(boolean dim);
|
||||
void drawPixel(int16_t x, int16_t y, uint16_t color);
|
||||
virtual void drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color);
|
||||
virtual void drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color);
|
||||
void startscrollright(uint8_t start, uint8_t stop);
|
||||
void startscrollleft(uint8_t start, uint8_t stop);
|
||||
void startscrolldiagright(uint8_t start, uint8_t stop);
|
||||
void startscrolldiagleft(uint8_t start, uint8_t stop);
|
||||
void stopscroll(void);
|
||||
void ssd1306_command(uint8_t c);
|
||||
boolean getPixel(int16_t x, int16_t y);
|
||||
uint8_t *getBuffer(void);
|
||||
|
||||
private:
|
||||
inline void SPIwrite(uint8_t d) __attribute__((always_inline));
|
||||
void drawFastHLineInternal(int16_t x, int16_t y, int16_t w,
|
||||
uint16_t color);
|
||||
void drawFastVLineInternal(int16_t x, int16_t y, int16_t h,
|
||||
uint16_t color);
|
||||
void ssd1306_command1(uint8_t c);
|
||||
void ssd1306_commandList(const uint8_t *c, uint8_t n);
|
||||
|
||||
SPIClass *spi;
|
||||
TwoWire *wire;
|
||||
uint8_t *buffer;
|
||||
int8_t i2caddr, vccstate, page_end;
|
||||
int8_t mosiPin , clkPin , dcPin , csPin, rstPin;
|
||||
#ifdef HAVE_PORTREG
|
||||
PortReg *mosiPort , *clkPort , *dcPort , *csPort;
|
||||
PortMask mosiPinMask, clkPinMask, dcPinMask, csPinMask;
|
||||
#endif
|
||||
#if defined(SPI_HAS_TRANSACTION)
|
||||
SPISettings spiSettings;
|
||||
#endif
|
||||
#if ARDUINO >= 157
|
||||
uint32_t wireClk; // Wire speed for SSD1306 transfers
|
||||
uint32_t restoreClk; // Wire speed following SSD1306 transfers
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif // _Adafruit_SSD1306_H_
|
||||
|
|
|
|||
|
|
@ -1,105 +1,105 @@
|
|||
#ifndef __ARDUINO_H__
|
||||
#define __ARDUINO_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "Wiring.h"
|
||||
#include "simusbmidi.h"
|
||||
|
||||
#include "core_pins.h"
|
||||
|
||||
#define PROGMEM
|
||||
|
||||
#ifndef _BV
|
||||
#define _BV(x) (1u<<(x))
|
||||
#endif
|
||||
|
||||
// SPI CTRL REG BITS
|
||||
#define SPIE 7
|
||||
#define SPE 6
|
||||
#define DORD 5
|
||||
#define MSTR 4
|
||||
#define CPOL 3
|
||||
#define CPHA 2
|
||||
#define SPR1 1
|
||||
#define SPR0 0
|
||||
|
||||
|
||||
#define A11 (0xa1)
|
||||
|
||||
/*
|
||||
SPCR
|
||||
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|
||||
| SPIE | SPE | DORD | MSTR | CPOL | CPHA | SPR1 | SPR0 |
|
||||
|
||||
SPIE - Enables the SPI interrupt when 1
|
||||
SPE - Enables the SPI when 1
|
||||
DORD - Sends data least Significant Bit First when 1, most Significant Bit first when 0
|
||||
MSTR - Sets the Arduino in master mode when 1, slave mode when 0
|
||||
CPOL - Sets the data clock to be idle when high if set to 1, idle when low if set to 0
|
||||
CPHA - Samples data on the falling edge of the data clock when 1, rising edge when 0
|
||||
SPR1 and SPR0 - Sets the SPI speed, 00 is fastest (4MHz) 11 is slowest (250KHz)
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#define LSBFIRST 0
|
||||
#define MSBFIRST 1
|
||||
|
||||
typedef bool boolean;
|
||||
typedef uint8_t byte;
|
||||
|
||||
// class Print
|
||||
// {
|
||||
// public:
|
||||
// };
|
||||
|
||||
|
||||
class SimSerial
|
||||
{
|
||||
public:
|
||||
void begin(uint32_t speed);
|
||||
void println(uint32_t value);
|
||||
void println();
|
||||
void println(const char* str);
|
||||
void print(const char* str);
|
||||
void print(uint32_t intValue);
|
||||
void write(const uint8_t str);
|
||||
void flush();
|
||||
|
||||
};
|
||||
|
||||
|
||||
extern SimSerial Serial;
|
||||
extern SimSerial Serial3; //Used for MIDI serial putput with default hardware
|
||||
extern SimUsbMidi usbMIDI;
|
||||
|
||||
//extern void putString(int row, int col, int color, const char* msg, const FONT_INFO fontInfo);
|
||||
|
||||
uint32_t micros();
|
||||
uint32_t millis();
|
||||
void delay(uint32_t millis);
|
||||
void delayMicroseconds(uint32_t micros);
|
||||
|
||||
|
||||
void pinMode(uint8_t, uint8_t);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
//void digitalWrite(uint8_t, uint8_t);
|
||||
//int digitalRead(uint8_t);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
int analogRead(uint8_t);
|
||||
void analogReference(uint8_t mode);
|
||||
void analogWrite(uint8_t, int);
|
||||
|
||||
#endif
|
||||
#ifndef __ARDUINO_H__
|
||||
#define __ARDUINO_H__
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include "Wiring.h"
|
||||
#include "simusbmidi.h"
|
||||
|
||||
#include "core_pins.h"
|
||||
|
||||
#define PROGMEM
|
||||
|
||||
#ifndef _BV
|
||||
#define _BV(x) (1u<<(x))
|
||||
#endif
|
||||
|
||||
// SPI CTRL REG BITS
|
||||
#define SPIE 7
|
||||
#define SPE 6
|
||||
#define DORD 5
|
||||
#define MSTR 4
|
||||
#define CPOL 3
|
||||
#define CPHA 2
|
||||
#define SPR1 1
|
||||
#define SPR0 0
|
||||
|
||||
|
||||
#define A11 (0xa1)
|
||||
|
||||
/*
|
||||
SPCR
|
||||
| 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|
||||
| SPIE | SPE | DORD | MSTR | CPOL | CPHA | SPR1 | SPR0 |
|
||||
|
||||
SPIE - Enables the SPI interrupt when 1
|
||||
SPE - Enables the SPI when 1
|
||||
DORD - Sends data least Significant Bit First when 1, most Significant Bit first when 0
|
||||
MSTR - Sets the Arduino in master mode when 1, slave mode when 0
|
||||
CPOL - Sets the data clock to be idle when high if set to 1, idle when low if set to 0
|
||||
CPHA - Samples data on the falling edge of the data clock when 1, rising edge when 0
|
||||
SPR1 and SPR0 - Sets the SPI speed, 00 is fastest (4MHz) 11 is slowest (250KHz)
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#define LSBFIRST 0
|
||||
#define MSBFIRST 1
|
||||
|
||||
typedef bool boolean;
|
||||
typedef uint8_t byte;
|
||||
|
||||
// class Print
|
||||
// {
|
||||
// public:
|
||||
// };
|
||||
|
||||
|
||||
class SimSerial
|
||||
{
|
||||
public:
|
||||
void begin(uint32_t speed);
|
||||
void println(uint32_t value);
|
||||
void println();
|
||||
void println(const char* str);
|
||||
void print(const char* str);
|
||||
void print(uint32_t intValue);
|
||||
void write(const uint8_t str);
|
||||
void flush();
|
||||
|
||||
};
|
||||
|
||||
|
||||
extern SimSerial Serial;
|
||||
extern SimSerial Serial3; //Used for MIDI serial putput with default hardware
|
||||
extern SimUsbMidi usbMIDI;
|
||||
|
||||
//extern void putString(int row, int col, int color, const char* msg, const FONT_INFO fontInfo);
|
||||
|
||||
uint32_t micros();
|
||||
uint32_t millis();
|
||||
void delay(uint32_t millis);
|
||||
void delayMicroseconds(uint32_t micros);
|
||||
|
||||
|
||||
void pinMode(uint8_t, uint8_t);
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
//void digitalWrite(uint8_t, uint8_t);
|
||||
//int digitalRead(uint8_t);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
int analogRead(uint8_t);
|
||||
void analogReference(uint8_t mode);
|
||||
void analogWrite(uint8_t, int);
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,55 +1,55 @@
|
|||
#ifndef __EEPROM_H
|
||||
#define __EEPROM_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
struct EEPROMClass
|
||||
{
|
||||
EEPROMClass();
|
||||
//Basic user access methods.
|
||||
// EERef operator[]( const int idx ) { return idx; }
|
||||
uint8_t read( int idx ); // { return EERef( idx ); }
|
||||
void write( int idx, uint8_t val ); // { (EERef( idx )) = val; }
|
||||
void update( int idx, uint8_t val ); // { EERef( idx ).update( val ); }
|
||||
|
||||
//STL and C++11 iteration capability.
|
||||
// EEPtr begin() { return 0x00; }
|
||||
// EEPtr end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid.
|
||||
uint16_t length(); // { return E2END + 1; }
|
||||
|
||||
//Functionality to 'get' and 'put' objects to and from EEPROM.
|
||||
// template< typename T > T &get( int idx, T &t ){
|
||||
// EEPtr e = idx;
|
||||
// uint8_t *ptr = (uint8_t*) &t;
|
||||
// for( int count = sizeof(T) ; count ; --count, ++e ) *ptr++ = *e;
|
||||
// return t;
|
||||
// }
|
||||
|
||||
// template< typename T > const T &put( int idx, const T &t ){
|
||||
// const uint8_t *ptr = (const uint8_t*) &t;
|
||||
// #ifdef __arm__
|
||||
// eeprom_write_block(ptr, (void *)idx, sizeof(T));
|
||||
// #else
|
||||
// EEPtr e = idx;
|
||||
// for( int count = sizeof(T) ; count ; --count, ++e ) (*e).update( *ptr++ );
|
||||
// #endif
|
||||
// return t;
|
||||
// }
|
||||
|
||||
//Make EEPROM persistent by storing to a file
|
||||
int16_t setStorage(const char* filename, bool write);
|
||||
void closeStorage();
|
||||
|
||||
private:
|
||||
uint8_t someFakeEEPROM_memory[2048]; //Teensy 3.2 size
|
||||
FILE *storage;
|
||||
bool autoUpdate;
|
||||
|
||||
|
||||
};
|
||||
|
||||
extern EEPROMClass EEPROM __unused;
|
||||
|
||||
|
||||
#endif
|
||||
#ifndef __EEPROM_H
|
||||
#define __EEPROM_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
struct EEPROMClass
|
||||
{
|
||||
EEPROMClass();
|
||||
//Basic user access methods.
|
||||
// EERef operator[]( const int idx ) { return idx; }
|
||||
uint8_t read( int idx ); // { return EERef( idx ); }
|
||||
void write( int idx, uint8_t val ); // { (EERef( idx )) = val; }
|
||||
void update( int idx, uint8_t val ); // { EERef( idx ).update( val ); }
|
||||
|
||||
//STL and C++11 iteration capability.
|
||||
// EEPtr begin() { return 0x00; }
|
||||
// EEPtr end() { return length(); } //Standards requires this to be the item after the last valid entry. The returned pointer is invalid.
|
||||
uint16_t length(); // { return E2END + 1; }
|
||||
|
||||
//Functionality to 'get' and 'put' objects to and from EEPROM.
|
||||
// template< typename T > T &get( int idx, T &t ){
|
||||
// EEPtr e = idx;
|
||||
// uint8_t *ptr = (uint8_t*) &t;
|
||||
// for( int count = sizeof(T) ; count ; --count, ++e ) *ptr++ = *e;
|
||||
// return t;
|
||||
// }
|
||||
|
||||
// template< typename T > const T &put( int idx, const T &t ){
|
||||
// const uint8_t *ptr = (const uint8_t*) &t;
|
||||
// #ifdef __arm__
|
||||
// eeprom_write_block(ptr, (void *)idx, sizeof(T));
|
||||
// #else
|
||||
// EEPtr e = idx;
|
||||
// for( int count = sizeof(T) ; count ; --count, ++e ) (*e).update( *ptr++ );
|
||||
// #endif
|
||||
// return t;
|
||||
// }
|
||||
|
||||
//Make EEPROM persistent by storing to a file
|
||||
int16_t setStorage(const char* filename, bool write);
|
||||
void closeStorage();
|
||||
|
||||
private:
|
||||
uint8_t someFakeEEPROM_memory[2048]; //Teensy 3.2 size
|
||||
FILE *storage;
|
||||
bool autoUpdate;
|
||||
|
||||
|
||||
};
|
||||
|
||||
extern EEPROMClass EEPROM __unused;
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,136 +1,136 @@
|
|||
/* Teensyduino Core Library
|
||||
* http://www.pjrc.com/teensy/
|
||||
* Copyright (c) 2017 PJRC.COM, LLC.
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* 1. The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* 2. If the Software is incorporated into a build system that allows
|
||||
* selection among a list of target devices, then similar target
|
||||
* devices manufactured by PJRC.COM must be included in the list of
|
||||
* target devices and selectable in the same manner.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef Print_h
|
||||
#define Print_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h> // for size_t - gives sprintf and other stuff to all sketches & libs
|
||||
#include <stdarg.h>
|
||||
#include "core_id.h"
|
||||
#include "WString.h"
|
||||
#include "Printable.h"
|
||||
|
||||
#define DEC 10
|
||||
#define HEX 16
|
||||
#define OCT 8
|
||||
#define BIN 2
|
||||
|
||||
|
||||
#ifndef isnan
|
||||
#define isnan(__x) (__builtin_isnan (__x))
|
||||
#endif
|
||||
|
||||
#ifndef isinf
|
||||
#define isinf(__x) (__builtin_isinf (__x))
|
||||
#endif
|
||||
|
||||
|
||||
class __FlashStringHelper;
|
||||
|
||||
class Print
|
||||
{
|
||||
public:
|
||||
constexpr Print() : write_error(0) {}
|
||||
virtual size_t write(uint8_t b) = 0;
|
||||
size_t write(const char *str) { return write((const uint8_t *)str, strlen(str)); }
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
virtual int availableForWrite(void) { return 0; }
|
||||
virtual void flush() { }
|
||||
size_t write(const char *buffer, size_t size) { return write((const uint8_t *)buffer, size); }
|
||||
// size_t print(const String &s);
|
||||
size_t print(char c) { return write((uint8_t)c); }
|
||||
size_t print(const char s[]) { return write(s); }
|
||||
size_t print(const __FlashStringHelper *f) { return write((const char *)f); }
|
||||
|
||||
size_t print(uint8_t b) { return printNumber(b, 10, 0); }
|
||||
size_t print(int n) { return print((long)n); }
|
||||
size_t print(unsigned int n) { return printNumber(n, 10, 0); }
|
||||
size_t print(long n);
|
||||
size_t print(unsigned long n) { return printNumber(n, 10, 0); }
|
||||
|
||||
size_t print(unsigned char n, int base) { return printNumber(n, base, 0); }
|
||||
size_t print(int n, int base) { return (base == 10) ? print(n) : printNumber(n, base, 0); }
|
||||
size_t print(unsigned int n, int base) { return printNumber(n, base, 0); }
|
||||
size_t print(long n, int base) { return (base == 10) ? print(n) : printNumber(n, base, 0); }
|
||||
size_t print(unsigned long n, int base) { return printNumber(n, base, 0); }
|
||||
|
||||
size_t print(double n, int digits = 2) { return printFloat(n, digits); }
|
||||
size_t print(const Printable &obj) { return obj.printTo(*this); }
|
||||
size_t println(void);
|
||||
// size_t println(const String &s) { return print(s) + println(); }
|
||||
size_t println(char c) { return print(c) + println(); }
|
||||
size_t println(const char s[]) { return print(s) + println(); }
|
||||
size_t println(const __FlashStringHelper *f) { return print(f) + println(); }
|
||||
|
||||
size_t println(uint8_t b) { return print(b) + println(); }
|
||||
size_t println(int n) { return print(n) + println(); }
|
||||
size_t println(unsigned int n) { return print(n) + println(); }
|
||||
size_t println(long n) { return print(n) + println(); }
|
||||
size_t println(unsigned long n) { return print(n) + println(); }
|
||||
|
||||
size_t println(unsigned char n, int base) { return print(n, base) + println(); }
|
||||
size_t println(int n, int base) { return print(n, base) + println(); }
|
||||
size_t println(unsigned int n, int base) { return print(n, base) + println(); }
|
||||
size_t println(long n, int base) { return print(n, base) + println(); }
|
||||
size_t println(unsigned long n, int base) { return print(n, base) + println(); }
|
||||
|
||||
size_t println(double n, int digits = 2) { return print(n, digits) + println(); }
|
||||
size_t println(const Printable &obj) { return obj.printTo(*this) + println(); }
|
||||
int getWriteError() { return write_error; }
|
||||
void clearWriteError() { setWriteError(0); }
|
||||
int printf(const char *format, ...);
|
||||
int printf(const __FlashStringHelper *format, ...);
|
||||
protected:
|
||||
void setWriteError(int err = 1) { write_error = err; }
|
||||
private:
|
||||
char write_error;
|
||||
size_t printFloat(double n, uint8_t digits);
|
||||
#ifdef __MKL26Z64__
|
||||
size_t printNumberDec(unsigned long n, uint8_t sign);
|
||||
size_t printNumberHex(unsigned long n);
|
||||
size_t printNumberBin(unsigned long n);
|
||||
size_t printNumberAny(unsigned long n, uint8_t base);
|
||||
inline size_t printNumber(unsigned long n, uint8_t base, uint8_t sign) __attribute__((always_inline)) {
|
||||
// when "base" is a constant (pretty much always), the
|
||||
// compiler optimizes this to a single function call.
|
||||
if (base == 0) return write((uint8_t)n);
|
||||
if (base == 10 || base < 2) return printNumberDec(n, sign);
|
||||
if (base == 16) return printNumberHex(n);
|
||||
if (base == 2) return printNumberBin(n);
|
||||
return printNumberAny(n, base);
|
||||
}
|
||||
#else
|
||||
size_t printNumber(unsigned long n, uint8_t base, uint8_t sign);
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
/* Teensyduino Core Library
|
||||
* http://www.pjrc.com/teensy/
|
||||
* Copyright (c) 2017 PJRC.COM, LLC.
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* 1. The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* 2. If the Software is incorporated into a build system that allows
|
||||
* selection among a list of target devices, then similar target
|
||||
* devices manufactured by PJRC.COM must be included in the list of
|
||||
* target devices and selectable in the same manner.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef Print_h
|
||||
#define Print_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <stdio.h> // for size_t - gives sprintf and other stuff to all sketches & libs
|
||||
#include <stdarg.h>
|
||||
#include "core_id.h"
|
||||
#include "WString.h"
|
||||
#include "Printable.h"
|
||||
|
||||
#define DEC 10
|
||||
#define HEX 16
|
||||
#define OCT 8
|
||||
#define BIN 2
|
||||
|
||||
|
||||
#ifndef isnan
|
||||
#define isnan(__x) (__builtin_isnan (__x))
|
||||
#endif
|
||||
|
||||
#ifndef isinf
|
||||
#define isinf(__x) (__builtin_isinf (__x))
|
||||
#endif
|
||||
|
||||
|
||||
class __FlashStringHelper;
|
||||
|
||||
class Print
|
||||
{
|
||||
public:
|
||||
constexpr Print() : write_error(0) {}
|
||||
virtual size_t write(uint8_t b) = 0;
|
||||
size_t write(const char *str) { return write((const uint8_t *)str, strlen(str)); }
|
||||
virtual size_t write(const uint8_t *buffer, size_t size);
|
||||
virtual int availableForWrite(void) { return 0; }
|
||||
virtual void flush() { }
|
||||
size_t write(const char *buffer, size_t size) { return write((const uint8_t *)buffer, size); }
|
||||
// size_t print(const String &s);
|
||||
size_t print(char c) { return write((uint8_t)c); }
|
||||
size_t print(const char s[]) { return write(s); }
|
||||
size_t print(const __FlashStringHelper *f) { return write((const char *)f); }
|
||||
|
||||
size_t print(uint8_t b) { return printNumber(b, 10, 0); }
|
||||
size_t print(int n) { return print((long)n); }
|
||||
size_t print(unsigned int n) { return printNumber(n, 10, 0); }
|
||||
size_t print(long n);
|
||||
size_t print(unsigned long n) { return printNumber(n, 10, 0); }
|
||||
|
||||
size_t print(unsigned char n, int base) { return printNumber(n, base, 0); }
|
||||
size_t print(int n, int base) { return (base == 10) ? print(n) : printNumber(n, base, 0); }
|
||||
size_t print(unsigned int n, int base) { return printNumber(n, base, 0); }
|
||||
size_t print(long n, int base) { return (base == 10) ? print(n) : printNumber(n, base, 0); }
|
||||
size_t print(unsigned long n, int base) { return printNumber(n, base, 0); }
|
||||
|
||||
size_t print(double n, int digits = 2) { return printFloat(n, digits); }
|
||||
size_t print(const Printable &obj) { return obj.printTo(*this); }
|
||||
size_t println(void);
|
||||
// size_t println(const String &s) { return print(s) + println(); }
|
||||
size_t println(char c) { return print(c) + println(); }
|
||||
size_t println(const char s[]) { return print(s) + println(); }
|
||||
size_t println(const __FlashStringHelper *f) { return print(f) + println(); }
|
||||
|
||||
size_t println(uint8_t b) { return print(b) + println(); }
|
||||
size_t println(int n) { return print(n) + println(); }
|
||||
size_t println(unsigned int n) { return print(n) + println(); }
|
||||
size_t println(long n) { return print(n) + println(); }
|
||||
size_t println(unsigned long n) { return print(n) + println(); }
|
||||
|
||||
size_t println(unsigned char n, int base) { return print(n, base) + println(); }
|
||||
size_t println(int n, int base) { return print(n, base) + println(); }
|
||||
size_t println(unsigned int n, int base) { return print(n, base) + println(); }
|
||||
size_t println(long n, int base) { return print(n, base) + println(); }
|
||||
size_t println(unsigned long n, int base) { return print(n, base) + println(); }
|
||||
|
||||
size_t println(double n, int digits = 2) { return print(n, digits) + println(); }
|
||||
size_t println(const Printable &obj) { return obj.printTo(*this) + println(); }
|
||||
int getWriteError() { return write_error; }
|
||||
void clearWriteError() { setWriteError(0); }
|
||||
int printf(const char *format, ...);
|
||||
int printf(const __FlashStringHelper *format, ...);
|
||||
protected:
|
||||
void setWriteError(int err = 1) { write_error = err; }
|
||||
private:
|
||||
char write_error;
|
||||
size_t printFloat(double n, uint8_t digits);
|
||||
#ifdef __MKL26Z64__
|
||||
size_t printNumberDec(unsigned long n, uint8_t sign);
|
||||
size_t printNumberHex(unsigned long n);
|
||||
size_t printNumberBin(unsigned long n);
|
||||
size_t printNumberAny(unsigned long n, uint8_t base);
|
||||
inline size_t printNumber(unsigned long n, uint8_t base, uint8_t sign) __attribute__((always_inline)) {
|
||||
// when "base" is a constant (pretty much always), the
|
||||
// compiler optimizes this to a single function call.
|
||||
if (base == 0) return write((uint8_t)n);
|
||||
if (base == 10 || base < 2) return printNumberDec(n, sign);
|
||||
if (base == 16) return printNumberHex(n);
|
||||
if (base == 2) return printNumberBin(n);
|
||||
return printNumberAny(n, base);
|
||||
}
|
||||
#else
|
||||
size_t printNumber(unsigned long n, uint8_t base, uint8_t sign);
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,42 +1,42 @@
|
|||
/*
|
||||
Printable.h - Interface class that allows printing of complex types
|
||||
Copyright (c) 2011 Adrian McEwen. All right reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef Printable_h
|
||||
#define Printable_h
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
// #include "new.h"
|
||||
|
||||
class Print;
|
||||
|
||||
/** The Printable class provides a way for new classes to allow themselves to be printed.
|
||||
By deriving from Printable and implementing the printTo method, it will then be possible
|
||||
for users to print out instances of this class by passing them into the usual
|
||||
Print::print and Print::println methods.
|
||||
*/
|
||||
class Printable
|
||||
{
|
||||
public:
|
||||
virtual size_t printTo(Print& p) const = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
/*
|
||||
Printable.h - Interface class that allows printing of complex types
|
||||
Copyright (c) 2011 Adrian McEwen. All right reserved.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef Printable_h
|
||||
#define Printable_h
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
// #include "new.h"
|
||||
|
||||
class Print;
|
||||
|
||||
/** The Printable class provides a way for new classes to allow themselves to be printed.
|
||||
By deriving from Printable and implementing the printTo method, it will then be possible
|
||||
for users to print out instances of this class by passing them into the usual
|
||||
Print::print and Print::println methods.
|
||||
*/
|
||||
class Printable
|
||||
{
|
||||
public:
|
||||
virtual size_t printTo(Print& p) const = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#if defined(__APPLE__)
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#else
|
||||
#error "Platform not supported, fix include paths and stuff.."
|
||||
#endif
|
||||
#if defined(__APPLE__)
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#else
|
||||
#error "Platform not supported, fix include paths and stuff.."
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
#include <SDL2/SDL_syswm.h>
|
||||
#include <SDL2/SDL_syswm.h>
|
||||
|
|
|
|||
|
|
@ -1,165 +1,165 @@
|
|||
#ifndef __SPI_H__
|
||||
#define __SPI_H__
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
#define SPIClass SimSPI
|
||||
|
||||
|
||||
#ifndef SPI_MODE0
|
||||
#define SPI_MODE0 0
|
||||
#endif
|
||||
|
||||
#ifndef SPI_CLOCK_DIV2
|
||||
#define SPI_CLOCK_DIV2 0
|
||||
#endif
|
||||
|
||||
#define SPDR *SPI.SPI_dataReg
|
||||
#define SPCR *SPI.SPI_ctrlReg
|
||||
#define SPSR *SPI.SPI_statusReg
|
||||
|
||||
//#define SPSR 0xff
|
||||
#define SPIF (SPI.SPI_IF)
|
||||
|
||||
|
||||
// Forward declare
|
||||
class SimSPI;
|
||||
class DataRegister;
|
||||
class SPICtrlRegister;
|
||||
class SPIStatusRegister;
|
||||
|
||||
|
||||
extern SimSPI SPI;
|
||||
|
||||
|
||||
class ISPIDevice
|
||||
{
|
||||
public:
|
||||
virtual uint8_t spiSlaveWrite( uint8_t ) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class SimSPI
|
||||
{
|
||||
public:
|
||||
SimSPI();
|
||||
|
||||
void AddDevice( ISPIDevice* device );
|
||||
|
||||
void begin();
|
||||
|
||||
void transfer( uint8_t something );
|
||||
|
||||
void setDataMode( uint8_t mode );
|
||||
void setClockDivider( uint32_t divider );
|
||||
void writeReg( DataRegister *reg, uint8_t data);
|
||||
|
||||
// Members
|
||||
DataRegister* SPI_dataReg;
|
||||
SPICtrlRegister* SPI_ctrlReg;
|
||||
SPIStatusRegister* SPI_statusReg;
|
||||
|
||||
|
||||
uint8_t SPI_IF;
|
||||
|
||||
private:
|
||||
ISPIDevice** devices;
|
||||
uint32_t devicesArraySize;
|
||||
|
||||
ISPIDevice* currentSlave;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class HWRegister
|
||||
{
|
||||
public:
|
||||
HWRegister( SimSPI& owner) : spi_( owner ) {}
|
||||
protected:
|
||||
SimSPI& spi_;
|
||||
};
|
||||
|
||||
|
||||
class DataRegister : HWRegister
|
||||
{
|
||||
public:
|
||||
DataRegister( SimSPI& owner) : HWRegister( owner ) {}
|
||||
void operator=(uint8_t data)
|
||||
{
|
||||
spi_.writeReg( this, data );
|
||||
}
|
||||
|
||||
operator uint8_t()
|
||||
{
|
||||
// TODO: Get last read byte
|
||||
return 0xffu;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class SPIStatusRegister : HWRegister
|
||||
{
|
||||
public:
|
||||
SPIStatusRegister( SimSPI& owner) : HWRegister( owner ) {}
|
||||
void operator =(uint8_t value)
|
||||
{
|
||||
reg_ = value;
|
||||
}
|
||||
|
||||
void operator |=(uint8_t value)
|
||||
{
|
||||
reg_ |= value;
|
||||
}
|
||||
|
||||
void operator &=(uint8_t value)
|
||||
{
|
||||
reg_ &= value;
|
||||
}
|
||||
/*
|
||||
operator uint8_t()
|
||||
{
|
||||
return reg_|0xff;
|
||||
}
|
||||
*/
|
||||
operator uint32_t()
|
||||
{
|
||||
return reg_|0xff;
|
||||
}
|
||||
|
||||
uint8_t reg_;
|
||||
};
|
||||
|
||||
class SPICtrlRegister : HWRegister
|
||||
{
|
||||
public:
|
||||
SPICtrlRegister( SimSPI& owner) : HWRegister( owner ) {}
|
||||
|
||||
void operator =(uint8_t value)
|
||||
{
|
||||
reg_ = value;
|
||||
}
|
||||
|
||||
void operator |=(uint8_t value)
|
||||
{
|
||||
reg_ |= value;
|
||||
}
|
||||
|
||||
void operator &=(uint8_t value)
|
||||
{
|
||||
reg_ &= value;
|
||||
}
|
||||
|
||||
|
||||
operator uint8_t()
|
||||
{
|
||||
return reg_;
|
||||
}
|
||||
|
||||
|
||||
uint8_t reg_;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
#ifndef __SPI_H__
|
||||
#define __SPI_H__
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
#define SPIClass SimSPI
|
||||
|
||||
|
||||
#ifndef SPI_MODE0
|
||||
#define SPI_MODE0 0
|
||||
#endif
|
||||
|
||||
#ifndef SPI_CLOCK_DIV2
|
||||
#define SPI_CLOCK_DIV2 0
|
||||
#endif
|
||||
|
||||
#define SPDR *SPI.SPI_dataReg
|
||||
#define SPCR *SPI.SPI_ctrlReg
|
||||
#define SPSR *SPI.SPI_statusReg
|
||||
|
||||
//#define SPSR 0xff
|
||||
#define SPIF (SPI.SPI_IF)
|
||||
|
||||
|
||||
// Forward declare
|
||||
class SimSPI;
|
||||
class DataRegister;
|
||||
class SPICtrlRegister;
|
||||
class SPIStatusRegister;
|
||||
|
||||
|
||||
extern SimSPI SPI;
|
||||
|
||||
|
||||
class ISPIDevice
|
||||
{
|
||||
public:
|
||||
virtual uint8_t spiSlaveWrite( uint8_t ) = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
class SimSPI
|
||||
{
|
||||
public:
|
||||
SimSPI();
|
||||
|
||||
void AddDevice( ISPIDevice* device );
|
||||
|
||||
void begin();
|
||||
|
||||
void transfer( uint8_t something );
|
||||
|
||||
void setDataMode( uint8_t mode );
|
||||
void setClockDivider( uint32_t divider );
|
||||
void writeReg( DataRegister *reg, uint8_t data);
|
||||
|
||||
// Members
|
||||
DataRegister* SPI_dataReg;
|
||||
SPICtrlRegister* SPI_ctrlReg;
|
||||
SPIStatusRegister* SPI_statusReg;
|
||||
|
||||
|
||||
uint8_t SPI_IF;
|
||||
|
||||
private:
|
||||
ISPIDevice** devices;
|
||||
uint32_t devicesArraySize;
|
||||
|
||||
ISPIDevice* currentSlave;
|
||||
|
||||
};
|
||||
|
||||
|
||||
class HWRegister
|
||||
{
|
||||
public:
|
||||
HWRegister( SimSPI& owner) : spi_( owner ) {}
|
||||
protected:
|
||||
SimSPI& spi_;
|
||||
};
|
||||
|
||||
|
||||
class DataRegister : HWRegister
|
||||
{
|
||||
public:
|
||||
DataRegister( SimSPI& owner) : HWRegister( owner ) {}
|
||||
void operator=(uint8_t data)
|
||||
{
|
||||
spi_.writeReg( this, data );
|
||||
}
|
||||
|
||||
operator uint8_t()
|
||||
{
|
||||
// TODO: Get last read byte
|
||||
return 0xffu;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class SPIStatusRegister : HWRegister
|
||||
{
|
||||
public:
|
||||
SPIStatusRegister( SimSPI& owner) : HWRegister( owner ) {}
|
||||
void operator =(uint8_t value)
|
||||
{
|
||||
reg_ = value;
|
||||
}
|
||||
|
||||
void operator |=(uint8_t value)
|
||||
{
|
||||
reg_ |= value;
|
||||
}
|
||||
|
||||
void operator &=(uint8_t value)
|
||||
{
|
||||
reg_ &= value;
|
||||
}
|
||||
/*
|
||||
operator uint8_t()
|
||||
{
|
||||
return reg_|0xff;
|
||||
}
|
||||
*/
|
||||
operator uint32_t()
|
||||
{
|
||||
return reg_|0xff;
|
||||
}
|
||||
|
||||
uint8_t reg_;
|
||||
};
|
||||
|
||||
class SPICtrlRegister : HWRegister
|
||||
{
|
||||
public:
|
||||
SPICtrlRegister( SimSPI& owner) : HWRegister( owner ) {}
|
||||
|
||||
void operator =(uint8_t value)
|
||||
{
|
||||
reg_ = value;
|
||||
}
|
||||
|
||||
void operator |=(uint8_t value)
|
||||
{
|
||||
reg_ |= value;
|
||||
}
|
||||
|
||||
void operator &=(uint8_t value)
|
||||
{
|
||||
reg_ &= value;
|
||||
}
|
||||
|
||||
|
||||
operator uint8_t()
|
||||
{
|
||||
return reg_;
|
||||
}
|
||||
|
||||
|
||||
uint8_t reg_;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,227 +1,227 @@
|
|||
/*
|
||||
WString.h - String library for Wiring & Arduino
|
||||
...mostly rewritten by Paul Stoffregen...
|
||||
Copyright (c) 2009-10 Hernando Barragan. All right reserved.
|
||||
Copyright 2011, Paul Stoffregen, paul@pjrc.com
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef String_class_h
|
||||
#define String_class_h
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
//#include "avr_functions.h"
|
||||
|
||||
// Not needed here, but some libs assume WString.h or Print.h
|
||||
// gives them PROGMEM and other AVR stuff.
|
||||
//#include "avr/pgmspace.h"
|
||||
|
||||
// When compiling programs with this class, the following gcc parameters
|
||||
// dramatically increase performance and memory (RAM) efficiency, typically
|
||||
// with little or no increase in code size.
|
||||
// -felide-constructors
|
||||
// -std=c++0x
|
||||
|
||||
// Brian Cook's "no overhead" Flash String type (message on Dec 14, 2010)
|
||||
// modified by Mikal Hart for his FlashString library
|
||||
class __FlashStringHelper;
|
||||
#ifndef F
|
||||
#define F(string_literal) ((const __FlashStringHelper *)(string_literal))
|
||||
#endif
|
||||
|
||||
// An inherited class for holding the result of a concatenation. These
|
||||
// result objects are assumed to be writable by subsequent concatenations.
|
||||
class StringSumHelper;
|
||||
|
||||
// The string class
|
||||
class String
|
||||
{
|
||||
public:
|
||||
// constructors
|
||||
String(const char *cstr = (const char *)NULL);
|
||||
String(const __FlashStringHelper *pgmstr);
|
||||
String(const String &str);
|
||||
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
String(String &&rval);
|
||||
String(StringSumHelper &&rval);
|
||||
#endif
|
||||
String(char c);
|
||||
String(unsigned char c);
|
||||
String(int, unsigned char base=10);
|
||||
String(unsigned int, unsigned char base=10);
|
||||
String(long, unsigned char base=10);
|
||||
String(unsigned long, unsigned char base=10);
|
||||
String(float num, unsigned char digits=2);
|
||||
String(double num, unsigned char digits=2) : String((float)num, digits) {}
|
||||
~String(void);
|
||||
|
||||
// memory management
|
||||
unsigned char reserve(unsigned int size);
|
||||
inline unsigned int length(void) const {return len;}
|
||||
|
||||
// copy and move
|
||||
String & copy(const char *cstr, unsigned int length);
|
||||
String & copy(const __FlashStringHelper *s) { return copy((const char *)s, strlen((const char *)s)); }
|
||||
void move(String &rhs);
|
||||
String & operator = (const String &rhs);
|
||||
String & operator = (const char *cstr);
|
||||
String & operator = (const __FlashStringHelper *pgmstr);
|
||||
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
String & operator = (String &&rval);
|
||||
String & operator = (StringSumHelper &&rval);
|
||||
#endif
|
||||
String & operator = (char c);
|
||||
|
||||
// append
|
||||
String & append(const String &str);
|
||||
String & append(const char *cstr);
|
||||
String & append(const __FlashStringHelper *s) {return append((const char *)s, strlen((const char *)s)); }
|
||||
String & append(char c);
|
||||
String & append(unsigned char c) {return append((int)c);}
|
||||
String & append(int num);
|
||||
String & append(unsigned int num);
|
||||
String & append(long num);
|
||||
String & append(unsigned long num);
|
||||
String & append(float num);
|
||||
String & append(double num) {return append((float)num);}
|
||||
String & operator += (const String &rhs) {return append(rhs);}
|
||||
String & operator += (const char *cstr) {return append(cstr);}
|
||||
String & operator += (const __FlashStringHelper *pgmstr) {return append(pgmstr);}
|
||||
String & operator += (char c) {return append(c);}
|
||||
String & operator += (unsigned char c) {return append((int)c);}
|
||||
String & operator += (int num) {return append(num);}
|
||||
String & operator += (unsigned int num) {return append(num);}
|
||||
String & operator += (long num) {return append(num);}
|
||||
String & operator += (unsigned long num) {return append(num);}
|
||||
String & operator += (float num) {return append(num);}
|
||||
String & operator += (double num) {return append(num);}
|
||||
|
||||
// concatenate
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *pgmstr);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, char c);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char c);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, int num);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, long num);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, float num);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, double num);
|
||||
String & concat(const String &str) {return append(str);}
|
||||
String & concat(const char *cstr) {return append(cstr);}
|
||||
String & concat(const __FlashStringHelper *pgmstr) {return append(pgmstr);}
|
||||
String & concat(char c) {return append(c);}
|
||||
String & concat(unsigned char c) {return append((int)c);}
|
||||
String & concat(int num) {return append(num);}
|
||||
String & concat(unsigned int num) {return append(num);}
|
||||
String & concat(long num) {return append(num);}
|
||||
String & concat(unsigned long num) {return append(num);}
|
||||
String & concat(float num) {return append(num);}
|
||||
String & concat(double num) {return append(num);}
|
||||
|
||||
// comparison
|
||||
int compareTo(const String &s) const;
|
||||
unsigned char equals(const String &s) const;
|
||||
unsigned char equals(const char *cstr) const;
|
||||
//unsigned char equals(const __FlashStringHelper *pgmstr) const;
|
||||
unsigned char operator == (const String &rhs) const {return equals(rhs);}
|
||||
unsigned char operator == (const char *cstr) const {return equals(cstr);}
|
||||
unsigned char operator == (const __FlashStringHelper *s) const {return equals((const char *)s);}
|
||||
unsigned char operator != (const String &rhs) const {return !equals(rhs);}
|
||||
unsigned char operator != (const char *cstr) const {return !equals(cstr);}
|
||||
unsigned char operator != (const __FlashStringHelper *s) const {return !equals(s);}
|
||||
unsigned char operator < (const String &rhs) const;
|
||||
unsigned char operator > (const String &rhs) const;
|
||||
unsigned char operator <= (const String &rhs) const;
|
||||
unsigned char operator >= (const String &rhs) const;
|
||||
unsigned char equalsIgnoreCase(const String &s) const;
|
||||
unsigned char startsWith( const String &prefix) const;
|
||||
unsigned char startsWith(const String &prefix, unsigned int offset) const;
|
||||
unsigned char endsWith(const String &suffix) const;
|
||||
|
||||
// character acccess
|
||||
char charAt(unsigned int index) const;
|
||||
void setCharAt(unsigned int index, char c);
|
||||
char operator [] (unsigned int index) const;
|
||||
char& operator [] (unsigned int index);
|
||||
void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const;
|
||||
void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const
|
||||
{getBytes((unsigned char *)buf, bufsize, index);}
|
||||
const char * c_str() const { return buffer; }
|
||||
|
||||
// search
|
||||
int indexOf( char ch ) const;
|
||||
int indexOf( char ch, unsigned int fromIndex ) const;
|
||||
int indexOf( const String &str ) const;
|
||||
int indexOf( const String &str, unsigned int fromIndex ) const;
|
||||
int lastIndexOf( char ch ) const;
|
||||
int lastIndexOf( char ch, unsigned int fromIndex ) const;
|
||||
int lastIndexOf( const String &str ) const;
|
||||
int lastIndexOf( const String &str, unsigned int fromIndex ) const;
|
||||
String substring( unsigned int beginIndex ) const;
|
||||
String substring( unsigned int beginIndex, unsigned int endIndex ) const;
|
||||
|
||||
// modification
|
||||
String & replace(char find, char replace);
|
||||
String & replace(const String& find, const String& replace);
|
||||
String & remove(unsigned int index);
|
||||
String & remove(unsigned int index, unsigned int count);
|
||||
String & toLowerCase(void);
|
||||
String & toUpperCase(void);
|
||||
String & trim(void);
|
||||
|
||||
// parsing/conversion
|
||||
long toInt(void) const;
|
||||
float toFloat(void) const;
|
||||
|
||||
protected:
|
||||
char *buffer; // the actual char array
|
||||
unsigned int capacity; // the array length minus one (for the '\0')
|
||||
unsigned int len; // the String length (not counting the '\0')
|
||||
unsigned char flags; // unused, for future features
|
||||
protected:
|
||||
void init(void);
|
||||
unsigned char changeBuffer(unsigned int maxStrLen);
|
||||
String & append(const char *cstr, unsigned int length);
|
||||
private:
|
||||
// allow for "if (s)" without the complications of an operator bool().
|
||||
// for more information http://www.artima.com/cppsource/safebool.html
|
||||
typedef void (String::*StringIfHelperType)() const;
|
||||
void StringIfHelper() const {}
|
||||
public:
|
||||
operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; }
|
||||
};
|
||||
|
||||
class StringSumHelper : public String
|
||||
{
|
||||
public:
|
||||
StringSumHelper(const String &s) : String(s) {}
|
||||
StringSumHelper(const char *p) : String(p) {}
|
||||
StringSumHelper(const __FlashStringHelper *pgmstr) : String(pgmstr) {}
|
||||
StringSumHelper(char c) : String(c) {}
|
||||
StringSumHelper(unsigned char c) : String(c) {}
|
||||
StringSumHelper(int num) : String(num, 10) {}
|
||||
StringSumHelper(unsigned int num) : String(num, 10) {}
|
||||
StringSumHelper(long num) : String(num, 10) {}
|
||||
StringSumHelper(unsigned long num) : String(num, 10) {}
|
||||
};
|
||||
|
||||
#endif // __cplusplus
|
||||
#endif // String_class_h
|
||||
/*
|
||||
WString.h - String library for Wiring & Arduino
|
||||
...mostly rewritten by Paul Stoffregen...
|
||||
Copyright (c) 2009-10 Hernando Barragan. All right reserved.
|
||||
Copyright 2011, Paul Stoffregen, paul@pjrc.com
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#ifndef String_class_h
|
||||
#define String_class_h
|
||||
#ifdef __cplusplus
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
//#include "avr_functions.h"
|
||||
|
||||
// Not needed here, but some libs assume WString.h or Print.h
|
||||
// gives them PROGMEM and other AVR stuff.
|
||||
//#include "avr/pgmspace.h"
|
||||
|
||||
// When compiling programs with this class, the following gcc parameters
|
||||
// dramatically increase performance and memory (RAM) efficiency, typically
|
||||
// with little or no increase in code size.
|
||||
// -felide-constructors
|
||||
// -std=c++0x
|
||||
|
||||
// Brian Cook's "no overhead" Flash String type (message on Dec 14, 2010)
|
||||
// modified by Mikal Hart for his FlashString library
|
||||
class __FlashStringHelper;
|
||||
#ifndef F
|
||||
#define F(string_literal) ((const __FlashStringHelper *)(string_literal))
|
||||
#endif
|
||||
|
||||
// An inherited class for holding the result of a concatenation. These
|
||||
// result objects are assumed to be writable by subsequent concatenations.
|
||||
class StringSumHelper;
|
||||
|
||||
// The string class
|
||||
class String
|
||||
{
|
||||
public:
|
||||
// constructors
|
||||
String(const char *cstr = (const char *)NULL);
|
||||
String(const __FlashStringHelper *pgmstr);
|
||||
String(const String &str);
|
||||
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
String(String &&rval);
|
||||
String(StringSumHelper &&rval);
|
||||
#endif
|
||||
String(char c);
|
||||
String(unsigned char c);
|
||||
String(int, unsigned char base=10);
|
||||
String(unsigned int, unsigned char base=10);
|
||||
String(long, unsigned char base=10);
|
||||
String(unsigned long, unsigned char base=10);
|
||||
String(float num, unsigned char digits=2);
|
||||
String(double num, unsigned char digits=2) : String((float)num, digits) {}
|
||||
~String(void);
|
||||
|
||||
// memory management
|
||||
unsigned char reserve(unsigned int size);
|
||||
inline unsigned int length(void) const {return len;}
|
||||
|
||||
// copy and move
|
||||
String & copy(const char *cstr, unsigned int length);
|
||||
String & copy(const __FlashStringHelper *s) { return copy((const char *)s, strlen((const char *)s)); }
|
||||
void move(String &rhs);
|
||||
String & operator = (const String &rhs);
|
||||
String & operator = (const char *cstr);
|
||||
String & operator = (const __FlashStringHelper *pgmstr);
|
||||
#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__)
|
||||
String & operator = (String &&rval);
|
||||
String & operator = (StringSumHelper &&rval);
|
||||
#endif
|
||||
String & operator = (char c);
|
||||
|
||||
// append
|
||||
String & append(const String &str);
|
||||
String & append(const char *cstr);
|
||||
String & append(const __FlashStringHelper *s) {return append((const char *)s, strlen((const char *)s)); }
|
||||
String & append(char c);
|
||||
String & append(unsigned char c) {return append((int)c);}
|
||||
String & append(int num);
|
||||
String & append(unsigned int num);
|
||||
String & append(long num);
|
||||
String & append(unsigned long num);
|
||||
String & append(float num);
|
||||
String & append(double num) {return append((float)num);}
|
||||
String & operator += (const String &rhs) {return append(rhs);}
|
||||
String & operator += (const char *cstr) {return append(cstr);}
|
||||
String & operator += (const __FlashStringHelper *pgmstr) {return append(pgmstr);}
|
||||
String & operator += (char c) {return append(c);}
|
||||
String & operator += (unsigned char c) {return append((int)c);}
|
||||
String & operator += (int num) {return append(num);}
|
||||
String & operator += (unsigned int num) {return append(num);}
|
||||
String & operator += (long num) {return append(num);}
|
||||
String & operator += (unsigned long num) {return append(num);}
|
||||
String & operator += (float num) {return append(num);}
|
||||
String & operator += (double num) {return append(num);}
|
||||
|
||||
// concatenate
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, const String &rhs);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, const char *cstr);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, const __FlashStringHelper *pgmstr);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, char c);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned char c);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, int num);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned int num);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, long num);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, unsigned long num);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, float num);
|
||||
friend StringSumHelper & operator + (const StringSumHelper &lhs, double num);
|
||||
String & concat(const String &str) {return append(str);}
|
||||
String & concat(const char *cstr) {return append(cstr);}
|
||||
String & concat(const __FlashStringHelper *pgmstr) {return append(pgmstr);}
|
||||
String & concat(char c) {return append(c);}
|
||||
String & concat(unsigned char c) {return append((int)c);}
|
||||
String & concat(int num) {return append(num);}
|
||||
String & concat(unsigned int num) {return append(num);}
|
||||
String & concat(long num) {return append(num);}
|
||||
String & concat(unsigned long num) {return append(num);}
|
||||
String & concat(float num) {return append(num);}
|
||||
String & concat(double num) {return append(num);}
|
||||
|
||||
// comparison
|
||||
int compareTo(const String &s) const;
|
||||
unsigned char equals(const String &s) const;
|
||||
unsigned char equals(const char *cstr) const;
|
||||
//unsigned char equals(const __FlashStringHelper *pgmstr) const;
|
||||
unsigned char operator == (const String &rhs) const {return equals(rhs);}
|
||||
unsigned char operator == (const char *cstr) const {return equals(cstr);}
|
||||
unsigned char operator == (const __FlashStringHelper *s) const {return equals((const char *)s);}
|
||||
unsigned char operator != (const String &rhs) const {return !equals(rhs);}
|
||||
unsigned char operator != (const char *cstr) const {return !equals(cstr);}
|
||||
unsigned char operator != (const __FlashStringHelper *s) const {return !equals(s);}
|
||||
unsigned char operator < (const String &rhs) const;
|
||||
unsigned char operator > (const String &rhs) const;
|
||||
unsigned char operator <= (const String &rhs) const;
|
||||
unsigned char operator >= (const String &rhs) const;
|
||||
unsigned char equalsIgnoreCase(const String &s) const;
|
||||
unsigned char startsWith( const String &prefix) const;
|
||||
unsigned char startsWith(const String &prefix, unsigned int offset) const;
|
||||
unsigned char endsWith(const String &suffix) const;
|
||||
|
||||
// character acccess
|
||||
char charAt(unsigned int index) const;
|
||||
void setCharAt(unsigned int index, char c);
|
||||
char operator [] (unsigned int index) const;
|
||||
char& operator [] (unsigned int index);
|
||||
void getBytes(unsigned char *buf, unsigned int bufsize, unsigned int index=0) const;
|
||||
void toCharArray(char *buf, unsigned int bufsize, unsigned int index=0) const
|
||||
{getBytes((unsigned char *)buf, bufsize, index);}
|
||||
const char * c_str() const { return buffer; }
|
||||
|
||||
// search
|
||||
int indexOf( char ch ) const;
|
||||
int indexOf( char ch, unsigned int fromIndex ) const;
|
||||
int indexOf( const String &str ) const;
|
||||
int indexOf( const String &str, unsigned int fromIndex ) const;
|
||||
int lastIndexOf( char ch ) const;
|
||||
int lastIndexOf( char ch, unsigned int fromIndex ) const;
|
||||
int lastIndexOf( const String &str ) const;
|
||||
int lastIndexOf( const String &str, unsigned int fromIndex ) const;
|
||||
String substring( unsigned int beginIndex ) const;
|
||||
String substring( unsigned int beginIndex, unsigned int endIndex ) const;
|
||||
|
||||
// modification
|
||||
String & replace(char find, char replace);
|
||||
String & replace(const String& find, const String& replace);
|
||||
String & remove(unsigned int index);
|
||||
String & remove(unsigned int index, unsigned int count);
|
||||
String & toLowerCase(void);
|
||||
String & toUpperCase(void);
|
||||
String & trim(void);
|
||||
|
||||
// parsing/conversion
|
||||
long toInt(void) const;
|
||||
float toFloat(void) const;
|
||||
|
||||
protected:
|
||||
char *buffer; // the actual char array
|
||||
unsigned int capacity; // the array length minus one (for the '\0')
|
||||
unsigned int len; // the String length (not counting the '\0')
|
||||
unsigned char flags; // unused, for future features
|
||||
protected:
|
||||
void init(void);
|
||||
unsigned char changeBuffer(unsigned int maxStrLen);
|
||||
String & append(const char *cstr, unsigned int length);
|
||||
private:
|
||||
// allow for "if (s)" without the complications of an operator bool().
|
||||
// for more information http://www.artima.com/cppsource/safebool.html
|
||||
typedef void (String::*StringIfHelperType)() const;
|
||||
void StringIfHelper() const {}
|
||||
public:
|
||||
operator StringIfHelperType() const { return buffer ? &String::StringIfHelper : 0; }
|
||||
};
|
||||
|
||||
class StringSumHelper : public String
|
||||
{
|
||||
public:
|
||||
StringSumHelper(const String &s) : String(s) {}
|
||||
StringSumHelper(const char *p) : String(p) {}
|
||||
StringSumHelper(const __FlashStringHelper *pgmstr) : String(pgmstr) {}
|
||||
StringSumHelper(char c) : String(c) {}
|
||||
StringSumHelper(unsigned char c) : String(c) {}
|
||||
StringSumHelper(int num) : String(num, 10) {}
|
||||
StringSumHelper(unsigned int num) : String(num, 10) {}
|
||||
StringSumHelper(long num) : String(num, 10) {}
|
||||
StringSumHelper(unsigned long num) : String(num, 10) {}
|
||||
};
|
||||
|
||||
#endif // __cplusplus
|
||||
#endif // String_class_h
|
||||
|
|
|
|||
|
|
@ -1,38 +1,38 @@
|
|||
#ifndef __WIRE_H__
|
||||
#define __WIRE_H__
|
||||
|
||||
#include <cstdint>
|
||||
#define TwoWire SimWire
|
||||
|
||||
class SimWire
|
||||
{
|
||||
public:
|
||||
SimWire(bool verbose = false);
|
||||
|
||||
void begin();
|
||||
void begin( uint8_t address ); // For slaves.
|
||||
void end();
|
||||
void setClock(uint32_t);
|
||||
void beginTransmission(uint8_t address);
|
||||
void beginTransmission(int);
|
||||
uint8_t endTransmission();
|
||||
uint8_t endTransmission(uint8_t);
|
||||
uint8_t requestFrom(uint8_t address, uint8_t count);
|
||||
uint8_t requestFrom(uint8_t, uint8_t, uint8_t);
|
||||
uint8_t requestFrom(uint8_t, uint8_t, uint32_t, uint8_t, uint8_t);
|
||||
size_t write(uint8_t);
|
||||
size_t write(const uint8_t *, size_t);
|
||||
int available();
|
||||
int read();
|
||||
int peek();
|
||||
void flush();
|
||||
void onReceive( void (*)(int) );
|
||||
void onRequest( void (*)(void) );
|
||||
private:
|
||||
bool verbose_;
|
||||
};
|
||||
|
||||
extern SimWire Wire;
|
||||
|
||||
|
||||
#endif
|
||||
#ifndef __WIRE_H__
|
||||
#define __WIRE_H__
|
||||
|
||||
#include <cstdint>
|
||||
#define TwoWire SimWire
|
||||
|
||||
class SimWire
|
||||
{
|
||||
public:
|
||||
SimWire(bool verbose = false);
|
||||
|
||||
void begin();
|
||||
void begin( uint8_t address ); // For slaves.
|
||||
void end();
|
||||
void setClock(uint32_t);
|
||||
void beginTransmission(uint8_t address);
|
||||
void beginTransmission(int);
|
||||
uint8_t endTransmission();
|
||||
uint8_t endTransmission(uint8_t);
|
||||
uint8_t requestFrom(uint8_t address, uint8_t count);
|
||||
uint8_t requestFrom(uint8_t, uint8_t, uint8_t);
|
||||
uint8_t requestFrom(uint8_t, uint8_t, uint32_t, uint8_t, uint8_t);
|
||||
size_t write(uint8_t);
|
||||
size_t write(const uint8_t *, size_t);
|
||||
int available();
|
||||
int read();
|
||||
int peek();
|
||||
void flush();
|
||||
void onReceive( void (*)(int) );
|
||||
void onRequest( void (*)(void) );
|
||||
private:
|
||||
bool verbose_;
|
||||
};
|
||||
|
||||
extern SimWire Wire;
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,5 +1,5 @@
|
|||
// This header file is in the public domain.
|
||||
|
||||
#ifndef CORE_TEENSY
|
||||
#define CORE_TEENSY
|
||||
#endif
|
||||
// This header file is in the public domain.
|
||||
|
||||
#ifndef CORE_TEENSY
|
||||
#define CORE_TEENSY
|
||||
#endif
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,29 +1,29 @@
|
|||
// Font structures for newer Adafruit_GFX (1.1 and later).
|
||||
// Example fonts are included in 'Fonts' directory.
|
||||
// To use a font in your Arduino sketch, #include the corresponding .h
|
||||
// file and pass address of GFXfont struct to setFont(). Pass NULL to
|
||||
// revert to 'classic' fixed-space bitmap font.
|
||||
|
||||
#ifndef _GFXFONT_H_
|
||||
#define _GFXFONT_H_
|
||||
|
||||
/// Font data stored PER GLYPH
|
||||
typedef struct {
|
||||
uint16_t bitmapOffset; ///< Pointer into GFXfont->bitmap
|
||||
uint8_t width; ///< Bitmap dimensions in pixels
|
||||
uint8_t height; ///< Bitmap dimensions in pixels
|
||||
uint8_t xAdvance; ///< Distance to advance cursor (x axis)
|
||||
int8_t xOffset; ///< X dist from cursor pos to UL corner
|
||||
int8_t yOffset; ///< Y dist from cursor pos to UL corner
|
||||
} GFXglyph;
|
||||
|
||||
/// Data stored for FONT AS A WHOLE
|
||||
typedef struct {
|
||||
uint8_t *bitmap; ///< Glyph bitmaps, concatenated
|
||||
GFXglyph *glyph; ///< Glyph array
|
||||
uint8_t first; ///< ASCII extents (first char)
|
||||
uint8_t last; ///< ASCII extents (last char)
|
||||
uint8_t yAdvance; ///< Newline distance (y axis)
|
||||
} GFXfont;
|
||||
|
||||
#endif // _GFXFONT_H_
|
||||
// Font structures for newer Adafruit_GFX (1.1 and later).
|
||||
// Example fonts are included in 'Fonts' directory.
|
||||
// To use a font in your Arduino sketch, #include the corresponding .h
|
||||
// file and pass address of GFXfont struct to setFont(). Pass NULL to
|
||||
// revert to 'classic' fixed-space bitmap font.
|
||||
|
||||
#ifndef _GFXFONT_H_
|
||||
#define _GFXFONT_H_
|
||||
|
||||
/// Font data stored PER GLYPH
|
||||
typedef struct {
|
||||
uint16_t bitmapOffset; ///< Pointer into GFXfont->bitmap
|
||||
uint8_t width; ///< Bitmap dimensions in pixels
|
||||
uint8_t height; ///< Bitmap dimensions in pixels
|
||||
uint8_t xAdvance; ///< Distance to advance cursor (x axis)
|
||||
int8_t xOffset; ///< X dist from cursor pos to UL corner
|
||||
int8_t yOffset; ///< Y dist from cursor pos to UL corner
|
||||
} GFXglyph;
|
||||
|
||||
/// Data stored for FONT AS A WHOLE
|
||||
typedef struct {
|
||||
uint8_t *bitmap; ///< Glyph bitmaps, concatenated
|
||||
GFXglyph *glyph; ///< Glyph array
|
||||
uint8_t first; ///< ASCII extents (first char)
|
||||
uint8_t last; ///< ASCII extents (last char)
|
||||
uint8_t yAdvance; ///< Newline distance (y axis)
|
||||
} GFXfont;
|
||||
|
||||
#endif // _GFXFONT_H_
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
#ifndef __INTERRUPTS_H
|
||||
#define __INTERRUPTS_H
|
||||
|
||||
//Dummy functions, used by macros for interrupts() / noInterrupts()
|
||||
void __enable_irq() {}
|
||||
void __disable_irq() {}
|
||||
|
||||
|
||||
struct IntervalTimer
|
||||
{
|
||||
public:
|
||||
IntervalTimer() {};
|
||||
bool begin(void (*funct)(), unsigned int microseconds) { };
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
#ifndef __INTERRUPTS_H
|
||||
#define __INTERRUPTS_H
|
||||
|
||||
//Dummy functions, used by macros for interrupts() / noInterrupts()
|
||||
void __enable_irq() {}
|
||||
void __disable_irq() {}
|
||||
|
||||
|
||||
struct IntervalTimer
|
||||
{
|
||||
public:
|
||||
IntervalTimer() {};
|
||||
bool begin(void (*funct)(), unsigned int microseconds) { };
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,283 +1,283 @@
|
|||
/* Teensyduino Core Library
|
||||
* http://www.pjrc.com/teensy/
|
||||
* Copyright (c) 2017 PJRC.COM, LLC.
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* 1. The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* 2. If the Software is incorporated into a build system that allows
|
||||
* selection among a list of target devices, then similar target
|
||||
* devices manufactured by PJRC.COM must be included in the list of
|
||||
* target devices and selectable in the same manner.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef pins_macros_for_arduino_compatibility_h
|
||||
#define pins_macros_for_arduino_compatibility_h
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// A0-A9 are always digital 14-23, for Arduino compatibility
|
||||
#define PIN_A0 (14)
|
||||
#define PIN_A1 (15)
|
||||
#define PIN_A2 (16)
|
||||
#define PIN_A3 (17)
|
||||
#define PIN_A4 (18)
|
||||
#define PIN_A5 (19)
|
||||
#define PIN_A6 (20)
|
||||
#define PIN_A7 (21)
|
||||
#define PIN_A8 (22)
|
||||
#define PIN_A9 (23)
|
||||
const static uint8_t A0 = PIN_A0;
|
||||
const static uint8_t A1 = PIN_A1;
|
||||
const static uint8_t A2 = PIN_A2;
|
||||
const static uint8_t A3 = PIN_A3;
|
||||
const static uint8_t A4 = PIN_A4;
|
||||
const static uint8_t A5 = PIN_A5;
|
||||
const static uint8_t A6 = PIN_A6;
|
||||
const static uint8_t A7 = PIN_A7;
|
||||
const static uint8_t A8 = PIN_A8;
|
||||
const static uint8_t A9 = PIN_A9;
|
||||
|
||||
#if defined(__MK20DX128__)
|
||||
#define PIN_A10 (34)
|
||||
#define PIN_A11 (35)
|
||||
#define PIN_A12 (36)
|
||||
#define PIN_A13 (37)
|
||||
const static uint8_t A10 = PIN_A10;
|
||||
const static uint8_t A11 = PIN_A11;
|
||||
const static uint8_t A12 = PIN_A12;
|
||||
const static uint8_t A13 = PIN_A13;
|
||||
|
||||
#elif defined(__MK20DX256__)
|
||||
#define PIN_A10 (34)
|
||||
#define PIN_A11 (35)
|
||||
#define PIN_A12 (36)
|
||||
#define PIN_A13 (37)
|
||||
#define PIN_A14 (40)
|
||||
#define PIN_A15 (26)
|
||||
#define PIN_A16 (27)
|
||||
#define PIN_A17 (28)
|
||||
#define PIN_A18 (29)
|
||||
#define PIN_A19 (30)
|
||||
#define PIN_A20 (31)
|
||||
const static uint8_t A10 = PIN_A10;
|
||||
const static uint8_t A11 = PIN_A11;
|
||||
const static uint8_t A12 = PIN_A12;
|
||||
const static uint8_t A13 = PIN_A13;
|
||||
const static uint8_t A14 = PIN_A14;
|
||||
const static uint8_t A15 = PIN_A15;
|
||||
const static uint8_t A16 = PIN_A16;
|
||||
const static uint8_t A17 = PIN_A17;
|
||||
const static uint8_t A18 = PIN_A18;
|
||||
const static uint8_t A19 = PIN_A19;
|
||||
const static uint8_t A20 = PIN_A20;
|
||||
|
||||
#elif defined(__MKL26Z64__)
|
||||
#define PIN_A10 (24)
|
||||
#define PIN_A11 (25)
|
||||
#define PIN_A12 (26)
|
||||
const static uint8_t A10 = PIN_A10;
|
||||
const static uint8_t A11 = PIN_A11;
|
||||
const static uint8_t A12 = PIN_A12;
|
||||
|
||||
#elif defined(__MK64FX512__) || defined(__MK66FX1M0__)
|
||||
#define PIN_A10 (64)
|
||||
#define PIN_A11 (65)
|
||||
#define PIN_A12 (31)
|
||||
#define PIN_A13 (32)
|
||||
#define PIN_A14 (33)
|
||||
#define PIN_A15 (34)
|
||||
#define PIN_A16 (35)
|
||||
#define PIN_A17 (36)
|
||||
#define PIN_A18 (37)
|
||||
#define PIN_A19 (38)
|
||||
#define PIN_A20 (39)
|
||||
#define PIN_A21 (66)
|
||||
#define PIN_A22 (67)
|
||||
#define PIN_A23 (49)
|
||||
#define PIN_A24 (50)
|
||||
#define PIN_A25 (68)
|
||||
#define PIN_A26 (69)
|
||||
const static uint8_t A10 = PIN_A10;
|
||||
const static uint8_t A11 = PIN_A11;
|
||||
const static uint8_t A12 = PIN_A12;
|
||||
const static uint8_t A13 = PIN_A13;
|
||||
const static uint8_t A14 = PIN_A14;
|
||||
const static uint8_t A15 = PIN_A15;
|
||||
const static uint8_t A16 = PIN_A16;
|
||||
const static uint8_t A17 = PIN_A17;
|
||||
const static uint8_t A18 = PIN_A18;
|
||||
const static uint8_t A19 = PIN_A19;
|
||||
const static uint8_t A20 = PIN_A20;
|
||||
const static uint8_t A21 = PIN_A21;
|
||||
const static uint8_t A22 = PIN_A22;
|
||||
const static uint8_t A23 = PIN_A23;
|
||||
const static uint8_t A24 = PIN_A24;
|
||||
const static uint8_t A25 = PIN_A25;
|
||||
const static uint8_t A26 = PIN_A26;
|
||||
#endif
|
||||
|
||||
#define LED_BUILTIN (13)
|
||||
|
||||
#define PIN_SPI_SS (10)
|
||||
#define PIN_SPI_MOSI (11)
|
||||
#define PIN_SPI_MISO (12)
|
||||
#define PIN_SPI_SCK (13)
|
||||
const static uint8_t SS = 10;
|
||||
const static uint8_t MOSI = 11;
|
||||
const static uint8_t MISO = 12;
|
||||
const static uint8_t SCK = 13;
|
||||
|
||||
#define PIN_WIRE_SDA (18)
|
||||
#define PIN_WIRE_SCL (19)
|
||||
const static uint8_t SDA = 18;
|
||||
const static uint8_t SCL = 19;
|
||||
|
||||
#define PIN_SERIAL_RX (0)
|
||||
#define PIN_SERIAL_TX (1)
|
||||
|
||||
|
||||
#define NUM_DIGITAL_PINS CORE_NUM_DIGITAL
|
||||
#define NUM_ANALOG_INPUTS CORE_NUM_ANALOG
|
||||
|
||||
|
||||
#define NOT_AN_INTERRUPT -1
|
||||
|
||||
|
||||
#if defined(__MK20DX128__)
|
||||
#define analogInputToDigitalPin(p) (((p) <= 9) ? (p) + 14 : (((p) <= 13) ? (p) + 24 : -1))
|
||||
#define digitalPinHasPWM(p) (((p) >= 3 && (p) <= 6) || (p) == 9 || (p) == 10 || ((p) >= 20 && (p) <= 23))
|
||||
#define digitalPinToInterrupt(p) ((p) < NUM_DIGITAL_PINS ? (p) : -1)
|
||||
#elif defined(__MK20DX256__)
|
||||
#define analogInputToDigitalPin(p) (((p) <= 9) ? (p) + 14 : (((p) <= 13) ? (p) + 24 : (((p) == 14) ? 40 : (((p) <= 20) ? (p) + 11 : -1))))
|
||||
#define digitalPinHasPWM(p) (((p) >= 3 && (p) <= 6) || (p) == 9 || (p) == 10 || ((p) >= 20 && (p) <= 23) || (p) == 25 || (p) == 32)
|
||||
#define digitalPinToInterrupt(p) ((p) < NUM_DIGITAL_PINS ? (p) : -1)
|
||||
#elif defined(__MKL26Z64__)
|
||||
#define analogInputToDigitalPin(p) (((p) <= 9) ? (p) + 14 : (((p) <= 12) ? (p) + 14 : -1))
|
||||
#define digitalPinHasPWM(p) ((p) == 3 || (p) == 4 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 16 || (p) == 17 || (p) == 20 || (p) == 22 || (p) == 23)
|
||||
#define digitalPinToInterrupt(p) ((((p) >= 2 && (p) <= 15) || ((p) >= 20 && (p) <= 23)) ? (p) : -1)
|
||||
#elif defined(__MK64FX512__) || defined(__MK66FX1M0__)
|
||||
// TODO analogInputToDigitalPin needs update...
|
||||
#define analogInputToDigitalPin(p) (((p) <= 9) ? (p) + 14 : (((p) >= 12 && (p) <= 20) ? (p) + 19 : -1))
|
||||
#define digitalPinHasPWM(p) (((p) >= 2 && (p) <= 10) || (p) == 14 || ((p) >= 20 && (p) <= 23) || (p) == 29 || (p) == 30 || ((p) >= 35 && (p) <= 38))
|
||||
#define digitalPinToInterrupt(p) ((p) < NUM_DIGITAL_PINS ? (p) : -1)
|
||||
#endif
|
||||
|
||||
#define digitalPinToPCICR(p) ((volatile uint8_t *)0)
|
||||
#define digitalPinToPCICRbit(p) (0)
|
||||
#define digitalPinToPCIFR(p) ((volatile uint8_t *)0)
|
||||
#define digitalPinToPCIFRbit(p) (0)
|
||||
#define digitalPinToPCMSK(p) ((volatile uint8_t *)0)
|
||||
#define digitalPinToPCMSKbit(p) (0)
|
||||
|
||||
|
||||
#if defined(KINETISK)
|
||||
struct digital_pin_bitband_and_config_table_struct {
|
||||
volatile uint32_t *reg;
|
||||
volatile uint32_t *config;
|
||||
};
|
||||
extern const struct digital_pin_bitband_and_config_table_struct digital_pin_to_info_PGM[];
|
||||
// compatibility macros
|
||||
#define digitalPinToPort(pin) (pin)
|
||||
#define digitalPinToBitMask(pin) (1)
|
||||
#define portOutputRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 0))
|
||||
#define portSetRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 32))
|
||||
#define portClearRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 64))
|
||||
#define portToggleRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 96))
|
||||
#define portInputRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 128))
|
||||
#define portModeRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 160))
|
||||
#define portConfigRegister(pin) ((volatile uint32_t *)(digital_pin_to_info_PGM[(pin)].config))
|
||||
#define digitalPinToPortReg(pin) (portOutputRegister(pin))
|
||||
#define digitalPinToBit(pin) (1)
|
||||
|
||||
#elif defined(KINETISL)
|
||||
struct digital_pin_bitband_and_config_table_struct {
|
||||
volatile uint8_t *reg;
|
||||
volatile uint32_t *config;
|
||||
uint8_t mask;
|
||||
};
|
||||
extern const struct digital_pin_bitband_and_config_table_struct digital_pin_to_info_PGM[];
|
||||
// compatibility macros
|
||||
#define digitalPinToPort(pin) (pin)
|
||||
#define digitalPinToBitMask(pin) (digital_pin_to_info_PGM[(pin)].mask)
|
||||
#define portOutputRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 0))
|
||||
#define portSetRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 4))
|
||||
#define portClearRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 8))
|
||||
#define portToggleRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 12))
|
||||
#define portInputRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 16))
|
||||
#define portModeRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 20))
|
||||
#define portConfigRegister(pin) ((digital_pin_to_info_PGM[(pin)].config))
|
||||
#define digitalPinToPortReg(pin) (portOutputRegister(pin))
|
||||
//#define digitalPinToBit(pin) (1)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define NOT_ON_TIMER 0
|
||||
static inline uint8_t digitalPinToTimer(uint8_t) __attribute__((always_inline, unused));
|
||||
static inline uint8_t digitalPinToTimer(uint8_t pin)
|
||||
{
|
||||
if (pin >= 3 && pin <= 6) return pin - 2;
|
||||
if (pin >= 9 && pin <= 10) return pin - 4;
|
||||
if (pin >= 20 && pin <= 23) return pin - 13;
|
||||
return NOT_ON_TIMER;
|
||||
}
|
||||
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
//
|
||||
#if F_CPU >= 20000000 && !defined(USB_DISABLED)
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#else
|
||||
#define SERIAL_PORT_MONITOR Serial1
|
||||
#endif
|
||||
#define SERIAL_PORT_USBVIRTUAL Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#define SERIAL_PORT_HARDWARE1 Serial2
|
||||
#define SERIAL_PORT_HARDWARE2 Serial3
|
||||
#define SERIAL_PORT_HARDWARE_OPEN Serial1
|
||||
#define SERIAL_PORT_HARDWARE_OPEN1 Serial2
|
||||
#define SERIAL_PORT_HARDWARE_OPEN2 Serial3
|
||||
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
|
||||
#define SERIAL_PORT_HARDWARE3 Serial4
|
||||
#define SERIAL_PORT_HARDWARE4 Serial5
|
||||
#define SERIAL_PORT_HARDWARE5 Serial6
|
||||
#define SERIAL_PORT_HARDWARE_OPEN3 Serial4
|
||||
#define SERIAL_PORT_HARDWARE_OPEN4 Serial5
|
||||
#define SERIAL_PORT_HARDWARE_OPEN5 Serial6
|
||||
#endif
|
||||
|
||||
#define SerialUSB Serial
|
||||
|
||||
#endif
|
||||
/* Teensyduino Core Library
|
||||
* http://www.pjrc.com/teensy/
|
||||
* Copyright (c) 2017 PJRC.COM, LLC.
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* 1. The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* 2. If the Software is incorporated into a build system that allows
|
||||
* selection among a list of target devices, then similar target
|
||||
* devices manufactured by PJRC.COM must be included in the list of
|
||||
* target devices and selectable in the same manner.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef pins_macros_for_arduino_compatibility_h
|
||||
#define pins_macros_for_arduino_compatibility_h
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
// A0-A9 are always digital 14-23, for Arduino compatibility
|
||||
#define PIN_A0 (14)
|
||||
#define PIN_A1 (15)
|
||||
#define PIN_A2 (16)
|
||||
#define PIN_A3 (17)
|
||||
#define PIN_A4 (18)
|
||||
#define PIN_A5 (19)
|
||||
#define PIN_A6 (20)
|
||||
#define PIN_A7 (21)
|
||||
#define PIN_A8 (22)
|
||||
#define PIN_A9 (23)
|
||||
const static uint8_t A0 = PIN_A0;
|
||||
const static uint8_t A1 = PIN_A1;
|
||||
const static uint8_t A2 = PIN_A2;
|
||||
const static uint8_t A3 = PIN_A3;
|
||||
const static uint8_t A4 = PIN_A4;
|
||||
const static uint8_t A5 = PIN_A5;
|
||||
const static uint8_t A6 = PIN_A6;
|
||||
const static uint8_t A7 = PIN_A7;
|
||||
const static uint8_t A8 = PIN_A8;
|
||||
const static uint8_t A9 = PIN_A9;
|
||||
|
||||
#if defined(__MK20DX128__)
|
||||
#define PIN_A10 (34)
|
||||
#define PIN_A11 (35)
|
||||
#define PIN_A12 (36)
|
||||
#define PIN_A13 (37)
|
||||
const static uint8_t A10 = PIN_A10;
|
||||
const static uint8_t A11 = PIN_A11;
|
||||
const static uint8_t A12 = PIN_A12;
|
||||
const static uint8_t A13 = PIN_A13;
|
||||
|
||||
#elif defined(__MK20DX256__)
|
||||
#define PIN_A10 (34)
|
||||
#define PIN_A11 (35)
|
||||
#define PIN_A12 (36)
|
||||
#define PIN_A13 (37)
|
||||
#define PIN_A14 (40)
|
||||
#define PIN_A15 (26)
|
||||
#define PIN_A16 (27)
|
||||
#define PIN_A17 (28)
|
||||
#define PIN_A18 (29)
|
||||
#define PIN_A19 (30)
|
||||
#define PIN_A20 (31)
|
||||
const static uint8_t A10 = PIN_A10;
|
||||
const static uint8_t A11 = PIN_A11;
|
||||
const static uint8_t A12 = PIN_A12;
|
||||
const static uint8_t A13 = PIN_A13;
|
||||
const static uint8_t A14 = PIN_A14;
|
||||
const static uint8_t A15 = PIN_A15;
|
||||
const static uint8_t A16 = PIN_A16;
|
||||
const static uint8_t A17 = PIN_A17;
|
||||
const static uint8_t A18 = PIN_A18;
|
||||
const static uint8_t A19 = PIN_A19;
|
||||
const static uint8_t A20 = PIN_A20;
|
||||
|
||||
#elif defined(__MKL26Z64__)
|
||||
#define PIN_A10 (24)
|
||||
#define PIN_A11 (25)
|
||||
#define PIN_A12 (26)
|
||||
const static uint8_t A10 = PIN_A10;
|
||||
const static uint8_t A11 = PIN_A11;
|
||||
const static uint8_t A12 = PIN_A12;
|
||||
|
||||
#elif defined(__MK64FX512__) || defined(__MK66FX1M0__)
|
||||
#define PIN_A10 (64)
|
||||
#define PIN_A11 (65)
|
||||
#define PIN_A12 (31)
|
||||
#define PIN_A13 (32)
|
||||
#define PIN_A14 (33)
|
||||
#define PIN_A15 (34)
|
||||
#define PIN_A16 (35)
|
||||
#define PIN_A17 (36)
|
||||
#define PIN_A18 (37)
|
||||
#define PIN_A19 (38)
|
||||
#define PIN_A20 (39)
|
||||
#define PIN_A21 (66)
|
||||
#define PIN_A22 (67)
|
||||
#define PIN_A23 (49)
|
||||
#define PIN_A24 (50)
|
||||
#define PIN_A25 (68)
|
||||
#define PIN_A26 (69)
|
||||
const static uint8_t A10 = PIN_A10;
|
||||
const static uint8_t A11 = PIN_A11;
|
||||
const static uint8_t A12 = PIN_A12;
|
||||
const static uint8_t A13 = PIN_A13;
|
||||
const static uint8_t A14 = PIN_A14;
|
||||
const static uint8_t A15 = PIN_A15;
|
||||
const static uint8_t A16 = PIN_A16;
|
||||
const static uint8_t A17 = PIN_A17;
|
||||
const static uint8_t A18 = PIN_A18;
|
||||
const static uint8_t A19 = PIN_A19;
|
||||
const static uint8_t A20 = PIN_A20;
|
||||
const static uint8_t A21 = PIN_A21;
|
||||
const static uint8_t A22 = PIN_A22;
|
||||
const static uint8_t A23 = PIN_A23;
|
||||
const static uint8_t A24 = PIN_A24;
|
||||
const static uint8_t A25 = PIN_A25;
|
||||
const static uint8_t A26 = PIN_A26;
|
||||
#endif
|
||||
|
||||
#define LED_BUILTIN (13)
|
||||
|
||||
#define PIN_SPI_SS (10)
|
||||
#define PIN_SPI_MOSI (11)
|
||||
#define PIN_SPI_MISO (12)
|
||||
#define PIN_SPI_SCK (13)
|
||||
const static uint8_t SS = 10;
|
||||
const static uint8_t MOSI = 11;
|
||||
const static uint8_t MISO = 12;
|
||||
const static uint8_t SCK = 13;
|
||||
|
||||
#define PIN_WIRE_SDA (18)
|
||||
#define PIN_WIRE_SCL (19)
|
||||
const static uint8_t SDA = 18;
|
||||
const static uint8_t SCL = 19;
|
||||
|
||||
#define PIN_SERIAL_RX (0)
|
||||
#define PIN_SERIAL_TX (1)
|
||||
|
||||
|
||||
#define NUM_DIGITAL_PINS CORE_NUM_DIGITAL
|
||||
#define NUM_ANALOG_INPUTS CORE_NUM_ANALOG
|
||||
|
||||
|
||||
#define NOT_AN_INTERRUPT -1
|
||||
|
||||
|
||||
#if defined(__MK20DX128__)
|
||||
#define analogInputToDigitalPin(p) (((p) <= 9) ? (p) + 14 : (((p) <= 13) ? (p) + 24 : -1))
|
||||
#define digitalPinHasPWM(p) (((p) >= 3 && (p) <= 6) || (p) == 9 || (p) == 10 || ((p) >= 20 && (p) <= 23))
|
||||
#define digitalPinToInterrupt(p) ((p) < NUM_DIGITAL_PINS ? (p) : -1)
|
||||
#elif defined(__MK20DX256__)
|
||||
#define analogInputToDigitalPin(p) (((p) <= 9) ? (p) + 14 : (((p) <= 13) ? (p) + 24 : (((p) == 14) ? 40 : (((p) <= 20) ? (p) + 11 : -1))))
|
||||
#define digitalPinHasPWM(p) (((p) >= 3 && (p) <= 6) || (p) == 9 || (p) == 10 || ((p) >= 20 && (p) <= 23) || (p) == 25 || (p) == 32)
|
||||
#define digitalPinToInterrupt(p) ((p) < NUM_DIGITAL_PINS ? (p) : -1)
|
||||
#elif defined(__MKL26Z64__)
|
||||
#define analogInputToDigitalPin(p) (((p) <= 9) ? (p) + 14 : (((p) <= 12) ? (p) + 14 : -1))
|
||||
#define digitalPinHasPWM(p) ((p) == 3 || (p) == 4 || (p) == 6 || (p) == 9 || (p) == 10 || (p) == 16 || (p) == 17 || (p) == 20 || (p) == 22 || (p) == 23)
|
||||
#define digitalPinToInterrupt(p) ((((p) >= 2 && (p) <= 15) || ((p) >= 20 && (p) <= 23)) ? (p) : -1)
|
||||
#elif defined(__MK64FX512__) || defined(__MK66FX1M0__)
|
||||
// TODO analogInputToDigitalPin needs update...
|
||||
#define analogInputToDigitalPin(p) (((p) <= 9) ? (p) + 14 : (((p) >= 12 && (p) <= 20) ? (p) + 19 : -1))
|
||||
#define digitalPinHasPWM(p) (((p) >= 2 && (p) <= 10) || (p) == 14 || ((p) >= 20 && (p) <= 23) || (p) == 29 || (p) == 30 || ((p) >= 35 && (p) <= 38))
|
||||
#define digitalPinToInterrupt(p) ((p) < NUM_DIGITAL_PINS ? (p) : -1)
|
||||
#endif
|
||||
|
||||
#define digitalPinToPCICR(p) ((volatile uint8_t *)0)
|
||||
#define digitalPinToPCICRbit(p) (0)
|
||||
#define digitalPinToPCIFR(p) ((volatile uint8_t *)0)
|
||||
#define digitalPinToPCIFRbit(p) (0)
|
||||
#define digitalPinToPCMSK(p) ((volatile uint8_t *)0)
|
||||
#define digitalPinToPCMSKbit(p) (0)
|
||||
|
||||
|
||||
#if defined(KINETISK)
|
||||
struct digital_pin_bitband_and_config_table_struct {
|
||||
volatile uint32_t *reg;
|
||||
volatile uint32_t *config;
|
||||
};
|
||||
extern const struct digital_pin_bitband_and_config_table_struct digital_pin_to_info_PGM[];
|
||||
// compatibility macros
|
||||
#define digitalPinToPort(pin) (pin)
|
||||
#define digitalPinToBitMask(pin) (1)
|
||||
#define portOutputRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 0))
|
||||
#define portSetRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 32))
|
||||
#define portClearRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 64))
|
||||
#define portToggleRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 96))
|
||||
#define portInputRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 128))
|
||||
#define portModeRegister(pin) ((volatile uint8_t *)(digital_pin_to_info_PGM[(pin)].reg + 160))
|
||||
#define portConfigRegister(pin) ((volatile uint32_t *)(digital_pin_to_info_PGM[(pin)].config))
|
||||
#define digitalPinToPortReg(pin) (portOutputRegister(pin))
|
||||
#define digitalPinToBit(pin) (1)
|
||||
|
||||
#elif defined(KINETISL)
|
||||
struct digital_pin_bitband_and_config_table_struct {
|
||||
volatile uint8_t *reg;
|
||||
volatile uint32_t *config;
|
||||
uint8_t mask;
|
||||
};
|
||||
extern const struct digital_pin_bitband_and_config_table_struct digital_pin_to_info_PGM[];
|
||||
// compatibility macros
|
||||
#define digitalPinToPort(pin) (pin)
|
||||
#define digitalPinToBitMask(pin) (digital_pin_to_info_PGM[(pin)].mask)
|
||||
#define portOutputRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 0))
|
||||
#define portSetRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 4))
|
||||
#define portClearRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 8))
|
||||
#define portToggleRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 12))
|
||||
#define portInputRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 16))
|
||||
#define portModeRegister(pin) ((digital_pin_to_info_PGM[(pin)].reg + 20))
|
||||
#define portConfigRegister(pin) ((digital_pin_to_info_PGM[(pin)].config))
|
||||
#define digitalPinToPortReg(pin) (portOutputRegister(pin))
|
||||
//#define digitalPinToBit(pin) (1)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define NOT_ON_TIMER 0
|
||||
static inline uint8_t digitalPinToTimer(uint8_t) __attribute__((always_inline, unused));
|
||||
static inline uint8_t digitalPinToTimer(uint8_t pin)
|
||||
{
|
||||
if (pin >= 3 && pin <= 6) return pin - 2;
|
||||
if (pin >= 9 && pin <= 10) return pin - 4;
|
||||
if (pin >= 20 && pin <= 23) return pin - 13;
|
||||
return NOT_ON_TIMER;
|
||||
}
|
||||
|
||||
// These serial port names are intended to allow libraries and architecture-neutral
|
||||
// sketches to automatically default to the correct port name for a particular type
|
||||
// of use. For example, a GPS module would normally connect to SERIAL_PORT_HARDWARE_OPEN,
|
||||
// the first hardware serial port whose RX/TX pins are not dedicated to another use.
|
||||
//
|
||||
// SERIAL_PORT_MONITOR Port which normally prints to the Arduino Serial Monitor
|
||||
//
|
||||
// SERIAL_PORT_USBVIRTUAL Port which is USB virtual serial
|
||||
//
|
||||
// SERIAL_PORT_LINUXBRIDGE Port which connects to a Linux system via Bridge library
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE Hardware serial port, physical RX & TX pins.
|
||||
//
|
||||
// SERIAL_PORT_HARDWARE_OPEN Hardware serial ports which are open for use. Their RX & TX
|
||||
// pins are NOT connected to anything by default.
|
||||
//
|
||||
#if F_CPU >= 20000000 && !defined(USB_DISABLED)
|
||||
#define SERIAL_PORT_MONITOR Serial
|
||||
#else
|
||||
#define SERIAL_PORT_MONITOR Serial1
|
||||
#endif
|
||||
#define SERIAL_PORT_USBVIRTUAL Serial
|
||||
#define SERIAL_PORT_HARDWARE Serial1
|
||||
#define SERIAL_PORT_HARDWARE1 Serial2
|
||||
#define SERIAL_PORT_HARDWARE2 Serial3
|
||||
#define SERIAL_PORT_HARDWARE_OPEN Serial1
|
||||
#define SERIAL_PORT_HARDWARE_OPEN1 Serial2
|
||||
#define SERIAL_PORT_HARDWARE_OPEN2 Serial3
|
||||
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
|
||||
#define SERIAL_PORT_HARDWARE3 Serial4
|
||||
#define SERIAL_PORT_HARDWARE4 Serial5
|
||||
#define SERIAL_PORT_HARDWARE5 Serial6
|
||||
#define SERIAL_PORT_HARDWARE_OPEN3 Serial4
|
||||
#define SERIAL_PORT_HARDWARE_OPEN4 Serial5
|
||||
#define SERIAL_PORT_HARDWARE_OPEN5 Serial6
|
||||
#endif
|
||||
|
||||
#define SerialUSB Serial
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,35 +1,35 @@
|
|||
#ifndef __SIMUSBMIDI_H__
|
||||
#define __SIMUSBMIDI_H__
|
||||
|
||||
#include <string>
|
||||
|
||||
class SimUsbMidi
|
||||
{
|
||||
public:
|
||||
void sendNoteOff(uint8_t note, uint8_t velocity, uint8_t channel, uint8_t cable=0);
|
||||
void sendNoteOn(uint8_t note, uint8_t velocity, uint8_t channel, uint8_t cable=0);
|
||||
void sendPolyPressure(uint8_t note, uint8_t pressure, uint8_t channel, uint8_t cable=0);
|
||||
void sendAfterTouchPoly(uint8_t note, uint8_t pressure, uint8_t channel, uint8_t cable=0);
|
||||
void sendControlChange(uint8_t control, uint8_t value, uint8_t channel, uint8_t cable=0);
|
||||
void sendProgramChange(uint8_t program, uint8_t channel, uint8_t cable=0);
|
||||
void sendAfterTouch(uint8_t pressure, uint8_t channel, uint8_t cable=0);
|
||||
void sendPitchBend(int value, uint8_t channel, uint8_t cable=0);
|
||||
void sendSysEx(uint16_t length, const uint8_t *data, bool hasTerm=false, uint8_t cable=0);
|
||||
bool read(uint8_t channel=0);
|
||||
void setHandleSystemExclusive(void (*fptr) (const uint8_t *array, unsigned int size));
|
||||
void setHandleSystemExclusive(void (*fptr) (const uint8_t *data, uint16_t length, bool complete));
|
||||
|
||||
//Things not part of Teensy USBMidi, but used to simulate sending data to it
|
||||
void receiveMidiData(const uint8_t *data, const uint16_t length); //Send midi data "into simulator"
|
||||
void setMidiFile(std::string filename); //MIDI data to send to device
|
||||
void triggerMidi(); //"Arm" so data is sent to device next time it tries to read anything
|
||||
private:
|
||||
//Handlers registered to receive MIDI
|
||||
void (*usb_midi_handleSysExPartial)(const uint8_t *data, uint16_t length, uint8_t complete);
|
||||
void (*usb_midi_handleSysExComplete)(const uint8_t *data, unsigned int size);
|
||||
std::string midiFile;
|
||||
bool sendMidi;
|
||||
};
|
||||
|
||||
|
||||
#ifndef __SIMUSBMIDI_H__
|
||||
#define __SIMUSBMIDI_H__
|
||||
|
||||
#include <string>
|
||||
|
||||
class SimUsbMidi
|
||||
{
|
||||
public:
|
||||
void sendNoteOff(uint8_t note, uint8_t velocity, uint8_t channel, uint8_t cable=0);
|
||||
void sendNoteOn(uint8_t note, uint8_t velocity, uint8_t channel, uint8_t cable=0);
|
||||
void sendPolyPressure(uint8_t note, uint8_t pressure, uint8_t channel, uint8_t cable=0);
|
||||
void sendAfterTouchPoly(uint8_t note, uint8_t pressure, uint8_t channel, uint8_t cable=0);
|
||||
void sendControlChange(uint8_t control, uint8_t value, uint8_t channel, uint8_t cable=0);
|
||||
void sendProgramChange(uint8_t program, uint8_t channel, uint8_t cable=0);
|
||||
void sendAfterTouch(uint8_t pressure, uint8_t channel, uint8_t cable=0);
|
||||
void sendPitchBend(int value, uint8_t channel, uint8_t cable=0);
|
||||
void sendSysEx(uint16_t length, const uint8_t *data, bool hasTerm=false, uint8_t cable=0);
|
||||
bool read(uint8_t channel=0);
|
||||
void setHandleSystemExclusive(void (*fptr) (const uint8_t *array, unsigned int size));
|
||||
void setHandleSystemExclusive(void (*fptr) (const uint8_t *data, uint16_t length, bool complete));
|
||||
|
||||
//Things not part of Teensy USBMidi, but used to simulate sending data to it
|
||||
void receiveMidiData(const uint8_t *data, const uint16_t length); //Send midi data "into simulator"
|
||||
void setMidiFile(std::string filename); //MIDI data to send to device
|
||||
void triggerMidi(); //"Arm" so data is sent to device next time it tries to read anything
|
||||
private:
|
||||
//Handlers registered to receive MIDI
|
||||
void (*usb_midi_handleSysExPartial)(const uint8_t *data, uint16_t length, uint8_t complete);
|
||||
void (*usb_midi_handleSysExComplete)(const uint8_t *data, unsigned int size);
|
||||
std::string midiFile;
|
||||
bool sendMidi;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -1,197 +1,197 @@
|
|||
/* Teensyduino Core Library
|
||||
* http://www.pjrc.com/teensy/
|
||||
* Copyright (c) 2017 PJRC.COM, LLC.
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* 1. The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* 2. If the Software is incorporated into a build system that allows
|
||||
* selection among a list of target devices, then similar target
|
||||
* devices manufactured by PJRC.COM must be included in the list of
|
||||
* target devices and selectable in the same manner.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef Wiring_h
|
||||
#define Wiring_h
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
// #include "binary.h"
|
||||
#include "core_id.h"
|
||||
// #include "core_pins.h"
|
||||
|
||||
// type_traits interferes with min() and other defines
|
||||
// include it early, so we can define these later
|
||||
// for Arduino compatibility
|
||||
#ifdef __cplusplus
|
||||
#include <type_traits>
|
||||
// when the input number is an integer type, do all math as 32 bit signed long
|
||||
template <class T, class A, class B, class C, class D>
|
||||
long map(T _x, A _in_min, B _in_max, C _out_min, D _out_max, typename std::enable_if<std::is_integral<T>::value >::type* = 0)
|
||||
{
|
||||
long x = _x, in_min = _in_min, in_max = _in_max, out_min = _out_min, out_max = _out_max;
|
||||
// Arduino's traditional algorithm
|
||||
//return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||
// st42's suggestion: https://github.com/arduino/Arduino/issues/2466#issuecomment-69873889
|
||||
// more conversation:
|
||||
// https://forum.pjrc.com/threads/44503-map()-function-improvements
|
||||
if ((in_max - in_min) > (out_max - out_min)) {
|
||||
return (x - in_min) * (out_max - out_min+1) / (in_max - in_min+1) + out_min;
|
||||
} else {
|
||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||
}
|
||||
}
|
||||
// when the input is a float or double, do all math using the input's type
|
||||
template <class T, class A, class B, class C, class D>
|
||||
T map(T x, A in_min, B in_max, C out_min, D out_max, typename std::enable_if<std::is_floating_point<T>::value >::type* = 0)
|
||||
{
|
||||
return (x - (T)in_min) * ((T)out_max - (T)out_min) / ((T)in_max - (T)in_min) + (T)out_min;
|
||||
}
|
||||
//#include <algorithm> // this isn't really needed, is it? (slows down compiling)
|
||||
#include <utility>
|
||||
// https://forum.pjrc.com/threads/44596-Teensyduino-1-37-Beta-2-(Arduino-1-8-3-support)?p=145150&viewfull=1#post145150
|
||||
template<class A, class B>
|
||||
constexpr auto min(A&& a, B&& b) -> decltype(a < b ? std::forward<A>(a) : std::forward<B>(b)) {
|
||||
return a < b ? std::forward<A>(a) : std::forward<B>(b);
|
||||
}
|
||||
template<class A, class B>
|
||||
constexpr auto max(A&& a, B&& b) -> decltype(a < b ? std::forward<A>(a) : std::forward<B>(b)) {
|
||||
return a >= b ? std::forward<A>(a) : std::forward<B>(b);
|
||||
}
|
||||
#else // not C++
|
||||
#define min(a, b) ({ \
|
||||
typeof(a) _a = (a); \
|
||||
typeof(b) _b = (b); \
|
||||
(_a < _b) ? _a : _b; \
|
||||
})
|
||||
#define max(a, b) ({ \
|
||||
typeof(a) _a = (a); \
|
||||
typeof(b) _b = (b); \
|
||||
(_a > _b) ? _a : _b; \
|
||||
})
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PI
|
||||
#undef PI
|
||||
#endif
|
||||
#define PI 3.1415926535897932384626433832795
|
||||
#define HALF_PI 1.5707963267948966192313216916398
|
||||
#define TWO_PI 6.283185307179586476925286766559
|
||||
#define DEG_TO_RAD 0.017453292519943295769236907684886
|
||||
#define RAD_TO_DEG 57.295779513082320876798154814105
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
#endif
|
||||
#ifndef M_SQRT2
|
||||
#define M_SQRT2 1.4142135623730950488016887
|
||||
#endif
|
||||
|
||||
#define SERIAL 0
|
||||
#define DISPLAY 1
|
||||
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#endif
|
||||
|
||||
#if __cplusplus >= 201103L && defined(__STRICT_ANSI__)
|
||||
#define typeof(a) decltype(a)
|
||||
#endif
|
||||
|
||||
#define abs(x) ({ \
|
||||
typeof(x) _x = (x); \
|
||||
(_x > 0) ? _x : -_x; \
|
||||
})
|
||||
#define constrain(amt, low, high) ({ \
|
||||
typeof(amt) _amt = (amt); \
|
||||
typeof(low) _low = (low); \
|
||||
typeof(high) _high = (high); \
|
||||
(_amt < _low) ? _low : ((_amt > _high) ? _high : _amt); \
|
||||
})
|
||||
#define round(x) ({ \
|
||||
typeof(x) _x = (x); \
|
||||
(_x>=0) ? (long)(_x+0.5) : (long)(_x-0.5); \
|
||||
})
|
||||
#define radians(deg) ((deg)*DEG_TO_RAD)
|
||||
#define degrees(rad) ((rad)*RAD_TO_DEG)
|
||||
#define sq(x) ({ \
|
||||
typeof(x) _x = (x); \
|
||||
_x * _x; \
|
||||
})
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
extern double exp10(double x);
|
||||
extern float exp10f(float x);
|
||||
extern long double exp10l(long double x);
|
||||
extern double pow10(double x);
|
||||
extern float pow10f(float x);
|
||||
extern long double pow10l(long double x);
|
||||
|
||||
#define stricmp(a, b) strcasecmp(a, b)
|
||||
|
||||
#define sei() __enable_irq()
|
||||
#define cli() __disable_irq()
|
||||
#define interrupts() __enable_irq()
|
||||
#define noInterrupts() __disable_irq()
|
||||
|
||||
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
|
||||
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
|
||||
#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
|
||||
|
||||
#define lowByte(w) ((uint8_t)((w) & 0xFF))
|
||||
#define highByte(w) ((uint8_t)((w) >> 8))
|
||||
|
||||
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
|
||||
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
|
||||
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
|
||||
#define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet((value), (bit)) : bitClear((value), (bit)))
|
||||
|
||||
typedef unsigned int word;
|
||||
|
||||
#define bit(b) (1UL << (b))
|
||||
|
||||
typedef uint8_t byte;
|
||||
|
||||
uint32_t pulseIn(uint8_t pin, uint8_t state, uint32_t timeout);
|
||||
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val);
|
||||
|
||||
void setup(void);
|
||||
void loop(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
// fix C++ boolean issue
|
||||
// https://github.com/arduino/Arduino/pull/2151
|
||||
#ifdef __cplusplus
|
||||
typedef bool boolean;
|
||||
#else
|
||||
typedef uint8_t boolean;
|
||||
#define false 0
|
||||
#define true (!false)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
/* Teensyduino Core Library
|
||||
* http://www.pjrc.com/teensy/
|
||||
* Copyright (c) 2017 PJRC.COM, LLC.
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* 1. The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* 2. If the Software is incorporated into a build system that allows
|
||||
* selection among a list of target devices, then similar target
|
||||
* devices manufactured by PJRC.COM must be included in the list of
|
||||
* target devices and selectable in the same manner.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef Wiring_h
|
||||
#define Wiring_h
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
// #include "binary.h"
|
||||
#include "core_id.h"
|
||||
// #include "core_pins.h"
|
||||
|
||||
// type_traits interferes with min() and other defines
|
||||
// include it early, so we can define these later
|
||||
// for Arduino compatibility
|
||||
#ifdef __cplusplus
|
||||
#include <type_traits>
|
||||
// when the input number is an integer type, do all math as 32 bit signed long
|
||||
template <class T, class A, class B, class C, class D>
|
||||
long map(T _x, A _in_min, B _in_max, C _out_min, D _out_max, typename std::enable_if<std::is_integral<T>::value >::type* = 0)
|
||||
{
|
||||
long x = _x, in_min = _in_min, in_max = _in_max, out_min = _out_min, out_max = _out_max;
|
||||
// Arduino's traditional algorithm
|
||||
//return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||
// st42's suggestion: https://github.com/arduino/Arduino/issues/2466#issuecomment-69873889
|
||||
// more conversation:
|
||||
// https://forum.pjrc.com/threads/44503-map()-function-improvements
|
||||
if ((in_max - in_min) > (out_max - out_min)) {
|
||||
return (x - in_min) * (out_max - out_min+1) / (in_max - in_min+1) + out_min;
|
||||
} else {
|
||||
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
|
||||
}
|
||||
}
|
||||
// when the input is a float or double, do all math using the input's type
|
||||
template <class T, class A, class B, class C, class D>
|
||||
T map(T x, A in_min, B in_max, C out_min, D out_max, typename std::enable_if<std::is_floating_point<T>::value >::type* = 0)
|
||||
{
|
||||
return (x - (T)in_min) * ((T)out_max - (T)out_min) / ((T)in_max - (T)in_min) + (T)out_min;
|
||||
}
|
||||
//#include <algorithm> // this isn't really needed, is it? (slows down compiling)
|
||||
#include <utility>
|
||||
// https://forum.pjrc.com/threads/44596-Teensyduino-1-37-Beta-2-(Arduino-1-8-3-support)?p=145150&viewfull=1#post145150
|
||||
template<class A, class B>
|
||||
constexpr auto min(A&& a, B&& b) -> decltype(a < b ? std::forward<A>(a) : std::forward<B>(b)) {
|
||||
return a < b ? std::forward<A>(a) : std::forward<B>(b);
|
||||
}
|
||||
template<class A, class B>
|
||||
constexpr auto max(A&& a, B&& b) -> decltype(a < b ? std::forward<A>(a) : std::forward<B>(b)) {
|
||||
return a >= b ? std::forward<A>(a) : std::forward<B>(b);
|
||||
}
|
||||
#else // not C++
|
||||
#define min(a, b) ({ \
|
||||
typeof(a) _a = (a); \
|
||||
typeof(b) _b = (b); \
|
||||
(_a < _b) ? _a : _b; \
|
||||
})
|
||||
#define max(a, b) ({ \
|
||||
typeof(a) _a = (a); \
|
||||
typeof(b) _b = (b); \
|
||||
(_a > _b) ? _a : _b; \
|
||||
})
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef PI
|
||||
#undef PI
|
||||
#endif
|
||||
#define PI 3.1415926535897932384626433832795
|
||||
#define HALF_PI 1.5707963267948966192313216916398
|
||||
#define TWO_PI 6.283185307179586476925286766559
|
||||
#define DEG_TO_RAD 0.017453292519943295769236907684886
|
||||
#define RAD_TO_DEG 57.295779513082320876798154814105
|
||||
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.1415926535897932384626433832795
|
||||
#endif
|
||||
#ifndef M_SQRT2
|
||||
#define M_SQRT2 1.4142135623730950488016887
|
||||
#endif
|
||||
|
||||
#define SERIAL 0
|
||||
#define DISPLAY 1
|
||||
|
||||
// undefine stdlib's abs if encountered
|
||||
#ifdef abs
|
||||
#undef abs
|
||||
#endif
|
||||
|
||||
#if __cplusplus >= 201103L && defined(__STRICT_ANSI__)
|
||||
#define typeof(a) decltype(a)
|
||||
#endif
|
||||
|
||||
#define abs(x) ({ \
|
||||
typeof(x) _x = (x); \
|
||||
(_x > 0) ? _x : -_x; \
|
||||
})
|
||||
#define constrain(amt, low, high) ({ \
|
||||
typeof(amt) _amt = (amt); \
|
||||
typeof(low) _low = (low); \
|
||||
typeof(high) _high = (high); \
|
||||
(_amt < _low) ? _low : ((_amt > _high) ? _high : _amt); \
|
||||
})
|
||||
#define round(x) ({ \
|
||||
typeof(x) _x = (x); \
|
||||
(_x>=0) ? (long)(_x+0.5) : (long)(_x-0.5); \
|
||||
})
|
||||
#define radians(deg) ((deg)*DEG_TO_RAD)
|
||||
#define degrees(rad) ((rad)*RAD_TO_DEG)
|
||||
#define sq(x) ({ \
|
||||
typeof(x) _x = (x); \
|
||||
_x * _x; \
|
||||
})
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"{
|
||||
#endif
|
||||
|
||||
extern double exp10(double x);
|
||||
extern float exp10f(float x);
|
||||
extern long double exp10l(long double x);
|
||||
extern double pow10(double x);
|
||||
extern float pow10f(float x);
|
||||
extern long double pow10l(long double x);
|
||||
|
||||
#define stricmp(a, b) strcasecmp(a, b)
|
||||
|
||||
#define sei() __enable_irq()
|
||||
#define cli() __disable_irq()
|
||||
#define interrupts() __enable_irq()
|
||||
#define noInterrupts() __disable_irq()
|
||||
|
||||
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
|
||||
#define clockCyclesToMicroseconds(a) ( (a) / clockCyclesPerMicrosecond() )
|
||||
#define microsecondsToClockCycles(a) ( (a) * clockCyclesPerMicrosecond() )
|
||||
|
||||
#define lowByte(w) ((uint8_t)((w) & 0xFF))
|
||||
#define highByte(w) ((uint8_t)((w) >> 8))
|
||||
|
||||
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)
|
||||
#define bitSet(value, bit) ((value) |= (1UL << (bit)))
|
||||
#define bitClear(value, bit) ((value) &= ~(1UL << (bit)))
|
||||
#define bitWrite(value, bit, bitvalue) ((bitvalue) ? bitSet((value), (bit)) : bitClear((value), (bit)))
|
||||
|
||||
typedef unsigned int word;
|
||||
|
||||
#define bit(b) (1UL << (b))
|
||||
|
||||
typedef uint8_t byte;
|
||||
|
||||
uint32_t pulseIn(uint8_t pin, uint8_t state, uint32_t timeout);
|
||||
void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, byte val);
|
||||
|
||||
void setup(void);
|
||||
void loop(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
// fix C++ boolean issue
|
||||
// https://github.com/arduino/Arduino/pull/2151
|
||||
#ifdef __cplusplus
|
||||
typedef bool boolean;
|
||||
#else
|
||||
typedef uint8_t boolean;
|
||||
#define false 0
|
||||
#define true (!false)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
# Simulator for NuEVI
|
||||
|
||||
This is a simple SDL2 based simulator that runs the NuEVI firmware compiled for MacOS. This is for testing the menu and is not supposed to produce any midi events.
|
||||
|
||||
## Requirements
|
||||
|
||||
* The Filters library must be installed in ~/Documents/Arduino/libraries/Filters.
|
||||
* [SDL2.framework](https://www.libsdl.org/download-2.0.php) must be installed on your machine in /Library/Frameworks/ (or ~/Library/Frameworks/).
|
||||
* You probably need to have XCode and XCodes command line tools installed as well, but using brew to install make and clang might be enough.
|
||||
|
||||
[Dear Imgui](https://github.com/ocornut/imgui) is pulled in as an git submodule. Run `git submodule init` and `git submodule update` to get the code. The code is tested with tag v1.70 of ImGui, so if you run into problems make sure that is the checked out version.
|
||||
|
||||
## Know limitations
|
||||
|
||||
Currently only some input is simulated, and the default values are not based on real hardware. There is also a limitation on some keyboards on how many buttons can be pressed at the same time. This means that all menu functions cannot be tested.
|
||||
|
||||
## Future plans
|
||||
|
||||
* Add simulation for all inputs
|
||||
* Show MIDI status in UI
|
||||
* Add in-app log window
|
||||
* Fake real breath input by keypress
|
||||
# Simulator for NuEVI
|
||||
|
||||
This is a simple SDL2 based simulator that runs the NuEVI firmware compiled for MacOS. This is for testing the menu and is not supposed to produce any midi events.
|
||||
|
||||
## Requirements
|
||||
|
||||
* The Filters library must be installed in ~/Documents/Arduino/libraries/Filters.
|
||||
* [SDL2.framework](https://www.libsdl.org/download-2.0.php) must be installed on your machine in /Library/Frameworks/ (or ~/Library/Frameworks/).
|
||||
* You probably need to have XCode and XCodes command line tools installed as well, but using brew to install make and clang might be enough.
|
||||
|
||||
[Dear Imgui](https://github.com/ocornut/imgui) is pulled in as an git submodule. Run `git submodule init` and `git submodule update` to get the code. The code is tested with tag v1.70 of ImGui, so if you run into problems make sure that is the checked out version.
|
||||
|
||||
## Know limitations
|
||||
|
||||
Currently only some input is simulated, and the default values are not based on real hardware. There is also a limitation on some keyboards on how many buttons can be pressed at the same time. This means that all menu functions cannot be tested.
|
||||
|
||||
## Future plans
|
||||
|
||||
* Add simulation for all inputs
|
||||
* Show MIDI status in UI
|
||||
* Add in-app log window
|
||||
* Fake real breath input by keypress
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,170 +1,170 @@
|
|||
/*!
|
||||
* @file Adafruit_MPR121.cpp
|
||||
*
|
||||
* @mainpage Adafruit MPR121 arduino driver
|
||||
*
|
||||
* @section intro_sec Introduction
|
||||
*
|
||||
This is a library for the MPR121 I2C 12-chan Capacitive Sensor
|
||||
|
||||
Designed specifically to work with the MPR121 sensor from Adafruit
|
||||
----> https://www.adafruit.com/products/1982
|
||||
|
||||
These sensors use I2C to communicate, 2+ pins are required to
|
||||
interface
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
*
|
||||
* @section author Author
|
||||
*
|
||||
* Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
*
|
||||
* @section license License
|
||||
*
|
||||
* BSD license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Adafruit_MPR121.h"
|
||||
|
||||
/**
|
||||
*****************************************************************************************
|
||||
* @brief Default constructor
|
||||
****************************************************************************************/
|
||||
Adafruit_MPR121::Adafruit_MPR121() {
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************************
|
||||
* @brief Begin an MPR121 object on a given I2C bus. This function resets the
|
||||
* device and writes the default settings.
|
||||
*
|
||||
* @param i2caddr the i2c address the device can be found on. Defaults to 0x5A.
|
||||
* @returns true on success, false otherwise
|
||||
****************************************************************************************/
|
||||
boolean Adafruit_MPR121::begin(uint8_t i2caddr) {
|
||||
_i2caddr = i2caddr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************************
|
||||
* @brief DEPRECATED. Use Adafruit_MPR121::setThresholds(uint8_t touch, uint8_t release) instead.
|
||||
*
|
||||
* @param touch see Adafruit_MPR121::setThresholds(uint8_t touch, uint8_t release)
|
||||
* @param release see Adafruit_MPR121::setThresholds(uint8_t touch, uint8_t release)
|
||||
****************************************************************************************/
|
||||
void Adafruit_MPR121::setThreshholds(uint8_t __attribute__((unused)) touch, uint8_t __attribute__((unused)) release) {
|
||||
// setThresholds(touch, release);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************************
|
||||
* @brief Set the touch and release thresholds for all 13 channels on the device to the
|
||||
* passed values. The threshold is defined as a deviation value from the baseline value,
|
||||
* so it remains constant even baseline value changes. Typically the touch
|
||||
* threshold is a little bigger than the release threshold to touch debounce and hysteresis.
|
||||
*
|
||||
* For typical touch application, the value can be in range 0x05~0x30 for example. The setting
|
||||
* of the threshold is depended on the actual application. For the operation details and how to set the threshold refer to
|
||||
* application note AN3892 and MPR121 design guidelines.
|
||||
*
|
||||
* @param touch the touch threshold value from 0 to 255.
|
||||
* @param release the release threshold from 0 to 255.
|
||||
****************************************************************************************/
|
||||
void Adafruit_MPR121::setThresholds(uint8_t __attribute__((unused)) touch, __attribute__((unused)) uint8_t release) {
|
||||
// for (uint8_t i=0; i<12; i++) {
|
||||
// writeRegister(MPR121_TOUCHTH_0 + 2*i, touch);
|
||||
// writeRegister(MPR121_RELEASETH_0 + 2*i, release);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************************
|
||||
* @brief Read the filtered data from channel t. The ADC raw data outputs run through 3
|
||||
* levels of digital filtering to filter out the high frequency and low frequency noise
|
||||
* encountered. For detailed information on this filtering see page 6 of the device datasheet.
|
||||
*
|
||||
* @param t the channel to read
|
||||
* @returns the filtered reading as a 10 bit unsigned value
|
||||
****************************************************************************************/
|
||||
uint16_t Adafruit_MPR121::filteredData(uint8_t t) {
|
||||
if (t > 12) return 0;
|
||||
return readRegister16(MPR121_FILTDATA_0L + t*2);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************************
|
||||
* @brief Read the baseline value for the channel. The 3rd level filtered result is internally 10bit
|
||||
* but only high 8 bits are readable from registers 0x1E~0x2A as the baseline value output for each channel.
|
||||
*
|
||||
* @param t the channel to read.
|
||||
* @returns the baseline data that was read
|
||||
****************************************************************************************/
|
||||
uint16_t Adafruit_MPR121::baselineData(uint8_t t) {
|
||||
if (t > 12) return 0;
|
||||
uint16_t bl = readRegister8(MPR121_BASELINE_0 + t);
|
||||
return (bl << 2);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************************
|
||||
* @brief Read the touch status of all 13 channels as bit values in a 12 bit integer.
|
||||
*
|
||||
* @returns a 12 bit integer with each bit corresponding to the touch status of a sensor.
|
||||
* For example, if bit 0 is set then channel 0 of the device is currently deemed to be touched.
|
||||
****************************************************************************************/
|
||||
uint16_t Adafruit_MPR121::touched(void) {
|
||||
uint16_t t = readRegister16(MPR121_TOUCHSTATUS_L);
|
||||
return t & 0x0FFF;
|
||||
}
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
/**
|
||||
*****************************************************************************************
|
||||
* @brief Read the contents of an 8 bit device register.
|
||||
*
|
||||
* @param reg the register address to read from
|
||||
* @returns the 8 bit value that was read.
|
||||
****************************************************************************************/
|
||||
uint8_t Adafruit_MPR121::readRegister8(uint8_t reg) {
|
||||
return this->_registers[reg];
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************************
|
||||
* @brief Read the contents of a 16 bit device register.
|
||||
*
|
||||
* @param reg the register address to read from
|
||||
* @returns the 16 bit value that was read.
|
||||
****************************************************************************************/
|
||||
uint16_t Adafruit_MPR121::readRegister16(uint8_t reg) {
|
||||
return _registers[reg] | (_registers[reg+1] << 8);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Writes 8-bits to the specified destination register
|
||||
|
||||
@param reg the register address to write to
|
||||
@param value the value to write
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_MPR121::writeRegister(uint8_t reg, uint8_t value) {
|
||||
|
||||
_registers[reg] = value;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Simulator specifics code..
|
||||
*/
|
||||
|
||||
|
||||
void Adafruit_MPR121::mockFilteredData(int reg, uint16_t value) {
|
||||
_registers[MPR121_FILTDATA_0L + reg*2] = value & 0xffu;
|
||||
_registers[MPR121_FILTDATA_0L + reg*2+1] = (value>>8) & 0xffu;
|
||||
}
|
||||
/*!
|
||||
* @file Adafruit_MPR121.cpp
|
||||
*
|
||||
* @mainpage Adafruit MPR121 arduino driver
|
||||
*
|
||||
* @section intro_sec Introduction
|
||||
*
|
||||
This is a library for the MPR121 I2C 12-chan Capacitive Sensor
|
||||
|
||||
Designed specifically to work with the MPR121 sensor from Adafruit
|
||||
----> https://www.adafruit.com/products/1982
|
||||
|
||||
These sensors use I2C to communicate, 2+ pins are required to
|
||||
interface
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
*
|
||||
* @section author Author
|
||||
*
|
||||
* Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||
*
|
||||
* @section license License
|
||||
*
|
||||
* BSD license, all text here must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "Adafruit_MPR121.h"
|
||||
|
||||
/**
|
||||
*****************************************************************************************
|
||||
* @brief Default constructor
|
||||
****************************************************************************************/
|
||||
Adafruit_MPR121::Adafruit_MPR121() {
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************************
|
||||
* @brief Begin an MPR121 object on a given I2C bus. This function resets the
|
||||
* device and writes the default settings.
|
||||
*
|
||||
* @param i2caddr the i2c address the device can be found on. Defaults to 0x5A.
|
||||
* @returns true on success, false otherwise
|
||||
****************************************************************************************/
|
||||
boolean Adafruit_MPR121::begin(uint8_t i2caddr) {
|
||||
_i2caddr = i2caddr;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************************
|
||||
* @brief DEPRECATED. Use Adafruit_MPR121::setThresholds(uint8_t touch, uint8_t release) instead.
|
||||
*
|
||||
* @param touch see Adafruit_MPR121::setThresholds(uint8_t touch, uint8_t release)
|
||||
* @param release see Adafruit_MPR121::setThresholds(uint8_t touch, uint8_t release)
|
||||
****************************************************************************************/
|
||||
void Adafruit_MPR121::setThreshholds(uint8_t __attribute__((unused)) touch, uint8_t __attribute__((unused)) release) {
|
||||
// setThresholds(touch, release);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************************
|
||||
* @brief Set the touch and release thresholds for all 13 channels on the device to the
|
||||
* passed values. The threshold is defined as a deviation value from the baseline value,
|
||||
* so it remains constant even baseline value changes. Typically the touch
|
||||
* threshold is a little bigger than the release threshold to touch debounce and hysteresis.
|
||||
*
|
||||
* For typical touch application, the value can be in range 0x05~0x30 for example. The setting
|
||||
* of the threshold is depended on the actual application. For the operation details and how to set the threshold refer to
|
||||
* application note AN3892 and MPR121 design guidelines.
|
||||
*
|
||||
* @param touch the touch threshold value from 0 to 255.
|
||||
* @param release the release threshold from 0 to 255.
|
||||
****************************************************************************************/
|
||||
void Adafruit_MPR121::setThresholds(uint8_t __attribute__((unused)) touch, __attribute__((unused)) uint8_t release) {
|
||||
// for (uint8_t i=0; i<12; i++) {
|
||||
// writeRegister(MPR121_TOUCHTH_0 + 2*i, touch);
|
||||
// writeRegister(MPR121_RELEASETH_0 + 2*i, release);
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************************
|
||||
* @brief Read the filtered data from channel t. The ADC raw data outputs run through 3
|
||||
* levels of digital filtering to filter out the high frequency and low frequency noise
|
||||
* encountered. For detailed information on this filtering see page 6 of the device datasheet.
|
||||
*
|
||||
* @param t the channel to read
|
||||
* @returns the filtered reading as a 10 bit unsigned value
|
||||
****************************************************************************************/
|
||||
uint16_t Adafruit_MPR121::filteredData(uint8_t t) {
|
||||
if (t > 12) return 0;
|
||||
return readRegister16(MPR121_FILTDATA_0L + t*2);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************************
|
||||
* @brief Read the baseline value for the channel. The 3rd level filtered result is internally 10bit
|
||||
* but only high 8 bits are readable from registers 0x1E~0x2A as the baseline value output for each channel.
|
||||
*
|
||||
* @param t the channel to read.
|
||||
* @returns the baseline data that was read
|
||||
****************************************************************************************/
|
||||
uint16_t Adafruit_MPR121::baselineData(uint8_t t) {
|
||||
if (t > 12) return 0;
|
||||
uint16_t bl = readRegister8(MPR121_BASELINE_0 + t);
|
||||
return (bl << 2);
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************************
|
||||
* @brief Read the touch status of all 13 channels as bit values in a 12 bit integer.
|
||||
*
|
||||
* @returns a 12 bit integer with each bit corresponding to the touch status of a sensor.
|
||||
* For example, if bit 0 is set then channel 0 of the device is currently deemed to be touched.
|
||||
****************************************************************************************/
|
||||
uint16_t Adafruit_MPR121::touched(void) {
|
||||
uint16_t t = readRegister16(MPR121_TOUCHSTATUS_L);
|
||||
return t & 0x0FFF;
|
||||
}
|
||||
|
||||
/*********************************************************************/
|
||||
|
||||
/**
|
||||
*****************************************************************************************
|
||||
* @brief Read the contents of an 8 bit device register.
|
||||
*
|
||||
* @param reg the register address to read from
|
||||
* @returns the 8 bit value that was read.
|
||||
****************************************************************************************/
|
||||
uint8_t Adafruit_MPR121::readRegister8(uint8_t reg) {
|
||||
return this->_registers[reg];
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************************
|
||||
* @brief Read the contents of a 16 bit device register.
|
||||
*
|
||||
* @param reg the register address to read from
|
||||
* @returns the 16 bit value that was read.
|
||||
****************************************************************************************/
|
||||
uint16_t Adafruit_MPR121::readRegister16(uint8_t reg) {
|
||||
return _registers[reg] | (_registers[reg+1] << 8);
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@brief Writes 8-bits to the specified destination register
|
||||
|
||||
@param reg the register address to write to
|
||||
@param value the value to write
|
||||
*/
|
||||
/**************************************************************************/
|
||||
void Adafruit_MPR121::writeRegister(uint8_t reg, uint8_t value) {
|
||||
|
||||
_registers[reg] = value;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Simulator specifics code..
|
||||
*/
|
||||
|
||||
|
||||
void Adafruit_MPR121::mockFilteredData(int reg, uint16_t value) {
|
||||
_registers[MPR121_FILTDATA_0L + reg*2] = value & 0xffu;
|
||||
_registers[MPR121_FILTDATA_0L + reg*2+1] = (value>>8) & 0xffu;
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,337 +1,337 @@
|
|||
/* Teensyduino Core Library
|
||||
* http://www.pjrc.com/teensy/
|
||||
* Copyright (c) 2017 PJRC.COM, LLC.
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* 1. The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* 2. If the Software is incorporated into a build system that allows
|
||||
* selection among a list of target devices, then similar target
|
||||
* devices manufactured by PJRC.COM must be included in the list of
|
||||
* target devices and selectable in the same manner.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// Long ago this file contained code from Arduino.cc, which was
|
||||
// Copyright (c) 2008 David A. Mellis. No substantial portion of
|
||||
// Arduino's original code remains. In fact, several improvements
|
||||
// developed for Teensyduino have made their way back into
|
||||
// Arduino's code base. :-)
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "Print.h"
|
||||
|
||||
|
||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t count = 0;
|
||||
while (size--) count += write(*buffer++);
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
// size_t Print::print(const String &s)
|
||||
// {
|
||||
// uint8_t buffer[33];
|
||||
// size_t count = 0;
|
||||
// unsigned int index = 0;
|
||||
// unsigned int len = s.length();
|
||||
// while (len > 0) {
|
||||
// s.getBytes(buffer, sizeof(buffer), index);
|
||||
// unsigned int nbytes = len;
|
||||
// if (nbytes > sizeof(buffer)-1) nbytes = sizeof(buffer)-1;
|
||||
// index += nbytes;
|
||||
// len -= nbytes;
|
||||
// count += write(buffer, nbytes);
|
||||
// }
|
||||
// return count;
|
||||
// }
|
||||
|
||||
|
||||
size_t Print::print(long n)
|
||||
{
|
||||
uint8_t sign=0;
|
||||
|
||||
if (n < 0) {
|
||||
sign = '-';
|
||||
n = -n;
|
||||
}
|
||||
return printNumber(n, 10, sign);
|
||||
}
|
||||
|
||||
|
||||
size_t Print::println(void)
|
||||
{
|
||||
uint8_t buf[2]={'\r', '\n'};
|
||||
return write(buf, 2);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
__attribute__((weak))
|
||||
int _write(long file, char *ptr, int len)
|
||||
{
|
||||
((class Print *)file)->write((uint8_t *)ptr, len);
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
int Print::printf(const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
#ifdef __STRICT_ANSI__
|
||||
return 0; // TODO: make this work with -std=c++0x
|
||||
#else
|
||||
return vdprintf((int)this, format, ap);
|
||||
#endif
|
||||
}
|
||||
|
||||
int Print::printf(const __FlashStringHelper *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
#ifdef __STRICT_ANSI__
|
||||
return 0;
|
||||
#else
|
||||
return vdprintf((int)this, (const char *)format, ap);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __MKL26Z64__
|
||||
|
||||
// optimized code inspired by Stimmer's optimization
|
||||
// obviously a dit different, adapted to 32 bit Cortex-M0+
|
||||
// http://forum.arduino.cc/index.php?topic=167414.msg1293679#msg1293679
|
||||
// http://forum.arduino.cc/index.php?topic=167414.msg1309482#msg1309482
|
||||
// equivelant code:
|
||||
// mod = div % 10;
|
||||
// div = div / 10;
|
||||
// tmp1 = {random};
|
||||
// tmp2 = 10;
|
||||
#if 1
|
||||
// https://forum.pjrc.com/threads/28932-LC-is-10-9-times-slower-than-T3-1?p=76072&viewfull=1#post76072
|
||||
void inline divmod10_v2(uint32_t n,uint32_t *div,uint32_t *mod) {
|
||||
uint32_t p,q;
|
||||
/* Using 32.16 fixed point representation p.q */
|
||||
/* p.q = (n+1)/512 */
|
||||
q = (n&0xFFFF) + 1;
|
||||
p = (n>>16);
|
||||
/* p.q = 51*(n+1)/512 */
|
||||
q = 13107*q;
|
||||
p = 13107*p;
|
||||
/* p.q = (1+1/2^8+1/2^16+1/2^24)*51*(n+1)/512 */
|
||||
q = q + (q>>16) + (p&0xFFFF);
|
||||
p = p + (p>>16) + (q>>16);
|
||||
/* divide by 2 */
|
||||
p = p>>1;
|
||||
*div = p;
|
||||
*mod = n-10*p;
|
||||
}
|
||||
#define divmod10_asm(div, mod, tmp1, tmp2, const3333) \
|
||||
divmod10_v2(div, &div, &mod);
|
||||
/*
|
||||
#define divmod10_asm(div, mod, tmp1, tmp2, const3333) \
|
||||
asm ( \
|
||||
" lsr %2, %0, #16" "\n\t" \
|
||||
" mul %2, %4" "\n\t" \
|
||||
" uxth %1, %0" "\n\t" \
|
||||
" mul %1, %4" "\n\t" \
|
||||
" add %1, #1" "\n\t" \
|
||||
" lsr %0, %2, #16" "\n\t" \
|
||||
" lsl %2, %2, #16" "\n\t" \
|
||||
" add %1, %2" "\n\t" \
|
||||
" mov %3, #0" "\n\t" \
|
||||
" adc %0, %3" "\n\t" \
|
||||
" lsl %0, %0, #15" "\n\t" \
|
||||
" lsr %2, %1, #17" "\n\t" \
|
||||
" orr %0, %2" "\n\t" \
|
||||
" lsl %1, %1, #15" "\n\t" \
|
||||
" lsr %2, %1, #16" "\n\t" \
|
||||
" lsl %3, %0, #16" "\n\t" \
|
||||
" orr %2, %3" "\n\t" \
|
||||
" lsr %3, %0, #16" "\n\t" \
|
||||
" add %1, %0" "\n\t" \
|
||||
" adc %0, %1" "\n\t" \
|
||||
" sub %0, %1" "\n\t" \
|
||||
" add %1, %2" "\n\t" \
|
||||
" adc %0, %3" "\n\t" \
|
||||
" lsr %1, %1, #4" "\n\t" \
|
||||
" mov %3, #10" "\n\t" \
|
||||
" mul %1, %3" "\n\t" \
|
||||
" lsr %1, %1, #28" "\n\t" \
|
||||
: "+l" (div), \
|
||||
"=&l" (mod), \
|
||||
"=&l" (tmp1), \
|
||||
"=&l" (tmp2) \
|
||||
: "l" (const3333) \
|
||||
: \
|
||||
)
|
||||
*/
|
||||
#else
|
||||
#define divmod10_asm(_div, _mod, _tmp1, _tmp2, _const3333) \
|
||||
({ _tmp1 = _div; _div = _div / 10; _mod = _tmp1 - _div * 10; })
|
||||
// ({_mod = _div % 10, _div = _div / 10; })
|
||||
#endif
|
||||
|
||||
|
||||
size_t Print::printNumberDec(unsigned long n, uint8_t sign)
|
||||
{
|
||||
uint8_t buf[11], *p;
|
||||
uint32_t digit;
|
||||
//uint32_t t1, t2, c3333=0x3333;
|
||||
|
||||
p = buf + (sizeof(buf));
|
||||
do {
|
||||
uint32_t div;
|
||||
divmod10_v2(n, &div, &digit);
|
||||
n = div;
|
||||
//divmod10_asm(n, digit, t1, t2, c3333);
|
||||
*--p = digit + '0';
|
||||
} while (n);
|
||||
if (sign) *--p = '-';
|
||||
return write(p, sizeof(buf) - (p - buf));
|
||||
}
|
||||
|
||||
size_t Print::printNumberHex(unsigned long n)
|
||||
{
|
||||
uint8_t digit, buf[8], *p;
|
||||
|
||||
p = buf + (sizeof(buf));
|
||||
do {
|
||||
digit = n & 15;
|
||||
*--p = (digit < 10) ? '0' + digit : 'A' + digit - 10;
|
||||
n >>= 4;
|
||||
} while (n);
|
||||
return write(p, sizeof(buf) - (p - buf));
|
||||
}
|
||||
|
||||
size_t Print::printNumberBin(unsigned long n)
|
||||
{
|
||||
uint8_t buf[32], *p;
|
||||
|
||||
p = buf + (sizeof(buf));
|
||||
do {
|
||||
*--p = '0' + ((uint8_t)n & 1);
|
||||
n >>= 1;
|
||||
} while (n);
|
||||
return write(p, sizeof(buf) - (p - buf));
|
||||
}
|
||||
|
||||
size_t Print::printNumberAny(unsigned long n, uint8_t base)
|
||||
{
|
||||
uint8_t digit, buf[21], *p;
|
||||
uint32_t tmp;
|
||||
|
||||
p = buf + sizeof(buf);
|
||||
do {
|
||||
tmp = n;
|
||||
n = n / base;
|
||||
digit = tmp - n * base;
|
||||
*--p = (digit < 10) ? '0' + digit : 'A' + digit - 10;
|
||||
} while (n);
|
||||
return write(p, sizeof(buf) - (p - buf));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
size_t Print::printNumber(unsigned long n, uint8_t base, uint8_t sign)
|
||||
{
|
||||
uint8_t buf[34];
|
||||
uint8_t digit, i;
|
||||
|
||||
// TODO: make these checks as inline, since base is
|
||||
// almost always a constant. base = 0 (BYTE) should
|
||||
// inline as a call directly to write()
|
||||
if (base == 0) {
|
||||
return write((uint8_t)n);
|
||||
} else if (base == 1) {
|
||||
base = 10;
|
||||
}
|
||||
|
||||
|
||||
if (n == 0) {
|
||||
buf[sizeof(buf) - 1] = '0';
|
||||
i = sizeof(buf) - 1;
|
||||
} else {
|
||||
i = sizeof(buf) - 1;
|
||||
while (1) {
|
||||
digit = n % base;
|
||||
buf[i] = ((digit < 10) ? '0' + digit : 'A' + digit - 10);
|
||||
n /= base;
|
||||
if (n == 0) break;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
if (sign) {
|
||||
i--;
|
||||
buf[i] = '-';
|
||||
}
|
||||
return write(buf + i, sizeof(buf) - i);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
size_t Print::printFloat(double number, uint8_t digits)
|
||||
{
|
||||
uint8_t sign=0;
|
||||
size_t count=0;
|
||||
|
||||
if (isnan(number)) return print("nan");
|
||||
if (isinf(number)) return print("inf");
|
||||
if (number > 4294967040.0f) return print("ovf"); // constant determined empirically
|
||||
if (number <-4294967040.0f) return print("ovf"); // constant determined empirically
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0) {
|
||||
sign = 1;
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
for (uint8_t i=0; i<digits; ++i) {
|
||||
rounding *= 0.1;
|
||||
}
|
||||
number += rounding;
|
||||
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
count += printNumber(int_part, 10, sign);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0) {
|
||||
uint8_t n, buf[16], count=1;
|
||||
buf[0] = '.';
|
||||
|
||||
// Extract digits from the remainder one at a time
|
||||
if (digits > sizeof(buf) - 1) digits = sizeof(buf) - 1;
|
||||
|
||||
while (digits-- > 0) {
|
||||
remainder *= 10.0;
|
||||
n = (uint8_t)(remainder);
|
||||
buf[count++] = '0' + n;
|
||||
remainder -= n;
|
||||
}
|
||||
count += write(buf, count);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
/* Teensyduino Core Library
|
||||
* http://www.pjrc.com/teensy/
|
||||
* Copyright (c) 2017 PJRC.COM, LLC.
|
||||
*
|
||||
* 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:
|
||||
*
|
||||
* 1. The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* 2. If the Software is incorporated into a build system that allows
|
||||
* selection among a list of target devices, then similar target
|
||||
* devices manufactured by PJRC.COM must be included in the list of
|
||||
* target devices and selectable in the same manner.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// Long ago this file contained code from Arduino.cc, which was
|
||||
// Copyright (c) 2008 David A. Mellis. No substantial portion of
|
||||
// Arduino's original code remains. In fact, several improvements
|
||||
// developed for Teensyduino have made their way back into
|
||||
// Arduino's code base. :-)
|
||||
|
||||
#include <Arduino.h>
|
||||
#include "Print.h"
|
||||
|
||||
|
||||
size_t Print::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t count = 0;
|
||||
while (size--) count += write(*buffer++);
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
// size_t Print::print(const String &s)
|
||||
// {
|
||||
// uint8_t buffer[33];
|
||||
// size_t count = 0;
|
||||
// unsigned int index = 0;
|
||||
// unsigned int len = s.length();
|
||||
// while (len > 0) {
|
||||
// s.getBytes(buffer, sizeof(buffer), index);
|
||||
// unsigned int nbytes = len;
|
||||
// if (nbytes > sizeof(buffer)-1) nbytes = sizeof(buffer)-1;
|
||||
// index += nbytes;
|
||||
// len -= nbytes;
|
||||
// count += write(buffer, nbytes);
|
||||
// }
|
||||
// return count;
|
||||
// }
|
||||
|
||||
|
||||
size_t Print::print(long n)
|
||||
{
|
||||
uint8_t sign=0;
|
||||
|
||||
if (n < 0) {
|
||||
sign = '-';
|
||||
n = -n;
|
||||
}
|
||||
return printNumber(n, 10, sign);
|
||||
}
|
||||
|
||||
|
||||
size_t Print::println(void)
|
||||
{
|
||||
uint8_t buf[2]={'\r', '\n'};
|
||||
return write(buf, 2);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
__attribute__((weak))
|
||||
int _write(long file, char *ptr, int len)
|
||||
{
|
||||
((class Print *)file)->write((uint8_t *)ptr, len);
|
||||
return len;
|
||||
}
|
||||
}
|
||||
|
||||
int Print::printf(const char *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
#ifdef __STRICT_ANSI__
|
||||
return 0; // TODO: make this work with -std=c++0x
|
||||
#else
|
||||
return vdprintf((int)this, format, ap);
|
||||
#endif
|
||||
}
|
||||
|
||||
int Print::printf(const __FlashStringHelper *format, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, format);
|
||||
#ifdef __STRICT_ANSI__
|
||||
return 0;
|
||||
#else
|
||||
return vdprintf((int)this, (const char *)format, ap);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __MKL26Z64__
|
||||
|
||||
// optimized code inspired by Stimmer's optimization
|
||||
// obviously a dit different, adapted to 32 bit Cortex-M0+
|
||||
// http://forum.arduino.cc/index.php?topic=167414.msg1293679#msg1293679
|
||||
// http://forum.arduino.cc/index.php?topic=167414.msg1309482#msg1309482
|
||||
// equivelant code:
|
||||
// mod = div % 10;
|
||||
// div = div / 10;
|
||||
// tmp1 = {random};
|
||||
// tmp2 = 10;
|
||||
#if 1
|
||||
// https://forum.pjrc.com/threads/28932-LC-is-10-9-times-slower-than-T3-1?p=76072&viewfull=1#post76072
|
||||
void inline divmod10_v2(uint32_t n,uint32_t *div,uint32_t *mod) {
|
||||
uint32_t p,q;
|
||||
/* Using 32.16 fixed point representation p.q */
|
||||
/* p.q = (n+1)/512 */
|
||||
q = (n&0xFFFF) + 1;
|
||||
p = (n>>16);
|
||||
/* p.q = 51*(n+1)/512 */
|
||||
q = 13107*q;
|
||||
p = 13107*p;
|
||||
/* p.q = (1+1/2^8+1/2^16+1/2^24)*51*(n+1)/512 */
|
||||
q = q + (q>>16) + (p&0xFFFF);
|
||||
p = p + (p>>16) + (q>>16);
|
||||
/* divide by 2 */
|
||||
p = p>>1;
|
||||
*div = p;
|
||||
*mod = n-10*p;
|
||||
}
|
||||
#define divmod10_asm(div, mod, tmp1, tmp2, const3333) \
|
||||
divmod10_v2(div, &div, &mod);
|
||||
/*
|
||||
#define divmod10_asm(div, mod, tmp1, tmp2, const3333) \
|
||||
asm ( \
|
||||
" lsr %2, %0, #16" "\n\t" \
|
||||
" mul %2, %4" "\n\t" \
|
||||
" uxth %1, %0" "\n\t" \
|
||||
" mul %1, %4" "\n\t" \
|
||||
" add %1, #1" "\n\t" \
|
||||
" lsr %0, %2, #16" "\n\t" \
|
||||
" lsl %2, %2, #16" "\n\t" \
|
||||
" add %1, %2" "\n\t" \
|
||||
" mov %3, #0" "\n\t" \
|
||||
" adc %0, %3" "\n\t" \
|
||||
" lsl %0, %0, #15" "\n\t" \
|
||||
" lsr %2, %1, #17" "\n\t" \
|
||||
" orr %0, %2" "\n\t" \
|
||||
" lsl %1, %1, #15" "\n\t" \
|
||||
" lsr %2, %1, #16" "\n\t" \
|
||||
" lsl %3, %0, #16" "\n\t" \
|
||||
" orr %2, %3" "\n\t" \
|
||||
" lsr %3, %0, #16" "\n\t" \
|
||||
" add %1, %0" "\n\t" \
|
||||
" adc %0, %1" "\n\t" \
|
||||
" sub %0, %1" "\n\t" \
|
||||
" add %1, %2" "\n\t" \
|
||||
" adc %0, %3" "\n\t" \
|
||||
" lsr %1, %1, #4" "\n\t" \
|
||||
" mov %3, #10" "\n\t" \
|
||||
" mul %1, %3" "\n\t" \
|
||||
" lsr %1, %1, #28" "\n\t" \
|
||||
: "+l" (div), \
|
||||
"=&l" (mod), \
|
||||
"=&l" (tmp1), \
|
||||
"=&l" (tmp2) \
|
||||
: "l" (const3333) \
|
||||
: \
|
||||
)
|
||||
*/
|
||||
#else
|
||||
#define divmod10_asm(_div, _mod, _tmp1, _tmp2, _const3333) \
|
||||
({ _tmp1 = _div; _div = _div / 10; _mod = _tmp1 - _div * 10; })
|
||||
// ({_mod = _div % 10, _div = _div / 10; })
|
||||
#endif
|
||||
|
||||
|
||||
size_t Print::printNumberDec(unsigned long n, uint8_t sign)
|
||||
{
|
||||
uint8_t buf[11], *p;
|
||||
uint32_t digit;
|
||||
//uint32_t t1, t2, c3333=0x3333;
|
||||
|
||||
p = buf + (sizeof(buf));
|
||||
do {
|
||||
uint32_t div;
|
||||
divmod10_v2(n, &div, &digit);
|
||||
n = div;
|
||||
//divmod10_asm(n, digit, t1, t2, c3333);
|
||||
*--p = digit + '0';
|
||||
} while (n);
|
||||
if (sign) *--p = '-';
|
||||
return write(p, sizeof(buf) - (p - buf));
|
||||
}
|
||||
|
||||
size_t Print::printNumberHex(unsigned long n)
|
||||
{
|
||||
uint8_t digit, buf[8], *p;
|
||||
|
||||
p = buf + (sizeof(buf));
|
||||
do {
|
||||
digit = n & 15;
|
||||
*--p = (digit < 10) ? '0' + digit : 'A' + digit - 10;
|
||||
n >>= 4;
|
||||
} while (n);
|
||||
return write(p, sizeof(buf) - (p - buf));
|
||||
}
|
||||
|
||||
size_t Print::printNumberBin(unsigned long n)
|
||||
{
|
||||
uint8_t buf[32], *p;
|
||||
|
||||
p = buf + (sizeof(buf));
|
||||
do {
|
||||
*--p = '0' + ((uint8_t)n & 1);
|
||||
n >>= 1;
|
||||
} while (n);
|
||||
return write(p, sizeof(buf) - (p - buf));
|
||||
}
|
||||
|
||||
size_t Print::printNumberAny(unsigned long n, uint8_t base)
|
||||
{
|
||||
uint8_t digit, buf[21], *p;
|
||||
uint32_t tmp;
|
||||
|
||||
p = buf + sizeof(buf);
|
||||
do {
|
||||
tmp = n;
|
||||
n = n / base;
|
||||
digit = tmp - n * base;
|
||||
*--p = (digit < 10) ? '0' + digit : 'A' + digit - 10;
|
||||
} while (n);
|
||||
return write(p, sizeof(buf) - (p - buf));
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
size_t Print::printNumber(unsigned long n, uint8_t base, uint8_t sign)
|
||||
{
|
||||
uint8_t buf[34];
|
||||
uint8_t digit, i;
|
||||
|
||||
// TODO: make these checks as inline, since base is
|
||||
// almost always a constant. base = 0 (BYTE) should
|
||||
// inline as a call directly to write()
|
||||
if (base == 0) {
|
||||
return write((uint8_t)n);
|
||||
} else if (base == 1) {
|
||||
base = 10;
|
||||
}
|
||||
|
||||
|
||||
if (n == 0) {
|
||||
buf[sizeof(buf) - 1] = '0';
|
||||
i = sizeof(buf) - 1;
|
||||
} else {
|
||||
i = sizeof(buf) - 1;
|
||||
while (1) {
|
||||
digit = n % base;
|
||||
buf[i] = ((digit < 10) ? '0' + digit : 'A' + digit - 10);
|
||||
n /= base;
|
||||
if (n == 0) break;
|
||||
i--;
|
||||
}
|
||||
}
|
||||
if (sign) {
|
||||
i--;
|
||||
buf[i] = '-';
|
||||
}
|
||||
return write(buf + i, sizeof(buf) - i);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
size_t Print::printFloat(double number, uint8_t digits)
|
||||
{
|
||||
uint8_t sign=0;
|
||||
size_t count=0;
|
||||
|
||||
if (isnan(number)) return print("nan");
|
||||
if (isinf(number)) return print("inf");
|
||||
if (number > 4294967040.0f) return print("ovf"); // constant determined empirically
|
||||
if (number <-4294967040.0f) return print("ovf"); // constant determined empirically
|
||||
|
||||
// Handle negative numbers
|
||||
if (number < 0.0) {
|
||||
sign = 1;
|
||||
number = -number;
|
||||
}
|
||||
|
||||
// Round correctly so that print(1.999, 2) prints as "2.00"
|
||||
double rounding = 0.5;
|
||||
for (uint8_t i=0; i<digits; ++i) {
|
||||
rounding *= 0.1;
|
||||
}
|
||||
number += rounding;
|
||||
|
||||
// Extract the integer part of the number and print it
|
||||
unsigned long int_part = (unsigned long)number;
|
||||
double remainder = number - (double)int_part;
|
||||
count += printNumber(int_part, 10, sign);
|
||||
|
||||
// Print the decimal point, but only if there are digits beyond
|
||||
if (digits > 0) {
|
||||
uint8_t n, buf[16], count=1;
|
||||
buf[0] = '.';
|
||||
|
||||
// Extract digits from the remainder one at a time
|
||||
if (digits > sizeof(buf) - 1) digits = sizeof(buf) - 1;
|
||||
|
||||
while (digits-- > 0) {
|
||||
remainder *= 10.0;
|
||||
n = (uint8_t)(remainder);
|
||||
buf[count++] = '0' + n;
|
||||
remainder -= n;
|
||||
}
|
||||
count += write(buf, count);
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,3 +1,3 @@
|
|||
#include <cmath>
|
||||
|
||||
#include "FilterOnePole.cpp"
|
||||
#include <cmath>
|
||||
|
||||
#include "FilterOnePole.cpp"
|
||||
|
|
|
|||
|
|
@ -1,276 +1,276 @@
|
|||
// This is the 'classic' fixed-space bitmap font for Adafruit_GFX since 1.0.
|
||||
// See gfxfont.h for newer custom bitmap font info.
|
||||
|
||||
#ifndef FONT5X7_H
|
||||
#define FONT5X7_H
|
||||
|
||||
#ifdef __AVR__
|
||||
#include <avr/io.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#elif defined(ESP8266)
|
||||
#include <pgmspace.h>
|
||||
#else
|
||||
#define PROGMEM
|
||||
#endif
|
||||
|
||||
// Standard ASCII 5x7 font
|
||||
|
||||
static const unsigned char font[] PROGMEM = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
|
||||
0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
|
||||
0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
|
||||
0x18, 0x3C, 0x7E, 0x3C, 0x18,
|
||||
0x1C, 0x57, 0x7D, 0x57, 0x1C,
|
||||
0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
|
||||
0x00, 0x18, 0x3C, 0x18, 0x00,
|
||||
0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
|
||||
0x00, 0x18, 0x24, 0x18, 0x00,
|
||||
0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
|
||||
0x30, 0x48, 0x3A, 0x06, 0x0E,
|
||||
0x26, 0x29, 0x79, 0x29, 0x26,
|
||||
0x40, 0x7F, 0x05, 0x05, 0x07,
|
||||
0x40, 0x7F, 0x05, 0x25, 0x3F,
|
||||
0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
|
||||
0x7F, 0x3E, 0x1C, 0x1C, 0x08,
|
||||
0x08, 0x1C, 0x1C, 0x3E, 0x7F,
|
||||
0x14, 0x22, 0x7F, 0x22, 0x14,
|
||||
0x5F, 0x5F, 0x00, 0x5F, 0x5F,
|
||||
0x06, 0x09, 0x7F, 0x01, 0x7F,
|
||||
0x00, 0x66, 0x89, 0x95, 0x6A,
|
||||
0x60, 0x60, 0x60, 0x60, 0x60,
|
||||
0x94, 0xA2, 0xFF, 0xA2, 0x94,
|
||||
0x08, 0x04, 0x7E, 0x04, 0x08,
|
||||
0x10, 0x20, 0x7E, 0x20, 0x10,
|
||||
0x08, 0x08, 0x2A, 0x1C, 0x08,
|
||||
0x08, 0x1C, 0x2A, 0x08, 0x08,
|
||||
0x1E, 0x10, 0x10, 0x10, 0x10,
|
||||
0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
|
||||
0x30, 0x38, 0x3E, 0x38, 0x30,
|
||||
0x06, 0x0E, 0x3E, 0x0E, 0x06,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x5F, 0x00, 0x00,
|
||||
0x00, 0x07, 0x00, 0x07, 0x00,
|
||||
0x14, 0x7F, 0x14, 0x7F, 0x14,
|
||||
0x24, 0x2A, 0x7F, 0x2A, 0x12,
|
||||
0x23, 0x13, 0x08, 0x64, 0x62,
|
||||
0x36, 0x49, 0x56, 0x20, 0x50,
|
||||
0x00, 0x08, 0x07, 0x03, 0x00,
|
||||
0x00, 0x1C, 0x22, 0x41, 0x00,
|
||||
0x00, 0x41, 0x22, 0x1C, 0x00,
|
||||
0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
|
||||
0x08, 0x08, 0x3E, 0x08, 0x08,
|
||||
0x00, 0x80, 0x70, 0x30, 0x00,
|
||||
0x08, 0x08, 0x08, 0x08, 0x08,
|
||||
0x00, 0x00, 0x60, 0x60, 0x00,
|
||||
0x20, 0x10, 0x08, 0x04, 0x02,
|
||||
0x3E, 0x51, 0x49, 0x45, 0x3E,
|
||||
0x00, 0x42, 0x7F, 0x40, 0x00,
|
||||
0x72, 0x49, 0x49, 0x49, 0x46,
|
||||
0x21, 0x41, 0x49, 0x4D, 0x33,
|
||||
0x18, 0x14, 0x12, 0x7F, 0x10,
|
||||
0x27, 0x45, 0x45, 0x45, 0x39,
|
||||
0x3C, 0x4A, 0x49, 0x49, 0x31,
|
||||
0x41, 0x21, 0x11, 0x09, 0x07,
|
||||
0x36, 0x49, 0x49, 0x49, 0x36,
|
||||
0x46, 0x49, 0x49, 0x29, 0x1E,
|
||||
0x00, 0x00, 0x14, 0x00, 0x00,
|
||||
0x00, 0x40, 0x34, 0x00, 0x00,
|
||||
0x00, 0x08, 0x14, 0x22, 0x41,
|
||||
0x14, 0x14, 0x14, 0x14, 0x14,
|
||||
0x00, 0x41, 0x22, 0x14, 0x08,
|
||||
0x02, 0x01, 0x59, 0x09, 0x06,
|
||||
0x3E, 0x41, 0x5D, 0x59, 0x4E,
|
||||
0x7C, 0x12, 0x11, 0x12, 0x7C,
|
||||
0x7F, 0x49, 0x49, 0x49, 0x36,
|
||||
0x3E, 0x41, 0x41, 0x41, 0x22,
|
||||
0x7F, 0x41, 0x41, 0x41, 0x3E,
|
||||
0x7F, 0x49, 0x49, 0x49, 0x41,
|
||||
0x7F, 0x09, 0x09, 0x09, 0x01,
|
||||
0x3E, 0x41, 0x41, 0x51, 0x73,
|
||||
0x7F, 0x08, 0x08, 0x08, 0x7F,
|
||||
0x00, 0x41, 0x7F, 0x41, 0x00,
|
||||
0x20, 0x40, 0x41, 0x3F, 0x01,
|
||||
0x7F, 0x08, 0x14, 0x22, 0x41,
|
||||
0x7F, 0x40, 0x40, 0x40, 0x40,
|
||||
0x7F, 0x02, 0x1C, 0x02, 0x7F,
|
||||
0x7F, 0x04, 0x08, 0x10, 0x7F,
|
||||
0x3E, 0x41, 0x41, 0x41, 0x3E,
|
||||
0x7F, 0x09, 0x09, 0x09, 0x06,
|
||||
0x3E, 0x41, 0x51, 0x21, 0x5E,
|
||||
0x7F, 0x09, 0x19, 0x29, 0x46,
|
||||
0x26, 0x49, 0x49, 0x49, 0x32,
|
||||
0x03, 0x01, 0x7F, 0x01, 0x03,
|
||||
0x3F, 0x40, 0x40, 0x40, 0x3F,
|
||||
0x1F, 0x20, 0x40, 0x20, 0x1F,
|
||||
0x3F, 0x40, 0x38, 0x40, 0x3F,
|
||||
0x63, 0x14, 0x08, 0x14, 0x63,
|
||||
0x03, 0x04, 0x78, 0x04, 0x03,
|
||||
0x61, 0x59, 0x49, 0x4D, 0x43,
|
||||
0x00, 0x7F, 0x41, 0x41, 0x41,
|
||||
0x02, 0x04, 0x08, 0x10, 0x20,
|
||||
0x00, 0x41, 0x41, 0x41, 0x7F,
|
||||
0x04, 0x02, 0x01, 0x02, 0x04,
|
||||
0x40, 0x40, 0x40, 0x40, 0x40,
|
||||
0x00, 0x03, 0x07, 0x08, 0x00,
|
||||
0x20, 0x54, 0x54, 0x78, 0x40,
|
||||
0x7F, 0x28, 0x44, 0x44, 0x38,
|
||||
0x38, 0x44, 0x44, 0x44, 0x28,
|
||||
0x38, 0x44, 0x44, 0x28, 0x7F,
|
||||
0x38, 0x54, 0x54, 0x54, 0x18,
|
||||
0x00, 0x08, 0x7E, 0x09, 0x02,
|
||||
0x18, 0xA4, 0xA4, 0x9C, 0x78,
|
||||
0x7F, 0x08, 0x04, 0x04, 0x78,
|
||||
0x00, 0x44, 0x7D, 0x40, 0x00,
|
||||
0x20, 0x40, 0x40, 0x3D, 0x00,
|
||||
0x7F, 0x10, 0x28, 0x44, 0x00,
|
||||
0x00, 0x41, 0x7F, 0x40, 0x00,
|
||||
0x7C, 0x04, 0x78, 0x04, 0x78,
|
||||
0x7C, 0x08, 0x04, 0x04, 0x78,
|
||||
0x38, 0x44, 0x44, 0x44, 0x38,
|
||||
0xFC, 0x18, 0x24, 0x24, 0x18,
|
||||
0x18, 0x24, 0x24, 0x18, 0xFC,
|
||||
0x7C, 0x08, 0x04, 0x04, 0x08,
|
||||
0x48, 0x54, 0x54, 0x54, 0x24,
|
||||
0x04, 0x04, 0x3F, 0x44, 0x24,
|
||||
0x3C, 0x40, 0x40, 0x20, 0x7C,
|
||||
0x1C, 0x20, 0x40, 0x20, 0x1C,
|
||||
0x3C, 0x40, 0x30, 0x40, 0x3C,
|
||||
0x44, 0x28, 0x10, 0x28, 0x44,
|
||||
0x4C, 0x90, 0x90, 0x90, 0x7C,
|
||||
0x44, 0x64, 0x54, 0x4C, 0x44,
|
||||
0x00, 0x08, 0x36, 0x41, 0x00,
|
||||
0x00, 0x00, 0x77, 0x00, 0x00,
|
||||
0x00, 0x41, 0x36, 0x08, 0x00,
|
||||
0x02, 0x01, 0x02, 0x04, 0x02,
|
||||
0x3C, 0x26, 0x23, 0x26, 0x3C,
|
||||
0x1E, 0xA1, 0xA1, 0x61, 0x12,
|
||||
0x3A, 0x40, 0x40, 0x20, 0x7A,
|
||||
0x38, 0x54, 0x54, 0x55, 0x59,
|
||||
0x21, 0x55, 0x55, 0x79, 0x41,
|
||||
0x22, 0x54, 0x54, 0x78, 0x42, // a-umlaut
|
||||
0x21, 0x55, 0x54, 0x78, 0x40,
|
||||
0x20, 0x54, 0x55, 0x79, 0x40,
|
||||
0x0C, 0x1E, 0x52, 0x72, 0x12,
|
||||
0x39, 0x55, 0x55, 0x55, 0x59,
|
||||
0x39, 0x54, 0x54, 0x54, 0x59,
|
||||
0x39, 0x55, 0x54, 0x54, 0x58,
|
||||
0x00, 0x00, 0x45, 0x7C, 0x41,
|
||||
0x00, 0x02, 0x45, 0x7D, 0x42,
|
||||
0x00, 0x01, 0x45, 0x7C, 0x40,
|
||||
0x7D, 0x12, 0x11, 0x12, 0x7D, // A-umlaut
|
||||
0xF0, 0x28, 0x25, 0x28, 0xF0,
|
||||
0x7C, 0x54, 0x55, 0x45, 0x00,
|
||||
0x20, 0x54, 0x54, 0x7C, 0x54,
|
||||
0x7C, 0x0A, 0x09, 0x7F, 0x49,
|
||||
0x32, 0x49, 0x49, 0x49, 0x32,
|
||||
0x3A, 0x44, 0x44, 0x44, 0x3A, // o-umlaut
|
||||
0x32, 0x4A, 0x48, 0x48, 0x30,
|
||||
0x3A, 0x41, 0x41, 0x21, 0x7A,
|
||||
0x3A, 0x42, 0x40, 0x20, 0x78,
|
||||
0x00, 0x9D, 0xA0, 0xA0, 0x7D,
|
||||
0x3D, 0x42, 0x42, 0x42, 0x3D, // O-umlaut
|
||||
0x3D, 0x40, 0x40, 0x40, 0x3D,
|
||||
0x3C, 0x24, 0xFF, 0x24, 0x24,
|
||||
0x48, 0x7E, 0x49, 0x43, 0x66,
|
||||
0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
|
||||
0xFF, 0x09, 0x29, 0xF6, 0x20,
|
||||
0xC0, 0x88, 0x7E, 0x09, 0x03,
|
||||
0x20, 0x54, 0x54, 0x79, 0x41,
|
||||
0x00, 0x00, 0x44, 0x7D, 0x41,
|
||||
0x30, 0x48, 0x48, 0x4A, 0x32,
|
||||
0x38, 0x40, 0x40, 0x22, 0x7A,
|
||||
0x00, 0x7A, 0x0A, 0x0A, 0x72,
|
||||
0x7D, 0x0D, 0x19, 0x31, 0x7D,
|
||||
0x26, 0x29, 0x29, 0x2F, 0x28,
|
||||
0x26, 0x29, 0x29, 0x29, 0x26,
|
||||
0x30, 0x48, 0x4D, 0x40, 0x20,
|
||||
0x38, 0x08, 0x08, 0x08, 0x08,
|
||||
0x08, 0x08, 0x08, 0x08, 0x38,
|
||||
0x2F, 0x10, 0xC8, 0xAC, 0xBA,
|
||||
0x2F, 0x10, 0x28, 0x34, 0xFA,
|
||||
0x00, 0x00, 0x7B, 0x00, 0x00,
|
||||
0x08, 0x14, 0x2A, 0x14, 0x22,
|
||||
0x22, 0x14, 0x2A, 0x14, 0x08,
|
||||
0x55, 0x00, 0x55, 0x00, 0x55, // #176 (25% block) missing in old code
|
||||
0xAA, 0x55, 0xAA, 0x55, 0xAA, // 50% block
|
||||
0xFF, 0x55, 0xFF, 0x55, 0xFF, // 75% block
|
||||
0x00, 0x00, 0x00, 0xFF, 0x00,
|
||||
0x10, 0x10, 0x10, 0xFF, 0x00,
|
||||
0x14, 0x14, 0x14, 0xFF, 0x00,
|
||||
0x10, 0x10, 0xFF, 0x00, 0xFF,
|
||||
0x10, 0x10, 0xF0, 0x10, 0xF0,
|
||||
0x14, 0x14, 0x14, 0xFC, 0x00,
|
||||
0x14, 0x14, 0xF7, 0x00, 0xFF,
|
||||
0x00, 0x00, 0xFF, 0x00, 0xFF,
|
||||
0x14, 0x14, 0xF4, 0x04, 0xFC,
|
||||
0x14, 0x14, 0x17, 0x10, 0x1F,
|
||||
0x10, 0x10, 0x1F, 0x10, 0x1F,
|
||||
0x14, 0x14, 0x14, 0x1F, 0x00,
|
||||
0x10, 0x10, 0x10, 0xF0, 0x00,
|
||||
0x00, 0x00, 0x00, 0x1F, 0x10,
|
||||
0x10, 0x10, 0x10, 0x1F, 0x10,
|
||||
0x10, 0x10, 0x10, 0xF0, 0x10,
|
||||
0x00, 0x00, 0x00, 0xFF, 0x10,
|
||||
0x10, 0x10, 0x10, 0x10, 0x10,
|
||||
0x10, 0x10, 0x10, 0xFF, 0x10,
|
||||
0x00, 0x00, 0x00, 0xFF, 0x14,
|
||||
0x00, 0x00, 0xFF, 0x00, 0xFF,
|
||||
0x00, 0x00, 0x1F, 0x10, 0x17,
|
||||
0x00, 0x00, 0xFC, 0x04, 0xF4,
|
||||
0x14, 0x14, 0x17, 0x10, 0x17,
|
||||
0x14, 0x14, 0xF4, 0x04, 0xF4,
|
||||
0x00, 0x00, 0xFF, 0x00, 0xF7,
|
||||
0x14, 0x14, 0x14, 0x14, 0x14,
|
||||
0x14, 0x14, 0xF7, 0x00, 0xF7,
|
||||
0x14, 0x14, 0x14, 0x17, 0x14,
|
||||
0x10, 0x10, 0x1F, 0x10, 0x1F,
|
||||
0x14, 0x14, 0x14, 0xF4, 0x14,
|
||||
0x10, 0x10, 0xF0, 0x10, 0xF0,
|
||||
0x00, 0x00, 0x1F, 0x10, 0x1F,
|
||||
0x00, 0x00, 0x00, 0x1F, 0x14,
|
||||
0x00, 0x00, 0x00, 0xFC, 0x14,
|
||||
0x00, 0x00, 0xF0, 0x10, 0xF0,
|
||||
0x10, 0x10, 0xFF, 0x10, 0xFF,
|
||||
0x14, 0x14, 0x14, 0xFF, 0x14,
|
||||
0x10, 0x10, 0x10, 0x1F, 0x00,
|
||||
0x00, 0x00, 0x00, 0xF0, 0x10,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
|
||||
0xFF, 0xFF, 0xFF, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0xFF, 0xFF,
|
||||
0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
|
||||
0x38, 0x44, 0x44, 0x38, 0x44,
|
||||
0xFC, 0x4A, 0x4A, 0x4A, 0x34, // sharp-s or beta
|
||||
0x7E, 0x02, 0x02, 0x06, 0x06,
|
||||
0x02, 0x7E, 0x02, 0x7E, 0x02,
|
||||
0x63, 0x55, 0x49, 0x41, 0x63,
|
||||
0x38, 0x44, 0x44, 0x3C, 0x04,
|
||||
0x40, 0x7E, 0x20, 0x1E, 0x20,
|
||||
0x06, 0x02, 0x7E, 0x02, 0x02,
|
||||
0x99, 0xA5, 0xE7, 0xA5, 0x99,
|
||||
0x1C, 0x2A, 0x49, 0x2A, 0x1C,
|
||||
0x4C, 0x72, 0x01, 0x72, 0x4C,
|
||||
0x30, 0x4A, 0x4D, 0x4D, 0x30,
|
||||
0x30, 0x48, 0x78, 0x48, 0x30,
|
||||
0xBC, 0x62, 0x5A, 0x46, 0x3D,
|
||||
0x3E, 0x49, 0x49, 0x49, 0x00,
|
||||
0x7E, 0x01, 0x01, 0x01, 0x7E,
|
||||
0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
|
||||
0x44, 0x44, 0x5F, 0x44, 0x44,
|
||||
0x40, 0x51, 0x4A, 0x44, 0x40,
|
||||
0x40, 0x44, 0x4A, 0x51, 0x40,
|
||||
0x00, 0x00, 0xFF, 0x01, 0x03,
|
||||
0xE0, 0x80, 0xFF, 0x00, 0x00,
|
||||
0x08, 0x08, 0x6B, 0x6B, 0x08,
|
||||
0x36, 0x12, 0x36, 0x24, 0x36,
|
||||
0x06, 0x0F, 0x09, 0x0F, 0x06,
|
||||
0x00, 0x00, 0x18, 0x18, 0x00,
|
||||
0x00, 0x00, 0x10, 0x10, 0x00,
|
||||
0x30, 0x40, 0xFF, 0x01, 0x01,
|
||||
0x00, 0x1F, 0x01, 0x01, 0x1E,
|
||||
0x00, 0x19, 0x1D, 0x17, 0x12,
|
||||
0x00, 0x3C, 0x3C, 0x3C, 0x3C,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00 // #255 NBSP
|
||||
};
|
||||
#endif // FONT5X7_H
|
||||
// This is the 'classic' fixed-space bitmap font for Adafruit_GFX since 1.0.
|
||||
// See gfxfont.h for newer custom bitmap font info.
|
||||
|
||||
#ifndef FONT5X7_H
|
||||
#define FONT5X7_H
|
||||
|
||||
#ifdef __AVR__
|
||||
#include <avr/io.h>
|
||||
#include <avr/pgmspace.h>
|
||||
#elif defined(ESP8266)
|
||||
#include <pgmspace.h>
|
||||
#else
|
||||
#define PROGMEM
|
||||
#endif
|
||||
|
||||
// Standard ASCII 5x7 font
|
||||
|
||||
static const unsigned char font[] PROGMEM = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
|
||||
0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
|
||||
0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
|
||||
0x18, 0x3C, 0x7E, 0x3C, 0x18,
|
||||
0x1C, 0x57, 0x7D, 0x57, 0x1C,
|
||||
0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
|
||||
0x00, 0x18, 0x3C, 0x18, 0x00,
|
||||
0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
|
||||
0x00, 0x18, 0x24, 0x18, 0x00,
|
||||
0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
|
||||
0x30, 0x48, 0x3A, 0x06, 0x0E,
|
||||
0x26, 0x29, 0x79, 0x29, 0x26,
|
||||
0x40, 0x7F, 0x05, 0x05, 0x07,
|
||||
0x40, 0x7F, 0x05, 0x25, 0x3F,
|
||||
0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
|
||||
0x7F, 0x3E, 0x1C, 0x1C, 0x08,
|
||||
0x08, 0x1C, 0x1C, 0x3E, 0x7F,
|
||||
0x14, 0x22, 0x7F, 0x22, 0x14,
|
||||
0x5F, 0x5F, 0x00, 0x5F, 0x5F,
|
||||
0x06, 0x09, 0x7F, 0x01, 0x7F,
|
||||
0x00, 0x66, 0x89, 0x95, 0x6A,
|
||||
0x60, 0x60, 0x60, 0x60, 0x60,
|
||||
0x94, 0xA2, 0xFF, 0xA2, 0x94,
|
||||
0x08, 0x04, 0x7E, 0x04, 0x08,
|
||||
0x10, 0x20, 0x7E, 0x20, 0x10,
|
||||
0x08, 0x08, 0x2A, 0x1C, 0x08,
|
||||
0x08, 0x1C, 0x2A, 0x08, 0x08,
|
||||
0x1E, 0x10, 0x10, 0x10, 0x10,
|
||||
0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
|
||||
0x30, 0x38, 0x3E, 0x38, 0x30,
|
||||
0x06, 0x0E, 0x3E, 0x0E, 0x06,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x5F, 0x00, 0x00,
|
||||
0x00, 0x07, 0x00, 0x07, 0x00,
|
||||
0x14, 0x7F, 0x14, 0x7F, 0x14,
|
||||
0x24, 0x2A, 0x7F, 0x2A, 0x12,
|
||||
0x23, 0x13, 0x08, 0x64, 0x62,
|
||||
0x36, 0x49, 0x56, 0x20, 0x50,
|
||||
0x00, 0x08, 0x07, 0x03, 0x00,
|
||||
0x00, 0x1C, 0x22, 0x41, 0x00,
|
||||
0x00, 0x41, 0x22, 0x1C, 0x00,
|
||||
0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
|
||||
0x08, 0x08, 0x3E, 0x08, 0x08,
|
||||
0x00, 0x80, 0x70, 0x30, 0x00,
|
||||
0x08, 0x08, 0x08, 0x08, 0x08,
|
||||
0x00, 0x00, 0x60, 0x60, 0x00,
|
||||
0x20, 0x10, 0x08, 0x04, 0x02,
|
||||
0x3E, 0x51, 0x49, 0x45, 0x3E,
|
||||
0x00, 0x42, 0x7F, 0x40, 0x00,
|
||||
0x72, 0x49, 0x49, 0x49, 0x46,
|
||||
0x21, 0x41, 0x49, 0x4D, 0x33,
|
||||
0x18, 0x14, 0x12, 0x7F, 0x10,
|
||||
0x27, 0x45, 0x45, 0x45, 0x39,
|
||||
0x3C, 0x4A, 0x49, 0x49, 0x31,
|
||||
0x41, 0x21, 0x11, 0x09, 0x07,
|
||||
0x36, 0x49, 0x49, 0x49, 0x36,
|
||||
0x46, 0x49, 0x49, 0x29, 0x1E,
|
||||
0x00, 0x00, 0x14, 0x00, 0x00,
|
||||
0x00, 0x40, 0x34, 0x00, 0x00,
|
||||
0x00, 0x08, 0x14, 0x22, 0x41,
|
||||
0x14, 0x14, 0x14, 0x14, 0x14,
|
||||
0x00, 0x41, 0x22, 0x14, 0x08,
|
||||
0x02, 0x01, 0x59, 0x09, 0x06,
|
||||
0x3E, 0x41, 0x5D, 0x59, 0x4E,
|
||||
0x7C, 0x12, 0x11, 0x12, 0x7C,
|
||||
0x7F, 0x49, 0x49, 0x49, 0x36,
|
||||
0x3E, 0x41, 0x41, 0x41, 0x22,
|
||||
0x7F, 0x41, 0x41, 0x41, 0x3E,
|
||||
0x7F, 0x49, 0x49, 0x49, 0x41,
|
||||
0x7F, 0x09, 0x09, 0x09, 0x01,
|
||||
0x3E, 0x41, 0x41, 0x51, 0x73,
|
||||
0x7F, 0x08, 0x08, 0x08, 0x7F,
|
||||
0x00, 0x41, 0x7F, 0x41, 0x00,
|
||||
0x20, 0x40, 0x41, 0x3F, 0x01,
|
||||
0x7F, 0x08, 0x14, 0x22, 0x41,
|
||||
0x7F, 0x40, 0x40, 0x40, 0x40,
|
||||
0x7F, 0x02, 0x1C, 0x02, 0x7F,
|
||||
0x7F, 0x04, 0x08, 0x10, 0x7F,
|
||||
0x3E, 0x41, 0x41, 0x41, 0x3E,
|
||||
0x7F, 0x09, 0x09, 0x09, 0x06,
|
||||
0x3E, 0x41, 0x51, 0x21, 0x5E,
|
||||
0x7F, 0x09, 0x19, 0x29, 0x46,
|
||||
0x26, 0x49, 0x49, 0x49, 0x32,
|
||||
0x03, 0x01, 0x7F, 0x01, 0x03,
|
||||
0x3F, 0x40, 0x40, 0x40, 0x3F,
|
||||
0x1F, 0x20, 0x40, 0x20, 0x1F,
|
||||
0x3F, 0x40, 0x38, 0x40, 0x3F,
|
||||
0x63, 0x14, 0x08, 0x14, 0x63,
|
||||
0x03, 0x04, 0x78, 0x04, 0x03,
|
||||
0x61, 0x59, 0x49, 0x4D, 0x43,
|
||||
0x00, 0x7F, 0x41, 0x41, 0x41,
|
||||
0x02, 0x04, 0x08, 0x10, 0x20,
|
||||
0x00, 0x41, 0x41, 0x41, 0x7F,
|
||||
0x04, 0x02, 0x01, 0x02, 0x04,
|
||||
0x40, 0x40, 0x40, 0x40, 0x40,
|
||||
0x00, 0x03, 0x07, 0x08, 0x00,
|
||||
0x20, 0x54, 0x54, 0x78, 0x40,
|
||||
0x7F, 0x28, 0x44, 0x44, 0x38,
|
||||
0x38, 0x44, 0x44, 0x44, 0x28,
|
||||
0x38, 0x44, 0x44, 0x28, 0x7F,
|
||||
0x38, 0x54, 0x54, 0x54, 0x18,
|
||||
0x00, 0x08, 0x7E, 0x09, 0x02,
|
||||
0x18, 0xA4, 0xA4, 0x9C, 0x78,
|
||||
0x7F, 0x08, 0x04, 0x04, 0x78,
|
||||
0x00, 0x44, 0x7D, 0x40, 0x00,
|
||||
0x20, 0x40, 0x40, 0x3D, 0x00,
|
||||
0x7F, 0x10, 0x28, 0x44, 0x00,
|
||||
0x00, 0x41, 0x7F, 0x40, 0x00,
|
||||
0x7C, 0x04, 0x78, 0x04, 0x78,
|
||||
0x7C, 0x08, 0x04, 0x04, 0x78,
|
||||
0x38, 0x44, 0x44, 0x44, 0x38,
|
||||
0xFC, 0x18, 0x24, 0x24, 0x18,
|
||||
0x18, 0x24, 0x24, 0x18, 0xFC,
|
||||
0x7C, 0x08, 0x04, 0x04, 0x08,
|
||||
0x48, 0x54, 0x54, 0x54, 0x24,
|
||||
0x04, 0x04, 0x3F, 0x44, 0x24,
|
||||
0x3C, 0x40, 0x40, 0x20, 0x7C,
|
||||
0x1C, 0x20, 0x40, 0x20, 0x1C,
|
||||
0x3C, 0x40, 0x30, 0x40, 0x3C,
|
||||
0x44, 0x28, 0x10, 0x28, 0x44,
|
||||
0x4C, 0x90, 0x90, 0x90, 0x7C,
|
||||
0x44, 0x64, 0x54, 0x4C, 0x44,
|
||||
0x00, 0x08, 0x36, 0x41, 0x00,
|
||||
0x00, 0x00, 0x77, 0x00, 0x00,
|
||||
0x00, 0x41, 0x36, 0x08, 0x00,
|
||||
0x02, 0x01, 0x02, 0x04, 0x02,
|
||||
0x3C, 0x26, 0x23, 0x26, 0x3C,
|
||||
0x1E, 0xA1, 0xA1, 0x61, 0x12,
|
||||
0x3A, 0x40, 0x40, 0x20, 0x7A,
|
||||
0x38, 0x54, 0x54, 0x55, 0x59,
|
||||
0x21, 0x55, 0x55, 0x79, 0x41,
|
||||
0x22, 0x54, 0x54, 0x78, 0x42, // a-umlaut
|
||||
0x21, 0x55, 0x54, 0x78, 0x40,
|
||||
0x20, 0x54, 0x55, 0x79, 0x40,
|
||||
0x0C, 0x1E, 0x52, 0x72, 0x12,
|
||||
0x39, 0x55, 0x55, 0x55, 0x59,
|
||||
0x39, 0x54, 0x54, 0x54, 0x59,
|
||||
0x39, 0x55, 0x54, 0x54, 0x58,
|
||||
0x00, 0x00, 0x45, 0x7C, 0x41,
|
||||
0x00, 0x02, 0x45, 0x7D, 0x42,
|
||||
0x00, 0x01, 0x45, 0x7C, 0x40,
|
||||
0x7D, 0x12, 0x11, 0x12, 0x7D, // A-umlaut
|
||||
0xF0, 0x28, 0x25, 0x28, 0xF0,
|
||||
0x7C, 0x54, 0x55, 0x45, 0x00,
|
||||
0x20, 0x54, 0x54, 0x7C, 0x54,
|
||||
0x7C, 0x0A, 0x09, 0x7F, 0x49,
|
||||
0x32, 0x49, 0x49, 0x49, 0x32,
|
||||
0x3A, 0x44, 0x44, 0x44, 0x3A, // o-umlaut
|
||||
0x32, 0x4A, 0x48, 0x48, 0x30,
|
||||
0x3A, 0x41, 0x41, 0x21, 0x7A,
|
||||
0x3A, 0x42, 0x40, 0x20, 0x78,
|
||||
0x00, 0x9D, 0xA0, 0xA0, 0x7D,
|
||||
0x3D, 0x42, 0x42, 0x42, 0x3D, // O-umlaut
|
||||
0x3D, 0x40, 0x40, 0x40, 0x3D,
|
||||
0x3C, 0x24, 0xFF, 0x24, 0x24,
|
||||
0x48, 0x7E, 0x49, 0x43, 0x66,
|
||||
0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
|
||||
0xFF, 0x09, 0x29, 0xF6, 0x20,
|
||||
0xC0, 0x88, 0x7E, 0x09, 0x03,
|
||||
0x20, 0x54, 0x54, 0x79, 0x41,
|
||||
0x00, 0x00, 0x44, 0x7D, 0x41,
|
||||
0x30, 0x48, 0x48, 0x4A, 0x32,
|
||||
0x38, 0x40, 0x40, 0x22, 0x7A,
|
||||
0x00, 0x7A, 0x0A, 0x0A, 0x72,
|
||||
0x7D, 0x0D, 0x19, 0x31, 0x7D,
|
||||
0x26, 0x29, 0x29, 0x2F, 0x28,
|
||||
0x26, 0x29, 0x29, 0x29, 0x26,
|
||||
0x30, 0x48, 0x4D, 0x40, 0x20,
|
||||
0x38, 0x08, 0x08, 0x08, 0x08,
|
||||
0x08, 0x08, 0x08, 0x08, 0x38,
|
||||
0x2F, 0x10, 0xC8, 0xAC, 0xBA,
|
||||
0x2F, 0x10, 0x28, 0x34, 0xFA,
|
||||
0x00, 0x00, 0x7B, 0x00, 0x00,
|
||||
0x08, 0x14, 0x2A, 0x14, 0x22,
|
||||
0x22, 0x14, 0x2A, 0x14, 0x08,
|
||||
0x55, 0x00, 0x55, 0x00, 0x55, // #176 (25% block) missing in old code
|
||||
0xAA, 0x55, 0xAA, 0x55, 0xAA, // 50% block
|
||||
0xFF, 0x55, 0xFF, 0x55, 0xFF, // 75% block
|
||||
0x00, 0x00, 0x00, 0xFF, 0x00,
|
||||
0x10, 0x10, 0x10, 0xFF, 0x00,
|
||||
0x14, 0x14, 0x14, 0xFF, 0x00,
|
||||
0x10, 0x10, 0xFF, 0x00, 0xFF,
|
||||
0x10, 0x10, 0xF0, 0x10, 0xF0,
|
||||
0x14, 0x14, 0x14, 0xFC, 0x00,
|
||||
0x14, 0x14, 0xF7, 0x00, 0xFF,
|
||||
0x00, 0x00, 0xFF, 0x00, 0xFF,
|
||||
0x14, 0x14, 0xF4, 0x04, 0xFC,
|
||||
0x14, 0x14, 0x17, 0x10, 0x1F,
|
||||
0x10, 0x10, 0x1F, 0x10, 0x1F,
|
||||
0x14, 0x14, 0x14, 0x1F, 0x00,
|
||||
0x10, 0x10, 0x10, 0xF0, 0x00,
|
||||
0x00, 0x00, 0x00, 0x1F, 0x10,
|
||||
0x10, 0x10, 0x10, 0x1F, 0x10,
|
||||
0x10, 0x10, 0x10, 0xF0, 0x10,
|
||||
0x00, 0x00, 0x00, 0xFF, 0x10,
|
||||
0x10, 0x10, 0x10, 0x10, 0x10,
|
||||
0x10, 0x10, 0x10, 0xFF, 0x10,
|
||||
0x00, 0x00, 0x00, 0xFF, 0x14,
|
||||
0x00, 0x00, 0xFF, 0x00, 0xFF,
|
||||
0x00, 0x00, 0x1F, 0x10, 0x17,
|
||||
0x00, 0x00, 0xFC, 0x04, 0xF4,
|
||||
0x14, 0x14, 0x17, 0x10, 0x17,
|
||||
0x14, 0x14, 0xF4, 0x04, 0xF4,
|
||||
0x00, 0x00, 0xFF, 0x00, 0xF7,
|
||||
0x14, 0x14, 0x14, 0x14, 0x14,
|
||||
0x14, 0x14, 0xF7, 0x00, 0xF7,
|
||||
0x14, 0x14, 0x14, 0x17, 0x14,
|
||||
0x10, 0x10, 0x1F, 0x10, 0x1F,
|
||||
0x14, 0x14, 0x14, 0xF4, 0x14,
|
||||
0x10, 0x10, 0xF0, 0x10, 0xF0,
|
||||
0x00, 0x00, 0x1F, 0x10, 0x1F,
|
||||
0x00, 0x00, 0x00, 0x1F, 0x14,
|
||||
0x00, 0x00, 0x00, 0xFC, 0x14,
|
||||
0x00, 0x00, 0xF0, 0x10, 0xF0,
|
||||
0x10, 0x10, 0xFF, 0x10, 0xFF,
|
||||
0x14, 0x14, 0x14, 0xFF, 0x14,
|
||||
0x10, 0x10, 0x10, 0x1F, 0x00,
|
||||
0x00, 0x00, 0x00, 0xF0, 0x10,
|
||||
0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
|
||||
0xFF, 0xFF, 0xFF, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0xFF, 0xFF,
|
||||
0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
|
||||
0x38, 0x44, 0x44, 0x38, 0x44,
|
||||
0xFC, 0x4A, 0x4A, 0x4A, 0x34, // sharp-s or beta
|
||||
0x7E, 0x02, 0x02, 0x06, 0x06,
|
||||
0x02, 0x7E, 0x02, 0x7E, 0x02,
|
||||
0x63, 0x55, 0x49, 0x41, 0x63,
|
||||
0x38, 0x44, 0x44, 0x3C, 0x04,
|
||||
0x40, 0x7E, 0x20, 0x1E, 0x20,
|
||||
0x06, 0x02, 0x7E, 0x02, 0x02,
|
||||
0x99, 0xA5, 0xE7, 0xA5, 0x99,
|
||||
0x1C, 0x2A, 0x49, 0x2A, 0x1C,
|
||||
0x4C, 0x72, 0x01, 0x72, 0x4C,
|
||||
0x30, 0x4A, 0x4D, 0x4D, 0x30,
|
||||
0x30, 0x48, 0x78, 0x48, 0x30,
|
||||
0xBC, 0x62, 0x5A, 0x46, 0x3D,
|
||||
0x3E, 0x49, 0x49, 0x49, 0x00,
|
||||
0x7E, 0x01, 0x01, 0x01, 0x7E,
|
||||
0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
|
||||
0x44, 0x44, 0x5F, 0x44, 0x44,
|
||||
0x40, 0x51, 0x4A, 0x44, 0x40,
|
||||
0x40, 0x44, 0x4A, 0x51, 0x40,
|
||||
0x00, 0x00, 0xFF, 0x01, 0x03,
|
||||
0xE0, 0x80, 0xFF, 0x00, 0x00,
|
||||
0x08, 0x08, 0x6B, 0x6B, 0x08,
|
||||
0x36, 0x12, 0x36, 0x24, 0x36,
|
||||
0x06, 0x0F, 0x09, 0x0F, 0x06,
|
||||
0x00, 0x00, 0x18, 0x18, 0x00,
|
||||
0x00, 0x00, 0x10, 0x10, 0x00,
|
||||
0x30, 0x40, 0xFF, 0x01, 0x01,
|
||||
0x00, 0x1F, 0x01, 0x01, 0x1E,
|
||||
0x00, 0x19, 0x1D, 0x17, 0x12,
|
||||
0x00, 0x3C, 0x3C, 0x3C, 0x3C,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00 // #255 NBSP
|
||||
};
|
||||
#endif // FONT5X7_H
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -1,124 +1,124 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
#include "EEPROM.h"
|
||||
|
||||
// TODO: Fake eeprom a bit better, maybe even save to file.
|
||||
|
||||
EEPROMClass::EEPROMClass() {
|
||||
memset(someFakeEEPROM_memory, 0xff, sizeof(someFakeEEPROM_memory));
|
||||
storage = NULL;
|
||||
autoUpdate = false;
|
||||
}
|
||||
|
||||
|
||||
uint8_t EEPROMClass::read( int idx )
|
||||
{
|
||||
printf("Reading EEPROM address %u: %u\n", idx, 0xff&someFakeEEPROM_memory[idx]);
|
||||
return someFakeEEPROM_memory[idx];
|
||||
}
|
||||
|
||||
|
||||
void EEPROMClass::write( int idx, uint8_t val )
|
||||
{
|
||||
printf("Writing to EEPROM address %u = %u\n", idx, val);
|
||||
|
||||
if(val == someFakeEEPROM_memory[idx])
|
||||
{
|
||||
//Value unchanged, do nothing.
|
||||
return;
|
||||
}
|
||||
|
||||
someFakeEEPROM_memory[idx] = val;
|
||||
|
||||
if(autoUpdate && storage)
|
||||
{
|
||||
fseek(storage, idx, SEEK_SET);
|
||||
fputc(val, storage);
|
||||
fflush(storage);
|
||||
}
|
||||
}
|
||||
|
||||
void EEPROMClass::update( int idx, uint8_t val )
|
||||
{
|
||||
write(idx, val);
|
||||
}
|
||||
|
||||
uint16_t EEPROMClass::length()
|
||||
{
|
||||
return sizeof(someFakeEEPROM_memory);
|
||||
}
|
||||
|
||||
int16_t EEPROMClass::setStorage(const char* filename, bool write)
|
||||
{
|
||||
|
||||
//Close any open storage file
|
||||
if(storage)
|
||||
{
|
||||
fclose(storage);
|
||||
storage = NULL;
|
||||
}
|
||||
|
||||
autoUpdate = write;
|
||||
|
||||
storage = fopen(filename, "rb");
|
||||
|
||||
|
||||
//If only reading, fail if file does not exist (makes no sense otherwise)
|
||||
if(!storage && !autoUpdate) {
|
||||
printf("Could not open EEPROM storage file: '%s'\n", filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(storage)
|
||||
{
|
||||
printf("Reading EEPROM storage file: '%s'\n", filename);
|
||||
rewind(storage);
|
||||
fread(someFakeEEPROM_memory, sizeof(someFakeEEPROM_memory), 1, storage);
|
||||
}
|
||||
|
||||
if(!autoUpdate)
|
||||
{
|
||||
//No need for the file anymore, close it
|
||||
fclose(storage);
|
||||
storage = NULL;
|
||||
}
|
||||
|
||||
//Create file if it doesn't exist (so we can write to it)
|
||||
if(!storage && autoUpdate)
|
||||
{
|
||||
storage = fopen(filename, "wb");
|
||||
if(!storage)
|
||||
{
|
||||
printf("Could not create EEPROM storage file: '%s'\n", filename);
|
||||
autoUpdate = false;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
if(storage && autoUpdate)
|
||||
{
|
||||
//Reopen file for writing without overwriting it
|
||||
storage = freopen(filename, "r+b", storage);
|
||||
|
||||
if(!storage)
|
||||
{
|
||||
printf("Could not access EEPROM storage file for writing: '%s'\n", filename);
|
||||
autoUpdate = false;
|
||||
return -3;
|
||||
}
|
||||
|
||||
printf("Writing any EEPROM changes to '%s'\n", filename);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void EEPROMClass::closeStorage() {
|
||||
if(storage!=NULL)
|
||||
{
|
||||
fclose(storage);
|
||||
storage=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <memory.h>
|
||||
#include "EEPROM.h"
|
||||
|
||||
// TODO: Fake eeprom a bit better, maybe even save to file.
|
||||
|
||||
EEPROMClass::EEPROMClass() {
|
||||
memset(someFakeEEPROM_memory, 0xff, sizeof(someFakeEEPROM_memory));
|
||||
storage = NULL;
|
||||
autoUpdate = false;
|
||||
}
|
||||
|
||||
|
||||
uint8_t EEPROMClass::read( int idx )
|
||||
{
|
||||
printf("Reading EEPROM address %u: %u\n", idx, 0xff&someFakeEEPROM_memory[idx]);
|
||||
return someFakeEEPROM_memory[idx];
|
||||
}
|
||||
|
||||
|
||||
void EEPROMClass::write( int idx, uint8_t val )
|
||||
{
|
||||
printf("Writing to EEPROM address %u = %u\n", idx, val);
|
||||
|
||||
if(val == someFakeEEPROM_memory[idx])
|
||||
{
|
||||
//Value unchanged, do nothing.
|
||||
return;
|
||||
}
|
||||
|
||||
someFakeEEPROM_memory[idx] = val;
|
||||
|
||||
if(autoUpdate && storage)
|
||||
{
|
||||
fseek(storage, idx, SEEK_SET);
|
||||
fputc(val, storage);
|
||||
fflush(storage);
|
||||
}
|
||||
}
|
||||
|
||||
void EEPROMClass::update( int idx, uint8_t val )
|
||||
{
|
||||
write(idx, val);
|
||||
}
|
||||
|
||||
uint16_t EEPROMClass::length()
|
||||
{
|
||||
return sizeof(someFakeEEPROM_memory);
|
||||
}
|
||||
|
||||
int16_t EEPROMClass::setStorage(const char* filename, bool write)
|
||||
{
|
||||
|
||||
//Close any open storage file
|
||||
if(storage)
|
||||
{
|
||||
fclose(storage);
|
||||
storage = NULL;
|
||||
}
|
||||
|
||||
autoUpdate = write;
|
||||
|
||||
storage = fopen(filename, "rb");
|
||||
|
||||
|
||||
//If only reading, fail if file does not exist (makes no sense otherwise)
|
||||
if(!storage && !autoUpdate) {
|
||||
printf("Could not open EEPROM storage file: '%s'\n", filename);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(storage)
|
||||
{
|
||||
printf("Reading EEPROM storage file: '%s'\n", filename);
|
||||
rewind(storage);
|
||||
fread(someFakeEEPROM_memory, sizeof(someFakeEEPROM_memory), 1, storage);
|
||||
}
|
||||
|
||||
if(!autoUpdate)
|
||||
{
|
||||
//No need for the file anymore, close it
|
||||
fclose(storage);
|
||||
storage = NULL;
|
||||
}
|
||||
|
||||
//Create file if it doesn't exist (so we can write to it)
|
||||
if(!storage && autoUpdate)
|
||||
{
|
||||
storage = fopen(filename, "wb");
|
||||
if(!storage)
|
||||
{
|
||||
printf("Could not create EEPROM storage file: '%s'\n", filename);
|
||||
autoUpdate = false;
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
if(storage && autoUpdate)
|
||||
{
|
||||
//Reopen file for writing without overwriting it
|
||||
storage = freopen(filename, "r+b", storage);
|
||||
|
||||
if(!storage)
|
||||
{
|
||||
printf("Could not access EEPROM storage file for writing: '%s'\n", filename);
|
||||
autoUpdate = false;
|
||||
return -3;
|
||||
}
|
||||
|
||||
printf("Writing any EEPROM changes to '%s'\n", filename);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void EEPROMClass::closeStorage() {
|
||||
if(storage!=NULL)
|
||||
{
|
||||
fclose(storage);
|
||||
storage=NULL;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,55 +1,55 @@
|
|||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
/********************************
|
||||
*
|
||||
*/
|
||||
void SimSerial::begin(uint32_t)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SimSerial::print(const char* str)
|
||||
{
|
||||
printf( "[Serial::print] %s\n", str );
|
||||
}
|
||||
|
||||
|
||||
void SimSerial::print(uint32_t intValue)
|
||||
{
|
||||
printf( "[Serial::print] %d\n", intValue );
|
||||
}
|
||||
|
||||
void SimSerial::println()
|
||||
{
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
void SimSerial::println(uint32_t intValue)
|
||||
{
|
||||
printf( "[Serial::println] %d\n", intValue );
|
||||
}
|
||||
|
||||
|
||||
void SimSerial::println(const char *str)
|
||||
{
|
||||
printf( "[Serial::println] %s\n", str );
|
||||
}
|
||||
|
||||
//Used to send serial midi
|
||||
void SimSerial::write(const uint8_t __unused str)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SimSerial::flush()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
/********************************
|
||||
*
|
||||
*/
|
||||
void SimSerial::begin(uint32_t)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SimSerial::print(const char* str)
|
||||
{
|
||||
printf( "[Serial::print] %s\n", str );
|
||||
}
|
||||
|
||||
|
||||
void SimSerial::print(uint32_t intValue)
|
||||
{
|
||||
printf( "[Serial::print] %d\n", intValue );
|
||||
}
|
||||
|
||||
void SimSerial::println()
|
||||
{
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
|
||||
void SimSerial::println(uint32_t intValue)
|
||||
{
|
||||
printf( "[Serial::println] %d\n", intValue );
|
||||
}
|
||||
|
||||
|
||||
void SimSerial::println(const char *str)
|
||||
{
|
||||
printf( "[Serial::println] %s\n", str );
|
||||
}
|
||||
|
||||
//Used to send serial midi
|
||||
void SimSerial::write(const uint8_t __unused str)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SimSerial::flush()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,145 +1,145 @@
|
|||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
#include "simusbmidi.h"
|
||||
|
||||
/*************************************
|
||||
* Stub simulation of Teensy usbMidi
|
||||
*/
|
||||
|
||||
void SimUsbMidi::sendNoteOff(uint8_t note, uint8_t velocity, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::noteOff] note %03d vel %03d ch %02d\n", note, velocity, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendNoteOn(uint8_t note, uint8_t velocity, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::noteOn] note %03d vel %03d ch %02d\n", note, velocity, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendPolyPressure(uint8_t note, uint8_t pressure, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::polyPressure] note %03d p %03d ch %02d\n", note, pressure, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendAfterTouchPoly(uint8_t note, uint8_t pressure, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::afterTouchPoly] note %03d p %03d ch %02d\n", note, pressure, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendControlChange(uint8_t control, uint8_t value, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::controlChange] cc %03d val %03d ch %02d\n", control, value, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendProgramChange(uint8_t program, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::programChange] prg %03d ch %02d\n", program, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendAfterTouch(uint8_t pressure, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::afterTouch] p %03d ch %02d\n", pressure, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendPitchBend(int value, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::pitchBend] pb %05d ch %02d\n", value, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendSysEx(uint16_t length, const uint8_t *data, bool __unused hasTerm, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::sysEx] Sending %d bytes\n", length);
|
||||
for(int i=0; i<length; i++) {
|
||||
printf("%02x%c", data[i], (i==length-1)?'\n':':');
|
||||
}
|
||||
}
|
||||
|
||||
//Set a low chunk size on purpose just to let the receiver work for it
|
||||
#define MIDI_SYSEX_CHUNK_SIZE 32
|
||||
|
||||
bool SimUsbMidi::read(uint8_t __unused channel) {
|
||||
if(this->sendMidi) {
|
||||
|
||||
printf("[SimUsbMidi::read] Attempting to send midi data\n");
|
||||
|
||||
std::ifstream file(this->midiFile, std::ios::binary | std::ios::ate);
|
||||
std::streamsize size = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
uint8_t *buffer = (uint8_t*)malloc(size);
|
||||
|
||||
if (file.read((char*)buffer, size))
|
||||
{
|
||||
printf("[SimUsbMidi::read] Sending %lu bytes.\n", size);
|
||||
|
||||
this->receiveMidiData(buffer, size);
|
||||
|
||||
}
|
||||
free(buffer);
|
||||
|
||||
this->sendMidi = false;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//Provide midi data for simulation to receive
|
||||
void SimUsbMidi::receiveMidiData(const uint8_t *data, const uint16_t length) {
|
||||
if(length==0) return; //There is no data, what's even the point
|
||||
uint8_t midi_message = data[0]; //First byte of data
|
||||
|
||||
if(midi_message != 0xF0) return; //Only sysex data supported (no other handlers available)
|
||||
|
||||
if(this->usb_midi_handleSysExPartial) {
|
||||
//Chunked sysex receiver set, use that.
|
||||
if(length<=MIDI_SYSEX_CHUNK_SIZE) {
|
||||
//Send all in one go
|
||||
printf( "[SimUsbMidi::receiveMidiData] usb_midi_handleSysExPartial(complete) %d B\n", length);
|
||||
(this->usb_midi_handleSysExPartial)(data, length, true);
|
||||
} else {
|
||||
uint8_t* buf = (uint8_t*)malloc(MIDI_SYSEX_CHUNK_SIZE);
|
||||
int pos=0;
|
||||
while(pos<length) {
|
||||
int remaining = length-pos;
|
||||
int bytesToSend = std::min(remaining, MIDI_SYSEX_CHUNK_SIZE);
|
||||
bool complete = (bytesToSend == remaining);
|
||||
|
||||
memcpy(buf, data+pos, bytesToSend);
|
||||
printf( "[SimUsbMidi::receiveMidiData] usb_midi_handleSysExPartial(complete: %d) %d B\n", complete, bytesToSend);
|
||||
(this->usb_midi_handleSysExPartial)(buf, bytesToSend, complete);
|
||||
pos=pos+bytesToSend;
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
|
||||
} else if(this->usb_midi_handleSysExComplete) {
|
||||
printf( "[SimUsbMidi::receiveMidiData] usb_midi_handleSysExComplete() %d B\n", length);
|
||||
(this->usb_midi_handleSysExComplete)(data, length);
|
||||
} else {
|
||||
//Nobody listening
|
||||
}
|
||||
}
|
||||
|
||||
//MIDI SysEx handlers. Choice of data types is a bit odd, but done to match Arduino/Teensy libraries
|
||||
void SimUsbMidi::setHandleSystemExclusive(void (*fptr) (const uint8_t *array, unsigned int size)) {
|
||||
this->usb_midi_handleSysExComplete = fptr;
|
||||
}
|
||||
|
||||
//"Chunked" sysex handler (teensy extension), for large messages
|
||||
void SimUsbMidi::setHandleSystemExclusive(void (*fptr) (const uint8_t *array, uint16_t size, bool last)) {
|
||||
this->usb_midi_handleSysExPartial = (void (*)(const uint8_t *, uint16_t, uint8_t))fptr;
|
||||
}
|
||||
|
||||
void SimUsbMidi::setMidiFile(std::string filename) {
|
||||
this->midiFile = filename;
|
||||
}
|
||||
|
||||
void SimUsbMidi::triggerMidi() {
|
||||
this->sendMidi = true;
|
||||
}
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
#include "simusbmidi.h"
|
||||
|
||||
/*************************************
|
||||
* Stub simulation of Teensy usbMidi
|
||||
*/
|
||||
|
||||
void SimUsbMidi::sendNoteOff(uint8_t note, uint8_t velocity, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::noteOff] note %03d vel %03d ch %02d\n", note, velocity, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendNoteOn(uint8_t note, uint8_t velocity, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::noteOn] note %03d vel %03d ch %02d\n", note, velocity, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendPolyPressure(uint8_t note, uint8_t pressure, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::polyPressure] note %03d p %03d ch %02d\n", note, pressure, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendAfterTouchPoly(uint8_t note, uint8_t pressure, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::afterTouchPoly] note %03d p %03d ch %02d\n", note, pressure, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendControlChange(uint8_t control, uint8_t value, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::controlChange] cc %03d val %03d ch %02d\n", control, value, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendProgramChange(uint8_t program, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::programChange] prg %03d ch %02d\n", program, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendAfterTouch(uint8_t pressure, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::afterTouch] p %03d ch %02d\n", pressure, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendPitchBend(int value, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::pitchBend] pb %05d ch %02d\n", value, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendSysEx(uint16_t length, const uint8_t *data, bool __unused hasTerm, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::sysEx] Sending %d bytes\n", length);
|
||||
for(int i=0; i<length; i++) {
|
||||
printf("%02x%c", data[i], (i==length-1)?'\n':':');
|
||||
}
|
||||
}
|
||||
|
||||
//Set a low chunk size on purpose just to let the receiver work for it
|
||||
#define MIDI_SYSEX_CHUNK_SIZE 32
|
||||
|
||||
bool SimUsbMidi::read(uint8_t __unused channel) {
|
||||
if(this->sendMidi) {
|
||||
|
||||
printf("[SimUsbMidi::read] Attempting to send midi data\n");
|
||||
|
||||
std::ifstream file(this->midiFile, std::ios::binary | std::ios::ate);
|
||||
std::streamsize size = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
uint8_t *buffer = (uint8_t*)malloc(size);
|
||||
|
||||
if (file.read((char*)buffer, size))
|
||||
{
|
||||
printf("[SimUsbMidi::read] Sending %lu bytes.\n", size);
|
||||
|
||||
this->receiveMidiData(buffer, size);
|
||||
|
||||
}
|
||||
free(buffer);
|
||||
|
||||
this->sendMidi = false;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//Provide midi data for simulation to receive
|
||||
void SimUsbMidi::receiveMidiData(const uint8_t *data, const uint16_t length) {
|
||||
if(length==0) return; //There is no data, what's even the point
|
||||
uint8_t midi_message = data[0]; //First byte of data
|
||||
|
||||
if(midi_message != 0xF0) return; //Only sysex data supported (no other handlers available)
|
||||
|
||||
if(this->usb_midi_handleSysExPartial) {
|
||||
//Chunked sysex receiver set, use that.
|
||||
if(length<=MIDI_SYSEX_CHUNK_SIZE) {
|
||||
//Send all in one go
|
||||
printf( "[SimUsbMidi::receiveMidiData] usb_midi_handleSysExPartial(complete) %d B\n", length);
|
||||
(this->usb_midi_handleSysExPartial)(data, length, true);
|
||||
} else {
|
||||
uint8_t* buf = (uint8_t*)malloc(MIDI_SYSEX_CHUNK_SIZE);
|
||||
int pos=0;
|
||||
while(pos<length) {
|
||||
int remaining = length-pos;
|
||||
int bytesToSend = std::min(remaining, MIDI_SYSEX_CHUNK_SIZE);
|
||||
bool complete = (bytesToSend == remaining);
|
||||
|
||||
memcpy(buf, data+pos, bytesToSend);
|
||||
printf( "[SimUsbMidi::receiveMidiData] usb_midi_handleSysExPartial(complete: %d) %d B\n", complete, bytesToSend);
|
||||
(this->usb_midi_handleSysExPartial)(buf, bytesToSend, complete);
|
||||
pos=pos+bytesToSend;
|
||||
}
|
||||
free(buf);
|
||||
}
|
||||
|
||||
} else if(this->usb_midi_handleSysExComplete) {
|
||||
printf( "[SimUsbMidi::receiveMidiData] usb_midi_handleSysExComplete() %d B\n", length);
|
||||
(this->usb_midi_handleSysExComplete)(data, length);
|
||||
} else {
|
||||
//Nobody listening
|
||||
}
|
||||
}
|
||||
|
||||
//MIDI SysEx handlers. Choice of data types is a bit odd, but done to match Arduino/Teensy libraries
|
||||
void SimUsbMidi::setHandleSystemExclusive(void (*fptr) (const uint8_t *array, unsigned int size)) {
|
||||
this->usb_midi_handleSysExComplete = fptr;
|
||||
}
|
||||
|
||||
//"Chunked" sysex handler (teensy extension), for large messages
|
||||
void SimUsbMidi::setHandleSystemExclusive(void (*fptr) (const uint8_t *array, uint16_t size, bool last)) {
|
||||
this->usb_midi_handleSysExPartial = (void (*)(const uint8_t *, uint16_t, uint8_t))fptr;
|
||||
}
|
||||
|
||||
void SimUsbMidi::setMidiFile(std::string filename) {
|
||||
this->midiFile = filename;
|
||||
}
|
||||
|
||||
void SimUsbMidi::triggerMidi() {
|
||||
this->sendMidi = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,94 +1,94 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "Wire.h"
|
||||
|
||||
/********************************
|
||||
*
|
||||
*/
|
||||
|
||||
SimWire::SimWire( bool verbose )
|
||||
: verbose_( verbose )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SimWire::setClock(uint32_t)
|
||||
{
|
||||
// Ignore.. lol
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SimWire::begin()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SimWire::beginTransmission(uint8_t address)
|
||||
{
|
||||
if( verbose_ )
|
||||
printf("[SimWire::beginTransmission] $%02x\n", address);
|
||||
}
|
||||
|
||||
|
||||
void SimWire::beginTransmission(int address)
|
||||
{
|
||||
beginTransmission((uint8_t)address);
|
||||
}
|
||||
|
||||
|
||||
uint8_t SimWire::endTransmission()
|
||||
{
|
||||
if( verbose_ )
|
||||
printf("[SimWire::endTransmission]\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t SimWire::endTransmission(uint8_t what)
|
||||
{
|
||||
if( verbose_ )
|
||||
printf("[SimWire::endTransmission %d]\n", what);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t SimWire::requestFrom(uint8_t address, uint8_t count)
|
||||
{
|
||||
if( verbose_ )
|
||||
printf("[SimWire::requestFrom] $%02x for %d bytes\n", address, count);
|
||||
|
||||
// TODO: We must check if there is an actual slave for that address.
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SimWire::read()
|
||||
{
|
||||
// TODO: Verify that bus is in read mode.
|
||||
// if( current_slave_ != NULL ) {
|
||||
// return current_slave_->i2cReadData( );
|
||||
// } else {
|
||||
printf("No slave selected, returning ones\n");
|
||||
return 0xffu;
|
||||
// }
|
||||
}
|
||||
|
||||
int SimWire::available()
|
||||
{
|
||||
// TODO: This needs to be implemented!!
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
size_t SimWire::write(uint8_t __attribute__((unused)) data)
|
||||
{
|
||||
// // TODO: Verify that bus is in write mode.
|
||||
// if( current_slave_ != NULL ) {
|
||||
// current_slave_->i2cWriteData( data );
|
||||
// } else {
|
||||
printf("No slave selected i2c writes to the void.\n");
|
||||
// }
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "Wire.h"
|
||||
|
||||
/********************************
|
||||
*
|
||||
*/
|
||||
|
||||
SimWire::SimWire( bool verbose )
|
||||
: verbose_( verbose )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SimWire::setClock(uint32_t)
|
||||
{
|
||||
// Ignore.. lol
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SimWire::begin()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SimWire::beginTransmission(uint8_t address)
|
||||
{
|
||||
if( verbose_ )
|
||||
printf("[SimWire::beginTransmission] $%02x\n", address);
|
||||
}
|
||||
|
||||
|
||||
void SimWire::beginTransmission(int address)
|
||||
{
|
||||
beginTransmission((uint8_t)address);
|
||||
}
|
||||
|
||||
|
||||
uint8_t SimWire::endTransmission()
|
||||
{
|
||||
if( verbose_ )
|
||||
printf("[SimWire::endTransmission]\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t SimWire::endTransmission(uint8_t what)
|
||||
{
|
||||
if( verbose_ )
|
||||
printf("[SimWire::endTransmission %d]\n", what);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
uint8_t SimWire::requestFrom(uint8_t address, uint8_t count)
|
||||
{
|
||||
if( verbose_ )
|
||||
printf("[SimWire::requestFrom] $%02x for %d bytes\n", address, count);
|
||||
|
||||
// TODO: We must check if there is an actual slave for that address.
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SimWire::read()
|
||||
{
|
||||
// TODO: Verify that bus is in read mode.
|
||||
// if( current_slave_ != NULL ) {
|
||||
// return current_slave_->i2cReadData( );
|
||||
// } else {
|
||||
printf("No slave selected, returning ones\n");
|
||||
return 0xffu;
|
||||
// }
|
||||
}
|
||||
|
||||
int SimWire::available()
|
||||
{
|
||||
// TODO: This needs to be implemented!!
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
size_t SimWire::write(uint8_t __attribute__((unused)) data)
|
||||
{
|
||||
// // TODO: Verify that bus is in write mode.
|
||||
// if( current_slave_ != NULL ) {
|
||||
// current_slave_->i2cWriteData( data );
|
||||
// } else {
|
||||
printf("No slave selected i2c writes to the void.\n");
|
||||
// }
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue