|
51 | 51 | #include "uart.h"
|
52 | 52 | #include "modmachine.h"
|
53 | 53 | #include "mpthreadport.h"
|
| 54 | +#include "bpp_init.h" |
54 | 55 | #include "badge_portexp.h"
|
55 | 56 | #include "badge_pins.h"
|
56 |
| -#include "bpp_init.h" |
57 |
| -#include "driver/gpio.h" |
58 | 57 | #include "badge_base.h"
|
59 | 58 | #include "badge_first_run.h"
|
| 59 | +#include <badge_input.h> |
| 60 | +#include <badge.h> |
60 | 61 |
|
61 | 62 | // MicroPython runs as a task under FreeRTOS
|
62 | 63 | #define MP_TASK_PRIORITY (ESP_TASK_PRIO_MIN + 1)
|
@@ -128,60 +129,51 @@ void mp_task(void *pvParameter) {
|
128 | 129 | }
|
129 | 130 |
|
130 | 131 | void do_bpp_bgnd() {
|
131 |
| - //Kick off bpp |
132 |
| - bpp_init(); |
133 |
| - printf("Bpp inited.\n"); |
134 |
| - //immediately abort and reboot when touchpad detects something |
135 |
| - while(gpio_get_level(PIN_NUM_MPR121_INT)==1) { |
136 |
| - vTaskDelay(10); |
137 |
| - } |
138 |
| - printf("Touch detected. Exiting bpp, rebooting.\n"); |
| 132 | + // Kick off bpp |
| 133 | + bpp_init(); |
| 134 | + |
| 135 | + printf("Bpp inited.\n"); |
| 136 | + |
| 137 | + // immediately abort and reboot when touchpad detects something |
| 138 | + while (badge_input_get_event(1000) == 0) { } |
| 139 | + |
| 140 | + printf("Touch detected. Exiting bpp, rebooting.\n"); |
139 | 141 | esp_restart();
|
140 | 142 | }
|
141 | 143 |
|
142 | 144 | void app_main(void) {
|
143 |
| - badge_check_first_run(); |
144 |
| - badge_base_init(); |
| 145 | + badge_check_first_run(); |
| 146 | + badge_base_init(); |
145 | 147 |
|
146 |
| - uint8_t magic = esp_rtcmem_read(0); |
147 |
| - uint8_t inv_magic = esp_rtcmem_read(1); |
| 148 | + uint8_t magic = esp_rtcmem_read(0); |
| 149 | + uint8_t inv_magic = esp_rtcmem_read(1); |
148 | 150 |
|
149 |
| -#ifdef CONFIG_SHA_BPP_ENABLE |
150 |
| - //Grab level of int pin of touchpad. If high, this was a |
151 |
| - //scheduled wakeup because of a deep sleep timeout. If low, |
152 |
| - //the user used the touchpad. |
153 |
| - //yes, this is v1 specific. Please add v0.x support yourself. |
154 |
| - gpio_config_t io_conf = { |
155 |
| - .mode = GPIO_MODE_INPUT, |
156 |
| - .pin_bit_mask = 1LL << PIN_NUM_MPR121_INT, |
157 |
| - .pull_down_en = 0, |
158 |
| - .pull_up_en = 1, |
159 |
| - }; |
160 |
| - gpio_config(&io_conf); |
161 |
| -#endif |
| 151 | + if (magic == (uint8_t)~inv_magic) { |
| 152 | + printf("Magic checked out!\n"); |
| 153 | + switch (magic) { |
| 154 | + case 1: |
| 155 | + printf("Starting OTA\n"); |
| 156 | + sha2017_ota_update(); |
| 157 | + break; |
162 | 158 |
|
163 |
| - if (magic == (uint8_t)~inv_magic) { |
164 |
| - printf("Magic checked out!\n"); |
165 |
| - switch (magic) { |
166 |
| - case 1: |
167 |
| - printf("Starting OTA\n"); |
168 |
| - sha2017_ota_update(); |
169 |
| - break; |
170 | 159 | #ifdef CONFIG_SHA_BPP_ENABLE
|
171 |
| - case 2: |
172 |
| - if (gpio_get_level(PIN_NUM_MPR121_INT)==1) { |
173 |
| - printf("Touch int is high. Starting bpp.\n"); |
174 |
| - do_bpp_bgnd(); |
175 |
| - } |
176 |
| - break; |
| 160 | + case 2: |
| 161 | + badge_init(); |
| 162 | + if (badge_input_button_state == 0) { |
| 163 | + printf("Starting bpp.\n"); |
| 164 | + do_bpp_bgnd(); |
| 165 | + } |
| 166 | + break; |
177 | 167 | #endif
|
178 |
| - case 3: |
179 |
| - badge_first_run(); |
180 |
| - } |
181 |
| - } else { |
182 |
| - xTaskCreateStaticPinnedToCore(mp_task, "mp_task", MP_TASK_STACK_LEN, NULL, MP_TASK_PRIORITY, |
183 |
| - &mp_task_stack[0], &mp_task_tcb, 0); |
184 |
| - } |
| 168 | + |
| 169 | + case 3: |
| 170 | + badge_first_run(); |
| 171 | + } |
| 172 | + |
| 173 | + } else { |
| 174 | + xTaskCreateStaticPinnedToCore(mp_task, "mp_task", MP_TASK_STACK_LEN, NULL, MP_TASK_PRIORITY, |
| 175 | + &mp_task_stack[0], &mp_task_tcb, 0); |
| 176 | + } |
185 | 177 | }
|
186 | 178 |
|
187 | 179 | void nlr_jump_fail(void *val) {
|
|
0 commit comments