2015-07-08 08:39:24 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Jared Boone, ShareBrained Technology, Inc.
|
|
|
|
*
|
|
|
|
* This file is part of PortaPack.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "touch_dma.hpp"
|
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <array>
|
|
|
|
|
|
|
|
#include "hal.h"
|
|
|
|
#include "gpdma.hpp"
|
|
|
|
using namespace lpc43xx;
|
|
|
|
|
|
|
|
#include "portapack_dma.hpp"
|
|
|
|
#include "portapack_adc.hpp"
|
|
|
|
#include "portapack_shared_memory.hpp"
|
|
|
|
|
|
|
|
namespace touch {
|
|
|
|
namespace dma {
|
|
|
|
|
|
|
|
/* TODO: SO MUCH REPEATED CODE FROM rssi_dma.cpp!!! */
|
|
|
|
|
|
|
|
static constexpr auto& gpdma_channel = gpdma::channels[portapack::adc0_gpdma_channel_number];
|
|
|
|
|
|
|
|
constexpr uint32_t gpdma_ahb_master_peripheral = 1;
|
|
|
|
constexpr uint32_t gpdma_ahb_master_memory = 0;
|
|
|
|
constexpr uint32_t gpdma_ahb_master_lli_fetch = 0;
|
|
|
|
|
|
|
|
constexpr uint32_t gpdma_src_peripheral = 0xd;
|
|
|
|
constexpr uint32_t gpdma_dest_peripheral = 0xd;
|
|
|
|
|
|
|
|
constexpr gpdma::channel::LLIPointer lli_pointer(const void* lli) {
|
2023-05-19 08:16:05 +12:00
|
|
|
return {
|
|
|
|
.lm = gpdma_ahb_master_lli_fetch,
|
|
|
|
.r = 0,
|
|
|
|
.lli = reinterpret_cast<uint32_t>(lli),
|
|
|
|
};
|
2015-07-08 08:39:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
constexpr gpdma::channel::Control control(const size_t number_of_transfers) {
|
2023-05-19 08:16:05 +12:00
|
|
|
return {
|
|
|
|
.transfersize = number_of_transfers,
|
|
|
|
.sbsize = 2, /* Burst size: 8 transfers */
|
|
|
|
.dbsize = 2, /* Burst size: 8 transfers */
|
|
|
|
.swidth = 2, /* Source transfer width: word (32 bits) */
|
|
|
|
.dwidth = 2, /* Destination transfer width: word (32 bits) */
|
|
|
|
.s = gpdma_ahb_master_peripheral,
|
|
|
|
.d = gpdma_ahb_master_memory,
|
|
|
|
.si = 1,
|
|
|
|
.di = 1,
|
|
|
|
.prot1 = 0,
|
|
|
|
.prot2 = 0,
|
|
|
|
.prot3 = 0,
|
|
|
|
.i = 0,
|
|
|
|
};
|
2015-07-08 08:39:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
constexpr gpdma::channel::Config config() {
|
2023-05-19 08:16:05 +12:00
|
|
|
return {
|
|
|
|
.e = 0,
|
|
|
|
.srcperipheral = gpdma_src_peripheral,
|
|
|
|
.destperipheral = gpdma_dest_peripheral,
|
|
|
|
.flowcntrl = gpdma::FlowControl::PeripheralToMemory_DMAControl,
|
|
|
|
.ie = 0,
|
|
|
|
.itc = 0,
|
|
|
|
.l = 0,
|
|
|
|
.a = 0,
|
|
|
|
.h = 0,
|
|
|
|
};
|
2015-07-08 08:39:24 -07:00
|
|
|
}
|
|
|
|
|
2023-05-19 08:16:05 +12:00
|
|
|
static gpdma::channel::LLI lli;
|
2015-07-08 08:39:24 -07:00
|
|
|
|
|
|
|
constexpr size_t channels_per_sample = 8;
|
2023-05-19 08:16:05 +12:00
|
|
|
// constexpr size_t samples_per_frame = 40;
|
|
|
|
// constexpr size_t channel_samples_per_frame = channels_per_sample * samples_per_frame;
|
2015-07-08 08:39:24 -07:00
|
|
|
|
|
|
|
void init() {
|
|
|
|
}
|
|
|
|
|
|
|
|
void allocate() {
|
2023-05-19 08:16:05 +12:00
|
|
|
// samples = new sample_t[channel_samples_per_frame];
|
|
|
|
// lli = new gpdma::channel::LLI;
|
|
|
|
lli.srcaddr = reinterpret_cast<uint32_t>(&LPC_ADC0->DR[0]);
|
|
|
|
lli.destaddr = reinterpret_cast<uint32_t>(&shared_memory.touch_adc_frame.dr[0]);
|
|
|
|
lli.lli = lli_pointer(&lli);
|
|
|
|
lli.control = control(channels_per_sample);
|
2015-07-08 08:39:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void free() {
|
2023-05-19 08:16:05 +12:00
|
|
|
// delete samples;
|
|
|
|
// delete lli;
|
2015-07-08 08:39:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void enable() {
|
2023-05-19 08:16:05 +12:00
|
|
|
const auto gpdma_config = config();
|
|
|
|
gpdma_channel.configure(lli, gpdma_config);
|
|
|
|
gpdma_channel.enable();
|
2015-07-08 08:39:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
bool is_enabled() {
|
2023-05-19 08:16:05 +12:00
|
|
|
return gpdma_channel.is_enabled();
|
2015-07-08 08:39:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void disable() {
|
2023-05-19 08:16:05 +12:00
|
|
|
gpdma_channel.disable();
|
2015-07-08 08:39:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
} /* namespace dma */
|
|
|
|
} /* namespace touch */
|