Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8503e38
Add Cosmolab board support
Dec 5, 2025
7a7b563
Add .DS_Store to gitignore
Dec 5, 2025
2373da1
Fix .gitignore: properly ignore .DS_Store files
Dec 5, 2025
be8efa9
Merge cosmolab-clean: Add Cosmolab board support
Dec 5, 2025
0843b3a
Update libdaisy submodule to v8.0.0
Dec 5, 2025
e3a052d
Add missing component definitions and json2daisy files
Dec 5, 2025
0c9e482
Update oopsy.js to use json2daisy for component definitions
Dec 5, 2025
2d1ff05
Fix Makefile generation: add hardware.includes and APP_TYPE support
Dec 5, 2025
e913e64
Update genlib_daisy.h and component_defs.json for libdaisy v8.0.0 com…
Dec 5, 2025
c20c342
Update UartHandler API for libdaisy v8.0.0
Dec 5, 2025
8208385
Add MIDI RX callback implementation for libdaisy v8.0.0 DMA listen mode
Dec 5, 2025
b2f8102
Fix: use class static midi_rx_buffer instead of local variable
Dec 5, 2025
2b14b9b
Fix component definitions for libdaisy v8.0.0
Dec 5, 2025
335db1c
Fix hardware.seed references and Switch PULL_UP for libdaisy v8.0.0
Dec 5, 2025
8017758
Fix Switch PULL_UP to GPIO::Pull::PULLUP for libdaisy v8.0.0
Dec 5, 2025
dc0fb42
Fix GPIOPort enum: use PORTB instead of GPIOPort::B
Dec 5, 2025
040ed20
Fix Makefile: only include petal_sm source when som is petal_125b_sm
Dec 5, 2025
47765a3
Fix ResetToBootloader: add BootloaderMode parameter
Dec 5, 2025
a6a94a9
Add comprehensive changelog for libdaisy v8.0.0 update and Cosmolab s…
Dec 5, 2025
78c513d
Fix date: December 2025 instead of 2024
Dec 5, 2025
a47e245
feat: Add Cosmolab board support with libDaisy v8.0.0
Dec 8, 2025
db072c5
Fix CV outs
Dec 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,13 @@ help/*.h
help/*.json
templates/*.cpp
templates/*.h
templates/*.json
templates/*.json
.DS_Store
*.DS_Store
**/.DS_Store

# Cosmolab hardware v1 (prototypes only, not for distribution)
source/cosmolab_hw_v1.json
source/COSMOLAB_BOARDS_README.md
COSMOLAB_README.md
COSMOLAB_BUTTON_POLARITY_FIX.md
68 changes: 68 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Changelog - Cosmolab Oopsy Support

All notable changes to Cosmolab board support in oopsy.

## [1.0.0] - 2025-12-08

### Added
- **Full Cosmolab hardware support**
- 32 LED-backlit buttons via CD4021 shift registers
- 32 button LEDs via PCA9685 I2C drivers
- 8 potentiometers via CD4051 multiplexer (already supported in oopsy)
- 16 knob LEDs (2 per knob: illumination + position indicator) via PCA9685
- 4 CV inputs, 2 CV outputs (Eurorack compatible)
- 1 Trigger input, 1 Trigger output (Eurorack compatible)
- MIDI I/O, OLED display (64x32)

- **Updated to libDaisy v8.0.0 (from v5.x)**
- Improved MIDI handling with DMA listen mode
- Better hardware compatibility
- Bug fixes and performance improvements

- **Fixed PCA9685 LED driver support**
- Added `hardware.LoopProcess()` call in main loop (line 958 of genlib_daisy.h)
- Enables proper I2C LED driver updates
- **Benefits all boards using PCA9685 or other I2C peripherals**

- **Added CD4021 shift register support**
- New `CD4021` parent component for shift register chains
- New `CD4021Switch` for normal polarity (pull-down resistors)
- New `CD4021SwitchInverted` for inverted polarity (pull-up resistors)
- Includes debouncing and edge detection
- **Supports both common hardware configurations**

### Changed
- Updated `genlib_daisy.h` to support boards with I2C peripherals
- Updated MIDI UART handling for libDaisy v8.0.0 compatibility

### Technical Notes

**LoopProcess() Fix:**
The addition of `hardware.LoopProcess()` was essential for boards with peripherals requiring periodic servicing. This is not oopsy-specific—it's a general requirement for boards using:
- I2C LED drivers (PCA9685, etc.)
- I2C sensors or displays
- Any hardware requiring non-audio-rate updates

**Component Polarity Support:**
Following libDaisy's `Switch::POLARITY_NORMAL/INVERTED` pattern, we added both normal and inverted variants for CD4021 shift registers to support different pull resistor configurations without forcing hardware redesigns.

---

## Testing

Tested on actual Cosmolab hardware:
- ✅ All 32 buttons
- ✅ All 48 LEDs
- ✅ All 8 potentiometers
- ✅ CV I/O
- ✅ MIDI I/O
- ✅ Display
- ✅ Audio I/O

---

## See Also

- `COSMOLAB_README.md` - Detailed technical documentation
- `source/cosmolab.json` - Board definition
- `source/COSMOLAB_BOARDS_README.md` - Board selection guide
220 changes: 220 additions & 0 deletions COSMOLAB_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
# Cosmolab Support for Oopsy

This document describes the work done to bring Cosmolab board support to oopsy, including the fixes and enhancements needed to make all hardware components work correctly.

## Overview

Cosmolab is a Eurorack/desktop music production board based on the Daisy Seed platform. It features:
- 32 LED-backlit buttons (via PCA9685 I2C LED drivers)
- 8 potentiometers with dual LED feedback (via CD4051 multiplexer)
- Each knob has 2 LEDs: one underneath for illumination, one above at 12 o'clock position
- 4 CV inputs, 2 CV outputs (Eurorack compatible)
- 1 Trigger input, 1 Trigger output (Eurorack compatible)
- OLED display (64x32)
- MIDI I/O
- Audio I/O (2 channels)

## Version History

### v1.0.0 (2025-12-08)
- ✅ Full Cosmolab hardware support
- ✅ Updated to libDaisy v8.0.0 (from v5.x)
- ✅ Fixed PCA9685 LED driver support
- ✅ Added CD4021SwitchInverted component for hardware flexibility

---

## Technical Implementation

### 1. LibDaisy v8.0.0 Update

**Challenge:** Oopsy was using an older version of libDaisy (v5.x), which had API differences and missing features needed for Cosmolab.

**Solution:** Updated oopsy to use libDaisy v8.0.0, including:
- Updated MIDI UART handling (now uses DMA listen mode)
- Updated hardware initialization patterns
- Compatibility with newer Daisy Seed bootrom

**Files Modified:**
- `source/genlib_daisy.h` - Updated MIDI callbacks and initialization
- Submodule `source/libdaisy` - Updated to v8.0.0

---

### 2. PCA9685 LED Driver Support

**Problem:** The PCA9685 I2C LED drivers (which control all 48 LEDs on Cosmolab) were not being updated in the main loop, causing LEDs to remain off or not respond to software commands.

**Root Cause:** Oopsy's main loop was missing a call to `hardware.LoopProcess()`, which is required for hardware components that need periodic servicing (like I2C-based LED drivers).

**Solution:** Added `hardware.LoopProcess()` call in the main UI update loop.

**Technical Details:**
```cpp
// In genlib_daisy.h, line 958:
// Call hardware loop processing (LED drivers, etc.)
hardware.LoopProcess();
```

This call triggers:
- PCA9685 buffer swap and I2C transmission
- Any other hardware-specific loop processing needed by the board class

**Why This Fix Helps Others:**
- **Any board with PCA9685 LED drivers** will need this fix
- **Any board with I2C peripherals** that need periodic updates
- The fix is board-agnostic and doesn't break existing boards

**Files Modified:**
- `source/genlib_daisy.h` (line 958)

---

### 3. CD4021 Shift Register Button Support

**Problem:** CD4021 shift registers (used to read 32 buttons) needed proper debouncing and edge detection.

**Solution:** Added comprehensive CD4021 support with two polarity options:
- `CD4021Switch` - For hardware with pull-down resistors (standard)
- `CD4021SwitchInverted` - For hardware with pull-up resistors

**Why Two Components?**
Different hardware designs use different pull resistor configurations:
- Pull-down: Button press = HIGH, released = LOW (less common)
- Pull-up: Button press = LOW, released = HIGH (more common, less wiring)

This mirrors libDaisy's own `Switch::POLARITY_NORMAL` and `Switch::POLARITY_INVERTED` pattern.

**Technical Details:**

Normal polarity (`CD4021Switch`):
```cpp
state == 0xFF → button released (buffer full of 1s)
state != 0xFF → button pressed
```

Inverted polarity (`CD4021SwitchInverted`):
```cpp
state == 0xFF → button pressed (hardware inverted, reads as 1s)
state != 0xFF → button released
```

**Why This Fix Helps Others:**
- CD4021 is a standard shift register for button matrices
- Both pull-up and pull-down configurations are valid design choices
- Having both options avoids forcing specific hardware decisions
- Useful for any project reading 8+ buttons via shift registers

**Files Modified:**
- `source/component_defs.json` - Added CD4021, CD4021Switch, and CD4021SwitchInverted

---

### 4. Board Definition Files

Created comprehensive board definition for Cosmolab hardware:

**`source/cosmolab.json`** - Main board definition with:
- PCA9685 LED driver configuration (3 drivers, 48 LEDs total)
- CD4021 shift register configuration (4 chips, 32 buttons total)
- CD4051 multiplexer configuration (8 potentiometers)
- CV inputs/outputs, switches, MIDI, display

**Component Hierarchy:**
```
cosmolab.json
├── Parents (shared peripherals):
│ ├── i2c (for LED drivers and display)
│ ├── led_driver (PCA9685 x3)
│ ├── pad_shift (CD4021 x4)
│ └── pot_mux (CD4051)
└── Components:
├── 32 buttons (pada1-padd8) via pad_shift
├── 32 LEDs for buttons (led_key_a*-d*) via led_driver
├── 8 knobs (knob1-8) via pot_mux
├── 16 LEDs for knobs (2 per knob: led_knob_*, led_knob_under_*) via led_driver
├── 4 CV inputs
├── 2 CV outputs
├── 1 Trigger input (Eurorack)
├── 1 Trigger output (Eurorack)
├── 2 switches
└── OLED display (64x32)
```

---

## Key Learnings & Best Practices

### 1. Hardware Loop Processing
**Always call `hardware.LoopProcess()` in the main loop** if your board has:
- I2C peripherals (LED drivers, displays, sensors)
- SPI peripherals that need periodic updates
- Any component requiring non-audio-rate servicing

### 2. Component Design Patterns
When adding new component types to oopsy:
- Follow lib Daisy's naming and patterns (e.g., POLARITY_NORMAL/INVERTED)
- Provide both hardware configuration options when reasonable
- Document hardware requirements clearly
- Test with actual hardware, not just simulation

### 3. Multiplexer Best Practices
- CD4051 (analog mux): Great for potentiometers, saves ADC inputs
- CD4021 (shift register): Perfect for button matrices, saves GPIO
- Document select pin mapping clearly
- Consider debouncing for shift register inputs

### 4. Pull Resistor Considerations
- Pull-up: More common, less wiring, better noise immunity
- Pull-down: Less common, explicit about "pressed" state
- Support both in software for maximum hardware flexibility

---

## Files Modified Summary

| File | Purpose | Lines Changed |
|------|---------|---------------|
| `source/genlib_daisy.h` | Added LoopProcess() call | ~1 |
| `source/component_defs.json` | Added CD4021, CD4051, variants | ~100 |
| `source/cosmolab.json` | Board definition | New file |
| `source/libdaisy/` (submodule) | Updated to v8.0.0 | Submodule |

---

## Testing

All features tested on actual Cosmolab hardware:
- ✅ All 32 buttons working with correct LED feedback
- ✅ All 8 potentiometers reading correctly
- ✅ CV inputs/outputs functioning
- ✅ OLED display working
- ✅ MIDI I/O operational
- ✅ Audio I/O clean and stable

---

## Future Enhancements

- [ ] Consider contributing fixes upstream to official oopsy repo
- [ ] Add polarity as a parameter instead of separate components
- [ ] Document more complex board definition patterns
- [ ] Add examples using Cosmolab-specific features

---

## Credits

- **Faselunare** - Cosmolab hardware design
- **Electro-Smith** - Daisy platform and libDaisy
- **oopsy** - Gen~ to Daisy bridge

## References

- [Oopsy GitHub](https://github.com/electro-smith/oopsy)
- [libDaisy Documentation](https://electro-smith.github.io/libDaisy/)
- [Daisy Wiki](https://github.com/electro-smith/DaisyWiki/wiki)
- [PCA9685 Datasheet](https://www.nxp.com/docs/en/data-sheet/PCA9685.pdf)
- [CD4051 Datasheet](https://www.ti.com/product/CD4051B)
- [CD4021 Datasheet](https://www.ti.com/product/CD4021B)
Loading