Simple simulation code
Builds a native program on MacOS that runs the NuEVI firmware compiled for x86_64. Only input is arrow keys for menu buttons for now. Only output is console and display. Copied some more library files into the simulation folder, and renamed the modified *.cpp files from the libraries to *_sim.cpp.
This commit is contained in:
parent
c9123b746f
commit
266b3334cb
30 changed files with 8532 additions and 0 deletions
65
simulation/Makefile
Normal file
65
simulation/Makefile
Normal file
|
@ -0,0 +1,65 @@
|
|||
CC=clang
|
||||
CXX=clang++
|
||||
|
||||
CFLAGS= -O0 -g -Wall -Wextra -Wpedantic -Wno-gnu -mmacosx-version-min=10.9 -F/Library/Frameworks
|
||||
CFLAGS += -DARDUINO=10808 -D__MK20DX256__
|
||||
|
||||
CXXFLAGS= $(CFLAGS) -std=c++14
|
||||
|
||||
LIBS=-framework SDL2 -lc++ -lc -framework OpenGL
|
||||
LDFLAGS=-macosx_version_min 10.9
|
||||
|
||||
SYSINC = ~/Documents/Arduino/libraries/Filters ./include
|
||||
INCS = ../NuEVI ./include
|
||||
|
||||
INCDIRS = $(addprefix -isystem ,$(SYSINC))
|
||||
INCDIRS += $(addprefix -I,$(INCS))
|
||||
|
||||
|
||||
TARGET=nuevisim
|
||||
|
||||
CXXFILES= ../NuEVI/menu.cpp \
|
||||
src/nuevisim.cpp \
|
||||
src/simeeprom.cpp \
|
||||
src/Print.cpp \
|
||||
src/simserial.cpp \
|
||||
src/simwire.cpp \
|
||||
src/simmidi.cpp \
|
||||
src/filters.cpp \
|
||||
src/Adafruit_GFX_sim.cpp \
|
||||
src/Adafruit_SSD1306_sim.cpp \
|
||||
src/Adafruit_MPR121_sim.cpp
|
||||
|
||||
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/*
|
232
simulation/include/Adafruit_GFX.h
Normal file
232
simulation/include/Adafruit_GFX.h
Normal file
|
@ -0,0 +1,232 @@
|
|||
#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_;
|
||||
|
||||
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
|
109
simulation/include/Adafruit_MPR121.h
Normal file
109
simulation/include/Adafruit_MPR121.h
Normal file
|
@ -0,0 +1,109 @@
|
|||
/*!
|
||||
* @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);
|
||||
|
||||
private:
|
||||
int8_t _i2caddr;
|
||||
uint8_t _registers[24];
|
||||
};
|
||||
|
||||
#endif // ADAFRUIT_MPR121_H
|
169
simulation/include/Adafruit_SSD1306.h
Normal file
169
simulation/include/Adafruit_SSD1306.h
Normal file
|
@ -0,0 +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_
|
98
simulation/include/Arduino.h
Normal file
98
simulation/include/Arduino.h
Normal file
|
@ -0,0 +1,98 @@
|
|||
#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 "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);
|
||||
};
|
||||
|
||||
extern SimSerial Serial;
|
||||
|
||||
//extern void putString(int row, int col, int color, const char* msg, const FONT_INFO fontInfo);
|
||||
|
||||
uint16_t micros();
|
||||
uint16_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
|
42
simulation/include/EEPROM.h
Normal file
42
simulation/include/EEPROM.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
#ifndef __EEPROM_H
|
||||
#define __EEPROM_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct 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;
|
||||
// }
|
||||
};
|
||||
|
||||
static EEPROMClass EEPROM __attribute__ ((unused));
|
||||
|
||||
|
||||
#endif
|
136
simulation/include/Print.h
Normal file
136
simulation/include/Print.h
Normal file
|
@ -0,0 +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
|
42
simulation/include/Printable.h
Normal file
42
simulation/include/Printable.h
Normal file
|
@ -0,0 +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
|
165
simulation/include/SPI.h
Normal file
165
simulation/include/SPI.h
Normal file
|
@ -0,0 +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
|
227
simulation/include/WString.h
Normal file
227
simulation/include/WString.h
Normal file
|
@ -0,0 +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
|
38
simulation/include/Wire.h
Normal file
38
simulation/include/Wire.h
Normal file
|
@ -0,0 +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
|
197
simulation/include/Wiring.h
Normal file
197
simulation/include/Wiring.h
Normal file
|
@ -0,0 +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
|
517
simulation/include/binary.h
Normal file
517
simulation/include/binary.h
Normal file
|
@ -0,0 +1,517 @@
|
|||
// This header file is in the public domain.
|
||||
|
||||
#ifndef Binary_h
|
||||
#define Binary_h
|
||||
|
||||
#define B0 0
|
||||
#define B00 0
|
||||
#define B000 0
|
||||
#define B0000 0
|
||||
#define B00000 0
|
||||
#define B000000 0
|
||||
#define B0000000 0
|
||||
#define B00000000 0
|
||||
#define B1 1
|
||||
#define B01 1
|
||||
#define B001 1
|
||||
#define B0001 1
|
||||
#define B00001 1
|
||||
#define B000001 1
|
||||
#define B0000001 1
|
||||
#define B00000001 1
|
||||
#define B10 2
|
||||
#define B010 2
|
||||
#define B0010 2
|
||||
#define B00010 2
|
||||
#define B000010 2
|
||||
#define B0000010 2
|
||||
#define B00000010 2
|
||||
#define B11 3
|
||||
#define B011 3
|
||||
#define B0011 3
|
||||
#define B00011 3
|
||||
#define B000011 3
|
||||
#define B0000011 3
|
||||
#define B00000011 3
|
||||
#define B100 4
|
||||
#define B0100 4
|
||||
#define B00100 4
|
||||
#define B000100 4
|
||||
#define B0000100 4
|
||||
#define B00000100 4
|
||||
#define B101 5
|
||||
#define B0101 5
|
||||
#define B00101 5
|
||||
#define B000101 5
|
||||
#define B0000101 5
|
||||
#define B00000101 5
|
||||
#define B110 6
|
||||
#define B0110 6
|
||||
#define B00110 6
|
||||
#define B000110 6
|
||||
#define B0000110 6
|
||||
#define B00000110 6
|
||||
#define B111 7
|
||||
#define B0111 7
|
||||
#define B00111 7
|
||||
#define B000111 7
|
||||
#define B0000111 7
|
||||
#define B00000111 7
|
||||
#define B1000 8
|
||||
#define B01000 8
|
||||
#define B001000 8
|
||||
#define B0001000 8
|
||||
#define B00001000 8
|
||||
#define B1001 9
|
||||
#define B01001 9
|
||||
#define B001001 9
|
||||
#define B0001001 9
|
||||
#define B00001001 9
|
||||
#define B1010 10
|
||||
#define B01010 10
|
||||
#define B001010 10
|
||||
#define B0001010 10
|
||||
#define B00001010 10
|
||||
#define B1011 11
|
||||
#define B01011 11
|
||||
#define B001011 11
|
||||
#define B0001011 11
|
||||
#define B00001011 11
|
||||
#define B1100 12
|
||||
#define B01100 12
|
||||
#define B001100 12
|
||||
#define B0001100 12
|
||||
#define B00001100 12
|
||||
#define B1101 13
|
||||
#define B01101 13
|
||||
#define B001101 13
|
||||
#define B0001101 13
|
||||
#define B00001101 13
|
||||
#define B1110 14
|
||||
#define B01110 14
|
||||
#define B001110 14
|
||||
#define B0001110 14
|
||||
#define B00001110 14
|
||||
#define B1111 15
|
||||
#define B01111 15
|
||||
#define B001111 15
|
||||
#define B0001111 15
|
||||
#define B00001111 15
|
||||
#define B10000 16
|
||||
#define B010000 16
|
||||
#define B0010000 16
|
||||
#define B00010000 16
|
||||
#define B10001 17
|
||||
#define B010001 17
|
||||
#define B0010001 17
|
||||
#define B00010001 17
|
||||
#define B10010 18
|
||||
#define B010010 18
|
||||
#define B0010010 18
|
||||
#define B00010010 18
|
||||
#define B10011 19
|
||||
#define B010011 19
|
||||
#define B0010011 19
|
||||
#define B00010011 19
|
||||
#define B10100 20
|
||||
#define B010100 20
|
||||
#define B0010100 20
|
||||
#define B00010100 20
|
||||
#define B10101 21
|
||||
#define B010101 21
|
||||
#define B0010101 21
|
||||
#define B00010101 21
|
||||
#define B10110 22
|
||||
#define B010110 22
|
||||
#define B0010110 22
|
||||
#define B00010110 22
|
||||
#define B10111 23
|
||||
#define B010111 23
|
||||
#define B0010111 23
|
||||
#define B00010111 23
|
||||
#define B11000 24
|
||||
#define B011000 24
|
||||
#define B0011000 24
|
||||
#define B00011000 24
|
||||
#define B11001 25
|
||||
#define B011001 25
|
||||
#define B0011001 25
|
||||
#define B00011001 25
|
||||
#define B11010 26
|
||||
#define B011010 26
|
||||
#define B0011010 26
|
||||
#define B00011010 26
|
||||
#define B11011 27
|
||||
#define B011011 27
|
||||
#define B0011011 27
|
||||
#define B00011011 27
|
||||
#define B11100 28
|
||||
#define B011100 28
|
||||
#define B0011100 28
|
||||
#define B00011100 28
|
||||
#define B11101 29
|
||||
#define B011101 29
|
||||
#define B0011101 29
|
||||
#define B00011101 29
|
||||
#define B11110 30
|
||||
#define B011110 30
|
||||
#define B0011110 30
|
||||
#define B00011110 30
|
||||
#define B11111 31
|
||||
#define B011111 31
|
||||
#define B0011111 31
|
||||
#define B00011111 31
|
||||
#define B100000 32
|
||||
#define B0100000 32
|
||||
#define B00100000 32
|
||||
#define B100001 33
|
||||
#define B0100001 33
|
||||
#define B00100001 33
|
||||
#define B100010 34
|
||||
#define B0100010 34
|
||||
#define B00100010 34
|
||||
#define B100011 35
|
||||
#define B0100011 35
|
||||
#define B00100011 35
|
||||
#define B100100 36
|
||||
#define B0100100 36
|
||||
#define B00100100 36
|
||||
#define B100101 37
|
||||
#define B0100101 37
|
||||
#define B00100101 37
|
||||
#define B100110 38
|
||||
#define B0100110 38
|
||||
#define B00100110 38
|
||||
#define B100111 39
|
||||
#define B0100111 39
|
||||
#define B00100111 39
|
||||
#define B101000 40
|
||||
#define B0101000 40
|
||||
#define B00101000 40
|
||||
#define B101001 41
|
||||
#define B0101001 41
|
||||
#define B00101001 41
|
||||
#define B101010 42
|
||||
#define B0101010 42
|
||||
#define B00101010 42
|
||||
#define B101011 43
|
||||
#define B0101011 43
|
||||
#define B00101011 43
|
||||
#define B101100 44
|
||||
#define B0101100 44
|
||||
#define B00101100 44
|
||||
#define B101101 45
|
||||
#define B0101101 45
|
||||
#define B00101101 45
|
||||
#define B101110 46
|
||||
#define B0101110 46
|
||||
#define B00101110 46
|
||||
#define B101111 47
|
||||
#define B0101111 47
|
||||
#define B00101111 47
|
||||
#define B110000 48
|
||||
#define B0110000 48
|
||||
#define B00110000 48
|
||||
#define B110001 49
|
||||
#define B0110001 49
|
||||
#define B00110001 49
|
||||
#define B110010 50
|
||||
#define B0110010 50
|
||||
#define B00110010 50
|
||||
#define B110011 51
|
||||
#define B0110011 51
|
||||
#define B00110011 51
|
||||
#define B110100 52
|
||||
#define B0110100 52
|
||||
#define B00110100 52
|
||||
#define B110101 53
|
||||
#define B0110101 53
|
||||
#define B00110101 53
|
||||
#define B110110 54
|
||||
#define B0110110 54
|
||||
#define B00110110 54
|
||||
#define B110111 55
|
||||
#define B0110111 55
|
||||
#define B00110111 55
|
||||
#define B111000 56
|
||||
#define B0111000 56
|
||||
#define B00111000 56
|
||||
#define B111001 57
|
||||
#define B0111001 57
|
||||
#define B00111001 57
|
||||
#define B111010 58
|
||||
#define B0111010 58
|
||||
#define B00111010 58
|
||||
#define B111011 59
|
||||
#define B0111011 59
|
||||
#define B00111011 59
|
||||
#define B111100 60
|
||||
#define B0111100 60
|
||||
#define B00111100 60
|
||||
#define B111101 61
|
||||
#define B0111101 61
|
||||
#define B00111101 61
|
||||
#define B111110 62
|
||||
#define B0111110 62
|
||||
#define B00111110 62
|
||||
#define B111111 63
|
||||
#define B0111111 63
|
||||
#define B00111111 63
|
||||
#define B1000000 64
|
||||
#define B01000000 64
|
||||
#define B1000001 65
|
||||
#define B01000001 65
|
||||
#define B1000010 66
|
||||
#define B01000010 66
|
||||
#define B1000011 67
|
||||
#define B01000011 67
|
||||
#define B1000100 68
|
||||
#define B01000100 68
|
||||
#define B1000101 69
|
||||
#define B01000101 69
|
||||
#define B1000110 70
|
||||
#define B01000110 70
|
||||
#define B1000111 71
|
||||
#define B01000111 71
|
||||
#define B1001000 72
|
||||
#define B01001000 72
|
||||
#define B1001001 73
|
||||
#define B01001001 73
|
||||
#define B1001010 74
|
||||
#define B01001010 74
|
||||
#define B1001011 75
|
||||
#define B01001011 75
|
||||
#define B1001100 76
|
||||
#define B01001100 76
|
||||
#define B1001101 77
|
||||
#define B01001101 77
|
||||
#define B1001110 78
|
||||
#define B01001110 78
|
||||
#define B1001111 79
|
||||
#define B01001111 79
|
||||
#define B1010000 80
|
||||
#define B01010000 80
|
||||
#define B1010001 81
|
||||
#define B01010001 81
|
||||
#define B1010010 82
|
||||
#define B01010010 82
|
||||
#define B1010011 83
|
||||
#define B01010011 83
|
||||
#define B1010100 84
|
||||
#define B01010100 84
|
||||
#define B1010101 85
|
||||
#define B01010101 85
|
||||
#define B1010110 86
|
||||
#define B01010110 86
|
||||
#define B1010111 87
|
||||
#define B01010111 87
|
||||
#define B1011000 88
|
||||
#define B01011000 88
|
||||
#define B1011001 89
|
||||
#define B01011001 89
|
||||
#define B1011010 90
|
||||
#define B01011010 90
|
||||
#define B1011011 91
|
||||
#define B01011011 91
|
||||
#define B1011100 92
|
||||
#define B01011100 92
|
||||
#define B1011101 93
|
||||
#define B01011101 93
|
||||
#define B1011110 94
|
||||
#define B01011110 94
|
||||
#define B1011111 95
|
||||
#define B01011111 95
|
||||
#define B1100000 96
|
||||
#define B01100000 96
|
||||
#define B1100001 97
|
||||
#define B01100001 97
|
||||
#define B1100010 98
|
||||
#define B01100010 98
|
||||
#define B1100011 99
|
||||
#define B01100011 99
|
||||
#define B1100100 100
|
||||
#define B01100100 100
|
||||
#define B1100101 101
|
||||
#define B01100101 101
|
||||
#define B1100110 102
|
||||
#define B01100110 102
|
||||
#define B1100111 103
|
||||
#define B01100111 103
|
||||
#define B1101000 104
|
||||
#define B01101000 104
|
||||
#define B1101001 105
|
||||
#define B01101001 105
|
||||
#define B1101010 106
|
||||
#define B01101010 106
|
||||
#define B1101011 107
|
||||
#define B01101011 107
|
||||
#define B1101100 108
|
||||
#define B01101100 108
|
||||
#define B1101101 109
|
||||
#define B01101101 109
|
||||
#define B1101110 110
|
||||
#define B01101110 110
|
||||
#define B1101111 111
|
||||
#define B01101111 111
|
||||
#define B1110000 112
|
||||
#define B01110000 112
|
||||
#define B1110001 113
|
||||
#define B01110001 113
|
||||
#define B1110010 114
|
||||
#define B01110010 114
|
||||
#define B1110011 115
|
||||
#define B01110011 115
|
||||
#define B1110100 116
|
||||
#define B01110100 116
|
||||
#define B1110101 117
|
||||
#define B01110101 117
|
||||
#define B1110110 118
|
||||
#define B01110110 118
|
||||
#define B1110111 119
|
||||
#define B01110111 119
|
||||
#define B1111000 120
|
||||
#define B01111000 120
|
||||
#define B1111001 121
|
||||
#define B01111001 121
|
||||
#define B1111010 122
|
||||
#define B01111010 122
|
||||
#define B1111011 123
|
||||
#define B01111011 123
|
||||
#define B1111100 124
|
||||
#define B01111100 124
|
||||
#define B1111101 125
|
||||
#define B01111101 125
|
||||
#define B1111110 126
|
||||
#define B01111110 126
|
||||
#define B1111111 127
|
||||
#define B01111111 127
|
||||
#define B10000000 128
|
||||
#define B10000001 129
|
||||
#define B10000010 130
|
||||
#define B10000011 131
|
||||
#define B10000100 132
|
||||
#define B10000101 133
|
||||
#define B10000110 134
|
||||
#define B10000111 135
|
||||
#define B10001000 136
|
||||
#define B10001001 137
|
||||
#define B10001010 138
|
||||
#define B10001011 139
|
||||
#define B10001100 140
|
||||
#define B10001101 141
|
||||
#define B10001110 142
|
||||
#define B10001111 143
|
||||
#define B10010000 144
|
||||
#define B10010001 145
|
||||
#define B10010010 146
|
||||
#define B10010011 147
|
||||
#define B10010100 148
|
||||
#define B10010101 149
|
||||
#define B10010110 150
|
||||
#define B10010111 151
|
||||
#define B10011000 152
|
||||
#define B10011001 153
|
||||
#define B10011010 154
|
||||
#define B10011011 155
|
||||
#define B10011100 156
|
||||
#define B10011101 157
|
||||
#define B10011110 158
|
||||
#define B10011111 159
|
||||
#define B10100000 160
|
||||
#define B10100001 161
|
||||
#define B10100010 162
|
||||
#define B10100011 163
|
||||
#define B10100100 164
|
||||
#define B10100101 165
|
||||
#define B10100110 166
|
||||
#define B10100111 167
|
||||
#define B10101000 168
|
||||
#define B10101001 169
|
||||
#define B10101010 170
|
||||
#define B10101011 171
|
||||
#define B10101100 172
|
||||
#define B10101101 173
|
||||
#define B10101110 174
|
||||
#define B10101111 175
|
||||
#define B10110000 176
|
||||
#define B10110001 177
|
||||
#define B10110010 178
|
||||
#define B10110011 179
|
||||
#define B10110100 180
|
||||
#define B10110101 181
|
||||
#define B10110110 182
|
||||
#define B10110111 183
|
||||
#define B10111000 184
|
||||
#define B10111001 185
|
||||
#define B10111010 186
|
||||
#define B10111011 187
|
||||
#define B10111100 188
|
||||
#define B10111101 189
|
||||
#define B10111110 190
|
||||
#define B10111111 191
|
||||
#define B11000000 192
|
||||
#define B11000001 193
|
||||
#define B11000010 194
|
||||
#define B11000011 195
|
||||
#define B11000100 196
|
||||
#define B11000101 197
|
||||
#define B11000110 198
|
||||
#define B11000111 199
|
||||
#define B11001000 200
|
||||
#define B11001001 201
|
||||
#define B11001010 202
|
||||
#define B11001011 203
|
||||
#define B11001100 204
|
||||
#define B11001101 205
|
||||
#define B11001110 206
|
||||
#define B11001111 207
|
||||
#define B11010000 208
|
||||
#define B11010001 209
|
||||
#define B11010010 210
|
||||
#define B11010011 211
|
||||
#define B11010100 212
|
||||
#define B11010101 213
|
||||
#define B11010110 214
|
||||
#define B11010111 215
|
||||
#define B11011000 216
|
||||
#define B11011001 217
|
||||
#define B11011010 218
|
||||
#define B11011011 219
|
||||
#define B11011100 220
|
||||
#define B11011101 221
|
||||
#define B11011110 222
|
||||
#define B11011111 223
|
||||
#define B11100000 224
|
||||
#define B11100001 225
|
||||
#define B11100010 226
|
||||
#define B11100011 227
|
||||
#define B11100100 228
|
||||
#define B11100101 229
|
||||
#define B11100110 230
|
||||
#define B11100111 231
|
||||
#define B11101000 232
|
||||
#define B11101001 233
|
||||
#define B11101010 234
|
||||
#define B11101011 235
|
||||
#define B11101100 236
|
||||
#define B11101101 237
|
||||
#define B11101110 238
|
||||
#define B11101111 239
|
||||
#define B11110000 240
|
||||
#define B11110001 241
|
||||
#define B11110010 242
|
||||
#define B11110011 243
|
||||
#define B11110100 244
|
||||
#define B11110101 245
|
||||
#define B11110110 246
|
||||
#define B11110111 247
|
||||
#define B11111000 248
|
||||
#define B11111001 249
|
||||
#define B11111010 250
|
||||
#define B11111011 251
|
||||
#define B11111100 252
|
||||
#define B11111101 253
|
||||
#define B11111110 254
|
||||
#define B11111111 255
|
||||
|
||||
#endif
|
5
simulation/include/core_id.h
Normal file
5
simulation/include/core_id.h
Normal file
|
@ -0,0 +1,5 @@
|
|||
// This header file is in the public domain.
|
||||
|
||||
#ifndef CORE_TEENSY
|
||||
#define CORE_TEENSY
|
||||
#endif
|
2115
simulation/include/core_pins.h
Normal file
2115
simulation/include/core_pins.h
Normal file
File diff suppressed because it is too large
Load diff
29
simulation/include/gfxfont.h
Normal file
29
simulation/include/gfxfont.h
Normal file
|
@ -0,0 +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_
|
283
simulation/include/pins_arduino.h
Normal file
283
simulation/include/pins_arduino.h
Normal file
|
@ -0,0 +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
|
0
simulation/include/wiring_private.h
Normal file
0
simulation/include/wiring_private.h
Normal file
19
simulation/readme.md
Normal file
19
simulation/readme.md
Normal file
|
@ -0,0 +1,19 @@
|
|||
## 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 must be installed on your machine.
|
||||
* You probably need to have XCode and XCodes command line tools installed as well.
|
||||
|
||||
|
||||
### Know limitations
|
||||
|
||||
Currently the only input simulated are the menu buttons (use the arrow keys). This means that all menu functions cannot be tested, since the rotator menu cannot be opened. There is also a limitation on some keyboard on how many buttons can be pressed at the same time.
|
||||
|
||||
|
||||
### Future plans
|
||||
|
||||
* Add a Dear ImGUI based UI for simulating all other inputs.
|
1982
simulation/src/Adafruit_GFX_sim.cpp
Normal file
1982
simulation/src/Adafruit_GFX_sim.cpp
Normal file
File diff suppressed because it is too large
Load diff
215
simulation/src/Adafruit_MPR121_sim.cpp
Normal file
215
simulation/src/Adafruit_MPR121_sim.cpp
Normal file
|
@ -0,0 +1,215 @@
|
|||
/*!
|
||||
* @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;
|
||||
|
||||
|
||||
// writeRegister(MPR121_ECR, 0x0);
|
||||
|
||||
// uint8_t c = readRegister8(MPR121_CONFIG2);
|
||||
|
||||
// if (c != 0x24) return false;
|
||||
|
||||
|
||||
// setThreshholds(12, 6);
|
||||
// writeRegister(MPR121_MHDR, 0x01);
|
||||
// writeRegister(MPR121_NHDR, 0x01);
|
||||
// writeRegister(MPR121_NCLR, 0x0E);
|
||||
// writeRegister(MPR121_FDLR, 0x00);
|
||||
|
||||
// writeRegister(MPR121_MHDF, 0x01);
|
||||
// writeRegister(MPR121_NHDF, 0x05);
|
||||
// writeRegister(MPR121_NCLF, 0x01);
|
||||
// writeRegister(MPR121_FDLF, 0x00);
|
||||
|
||||
// writeRegister(MPR121_NHDT, 0x00);
|
||||
// writeRegister(MPR121_NCLT, 0x00);
|
||||
// writeRegister(MPR121_FDLT, 0x00);
|
||||
|
||||
// writeRegister(MPR121_DEBOUNCE, 0);
|
||||
// writeRegister(MPR121_CONFIG1, 0x10); // default, 16uA charge current
|
||||
// writeRegister(MPR121_CONFIG2, 0x20); // 0.5uS encoding, 1ms period
|
||||
|
||||
// // writeRegister(MPR121_AUTOCONFIG0, 0x8F);
|
||||
|
||||
// // writeRegister(MPR121_UPLIMIT, 150);
|
||||
// // writeRegister(MPR121_TARGETLIMIT, 100); // should be ~400 (100 shifted)
|
||||
// // writeRegister(MPR121_LOWLIMIT, 50);
|
||||
// // enable all electrodes
|
||||
// writeRegister(MPR121_ECR, 0x8F); // start with first 5 bits of baseline tracking
|
||||
|
||||
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];
|
||||
// Wire.beginTransmission(_i2caddr);
|
||||
// Wire.write(reg);
|
||||
// Wire.endTransmission(false);
|
||||
// Wire.requestFrom(_i2caddr, 1);
|
||||
// if (Wire.available() < 1)
|
||||
// return 0;
|
||||
// return (Wire.read());
|
||||
}
|
||||
|
||||
/**
|
||||
*****************************************************************************************
|
||||
* @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);
|
||||
// Wire.beginTransmission(_i2caddr);
|
||||
// Wire.write(reg);
|
||||
// Wire.endTransmission(false);
|
||||
// Wire.requestFrom(_i2caddr, 2);
|
||||
// if (Wire.available() < 2)
|
||||
// return 0;
|
||||
// uint16_t v = Wire.read();
|
||||
// v |= ((uint16_t) Wire.read()) << 8;
|
||||
// return v;
|
||||
}
|
||||
|
||||
/**************************************************************************/
|
||||
/*!
|
||||
@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;
|
||||
// Wire.beginTransmission(_i2caddr);
|
||||
// Wire.write((uint8_t)reg);
|
||||
// Wire.write((uint8_t)(value));
|
||||
// Wire.endTransmission();
|
||||
}
|
730
simulation/src/Adafruit_SSD1306_sim.cpp
Normal file
730
simulation/src/Adafruit_SSD1306_sim.cpp
Normal file
|
@ -0,0 +1,730 @@
|
|||
/*!
|
||||
* @file Adafruit_SSD1306.cpp
|
||||
*
|
||||
* @mainpage Arduino library for monochrome OLEDs based on SSD1306 drivers.
|
||||
*
|
||||
* @section intro_sec Introduction
|
||||
*
|
||||
* This is documentation 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!
|
||||
*
|
||||
* @section dependencies Dependencies
|
||||
*
|
||||
* This library depends on <a href="https://github.com/adafruit/Adafruit-GFX-Library">
|
||||
* Adafruit_GFX</a> being present on your system. Please make sure you have
|
||||
* installed the latest version before using this library.
|
||||
*
|
||||
* @section author Author
|
||||
*
|
||||
* Written by Limor Fried/Ladyada for Adafruit Industries, with
|
||||
* contributions from the open source community.
|
||||
*
|
||||
* @section license License
|
||||
*
|
||||
* BSD license, all text above, and the splash screen included below,
|
||||
* must be included in any redistribution.
|
||||
*
|
||||
*/
|
||||
|
||||
// #ifdef __AVR__
|
||||
// #include <avr/pgmspace.h>
|
||||
// #elif defined(ESP8266) || defined(ESP32)
|
||||
// #include <pgmspace.h>
|
||||
// #else
|
||||
#define pgm_read_byte(addr) \
|
||||
(*(const unsigned char *)(addr)) ///< PROGMEM workaround for non-AVR
|
||||
// #endif
|
||||
|
||||
// #if !defined(__ARM_ARCH) && !defined(ENERGIA) && !defined(ESP8266) && !defined(ESP32) && !defined(__arc__)
|
||||
// #include <util/delay.h>
|
||||
// #endif
|
||||
|
||||
#include <Adafruit_GFX.h>
|
||||
#include "Adafruit_SSD1306.h"
|
||||
|
||||
// SOME DEFINES AND STATIC VARIABLES USED INTERNALLY -----------------------
|
||||
|
||||
// #if defined(BUFFER_LENGTH)
|
||||
// #define WIRE_MAX BUFFER_LENGTH ///< AVR or similar Wire lib
|
||||
// #elif defined(SERIAL_BUFFER_SIZE)
|
||||
// #define WIRE_MAX (SERIAL_BUFFER_SIZE-1) ///< Newer Wire uses RingBuffer
|
||||
// #else
|
||||
// #define WIRE_MAX 32 ///< Use common Arduino core default
|
||||
// #endif
|
||||
|
||||
#define ssd1306_swap(a, b) \
|
||||
(((a) ^= (b)), ((b) ^= (a)), ((a) ^= (b))) ///< No-temp-var swap operation
|
||||
|
||||
// #if ARDUINO >= 100
|
||||
// #define WIRE_WRITE wire->write ///< Wire write function in recent Arduino lib
|
||||
// #else
|
||||
// #define WIRE_WRITE wire->send ///< Wire write function in older Arduino lib
|
||||
// #endif
|
||||
|
||||
// #ifdef HAVE_PORTREG
|
||||
// #define SSD1306_SELECT *csPort &= ~csPinMask; ///< Device select
|
||||
// #define SSD1306_DESELECT *csPort |= csPinMask; ///< Device deselect
|
||||
// #define SSD1306_MODE_COMMAND *dcPort &= ~dcPinMask; ///< Command mode
|
||||
// #define SSD1306_MODE_DATA *dcPort |= dcPinMask; ///< Data mode
|
||||
// #else
|
||||
// #define SSD1306_SELECT digitalWrite(csPin, LOW); ///< Device select
|
||||
// #define SSD1306_DESELECT digitalWrite(csPin, HIGH); ///< Device deselect
|
||||
// #define SSD1306_MODE_COMMAND digitalWrite(dcPin, LOW); ///< Command mode
|
||||
// #define SSD1306_MODE_DATA digitalWrite(dcPin, HIGH); ///< Data mode
|
||||
// #endif
|
||||
|
||||
// #if (ARDUINO >= 157) && !defined(ARDUINO_STM32_FEATHER)
|
||||
// #define SETWIRECLOCK wire->setClock(wireClk) ///< Set before I2C transfer
|
||||
// #define RESWIRECLOCK wire->setClock(restoreClk) ///< Restore after I2C xfer
|
||||
// #else // setClock() is not present in older Arduino Wire lib (or WICED)
|
||||
// #define SETWIRECLOCK ///< Dummy stand-in define
|
||||
// #define RESWIRECLOCK ///< keeps compiler happy
|
||||
// #endif
|
||||
|
||||
// #if defined(SPI_HAS_TRANSACTION)
|
||||
// #define SPI_TRANSACTION_START spi->beginTransaction(spiSettings) ///< Pre-SPI
|
||||
// #define SPI_TRANSACTION_END spi->endTransaction() ///< Post-SPI
|
||||
// #else // SPI transactions likewise not present in older Arduino SPI lib
|
||||
// #define SPI_TRANSACTION_START ///< Dummy stand-in define
|
||||
// #define SPI_TRANSACTION_END ///< keeps compiler happy
|
||||
// #endif
|
||||
|
||||
// The definition of 'transaction' is broadened a bit in the context of
|
||||
// this library -- referring not just to SPI transactions (if supported
|
||||
// in the version of the SPI library being used), but also chip select
|
||||
// (if SPI is being used, whether hardware or soft), and also to the
|
||||
// beginning and end of I2C transfers (the Wire clock may be sped up before
|
||||
// issuing data to the display, then restored to the default rate afterward
|
||||
// so other I2C device types still work). All of these are encapsulated
|
||||
// in the TRANSACTION_* macros.
|
||||
|
||||
// Check first if Wire, then hardware SPI, then soft SPI:
|
||||
// #define TRANSACTION_START \
|
||||
// if(wire) { \
|
||||
// SETWIRECLOCK; \
|
||||
// } else { \
|
||||
// if(spi) { \
|
||||
// SPI_TRANSACTION_START; \
|
||||
// } \
|
||||
// SSD1306_SELECT; \
|
||||
// } ///< Wire, SPI or bitbang transfer setup
|
||||
// #define TRANSACTION_END \
|
||||
// if(wire) { \
|
||||
// RESWIRECLOCK; \
|
||||
// } else { \
|
||||
// SSD1306_DESELECT; \
|
||||
// if(spi) { \
|
||||
// SPI_TRANSACTION_END; \
|
||||
// } \
|
||||
// } ///< Wire, SPI or bitbang transfer end
|
||||
|
||||
// CONSTRUCTORS, DESTRUCTOR ------------------------------------------------
|
||||
|
||||
/*!
|
||||
@brief Constructor for I2C-interfaced SSD1306 displays.
|
||||
@param w
|
||||
Display width in pixels
|
||||
@param h
|
||||
Display height in pixels
|
||||
@param twi
|
||||
Pointer to an existing TwoWire instance (e.g. &Wire, the
|
||||
microcontroller's primary I2C bus).
|
||||
@param rst_pin
|
||||
Reset pin (using Arduino pin numbering), or -1 if not used
|
||||
(some displays might be wired to share the microcontroller's
|
||||
reset pin).
|
||||
@param clkDuring
|
||||
Speed (in Hz) for Wire transmissions in SSD1306 library calls.
|
||||
Defaults to 400000 (400 KHz), a known 'safe' value for most
|
||||
microcontrollers, and meets the SSD1306 datasheet spec.
|
||||
Some systems can operate I2C faster (800 KHz for ESP32, 1 MHz
|
||||
for many other 32-bit MCUs), and some (perhaps not all)
|
||||
SSD1306's can work with this -- so it's optionally be specified
|
||||
here and is not a default behavior. (Ignored if using pre-1.5.7
|
||||
Arduino software, which operates I2C at a fixed 100 KHz.)
|
||||
@param clkAfter
|
||||
Speed (in Hz) for Wire transmissions following SSD1306 library
|
||||
calls. Defaults to 100000 (100 KHz), the default Arduino Wire
|
||||
speed. This is done rather than leaving it at the 'during' speed
|
||||
because other devices on the I2C bus might not be compatible
|
||||
with the faster rate. (Ignored if using pre-1.5.7 Arduino
|
||||
software, which operates I2C at a fixed 100 KHz.)
|
||||
@return Adafruit_SSD1306 object.
|
||||
@note Call the object's begin() function before use -- buffer
|
||||
allocation is performed there!
|
||||
*/
|
||||
Adafruit_SSD1306::Adafruit_SSD1306(uint8_t w, uint8_t h, TwoWire *twi,
|
||||
int8_t rst_pin, uint32_t clkDuring, uint32_t clkAfter) :
|
||||
Adafruit_GFX(w, h), spi(NULL), wire(twi), buffer(NULL),
|
||||
mosiPin(-1), clkPin(-1), dcPin(-1), csPin(-1), rstPin(rst_pin),
|
||||
wireClk(clkDuring), restoreClk(clkAfter)
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Constructor for SPI SSD1306 displays, using software (bitbang)
|
||||
SPI.
|
||||
@param w
|
||||
Display width in pixels
|
||||
@param h
|
||||
Display height in pixels
|
||||
@param mosi_pin
|
||||
MOSI (master out, slave in) pin (using Arduino pin numbering).
|
||||
This transfers serial data from microcontroller to display.
|
||||
@param sclk_pin
|
||||
SCLK (serial clock) pin (using Arduino pin numbering).
|
||||
This clocks each bit from MOSI.
|
||||
@param dc_pin
|
||||
Data/command pin (using Arduino pin numbering), selects whether
|
||||
display is receiving commands (low) or data (high).
|
||||
@param rst_pin
|
||||
Reset pin (using Arduino pin numbering), or -1 if not used
|
||||
(some displays might be wired to share the microcontroller's
|
||||
reset pin).
|
||||
@param cs_pin
|
||||
Chip-select pin (using Arduino pin numbering) for sharing the
|
||||
bus with other devices. Active low.
|
||||
@return Adafruit_SSD1306 object.
|
||||
@note Call the object's begin() function before use -- buffer
|
||||
allocation is performed there!
|
||||
*/
|
||||
Adafruit_SSD1306::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_GFX(w, h), spi(NULL), wire(NULL), buffer(NULL),
|
||||
mosiPin(mosi_pin), clkPin(sclk_pin), dcPin(dc_pin), csPin(cs_pin),
|
||||
rstPin(rst_pin) {
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Constructor for SPI SSD1306 displays, using native hardware SPI.
|
||||
@param w
|
||||
Display width in pixels
|
||||
@param h
|
||||
Display height in pixels
|
||||
@param spi
|
||||
Pointer to an existing SPIClass instance (e.g. &SPI, the
|
||||
microcontroller's primary SPI bus).
|
||||
@param dc_pin
|
||||
Data/command pin (using Arduino pin numbering), selects whether
|
||||
display is receiving commands (low) or data (high).
|
||||
@param rst_pin
|
||||
Reset pin (using Arduino pin numbering), or -1 if not used
|
||||
(some displays might be wired to share the microcontroller's
|
||||
reset pin).
|
||||
@param cs_pin
|
||||
Chip-select pin (using Arduino pin numbering) for sharing the
|
||||
bus with other devices. Active low.
|
||||
@param bitrate
|
||||
SPI clock rate for transfers to this display. Default if
|
||||
unspecified is 8000000UL (8 MHz).
|
||||
@return Adafruit_SSD1306 object.
|
||||
@note Call the object's begin() function before use -- buffer
|
||||
allocation is performed there!
|
||||
*/
|
||||
Adafruit_SSD1306::Adafruit_SSD1306(uint8_t w, uint8_t h, SPIClass *spi,
|
||||
int8_t dc_pin, int8_t rst_pin, int8_t cs_pin, uint32_t __attribute__((unused)) bitrate) :
|
||||
Adafruit_GFX(w, h), spi(spi), wire(NULL), buffer(NULL),
|
||||
mosiPin(-1), clkPin(-1), dcPin(dc_pin), csPin(cs_pin), rstPin(rst_pin) {
|
||||
#ifdef SPI_HAS_TRANSACTION
|
||||
spiSettings = SPISettings(bitrate, MSBFIRST, SPI_MODE0);
|
||||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Destructor for Adafruit_SSD1306 object.
|
||||
*/
|
||||
Adafruit_SSD1306::~Adafruit_SSD1306(void) {
|
||||
if(buffer) {
|
||||
free(buffer);
|
||||
buffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
// LOW-LEVEL UTILS ---------------------------------------------------------
|
||||
|
||||
// ALLOCATE & INIT DISPLAY -------------------------------------------------
|
||||
|
||||
/*!
|
||||
@brief Allocate RAM for image buffer, initialize peripherals and pins.
|
||||
@param vcs
|
||||
VCC selection. Pass SSD1306_SWITCHCAPVCC to generate the display
|
||||
voltage (step up) from the 3.3V source, or SSD1306_EXTERNALVCC
|
||||
otherwise. Most situations with Adafruit SSD1306 breakouts will
|
||||
want SSD1306_SWITCHCAPVCC.
|
||||
@param addr
|
||||
I2C address of corresponding SSD1306 display (or pass 0 to use
|
||||
default of 0x3C for 128x32 display, 0x3D for all others).
|
||||
SPI displays (hardware or software) do not use addresses, but
|
||||
this argument is still required (pass 0 or any value really,
|
||||
it will simply be ignored). Default if unspecified is 0.
|
||||
@param reset
|
||||
If true, and if the reset pin passed to the constructor is
|
||||
valid, a hard reset will be performed before initializing the
|
||||
display. If using multiple SSD1306 displays on the same bus, and
|
||||
if they all share the same reset pin, you should only pass true
|
||||
on the first display being initialized, false on all others,
|
||||
else the already-initialized displays would be reset. Default if
|
||||
unspecified is true.
|
||||
@param periphBegin
|
||||
If true, and if a hardware peripheral is being used (I2C or SPI,
|
||||
but not software SPI), call that peripheral's begin() function,
|
||||
else (false) it has already been done in one's sketch code.
|
||||
Cases where false might be used include multiple displays or
|
||||
other devices sharing a common bus, or situations on some
|
||||
platforms where a nonstandard begin() function is available
|
||||
(e.g. a TwoWire interface on non-default pins, as can be done
|
||||
on the ESP8266 and perhaps others).
|
||||
@return true on successful allocation/init, false otherwise.
|
||||
Well-behaved code should check the return value before
|
||||
proceeding.
|
||||
@note MUST call this function before any drawing or updates!
|
||||
*/
|
||||
boolean Adafruit_SSD1306::begin(uint8_t __attribute__((unused)) vcs, uint8_t __attribute__((unused)) addr, boolean __attribute__((unused)) reset,
|
||||
boolean __attribute__((unused)) periphBegin) {
|
||||
|
||||
if((!buffer) && !(buffer = (uint8_t *)malloc(WIDTH * ((HEIGHT + 7) / 8))))
|
||||
return false;
|
||||
|
||||
enabled_ = true;
|
||||
|
||||
clearDisplay();
|
||||
// if(HEIGHT > 32) {
|
||||
// drawBitmap((WIDTH - splash1_width) / 2, (HEIGHT - splash1_height) / 2,
|
||||
// splash1_data, splash1_width, splash1_height, 1);
|
||||
// } else {
|
||||
// drawBitmap((WIDTH - splash2_width) / 2, (HEIGHT - splash2_height) / 2,
|
||||
// splash2_data, splash2_width, splash2_height, 1);
|
||||
// }
|
||||
|
||||
return true; // Success
|
||||
}
|
||||
|
||||
// DRAWING FUNCTIONS -------------------------------------------------------
|
||||
|
||||
/*!
|
||||
@brief Set/clear/invert a single pixel. This is also invoked by the
|
||||
Adafruit_GFX library in generating many higher-level graphics
|
||||
primitives.
|
||||
@param x
|
||||
Column of display -- 0 at left to (screen width - 1) at right.
|
||||
@param y
|
||||
Row of display -- 0 at top to (screen height -1) at bottom.
|
||||
@param color
|
||||
Pixel color, one of: BLACK, WHITE or INVERT.
|
||||
@return None (void).
|
||||
@note Changes buffer contents only, no immediate effect on display.
|
||||
Follow up with a call to display(), or with other graphics
|
||||
commands as needed by one's own application.
|
||||
*/
|
||||
void Adafruit_SSD1306::drawPixel(int16_t x, int16_t y, uint16_t color) {
|
||||
if((x >= 0) && (x < width()) && (y >= 0) && (y < height())) {
|
||||
// Pixel is in-bounds. Rotate coordinates if needed.
|
||||
switch(getRotation()) {
|
||||
case 1:
|
||||
ssd1306_swap(x, y);
|
||||
x = WIDTH - x - 1;
|
||||
break;
|
||||
case 2:
|
||||
x = WIDTH - x - 1;
|
||||
y = HEIGHT - y - 1;
|
||||
break;
|
||||
case 3:
|
||||
ssd1306_swap(x, y);
|
||||
y = HEIGHT - y - 1;
|
||||
break;
|
||||
}
|
||||
switch(color) {
|
||||
case WHITE: buffer[x + (y/8)*WIDTH] |= (1 << (y&7)); break;
|
||||
case BLACK: buffer[x + (y/8)*WIDTH] &= ~(1 << (y&7)); break;
|
||||
case INVERSE: buffer[x + (y/8)*WIDTH] ^= (1 << (y&7)); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Clear contents of display buffer (set all pixels to off).
|
||||
@return None (void).
|
||||
@note Changes buffer contents only, no immediate effect on display.
|
||||
Follow up with a call to display(), or with other graphics
|
||||
commands as needed by one's own application.
|
||||
*/
|
||||
void Adafruit_SSD1306::clearDisplay(void) {
|
||||
memset(buffer, 0, WIDTH * ((HEIGHT + 7) / 8));
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Draw a horizontal line. This is also invoked by the Adafruit_GFX
|
||||
library in generating many higher-level graphics primitives.
|
||||
@param x
|
||||
Leftmost column -- 0 at left to (screen width - 1) at right.
|
||||
@param y
|
||||
Row of display -- 0 at top to (screen height -1) at bottom.
|
||||
@param w
|
||||
Width of line, in pixels.
|
||||
@param color
|
||||
Line color, one of: BLACK, WHITE or INVERT.
|
||||
@return None (void).
|
||||
@note Changes buffer contents only, no immediate effect on display.
|
||||
Follow up with a call to display(), or with other graphics
|
||||
commands as needed by one's own application.
|
||||
*/
|
||||
void Adafruit_SSD1306::drawFastHLine(
|
||||
int16_t x, int16_t y, int16_t w, uint16_t color) {
|
||||
boolean bSwap = false;
|
||||
switch(rotation) {
|
||||
case 1:
|
||||
// 90 degree rotation, swap x & y for rotation, then invert x
|
||||
bSwap = true;
|
||||
ssd1306_swap(x, y);
|
||||
x = WIDTH - x - 1;
|
||||
break;
|
||||
case 2:
|
||||
// 180 degree rotation, invert x and y, then shift y around for height.
|
||||
x = WIDTH - x - 1;
|
||||
y = HEIGHT - y - 1;
|
||||
x -= (w-1);
|
||||
break;
|
||||
case 3:
|
||||
// 270 degree rotation, swap x & y for rotation,
|
||||
// then invert y and adjust y for w (not to become h)
|
||||
bSwap = true;
|
||||
ssd1306_swap(x, y);
|
||||
y = HEIGHT - y - 1;
|
||||
y -= (w-1);
|
||||
break;
|
||||
}
|
||||
|
||||
if(bSwap) drawFastVLineInternal(x, y, w, color);
|
||||
else drawFastHLineInternal(x, y, w, color);
|
||||
}
|
||||
|
||||
void Adafruit_SSD1306::drawFastHLineInternal(
|
||||
int16_t x, int16_t y, int16_t w, uint16_t color) {
|
||||
|
||||
if((y >= 0) && (y < HEIGHT)) { // Y coord in bounds?
|
||||
if(x < 0) { // Clip left
|
||||
w += x;
|
||||
x = 0;
|
||||
}
|
||||
if((x + w) > WIDTH) { // Clip right
|
||||
w = (WIDTH - x);
|
||||
}
|
||||
if(w > 0) { // Proceed only if width is positive
|
||||
uint8_t *pBuf = &buffer[(y / 8) * WIDTH + x],
|
||||
mask = 1 << (y & 7);
|
||||
switch(color) {
|
||||
case WHITE: while(w--) { *pBuf++ |= mask; }; break;
|
||||
case BLACK: mask = ~mask; while(w--) { *pBuf++ &= mask; }; break;
|
||||
case INVERSE: while(w--) { *pBuf++ ^= mask; }; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Draw a vertical line. This is also invoked by the Adafruit_GFX
|
||||
library in generating many higher-level graphics primitives.
|
||||
@param x
|
||||
Column of display -- 0 at left to (screen width -1) at right.
|
||||
@param y
|
||||
Topmost row -- 0 at top to (screen height - 1) at bottom.
|
||||
@param h
|
||||
Height of line, in pixels.
|
||||
@param color
|
||||
Line color, one of: BLACK, WHITE or INVERT.
|
||||
@return None (void).
|
||||
@note Changes buffer contents only, no immediate effect on display.
|
||||
Follow up with a call to display(), or with other graphics
|
||||
commands as needed by one's own application.
|
||||
*/
|
||||
void Adafruit_SSD1306::drawFastVLine(
|
||||
int16_t x, int16_t y, int16_t h, uint16_t color) {
|
||||
boolean bSwap = false;
|
||||
switch(rotation) {
|
||||
case 1:
|
||||
// 90 degree rotation, swap x & y for rotation,
|
||||
// then invert x and adjust x for h (now to become w)
|
||||
bSwap = true;
|
||||
ssd1306_swap(x, y);
|
||||
x = WIDTH - x - 1;
|
||||
x -= (h-1);
|
||||
break;
|
||||
case 2:
|
||||
// 180 degree rotation, invert x and y, then shift y around for height.
|
||||
x = WIDTH - x - 1;
|
||||
y = HEIGHT - y - 1;
|
||||
y -= (h-1);
|
||||
break;
|
||||
case 3:
|
||||
// 270 degree rotation, swap x & y for rotation, then invert y
|
||||
bSwap = true;
|
||||
ssd1306_swap(x, y);
|
||||
y = HEIGHT - y - 1;
|
||||
break;
|
||||
}
|
||||
|
||||
if(bSwap) drawFastHLineInternal(x, y, h, color);
|
||||
else drawFastVLineInternal(x, y, h, color);
|
||||
}
|
||||
|
||||
void Adafruit_SSD1306::drawFastVLineInternal(
|
||||
int16_t x, int16_t __y, int16_t __h, uint16_t color) {
|
||||
|
||||
if((x >= 0) && (x < WIDTH)) { // X coord in bounds?
|
||||
if(__y < 0) { // Clip top
|
||||
__h += __y;
|
||||
__y = 0;
|
||||
}
|
||||
if((__y + __h) > HEIGHT) { // Clip bottom
|
||||
__h = (HEIGHT - __y);
|
||||
}
|
||||
if(__h > 0) { // Proceed only if height is now positive
|
||||
// this display doesn't need ints for coordinates,
|
||||
// use local byte registers for faster juggling
|
||||
uint8_t y = __y, h = __h;
|
||||
uint8_t *pBuf = &buffer[(y / 8) * WIDTH + x];
|
||||
|
||||
// do the first partial byte, if necessary - this requires some masking
|
||||
uint8_t mod = (y & 7);
|
||||
if(mod) {
|
||||
// mask off the high n bits we want to set
|
||||
mod = 8 - mod;
|
||||
// note - lookup table results in a nearly 10% performance
|
||||
// improvement in fill* functions
|
||||
// uint8_t mask = ~(0xFF >> mod);
|
||||
static const uint8_t PROGMEM premask[8] =
|
||||
{ 0x00, 0x80, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC, 0xFE };
|
||||
uint8_t mask = pgm_read_byte(&premask[mod]);
|
||||
// adjust the mask if we're not going to reach the end of this byte
|
||||
if(h < mod) mask &= (0XFF >> (mod - h));
|
||||
|
||||
switch(color) {
|
||||
case WHITE: *pBuf |= mask; break;
|
||||
case BLACK: *pBuf &= ~mask; break;
|
||||
case INVERSE: *pBuf ^= mask; break;
|
||||
}
|
||||
pBuf += WIDTH;
|
||||
}
|
||||
|
||||
if(h >= mod) { // More to go?
|
||||
h -= mod;
|
||||
// Write solid bytes while we can - effectively 8 rows at a time
|
||||
if(h >= 8) {
|
||||
if(color == INVERSE) {
|
||||
// separate copy of the code so we don't impact performance of
|
||||
// black/white write version with an extra comparison per loop
|
||||
do {
|
||||
*pBuf ^= 0xFF; // Invert byte
|
||||
pBuf += WIDTH; // Advance pointer 8 rows
|
||||
h -= 8; // Subtract 8 rows from height
|
||||
} while(h >= 8);
|
||||
} else {
|
||||
// store a local value to work with
|
||||
uint8_t val = (color != BLACK) ? 255 : 0;
|
||||
do {
|
||||
*pBuf = val; // Set byte
|
||||
pBuf += WIDTH; // Advance pointer 8 rows
|
||||
h -= 8; // Subtract 8 rows from height
|
||||
} while(h >= 8);
|
||||
}
|
||||
}
|
||||
|
||||
if(h) { // Do the final partial byte, if necessary
|
||||
mod = h & 7;
|
||||
// this time we want to mask the low bits of the byte,
|
||||
// vs the high bits we did above
|
||||
// uint8_t mask = (1 << mod) - 1;
|
||||
// note - lookup table results in a nearly 10% performance
|
||||
// improvement in fill* functions
|
||||
static const uint8_t PROGMEM postmask[8] =
|
||||
{ 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F };
|
||||
uint8_t mask = pgm_read_byte(&postmask[mod]);
|
||||
switch(color) {
|
||||
case WHITE: *pBuf |= mask; break;
|
||||
case BLACK: *pBuf &= ~mask; break;
|
||||
case INVERSE: *pBuf ^= mask; break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // endif positive height
|
||||
} // endif x in bounds
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Return color of a single pixel in display buffer.
|
||||
@param x
|
||||
Column of display -- 0 at left to (screen width - 1) at right.
|
||||
@param y
|
||||
Row of display -- 0 at top to (screen height -1) at bottom.
|
||||
@return true if pixel is set (usually WHITE, unless display invert mode
|
||||
is enabled), false if clear (BLACK).
|
||||
@note Reads from buffer contents; may not reflect current contents of
|
||||
screen if display() has not been called.
|
||||
*/
|
||||
boolean Adafruit_SSD1306::getPixel(int16_t x, int16_t y) {
|
||||
if((x >= 0) && (x < width()) && (y >= 0) && (y < height())) {
|
||||
// Pixel is in-bounds. Rotate coordinates if needed.
|
||||
switch(getRotation()) {
|
||||
case 1:
|
||||
ssd1306_swap(x, y);
|
||||
x = WIDTH - x - 1;
|
||||
break;
|
||||
case 2:
|
||||
x = WIDTH - x - 1;
|
||||
y = HEIGHT - y - 1;
|
||||
break;
|
||||
case 3:
|
||||
ssd1306_swap(x, y);
|
||||
y = HEIGHT - y - 1;
|
||||
break;
|
||||
}
|
||||
return (buffer[x + (y / 8) * WIDTH] & (1 << (y & 7)));
|
||||
}
|
||||
return false; // Pixel out of bounds
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Get base address of display buffer for direct reading or writing.
|
||||
@return Pointer to an unsigned 8-bit array, column-major, columns padded
|
||||
to full byte boundary if needed.
|
||||
*/
|
||||
uint8_t *Adafruit_SSD1306::getBuffer(void) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// REFRESH DISPLAY ---------------------------------------------------------
|
||||
|
||||
/*!
|
||||
@brief Push data currently in RAM to SSD1306 display.
|
||||
@return None (void).
|
||||
@note Drawing operations are not visible until this function is
|
||||
called. Call after each graphics command, or after a whole set
|
||||
of graphics commands, as best needed by one's own application.
|
||||
*/
|
||||
void Adafruit_SSD1306::display(void) {
|
||||
|
||||
// TODO: Update SDL surface with content of `buffer`
|
||||
|
||||
}
|
||||
|
||||
// SCROLLING FUNCTIONS -----------------------------------------------------
|
||||
|
||||
/*!
|
||||
@brief Activate a right-handed scroll for all or part of the display.
|
||||
@param start
|
||||
First row.
|
||||
@param stop
|
||||
Last row.
|
||||
@return None (void).
|
||||
*/
|
||||
// To scroll the whole display, run: display.startscrollright(0x00, 0x0F)
|
||||
void Adafruit_SSD1306::startscrollright(uint8_t __attribute__((unused)) start, uint8_t __attribute__((unused)) stop) {
|
||||
|
||||
// not used for now
|
||||
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Activate a left-handed scroll for all or part of the display.
|
||||
@param start
|
||||
First row.
|
||||
@param stop
|
||||
Last row.
|
||||
@return None (void).
|
||||
*/
|
||||
// To scroll the whole display, run: display.startscrollleft(0x00, 0x0F)
|
||||
void Adafruit_SSD1306::startscrollleft(uint8_t __attribute__((unused)) start, uint8_t __attribute__((unused)) stop) {
|
||||
// not used for now
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Activate a diagonal scroll for all or part of the display.
|
||||
@param start
|
||||
First row.
|
||||
@param stop
|
||||
Last row.
|
||||
@return None (void).
|
||||
*/
|
||||
// display.startscrolldiagright(0x00, 0x0F)
|
||||
void Adafruit_SSD1306::startscrolldiagright(uint8_t __attribute__((unused)) start, uint8_t __attribute__((unused)) stop) {
|
||||
// not used for now
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Activate alternate diagonal scroll for all or part of the display.
|
||||
@param start
|
||||
First row.
|
||||
@param stop
|
||||
Last row.
|
||||
@return None (void).
|
||||
*/
|
||||
// To scroll the whole display, run: display.startscrolldiagleft(0x00, 0x0F)
|
||||
void Adafruit_SSD1306::startscrolldiagleft(uint8_t __attribute__((unused)) start, uint8_t __attribute__((unused)) stop) {
|
||||
// not used for now
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Cease a previously-begun scrolling action.
|
||||
@return None (void).
|
||||
*/
|
||||
void Adafruit_SSD1306::stopscroll(void) {
|
||||
// not used for now
|
||||
}
|
||||
|
||||
// OTHER HARDWARE SETTINGS -------------------------------------------------
|
||||
|
||||
/*!
|
||||
@brief Enable or disable display invert mode (white-on-black vs
|
||||
black-on-white).
|
||||
@param i
|
||||
If true, switch to invert mode (black-on-white), else normal
|
||||
mode (white-on-black).
|
||||
@return None (void).
|
||||
@note This has an immediate effect on the display, no need to call the
|
||||
display() function -- buffer contents are not changed, rather a
|
||||
different pixel mode of the display hardware is used. When
|
||||
enabled, drawing BLACK (value 0) pixels will actually draw white,
|
||||
WHITE (value 1) will draw black.
|
||||
*/
|
||||
void Adafruit_SSD1306::invertDisplay(boolean i) {
|
||||
// not used for now
|
||||
inverted_ = i;
|
||||
}
|
||||
|
||||
/*!
|
||||
@brief Dim the display.
|
||||
@param dim
|
||||
true to enable lower brightness mode, false for full brightness.
|
||||
@return None (void).
|
||||
@note This has an immediate effect on the display, no need to call the
|
||||
display() function -- buffer contents are not changed.
|
||||
*/
|
||||
void Adafruit_SSD1306::dim(boolean dim)
|
||||
{
|
||||
dimmed_ = dim;
|
||||
}
|
||||
|
||||
void Adafruit_SSD1306::ssd1306_command(uint8_t cmd)
|
||||
{
|
||||
// TODO: parse command and act on it...
|
||||
switch(cmd)
|
||||
{
|
||||
case SSD1306_DISPLAYOFF:
|
||||
enabled_ = false;
|
||||
break;
|
||||
case SSD1306_DISPLAYON:
|
||||
enabled_ = true;
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
337
simulation/src/Print.cpp
Normal file
337
simulation/src/Print.cpp
Normal file
|
@ -0,0 +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;
|
||||
}
|
||||
|
||||
|
3
simulation/src/filters.cpp
Normal file
3
simulation/src/filters.cpp
Normal file
|
@ -0,0 +1,3 @@
|
|||
#include <cmath>
|
||||
|
||||
#include "FilterOnepole.cpp"
|
276
simulation/src/glcdfont.c
Normal file
276
simulation/src/glcdfont.c
Normal file
|
@ -0,0 +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
|
278
simulation/src/nuevisim.cpp
Normal file
278
simulation/src/nuevisim.cpp
Normal file
|
@ -0,0 +1,278 @@
|
|||
#include <functional>
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
|
||||
#include <Adafruit_MPR121.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
#include "globals.h"
|
||||
#include "hardware.h"
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
// Forward declarations
|
||||
static void SimQuit(void);
|
||||
static int SimInit(void);
|
||||
static int SimRun(void);
|
||||
static void SimLoop(std::function<bool()>, std::function<void()>);
|
||||
|
||||
|
||||
|
||||
extern Adafruit_SSD1306 display;
|
||||
extern Adafruit_MPR121 touchSensor;
|
||||
SimWire Wire;
|
||||
SimSerial Serial;
|
||||
|
||||
|
||||
static const int scale = 2;
|
||||
|
||||
static SDL_Window *window;
|
||||
static SDL_Surface *surface;
|
||||
|
||||
void _reboot_Teensyduino_()
|
||||
{
|
||||
// TODO: reboot
|
||||
// Ignore that this is marked as noreturn
|
||||
printf("Some kind of panic, rebooting teensy...\n");
|
||||
setup();
|
||||
}
|
||||
|
||||
extern void menu(void);
|
||||
extern void initDisplay(void);
|
||||
extern void breath();
|
||||
extern int noteValueCheck(int);
|
||||
extern unsigned int breathCurve(unsigned int);
|
||||
extern void pitch_bend(void);
|
||||
extern void portamento_(void);
|
||||
extern void extraController(void);
|
||||
extern void statusLEDs(void);
|
||||
extern void doorKnobCheck(void);
|
||||
extern void portOn(void);
|
||||
extern void portOff(void);
|
||||
extern void port(void);
|
||||
extern void readSwitches(void);
|
||||
extern int patchLimit(int value);
|
||||
|
||||
static uint8_t digitalInputs[256]; // random number of inputs..
|
||||
static uint8_t digitalOutputs[256]; // random number of inputs..
|
||||
static uint16_t analogInputs[256]; // random number of inputs..
|
||||
static uint16_t analogOutputs[256]; // random number of inputs..
|
||||
static int _analogRes = 12;
|
||||
|
||||
void digitalWrite(uint8_t pin, uint8_t val)
|
||||
{
|
||||
printf("digital write %d = %d\n", pin, val);
|
||||
digitalOutputs[pin] = val;
|
||||
}
|
||||
|
||||
uint8_t digitalRead(uint8_t pin) {
|
||||
return digitalInputs[pin];
|
||||
}
|
||||
|
||||
void delay(unsigned int ms)
|
||||
{
|
||||
uint32_t endTick = SDL_GetTicks() + ms;
|
||||
auto checktime = [endTick]() -> bool { return endTick > SDL_GetTicks(); };
|
||||
SimLoop(checktime,NULL);
|
||||
}
|
||||
|
||||
void pinMode(uint8_t __attribute((unused)) pin, uint8_t __attribute((unused)) mode)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int analogRead(uint8_t pin)
|
||||
{
|
||||
return analogInputs[pin];
|
||||
}
|
||||
|
||||
|
||||
void analogReadRes(unsigned int __attribute__((unused)) bits)
|
||||
{
|
||||
// ??
|
||||
}
|
||||
|
||||
uint32_t analogWriteRes(uint32_t res)
|
||||
{
|
||||
_analogRes = res; // ??
|
||||
return _analogRes; // ??
|
||||
}
|
||||
|
||||
|
||||
void analogWriteFrequency(uint8_t __unused pin, float __unused frequency)
|
||||
{
|
||||
}
|
||||
|
||||
void analogWrite(uint8_t pin, int value)
|
||||
{
|
||||
analogOutputs[pin] = value;
|
||||
}
|
||||
|
||||
|
||||
uint16_t micros()
|
||||
{
|
||||
return SDL_GetTicks()*1000;
|
||||
}
|
||||
|
||||
uint16_t millis()
|
||||
{
|
||||
return SDL_GetTicks();
|
||||
}
|
||||
|
||||
int touchRead(uint8_t reg){ return touchSensor.readRegister16(reg); }
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
return SimRun();
|
||||
}
|
||||
|
||||
//***********************************************************
|
||||
|
||||
static void GetDisplay(SDL_Surface* dest)
|
||||
{
|
||||
int w = display.width();
|
||||
int h = display.height();
|
||||
|
||||
SDL_LockSurface(dest);
|
||||
uint8_t* buffer = (uint8_t*)surface->pixels;
|
||||
int pitch = surface->pitch;
|
||||
|
||||
if(!display.enabled_) {
|
||||
SDL_memset( buffer, 0, (w*h)*3);
|
||||
} else {
|
||||
int fg = 255;
|
||||
int bg = 0;
|
||||
|
||||
if( display.dimmed_) fg = 127;
|
||||
if( display.inverted_ ) { int tmp = fg; fg = bg; bg = tmp; }
|
||||
|
||||
for(int y = 0 ; y < h; ++y) {
|
||||
for(int x = 0 ; x < w; ++x) {
|
||||
int color = display.getPixel(x,y) ? fg : bg;
|
||||
SDL_memset( buffer + pitch*y + x*3, color, 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
SDL_UnlockSurface(dest);
|
||||
}
|
||||
|
||||
|
||||
static int doQuit = 0;
|
||||
|
||||
static void SimLoop(std::function<bool()> continue_predicate, std::function<void()> loopFunc)
|
||||
{
|
||||
uint32_t time;
|
||||
while( continue_predicate() ) {
|
||||
SDL_Event event;
|
||||
while( SDL_PollEvent(&event) ) {
|
||||
if( event.type == SDL_QUIT ) {
|
||||
doQuit = 1;
|
||||
break;
|
||||
}
|
||||
if(event.type == SDL_KEYDOWN)
|
||||
{
|
||||
switch(event.key.keysym.sym)
|
||||
{
|
||||
case SDLK_LEFT: digitalInputs[mPin] = 0; break;
|
||||
case SDLK_RIGHT: digitalInputs[ePin] = 0; break;
|
||||
case SDLK_UP: digitalInputs[uPin] = 0; break;
|
||||
case SDLK_DOWN: digitalInputs[dPin] = 0; break;
|
||||
}
|
||||
}
|
||||
else if(event.type == SDL_KEYUP )
|
||||
{
|
||||
switch(event.key.keysym.sym)
|
||||
{
|
||||
case SDLK_LEFT: digitalInputs[mPin] = 1; break;
|
||||
case SDLK_RIGHT: digitalInputs[ePin] = 1; break;
|
||||
case SDLK_UP: digitalInputs[uPin] = 1; break;
|
||||
case SDLK_DOWN: digitalInputs[dPin] = 1; break;
|
||||
}
|
||||
fflush(stdout);
|
||||
}
|
||||
}
|
||||
|
||||
if(doQuit)
|
||||
break;
|
||||
|
||||
if(loopFunc) loopFunc();
|
||||
|
||||
time = SDL_GetTicks();
|
||||
|
||||
// TODO: Get buffer from SSD1306 and copy to surface...
|
||||
|
||||
GetDisplay(surface);
|
||||
|
||||
SDL_Surface *dstSurface = SDL_GetWindowSurface(window);
|
||||
SDL_BlitScaled( surface, NULL, dstSurface, NULL );
|
||||
SDL_UpdateWindowSurface(window);
|
||||
|
||||
uint32_t timePassed = SDL_GetTicks() - time;
|
||||
if( timePassed < 16 ) {
|
||||
SDL_Delay( 16-timePassed );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int SimRun( )
|
||||
{
|
||||
if( 0 != SimInit() ) { return 1; }
|
||||
setup();
|
||||
SimLoop( []() -> bool { return true; }, loop );
|
||||
SimQuit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int SimInit()
|
||||
{
|
||||
int result = result = SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO );
|
||||
if( 0 != result ) {
|
||||
fprintf(stderr, "Could not initialize SDL");
|
||||
return 1;
|
||||
}
|
||||
|
||||
window = SDL_CreateWindow( "TinySim"
|
||||
, SDL_WINDOWPOS_UNDEFINED
|
||||
, SDL_WINDOWPOS_UNDEFINED
|
||||
, 128*scale
|
||||
, 64*scale
|
||||
, SDL_WINDOW_SHOWN );
|
||||
|
||||
if( window == NULL ) {
|
||||
fprintf(stderr, "Could not create SDL window");
|
||||
SimQuit();
|
||||
return 2;
|
||||
}
|
||||
|
||||
SDL_SetWindowTitle( window, "Tiny Sim" );
|
||||
|
||||
memset(digitalInputs, 1, sizeof(digitalInputs));
|
||||
|
||||
int16_t w = display.width();
|
||||
int16_t h = display.height();
|
||||
|
||||
surface = SDL_CreateRGBSurfaceWithFormat(0, w, h, 0, SDL_PIXELFORMAT_RGB24);
|
||||
if(!surface)
|
||||
{
|
||||
printf("Could not create surface with size %d %d\n", w,h);
|
||||
SimQuit();
|
||||
}
|
||||
|
||||
printf("create surface with size %d %d\n", w,h);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void SimQuit()
|
||||
{
|
||||
printf("Leaving Sim, see you later!\n");
|
||||
|
||||
if( window != NULL ) {
|
||||
SDL_DestroyWindow( window );
|
||||
SDL_FreeSurface( surface );
|
||||
}
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
#include "NuEVI.ino"
|
30
simulation/src/simeeprom.cpp
Normal file
30
simulation/src/simeeprom.cpp
Normal file
|
@ -0,0 +1,30 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include "EEPROM.h"
|
||||
|
||||
// TODO: Fake eeprom a bit better, maybe even save to file.
|
||||
|
||||
static char someFakeEEPROM_memory[4096];
|
||||
|
||||
|
||||
uint8_t EEPROMClass::read( int idx )
|
||||
{
|
||||
return someFakeEEPROM_memory[idx];
|
||||
}
|
||||
|
||||
|
||||
void EEPROMClass::write( int idx, uint8_t val )
|
||||
{
|
||||
someFakeEEPROM_memory[idx] = val;
|
||||
}
|
||||
|
||||
void EEPROMClass::update( int idx, uint8_t val )
|
||||
{
|
||||
someFakeEEPROM_memory[idx] = val;
|
||||
}
|
||||
uint16_t EEPROMClass::length()
|
||||
{
|
||||
return sizeof(someFakeEEPROM_memory);
|
||||
}
|
||||
|
||||
// TODO: Add missing functioality..
|
56
simulation/src/simmidi.cpp
Normal file
56
simulation/src/simmidi.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
#include <Arduino.h>
|
||||
#include "midi.h"
|
||||
|
||||
void midiSetChannel(byte __attribute__((unused)) channel){}
|
||||
|
||||
byte midiGetChannel(){ return 1; }
|
||||
|
||||
void midiSendProgramChange(int __attribute__((unused)) patch)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void midiSendControlChange(int __attribute__((unused)) ccParam, int __attribute__((unused)) ccValue)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void midiSendNoteOn(byte __attribute__((unused)) note, int __attribute__((unused)) velocity)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void midiSendNoteOff(byte __attribute__((unused)) note)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void midiSendAfterTouch(byte __attribute__((unused)) value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void midiSendPitchBend(int __attribute__((unused)) value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void midiDiscardInput()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void midiReset()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void midiPanic()
|
||||
{
|
||||
// turn all notes off
|
||||
}
|
||||
|
||||
void midiInitialize(byte __attribute__((unused)) channel)
|
||||
{
|
||||
|
||||
}
|
43
simulation/src/simserial.cpp
Normal file
43
simulation/src/simserial.cpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
#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 );
|
||||
}
|
||||
|
94
simulation/src/simwire.cpp
Normal file
94
simulation/src/simwire.cpp
Normal file
|
@ -0,0 +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;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue