spi dma work but it actually draw image slower than before
This commit is contained in:
1 parent
69323fd115
commit
3adc899f81
3 files changed
+106
-55
No files matched your search
+63
-14
@@ -2,6 +2,7 @@
|
||||
* SPI Master library for nRF5x.
|
||||
* Copyright (c) 2015 Arduino LLC
|
||||
* Copyright (c) 2016 Sandeep Mistry All right reserved.
|
||||
* Copyright (c) 2019 Ha Thach for Adafruit Industries. All right reserved.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -35,6 +36,9 @@ SPIClass::SPIClass(NRF_SPI_Type *p_spi, uint8_t uc_pinMISO, uint8_t uc_pinSCK, u
|
||||
assert(p_spi != NULL);
|
||||
_p_spi = p_spi;
|
||||
|
||||
_spim.p_reg = NRF_SPIM0;
|
||||
_spim.drv_inst_idx = NRFX_SPIM0_INST_IDX;
|
||||
|
||||
// pins
|
||||
_uc_pinMiso = g_ADigitalPinMap[uc_pinMISO];
|
||||
_uc_pinSCK = g_ADigitalPinMap[uc_pinSCK];
|
||||
@@ -46,7 +50,25 @@ SPIClass::SPIClass(NRF_SPI_Type *p_spi, uint8_t uc_pinMISO, uint8_t uc_pinSCK, u
|
||||
|
||||
void SPIClass::begin()
|
||||
{
|
||||
init();
|
||||
if (initialized) return;
|
||||
initialized = true;
|
||||
|
||||
nrfx_spim_config_t cfg =
|
||||
{
|
||||
.sck_pin = _uc_pinSCK,
|
||||
.mosi_pin = _uc_pinMosi,
|
||||
.miso_pin = _uc_pinMiso,
|
||||
.ss_pin = NRFX_SPIM_PIN_NOT_USED,
|
||||
.ss_active_high = false,
|
||||
.irq_priority = 3,
|
||||
.orc = 0xFF,
|
||||
.frequency = NRF_SPIM_FREQ_8M, // NRF_SPIM_FREQ_4M,
|
||||
.mode = NRF_SPIM_MODE_0,
|
||||
.bit_order = NRF_SPIM_BIT_ORDER_MSB_FIRST,
|
||||
};
|
||||
|
||||
// blocking
|
||||
nrfx_spim_init(&_spim, &cfg, NULL, NULL);
|
||||
|
||||
_p_spi->PSELSCK = _uc_pinSCK;
|
||||
_p_spi->PSELMOSI = _uc_pinMosi;
|
||||
@@ -55,18 +77,9 @@ void SPIClass::begin()
|
||||
config(DEFAULT_SPI_SETTINGS);
|
||||
}
|
||||
|
||||
void SPIClass::init()
|
||||
{
|
||||
if (initialized)
|
||||
return;
|
||||
interruptMode = SPI_IMODE_NONE;
|
||||
interruptSave = 0;
|
||||
interruptMask = 0;
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
void SPIClass::config(SPISettings settings)
|
||||
{
|
||||
#if 0
|
||||
_p_spi->ENABLE = (SPI_ENABLE_ENABLE_Disabled << SPI_ENABLE_ENABLE_Pos);
|
||||
|
||||
uint32_t config = settings.bitOrder;
|
||||
@@ -98,11 +111,14 @@ void SPIClass::config(SPISettings settings)
|
||||
_p_spi->FREQUENCY = settings.clockFreq;
|
||||
|
||||
_p_spi->ENABLE = (SPI_ENABLE_ENABLE_Enabled << SPI_ENABLE_ENABLE_Pos);
|
||||
#endif
|
||||
}
|
||||
|
||||
void SPIClass::end()
|
||||
{
|
||||
_p_spi->ENABLE = (SPI_ENABLE_ENABLE_Disabled << SPI_ENABLE_ENABLE_Pos);
|
||||
// _p_spi->ENABLE = (SPI_ENABLE_ENABLE_Disabled << SPI_ENABLE_ENABLE_Pos);
|
||||
|
||||
nrfx_spim_uninit(&_spim);
|
||||
|
||||
initialized = false;
|
||||
}
|
||||
@@ -113,16 +129,17 @@ void SPIClass::usingInterrupt(int /*interruptNumber*/)
|
||||
|
||||
void SPIClass::beginTransaction(SPISettings settings)
|
||||
{
|
||||
config(settings);
|
||||
// config(settings);
|
||||
}
|
||||
|
||||
void SPIClass::endTransaction(void)
|
||||
{
|
||||
_p_spi->ENABLE = (SPI_ENABLE_ENABLE_Disabled << SPI_ENABLE_ENABLE_Pos);
|
||||
// _p_spi->ENABLE = (SPI_ENABLE_ENABLE_Disabled << SPI_ENABLE_ENABLE_Pos);
|
||||
}
|
||||
|
||||
void SPIClass::setBitOrder(BitOrder order)
|
||||
{
|
||||
#if 0
|
||||
this->_bitOrder = (order == MSBFIRST ? SPI_CONFIG_ORDER_MsbFirst : SPI_CONFIG_ORDER_LsbFirst);
|
||||
|
||||
uint32_t config = this->_bitOrder;
|
||||
@@ -151,10 +168,12 @@ void SPIClass::setBitOrder(BitOrder order)
|
||||
}
|
||||
|
||||
_p_spi->CONFIG = config;
|
||||
#endif
|
||||
}
|
||||
|
||||
void SPIClass::setDataMode(uint8_t mode)
|
||||
{
|
||||
#if 0
|
||||
this->_dataMode = mode;
|
||||
|
||||
uint32_t config = this->_bitOrder;
|
||||
@@ -183,10 +202,12 @@ void SPIClass::setDataMode(uint8_t mode)
|
||||
}
|
||||
|
||||
_p_spi->CONFIG = config;
|
||||
#endif
|
||||
}
|
||||
|
||||
void SPIClass::setClockDivider(uint8_t div)
|
||||
{
|
||||
#if 0
|
||||
uint32_t clockFreq;
|
||||
|
||||
// Adafruit Note: nrf52 run at 64MHz
|
||||
@@ -207,10 +228,32 @@ void SPIClass::setClockDivider(uint8_t div)
|
||||
}
|
||||
|
||||
_p_spi->FREQUENCY = clockFreq;
|
||||
#endif
|
||||
}
|
||||
|
||||
void SPIClass::transfer(void *buf, size_t count)
|
||||
{
|
||||
#if 0
|
||||
// TODO: Optimize for faster block-transfer
|
||||
uint8_t *buffer = reinterpret_cast<uint8_t *>(buf);
|
||||
for (size_t i=0; i<count; i++)
|
||||
buffer[i] = transfer(buffer[i]);
|
||||
#else
|
||||
nrfx_spim_xfer_desc_t xfer_desc =
|
||||
{
|
||||
.p_tx_buffer = (uint8_t*) buf,
|
||||
.tx_length = count,
|
||||
.p_rx_buffer = (uint8_t*) buf,
|
||||
.rx_length = count,
|
||||
};
|
||||
|
||||
nrfx_spim_xfer(&_spim, &xfer_desc, 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
byte SPIClass::transfer(uint8_t data)
|
||||
{
|
||||
#if 0
|
||||
_p_spi->TXD = data;
|
||||
|
||||
while(!_p_spi->EVENTS_READY);
|
||||
@@ -220,9 +263,14 @@ byte SPIClass::transfer(uint8_t data)
|
||||
_p_spi->EVENTS_READY = 0x0UL;
|
||||
|
||||
return data;
|
||||
#else
|
||||
transfer(&data, 1);
|
||||
return data;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint16_t SPIClass::transfer16(uint16_t data) {
|
||||
|
||||
union { uint16_t val; struct { uint8_t lsb; uint8_t msb; }; } t;
|
||||
|
||||
t.val = data;
|
||||
@@ -249,6 +297,7 @@ void SPIClass::detachInterrupt() {
|
||||
#if SPI_INTERFACES_COUNT > 0
|
||||
SPIClass SPI (NRF_SPI0, PIN_SPI_MISO, PIN_SPI_SCK, PIN_SPI_MOSI);
|
||||
#endif
|
||||
|
||||
#if SPI_INTERFACES_COUNT > 1
|
||||
SPIClass SPI1(NRF_SPI1, PIN_SPI1_MISO, PIN_SPI1_SCK, PIN_SPI1_MOSI);
|
||||
#endif
|
||||
Reference in new issue
Block a user