Skip to content

Commit

Permalink
Adds support for 74HC595 Mux Output, adds Typer event for buttons.
Browse files Browse the repository at this point in the history
  • Loading branch information
neroroxxx committed Aug 24, 2020
1 parent f34bea8 commit 347c7cd
Show file tree
Hide file tree
Showing 34 changed files with 1,081 additions and 154 deletions.
6 changes: 6 additions & 0 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ void onBleConnectionChange(void (*fptr)(bool t_connected));
// triggered when a Menu Command is handled by a button, encoder, API, etc.
void onMenu(void (*fptr)(uint8_t t_command));
// triggered when the Typer value has been Updated
void onTyperUpdate(void (*fptr)(uint16_t t_value));
// triggered when the Typer value has been Updated and you set it to custom calback
void onTyperCustomUpdate(void (*fptr)(uint16_t t_value));
// triggered when BMC runs it's update() method the first time.
void onFirstLoop(void (*fptr)());
Expand Down
57 changes: 34 additions & 23 deletions docs/multiplexers.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
***********************************************
***BMC now allows for up to 127 Analog Mux Pins, Digital Mux In will still be limited to 64 pins***
***********************************************
***********************************************
***BMC now supports Mux Out with the 74HC595***
***********************************************

While BMC uses a Teensy's pins to read inputs it also has support for up 64 Mux inputs.

These include:
Expand All @@ -20,6 +24,11 @@ IC | Input Type | Inputs | Pins Required
**74HC4067** | Analog Only | 16 | 5 *(1 must be analog)*
**74HC4051** | Analog Only | 8 | 4 *(1 must be analog)*

#### MUX OUT:

IC | Output Type | Outputs | Pins Required
-|-|-|-
**74HC595** | Digital Only | 8 | 3 (4 optional for PWM)


BMC has code to read all chips above however there are a few limits. For digital inputs you can only use one type of chip, so if you want to have 32 inputs you can either use four 74HC165 or two MCP23017 or two MCP23018, you can not combine them.
Expand Down Expand Up @@ -57,25 +66,26 @@ BMC also lets you use other ICs, however you have to write the code to read them
For Digital Inputs you can use these API functions:

```c++
// for the first 32 pins
void setMuxIn1To32(uint32_t values);
// @n the digital pin index, this is the actual index, that is if it's the very first digital pin, n will be 0
// @value false if button is pressed, true is released
void setMuxDigitalValue(uint8_t n, bool value);
```
// for the last 32 pins
// (only available if more than 32 Digital Mux In pins compiled)
void setMuxIn33To64(uint32_t values);
For Digital Output
```c++
void setMuxDigitalOutValue(uint8_t pin, bool value);
```

For Analog Inputs you can use:

```c++
// @n the analog pin index, this is the actual index, that is if it's the very first analog pin, n will be 0
// @value the 10-bit analog value 0 to 1023
void setMuxInAnalogValue(uint8_t n, uint16_t value);
void setMuxAnalogValue(uint8_t n, uint16_t value);
```
Since digital inputs only have 2 states on/off, true/false, 0/1, etc, you have to think of each digital input as a ***bit***, so bit-0 of `values` in `setMuxIn1To32` is the very first digital pin.
Additionally, BMC reads digital inputs **Active Low** that is when a button is inactive (depressed) that bit must be **1**, when a button is pressed that bit must be **0**
Additionally, BMC reads digital inputs **Active Low** that is when a button is inactive (depressed) that value passed must be **1**, when a button is pressed the value passed must be **0**
With the API could use a touch sensor to trigger a Pot and send MIDI messages from assigned to that Pot, MIDI Theremin anybody?
Expand All @@ -84,38 +94,39 @@ There are many API callbacks and functions available for use, these may not refl
##### FUNCTIONS

For Digital Input
```c++
// Only available if Mux In is set to *Other*
// for the first 32 pins
// each bit of the 32-bit int represents the digital input
// they must be active low
void setMuxIn1To32(uint32_t values);

// Only available if Mux In is set to *Other*
// for the last 32 pins
// (only available if more than 32 Digital Mux In pins compiled)
void setMuxIn33To64(uint32_t values);
// @n the digital pin index, this is the actual index, that is if it's the very first digital pin, n will be 0
// @value false if button is pressed, true is released
void setMuxDigitalValue(uint8_t n, bool value);
// Only available for supported Mux ICs, useful when you want to read pins
// to be handled by your sketch
// read a digital mux in pin
bool getMuxInValue(uint8_t n);
bool getMuxValue(uint8_t n);
```

For Digital Output
```c++
// set the value of a custom mux output pin
void setMuxDigitalOutValue(uint8_t pin, bool value);

// get the value of a mux output pin
bool getMuxOutValue(uint8_t n);
```
For Analog Inputs you can use these API functions:
```c++
// Only available if Mux In is set to *Other*
// @n the analog pin index, this is the actual index, that is if it's the very first analog pin, n will be 0
// @value the 10-bit analog value 0 to 1023
void setMuxInAnalogValue(uint8_t n, uint16_t value);
void setMuxAnalogValue(uint8_t n, uint16_t value);
// Only available for supported Analog Mux ICs, useful when you want to read pins
// to be handled by your sketch
// @n the analog pin index, this is the actual index, that is if it's the very first analog pin, n will be 0
// returns a 10-bit value
uint16_t getMuxInAnalogValue(uint8_t n);
uint16_t getMuxAnalogValue(uint8_t n);
```


Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=BMC
version=0.0.14
version=0.0.15
author=Nero Rox
maintainer=Nero Rox
sentence=Badass MIDI Controller (BMC), a fully featured MIDI Controller with a Desktop Editor App. For 32-bit Teensy Only
Expand Down
57 changes: 35 additions & 22 deletions src/BMC-Api.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,16 @@ class BMCApi : public BMC {
void onMenu(void (*fptr)(uint8_t t_command)){
callback.menuCommand = fptr;
}
// triggered when the Typer value has been Updated
void onTyperUpdate(void (*fptr)(uint16_t t_value)){
callback.typerCommand = fptr;
}
// triggered when the Typer value has been Updated and you set it to custom calback
void onTyperCustomUpdate(void (*fptr)(uint16_t t_value)){
callback.typerCustomCommand = fptr;
}


// triggered when BMC runs it's update() method the first time.
void onFirstLoop(void (*fptr)()){
callback.firstLoop = fptr;
Expand Down Expand Up @@ -759,25 +769,28 @@ class BMCApi : public BMC {

#if BMC_MAX_MUX_IN > 0
#if BMC_MUX_IN_CHIPSET==BMC_MUX_IN_CHIPSET_OTHER
// for the first 32 pins
// each bit of the 32-bit int represents the digital input
// they must be active low
void setMuxIn1To32(uint32_t values){
muxIn.setPinValues1To32(values);
}
#if BMC_MAX_MUX_IN > 32
// for the last 32 pins
// (only available if more than 32 Digital Mux In pins compiled)
void setMuxIn33To64(uint32_t values){
muxIn.setPinValues33To64(values);
}
#endif
// set the value of a custom mux input pin
void setMuxDigitalValue(uint8_t pin, bool value){
mux.setDigitalValue(pin, value);
}
#else
// available for supported Mux ICs, useful when you want to read pins
// to be handled by your sketch
// read a digital mux in pin
bool getMuxInValue(uint8_t n){
return muxIn.getPinValue(n);
// get the value of a mux input pin
bool getMuxValue(uint8_t n){
return mux.readDigital(n);
}
#endif
#endif

#if BMC_MAX_MUX_OUT > 0
#if BMC_MUX_OUT_CHIPSET==BMC_MUX_OUT_CHIPSET_OTHER
// set the value of a custom mux output pin
void setMuxDigitalOutValue(uint8_t pin, bool value){
mux.writeDigital(pin, value);
}
#else
// get the value of a mux output pin
bool getMuxOutValue(uint8_t n){
return mux.getDigitalValue(n);
}
#endif
#endif
Expand All @@ -786,16 +799,16 @@ class BMCApi : public BMC {
#if BMC_MUX_IN_ANALOG_CHIPSET==BMC_MUX_IN_ANALOG_CHIPSET_OTHER
// @n the analog pin index, this is the actual index, that is if it's the very first analog pin, n will be 0
// @value the 10-bit analog value 0 to 1023
void setMuxInAnalogValue(uint8_t n, uint16_t value){
muxInAnalog.setPinValue(n, value);
void setMuxAnalogValue(uint8_t n, uint16_t value){
mux.setAnalogValue(n, value);
}
#else
// available for supported Analog Mux ICs, useful when you want to read pins
// to be handled by your sketch
// @n the analog pin index, this is the actual index, that is if it's the very first analog pin, n will be 0
// returns a 10-bit value
uint16_t getMuxInAnalogValue(uint8_t n){
return muxInAnalog.getPinValue(n);
uint16_t getMuxAnalogValue(uint8_t n){
return mux.readAnalog(n);
}
#endif
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/BMC-Version.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// BMC Version stored in EEPROM (for editor usage)
#define BMC_VERSION_MAJ 0
#define BMC_VERSION_MIN 0
#define BMC_VERSION_PATCH 14
#define BMC_VERSION_PATCH 15

//16 bits unsigned, LSB byte is minor, MSB byte is major
#define BMC_VERSION ((BMC_VERSION_MAJ<<8) | BMC_VERSION_MIN)
Expand Down
1 change: 1 addition & 0 deletions src/BMC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ BMC::BMC():
globalData(store.global),
settings(store.global.settings),
midi(callback, globals, store.global.portPresets),
valueTyper(callback),
editor(store, midi, settings, messenger),
midiClock(midi),
midiActiveSense(midi)
Expand Down
11 changes: 10 additions & 1 deletion src/BMC.debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ void BMC::readDebug(){

BMC_PRINTLN("storageDebug = Prints the time it takes to read/write/clear EEPROM everytime the actions happens");
BMC_PRINTLN("metrics = Prints some metrics of the performance of BMC like loops per second, etc. Happens every other second.");

BMC_PRINTLN("nextPage = Go to next page");
BMC_PRINTLN("prevPage = Go to previous page");
BMC_PRINTLN("midiClockInfo = Display Master/Slave Clock Info");
BMC_PRINTLN("midiIn = Toggles displaying all incoming MIDI Messages (excludes Clock)");
BMC_PRINTLN("midiOut = Toggles displaying all outgoing MIDI Messages (excludes Clock)");
Expand Down Expand Up @@ -126,6 +127,14 @@ void BMC::readDebug(){
}
printDebugHeader(debugInput);

} else if(BMC_STR_MATCH(debugInput,"nextPage")){

nextPage();

} else if(BMC_STR_MATCH(debugInput,"prevPage")){

prevPage();

} else if(BMC_STR_MATCH(debugInput,"midiClockInfo")){

printDebugHeader(debugInput);
Expand Down
20 changes: 8 additions & 12 deletions src/BMC.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,8 @@
#include "addon/BMC-Kemper.h"
#endif

#if BMC_MAX_MUX_IN > 0
#include "hardware/BMC-MuxIn.h"
#endif

#if BMC_MAX_MUX_IN_ANALOG
#include "hardware/BMC-MuxInAnalog.h"
#if defined(BMC_MUX_AVAILABLE)
#include "mux/BMC-Mux.h"
#endif

#if BMC_MAX_BUTTONS > 0 || BMC_MAX_GLOBAL_BUTTONS > 0
Expand Down Expand Up @@ -156,6 +152,8 @@ class BMC {
// go to a new page
// @reassignSettings if true will reassign all global settings
void setPage(uint8_t page, bool reassignSettings=false);
void nextPage();
void prevPage();
// scroll to a different page, either the previous or next page
void scrollPage(uint8_t t_flags, uint8_t t_min,
uint8_t t_max, uint8_t t_amount);
Expand Down Expand Up @@ -198,6 +196,8 @@ class BMC {
BMCSettings settings;
// the global midi object
BMCMidi midi;
// value typer object
BMCTyper valueTyper;
// struct to hold messenger data sent between sketch and editor app
BMCMessenger messenger;
// editor handling all editing of the store
Expand Down Expand Up @@ -334,12 +334,8 @@ class BMC {
uint8_t parseMidiEventType(uint8_t t_type);
uint8_t parseUserEventType(uint8_t t_type);

#if BMC_MAX_MUX_IN > 0
BMCMuxIn muxIn;
#endif

#if BMC_MAX_MUX_IN_ANALOG > 0
BMCMuxInAnalog muxInAnalog;
#if defined(BMC_MUX_AVAILABLE)
BMCMux mux;
#endif

// PIXELS AND LEDS
Expand Down
30 changes: 28 additions & 2 deletions src/BMC.hardware.buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void BMC::readButtons(){

// GET THE PIN STATE FROM MUX
#if BMC_MAX_MUX_IN > 0
buttons[i].setMuxValue(muxIn.getPinValue(buttons[i].getMuxPin()));
buttons[i].setMuxValue(mux.readDigital(buttons[i].getMuxPin()));
#endif

uint8_t buttonTrigger = buttons[i].read();
Expand Down Expand Up @@ -196,7 +196,7 @@ void BMC::readGlobalButtons(){
for(uint8_t i = 0; i < BMC_MAX_GLOBAL_BUTTONS; i++){
// GET THE PIN STATE FROM MUX
#if BMC_MAX_MUX_IN > 0
globalButtons[i].setMuxValue(muxIn.getPinValue(globalButtons[i].getMuxPin()));
globalButtons[i].setMuxValue(mux.readDigital(globalButtons[i].getMuxPin()));
#endif

#if BMC_MAX_GLOBAL_BUTTONS == 1
Expand Down Expand Up @@ -717,6 +717,32 @@ void BMC::handleGlobalButton(uint8_t index, uint8_t t_trigger){
// byteB = Channel
midiProgramBankTrigger(byteA, byteB, ports);
break;
case BMC_BUTTON_EVENT_TYPE_TYPER_CMD:
{
uint8_t cmd = valueTyper.cmd(byteA, byteB);
if(cmd > 10){// cmd 10 is Clear
if(cmd==12){// page
setPage(valueTyper.getOutput());
} else if(cmd==13){// preset
#if BMC_MAX_PRESETS > 0
presets.set(valueTyper.getOutput());
#endif
} else if(cmd==14){// fas preset
#if defined(BMC_USE_FAS)
fas.setPreset(valueTyper.getOutput());
#endif
} else if(cmd==15){// fas scene
#if defined(BMC_USE_FAS)
fas.setSceneNumber(valueTyper.getOutput(), false);
#endif
} else if(cmd==16){// fas scene revert
#if defined(BMC_USE_FAS)
fas.setSceneNumber(valueTyper.getOutput(), true);
#endif
}
}
}
break;

#if BMC_MAX_CUSTOM_SYSEX > 0
case BMC_BUTTON_EVENT_TYPE_CUSTOM_SYSEX:
Expand Down
18 changes: 5 additions & 13 deletions src/BMC.hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void BMC::setupHardware(){
BMC_PRINTLN("BMC_MAX_AUX_JACKS", BMC_MAX_AUX_JACKS);
for(uint8_t i=0;i<BMC_MAX_AUX_JACKS;i++){

#if BMC_MAX_MUX_IN > 0 || BMC_MAX_MUX_IN_ANALOG > 0
#if BMC_MAX_MUX_IN > 0 || BMC_MAX_MUX_OUT > 0 || BMC_MAX_MUX_IN_ANALOG > 0
if(
BMCBuildData::getPotPin(BMCBuildData::getPotMergeItem(i, 0))>=64 ||
BMCBuildData::getButtonPin(BMCBuildData::getPotMergeItem(i, 1))>=64 ||
Expand All @@ -34,12 +34,8 @@ void BMC::setupHardware(){
}
#endif

#if BMC_MAX_MUX_IN > 0
muxIn.begin();
#endif

#if BMC_MAX_MUX_IN_ANALOG > 0
muxInAnalog.begin();
#if defined(BMC_MUX_AVAILABLE)
mux.begin();
#endif

#if BMC_MAX_PIXELS > 0
Expand Down Expand Up @@ -151,12 +147,8 @@ void BMC::assignHardware() {
// Read the hardware items for changes
void BMC::readHardware(){

#if BMC_MAX_MUX_IN > 0
muxIn.update();
#endif

#if BMC_MAX_MUX_IN_ANALOG > 0
muxInAnalog.update();
#if defined(BMC_MUX_AVAILABLE)
mux.update();
#endif

#if BMC_MAX_AUX_JACKS > 0
Expand Down
Loading

0 comments on commit 347c7cd

Please sign in to comment.