Refactored for teensy 4.0, xEvi hardware

- Switched to platformio, ino -> cpp
- MPRLS for pressure sensor
- Added basic ICM support
- Removed widi, battery, other features not supported in xEvi
- Removed legacy options/processing
- Added LED strip support
- Added encoder support
- Reworked menu code to use encoders/be more flexible
This commit is contained in:
Brian Hrebec 2023-08-27 11:52:08 -05:00
parent c58c3f9e46
commit 01d193c9b3
92 changed files with 69119 additions and 73272 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,170 +1,170 @@
/*!
* @file Adafruit_MPR121.cpp
*
* @mainpage Adafruit MPR121 arduino driver
*
* @section intro_sec Introduction
*
This is a library for the MPR121 I2C 12-chan Capacitive Sensor
Designed specifically to work with the MPR121 sensor from Adafruit
----> https://www.adafruit.com/products/1982
These sensors use I2C to communicate, 2+ pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
*
* @section author Author
*
* Written by Limor Fried/Ladyada for Adafruit Industries.
*
* @section license License
*
* BSD license, all text here must be included in any redistribution.
*
*/
#include "Adafruit_MPR121.h"
/**
*****************************************************************************************
* @brief Default constructor
****************************************************************************************/
Adafruit_MPR121::Adafruit_MPR121() {
}
/**
*****************************************************************************************
* @brief Begin an MPR121 object on a given I2C bus. This function resets the
* device and writes the default settings.
*
* @param i2caddr the i2c address the device can be found on. Defaults to 0x5A.
* @returns true on success, false otherwise
****************************************************************************************/
boolean Adafruit_MPR121::begin(uint8_t i2caddr) {
_i2caddr = i2caddr;
return true;
}
/**
*****************************************************************************************
* @brief DEPRECATED. Use Adafruit_MPR121::setThresholds(uint8_t touch, uint8_t release) instead.
*
* @param touch see Adafruit_MPR121::setThresholds(uint8_t touch, uint8_t release)
* @param release see Adafruit_MPR121::setThresholds(uint8_t touch, uint8_t release)
****************************************************************************************/
void Adafruit_MPR121::setThreshholds(uint8_t __attribute__((unused)) touch, uint8_t __attribute__((unused)) release) {
// setThresholds(touch, release);
}
/**
*****************************************************************************************
* @brief Set the touch and release thresholds for all 13 channels on the device to the
* passed values. The threshold is defined as a deviation value from the baseline value,
* so it remains constant even baseline value changes. Typically the touch
* threshold is a little bigger than the release threshold to touch debounce and hysteresis.
*
* For typical touch application, the value can be in range 0x05~0x30 for example. The setting
* of the threshold is depended on the actual application. For the operation details and how to set the threshold refer to
* application note AN3892 and MPR121 design guidelines.
*
* @param touch the touch threshold value from 0 to 255.
* @param release the release threshold from 0 to 255.
****************************************************************************************/
void Adafruit_MPR121::setThresholds(uint8_t __attribute__((unused)) touch, __attribute__((unused)) uint8_t release) {
// for (uint8_t i=0; i<12; i++) {
// writeRegister(MPR121_TOUCHTH_0 + 2*i, touch);
// writeRegister(MPR121_RELEASETH_0 + 2*i, release);
// }
}
/**
*****************************************************************************************
* @brief Read the filtered data from channel t. The ADC raw data outputs run through 3
* levels of digital filtering to filter out the high frequency and low frequency noise
* encountered. For detailed information on this filtering see page 6 of the device datasheet.
*
* @param t the channel to read
* @returns the filtered reading as a 10 bit unsigned value
****************************************************************************************/
uint16_t Adafruit_MPR121::filteredData(uint8_t t) {
if (t > 12) return 0;
return readRegister16(MPR121_FILTDATA_0L + t*2);
}
/**
*****************************************************************************************
* @brief Read the baseline value for the channel. The 3rd level filtered result is internally 10bit
* but only high 8 bits are readable from registers 0x1E~0x2A as the baseline value output for each channel.
*
* @param t the channel to read.
* @returns the baseline data that was read
****************************************************************************************/
uint16_t Adafruit_MPR121::baselineData(uint8_t t) {
if (t > 12) return 0;
uint16_t bl = readRegister8(MPR121_BASELINE_0 + t);
return (bl << 2);
}
/**
*****************************************************************************************
* @brief Read the touch status of all 13 channels as bit values in a 12 bit integer.
*
* @returns a 12 bit integer with each bit corresponding to the touch status of a sensor.
* For example, if bit 0 is set then channel 0 of the device is currently deemed to be touched.
****************************************************************************************/
uint16_t Adafruit_MPR121::touched(void) {
uint16_t t = readRegister16(MPR121_TOUCHSTATUS_L);
return t & 0x0FFF;
}
/*********************************************************************/
/**
*****************************************************************************************
* @brief Read the contents of an 8 bit device register.
*
* @param reg the register address to read from
* @returns the 8 bit value that was read.
****************************************************************************************/
uint8_t Adafruit_MPR121::readRegister8(uint8_t reg) {
return this->_registers[reg];
}
/**
*****************************************************************************************
* @brief Read the contents of a 16 bit device register.
*
* @param reg the register address to read from
* @returns the 16 bit value that was read.
****************************************************************************************/
uint16_t Adafruit_MPR121::readRegister16(uint8_t reg) {
return _registers[reg] | (_registers[reg+1] << 8);
}
/**************************************************************************/
/*!
@brief Writes 8-bits to the specified destination register
@param reg the register address to write to
@param value the value to write
*/
/**************************************************************************/
void Adafruit_MPR121::writeRegister(uint8_t reg, uint8_t value) {
_registers[reg] = value;
}
/*
Simulator specifics code..
*/
void Adafruit_MPR121::mockFilteredData(int reg, uint16_t value) {
_registers[MPR121_FILTDATA_0L + reg*2] = value & 0xffu;
_registers[MPR121_FILTDATA_0L + reg*2+1] = (value>>8) & 0xffu;
}
/*!
* @file Adafruit_MPR121.cpp
*
* @mainpage Adafruit MPR121 arduino driver
*
* @section intro_sec Introduction
*
This is a library for the MPR121 I2C 12-chan Capacitive Sensor
Designed specifically to work with the MPR121 sensor from Adafruit
----> https://www.adafruit.com/products/1982
These sensors use I2C to communicate, 2+ pins are required to
interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
*
* @section author Author
*
* Written by Limor Fried/Ladyada for Adafruit Industries.
*
* @section license License
*
* BSD license, all text here must be included in any redistribution.
*
*/
#include "Adafruit_MPR121.h"
/**
*****************************************************************************************
* @brief Default constructor
****************************************************************************************/
Adafruit_MPR121::Adafruit_MPR121() {
}
/**
*****************************************************************************************
* @brief Begin an MPR121 object on a given I2C bus. This function resets the
* device and writes the default settings.
*
* @param i2caddr the i2c address the device can be found on. Defaults to 0x5A.
* @returns true on success, false otherwise
****************************************************************************************/
boolean Adafruit_MPR121::begin(uint8_t i2caddr) {
_i2caddr = i2caddr;
return true;
}
/**
*****************************************************************************************
* @brief DEPRECATED. Use Adafruit_MPR121::setThresholds(uint8_t touch, uint8_t release) instead.
*
* @param touch see Adafruit_MPR121::setThresholds(uint8_t touch, uint8_t release)
* @param release see Adafruit_MPR121::setThresholds(uint8_t touch, uint8_t release)
****************************************************************************************/
void Adafruit_MPR121::setThreshholds(uint8_t __attribute__((unused)) touch, uint8_t __attribute__((unused)) release) {
// setThresholds(touch, release);
}
/**
*****************************************************************************************
* @brief Set the touch and release thresholds for all 13 channels on the device to the
* passed values. The threshold is defined as a deviation value from the baseline value,
* so it remains constant even baseline value changes. Typically the touch
* threshold is a little bigger than the release threshold to touch debounce and hysteresis.
*
* For typical touch application, the value can be in range 0x05~0x30 for example. The setting
* of the threshold is depended on the actual application. For the operation details and how to set the threshold refer to
* application note AN3892 and MPR121 design guidelines.
*
* @param touch the touch threshold value from 0 to 255.
* @param release the release threshold from 0 to 255.
****************************************************************************************/
void Adafruit_MPR121::setThresholds(uint8_t __attribute__((unused)) touch, __attribute__((unused)) uint8_t release) {
// for (uint8_t i=0; i<12; i++) {
// writeRegister(MPR121_TOUCHTH_0 + 2*i, touch);
// writeRegister(MPR121_RELEASETH_0 + 2*i, release);
// }
}
/**
*****************************************************************************************
* @brief Read the filtered data from channel t. The ADC raw data outputs run through 3
* levels of digital filtering to filter out the high frequency and low frequency noise
* encountered. For detailed information on this filtering see page 6 of the device datasheet.
*
* @param t the channel to read
* @returns the filtered reading as a 10 bit unsigned value
****************************************************************************************/
uint16_t Adafruit_MPR121::filteredData(uint8_t t) {
if (t > 12) return 0;
return readRegister16(MPR121_FILTDATA_0L + t*2);
}
/**
*****************************************************************************************
* @brief Read the baseline value for the channel. The 3rd level filtered result is internally 10bit
* but only high 8 bits are readable from registers 0x1E~0x2A as the baseline value output for each channel.
*
* @param t the channel to read.
* @returns the baseline data that was read
****************************************************************************************/
uint16_t Adafruit_MPR121::baselineData(uint8_t t) {
if (t > 12) return 0;
uint16_t bl = readRegister8(MPR121_BASELINE_0 + t);
return (bl << 2);
}
/**
*****************************************************************************************
* @brief Read the touch status of all 13 channels as bit values in a 12 bit integer.
*
* @returns a 12 bit integer with each bit corresponding to the touch status of a sensor.
* For example, if bit 0 is set then channel 0 of the device is currently deemed to be touched.
****************************************************************************************/
uint16_t Adafruit_MPR121::touched(void) {
uint16_t t = readRegister16(MPR121_TOUCHSTATUS_L);
return t & 0x0FFF;
}
/*********************************************************************/
/**
*****************************************************************************************
* @brief Read the contents of an 8 bit device register.
*
* @param reg the register address to read from
* @returns the 8 bit value that was read.
****************************************************************************************/
uint8_t Adafruit_MPR121::readRegister8(uint8_t reg) {
return this->_registers[reg];
}
/**
*****************************************************************************************
* @brief Read the contents of a 16 bit device register.
*
* @param reg the register address to read from
* @returns the 16 bit value that was read.
****************************************************************************************/
uint16_t Adafruit_MPR121::readRegister16(uint8_t reg) {
return _registers[reg] | (_registers[reg+1] << 8);
}
/**************************************************************************/
/*!
@brief Writes 8-bits to the specified destination register
@param reg the register address to write to
@param value the value to write
*/
/**************************************************************************/
void Adafruit_MPR121::writeRegister(uint8_t reg, uint8_t value) {
_registers[reg] = value;
}
/*
Simulator specifics code..
*/
void Adafruit_MPR121::mockFilteredData(int reg, uint16_t value) {
_registers[MPR121_FILTDATA_0L + reg*2] = value & 0xffu;
_registers[MPR121_FILTDATA_0L + reg*2+1] = (value>>8) & 0xffu;
}

File diff suppressed because it is too large Load diff

View file

@ -1,337 +1,337 @@
/* Teensyduino Core Library
* http://www.pjrc.com/teensy/
* Copyright (c) 2017 PJRC.COM, LLC.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* 1. The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* 2. If the Software is incorporated into a build system that allows
* selection among a list of target devices, then similar target
* devices manufactured by PJRC.COM must be included in the list of
* target devices and selectable in the same manner.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
// Long ago this file contained code from Arduino.cc, which was
// Copyright (c) 2008 David A. Mellis. No substantial portion of
// Arduino's original code remains. In fact, several improvements
// developed for Teensyduino have made their way back into
// Arduino's code base. :-)
#include <Arduino.h>
#include "Print.h"
size_t Print::write(const uint8_t *buffer, size_t size)
{
size_t count = 0;
while (size--) count += write(*buffer++);
return count;
}
// size_t Print::print(const String &s)
// {
// uint8_t buffer[33];
// size_t count = 0;
// unsigned int index = 0;
// unsigned int len = s.length();
// while (len > 0) {
// s.getBytes(buffer, sizeof(buffer), index);
// unsigned int nbytes = len;
// if (nbytes > sizeof(buffer)-1) nbytes = sizeof(buffer)-1;
// index += nbytes;
// len -= nbytes;
// count += write(buffer, nbytes);
// }
// return count;
// }
size_t Print::print(long n)
{
uint8_t sign=0;
if (n < 0) {
sign = '-';
n = -n;
}
return printNumber(n, 10, sign);
}
size_t Print::println(void)
{
uint8_t buf[2]={'\r', '\n'};
return write(buf, 2);
}
extern "C" {
__attribute__((weak))
int _write(long file, char *ptr, int len)
{
((class Print *)file)->write((uint8_t *)ptr, len);
return len;
}
}
int Print::printf(const char *format, ...)
{
va_list ap;
va_start(ap, format);
#ifdef __STRICT_ANSI__
return 0; // TODO: make this work with -std=c++0x
#else
return vdprintf((int)this, format, ap);
#endif
}
int Print::printf(const __FlashStringHelper *format, ...)
{
va_list ap;
va_start(ap, format);
#ifdef __STRICT_ANSI__
return 0;
#else
return vdprintf((int)this, (const char *)format, ap);
#endif
}
#ifdef __MKL26Z64__
// optimized code inspired by Stimmer's optimization
// obviously a dit different, adapted to 32 bit Cortex-M0+
// http://forum.arduino.cc/index.php?topic=167414.msg1293679#msg1293679
// http://forum.arduino.cc/index.php?topic=167414.msg1309482#msg1309482
// equivelant code:
// mod = div % 10;
// div = div / 10;
// tmp1 = {random};
// tmp2 = 10;
#if 1
// https://forum.pjrc.com/threads/28932-LC-is-10-9-times-slower-than-T3-1?p=76072&viewfull=1#post76072
void inline divmod10_v2(uint32_t n,uint32_t *div,uint32_t *mod) {
uint32_t p,q;
/* Using 32.16 fixed point representation p.q */
/* p.q = (n+1)/512 */
q = (n&0xFFFF) + 1;
p = (n>>16);
/* p.q = 51*(n+1)/512 */
q = 13107*q;
p = 13107*p;
/* p.q = (1+1/2^8+1/2^16+1/2^24)*51*(n+1)/512 */
q = q + (q>>16) + (p&0xFFFF);
p = p + (p>>16) + (q>>16);
/* divide by 2 */
p = p>>1;
*div = p;
*mod = n-10*p;
}
#define divmod10_asm(div, mod, tmp1, tmp2, const3333) \
divmod10_v2(div, &div, &mod);
/*
#define divmod10_asm(div, mod, tmp1, tmp2, const3333) \
asm ( \
" lsr %2, %0, #16" "\n\t" \
" mul %2, %4" "\n\t" \
" uxth %1, %0" "\n\t" \
" mul %1, %4" "\n\t" \
" add %1, #1" "\n\t" \
" lsr %0, %2, #16" "\n\t" \
" lsl %2, %2, #16" "\n\t" \
" add %1, %2" "\n\t" \
" mov %3, #0" "\n\t" \
" adc %0, %3" "\n\t" \
" lsl %0, %0, #15" "\n\t" \
" lsr %2, %1, #17" "\n\t" \
" orr %0, %2" "\n\t" \
" lsl %1, %1, #15" "\n\t" \
" lsr %2, %1, #16" "\n\t" \
" lsl %3, %0, #16" "\n\t" \
" orr %2, %3" "\n\t" \
" lsr %3, %0, #16" "\n\t" \
" add %1, %0" "\n\t" \
" adc %0, %1" "\n\t" \
" sub %0, %1" "\n\t" \
" add %1, %2" "\n\t" \
" adc %0, %3" "\n\t" \
" lsr %1, %1, #4" "\n\t" \
" mov %3, #10" "\n\t" \
" mul %1, %3" "\n\t" \
" lsr %1, %1, #28" "\n\t" \
: "+l" (div), \
"=&l" (mod), \
"=&l" (tmp1), \
"=&l" (tmp2) \
: "l" (const3333) \
: \
)
*/
#else
#define divmod10_asm(_div, _mod, _tmp1, _tmp2, _const3333) \
({ _tmp1 = _div; _div = _div / 10; _mod = _tmp1 - _div * 10; })
// ({_mod = _div % 10, _div = _div / 10; })
#endif
size_t Print::printNumberDec(unsigned long n, uint8_t sign)
{
uint8_t buf[11], *p;
uint32_t digit;
//uint32_t t1, t2, c3333=0x3333;
p = buf + (sizeof(buf));
do {
uint32_t div;
divmod10_v2(n, &div, &digit);
n = div;
//divmod10_asm(n, digit, t1, t2, c3333);
*--p = digit + '0';
} while (n);
if (sign) *--p = '-';
return write(p, sizeof(buf) - (p - buf));
}
size_t Print::printNumberHex(unsigned long n)
{
uint8_t digit, buf[8], *p;
p = buf + (sizeof(buf));
do {
digit = n & 15;
*--p = (digit < 10) ? '0' + digit : 'A' + digit - 10;
n >>= 4;
} while (n);
return write(p, sizeof(buf) - (p - buf));
}
size_t Print::printNumberBin(unsigned long n)
{
uint8_t buf[32], *p;
p = buf + (sizeof(buf));
do {
*--p = '0' + ((uint8_t)n & 1);
n >>= 1;
} while (n);
return write(p, sizeof(buf) - (p - buf));
}
size_t Print::printNumberAny(unsigned long n, uint8_t base)
{
uint8_t digit, buf[21], *p;
uint32_t tmp;
p = buf + sizeof(buf);
do {
tmp = n;
n = n / base;
digit = tmp - n * base;
*--p = (digit < 10) ? '0' + digit : 'A' + digit - 10;
} while (n);
return write(p, sizeof(buf) - (p - buf));
}
#else
size_t Print::printNumber(unsigned long n, uint8_t base, uint8_t sign)
{
uint8_t buf[34];
uint8_t digit, i;
// TODO: make these checks as inline, since base is
// almost always a constant. base = 0 (BYTE) should
// inline as a call directly to write()
if (base == 0) {
return write((uint8_t)n);
} else if (base == 1) {
base = 10;
}
if (n == 0) {
buf[sizeof(buf) - 1] = '0';
i = sizeof(buf) - 1;
} else {
i = sizeof(buf) - 1;
while (1) {
digit = n % base;
buf[i] = ((digit < 10) ? '0' + digit : 'A' + digit - 10);
n /= base;
if (n == 0) break;
i--;
}
}
if (sign) {
i--;
buf[i] = '-';
}
return write(buf + i, sizeof(buf) - i);
}
#endif
size_t Print::printFloat(double number, uint8_t digits)
{
uint8_t sign=0;
size_t count=0;
if (isnan(number)) return print("nan");
if (isinf(number)) return print("inf");
if (number > 4294967040.0f) return print("ovf"); // constant determined empirically
if (number <-4294967040.0f) return print("ovf"); // constant determined empirically
// Handle negative numbers
if (number < 0.0) {
sign = 1;
number = -number;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i) {
rounding *= 0.1;
}
number += rounding;
// Extract the integer part of the number and print it
unsigned long int_part = (unsigned long)number;
double remainder = number - (double)int_part;
count += printNumber(int_part, 10, sign);
// Print the decimal point, but only if there are digits beyond
if (digits > 0) {
uint8_t n, buf[16], count=1;
buf[0] = '.';
// Extract digits from the remainder one at a time
if (digits > sizeof(buf) - 1) digits = sizeof(buf) - 1;
while (digits-- > 0) {
remainder *= 10.0;
n = (uint8_t)(remainder);
buf[count++] = '0' + n;
remainder -= n;
}
count += write(buf, count);
}
return count;
}
/* Teensyduino Core Library
* http://www.pjrc.com/teensy/
* Copyright (c) 2017 PJRC.COM, LLC.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* 1. The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* 2. If the Software is incorporated into a build system that allows
* selection among a list of target devices, then similar target
* devices manufactured by PJRC.COM must be included in the list of
* target devices and selectable in the same manner.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
// Long ago this file contained code from Arduino.cc, which was
// Copyright (c) 2008 David A. Mellis. No substantial portion of
// Arduino's original code remains. In fact, several improvements
// developed for Teensyduino have made their way back into
// Arduino's code base. :-)
#include <Arduino.h>
#include "Print.h"
size_t Print::write(const uint8_t *buffer, size_t size)
{
size_t count = 0;
while (size--) count += write(*buffer++);
return count;
}
// size_t Print::print(const String &s)
// {
// uint8_t buffer[33];
// size_t count = 0;
// unsigned int index = 0;
// unsigned int len = s.length();
// while (len > 0) {
// s.getBytes(buffer, sizeof(buffer), index);
// unsigned int nbytes = len;
// if (nbytes > sizeof(buffer)-1) nbytes = sizeof(buffer)-1;
// index += nbytes;
// len -= nbytes;
// count += write(buffer, nbytes);
// }
// return count;
// }
size_t Print::print(long n)
{
uint8_t sign=0;
if (n < 0) {
sign = '-';
n = -n;
}
return printNumber(n, 10, sign);
}
size_t Print::println(void)
{
uint8_t buf[2]={'\r', '\n'};
return write(buf, 2);
}
extern "C" {
__attribute__((weak))
int _write(long file, char *ptr, int len)
{
((class Print *)file)->write((uint8_t *)ptr, len);
return len;
}
}
int Print::printf(const char *format, ...)
{
va_list ap;
va_start(ap, format);
#ifdef __STRICT_ANSI__
return 0; // TODO: make this work with -std=c++0x
#else
return vdprintf((int)this, format, ap);
#endif
}
int Print::printf(const __FlashStringHelper *format, ...)
{
va_list ap;
va_start(ap, format);
#ifdef __STRICT_ANSI__
return 0;
#else
return vdprintf((int)this, (const char *)format, ap);
#endif
}
#ifdef __MKL26Z64__
// optimized code inspired by Stimmer's optimization
// obviously a dit different, adapted to 32 bit Cortex-M0+
// http://forum.arduino.cc/index.php?topic=167414.msg1293679#msg1293679
// http://forum.arduino.cc/index.php?topic=167414.msg1309482#msg1309482
// equivelant code:
// mod = div % 10;
// div = div / 10;
// tmp1 = {random};
// tmp2 = 10;
#if 1
// https://forum.pjrc.com/threads/28932-LC-is-10-9-times-slower-than-T3-1?p=76072&viewfull=1#post76072
void inline divmod10_v2(uint32_t n,uint32_t *div,uint32_t *mod) {
uint32_t p,q;
/* Using 32.16 fixed point representation p.q */
/* p.q = (n+1)/512 */
q = (n&0xFFFF) + 1;
p = (n>>16);
/* p.q = 51*(n+1)/512 */
q = 13107*q;
p = 13107*p;
/* p.q = (1+1/2^8+1/2^16+1/2^24)*51*(n+1)/512 */
q = q + (q>>16) + (p&0xFFFF);
p = p + (p>>16) + (q>>16);
/* divide by 2 */
p = p>>1;
*div = p;
*mod = n-10*p;
}
#define divmod10_asm(div, mod, tmp1, tmp2, const3333) \
divmod10_v2(div, &div, &mod);
/*
#define divmod10_asm(div, mod, tmp1, tmp2, const3333) \
asm ( \
" lsr %2, %0, #16" "\n\t" \
" mul %2, %4" "\n\t" \
" uxth %1, %0" "\n\t" \
" mul %1, %4" "\n\t" \
" add %1, #1" "\n\t" \
" lsr %0, %2, #16" "\n\t" \
" lsl %2, %2, #16" "\n\t" \
" add %1, %2" "\n\t" \
" mov %3, #0" "\n\t" \
" adc %0, %3" "\n\t" \
" lsl %0, %0, #15" "\n\t" \
" lsr %2, %1, #17" "\n\t" \
" orr %0, %2" "\n\t" \
" lsl %1, %1, #15" "\n\t" \
" lsr %2, %1, #16" "\n\t" \
" lsl %3, %0, #16" "\n\t" \
" orr %2, %3" "\n\t" \
" lsr %3, %0, #16" "\n\t" \
" add %1, %0" "\n\t" \
" adc %0, %1" "\n\t" \
" sub %0, %1" "\n\t" \
" add %1, %2" "\n\t" \
" adc %0, %3" "\n\t" \
" lsr %1, %1, #4" "\n\t" \
" mov %3, #10" "\n\t" \
" mul %1, %3" "\n\t" \
" lsr %1, %1, #28" "\n\t" \
: "+l" (div), \
"=&l" (mod), \
"=&l" (tmp1), \
"=&l" (tmp2) \
: "l" (const3333) \
: \
)
*/
#else
#define divmod10_asm(_div, _mod, _tmp1, _tmp2, _const3333) \
({ _tmp1 = _div; _div = _div / 10; _mod = _tmp1 - _div * 10; })
// ({_mod = _div % 10, _div = _div / 10; })
#endif
size_t Print::printNumberDec(unsigned long n, uint8_t sign)
{
uint8_t buf[11], *p;
uint32_t digit;
//uint32_t t1, t2, c3333=0x3333;
p = buf + (sizeof(buf));
do {
uint32_t div;
divmod10_v2(n, &div, &digit);
n = div;
//divmod10_asm(n, digit, t1, t2, c3333);
*--p = digit + '0';
} while (n);
if (sign) *--p = '-';
return write(p, sizeof(buf) - (p - buf));
}
size_t Print::printNumberHex(unsigned long n)
{
uint8_t digit, buf[8], *p;
p = buf + (sizeof(buf));
do {
digit = n & 15;
*--p = (digit < 10) ? '0' + digit : 'A' + digit - 10;
n >>= 4;
} while (n);
return write(p, sizeof(buf) - (p - buf));
}
size_t Print::printNumberBin(unsigned long n)
{
uint8_t buf[32], *p;
p = buf + (sizeof(buf));
do {
*--p = '0' + ((uint8_t)n & 1);
n >>= 1;
} while (n);
return write(p, sizeof(buf) - (p - buf));
}
size_t Print::printNumberAny(unsigned long n, uint8_t base)
{
uint8_t digit, buf[21], *p;
uint32_t tmp;
p = buf + sizeof(buf);
do {
tmp = n;
n = n / base;
digit = tmp - n * base;
*--p = (digit < 10) ? '0' + digit : 'A' + digit - 10;
} while (n);
return write(p, sizeof(buf) - (p - buf));
}
#else
size_t Print::printNumber(unsigned long n, uint8_t base, uint8_t sign)
{
uint8_t buf[34];
uint8_t digit, i;
// TODO: make these checks as inline, since base is
// almost always a constant. base = 0 (BYTE) should
// inline as a call directly to write()
if (base == 0) {
return write((uint8_t)n);
} else if (base == 1) {
base = 10;
}
if (n == 0) {
buf[sizeof(buf) - 1] = '0';
i = sizeof(buf) - 1;
} else {
i = sizeof(buf) - 1;
while (1) {
digit = n % base;
buf[i] = ((digit < 10) ? '0' + digit : 'A' + digit - 10);
n /= base;
if (n == 0) break;
i--;
}
}
if (sign) {
i--;
buf[i] = '-';
}
return write(buf + i, sizeof(buf) - i);
}
#endif
size_t Print::printFloat(double number, uint8_t digits)
{
uint8_t sign=0;
size_t count=0;
if (isnan(number)) return print("nan");
if (isinf(number)) return print("inf");
if (number > 4294967040.0f) return print("ovf"); // constant determined empirically
if (number <-4294967040.0f) return print("ovf"); // constant determined empirically
// Handle negative numbers
if (number < 0.0) {
sign = 1;
number = -number;
}
// Round correctly so that print(1.999, 2) prints as "2.00"
double rounding = 0.5;
for (uint8_t i=0; i<digits; ++i) {
rounding *= 0.1;
}
number += rounding;
// Extract the integer part of the number and print it
unsigned long int_part = (unsigned long)number;
double remainder = number - (double)int_part;
count += printNumber(int_part, 10, sign);
// Print the decimal point, but only if there are digits beyond
if (digits > 0) {
uint8_t n, buf[16], count=1;
buf[0] = '.';
// Extract digits from the remainder one at a time
if (digits > sizeof(buf) - 1) digits = sizeof(buf) - 1;
while (digits-- > 0) {
remainder *= 10.0;
n = (uint8_t)(remainder);
buf[count++] = '0' + n;
remainder -= n;
}
count += write(buf, count);
}
return count;
}

File diff suppressed because it is too large Load diff

View file

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

View file

@ -1,276 +1,276 @@
// This is the 'classic' fixed-space bitmap font for Adafruit_GFX since 1.0.
// See gfxfont.h for newer custom bitmap font info.
#ifndef FONT5X7_H
#define FONT5X7_H
#ifdef __AVR__
#include <avr/io.h>
#include <avr/pgmspace.h>
#elif defined(ESP8266)
#include <pgmspace.h>
#else
#define PROGMEM
#endif
// Standard ASCII 5x7 font
static const unsigned char font[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00,
0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
0x18, 0x3C, 0x7E, 0x3C, 0x18,
0x1C, 0x57, 0x7D, 0x57, 0x1C,
0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
0x00, 0x18, 0x3C, 0x18, 0x00,
0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
0x00, 0x18, 0x24, 0x18, 0x00,
0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
0x30, 0x48, 0x3A, 0x06, 0x0E,
0x26, 0x29, 0x79, 0x29, 0x26,
0x40, 0x7F, 0x05, 0x05, 0x07,
0x40, 0x7F, 0x05, 0x25, 0x3F,
0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
0x7F, 0x3E, 0x1C, 0x1C, 0x08,
0x08, 0x1C, 0x1C, 0x3E, 0x7F,
0x14, 0x22, 0x7F, 0x22, 0x14,
0x5F, 0x5F, 0x00, 0x5F, 0x5F,
0x06, 0x09, 0x7F, 0x01, 0x7F,
0x00, 0x66, 0x89, 0x95, 0x6A,
0x60, 0x60, 0x60, 0x60, 0x60,
0x94, 0xA2, 0xFF, 0xA2, 0x94,
0x08, 0x04, 0x7E, 0x04, 0x08,
0x10, 0x20, 0x7E, 0x20, 0x10,
0x08, 0x08, 0x2A, 0x1C, 0x08,
0x08, 0x1C, 0x2A, 0x08, 0x08,
0x1E, 0x10, 0x10, 0x10, 0x10,
0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
0x30, 0x38, 0x3E, 0x38, 0x30,
0x06, 0x0E, 0x3E, 0x0E, 0x06,
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x5F, 0x00, 0x00,
0x00, 0x07, 0x00, 0x07, 0x00,
0x14, 0x7F, 0x14, 0x7F, 0x14,
0x24, 0x2A, 0x7F, 0x2A, 0x12,
0x23, 0x13, 0x08, 0x64, 0x62,
0x36, 0x49, 0x56, 0x20, 0x50,
0x00, 0x08, 0x07, 0x03, 0x00,
0x00, 0x1C, 0x22, 0x41, 0x00,
0x00, 0x41, 0x22, 0x1C, 0x00,
0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
0x08, 0x08, 0x3E, 0x08, 0x08,
0x00, 0x80, 0x70, 0x30, 0x00,
0x08, 0x08, 0x08, 0x08, 0x08,
0x00, 0x00, 0x60, 0x60, 0x00,
0x20, 0x10, 0x08, 0x04, 0x02,
0x3E, 0x51, 0x49, 0x45, 0x3E,
0x00, 0x42, 0x7F, 0x40, 0x00,
0x72, 0x49, 0x49, 0x49, 0x46,
0x21, 0x41, 0x49, 0x4D, 0x33,
0x18, 0x14, 0x12, 0x7F, 0x10,
0x27, 0x45, 0x45, 0x45, 0x39,
0x3C, 0x4A, 0x49, 0x49, 0x31,
0x41, 0x21, 0x11, 0x09, 0x07,
0x36, 0x49, 0x49, 0x49, 0x36,
0x46, 0x49, 0x49, 0x29, 0x1E,
0x00, 0x00, 0x14, 0x00, 0x00,
0x00, 0x40, 0x34, 0x00, 0x00,
0x00, 0x08, 0x14, 0x22, 0x41,
0x14, 0x14, 0x14, 0x14, 0x14,
0x00, 0x41, 0x22, 0x14, 0x08,
0x02, 0x01, 0x59, 0x09, 0x06,
0x3E, 0x41, 0x5D, 0x59, 0x4E,
0x7C, 0x12, 0x11, 0x12, 0x7C,
0x7F, 0x49, 0x49, 0x49, 0x36,
0x3E, 0x41, 0x41, 0x41, 0x22,
0x7F, 0x41, 0x41, 0x41, 0x3E,
0x7F, 0x49, 0x49, 0x49, 0x41,
0x7F, 0x09, 0x09, 0x09, 0x01,
0x3E, 0x41, 0x41, 0x51, 0x73,
0x7F, 0x08, 0x08, 0x08, 0x7F,
0x00, 0x41, 0x7F, 0x41, 0x00,
0x20, 0x40, 0x41, 0x3F, 0x01,
0x7F, 0x08, 0x14, 0x22, 0x41,
0x7F, 0x40, 0x40, 0x40, 0x40,
0x7F, 0x02, 0x1C, 0x02, 0x7F,
0x7F, 0x04, 0x08, 0x10, 0x7F,
0x3E, 0x41, 0x41, 0x41, 0x3E,
0x7F, 0x09, 0x09, 0x09, 0x06,
0x3E, 0x41, 0x51, 0x21, 0x5E,
0x7F, 0x09, 0x19, 0x29, 0x46,
0x26, 0x49, 0x49, 0x49, 0x32,
0x03, 0x01, 0x7F, 0x01, 0x03,
0x3F, 0x40, 0x40, 0x40, 0x3F,
0x1F, 0x20, 0x40, 0x20, 0x1F,
0x3F, 0x40, 0x38, 0x40, 0x3F,
0x63, 0x14, 0x08, 0x14, 0x63,
0x03, 0x04, 0x78, 0x04, 0x03,
0x61, 0x59, 0x49, 0x4D, 0x43,
0x00, 0x7F, 0x41, 0x41, 0x41,
0x02, 0x04, 0x08, 0x10, 0x20,
0x00, 0x41, 0x41, 0x41, 0x7F,
0x04, 0x02, 0x01, 0x02, 0x04,
0x40, 0x40, 0x40, 0x40, 0x40,
0x00, 0x03, 0x07, 0x08, 0x00,
0x20, 0x54, 0x54, 0x78, 0x40,
0x7F, 0x28, 0x44, 0x44, 0x38,
0x38, 0x44, 0x44, 0x44, 0x28,
0x38, 0x44, 0x44, 0x28, 0x7F,
0x38, 0x54, 0x54, 0x54, 0x18,
0x00, 0x08, 0x7E, 0x09, 0x02,
0x18, 0xA4, 0xA4, 0x9C, 0x78,
0x7F, 0x08, 0x04, 0x04, 0x78,
0x00, 0x44, 0x7D, 0x40, 0x00,
0x20, 0x40, 0x40, 0x3D, 0x00,
0x7F, 0x10, 0x28, 0x44, 0x00,
0x00, 0x41, 0x7F, 0x40, 0x00,
0x7C, 0x04, 0x78, 0x04, 0x78,
0x7C, 0x08, 0x04, 0x04, 0x78,
0x38, 0x44, 0x44, 0x44, 0x38,
0xFC, 0x18, 0x24, 0x24, 0x18,
0x18, 0x24, 0x24, 0x18, 0xFC,
0x7C, 0x08, 0x04, 0x04, 0x08,
0x48, 0x54, 0x54, 0x54, 0x24,
0x04, 0x04, 0x3F, 0x44, 0x24,
0x3C, 0x40, 0x40, 0x20, 0x7C,
0x1C, 0x20, 0x40, 0x20, 0x1C,
0x3C, 0x40, 0x30, 0x40, 0x3C,
0x44, 0x28, 0x10, 0x28, 0x44,
0x4C, 0x90, 0x90, 0x90, 0x7C,
0x44, 0x64, 0x54, 0x4C, 0x44,
0x00, 0x08, 0x36, 0x41, 0x00,
0x00, 0x00, 0x77, 0x00, 0x00,
0x00, 0x41, 0x36, 0x08, 0x00,
0x02, 0x01, 0x02, 0x04, 0x02,
0x3C, 0x26, 0x23, 0x26, 0x3C,
0x1E, 0xA1, 0xA1, 0x61, 0x12,
0x3A, 0x40, 0x40, 0x20, 0x7A,
0x38, 0x54, 0x54, 0x55, 0x59,
0x21, 0x55, 0x55, 0x79, 0x41,
0x22, 0x54, 0x54, 0x78, 0x42, // a-umlaut
0x21, 0x55, 0x54, 0x78, 0x40,
0x20, 0x54, 0x55, 0x79, 0x40,
0x0C, 0x1E, 0x52, 0x72, 0x12,
0x39, 0x55, 0x55, 0x55, 0x59,
0x39, 0x54, 0x54, 0x54, 0x59,
0x39, 0x55, 0x54, 0x54, 0x58,
0x00, 0x00, 0x45, 0x7C, 0x41,
0x00, 0x02, 0x45, 0x7D, 0x42,
0x00, 0x01, 0x45, 0x7C, 0x40,
0x7D, 0x12, 0x11, 0x12, 0x7D, // A-umlaut
0xF0, 0x28, 0x25, 0x28, 0xF0,
0x7C, 0x54, 0x55, 0x45, 0x00,
0x20, 0x54, 0x54, 0x7C, 0x54,
0x7C, 0x0A, 0x09, 0x7F, 0x49,
0x32, 0x49, 0x49, 0x49, 0x32,
0x3A, 0x44, 0x44, 0x44, 0x3A, // o-umlaut
0x32, 0x4A, 0x48, 0x48, 0x30,
0x3A, 0x41, 0x41, 0x21, 0x7A,
0x3A, 0x42, 0x40, 0x20, 0x78,
0x00, 0x9D, 0xA0, 0xA0, 0x7D,
0x3D, 0x42, 0x42, 0x42, 0x3D, // O-umlaut
0x3D, 0x40, 0x40, 0x40, 0x3D,
0x3C, 0x24, 0xFF, 0x24, 0x24,
0x48, 0x7E, 0x49, 0x43, 0x66,
0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
0xFF, 0x09, 0x29, 0xF6, 0x20,
0xC0, 0x88, 0x7E, 0x09, 0x03,
0x20, 0x54, 0x54, 0x79, 0x41,
0x00, 0x00, 0x44, 0x7D, 0x41,
0x30, 0x48, 0x48, 0x4A, 0x32,
0x38, 0x40, 0x40, 0x22, 0x7A,
0x00, 0x7A, 0x0A, 0x0A, 0x72,
0x7D, 0x0D, 0x19, 0x31, 0x7D,
0x26, 0x29, 0x29, 0x2F, 0x28,
0x26, 0x29, 0x29, 0x29, 0x26,
0x30, 0x48, 0x4D, 0x40, 0x20,
0x38, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x38,
0x2F, 0x10, 0xC8, 0xAC, 0xBA,
0x2F, 0x10, 0x28, 0x34, 0xFA,
0x00, 0x00, 0x7B, 0x00, 0x00,
0x08, 0x14, 0x2A, 0x14, 0x22,
0x22, 0x14, 0x2A, 0x14, 0x08,
0x55, 0x00, 0x55, 0x00, 0x55, // #176 (25% block) missing in old code
0xAA, 0x55, 0xAA, 0x55, 0xAA, // 50% block
0xFF, 0x55, 0xFF, 0x55, 0xFF, // 75% block
0x00, 0x00, 0x00, 0xFF, 0x00,
0x10, 0x10, 0x10, 0xFF, 0x00,
0x14, 0x14, 0x14, 0xFF, 0x00,
0x10, 0x10, 0xFF, 0x00, 0xFF,
0x10, 0x10, 0xF0, 0x10, 0xF0,
0x14, 0x14, 0x14, 0xFC, 0x00,
0x14, 0x14, 0xF7, 0x00, 0xFF,
0x00, 0x00, 0xFF, 0x00, 0xFF,
0x14, 0x14, 0xF4, 0x04, 0xFC,
0x14, 0x14, 0x17, 0x10, 0x1F,
0x10, 0x10, 0x1F, 0x10, 0x1F,
0x14, 0x14, 0x14, 0x1F, 0x00,
0x10, 0x10, 0x10, 0xF0, 0x00,
0x00, 0x00, 0x00, 0x1F, 0x10,
0x10, 0x10, 0x10, 0x1F, 0x10,
0x10, 0x10, 0x10, 0xF0, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0xFF, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x14,
0x00, 0x00, 0xFF, 0x00, 0xFF,
0x00, 0x00, 0x1F, 0x10, 0x17,
0x00, 0x00, 0xFC, 0x04, 0xF4,
0x14, 0x14, 0x17, 0x10, 0x17,
0x14, 0x14, 0xF4, 0x04, 0xF4,
0x00, 0x00, 0xFF, 0x00, 0xF7,
0x14, 0x14, 0x14, 0x14, 0x14,
0x14, 0x14, 0xF7, 0x00, 0xF7,
0x14, 0x14, 0x14, 0x17, 0x14,
0x10, 0x10, 0x1F, 0x10, 0x1F,
0x14, 0x14, 0x14, 0xF4, 0x14,
0x10, 0x10, 0xF0, 0x10, 0xF0,
0x00, 0x00, 0x1F, 0x10, 0x1F,
0x00, 0x00, 0x00, 0x1F, 0x14,
0x00, 0x00, 0x00, 0xFC, 0x14,
0x00, 0x00, 0xF0, 0x10, 0xF0,
0x10, 0x10, 0xFF, 0x10, 0xFF,
0x14, 0x14, 0x14, 0xFF, 0x14,
0x10, 0x10, 0x10, 0x1F, 0x00,
0x00, 0x00, 0x00, 0xF0, 0x10,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xFF, 0xFF, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFF, 0xFF,
0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
0x38, 0x44, 0x44, 0x38, 0x44,
0xFC, 0x4A, 0x4A, 0x4A, 0x34, // sharp-s or beta
0x7E, 0x02, 0x02, 0x06, 0x06,
0x02, 0x7E, 0x02, 0x7E, 0x02,
0x63, 0x55, 0x49, 0x41, 0x63,
0x38, 0x44, 0x44, 0x3C, 0x04,
0x40, 0x7E, 0x20, 0x1E, 0x20,
0x06, 0x02, 0x7E, 0x02, 0x02,
0x99, 0xA5, 0xE7, 0xA5, 0x99,
0x1C, 0x2A, 0x49, 0x2A, 0x1C,
0x4C, 0x72, 0x01, 0x72, 0x4C,
0x30, 0x4A, 0x4D, 0x4D, 0x30,
0x30, 0x48, 0x78, 0x48, 0x30,
0xBC, 0x62, 0x5A, 0x46, 0x3D,
0x3E, 0x49, 0x49, 0x49, 0x00,
0x7E, 0x01, 0x01, 0x01, 0x7E,
0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
0x44, 0x44, 0x5F, 0x44, 0x44,
0x40, 0x51, 0x4A, 0x44, 0x40,
0x40, 0x44, 0x4A, 0x51, 0x40,
0x00, 0x00, 0xFF, 0x01, 0x03,
0xE0, 0x80, 0xFF, 0x00, 0x00,
0x08, 0x08, 0x6B, 0x6B, 0x08,
0x36, 0x12, 0x36, 0x24, 0x36,
0x06, 0x0F, 0x09, 0x0F, 0x06,
0x00, 0x00, 0x18, 0x18, 0x00,
0x00, 0x00, 0x10, 0x10, 0x00,
0x30, 0x40, 0xFF, 0x01, 0x01,
0x00, 0x1F, 0x01, 0x01, 0x1E,
0x00, 0x19, 0x1D, 0x17, 0x12,
0x00, 0x3C, 0x3C, 0x3C, 0x3C,
0x00, 0x00, 0x00, 0x00, 0x00 // #255 NBSP
};
#endif // FONT5X7_H
// This is the 'classic' fixed-space bitmap font for Adafruit_GFX since 1.0.
// See gfxfont.h for newer custom bitmap font info.
#ifndef FONT5X7_H
#define FONT5X7_H
#ifdef __AVR__
#include <avr/io.h>
#include <avr/pgmspace.h>
#elif defined(ESP8266)
#include <pgmspace.h>
#else
#define PROGMEM
#endif
// Standard ASCII 5x7 font
static const unsigned char font[] PROGMEM = {
0x00, 0x00, 0x00, 0x00, 0x00,
0x3E, 0x5B, 0x4F, 0x5B, 0x3E,
0x3E, 0x6B, 0x4F, 0x6B, 0x3E,
0x1C, 0x3E, 0x7C, 0x3E, 0x1C,
0x18, 0x3C, 0x7E, 0x3C, 0x18,
0x1C, 0x57, 0x7D, 0x57, 0x1C,
0x1C, 0x5E, 0x7F, 0x5E, 0x1C,
0x00, 0x18, 0x3C, 0x18, 0x00,
0xFF, 0xE7, 0xC3, 0xE7, 0xFF,
0x00, 0x18, 0x24, 0x18, 0x00,
0xFF, 0xE7, 0xDB, 0xE7, 0xFF,
0x30, 0x48, 0x3A, 0x06, 0x0E,
0x26, 0x29, 0x79, 0x29, 0x26,
0x40, 0x7F, 0x05, 0x05, 0x07,
0x40, 0x7F, 0x05, 0x25, 0x3F,
0x5A, 0x3C, 0xE7, 0x3C, 0x5A,
0x7F, 0x3E, 0x1C, 0x1C, 0x08,
0x08, 0x1C, 0x1C, 0x3E, 0x7F,
0x14, 0x22, 0x7F, 0x22, 0x14,
0x5F, 0x5F, 0x00, 0x5F, 0x5F,
0x06, 0x09, 0x7F, 0x01, 0x7F,
0x00, 0x66, 0x89, 0x95, 0x6A,
0x60, 0x60, 0x60, 0x60, 0x60,
0x94, 0xA2, 0xFF, 0xA2, 0x94,
0x08, 0x04, 0x7E, 0x04, 0x08,
0x10, 0x20, 0x7E, 0x20, 0x10,
0x08, 0x08, 0x2A, 0x1C, 0x08,
0x08, 0x1C, 0x2A, 0x08, 0x08,
0x1E, 0x10, 0x10, 0x10, 0x10,
0x0C, 0x1E, 0x0C, 0x1E, 0x0C,
0x30, 0x38, 0x3E, 0x38, 0x30,
0x06, 0x0E, 0x3E, 0x0E, 0x06,
0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x5F, 0x00, 0x00,
0x00, 0x07, 0x00, 0x07, 0x00,
0x14, 0x7F, 0x14, 0x7F, 0x14,
0x24, 0x2A, 0x7F, 0x2A, 0x12,
0x23, 0x13, 0x08, 0x64, 0x62,
0x36, 0x49, 0x56, 0x20, 0x50,
0x00, 0x08, 0x07, 0x03, 0x00,
0x00, 0x1C, 0x22, 0x41, 0x00,
0x00, 0x41, 0x22, 0x1C, 0x00,
0x2A, 0x1C, 0x7F, 0x1C, 0x2A,
0x08, 0x08, 0x3E, 0x08, 0x08,
0x00, 0x80, 0x70, 0x30, 0x00,
0x08, 0x08, 0x08, 0x08, 0x08,
0x00, 0x00, 0x60, 0x60, 0x00,
0x20, 0x10, 0x08, 0x04, 0x02,
0x3E, 0x51, 0x49, 0x45, 0x3E,
0x00, 0x42, 0x7F, 0x40, 0x00,
0x72, 0x49, 0x49, 0x49, 0x46,
0x21, 0x41, 0x49, 0x4D, 0x33,
0x18, 0x14, 0x12, 0x7F, 0x10,
0x27, 0x45, 0x45, 0x45, 0x39,
0x3C, 0x4A, 0x49, 0x49, 0x31,
0x41, 0x21, 0x11, 0x09, 0x07,
0x36, 0x49, 0x49, 0x49, 0x36,
0x46, 0x49, 0x49, 0x29, 0x1E,
0x00, 0x00, 0x14, 0x00, 0x00,
0x00, 0x40, 0x34, 0x00, 0x00,
0x00, 0x08, 0x14, 0x22, 0x41,
0x14, 0x14, 0x14, 0x14, 0x14,
0x00, 0x41, 0x22, 0x14, 0x08,
0x02, 0x01, 0x59, 0x09, 0x06,
0x3E, 0x41, 0x5D, 0x59, 0x4E,
0x7C, 0x12, 0x11, 0x12, 0x7C,
0x7F, 0x49, 0x49, 0x49, 0x36,
0x3E, 0x41, 0x41, 0x41, 0x22,
0x7F, 0x41, 0x41, 0x41, 0x3E,
0x7F, 0x49, 0x49, 0x49, 0x41,
0x7F, 0x09, 0x09, 0x09, 0x01,
0x3E, 0x41, 0x41, 0x51, 0x73,
0x7F, 0x08, 0x08, 0x08, 0x7F,
0x00, 0x41, 0x7F, 0x41, 0x00,
0x20, 0x40, 0x41, 0x3F, 0x01,
0x7F, 0x08, 0x14, 0x22, 0x41,
0x7F, 0x40, 0x40, 0x40, 0x40,
0x7F, 0x02, 0x1C, 0x02, 0x7F,
0x7F, 0x04, 0x08, 0x10, 0x7F,
0x3E, 0x41, 0x41, 0x41, 0x3E,
0x7F, 0x09, 0x09, 0x09, 0x06,
0x3E, 0x41, 0x51, 0x21, 0x5E,
0x7F, 0x09, 0x19, 0x29, 0x46,
0x26, 0x49, 0x49, 0x49, 0x32,
0x03, 0x01, 0x7F, 0x01, 0x03,
0x3F, 0x40, 0x40, 0x40, 0x3F,
0x1F, 0x20, 0x40, 0x20, 0x1F,
0x3F, 0x40, 0x38, 0x40, 0x3F,
0x63, 0x14, 0x08, 0x14, 0x63,
0x03, 0x04, 0x78, 0x04, 0x03,
0x61, 0x59, 0x49, 0x4D, 0x43,
0x00, 0x7F, 0x41, 0x41, 0x41,
0x02, 0x04, 0x08, 0x10, 0x20,
0x00, 0x41, 0x41, 0x41, 0x7F,
0x04, 0x02, 0x01, 0x02, 0x04,
0x40, 0x40, 0x40, 0x40, 0x40,
0x00, 0x03, 0x07, 0x08, 0x00,
0x20, 0x54, 0x54, 0x78, 0x40,
0x7F, 0x28, 0x44, 0x44, 0x38,
0x38, 0x44, 0x44, 0x44, 0x28,
0x38, 0x44, 0x44, 0x28, 0x7F,
0x38, 0x54, 0x54, 0x54, 0x18,
0x00, 0x08, 0x7E, 0x09, 0x02,
0x18, 0xA4, 0xA4, 0x9C, 0x78,
0x7F, 0x08, 0x04, 0x04, 0x78,
0x00, 0x44, 0x7D, 0x40, 0x00,
0x20, 0x40, 0x40, 0x3D, 0x00,
0x7F, 0x10, 0x28, 0x44, 0x00,
0x00, 0x41, 0x7F, 0x40, 0x00,
0x7C, 0x04, 0x78, 0x04, 0x78,
0x7C, 0x08, 0x04, 0x04, 0x78,
0x38, 0x44, 0x44, 0x44, 0x38,
0xFC, 0x18, 0x24, 0x24, 0x18,
0x18, 0x24, 0x24, 0x18, 0xFC,
0x7C, 0x08, 0x04, 0x04, 0x08,
0x48, 0x54, 0x54, 0x54, 0x24,
0x04, 0x04, 0x3F, 0x44, 0x24,
0x3C, 0x40, 0x40, 0x20, 0x7C,
0x1C, 0x20, 0x40, 0x20, 0x1C,
0x3C, 0x40, 0x30, 0x40, 0x3C,
0x44, 0x28, 0x10, 0x28, 0x44,
0x4C, 0x90, 0x90, 0x90, 0x7C,
0x44, 0x64, 0x54, 0x4C, 0x44,
0x00, 0x08, 0x36, 0x41, 0x00,
0x00, 0x00, 0x77, 0x00, 0x00,
0x00, 0x41, 0x36, 0x08, 0x00,
0x02, 0x01, 0x02, 0x04, 0x02,
0x3C, 0x26, 0x23, 0x26, 0x3C,
0x1E, 0xA1, 0xA1, 0x61, 0x12,
0x3A, 0x40, 0x40, 0x20, 0x7A,
0x38, 0x54, 0x54, 0x55, 0x59,
0x21, 0x55, 0x55, 0x79, 0x41,
0x22, 0x54, 0x54, 0x78, 0x42, // a-umlaut
0x21, 0x55, 0x54, 0x78, 0x40,
0x20, 0x54, 0x55, 0x79, 0x40,
0x0C, 0x1E, 0x52, 0x72, 0x12,
0x39, 0x55, 0x55, 0x55, 0x59,
0x39, 0x54, 0x54, 0x54, 0x59,
0x39, 0x55, 0x54, 0x54, 0x58,
0x00, 0x00, 0x45, 0x7C, 0x41,
0x00, 0x02, 0x45, 0x7D, 0x42,
0x00, 0x01, 0x45, 0x7C, 0x40,
0x7D, 0x12, 0x11, 0x12, 0x7D, // A-umlaut
0xF0, 0x28, 0x25, 0x28, 0xF0,
0x7C, 0x54, 0x55, 0x45, 0x00,
0x20, 0x54, 0x54, 0x7C, 0x54,
0x7C, 0x0A, 0x09, 0x7F, 0x49,
0x32, 0x49, 0x49, 0x49, 0x32,
0x3A, 0x44, 0x44, 0x44, 0x3A, // o-umlaut
0x32, 0x4A, 0x48, 0x48, 0x30,
0x3A, 0x41, 0x41, 0x21, 0x7A,
0x3A, 0x42, 0x40, 0x20, 0x78,
0x00, 0x9D, 0xA0, 0xA0, 0x7D,
0x3D, 0x42, 0x42, 0x42, 0x3D, // O-umlaut
0x3D, 0x40, 0x40, 0x40, 0x3D,
0x3C, 0x24, 0xFF, 0x24, 0x24,
0x48, 0x7E, 0x49, 0x43, 0x66,
0x2B, 0x2F, 0xFC, 0x2F, 0x2B,
0xFF, 0x09, 0x29, 0xF6, 0x20,
0xC0, 0x88, 0x7E, 0x09, 0x03,
0x20, 0x54, 0x54, 0x79, 0x41,
0x00, 0x00, 0x44, 0x7D, 0x41,
0x30, 0x48, 0x48, 0x4A, 0x32,
0x38, 0x40, 0x40, 0x22, 0x7A,
0x00, 0x7A, 0x0A, 0x0A, 0x72,
0x7D, 0x0D, 0x19, 0x31, 0x7D,
0x26, 0x29, 0x29, 0x2F, 0x28,
0x26, 0x29, 0x29, 0x29, 0x26,
0x30, 0x48, 0x4D, 0x40, 0x20,
0x38, 0x08, 0x08, 0x08, 0x08,
0x08, 0x08, 0x08, 0x08, 0x38,
0x2F, 0x10, 0xC8, 0xAC, 0xBA,
0x2F, 0x10, 0x28, 0x34, 0xFA,
0x00, 0x00, 0x7B, 0x00, 0x00,
0x08, 0x14, 0x2A, 0x14, 0x22,
0x22, 0x14, 0x2A, 0x14, 0x08,
0x55, 0x00, 0x55, 0x00, 0x55, // #176 (25% block) missing in old code
0xAA, 0x55, 0xAA, 0x55, 0xAA, // 50% block
0xFF, 0x55, 0xFF, 0x55, 0xFF, // 75% block
0x00, 0x00, 0x00, 0xFF, 0x00,
0x10, 0x10, 0x10, 0xFF, 0x00,
0x14, 0x14, 0x14, 0xFF, 0x00,
0x10, 0x10, 0xFF, 0x00, 0xFF,
0x10, 0x10, 0xF0, 0x10, 0xF0,
0x14, 0x14, 0x14, 0xFC, 0x00,
0x14, 0x14, 0xF7, 0x00, 0xFF,
0x00, 0x00, 0xFF, 0x00, 0xFF,
0x14, 0x14, 0xF4, 0x04, 0xFC,
0x14, 0x14, 0x17, 0x10, 0x1F,
0x10, 0x10, 0x1F, 0x10, 0x1F,
0x14, 0x14, 0x14, 0x1F, 0x00,
0x10, 0x10, 0x10, 0xF0, 0x00,
0x00, 0x00, 0x00, 0x1F, 0x10,
0x10, 0x10, 0x10, 0x1F, 0x10,
0x10, 0x10, 0x10, 0xF0, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x10,
0x10, 0x10, 0x10, 0x10, 0x10,
0x10, 0x10, 0x10, 0xFF, 0x10,
0x00, 0x00, 0x00, 0xFF, 0x14,
0x00, 0x00, 0xFF, 0x00, 0xFF,
0x00, 0x00, 0x1F, 0x10, 0x17,
0x00, 0x00, 0xFC, 0x04, 0xF4,
0x14, 0x14, 0x17, 0x10, 0x17,
0x14, 0x14, 0xF4, 0x04, 0xF4,
0x00, 0x00, 0xFF, 0x00, 0xF7,
0x14, 0x14, 0x14, 0x14, 0x14,
0x14, 0x14, 0xF7, 0x00, 0xF7,
0x14, 0x14, 0x14, 0x17, 0x14,
0x10, 0x10, 0x1F, 0x10, 0x1F,
0x14, 0x14, 0x14, 0xF4, 0x14,
0x10, 0x10, 0xF0, 0x10, 0xF0,
0x00, 0x00, 0x1F, 0x10, 0x1F,
0x00, 0x00, 0x00, 0x1F, 0x14,
0x00, 0x00, 0x00, 0xFC, 0x14,
0x00, 0x00, 0xF0, 0x10, 0xF0,
0x10, 0x10, 0xFF, 0x10, 0xFF,
0x14, 0x14, 0x14, 0xFF, 0x14,
0x10, 0x10, 0x10, 0x1F, 0x00,
0x00, 0x00, 0x00, 0xF0, 0x10,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xF0, 0xF0, 0xF0, 0xF0, 0xF0,
0xFF, 0xFF, 0xFF, 0x00, 0x00,
0x00, 0x00, 0x00, 0xFF, 0xFF,
0x0F, 0x0F, 0x0F, 0x0F, 0x0F,
0x38, 0x44, 0x44, 0x38, 0x44,
0xFC, 0x4A, 0x4A, 0x4A, 0x34, // sharp-s or beta
0x7E, 0x02, 0x02, 0x06, 0x06,
0x02, 0x7E, 0x02, 0x7E, 0x02,
0x63, 0x55, 0x49, 0x41, 0x63,
0x38, 0x44, 0x44, 0x3C, 0x04,
0x40, 0x7E, 0x20, 0x1E, 0x20,
0x06, 0x02, 0x7E, 0x02, 0x02,
0x99, 0xA5, 0xE7, 0xA5, 0x99,
0x1C, 0x2A, 0x49, 0x2A, 0x1C,
0x4C, 0x72, 0x01, 0x72, 0x4C,
0x30, 0x4A, 0x4D, 0x4D, 0x30,
0x30, 0x48, 0x78, 0x48, 0x30,
0xBC, 0x62, 0x5A, 0x46, 0x3D,
0x3E, 0x49, 0x49, 0x49, 0x00,
0x7E, 0x01, 0x01, 0x01, 0x7E,
0x2A, 0x2A, 0x2A, 0x2A, 0x2A,
0x44, 0x44, 0x5F, 0x44, 0x44,
0x40, 0x51, 0x4A, 0x44, 0x40,
0x40, 0x44, 0x4A, 0x51, 0x40,
0x00, 0x00, 0xFF, 0x01, 0x03,
0xE0, 0x80, 0xFF, 0x00, 0x00,
0x08, 0x08, 0x6B, 0x6B, 0x08,
0x36, 0x12, 0x36, 0x24, 0x36,
0x06, 0x0F, 0x09, 0x0F, 0x06,
0x00, 0x00, 0x18, 0x18, 0x00,
0x00, 0x00, 0x10, 0x10, 0x00,
0x30, 0x40, 0xFF, 0x01, 0x01,
0x00, 0x1F, 0x01, 0x01, 0x1E,
0x00, 0x19, 0x1D, 0x17, 0x12,
0x00, 0x3C, 0x3C, 0x3C, 0x3C,
0x00, 0x00, 0x00, 0x00, 0x00 // #255 NBSP
};
#endif // FONT5X7_H

File diff suppressed because it is too large Load diff

View file

@ -1,124 +1,124 @@
#include <stdint.h>
#include <stdio.h>
#include <memory.h>
#include "EEPROM.h"
// TODO: Fake eeprom a bit better, maybe even save to file.
EEPROMClass::EEPROMClass() {
memset(someFakeEEPROM_memory, 0xff, sizeof(someFakeEEPROM_memory));
storage = NULL;
autoUpdate = false;
}
uint8_t EEPROMClass::read( int idx )
{
printf("Reading EEPROM address %u: %u\n", idx, 0xff&someFakeEEPROM_memory[idx]);
return someFakeEEPROM_memory[idx];
}
void EEPROMClass::write( int idx, uint8_t val )
{
printf("Writing to EEPROM address %u = %u\n", idx, val);
if(val == someFakeEEPROM_memory[idx])
{
//Value unchanged, do nothing.
return;
}
someFakeEEPROM_memory[idx] = val;
if(autoUpdate && storage)
{
fseek(storage, idx, SEEK_SET);
fputc(val, storage);
fflush(storage);
}
}
void EEPROMClass::update( int idx, uint8_t val )
{
write(idx, val);
}
uint16_t EEPROMClass::length()
{
return sizeof(someFakeEEPROM_memory);
}
int16_t EEPROMClass::setStorage(const char* filename, bool write)
{
//Close any open storage file
if(storage)
{
fclose(storage);
storage = NULL;
}
autoUpdate = write;
storage = fopen(filename, "rb");
//If only reading, fail if file does not exist (makes no sense otherwise)
if(!storage && !autoUpdate) {
printf("Could not open EEPROM storage file: '%s'\n", filename);
return -1;
}
if(storage)
{
printf("Reading EEPROM storage file: '%s'\n", filename);
rewind(storage);
fread(someFakeEEPROM_memory, sizeof(someFakeEEPROM_memory), 1, storage);
}
if(!autoUpdate)
{
//No need for the file anymore, close it
fclose(storage);
storage = NULL;
}
//Create file if it doesn't exist (so we can write to it)
if(!storage && autoUpdate)
{
storage = fopen(filename, "wb");
if(!storage)
{
printf("Could not create EEPROM storage file: '%s'\n", filename);
autoUpdate = false;
return -2;
}
}
if(storage && autoUpdate)
{
//Reopen file for writing without overwriting it
storage = freopen(filename, "r+b", storage);
if(!storage)
{
printf("Could not access EEPROM storage file for writing: '%s'\n", filename);
autoUpdate = false;
return -3;
}
printf("Writing any EEPROM changes to '%s'\n", filename);
}
return 0;
}
void EEPROMClass::closeStorage() {
if(storage!=NULL)
{
fclose(storage);
storage=NULL;
}
}
#include <stdint.h>
#include <stdio.h>
#include <memory.h>
#include "EEPROM.h"
// TODO: Fake eeprom a bit better, maybe even save to file.
EEPROMClass::EEPROMClass() {
memset(someFakeEEPROM_memory, 0xff, sizeof(someFakeEEPROM_memory));
storage = NULL;
autoUpdate = false;
}
uint8_t EEPROMClass::read( int idx )
{
printf("Reading EEPROM address %u: %u\n", idx, 0xff&someFakeEEPROM_memory[idx]);
return someFakeEEPROM_memory[idx];
}
void EEPROMClass::write( int idx, uint8_t val )
{
printf("Writing to EEPROM address %u = %u\n", idx, val);
if(val == someFakeEEPROM_memory[idx])
{
//Value unchanged, do nothing.
return;
}
someFakeEEPROM_memory[idx] = val;
if(autoUpdate && storage)
{
fseek(storage, idx, SEEK_SET);
fputc(val, storage);
fflush(storage);
}
}
void EEPROMClass::update( int idx, uint8_t val )
{
write(idx, val);
}
uint16_t EEPROMClass::length()
{
return sizeof(someFakeEEPROM_memory);
}
int16_t EEPROMClass::setStorage(const char* filename, bool write)
{
//Close any open storage file
if(storage)
{
fclose(storage);
storage = NULL;
}
autoUpdate = write;
storage = fopen(filename, "rb");
//If only reading, fail if file does not exist (makes no sense otherwise)
if(!storage && !autoUpdate) {
printf("Could not open EEPROM storage file: '%s'\n", filename);
return -1;
}
if(storage)
{
printf("Reading EEPROM storage file: '%s'\n", filename);
rewind(storage);
fread(someFakeEEPROM_memory, sizeof(someFakeEEPROM_memory), 1, storage);
}
if(!autoUpdate)
{
//No need for the file anymore, close it
fclose(storage);
storage = NULL;
}
//Create file if it doesn't exist (so we can write to it)
if(!storage && autoUpdate)
{
storage = fopen(filename, "wb");
if(!storage)
{
printf("Could not create EEPROM storage file: '%s'\n", filename);
autoUpdate = false;
return -2;
}
}
if(storage && autoUpdate)
{
//Reopen file for writing without overwriting it
storage = freopen(filename, "r+b", storage);
if(!storage)
{
printf("Could not access EEPROM storage file for writing: '%s'\n", filename);
autoUpdate = false;
return -3;
}
printf("Writing any EEPROM changes to '%s'\n", filename);
}
return 0;
}
void EEPROMClass::closeStorage() {
if(storage!=NULL)
{
fclose(storage);
storage=NULL;
}
}

View file

@ -1,55 +1,55 @@
#include <cstdint>
#include <cstdio>
#include "Arduino.h"
/********************************
*
*/
void SimSerial::begin(uint32_t)
{
}
void SimSerial::print(const char* str)
{
printf( "[Serial::print] %s\n", str );
}
void SimSerial::print(uint32_t intValue)
{
printf( "[Serial::print] %d\n", intValue );
}
void SimSerial::println()
{
printf("\n");
}
void SimSerial::println(uint32_t intValue)
{
printf( "[Serial::println] %d\n", intValue );
}
void SimSerial::println(const char *str)
{
printf( "[Serial::println] %s\n", str );
}
//Used to send serial midi
void SimSerial::write(const uint8_t __unused str)
{
}
void SimSerial::flush()
{
}
#include <cstdint>
#include <cstdio>
#include "Arduino.h"
/********************************
*
*/
void SimSerial::begin(uint32_t)
{
}
void SimSerial::print(const char* str)
{
printf( "[Serial::print] %s\n", str );
}
void SimSerial::print(uint32_t intValue)
{
printf( "[Serial::print] %d\n", intValue );
}
void SimSerial::println()
{
printf("\n");
}
void SimSerial::println(uint32_t intValue)
{
printf( "[Serial::println] %d\n", intValue );
}
void SimSerial::println(const char *str)
{
printf( "[Serial::println] %s\n", str );
}
//Used to send serial midi
void SimSerial::write(const uint8_t __unused str)
{
}
void SimSerial::flush()
{
}

View file

@ -1,145 +1,145 @@
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <fstream>
#include "simusbmidi.h"
/*************************************
* Stub simulation of Teensy usbMidi
*/
void SimUsbMidi::sendNoteOff(uint8_t note, uint8_t velocity, uint8_t channel, uint8_t __unused cable)
{
printf( "[usbMIDI::noteOff] note %03d vel %03d ch %02d\n", note, velocity, channel);
}
void SimUsbMidi::sendNoteOn(uint8_t note, uint8_t velocity, uint8_t channel, uint8_t __unused cable)
{
printf( "[usbMIDI::noteOn] note %03d vel %03d ch %02d\n", note, velocity, channel);
}
void SimUsbMidi::sendPolyPressure(uint8_t note, uint8_t pressure, uint8_t channel, uint8_t __unused cable)
{
printf( "[usbMIDI::polyPressure] note %03d p %03d ch %02d\n", note, pressure, channel);
}
void SimUsbMidi::sendAfterTouchPoly(uint8_t note, uint8_t pressure, uint8_t channel, uint8_t __unused cable)
{
printf( "[usbMIDI::afterTouchPoly] note %03d p %03d ch %02d\n", note, pressure, channel);
}
void SimUsbMidi::sendControlChange(uint8_t control, uint8_t value, uint8_t channel, uint8_t __unused cable)
{
printf( "[usbMIDI::controlChange] cc %03d val %03d ch %02d\n", control, value, channel);
}
void SimUsbMidi::sendProgramChange(uint8_t program, uint8_t channel, uint8_t __unused cable)
{
printf( "[usbMIDI::programChange] prg %03d ch %02d\n", program, channel);
}
void SimUsbMidi::sendAfterTouch(uint8_t pressure, uint8_t channel, uint8_t __unused cable)
{
printf( "[usbMIDI::afterTouch] p %03d ch %02d\n", pressure, channel);
}
void SimUsbMidi::sendPitchBend(int value, uint8_t channel, uint8_t __unused cable)
{
printf( "[usbMIDI::pitchBend] pb %05d ch %02d\n", value, channel);
}
void SimUsbMidi::sendSysEx(uint16_t length, const uint8_t *data, bool __unused hasTerm, uint8_t __unused cable)
{
printf( "[usbMIDI::sysEx] Sending %d bytes\n", length);
for(int i=0; i<length; i++) {
printf("%02x%c", data[i], (i==length-1)?'\n':':');
}
}
//Set a low chunk size on purpose just to let the receiver work for it
#define MIDI_SYSEX_CHUNK_SIZE 32
bool SimUsbMidi::read(uint8_t __unused channel) {
if(this->sendMidi) {
printf("[SimUsbMidi::read] Attempting to send midi data\n");
std::ifstream file(this->midiFile, std::ios::binary | std::ios::ate);
std::streamsize size = file.tellg();
file.seekg(0, std::ios::beg);
uint8_t *buffer = (uint8_t*)malloc(size);
if (file.read((char*)buffer, size))
{
printf("[SimUsbMidi::read] Sending %lu bytes.\n", size);
this->receiveMidiData(buffer, size);
}
free(buffer);
this->sendMidi = false;
}
return false;
}
//Provide midi data for simulation to receive
void SimUsbMidi::receiveMidiData(const uint8_t *data, const uint16_t length) {
if(length==0) return; //There is no data, what's even the point
uint8_t midi_message = data[0]; //First byte of data
if(midi_message != 0xF0) return; //Only sysex data supported (no other handlers available)
if(this->usb_midi_handleSysExPartial) {
//Chunked sysex receiver set, use that.
if(length<=MIDI_SYSEX_CHUNK_SIZE) {
//Send all in one go
printf( "[SimUsbMidi::receiveMidiData] usb_midi_handleSysExPartial(complete) %d B\n", length);
(this->usb_midi_handleSysExPartial)(data, length, true);
} else {
uint8_t* buf = (uint8_t*)malloc(MIDI_SYSEX_CHUNK_SIZE);
int pos=0;
while(pos<length) {
int remaining = length-pos;
int bytesToSend = std::min(remaining, MIDI_SYSEX_CHUNK_SIZE);
bool complete = (bytesToSend == remaining);
memcpy(buf, data+pos, bytesToSend);
printf( "[SimUsbMidi::receiveMidiData] usb_midi_handleSysExPartial(complete: %d) %d B\n", complete, bytesToSend);
(this->usb_midi_handleSysExPartial)(buf, bytesToSend, complete);
pos=pos+bytesToSend;
}
free(buf);
}
} else if(this->usb_midi_handleSysExComplete) {
printf( "[SimUsbMidi::receiveMidiData] usb_midi_handleSysExComplete() %d B\n", length);
(this->usb_midi_handleSysExComplete)(data, length);
} else {
//Nobody listening
}
}
//MIDI SysEx handlers. Choice of data types is a bit odd, but done to match Arduino/Teensy libraries
void SimUsbMidi::setHandleSystemExclusive(void (*fptr) (const uint8_t *array, unsigned int size)) {
this->usb_midi_handleSysExComplete = fptr;
}
//"Chunked" sysex handler (teensy extension), for large messages
void SimUsbMidi::setHandleSystemExclusive(void (*fptr) (const uint8_t *array, uint16_t size, bool last)) {
this->usb_midi_handleSysExPartial = (void (*)(const uint8_t *, uint16_t, uint8_t))fptr;
}
void SimUsbMidi::setMidiFile(std::string filename) {
this->midiFile = filename;
}
void SimUsbMidi::triggerMidi() {
this->sendMidi = true;
}
#include <cstdint>
#include <cstdio>
#include <iostream>
#include <fstream>
#include "simusbmidi.h"
/*************************************
* Stub simulation of Teensy usbMidi
*/
void SimUsbMidi::sendNoteOff(uint8_t note, uint8_t velocity, uint8_t channel, uint8_t __unused cable)
{
printf( "[usbMIDI::noteOff] note %03d vel %03d ch %02d\n", note, velocity, channel);
}
void SimUsbMidi::sendNoteOn(uint8_t note, uint8_t velocity, uint8_t channel, uint8_t __unused cable)
{
printf( "[usbMIDI::noteOn] note %03d vel %03d ch %02d\n", note, velocity, channel);
}
void SimUsbMidi::sendPolyPressure(uint8_t note, uint8_t pressure, uint8_t channel, uint8_t __unused cable)
{
printf( "[usbMIDI::polyPressure] note %03d p %03d ch %02d\n", note, pressure, channel);
}
void SimUsbMidi::sendAfterTouchPoly(uint8_t note, uint8_t pressure, uint8_t channel, uint8_t __unused cable)
{
printf( "[usbMIDI::afterTouchPoly] note %03d p %03d ch %02d\n", note, pressure, channel);
}
void SimUsbMidi::sendControlChange(uint8_t control, uint8_t value, uint8_t channel, uint8_t __unused cable)
{
printf( "[usbMIDI::controlChange] cc %03d val %03d ch %02d\n", control, value, channel);
}
void SimUsbMidi::sendProgramChange(uint8_t program, uint8_t channel, uint8_t __unused cable)
{
printf( "[usbMIDI::programChange] prg %03d ch %02d\n", program, channel);
}
void SimUsbMidi::sendAfterTouch(uint8_t pressure, uint8_t channel, uint8_t __unused cable)
{
printf( "[usbMIDI::afterTouch] p %03d ch %02d\n", pressure, channel);
}
void SimUsbMidi::sendPitchBend(int value, uint8_t channel, uint8_t __unused cable)
{
printf( "[usbMIDI::pitchBend] pb %05d ch %02d\n", value, channel);
}
void SimUsbMidi::sendSysEx(uint16_t length, const uint8_t *data, bool __unused hasTerm, uint8_t __unused cable)
{
printf( "[usbMIDI::sysEx] Sending %d bytes\n", length);
for(int i=0; i<length; i++) {
printf("%02x%c", data[i], (i==length-1)?'\n':':');
}
}
//Set a low chunk size on purpose just to let the receiver work for it
#define MIDI_SYSEX_CHUNK_SIZE 32
bool SimUsbMidi::read(uint8_t __unused channel) {
if(this->sendMidi) {
printf("[SimUsbMidi::read] Attempting to send midi data\n");
std::ifstream file(this->midiFile, std::ios::binary | std::ios::ate);
std::streamsize size = file.tellg();
file.seekg(0, std::ios::beg);
uint8_t *buffer = (uint8_t*)malloc(size);
if (file.read((char*)buffer, size))
{
printf("[SimUsbMidi::read] Sending %lu bytes.\n", size);
this->receiveMidiData(buffer, size);
}
free(buffer);
this->sendMidi = false;
}
return false;
}
//Provide midi data for simulation to receive
void SimUsbMidi::receiveMidiData(const uint8_t *data, const uint16_t length) {
if(length==0) return; //There is no data, what's even the point
uint8_t midi_message = data[0]; //First byte of data
if(midi_message != 0xF0) return; //Only sysex data supported (no other handlers available)
if(this->usb_midi_handleSysExPartial) {
//Chunked sysex receiver set, use that.
if(length<=MIDI_SYSEX_CHUNK_SIZE) {
//Send all in one go
printf( "[SimUsbMidi::receiveMidiData] usb_midi_handleSysExPartial(complete) %d B\n", length);
(this->usb_midi_handleSysExPartial)(data, length, true);
} else {
uint8_t* buf = (uint8_t*)malloc(MIDI_SYSEX_CHUNK_SIZE);
int pos=0;
while(pos<length) {
int remaining = length-pos;
int bytesToSend = std::min(remaining, MIDI_SYSEX_CHUNK_SIZE);
bool complete = (bytesToSend == remaining);
memcpy(buf, data+pos, bytesToSend);
printf( "[SimUsbMidi::receiveMidiData] usb_midi_handleSysExPartial(complete: %d) %d B\n", complete, bytesToSend);
(this->usb_midi_handleSysExPartial)(buf, bytesToSend, complete);
pos=pos+bytesToSend;
}
free(buf);
}
} else if(this->usb_midi_handleSysExComplete) {
printf( "[SimUsbMidi::receiveMidiData] usb_midi_handleSysExComplete() %d B\n", length);
(this->usb_midi_handleSysExComplete)(data, length);
} else {
//Nobody listening
}
}
//MIDI SysEx handlers. Choice of data types is a bit odd, but done to match Arduino/Teensy libraries
void SimUsbMidi::setHandleSystemExclusive(void (*fptr) (const uint8_t *array, unsigned int size)) {
this->usb_midi_handleSysExComplete = fptr;
}
//"Chunked" sysex handler (teensy extension), for large messages
void SimUsbMidi::setHandleSystemExclusive(void (*fptr) (const uint8_t *array, uint16_t size, bool last)) {
this->usb_midi_handleSysExPartial = (void (*)(const uint8_t *, uint16_t, uint8_t))fptr;
}
void SimUsbMidi::setMidiFile(std::string filename) {
this->midiFile = filename;
}
void SimUsbMidi::triggerMidi() {
this->sendMidi = true;
}

View file

@ -1,94 +1,94 @@
#include <stdio.h>
#include "Wire.h"
/********************************
*
*/
SimWire::SimWire( bool verbose )
: verbose_( verbose )
{
}
void SimWire::setClock(uint32_t)
{
// Ignore.. lol
}
void SimWire::begin()
{
}
void SimWire::beginTransmission(uint8_t address)
{
if( verbose_ )
printf("[SimWire::beginTransmission] $%02x\n", address);
}
void SimWire::beginTransmission(int address)
{
beginTransmission((uint8_t)address);
}
uint8_t SimWire::endTransmission()
{
if( verbose_ )
printf("[SimWire::endTransmission]\n");
return 0;
}
uint8_t SimWire::endTransmission(uint8_t what)
{
if( verbose_ )
printf("[SimWire::endTransmission %d]\n", what);
return 0;
}
uint8_t SimWire::requestFrom(uint8_t address, uint8_t count)
{
if( verbose_ )
printf("[SimWire::requestFrom] $%02x for %d bytes\n", address, count);
// TODO: We must check if there is an actual slave for that address.
return 0;
}
int SimWire::read()
{
// TODO: Verify that bus is in read mode.
// if( current_slave_ != NULL ) {
// return current_slave_->i2cReadData( );
// } else {
printf("No slave selected, returning ones\n");
return 0xffu;
// }
}
int SimWire::available()
{
// TODO: This needs to be implemented!!
return 0;
}
size_t SimWire::write(uint8_t __attribute__((unused)) data)
{
// // TODO: Verify that bus is in write mode.
// if( current_slave_ != NULL ) {
// current_slave_->i2cWriteData( data );
// } else {
printf("No slave selected i2c writes to the void.\n");
// }
return 1;
}
#include <stdio.h>
#include "Wire.h"
/********************************
*
*/
SimWire::SimWire( bool verbose )
: verbose_( verbose )
{
}
void SimWire::setClock(uint32_t)
{
// Ignore.. lol
}
void SimWire::begin()
{
}
void SimWire::beginTransmission(uint8_t address)
{
if( verbose_ )
printf("[SimWire::beginTransmission] $%02x\n", address);
}
void SimWire::beginTransmission(int address)
{
beginTransmission((uint8_t)address);
}
uint8_t SimWire::endTransmission()
{
if( verbose_ )
printf("[SimWire::endTransmission]\n");
return 0;
}
uint8_t SimWire::endTransmission(uint8_t what)
{
if( verbose_ )
printf("[SimWire::endTransmission %d]\n", what);
return 0;
}
uint8_t SimWire::requestFrom(uint8_t address, uint8_t count)
{
if( verbose_ )
printf("[SimWire::requestFrom] $%02x for %d bytes\n", address, count);
// TODO: We must check if there is an actual slave for that address.
return 0;
}
int SimWire::read()
{
// TODO: Verify that bus is in read mode.
// if( current_slave_ != NULL ) {
// return current_slave_->i2cReadData( );
// } else {
printf("No slave selected, returning ones\n");
return 0xffu;
// }
}
int SimWire::available()
{
// TODO: This needs to be implemented!!
return 0;
}
size_t SimWire::write(uint8_t __attribute__((unused)) data)
{
// // TODO: Verify that bus is in write mode.
// if( current_slave_ != NULL ) {
// current_slave_->i2cWriteData( data );
// } else {
printf("No slave selected i2c writes to the void.\n");
// }
return 1;
}