europi

package module
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2022 License: MIT Imports: 9 Imported by: 3

README

EuroPiGo

Go Reference

Alternate firmware for the Allen Synthesis EuroPi written in Go.

Getting started

Install Go

https://go.dev/doc/install

Install TinyGo

https://tinygo.org/getting-started/install

Install the TinyGo VSCode plugin

https://marketplace.visualstudio.com/items?itemName=tinygo.vscode-tinygo

Build the example

Use the tinygo flash command while your pico is in BOOTSEL mode to compile the script and copy it to your attached EuroPi pico.

tinygo flash --target pico examples/diagnostics.go

After the first time you flash your TinyGo program you will no longer need to reboot in BOOTSEL mode to flash your script.

NOTE: If your script throws a panic, you will need to reflash using BOOTSEL mode.

Serial printing

When your EuroPi pico is connected via USB you can view printed serial output using a tool like minicom.

For example, a line in your code like:

log.Printf("K1: %2.2f\n\r", e.K1.ReadVoltage())

You can launch minicom to view the printed output:

minicom -b 115200 -o -D /dev/ttyACM0

VSCode build task

Add the TinyGo flash command as your default build task:

Ctrl + Shift + P > Tasks: Configure Default Build Task

Use the following example task configuration to set tinygo flash as your default build command:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "tinygo flash",
            "type": "shell",
            "command": "tinygo flash --target pico -size short -opt 1 ${workspaceRoot}/examples",
            "group": {
                "kind": "build",
                "isDefault": true
            },
        }
    ]
}

Now you can build and flash your project using Ctrl + Shift + B or search for the command:

Ctrl + Shift + P > Tasks: Run Build Task

Debugging using picoprobe

TODO

Why should I use this?

You probably shouldn't. This is my passion project because I love Go. You should probably be using the official EuroPi firmware. But if you are interested in writing a dedicated script for the EuroPi that requires concurrency and faster performance than MicroPython can offer, then maybe this is the right firmware for you!

Documentation

Index

Constants

View Source
const (
	// Calibrated[Min|Max]AI was calculated using the EuroPi calibration program:
	// https://github.com/Allen-Synthesis/EuroPi/blob/main/software/programming_instructions.md#calibrate-the-module
	CalibratedMinAI = 384
	CalibratedMaxAI = 44634

	DefaultSamples = 1000
)
View Source
const (
	OLEDFreq   = machine.TWI_FREQ_400KHZ
	OLEDAddr   = 0x3C
	OLEDWidth  = 128
	OLEDHeight = 32
)
View Source
const (
	MaxVoltage = 10.0
	MinVoltage = 0.0
)
View Source
const (
	// Manually calibrated to best match expected voltages. Additional info:
	// https://github.com/Allen-Synthesis/EuroPi/blob/main/software/programming_instructions.md#calibrate-the-module
	CalibratedOffset = 32
	// The default PWM Top of MaxUint16 caused noisy output. Dropping this down to a 12bit value resulted in much smoother cv output.
	CalibratedTop = 0xfff - CalibratedOffset
)
View Source
const DefaultDebounceDelay = time.Duration(50 * time.Millisecond)

Variables

View Source
var (
	DefaultChannel = machine.I2C0
	DefaultFont    = &proggy.TinySZ8pt7b
	White          = color.RGBA{255, 255, 255, 255}
)

Functions

func Clamp

func Clamp[V uint8 | uint16 | int | float32](value, low, high V) V

Clamp returns a value that is no lower than "low" and no higher than "high".

func DebugMemoryUsage added in v0.1.3

func DebugMemoryUsage()

Types

type AnalogInput

type AnalogInput struct {
	machine.ADC
	// contains filtered or unexported fields
}

A struct for handling the reading of analogue control voltage. The analogue input allows you to 'read' CV from anywhere between 0 and 12V.

func NewAI

func NewAI(pin machine.Pin) *AnalogInput

NewAI creates a new AnalogInput.

func (*AnalogInput) Percent

func (a *AnalogInput) Percent() float32

Percent return the percentage of the input's current relative range as a float between 0.0 and 1.0.

func (*AnalogInput) Range

func (a *AnalogInput) Range(steps uint16) uint16

Range return a value between 0 and the given steps (not inclusive) based on the range of the analog input.

func (*AnalogInput) ReadVoltage

func (a *AnalogInput) ReadVoltage() float32

ReadVoltage return the current read voltage between 0.0 and 10.0 volts.

func (*AnalogInput) Samples

func (a *AnalogInput) Samples(samples uint16)

Samples sets the number of reads for an more accurate average read.

type AnalogReader

type AnalogReader interface {
	Samples(samples uint16)
	ReadVoltage() float32
	Percent() float32
	Range(steps uint16) uint16
}

AnalogReader is an interface for common analog read methods for knobs and cv input.

type Button

type Button struct {
	Pin machine.Pin
	// contains filtered or unexported fields
}

Button is a struct for handling push button behavior.

func NewButton

func NewButton(pin machine.Pin) *Button

NewButton creates a new Button struct.

func (*Button) Handler

func (b *Button) Handler(handler func(p machine.Pin))

Handler sets the callback function to be call when the button is pressed.

func (*Button) HandlerWithDebounce added in v0.1.3

func (b *Button) HandlerWithDebounce(handler func(p machine.Pin), delay time.Duration)

Handler sets the callback function to be call when the button is pressed and debounce delay time has elapsed.

func (*Button) LastInput

func (b *Button) LastInput() time.Time

LastInput return the time of the last button press.

func (*Button) Value

func (b *Button) Value() bool

Value returns true if button is currently pressed, else false.

type DigitalInput

type DigitalInput struct {
	Pin machine.Pin
	// contains filtered or unexported fields
}

DigitalInput is a struct for handling reading of the digital input.

func NewDI

func NewDI(pin machine.Pin) *DigitalInput

NewDI creates a new DigitalInput struct.

func (*DigitalInput) Handler

func (d *DigitalInput) Handler(handler func(p machine.Pin))

Handler sets the callback function to be call when a rising edge is detected.

func (*DigitalInput) HandlerWithDebounce added in v0.1.3

func (d *DigitalInput) HandlerWithDebounce(handler func(p machine.Pin), delay time.Duration)

Handler sets the callback function to be call when a rising edge is detected and debounce delay time has elapsed.

func (*DigitalInput) LastInput

func (d *DigitalInput) LastInput() time.Time

LastInput return the time of the last high input (triggered at 0.8v).

func (*DigitalInput) Value

func (d *DigitalInput) Value() bool

Value returns true if the input is high (above 0.8v), else false.

type DigitalReader

type DigitalReader interface {
	Handler(func(machine.Pin))
	HandlerWithDebounce(func(machine.Pin), time.Duration)
	LastInput() time.Time
	Value() bool
}

DigitalReader is an interface for common digital inputs methods.

type Display

type Display struct {
	ssd1306.Device
	// contains filtered or unexported fields
}

Display is a wrapper around `ssd1306.Device` for drawing graphics and text to the OLED.

func NewDisplay

func NewDisplay(channel *machine.I2C, sdaPin, sclPin machine.Pin) *Display

NewDisplay returns a new Display struct.

func (*Display) Font

func (d *Display) Font(font *tinyfont.Font)

Font overrides the default font used by `WriteLine`.

func (*Display) WriteLine

func (d *Display) WriteLine(text string, x, y int16)

WriteLine writes the given text to the display where x, y is the bottom leftmost pixel of the text.

type EuroPi

type EuroPi struct {
	// Display is a wrapper around ssd1306.Device
	Display *Display

	DI DigitalReader
	AI AnalogReader

	B1 DigitalReader
	B2 DigitalReader

	K1 AnalogReader
	K2 AnalogReader

	CV1 Outputer
	CV2 Outputer
	CV3 Outputer
	CV4 Outputer
	CV5 Outputer
	CV6 Outputer
	CV  [6]Outputer
}

EuroPi is the collection of component wrappers used to interact with the module.

func New

func New() *EuroPi

New will return a new EuroPi struct.

type Knob

type Knob struct {
	machine.ADC
	// contains filtered or unexported fields
}

A struct for handling the reading of knob voltage and position.

func NewKnob

func NewKnob(pin machine.Pin) *Knob

NewKnob creates a new Knob struct.

func (*Knob) Percent

func (k *Knob) Percent() float32

Percent return the percentage of the knob's current relative range as a float between 0.0 and 1.0.

func (*Knob) Range

func (k *Knob) Range(steps uint16) uint16

Range return a value between 0 and the given steps (not inclusive) based on the range of the knob's position.

func (*Knob) ReadVoltage

func (k *Knob) ReadVoltage() float32

ReadVoltage return the current read voltage between 0.0 and 10.0 volts.

func (*Knob) Samples

func (k *Knob) Samples(samples uint16)

Samples sets the number of reads for an more accurate average read.

type Output

type Output struct {
	// contains filtered or unexported fields
}

Outputer is struct for interacting with the cv output jacks.

func NewOutput

func NewOutput(pin machine.Pin, pwm PWMer) *Output

NewOutput returns a new Output struct.

func (*Output) Get

func (o *Output) Get() uint32

Get returns the current set voltage in the range of 0 to pwm.Top().

func (*Output) Off

func (o *Output) Off()

Off sets the current voltage low at 0.0v.

func (*Output) On

func (o *Output) On()

On sets the current voltage high at 10.0v.

func (*Output) Voltage

func (o *Output) Voltage(v float32)

Voltage sets the current output voltage within a range of 0.0 to 10.0.

type Outputer

type Outputer interface {
	Get() (value uint32)
	Voltage(v float32)
	On()
	Off()
}

Outputer is an interface for interacting with the cv output jacks.

type PWMer

type PWMer interface {
	Configure(config machine.PWMConfig) error
	Channel(pin machine.Pin) (channel uint8, err error)
	Top() uint32
	SetTop(top uint32)
	Get(channel uint8) (value uint32)
	Set(channel uint8, value uint32)
	SetPeriod(period uint64) error
}

PWMer is an interface for interacting with a machine.pwmGroup

Directories

Path Synopsis
clockwerk
Clockwerk author: Adam Wonak (github.com/awonak) date: 2022-09-12 labels: clock
Clockwerk author: Adam Wonak (github.com/awonak) date: 2022-09-12 labels: clock

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL