Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions src/opendisplay_ble.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "opendisplay_display.h"
#include "opendisplay_button.h"
#include "opendisplay_led.h"
#include "opendisplay_touch.h"
#include "opendisplay_buzzer.h"
#include "opendisplay_pipe.h"
#include "opendisplay_battery.h"
Expand Down Expand Up @@ -554,6 +555,7 @@ void opendisplay_ble_init(void)
}

opendisplay_button_init();
opendisplay_touch_init();
k_work_init_delayable(&s_adv_restart_work, adv_work_handler);
apply_tx_power(BT_HCI_VS_LL_HANDLE_TYPE_ADV, 0);
update_msd_payload();
Expand All @@ -569,6 +571,7 @@ void opendisplay_ble_process(void)
opendisplay_led_process();
opendisplay_buzzer_process();
opendisplay_button_process();
opendisplay_touch_process();
opendisplay_ble_advertising_tick();

/* Fallback if the delayed work restart fails or was cancelled. */
Expand Down
5 changes: 5 additions & 0 deletions src/opendisplay_button.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "opendisplay_ble.h"
#include "opendisplay_config_parser.h"
#include "opendisplay_structs.h"
#include "opendisplay_touch.h"
#include "nrf54_gpio.h"

#include <stdio.h>
Expand Down Expand Up @@ -67,6 +68,10 @@ void opendisplay_button_init(void)
if (pin == 0xFFu || s_button_count >= MAX_BUTTONS) {
continue;
}
if (opendisplay_touch_gpio_is_touch_int(pin)) {
printf("[OD] button: skip pin 0x%02X (reserved for GT911 INT)\r\n", (unsigned)pin);
continue;
}

ButtonState *btn = &s_buttons[s_button_count++];
btn->button_id = (uint8_t)((input->instance_number * 8u) + pin_idx);
Expand Down
21 changes: 21 additions & 0 deletions src/opendisplay_config_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,26 @@ bool parseConfigBytes(uint8_t* configData, uint32_t configLen, struct GlobalConf
return false;
}
break;

case CONFIG_PKT_TOUCH: // touch_controller (0x28) - parse but don't log
if (offset > configLen) {
printf("Offset overflow before touch_controller\r\n");
globalConfig->loaded = false;
return false;
}
if (globalConfig->touch_controller_count < 4 && offset + sizeof(struct TouchController) <= configLen - 2) {
memcpy(&globalConfig->touch_controllers[globalConfig->touch_controller_count], &configData[offset], sizeof(struct TouchController));
offset += sizeof(struct TouchController);
if (offset > configLen) {
printf("Offset overflow after touch_controller\r\n");
globalConfig->loaded = false;
return false;
}
globalConfig->touch_controller_count++;
} else if (globalConfig->touch_controller_count >= 4) {
offset += sizeof(struct TouchController);
if (offset > configLen) {
printf("Offset overflow after touch_controller (skipped)\r\n");

case CONFIG_PKT_PASSIVE_BUZZER: // passive_buzzer (0x29) - parse but don't log
if (offset > configLen) {
Expand All @@ -400,6 +420,7 @@ bool parseConfigBytes(uint8_t* configData, uint32_t configLen, struct GlobalConf
return false;
}
} else {
printf("touch_controller: need %zu, have %u\r\n", sizeof(struct TouchController), (unsigned)(configLen - 2 - offset));
printf("passive_buzzer: need %zu, have %u\r\n", sizeof(struct PassiveBuzzerConfig), (unsigned)(configLen - 2 - offset));
globalConfig->loaded = false;
return false;
Expand Down
1 change: 1 addition & 0 deletions src/opendisplay_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#define CONFIG_PKT_BINARY_INPUT 0x25
#define CONFIG_PKT_WIFI 0x26
#define CONFIG_PKT_SECURITY 0x27
#define CONFIG_PKT_TOUCH 0x28
#define CONFIG_PKT_PASSIVE_BUZZER 0x29
#define CONFIG_PKT_NFC 0x2A
#define CONFIG_PKT_FLASH 0x2B
Expand Down
6 changes: 6 additions & 0 deletions src/opendisplay_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "opendisplay_epd_map.h"
#include "opendisplay_protocol.h"
#include "opendisplay_structs.h"
#include "opendisplay_touch.h"
#include "board_nrf54.h"
#include "boot_screen.h"
#include "nrf54_gpio.h"
Expand Down Expand Up @@ -930,6 +931,9 @@ extern "C" int opendisplay_display_direct_write_end_refresh(const uint8_t *paylo
*refresh_ok = ok;
}
partial_cleanup();
/* An EPD refresh can perturb a GT911 sharing the panel power rail; re-probe
* it (light probe first, full reset fallback) as the Arduino reference does. */
opendisplay_touch_resume_after_refresh();
return 0;
}

Expand Down Expand Up @@ -972,5 +976,7 @@ extern "C" int opendisplay_display_direct_write_end_refresh(const uint8_t *paylo
if (refresh_ok != nullptr) {
*refresh_ok = ok;
}
/* See note above: re-probe touch after the full-refresh path too. */
opendisplay_touch_resume_after_refresh();
return 0;
}
25 changes: 25 additions & 0 deletions src/opendisplay_structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,29 @@ struct BinaryInputs {
uint8_t reserved[14];
} __attribute__((packed));

/* 0x28: touch_controller (repeatable, max 4 instances). 32-byte fixed packet;
* on-wire layout matches OpenDisplay-Firmware src/structs.h TouchController and
* the py-opendisplay serializer (config_serializer.serialize_touch_controller).
* touch_ic_type: 0 = disabled / none, 1 = GT911. */
#define TOUCH_IC_NONE 0u
#define TOUCH_IC_GT911 1u
#define TOUCH_FLAG_INVERT_X (1u << 0)
#define TOUCH_FLAG_INVERT_Y (1u << 1)
#define TOUCH_FLAG_SWAP_XY (1u << 2)

struct TouchController {
uint8_t instance_number;
uint16_t touch_ic_type;
uint8_t bus_id; /* data_bus index for the I2C SCL/SDA pins */
uint8_t i2c_addr_7bit; /* GT911: 0x5D or 0x14; 0 or 0xFF = auto */
uint8_t int_pin; /* GT911 INT, 0xFF = poll only */
uint8_t rst_pin; /* GT911 RST, 0xFF = skip hardware reset */
uint8_t display_instance; /* clip/scale to displays[instance] pixel size */
uint8_t flags; /* TOUCH_FLAG_* */
uint8_t poll_interval_ms; /* 0 = default */
uint8_t touch_data_start_byte; /* first of 5 MSD dynamic bytes (0-6) */
uint8_t enable_pin; /* optional touch panel power enable; 0/0xFF = unused */
uint8_t reserved[20];
/* 0x29: passive_buzzer (repeatable, max 4 instances). On-wire layout matches the
* Arduino reference Firmware src/structs.h PassiveBuzzerConfig exactly (32 bytes).
* Frequency in the 0x0077 payload: 0 = silence/rest; 1-255 maps linearly to a
Expand Down Expand Up @@ -219,6 +242,8 @@ struct GlobalConfig {
uint8_t data_bus_count;
struct BinaryInputs binary_inputs[4];
uint8_t binary_input_count;
struct TouchController touch_controllers[4];
uint8_t touch_controller_count;
struct PassiveBuzzerConfig passive_buzzers[4];
uint8_t passive_buzzer_count;
struct NfcConfig nfc_configs[2];
Expand Down
Loading
Loading