-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Treat europi_config
keys like named constants
#346
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
13662d6
Create a new ConfigSettings class that exposes the config dict's item…
chrisib c550d4d
Make the new class _not_ a dict just to avoid any chance of subscript…
chrisib 872d319
Use double-quotes to make the linter happier
chrisib af00178
Update scripts that use their own config_point instances
chrisib 851a8c9
Make the config object a dict again; the tests were failing and I don…
chrisib 6d507d2
Hack the tests by providing an __eq__ method that supports comparing …
chrisib c402f67
Add additional documentation about the dict key -> attribute name con…
chrisib 9986b5e
Single -> double quotes
chrisib 2dba94e
Revert the config file to load as a dict to preserve read/write compa…
chrisib f7d0fbb
Fix the tests now that we've rolled back the JSON parsing
chrisib 53a6546
Typo
chrisib cab1ade
Add a comment explaining why self.__dict__ is required
chrisib 66f42e3
Revert accidental changes to turing_machine.py
chrisib 593b8c3
Linting
chrisib 16cd1ad
Tweak the example to not need to explicitly use the `europi` namespace
chrisib f2e9687
Update the new e. melodiam script to use the new constants instead of…
chrisib 058d1fe
Fix bug in the quantizer
chrisib 2ae4c83
Remove the intermediate `dict` objects, be less permissive with confi…
chrisib d99269d
Fix the tests, add an == comparator to the ConfigSettings, fix contri…
chrisib 5fb1cf6
Linting
chrisib f5df7ed
Remove an unnecessary newline
chrisib 68e2553
Fix some typos in the readme
chrisib 9bada65
Simplify the ConfigSettings __eq__ implementation
chrisib aff93e0
Revert link to point back to the __init__ file
chrisib f95b3a3
Use ALL_CAPS for all configuration JSON keys; do not convert case. Up…
chrisib 293f144
Linting
chrisib 0759e7f
Update contrib scripts to use ALL_CAPS json keys for their own configs
chrisib c64169f
Remove notice about caps not being enforced
chrisib 22f082a
Expand the text around the code examples
chrisib c9a3aca
Remove references to "namespace"
chrisib 25c77a9
Reword the above/below text to be less confusing
chrisib File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,143 @@ | ||
# Configuration Customization | ||
|
||
Certain properties of the module, such as screen rotation, CPU clock speed, and Raspberry Pi Pico model, can be | ||
set using a static configuration file. This file is located at `/config/config_EuroPiConfig.json` on the | ||
set using a static configuration file. This file is located at `/config/EuroPiConfig.json` on the | ||
Raspberry Pi Pico. If this file does not exist, default settings will be loaded. The following shows the | ||
default configuration: | ||
```json | ||
{ | ||
"europi_model": "europi", | ||
"pico_model": "pico", | ||
"cpu_freq": 250000000, | ||
"rotate_display": false, | ||
"display_width": 128, | ||
"display_height": 32, | ||
"display_sda": 0, | ||
"display_scl": 1, | ||
"display_channel": 0 | ||
"max_output_voltage": 10, | ||
"max_input_voltage": 12, | ||
"gate_voltage": 5 | ||
"EUROPI_MODEL": "europi", | ||
"PICO_MODEL": "pico", | ||
"CPU_FREQ": 250000000, | ||
"ROTATE_DISPLAY": false, | ||
"DISPLAY_WIDTH": 128, | ||
"DISPLAY_HEIGHT": 32, | ||
"DISPLAY_SDA": 0, | ||
"DISPLAY_SCL": 1, | ||
"DISPLAY_CHANNEL": 0, | ||
"MAX_OUTPUT_VOLTAGE": 10, | ||
"MAX_INPUT_VOLTAGE": 12, | ||
"GATE_VOLTAGE": 5 | ||
} | ||
``` | ||
|
||
- `europi_model` specifies the type of EuroPi module. Currently only `"europi"` is supported | ||
- `pico_model` must be one of `"pico"` or `"pico w"` | ||
- `cpu_freq` must be one of `250000000` or `125000000` | ||
- `rotate_display` must be one of `false` or `true` | ||
- `display_width` is the width of the screen in pixels. The standard EuroPi screen is 128 pixels wide | ||
- `display_height` is the height of the screen in pixels. The standard EuroPi screen is 32 pixels tall | ||
- `display_sda` is the I²C SDA pin used for the display. Only SDA capable pins can be selected | ||
- `display_scl` is the I²C SCL pin used for the display. Only SCL capable pins can be selected | ||
- `display_channel` is the I²C channel used for the display, either 0 or 1. | ||
- `volts_per_octave` must be one of `1.0` (Eurorack standard) or `1.2` (Buchla standard) | ||
- `max_output_voltage` is an integer in the range `[0, 10]` indicating the maximum voltage CV output can generate. | ||
- `EUROPI_MODEL` specifies the type of EuroPi module. Currently only `"europi"` is supported | ||
- `PICO_MODEL` must be one of `"pico"` or `"pico w"` | ||
- `CPU_FREQ` must be one of `250000000` or `125000000` | ||
- `ROTATE_DISPLAY` must be one of `false` or `true` | ||
- `DISPLAY_WIDTH` is the width of the screen in pixels. The standard EuroPi screen is 128 pixels wide | ||
- `DISPLAY_HEIGHT` is the height of the screen in pixels. The standard EuroPi screen is 32 pixels tall | ||
- `DISPLAY_SDA` is the I²C SDA pin used for the display. Only SDA capable pins can be selected | ||
- `DISPLAY_SCL` is the I²C SCL pin used for the display. Only SCL capable pins can be selected | ||
- `DISPLAY_CHANNEL` is the I²C channel used for the display, either 0 or 1. | ||
- `MAX_OUTPUT_VOLTAGE` is an integer in the range `[0, 10]` indicating the maximum voltage CV output can generate. | ||
The hardware is capable of 10V maximum | ||
- `max_input_voltage` is an integer in the range `[0, 12]` indicating the maximum allowed voltage into the `ain` jack. | ||
- `MAX_INPUT_VOLTAGE` is an integer in the range `[0, 12]` indicating the maximum allowed voltage into the `ain` jack. | ||
The hardware is capable of 12V maximum | ||
- `gate_voltage` is an integer in the range `[0, 12]` indicating the voltage that an output will produce when `cvx.on()` is called | ||
- `GATE_VOLTAGE` is an integer in the range `[0, 10]` indicating the voltage that an output will produce when `cvx.on()` | ||
is called. This value must not be higher than `MAX_OUTPUT_VOLTAGE` | ||
|
||
|
||
|
||
# Experimental configuration | ||
|
||
Other configuration properties are used by [experimental features](software/firmware/experimental/__init__.py) | ||
and can be set using a similar static configuration file. This file is located at `/config/config_ExperimentalConfig.json` | ||
Other configuration properties are used by [experimental features](/software/firmware/experimental/__init__.py) | ||
and can be set using a similar static configuration file. This file is located at `/config/ExperimentalConfig.json` | ||
on the Raspberry Pi Pico. If this file does not exist, default settings will be loaded. The following | ||
shows the default configuration: | ||
|
||
```json | ||
{ | ||
"volts_per_octave": 1.0, | ||
"VOLTS_PER_OCTAVE": 1.0, | ||
} | ||
``` | ||
|
||
- `volts_per_octave` must be one of `1.0` (Eurorack standard) or `1.2` (Buchla standard) | ||
- `VOLTS_PER_OCTAVE` must be one of `1.0` (Eurorack standard) or `1.2` (Buchla standard) | ||
|
||
|
||
# Accessing config members in Python code | ||
|
||
The firmware converts the JSON file into a `ConfigSettings` object, where the JSON keys are converted | ||
to Python attributes. The JSON object's keys must follow these rules, otherwise a `ValueError` will be raised: | ||
|
||
1. The string may not be empty | ||
1. The string may only contain letters, numbers, and the underscore (`_`) character | ||
1. The string may not begin with a number | ||
1. The string should be in `ALL_CAPS` | ||
|
||
The JSON key is converted into a Python attribute of the configuration object. For example, this JSON file | ||
```json | ||
{ | ||
"CLOCK_MULTIPLIER": 4, | ||
"HARD_SYNC": true, | ||
"WAVE_SHAPE": "sine" | ||
} | ||
``` | ||
would produce a Python object with these attributes: | ||
```python | ||
>>> dir(config_object) | ||
[ | ||
'__class__', | ||
'__init__', | ||
'__module__', | ||
'__qualname__', | ||
'__dict__', | ||
'to_attr_name', | ||
'CLOCK_MULTIPLIER', | ||
'HARD_SYNC', | ||
'WAVE_SHAPE' | ||
] | ||
|
||
>>> config_object.CLOCK_MULTIPLIER | ||
4 | ||
|
||
>>> config_object.HARD_SYNC | ||
True | ||
|
||
>>> config_object.WAVE_SHAPE | ||
'sine' | ||
``` | ||
|
||
`europi.py` contains objects called `europi_config` and `experimental_config` which implement the core & experimental | ||
customizations described in the sections above. Below is a detailed summary of the contents of these objects: | ||
|
||
```python | ||
>>> from europi import europi_config | ||
>>> dir(europi_config) | ||
[ | ||
'__class__', | ||
'__init__', | ||
'__module__', | ||
'__qualname__', | ||
'__dict__', | ||
'to_attr_name', | ||
'CPU_FREQ', | ||
'DISPLAY_CHANNEL', | ||
'DISPLAY_HEIGHT', | ||
'DISPLAY_SCL', | ||
'DISPLAY_SDA', | ||
'DISPLAY_WIDTH', | ||
'EUROPI_MODEL', | ||
'GATE_VOLTAGE', | ||
'MAX_INPUT_VOLTAGE', | ||
'MAX_OUTPUT_VOLTAGE', | ||
'PICO_MODEL', | ||
'ROTATE_DISPLAY' | ||
] | ||
``` | ||
|
||
When you import `europi` into your project you can access the `europi_config` object like this: | ||
```python | ||
from europi import * | ||
|
||
# A voltage range we can select from in a user menu | ||
VOLTAGE_RANGE = range(0, europi_config.MAX_OUTPUT_VOLTAGE) | ||
``` | ||
|
||
Alternatively, you can access it using the fully qualified namespace: | ||
```python | ||
import europi | ||
mjaskula marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
# A voltage range we can select from in a user menu | ||
VOLTAGE_RANGE = range(0, europi.europi_config.MAX_OUTPUT_VOLTAGE) | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this link is broken again because it's already inside
software
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the leading
/
so it shouldn't be broken anymore: https://github.com/Allen-Synthesis/EuroPi/blob/d283522d5778423293db06455bb901485266f0b6/software/CONFIGURATION.mdThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It still seems broken, I think it's the fact CONFIGURATION is inside software already, so it would need either ./ to go up and then down one folder, or just start with firmware/
[experimental features](firmware/experimental/__init__.py)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I view the file in question here: https://github.com/Allen-Synthesis/EuroPi/blob/c9a3acac9fc9f2b350c4e3f5a93e47575781845f/software/CONFIGURATION.md the link is working. How/where are you looking at it where the link is broken?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'll probably be fine once merged. It works for me in that linked file, but not in the rich diff when I look at the PR