Skip to content

Add GRID_MUX_UNUSED macro and improve module mux handling#312

Draft
SukuWc wants to merge 26 commits intomasterfrom
SUKU-module-mux-improvements
Draft

Add GRID_MUX_UNUSED macro and improve module mux handling#312
SukuWc wants to merge 26 commits intomasterfrom
SUKU-module-mux-improvements

Conversation

@SukuWc
Copy link
Member

@SukuWc SukuWc commented Feb 1, 2026

  • Add GRID_MUX_UNUSED macro to grid_ain.h for cross-platform use
  • Rename mux_position to element_index for clarity
  • Add bounds asserts before array access
  • Add if-guards for unused mux indices where needed
  • Replace magic numbers with defines
  • Fix EF44 invalid lookup entries (10,8,11,9 -> unused)

Modules updated: EF44, PBF4, TEK1, TEK2

- Add GRID_MUX_UNUSED macro to grid_ain.h for cross-platform use
- Rename mux_position to element_index for clarity
- Add bounds asserts before array access
- Add if-guards for unused mux indices where needed
- Replace magic numbers with defines
- Fix EF44 invalid lookup entries (10,8,11,9 -> unused)

Modules updated: EF44, PBF4, TEK1, TEK2

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
SukuWc and others added 18 commits February 1, 2026 15:03
- Replace mux_overflow count with mux_positions_bm bitmask to support
  non-contiguous mux positions (e.g., PBF4 skips positions 4-5)
- Add GRID_MUX_FIRST_VALID and GRID_MUX_INCREMENT macros for shared
  mux index manipulation between ESP32 and ULP
- ULP now skips invalid mux positions, improving efficiency on Rev H
- Update all module init calls to use binary bitmask notation
- PBF4/TEK2: replace if-guard with assert since invalid positions
  are now skipped at driver level

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add GRID_AIN_INTERNAL_RESOLUTION, GRID_ADC_MAX, GRID_ADC_INVERT macros
- Add GRID_POTMETER_DEADZONE, GRID_POTMETER_CENTER platform constants
- Move GRID_MUX_* macros from grid_esp32_pins.h to grid_ain.h (shared)
- Refactor D51 BU16/PO16/PBF4 to use for loop and interleaved lookup tables
- Normalize D51 BU16 to 12-bit internal resolution (was 16-bit)
- Add invert_result_lookup tables for consistent polarity handling
- Add grid_common dependency to grid_esp32_adc for ULP build

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
… data flow

- Add GRID_ADC_DOWNSAMPLE and GRID_ADC_INVERT_COND macros to grid_ain.h
- Convert all D51 modules to use 2D mux_element_lookup[channel][mux_position]
- Use element_invert_bm bitmask for constant-time conditional inversion
- Standardize callback data flow: raw -> inverted -> downsampled
- Move adcs array to global scope with correct MUX->ADC mapping
- Rename loop iterator to 'channel' for clarity

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…flow

- Convert to 2D mux_element_lookup[channel][mux_state]
- Use element_invert_bm bitmask with GRID_ADC_INVERT_COND macro
- Standardize signal flow: raw -> inverted -> downsampled -> ASC -> store
- Use GRID_AIN_INTERNAL_RESOLUTION instead of hardcoded 12

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…stent signal flow

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…ent index

- Add ASC pass-through (factor=1) to D51 module drivers for cross-platform consistency
- Refactor grid_asc_process signature to take array and index separately
- Change ASC indexing from ADC position to element_index across all modules
- Adjust array sizes to match element counts (PBF4: 12, EF44: 8)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Change first param from grid_ui_element* to grid_ui_model*
- Add element_index param to derive element internally
- Add assertions for ui pointer and bounds checking
- Rename input_channel to element_index for clarity
- Update all call sites across D51 and ESP32 modules

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Convert static arrays to dynamically allocated memory using
grid_platform_allocate_volatile(), matching the ESP32 pattern
for cross-platform consistency.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Refactor UI state management to store state structs inside grid_ui_element
using primary_state and secondary_state void pointers instead of separate
module-level arrays. This centralizes state ownership in the element itself.

State mapping:
- Potmeter: primary_state = potmeter_state
- Button: primary_state = button_state
- Encoder: primary_state = encoder_state, secondary_state = button_state
- Endless: primary_state = endless_state, secondary_state = button_state

Changes:
- Add primary_state/secondary_state to grid_ui_element struct
- Allocate state in element init functions (button, encoder, endless, potmeter)
- Simplify store_input signatures by removing state parameters
- Update all ESP32 and D51 module drivers to use element state
- Replace hardcoded magic numbers with GRID_AIN_INTERNAL_RESOLUTION
- Replace hardcoded loop bounds with module constants

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…ored adc_bit_depth

- Remove adc_bit_depth parameter from button, potmeter, endless store_input
- Store adc_bit_depth in potmeter and endless state structs during init
- Create grid_ui_encoder_sample and grid_ui_endless_sample structs
- Pass sample structs by value to store_input functions
- Move button_store_input calls inside encoder and endless store_input
- Add GRID_UI_ENCODER_NIBBLE_FROM_BUFFER and SAMPLE_FROM_NIBBLE macros
- Fix endless hardcoded 12-bit resolution to use state->adc_bit_depth

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
TEK2:
- Convert 1D lookup to 2D mux_element_lookup[channel][mux_state]
- Move lookup table outside ISR function
- Remove unused variables (ele, endless_index, elements)
- Rename constants: BUT_NUM/POT_NUM -> BUTTON_NUM/ENDLESS_NUM
- Combine two init loops into single type-based loop
- Use element_index for asc_process instead of lookup_index
- Simplify endless phase handling with if/else on mux_state

PBF4:
- Use assert for GRID_MUX_UNUSED check (consistent with TEK2)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…log buttons

- Merge vsn1l/vsn1r/vsn2 analog functions into single vsnx_process_analog
- Merge all encoder functions into single vsnx_process_minibutton
- Use lookup table pointers (vsnx_mux_lookup, vsnx_minibutton_lookup)
- Remove is_legacy_analog_buttons support (minibuttons always digital)
- Remove minibutton entries from analog lookup tables
- Rename constants: BUTTON_COUNT (0-7), MINIBUTTON_COUNT (shift register)
- Simplify conditions: use element_index instead of element type checks
- Add comment explaining encoder driver reads minibuttons via shift registers

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- _BUT_NUM → _BUTTON_COUNT
- _POT_NUM → _POTMETER_COUNT
- _ENC_NUM → _ENCODER_COUNT
- _BUTTON_NUM → _BUTTON_COUNT
- _ENDLESS_NUM → _ENDLESS_COUNT

Affected modules: BU16, EF44, EN16, PBF4, PO16, TEK2 (both ESP32 and D51)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Rename grid_esp32_module_tek1 to grid_esp32_module_vsnx
- Merge tek2 functionality into vsnx driver using lookup tables
- Remove grid_esp32_module_tek2 component (now handled by vsnx)
- Drop TEK1_RevA support
- Extract LCD init into vsnx_lcd_init function
- Remove .vscode folder

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Extract init_lcd_panel() helper to reduce code duplication.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
void grid_ulp_adc_mux_init(void) {
void grid_platform_mux_write(uint8_t index) {
mux_index = index;
ulp_riscv_gpio_output_level(GRID_ESP32_PINS_MUX_1_A, mux_index / 1 % 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check what this division and remainder assembles to, these were '&' previously

SukuWc and others added 7 commits February 11, 2026 16:55
…_init on both architectures

Create grid_d51_adc and grid_d51_encoder abstractions mirroring the ESP32
pattern. Each D51 module now provides a process_analog/process_encoder
callback instead of duplicating hardware init, transfer, and ISR code.
Fold grid_platform_mux_init into adc_init on both D51 and ESP32 so modules
pass the mux bitmask at init time.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Change grid_ui_button_state_init, grid_ui_potmeter_state_init, and
grid_ui_encoder_state_init to take (ui, element_index) instead of raw
state pointers. Each function now resolves primary/secondary state
internally, matching the existing store_input pattern. Add new
grid_ui_endless_state_init following the same convention. Encoder and
endless state_init handle button secondary state initialization
internally, removing duplicate loops from all module drivers.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…wnsample

Move grid_adc_result, grid_process_analog_t, grid_encoder_result, and
grid_process_encoder_t into common headers. Callbacks receive properly
typed pointers instead of void*. D51 ADC driver downsamples to 12-bit
before calling process_analog. Encoder drivers skip hwcfg byte and
accept transfer_length parameter for bounds checking.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…X buffer

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…parameter, unify D51 to 2000 Hz

Each module now computes and passes its own clock_rate to the encoder
driver, making the callback frequency explicit and consistent across
platforms. D51 modules adjusted from ~4167/~1389 Hz to 2000 Hz to
match ESP32.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants