Skip to content

Commit 8423fb9

Browse files
Merge branch 'stevstrong-F1_SPI_development'
2 parents df78777 + ed8c7a1 commit 8423fb9

8 files changed

Lines changed: 173 additions & 220 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ other/maple-bootloader/build
77
other/maple-bootloader/*~
88
*.o
99
tools/src/stm32flash_serial/src/parsers/parsers.a
10+
*.bak
11+
*.1

STM32F1/cores/maple/libmaple/dma_f1.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,6 @@ void dma_set_per_addr(dma_dev *dev, dma_channel channel, __io void *addr) {
341341
* @see dma_attach_interrupt()
342342
* @see dma_enable()
343343
*/
344-
__deprecated
345344
void dma_setup_transfer(dma_dev *dev,
346345
dma_channel channel,
347346
__io void *peripheral_address,

STM32F1/cores/maple/libmaple/spi.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ void spi_slave_enable(spi_dev *dev, spi_mode mode, uint32 flags) {
8484
}
8585

8686
/**
87-
* @brief Nonblocking SPI transmit.
87+
* @brief Blocking SPI transmit.
8888
* @param dev SPI port to use for transmission
8989
* @param buf Buffer to transmit. The sizeof buf's elements are
9090
* inferred from dev's data frame format (i.e., are
@@ -93,15 +93,21 @@ void spi_slave_enable(spi_dev *dev, spi_mode mode, uint32 flags) {
9393
* @return Number of elements transmitted.
9494
*/
9595
uint32 spi_tx(spi_dev *dev, const void *buf, uint32 len) {
96-
uint32 txed = 0;
97-
uint8 byte_frame = spi_dff(dev) == SPI_DFF_8_BIT;
98-
while (spi_is_tx_empty(dev) && (txed < len)) {
99-
if (byte_frame) {
100-
dev->regs->DR = ((const uint8*)buf)[txed++];
101-
} else {
102-
dev->regs->DR = ((const uint16*)buf)[txed++];
103-
}
104-
}
96+
uint32 txed = len;
97+
spi_reg_map *regs = dev->regs;
98+
if ( spi_dff(dev) == SPI_DFF_8_BIT ) {
99+
const uint8 * dp8 = (const uint8*)buf;
100+
while ( len-- ) {
101+
while ( (regs->SR & SPI_SR_TXE)==0 ) ; //while ( spi_is_tx_empty(dev)==0 ); // wait Tx to be empty
102+
regs->DR = *dp8++;
103+
}
104+
} else {
105+
const uint16 * dp16 = (const uint16*)buf;
106+
while ( len-- ) {
107+
while ( (regs->SR & SPI_SR_TXE)==0 ) ; //while ( spi_is_tx_empty(dev)==0 ); // wait Tx to be empty
108+
regs->DR = *dp16++;
109+
}
110+
}
105111
return txed;
106112
}
107113

STM32F1/libraries/Adafruit_ILI9341_STM/Adafruit_ILI9341_STM.cpp

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Adafruit_ILI9341_STM::Adafruit_ILI9341_STM(int8_t cs, int8_t dc, int8_t rst) : A
3636
}
3737

3838

39-
void Adafruit_ILI9341_STM::spiwrite(uint8_t c) {
39+
void Adafruit_ILI9341_STM::spiwrite(uint16_t c) {
4040

4141
//Serial.print("0x"); Serial.print(c, HEX); Serial.print(", ");
4242

@@ -178,10 +178,7 @@ void Adafruit_ILI9341_STM::begin(void) {
178178
SPI.setBitOrder(MSBFIRST);
179179
SPI.setDataMode(SPI_MODE0);
180180
#elif defined (__STM32F1__)
181-
SPI.begin();
182-
SPI.setClockDivider(SPI_CLOCK_DIV2);
183-
SPI.setBitOrder(MSBFIRST);
184-
SPI.setDataMode(SPI_MODE0);
181+
SPI.beginTransaction(SPISettings(36000000));
185182

186183
#elif defined (__arm__)
187184
SPI.begin();
@@ -335,6 +332,7 @@ void Adafruit_ILI9341_STM::begin(void) {
335332
if (hwSPI) spi_begin();
336333
writecommand(ILI9341_DISPON); //Display on
337334
if (hwSPI) spi_end();
335+
if (hwSPI) SPI.setDataSize(SPI_CR1_DFF);
338336

339337
}
340338

@@ -345,18 +343,14 @@ void Adafruit_ILI9341_STM::setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1,
345343
writecommand(ILI9341_CASET); // Column addr set
346344
*dcport |= dcpinmask;
347345
*csport &= ~cspinmask;
348-
SPI.setDataSize (SPI_CR1_DFF);
349346
SPI.write(x0);
350347
SPI.write(x1);
351-
// SPI.setDataSize (0);
352348

353349
writecommand(ILI9341_PASET); // Row addr set
354350
*dcport |= dcpinmask;
355351
*csport &= ~cspinmask;
356-
// SPI.setDataSize (SPI_CR1_DFF);
357352
SPI.write(y0);
358353
SPI.write(y1);
359-
SPI.setDataSize (0);
360354

361355
writecommand(ILI9341_RAMWR); // write to RAM
362356

@@ -385,7 +379,6 @@ void Adafruit_ILI9341_STM::pushColor(uint16_t color) {
385379
//digitalWrite(_cs, LOW);
386380
*csport &= ~cspinmask;
387381

388-
spiwrite(color >> 8);
389382
spiwrite(color);
390383

391384
*csport |= cspinmask;
@@ -403,7 +396,6 @@ void Adafruit_ILI9341_STM::drawPixel(int16_t x, int16_t y, uint16_t color) {
403396
*dcport |= dcpinmask;
404397
*csport &= ~cspinmask;
405398

406-
spiwrite(color >> 8);
407399
spiwrite(color);
408400

409401
*csport |= cspinmask;
@@ -431,10 +423,8 @@ void Adafruit_ILI9341_STM::drawFastVLine(int16_t x, int16_t y, int16_t h,
431423
*csport &= ~cspinmask;
432424

433425
#if defined (__STM32F1__)
434-
SPI.setDataSize (SPI_CR1_DFF); // Set SPI 16bit mode
435426
lineBuffer[0] = color;
436427
SPI.dmaSend(lineBuffer, h, 0);
437-
SPI.setDataSize (0);
438428
#else
439429
uint8_t hi = color >> 8, lo = color;
440430
while (h--) {
@@ -464,10 +454,8 @@ void Adafruit_ILI9341_STM::drawFastHLine(int16_t x, int16_t y, int16_t w,
464454
*csport &= ~cspinmask;
465455

466456
#if defined (__STM32F1__)
467-
SPI.setDataSize (SPI_CR1_DFF); // Set spi 16bit mode
468457
lineBuffer[0] = color;
469458
SPI.dmaSend(lineBuffer, w, 0);
470-
SPI.setDataSize (0);
471459
#else
472460
uint8_t hi = color >> 8, lo = color;
473461
while (w--) {
@@ -485,11 +473,9 @@ void Adafruit_ILI9341_STM::fillScreen(uint16_t color) {
485473
setAddrWindow(0, 0, _width - 1, _height - 1);
486474
*dcport |= dcpinmask;
487475
*csport &= ~cspinmask;
488-
SPI.setDataSize (SPI_CR1_DFF); // Set spi 16bit mode
489476
lineBuffer[0] = color;
490477
SPI.dmaSend(lineBuffer, (65535), 0);
491478
SPI.dmaSend(lineBuffer, ((_width * _height) - 65535), 0);
492-
SPI.setDataSize (0);
493479

494480
#else
495481
fillRect(0, 0, _width, _height, color);
@@ -515,7 +501,6 @@ void Adafruit_ILI9341_STM::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
515501
*dcport |= dcpinmask;
516502
*csport &= ~cspinmask;
517503
#if defined (__STM32F1__)
518-
SPI.setDataSize (SPI_CR1_DFF); // Set spi 16bit mode
519504
lineBuffer[0] = color;
520505
if (w*h <= 65535) {
521506
SPI.dmaSend(lineBuffer, (w*h), 0);
@@ -524,7 +509,6 @@ void Adafruit_ILI9341_STM::fillRect(int16_t x, int16_t y, int16_t w, int16_t h,
524509
SPI.dmaSend(lineBuffer, (65535), 0);
525510
SPI.dmaSend(lineBuffer, ((w*h) - 65535), 0);
526511
}
527-
SPI.setDataSize (0);
528512
#else
529513
uint8_t hi = color >> 8, lo = color;
530514
for(y=h; y>0; y--)
@@ -672,6 +656,7 @@ uint16_t Adafruit_ILI9341_STM::color565(uint8_t r, uint8_t g, uint8_t b) {
672656
void Adafruit_ILI9341_STM::setRotation(uint8_t m) {
673657

674658
if (hwSPI) spi_begin();
659+
if (hwSPI) SPI.setDataSize(0);
675660
writecommand(ILI9341_MADCTL);
676661
rotation = m % 4; // can't be higher than 3
677662
switch (rotation) {
@@ -696,6 +681,7 @@ void Adafruit_ILI9341_STM::setRotation(uint8_t m) {
696681
_height = ILI9341_TFTWIDTH;
697682
break;
698683
}
684+
if (hwSPI) SPI.setDataSize(SPI_CR1_DFF);
699685
if (hwSPI) spi_end();
700686
}
701687

STM32F1/libraries/Adafruit_ILI9341_STM/Adafruit_ILI9341_STM.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ This library has been modified for the Maple Mini
1111
#include <Adafruit_GFX_AS.h>
1212
#include <avr/pgmspace.h>
1313

14+
#ifndef swap
15+
#define swap(a, b) { int16_t t = a; a = b; b = t; }
16+
#endif
17+
1418
#define ILI9341_TFTWIDTH 240
1519
#define ILI9341_TFTHEIGHT 320
1620

@@ -125,7 +129,7 @@ class Adafruit_ILI9341_STM : public Adafruit_GFX {
125129
void dummyclock(void);
126130
*/
127131

128-
void spiwrite(uint8_t),
132+
void spiwrite(uint16_t),
129133
writecommand(uint8_t c),
130134
writedata(uint8_t d),
131135
commandList(uint8_t *addr);

0 commit comments

Comments
 (0)