Skip to content

Commit 7f4a100

Browse files
committed
update README
add some docu and todo
1 parent ee5def9 commit 7f4a100

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ else they default to pins 4(SDA) and 5(SCL).
132132

133133
#### SPI ####
134134

135-
SPI library supports the entire Arduino SPI API including transactions, including setting phase and polarity.
135+
SPI library supports the entire Arduino SPI API including transactions, including setting phase (CPHA).
136+
Setting the Clock polarity (CPOL) is not supported, yet (SPI_MODE2 and SPI_MODE3 not working).
136137

137138
#### ESP-specific APIs ####
138139

libraries/SPI/SPI.cpp

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,39 @@
2121

2222
#include "SPI.h"
2323
#include "HardwareSerial.h"
24+
2425
typedef struct {
2526
uint32_t divider;
26-
uint32_t regValue;
27+
union {
28+
uint32_t regValue;
29+
struct {
30+
unsigned regL :6;
31+
unsigned regH :6;
32+
unsigned regN :6;
33+
unsigned regPre :13;
34+
unsigned regEQU :1;
35+
};
36+
};
2737
} spiClockDiv_t;
2838

39+
// todo find way of calculation for the divider
2940
static const spiClockDiv_t spiClockDiv[] = {
30-
{ 0, (0x80000000) }, ///< @80Mhz = 80 MHz @160Mhz = 160 MHz
31-
{ 2, (0x00001001) }, ///< @80Mhz = 40 MHz @160Mhz = 80 MHz
32-
{ 4, (0x00041001) }, ///< @80Mhz = 20 MHz @160Mhz = 40 MHz
33-
{ 6, (0x000fffc0) }, ///< @80Mhz = 16 MHz @160Mhz = 32 MHz
34-
{ 8, (0x000c1001) }, ///< @80Mhz = 10 MHz @160Mhz = 20 MHz
35-
{ 10, (0x00101001) }, ///< @80Mhz = 8 MHz @160Mhz = 16 MHz
36-
{ 16, (0x001c1001) }, ///< @80Mhz = 5 MHz @160Mhz = 10 MHz
37-
{ 20, (0x00241001) }, ///< @80Mhz = 4 MHz @160Mhz = 8 MHz
38-
{ 40, (0x004c1001) }, ///< @80Mhz = 2 MHz @160Mhz = 4 MHz
39-
{ 80, (0x009c1001) }, ///< @80Mhz = 1 MHz @160Mhz = 2 MHz
40-
{ 160, (0x013c1001) }, ///< @80Mhz = 500 KHz @160Mhz = 1 MHz
41-
{ 320, (0x027c1001) }, ///< @80Mhz = 250 KHz @160Mhz = 500 KHz
42-
{ 640, (0x04fc1001) } ///< @80Mhz = 125 KHz @160Mhz = 250 KHz
41+
{ 0, (0x80000000) }, ///< [0] EQU: 1 Pre: 0 N: 0 H: 0 L: 0 Div: 0 @80Mhz = 80 MHz @160Mhz = 160 MHz
42+
{ 2, (0x00001001) }, ///< [1] EQU: 0 Pre: 0 N: 1 H: 0 L: 1 Div: 2 @80Mhz = 40 MHz @160Mhz = 80 MHz
43+
{ 4, (0x00041001) }, ///< [2] EQU: 0 Pre: 1 N: 1 H: 0 L: 1 Div: 4 @80Mhz = 20 MHz @160Mhz = 40 MHz
44+
{ 6, (0x000fffc0) }, ///< [3] EQU: 0 Pre: 3 N: 63 H: 63 L: 0 Div: 6 @80Mhz = 16 MHz @160Mhz = 32 MHz
45+
{ 8, (0x000c1001) }, ///< [4] EQU: 0 Pre: 3 N: 1 H: 0 L: 1 Div: 8 @80Mhz = 10 MHz @160Mhz = 20 MHz
46+
{ 10, (0x00101001) }, ///< [5] EQU: 0 Pre: 4 N: 1 H: 0 L: 1 Div: 10 @80Mhz = 8 MHz @160Mhz = 16 MHz
47+
{ 16, (0x001c1001) }, ///< [6] EQU: 0 Pre: 7 N: 1 H: 0 L: 1 Div: 16 @80Mhz = 5 MHz @160Mhz = 10 MHz
48+
{ 20, (0x00241001) }, ///< [7] EQU: 0 Pre: 9 N: 1 H: 0 L: 1 Div: 20 @80Mhz = 4 MHz @160Mhz = 8 MHz
49+
{ 40, (0x004c1001) }, ///< [8] EQU: 0 Pre: 19 N: 1 H: 0 L: 1 Div: 40 @80Mhz = 2 MHz @160Mhz = 4 MHz
50+
{ 80, (0x009c1001) }, ///< [9] EQU: 0 Pre: 39 N: 1 H: 0 L: 1 Div: 80 @80Mhz = 1 MHz @160Mhz = 2 MHz
51+
{ 160, (0x013c1001) }, ///< [10] EQU: 0 Pre: 79 N: 1 H: 0 L: 1 Div: 160 @80Mhz = 500 KHz @160Mhz = 1 MHz
52+
{ 320, (0x027c1001) }, ///< [11] EQU: 0 Pre: 159 N: 1 H: 0 L: 1 Div: 320 @80Mhz = 250 KHz @160Mhz = 500 KHz
53+
{ 640, (0x04fc1001) } ///< [12] EQU: 0 Pre: 319 N: 1 H: 0 L: 1 Div: 640 @80Mhz = 125 KHz @160Mhz = 250 KHz
4354
};
4455

56+
4557
static const uint8_t spiClockDiv_count = (sizeof(spiClockDiv) / sizeof(spiClockDiv_t));
4658

4759
SPIClass SPI;
@@ -53,6 +65,11 @@ void SPIClass::begin() {
5365
pinMode(SCK, SPECIAL); ///< GPIO14
5466
pinMode(MISO, SPECIAL); ///< GPIO12
5567
pinMode(MOSI, SPECIAL); ///< GPIO13
68+
/*
69+
for(uint8_t i = 0; i < (spiClockDiv_count); i++) {
70+
os_printf("[%d]\t EQU: %d\t Pre: %d\t N: %d\t H: %d\t L: %d\t Div: %d - %d\n", i, spiClockDiv[i].regEQU, spiClockDiv[i].regPre, spiClockDiv[i].regN, spiClockDiv[i].regH, spiClockDiv[i].regL, spiClockDiv[i].divider );
71+
}
72+
*/
5673

5774
GPMUX = 0x105; // note crash if SPI flash Frequency < 40MHz
5875
SPI1C = 0;

0 commit comments

Comments
 (0)