MCPcopy Create free account
hub / github.com/TactilityProject/Tactility / initNavButtons

Method initNavButtons

Devices/unphone/Source/UnPhoneFeatures.cpp:91–143  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89}
90
91bool UnPhoneFeatures::initNavButtons() {
92 if (!initGpioExpander()) {
93 LOGGER.error("GPIO expander init failed");
94 return false;
95 }
96
97 interruptQueue = xQueueCreate(4, sizeof(int));
98
99 buttonHandlingThread.setName("unphone_buttons");
100 buttonHandlingThread.setPriority(tt::Thread::Priority::High);
101 buttonHandlingThread.setStackSize(3072);
102 buttonHandlingThread.setMainFunction(
103 [this] {
104 return buttonHandlingThreadMain(&this->buttonHandlingThreadInterruptRequest);
105 }
106 );
107 buttonHandlingThread.start();
108
109 uint64_t pin_mask =
110 BIT64(pin::BUTTON1) |
111 BIT64(pin::BUTTON2) |
112 BIT64(pin::BUTTON3);
113
114 gpio_config_t config = {
115 .pin_bit_mask = pin_mask,
116 .mode = GPIO_MODE_INPUT,
117 .pull_up_en = GPIO_PULLUP_ENABLE,
118 .pull_down_en = GPIO_PULLDOWN_DISABLE,
119 /**
120 * We have to listen to the button release (= positive signal).
121 * If we listen to button press, the buttons might create more than 1 signal
122 * when they are continuously pressed.
123 */
124 .intr_type = GPIO_INTR_POSEDGE,
125 };
126
127 if (gpio_config(&config) != ESP_OK) {
128 LOGGER.error("Nav button pin init failed");
129 return false;
130 }
131
132 if (
133 gpio_install_isr_service(0) != ESP_OK ||
134 gpio_isr_handler_add(pin::BUTTON1, navButtonInterruptHandler, reinterpret_cast<void*>(pin::BUTTON1)) != ESP_OK ||
135 gpio_isr_handler_add(pin::BUTTON2, navButtonInterruptHandler, reinterpret_cast<void*>(pin::BUTTON2)) != ESP_OK ||
136 gpio_isr_handler_add(pin::BUTTON3, navButtonInterruptHandler, reinterpret_cast<void*>(pin::BUTTON3)) != ESP_OK
137 ) {
138 LOGGER.error("Nav buttons ISR init failed");
139 return false;
140 }
141
142 return true;
143}
144
145bool UnPhoneFeatures::initOutputPins() {
146 uint64_t output_pin_mask =

Callers

nothing calls this directly

Calls 8

buttonHandlingThreadMainFunction · 0.85
errorMethod · 0.80
setNameMethod · 0.80
setPriorityMethod · 0.80
setStackSizeMethod · 0.80
setMainFunctionMethod · 0.80
initGpioExpanderFunction · 0.50
startMethod · 0.45

Tested by

no test coverage detected