Skip to content
19 changes: 19 additions & 0 deletions common/src/c/grid_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "grid_ui_lcd.h"
#include "grid_ui_potmeter.h"
#include "grid_ui_system.h"
#include "grid_ui_touch.h"

extern struct luaL_Reg* grid_lua_api_gui_lib_reference;

Expand Down Expand Up @@ -60,6 +61,9 @@ void grid_lua_ui_init(struct grid_lua_model* lua) {
case GRID_PARAMETER_ELEMENT_LCD: {
GRID_LUA_UI_INIT_ASSIGN(GRID_LUA_L);
} break;
case GRID_PARAMETER_ELEMENT_TOUCH: {
GRID_LUA_UI_INIT_ASSIGN(GRID_LUA_T);
} break;
default:
assert(0);
break;
Expand Down Expand Up @@ -255,3 +259,18 @@ void grid_module_octv_ui_init(struct grid_ain_model* ain, struct grid_led_model*

ui->lua_ui_init_callback = grid_lua_ui_init;
}

void grid_module_xy_ui_init(struct grid_ain_model* ain, struct grid_led_model* led, struct grid_ui_model* ui) {

grid_led_init(led, 25);
grid_led_lookup_alloc_identity(led, 0, 25);

grid_ui_model_init(ui, 6);

for (uint8_t i = 0; i < 5; i++) {
grid_ui_element_touch_init(grid_ui_element_model_init(ui, i));
}
grid_ui_element_system_init(grid_ui_element_model_init(ui, 5));

ui->lua_ui_init_callback = grid_lua_ui_init;
}
1 change: 1 addition & 0 deletions common/src/c/grid_module.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ void grid_module_pbf4_ui_init(struct grid_ain_model* ain, struct grid_led_model*
void grid_module_en16_ui_init(struct grid_ain_model* ain, struct grid_led_model* led, struct grid_ui_model* ui);
void grid_module_ef44_ui_init(struct grid_ain_model* ain, struct grid_led_model* led, struct grid_ui_model* ui);
void grid_module_octv_ui_init(struct grid_ain_model* ain, struct grid_led_model* led, struct grid_ui_model* ui);
void grid_module_xy_ui_init(struct grid_ain_model* ain, struct grid_led_model* led, struct grid_ui_model* ui);

#endif /* GRID_MODULE_H */
10 changes: 10 additions & 0 deletions common/src/c/grid_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,16 @@ int grid_hwcfg_module_is_octv(struct grid_sys_model* sys) {
}
}

int grid_hwcfg_module_is_xy(struct grid_sys_model* sys) {

switch (grid_sys_get_hwcfg(sys)) {
case GRID_MODULE_XY_RevH:
return 1;
default:
return 0;
}
}

int grid_hwcfg_module_is_pbf4(struct grid_sys_model* sys) {

switch (grid_sys_get_hwcfg(sys)) {
Expand Down
1 change: 1 addition & 0 deletions common/src/c/grid_sys.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ int grid_hwcfg_module_is_bu16(struct grid_sys_model* sys);
int grid_hwcfg_module_is_ef44(struct grid_sys_model* sys);
int grid_hwcfg_module_is_en16(struct grid_sys_model* sys);
int grid_hwcfg_module_is_octv(struct grid_sys_model* sys);
int grid_hwcfg_module_is_xy(struct grid_sys_model* sys);
int grid_hwcfg_module_is_pbf4(struct grid_sys_model* sys);
int grid_hwcfg_module_is_po16(struct grid_sys_model* sys);
int grid_hwcfg_module_is_tek2(struct grid_sys_model* sys);
Expand Down
1 change: 1 addition & 0 deletions common/src/c/grid_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void grid_ele_eve_to_value_idx_init(uint8_t map[GRID_PARAMETER_ELEMENT_COUNT][GR
map[GRID_PARAMETER_ELEMENT_ENCODER][GRID_PARAMETER_EVENT_ENCODER] = GRID_LUA_FNC_E_ENCODER_VALUE_index;
map[GRID_PARAMETER_ELEMENT_ENDLESS][GRID_PARAMETER_EVENT_BUTTON] = GRID_LUA_FNC_EP_BUTTON_VALUE_index;
map[GRID_PARAMETER_ELEMENT_ENDLESS][GRID_PARAMETER_EVENT_ENDLESS] = GRID_LUA_FNC_EP_ENDLESS_VALUE_index;
map[GRID_PARAMETER_ELEMENT_TOUCH][GRID_PARAMETER_EVENT_TOUCH] = GRID_LUA_FNC_T_TOUCH_X_index;
}

struct grid_ui_model grid_ui_state = {0};
Expand Down
1 change: 1 addition & 0 deletions d51n20a/gcc/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ SRCS = \
common/src/c/grid_ui_lcd.c \
common/src/c/grid_ui_potmeter.c \
common/src/c/grid_ui_system.c \
common/src/c/grid_ui_touch.c \
common/src/c/grid_usb.c \
common/src/c/grid_utask.c \
common/dep/lua-5.4.3/src/dirent.c \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "grid_esp32_adc.h"
#include "grid_esp32_encoder.h"
#include "rom/ets_sys.h"

// static const char* TAG = "module_octv";

Expand Down
8 changes: 8 additions & 0 deletions esp32s3/components/grid_esp32_module_xy/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
idf_component_register(
SRCS
"grid_esp32_module_xy.c"
INCLUDE_DIRS
"."
REQUIRES
"grid_common" "grid_esp32_touch"
)
52 changes: 52 additions & 0 deletions esp32s3/components/grid_esp32_module_xy/grid_esp32_module_xy.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "grid_esp32_module_xy.h"

#include <stdint.h>

#include "grid_sys.h"
#include "grid_ui.h"
#include "grid_ui_touch.h"

#include "grid_esp32_touch.h"

#define XY_I2C_PORT I2C_NUM_0
#define XY_I2C_SCL_GPIO 40
#define XY_I2C_SDA_GPIO 41
#define XY_I2C_FREQ_HZ 100000

#define XY_SENSOR_RESET_GPIO 39
#define XY_SENSOR_INT_GPIO 42

void grid_esp32_module_xy_handle_touch(void) {
TOUCHINFO ti = {};
if (!grid_esp32_touch_get_samples(&grid_esp32_touch_state, &ti)) {
return;
}

for (uint8_t i = 0; i < 5; i++) {
struct grid_ui_element* ele = grid_ui_element_find(&grid_ui_state, i);
if (!ele) {
continue;
}
struct grid_ui_touch_state* state = grid_ui_touch_get_state(ele);

if (i < ti.count) {
grid_ui_touch_store_input(state, ti.x[i], ti.y[i], ti.area[i]);
} else if (state->area > 0) {
grid_ui_touch_store_input(state, state->x, state->y, 0);
}
}
}

void grid_esp32_module_xy_init(struct grid_sys_model* sys, struct grid_ui_model* ui) {

grid_esp32_touch_init(&grid_esp32_touch_state, XY_I2C_PORT, XY_I2C_SCL_GPIO, XY_I2C_SDA_GPIO, XY_SENSOR_RESET_GPIO, XY_SENSOR_INT_GPIO, XY_I2C_FREQ_HZ, NULL);

grid_ui_bulk_start_with_state(ui, grid_ui_bulk_conf_read, 0, 0, NULL);
grid_ui_bulk_flush(ui);
}
20 changes: 20 additions & 0 deletions esp32s3/components/grid_esp32_module_xy/grid_esp32_module_xy.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include "grid_sys.h"
#include "grid_ui.h"

void grid_esp32_module_xy_init(struct grid_sys_model* sys, struct grid_ui_model* ui);
void grid_esp32_module_xy_handle_touch(void);

#ifdef __cplusplus
}
#endif
22 changes: 11 additions & 11 deletions esp32s3/components/grid_esp32_port/grid_esp32_port.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ void grid_esp32_port_task(void* arg) {

// Watchdog-style tracking for the rolling ID
uint8_t watchdog_rollid_last_recv = rollid.last_recv;
uint8_t watchdog_rollid_last_errors = rollid.errors;
uint64_t watchdog_rollid_last_time = grid_platform_rtc_get_micros();

// Allocate custom SPI transaction queue
Expand Down Expand Up @@ -446,25 +447,24 @@ void grid_esp32_port_task(void* arg) {

while (1) {

// When the rolling ID changes, reset watchdog
// When the rolling ID changes without error, reset watchdog
if (rollid.last_recv != watchdog_rollid_last_recv) {

watchdog_rollid_last_time = grid_platform_rtc_get_micros();
watchdog_rollid_last_recv = rollid.last_recv;

rp2040_active = true;
}
// Only mark RP2040 active if the byte was the expected next value (no new error)
if (rollid.errors == watchdog_rollid_last_errors) {
rp2040_active = true;
}

// Rolling ID watchdog expiration
if (grid_platform_rtc_get_elapsed_time(watchdog_rollid_last_time) > 100000) {
watchdog_rollid_last_recv = rollid.last_recv;
watchdog_rollid_last_errors = rollid.errors;
}

grid_platform_printf("ERROR: SPI frozen\n");
// Rolling ID watchdog expiration (only if RP2040 was ever seen)
if (rp2040_active && grid_platform_rtc_get_elapsed_time(watchdog_rollid_last_time) > 100000) {

watchdog_rollid_last_time = grid_platform_rtc_get_micros();

grid_alert_all_set(&grid_led_state, GRID_LED_COLOR_PURPLE, 50);
grid_alert_all_set_frequency(&grid_led_state, -4);
grid_alert_all_set_phase(&grid_led_state, 100);
}

// Check if USB is connected and start animation
Expand Down
8 changes: 8 additions & 0 deletions esp32s3/components/grid_esp32_touch/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
idf_component_register(
SRCS
"grid_esp32_touch.c"
INCLUDE_DIRS
"."
REQUIRES
"driver" "esp_driver_gpio" "freertos"
)
Loading
Loading