From 8b02e40602e6813b4cd4c31e1d9e9cd018176100 Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Sun, 24 Jul 2016 15:31:53 -0700 Subject: [PATCH] Move touch ADC data collection to M0. ...so it continues when M4 is shut down. It's not as pretty as using DMA, but it's far simpler, even if it involves letting the ADC run continuously and taking the last samples even if not synchronizing to the phase of the sampling of the channels. --- firmware/application/irq_controls.cpp | 4 +-- firmware/application/touch_adc.cpp | 27 ++++++--------------- firmware/baseband/CMakeLists.txt | 1 - firmware/baseband/main.cpp | 6 ----- firmware/common/portapack_shared_memory.hpp | 8 ------ 5 files changed, 10 insertions(+), 36 deletions(-) diff --git a/firmware/application/irq_controls.cpp b/firmware/application/irq_controls.cpp index 5a789721d..cb6a2df5c 100644 --- a/firmware/application/irq_controls.cpp +++ b/firmware/application/irq_controls.cpp @@ -168,8 +168,6 @@ void timer0_callback(GPTDriver* const) { EventDispatcher::events_flag_isr(event_mask); chSysUnlockFromIsr(); } - - touch::adc::start(); } /* TODO: Refactor some/all of this to appropriate shared headers? */ @@ -187,6 +185,8 @@ static GPTConfig timer0_config { }; void controls_init() { + touch::adc::start(); + /* GPT timer 0 is used to scan user interface controls -- touch screen, * navigation switches. */ diff --git a/firmware/application/touch_adc.cpp b/firmware/application/touch_adc.cpp index 0808f9fcb..be731282e 100644 --- a/firmware/application/touch_adc.cpp +++ b/firmware/application/touch_adc.cpp @@ -70,26 +70,15 @@ void start() { // static constexpr bool monitor_overruns_and_not_dones = false; Samples get() { - const auto& frame = shared_memory.touch_adc_frame; - const auto xp = frame.dr[portapack::adc0_touch_xp_input]; - const auto xn = frame.dr[portapack::adc0_touch_xn_input]; - const auto yp = frame.dr[portapack::adc0_touch_yp_input]; - const auto yn = frame.dr[portapack::adc0_touch_yn_input]; - - // if( monitor_overruns_and_not_dones ) { - // const auto dr_and = xp & xn & yp & yn; - // const auto dr_or = xp | xn | yp | yn; - // const bool done = (dr_and >> 31) & 1; - // const bool overrun = (dr_or >> 30) & 1; - // led_tx.write(overrun); - // led_rx.write(!done); - // } - + const auto xp_reg = LPC_ADC0->DR[portapack::adc0_touch_xp_input]; + const auto xn_reg = LPC_ADC0->DR[portapack::adc0_touch_xn_input]; + const auto yp_reg = LPC_ADC0->DR[portapack::adc0_touch_yp_input]; + const auto yn_reg = LPC_ADC0->DR[portapack::adc0_touch_yn_input]; return { - (xp >> 6) & 0x3ff, - (xn >> 6) & 0x3ff, - (yp >> 6) & 0x3ff, - (yn >> 6) & 0x3ff, + (xp_reg >> 6) & 0x3ff, + (xn_reg >> 6) & 0x3ff, + (yp_reg >> 6) & 0x3ff, + (yn_reg >> 6) & 0x3ff, }; } diff --git a/firmware/baseband/CMakeLists.txt b/firmware/baseband/CMakeLists.txt index 2aaa3028d..067b8dd22 100644 --- a/firmware/baseband/CMakeLists.txt +++ b/firmware/baseband/CMakeLists.txt @@ -128,7 +128,6 @@ set(CPPSRC audio_output.cpp audio_dma.cpp audio_stats_collector.cpp - touch_dma.cpp ${COMMON}/utility.cpp ${COMMON}/chibios_cpp.cpp ${COMMON}/debug.cpp diff --git a/firmware/baseband/main.cpp b/firmware/baseband/main.cpp index e99a0f34d..c192f6602 100755 --- a/firmware/baseband/main.cpp +++ b/firmware/baseband/main.cpp @@ -28,8 +28,6 @@ #include "gpdma.hpp" -#include "touch_dma.hpp" - #include "message_queue.hpp" #include "utility.hpp" @@ -73,10 +71,6 @@ static void init() { LPC_CREG->DMAMUX = portapack::gpdma_mux; gpdma::controller.enable(); nvicEnableVector(DMA_IRQn, CORTEX_PRIORITY_MASK(LPC_DMA_IRQ_PRIORITY)); - - touch::dma::init(); - touch::dma::allocate(); - touch::dma::enable(); } extern void run(); diff --git a/firmware/common/portapack_shared_memory.hpp b/firmware/common/portapack_shared_memory.hpp index a509473e9..3ff738c90 100644 --- a/firmware/common/portapack_shared_memory.hpp +++ b/firmware/common/portapack_shared_memory.hpp @@ -27,19 +27,11 @@ #include "message_queue.hpp" -struct TouchADCFrame { - uint32_t dr[8]; -}; - /* NOTE: These structures must be located in the same location in both M4 and M0 binaries */ struct SharedMemory { static constexpr size_t application_queue_k = 11; static constexpr size_t app_local_queue_k = 11; - - // TODO: M0 should directly configure and control DMA channel that is - // acquiring ADC samples. - TouchADCFrame touch_adc_frame; uint8_t application_queue_data[1 << application_queue_k] { 0 }; uint8_t app_local_queue_data[1 << app_local_queue_k] { 0 }; const Message* volatile baseband_message { nullptr };