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:
Mikael Degerfält 2019-06-06 21:13:07 +02:00
parent c9123b746f
commit 266b3334cb
30 changed files with 8532 additions and 0 deletions

File diff suppressed because it is too large Load diff

View 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();
}

View 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
View 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;
}

View file

@ -0,0 +1,3 @@
#include <cmath>
#include "FilterOnepole.cpp"

276
simulation/src/glcdfont.c Normal file
View 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
View 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"

View 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..

View 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)
{
}

View 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 );
}

View 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;
}