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.
This commit is contained in:
Jared Boone 2016-07-24 15:31:53 -07:00
parent b3f4ea8978
commit 8b02e40602
5 changed files with 10 additions and 36 deletions

View File

@ -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.
*/

View File

@ -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,
};
}

View File

@ -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

View File

@ -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();

View File

@ -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 };