@@ -164,14 +164,23 @@ void case_detect_pin_interrupt_handler(nrfx_gpiote_pin_t unused_gptiote_pin,
164164 shutdown (false);
165165}
166166
167+ void frame_lite_button_interrupt_handler (nrfx_gpiote_pin_t unused_gptiote_pin ,
168+ nrfx_gpiote_trigger_t unused_gptiote_trigger ,
169+ void * unused_gptiote_context_pointer )
170+ {
171+ nrfx_gpiote_trigger_disable (FRAME_LITE_BUTTON_PIN );
172+ bluetooth_unpair ();
173+ NVIC_SystemReset ();
174+ }
175+
167176static void fpga_send_bitstream_bytes (void * context ,
168177 void * data ,
169178 size_t data_size )
170179{
171180 spi_write_raw (FPGA , data , data_size );
172181}
173182
174- static void hardware_setup (bool * factory_reset )
183+ static void hardware_setup ()
175184{
176185 // Configure watchdog
177186 {
@@ -183,6 +192,20 @@ static void hardware_setup(bool *factory_reset)
183192 nrfx_systick_init ();
184193 }
185194
195+ // Check if Frame or Frame lite
196+ {
197+ nrf_gpio_cfg_input (FRAME_LITE_HW_DETECT_PIN , NRF_GPIO_PIN_PULLUP );
198+
199+ if (nrf_gpio_pin_read (FRAME_LITE_HW_DETECT_PIN ))
200+ {
201+ LOG ("Running on Frame" );
202+ }
203+ else
204+ {
205+ LOG ("Running on Frame Lite" );
206+ }
207+ }
208+
186209 // Configure the I2C and SPI drivers
187210 {
188211 i2c_configure ();
@@ -299,7 +322,7 @@ static void hardware_setup(bool *factory_reset)
299322 else
300323 {
301324 LOG ("Factory reset" );
302- * factory_reset = true ;
325+ bluetooth_unpair () ;
303326 stay_awake = true;
304327 }
305328 }
@@ -308,6 +331,30 @@ static void hardware_setup(bool *factory_reset)
308331 nrfx_gpiote_trigger_enable (CASE_DETECT_PIN , true);
309332 }
310333
334+ // Configure the Frame lite button
335+ {
336+ nrfx_gpiote_input_config_t input_config = {
337+ .pull = NRF_GPIO_PIN_PULLUP ,
338+ };
339+
340+ nrfx_gpiote_trigger_config_t trigger_config = {
341+ .trigger = NRFX_GPIOTE_TRIGGER_HITOLO ,
342+ .p_in_channel = NULL ,
343+ };
344+
345+ nrfx_gpiote_handler_config_t handler_config = {
346+ .handler = frame_lite_button_interrupt_handler ,
347+ .p_context = NULL ,
348+ };
349+
350+ check_error (nrfx_gpiote_input_configure (FRAME_LITE_BUTTON_PIN ,
351+ & input_config ,
352+ & trigger_config ,
353+ & handler_config ));
354+
355+ nrfx_gpiote_trigger_enable (FRAME_LITE_BUTTON_PIN , true);
356+ }
357+
311358 // Load and start the FPGA image
312359 {
313360 nrf_gpio_cfg_output (FPGA_PROGRAM_PIN );
@@ -412,19 +459,14 @@ int main(void)
412459{
413460 LOG ("Frame firmware " BUILD_VERSION " (" GIT_COMMIT ")" );
414461
415- bool factory_reset = false;
416- bool is_paired = false;
462+ hardware_setup ();
417463
418- hardware_setup (& factory_reset );
419-
420- bluetooth_setup (factory_reset , & is_paired );
464+ bluetooth_setup ();
421465
422466 while (1 )
423467 {
424468 reload_watchdog (NULL , NULL );
425469
426- run_lua (factory_reset , is_paired );
427-
428- factory_reset = false;
470+ run_lua (bluetooth_is_paired ());
429471 }
430472}
0 commit comments