1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-27 18:02:17 +03:00

register and clock changes

This commit is contained in:
John Doe
2015-06-02 00:11:20 +03:00
parent 1501818c67
commit 6ab3c76e03
7 changed files with 67 additions and 49 deletions

View File

@ -121,14 +121,14 @@ void SPIClass::setBitOrder(uint8_t bitOrder) {
* @return
*/
static uint32_t ClkRegToFreq(spiClk_t * reg) {
return (SPI_MAX_SPEED / ((reg->regPre + 1) * (reg->regN + 1)));
return (ESP8266_CLOCK / ((reg->regPre + 1) * (reg->regN + 1)));
}
void SPIClass::setFrequency(uint32_t freq) {
static uint32_t lastSetFrequency = 0;
static uint32_t lastSetRegister = 0;
if(freq >= SPI_MAX_SPEED) {
if(freq >= ESP8266_CLOCK) {
setClockDivider(0x80000000);
return;
}
@ -164,7 +164,7 @@ void SPIClass::setFrequency(uint32_t freq) {
reg.regN = calN;
while(calPreVari++ <= 1) { // test different variants for Pre (we calculate in int so we miss the decimals, testing is the easyest and fastest way)
calPre = (((SPI_MAX_SPEED / (reg.regN + 1)) / freq) - 1) + calPreVari;
calPre = (((ESP8266_CLOCK / (reg.regN + 1)) / freq) - 1) + calPreVari;
if(calPre > 0x1FFF) {
reg.regPre = 0x1FFF; // 8191
} else if(calPre <= 0) {

View File

@ -45,8 +45,6 @@
#define SPI_CLOCK_DIV64 0x04fc1001 //250 KHz
#endif
#define SPI_MAX_SPEED (80000000L)
const uint8_t SPI_MODE0 = 0x00; ///< CPOL: 0 CPHA: 0
const uint8_t SPI_MODE1 = 0x01; ///< CPOL: 0 CPHA: 1
const uint8_t SPI_MODE2 = 0x10; ///< CPOL: 1 CPHA: 0